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

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

Issue 15582004: Move NotificationDelegate into message_center. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Win browsertests. Created 7 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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/i18n/time_formatting.h" 8 #include "base/i18n/time_formatting.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 15 matching lines...) Expand all
26 counter_ = 0; 26 counter_ = 0;
27 } 27 }
28 28
29 protected: 29 protected:
30 // Currently NotificationListTest doesn't care about some fields like title or 30 // Currently NotificationListTest doesn't care about some fields like title or
31 // message, so put a simple template on it. Returns the id of the new 31 // message, so put a simple template on it. Returns the id of the new
32 // notification. 32 // notification.
33 std::string AddNotification(const base::DictionaryValue* optional_fields) { 33 std::string AddNotification(const base::DictionaryValue* optional_fields) {
34 std::string new_id = base::StringPrintf(kIdFormat, counter_); 34 std::string new_id = base::StringPrintf(kIdFormat, counter_);
35 notification_list_->AddNotification( 35 notification_list_->AddNotification(
36 message_center::NOTIFICATION_TYPE_SIMPLE, new_id, 36 message_center::NOTIFICATION_TYPE_SIMPLE,
37 new_id,
37 UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)), 38 UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)),
38 UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)), 39 UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)),
39 UTF8ToUTF16(kDisplaySource), kExtensionId, 40 UTF8ToUTF16(kDisplaySource),
40 optional_fields); 41 kExtensionId,
42 optional_fields,
43 NULL);
41 counter_++; 44 counter_++;
42 return new_id; 45 return new_id;
43 } 46 }
44 47
45 // Utility methods of AddNotification. 48 // Utility methods of AddNotification.
46 std::string AddPriorityNotification(NotificationPriority priority) { 49 std::string AddPriorityNotification(NotificationPriority priority) {
47 base::DictionaryValue optional; 50 base::DictionaryValue optional;
48 optional.SetInteger(message_center::kPriorityKey, 51 optional.SetInteger(message_center::kPriorityKey,
49 static_cast<int>(priority)); 52 static_cast<int>(priority));
50 return AddNotification(&optional); 53 return AddNotification(&optional);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 id0, replaced, UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), NULL); 168 id0, replaced, UTF8ToUTF16("newtitle"), UTF8ToUTF16("newbody"), NULL);
166 EXPECT_EQ(1u, notification_list()->NotificationCount()); 169 EXPECT_EQ(1u, notification_list()->NotificationCount());
167 const NotificationList::Notifications& notifications = 170 const NotificationList::Notifications& notifications =
168 notification_list()->GetNotifications(); 171 notification_list()->GetNotifications();
169 EXPECT_EQ(replaced, (*notifications.begin())->id()); 172 EXPECT_EQ(replaced, (*notifications.begin())->id());
170 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title()); 173 EXPECT_EQ(UTF8ToUTF16("newtitle"), (*notifications.begin())->title());
171 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message()); 174 EXPECT_EQ(UTF8ToUTF16("newbody"), (*notifications.begin())->message());
172 } 175 }
173 176
174 TEST_F(NotificationListTest, GetNotificationsBySourceOrExtensions) { 177 TEST_F(NotificationListTest, GetNotificationsBySourceOrExtensions) {
175 notification_list()->AddNotification( 178 notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
176 message_center::NOTIFICATION_TYPE_SIMPLE, "id0", UTF8ToUTF16("title0"), 179 "id0",
177 UTF8ToUTF16("message0"), UTF8ToUTF16("source0"), "ext0", NULL); 180 UTF8ToUTF16("title0"),
178 notification_list()->AddNotification( 181 UTF8ToUTF16("message0"),
179 message_center::NOTIFICATION_TYPE_SIMPLE, "id1", UTF8ToUTF16("title1"), 182 UTF8ToUTF16("source0"),
180 UTF8ToUTF16("message1"), UTF8ToUTF16("source0"), "ext0", NULL); 183 "ext0",
181 notification_list()->AddNotification( 184 NULL,
182 message_center::NOTIFICATION_TYPE_SIMPLE, "id2", UTF8ToUTF16("title1"), 185 NULL);
183 UTF8ToUTF16("message1"), UTF8ToUTF16("source1"), "ext0", NULL); 186 notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
184 notification_list()->AddNotification( 187 "id1",
185 message_center::NOTIFICATION_TYPE_SIMPLE, "id3", UTF8ToUTF16("title1"), 188 UTF8ToUTF16("title1"),
186 UTF8ToUTF16("message1"), UTF8ToUTF16("source2"), "ext1", NULL); 189 UTF8ToUTF16("message1"),
190 UTF8ToUTF16("source0"),
191 "ext0",
192 NULL,
193 NULL);
194 notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
195 "id2",
196 UTF8ToUTF16("title1"),
197 UTF8ToUTF16("message1"),
198 UTF8ToUTF16("source1"),
199 "ext0",
200 NULL,
201 NULL);
202 notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE,
203 "id3",
204 UTF8ToUTF16("title1"),
205 UTF8ToUTF16("message1"),
206 UTF8ToUTF16("source2"),
207 "ext1",
208 NULL,
209 NULL);
187 210
188 NotificationList::Notifications by_source = 211 NotificationList::Notifications by_source =
189 notification_list()->GetNotificationsBySource("id0"); 212 notification_list()->GetNotificationsBySource("id0");
190 EXPECT_TRUE(IsInNotifications(by_source, "id0")); 213 EXPECT_TRUE(IsInNotifications(by_source, "id0"));
191 EXPECT_TRUE(IsInNotifications(by_source, "id1")); 214 EXPECT_TRUE(IsInNotifications(by_source, "id1"));
192 EXPECT_FALSE(IsInNotifications(by_source, "id2")); 215 EXPECT_FALSE(IsInNotifications(by_source, "id2"));
193 EXPECT_FALSE(IsInNotifications(by_source, "id3")); 216 EXPECT_FALSE(IsInNotifications(by_source, "id3"));
194 217
195 NotificationList::Notifications by_extension = 218 NotificationList::Notifications by_extension =
196 notification_list()->GetNotificationsByExtension("id0"); 219 notification_list()->GetNotificationsByExtension("id0");
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 notification_list()->SetQuietMode(false); 518 notification_list()->SetQuietMode(false);
496 AddNotification(NULL); 519 AddNotification(NULL);
497 EXPECT_EQ(4u, notification_list()->NotificationCount()); 520 EXPECT_EQ(4u, notification_list()->NotificationCount());
498 EXPECT_EQ(1u, GetPopupCounts()); 521 EXPECT_EQ(1u, GetPopupCounts());
499 522
500 // TODO(mukai): Add test of quiet mode with expiration. 523 // TODO(mukai): Add test of quiet mode with expiration.
501 } 524 }
502 525
503 } // namespace test 526 } // namespace test
504 } // namespace message_center 527 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698