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

Side by Side Diff: chrome/browser/notifications/multi_user_notification_blocker_chromeos_unittest.cc

Issue 127423002: Supports window teleports for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix wallpaper private api test Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 "ash/shell.h"
6 #include "ash/system/system_notifier.h"
7 #include "ash/test/ash_test_base.h"
8 #include "ash/test/test_shell_delegate.h"
9 #include "chrome/browser/chromeos/login/fake_user_manager.h"
10 #include "chrome/browser/notifications/multi_user_notification_blocker_chromeos. h"
11 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
12 #include "chrome/test/base/testing_browser_process.h"
13 #include "chrome/test/base/testing_profile_manager.h"
14 #include "ui/message_center/message_center.h"
15 #include "ui/message_center/notification.h"
16
17 namespace {
18
19 // This value should be same as the one in fake_user_manager.cc
20 static const char kUserIdHashSuffix[] = "-hash";
21
22 }
23
24 class MultiUserNotificationBlockerChromeOSTest
25 : public ash::test::AshTestBase,
26 public message_center::NotificationBlocker::Observer {
27 public:
28 MultiUserNotificationBlockerChromeOSTest()
29 : state_changed_count_(0),
30 is_logged_in_(false),
31 testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {}
32 virtual ~MultiUserNotificationBlockerChromeOSTest() {}
33
34 // ash::test::AshTestBase overrides:
35 virtual void SetUp() OVERRIDE {
36 ash::test::AshTestBase::SetUp();
37 ASSERT_TRUE(testing_profile_manager_.SetUp());
38
39 // Initialize the UserManager singleton to a fresh FakeUserManager instance.
40 user_manager_enabler_.reset(
41 new chromeos::ScopedUserManagerEnabler(new chromeos::FakeUserManager));
42 blocker_.reset(new MultiUserNotificationBlockerChromeOS(
43 message_center::MessageCenter::Get()));
44 blocker_->AddObserver(this);
45 }
46
47 virtual void TearDown() OVERRIDE {
48 blocker_->RemoveObserver(this);
49 blocker_.reset();
50 if (chrome::MultiUserWindowManager::GetInstance())
51 chrome::MultiUserWindowManager::DeleteInstance();
52 ash::test::AshTestBase::TearDown();
53 }
54
55 // message_center::NotificationBlocker::Observer ovverrides:
56 virtual void OnBlockingStateChanged(
57 message_center::NotificationBlocker* blocker) OVERRIDE {
58 state_changed_count_++;
59 }
60
61 protected:
62 void SetupMultiUserMode(bool enabled) {
63 ash::test::TestShellDelegate* shell_delegate =
64 static_cast<ash::test::TestShellDelegate*>(
65 ash::Shell::GetInstance()->delegate());
66 shell_delegate->set_multi_profiles_enabled(enabled);
67 chrome::MultiUserWindowManager::CreateInstance();
68 }
69
70 void CreateProfile(const std::string& name) {
71 testing_profile_manager_.CreateTestingProfile(name);
72 GetFakeUserManager()->AddUser(name);
73 GetFakeUserManager()->UserLoggedIn(name, name + kUserIdHashSuffix, false);
74 if (!is_logged_in_) {
75 SwitchActiveUser(name);
76 is_logged_in_ = true;
77 }
78 }
79
80 void SwitchActiveUser(const std::string& name) {
81 GetFakeUserManager()->SwitchActiveUser(name);
82 blocker_->ActiveUserChanged(GetFakeUserManager()->GetActiveUser());
83 }
84
85 int GetStateChangedCountAndReset() {
86 int result = state_changed_count_;
87 state_changed_count_ = 0;
88 return result;
89 }
90
91 bool ShouldShowNotificationAsPopup(
92 const message_center::NotifierId& notifier_id,
93 const std::string profile_id) {
94 message_center::NotifierId id_with_profile = notifier_id;
95 id_with_profile.profile_id = profile_id;
96 return blocker_->ShouldShowNotificationAsPopup(id_with_profile);
97 }
98
99 bool ShouldShowNotification(
100 const message_center::NotifierId& notifier_id,
101 const std::string profile_id) {
102 message_center::NotifierId id_with_profile = notifier_id;
103 id_with_profile.profile_id = profile_id;
104 return blocker_->ShouldShowNotification(id_with_profile);
105 }
106
107 private:
108 chromeos::FakeUserManager* GetFakeUserManager() {
109 return static_cast<chromeos::FakeUserManager*>(
110 chromeos::UserManager::Get());
111 }
112
113 int state_changed_count_;
114 bool is_logged_in_;
115 TestingProfileManager testing_profile_manager_;
116 scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
117 scoped_ptr<MultiUserNotificationBlockerChromeOS> blocker_;
118
119 DISALLOW_COPY_AND_ASSIGN(MultiUserNotificationBlockerChromeOSTest);
120 };
121
122 TEST_F(MultiUserNotificationBlockerChromeOSTest, Basic) {
123 SetupMultiUserMode(true);
124 ASSERT_EQ(chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED,
125 chrome::MultiUserWindowManager::GetMultiProfileMode());
126
127 message_center::NotifierId notifier_id(
128 message_center::NotifierId::APPLICATION, "test-app");
129 // Only allowed the system notifier.
130 message_center::NotifierId ash_system_notifier(
131 message_center::NotifierId::SYSTEM_COMPONENT,
132 ash::system_notifier::kNotifierDisplay);
133 // Other system notifiers should be treated as same as a normal notifier.
134 message_center::NotifierId random_system_notifier(
135 message_center::NotifierId::SYSTEM_COMPONENT, "random_system_component");
136
137 // Nothing is created, active_user_id_ should be empty.
138 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id, ""));
139 EXPECT_TRUE(ShouldShowNotificationAsPopup(ash_system_notifier, ""));
140 EXPECT_TRUE(ShouldShowNotificationAsPopup(random_system_notifier, ""));
141 EXPECT_TRUE(ShouldShowNotification(notifier_id, ""));
142 EXPECT_TRUE(ShouldShowNotification(ash_system_notifier, ""));
143 EXPECT_TRUE(ShouldShowNotification(random_system_notifier, ""));
144
145 CreateProfile("test@example.com");
146 EXPECT_EQ(1, GetStateChangedCountAndReset());
147 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id, ""));
148 EXPECT_TRUE(ShouldShowNotificationAsPopup(ash_system_notifier, ""));
149 EXPECT_FALSE(ShouldShowNotificationAsPopup(random_system_notifier, ""));
150 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id, "test@example.com"));
151 EXPECT_FALSE(ShouldShowNotification(notifier_id, ""));
152 EXPECT_TRUE(ShouldShowNotification(ash_system_notifier, ""));
153 EXPECT_FALSE(ShouldShowNotification(random_system_notifier, ""));
154 EXPECT_TRUE(ShouldShowNotification(notifier_id, "test@example.com"));
155 EXPECT_TRUE(ShouldShowNotification(random_system_notifier,
156 "test@example.com"));
157
158 CreateProfile("test2@example.com");
159 EXPECT_EQ(0, GetStateChangedCountAndReset());
160 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id, ""));
161 EXPECT_TRUE(ShouldShowNotificationAsPopup(ash_system_notifier, ""));
162 EXPECT_FALSE(ShouldShowNotificationAsPopup(random_system_notifier, ""));
163 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id, "test@example.com"));
164 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id, "test2@example.com"));
165 EXPECT_TRUE(ShouldShowNotificationAsPopup(random_system_notifier,
166 "test@example.com"));
167 EXPECT_FALSE(ShouldShowNotificationAsPopup(random_system_notifier,
168 "test2@example.com"));
169 EXPECT_FALSE(ShouldShowNotification(notifier_id, ""));
170 EXPECT_TRUE(ShouldShowNotification(ash_system_notifier, ""));
171 EXPECT_FALSE(ShouldShowNotification(random_system_notifier, ""));
172 EXPECT_TRUE(ShouldShowNotification(notifier_id, "test@example.com"));
173 EXPECT_FALSE(ShouldShowNotification(notifier_id, "test2@example.com"));
174 EXPECT_TRUE(ShouldShowNotification(random_system_notifier,
175 "test@example.com"));
176 EXPECT_FALSE(ShouldShowNotification(random_system_notifier,
177 "test2@example.com"));
178
179 SwitchActiveUser("test2@example.com");
180 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id, ""));
181 EXPECT_TRUE(ShouldShowNotificationAsPopup(ash_system_notifier, ""));
182 EXPECT_FALSE(ShouldShowNotificationAsPopup(random_system_notifier, ""));
183 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id, "test@example.com"));
184 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id, "test2@example.com"));
185 EXPECT_FALSE(ShouldShowNotificationAsPopup(random_system_notifier,
186 "test@example.com"));
187 EXPECT_TRUE(ShouldShowNotificationAsPopup(random_system_notifier,
188 "test2@example.com"));
189 EXPECT_FALSE(ShouldShowNotification(notifier_id, ""));
190 EXPECT_TRUE(ShouldShowNotification(ash_system_notifier, ""));
191 EXPECT_FALSE(ShouldShowNotification(random_system_notifier, ""));
192 EXPECT_FALSE(ShouldShowNotification(notifier_id, "test@example.com"));
193 EXPECT_TRUE(ShouldShowNotification(notifier_id, "test2@example.com"));
194 EXPECT_FALSE(ShouldShowNotification(random_system_notifier,
195 "test@example.com"));
196 EXPECT_TRUE(ShouldShowNotification(random_system_notifier,
197 "test2@example.com"));
198
199 SwitchActiveUser("test@example.com");
200 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id, ""));
201 EXPECT_TRUE(ShouldShowNotificationAsPopup(ash_system_notifier, ""));
202 EXPECT_FALSE(ShouldShowNotificationAsPopup(random_system_notifier, ""));
203 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id, "test@example.com"));
204 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id, "test2@example.com"));
205 EXPECT_TRUE(ShouldShowNotificationAsPopup(random_system_notifier,
206 "test@example.com"));
207 EXPECT_FALSE(ShouldShowNotificationAsPopup(random_system_notifier,
208 "test2@example.com"));
209 EXPECT_FALSE(ShouldShowNotification(notifier_id, ""));
210 EXPECT_TRUE(ShouldShowNotification(ash_system_notifier, ""));
211 EXPECT_FALSE(ShouldShowNotification(random_system_notifier, ""));
212 EXPECT_TRUE(ShouldShowNotification(notifier_id, "test@example.com"));
213 EXPECT_FALSE(ShouldShowNotification(notifier_id, "test2@example.com"));
214 EXPECT_TRUE(ShouldShowNotification(random_system_notifier,
215 "test@example.com"));
216 EXPECT_FALSE(ShouldShowNotification(random_system_notifier,
217 "test2@example.com"));
218 }
219
220 TEST_F(MultiUserNotificationBlockerChromeOSTest, SingleUser) {
221 SetupMultiUserMode(false);
222 ASSERT_EQ(chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF,
223 chrome::MultiUserWindowManager::GetMultiProfileMode());
224
225 message_center::NotifierId notifier_id(
226 message_center::NotifierId::APPLICATION, "test-app");
227 // Only allowed the system notifier.
228 message_center::NotifierId ash_system_notifier(
229 message_center::NotifierId::SYSTEM_COMPONENT,
230 ash::system_notifier::kNotifierDisplay);
231 // Other system notifiers should be treated as same as a normal notifier.
232 message_center::NotifierId random_system_notifier(
233 message_center::NotifierId::SYSTEM_COMPONENT, "random_system_component");
234
235 // Nothing is created, active_user_id_ should be empty.
236 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id, ""));
237 EXPECT_TRUE(ShouldShowNotificationAsPopup(ash_system_notifier, ""));
238 EXPECT_TRUE(ShouldShowNotificationAsPopup(random_system_notifier, ""));
239 EXPECT_TRUE(ShouldShowNotification(notifier_id, ""));
240 EXPECT_TRUE(ShouldShowNotification(ash_system_notifier, ""));
241 EXPECT_TRUE(ShouldShowNotification(random_system_notifier, ""));
242
243 CreateProfile("test@example.com");
244 EXPECT_EQ(1, GetStateChangedCountAndReset());
245 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id, ""));
246 EXPECT_TRUE(ShouldShowNotificationAsPopup(ash_system_notifier, ""));
247 EXPECT_TRUE(ShouldShowNotificationAsPopup(random_system_notifier, ""));
248 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id, "test@example.com"));
249 EXPECT_TRUE(ShouldShowNotificationAsPopup(random_system_notifier,
250 "test@example.com"));
251 EXPECT_TRUE(ShouldShowNotification(notifier_id, ""));
252 EXPECT_TRUE(ShouldShowNotification(ash_system_notifier, ""));
253 EXPECT_TRUE(ShouldShowNotification(random_system_notifier, ""));
254 EXPECT_TRUE(ShouldShowNotification(notifier_id, "test@example.com"));
255 EXPECT_TRUE(ShouldShowNotification(random_system_notifier,
256 "test@example.com"));
257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698