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

Side by Side Diff: ui/message_center/notification_list_unittest.cc

Issue 1986493002: Show message center on lock screen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/notification_list.h" 5 #include "ui/message_center/notification_list.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/i18n/time_formatting.h" 11 #include "base/i18n/time_formatting.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/message_center/fake_message_center.h"
17 #include "ui/message_center/message_center_style.h" 18 #include "ui/message_center/message_center_style.h"
18 #include "ui/message_center/notification_blocker.h" 19 #include "ui/message_center/notification_blocker.h"
19 #include "ui/message_center/notification_types.h" 20 #include "ui/message_center/notification_types.h"
20 #include "ui/message_center/notifier_settings.h" 21 #include "ui/message_center/notifier_settings.h"
21 22
22 using base::UTF8ToUTF16; 23 using base::UTF8ToUTF16;
23 24
24 namespace message_center { 25 namespace message_center {
25 26
26 class NotificationListTest : public testing::Test { 27 class NotificationListTest : public testing::Test {
27 public: 28 public:
28 NotificationListTest() {} 29 NotificationListTest() {}
29 ~NotificationListTest() override {} 30 ~NotificationListTest() override {}
30 31
31 void SetUp() override { 32 void SetUp() override {
32 notification_list_.reset(new NotificationList()); 33 notification_list_.reset(new NotificationList(new FakeMessageCenter()));
33 counter_ = 0; 34 counter_ = 0;
34 } 35 }
35 36
36 protected: 37 protected:
37 // Currently NotificationListTest doesn't care about some fields like title or 38 // Currently NotificationListTest doesn't care about some fields like title or
38 // message, so put a simple template on it. Returns the id of the new 39 // message, so put a simple template on it. Returns the id of the new
39 // notification. 40 // notification.
40 std::string AddNotification( 41 std::string AddNotification(
41 const message_center::RichNotificationData& optional_fields) { 42 const message_center::RichNotificationData& optional_fields) {
42 std::string new_id; 43 std::string new_id;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 AddNotification(); 156 AddNotification();
156 EXPECT_EQ(2u, notification_list()->NotificationCount(blockers())); 157 EXPECT_EQ(2u, notification_list()->NotificationCount(blockers()));
157 } 158 }
158 159
159 TEST_F(NotificationListTest, MessageCenterVisible) { 160 TEST_F(NotificationListTest, MessageCenterVisible) {
160 AddNotification(); 161 AddNotification();
161 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 162 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers()));
162 ASSERT_EQ(1u, notification_list()->UnreadCount(blockers())); 163 ASSERT_EQ(1u, notification_list()->UnreadCount(blockers()));
163 ASSERT_EQ(1u, GetPopupCounts()); 164 ASSERT_EQ(1u, GetPopupCounts());
164 165
165 // Make the message center visible. It resets the unread count and popup 166 // Resets the unread count and popup counts.
166 // counts. 167 notification_list()->SetNotificationsShown(blockers(), NULL);
167 notification_list()->SetMessageCenterVisible(true, NULL);
168 ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 168 ASSERT_EQ(0u, notification_list()->UnreadCount(blockers()));
169 ASSERT_EQ(0u, GetPopupCounts()); 169 ASSERT_EQ(0u, GetPopupCounts());
170 } 170 }
171 171
172 TEST_F(NotificationListTest, UnreadCount) { 172 TEST_F(NotificationListTest, UnreadCount) {
173 std::string id0 = AddNotification(); 173 std::string id0 = AddNotification();
174 std::string id1 = AddNotification(); 174 std::string id1 = AddNotification();
175 ASSERT_EQ(2u, notification_list()->UnreadCount(blockers())); 175 ASSERT_EQ(2u, notification_list()->UnreadCount(blockers()));
176 176
177 notification_list()->MarkSinglePopupAsDisplayed(id0); 177 notification_list()->MarkSinglePopupAsDisplayed(id0);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 302 ASSERT_EQ(0u, notification_list()->UnreadCount(blockers()));
303 303
304 // Default priority has the limit on the number of the popups. 304 // Default priority has the limit on the number of the popups.
305 for (size_t i = 0; i <= kMaxVisiblePopupNotifications; ++i) 305 for (size_t i = 0; i <= kMaxVisiblePopupNotifications; ++i)
306 AddNotification(); 306 AddNotification();
307 EXPECT_EQ(kMaxVisiblePopupNotifications + 1, 307 EXPECT_EQ(kMaxVisiblePopupNotifications + 1,
308 notification_list()->NotificationCount(blockers())); 308 notification_list()->NotificationCount(blockers()));
309 EXPECT_EQ(kMaxVisiblePopupNotifications, GetPopupCounts()); 309 EXPECT_EQ(kMaxVisiblePopupNotifications, GetPopupCounts());
310 310
311 // Low priority: not visible to popups. 311 // Low priority: not visible to popups.
312 notification_list()->SetMessageCenterVisible(true, NULL); 312 notification_list()->SetNotificationsShown(blockers(), NULL);
313 notification_list()->SetMessageCenterVisible(false, NULL);
314 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); 313 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers()));
315 AddPriorityNotification(LOW_PRIORITY); 314 AddPriorityNotification(LOW_PRIORITY);
316 EXPECT_EQ(kMaxVisiblePopupNotifications + 2, 315 EXPECT_EQ(kMaxVisiblePopupNotifications + 2,
317 notification_list()->NotificationCount(blockers())); 316 notification_list()->NotificationCount(blockers()));
318 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 317 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers()));
319 EXPECT_EQ(0u, GetPopupCounts()); 318 EXPECT_EQ(0u, GetPopupCounts());
320 319
321 // Minimum priority: doesn't update the unread count. 320 // Minimum priority: doesn't update the unread count.
322 AddPriorityNotification(MIN_PRIORITY); 321 AddPriorityNotification(MIN_PRIORITY);
323 EXPECT_EQ(kMaxVisiblePopupNotifications + 3, 322 EXPECT_EQ(kMaxVisiblePopupNotifications + 3,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 GetNotification(system_id)->SetSystemPriority(); 360 GetNotification(system_id)->SetSystemPriority();
362 361
363 EXPECT_EQ(2u, GetPopupCounts()); 362 EXPECT_EQ(2u, GetPopupCounts());
364 363
365 notification_list()->MarkSinglePopupAsDisplayed(normal_id); 364 notification_list()->MarkSinglePopupAsDisplayed(normal_id);
366 notification_list()->MarkSinglePopupAsDisplayed(system_id); 365 notification_list()->MarkSinglePopupAsDisplayed(system_id);
367 366
368 notification_list()->MarkSinglePopupAsShown(normal_id, false); 367 notification_list()->MarkSinglePopupAsShown(normal_id, false);
369 notification_list()->MarkSinglePopupAsShown(system_id, false); 368 notification_list()->MarkSinglePopupAsShown(system_id, false);
370 369
371 notification_list()->SetMessageCenterVisible(true, NULL); 370 notification_list()->SetNotificationsShown(blockers(), NULL);
372 notification_list()->SetMessageCenterVisible(false, NULL);
373 EXPECT_EQ(1u, GetPopupCounts()); 371 EXPECT_EQ(1u, GetPopupCounts());
374 372
375 // Mark as read -- emulation of mouse click. 373 // Mark as read -- emulation of mouse click.
376 notification_list()->MarkSinglePopupAsShown(system_id, true); 374 notification_list()->MarkSinglePopupAsShown(system_id, true);
377 EXPECT_EQ(0u, GetPopupCounts()); 375 EXPECT_EQ(0u, GetPopupCounts());
378 } 376 }
379 377
380 TEST_F(NotificationListTest, PriorityPromotion) { 378 TEST_F(NotificationListTest, PriorityPromotion) {
381 std::string id0 = AddPriorityNotification(LOW_PRIORITY); 379 std::string id0 = AddPriorityNotification(LOW_PRIORITY);
382 std::string replaced = id0 + "_replaced"; 380 std::string replaced = id0 + "_replaced";
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 NotifierId(), RichNotificationData(), NULL)); 660 NotifierId(), RichNotificationData(), NULL));
663 notification_list()->AddNotification(std::move(updated_notification)); 661 notification_list()->AddNotification(std::move(updated_notification));
664 662
665 EXPECT_FALSE(notification_list()->HasNotificationOfType( 663 EXPECT_FALSE(notification_list()->HasNotificationOfType(
666 id, message_center::NOTIFICATION_TYPE_SIMPLE)); 664 id, message_center::NOTIFICATION_TYPE_SIMPLE));
667 EXPECT_TRUE(notification_list()->HasNotificationOfType( 665 EXPECT_TRUE(notification_list()->HasNotificationOfType(
668 id, message_center::NOTIFICATION_TYPE_PROGRESS)); 666 id, message_center::NOTIFICATION_TYPE_PROGRESS));
669 } 667 }
670 668
671 } // namespace message_center 669 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698