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

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

Issue 2968323002: [EasyUnlock] Introduce EasyUnlockNotificationController (Closed)
Patch Set: fix unittests 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 "content/public/test/test_browser_thread_bundle.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/message_center/fake_message_center.h"
13 #include "ui/message_center/notification.h"
14 #include "ui/message_center/notification_types.h"
15
16 namespace {
17
18 const char kPhoneName[] = "Nexus 6";
19
20 class TestMessageCenter : public message_center::FakeMessageCenter {
21 public:
22 TestMessageCenter() : message_center::FakeMessageCenter() {}
23 ~TestMessageCenter() override {}
24
25 // message_center::FakeMessageCenter:
26 message_center::Notification* FindVisibleNotificationById(
27 const std::string& id) override {
28 auto iter = std::find_if(
29 notifications_.begin(), notifications_.end(),
30 [id](const std::shared_ptr<message_center::Notification> notification) {
31 return notification->id() == id;
32 });
33 return iter != notifications_.end() ? iter->get() : nullptr;
34 }
35
36 void AddNotification(
37 std::unique_ptr<message_center::Notification> notification) override {
38 notifications_.push_back(std::move(notification));
39 }
40
41 void UpdateNotification(
42 const std::string& old_id,
43 std::unique_ptr<message_center::Notification> new_notification) override {
44 RemoveNotification(old_id, false /* by_user */);
45 AddNotification(std::move(new_notification));
46 }
47
48 void RemoveNotification(const std::string& id, bool by_user) override {
49 if (!FindVisibleNotificationById(id))
50 return;
51
52 notifications_.erase(std::find_if(
53 notifications_.begin(), notifications_.end(),
54 [id](const std::shared_ptr<message_center::Notification> notification) {
55 return notification->id() == id;
56 }));
57 }
58
59 private:
60 std::vector<std::shared_ptr<message_center::Notification>> notifications_;
61
62 DISALLOW_COPY_AND_ASSIGN(TestMessageCenter);
63 };
64
65 class TestableNotificationController
66 : public EasyUnlockNotificationControllerChromeOS {
67 public:
68 TestableNotificationController(Profile* profile,
69 message_center::MessageCenter* message_center)
70 : EasyUnlockNotificationControllerChromeOS(profile, message_center) {}
71
72 ~TestableNotificationController() override {}
73
74 // EasyUnlockNotificationControllerChromeOS:
75 MOCK_METHOD0(LaunchEasyUnlockSettings, void());
76 MOCK_METHOD0(LockScreen, void());
77
78 private:
79 DISALLOW_COPY_AND_ASSIGN(TestableNotificationController);
80 };
81
82 } // namespace
83
84 class EasyUnlockNotificationControllerChromeOSTest : public ::testing::Test {
85 protected:
86 EasyUnlockNotificationControllerChromeOSTest()
87 : notification_controller_(&profile_, &message_center_) {}
88
89 ~EasyUnlockNotificationControllerChromeOSTest() override {}
90
91 const content::TestBrowserThreadBundle thread_bundle_;
92 TestingProfile profile_;
93 TestMessageCenter message_center_;
94 testing::StrictMock<TestableNotificationController> notification_controller_;
95
96 private:
97 DISALLOW_COPY_AND_ASSIGN(EasyUnlockNotificationControllerChromeOSTest);
98 };
99
100 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
101 TestShowChromebookAddedNotification) {
102 const char kNotificationId[] = "easyunlock_notification_ids.chromebook_added";
103
104 notification_controller_.ShowChromebookAddedNotification();
105 message_center::Notification* notification =
106 message_center_.FindVisibleNotificationById(kNotificationId);
107 ASSERT_TRUE(notification);
108 ASSERT_EQ(1u, notification->buttons().size());
109 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
110
111 // Clicking notification button should launch settings.
112 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
113 notification->ButtonClick(0);
114
115 // Clicking the notification itself should also launch settings.
116 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
117 notification->Click();
118 }
119
120 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
121 TestShowPairingChangeNotification) {
122 const char kNotificationId[] = "easyunlock_notification_ids.pairing_change";
123
124 notification_controller_.ShowPairingChangeNotification();
125 message_center::Notification* notification =
126 message_center_.FindVisibleNotificationById(kNotificationId);
127 ASSERT_TRUE(notification);
128 ASSERT_EQ(2u, notification->buttons().size());
129 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
130
131 // Clicking 1st notification button should lock screen settings.
132 EXPECT_CALL(notification_controller_, LockScreen());
133 notification->ButtonClick(0);
134
135 // Clicking 2nd notification button should launch settings.
136 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
137 notification->ButtonClick(1);
138
139 // Clicking the notification itself should do nothing.
140 notification->Click();
141 }
142
143 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
144 TestShowPairingChangeAppliedNotification) {
145 const char kNotificationId[] =
146 "easyunlock_notification_ids.pairing_change_applied";
147
148 notification_controller_.ShowPairingChangeAppliedNotification(kPhoneName);
149 message_center::Notification* notification =
150 message_center_.FindVisibleNotificationById(kNotificationId);
151 ASSERT_TRUE(notification);
152 ASSERT_EQ(1u, notification->buttons().size());
153 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
154
155 // Check that the phone name is in the notification message.
156 EXPECT_NE(std::string::npos,
157 notification->message().find(base::UTF8ToUTF16(kPhoneName)));
158
159 // Clicking notification button should launch settings.
160 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
161 notification->ButtonClick(0);
162
163 // Clicking the notification itself should also launch settings.
164 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
165 notification->Click();
166 }
167
168 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
169 PairingAppliedRemovesPairingChange) {
170 const char kPairingChangeId[] = "easyunlock_notification_ids.pairing_change";
171 const char kPairingAppliedId[] =
172 "easyunlock_notification_ids.pairing_change_applied";
173
174 notification_controller_.ShowPairingChangeNotification();
175 EXPECT_TRUE(message_center_.FindVisibleNotificationById(kPairingChangeId));
176
177 notification_controller_.ShowPairingChangeAppliedNotification(kPhoneName);
178 EXPECT_FALSE(message_center_.FindVisibleNotificationById(kPairingChangeId));
179 EXPECT_TRUE(message_center_.FindVisibleNotificationById(kPairingAppliedId));
180 }
181
182 TEST_F(EasyUnlockNotificationControllerChromeOSTest,
183 TestShowPromotionNotification) {
184 const char kNotificationId[] = "easyunlock_notification_ids.promotion";
185
186 notification_controller_.ShowPromotionNotification();
187 message_center::Notification* notification =
188 message_center_.FindVisibleNotificationById(kNotificationId);
189 ASSERT_TRUE(notification);
190 ASSERT_EQ(1u, notification->buttons().size());
191 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
192
193 // Clicking notification button should launch settings.
194 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
195 notification->ButtonClick(0);
196
197 // Clicking the notification itself should also launch settings.
198 EXPECT_CALL(notification_controller_, LaunchEasyUnlockSettings());
199 notification->Click();
200 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_notification_controller_chromeos.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698