| Index: chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
|
| diff --git a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
|
| index f77af5e53281618b03082c17036b3def5d3abbb0..4a36a0e0ed48472f6d8f81b9c7a8d4bb243a9bb1 100644
|
| --- a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
|
| +++ b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
|
| @@ -19,6 +19,7 @@ using sync_pb::SyncedNotificationSpecifics;
|
| namespace {
|
|
|
| const int64 kFakeCreationTime = 42;
|
| +const int kPriority = 1;
|
|
|
| const char kTitle1[] = "New appointment at 2:15";
|
| const char kTitle2[] = "Email from Mark: Upcoming Ski trip";
|
| @@ -36,6 +37,22 @@ const char kIconUrl3[] = "http://www.google.com/icon3.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 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/image5.jpg";
|
| +const char kButtonOneUrl[] = "http://www.google.com/do-something1";
|
| +const char kButtonTwoTitle[] = "Reply";
|
| +const char kButtonTwoIconUrl[] = "http://www.google.com/image6.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 sync_pb::CoalescedSyncedNotification_ReadState kRead =
|
| sync_pb::CoalescedSyncedNotification_ReadState_READ;
|
| const sync_pb::CoalescedSyncedNotification_ReadState kUnread =
|
| @@ -54,11 +71,11 @@ class SyncedNotificationTest : public testing::Test {
|
| virtual void SetUp() OVERRIDE {
|
| sync_data1_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1,
|
| kAppId1, kKey1, kUnread);
|
| - sync_data2_ = CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl1,
|
| + sync_data2_ = CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl2,
|
| kAppId2, kKey2, kUnread);
|
| // Notification 3 will have the same ID as notification1, but different
|
| // data inside.
|
| - sync_data3_ = CreateSyncData(kTitle3, kText3, kIconUrl3, kImageUrl1,
|
| + sync_data3_ = CreateSyncData(kTitle3, kText3, kIconUrl3, kImageUrl3,
|
| kAppId1, kKey1, kUnread);
|
| // Notification 4 will be the same as 1, but the read state will be 'read'.
|
| sync_data4_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1,
|
| @@ -108,17 +125,24 @@ class SyncedNotificationTest : public testing::Test {
|
| set_key(key);
|
|
|
| specifics->mutable_coalesced_notification()->
|
| + set_priority(static_cast<sync_pb::CoalescedSyncedNotification_Priority>(
|
| + kPriority));
|
| +
|
| + // Set the title.
|
| + specifics->mutable_coalesced_notification()->
|
| mutable_render_info()->
|
| mutable_expanded_info()->
|
| mutable_simple_expanded_layout()->
|
| set_title(title);
|
|
|
| + // Set the text.
|
| specifics->mutable_coalesced_notification()->
|
| mutable_render_info()->
|
| mutable_expanded_info()->
|
| mutable_simple_expanded_layout()->
|
| set_text(text);
|
|
|
| + // Add the collapsed info and set the app_icon_url on it.
|
| specifics->mutable_coalesced_notification()->
|
| mutable_render_info()->
|
| mutable_expanded_info()->
|
| @@ -131,6 +155,7 @@ class SyncedNotificationTest : public testing::Test {
|
| 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()->
|
| @@ -148,13 +173,150 @@ class SyncedNotificationTest : public testing::Test {
|
| set_creation_time_msec(kFakeCreationTime);
|
|
|
| specifics->mutable_coalesced_notification()->
|
| - add_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()->
|
| - set_read_state(read_state);
|
| + 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);
|
|
|
| - // TODO(petewil): Improve ctor to pass in an image and type so this test can
|
| - // pass on actual data.
|
| SyncData sync_data = SyncData::CreateLocalData(
|
| "syncer::SYNCED_NOTIFICATIONS",
|
| "SyncedNotificationTest",
|
| @@ -228,20 +390,74 @@ TEST_F(SyncedNotificationTest, GetTextTest) {
|
| EXPECT_EQ(expected_text, found_text);
|
| }
|
|
|
| -TEST_F(SyncedNotificationTest, GetNotificationIdTest) {
|
| - std::string found_id = notification1_->notification_id();
|
| - std::string expected_id(kKey1);
|
| +TEST_F(SyncedNotificationTest, GetCreationTimeTest) {
|
| + uint64 found_time = notification1_->creation_time();
|
| + EXPECT_EQ(kFakeCreationTime, found_time);
|
| +}
|
| +
|
| +TEST_F(SyncedNotificationTest, GetPriorityTest) {
|
| + double found_priority = notification1_->priority();
|
| + EXPECT_EQ(static_cast<double>(kPriority), found_priority);
|
| +}
|
| +
|
| +TEST_F(SyncedNotificationTest, GetButtonCountTest) {
|
| + int found_button_count = notification1_->button_count();
|
| + EXPECT_EQ(2, found_button_count);
|
| +}
|
| +
|
| +TEST_F(SyncedNotificationTest, GetNotificationCountTest) {
|
| + int found_notification_count = notification1_->notification_count();
|
| + EXPECT_EQ(3, found_notification_count);
|
| +}
|
| +
|
| +TEST_F(SyncedNotificationTest, GetDefaultDestinationDataTest) {
|
| + std::string default_destination_title =
|
| + notification1_->default_destination_title();
|
| + std::string default_destination_icon_url =
|
| + notification1_->default_destination_icon_url();
|
| + std::string default_destination_url =
|
| + notification1_->default_destination_url();
|
| + EXPECT_EQ(std::string(kDefaultDestinationTitle), default_destination_title);
|
| + EXPECT_EQ(std::string(kDefaultDestinationIconUrl),
|
| + default_destination_icon_url);
|
| + EXPECT_EQ(std::string(kDefaultDestinationUrl), default_destination_url);
|
| +}
|
|
|
| - EXPECT_EQ(expected_id, found_id);
|
| +TEST_F(SyncedNotificationTest, GetButtonDataTest) {
|
| + std::string button_one_title = notification1_->button_one_title();
|
| + std::string button_one_icon_url = notification1_->button_one_icon_url();
|
| + std::string button_one_url = notification1_->button_one_url();
|
| + std::string button_two_title = notification1_->button_two_title();
|
| + std::string button_two_icon_url = notification1_->button_two_icon_url();
|
| + std::string button_two_url = notification1_->button_two_url();
|
| + EXPECT_EQ(std::string(kButtonOneTitle), button_one_title);
|
| + EXPECT_EQ(std::string(kButtonOneIconUrl), button_one_icon_url);
|
| + EXPECT_EQ(std::string(kButtonOneUrl), button_one_url);
|
| + EXPECT_EQ(std::string(kButtonTwoTitle), button_two_title);
|
| + EXPECT_EQ(std::string(kButtonTwoIconUrl), button_two_icon_url);
|
| + EXPECT_EQ(std::string(kButtonTwoUrl), button_two_url);
|
| }
|
|
|
| -// test that the ID match function works as we expect
|
| -TEST_F(SyncedNotificationTest, IdMatchesTest) {
|
| - EXPECT_TRUE(notification1_->IdMatches(*notification1_));
|
| - EXPECT_TRUE(notification2_->IdMatches(*notification2_));
|
| - EXPECT_FALSE(notification1_->IdMatches(*notification2_));
|
| - EXPECT_TRUE(notification1_->IdMatches(*notification3_));
|
| - EXPECT_TRUE(notification1_->IdMatches(*notification4_));
|
| +TEST_F(SyncedNotificationTest, ContainedNotificationTest) {
|
| + std::string notification_title1 =
|
| + notification1_->contained_notification_title(0);
|
| + std::string notification_title2 =
|
| + notification1_->contained_notification_title(1);
|
| + std::string notification_title3 =
|
| + notification1_->contained_notification_title(2);
|
| + std::string notification_message1 =
|
| + notification1_->contained_notification_message(0);
|
| + std::string notification_message2 =
|
| + notification1_->contained_notification_message(1);
|
| + std::string notification_message3 =
|
| + notification1_->contained_notification_message(2);
|
| +
|
| + EXPECT_EQ(std::string(kContainedTitle1), notification_title1);
|
| + EXPECT_EQ(std::string(kContainedTitle2), notification_title2);
|
| + EXPECT_EQ(std::string(kContainedTitle3), notification_title3);
|
| + EXPECT_EQ(std::string(kContainedMessage1), notification_message1);
|
| + EXPECT_EQ(std::string(kContainedMessage2), notification_message2);
|
| + EXPECT_EQ(std::string(kContainedMessage3), notification_message3);
|
| }
|
|
|
| // test that EqualsIgnoringReadState works as we expect
|
| @@ -264,5 +480,4 @@ TEST_F(SyncedNotificationTest, UpdateTest) {
|
| EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_));
|
| }
|
|
|
| -// Add a test for set_local_changes and has_local_changes together
|
| -// Add a test for a notification being read and or deleted
|
| +// Add a test for a notification being read and or deleted.
|
|
|