Chromium Code Reviews| Index: chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc |
| diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc |
| index f9322e2141e2ba2afda6c2be3eb2976ea1b8edfc..ddea95420eb443ffd0aa3b0f8c343f81cc5377db 100644 |
| --- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc |
| +++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc |
| @@ -5,6 +5,9 @@ |
| #include <map> |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/notifications/notification.h" |
| #include "chrome/browser/notifications/notification_ui_manager.h" |
| #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
| @@ -42,7 +45,54 @@ const char kKey4[] = "baz"; |
| const char kKey5[] = "foobar"; |
| const char kKey6[] = "fu"; |
| const char kKey7[] = "meta"; |
| +const char kIconUrl[] = "http://www.google.com/icon1.jpg"; |
| +const char kTitle1[] = "New appointment at 2:15"; |
| +const char kTitle2[] = "Email from Mark: Upcoming Ski trip"; |
| +const char kTitle3[] = "Weather alert - light rain tonight."; |
| +const char kTitle4[] = "Zombie Alert on I-405"; |
| +const char kTitle5[] = "5-dimensional plutonian steam hockey scores"; |
| +const char kTitle6[] = "Conterfactuals Inc Stock report"; |
| +const char kTitle7[] = "Push Messaging app updated"; |
| +const char kText1[] = "Space Needle, 12:00 pm"; |
| +const char kText2[] = "Stevens Pass is our first choice."; |
| +const char kText3[] = "More rain expected in the Seattle area tonight."; |
| +const char kText4[] = "Traffic slowdown as motorists are hitting zombies"; |
| +const char kText5[] = "Neptune wins, pi to e"; |
| +const char kText6[] = "Beef flavored base for soups"; |
| +const char kText7[] = "You now have the latest version of Push Messaging App."; |
| +const char kIconUrl1[] = "http://www.google.com/icon1.jpg"; |
| +const char kIconUrl2[] = "http://www.google.com/icon2.jpg"; |
| +const char kIconUrl3[] = "http://www.google.com/icon3.jpg"; |
| +const char kIconUrl4[] = "http://www.google.com/icon4.jpg"; |
| +const char kIconUrl5[] = "http://www.google.com/icon5.jpg"; |
| +const char kIconUrl6[] = "http://www.google.com/icon6.jpg"; |
| +const char kIconUrl7[] = "http://www.google.com/icon7.jpg"; |
| +const char kImageUrl1[] = "http://www.google.com/image1.jpg"; |
| +const char kImageUrl2[] = "http://www.google.com/image2.jpg"; |
| +const char kImageUrl3[] = "http://www.google.com/image3.jpg"; |
| +const char kImageUrl4[] = "http://www.google.com/image4.jpg"; |
| +const char kImageUrl5[] = "http://www.google.com/image5.jpg"; |
| +const char kImageUrl6[] = "http://www.google.com/image6.jpg"; |
| +const char kImageUrl7[] = "http://www.google.com/image7.jpg"; |
| +const char kExpectedOriginUrl[] = |
| + "chrome-extension://fboilmbenheemaomgaeehigklolhkhnf/"; |
| +const char kDefaultDestinationTitle[] = "Open web page"; |
| +const char kDefaultDestinationIconUrl[] = "http://www.google.com/image4.jpg"; |
| +const char kDefaultDestinationUrl[] = "http://www.google.com"; |
| +const char kButtonOneTitle[] = "Read"; |
| +const char kButtonOneIconUrl[] = "http://www.google.com/image8.jpg"; |
| +const char kButtonOneUrl[] = "http://www.google.com/do-something1"; |
| +const char kButtonTwoTitle[] = "Reply"; |
| +const char kButtonTwoIconUrl[] = "http://www.google.com/image9.jpg"; |
| +const char kButtonTwoUrl[] = "http://www.google.com/do-something2"; |
| +const char kContainedTitle1[] = "Today's Picnic moved"; |
| +const char kContainedTitle2[] = "Group Run Today"; |
| +const char kContainedTitle3[] = "Starcraft Tonight"; |
| +const char kContainedMessage1[] = "Due to rain, we will be inside the cafe."; |
| +const char kContainedMessage2[] = "Meet at noon in the Gym."; |
| +const char kContainedMessage3[] = "Let's play starcraft tonight on the LAN."; |
| const int64 kFakeCreationTime = 42; |
| +const int kFakePriority = 1; |
| const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = |
| sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; |
| const sync_pb::CoalescedSyncedNotification_ReadState kUnread = |
| @@ -52,18 +102,22 @@ const sync_pb::CoalescedSyncedNotification_ReadState kUnread = |
| std::string GetNotificationId(const SyncData& sync_data) { |
| SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). |
| synced_notification(); |
| + |
| return specifics.coalesced_notification().key(); |
| } |
| // Stub out the NotificationUIManager for unit testing. |
| class StubNotificationUIManager : public NotificationUIManager { |
| public: |
| - StubNotificationUIManager() {} |
| + StubNotificationUIManager() : notification_(GURL(), GURL(), L"", L"", NULL) {} |
| virtual ~StubNotificationUIManager() {} |
| // Adds a notification to be displayed. Virtual for unit test override. |
| virtual void Add(const Notification& notification, Profile* profile) |
| - OVERRIDE {} |
| + OVERRIDE { |
| + // Make a deep copy of the notification that we can inspect. |
| + notification_ = notification; |
| + } |
| // Returns true if any notifications match the supplied ID, either currently |
| // displayed or in the queue. |
| @@ -92,8 +146,12 @@ class StubNotificationUIManager : public NotificationUIManager { |
| // Used when the app is terminating. |
| virtual void CancelAll() OVERRIDE {} |
| + // Test hook to get the notification so we can check it |
| + Notification& notification() { return notification_; } |
|
dcheng
2013/03/28 00:03:19
No mutable references.
Pete Williamson
2013/03/28 00:38:09
made it const
|
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); |
| + Notification notification_; |
| }; |
| // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed |
| @@ -180,13 +238,15 @@ class ChromeNotifierServiceTest : public testing::Test { |
| } |
| SyncedNotification* CreateNotification( |
| - const std::string& message, |
| + const std::string& title, |
| + const std::string& text, |
| + const std::string& app_icon_url, |
| + const std::string& image_url, |
| const std::string& app_id, |
| const std::string& key, |
| - const std::string& external_id, |
| sync_pb::CoalescedSyncedNotification_ReadState read_state) { |
| - SyncData sync_data = CreateSyncData(message, app_id, key, |
| - external_id, read_state); |
| + SyncData sync_data = CreateSyncData(title, text, app_icon_url, image_url, |
| + app_id, key, read_state); |
| // Set enough fields in sync_data, including specifics, for our tests |
| // to pass. |
| return new SyncedNotification(sync_data); |
| @@ -207,15 +267,19 @@ class ChromeNotifierServiceTest : public testing::Test { |
| // Helper to create syncer::SyncData. |
| static SyncData CreateSyncData( |
| - const std::string& message, |
| + const std::string& title, |
| + const std::string& text, |
| + const std::string& app_icon_url, |
| + const std::string& image_url, |
| const std::string& app_id, |
| const std::string& key, |
| - const std::string& external_id, |
| - sync_pb::CoalescedSyncedNotification_ReadState read_state) { |
| + const sync_pb::CoalescedSyncedNotification_ReadState read_state) { |
| // CreateLocalData makes a copy of this, so this can safely live |
| // on the stack. |
| EntitySpecifics entity_specifics; |
| + // Get a writeable pointer to the sync notifications specifics inside the |
| + // entity specifics. |
| SyncedNotificationSpecifics* specifics = |
| entity_specifics.mutable_synced_notification(); |
| @@ -226,27 +290,210 @@ class ChromeNotifierServiceTest : public testing::Test { |
| set_key(key); |
| specifics->mutable_coalesced_notification()-> |
| + set_priority(static_cast<sync_pb::CoalescedSyncedNotification_Priority>( |
| + kFakePriority)); |
| + |
| + // Set the title. |
| + specifics->mutable_coalesced_notification()-> |
| mutable_render_info()-> |
| mutable_expanded_info()-> |
| mutable_simple_expanded_layout()-> |
| - set_title(message); |
| + set_title(title); |
| + // Set the text. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_simple_expanded_layout()-> |
| + set_text(text); |
| + |
| + // Set the heading. |
| specifics-> |
| mutable_coalesced_notification()-> |
| - set_creation_time_msec(kFakeCreationTime); |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_simple_collapsed_layout()-> |
| + set_heading(title); |
| + // Add the collapsed info and set the app_icon_url on it. |
| specifics-> |
| mutable_coalesced_notification()-> |
| - add_notification(); |
| - |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + add_collapsed_info(); |
| specifics-> |
| mutable_coalesced_notification()-> |
| - mutable_notification(0)->set_external_id(external_id); |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_collapsed_info(0)-> |
| + mutable_simple_collapsed_layout()-> |
| + mutable_app_icon()-> |
| + set_url(app_icon_url); |
| + // Add the media object and set the image url on it. |
| specifics-> |
| mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_simple_expanded_layout()-> |
| + add_media(); |
| + specifics-> |
| + mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_simple_expanded_layout()-> |
| + mutable_media(0)-> |
| + mutable_image()-> |
| + set_url(image_url); |
| + |
| + specifics->mutable_coalesced_notification()-> |
| + set_creation_time_msec(kFakeCreationTime); |
| + |
| + specifics->mutable_coalesced_notification()-> |
| set_read_state(read_state); |
| + // Contained notification one. |
| + // We re-use the collapsed info we added for the app_icon_url, |
| + // so no need to create another one here. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_collapsed_info(0)-> |
| + mutable_simple_collapsed_layout()-> |
| + set_heading(kContainedTitle1); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_collapsed_info(0)-> |
| + mutable_simple_collapsed_layout()-> |
| + set_description(kContainedMessage1); |
| + |
| + // Contained notification two. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + add_collapsed_info(); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_collapsed_info(1)-> |
| + mutable_simple_collapsed_layout()-> |
| + set_heading(kContainedTitle2); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_collapsed_info(1)-> |
| + mutable_simple_collapsed_layout()-> |
| + set_description(kContainedMessage2); |
| + |
| + // Contained notification three. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + add_collapsed_info(); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_collapsed_info(2)-> |
| + mutable_simple_collapsed_layout()-> |
| + set_heading(kContainedTitle3); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_expanded_info()-> |
| + mutable_collapsed_info(2)-> |
| + mutable_simple_collapsed_layout()-> |
| + set_description(kContainedMessage3); |
| + |
| + // Default Destination. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_default_destination()-> |
| + set_text(kDefaultDestinationTitle); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_default_destination()-> |
| + mutable_icon()-> |
| + set_url(kDefaultDestinationIconUrl); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_default_destination()-> |
| + mutable_icon()-> |
| + set_alt_text(kDefaultDestinationTitle); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_default_destination()-> |
| + set_url(kDefaultDestinationUrl); |
| + |
| + // Buttons are represented as targets. |
| + |
| + // Button One. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + add_target(); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_target(0)-> |
| + mutable_action()-> |
| + set_text(kButtonOneTitle); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_target(0)-> |
| + mutable_action()-> |
| + mutable_icon()-> |
| + set_url(kButtonOneIconUrl); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_target(0)-> |
| + mutable_action()-> |
| + mutable_icon()-> |
| + set_alt_text(kButtonOneTitle); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_target(0)-> |
| + mutable_action()-> |
| + set_url(kButtonOneUrl); |
| + |
| + // Button Two. |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + add_target(); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_target(1)-> |
| + mutable_action()-> |
| + set_text(kButtonTwoTitle); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_target(1)-> |
| + mutable_action()-> |
| + mutable_icon()-> |
| + set_url(kButtonTwoIconUrl); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_target(1)-> |
| + mutable_action()-> |
| + mutable_icon()-> |
| + set_alt_text(kButtonTwoTitle); |
| + specifics->mutable_coalesced_notification()-> |
| + mutable_render_info()-> |
| + mutable_collapsed_info()-> |
| + mutable_target(1)-> |
| + mutable_action()-> |
| + set_url(kButtonTwoUrl); |
| + |
| SyncData sync_data = SyncData::CreateLocalData( |
| "syncer::SYNCED_NOTIFICATIONS", |
| "ChromeNotifierServiceUnitTest", |
| @@ -268,14 +515,15 @@ class ChromeNotifierServiceTest : public testing::Test { |
| // Create a Notification, convert it to SyncData and convert it back. |
| TEST_F(ChromeNotifierServiceTest, NotificationToSyncDataToNotification) { |
| scoped_ptr<SyncedNotification> notification1( |
| - CreateNotification("1", kAppId1, kKey1, "11", kUnread)); |
| + CreateNotification(kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, |
| + kKey1, kUnread)); |
| SyncData sync_data = |
| ChromeNotifierService::CreateSyncDataFromNotification(*notification1); |
| scoped_ptr<SyncedNotification> notification2( |
| ChromeNotifierService::CreateNotificationFromSyncData(sync_data)); |
| EXPECT_TRUE(notification2.get()); |
| EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); |
| - EXPECT_EQ(notification1->read_state(), notification2->read_state()); |
| + EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState()); |
| } |
| // Model assocation: We have no local data, and no remote data. |
| @@ -309,13 +557,13 @@ TEST_F(ChromeNotifierServiceTest, ProcessSyncChangesEmptyModel) { |
| SyncChangeList changes; |
| changes.push_back(CreateSyncChange( |
| SyncChange::ACTION_ADD, CreateNotification( |
| - "1", kAppId1, kKey1, "11", kUnread))); |
| + kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread))); |
| changes.push_back(CreateSyncChange( |
| SyncChange::ACTION_ADD, CreateNotification( |
| - "2", kAppId2, kKey2, "22", kUnread))); |
| + kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread))); |
| changes.push_back(CreateSyncChange( |
| SyncChange::ACTION_ADD, CreateNotification( |
| - "3", kAppId3, kKey3, "33", kUnread))); |
| + kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread))); |
| notifier.ProcessSyncChanges(FROM_HERE, changes); |
| @@ -332,25 +580,25 @@ TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) { |
| // Create some local fake data. |
| scoped_ptr<SyncedNotification> n1(CreateNotification( |
| - "1", kAppId1, kKey1, "11", kUnread)); |
| + kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); |
| notifier.AddForTest(n1.Pass()); |
| scoped_ptr<SyncedNotification> n2(CreateNotification( |
| - "2", kAppId2, kKey2, "22", kUnread)); |
| + kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread)); |
| notifier.AddForTest(n2.Pass()); |
| scoped_ptr<SyncedNotification> n3(CreateNotification( |
| - "3", kAppId3, kKey3, "33", kUnread)); |
| + kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread)); |
| notifier.AddForTest(n3.Pass()); |
| // Create some remote fake data. |
| SyncDataList initial_data; |
| - initial_data.push_back(CreateSyncData("4", kAppId4, kKey4, |
| - "44", kUnread)); |
| - initial_data.push_back(CreateSyncData("5", kAppId5, kKey5, |
| - "55", kUnread)); |
| - initial_data.push_back(CreateSyncData("6", kAppId6, kKey6, |
| - "66", kUnread)); |
| - initial_data.push_back(CreateSyncData("7", kAppId7, kKey7, |
| - "77", kUnread)); |
| + initial_data.push_back(CreateSyncData(kTitle4, kText4, kIconUrl4, kImageUrl4, |
| + kAppId4, kKey4, kUnread)); |
| + initial_data.push_back(CreateSyncData(kTitle5, kText5, kIconUrl5, kImageUrl5, |
| + kAppId5, kKey5, kUnread)); |
| + initial_data.push_back(CreateSyncData(kTitle6, kText6, kIconUrl6, kImageUrl6, |
| + kAppId6, kKey6, kUnread)); |
| + initial_data.push_back(CreateSyncData(kTitle7, kText7, kIconUrl7, kImageUrl7, |
| + kAppId7, kKey7, kUnread)); |
| // Merge the local and remote data. |
| notifier.MergeDataAndStartSyncing( |
| @@ -361,13 +609,13 @@ TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) { |
| // Ensure the local store now has all local and remote notifications. |
| EXPECT_EQ(7U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey1)); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey2)); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey3)); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey4)); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey5)); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey6)); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey7)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey1)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey2)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey3)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey4)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey5)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey6)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey7)); |
| // Test the type conversion and construction functions. |
| for (SyncDataList::const_iterator iter = initial_data.begin(); |
| @@ -375,15 +623,16 @@ TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) { |
| scoped_ptr<SyncedNotification> notification1( |
| ChromeNotifierService::CreateNotificationFromSyncData(*iter)); |
| // TODO(petewil): Revisit this when we add version info to notifications. |
| - const std::string& id = notification1->notification_id(); |
| - const SyncedNotification* notification2 = notifier.FindNotificationById(id); |
| + const std::string& key = notification1->GetKey(); |
| + const SyncedNotification* notification2 = |
| + notifier.FindNotificationByKey(key); |
| EXPECT_TRUE(NULL != notification2); |
| EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); |
| - EXPECT_EQ(notification1->read_state(), notification2->read_state()); |
| + EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState()); |
| } |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey1)); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey2)); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey3)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey1)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey2)); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey3)); |
| } |
| // Test the local store having the read bit unset, the remote store having |
| @@ -394,16 +643,16 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) { |
| // Create some local fake data. |
| scoped_ptr<SyncedNotification> n1(CreateNotification( |
| - "1", kAppId1, kKey1, "11", kUnread)); |
| + kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); |
| notifier.AddForTest(n1.Pass()); |
| scoped_ptr<SyncedNotification> n2(CreateNotification( |
| - "2", kAppId2, kKey2, "22", kUnread)); |
| + kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread)); |
| notifier.AddForTest(n2.Pass()); |
| // Create some remote fake data, item 1 matches except for the read state. |
| syncer::SyncDataList initial_data; |
| - initial_data.push_back(CreateSyncData("1", kAppId1, kKey1, |
| - "11", kDismissed)); |
| + initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, |
| + kAppId1, kKey1, kDismissed)); |
| // Merge the local and remote data. |
| notifier.MergeDataAndStartSyncing( |
| syncer::SYNCED_NOTIFICATIONS, |
| @@ -415,11 +664,11 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) { |
| // state of the first is now read. |
| EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); |
| SyncedNotification* notification1 = |
| - notifier.FindNotificationById(kKey1); |
| + notifier.FindNotificationByKey(kKey1); |
| EXPECT_FALSE(NULL == notification1); |
| - EXPECT_EQ(SyncedNotification::kDismissed, notification1->read_state()); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey2)); |
| - EXPECT_FALSE(notifier.FindNotificationById(kKey3)); |
| + EXPECT_EQ(kDismissed, notification1->GetReadState()); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey2)); |
| + EXPECT_FALSE(notifier.FindNotificationByKey(kKey3)); |
| // Ensure no new data will be sent to the remote store for notification1. |
| EXPECT_EQ(0U, processor()->change_list_size()); |
| @@ -434,16 +683,16 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) { |
| // Create some local fake data. |
| scoped_ptr<SyncedNotification> n1(CreateNotification( |
| - "1", kAppId1, kKey1, "11", kDismissed)); |
| + kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kDismissed)); |
| notifier.AddForTest(n1.Pass()); |
| scoped_ptr<SyncedNotification> n2(CreateNotification( |
| - "2", kAppId2, kKey2, "22", kUnread)); |
| + kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread)); |
| notifier.AddForTest(n2.Pass()); |
| // Create some remote fake data, item 1 matches except for the read state. |
| syncer::SyncDataList initial_data; |
| - initial_data.push_back(CreateSyncData("1", kAppId1, kKey1, |
| - "11", kUnread)); |
| + initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, |
| + kAppId1, kKey1, kUnread)); |
| // Merge the local and remote data. |
| notifier.MergeDataAndStartSyncing( |
| syncer::SYNCED_NOTIFICATIONS, |
| @@ -455,11 +704,11 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) { |
| // state of the first is now read. |
| EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); |
| SyncedNotification* notification1 = |
| - notifier.FindNotificationById(kKey1); |
| + notifier.FindNotificationByKey(kKey1); |
| EXPECT_FALSE(NULL == notification1); |
| - EXPECT_EQ(SyncedNotification::kDismissed, notification1->read_state()); |
| - EXPECT_TRUE(notifier.FindNotificationById(kKey2)); |
| - EXPECT_FALSE(notifier.FindNotificationById(kKey3)); |
| + EXPECT_EQ(kDismissed, notification1->GetReadState()); |
| + EXPECT_TRUE(notifier.FindNotificationByKey(kKey2)); |
| + EXPECT_FALSE(notifier.FindNotificationByKey(kKey3)); |
| // Ensure the new data will be sent to the remote store for notification1. |
| EXPECT_EQ(1U, processor()->change_list_size()); |
| @@ -476,13 +725,13 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyWithUpdate) { |
| // Create some local fake data. |
| scoped_ptr<SyncedNotification> n1(CreateNotification( |
| - "1", kAppId1, kKey1, "11", kDismissed)); |
| + kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kDismissed)); |
| notifier.AddForTest(n1.Pass()); |
| // Create some remote fake data, item 1 matches the ID, but has different data |
| syncer::SyncDataList initial_data; |
| - initial_data.push_back(CreateSyncData("One", kAppId1, kKey1, |
| - "Eleven", kUnread)); |
| + initial_data.push_back(CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl2, |
| + kAppId1, kKey1, kUnread)); |
| // Merge the local and remote data. |
| notifier.MergeDataAndStartSyncing( |
| syncer::SYNCED_NOTIFICATIONS, |
| @@ -493,17 +742,115 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyWithUpdate) { |
| // Ensure the local store still has only one notification |
| EXPECT_EQ(1U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); |
| SyncedNotification* notification1 = |
| - notifier.FindNotificationById(kKey1); |
| + notifier.FindNotificationByKey(kKey1); |
| + |
| EXPECT_FALSE(NULL == notification1); |
| - EXPECT_EQ(SyncedNotification::kUnread, notification1->read_state()); |
| - EXPECT_EQ("One", notification1->title()); |
| - EXPECT_EQ("Eleven", notification1->first_external_id()); |
| + EXPECT_EQ(kUnread, notification1->GetReadState()); |
| + EXPECT_EQ(kTitle2, notification1->GetTitle()); |
| // Ensure no new data will be sent to the remote store for notification1. |
| EXPECT_EQ(0U, processor()->change_list_size()); |
| EXPECT_FALSE(processor()->ContainsId(kKey1)); |
| } |
| +TEST_F(ChromeNotifierServiceTest, ShowTest) { |
| + StubNotificationUIManager notification_manager; |
| + ChromeNotifierService notifier(NULL, ¬ification_manager); |
| + |
| + // Create some remote fake data |
| + syncer::SyncDataList initial_data; |
| + initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, |
| + kAppId1, kKey1, kUnread)); |
| + // Merge the local and remote data. |
| + notifier.MergeDataAndStartSyncing( |
| + syncer::SYNCED_NOTIFICATIONS, |
| + initial_data, |
| + PassProcessor(), |
| + scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| + |
| + // Check the base fields of the notification. |
| + EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, |
| + notification_manager.notification().type()); |
| + EXPECT_EQ(kTitle1, |
| + UTF16ToUTF8(notification_manager.notification().title())); |
| + EXPECT_EQ(kText1, |
| + UTF16ToUTF8(notification_manager.notification().body())); |
| + EXPECT_EQ(kExpectedOriginUrl, |
| + notification_manager.notification().origin_url().spec()); |
| + EXPECT_EQ(kIconUrl, notification_manager.notification().icon_url().spec()); |
| + EXPECT_EQ(kKey1, |
| + UTF16ToUTF8(notification_manager.notification().replace_id())); |
| + const DictionaryValue* optional_fields = |
| + notification_manager.notification().optional_fields(); |
| + |
| + // Check the optional fields of the notification. |
|
dcheng
2013/03/28 00:03:19
Consider that it may be easier (and possibly more
Pete Williamson
2013/03/28 00:38:09
Done.
|
| + double creation_time = 0.0; |
| + EXPECT_TRUE(optional_fields->GetDouble(message_center::kTimestampKey, |
| + &creation_time)); |
| + EXPECT_EQ(static_cast<double>(kFakeCreationTime), creation_time); |
| + |
| + int priority = -1; |
| + EXPECT_TRUE(optional_fields->GetInteger(message_center::kPriorityKey, |
| + &priority)); |
| + EXPECT_EQ(kFakePriority, priority); |
| + |
| + // Buttons. |
| + std::string button_one_title; |
| + EXPECT_TRUE(optional_fields->GetString(message_center::kButtonOneTitleKey, |
| + &button_one_title)); |
| + EXPECT_EQ(kButtonOneTitle, button_one_title); |
| + std::string button_one_icon_url; |
| + EXPECT_TRUE(optional_fields->GetString(message_center::kButtonOneIconUrlKey, |
| + &button_one_icon_url)); |
| + EXPECT_EQ(kButtonOneIconUrl, button_one_icon_url); |
| + std::string button_two_title; |
| + EXPECT_TRUE(optional_fields->GetString(message_center::kButtonTwoTitleKey, |
| + &button_two_title)); |
| + EXPECT_EQ(kButtonTwoTitle, button_two_title); |
| + std::string button_two_icon_url; |
| + EXPECT_TRUE(optional_fields->GetString(message_center::kButtonTwoIconUrlKey, |
| + &button_two_icon_url)); |
| + EXPECT_EQ(kButtonTwoIconUrl, button_two_icon_url); |
| + |
| + // Check the contained notifications. Note that the list owns these pointers. |
| + const ListValue* items; |
| + EXPECT_TRUE(optional_fields->GetList(message_center::kItemsKey, &items)); |
| + EXPECT_EQ(3, items->GetSize()); |
| + |
| + // Contained item 1. |
| + const DictionaryValue* item1; |
| + std::string item_title1; |
| + std::string item_message1; |
| + EXPECT_TRUE(items->GetDictionary(0, &item1)); |
| + EXPECT_TRUE(item1->GetString(message_center::kItemTitleKey, &item_title1)); |
| + EXPECT_TRUE(item1->GetString(message_center::kItemMessageKey, |
| + &item_message1)); |
| + EXPECT_EQ(kContainedTitle1, item_title1); |
| + EXPECT_EQ(kContainedMessage1, item_message1); |
| + |
| + // Contained item 2. |
| + const DictionaryValue* item2; |
| + std::string item_title2; |
| + std::string item_message2; |
| + EXPECT_TRUE(items->GetDictionary(1, &item2)); |
| + EXPECT_TRUE(item2->GetString(message_center::kItemTitleKey, &item_title2)); |
| + EXPECT_TRUE(item2->GetString(message_center::kItemMessageKey, |
| + &item_message2)); |
| + EXPECT_EQ(kContainedTitle2, item_title2); |
| + EXPECT_EQ(kContainedMessage2, item_message2); |
| + |
| + // Contained item 3. |
| + const DictionaryValue* item3; |
| + std::string item_title3; |
| + std::string item_message3; |
| + EXPECT_TRUE(items->GetDictionary(2, &item3)); |
| + EXPECT_TRUE(item3->GetString(message_center::kItemTitleKey, &item_title3)); |
| + EXPECT_TRUE(item3->GetString(message_center::kItemMessageKey, |
| + &item_message3)); |
| + EXPECT_EQ(kContainedTitle3, item_title3); |
| + EXPECT_EQ(kContainedMessage3, item_message3); |
| +} |
| + |
| // TODO(petewil): There are more tests to add, such as when we add an API |
| // to allow data entry from the client, we might have a more up to date |
| // item on the client than the server, or we might have a merge conflict. |