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