OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
| 9 #include "sync/api/sync_data.h" |
| 10 #include "sync/protocol/sync.pb.h" |
| 11 #include "sync/protocol/synced_notification_specifics.pb.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using syncer::SyncData; |
| 15 using notifier::SyncedNotification; |
| 16 using sync_pb::EntitySpecifics; |
| 17 using sync_pb::SyncedNotificationSpecifics; |
| 18 using sync_pb::SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT; |
| 19 |
| 20 namespace { |
| 21 |
| 22 const int64 kFakeCreationTime = 42; |
| 23 |
| 24 const char kTitle1[] = "New appointment at 2:15"; |
| 25 const char kTitle2[] = "Email from Mark: Upcoming Ski trip"; |
| 26 const char kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf"; |
| 27 const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf"; |
| 28 const char kCoalescingKey1[] = "foo"; |
| 29 const char kCoalescingKey2[] = "bar"; |
| 30 const char kBody1[] = "Space Needle, 12:00 pm"; |
| 31 const char kBody2[] = "Stevens Pass is our first choice."; |
| 32 const char kIconUrl1[] = "http://www.google.com/icon1.jpg"; |
| 33 const char kIconUrl2[] = "http://www.google.com/icon2.jpg"; |
| 34 const char kImageUrl1[] = "http://www.google.com/image1.jpg"; |
| 35 const char kImageUrl2[] = "http://www.google.com/image2.jpg"; |
| 36 |
| 37 } // namespace |
| 38 |
| 39 class SyncedNotificationTest : public testing::Test { |
| 40 public: |
| 41 SyncedNotificationTest() : notification1(NULL), |
| 42 notification2(NULL) {} |
| 43 ~SyncedNotificationTest() {} |
| 44 |
| 45 // Methods from testing::Test. |
| 46 |
| 47 virtual void SetUp() OVERRIDE { |
| 48 syncer::SyncData sync_data1 = CreateSyncData(kTitle1, kBody1, kIconUrl1, |
| 49 kAppId1, kCoalescingKey1); |
| 50 syncer::SyncData sync_data2 = CreateSyncData(kTitle2, kBody2, kIconUrl2, |
| 51 kAppId2, kCoalescingKey2); |
| 52 |
| 53 notification1.reset(new SyncedNotification(sync_data1)); |
| 54 notification2.reset(new SyncedNotification(sync_data2)); |
| 55 } |
| 56 |
| 57 virtual void TearDown() OVERRIDE { |
| 58 } |
| 59 |
| 60 scoped_ptr<SyncedNotification> notification1; |
| 61 scoped_ptr<SyncedNotification> notification2; |
| 62 |
| 63 private: |
| 64 // Helper to create syncer::SyncData. |
| 65 static SyncData CreateSyncData(const std::string& title, |
| 66 const std::string& body, |
| 67 const std::string& icon_url, |
| 68 const std::string& app_id, |
| 69 const std::string& coalescing_key) { |
| 70 // CreateLocalData makes a copy of this, so this can safely live |
| 71 // on the stack. |
| 72 EntitySpecifics entity_specifics; |
| 73 |
| 74 // Get a writeable pointer to the sync notifications specifics inside the |
| 75 // entity specifics. |
| 76 SyncedNotificationSpecifics* specifics = |
| 77 entity_specifics.mutable_synced_notification(); |
| 78 |
| 79 specifics->mutable_coalesced_notification()-> |
| 80 mutable_render_info()-> |
| 81 mutable_layout()-> |
| 82 set_layout_type( |
| 83 SyncedNotificationRenderInfo_Layout_LayoutType_TITLE_AND_SUBTEXT); |
| 84 |
| 85 specifics->mutable_coalesced_notification()-> |
| 86 mutable_id()-> |
| 87 set_app_id(app_id); |
| 88 |
| 89 specifics->mutable_coalesced_notification()-> |
| 90 mutable_id()-> |
| 91 set_coalescing_key(coalescing_key); |
| 92 |
| 93 specifics->mutable_coalesced_notification()-> |
| 94 mutable_render_info()-> |
| 95 mutable_layout()-> |
| 96 mutable_title_and_subtext_data()-> |
| 97 set_title(title); |
| 98 |
| 99 specifics->mutable_coalesced_notification()-> |
| 100 mutable_render_info()-> |
| 101 mutable_layout()-> |
| 102 mutable_title_and_subtext_data()-> |
| 103 add_subtext(body); |
| 104 |
| 105 specifics->mutable_coalesced_notification()-> |
| 106 mutable_render_info()-> |
| 107 mutable_layout()-> |
| 108 mutable_title_and_subtext_data()-> |
| 109 mutable_icon()-> |
| 110 set_url(icon_url); |
| 111 |
| 112 specifics->mutable_coalesced_notification()-> |
| 113 set_creation_time_msec(kFakeCreationTime); |
| 114 |
| 115 specifics->mutable_coalesced_notification()-> |
| 116 add_notification(); |
| 117 |
| 118 SyncData sync_data = SyncData::CreateLocalData( |
| 119 "syncer::SYNCED_NOTIFICATIONS", |
| 120 "SyncedNotificationTest", |
| 121 entity_specifics); |
| 122 |
| 123 return sync_data; |
| 124 } |
| 125 |
| 126 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(SyncedNotificationTest); |
| 128 }; |
| 129 |
| 130 // test simple accessors |
| 131 |
| 132 TEST_F(SyncedNotificationTest, GetAppIdTest) { |
| 133 std::string found_app_id = notification1->app_id(); |
| 134 std::string expected_app_id(kAppId1); |
| 135 |
| 136 EXPECT_EQ(found_app_id, expected_app_id); |
| 137 } |
| 138 |
| 139 TEST_F(SyncedNotificationTest, GetCoalescingKeyTest) { |
| 140 std::string found_key = notification1->coalescing_key(); |
| 141 std::string expected_key(kCoalescingKey1); |
| 142 |
| 143 EXPECT_EQ(found_key, expected_key); |
| 144 } |
| 145 |
| 146 TEST_F(SyncedNotificationTest, GetTitleTest) { |
| 147 std::string found_title = notification1->title(); |
| 148 std::string expected_title(kTitle1); |
| 149 |
| 150 EXPECT_EQ(found_title, expected_title); |
| 151 } |
| 152 |
| 153 TEST_F(SyncedNotificationTest, GetIconURLTest) { |
| 154 std::string found_icon_url = notification1->icon_url().spec(); |
| 155 std::string expected_icon_url(kIconUrl1); |
| 156 |
| 157 EXPECT_EQ(found_icon_url, expected_icon_url); |
| 158 } |
| 159 |
| 160 // TODO(petewil): Improve ctor to pass in an image and type so this test can |
| 161 // pass on actual data. |
| 162 TEST_F(SyncedNotificationTest, GetImageURLTest) { |
| 163 std::string found_image_url = notification1->image_url().spec(); |
| 164 std::string expected_image_url; // TODO(petewil): (kImageUrl1) |
| 165 |
| 166 EXPECT_EQ(found_image_url, expected_image_url); |
| 167 } |
| 168 |
| 169 // TODO(petewil): test with a multi-line body |
| 170 TEST_F(SyncedNotificationTest, GetBodyTest) { |
| 171 std::string found_body = notification1->body(); |
| 172 std::string expected_body(kBody1); |
| 173 |
| 174 EXPECT_EQ(found_body, expected_body); |
| 175 } |
| 176 |
| 177 TEST_F(SyncedNotificationTest, GetNotificationIdTest) { |
| 178 std::string found_id = notification1->notification_id(); |
| 179 std::string expected_id(kAppId1); |
| 180 expected_id += "/"; |
| 181 expected_id += kCoalescingKey1; |
| 182 |
| 183 EXPECT_EQ(found_id, expected_id); |
| 184 } |
| 185 |
| 186 // test that equals works as we expect |
| 187 TEST_F(SyncedNotificationTest, EqualsTest) { |
| 188 EXPECT_TRUE(notification1->Equals(*notification1)); |
| 189 EXPECT_TRUE(notification2->Equals(*notification2)); |
| 190 EXPECT_FALSE(notification1->Equals(*notification2)); |
| 191 } |
| 192 |
| 193 // Add a test for set_local_changes and has_local_changes together |
| 194 // Add a test for a notification being read and or deleted |
OLD | NEW |