1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/notifications/deprecation_notification_controller.h"
#include "ash/accelerators/accelerator_controller_impl.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/fake_message_center.h"
namespace ash {
namespace {
class DeprecationNotificationControllerTest : public AshTestBase {
protected:
DeprecationNotificationControllerTest() : controller_(&message_center_) {}
DeprecationNotificationControllerTest(
const DeprecationNotificationControllerTest&) = delete;
DeprecationNotificationControllerTest& operator=(
const DeprecationNotificationControllerTest&) = delete;
~DeprecationNotificationControllerTest() override = default;
// |message_center_| must be declared before |controller_| since it is an
// argument to it's constructor.
message_center::FakeMessageCenter message_center_;
DeprecationNotificationController controller_;
};
} // namespace
// Test that all the notifications are displayed and only once each.
TEST_F(DeprecationNotificationControllerTest, AllNotificationsWorkAndNoDupes) {
size_t expected_notification_count = 1;
controller_.NotifyDeprecatedRightClickRewrite();
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_DELETE);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_INSERT);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_HOME);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_END);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_PRIOR);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_NEXT);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
// Clear the messages from the message center.
message_center_.RemoveAllNotifications(
/*by_user=*/false, message_center::FakeMessageCenter::RemoveType::ALL);
// No additional notifications should be generated.
controller_.NotifyDeprecatedRightClickRewrite();
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_DELETE);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_INSERT);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_HOME);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_END);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_PRIOR);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_NEXT);
EXPECT_EQ(message_center_.NotificationCount(), 0u);
}
// Test that six pack notifications are not displayed when accelerators are
// blocked.
TEST_F(DeprecationNotificationControllerTest,
SixPackNotificationsBlockedWithShortcuts) {
// Block shortcuts and attempt to create notifications. Since shortcuts are
// blocked, no notifications should be created.
Shell::Get()->accelerator_controller()->SetPreventProcessingAccelerators(
/*prevent_processing_accelerators=*/true);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_DELETE);
EXPECT_EQ(message_center_.NotificationCount(), 0u);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_INSERT);
EXPECT_EQ(message_center_.NotificationCount(), 0u);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_HOME);
EXPECT_EQ(message_center_.NotificationCount(), 0u);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_END);
EXPECT_EQ(message_center_.NotificationCount(), 0u);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_PRIOR);
EXPECT_EQ(message_center_.NotificationCount(), 0u);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_NEXT);
EXPECT_EQ(message_center_.NotificationCount(), 0u);
// Clear the messages from the message center.
message_center_.RemoveAllNotifications(
/*by_user=*/false, message_center::FakeMessageCenter::RemoveType::ALL);
// Unblock shortcuts and then publish notifications, notifications should now
// publish as expected.
Shell::Get()->accelerator_controller()->SetPreventProcessingAccelerators(
/*prevent_processing_accelerators=*/false);
size_t expected_notification_count = 1;
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_DELETE);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_INSERT);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_HOME);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_END);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_PRIOR);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
controller_.NotifyDeprecatedSixPackKeyRewrite(ui::VKEY_NEXT);
EXPECT_EQ(message_center_.NotificationCount(), expected_notification_count++);
}
} // namespace ash
|