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

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

Issue 14631005: Enable users of NotificationUIManager to specify binary images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase for relanding. Created 7 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
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/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/notifications/notification.h" 9 #include "chrome/browser/notifications/notification.h"
10 #include "chrome/browser/notifications/notification_test_util.h"
10 #include "chrome/browser/notifications/notification_ui_manager.h" 11 #include "chrome/browser/notifications/notification_ui_manager.h"
11 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" 12 #include "chrome/browser/notifications/sync_notifier/synced_notification.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "sync/api/sync_data.h" 14 #include "sync/api/sync_data.h"
14 #include "sync/protocol/sync.pb.h" 15 #include "sync/protocol/sync.pb.h"
15 #include "sync/protocol/synced_notification_specifics.pb.h" 16 #include "sync/protocol/synced_notification_specifics.pb.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/message_center/message_center_util.h" 18 #include "ui/message_center/message_center_util.h"
18 #include "ui/message_center/notification_types.h" 19 #include "ui/message_center/notification_types.h"
19 20
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const sync_pb::CoalescedSyncedNotification_ReadState kUnread = 74 const sync_pb::CoalescedSyncedNotification_ReadState kUnread =
74 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD; 75 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD;
75 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = 76 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed =
76 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; 77 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED;
77 } // namespace 78 } // namespace
78 79
79 // Stub out the NotificationUIManager for unit testing. 80 // Stub out the NotificationUIManager for unit testing.
80 class StubNotificationUIManager : public NotificationUIManager { 81 class StubNotificationUIManager : public NotificationUIManager {
81 public: 82 public:
82 StubNotificationUIManager() 83 StubNotificationUIManager()
83 : notification_(GURL(), GURL(), string16(), string16(), NULL) {} 84 : notification_(GURL(),
85 GURL(),
86 string16(),
87 string16(),
88 new MockNotificationDelegate("stub")) {}
84 virtual ~StubNotificationUIManager() {} 89 virtual ~StubNotificationUIManager() {}
85 90
86 // Adds a notification to be displayed. Virtual for unit test override. 91 // Adds a notification to be displayed. Virtual for unit test override.
87 virtual void Add(const Notification& notification, Profile* profile) 92 virtual void Add(const Notification& notification, Profile* profile)
88 OVERRIDE { 93 OVERRIDE {
89 // Make a deep copy of the notification that we can inspect. 94 // Make a deep copy of the notification that we can inspect.
90 notification_ = notification; 95 notification_ = notification;
91 profile_ = profile; 96 profile_ = profile;
92 } 97 }
93 98
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 470
466 // TODO(petewil): Improve ctor to pass in an image and type so this test can 471 // TODO(petewil): Improve ctor to pass in an image and type so this test can
467 // pass on actual data. 472 // pass on actual data.
468 TEST_F(SyncedNotificationTest, GetImageURLTest) { 473 TEST_F(SyncedNotificationTest, GetImageURLTest) {
469 std::string found_image_url = notification1_->GetImageUrl().spec(); 474 std::string found_image_url = notification1_->GetImageUrl().spec();
470 std::string expected_image_url = kImageUrl1; 475 std::string expected_image_url = kImageUrl1;
471 476
472 EXPECT_EQ(expected_image_url, found_image_url); 477 EXPECT_EQ(expected_image_url, found_image_url);
473 } 478 }
474 479
475 // TODO(petewil): test with a multi-line body 480 // TODO(petewil): test with a multi-line message
476 TEST_F(SyncedNotificationTest, GetTextTest) { 481 TEST_F(SyncedNotificationTest, GetTextTest) {
477 std::string found_text = notification1_->GetText(); 482 std::string found_text = notification1_->GetText();
478 std::string expected_text(kText1); 483 std::string expected_text(kText1);
479 484
480 EXPECT_EQ(expected_text, found_text); 485 EXPECT_EQ(expected_text, found_text);
481 } 486 }
482 487
483 TEST_F(SyncedNotificationTest, GetCreationTimeTest) { 488 TEST_F(SyncedNotificationTest, GetCreationTimeTest) {
484 uint64 found_time = notification1_->GetCreationTime(); 489 uint64 found_time = notification1_->GetCreationTime();
485 EXPECT_EQ(kFakeCreationTime, found_time); 490 EXPECT_EQ(kFakeCreationTime, found_time);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 TEST_F(SyncedNotificationTest, ShowTest) { 578 TEST_F(SyncedNotificationTest, ShowTest) {
574 579
575 if (!UseRichNotifications()) 580 if (!UseRichNotifications())
576 return; 581 return;
577 582
578 StubNotificationUIManager notification_manager; 583 StubNotificationUIManager notification_manager;
579 584
580 // Call the method under test using the pre-populated data. 585 // Call the method under test using the pre-populated data.
581 notification1_->Show(&notification_manager, NULL, NULL); 586 notification1_->Show(&notification_manager, NULL, NULL);
582 587
588 const Notification notification = notification_manager.notification();
589
583 // Check the base fields of the notification. 590 // Check the base fields of the notification.
584 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, 591 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification.type());
585 notification_manager.notification().type()); 592 EXPECT_EQ(kTitle1, UTF16ToUTF8(notification.title()));
586 EXPECT_EQ(kTitle1, 593 EXPECT_EQ(kText1, UTF16ToUTF8(notification.message()));
587 UTF16ToUTF8(notification_manager.notification().title())); 594 EXPECT_EQ(kExpectedOriginUrl, notification.origin_url().spec());
588 EXPECT_EQ(kText1, 595 EXPECT_EQ(kKey1, UTF16ToUTF8(notification.replace_id()));
589 UTF16ToUTF8(notification_manager.notification().body()));
590 EXPECT_EQ(kExpectedOriginUrl,
591 notification_manager.notification().origin_url().spec());
592 EXPECT_EQ(kIconUrl1, notification_manager.notification().icon_url().spec());
593 EXPECT_EQ(kKey1,
594 UTF16ToUTF8(notification_manager.notification().replace_id()));
595 const DictionaryValue* actual_fields =
596 notification_manager.notification().optional_fields();
597 596
598 // Check the optional fields of the notification. 597 EXPECT_EQ(kFakeCreationTime, notification.timestamp().ToDoubleT());
599 // Make an optional fields struct like we expect, compare it with actual. 598 EXPECT_EQ(kNotificationPriority, notification.priority());
600 DictionaryValue expected_fields;
601 expected_fields.SetDouble(message_center::kTimestampKey, kFakeCreationTime);
602 expected_fields.SetInteger(message_center::kPriorityKey,
603 kNotificationPriority);
604 expected_fields.SetString(message_center::kButtonOneTitleKey,
605 kButtonOneTitle);
606 expected_fields.SetString(message_center::kButtonOneIconUrlKey,
607 kButtonOneIconUrl);
608 expected_fields.SetString(message_center::kButtonTwoTitleKey,
609 kButtonTwoTitle);
610 expected_fields.SetString(message_center::kButtonTwoIconUrlKey,
611 kButtonTwoIconUrl);
612 599
613 // Fill the individual notification fields for a mutiple notification. 600 EXPECT_EQ(UTF8ToUTF16(kButtonOneTitle), notification.buttons()[0].title);
614 base::ListValue* items = new base::ListValue(); 601 EXPECT_EQ(UTF8ToUTF16(kButtonTwoTitle), notification.buttons()[1].title);
615 DictionaryValue* item1 = new DictionaryValue();
616 DictionaryValue* item2 = new DictionaryValue();
617 DictionaryValue* item3 = new DictionaryValue();
618 item1->SetString(message_center::kItemTitleKey,
619 UTF8ToUTF16(kContainedTitle1));
620 item1->SetString(message_center::kItemMessageKey,
621 UTF8ToUTF16(kContainedMessage1));
622 item2->SetString(message_center::kItemTitleKey,
623 UTF8ToUTF16(kContainedTitle2));
624 item2->SetString(message_center::kItemMessageKey,
625 UTF8ToUTF16(kContainedMessage2));
626 item3->SetString(message_center::kItemTitleKey,
627 UTF8ToUTF16(kContainedTitle3));
628 item3->SetString(message_center::kItemMessageKey,
629 UTF8ToUTF16(kContainedMessage3));
630 items->Append(item1);
631 items->Append(item2);
632 items->Append(item3);
633 expected_fields.Set(message_center::kItemsKey, items);
634 602
635 EXPECT_TRUE(expected_fields.Equals(actual_fields)) 603 EXPECT_EQ(UTF8ToUTF16(kContainedTitle1), notification.items()[0].title);
636 << "Expected: " << expected_fields 604 EXPECT_EQ(UTF8ToUTF16(kContainedTitle2), notification.items()[1].title);
637 << ", but actual: " << *actual_fields; 605 EXPECT_EQ(UTF8ToUTF16(kContainedTitle3), notification.items()[2].title);
638 606
607 EXPECT_EQ(UTF8ToUTF16(kContainedMessage1), notification.items()[0].message);
608 EXPECT_EQ(UTF8ToUTF16(kContainedMessage2), notification.items()[1].message);
609 EXPECT_EQ(UTF8ToUTF16(kContainedMessage3), notification.items()[2].message);
639 } 610 }
640 611
641 // TODO(petewil): Add a test for a notification being read and or deleted. 612 // TODO(petewil): Add a test for a notification being read and or deleted.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698