Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(680)

Side by Side Diff: chrome/browser/signin/easy_unlock_notification_controller_chromeos_unittest.cc

Issue 2968323002: [EasyUnlock] Introduce EasyUnlockNotificationController (Closed)
Patch Set: use delegate instead of mc observer Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/signin/easy_unlock_notification_controller_chromeos.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/message_center/fake_message_center.h"
12 #include "ui/message_center/notification.h"
13 #include "ui/message_center/notification_types.h"
14
15 namespace {
16
17 const char kPhoneName[] = "Nexus 6";
18
19 class TestMessageCenter : public message_center::FakeMessageCenter {
20 public:
21 TestMessageCenter() : message_center::FakeMessageCenter() {}
22 ~TestMessageCenter() override {}
23
24 // message_center::FakeMessageCenter:
25 message_center::Notification* FindVisibleNotificationById(
26 const std::string& id) override {
27 auto iter = std::find_if(
28 notifications_.begin(), notifications_.end(),
29 [id](const std::shared_ptr<message_center::Notification> notification) {
30 return notification->id() == id;
31 });
32 return iter != notifications_.end() ? iter->get() : nullptr;
33 }
34
35 void AddNotification(
36 std::unique_ptr<message_center::Notification> notification) override {
37 notifications_.push_back(std::move(notification));
38 }
39
40 void UpdateNotification(
41 const std::string& old_id,
42 std::unique_ptr<message_center::Notification> new_notification) override {
43 RemoveNotification(old_id, false /* by_user */);
44 AddNotification(std::move(new_notification));
45 }
46
47 void RemoveNotification(const std::string& id, bool by_user) override {
48 if (!FindVisibleNotificationById(id))
49 return;
50
51 notifications_.erase(std::find_if(
52 notifications_.begin(), notifications_.end(),
53 [id](const std::shared_ptr<message_center::Notification> notification) {
54 return notification->id() == id;
55 }));
56 }
57
58 private:
59 std::vector<std::shared_ptr<message_center::Notification>> notifications_;
60
61 DISALLOW_COPY_AND_ASSIGN(TestMessageCenter);
62 };
63
64 class TestableNotificationController
65 : public EasyUnlockNotificationControllerChromeOS {
66 public:
67 TestableNotificationController(Profile* profile,
68 message_center::MessageCenter* message_center)
69 : EasyUnlockNotificationControllerChromeOS(profile, message_center) {}
70
71 ~TestableNotificationController() override {}
72
73 // EasyUnlockNotificationControllerChromeOS:
74 MOCK_METHOD0(LaunchEasyUnlockSettings, void());
75 MOCK_METHOD0(LockScreen, void());
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(TestableNotificationController);
79 };
80
81 } // namespace
82
83 class EasyUnlockNotificationControllerChromeOSTest : public ::testing::Test {
84 protected:
85 EasyUnlockNotificationControllerChromeOSTest()
86 : notification_controller_(&profile_, &message_center_) {}
87
88 ~EasyUnlockNotificationControllerChromeOSTest() override {}
89
90 TestingProfile profile_;
91 TestMessageCenter message_center_;
92 testing::StrictMock<TestableNotificationController> notification_controller_;
93
94 private:
95 DISALLOW_COPY_AND_ASSIGN(EasyUnlockNotificationControllerChromeOSTest);
96 };
97
98 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
99 TestShowChromebookAddedNotification) {
100 const char kNotificationId[] = "easyunlock_notification_ids.chromebook_added";
101
102 notification_controller_.ShowChromebookAddedNotification();
103 message_center::Notification* notification =
104 message_center_.FindVisibleNotificationById(kNotificationId);
105 ASSERT_TRUE(notification);
106 ASSERT_EQ(1u, notification->buttons().size());
107 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
108
109 // Clicking notification button should launch settings.
110 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
111 notification->ButtonClick(0);
112
113 // Clicking the notification itself should also launch settings.
114 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
115 notification->Click();
116 }
117
118 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
119 TestShowPairingChangeNotification) {
120 const char kNotificationId[] = "easyunlock_notification_ids.pairing_change";
121
122 notification_controller_.ShowPairingChangeNotification();
123 message_center::Notification* notification =
124 message_center_.FindVisibleNotificationById(kNotificationId);
125 ASSERT_TRUE(notification);
126 ASSERT_EQ(2u, notification->buttons().size());
127 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
128
129 // Clicking 1st notification button should lock screen settings.
130 EXPECT_CALL(notification_controller_, LockScreen());
131 notification->ButtonClick(0);
132
133 // Clicking 2nd notification button should launch settings.
134 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
135 notification->ButtonClick(1);
136
137 // Clicking the notification itself should do nothing.
138 notification->Click();
139 }
140
141 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
142 TestShowPairingChangeAppliedNotification) {
143 const char kNotificationId[] =
144 "easyunlock_notification_ids.pairing_change_applied";
145
146 notification_controller_.ShowPairingChangeAppliedNotification(kPhoneName);
147 message_center::Notification* notification =
148 message_center_.FindVisibleNotificationById(kNotificationId);
149 ASSERT_TRUE(notification);
150 ASSERT_EQ(1u, notification->buttons().size());
151 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
152
153 // Check that the phone name is in the notification message.
154 EXPECT_NE(std::string::npos,
155 notification->message().find(base::UTF8ToUTF16(kPhoneName)));
156
157 // Clicking notification button should launch settings.
158 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
159 notification->ButtonClick(0);
160
161 // Clicking the notification itself should also launch settings.
162 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
163 notification->Click();
164 }
165
166 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
167 PairingAppliedRemovesPairingChange) {
168 const char kPairingChangeId[] = "easyunlock_notification_ids.pairing_change";
169 const char kPairingAppliedId[] =
170 "easyunlock_notification_ids.pairing_change_applied";
171
172 notification_controller_.ShowPairingChangeNotification();
173 EXPECT_TRUE(message_center_.FindVisibleNotificationById(kPairingChangeId));
174
175 notification_controller_.ShowPairingChangeAppliedNotification(kPhoneName);
176 EXPECT_FALSE(message_center_.FindVisibleNotificationById(kPairingChangeId));
177 EXPECT_TRUE(message_center_.FindVisibleNotificationById(kPairingAppliedId));
178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698