OLD | NEW |
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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 using syncer::SyncData; | 23 using syncer::SyncData; |
24 using notifier::SyncedNotification; | 24 using notifier::SyncedNotification; |
25 using sync_pb::EntitySpecifics; | 25 using sync_pb::EntitySpecifics; |
26 using sync_pb::SyncedNotificationSpecifics; | 26 using sync_pb::SyncedNotificationSpecifics; |
27 | 27 |
28 namespace { | 28 namespace { |
29 const int kNotificationPriority = static_cast<int>( | 29 const int kNotificationPriority = static_cast<int>( |
30 message_center::LOW_PRIORITY); | 30 message_center::LOW_PRIORITY); |
31 | 31 |
32 bool UseRichNotifications() { | |
33 return message_center::IsRichNotificationEnabled(); | |
34 } | |
35 | |
36 } // namespace | 32 } // namespace |
37 | 33 |
38 namespace notifier { | 34 namespace notifier { |
39 | 35 |
40 class SyncedNotificationTest : public testing::Test { | 36 class SyncedNotificationTest : public testing::Test { |
41 public: | 37 public: |
42 SyncedNotificationTest() | 38 SyncedNotificationTest() |
43 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} | 39 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} |
44 virtual ~SyncedNotificationTest() {} | 40 virtual ~SyncedNotificationTest() {} |
45 | 41 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 sync_data1_, NULL, notification_manager())); | 246 sync_data1_, NULL, notification_manager())); |
251 | 247 |
252 // update with the sync data from notification2, and ensure they are equal. | 248 // update with the sync data from notification2, and ensure they are equal. |
253 notification5->Update(sync_data2_); | 249 notification5->Update(sync_data2_); |
254 EXPECT_TRUE(notification5->EqualsIgnoringReadState(*notification2_)); | 250 EXPECT_TRUE(notification5->EqualsIgnoringReadState(*notification2_)); |
255 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState()); | 251 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState()); |
256 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); | 252 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); |
257 } | 253 } |
258 | 254 |
259 TEST_F(SyncedNotificationTest, ShowTest) { | 255 TEST_F(SyncedNotificationTest, ShowTest) { |
260 | |
261 if (!UseRichNotifications()) | |
262 return; | |
263 | |
264 // Call the method under test using the pre-populated data. | 256 // Call the method under test using the pre-populated data. |
265 notification1_->Show(NULL); | 257 notification1_->Show(NULL); |
266 | 258 |
267 const Notification notification = notification_manager()->notification(); | 259 const Notification notification = notification_manager()->notification(); |
268 | 260 |
269 // Check the base fields of the notification. | 261 // Check the base fields of the notification. |
270 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification.type()); | 262 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification.type()); |
271 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification.title())); | 263 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification.title())); |
272 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification.message())); | 264 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification.message())); |
273 EXPECT_EQ(std::string(kExpectedOriginUrl), notification.origin_url().spec()); | 265 EXPECT_EQ(std::string(kExpectedOriginUrl), notification.origin_url().spec()); |
274 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification.replace_id())); | 266 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification.replace_id())); |
275 | 267 |
276 EXPECT_EQ(kFakeCreationTime, notification.timestamp().ToDoubleT()); | 268 EXPECT_EQ(kFakeCreationTime, notification.timestamp().ToDoubleT()); |
277 EXPECT_EQ(kNotificationPriority, notification.priority()); | 269 EXPECT_EQ(kNotificationPriority, notification.priority()); |
278 } | 270 } |
279 | 271 |
280 TEST_F(SyncedNotificationTest, DismissTest) { | 272 TEST_F(SyncedNotificationTest, DismissTest) { |
281 | 273 |
282 if (!UseRichNotifications()) | |
283 return; | |
284 | |
285 // Call the method under test using a dismissed notification. | 274 // Call the method under test using a dismissed notification. |
286 notification4_->Show(NULL); | 275 notification4_->Show(NULL); |
287 | 276 |
288 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); | 277 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); |
289 } | 278 } |
290 | 279 |
291 TEST_F(SyncedNotificationTest, CreateBitmapFetcherTest) { | 280 TEST_F(SyncedNotificationTest, CreateBitmapFetcherTest) { |
292 scoped_ptr<SyncedNotification> notification6; | 281 scoped_ptr<SyncedNotification> notification6; |
293 notification6.reset(new SyncedNotification( | 282 notification6.reset(new SyncedNotification( |
294 sync_data1_, NULL, notification_manager())); | 283 sync_data1_, NULL, notification_manager())); |
295 | 284 |
296 // Add two bitmaps to the queue. | 285 // Add two bitmaps to the queue. |
297 notification6->CreateBitmapFetcher(GURL(kIconUrl1)); | 286 notification6->CreateBitmapFetcher(GURL(kIconUrl1)); |
298 notification6->CreateBitmapFetcher(GURL(kIconUrl2)); | 287 notification6->CreateBitmapFetcher(GURL(kIconUrl2)); |
299 | 288 |
300 EXPECT_EQ(GURL(kIconUrl1), notification6->fetchers_[0]->url()); | 289 EXPECT_EQ(GURL(kIconUrl1), notification6->fetchers_[0]->url()); |
301 EXPECT_EQ(GURL(kIconUrl2), notification6->fetchers_[1]->url()); | 290 EXPECT_EQ(GURL(kIconUrl2), notification6->fetchers_[1]->url()); |
302 | 291 |
303 notification6->CreateBitmapFetcher(GURL(kIconUrl2)); | 292 notification6->CreateBitmapFetcher(GURL(kIconUrl2)); |
304 } | 293 } |
305 | 294 |
306 TEST_F(SyncedNotificationTest, OnFetchCompleteTest) { | 295 TEST_F(SyncedNotificationTest, OnFetchCompleteTest) { |
307 if (!UseRichNotifications()) | |
308 return; | |
309 | |
310 // Set up the internal state that FetchBitmaps() would have set. | 296 // Set up the internal state that FetchBitmaps() would have set. |
311 notification1_->notification_manager_ = notification_manager(); | 297 notification1_->notification_manager_ = notification_manager(); |
312 | 298 |
313 // Add the bitmaps to the queue for us to match up. | 299 // Add the bitmaps to the queue for us to match up. |
314 notification1_->CreateBitmapFetcher(GURL(kIconUrl1)); | 300 notification1_->CreateBitmapFetcher(GURL(kIconUrl1)); |
315 notification1_->CreateBitmapFetcher(GURL(kImageUrl1)); | 301 notification1_->CreateBitmapFetcher(GURL(kImageUrl1)); |
316 notification1_->CreateBitmapFetcher(GURL(kButtonOneIconUrl)); | 302 notification1_->CreateBitmapFetcher(GURL(kButtonOneIconUrl)); |
317 notification1_->CreateBitmapFetcher(GURL(kButtonTwoIconUrl)); | 303 notification1_->CreateBitmapFetcher(GURL(kButtonTwoIconUrl)); |
318 | 304 |
319 // Put some realistic looking bitmap data into the url_fetcher. | 305 // Put some realistic looking bitmap data into the url_fetcher. |
(...skipping 30 matching lines...) Expand all Loading... |
350 base::UTF16ToUTF8(notification_manager()->notification().message())); | 336 base::UTF16ToUTF8(notification_manager()->notification().message())); |
351 | 337 |
352 // TODO(petewil): Check that the bitmap in the notification is what we expect. | 338 // TODO(petewil): Check that the bitmap in the notification is what we expect. |
353 // This fails today, the type info is different. | 339 // This fails today, the type info is different. |
354 // EXPECT_TRUE(gfx::BitmapsAreEqual( | 340 // EXPECT_TRUE(gfx::BitmapsAreEqual( |
355 // image, notification1_->GetAppIconBitmap())); | 341 // image, notification1_->GetAppIconBitmap())); |
356 } | 342 } |
357 | 343 |
358 // TODO(petewil): Empty bitmap should count as a successful fetch. | 344 // TODO(petewil): Empty bitmap should count as a successful fetch. |
359 TEST_F(SyncedNotificationTest, EmptyBitmapTest) { | 345 TEST_F(SyncedNotificationTest, EmptyBitmapTest) { |
360 if (!UseRichNotifications()) | |
361 return; | |
362 | |
363 // Set up the internal state that FetchBitmaps() would have set. | 346 // Set up the internal state that FetchBitmaps() would have set. |
364 notification1_->notification_manager_ = notification_manager(); | 347 notification1_->notification_manager_ = notification_manager(); |
365 | 348 |
366 // Add the bitmaps to the queue for us to match up. | 349 // Add the bitmaps to the queue for us to match up. |
367 notification1_->CreateBitmapFetcher(GURL(kIconUrl1)); | 350 notification1_->CreateBitmapFetcher(GURL(kIconUrl1)); |
368 notification1_->CreateBitmapFetcher(GURL(kImageUrl1)); | 351 notification1_->CreateBitmapFetcher(GURL(kImageUrl1)); |
369 notification1_->CreateBitmapFetcher(GURL(kButtonOneIconUrl)); | 352 notification1_->CreateBitmapFetcher(GURL(kButtonOneIconUrl)); |
370 notification1_->CreateBitmapFetcher(GURL(kButtonTwoIconUrl)); | 353 notification1_->CreateBitmapFetcher(GURL(kButtonTwoIconUrl)); |
371 | 354 |
372 // Put some realistic looking bitmap data into the url_fetcher. | 355 // Put some realistic looking bitmap data into the url_fetcher. |
(...skipping 26 matching lines...) Expand all Loading... |
399 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, | 382 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, |
400 notification_manager()->notification().type()); | 383 notification_manager()->notification().type()); |
401 EXPECT_EQ(std::string(kTitle1), | 384 EXPECT_EQ(std::string(kTitle1), |
402 base::UTF16ToUTF8(notification_manager()->notification().title())); | 385 base::UTF16ToUTF8(notification_manager()->notification().title())); |
403 EXPECT_EQ( | 386 EXPECT_EQ( |
404 std::string(kText1), | 387 std::string(kText1), |
405 base::UTF16ToUTF8(notification_manager()->notification().message())); | 388 base::UTF16ToUTF8(notification_manager()->notification().message())); |
406 } | 389 } |
407 | 390 |
408 TEST_F(SyncedNotificationTest, ShowIfNewlyEnabledTest) { | 391 TEST_F(SyncedNotificationTest, ShowIfNewlyEnabledTest) { |
409 if (!UseRichNotifications()) | |
410 return; | |
411 | |
412 // Call the method using the wrong app id, nothing should get shown. | 392 // Call the method using the wrong app id, nothing should get shown. |
413 notification1_->ShowAllForAppId(NULL, kAppId2); | 393 notification1_->ShowAllForAppId(NULL, kAppId2); |
414 | 394 |
415 // Ensure no notification was generated and shown. | 395 // Ensure no notification was generated and shown. |
416 const Notification notification1 = notification_manager()->notification(); | 396 const Notification notification1 = notification_manager()->notification(); |
417 EXPECT_EQ(std::string(), base::UTF16ToUTF8(notification1.replace_id())); | 397 EXPECT_EQ(std::string(), base::UTF16ToUTF8(notification1.replace_id())); |
418 | 398 |
419 // Call the method under test using the pre-populated data. | 399 // Call the method under test using the pre-populated data. |
420 notification1_->ShowAllForAppId(NULL, kAppId1); | 400 notification1_->ShowAllForAppId(NULL, kAppId1); |
421 | 401 |
422 const Notification notification2 = notification_manager()->notification(); | 402 const Notification notification2 = notification_manager()->notification(); |
423 | 403 |
424 // Check the base fields of the notification. | 404 // Check the base fields of the notification. |
425 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification2.type()); | 405 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification2.type()); |
426 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification2.title())); | 406 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification2.title())); |
427 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification2.message())); | 407 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification2.message())); |
428 EXPECT_EQ(std::string(kExpectedOriginUrl), notification2.origin_url().spec()); | 408 EXPECT_EQ(std::string(kExpectedOriginUrl), notification2.origin_url().spec()); |
429 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification2.replace_id())); | 409 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification2.replace_id())); |
430 | 410 |
431 EXPECT_EQ(kFakeCreationTime, notification2.timestamp().ToDoubleT()); | 411 EXPECT_EQ(kFakeCreationTime, notification2.timestamp().ToDoubleT()); |
432 EXPECT_EQ(kNotificationPriority, notification2.priority()); | 412 EXPECT_EQ(kNotificationPriority, notification2.priority()); |
433 } | 413 } |
434 | 414 |
435 TEST_F(SyncedNotificationTest, HideIfNewlyRemovedTest) { | 415 TEST_F(SyncedNotificationTest, HideIfNewlyRemovedTest) { |
436 if (!UseRichNotifications()) | |
437 return; | |
438 | |
439 // Add the notification to the notification manger, so it exists before we | 416 // Add the notification to the notification manger, so it exists before we |
440 // we remove it. | 417 // we remove it. |
441 notification1_->Show(NULL); | 418 notification1_->Show(NULL); |
442 const Notification* found1 = notification_manager()->FindById(kKey1); | 419 const Notification* found1 = notification_manager()->FindById(kKey1); |
443 EXPECT_NE(reinterpret_cast<Notification*>(NULL), found1); | 420 EXPECT_NE(reinterpret_cast<Notification*>(NULL), found1); |
444 | 421 |
445 // Call the method under test using the pre-populated data. | 422 // Call the method under test using the pre-populated data. |
446 notification1_->HideAllForAppId(kAppId1); | 423 notification1_->HideAllForAppId(kAppId1); |
447 | 424 |
448 // Ensure the notification was removed from the notification manager | 425 // Ensure the notification was removed from the notification manager |
449 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); | 426 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); |
450 } | 427 } |
451 | 428 |
452 // TODO(petewil): Add a test for a notification being read and or deleted. | 429 // TODO(petewil): Add a test for a notification being read and or deleted. |
453 | 430 |
454 } // namespace notifier | 431 } // namespace notifier |
OLD | NEW |