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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 // TODO(petewil): Improve ctor to pass in an image and type so this test can | 147 // TODO(petewil): Improve ctor to pass in an image and type so this test can |
148 // pass on actual data. | 148 // pass on actual data. |
149 TEST_F(SyncedNotificationTest, GetImageURLTest) { | 149 TEST_F(SyncedNotificationTest, GetImageURLTest) { |
150 GURL found_image_url = notification1_->GetImageUrl(); | 150 GURL found_image_url = notification1_->GetImageUrl(); |
151 GURL expected_image_url = GURL(kImageUrl1); | 151 GURL expected_image_url = GURL(kImageUrl1); |
152 | 152 |
153 EXPECT_EQ(expected_image_url, found_image_url); | 153 EXPECT_EQ(expected_image_url, found_image_url); |
154 } | 154 } |
155 | 155 |
156 // TODO(petewil): test with a multi-line message | |
157 TEST_F(SyncedNotificationTest, GetTextTest) { | 156 TEST_F(SyncedNotificationTest, GetTextTest) { |
158 std::string found_text = notification1_->GetText(); | 157 std::string found_text = notification1_->GetText(); |
159 std::string expected_text(kText1); | 158 std::string expected_text(kText1); |
160 | 159 |
161 EXPECT_EQ(expected_text, found_text); | 160 EXPECT_EQ(expected_text, found_text); |
162 } | 161 } |
163 | 162 |
164 TEST_F(SyncedNotificationTest, GetCreationTimeTest) { | 163 TEST_F(SyncedNotificationTest, GetCreationTimeTest) { |
165 uint64 found_time = notification1_->GetCreationTime(); | 164 uint64 found_time = notification1_->GetCreationTime(); |
166 EXPECT_EQ(kFakeCreationTime, found_time); | 165 EXPECT_EQ(kFakeCreationTime, found_time); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 EXPECT_EQ( | 341 EXPECT_EQ( |
343 std::string(kText1), | 342 std::string(kText1), |
344 base::UTF16ToUTF8(notification_manager()->notification().message())); | 343 base::UTF16ToUTF8(notification_manager()->notification().message())); |
345 | 344 |
346 // TODO(petewil): Check that the bitmap in the notification is what we expect. | 345 // TODO(petewil): Check that the bitmap in the notification is what we expect. |
347 // This fails today, the type info is different. | 346 // This fails today, the type info is different. |
348 // EXPECT_TRUE(gfx::BitmapsAreEqual( | 347 // EXPECT_TRUE(gfx::BitmapsAreEqual( |
349 // image, notification1_->GetAppIconBitmap())); | 348 // image, notification1_->GetAppIconBitmap())); |
350 } | 349 } |
351 | 350 |
352 | 351 // TODO(petewil): Empty bitmap should count as a successful fetch. |
353 TEST_F(SyncedNotificationTest, EmptyBitmapTest) { | 352 TEST_F(SyncedNotificationTest, EmptyBitmapTest) { |
354 if (!UseRichNotifications()) | 353 if (!UseRichNotifications()) |
355 return; | 354 return; |
356 | 355 |
357 // Set up the internal state that FetchBitmaps() would have set. | 356 // Set up the internal state that FetchBitmaps() would have set. |
358 notification1_->notification_manager_ = notification_manager(); | 357 notification1_->notification_manager_ = notification_manager(); |
359 | 358 |
360 // Add the bitmaps to the queue for us to match up. | 359 // Add the bitmaps to the queue for us to match up. |
361 notification1_->AddBitmapToFetchQueue(GURL(kIconUrl1)); | 360 notification1_->AddBitmapToFetchQueue(GURL(kIconUrl1)); |
362 notification1_->AddBitmapToFetchQueue(GURL(kImageUrl1)); | 361 notification1_->AddBitmapToFetchQueue(GURL(kImageUrl1)); |
(...skipping 29 matching lines...) Expand all Loading... |
392 // Since we check Show() thoroughly in its own test, we only check cursorily. | 391 // Since we check Show() thoroughly in its own test, we only check cursorily. |
393 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, | 392 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, |
394 notification_manager()->notification().type()); | 393 notification_manager()->notification().type()); |
395 EXPECT_EQ(std::string(kTitle1), | 394 EXPECT_EQ(std::string(kTitle1), |
396 base::UTF16ToUTF8(notification_manager()->notification().title())); | 395 base::UTF16ToUTF8(notification_manager()->notification().title())); |
397 EXPECT_EQ( | 396 EXPECT_EQ( |
398 std::string(kText1), | 397 std::string(kText1), |
399 base::UTF16ToUTF8(notification_manager()->notification().message())); | 398 base::UTF16ToUTF8(notification_manager()->notification().message())); |
400 } | 399 } |
401 | 400 |
| 401 TEST_F(SyncedNotificationTest, ShowIfNewlyEnabledTest) { |
| 402 if (!UseRichNotifications()) |
| 403 return; |
| 404 |
| 405 // Call the method using the wrong app id, nothing should get shown. |
| 406 notification1_->ShowIfNewlyEnabled( |
| 407 notification_manager(), NULL, NULL, kAppId2); |
| 408 |
| 409 // Ensure no notification was generated and shown. |
| 410 const Notification notification1 = notification_manager()->notification(); |
| 411 EXPECT_EQ(std::string(), base::UTF16ToUTF8(notification1.replace_id())); |
| 412 |
| 413 // Call the method under test using the pre-populated data. |
| 414 notification1_->ShowIfNewlyEnabled( |
| 415 notification_manager(), NULL, NULL, kAppId1); |
| 416 |
| 417 const Notification notification2 = notification_manager()->notification(); |
| 418 |
| 419 // Check the base fields of the notification. |
| 420 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification2.type()); |
| 421 EXPECT_EQ(std::string(kTitle1), base::UTF16ToUTF8(notification2.title())); |
| 422 EXPECT_EQ(std::string(kText1), base::UTF16ToUTF8(notification2.message())); |
| 423 EXPECT_EQ(std::string(kExpectedOriginUrl), notification2.origin_url().spec()); |
| 424 EXPECT_EQ(std::string(kKey1), base::UTF16ToUTF8(notification2.replace_id())); |
| 425 |
| 426 EXPECT_EQ(kFakeCreationTime, notification2.timestamp().ToDoubleT()); |
| 427 EXPECT_EQ(kNotificationPriority, notification2.priority()); |
| 428 } |
| 429 |
| 430 TEST_F(SyncedNotificationTest, HideIfNewlyRemovedTest) { |
| 431 if (!UseRichNotifications()) |
| 432 return; |
| 433 |
| 434 // Add the notification to the notification manger, so it exists before we |
| 435 // we remove it. |
| 436 notification1_->Show(notification_manager(), NULL, NULL); |
| 437 const Notification* found1 = notification_manager()->FindById(kKey1); |
| 438 EXPECT_NE(reinterpret_cast<Notification*>(NULL), found1); |
| 439 |
| 440 // Call the method under test using the pre-populated data. |
| 441 notification1_->HideIfNewlyRemoved( |
| 442 notification_manager(), NULL, NULL, kAppId1); |
| 443 |
| 444 // Ensure the notification was removed from the notification manager |
| 445 EXPECT_EQ(std::string(kKey1), notification_manager()->dismissed_id()); |
| 446 } |
| 447 |
402 // TODO(petewil): Add a test for a notification being read and or deleted. | 448 // TODO(petewil): Add a test for a notification being read and or deleted. |
403 | 449 |
404 } // namespace notifier | 450 } // namespace notifier |
OLD | NEW |