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

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

Issue 2025613002: Reland: Show message center on lock screen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « ui/message_center/notification_list.cc ('k') | ui/message_center/views/message_center_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 message_center_.reset(new FakeMessageCenter());
34 notification_list_.reset(new NotificationList(message_center_.get()));
33 counter_ = 0; 35 counter_ = 0;
34 } 36 }
35 37
36 protected: 38 protected:
37 // Currently NotificationListTest doesn't care about some fields like title or 39 // 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 40 // message, so put a simple template on it. Returns the id of the new
39 // notification. 41 // notification.
40 std::string AddNotification( 42 std::string AddNotification(
41 const message_center::RichNotificationData& optional_fields) { 43 const message_center::RichNotificationData& optional_fields) {
42 std::string new_id; 44 std::string new_id;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 NotificationList* notification_list() { return notification_list_.get(); } 98 NotificationList* notification_list() { return notification_list_.get(); }
97 const NotificationBlockers& blockers() const { return blockers_; } 99 const NotificationBlockers& blockers() const { return blockers_; }
98 100
99 static const char kIdFormat[]; 101 static const char kIdFormat[];
100 static const char kTitleFormat[]; 102 static const char kTitleFormat[];
101 static const char kMessageFormat[]; 103 static const char kMessageFormat[];
102 static const char kDisplaySource[]; 104 static const char kDisplaySource[];
103 static const char kExtensionId[]; 105 static const char kExtensionId[];
104 106
105 private: 107 private:
108 std::unique_ptr<FakeMessageCenter> message_center_;
106 std::unique_ptr<NotificationList> notification_list_; 109 std::unique_ptr<NotificationList> notification_list_;
107 NotificationBlockers blockers_; 110 NotificationBlockers blockers_;
108 size_t counter_; 111 size_t counter_;
109 112
110 DISALLOW_COPY_AND_ASSIGN(NotificationListTest); 113 DISALLOW_COPY_AND_ASSIGN(NotificationListTest);
111 }; 114 };
112 115
113 bool IsInNotifications(const NotificationList::Notifications& notifications, 116 bool IsInNotifications(const NotificationList::Notifications& notifications,
114 const std::string& id) { 117 const std::string& id) {
115 for (NotificationList::Notifications::const_iterator iter = 118 for (NotificationList::Notifications::const_iterator iter =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 AddNotification(); 158 AddNotification();
156 EXPECT_EQ(2u, notification_list()->NotificationCount(blockers())); 159 EXPECT_EQ(2u, notification_list()->NotificationCount(blockers()));
157 } 160 }
158 161
159 TEST_F(NotificationListTest, MessageCenterVisible) { 162 TEST_F(NotificationListTest, MessageCenterVisible) {
160 AddNotification(); 163 AddNotification();
161 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers())); 164 EXPECT_EQ(1u, notification_list()->NotificationCount(blockers()));
162 ASSERT_EQ(1u, notification_list()->UnreadCount(blockers())); 165 ASSERT_EQ(1u, notification_list()->UnreadCount(blockers()));
163 ASSERT_EQ(1u, GetPopupCounts()); 166 ASSERT_EQ(1u, GetPopupCounts());
164 167
165 // Make the message center visible. It resets the unread count and popup 168 // Resets the unread count and popup counts.
166 // counts. 169 notification_list()->SetNotificationsShown(blockers(), NULL);
167 notification_list()->SetMessageCenterVisible(true, NULL);
168 ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 170 ASSERT_EQ(0u, notification_list()->UnreadCount(blockers()));
169 ASSERT_EQ(0u, GetPopupCounts()); 171 ASSERT_EQ(0u, GetPopupCounts());
170 } 172 }
171 173
172 TEST_F(NotificationListTest, UnreadCount) { 174 TEST_F(NotificationListTest, UnreadCount) {
173 std::string id0 = AddNotification(); 175 std::string id0 = AddNotification();
174 std::string id1 = AddNotification(); 176 std::string id1 = AddNotification();
175 ASSERT_EQ(2u, notification_list()->UnreadCount(blockers())); 177 ASSERT_EQ(2u, notification_list()->UnreadCount(blockers()));
176 178
177 notification_list()->MarkSinglePopupAsDisplayed(id0); 179 notification_list()->MarkSinglePopupAsDisplayed(id0);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 ASSERT_EQ(0u, notification_list()->UnreadCount(blockers())); 304 ASSERT_EQ(0u, notification_list()->UnreadCount(blockers()));
303 305
304 // Default priority has the limit on the number of the popups. 306 // Default priority has the limit on the number of the popups.
305 for (size_t i = 0; i <= kMaxVisiblePopupNotifications; ++i) 307 for (size_t i = 0; i <= kMaxVisiblePopupNotifications; ++i)
306 AddNotification(); 308 AddNotification();
307 EXPECT_EQ(kMaxVisiblePopupNotifications + 1, 309 EXPECT_EQ(kMaxVisiblePopupNotifications + 1,
308 notification_list()->NotificationCount(blockers())); 310 notification_list()->NotificationCount(blockers()));
309 EXPECT_EQ(kMaxVisiblePopupNotifications, GetPopupCounts()); 311 EXPECT_EQ(kMaxVisiblePopupNotifications, GetPopupCounts());
310 312
311 // Low priority: not visible to popups. 313 // Low priority: not visible to popups.
312 notification_list()->SetMessageCenterVisible(true, NULL); 314 notification_list()->SetNotificationsShown(blockers(), NULL);
313 notification_list()->SetMessageCenterVisible(false, NULL);
314 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers())); 315 EXPECT_EQ(0u, notification_list()->UnreadCount(blockers()));
315 AddPriorityNotification(LOW_PRIORITY); 316 AddPriorityNotification(LOW_PRIORITY);
316 EXPECT_EQ(kMaxVisiblePopupNotifications + 2, 317 EXPECT_EQ(kMaxVisiblePopupNotifications + 2,
317 notification_list()->NotificationCount(blockers())); 318 notification_list()->NotificationCount(blockers()));
318 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers())); 319 EXPECT_EQ(1u, notification_list()->UnreadCount(blockers()));
319 EXPECT_EQ(0u, GetPopupCounts()); 320 EXPECT_EQ(0u, GetPopupCounts());
320 321
321 // Minimum priority: doesn't update the unread count. 322 // Minimum priority: doesn't update the unread count.
322 AddPriorityNotification(MIN_PRIORITY); 323 AddPriorityNotification(MIN_PRIORITY);
323 EXPECT_EQ(kMaxVisiblePopupNotifications + 3, 324 EXPECT_EQ(kMaxVisiblePopupNotifications + 3,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 GetNotification(system_id)->SetSystemPriority(); 362 GetNotification(system_id)->SetSystemPriority();
362 363
363 EXPECT_EQ(2u, GetPopupCounts()); 364 EXPECT_EQ(2u, GetPopupCounts());
364 365
365 notification_list()->MarkSinglePopupAsDisplayed(normal_id); 366 notification_list()->MarkSinglePopupAsDisplayed(normal_id);
366 notification_list()->MarkSinglePopupAsDisplayed(system_id); 367 notification_list()->MarkSinglePopupAsDisplayed(system_id);
367 368
368 notification_list()->MarkSinglePopupAsShown(normal_id, false); 369 notification_list()->MarkSinglePopupAsShown(normal_id, false);
369 notification_list()->MarkSinglePopupAsShown(system_id, false); 370 notification_list()->MarkSinglePopupAsShown(system_id, false);
370 371
371 notification_list()->SetMessageCenterVisible(true, NULL); 372 notification_list()->SetNotificationsShown(blockers(), NULL);
372 notification_list()->SetMessageCenterVisible(false, NULL);
373 EXPECT_EQ(1u, GetPopupCounts()); 373 EXPECT_EQ(1u, GetPopupCounts());
374 374
375 // Mark as read -- emulation of mouse click. 375 // Mark as read -- emulation of mouse click.
376 notification_list()->MarkSinglePopupAsShown(system_id, true); 376 notification_list()->MarkSinglePopupAsShown(system_id, true);
377 EXPECT_EQ(0u, GetPopupCounts()); 377 EXPECT_EQ(0u, GetPopupCounts());
378 } 378 }
379 379
380 TEST_F(NotificationListTest, PriorityPromotion) { 380 TEST_F(NotificationListTest, PriorityPromotion) {
381 std::string id0 = AddPriorityNotification(LOW_PRIORITY); 381 std::string id0 = AddPriorityNotification(LOW_PRIORITY);
382 std::string replaced = id0 + "_replaced"; 382 std::string replaced = id0 + "_replaced";
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 NotifierId(), RichNotificationData(), NULL)); 662 NotifierId(), RichNotificationData(), NULL));
663 notification_list()->AddNotification(std::move(updated_notification)); 663 notification_list()->AddNotification(std::move(updated_notification));
664 664
665 EXPECT_FALSE(notification_list()->HasNotificationOfType( 665 EXPECT_FALSE(notification_list()->HasNotificationOfType(
666 id, message_center::NOTIFICATION_TYPE_SIMPLE)); 666 id, message_center::NOTIFICATION_TYPE_SIMPLE));
667 EXPECT_TRUE(notification_list()->HasNotificationOfType( 667 EXPECT_TRUE(notification_list()->HasNotificationOfType(
668 id, message_center::NOTIFICATION_TYPE_PROGRESS)); 668 id, message_center::NOTIFICATION_TYPE_PROGRESS));
669 } 669 }
670 670
671 } // namespace message_center 671 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/notification_list.cc ('k') | ui/message_center/views/message_center_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698