OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "ui/message_center/message_center_impl.h" | 5 #include "ui/message_center/message_center_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
18 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
19 #include "ui/message_center/message_center_types.h" | 20 #include "ui/message_center/message_center_types.h" |
20 #include "ui/message_center/notification_blocker.h" | 21 #include "ui/message_center/notification_blocker.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 NotifierId(NotifierId::APPLICATION, notifier_id), | 91 NotifierId(NotifierId::APPLICATION, notifier_id), |
91 optional_fields, NULL); | 92 optional_fields, NULL); |
92 } | 93 } |
93 | 94 |
94 void ForceNotificationFlush(const std::string& id) { | 95 void ForceNotificationFlush(const std::string& id) { |
95 message_center()->ForceNotificationFlush(id); | 96 message_center()->ForceNotificationFlush(id); |
96 } | 97 } |
97 | 98 |
98 private: | 99 private: |
99 MessageCenter* message_center_; | 100 MessageCenter* message_center_; |
100 scoped_ptr<base::MessageLoop> loop_; | 101 std::unique_ptr<base::MessageLoop> loop_; |
101 scoped_ptr<base::RunLoop> run_loop_; | 102 std::unique_ptr<base::RunLoop> run_loop_; |
102 base::Closure closure_; | 103 base::Closure closure_; |
103 | 104 |
104 DISALLOW_COPY_AND_ASSIGN(MessageCenterImplTest); | 105 DISALLOW_COPY_AND_ASSIGN(MessageCenterImplTest); |
105 }; | 106 }; |
106 | 107 |
107 class MessageCenterImplTestWithChangeQueue : public MessageCenterImplTest { | 108 class MessageCenterImplTestWithChangeQueue : public MessageCenterImplTest { |
108 public: | 109 public: |
109 MessageCenterImplTestWithChangeQueue() {} | 110 MessageCenterImplTestWithChangeQueue() {} |
110 ~MessageCenterImplTestWithChangeQueue() override {} | 111 ~MessageCenterImplTestWithChangeQueue() override {} |
111 | 112 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 bool timer_finished() const { return timer_finished_; } | 243 bool timer_finished() const { return timer_finished_; } |
243 const std::string& last_id() const { return last_id_; } | 244 const std::string& last_id() const { return last_id_; } |
244 | 245 |
245 private: | 246 private: |
246 bool timer_finished_; | 247 bool timer_finished_; |
247 std::string last_id_; | 248 std::string last_id_; |
248 base::Closure quit_closure_; | 249 base::Closure quit_closure_; |
249 }; | 250 }; |
250 | 251 |
251 TEST_F(MessageCenterImplTest, PopupTimersEmptyController) { | 252 TEST_F(MessageCenterImplTest, PopupTimersEmptyController) { |
252 scoped_ptr<PopupTimersController> popup_timers_controller = | 253 std::unique_ptr<PopupTimersController> popup_timers_controller = |
253 make_scoped_ptr(new PopupTimersController(message_center())); | 254 base::WrapUnique(new PopupTimersController(message_center())); |
254 | 255 |
255 // Test that all functions succed without any timers created. | 256 // Test that all functions succed without any timers created. |
256 popup_timers_controller->PauseAll(); | 257 popup_timers_controller->PauseAll(); |
257 popup_timers_controller->StartAll(); | 258 popup_timers_controller->StartAll(); |
258 popup_timers_controller->CancelAll(); | 259 popup_timers_controller->CancelAll(); |
259 popup_timers_controller->TimerFinished("unknown"); | 260 popup_timers_controller->TimerFinished("unknown"); |
260 popup_timers_controller->PauseTimer("unknown"); | 261 popup_timers_controller->PauseTimer("unknown"); |
261 popup_timers_controller->CancelTimer("unknown"); | 262 popup_timers_controller->CancelTimer("unknown"); |
262 } | 263 } |
263 | 264 |
264 TEST_F(MessageCenterImplTest, PopupTimersControllerStartTimer) { | 265 TEST_F(MessageCenterImplTest, PopupTimersControllerStartTimer) { |
265 scoped_ptr<MockPopupTimersController> popup_timers_controller = | 266 std::unique_ptr<MockPopupTimersController> popup_timers_controller = |
266 make_scoped_ptr( | 267 base::WrapUnique( |
267 new MockPopupTimersController(message_center(), closure())); | 268 new MockPopupTimersController(message_center(), closure())); |
268 popup_timers_controller->StartTimer("test", | 269 popup_timers_controller->StartTimer("test", |
269 base::TimeDelta::FromMilliseconds(1)); | 270 base::TimeDelta::FromMilliseconds(1)); |
270 run_loop()->Run(); | 271 run_loop()->Run(); |
271 EXPECT_TRUE(popup_timers_controller->timer_finished()); | 272 EXPECT_TRUE(popup_timers_controller->timer_finished()); |
272 } | 273 } |
273 | 274 |
274 TEST_F(MessageCenterImplTest, PopupTimersControllerPauseTimer) { | 275 TEST_F(MessageCenterImplTest, PopupTimersControllerPauseTimer) { |
275 scoped_ptr<MockPopupTimersController> popup_timers_controller = | 276 std::unique_ptr<MockPopupTimersController> popup_timers_controller = |
276 make_scoped_ptr( | 277 base::WrapUnique( |
277 new MockPopupTimersController(message_center(), closure())); | 278 new MockPopupTimersController(message_center(), closure())); |
278 popup_timers_controller->StartTimer("test", | 279 popup_timers_controller->StartTimer("test", |
279 base::TimeDelta::FromMilliseconds(1)); | 280 base::TimeDelta::FromMilliseconds(1)); |
280 popup_timers_controller->PauseTimer("test"); | 281 popup_timers_controller->PauseTimer("test"); |
281 run_loop()->RunUntilIdle(); | 282 run_loop()->RunUntilIdle(); |
282 | 283 |
283 EXPECT_FALSE(popup_timers_controller->timer_finished()); | 284 EXPECT_FALSE(popup_timers_controller->timer_finished()); |
284 } | 285 } |
285 | 286 |
286 TEST_F(MessageCenterImplTest, PopupTimersControllerCancelTimer) { | 287 TEST_F(MessageCenterImplTest, PopupTimersControllerCancelTimer) { |
287 scoped_ptr<MockPopupTimersController> popup_timers_controller = | 288 std::unique_ptr<MockPopupTimersController> popup_timers_controller = |
288 make_scoped_ptr( | 289 base::WrapUnique( |
289 new MockPopupTimersController(message_center(), closure())); | 290 new MockPopupTimersController(message_center(), closure())); |
290 popup_timers_controller->StartTimer("test", | 291 popup_timers_controller->StartTimer("test", |
291 base::TimeDelta::FromMilliseconds(1)); | 292 base::TimeDelta::FromMilliseconds(1)); |
292 popup_timers_controller->CancelTimer("test"); | 293 popup_timers_controller->CancelTimer("test"); |
293 run_loop()->RunUntilIdle(); | 294 run_loop()->RunUntilIdle(); |
294 | 295 |
295 EXPECT_FALSE(popup_timers_controller->timer_finished()); | 296 EXPECT_FALSE(popup_timers_controller->timer_finished()); |
296 } | 297 } |
297 | 298 |
298 TEST_F(MessageCenterImplTest, PopupTimersControllerPauseAllTimers) { | 299 TEST_F(MessageCenterImplTest, PopupTimersControllerPauseAllTimers) { |
299 scoped_ptr<MockPopupTimersController> popup_timers_controller = | 300 std::unique_ptr<MockPopupTimersController> popup_timers_controller = |
300 make_scoped_ptr( | 301 base::WrapUnique( |
301 new MockPopupTimersController(message_center(), closure())); | 302 new MockPopupTimersController(message_center(), closure())); |
302 popup_timers_controller->StartTimer("test", | 303 popup_timers_controller->StartTimer("test", |
303 base::TimeDelta::FromMilliseconds(1)); | 304 base::TimeDelta::FromMilliseconds(1)); |
304 popup_timers_controller->PauseAll(); | 305 popup_timers_controller->PauseAll(); |
305 run_loop()->RunUntilIdle(); | 306 run_loop()->RunUntilIdle(); |
306 | 307 |
307 EXPECT_FALSE(popup_timers_controller->timer_finished()); | 308 EXPECT_FALSE(popup_timers_controller->timer_finished()); |
308 } | 309 } |
309 | 310 |
310 TEST_F(MessageCenterImplTest, PopupTimersControllerStartAllTimers) { | 311 TEST_F(MessageCenterImplTest, PopupTimersControllerStartAllTimers) { |
311 scoped_ptr<MockPopupTimersController> popup_timers_controller = | 312 std::unique_ptr<MockPopupTimersController> popup_timers_controller = |
312 make_scoped_ptr( | 313 base::WrapUnique( |
313 new MockPopupTimersController(message_center(), closure())); | 314 new MockPopupTimersController(message_center(), closure())); |
314 popup_timers_controller->StartTimer("test", | 315 popup_timers_controller->StartTimer("test", |
315 base::TimeDelta::FromMilliseconds(1)); | 316 base::TimeDelta::FromMilliseconds(1)); |
316 popup_timers_controller->PauseAll(); | 317 popup_timers_controller->PauseAll(); |
317 popup_timers_controller->StartAll(); | 318 popup_timers_controller->StartAll(); |
318 run_loop()->Run(); | 319 run_loop()->Run(); |
319 | 320 |
320 EXPECT_TRUE(popup_timers_controller->timer_finished()); | 321 EXPECT_TRUE(popup_timers_controller->timer_finished()); |
321 } | 322 } |
322 | 323 |
323 TEST_F(MessageCenterImplTest, PopupTimersControllerStartMultipleTimers) { | 324 TEST_F(MessageCenterImplTest, PopupTimersControllerStartMultipleTimers) { |
324 scoped_ptr<MockPopupTimersController> popup_timers_controller = | 325 std::unique_ptr<MockPopupTimersController> popup_timers_controller = |
325 make_scoped_ptr( | 326 base::WrapUnique( |
326 new MockPopupTimersController(message_center(), closure())); | 327 new MockPopupTimersController(message_center(), closure())); |
327 popup_timers_controller->StartTimer("test", | 328 popup_timers_controller->StartTimer("test", |
328 base::TimeDelta::FromMilliseconds(5)); | 329 base::TimeDelta::FromMilliseconds(5)); |
329 popup_timers_controller->StartTimer("test2", | 330 popup_timers_controller->StartTimer("test2", |
330 base::TimeDelta::FromMilliseconds(1)); | 331 base::TimeDelta::FromMilliseconds(1)); |
331 popup_timers_controller->StartTimer("test3", | 332 popup_timers_controller->StartTimer("test3", |
332 base::TimeDelta::FromMilliseconds(3)); | 333 base::TimeDelta::FromMilliseconds(3)); |
333 popup_timers_controller->PauseAll(); | 334 popup_timers_controller->PauseAll(); |
334 popup_timers_controller->StartAll(); | 335 popup_timers_controller->StartAll(); |
335 run_loop()->Run(); | 336 run_loop()->Run(); |
336 | 337 |
337 EXPECT_EQ(popup_timers_controller->last_id(), "test2"); | 338 EXPECT_EQ(popup_timers_controller->last_id(), "test2"); |
338 EXPECT_TRUE(popup_timers_controller->timer_finished()); | 339 EXPECT_TRUE(popup_timers_controller->timer_finished()); |
339 } | 340 } |
340 | 341 |
341 TEST_F(MessageCenterImplTest, PopupTimersControllerStartMultipleTimersPause) { | 342 TEST_F(MessageCenterImplTest, PopupTimersControllerStartMultipleTimersPause) { |
342 scoped_ptr<MockPopupTimersController> popup_timers_controller = | 343 std::unique_ptr<MockPopupTimersController> popup_timers_controller = |
343 make_scoped_ptr( | 344 base::WrapUnique( |
344 new MockPopupTimersController(message_center(), closure())); | 345 new MockPopupTimersController(message_center(), closure())); |
345 popup_timers_controller->StartTimer("test", | 346 popup_timers_controller->StartTimer("test", |
346 base::TimeDelta::FromMilliseconds(5)); | 347 base::TimeDelta::FromMilliseconds(5)); |
347 popup_timers_controller->StartTimer("test2", | 348 popup_timers_controller->StartTimer("test2", |
348 base::TimeDelta::FromMilliseconds(1)); | 349 base::TimeDelta::FromMilliseconds(1)); |
349 popup_timers_controller->StartTimer("test3", | 350 popup_timers_controller->StartTimer("test3", |
350 base::TimeDelta::FromMilliseconds(3)); | 351 base::TimeDelta::FromMilliseconds(3)); |
351 popup_timers_controller->PauseTimer("test2"); | 352 popup_timers_controller->PauseTimer("test2"); |
352 | 353 |
353 run_loop()->Run(); | 354 run_loop()->Run(); |
354 | 355 |
355 EXPECT_EQ(popup_timers_controller->last_id(), "test3"); | 356 EXPECT_EQ(popup_timers_controller->last_id(), "test3"); |
356 EXPECT_TRUE(popup_timers_controller->timer_finished()); | 357 EXPECT_TRUE(popup_timers_controller->timer_finished()); |
357 } | 358 } |
358 | 359 |
359 TEST_F(MessageCenterImplTest, PopupTimersControllerResetTimer) { | 360 TEST_F(MessageCenterImplTest, PopupTimersControllerResetTimer) { |
360 scoped_ptr<MockPopupTimersController> popup_timers_controller = | 361 std::unique_ptr<MockPopupTimersController> popup_timers_controller = |
361 make_scoped_ptr( | 362 base::WrapUnique( |
362 new MockPopupTimersController(message_center(), closure())); | 363 new MockPopupTimersController(message_center(), closure())); |
363 popup_timers_controller->StartTimer("test", | 364 popup_timers_controller->StartTimer("test", |
364 base::TimeDelta::FromMilliseconds(5)); | 365 base::TimeDelta::FromMilliseconds(5)); |
365 popup_timers_controller->StartTimer("test2", | 366 popup_timers_controller->StartTimer("test2", |
366 base::TimeDelta::FromMilliseconds(1)); | 367 base::TimeDelta::FromMilliseconds(1)); |
367 popup_timers_controller->StartTimer("test3", | 368 popup_timers_controller->StartTimer("test3", |
368 base::TimeDelta::FromMilliseconds(3)); | 369 base::TimeDelta::FromMilliseconds(3)); |
369 popup_timers_controller->PauseTimer("test2"); | 370 popup_timers_controller->PauseTimer("test2"); |
370 popup_timers_controller->ResetTimer("test", | 371 popup_timers_controller->ResetTimer("test", |
371 base::TimeDelta::FromMilliseconds(2)); | 372 base::TimeDelta::FromMilliseconds(2)); |
372 | 373 |
373 run_loop()->Run(); | 374 run_loop()->Run(); |
374 | 375 |
375 EXPECT_EQ(popup_timers_controller->last_id(), "test"); | 376 EXPECT_EQ(popup_timers_controller->last_id(), "test"); |
376 EXPECT_TRUE(popup_timers_controller->timer_finished()); | 377 EXPECT_TRUE(popup_timers_controller->timer_finished()); |
377 } | 378 } |
378 | 379 |
379 TEST_F(MessageCenterImplTest, NotificationBlocker) { | 380 TEST_F(MessageCenterImplTest, NotificationBlocker) { |
380 NotifierId notifier_id(NotifierId::APPLICATION, "app1"); | 381 NotifierId notifier_id(NotifierId::APPLICATION, "app1"); |
381 // Multiple blockers to verify the case that one blocker blocks but another | 382 // Multiple blockers to verify the case that one blocker blocks but another |
382 // doesn't. | 383 // doesn't. |
383 ToggledNotificationBlocker blocker1(message_center()); | 384 ToggledNotificationBlocker blocker1(message_center()); |
384 ToggledNotificationBlocker blocker2(message_center()); | 385 ToggledNotificationBlocker blocker2(message_center()); |
385 | 386 |
386 message_center()->AddNotification(scoped_ptr<Notification>( | 387 message_center()->AddNotification(std::unique_ptr<Notification>( |
387 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"), | 388 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"), |
388 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 389 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
389 base::string16() /* display_source */, GURL(), | 390 base::string16() /* display_source */, GURL(), |
390 notifier_id, RichNotificationData(), NULL))); | 391 notifier_id, RichNotificationData(), NULL))); |
391 message_center()->AddNotification(scoped_ptr<Notification>( | 392 message_center()->AddNotification(std::unique_ptr<Notification>( |
392 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"), | 393 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"), |
393 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 394 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
394 base::string16() /* display_source */, GURL(), | 395 base::string16() /* display_source */, GURL(), |
395 notifier_id, RichNotificationData(), NULL))); | 396 notifier_id, RichNotificationData(), NULL))); |
396 EXPECT_EQ(2u, message_center()->GetPopupNotifications().size()); | 397 EXPECT_EQ(2u, message_center()->GetPopupNotifications().size()); |
397 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); | 398 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); |
398 | 399 |
399 // Block all notifications. All popups are gone and message center should be | 400 // Block all notifications. All popups are gone and message center should be |
400 // hidden. | 401 // hidden. |
401 blocker1.SetNotificationsEnabled(false); | 402 blocker1.SetNotificationsEnabled(false); |
(...skipping 20 matching lines...) Expand all Loading... |
422 // aren't shown. | 423 // aren't shown. |
423 blocker2.SetNotificationsEnabled(true); | 424 blocker2.SetNotificationsEnabled(true); |
424 EXPECT_TRUE(message_center()->GetPopupNotifications().empty()); | 425 EXPECT_TRUE(message_center()->GetPopupNotifications().empty()); |
425 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); | 426 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); |
426 } | 427 } |
427 | 428 |
428 TEST_F(MessageCenterImplTest, NotificationsDuringBlocked) { | 429 TEST_F(MessageCenterImplTest, NotificationsDuringBlocked) { |
429 NotifierId notifier_id(NotifierId::APPLICATION, "app1"); | 430 NotifierId notifier_id(NotifierId::APPLICATION, "app1"); |
430 ToggledNotificationBlocker blocker(message_center()); | 431 ToggledNotificationBlocker blocker(message_center()); |
431 | 432 |
432 message_center()->AddNotification(scoped_ptr<Notification>( | 433 message_center()->AddNotification(std::unique_ptr<Notification>( |
433 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"), | 434 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"), |
434 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 435 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
435 base::string16() /* display_source */, GURL(), | 436 base::string16() /* display_source */, GURL(), |
436 notifier_id, RichNotificationData(), NULL))); | 437 notifier_id, RichNotificationData(), NULL))); |
437 EXPECT_EQ(1u, message_center()->GetPopupNotifications().size()); | 438 EXPECT_EQ(1u, message_center()->GetPopupNotifications().size()); |
438 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); | 439 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size()); |
439 | 440 |
440 // Create a notification during blocked. Still no popups. | 441 // Create a notification during blocked. Still no popups. |
441 blocker.SetNotificationsEnabled(false); | 442 blocker.SetNotificationsEnabled(false); |
442 message_center()->AddNotification(scoped_ptr<Notification>( | 443 message_center()->AddNotification(std::unique_ptr<Notification>( |
443 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"), | 444 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"), |
444 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 445 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
445 base::string16() /* display_source */, GURL(), | 446 base::string16() /* display_source */, GURL(), |
446 notifier_id, RichNotificationData(), NULL))); | 447 notifier_id, RichNotificationData(), NULL))); |
447 EXPECT_TRUE(message_center()->GetPopupNotifications().empty()); | 448 EXPECT_TRUE(message_center()->GetPopupNotifications().empty()); |
448 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); | 449 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); |
449 | 450 |
450 // Unblock notifications, the id1 should appear as a popup. | 451 // Unblock notifications, the id1 should appear as a popup. |
451 blocker.SetNotificationsEnabled(true); | 452 blocker.SetNotificationsEnabled(true); |
452 NotificationList::PopupNotifications popups = | 453 NotificationList::PopupNotifications popups = |
453 message_center()->GetPopupNotifications(); | 454 message_center()->GetPopupNotifications(); |
454 EXPECT_EQ(1u, popups.size()); | 455 EXPECT_EQ(1u, popups.size()); |
455 EXPECT_TRUE(PopupNotificationsContain(popups, "id2")); | 456 EXPECT_TRUE(PopupNotificationsContain(popups, "id2")); |
456 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); | 457 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); |
457 } | 458 } |
458 | 459 |
459 // Similar to other blocker cases but this test case allows |notifier_id2| even | 460 // Similar to other blocker cases but this test case allows |notifier_id2| even |
460 // in blocked. | 461 // in blocked. |
461 TEST_F(MessageCenterImplTest, NotificationBlockerAllowsPopups) { | 462 TEST_F(MessageCenterImplTest, NotificationBlockerAllowsPopups) { |
462 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 463 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
463 NotifierId notifier_id2(NotifierId::APPLICATION, "app2"); | 464 NotifierId notifier_id2(NotifierId::APPLICATION, "app2"); |
464 PopupNotificationBlocker blocker(message_center(), notifier_id2); | 465 PopupNotificationBlocker blocker(message_center(), notifier_id2); |
465 | 466 |
466 message_center()->AddNotification(scoped_ptr<Notification>( | 467 message_center()->AddNotification(std::unique_ptr<Notification>( |
467 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"), | 468 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"), |
468 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 469 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
469 base::string16() /* display_source */, GURL(), | 470 base::string16() /* display_source */, GURL(), |
470 notifier_id1, RichNotificationData(), NULL))); | 471 notifier_id1, RichNotificationData(), NULL))); |
471 message_center()->AddNotification(scoped_ptr<Notification>( | 472 message_center()->AddNotification(std::unique_ptr<Notification>( |
472 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"), | 473 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"), |
473 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 474 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
474 base::string16() /* display_source */, GURL(), | 475 base::string16() /* display_source */, GURL(), |
475 notifier_id2, RichNotificationData(), NULL))); | 476 notifier_id2, RichNotificationData(), NULL))); |
476 | 477 |
477 // "id1" is closed but "id2" is still visible as a popup. | 478 // "id1" is closed but "id2" is still visible as a popup. |
478 blocker.SetNotificationsEnabled(false); | 479 blocker.SetNotificationsEnabled(false); |
479 NotificationList::PopupNotifications popups = | 480 NotificationList::PopupNotifications popups = |
480 message_center()->GetPopupNotifications(); | 481 message_center()->GetPopupNotifications(); |
481 EXPECT_EQ(1u, popups.size()); | 482 EXPECT_EQ(1u, popups.size()); |
482 EXPECT_TRUE(PopupNotificationsContain(popups, "id2")); | 483 EXPECT_TRUE(PopupNotificationsContain(popups, "id2")); |
483 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); | 484 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size()); |
484 | 485 |
485 message_center()->AddNotification(scoped_ptr<Notification>( | 486 message_center()->AddNotification(std::unique_ptr<Notification>( |
486 new Notification(NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title"), | 487 new Notification(NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title"), |
487 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 488 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
488 base::string16() /* display_source */, GURL(), | 489 base::string16() /* display_source */, GURL(), |
489 notifier_id1, RichNotificationData(), NULL))); | 490 notifier_id1, RichNotificationData(), NULL))); |
490 message_center()->AddNotification(scoped_ptr<Notification>( | 491 message_center()->AddNotification(std::unique_ptr<Notification>( |
491 new Notification(NOTIFICATION_TYPE_SIMPLE, "id4", UTF8ToUTF16("title"), | 492 new Notification(NOTIFICATION_TYPE_SIMPLE, "id4", UTF8ToUTF16("title"), |
492 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 493 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
493 base::string16() /* display_source */, GURL(), | 494 base::string16() /* display_source */, GURL(), |
494 notifier_id2, RichNotificationData(), NULL))); | 495 notifier_id2, RichNotificationData(), NULL))); |
495 popups = message_center()->GetPopupNotifications(); | 496 popups = message_center()->GetPopupNotifications(); |
496 EXPECT_EQ(2u, popups.size()); | 497 EXPECT_EQ(2u, popups.size()); |
497 EXPECT_TRUE(PopupNotificationsContain(popups, "id2")); | 498 EXPECT_TRUE(PopupNotificationsContain(popups, "id2")); |
498 EXPECT_TRUE(PopupNotificationsContain(popups, "id4")); | 499 EXPECT_TRUE(PopupNotificationsContain(popups, "id4")); |
499 EXPECT_EQ(4u, message_center()->GetVisibleNotifications().size()); | 500 EXPECT_EQ(4u, message_center()->GetVisibleNotifications().size()); |
500 | 501 |
501 blocker.SetNotificationsEnabled(true); | 502 blocker.SetNotificationsEnabled(true); |
502 popups = message_center()->GetPopupNotifications(); | 503 popups = message_center()->GetPopupNotifications(); |
503 EXPECT_EQ(3u, popups.size()); | 504 EXPECT_EQ(3u, popups.size()); |
504 EXPECT_TRUE(PopupNotificationsContain(popups, "id2")); | 505 EXPECT_TRUE(PopupNotificationsContain(popups, "id2")); |
505 EXPECT_TRUE(PopupNotificationsContain(popups, "id3")); | 506 EXPECT_TRUE(PopupNotificationsContain(popups, "id3")); |
506 EXPECT_TRUE(PopupNotificationsContain(popups, "id4")); | 507 EXPECT_TRUE(PopupNotificationsContain(popups, "id4")); |
507 EXPECT_EQ(4u, message_center()->GetVisibleNotifications().size()); | 508 EXPECT_EQ(4u, message_center()->GetVisibleNotifications().size()); |
508 } | 509 } |
509 | 510 |
510 // TotalNotificationBlocker suppresses showing notifications even from the list. | 511 // TotalNotificationBlocker suppresses showing notifications even from the list. |
511 // This would provide the feature to 'separated' message centers per-profile for | 512 // This would provide the feature to 'separated' message centers per-profile for |
512 // ChromeOS multi-login. | 513 // ChromeOS multi-login. |
513 TEST_F(MessageCenterImplTest, TotalNotificationBlocker) { | 514 TEST_F(MessageCenterImplTest, TotalNotificationBlocker) { |
514 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 515 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
515 NotifierId notifier_id2(NotifierId::APPLICATION, "app2"); | 516 NotifierId notifier_id2(NotifierId::APPLICATION, "app2"); |
516 TotalNotificationBlocker blocker(message_center(), notifier_id2); | 517 TotalNotificationBlocker blocker(message_center(), notifier_id2); |
517 | 518 |
518 message_center()->AddNotification(scoped_ptr<Notification>( | 519 message_center()->AddNotification(std::unique_ptr<Notification>( |
519 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"), | 520 new Notification(NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title"), |
520 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 521 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
521 base::string16() /* display_source */, GURL(), | 522 base::string16() /* display_source */, GURL(), |
522 notifier_id1, RichNotificationData(), NULL))); | 523 notifier_id1, RichNotificationData(), NULL))); |
523 message_center()->AddNotification(scoped_ptr<Notification>( | 524 message_center()->AddNotification(std::unique_ptr<Notification>( |
524 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"), | 525 new Notification(NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title"), |
525 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 526 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
526 base::string16() /* display_source */, GURL(), | 527 base::string16() /* display_source */, GURL(), |
527 notifier_id2, RichNotificationData(), NULL))); | 528 notifier_id2, RichNotificationData(), NULL))); |
528 | 529 |
529 // "id1" becomes invisible while "id2" is still visible. | 530 // "id1" becomes invisible while "id2" is still visible. |
530 blocker.SetNotificationsEnabled(false); | 531 blocker.SetNotificationsEnabled(false); |
531 EXPECT_EQ(1u, message_center()->NotificationCount()); | 532 EXPECT_EQ(1u, message_center()->NotificationCount()); |
532 NotificationList::Notifications notifications = | 533 NotificationList::Notifications notifications = |
533 message_center()->GetVisibleNotifications(); | 534 message_center()->GetVisibleNotifications(); |
534 EXPECT_FALSE(NotificationsContain(notifications, "id1")); | 535 EXPECT_FALSE(NotificationsContain(notifications, "id1")); |
535 EXPECT_TRUE(NotificationsContain(notifications, "id2")); | 536 EXPECT_TRUE(NotificationsContain(notifications, "id2")); |
536 | 537 |
537 message_center()->AddNotification(scoped_ptr<Notification>( | 538 message_center()->AddNotification(std::unique_ptr<Notification>( |
538 new Notification(NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title"), | 539 new Notification(NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title"), |
539 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 540 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
540 base::string16() /* display_source */, GURL(), | 541 base::string16() /* display_source */, GURL(), |
541 notifier_id1, RichNotificationData(), NULL))); | 542 notifier_id1, RichNotificationData(), NULL))); |
542 message_center()->AddNotification(scoped_ptr<Notification>( | 543 message_center()->AddNotification(std::unique_ptr<Notification>( |
543 new Notification(NOTIFICATION_TYPE_SIMPLE, "id4", UTF8ToUTF16("title"), | 544 new Notification(NOTIFICATION_TYPE_SIMPLE, "id4", UTF8ToUTF16("title"), |
544 UTF8ToUTF16("message"), gfx::Image() /* icon */, | 545 UTF8ToUTF16("message"), gfx::Image() /* icon */, |
545 base::string16() /* display_source */, GURL(), | 546 base::string16() /* display_source */, GURL(), |
546 notifier_id2, RichNotificationData(), NULL))); | 547 notifier_id2, RichNotificationData(), NULL))); |
547 EXPECT_EQ(2u, message_center()->NotificationCount()); | 548 EXPECT_EQ(2u, message_center()->NotificationCount()); |
548 notifications = message_center()->GetVisibleNotifications(); | 549 notifications = message_center()->GetVisibleNotifications(); |
549 EXPECT_FALSE(NotificationsContain(notifications, "id1")); | 550 EXPECT_FALSE(NotificationsContain(notifications, "id1")); |
550 EXPECT_TRUE(NotificationsContain(notifications, "id2")); | 551 EXPECT_TRUE(NotificationsContain(notifications, "id2")); |
551 EXPECT_FALSE(NotificationsContain(notifications, "id3")); | 552 EXPECT_FALSE(NotificationsContain(notifications, "id3")); |
552 EXPECT_TRUE(NotificationsContain(notifications, "id4")); | 553 EXPECT_TRUE(NotificationsContain(notifications, "id4")); |
(...skipping 22 matching lines...) Expand all Loading... |
575 // And remove all including invisible notifications. | 576 // And remove all including invisible notifications. |
576 blocker.SetNotificationsEnabled(false); | 577 blocker.SetNotificationsEnabled(false); |
577 message_center()->RemoveAllNotifications(false /* by_user */, | 578 message_center()->RemoveAllNotifications(false /* by_user */, |
578 MessageCenter::RemoveType::ALL); | 579 MessageCenter::RemoveType::ALL); |
579 EXPECT_EQ(0u, message_center()->NotificationCount()); | 580 EXPECT_EQ(0u, message_center()->NotificationCount()); |
580 } | 581 } |
581 | 582 |
582 #if defined(OS_CHROMEOS) | 583 #if defined(OS_CHROMEOS) |
583 TEST_F(MessageCenterImplTest, CachedUnreadCount) { | 584 TEST_F(MessageCenterImplTest, CachedUnreadCount) { |
584 message_center()->AddNotification( | 585 message_center()->AddNotification( |
585 scoped_ptr<Notification>(CreateSimpleNotification("id1"))); | 586 std::unique_ptr<Notification>(CreateSimpleNotification("id1"))); |
586 message_center()->AddNotification( | 587 message_center()->AddNotification( |
587 scoped_ptr<Notification>(CreateSimpleNotification("id2"))); | 588 std::unique_ptr<Notification>(CreateSimpleNotification("id2"))); |
588 message_center()->AddNotification( | 589 message_center()->AddNotification( |
589 scoped_ptr<Notification>(CreateSimpleNotification("id3"))); | 590 std::unique_ptr<Notification>(CreateSimpleNotification("id3"))); |
590 ASSERT_EQ(3u, message_center()->UnreadNotificationCount()); | 591 ASSERT_EQ(3u, message_center()->UnreadNotificationCount()); |
591 | 592 |
592 // Mark 'displayed' on all notifications by using for-loop. This shouldn't | 593 // Mark 'displayed' on all notifications by using for-loop. This shouldn't |
593 // recreate |notifications| inside of the loop. | 594 // recreate |notifications| inside of the loop. |
594 const NotificationList::Notifications& notifications = | 595 const NotificationList::Notifications& notifications = |
595 message_center()->GetVisibleNotifications(); | 596 message_center()->GetVisibleNotifications(); |
596 for (NotificationList::Notifications::const_iterator iter = | 597 for (NotificationList::Notifications::const_iterator iter = |
597 notifications.begin(); iter != notifications.end(); ++iter) { | 598 notifications.begin(); iter != notifications.end(); ++iter) { |
598 message_center()->DisplayedNotification( | 599 message_center()->DisplayedNotification( |
599 (*iter)->id(), message_center::DISPLAY_SOURCE_MESSAGE_CENTER); | 600 (*iter)->id(), message_center::DISPLAY_SOURCE_MESSAGE_CENTER); |
(...skipping 15 matching lines...) Expand all Loading... |
615 #endif // OS_CHROMEOS | 616 #endif // OS_CHROMEOS |
616 | 617 |
617 TEST_F(MessageCenterImplTest, ForceNotificationFlush_InconsistentUpdate) { | 618 TEST_F(MessageCenterImplTest, ForceNotificationFlush_InconsistentUpdate) { |
618 std::string id1("id1"); | 619 std::string id1("id1"); |
619 std::string id2("id2"); | 620 std::string id2("id2"); |
620 std::string id3("id3"); | 621 std::string id3("id3"); |
621 | 622 |
622 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 623 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
623 | 624 |
624 // Add -> Update (with ID change) | 625 // Add -> Update (with ID change) |
625 scoped_ptr<Notification> notification(CreateSimpleNotification(id1)); | 626 std::unique_ptr<Notification> notification(CreateSimpleNotification(id1)); |
626 message_center()->AddNotification(std::move(notification)); | 627 message_center()->AddNotification(std::move(notification)); |
627 notification.reset(CreateSimpleNotification(id2)); | 628 notification.reset(CreateSimpleNotification(id2)); |
628 message_center()->UpdateNotification(id1, std::move(notification)); | 629 message_center()->UpdateNotification(id1, std::move(notification)); |
629 | 630 |
630 // Add (although the same ID exists) -> Update (with ID change) -> Remove | 631 // Add (although the same ID exists) -> Update (with ID change) -> Remove |
631 notification.reset(CreateSimpleNotification(id2)); | 632 notification.reset(CreateSimpleNotification(id2)); |
632 message_center()->AddNotification(std::move(notification)); | 633 message_center()->AddNotification(std::move(notification)); |
633 notification.reset(CreateSimpleNotification(id3)); | 634 notification.reset(CreateSimpleNotification(id3)); |
634 message_center()->UpdateNotification(id2, std::move(notification)); | 635 message_center()->UpdateNotification(id2, std::move(notification)); |
635 message_center()->RemoveNotification(id3, false); | 636 message_center()->RemoveNotification(id3, false); |
636 | 637 |
637 // Remove (although the ID has already removed) | 638 // Remove (although the ID has already removed) |
638 message_center()->RemoveNotification(id3, false); | 639 message_center()->RemoveNotification(id3, false); |
639 | 640 |
640 // Notification is not added since the message center has opened. | 641 // Notification is not added since the message center has opened. |
641 ASSERT_EQ(0u, message_center()->NotificationCount()); | 642 ASSERT_EQ(0u, message_center()->NotificationCount()); |
642 | 643 |
643 // Forced to update. | 644 // Forced to update. |
644 ForceNotificationFlush(id3); | 645 ForceNotificationFlush(id3); |
645 | 646 |
646 // Confirms the chagnes are applied. | 647 // Confirms the chagnes are applied. |
647 ASSERT_EQ(0u, message_center()->NotificationCount()); | 648 ASSERT_EQ(0u, message_center()->NotificationCount()); |
648 } | 649 } |
649 | 650 |
650 TEST_F(MessageCenterImplTest, DisableNotificationsByNotifier) { | 651 TEST_F(MessageCenterImplTest, DisableNotificationsByNotifier) { |
651 ASSERT_EQ(0u, message_center()->NotificationCount()); | 652 ASSERT_EQ(0u, message_center()->NotificationCount()); |
652 message_center()->AddNotification( | 653 message_center()->AddNotification(std::unique_ptr<Notification>( |
653 scoped_ptr<Notification>( | 654 CreateSimpleNotificationWithNotifierId("id1-1", "app1"))); |
654 CreateSimpleNotificationWithNotifierId("id1-1", "app1"))); | 655 message_center()->AddNotification(std::unique_ptr<Notification>( |
655 message_center()->AddNotification( | 656 CreateSimpleNotificationWithNotifierId("id1-2", "app1"))); |
656 scoped_ptr<Notification>( | 657 message_center()->AddNotification(std::unique_ptr<Notification>( |
657 CreateSimpleNotificationWithNotifierId("id1-2", "app1"))); | 658 CreateSimpleNotificationWithNotifierId("id2-1", "app2"))); |
658 message_center()->AddNotification( | 659 message_center()->AddNotification(std::unique_ptr<Notification>( |
659 scoped_ptr<Notification>( | 660 CreateSimpleNotificationWithNotifierId("id2-2", "app2"))); |
660 CreateSimpleNotificationWithNotifierId("id2-1", "app2"))); | 661 message_center()->AddNotification(std::unique_ptr<Notification>( |
661 message_center()->AddNotification( | 662 CreateSimpleNotificationWithNotifierId("id2-3", "app2"))); |
662 scoped_ptr<Notification>( | |
663 CreateSimpleNotificationWithNotifierId("id2-2", "app2"))); | |
664 message_center()->AddNotification( | |
665 scoped_ptr<Notification>( | |
666 CreateSimpleNotificationWithNotifierId("id2-3", "app2"))); | |
667 ASSERT_EQ(5u, message_center()->NotificationCount()); | 663 ASSERT_EQ(5u, message_center()->NotificationCount()); |
668 | 664 |
669 // Removing all of app1's notifications should only leave app2's. | 665 // Removing all of app1's notifications should only leave app2's. |
670 message_center()->DisableNotificationsByNotifier( | 666 message_center()->DisableNotificationsByNotifier( |
671 NotifierId(NotifierId::APPLICATION, "app1")); | 667 NotifierId(NotifierId::APPLICATION, "app1")); |
672 ASSERT_EQ(3u, message_center()->NotificationCount()); | 668 ASSERT_EQ(3u, message_center()->NotificationCount()); |
673 | 669 |
674 // Now we remove the remaining notifications. | 670 // Now we remove the remaining notifications. |
675 message_center()->DisableNotificationsByNotifier( | 671 message_center()->DisableNotificationsByNotifier( |
676 NotifierId(NotifierId::APPLICATION, "app2")); | 672 NotifierId(NotifierId::APPLICATION, "app2")); |
677 ASSERT_EQ(0u, message_center()->NotificationCount()); | 673 ASSERT_EQ(0u, message_center()->NotificationCount()); |
678 } | 674 } |
679 | 675 |
680 TEST_F(MessageCenterImplTest, NotifierEnabledChanged) { | 676 TEST_F(MessageCenterImplTest, NotifierEnabledChanged) { |
681 ASSERT_EQ(0u, message_center()->NotificationCount()); | 677 ASSERT_EQ(0u, message_center()->NotificationCount()); |
682 message_center()->AddNotification( | 678 message_center()->AddNotification(std::unique_ptr<Notification>( |
683 scoped_ptr<Notification>( | 679 CreateSimpleNotificationWithNotifierId("id1-1", "app1"))); |
684 CreateSimpleNotificationWithNotifierId("id1-1", "app1"))); | 680 message_center()->AddNotification(std::unique_ptr<Notification>( |
685 message_center()->AddNotification( | 681 CreateSimpleNotificationWithNotifierId("id1-2", "app1"))); |
686 scoped_ptr<Notification>( | 682 message_center()->AddNotification(std::unique_ptr<Notification>( |
687 CreateSimpleNotificationWithNotifierId("id1-2", "app1"))); | 683 CreateSimpleNotificationWithNotifierId("id1-3", "app1"))); |
688 message_center()->AddNotification( | 684 message_center()->AddNotification(std::unique_ptr<Notification>( |
689 scoped_ptr<Notification>( | 685 CreateSimpleNotificationWithNotifierId("id2-1", "app2"))); |
690 CreateSimpleNotificationWithNotifierId("id1-3", "app1"))); | 686 message_center()->AddNotification(std::unique_ptr<Notification>( |
691 message_center()->AddNotification( | 687 CreateSimpleNotificationWithNotifierId("id2-2", "app2"))); |
692 scoped_ptr<Notification>( | 688 message_center()->AddNotification(std::unique_ptr<Notification>( |
693 CreateSimpleNotificationWithNotifierId("id2-1", "app2"))); | 689 CreateSimpleNotificationWithNotifierId("id2-3", "app2"))); |
694 message_center()->AddNotification( | 690 message_center()->AddNotification(std::unique_ptr<Notification>( |
695 scoped_ptr<Notification>( | 691 CreateSimpleNotificationWithNotifierId("id2-4", "app2"))); |
696 CreateSimpleNotificationWithNotifierId("id2-2", "app2"))); | 692 message_center()->AddNotification(std::unique_ptr<Notification>( |
697 message_center()->AddNotification( | 693 CreateSimpleNotificationWithNotifierId("id2-5", "app2"))); |
698 scoped_ptr<Notification>( | |
699 CreateSimpleNotificationWithNotifierId("id2-3", "app2"))); | |
700 message_center()->AddNotification( | |
701 scoped_ptr<Notification>( | |
702 CreateSimpleNotificationWithNotifierId("id2-4", "app2"))); | |
703 message_center()->AddNotification( | |
704 scoped_ptr<Notification>( | |
705 CreateSimpleNotificationWithNotifierId("id2-5", "app2"))); | |
706 ASSERT_EQ(8u, message_center()->NotificationCount()); | 694 ASSERT_EQ(8u, message_center()->NotificationCount()); |
707 | 695 |
708 // Enabling an extension should have no effect on the count. | 696 // Enabling an extension should have no effect on the count. |
709 notifier_settings_observer()->NotifierEnabledChanged( | 697 notifier_settings_observer()->NotifierEnabledChanged( |
710 NotifierId(NotifierId::APPLICATION, "app1"), true); | 698 NotifierId(NotifierId::APPLICATION, "app1"), true); |
711 ASSERT_EQ(8u, message_center()->NotificationCount()); | 699 ASSERT_EQ(8u, message_center()->NotificationCount()); |
712 | 700 |
713 // Removing all of app2's notifications should only leave app1's. | 701 // Removing all of app2's notifications should only leave app1's. |
714 notifier_settings_observer()->NotifierEnabledChanged( | 702 notifier_settings_observer()->NotifierEnabledChanged( |
715 NotifierId(NotifierId::APPLICATION, "app2"), false); | 703 NotifierId(NotifierId::APPLICATION, "app2"), false); |
(...skipping 10 matching lines...) Expand all Loading... |
726 ASSERT_EQ(0u, message_center()->NotificationCount()); | 714 ASSERT_EQ(0u, message_center()->NotificationCount()); |
727 } | 715 } |
728 | 716 |
729 TEST_F(MessageCenterImplTestWithChangeQueue, QueueUpdatesWithCenterVisible) { | 717 TEST_F(MessageCenterImplTestWithChangeQueue, QueueUpdatesWithCenterVisible) { |
730 std::string id("id1"); | 718 std::string id("id1"); |
731 std::string id2("id2"); | 719 std::string id2("id2"); |
732 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 720 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
733 | 721 |
734 // First, add and update a notification to ensure updates happen | 722 // First, add and update a notification to ensure updates happen |
735 // normally. | 723 // normally. |
736 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 724 std::unique_ptr<Notification> notification(CreateSimpleNotification(id)); |
737 message_center()->AddNotification(std::move(notification)); | 725 message_center()->AddNotification(std::move(notification)); |
738 notification.reset(CreateSimpleNotification(id2)); | 726 notification.reset(CreateSimpleNotification(id2)); |
739 message_center()->UpdateNotification(id, std::move(notification)); | 727 message_center()->UpdateNotification(id, std::move(notification)); |
740 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); | 728 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); |
741 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 729 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
742 | 730 |
743 // Then open the message center. | 731 // Then open the message center. |
744 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 732 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
745 | 733 |
746 // Then update a notification; nothing should have happened. | 734 // Then update a notification; nothing should have happened. |
747 notification.reset(CreateSimpleNotification(id)); | 735 notification.reset(CreateSimpleNotification(id)); |
748 message_center()->UpdateNotification(id2, std::move(notification)); | 736 message_center()->UpdateNotification(id2, std::move(notification)); |
749 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); | 737 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); |
750 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 738 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
751 | 739 |
752 // Close the message center; then the update should have propagated. | 740 // Close the message center; then the update should have propagated. |
753 message_center()->SetVisibility(VISIBILITY_TRANSIENT); | 741 message_center()->SetVisibility(VISIBILITY_TRANSIENT); |
754 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); | 742 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); |
755 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 743 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
756 } | 744 } |
757 | 745 |
758 TEST_F(MessageCenterImplTestWithChangeQueue, ComplexQueueing) { | 746 TEST_F(MessageCenterImplTestWithChangeQueue, ComplexQueueing) { |
759 std::string ids[6] = {"0", "1", "2", "3", "4p", "5"}; | 747 std::string ids[6] = {"0", "1", "2", "3", "4p", "5"}; |
760 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 748 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
761 | 749 |
762 scoped_ptr<Notification> notification; | 750 std::unique_ptr<Notification> notification; |
763 // Add some notifications | 751 // Add some notifications |
764 int i = 0; | 752 int i = 0; |
765 for (; i < 3; i++) { | 753 for (; i < 3; i++) { |
766 notification.reset(CreateSimpleNotification(ids[i])); | 754 notification.reset(CreateSimpleNotification(ids[i])); |
767 message_center()->AddNotification(std::move(notification)); | 755 message_center()->AddNotification(std::move(notification)); |
768 } | 756 } |
769 for (i = 0; i < 3; i++) { | 757 for (i = 0; i < 3; i++) { |
770 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i])); | 758 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i])); |
771 } | 759 } |
772 for (; i < 6; i++) { | 760 for (; i < 6; i++) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[4])); | 807 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[4])); |
820 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[5])); | 808 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[5])); |
821 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 5u); | 809 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 5u); |
822 } | 810 } |
823 | 811 |
824 TEST_F(MessageCenterImplTestWithChangeQueue, UpdateWhileQueueing) { | 812 TEST_F(MessageCenterImplTestWithChangeQueue, UpdateWhileQueueing) { |
825 std::string ids[11] = | 813 std::string ids[11] = |
826 {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10p"}; | 814 {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10p"}; |
827 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 815 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
828 | 816 |
829 scoped_ptr<Notification> notification; | 817 std::unique_ptr<Notification> notification; |
830 // Add some notifications | 818 // Add some notifications |
831 int i = 0; | 819 int i = 0; |
832 for (; i < 6; i++) { | 820 for (; i < 6; i++) { |
833 notification.reset(CreateSimpleNotification(ids[i])); | 821 notification.reset(CreateSimpleNotification(ids[i])); |
834 notification->set_title(base::ASCIIToUTF16("ORIGINAL TITLE")); | 822 notification->set_title(base::ASCIIToUTF16("ORIGINAL TITLE")); |
835 message_center()->AddNotification(std::move(notification)); | 823 message_center()->AddNotification(std::move(notification)); |
836 } | 824 } |
837 for (i = 0; i < 6; i++) { | 825 for (i = 0; i < 6; i++) { |
838 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i])); | 826 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids[i])); |
839 } | 827 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 std::string id("id1"); | 962 std::string id("id1"); |
975 std::string id2("id2"); | 963 std::string id2("id2"); |
976 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 964 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
977 | 965 |
978 gfx::Size original_size(0, 0); | 966 gfx::Size original_size(0, 0); |
979 // Open the message center to prevent adding notifications | 967 // Open the message center to prevent adding notifications |
980 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 968 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
981 | 969 |
982 // Create new notification to be added to the queue; images all have the same | 970 // Create new notification to be added to the queue; images all have the same |
983 // original size. | 971 // original size. |
984 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 972 std::unique_ptr<Notification> notification(CreateSimpleNotification(id)); |
985 | 973 |
986 // Double-check that sizes all match. | 974 // Double-check that sizes all match. |
987 const std::vector<ButtonInfo>& original_buttons = notification->buttons(); | 975 const std::vector<ButtonInfo>& original_buttons = notification->buttons(); |
988 ASSERT_EQ(2u, original_buttons.size()); | 976 ASSERT_EQ(2u, original_buttons.size()); |
989 | 977 |
990 EXPECT_EQ(original_size, notification->icon().Size()); | 978 EXPECT_EQ(original_size, notification->icon().Size()); |
991 EXPECT_EQ(original_size, notification->image().Size()); | 979 EXPECT_EQ(original_size, notification->image().Size()); |
992 EXPECT_EQ(original_size, original_buttons[0].icon.Size()); | 980 EXPECT_EQ(original_size, original_buttons[0].icon.Size()); |
993 EXPECT_EQ(original_size, original_buttons[1].icon.Size()); | 981 EXPECT_EQ(original_size, original_buttons[1].icon.Size()); |
994 | 982 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 EXPECT_EQ(new_size, mc_notification->image().Size()); | 1014 EXPECT_EQ(new_size, mc_notification->image().Size()); |
1027 EXPECT_EQ(new_size, buttons[0].icon.Size()); | 1015 EXPECT_EQ(new_size, buttons[0].icon.Size()); |
1028 EXPECT_EQ(new_size, buttons[1].icon.Size()); | 1016 EXPECT_EQ(new_size, buttons[1].icon.Size()); |
1029 } | 1017 } |
1030 | 1018 |
1031 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushAdd) { | 1019 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushAdd) { |
1032 std::string id("id1"); | 1020 std::string id("id1"); |
1033 | 1021 |
1034 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1022 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
1035 message_center()->AddNotification( | 1023 message_center()->AddNotification( |
1036 scoped_ptr<Notification>(CreateSimpleNotification(id))); | 1024 std::unique_ptr<Notification>(CreateSimpleNotification(id))); |
1037 | 1025 |
1038 // Notification is not added yet. | 1026 // Notification is not added yet. |
1039 ASSERT_EQ(0u, message_center()->NotificationCount()); | 1027 ASSERT_EQ(0u, message_center()->NotificationCount()); |
1040 // Forced to update. | 1028 // Forced to update. |
1041 ForceNotificationFlush(id); | 1029 ForceNotificationFlush(id); |
1042 // Notification is added. | 1030 // Notification is added. |
1043 ASSERT_EQ(1u, message_center()->NotificationCount()); | 1031 ASSERT_EQ(1u, message_center()->NotificationCount()); |
1044 } | 1032 } |
1045 | 1033 |
1046 | 1034 |
1047 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushUpdate) { | 1035 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushUpdate) { |
1048 std::string id("id1"); | 1036 std::string id("id1"); |
1049 std::string id2("id2"); | 1037 std::string id2("id2"); |
1050 | 1038 |
1051 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1039 std::unique_ptr<Notification> notification(CreateSimpleNotification(id)); |
1052 message_center()->AddNotification(std::move(notification)); | 1040 message_center()->AddNotification(std::move(notification)); |
1053 | 1041 |
1054 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1042 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
1055 | 1043 |
1056 notification.reset(CreateSimpleNotification(id2)); | 1044 notification.reset(CreateSimpleNotification(id2)); |
1057 message_center()->UpdateNotification(id, std::move(notification)); | 1045 message_center()->UpdateNotification(id, std::move(notification)); |
1058 | 1046 |
1059 // Nothing is changed. | 1047 // Nothing is changed. |
1060 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); | 1048 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); |
1061 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1049 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
(...skipping 12 matching lines...) Expand all Loading... |
1074 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); | 1062 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); |
1075 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 1063 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
1076 | 1064 |
1077 // Makes sure if there is only one notification. | 1065 // Makes sure if there is only one notification. |
1078 ASSERT_EQ(1u, message_center()->NotificationCount()); | 1066 ASSERT_EQ(1u, message_center()->NotificationCount()); |
1079 } | 1067 } |
1080 | 1068 |
1081 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushRemove) { | 1069 TEST_F(MessageCenterImplTestWithChangeQueue, ForceNotificationFlushRemove) { |
1082 std::string id("id1"); | 1070 std::string id("id1"); |
1083 | 1071 |
1084 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1072 std::unique_ptr<Notification> notification(CreateSimpleNotification(id)); |
1085 message_center()->AddNotification(std::move(notification)); | 1073 message_center()->AddNotification(std::move(notification)); |
1086 | 1074 |
1087 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1075 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
1088 message_center()->RemoveNotification(id, false); | 1076 message_center()->RemoveNotification(id, false); |
1089 | 1077 |
1090 // Notification is not removed yet. | 1078 // Notification is not removed yet. |
1091 ASSERT_EQ(1u, message_center()->NotificationCount()); | 1079 ASSERT_EQ(1u, message_center()->NotificationCount()); |
1092 | 1080 |
1093 // Forced to update. | 1081 // Forced to update. |
1094 ForceNotificationFlush(id); | 1082 ForceNotificationFlush(id); |
1095 | 1083 |
1096 // Notification is removed. | 1084 // Notification is removed. |
1097 ASSERT_EQ(0u, message_center()->NotificationCount()); | 1085 ASSERT_EQ(0u, message_center()->NotificationCount()); |
1098 } | 1086 } |
1099 | 1087 |
1100 TEST_F(MessageCenterImplTestWithChangeQueue, | 1088 TEST_F(MessageCenterImplTestWithChangeQueue, |
1101 ForceNotificationFlush_ComplexUpdate) { | 1089 ForceNotificationFlush_ComplexUpdate) { |
1102 std::string id1("id1"); | 1090 std::string id1("id1"); |
1103 std::string id2("id2"); | 1091 std::string id2("id2"); |
1104 std::string id3("id3"); | 1092 std::string id3("id3"); |
1105 | 1093 |
1106 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1094 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
1107 | 1095 |
1108 // Add -> Update (with ID change) -> Remove | 1096 // Add -> Update (with ID change) -> Remove |
1109 scoped_ptr<Notification> notification(CreateSimpleNotification(id1)); | 1097 std::unique_ptr<Notification> notification(CreateSimpleNotification(id1)); |
1110 message_center()->AddNotification(std::move(notification)); | 1098 message_center()->AddNotification(std::move(notification)); |
1111 notification.reset(CreateSimpleNotification(id2)); | 1099 notification.reset(CreateSimpleNotification(id2)); |
1112 message_center()->UpdateNotification(id1, std::move(notification)); | 1100 message_center()->UpdateNotification(id1, std::move(notification)); |
1113 message_center()->RemoveNotification(id2, false); | 1101 message_center()->RemoveNotification(id2, false); |
1114 | 1102 |
1115 // Add -> Update (with ID change) | 1103 // Add -> Update (with ID change) |
1116 notification.reset(CreateSimpleNotification(id2)); | 1104 notification.reset(CreateSimpleNotification(id2)); |
1117 message_center()->AddNotification(std::move(notification)); | 1105 message_center()->AddNotification(std::move(notification)); |
1118 notification.reset(CreateSimpleNotification(id3)); | 1106 notification.reset(CreateSimpleNotification(id3)); |
1119 message_center()->UpdateNotification(id2, std::move(notification)); | 1107 message_center()->UpdateNotification(id2, std::move(notification)); |
1120 | 1108 |
1121 // Notification is not added since the message center has opened. | 1109 // Notification is not added since the message center has opened. |
1122 ASSERT_EQ(0u, message_center()->NotificationCount()); | 1110 ASSERT_EQ(0u, message_center()->NotificationCount()); |
1123 | 1111 |
1124 // Forced to update. | 1112 // Forced to update. |
1125 ForceNotificationFlush(id3); | 1113 ForceNotificationFlush(id3); |
1126 | 1114 |
1127 // Confirms the chagnes are applied. | 1115 // Confirms the chagnes are applied. |
1128 ASSERT_EQ(1u, message_center()->NotificationCount()); | 1116 ASSERT_EQ(1u, message_center()->NotificationCount()); |
1129 } | 1117 } |
1130 | 1118 |
1131 TEST_F(MessageCenterImplTestWithoutChangeQueue, | 1119 TEST_F(MessageCenterImplTestWithoutChangeQueue, |
1132 UpdateWhileMessageCenterVisible) { | 1120 UpdateWhileMessageCenterVisible) { |
1133 std::string id("id1"); | 1121 std::string id("id1"); |
1134 std::string id2("id2"); | 1122 std::string id2("id2"); |
1135 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); | 1123 NotifierId notifier_id1(NotifierId::APPLICATION, "app1"); |
1136 | 1124 |
1137 // First, add and update a notification to ensure updates happen | 1125 // First, add and update a notification to ensure updates happen |
1138 // normally. | 1126 // normally. |
1139 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1127 std::unique_ptr<Notification> notification(CreateSimpleNotification(id)); |
1140 message_center()->AddNotification(std::move(notification)); | 1128 message_center()->AddNotification(std::move(notification)); |
1141 notification.reset(CreateSimpleNotification(id2)); | 1129 notification.reset(CreateSimpleNotification(id2)); |
1142 message_center()->UpdateNotification(id, std::move(notification)); | 1130 message_center()->UpdateNotification(id, std::move(notification)); |
1143 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); | 1131 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2)); |
1144 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 1132 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
1145 | 1133 |
1146 // Then open the message center. | 1134 // Then open the message center. |
1147 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1135 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
1148 | 1136 |
1149 // Then update a notification; the update should have propagated. | 1137 // Then update a notification; the update should have propagated. |
1150 notification.reset(CreateSimpleNotification(id)); | 1138 notification.reset(CreateSimpleNotification(id)); |
1151 message_center()->UpdateNotification(id2, std::move(notification)); | 1139 message_center()->UpdateNotification(id2, std::move(notification)); |
1152 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); | 1140 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2)); |
1153 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1141 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
1154 } | 1142 } |
1155 | 1143 |
1156 TEST_F(MessageCenterImplTestWithoutChangeQueue, AddWhileMessageCenterVisible) { | 1144 TEST_F(MessageCenterImplTestWithoutChangeQueue, AddWhileMessageCenterVisible) { |
1157 std::string id("id1"); | 1145 std::string id("id1"); |
1158 | 1146 |
1159 // Then open the message center. | 1147 // Then open the message center. |
1160 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1148 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
1161 | 1149 |
1162 // Add a notification and confirm the adding should have propagated. | 1150 // Add a notification and confirm the adding should have propagated. |
1163 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1151 std::unique_ptr<Notification> notification(CreateSimpleNotification(id)); |
1164 message_center()->AddNotification(std::move(notification)); | 1152 message_center()->AddNotification(std::move(notification)); |
1165 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1153 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
1166 } | 1154 } |
1167 | 1155 |
1168 TEST_F(MessageCenterImplTestWithoutChangeQueue, | 1156 TEST_F(MessageCenterImplTestWithoutChangeQueue, |
1169 RemoveWhileMessageCenterVisible) { | 1157 RemoveWhileMessageCenterVisible) { |
1170 std::string id("id1"); | 1158 std::string id("id1"); |
1171 | 1159 |
1172 // First, add a notification to ensure updates happen normally. | 1160 // First, add a notification to ensure updates happen normally. |
1173 scoped_ptr<Notification> notification(CreateSimpleNotification(id)); | 1161 std::unique_ptr<Notification> notification(CreateSimpleNotification(id)); |
1174 message_center()->AddNotification(std::move(notification)); | 1162 message_center()->AddNotification(std::move(notification)); |
1175 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); | 1163 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id)); |
1176 | 1164 |
1177 // Then open the message center. | 1165 // Then open the message center. |
1178 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); | 1166 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER); |
1179 | 1167 |
1180 // Then update a notification; the update should have propagated. | 1168 // Then update a notification; the update should have propagated. |
1181 message_center()->RemoveNotification(id, false); | 1169 message_center()->RemoveNotification(id, false); |
1182 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); | 1170 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id)); |
1183 } | 1171 } |
1184 | 1172 |
1185 } // namespace internal | 1173 } // namespace internal |
1186 } // namespace message_center | 1174 } // namespace message_center |
OLD | NEW |