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

Side by Side Diff: chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: LGTM nits Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <string> 5 #include <string>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/notifications/notification.h" 10 #include "chrome/browser/notifications/notification.h"
(...skipping 28 matching lines...) Expand all
39 39
40 class SyncedNotificationTest : public testing::Test { 40 class SyncedNotificationTest : public testing::Test {
41 public: 41 public:
42 SyncedNotificationTest() 42 SyncedNotificationTest()
43 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} 43 : ui_thread_(content::BrowserThread::UI, &message_loop_) {}
44 virtual ~SyncedNotificationTest() {} 44 virtual ~SyncedNotificationTest() {}
45 45
46 // Methods from testing::Test. 46 // Methods from testing::Test.
47 47
48 virtual void SetUp() OVERRIDE { 48 virtual void SetUp() OVERRIDE {
49 notification_manager_.reset(new StubNotificationUIManager(GURL(
50 kSyncedNotificationsWelcomeOrigin)));
51
49 sync_data1_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, 52 sync_data1_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1,
50 kAppId1, kKey1, kUnread); 53 kAppId1, kKey1, kUnread);
51 sync_data2_ = CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl2, 54 sync_data2_ = CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl2,
52 kAppId2, kKey2, kUnread); 55 kAppId2, kKey2, kUnread);
53 // Notification 3 will have the same ID as notification1, but different 56 // Notification 3 will have the same ID as notification1, but different
54 // data inside. 57 // data inside.
55 sync_data3_ = CreateSyncData(kTitle3, kText3, kIconUrl3, kImageUrl3, 58 sync_data3_ = CreateSyncData(kTitle3, kText3, kIconUrl3, kImageUrl3,
56 kAppId1, kKey1, kUnread); 59 kAppId1, kKey1, kUnread);
57 // Notification 4 will be the same as 1, but the read state will be 'read'. 60 // Notification 4 will be the same as 1, but the read state will be 'read'.
58 sync_data4_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, 61 sync_data4_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1,
59 kAppId1, kKey1, kDismissed); 62 kAppId1, kKey1, kDismissed);
60 63
61 notification1_.reset(new SyncedNotification(sync_data1_)); 64 notification1_.reset(new SyncedNotification(
62 notification2_.reset(new SyncedNotification(sync_data2_)); 65 sync_data1_, NULL, notification_manager_.get()));
63 notification3_.reset(new SyncedNotification(sync_data3_)); 66 notification2_.reset(new SyncedNotification(
64 notification4_.reset(new SyncedNotification(sync_data4_)); 67 sync_data2_, NULL, notification_manager_.get()));
68 notification3_.reset(new SyncedNotification(
69 sync_data3_, NULL, notification_manager_.get()));
70 notification4_.reset(new SyncedNotification(
71 sync_data4_, NULL, notification_manager_.get()));
65 72
66 notification_manager_.reset(new StubNotificationUIManager(GURL(
67 kSyncedNotificationsWelcomeOrigin)));
68 } 73 }
69 74
70 virtual void TearDown() OVERRIDE { 75 virtual void TearDown() OVERRIDE {
71 notification_manager_.reset(); 76 notification_manager_.reset();
72 } 77 }
73 78
74 virtual void AddButtonBitmaps(SyncedNotification* notification, 79 virtual void AddButtonBitmaps(SyncedNotification* notification,
75 unsigned int how_many) { 80 unsigned int how_many) {
76 for (unsigned int i = 0; i < how_many; ++i) { 81 for (unsigned int i = 0; i < how_many; ++i) {
77 notification->button_bitmaps_.push_back(gfx::Image()); 82 notification->button_bitmaps_.push_back(gfx::Image());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 151
147 // TODO(petewil): Improve ctor to pass in an image and type so this test can 152 // TODO(petewil): Improve ctor to pass in an image and type so this test can
148 // pass on actual data. 153 // pass on actual data.
149 TEST_F(SyncedNotificationTest, GetImageURLTest) { 154 TEST_F(SyncedNotificationTest, GetImageURLTest) {
150 GURL found_image_url = notification1_->GetImageUrl(); 155 GURL found_image_url = notification1_->GetImageUrl();
151 GURL expected_image_url = GURL(kImageUrl1); 156 GURL expected_image_url = GURL(kImageUrl1);
152 157
153 EXPECT_EQ(expected_image_url, found_image_url); 158 EXPECT_EQ(expected_image_url, found_image_url);
154 } 159 }
155 160
156 // TODO(petewil): test with a multi-line message
157 TEST_F(SyncedNotificationTest, GetTextTest) { 161 TEST_F(SyncedNotificationTest, GetTextTest) {
158 std::string found_text = notification1_->GetText(); 162 std::string found_text = notification1_->GetText();
159 std::string expected_text(kText1); 163 std::string expected_text(kText1);
160 164
161 EXPECT_EQ(expected_text, found_text); 165 EXPECT_EQ(expected_text, found_text);
162 } 166 }
163 167
164 TEST_F(SyncedNotificationTest, GetCreationTimeTest) { 168 TEST_F(SyncedNotificationTest, GetCreationTimeTest) {
165 uint64 found_time = notification1_->GetCreationTime(); 169 uint64 found_time = notification1_->GetCreationTime();
166 EXPECT_EQ(kFakeCreationTime, found_time); 170 EXPECT_EQ(kFakeCreationTime, found_time);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 TEST_F(SyncedNotificationTest, EqualsIgnoringReadStateTest) { 239 TEST_F(SyncedNotificationTest, EqualsIgnoringReadStateTest) {
236 EXPECT_TRUE(notification1_->EqualsIgnoringReadState(*notification1_)); 240 EXPECT_TRUE(notification1_->EqualsIgnoringReadState(*notification1_));
237 EXPECT_TRUE(notification2_->EqualsIgnoringReadState(*notification2_)); 241 EXPECT_TRUE(notification2_->EqualsIgnoringReadState(*notification2_));
238 EXPECT_FALSE(notification1_->EqualsIgnoringReadState(*notification2_)); 242 EXPECT_FALSE(notification1_->EqualsIgnoringReadState(*notification2_));
239 EXPECT_FALSE(notification1_->EqualsIgnoringReadState(*notification3_)); 243 EXPECT_FALSE(notification1_->EqualsIgnoringReadState(*notification3_));
240 EXPECT_TRUE(notification1_->EqualsIgnoringReadState(*notification4_)); 244 EXPECT_TRUE(notification1_->EqualsIgnoringReadState(*notification4_));
241 } 245 }
242 246
243 TEST_F(SyncedNotificationTest, UpdateTest) { 247 TEST_F(SyncedNotificationTest, UpdateTest) {
244 scoped_ptr<SyncedNotification> notification5; 248 scoped_ptr<SyncedNotification> notification5;
245 notification5.reset(new SyncedNotification(sync_data1_)); 249 notification5.reset(new SyncedNotification(
250 sync_data1_, NULL, notification_manager()));
246 251
247 // update with the sync data from notification2, and ensure they are equal. 252 // update with the sync data from notification2, and ensure they are equal.
248 notification5->Update(sync_data2_); 253 notification5->Update(sync_data2_);
249 EXPECT_TRUE(notification5->EqualsIgnoringReadState(*notification2_)); 254 EXPECT_TRUE(notification5->EqualsIgnoringReadState(*notification2_));
250 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState()); 255 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState());
251 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); 256 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_));
252 } 257 }
253 258
254 TEST_F(SyncedNotificationTest, ShowTest) { 259 TEST_F(SyncedNotificationTest, ShowTest) {
255 260
256 if (!UseRichNotifications()) 261 if (!UseRichNotifications())
257 return; 262 return;
258 263
259 // Call the method under test using the pre-populated data. 264 // Call the method under test using the pre-populated data.
260 notification1_->Show(notification_manager(), NULL, NULL); 265 notification1_->Show(NULL);
261 266
262 const Notification notification = notification_manager()->notification(); 267 const Notification notification = notification_manager()->notification();
263 268
264 // Check the base fields of the notification. 269 // Check the base fields of the notification.
265 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification.type()); 270 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification.type());
266 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification.title())); 271 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification.title()));
267 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification.message())); 272 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification.message()));
268 EXPECT_EQ(std::string(kExpectedOriginUrl), notification.origin_url().spec()); 273 EXPECT_EQ(std::string(kExpectedOriginUrl), notification.origin_url().spec());
269 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification.replace_id())); 274 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification.replace_id()));
270 275
271 EXPECT_EQ(kFakeCreationTime, notification.timestamp().ToDoubleT()); 276 EXPECT_EQ(kFakeCreationTime, notification.timestamp().ToDoubleT());
272 EXPECT_EQ(kNotificationPriority, notification.priority()); 277 EXPECT_EQ(kNotificationPriority, notification.priority());
273 } 278 }
274 279
275 TEST_F(SyncedNotificationTest, DismissTest) { 280 TEST_F(SyncedNotificationTest, DismissTest) {
276 281
277 if (!UseRichNotifications()) 282 if (!UseRichNotifications())
278 return; 283 return;
279 284
280 // Call the method under test using a dismissed notification. 285 // Call the method under test using a dismissed notification.
281 notification4_->Show(notification_manager(), NULL, NULL); 286 notification4_->Show(NULL);
282 287
283 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); 288 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id());
284 } 289 }
285 290
286 TEST_F(SyncedNotificationTest, AddBitmapToFetchQueueTest) { 291 TEST_F(SyncedNotificationTest, CreateBitmapFetcherTest) {
287 scoped_ptr<SyncedNotification> notification6; 292 scoped_ptr<SyncedNotification> notification6;
288 notification6.reset(new SyncedNotification(sync_data1_)); 293 notification6.reset(new SyncedNotification(
294 sync_data1_, NULL, notification_manager()));
289 295
290 // Add two bitmaps to the queue. 296 // Add two bitmaps to the queue.
291 notification6->AddBitmapToFetchQueue(GURL(kIconUrl1)); 297 notification6->CreateBitmapFetcher(GURL(kIconUrl1));
292 notification6->AddBitmapToFetchQueue(GURL(kIconUrl2)); 298 notification6->CreateBitmapFetcher(GURL(kIconUrl2));
293 299
294 EXPECT_EQ(GURL(kIconUrl1), notification6->fetchers_[0]->url()); 300 EXPECT_EQ(GURL(kIconUrl1), notification6->fetchers_[0]->url());
295 EXPECT_EQ(GURL(kIconUrl2), notification6->fetchers_[1]->url()); 301 EXPECT_EQ(GURL(kIconUrl2), notification6->fetchers_[1]->url());
296 302
297 notification6->AddBitmapToFetchQueue(GURL(kIconUrl2)); 303 notification6->CreateBitmapFetcher(GURL(kIconUrl2));
298 } 304 }
299 305
300 TEST_F(SyncedNotificationTest, OnFetchCompleteTest) { 306 TEST_F(SyncedNotificationTest, OnFetchCompleteTest) {
301 if (!UseRichNotifications()) 307 if (!UseRichNotifications())
302 return; 308 return;
303 309
304 // Set up the internal state that FetchBitmaps() would have set. 310 // Set up the internal state that FetchBitmaps() would have set.
305 notification1_->notification_manager_ = notification_manager(); 311 notification1_->notification_manager_ = notification_manager();
306 312
307 // Add the bitmaps to the queue for us to match up. 313 // Add the bitmaps to the queue for us to match up.
308 notification1_->AddBitmapToFetchQueue(GURL(kIconUrl1)); 314 notification1_->CreateBitmapFetcher(GURL(kIconUrl1));
309 notification1_->AddBitmapToFetchQueue(GURL(kImageUrl1)); 315 notification1_->CreateBitmapFetcher(GURL(kImageUrl1));
310 notification1_->AddBitmapToFetchQueue(GURL(kButtonOneIconUrl)); 316 notification1_->CreateBitmapFetcher(GURL(kButtonOneIconUrl));
311 notification1_->AddBitmapToFetchQueue(GURL(kButtonTwoIconUrl)); 317 notification1_->CreateBitmapFetcher(GURL(kButtonTwoIconUrl));
312 318
313 // Put some realistic looking bitmap data into the url_fetcher. 319 // Put some realistic looking bitmap data into the url_fetcher.
314 SkBitmap bitmap; 320 SkBitmap bitmap;
315 321
316 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. 322 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
317 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); 323 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
318 bitmap.allocPixels(); 324 bitmap.allocPixels();
319 bitmap.eraseColor(SK_ColorGREEN); 325 bitmap.eraseColor(SK_ColorGREEN);
320 326
321 // Allocate the button_bitmaps_ array as the calling function normally would. 327 // Allocate the button_bitmaps_ array as the calling function normally would.
(...skipping 20 matching lines...) Expand all
342 EXPECT_EQ( 348 EXPECT_EQ(
343 std::string(kText1), 349 std::string(kText1),
344 base::UTF16ToUTF8(notification_manager()->notification().message())); 350 base::UTF16ToUTF8(notification_manager()->notification().message()));
345 351
346 // TODO(petewil): Check that the bitmap in the notification is what we expect. 352 // TODO(petewil): Check that the bitmap in the notification is what we expect.
347 // This fails today, the type info is different. 353 // This fails today, the type info is different.
348 // EXPECT_TRUE(gfx::BitmapsAreEqual( 354 // EXPECT_TRUE(gfx::BitmapsAreEqual(
349 // image, notification1_->GetAppIconBitmap())); 355 // image, notification1_->GetAppIconBitmap()));
350 } 356 }
351 357
352 358 // TODO(petewil): Empty bitmap should count as a successful fetch.
353 TEST_F(SyncedNotificationTest, EmptyBitmapTest) { 359 TEST_F(SyncedNotificationTest, EmptyBitmapTest) {
354 if (!UseRichNotifications()) 360 if (!UseRichNotifications())
355 return; 361 return;
356 362
357 // Set up the internal state that FetchBitmaps() would have set. 363 // Set up the internal state that FetchBitmaps() would have set.
358 notification1_->notification_manager_ = notification_manager(); 364 notification1_->notification_manager_ = notification_manager();
359 365
360 // Add the bitmaps to the queue for us to match up. 366 // Add the bitmaps to the queue for us to match up.
361 notification1_->AddBitmapToFetchQueue(GURL(kIconUrl1)); 367 notification1_->CreateBitmapFetcher(GURL(kIconUrl1));
362 notification1_->AddBitmapToFetchQueue(GURL(kImageUrl1)); 368 notification1_->CreateBitmapFetcher(GURL(kImageUrl1));
363 notification1_->AddBitmapToFetchQueue(GURL(kButtonOneIconUrl)); 369 notification1_->CreateBitmapFetcher(GURL(kButtonOneIconUrl));
364 notification1_->AddBitmapToFetchQueue(GURL(kButtonTwoIconUrl)); 370 notification1_->CreateBitmapFetcher(GURL(kButtonTwoIconUrl));
365 371
366 // Put some realistic looking bitmap data into the url_fetcher. 372 // Put some realistic looking bitmap data into the url_fetcher.
367 SkBitmap bitmap; 373 SkBitmap bitmap;
368 SkBitmap empty_bitmap; 374 SkBitmap empty_bitmap;
369 375
370 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. 376 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
371 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); 377 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
372 bitmap.allocPixels(); 378 bitmap.allocPixels();
373 bitmap.eraseColor(SK_ColorGREEN); 379 bitmap.eraseColor(SK_ColorGREEN);
374 380
(...skipping 17 matching lines...) Expand all
392 // Since we check Show() thoroughly in its own test, we only check cursorily. 398 // Since we check Show() thoroughly in its own test, we only check cursorily.
393 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, 399 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE,
394 notification_manager()->notification().type()); 400 notification_manager()->notification().type());
395 EXPECT_EQ(std::string(kTitle1), 401 EXPECT_EQ(std::string(kTitle1),
396 base::UTF16ToUTF8(notification_manager()->notification().title())); 402 base::UTF16ToUTF8(notification_manager()->notification().title()));
397 EXPECT_EQ( 403 EXPECT_EQ(
398 std::string(kText1), 404 std::string(kText1),
399 base::UTF16ToUTF8(notification_manager()->notification().message())); 405 base::UTF16ToUTF8(notification_manager()->notification().message()));
400 } 406 }
401 407
408 TEST_F(SyncedNotificationTest, ShowIfNewlyEnabledTest) {
409 if (!UseRichNotifications())
410 return;
411
412 // Call the method using the wrong app id, nothing should get shown.
413 notification1_->ShowAllForAppId(NULL, kAppId2);
414
415 // Ensure no notification was generated and shown.
416 const Notification notification1 = notification_manager()->notification();
417 EXPECT_EQ(std::string(), base::UTF16ToUTF8(notification1.replace_id()));
418
419 // Call the method under test using the pre-populated data.
420 notification1_->ShowAllForAppId(NULL, kAppId1);
421
422 const Notification notification2 = notification_manager()->notification();
423
424 // Check the base fields of the notification.
425 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification2.type());
426 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification2.title()));
427 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification2.message()));
428 EXPECT_EQ(std::string(kExpectedOriginUrl), notification2.origin_url().spec());
429 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification2.replace_id()));
430
431 EXPECT_EQ(kFakeCreationTime, notification2.timestamp().ToDoubleT());
432 EXPECT_EQ(kNotificationPriority, notification2.priority());
433 }
434
435 TEST_F(SyncedNotificationTest, HideIfNewlyRemovedTest) {
436 if (!UseRichNotifications())
437 return;
438
439 // Add the notification to the notification manger, so it exists before we
440 // we remove it.
441 notification1_->Show(NULL);
442 const Notification* found1 = notification_manager()->FindById(kKey1);
443 EXPECT_NE(reinterpret_cast<Notification*>(NULL), found1);
444
445 // Call the method under test using the pre-populated data.
446 notification1_->HideAllForAppId(kAppId1);
447
448 // Ensure the notification was removed from the notification manager
449 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id());
450 }
451
402 // TODO(petewil): Add a test for a notification being read and or deleted. 452 // TODO(petewil): Add a test for a notification being read and or deleted.
403 453
404 } // namespace notifier 454 } // namespace notifier
OLDNEW
« no previous file with comments | « chrome/browser/notifications/sync_notifier/synced_notification_app_info_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698