| 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 "chrome/browser/notifications/sync_notifier/synced_notification.h" | 8 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
| 9 #include "sync/api/sync_data.h" | 9 #include "sync/api/sync_data.h" |
| 10 #include "sync/protocol/sync.pb.h" | 10 #include "sync/protocol/sync.pb.h" |
| 11 #include "sync/protocol/synced_notification_specifics.pb.h" | 11 #include "sync/protocol/synced_notification_specifics.pb.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using syncer::SyncData; | 14 using syncer::SyncData; |
| 15 using notifier::SyncedNotification; | 15 using notifier::SyncedNotification; |
| 16 using sync_pb::EntitySpecifics; | 16 using sync_pb::EntitySpecifics; |
| 17 using sync_pb::SyncedNotificationSpecifics; | 17 using sync_pb::SyncedNotificationSpecifics; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const int64 kFakeCreationTime = 42; | 21 const int64 kFakeCreationTime = 42; |
| 22 const int kPriority = 1; |
| 22 | 23 |
| 23 const char kTitle1[] = "New appointment at 2:15"; | 24 const char kTitle1[] = "New appointment at 2:15"; |
| 24 const char kTitle2[] = "Email from Mark: Upcoming Ski trip"; | 25 const char kTitle2[] = "Email from Mark: Upcoming Ski trip"; |
| 25 const char kTitle3[] = "Weather alert - light rain tonight."; | 26 const char kTitle3[] = "Weather alert - light rain tonight."; |
| 26 const char kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf"; | 27 const char kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf"; |
| 27 const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf"; | 28 const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf"; |
| 28 const char kKey1[] = "foo"; | 29 const char kKey1[] = "foo"; |
| 29 const char kKey2[] = "bar"; | 30 const char kKey2[] = "bar"; |
| 30 const char kText1[] = "Space Needle, 12:00 pm"; | 31 const char kText1[] = "Space Needle, 12:00 pm"; |
| 31 const char kText2[] = "Stevens Pass is our first choice."; | 32 const char kText2[] = "Stevens Pass is our first choice."; |
| 32 const char kText3[] = "More rain expected in the Seattle area tonight."; | 33 const char kText3[] = "More rain expected in the Seattle area tonight."; |
| 33 const char kIconUrl1[] = "http://www.google.com/icon1.jpg"; | 34 const char kIconUrl1[] = "http://www.google.com/icon1.jpg"; |
| 34 const char kIconUrl2[] = "http://www.google.com/icon2.jpg"; | 35 const char kIconUrl2[] = "http://www.google.com/icon2.jpg"; |
| 35 const char kIconUrl3[] = "http://www.google.com/icon3.jpg"; | 36 const char kIconUrl3[] = "http://www.google.com/icon3.jpg"; |
| 36 const char kImageUrl1[] = "http://www.google.com/image1.jpg"; | 37 const char kImageUrl1[] = "http://www.google.com/image1.jpg"; |
| 37 const char kImageUrl2[] = "http://www.google.com/image2.jpg"; | 38 const char kImageUrl2[] = "http://www.google.com/image2.jpg"; |
| 38 const char kImageUrl3[] = "http://www.google.com/image3.jpg"; | 39 const char kImageUrl3[] = "http://www.google.com/image3.jpg"; |
| 40 const char kDefaultDestinationTitle[] = "Open web page"; |
| 41 const char kDefaultDestinationIconUrl[] = "http://www.google.com/image4.jpg"; |
| 42 const char kDefaultDestinationUrl[] = "http://www.google.com"; |
| 43 const char kButtonOneTitle[] = "Read"; |
| 44 const char kButtonOneIconUrl[] = "http://www.google.com/image5.jpg"; |
| 45 const char kButtonOneUrl[] = "http://www.google.com/do-something1"; |
| 46 const char kButtonTwoTitle[] = "Reply"; |
| 47 const char kButtonTwoIconUrl[] = "http://www.google.com/image6.jpg"; |
| 48 const char kButtonTwoUrl[] = "http://www.google.com/do-something2"; |
| 49 const char kContainedTitle1[] = "Today's Picnic moved"; |
| 50 const char kContainedTitle2[] = "Group Run Today"; |
| 51 const char kContainedTitle3[] = "Starcraft Tonight"; |
| 52 const char kContainedMessage1[] = "Due to rain, we will be inside the cafe."; |
| 53 const char kContainedMessage2[] = "Meet at noon in the Gym."; |
| 54 const char kContainedMessage3[] = "Let's play starcraft tonight on the LAN."; |
| 55 |
| 39 const sync_pb::CoalescedSyncedNotification_ReadState kRead = | 56 const sync_pb::CoalescedSyncedNotification_ReadState kRead = |
| 40 sync_pb::CoalescedSyncedNotification_ReadState_READ; | 57 sync_pb::CoalescedSyncedNotification_ReadState_READ; |
| 41 const sync_pb::CoalescedSyncedNotification_ReadState kUnread = | 58 const sync_pb::CoalescedSyncedNotification_ReadState kUnread = |
| 42 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD; | 59 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD; |
| 43 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = | 60 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = |
| 44 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; | 61 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; |
| 45 } // namespace | 62 } // namespace |
| 46 | 63 |
| 47 class SyncedNotificationTest : public testing::Test { | 64 class SyncedNotificationTest : public testing::Test { |
| 48 public: | 65 public: |
| 49 SyncedNotificationTest() {} | 66 SyncedNotificationTest() {} |
| 50 ~SyncedNotificationTest() {} | 67 ~SyncedNotificationTest() {} |
| 51 | 68 |
| 52 // Methods from testing::Test. | 69 // Methods from testing::Test. |
| 53 | 70 |
| 54 virtual void SetUp() OVERRIDE { | 71 virtual void SetUp() OVERRIDE { |
| 55 sync_data1_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, | 72 sync_data1_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, |
| 56 kAppId1, kKey1, kUnread); | 73 kAppId1, kKey1, kUnread); |
| 57 sync_data2_ = CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl1, | 74 sync_data2_ = CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl2, |
| 58 kAppId2, kKey2, kUnread); | 75 kAppId2, kKey2, kUnread); |
| 59 // Notification 3 will have the same ID as notification1, but different | 76 // Notification 3 will have the same ID as notification1, but different |
| 60 // data inside. | 77 // data inside. |
| 61 sync_data3_ = CreateSyncData(kTitle3, kText3, kIconUrl3, kImageUrl1, | 78 sync_data3_ = CreateSyncData(kTitle3, kText3, kIconUrl3, kImageUrl3, |
| 62 kAppId1, kKey1, kUnread); | 79 kAppId1, kKey1, kUnread); |
| 63 // Notification 4 will be the same as 1, but the read state will be 'read'. | 80 // Notification 4 will be the same as 1, but the read state will be 'read'. |
| 64 sync_data4_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, | 81 sync_data4_ = CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, |
| 65 kAppId1, kKey1, kDismissed); | 82 kAppId1, kKey1, kDismissed); |
| 66 | 83 |
| 67 notification1_.reset(new SyncedNotification(sync_data1_)); | 84 notification1_.reset(new SyncedNotification(sync_data1_)); |
| 68 notification2_.reset(new SyncedNotification(sync_data2_)); | 85 notification2_.reset(new SyncedNotification(sync_data2_)); |
| 69 notification3_.reset(new SyncedNotification(sync_data3_)); | 86 notification3_.reset(new SyncedNotification(sync_data3_)); |
| 70 notification4_.reset(new SyncedNotification(sync_data4_)); | 87 notification4_.reset(new SyncedNotification(sync_data4_)); |
| 71 } | 88 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 101 SyncedNotificationSpecifics* specifics = | 118 SyncedNotificationSpecifics* specifics = |
| 102 entity_specifics.mutable_synced_notification(); | 119 entity_specifics.mutable_synced_notification(); |
| 103 | 120 |
| 104 specifics->mutable_coalesced_notification()-> | 121 specifics->mutable_coalesced_notification()-> |
| 105 set_app_id(app_id); | 122 set_app_id(app_id); |
| 106 | 123 |
| 107 specifics->mutable_coalesced_notification()-> | 124 specifics->mutable_coalesced_notification()-> |
| 108 set_key(key); | 125 set_key(key); |
| 109 | 126 |
| 110 specifics->mutable_coalesced_notification()-> | 127 specifics->mutable_coalesced_notification()-> |
| 128 set_priority(static_cast<sync_pb::CoalescedSyncedNotification_Priority>( |
| 129 kPriority)); |
| 130 |
| 131 // Set the title. |
| 132 specifics->mutable_coalesced_notification()-> |
| 111 mutable_render_info()-> | 133 mutable_render_info()-> |
| 112 mutable_expanded_info()-> | 134 mutable_expanded_info()-> |
| 113 mutable_simple_expanded_layout()-> | 135 mutable_simple_expanded_layout()-> |
| 114 set_title(title); | 136 set_title(title); |
| 115 | 137 |
| 138 // Set the text. |
| 116 specifics->mutable_coalesced_notification()-> | 139 specifics->mutable_coalesced_notification()-> |
| 117 mutable_render_info()-> | 140 mutable_render_info()-> |
| 118 mutable_expanded_info()-> | 141 mutable_expanded_info()-> |
| 119 mutable_simple_expanded_layout()-> | 142 mutable_simple_expanded_layout()-> |
| 120 set_text(text); | 143 set_text(text); |
| 121 | 144 |
| 145 // Add the collapsed info and set the app_icon_url on it. |
| 122 specifics->mutable_coalesced_notification()-> | 146 specifics->mutable_coalesced_notification()-> |
| 123 mutable_render_info()-> | 147 mutable_render_info()-> |
| 124 mutable_expanded_info()-> | 148 mutable_expanded_info()-> |
| 125 add_collapsed_info(); | 149 add_collapsed_info(); |
| 126 specifics->mutable_coalesced_notification()-> | 150 specifics->mutable_coalesced_notification()-> |
| 127 mutable_render_info()-> | 151 mutable_render_info()-> |
| 128 mutable_expanded_info()-> | 152 mutable_expanded_info()-> |
| 129 mutable_collapsed_info(0)-> | 153 mutable_collapsed_info(0)-> |
| 130 mutable_simple_collapsed_layout()-> | 154 mutable_simple_collapsed_layout()-> |
| 131 mutable_app_icon()-> | 155 mutable_app_icon()-> |
| 132 set_url(app_icon_url); | 156 set_url(app_icon_url); |
| 133 | 157 |
| 158 // Add the media object and set the image url on it. |
| 134 specifics->mutable_coalesced_notification()-> | 159 specifics->mutable_coalesced_notification()-> |
| 135 mutable_render_info()-> | 160 mutable_render_info()-> |
| 136 mutable_expanded_info()-> | 161 mutable_expanded_info()-> |
| 137 mutable_simple_expanded_layout()-> | 162 mutable_simple_expanded_layout()-> |
| 138 add_media(); | 163 add_media(); |
| 139 specifics->mutable_coalesced_notification()-> | 164 specifics->mutable_coalesced_notification()-> |
| 140 mutable_render_info()-> | 165 mutable_render_info()-> |
| 141 mutable_expanded_info()-> | 166 mutable_expanded_info()-> |
| 142 mutable_simple_expanded_layout()-> | 167 mutable_simple_expanded_layout()-> |
| 143 mutable_media(0)-> | 168 mutable_media(0)-> |
| 144 mutable_image()-> | 169 mutable_image()-> |
| 145 set_url(image_url); | 170 set_url(image_url); |
| 146 | 171 |
| 147 specifics->mutable_coalesced_notification()-> | 172 specifics->mutable_coalesced_notification()-> |
| 148 set_creation_time_msec(kFakeCreationTime); | 173 set_creation_time_msec(kFakeCreationTime); |
| 149 | 174 |
| 150 specifics->mutable_coalesced_notification()-> | 175 specifics->mutable_coalesced_notification()-> |
| 151 add_notification(); | |
| 152 | |
| 153 specifics->mutable_coalesced_notification()-> | |
| 154 set_read_state(read_state); | 176 set_read_state(read_state); |
| 155 | 177 |
| 156 // TODO(petewil): Improve ctor to pass in an image and type so this test can | 178 // Contained notification one. |
| 157 // pass on actual data. | 179 // We re-use the collapsed info we added for the app_icon_url, |
| 180 // so no need to create another one here. |
| 181 specifics->mutable_coalesced_notification()-> |
| 182 mutable_render_info()-> |
| 183 mutable_expanded_info()-> |
| 184 mutable_collapsed_info(0)-> |
| 185 mutable_simple_collapsed_layout()-> |
| 186 set_heading(kContainedTitle1); |
| 187 specifics->mutable_coalesced_notification()-> |
| 188 mutable_render_info()-> |
| 189 mutable_expanded_info()-> |
| 190 mutable_collapsed_info(0)-> |
| 191 mutable_simple_collapsed_layout()-> |
| 192 set_description(kContainedMessage1); |
| 193 |
| 194 // Contained notification two. |
| 195 specifics->mutable_coalesced_notification()-> |
| 196 mutable_render_info()-> |
| 197 mutable_expanded_info()-> |
| 198 add_collapsed_info(); |
| 199 specifics->mutable_coalesced_notification()-> |
| 200 mutable_render_info()-> |
| 201 mutable_expanded_info()-> |
| 202 mutable_collapsed_info(1)-> |
| 203 mutable_simple_collapsed_layout()-> |
| 204 set_heading(kContainedTitle2); |
| 205 specifics->mutable_coalesced_notification()-> |
| 206 mutable_render_info()-> |
| 207 mutable_expanded_info()-> |
| 208 mutable_collapsed_info(1)-> |
| 209 mutable_simple_collapsed_layout()-> |
| 210 set_description(kContainedMessage2); |
| 211 |
| 212 // Contained notification three. |
| 213 specifics->mutable_coalesced_notification()-> |
| 214 mutable_render_info()-> |
| 215 mutable_expanded_info()-> |
| 216 add_collapsed_info(); |
| 217 specifics->mutable_coalesced_notification()-> |
| 218 mutable_render_info()-> |
| 219 mutable_expanded_info()-> |
| 220 mutable_collapsed_info(2)-> |
| 221 mutable_simple_collapsed_layout()-> |
| 222 set_heading(kContainedTitle3); |
| 223 specifics->mutable_coalesced_notification()-> |
| 224 mutable_render_info()-> |
| 225 mutable_expanded_info()-> |
| 226 mutable_collapsed_info(2)-> |
| 227 mutable_simple_collapsed_layout()-> |
| 228 set_description(kContainedMessage3); |
| 229 |
| 230 // Default Destination. |
| 231 specifics->mutable_coalesced_notification()-> |
| 232 mutable_render_info()-> |
| 233 mutable_collapsed_info()-> |
| 234 mutable_default_destination()-> |
| 235 set_text(kDefaultDestinationTitle); |
| 236 specifics->mutable_coalesced_notification()-> |
| 237 mutable_render_info()-> |
| 238 mutable_collapsed_info()-> |
| 239 mutable_default_destination()-> |
| 240 mutable_icon()-> |
| 241 set_url(kDefaultDestinationIconUrl); |
| 242 specifics->mutable_coalesced_notification()-> |
| 243 mutable_render_info()-> |
| 244 mutable_collapsed_info()-> |
| 245 mutable_default_destination()-> |
| 246 mutable_icon()-> |
| 247 set_alt_text(kDefaultDestinationTitle); |
| 248 specifics->mutable_coalesced_notification()-> |
| 249 mutable_render_info()-> |
| 250 mutable_collapsed_info()-> |
| 251 mutable_default_destination()-> |
| 252 set_url(kDefaultDestinationUrl); |
| 253 |
| 254 // Buttons are represented as targets. |
| 255 |
| 256 // Button One. |
| 257 specifics->mutable_coalesced_notification()-> |
| 258 mutable_render_info()-> |
| 259 mutable_collapsed_info()-> |
| 260 add_target(); |
| 261 specifics->mutable_coalesced_notification()-> |
| 262 mutable_render_info()-> |
| 263 mutable_collapsed_info()-> |
| 264 mutable_target(0)-> |
| 265 mutable_action()-> |
| 266 set_text(kButtonOneTitle); |
| 267 specifics->mutable_coalesced_notification()-> |
| 268 mutable_render_info()-> |
| 269 mutable_collapsed_info()-> |
| 270 mutable_target(0)-> |
| 271 mutable_action()-> |
| 272 mutable_icon()-> |
| 273 set_url(kButtonOneIconUrl); |
| 274 specifics->mutable_coalesced_notification()-> |
| 275 mutable_render_info()-> |
| 276 mutable_collapsed_info()-> |
| 277 mutable_target(0)-> |
| 278 mutable_action()-> |
| 279 mutable_icon()-> |
| 280 set_alt_text(kButtonOneTitle); |
| 281 specifics->mutable_coalesced_notification()-> |
| 282 mutable_render_info()-> |
| 283 mutable_collapsed_info()-> |
| 284 mutable_target(0)-> |
| 285 mutable_action()-> |
| 286 set_url(kButtonOneUrl); |
| 287 |
| 288 // Button Two. |
| 289 specifics->mutable_coalesced_notification()-> |
| 290 mutable_render_info()-> |
| 291 mutable_collapsed_info()-> |
| 292 add_target(); |
| 293 specifics->mutable_coalesced_notification()-> |
| 294 mutable_render_info()-> |
| 295 mutable_collapsed_info()-> |
| 296 mutable_target(1)-> |
| 297 mutable_action()-> |
| 298 set_text(kButtonTwoTitle); |
| 299 specifics->mutable_coalesced_notification()-> |
| 300 mutable_render_info()-> |
| 301 mutable_collapsed_info()-> |
| 302 mutable_target(1)-> |
| 303 mutable_action()-> |
| 304 mutable_icon()-> |
| 305 set_url(kButtonTwoIconUrl); |
| 306 specifics->mutable_coalesced_notification()-> |
| 307 mutable_render_info()-> |
| 308 mutable_collapsed_info()-> |
| 309 mutable_target(1)-> |
| 310 mutable_action()-> |
| 311 mutable_icon()-> |
| 312 set_alt_text(kButtonTwoTitle); |
| 313 specifics->mutable_coalesced_notification()-> |
| 314 mutable_render_info()-> |
| 315 mutable_collapsed_info()-> |
| 316 mutable_target(1)-> |
| 317 mutable_action()-> |
| 318 set_url(kButtonTwoUrl); |
| 319 |
| 158 SyncData sync_data = SyncData::CreateLocalData( | 320 SyncData sync_data = SyncData::CreateLocalData( |
| 159 "syncer::SYNCED_NOTIFICATIONS", | 321 "syncer::SYNCED_NOTIFICATIONS", |
| 160 "SyncedNotificationTest", | 322 "SyncedNotificationTest", |
| 161 entity_specifics); | 323 entity_specifics); |
| 162 | 324 |
| 163 return sync_data; | 325 return sync_data; |
| 164 } | 326 } |
| 165 | 327 |
| 166 private: | 328 private: |
| 167 DISALLOW_COPY_AND_ASSIGN(SyncedNotificationTest); | 329 DISALLOW_COPY_AND_ASSIGN(SyncedNotificationTest); |
| 168 }; | 330 }; |
| 169 | 331 |
| 170 // test simple accessors | 332 // test simple accessors |
| 171 | 333 |
| 172 TEST_F(SyncedNotificationTest, GetAppIdTest) { | 334 TEST_F(SyncedNotificationTest, GetAppIdTest) { |
| 173 std::string found_app_id = notification1_->app_id(); | 335 std::string found_app_id = notification1_->GetAppId(); |
| 174 std::string expected_app_id(kAppId1); | 336 std::string expected_app_id(kAppId1); |
| 175 | 337 |
| 176 EXPECT_EQ(found_app_id, expected_app_id); | 338 EXPECT_EQ(found_app_id, expected_app_id); |
| 177 } | 339 } |
| 178 | 340 |
| 179 TEST_F(SyncedNotificationTest, GetKeyTest) { | 341 TEST_F(SyncedNotificationTest, GetKeyTest) { |
| 180 std::string found_key = notification1_->key(); | 342 std::string found_key = notification1_->GetKey(); |
| 181 std::string expected_key(kKey1); | 343 std::string expected_key(kKey1); |
| 182 | 344 |
| 183 EXPECT_EQ(expected_key, found_key); | 345 EXPECT_EQ(expected_key, found_key); |
| 184 } | 346 } |
| 185 | 347 |
| 186 TEST_F(SyncedNotificationTest, GetTitleTest) { | 348 TEST_F(SyncedNotificationTest, GetTitleTest) { |
| 187 std::string found_title = notification1_->title(); | 349 std::string found_title = notification1_->GetTitle(); |
| 188 std::string expected_title(kTitle1); | 350 std::string expected_title(kTitle1); |
| 189 | 351 |
| 190 EXPECT_EQ(expected_title, found_title); | 352 EXPECT_EQ(expected_title, found_title); |
| 191 } | 353 } |
| 192 | 354 |
| 193 TEST_F(SyncedNotificationTest, GetIconURLTest) { | 355 TEST_F(SyncedNotificationTest, GetIconURLTest) { |
| 194 std::string found_icon_url = notification1_->app_icon_url().spec(); | 356 std::string found_icon_url = notification1_->GetAppIconUrl().spec(); |
| 195 std::string expected_icon_url(kIconUrl1); | 357 std::string expected_icon_url(kIconUrl1); |
| 196 | 358 |
| 197 EXPECT_EQ(expected_icon_url, found_icon_url); | 359 EXPECT_EQ(expected_icon_url, found_icon_url); |
| 198 } | 360 } |
| 199 | 361 |
| 200 TEST_F(SyncedNotificationTest, GetReadStateTest) { | 362 TEST_F(SyncedNotificationTest, GetReadStateTest) { |
| 201 SyncedNotification::ReadState found_state1 = | 363 SyncedNotification::ReadState found_state1 = |
| 202 notification1_->read_state(); | 364 notification1_->GetReadState(); |
| 203 SyncedNotification::ReadState expected_state1(SyncedNotification::kUnread); | 365 SyncedNotification::ReadState expected_state1(SyncedNotification::kUnread); |
| 204 | 366 |
| 205 EXPECT_EQ(expected_state1, found_state1); | 367 EXPECT_EQ(expected_state1, found_state1); |
| 206 | 368 |
| 207 SyncedNotification::ReadState found_state2 = | 369 SyncedNotification::ReadState found_state2 = |
| 208 notification4_->read_state(); | 370 notification4_->GetReadState(); |
| 209 SyncedNotification::ReadState expected_state2(SyncedNotification::kDismissed); | 371 SyncedNotification::ReadState expected_state2(SyncedNotification::kDismissed); |
| 210 | 372 |
| 211 EXPECT_EQ(expected_state2, found_state2); | 373 EXPECT_EQ(expected_state2, found_state2); |
| 212 } | 374 } |
| 213 | 375 |
| 214 // TODO(petewil): Improve ctor to pass in an image and type so this test can | 376 // TODO(petewil): Improve ctor to pass in an image and type so this test can |
| 215 // pass on actual data. | 377 // pass on actual data. |
| 216 TEST_F(SyncedNotificationTest, GetImageURLTest) { | 378 TEST_F(SyncedNotificationTest, GetImageURLTest) { |
| 217 std::string found_image_url = notification1_->image_url().spec(); | 379 std::string found_image_url = notification1_->GetImageUrl().spec(); |
| 218 std::string expected_image_url = kImageUrl1; | 380 std::string expected_image_url = kImageUrl1; |
| 219 | 381 |
| 220 EXPECT_EQ(expected_image_url, found_image_url); | 382 EXPECT_EQ(expected_image_url, found_image_url); |
| 221 } | 383 } |
| 222 | 384 |
| 223 // TODO(petewil): test with a multi-line body | 385 // TODO(petewil): test with a multi-line body |
| 224 TEST_F(SyncedNotificationTest, GetTextTest) { | 386 TEST_F(SyncedNotificationTest, GetTextTest) { |
| 225 std::string found_text = notification1_->text(); | 387 std::string found_text = notification1_->GetText(); |
| 226 std::string expected_text(kText1); | 388 std::string expected_text(kText1); |
| 227 | 389 |
| 228 EXPECT_EQ(expected_text, found_text); | 390 EXPECT_EQ(expected_text, found_text); |
| 229 } | 391 } |
| 230 | 392 |
| 231 TEST_F(SyncedNotificationTest, GetNotificationIdTest) { | 393 TEST_F(SyncedNotificationTest, GetCreationTimeTest) { |
| 232 std::string found_id = notification1_->notification_id(); | 394 uint64 found_time = notification1_->GetCreationTime(); |
| 233 std::string expected_id(kKey1); | 395 EXPECT_EQ(kFakeCreationTime, found_time); |
| 234 | |
| 235 EXPECT_EQ(expected_id, found_id); | |
| 236 } | 396 } |
| 237 | 397 |
| 238 // test that the ID match function works as we expect | 398 TEST_F(SyncedNotificationTest, GetPriorityTest) { |
| 239 TEST_F(SyncedNotificationTest, IdMatchesTest) { | 399 double found_priority = notification1_->GetPriority(); |
| 240 EXPECT_TRUE(notification1_->IdMatches(*notification1_)); | 400 EXPECT_EQ(static_cast<double>(kPriority), found_priority); |
| 241 EXPECT_TRUE(notification2_->IdMatches(*notification2_)); | 401 } |
| 242 EXPECT_FALSE(notification1_->IdMatches(*notification2_)); | 402 |
| 243 EXPECT_TRUE(notification1_->IdMatches(*notification3_)); | 403 TEST_F(SyncedNotificationTest, GetButtonCountTest) { |
| 244 EXPECT_TRUE(notification1_->IdMatches(*notification4_)); | 404 int found_button_count = notification1_->GetButtonCount(); |
| 405 EXPECT_EQ(2, found_button_count); |
| 406 } |
| 407 |
| 408 TEST_F(SyncedNotificationTest, GetNotificationCountTest) { |
| 409 int found_notification_count = notification1_->GetNotificationCount(); |
| 410 EXPECT_EQ(3, found_notification_count); |
| 411 } |
| 412 |
| 413 TEST_F(SyncedNotificationTest, GetDefaultDestinationDataTest) { |
| 414 std::string default_destination_title = |
| 415 notification1_->GetDefaultDestinationTitle(); |
| 416 std::string default_destination_icon_url = |
| 417 notification1_->GetDefaultDestinationIconUrl(); |
| 418 std::string default_destination_url = |
| 419 notification1_->GetDefaultDestinationUrl(); |
| 420 EXPECT_EQ(std::string(kDefaultDestinationTitle), default_destination_title); |
| 421 EXPECT_EQ(std::string(kDefaultDestinationIconUrl), |
| 422 default_destination_icon_url); |
| 423 EXPECT_EQ(std::string(kDefaultDestinationUrl), default_destination_url); |
| 424 } |
| 425 |
| 426 TEST_F(SyncedNotificationTest, GetButtonDataTest) { |
| 427 std::string button_one_title = notification1_->GetButtonOneTitle(); |
| 428 std::string button_one_icon_url = notification1_->GetButtonOneIconUrl(); |
| 429 std::string button_one_url = notification1_->GetButtonOneUrl(); |
| 430 std::string button_two_title = notification1_->GetButtonTwoTitle(); |
| 431 std::string button_two_icon_url = notification1_->GetButtonTwoIconUrl(); |
| 432 std::string button_two_url = notification1_->GetButtonTwoUrl(); |
| 433 EXPECT_EQ(std::string(kButtonOneTitle), button_one_title); |
| 434 EXPECT_EQ(std::string(kButtonOneIconUrl), button_one_icon_url); |
| 435 EXPECT_EQ(std::string(kButtonOneUrl), button_one_url); |
| 436 EXPECT_EQ(std::string(kButtonTwoTitle), button_two_title); |
| 437 EXPECT_EQ(std::string(kButtonTwoIconUrl), button_two_icon_url); |
| 438 EXPECT_EQ(std::string(kButtonTwoUrl), button_two_url); |
| 439 } |
| 440 |
| 441 TEST_F(SyncedNotificationTest, ContainedNotificationTest) { |
| 442 std::string notification_title1 = |
| 443 notification1_->GetContainedNotificationTitle(0); |
| 444 std::string notification_title2 = |
| 445 notification1_->GetContainedNotificationTitle(1); |
| 446 std::string notification_title3 = |
| 447 notification1_->GetContainedNotificationTitle(2); |
| 448 std::string notification_message1 = |
| 449 notification1_->GetContainedNotificationMessage(0); |
| 450 std::string notification_message2 = |
| 451 notification1_->GetContainedNotificationMessage(1); |
| 452 std::string notification_message3 = |
| 453 notification1_->GetContainedNotificationMessage(2); |
| 454 |
| 455 EXPECT_EQ(std::string(kContainedTitle1), notification_title1); |
| 456 EXPECT_EQ(std::string(kContainedTitle2), notification_title2); |
| 457 EXPECT_EQ(std::string(kContainedTitle3), notification_title3); |
| 458 EXPECT_EQ(std::string(kContainedMessage1), notification_message1); |
| 459 EXPECT_EQ(std::string(kContainedMessage2), notification_message2); |
| 460 EXPECT_EQ(std::string(kContainedMessage3), notification_message3); |
| 245 } | 461 } |
| 246 | 462 |
| 247 // test that EqualsIgnoringReadState works as we expect | 463 // test that EqualsIgnoringReadState works as we expect |
| 248 TEST_F(SyncedNotificationTest, EqualsIgnoringReadStateTest) { | 464 TEST_F(SyncedNotificationTest, EqualsIgnoringReadStateTest) { |
| 249 EXPECT_TRUE(notification1_->EqualsIgnoringReadState(*notification1_)); | 465 EXPECT_TRUE(notification1_->EqualsIgnoringReadState(*notification1_)); |
| 250 EXPECT_TRUE(notification2_->EqualsIgnoringReadState(*notification2_)); | 466 EXPECT_TRUE(notification2_->EqualsIgnoringReadState(*notification2_)); |
| 251 EXPECT_FALSE(notification1_->EqualsIgnoringReadState(*notification2_)); | 467 EXPECT_FALSE(notification1_->EqualsIgnoringReadState(*notification2_)); |
| 252 EXPECT_FALSE(notification1_->EqualsIgnoringReadState(*notification3_)); | 468 EXPECT_FALSE(notification1_->EqualsIgnoringReadState(*notification3_)); |
| 253 EXPECT_TRUE(notification1_->EqualsIgnoringReadState(*notification4_)); | 469 EXPECT_TRUE(notification1_->EqualsIgnoringReadState(*notification4_)); |
| 254 } | 470 } |
| 255 | 471 |
| 256 TEST_F(SyncedNotificationTest, UpdateTest) { | 472 TEST_F(SyncedNotificationTest, UpdateTest) { |
| 257 scoped_ptr<SyncedNotification> notification5; | 473 scoped_ptr<SyncedNotification> notification5; |
| 258 notification5.reset(new SyncedNotification(sync_data1_)); | 474 notification5.reset(new SyncedNotification(sync_data1_)); |
| 259 | 475 |
| 260 // update with the sync data from notification2, and ensure they are equal. | 476 // update with the sync data from notification2, and ensure they are equal. |
| 261 notification5->Update(sync_data2_); | 477 notification5->Update(sync_data2_); |
| 262 EXPECT_TRUE(notification5->EqualsIgnoringReadState(*notification2_)); | 478 EXPECT_TRUE(notification5->EqualsIgnoringReadState(*notification2_)); |
| 263 EXPECT_EQ(notification5->read_state(), notification2_->read_state()); | 479 EXPECT_EQ(notification5->GetReadState(), notification2_->GetReadState()); |
| 264 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); | 480 EXPECT_FALSE(notification5->EqualsIgnoringReadState(*notification1_)); |
| 265 } | 481 } |
| 266 | 482 |
| 267 // Add a test for set_local_changes and has_local_changes together | 483 // Add a test for a notification being read and or deleted. |
| 268 // Add a test for a notification being read and or deleted | |
| OLD | NEW |