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

Side by Side Diff: chrome/browser/chromeos/notifications/notification_browsertest.cc

Issue 4635007: When an extension is uninstalled, close all desktop notifications from that e... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "app/x11_util.h" 5 #include "app/x11_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" 14 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h"
15 #include "chrome/browser/chromeos/notifications/balloon_view.h" 15 #include "chrome/browser/chromeos/notifications/balloon_view.h"
16 #include "chrome/browser/chromeos/notifications/notification_panel.h" 16 #include "chrome/browser/chromeos/notifications/notification_panel.h"
17 #include "chrome/browser/chromeos/notifications/system_notification_factory.h" 17 #include "chrome/browser/chromeos/notifications/system_notification_factory.h"
18 #include "chrome/browser/notifications/notification_delegate.h" 18 #include "chrome/browser/notifications/notification_test_util.h"
19 #include "chrome/browser/notifications/notification_ui_manager.h" 19 #include "chrome/browser/notifications/notification_ui_manager.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/common/notification_service.h" 21 #include "chrome/common/notification_service.h"
22 #include "chrome/test/in_process_browser_test.h" 22 #include "chrome/test/in_process_browser_test.h"
23 #include "chrome/test/ui_test_utils.h" 23 #include "chrome/test/ui_test_utils.h"
24 24
25 namespace { 25 namespace {
26 26
27 class MockNotificationDelegate : public NotificationDelegate {
28 public:
29 explicit MockNotificationDelegate(const std::string& id) : id_(id) {}
30
31 virtual void Display() {}
32 virtual void Error() {}
33 virtual void Close(bool by_user) {}
34 virtual void Click() {}
35 virtual std::string id() const { return id_; }
36
37 private:
38 std::string id_;
39
40 DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate);
41 };
42
43 // The name of ChromeOS's window manager. 27 // The name of ChromeOS's window manager.
44 const char* kChromeOsWindowManagerName = "chromeos-wm"; 28 const char* kChromeOsWindowManagerName = "chromeos-wm";
45 29
46 } // namespace 30 } // namespace
47 31
48 namespace chromeos { 32 namespace chromeos {
49 33
50 class NotificationTest : public InProcessBrowserTest, 34 class NotificationTest : public InProcessBrowserTest,
51 public NotificationObserver { 35 public NotificationObserver {
52 public: 36 public:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 EXPECT_EQ(1, tester->GetNotificationCount()); 139 EXPECT_EQ(1, tester->GetNotificationCount());
156 EXPECT_EQ(0, tester->GetStickyNotificationCount()); 140 EXPECT_EQ(0, tester->GetStickyNotificationCount());
157 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 141 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
158 142
159 collection->Add(NewMockNotification("2"), browser()->profile()); 143 collection->Add(NewMockNotification("2"), browser()->profile());
160 144
161 EXPECT_EQ(2, tester->GetNewNotificationCount()); 145 EXPECT_EQ(2, tester->GetNewNotificationCount());
162 EXPECT_EQ(2, tester->GetNotificationCount()); 146 EXPECT_EQ(2, tester->GetNotificationCount());
163 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 147 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
164 148
165 collection->Remove(NewMockNotification("1")); 149 collection->RemoveById("1");
166 ui_test_utils::RunAllPendingInMessageLoop(); 150 ui_test_utils::RunAllPendingInMessageLoop();
167 151
168 EXPECT_EQ(1, tester->GetNewNotificationCount()); 152 EXPECT_EQ(1, tester->GetNewNotificationCount());
169 EXPECT_EQ(1, tester->GetNotificationCount()); 153 EXPECT_EQ(1, tester->GetNotificationCount());
170 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 154 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
171 155
172 collection->Remove(NewMockNotification("2")); 156 collection->RemoveById("2");
173 ui_test_utils::RunAllPendingInMessageLoop(); 157 ui_test_utils::RunAllPendingInMessageLoop();
174 EXPECT_EQ(0, tester->GetNewNotificationCount()); 158 EXPECT_EQ(0, tester->GetNewNotificationCount());
175 EXPECT_EQ(0, tester->GetNotificationCount()); 159 EXPECT_EQ(0, tester->GetNotificationCount());
176 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); 160 EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
177 161
178 // CLOSE is asynchronous. Run the all pending tasks to finish closing 162 // CLOSE is asynchronous. Run the all pending tasks to finish closing
179 // task. 163 // task.
180 ui_test_utils::RunAllPendingInMessageLoop(); 164 ui_test_utils::RunAllPendingInMessageLoop();
181 } 165 }
182 166
183 // [CLOSED] -add->[STICKY_AND_NEW] -mouse-> [KEEP_SIZE] -remove/add-> 167 // [CLOSED] -add->[STICKY_AND_NEW] -mouse-> [KEEP_SIZE] -remove/add->
184 // [KEEP_SIZE] -remove-> [CLOSED] -add-> [STICKY_AND_NEW] -remove-> [CLOSED] 168 // [KEEP_SIZE] -remove-> [CLOSED] -add-> [STICKY_AND_NEW] -remove-> [CLOSED]
185 IN_PROC_BROWSER_TEST_F(NotificationTest, TestKeepSizeState) { 169 IN_PROC_BROWSER_TEST_F(NotificationTest, TestKeepSizeState) {
186 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); 170 BalloonCollectionImpl* collection = GetBalloonCollectionImpl();
187 NotificationPanel* panel = GetNotificationPanel(); 171 NotificationPanel* panel = GetNotificationPanel();
188 NotificationPanelTester* tester = panel->GetTester(); 172 NotificationPanelTester* tester = panel->GetTester();
189 173
190 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); 174 EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
191 175
192 // Using system notification as regular notification. 176 // Using system notification as regular notification.
193 collection->Add(NewMockNotification("1"), browser()->profile()); 177 collection->Add(NewMockNotification("1"), browser()->profile());
194 collection->Add(NewMockNotification("2"), browser()->profile()); 178 collection->Add(NewMockNotification("2"), browser()->profile());
195 179
196 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 180 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
197 181
198 panel->OnMouseMotion(gfx::Point(10, 10)); 182 panel->OnMouseMotion(gfx::Point(10, 10));
199 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state()); 183 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state());
200 184
201 collection->Remove(NewMockNotification("1")); 185 collection->RemoveById("1");
202 ui_test_utils::RunAllPendingInMessageLoop(); 186 ui_test_utils::RunAllPendingInMessageLoop();
203 EXPECT_EQ(1, tester->GetNewNotificationCount()); 187 EXPECT_EQ(1, tester->GetNewNotificationCount());
204 EXPECT_EQ(1, tester->GetNotificationCount()); 188 EXPECT_EQ(1, tester->GetNotificationCount());
205 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state()); 189 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state());
206 190
207 collection->Add(NewMockNotification("1"), browser()->profile()); 191 collection->Add(NewMockNotification("1"), browser()->profile());
208 ui_test_utils::RunAllPendingInMessageLoop(); 192 ui_test_utils::RunAllPendingInMessageLoop();
209 EXPECT_EQ(2, tester->GetNewNotificationCount()); 193 EXPECT_EQ(2, tester->GetNewNotificationCount());
210 EXPECT_EQ(2, tester->GetNotificationCount()); 194 EXPECT_EQ(2, tester->GetNotificationCount());
211 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state()); 195 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state());
212 196
213 collection->Remove(NewMockNotification("1")); 197 collection->RemoveById("1");
214 ui_test_utils::RunAllPendingInMessageLoop(); 198 ui_test_utils::RunAllPendingInMessageLoop();
215 EXPECT_EQ(1, tester->GetNewNotificationCount()); 199 EXPECT_EQ(1, tester->GetNewNotificationCount());
216 EXPECT_EQ(1, tester->GetNotificationCount()); 200 EXPECT_EQ(1, tester->GetNotificationCount());
217 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state()); 201 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state());
218 202
219 collection->Remove(NewMockNotification("2")); 203 collection->RemoveById("2");
220 ui_test_utils::RunAllPendingInMessageLoop(); 204 ui_test_utils::RunAllPendingInMessageLoop();
221 EXPECT_EQ(0, tester->GetNotificationCount()); 205 EXPECT_EQ(0, tester->GetNotificationCount());
222 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); 206 EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
223 207
224 collection->Add(NewMockNotification("3"), browser()->profile()); 208 collection->Add(NewMockNotification("3"), browser()->profile());
225 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 209 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
226 collection->Remove(NewMockNotification("3")); 210 collection->RemoveById("3");
227 211
228 ui_test_utils::RunAllPendingInMessageLoop(); 212 ui_test_utils::RunAllPendingInMessageLoop();
229 EXPECT_EQ(0, tester->GetNotificationCount()); 213 EXPECT_EQ(0, tester->GetNotificationCount());
230 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); 214 EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
231 } 215 }
232 216
233 IN_PROC_BROWSER_TEST_F(NotificationTest, TestSystemNotification) { 217 IN_PROC_BROWSER_TEST_F(NotificationTest, TestSystemNotification) {
234 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); 218 BalloonCollectionImpl* collection = GetBalloonCollectionImpl();
235 NotificationPanel* panel = GetNotificationPanel(); 219 NotificationPanel* panel = GetNotificationPanel();
236 scoped_refptr<MockNotificationDelegate> delegate( 220 scoped_refptr<MockNotificationDelegate> delegate(
(...skipping 13 matching lines...) Expand all
250 EXPECT_EQ(1, tester->GetStickyNotificationCount()); 234 EXPECT_EQ(1, tester->GetStickyNotificationCount());
251 235
252 Notification update_and_show = SystemNotificationFactory::Create( 236 Notification update_and_show = SystemNotificationFactory::Create(
253 GURL(), ASCIIToUTF16("Title"), ASCIIToUTF16("updated and shown"), 237 GURL(), ASCIIToUTF16("Title"), ASCIIToUTF16("updated and shown"),
254 delegate.get()); 238 delegate.get());
255 collection->UpdateAndShowNotification(update_and_show); 239 collection->UpdateAndShowNotification(update_and_show);
256 240
257 EXPECT_EQ(1, tester->GetStickyNotificationCount()); 241 EXPECT_EQ(1, tester->GetStickyNotificationCount());
258 242
259 // Dismiss the notification. 243 // Dismiss the notification.
260 // TODO(oshima): Consider updating API to Remove(NotificationDelegate) 244 collection->RemoveById(delegate->id());
261 // or Remove(std::string id);
262 collection->Remove(Notification(GURL(), GURL(), string16(), string16(),
263 delegate.get()));
264 ui_test_utils::RunAllPendingInMessageLoop(); 245 ui_test_utils::RunAllPendingInMessageLoop();
265 246
266 EXPECT_EQ(0, tester->GetStickyNotificationCount()); 247 EXPECT_EQ(0, tester->GetStickyNotificationCount());
267 EXPECT_EQ(0, tester->GetNewNotificationCount()); 248 EXPECT_EQ(0, tester->GetNewNotificationCount());
268 // TODO(oshima): check content, etc.. 249 // TODO(oshima): check content, etc..
269 } 250 }
270 251
271 // [CLOSED] -add,add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -remove-> 252 // [CLOSED] -add,add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -remove->
272 // [MINIMIZED] -remove-> [CLOSED] 253 // [MINIMIZED] -remove-> [CLOSED]
273 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition1) { 254 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition1) {
274 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); 255 BalloonCollectionImpl* collection = GetBalloonCollectionImpl();
275 NotificationPanel* panel = GetNotificationPanel(); 256 NotificationPanel* panel = GetNotificationPanel();
276 NotificationPanelTester* tester = panel->GetTester(); 257 NotificationPanelTester* tester = panel->GetTester();
277 258
278 tester->SetStaleTimeout(0); 259 tester->SetStaleTimeout(0);
279 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); 260 EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
280 261
281 collection->Add(NewMockNotification("1"), browser()->profile()); 262 collection->Add(NewMockNotification("1"), browser()->profile());
282 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 263 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
283 264
284 collection->Add(NewMockNotification("2"), browser()->profile()); 265 collection->Add(NewMockNotification("2"), browser()->profile());
285 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 266 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
286 267
287 ui_test_utils::RunAllPendingInMessageLoop(); 268 ui_test_utils::RunAllPendingInMessageLoop();
288 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); 269 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state());
289 270
290 collection->Remove(NewMockNotification("2")); 271 collection->RemoveById("2");
291 ui_test_utils::RunAllPendingInMessageLoop(); 272 ui_test_utils::RunAllPendingInMessageLoop();
292 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); 273 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state());
293 274
294 collection->Remove(NewMockNotification("1")); 275 collection->RemoveById("1");
295 ui_test_utils::RunAllPendingInMessageLoop(); 276 ui_test_utils::RunAllPendingInMessageLoop();
296 EXPECT_EQ(0, tester->GetNotificationCount()); 277 EXPECT_EQ(0, tester->GetNotificationCount());
297 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); 278 EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
298 279
299 ui_test_utils::RunAllPendingInMessageLoop(); 280 ui_test_utils::RunAllPendingInMessageLoop();
300 } 281 }
301 282
302 // [CLOSED] -add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -add-> 283 // [CLOSED] -add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -add->
303 // [STICKY_AND_NEW] -stale-> [MINIMIZED] -add sys-> [STICKY_NEW] 284 // [STICKY_AND_NEW] -stale-> [MINIMIZED] -add sys-> [STICKY_NEW]
304 // -stale-> [STICKY_NEW] -remove-> [STICKY_NEW] -remove sys-> 285 // -stale-> [STICKY_NEW] -remove-> [STICKY_NEW] -remove sys->
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 collection->AddSystemNotification( 331 collection->AddSystemNotification(
351 NewMockNotification("3"), browser()->profile(), true, false); 332 NewMockNotification("3"), browser()->profile(), true, false);
352 EXPECT_EQ(3, tester->GetNotificationCount()); 333 EXPECT_EQ(3, tester->GetNotificationCount());
353 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 334 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
354 WaitForPanelState(tester, PanelController::EXPANDED); 335 WaitForPanelState(tester, PanelController::EXPANDED);
355 336
356 // Running all events nor removing non sticky should not change the state. 337 // Running all events nor removing non sticky should not change the state.
357 ui_test_utils::RunAllPendingInMessageLoop(); 338 ui_test_utils::RunAllPendingInMessageLoop();
358 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 339 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
359 340
360 collection->Remove(NewMockNotification("1")); 341 collection->RemoveById("1");
361 ui_test_utils::RunAllPendingInMessageLoop(); 342 ui_test_utils::RunAllPendingInMessageLoop();
362 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); 343 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
363 344
364 // Removing the system notification should minimize the panel. 345 // Removing the system notification should minimize the panel.
365 collection->Remove(NewMockNotification("3")); 346 collection->RemoveById("3");
366 ui_test_utils::RunAllPendingInMessageLoop(); 347 ui_test_utils::RunAllPendingInMessageLoop();
367 EXPECT_EQ(1, tester->GetNotificationCount()); 348 EXPECT_EQ(1, tester->GetNotificationCount());
368 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); 349 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state());
369 WaitForPanelState(tester, PanelController::MINIMIZED); 350 WaitForPanelState(tester, PanelController::MINIMIZED);
370 351
371 // Removing the last notification. Should close the panel. 352 // Removing the last notification. Should close the panel.
372 353 collection->RemoveById("2");
373 collection->Remove(NewMockNotification("2"));
374 ui_test_utils::RunAllPendingInMessageLoop(); 354 ui_test_utils::RunAllPendingInMessageLoop();
375 EXPECT_EQ(0, tester->GetNotificationCount()); 355 EXPECT_EQ(0, tester->GetNotificationCount());
376 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); 356 EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
377 357
378 ui_test_utils::RunAllPendingInMessageLoop(); 358 ui_test_utils::RunAllPendingInMessageLoop();
379 } 359 }
380 360
381 IN_PROC_BROWSER_TEST_F(NotificationTest, TestCleanupOnExit) { 361 IN_PROC_BROWSER_TEST_F(NotificationTest, TestCleanupOnExit) {
382 NotificationRegistrar registrar; 362 NotificationRegistrar registrar;
383 registrar.Add(this, 363 registrar.Add(this,
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 EXPECT_TRUE(collection->AddDOMUIMessageCallback( 588 EXPECT_TRUE(collection->AddDOMUIMessageCallback(
609 NewMockNotification("1"), 589 NewMockNotification("1"),
610 "test", 590 "test",
611 NewCallback( 591 NewCallback(
612 static_cast<NotificationTest*>(this), 592 static_cast<NotificationTest*>(this),
613 &NotificationTest::HandleDOMUIMessage))); 593 &NotificationTest::HandleDOMUIMessage)));
614 MessageLoop::current()->Run(); 594 MessageLoop::current()->Run();
615 } 595 }
616 596
617 } // namespace chromeos 597 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698