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.
5 #include "ui/message_center/message_center_impl.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/geometry/size.h"
14 #include "ui/message_center/message_center.h"
15 #include "ui/message_center/message_center_types.h"
16 #include "ui/message_center/notification_blocker.h"
17 #include "ui/message_center/notification_types.h"
18 #include "ui/message_center/notifier_settings.h"
20 using base::UTF8ToUTF16
;
22 namespace message_center
{
24 class MessageCenterImplTest
: public testing::Test
,
25 public MessageCenterObserver
{
27 MessageCenterImplTest() {}
29 void SetUp() override
{
30 MessageCenter::Initialize();
31 message_center_
= MessageCenter::Get();
32 loop_
.reset(new base::MessageLoop
);
33 run_loop_
.reset(new base::RunLoop());
34 closure_
= run_loop_
->QuitClosure();
37 void TearDown() override
{
40 message_center_
= NULL
;
41 MessageCenter::Shutdown();
44 MessageCenter
* message_center() const { return message_center_
; }
45 NotifierSettingsObserver
* notifier_settings_observer() const {
46 return static_cast<NotifierSettingsObserver
*>(message_center_impl());
48 MessageCenterImpl
* message_center_impl() const {
49 return reinterpret_cast<MessageCenterImpl
*>(message_center_
);
52 base::RunLoop
* run_loop() const { return run_loop_
.get(); }
53 base::Closure
closure() const { return closure_
; }
56 Notification
* CreateSimpleNotification(const std::string
& id
) {
57 return CreateNotificationWithNotifierId(
60 NOTIFICATION_TYPE_SIMPLE
);
63 Notification
* CreateSimpleNotificationWithNotifierId(
64 const std::string
& id
, const std::string
& notifier_id
) {
65 return CreateNotificationWithNotifierId(
68 NOTIFICATION_TYPE_SIMPLE
);
71 Notification
* CreateNotification(const std::string
& id
,
72 message_center::NotificationType type
) {
73 return CreateNotificationWithNotifierId(id
, "app1", type
);
76 Notification
* CreateNotificationWithNotifierId(
77 const std::string
& id
,
78 const std::string
& notifier_id
,
79 message_center::NotificationType type
) {
80 RichNotificationData optional_fields
;
81 optional_fields
.buttons
.push_back(ButtonInfo(UTF8ToUTF16("foo")));
82 optional_fields
.buttons
.push_back(ButtonInfo(UTF8ToUTF16("foo")));
83 return new Notification(type
, id
, UTF8ToUTF16("title"), UTF8ToUTF16(id
),
84 gfx::Image() /* icon */,
85 base::string16() /* display_source */, GURL(),
86 NotifierId(NotifierId::APPLICATION
, notifier_id
),
87 optional_fields
, NULL
);
90 void ForceNotificationFlush(const std::string
& id
) {
91 message_center()->ForceNotificationFlush(id
);
95 MessageCenter
* message_center_
;
96 scoped_ptr
<base::MessageLoop
> loop_
;
97 scoped_ptr
<base::RunLoop
> run_loop_
;
98 base::Closure closure_
;
100 DISALLOW_COPY_AND_ASSIGN(MessageCenterImplTest
);
105 class ToggledNotificationBlocker
: public NotificationBlocker
{
107 explicit ToggledNotificationBlocker(MessageCenter
* message_center
)
108 : NotificationBlocker(message_center
),
109 notifications_enabled_(true) {}
110 ~ToggledNotificationBlocker() override
{}
112 void SetNotificationsEnabled(bool enabled
) {
113 if (notifications_enabled_
!= enabled
) {
114 notifications_enabled_
= enabled
;
115 NotifyBlockingStateChanged();
119 // NotificationBlocker overrides:
120 bool ShouldShowNotificationAsPopup(
121 const message_center::NotifierId
& notifier_id
) const override
{
122 return notifications_enabled_
;
126 bool notifications_enabled_
;
128 DISALLOW_COPY_AND_ASSIGN(ToggledNotificationBlocker
);
131 class PopupNotificationBlocker
: public ToggledNotificationBlocker
{
133 PopupNotificationBlocker(MessageCenter
* message_center
,
134 const NotifierId
& allowed_notifier
)
135 : ToggledNotificationBlocker(message_center
),
136 allowed_notifier_(allowed_notifier
) {}
137 ~PopupNotificationBlocker() override
{}
139 // NotificationBlocker overrides:
140 bool ShouldShowNotificationAsPopup(
141 const NotifierId
& notifier_id
) const override
{
142 return (notifier_id
== allowed_notifier_
) ||
143 ToggledNotificationBlocker::ShouldShowNotificationAsPopup(notifier_id
);
147 NotifierId allowed_notifier_
;
149 DISALLOW_COPY_AND_ASSIGN(PopupNotificationBlocker
);
152 class TotalNotificationBlocker
: public PopupNotificationBlocker
{
154 TotalNotificationBlocker(MessageCenter
* message_center
,
155 const NotifierId
& allowed_notifier
)
156 : PopupNotificationBlocker(message_center
, allowed_notifier
) {}
157 ~TotalNotificationBlocker() override
{}
159 // NotificationBlocker overrides:
160 bool ShouldShowNotification(const NotifierId
& notifier_id
) const override
{
161 return ShouldShowNotificationAsPopup(notifier_id
);
165 DISALLOW_COPY_AND_ASSIGN(TotalNotificationBlocker
);
168 bool PopupNotificationsContain(
169 const NotificationList::PopupNotifications
& popups
,
170 const std::string
& id
) {
171 for (NotificationList::PopupNotifications::const_iterator iter
=
172 popups
.begin(); iter
!= popups
.end(); ++iter
) {
173 if ((*iter
)->id() == id
)
179 // Right now, MessageCenter::HasNotification() returns regardless of blockers.
180 bool NotificationsContain(
181 const NotificationList::Notifications
& notifications
,
182 const std::string
& id
) {
183 for (NotificationList::Notifications::const_iterator iter
=
184 notifications
.begin(); iter
!= notifications
.end(); ++iter
) {
185 if ((*iter
)->id() == id
)
195 class MockPopupTimersController
: public PopupTimersController
{
197 MockPopupTimersController(MessageCenter
* message_center
,
198 base::Closure quit_closure
)
199 : PopupTimersController(message_center
),
200 timer_finished_(false),
201 quit_closure_(quit_closure
) {}
202 ~MockPopupTimersController() override
{}
204 void TimerFinished(const std::string
& id
) override
{
205 base::MessageLoop::current()->PostTask(FROM_HERE
, quit_closure_
);
206 timer_finished_
= true;
210 bool timer_finished() const { return timer_finished_
; }
211 const std::string
& last_id() const { return last_id_
; }
214 bool timer_finished_
;
215 std::string last_id_
;
216 base::Closure quit_closure_
;
219 TEST_F(MessageCenterImplTest
, PopupTimersEmptyController
) {
220 scoped_ptr
<PopupTimersController
> popup_timers_controller
=
221 make_scoped_ptr(new PopupTimersController(message_center()));
223 // Test that all functions succed without any timers created.
224 popup_timers_controller
->PauseAll();
225 popup_timers_controller
->StartAll();
226 popup_timers_controller
->CancelAll();
227 popup_timers_controller
->TimerFinished("unknown");
228 popup_timers_controller
->PauseTimer("unknown");
229 popup_timers_controller
->CancelTimer("unknown");
232 TEST_F(MessageCenterImplTest
, PopupTimersControllerStartTimer
) {
233 scoped_ptr
<MockPopupTimersController
> popup_timers_controller
=
235 new MockPopupTimersController(message_center(), closure()));
236 popup_timers_controller
->StartTimer("test",
237 base::TimeDelta::FromMilliseconds(1));
239 EXPECT_TRUE(popup_timers_controller
->timer_finished());
242 TEST_F(MessageCenterImplTest
, PopupTimersControllerPauseTimer
) {
243 scoped_ptr
<MockPopupTimersController
> popup_timers_controller
=
245 new MockPopupTimersController(message_center(), closure()));
246 popup_timers_controller
->StartTimer("test",
247 base::TimeDelta::FromMilliseconds(1));
248 popup_timers_controller
->PauseTimer("test");
249 run_loop()->RunUntilIdle();
251 EXPECT_FALSE(popup_timers_controller
->timer_finished());
254 TEST_F(MessageCenterImplTest
, PopupTimersControllerCancelTimer
) {
255 scoped_ptr
<MockPopupTimersController
> popup_timers_controller
=
257 new MockPopupTimersController(message_center(), closure()));
258 popup_timers_controller
->StartTimer("test",
259 base::TimeDelta::FromMilliseconds(1));
260 popup_timers_controller
->CancelTimer("test");
261 run_loop()->RunUntilIdle();
263 EXPECT_FALSE(popup_timers_controller
->timer_finished());
266 TEST_F(MessageCenterImplTest
, PopupTimersControllerPauseAllTimers
) {
267 scoped_ptr
<MockPopupTimersController
> popup_timers_controller
=
269 new MockPopupTimersController(message_center(), closure()));
270 popup_timers_controller
->StartTimer("test",
271 base::TimeDelta::FromMilliseconds(1));
272 popup_timers_controller
->PauseAll();
273 run_loop()->RunUntilIdle();
275 EXPECT_FALSE(popup_timers_controller
->timer_finished());
278 TEST_F(MessageCenterImplTest
, PopupTimersControllerStartAllTimers
) {
279 scoped_ptr
<MockPopupTimersController
> popup_timers_controller
=
281 new MockPopupTimersController(message_center(), closure()));
282 popup_timers_controller
->StartTimer("test",
283 base::TimeDelta::FromMilliseconds(1));
284 popup_timers_controller
->PauseAll();
285 popup_timers_controller
->StartAll();
288 EXPECT_TRUE(popup_timers_controller
->timer_finished());
291 TEST_F(MessageCenterImplTest
, PopupTimersControllerStartMultipleTimers
) {
292 scoped_ptr
<MockPopupTimersController
> popup_timers_controller
=
294 new MockPopupTimersController(message_center(), closure()));
295 popup_timers_controller
->StartTimer("test",
296 base::TimeDelta::FromMilliseconds(5));
297 popup_timers_controller
->StartTimer("test2",
298 base::TimeDelta::FromMilliseconds(1));
299 popup_timers_controller
->StartTimer("test3",
300 base::TimeDelta::FromMilliseconds(3));
301 popup_timers_controller
->PauseAll();
302 popup_timers_controller
->StartAll();
305 EXPECT_EQ(popup_timers_controller
->last_id(), "test2");
306 EXPECT_TRUE(popup_timers_controller
->timer_finished());
309 TEST_F(MessageCenterImplTest
, PopupTimersControllerStartMultipleTimersPause
) {
310 scoped_ptr
<MockPopupTimersController
> popup_timers_controller
=
312 new MockPopupTimersController(message_center(), closure()));
313 popup_timers_controller
->StartTimer("test",
314 base::TimeDelta::FromMilliseconds(5));
315 popup_timers_controller
->StartTimer("test2",
316 base::TimeDelta::FromMilliseconds(1));
317 popup_timers_controller
->StartTimer("test3",
318 base::TimeDelta::FromMilliseconds(3));
319 popup_timers_controller
->PauseTimer("test2");
323 EXPECT_EQ(popup_timers_controller
->last_id(), "test3");
324 EXPECT_TRUE(popup_timers_controller
->timer_finished());
327 TEST_F(MessageCenterImplTest
, PopupTimersControllerResetTimer
) {
328 scoped_ptr
<MockPopupTimersController
> popup_timers_controller
=
330 new MockPopupTimersController(message_center(), closure()));
331 popup_timers_controller
->StartTimer("test",
332 base::TimeDelta::FromMilliseconds(5));
333 popup_timers_controller
->StartTimer("test2",
334 base::TimeDelta::FromMilliseconds(1));
335 popup_timers_controller
->StartTimer("test3",
336 base::TimeDelta::FromMilliseconds(3));
337 popup_timers_controller
->PauseTimer("test2");
338 popup_timers_controller
->ResetTimer("test",
339 base::TimeDelta::FromMilliseconds(2));
343 EXPECT_EQ(popup_timers_controller
->last_id(), "test");
344 EXPECT_TRUE(popup_timers_controller
->timer_finished());
347 TEST_F(MessageCenterImplTest
, NotificationBlocker
) {
348 NotifierId
notifier_id(NotifierId::APPLICATION
, "app1");
349 // Multiple blockers to verify the case that one blocker blocks but another
351 ToggledNotificationBlocker
blocker1(message_center());
352 ToggledNotificationBlocker
blocker2(message_center());
354 message_center()->AddNotification(scoped_ptr
<Notification
>(
355 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id1", UTF8ToUTF16("title"),
356 UTF8ToUTF16("message"), gfx::Image() /* icon */,
357 base::string16() /* display_source */, GURL(),
358 notifier_id
, RichNotificationData(), NULL
)));
359 message_center()->AddNotification(scoped_ptr
<Notification
>(
360 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id2", UTF8ToUTF16("title"),
361 UTF8ToUTF16("message"), gfx::Image() /* icon */,
362 base::string16() /* display_source */, GURL(),
363 notifier_id
, RichNotificationData(), NULL
)));
364 EXPECT_EQ(2u, message_center()->GetPopupNotifications().size());
365 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
367 // Block all notifications. All popups are gone and message center should be
369 blocker1
.SetNotificationsEnabled(false);
370 EXPECT_TRUE(message_center()->GetPopupNotifications().empty());
371 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
373 // Updates |blocker2| state, which doesn't affect the global state.
374 blocker2
.SetNotificationsEnabled(false);
375 EXPECT_TRUE(message_center()->GetPopupNotifications().empty());
376 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
378 blocker2
.SetNotificationsEnabled(true);
379 EXPECT_TRUE(message_center()->GetPopupNotifications().empty());
380 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
382 // If |blocker2| blocks, then unblocking blocker1 doesn't change the global
384 blocker2
.SetNotificationsEnabled(false);
385 blocker1
.SetNotificationsEnabled(true);
386 EXPECT_TRUE(message_center()->GetPopupNotifications().empty());
387 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
389 // Unblock both blockers, which recovers the global state, but the popups
391 blocker2
.SetNotificationsEnabled(true);
392 EXPECT_TRUE(message_center()->GetPopupNotifications().empty());
393 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
396 TEST_F(MessageCenterImplTest
, NotificationsDuringBlocked
) {
397 NotifierId
notifier_id(NotifierId::APPLICATION
, "app1");
398 ToggledNotificationBlocker
blocker(message_center());
400 message_center()->AddNotification(scoped_ptr
<Notification
>(
401 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id1", UTF8ToUTF16("title"),
402 UTF8ToUTF16("message"), gfx::Image() /* icon */,
403 base::string16() /* display_source */, GURL(),
404 notifier_id
, RichNotificationData(), NULL
)));
405 EXPECT_EQ(1u, message_center()->GetPopupNotifications().size());
406 EXPECT_EQ(1u, message_center()->GetVisibleNotifications().size());
408 // Create a notification during blocked. Still no popups.
409 blocker
.SetNotificationsEnabled(false);
410 message_center()->AddNotification(scoped_ptr
<Notification
>(
411 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id2", UTF8ToUTF16("title"),
412 UTF8ToUTF16("message"), gfx::Image() /* icon */,
413 base::string16() /* display_source */, GURL(),
414 notifier_id
, RichNotificationData(), NULL
)));
415 EXPECT_TRUE(message_center()->GetPopupNotifications().empty());
416 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
418 // Unblock notifications, the id1 should appear as a popup.
419 blocker
.SetNotificationsEnabled(true);
420 NotificationList::PopupNotifications popups
=
421 message_center()->GetPopupNotifications();
422 EXPECT_EQ(1u, popups
.size());
423 EXPECT_TRUE(PopupNotificationsContain(popups
, "id2"));
424 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
427 // Similar to other blocker cases but this test case allows |notifier_id2| even
429 TEST_F(MessageCenterImplTest
, NotificationBlockerAllowsPopups
) {
430 NotifierId
notifier_id1(NotifierId::APPLICATION
, "app1");
431 NotifierId
notifier_id2(NotifierId::APPLICATION
, "app2");
432 PopupNotificationBlocker
blocker(message_center(), notifier_id2
);
434 message_center()->AddNotification(scoped_ptr
<Notification
>(
435 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id1", UTF8ToUTF16("title"),
436 UTF8ToUTF16("message"), gfx::Image() /* icon */,
437 base::string16() /* display_source */, GURL(),
438 notifier_id1
, RichNotificationData(), NULL
)));
439 message_center()->AddNotification(scoped_ptr
<Notification
>(
440 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id2", UTF8ToUTF16("title"),
441 UTF8ToUTF16("message"), gfx::Image() /* icon */,
442 base::string16() /* display_source */, GURL(),
443 notifier_id2
, RichNotificationData(), NULL
)));
445 // "id1" is closed but "id2" is still visible as a popup.
446 blocker
.SetNotificationsEnabled(false);
447 NotificationList::PopupNotifications popups
=
448 message_center()->GetPopupNotifications();
449 EXPECT_EQ(1u, popups
.size());
450 EXPECT_TRUE(PopupNotificationsContain(popups
, "id2"));
451 EXPECT_EQ(2u, message_center()->GetVisibleNotifications().size());
453 message_center()->AddNotification(scoped_ptr
<Notification
>(
454 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id3", UTF8ToUTF16("title"),
455 UTF8ToUTF16("message"), gfx::Image() /* icon */,
456 base::string16() /* display_source */, GURL(),
457 notifier_id1
, RichNotificationData(), NULL
)));
458 message_center()->AddNotification(scoped_ptr
<Notification
>(
459 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id4", UTF8ToUTF16("title"),
460 UTF8ToUTF16("message"), gfx::Image() /* icon */,
461 base::string16() /* display_source */, GURL(),
462 notifier_id2
, RichNotificationData(), NULL
)));
463 popups
= message_center()->GetPopupNotifications();
464 EXPECT_EQ(2u, popups
.size());
465 EXPECT_TRUE(PopupNotificationsContain(popups
, "id2"));
466 EXPECT_TRUE(PopupNotificationsContain(popups
, "id4"));
467 EXPECT_EQ(4u, message_center()->GetVisibleNotifications().size());
469 blocker
.SetNotificationsEnabled(true);
470 popups
= message_center()->GetPopupNotifications();
471 EXPECT_EQ(3u, popups
.size());
472 EXPECT_TRUE(PopupNotificationsContain(popups
, "id2"));
473 EXPECT_TRUE(PopupNotificationsContain(popups
, "id3"));
474 EXPECT_TRUE(PopupNotificationsContain(popups
, "id4"));
475 EXPECT_EQ(4u, message_center()->GetVisibleNotifications().size());
478 // TotalNotificationBlocker suppresses showing notifications even from the list.
479 // This would provide the feature to 'separated' message centers per-profile for
480 // ChromeOS multi-login.
481 TEST_F(MessageCenterImplTest
, TotalNotificationBlocker
) {
482 NotifierId
notifier_id1(NotifierId::APPLICATION
, "app1");
483 NotifierId
notifier_id2(NotifierId::APPLICATION
, "app2");
484 TotalNotificationBlocker
blocker(message_center(), notifier_id2
);
486 message_center()->AddNotification(scoped_ptr
<Notification
>(
487 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id1", UTF8ToUTF16("title"),
488 UTF8ToUTF16("message"), gfx::Image() /* icon */,
489 base::string16() /* display_source */, GURL(),
490 notifier_id1
, RichNotificationData(), NULL
)));
491 message_center()->AddNotification(scoped_ptr
<Notification
>(
492 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id2", UTF8ToUTF16("title"),
493 UTF8ToUTF16("message"), gfx::Image() /* icon */,
494 base::string16() /* display_source */, GURL(),
495 notifier_id2
, RichNotificationData(), NULL
)));
497 // "id1" becomes invisible while "id2" is still visible.
498 blocker
.SetNotificationsEnabled(false);
499 EXPECT_EQ(1u, message_center()->NotificationCount());
500 NotificationList::Notifications notifications
=
501 message_center()->GetVisibleNotifications();
502 EXPECT_FALSE(NotificationsContain(notifications
, "id1"));
503 EXPECT_TRUE(NotificationsContain(notifications
, "id2"));
505 message_center()->AddNotification(scoped_ptr
<Notification
>(
506 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id3", UTF8ToUTF16("title"),
507 UTF8ToUTF16("message"), gfx::Image() /* icon */,
508 base::string16() /* display_source */, GURL(),
509 notifier_id1
, RichNotificationData(), NULL
)));
510 message_center()->AddNotification(scoped_ptr
<Notification
>(
511 new Notification(NOTIFICATION_TYPE_SIMPLE
, "id4", UTF8ToUTF16("title"),
512 UTF8ToUTF16("message"), gfx::Image() /* icon */,
513 base::string16() /* display_source */, GURL(),
514 notifier_id2
, RichNotificationData(), NULL
)));
515 EXPECT_EQ(2u, message_center()->NotificationCount());
516 notifications
= message_center()->GetVisibleNotifications();
517 EXPECT_FALSE(NotificationsContain(notifications
, "id1"));
518 EXPECT_TRUE(NotificationsContain(notifications
, "id2"));
519 EXPECT_FALSE(NotificationsContain(notifications
, "id3"));
520 EXPECT_TRUE(NotificationsContain(notifications
, "id4"));
522 blocker
.SetNotificationsEnabled(true);
523 EXPECT_EQ(4u, message_center()->NotificationCount());
524 notifications
= message_center()->GetVisibleNotifications();
525 EXPECT_TRUE(NotificationsContain(notifications
, "id1"));
526 EXPECT_TRUE(NotificationsContain(notifications
, "id2"));
527 EXPECT_TRUE(NotificationsContain(notifications
, "id3"));
528 EXPECT_TRUE(NotificationsContain(notifications
, "id4"));
530 // RemoveAllVisibleNotifications should remove just visible notifications.
531 blocker
.SetNotificationsEnabled(false);
532 message_center()->RemoveAllVisibleNotifications(false /* by_user */);
533 EXPECT_EQ(0u, message_center()->NotificationCount());
534 blocker
.SetNotificationsEnabled(true);
535 EXPECT_EQ(2u, message_center()->NotificationCount());
536 notifications
= message_center()->GetVisibleNotifications();
537 EXPECT_TRUE(NotificationsContain(notifications
, "id1"));
538 EXPECT_FALSE(NotificationsContain(notifications
, "id2"));
539 EXPECT_TRUE(NotificationsContain(notifications
, "id3"));
540 EXPECT_FALSE(NotificationsContain(notifications
, "id4"));
542 // And RemoveAllNotifications should remove all.
543 blocker
.SetNotificationsEnabled(false);
544 message_center()->RemoveAllNotifications(false /* by_user */);
545 EXPECT_EQ(0u, message_center()->NotificationCount());
548 TEST_F(MessageCenterImplTest
, QueueUpdatesWithCenterVisible
) {
549 std::string
id("id1");
550 std::string
id2("id2");
551 NotifierId
notifier_id1(NotifierId::APPLICATION
, "app1");
553 // First, add and update a notification to ensure updates happen
555 scoped_ptr
<Notification
> notification(CreateSimpleNotification(id
));
556 message_center()->AddNotification(notification
.Pass());
557 notification
.reset(CreateSimpleNotification(id2
));
558 message_center()->UpdateNotification(id
, notification
.Pass());
559 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2
));
560 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id
));
562 // Then open the message center.
563 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
565 // Then update a notification; nothing should have happened.
566 notification
.reset(CreateSimpleNotification(id
));
567 message_center()->UpdateNotification(id2
, notification
.Pass());
568 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2
));
569 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id
));
571 // Close the message center; then the update should have propagated.
572 message_center()->SetVisibility(VISIBILITY_TRANSIENT
);
573 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2
));
574 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id
));
577 TEST_F(MessageCenterImplTest
, ComplexQueueing
) {
578 std::string ids
[6] = {"0", "1", "2", "3", "4p", "5"};
579 NotifierId
notifier_id1(NotifierId::APPLICATION
, "app1");
581 scoped_ptr
<Notification
> notification
;
582 // Add some notifications
585 notification
.reset(CreateSimpleNotification(ids
[i
]));
586 message_center()->AddNotification(notification
.Pass());
588 for (i
= 0; i
< 3; i
++) {
589 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[i
]));
592 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[i
]));
595 notification
.reset(CreateNotification(ids
[4], NOTIFICATION_TYPE_PROGRESS
));
596 message_center()->AddNotification(notification
.Pass());
598 // Now start queueing.
599 // NL: ["0", "1", "2", "4p"]
600 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
602 // This should update notification "1" to have id "3".
603 notification
.reset(CreateSimpleNotification(ids
[3]));
604 message_center()->UpdateNotification(ids
[1], notification
.Pass());
606 // Change the ID: "4p" -> "5", "5" -> "1", "1" -> "4p". They shouldn't
607 // override the previous change ("1" -> "3") nor the next one ("3" -> "5").
608 notification
.reset(CreateSimpleNotification(ids
[5]));
609 message_center()->UpdateNotification(ids
[4], notification
.Pass());
610 notification
.reset(CreateSimpleNotification(ids
[1]));
611 message_center()->UpdateNotification(ids
[5], notification
.Pass());
612 notification
.reset(CreateNotification(ids
[4], NOTIFICATION_TYPE_PROGRESS
));
613 message_center()->UpdateNotification(ids
[1], notification
.Pass());
615 // This should update notification "3" to "5" after we go TRANSIENT.
616 notification
.reset(CreateSimpleNotification(ids
[5]));
617 message_center()->UpdateNotification(ids
[3], notification
.Pass());
619 // This should create a new "3", that doesn't overwrite the update to 3
621 notification
.reset(CreateSimpleNotification(ids
[3]));
622 message_center()->AddNotification(notification
.Pass());
624 // The NL should still be the same: ["0", "1", "2", "4p"]
625 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[0]));
626 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[1]));
627 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[2]));
628 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[3]));
629 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[4]));
630 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[5]));
631 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 4u);
632 message_center()->SetVisibility(VISIBILITY_TRANSIENT
);
634 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[0]));
635 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[1]));
636 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[2]));
637 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[3]));
638 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[4]));
639 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[5]));
640 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 5u);
643 TEST_F(MessageCenterImplTest
, UpdateWhileQueueing
) {
644 std::string ids
[11] =
645 {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10p"};
646 NotifierId
notifier_id1(NotifierId::APPLICATION
, "app1");
648 scoped_ptr
<Notification
> notification
;
649 // Add some notifications
652 notification
.reset(CreateSimpleNotification(ids
[i
]));
653 notification
->set_title(base::ASCIIToUTF16("ORIGINAL TITLE"));
654 message_center()->AddNotification(notification
.Pass());
656 for (i
= 0; i
< 6; i
++) {
657 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[i
]));
660 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[i
]));
663 notification
.reset(CreateNotification(ids
[10], NOTIFICATION_TYPE_PROGRESS
));
664 notification
->set_progress(10);
665 message_center()->AddNotification(notification
.Pass());
667 // Now start queueing.
668 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
670 // Notification 0: (Exists) -> Removed
671 message_center()->RemoveNotification(ids
[0], false);
673 // Notification 1: (Exists) -> Removed (by user)
674 message_center()->RemoveNotification(ids
[1], true); // removed immediately
676 // Notification 2: (Exists) -> Removed -> Added
677 message_center()->RemoveNotification(ids
[2], false);
678 notification
.reset(CreateSimpleNotification(ids
[2]));
679 notification
->set_title(base::ASCIIToUTF16("NEW TITLE 2"));
680 message_center()->UpdateNotification(ids
[2], notification
.Pass());
682 // Notification 3: (Exists) -> Removed -> Updated
683 message_center()->RemoveNotification(ids
[3], false);
684 notification
.reset(CreateSimpleNotification(ids
[3]));
685 notification
->set_title(base::ASCIIToUTF16("NEW TITLE 3"));
686 message_center()->UpdateNotification(ids
[3], notification
.Pass());
688 // Notification 4: (Exists) -> Removed -> Added -> Removed
689 message_center()->RemoveNotification(ids
[4], false);
690 notification
.reset(CreateSimpleNotification(ids
[4]));
691 message_center()->AddNotification(notification
.Pass());
692 message_center()->RemoveNotification(ids
[4], false);
694 // Notification 5: (Exists) -> Updated
695 notification
.reset(CreateSimpleNotification(ids
[5]));
696 notification
->set_title(base::ASCIIToUTF16("NEW TITLE 5"));
697 message_center()->UpdateNotification(ids
[5], notification
.Pass());
699 // Notification 6: Updated
700 notification
.reset(CreateSimpleNotification(ids
[6]));
701 message_center()->UpdateNotification(ids
[6], notification
.Pass());
703 // Notification 7: Updated -> Removed
704 notification
.reset(CreateSimpleNotification(ids
[7]));
705 message_center()->UpdateNotification(ids
[7], notification
.Pass());
706 message_center()->RemoveNotification(ids
[7], false);
708 // Notification 8: Added -> Updated
709 notification
.reset(CreateSimpleNotification(ids
[8]));
710 notification
->set_title(base::ASCIIToUTF16("UPDATING 8-1"));
711 message_center()->AddNotification(notification
.Pass());
712 notification
.reset(CreateSimpleNotification(ids
[8]));
713 notification
->set_title(base::ASCIIToUTF16("NEW TITLE 8"));
714 message_center()->UpdateNotification(ids
[8], notification
.Pass());
716 // Notification 9: Added -> Updated -> Removed
717 notification
.reset(CreateSimpleNotification(ids
[9]));
718 message_center()->AddNotification(notification
.Pass());
719 notification
.reset(CreateSimpleNotification(ids
[9]));
720 message_center()->UpdateNotification(ids
[9], notification
.Pass());
721 message_center()->RemoveNotification(ids
[9], false);
723 // Notification 10 (TYPE_PROGRESS): Updated -> Removed -> Added -> Updated
724 // Step 1) Progress is updated immediately before removed.
725 notification
.reset(CreateNotification(ids
[10], NOTIFICATION_TYPE_PROGRESS
));
726 notification
->set_progress(20);
727 message_center()->UpdateNotification(ids
[10], notification
.Pass());
729 message_center()->FindVisibleNotificationById(ids
[10])->progress());
730 message_center()->RemoveNotification(ids
[10], false);
731 // Step 2) Progress isn't updated after removed.
732 notification
.reset(CreateSimpleNotification(ids
[10]));
733 message_center()->AddNotification(notification
.Pass());
735 message_center()->FindVisibleNotificationById(ids
[10])->progress());
736 notification
.reset(CreateSimpleNotification(ids
[10]));
737 notification
->set_progress(40);
738 message_center()->UpdateNotification(ids
[10], notification
.Pass());
740 message_center()->FindVisibleNotificationById(ids
[10])->progress());
742 // All changes except the notification 1 and 10 are not refrected.
743 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[0]));
744 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"),
745 message_center()->FindVisibleNotificationById(ids
[0])->title());
746 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[1]));
747 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[2]));
748 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"),
749 message_center()->FindVisibleNotificationById(ids
[2])->title());
750 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[3]));
751 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"),
752 message_center()->FindVisibleNotificationById(ids
[3])->title());
753 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[4]));
754 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"),
755 message_center()->FindVisibleNotificationById(ids
[4])->title());
756 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[5]));
757 EXPECT_EQ(base::ASCIIToUTF16("ORIGINAL TITLE"),
758 message_center()->FindVisibleNotificationById(ids
[5])->title());
759 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[6]));
760 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[7]));
761 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[8]));
762 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[9]));
763 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[10]));
764 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 6u);
766 message_center()->SetVisibility(VISIBILITY_TRANSIENT
);
768 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[0]));
769 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[1]));
770 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[2]));
771 EXPECT_EQ(base::ASCIIToUTF16("NEW TITLE 2"),
772 message_center()->FindVisibleNotificationById(ids
[2])->title());
773 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[3]));
774 EXPECT_EQ(base::ASCIIToUTF16("NEW TITLE 3"),
775 message_center()->FindVisibleNotificationById(ids
[3])->title());
776 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[4]));
777 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[5]));
778 EXPECT_EQ(base::ASCIIToUTF16("NEW TITLE 5"),
779 message_center()->FindVisibleNotificationById(ids
[5])->title());
780 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[6]));
781 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[7]));
782 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[8]));
783 EXPECT_EQ(base::ASCIIToUTF16("NEW TITLE 8"),
784 message_center()->FindVisibleNotificationById(ids
[8])->title());
785 EXPECT_FALSE(message_center()->FindVisibleNotificationById(ids
[9]));
786 EXPECT_TRUE(message_center()->FindVisibleNotificationById(ids
[10]));
788 message_center()->FindVisibleNotificationById(ids
[10])->progress());
789 EXPECT_EQ(message_center()->GetVisibleNotifications().size(), 5u);
792 TEST_F(MessageCenterImplTest
, QueuedDirectUpdates
) {
793 std::string
id("id1");
794 std::string
id2("id2");
795 NotifierId
notifier_id1(NotifierId::APPLICATION
, "app1");
797 gfx::Size
original_size(0, 0);
798 // Open the message center to prevent adding notifications
799 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
801 // Create new notification to be added to the queue; images all have the same
803 scoped_ptr
<Notification
> notification(CreateSimpleNotification(id
));
805 // Double-check that sizes all match.
806 const std::vector
<ButtonInfo
>& original_buttons
= notification
->buttons();
807 ASSERT_EQ(2u, original_buttons
.size());
809 EXPECT_EQ(original_size
, notification
->icon().Size());
810 EXPECT_EQ(original_size
, notification
->image().Size());
811 EXPECT_EQ(original_size
, original_buttons
[0].icon
.Size());
812 EXPECT_EQ(original_size
, original_buttons
[1].icon
.Size());
814 message_center()->AddNotification(notification
.Pass());
816 // The notification should be in the queue.
817 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id
));
819 // Now try setting the icon to a different size.
820 gfx::Size
new_size(16, 16);
821 EXPECT_NE(original_size
, new_size
);
823 gfx::Canvas
canvas(new_size
, 1.0f
, true);
824 canvas
.DrawColor(SK_ColorBLUE
);
825 gfx::Image
testImage(gfx::Image(gfx::ImageSkia(canvas
.ExtractImageRep())));
826 message_center()->SetNotificationIcon(id
, testImage
);
827 message_center()->SetNotificationImage(id
, testImage
);
828 message_center()->SetNotificationButtonIcon(id
, 0, testImage
);
829 message_center()->SetNotificationButtonIcon(id
, 1, testImage
);
831 // The notification should be in the queue.
832 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id
));
834 // Close the message center; then the update should have propagated.
835 message_center()->SetVisibility(VISIBILITY_TRANSIENT
);
836 // The notification should no longer be in the queue.
837 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id
));
839 Notification
* mc_notification
=
840 *(message_center()->GetVisibleNotifications().begin());
841 const std::vector
<ButtonInfo
>& buttons
= mc_notification
->buttons();
842 ASSERT_EQ(2u, buttons
.size());
844 EXPECT_EQ(new_size
, mc_notification
->icon().Size());
845 EXPECT_EQ(new_size
, mc_notification
->image().Size());
846 EXPECT_EQ(new_size
, buttons
[0].icon
.Size());
847 EXPECT_EQ(new_size
, buttons
[1].icon
.Size());
850 TEST_F(MessageCenterImplTest
, CachedUnreadCount
) {
851 message_center()->AddNotification(
852 scoped_ptr
<Notification
>(CreateSimpleNotification("id1")));
853 message_center()->AddNotification(
854 scoped_ptr
<Notification
>(CreateSimpleNotification("id2")));
855 message_center()->AddNotification(
856 scoped_ptr
<Notification
>(CreateSimpleNotification("id3")));
857 ASSERT_EQ(3u, message_center()->UnreadNotificationCount());
859 // Mark 'displayed' on all notifications by using for-loop. This shouldn't
860 // recreate |notifications| inside of the loop.
861 const NotificationList::Notifications
& notifications
=
862 message_center()->GetVisibleNotifications();
863 for (NotificationList::Notifications::const_iterator iter
=
864 notifications
.begin(); iter
!= notifications
.end(); ++iter
) {
865 message_center()->DisplayedNotification(
866 (*iter
)->id(), message_center::DISPLAY_SOURCE_MESSAGE_CENTER
);
868 EXPECT_EQ(0u, message_center()->UnreadNotificationCount());
870 // Imitate the timeout, which recovers the unread count. Again, this shouldn't
871 // recreate |notifications| inside of the loop.
872 for (NotificationList::Notifications::const_iterator iter
=
873 notifications
.begin(); iter
!= notifications
.end(); ++iter
) {
874 message_center()->MarkSinglePopupAsShown((*iter
)->id(), false);
876 EXPECT_EQ(3u, message_center()->UnreadNotificationCount());
878 // Opening the message center will reset the unread count.
879 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
880 EXPECT_EQ(0u, message_center()->UnreadNotificationCount());
883 TEST_F(MessageCenterImplTest
, ForceNotificationFlushAdd
) {
884 std::string
id("id1");
886 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
887 message_center()->AddNotification(
888 scoped_ptr
<Notification
>(CreateSimpleNotification(id
)));
890 // Notification is not added yet.
891 ASSERT_EQ(0u, message_center()->NotificationCount());
893 ForceNotificationFlush(id
);
894 // Notification is added.
895 ASSERT_EQ(1u, message_center()->NotificationCount());
899 TEST_F(MessageCenterImplTest
, ForceNotificationFlushUpdate
) {
900 std::string
id("id1");
901 std::string
id2("id2");
903 scoped_ptr
<Notification
> notification(CreateSimpleNotification(id
));
904 message_center()->AddNotification(notification
.Pass());
906 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
908 notification
.reset(CreateSimpleNotification(id2
));
909 message_center()->UpdateNotification(id
, notification
.Pass());
911 // Nothing is changed.
912 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2
));
913 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id
));
915 // Forced to update ID1.
916 ForceNotificationFlush(id
);
918 // Nothing is changed, since the ID is changed.
919 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id2
));
920 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id
));
922 // Forced to update ID2.
923 ForceNotificationFlush(id2
);
925 // The ID is changed.
926 EXPECT_TRUE(message_center()->FindVisibleNotificationById(id2
));
927 EXPECT_FALSE(message_center()->FindVisibleNotificationById(id
));
929 // Makes sure if there is only one notification.
930 ASSERT_EQ(1u, message_center()->NotificationCount());
933 TEST_F(MessageCenterImplTest
, ForceNotificationFlushRemove
) {
934 std::string
id("id1");
936 scoped_ptr
<Notification
> notification(CreateSimpleNotification(id
));
937 message_center()->AddNotification(notification
.Pass());
939 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
940 message_center()->RemoveNotification(id
, false);
942 // Notification is not removed yet.
943 ASSERT_EQ(1u, message_center()->NotificationCount());
946 ForceNotificationFlush(id
);
948 // Notification is removed.
949 ASSERT_EQ(0u, message_center()->NotificationCount());
952 TEST_F(MessageCenterImplTest
, ForceNotificationFlush_ComplexUpdate
) {
953 std::string
id1("id1");
954 std::string
id2("id2");
955 std::string
id3("id3");
957 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
959 // Add -> Update (with ID change) -> Remove
960 scoped_ptr
<Notification
> notification(CreateSimpleNotification(id1
));
961 message_center()->AddNotification(notification
.Pass());
962 notification
.reset(CreateSimpleNotification(id2
));
963 message_center()->UpdateNotification(id1
, notification
.Pass());
964 message_center()->RemoveNotification(id2
, false);
966 // Add -> Update (with ID change)
967 notification
.reset(CreateSimpleNotification(id2
));
968 message_center()->AddNotification(notification
.Pass());
969 notification
.reset(CreateSimpleNotification(id3
));
970 message_center()->UpdateNotification(id2
, notification
.Pass());
972 // Notification is not added since the message center has opened.
973 ASSERT_EQ(0u, message_center()->NotificationCount());
976 ForceNotificationFlush(id3
);
978 // Confirms the chagnes are applied.
979 ASSERT_EQ(1u, message_center()->NotificationCount());
982 TEST_F(MessageCenterImplTest
, ForceNotificationFlush_InconsistentUpdate
) {
983 std::string
id1("id1");
984 std::string
id2("id2");
985 std::string
id3("id3");
987 message_center()->SetVisibility(VISIBILITY_MESSAGE_CENTER
);
989 // Add -> Update (with ID change)
990 scoped_ptr
<Notification
> notification(CreateSimpleNotification(id1
));
991 message_center()->AddNotification(notification
.Pass());
992 notification
.reset(CreateSimpleNotification(id2
));
993 message_center()->UpdateNotification(id1
, notification
.Pass());
995 // Add (although the same ID exists) -> Update (with ID change) -> Remove
996 notification
.reset(CreateSimpleNotification(id2
));
997 message_center()->AddNotification(notification
.Pass());
998 notification
.reset(CreateSimpleNotification(id3
));
999 message_center()->UpdateNotification(id2
, notification
.Pass());
1000 message_center()->RemoveNotification(id3
, false);
1002 // Remove (although the ID has already removed)
1003 message_center()->RemoveNotification(id3
, false);
1005 // Notification is not added since the message center has opened.
1006 ASSERT_EQ(0u, message_center()->NotificationCount());
1008 // Forced to update.
1009 ForceNotificationFlush(id3
);
1011 // Confirms the chagnes are applied.
1012 ASSERT_EQ(0u, message_center()->NotificationCount());
1015 TEST_F(MessageCenterImplTest
, DisableNotificationsByNotifier
) {
1016 ASSERT_EQ(0u, message_center()->NotificationCount());
1017 message_center()->AddNotification(
1018 scoped_ptr
<Notification
>(
1019 CreateSimpleNotificationWithNotifierId("id1-1", "app1")));
1020 message_center()->AddNotification(
1021 scoped_ptr
<Notification
>(
1022 CreateSimpleNotificationWithNotifierId("id1-2", "app1")));
1023 message_center()->AddNotification(
1024 scoped_ptr
<Notification
>(
1025 CreateSimpleNotificationWithNotifierId("id2-1", "app2")));
1026 message_center()->AddNotification(
1027 scoped_ptr
<Notification
>(
1028 CreateSimpleNotificationWithNotifierId("id2-2", "app2")));
1029 message_center()->AddNotification(
1030 scoped_ptr
<Notification
>(
1031 CreateSimpleNotificationWithNotifierId("id2-3", "app2")));
1032 ASSERT_EQ(5u, message_center()->NotificationCount());
1034 // Removing all of app1's notifications should only leave app2's.
1035 message_center()->DisableNotificationsByNotifier(
1036 NotifierId(NotifierId::APPLICATION
, "app1"));
1037 ASSERT_EQ(3u, message_center()->NotificationCount());
1039 // Now we remove the remaining notifications.
1040 message_center()->DisableNotificationsByNotifier(
1041 NotifierId(NotifierId::APPLICATION
, "app2"));
1042 ASSERT_EQ(0u, message_center()->NotificationCount());
1045 TEST_F(MessageCenterImplTest
, NotifierEnabledChanged
) {
1046 ASSERT_EQ(0u, message_center()->NotificationCount());
1047 message_center()->AddNotification(
1048 scoped_ptr
<Notification
>(
1049 CreateSimpleNotificationWithNotifierId("id1-1", "app1")));
1050 message_center()->AddNotification(
1051 scoped_ptr
<Notification
>(
1052 CreateSimpleNotificationWithNotifierId("id1-2", "app1")));
1053 message_center()->AddNotification(
1054 scoped_ptr
<Notification
>(
1055 CreateSimpleNotificationWithNotifierId("id1-3", "app1")));
1056 message_center()->AddNotification(
1057 scoped_ptr
<Notification
>(
1058 CreateSimpleNotificationWithNotifierId("id2-1", "app2")));
1059 message_center()->AddNotification(
1060 scoped_ptr
<Notification
>(
1061 CreateSimpleNotificationWithNotifierId("id2-2", "app2")));
1062 message_center()->AddNotification(
1063 scoped_ptr
<Notification
>(
1064 CreateSimpleNotificationWithNotifierId("id2-3", "app2")));
1065 message_center()->AddNotification(
1066 scoped_ptr
<Notification
>(
1067 CreateSimpleNotificationWithNotifierId("id2-4", "app2")));
1068 message_center()->AddNotification(
1069 scoped_ptr
<Notification
>(
1070 CreateSimpleNotificationWithNotifierId("id2-5", "app2")));
1071 ASSERT_EQ(8u, message_center()->NotificationCount());
1073 // Enabling an extension should have no effect on the count.
1074 notifier_settings_observer()->NotifierEnabledChanged(
1075 NotifierId(NotifierId::APPLICATION
, "app1"), true);
1076 ASSERT_EQ(8u, message_center()->NotificationCount());
1078 // Removing all of app2's notifications should only leave app1's.
1079 notifier_settings_observer()->NotifierEnabledChanged(
1080 NotifierId(NotifierId::APPLICATION
, "app2"), false);
1081 ASSERT_EQ(3u, message_center()->NotificationCount());
1083 // Removal operations should be idempotent.
1084 notifier_settings_observer()->NotifierEnabledChanged(
1085 NotifierId(NotifierId::APPLICATION
, "app2"), false);
1086 ASSERT_EQ(3u, message_center()->NotificationCount());
1088 // Now we remove the remaining notifications.
1089 notifier_settings_observer()->NotifierEnabledChanged(
1090 NotifierId(NotifierId::APPLICATION
, "app1"), false);
1091 ASSERT_EQ(0u, message_center()->NotificationCount());
1094 } // namespace internal
1095 } // namespace message_center