Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/notifications/notification.h" | |
| 8 #include "chrome/browser/notifications/notification_ui_manager.h" | 11 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 12 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 10 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" | 13 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
| 11 #include "sync/api/sync_change.h" | 14 #include "sync/api/sync_change.h" |
| 12 #include "sync/api/sync_change_processor.h" | 15 #include "sync/api/sync_change_processor.h" |
| 13 #include "sync/api/sync_error_factory.h" | 16 #include "sync/api/sync_error_factory.h" |
| 14 #include "sync/api/sync_error_factory_mock.h" | 17 #include "sync/api/sync_error_factory_mock.h" |
| 15 #include "sync/protocol/sync.pb.h" | 18 #include "sync/protocol/sync.pb.h" |
| 16 #include "sync/protocol/synced_notification_specifics.pb.h" | 19 #include "sync/protocol/synced_notification_specifics.pb.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 35 const char kAppId5[] = "fbcmoldooppoahjhfflnmljoanccek55"; | 38 const char kAppId5[] = "fbcmoldooppoahjhfflnmljoanccek55"; |
| 36 const char kAppId6[] = "fbcmoldooppoahjhfflnmljoanccek66"; | 39 const char kAppId6[] = "fbcmoldooppoahjhfflnmljoanccek66"; |
| 37 const char kAppId7[] = "fbcmoldooppoahjhfflnmljoanccek77"; | 40 const char kAppId7[] = "fbcmoldooppoahjhfflnmljoanccek77"; |
| 38 const char kKey1[] = "foo"; | 41 const char kKey1[] = "foo"; |
| 39 const char kKey2[] = "bar"; | 42 const char kKey2[] = "bar"; |
| 40 const char kKey3[] = "bat"; | 43 const char kKey3[] = "bat"; |
| 41 const char kKey4[] = "baz"; | 44 const char kKey4[] = "baz"; |
| 42 const char kKey5[] = "foobar"; | 45 const char kKey5[] = "foobar"; |
| 43 const char kKey6[] = "fu"; | 46 const char kKey6[] = "fu"; |
| 44 const char kKey7[] = "meta"; | 47 const char kKey7[] = "meta"; |
| 48 const char kIconUrl[] = "http://www.google.com/icon1.jpg"; | |
| 49 const char kTitle1[] = "New appointment at 2:15"; | |
| 50 const char kTitle2[] = "Email from Mark: Upcoming Ski trip"; | |
| 51 const char kTitle3[] = "Weather alert - light rain tonight."; | |
| 52 const char kTitle4[] = "Zombie Alert on I-405"; | |
| 53 const char kTitle5[] = "5-dimensional plutonian steam hockey scores"; | |
| 54 const char kTitle6[] = "Conterfactuals Inc Stock report"; | |
| 55 const char kTitle7[] = "Push Messaging app updated"; | |
| 56 const char kText1[] = "Space Needle, 12:00 pm"; | |
| 57 const char kText2[] = "Stevens Pass is our first choice."; | |
| 58 const char kText3[] = "More rain expected in the Seattle area tonight."; | |
| 59 const char kText4[] = "Traffic slowdown as motorists are hitting zombies"; | |
| 60 const char kText5[] = "Neptune wins, pi to e"; | |
| 61 const char kText6[] = "Beef flavored base for soups"; | |
| 62 const char kText7[] = "You now have the latest version of Push Messaging App."; | |
| 63 const char kIconUrl1[] = "http://www.google.com/icon1.jpg"; | |
| 64 const char kIconUrl2[] = "http://www.google.com/icon2.jpg"; | |
| 65 const char kIconUrl3[] = "http://www.google.com/icon3.jpg"; | |
| 66 const char kIconUrl4[] = "http://www.google.com/icon4.jpg"; | |
| 67 const char kIconUrl5[] = "http://www.google.com/icon5.jpg"; | |
| 68 const char kIconUrl6[] = "http://www.google.com/icon6.jpg"; | |
| 69 const char kIconUrl7[] = "http://www.google.com/icon7.jpg"; | |
| 70 const char kImageUrl1[] = "http://www.google.com/image1.jpg"; | |
| 71 const char kImageUrl2[] = "http://www.google.com/image2.jpg"; | |
| 72 const char kImageUrl3[] = "http://www.google.com/image3.jpg"; | |
| 73 const char kImageUrl4[] = "http://www.google.com/image4.jpg"; | |
| 74 const char kImageUrl5[] = "http://www.google.com/image5.jpg"; | |
| 75 const char kImageUrl6[] = "http://www.google.com/image6.jpg"; | |
| 76 const char kImageUrl7[] = "http://www.google.com/image7.jpg"; | |
| 77 const char kExpectedOriginUrl[] = | |
| 78 "chrome-extension://fboilmbenheemaomgaeehigklolhkhnf/"; | |
| 79 const char kDefaultDestinationTitle[] = "Open web page"; | |
| 80 const char kDefaultDestinationIconUrl[] = "http://www.google.com/image4.jpg"; | |
| 81 const char kDefaultDestinationUrl[] = "http://www.google.com"; | |
| 82 const char kButtonOneTitle[] = "Read"; | |
| 83 const char kButtonOneIconUrl[] = "http://www.google.com/image8.jpg"; | |
| 84 const char kButtonOneUrl[] = "http://www.google.com/do-something1"; | |
| 85 const char kButtonTwoTitle[] = "Reply"; | |
| 86 const char kButtonTwoIconUrl[] = "http://www.google.com/image9.jpg"; | |
| 87 const char kButtonTwoUrl[] = "http://www.google.com/do-something2"; | |
| 88 const char kContainedTitle1[] = "Today's Picnic moved"; | |
| 89 const char kContainedTitle2[] = "Group Run Today"; | |
| 90 const char kContainedTitle3[] = "Starcraft Tonight"; | |
| 91 const char kContainedMessage1[] = "Due to rain, we will be inside the cafe."; | |
| 92 const char kContainedMessage2[] = "Meet at noon in the Gym."; | |
| 93 const char kContainedMessage3[] = "Let's play starcraft tonight on the LAN."; | |
| 45 const int64 kFakeCreationTime = 42; | 94 const int64 kFakeCreationTime = 42; |
| 95 const int kFakePriority = 1; | |
| 46 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = | 96 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = |
| 47 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; | 97 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; |
| 48 const sync_pb::CoalescedSyncedNotification_ReadState kUnread = | 98 const sync_pb::CoalescedSyncedNotification_ReadState kUnread = |
| 49 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD; | 99 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD; |
| 50 | 100 |
| 51 // Extract notification id from syncer::SyncData. | 101 // Extract notification id from syncer::SyncData. |
| 52 std::string GetNotificationId(const SyncData& sync_data) { | 102 std::string GetNotificationId(const SyncData& sync_data) { |
| 53 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). | 103 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). |
| 54 synced_notification(); | 104 synced_notification(); |
| 105 | |
| 55 return specifics.coalesced_notification().key(); | 106 return specifics.coalesced_notification().key(); |
| 56 } | 107 } |
| 57 | 108 |
| 58 // Stub out the NotificationUIManager for unit testing. | 109 // Stub out the NotificationUIManager for unit testing. |
| 59 class StubNotificationUIManager : public NotificationUIManager { | 110 class StubNotificationUIManager : public NotificationUIManager { |
| 60 public: | 111 public: |
| 61 StubNotificationUIManager() {} | 112 StubNotificationUIManager() : notification_(GURL(), GURL(), L"", L"", NULL) {} |
| 62 virtual ~StubNotificationUIManager() {} | 113 virtual ~StubNotificationUIManager() {} |
| 63 | 114 |
| 64 // Adds a notification to be displayed. Virtual for unit test override. | 115 // Adds a notification to be displayed. Virtual for unit test override. |
| 65 virtual void Add(const Notification& notification, Profile* profile) | 116 virtual void Add(const Notification& notification, Profile* profile) |
| 66 OVERRIDE {} | 117 OVERRIDE { |
| 118 // Make a deep copy of the notification that we can inspect. | |
| 119 notification_ = notification; | |
| 120 } | |
| 67 | 121 |
| 68 // Returns true if any notifications match the supplied ID, either currently | 122 // Returns true if any notifications match the supplied ID, either currently |
| 69 // displayed or in the queue. | 123 // displayed or in the queue. |
| 70 virtual bool DoesIdExist(const std::string& id) OVERRIDE { | 124 virtual bool DoesIdExist(const std::string& id) OVERRIDE { |
| 71 return true; | 125 return true; |
| 72 } | 126 } |
| 73 | 127 |
| 74 // Removes any notifications matching the supplied ID, either currently | 128 // Removes any notifications matching the supplied ID, either currently |
| 75 // displayed or in the queue. Returns true if anything was removed. | 129 // displayed or in the queue. Returns true if anything was removed. |
| 76 virtual bool CancelById(const std::string& notification_id) OVERRIDE { | 130 virtual bool CancelById(const std::string& notification_id) OVERRIDE { |
| 77 return false; | 131 return false; |
| 78 } | 132 } |
| 79 | 133 |
| 80 // Removes notifications matching the |source_origin| (which could be an | 134 // Removes notifications matching the |source_origin| (which could be an |
| 81 // extension ID). Returns true if anything was removed. | 135 // extension ID). Returns true if anything was removed. |
| 82 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { | 136 virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { |
| 83 return false; | 137 return false; |
| 84 } | 138 } |
| 85 | 139 |
| 86 // Removes notifications matching |profile|. Returns true if any were removed. | 140 // Removes notifications matching |profile|. Returns true if any were removed. |
| 87 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE { | 141 virtual bool CancelAllByProfile(Profile* profile) OVERRIDE { |
| 88 return false; | 142 return false; |
| 89 } | 143 } |
| 90 | 144 |
| 91 // Cancels all pending notifications and closes anything currently showing. | 145 // Cancels all pending notifications and closes anything currently showing. |
| 92 // Used when the app is terminating. | 146 // Used when the app is terminating. |
| 93 virtual void CancelAll() OVERRIDE {} | 147 virtual void CancelAll() OVERRIDE {} |
| 94 | 148 |
| 149 // Test hook to get the notification so we can check it | |
| 150 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
| |
| 151 | |
| 95 private: | 152 private: |
| 96 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); | 153 DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); |
| 154 Notification notification_; | |
| 97 }; | 155 }; |
| 98 | 156 |
| 99 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed | 157 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed |
| 100 // back up to Sync. | 158 // back up to Sync. |
| 101 class TestChangeProcessor : public syncer::SyncChangeProcessor { | 159 class TestChangeProcessor : public syncer::SyncChangeProcessor { |
| 102 public: | 160 public: |
| 103 TestChangeProcessor() { } | 161 TestChangeProcessor() { } |
| 104 virtual ~TestChangeProcessor() { } | 162 virtual ~TestChangeProcessor() { } |
| 105 | 163 |
| 106 // Store a copy of all the changes passed in so we can examine them later. | 164 // Store a copy of all the changes passed in so we can examine them later. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 | 231 |
| 174 TestChangeProcessor* processor() { | 232 TestChangeProcessor* processor() { |
| 175 return static_cast<TestChangeProcessor*>(sync_processor_.get()); | 233 return static_cast<TestChangeProcessor*>(sync_processor_.get()); |
| 176 } | 234 } |
| 177 | 235 |
| 178 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor() { | 236 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor() { |
| 179 return sync_processor_delegate_.Pass(); | 237 return sync_processor_delegate_.Pass(); |
| 180 } | 238 } |
| 181 | 239 |
| 182 SyncedNotification* CreateNotification( | 240 SyncedNotification* CreateNotification( |
| 183 const std::string& message, | 241 const std::string& title, |
| 242 const std::string& text, | |
| 243 const std::string& app_icon_url, | |
| 244 const std::string& image_url, | |
| 184 const std::string& app_id, | 245 const std::string& app_id, |
| 185 const std::string& key, | 246 const std::string& key, |
| 186 const std::string& external_id, | |
| 187 sync_pb::CoalescedSyncedNotification_ReadState read_state) { | 247 sync_pb::CoalescedSyncedNotification_ReadState read_state) { |
| 188 SyncData sync_data = CreateSyncData(message, app_id, key, | 248 SyncData sync_data = CreateSyncData(title, text, app_icon_url, image_url, |
| 189 external_id, read_state); | 249 app_id, key, read_state); |
| 190 // Set enough fields in sync_data, including specifics, for our tests | 250 // Set enough fields in sync_data, including specifics, for our tests |
| 191 // to pass. | 251 // to pass. |
| 192 return new SyncedNotification(sync_data); | 252 return new SyncedNotification(sync_data); |
| 193 } | 253 } |
| 194 | 254 |
| 195 // Helper to create syncer::SyncChange. | 255 // Helper to create syncer::SyncChange. |
| 196 static SyncChange CreateSyncChange( | 256 static SyncChange CreateSyncChange( |
| 197 SyncChange::SyncChangeType type, | 257 SyncChange::SyncChangeType type, |
| 198 SyncedNotification* notification) { | 258 SyncedNotification* notification) { |
| 199 // Take control of the notification to clean it up after we create data | 259 // Take control of the notification to clean it up after we create data |
| 200 // out of it. | 260 // out of it. |
| 201 scoped_ptr<SyncedNotification> scoped_notification(notification); | 261 scoped_ptr<SyncedNotification> scoped_notification(notification); |
| 202 return SyncChange( | 262 return SyncChange( |
| 203 FROM_HERE, | 263 FROM_HERE, |
| 204 type, | 264 type, |
| 205 ChromeNotifierService::CreateSyncDataFromNotification(*notification)); | 265 ChromeNotifierService::CreateSyncDataFromNotification(*notification)); |
| 206 } | 266 } |
| 207 | 267 |
| 208 // Helper to create syncer::SyncData. | 268 // Helper to create syncer::SyncData. |
| 209 static SyncData CreateSyncData( | 269 static SyncData CreateSyncData( |
| 210 const std::string& message, | 270 const std::string& title, |
| 271 const std::string& text, | |
| 272 const std::string& app_icon_url, | |
| 273 const std::string& image_url, | |
| 211 const std::string& app_id, | 274 const std::string& app_id, |
| 212 const std::string& key, | 275 const std::string& key, |
| 213 const std::string& external_id, | 276 const sync_pb::CoalescedSyncedNotification_ReadState read_state) { |
| 214 sync_pb::CoalescedSyncedNotification_ReadState read_state) { | |
| 215 // CreateLocalData makes a copy of this, so this can safely live | 277 // CreateLocalData makes a copy of this, so this can safely live |
| 216 // on the stack. | 278 // on the stack. |
| 217 EntitySpecifics entity_specifics; | 279 EntitySpecifics entity_specifics; |
| 218 | 280 |
| 281 // Get a writeable pointer to the sync notifications specifics inside the | |
| 282 // entity specifics. | |
| 219 SyncedNotificationSpecifics* specifics = | 283 SyncedNotificationSpecifics* specifics = |
| 220 entity_specifics.mutable_synced_notification(); | 284 entity_specifics.mutable_synced_notification(); |
| 221 | 285 |
| 222 specifics->mutable_coalesced_notification()-> | 286 specifics->mutable_coalesced_notification()-> |
| 223 set_app_id(app_id); | 287 set_app_id(app_id); |
| 224 | 288 |
| 225 specifics->mutable_coalesced_notification()-> | 289 specifics->mutable_coalesced_notification()-> |
| 226 set_key(key); | 290 set_key(key); |
| 227 | 291 |
| 228 specifics->mutable_coalesced_notification()-> | 292 specifics->mutable_coalesced_notification()-> |
| 229 mutable_render_info()-> | 293 set_priority(static_cast<sync_pb::CoalescedSyncedNotification_Priority>( |
| 230 mutable_expanded_info()-> | 294 kFakePriority)); |
| 231 mutable_simple_expanded_layout()-> | 295 |
| 232 set_title(message); | 296 // Set the title. |
| 233 | 297 specifics->mutable_coalesced_notification()-> |
| 234 specifics-> | 298 mutable_render_info()-> |
| 235 mutable_coalesced_notification()-> | 299 mutable_expanded_info()-> |
| 300 mutable_simple_expanded_layout()-> | |
| 301 set_title(title); | |
| 302 | |
| 303 // Set the text. | |
| 304 specifics->mutable_coalesced_notification()-> | |
| 305 mutable_render_info()-> | |
| 306 mutable_expanded_info()-> | |
| 307 mutable_simple_expanded_layout()-> | |
| 308 set_text(text); | |
| 309 | |
| 310 // Set the heading. | |
| 311 specifics-> | |
| 312 mutable_coalesced_notification()-> | |
| 313 mutable_render_info()-> | |
| 314 mutable_collapsed_info()-> | |
| 315 mutable_simple_collapsed_layout()-> | |
| 316 set_heading(title); | |
| 317 | |
| 318 // Add the collapsed info and set the app_icon_url on it. | |
| 319 specifics-> | |
| 320 mutable_coalesced_notification()-> | |
| 321 mutable_render_info()-> | |
| 322 mutable_expanded_info()-> | |
| 323 add_collapsed_info(); | |
| 324 specifics-> | |
| 325 mutable_coalesced_notification()-> | |
| 326 mutable_render_info()-> | |
| 327 mutable_expanded_info()-> | |
| 328 mutable_collapsed_info(0)-> | |
| 329 mutable_simple_collapsed_layout()-> | |
| 330 mutable_app_icon()-> | |
| 331 set_url(app_icon_url); | |
| 332 | |
| 333 // Add the media object and set the image url on it. | |
| 334 specifics-> | |
| 335 mutable_coalesced_notification()-> | |
| 336 mutable_render_info()-> | |
| 337 mutable_expanded_info()-> | |
| 338 mutable_simple_expanded_layout()-> | |
| 339 add_media(); | |
| 340 specifics-> | |
| 341 mutable_coalesced_notification()-> | |
| 342 mutable_render_info()-> | |
| 343 mutable_expanded_info()-> | |
| 344 mutable_simple_expanded_layout()-> | |
| 345 mutable_media(0)-> | |
| 346 mutable_image()-> | |
| 347 set_url(image_url); | |
| 348 | |
| 349 specifics->mutable_coalesced_notification()-> | |
| 236 set_creation_time_msec(kFakeCreationTime); | 350 set_creation_time_msec(kFakeCreationTime); |
| 237 | 351 |
| 238 specifics-> | 352 specifics->mutable_coalesced_notification()-> |
| 239 mutable_coalesced_notification()-> | |
| 240 add_notification(); | |
| 241 | |
| 242 specifics-> | |
| 243 mutable_coalesced_notification()-> | |
| 244 mutable_notification(0)->set_external_id(external_id); | |
| 245 | |
| 246 specifics-> | |
| 247 mutable_coalesced_notification()-> | |
| 248 set_read_state(read_state); | 353 set_read_state(read_state); |
| 249 | 354 |
| 355 // Contained notification one. | |
| 356 // We re-use the collapsed info we added for the app_icon_url, | |
| 357 // so no need to create another one here. | |
| 358 specifics->mutable_coalesced_notification()-> | |
| 359 mutable_render_info()-> | |
| 360 mutable_expanded_info()-> | |
| 361 mutable_collapsed_info(0)-> | |
| 362 mutable_simple_collapsed_layout()-> | |
| 363 set_heading(kContainedTitle1); | |
| 364 specifics->mutable_coalesced_notification()-> | |
| 365 mutable_render_info()-> | |
| 366 mutable_expanded_info()-> | |
| 367 mutable_collapsed_info(0)-> | |
| 368 mutable_simple_collapsed_layout()-> | |
| 369 set_description(kContainedMessage1); | |
| 370 | |
| 371 // Contained notification two. | |
| 372 specifics->mutable_coalesced_notification()-> | |
| 373 mutable_render_info()-> | |
| 374 mutable_expanded_info()-> | |
| 375 add_collapsed_info(); | |
| 376 specifics->mutable_coalesced_notification()-> | |
| 377 mutable_render_info()-> | |
| 378 mutable_expanded_info()-> | |
| 379 mutable_collapsed_info(1)-> | |
| 380 mutable_simple_collapsed_layout()-> | |
| 381 set_heading(kContainedTitle2); | |
| 382 specifics->mutable_coalesced_notification()-> | |
| 383 mutable_render_info()-> | |
| 384 mutable_expanded_info()-> | |
| 385 mutable_collapsed_info(1)-> | |
| 386 mutable_simple_collapsed_layout()-> | |
| 387 set_description(kContainedMessage2); | |
| 388 | |
| 389 // Contained notification three. | |
| 390 specifics->mutable_coalesced_notification()-> | |
| 391 mutable_render_info()-> | |
| 392 mutable_expanded_info()-> | |
| 393 add_collapsed_info(); | |
| 394 specifics->mutable_coalesced_notification()-> | |
| 395 mutable_render_info()-> | |
| 396 mutable_expanded_info()-> | |
| 397 mutable_collapsed_info(2)-> | |
| 398 mutable_simple_collapsed_layout()-> | |
| 399 set_heading(kContainedTitle3); | |
| 400 specifics->mutable_coalesced_notification()-> | |
| 401 mutable_render_info()-> | |
| 402 mutable_expanded_info()-> | |
| 403 mutable_collapsed_info(2)-> | |
| 404 mutable_simple_collapsed_layout()-> | |
| 405 set_description(kContainedMessage3); | |
| 406 | |
| 407 // Default Destination. | |
| 408 specifics->mutable_coalesced_notification()-> | |
| 409 mutable_render_info()-> | |
| 410 mutable_collapsed_info()-> | |
| 411 mutable_default_destination()-> | |
| 412 set_text(kDefaultDestinationTitle); | |
| 413 specifics->mutable_coalesced_notification()-> | |
| 414 mutable_render_info()-> | |
| 415 mutable_collapsed_info()-> | |
| 416 mutable_default_destination()-> | |
| 417 mutable_icon()-> | |
| 418 set_url(kDefaultDestinationIconUrl); | |
| 419 specifics->mutable_coalesced_notification()-> | |
| 420 mutable_render_info()-> | |
| 421 mutable_collapsed_info()-> | |
| 422 mutable_default_destination()-> | |
| 423 mutable_icon()-> | |
| 424 set_alt_text(kDefaultDestinationTitle); | |
| 425 specifics->mutable_coalesced_notification()-> | |
| 426 mutable_render_info()-> | |
| 427 mutable_collapsed_info()-> | |
| 428 mutable_default_destination()-> | |
| 429 set_url(kDefaultDestinationUrl); | |
| 430 | |
| 431 // Buttons are represented as targets. | |
| 432 | |
| 433 // Button One. | |
| 434 specifics->mutable_coalesced_notification()-> | |
| 435 mutable_render_info()-> | |
| 436 mutable_collapsed_info()-> | |
| 437 add_target(); | |
| 438 specifics->mutable_coalesced_notification()-> | |
| 439 mutable_render_info()-> | |
| 440 mutable_collapsed_info()-> | |
| 441 mutable_target(0)-> | |
| 442 mutable_action()-> | |
| 443 set_text(kButtonOneTitle); | |
| 444 specifics->mutable_coalesced_notification()-> | |
| 445 mutable_render_info()-> | |
| 446 mutable_collapsed_info()-> | |
| 447 mutable_target(0)-> | |
| 448 mutable_action()-> | |
| 449 mutable_icon()-> | |
| 450 set_url(kButtonOneIconUrl); | |
| 451 specifics->mutable_coalesced_notification()-> | |
| 452 mutable_render_info()-> | |
| 453 mutable_collapsed_info()-> | |
| 454 mutable_target(0)-> | |
| 455 mutable_action()-> | |
| 456 mutable_icon()-> | |
| 457 set_alt_text(kButtonOneTitle); | |
| 458 specifics->mutable_coalesced_notification()-> | |
| 459 mutable_render_info()-> | |
| 460 mutable_collapsed_info()-> | |
| 461 mutable_target(0)-> | |
| 462 mutable_action()-> | |
| 463 set_url(kButtonOneUrl); | |
| 464 | |
| 465 // Button Two. | |
| 466 specifics->mutable_coalesced_notification()-> | |
| 467 mutable_render_info()-> | |
| 468 mutable_collapsed_info()-> | |
| 469 add_target(); | |
| 470 specifics->mutable_coalesced_notification()-> | |
| 471 mutable_render_info()-> | |
| 472 mutable_collapsed_info()-> | |
| 473 mutable_target(1)-> | |
| 474 mutable_action()-> | |
| 475 set_text(kButtonTwoTitle); | |
| 476 specifics->mutable_coalesced_notification()-> | |
| 477 mutable_render_info()-> | |
| 478 mutable_collapsed_info()-> | |
| 479 mutable_target(1)-> | |
| 480 mutable_action()-> | |
| 481 mutable_icon()-> | |
| 482 set_url(kButtonTwoIconUrl); | |
| 483 specifics->mutable_coalesced_notification()-> | |
| 484 mutable_render_info()-> | |
| 485 mutable_collapsed_info()-> | |
| 486 mutable_target(1)-> | |
| 487 mutable_action()-> | |
| 488 mutable_icon()-> | |
| 489 set_alt_text(kButtonTwoTitle); | |
| 490 specifics->mutable_coalesced_notification()-> | |
| 491 mutable_render_info()-> | |
| 492 mutable_collapsed_info()-> | |
| 493 mutable_target(1)-> | |
| 494 mutable_action()-> | |
| 495 set_url(kButtonTwoUrl); | |
| 496 | |
| 250 SyncData sync_data = SyncData::CreateLocalData( | 497 SyncData sync_data = SyncData::CreateLocalData( |
| 251 "syncer::SYNCED_NOTIFICATIONS", | 498 "syncer::SYNCED_NOTIFICATIONS", |
| 252 "ChromeNotifierServiceUnitTest", | 499 "ChromeNotifierServiceUnitTest", |
| 253 entity_specifics); | 500 entity_specifics); |
| 254 | 501 |
| 255 return sync_data; | 502 return sync_data; |
| 256 } | 503 } |
| 257 | 504 |
| 258 private: | 505 private: |
| 259 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 506 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 260 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_delegate_; | 507 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_delegate_; |
| 261 | 508 |
| 262 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest); | 509 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierServiceTest); |
| 263 }; | 510 }; |
| 264 | 511 |
| 265 // TODO(petewil): Add more tests as I add functionalty. Tests are based on | 512 // TODO(petewil): Add more tests as I add functionalty. Tests are based on |
| 266 // chrome/browser/extensions/app_notification_manager_sync_unittest.cc | 513 // chrome/browser/extensions/app_notification_manager_sync_unittest.cc |
| 267 | 514 |
| 268 // Create a Notification, convert it to SyncData and convert it back. | 515 // Create a Notification, convert it to SyncData and convert it back. |
| 269 TEST_F(ChromeNotifierServiceTest, NotificationToSyncDataToNotification) { | 516 TEST_F(ChromeNotifierServiceTest, NotificationToSyncDataToNotification) { |
| 270 scoped_ptr<SyncedNotification> notification1( | 517 scoped_ptr<SyncedNotification> notification1( |
| 271 CreateNotification("1", kAppId1, kKey1, "11", kUnread)); | 518 CreateNotification(kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, |
| 519 kKey1, kUnread)); | |
| 272 SyncData sync_data = | 520 SyncData sync_data = |
| 273 ChromeNotifierService::CreateSyncDataFromNotification(*notification1); | 521 ChromeNotifierService::CreateSyncDataFromNotification(*notification1); |
| 274 scoped_ptr<SyncedNotification> notification2( | 522 scoped_ptr<SyncedNotification> notification2( |
| 275 ChromeNotifierService::CreateNotificationFromSyncData(sync_data)); | 523 ChromeNotifierService::CreateNotificationFromSyncData(sync_data)); |
| 276 EXPECT_TRUE(notification2.get()); | 524 EXPECT_TRUE(notification2.get()); |
| 277 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); | 525 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); |
| 278 EXPECT_EQ(notification1->read_state(), notification2->read_state()); | 526 EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState()); |
| 279 } | 527 } |
| 280 | 528 |
| 281 // Model assocation: We have no local data, and no remote data. | 529 // Model assocation: We have no local data, and no remote data. |
| 282 TEST_F(ChromeNotifierServiceTest, ModelAssocBothEmpty) { | 530 TEST_F(ChromeNotifierServiceTest, ModelAssocBothEmpty) { |
| 283 StubNotificationUIManager notification_manager; | 531 StubNotificationUIManager notification_manager; |
| 284 ChromeNotifierService notifier(NULL, ¬ification_manager); | 532 ChromeNotifierService notifier(NULL, ¬ification_manager); |
| 285 | 533 |
| 286 notifier.MergeDataAndStartSyncing( | 534 notifier.MergeDataAndStartSyncing( |
| 287 SYNCED_NOTIFICATIONS, | 535 SYNCED_NOTIFICATIONS, |
| 288 SyncDataList(), // Empty. | 536 SyncDataList(), // Empty. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 302 notifier.MergeDataAndStartSyncing( | 550 notifier.MergeDataAndStartSyncing( |
| 303 SYNCED_NOTIFICATIONS, | 551 SYNCED_NOTIFICATIONS, |
| 304 SyncDataList(), | 552 SyncDataList(), |
| 305 PassProcessor(), | 553 PassProcessor(), |
| 306 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 554 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 307 | 555 |
| 308 // Set up a bunch of ADDs. | 556 // Set up a bunch of ADDs. |
| 309 SyncChangeList changes; | 557 SyncChangeList changes; |
| 310 changes.push_back(CreateSyncChange( | 558 changes.push_back(CreateSyncChange( |
| 311 SyncChange::ACTION_ADD, CreateNotification( | 559 SyncChange::ACTION_ADD, CreateNotification( |
| 312 "1", kAppId1, kKey1, "11", kUnread))); | 560 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread))); |
| 313 changes.push_back(CreateSyncChange( | 561 changes.push_back(CreateSyncChange( |
| 314 SyncChange::ACTION_ADD, CreateNotification( | 562 SyncChange::ACTION_ADD, CreateNotification( |
| 315 "2", kAppId2, kKey2, "22", kUnread))); | 563 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread))); |
| 316 changes.push_back(CreateSyncChange( | 564 changes.push_back(CreateSyncChange( |
| 317 SyncChange::ACTION_ADD, CreateNotification( | 565 SyncChange::ACTION_ADD, CreateNotification( |
| 318 "3", kAppId3, kKey3, "33", kUnread))); | 566 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread))); |
| 319 | 567 |
| 320 notifier.ProcessSyncChanges(FROM_HERE, changes); | 568 notifier.ProcessSyncChanges(FROM_HERE, changes); |
| 321 | 569 |
| 322 EXPECT_EQ(3U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); | 570 EXPECT_EQ(3U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); |
| 323 // TODO(petewil): verify that the list entries have expected values to make | 571 // TODO(petewil): verify that the list entries have expected values to make |
| 324 // this test more robust. | 572 // this test more robust. |
| 325 } | 573 } |
| 326 | 574 |
| 327 // Model has some notifications, some of them are local only. Sync has some | 575 // Model has some notifications, some of them are local only. Sync has some |
| 328 // notifications. No items match up. | 576 // notifications. No items match up. |
| 329 TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) { | 577 TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) { |
| 330 StubNotificationUIManager notification_manager; | 578 StubNotificationUIManager notification_manager; |
| 331 ChromeNotifierService notifier(NULL, ¬ification_manager); | 579 ChromeNotifierService notifier(NULL, ¬ification_manager); |
| 332 | 580 |
| 333 // Create some local fake data. | 581 // Create some local fake data. |
| 334 scoped_ptr<SyncedNotification> n1(CreateNotification( | 582 scoped_ptr<SyncedNotification> n1(CreateNotification( |
| 335 "1", kAppId1, kKey1, "11", kUnread)); | 583 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); |
| 336 notifier.AddForTest(n1.Pass()); | 584 notifier.AddForTest(n1.Pass()); |
| 337 scoped_ptr<SyncedNotification> n2(CreateNotification( | 585 scoped_ptr<SyncedNotification> n2(CreateNotification( |
| 338 "2", kAppId2, kKey2, "22", kUnread)); | 586 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread)); |
| 339 notifier.AddForTest(n2.Pass()); | 587 notifier.AddForTest(n2.Pass()); |
| 340 scoped_ptr<SyncedNotification> n3(CreateNotification( | 588 scoped_ptr<SyncedNotification> n3(CreateNotification( |
| 341 "3", kAppId3, kKey3, "33", kUnread)); | 589 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread)); |
| 342 notifier.AddForTest(n3.Pass()); | 590 notifier.AddForTest(n3.Pass()); |
| 343 | 591 |
| 344 // Create some remote fake data. | 592 // Create some remote fake data. |
| 345 SyncDataList initial_data; | 593 SyncDataList initial_data; |
| 346 initial_data.push_back(CreateSyncData("4", kAppId4, kKey4, | 594 initial_data.push_back(CreateSyncData(kTitle4, kText4, kIconUrl4, kImageUrl4, |
| 347 "44", kUnread)); | 595 kAppId4, kKey4, kUnread)); |
| 348 initial_data.push_back(CreateSyncData("5", kAppId5, kKey5, | 596 initial_data.push_back(CreateSyncData(kTitle5, kText5, kIconUrl5, kImageUrl5, |
| 349 "55", kUnread)); | 597 kAppId5, kKey5, kUnread)); |
| 350 initial_data.push_back(CreateSyncData("6", kAppId6, kKey6, | 598 initial_data.push_back(CreateSyncData(kTitle6, kText6, kIconUrl6, kImageUrl6, |
| 351 "66", kUnread)); | 599 kAppId6, kKey6, kUnread)); |
| 352 initial_data.push_back(CreateSyncData("7", kAppId7, kKey7, | 600 initial_data.push_back(CreateSyncData(kTitle7, kText7, kIconUrl7, kImageUrl7, |
| 353 "77", kUnread)); | 601 kAppId7, kKey7, kUnread)); |
| 354 | 602 |
| 355 // Merge the local and remote data. | 603 // Merge the local and remote data. |
| 356 notifier.MergeDataAndStartSyncing( | 604 notifier.MergeDataAndStartSyncing( |
| 357 SYNCED_NOTIFICATIONS, | 605 SYNCED_NOTIFICATIONS, |
| 358 initial_data, | 606 initial_data, |
| 359 PassProcessor(), | 607 PassProcessor(), |
| 360 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 608 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 361 | 609 |
| 362 // Ensure the local store now has all local and remote notifications. | 610 // Ensure the local store now has all local and remote notifications. |
| 363 EXPECT_EQ(7U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); | 611 EXPECT_EQ(7U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); |
| 364 EXPECT_TRUE(notifier.FindNotificationById(kKey1)); | 612 EXPECT_TRUE(notifier.FindNotificationByKey(kKey1)); |
| 365 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); | 613 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2)); |
| 366 EXPECT_TRUE(notifier.FindNotificationById(kKey3)); | 614 EXPECT_TRUE(notifier.FindNotificationByKey(kKey3)); |
| 367 EXPECT_TRUE(notifier.FindNotificationById(kKey4)); | 615 EXPECT_TRUE(notifier.FindNotificationByKey(kKey4)); |
| 368 EXPECT_TRUE(notifier.FindNotificationById(kKey5)); | 616 EXPECT_TRUE(notifier.FindNotificationByKey(kKey5)); |
| 369 EXPECT_TRUE(notifier.FindNotificationById(kKey6)); | 617 EXPECT_TRUE(notifier.FindNotificationByKey(kKey6)); |
| 370 EXPECT_TRUE(notifier.FindNotificationById(kKey7)); | 618 EXPECT_TRUE(notifier.FindNotificationByKey(kKey7)); |
| 371 | 619 |
| 372 // Test the type conversion and construction functions. | 620 // Test the type conversion and construction functions. |
| 373 for (SyncDataList::const_iterator iter = initial_data.begin(); | 621 for (SyncDataList::const_iterator iter = initial_data.begin(); |
| 374 iter != initial_data.end(); ++iter) { | 622 iter != initial_data.end(); ++iter) { |
| 375 scoped_ptr<SyncedNotification> notification1( | 623 scoped_ptr<SyncedNotification> notification1( |
| 376 ChromeNotifierService::CreateNotificationFromSyncData(*iter)); | 624 ChromeNotifierService::CreateNotificationFromSyncData(*iter)); |
| 377 // TODO(petewil): Revisit this when we add version info to notifications. | 625 // TODO(petewil): Revisit this when we add version info to notifications. |
| 378 const std::string& id = notification1->notification_id(); | 626 const std::string& key = notification1->GetKey(); |
| 379 const SyncedNotification* notification2 = notifier.FindNotificationById(id); | 627 const SyncedNotification* notification2 = |
| 628 notifier.FindNotificationByKey(key); | |
| 380 EXPECT_TRUE(NULL != notification2); | 629 EXPECT_TRUE(NULL != notification2); |
| 381 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); | 630 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); |
| 382 EXPECT_EQ(notification1->read_state(), notification2->read_state()); | 631 EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState()); |
| 383 } | 632 } |
| 384 EXPECT_TRUE(notifier.FindNotificationById(kKey1)); | 633 EXPECT_TRUE(notifier.FindNotificationByKey(kKey1)); |
| 385 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); | 634 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2)); |
| 386 EXPECT_TRUE(notifier.FindNotificationById(kKey3)); | 635 EXPECT_TRUE(notifier.FindNotificationByKey(kKey3)); |
| 387 } | 636 } |
| 388 | 637 |
| 389 // Test the local store having the read bit unset, the remote store having | 638 // Test the local store having the read bit unset, the remote store having |
| 390 // it set. | 639 // it set. |
| 391 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) { | 640 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) { |
| 392 StubNotificationUIManager notification_manager; | 641 StubNotificationUIManager notification_manager; |
| 393 ChromeNotifierService notifier(NULL, ¬ification_manager); | 642 ChromeNotifierService notifier(NULL, ¬ification_manager); |
| 394 | 643 |
| 395 // Create some local fake data. | 644 // Create some local fake data. |
| 396 scoped_ptr<SyncedNotification> n1(CreateNotification( | 645 scoped_ptr<SyncedNotification> n1(CreateNotification( |
| 397 "1", kAppId1, kKey1, "11", kUnread)); | 646 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); |
| 398 notifier.AddForTest(n1.Pass()); | 647 notifier.AddForTest(n1.Pass()); |
| 399 scoped_ptr<SyncedNotification> n2(CreateNotification( | 648 scoped_ptr<SyncedNotification> n2(CreateNotification( |
| 400 "2", kAppId2, kKey2, "22", kUnread)); | 649 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread)); |
| 401 notifier.AddForTest(n2.Pass()); | 650 notifier.AddForTest(n2.Pass()); |
| 402 | 651 |
| 403 // Create some remote fake data, item 1 matches except for the read state. | 652 // Create some remote fake data, item 1 matches except for the read state. |
| 404 syncer::SyncDataList initial_data; | 653 syncer::SyncDataList initial_data; |
| 405 initial_data.push_back(CreateSyncData("1", kAppId1, kKey1, | 654 initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, |
| 406 "11", kDismissed)); | 655 kAppId1, kKey1, kDismissed)); |
| 407 // Merge the local and remote data. | 656 // Merge the local and remote data. |
| 408 notifier.MergeDataAndStartSyncing( | 657 notifier.MergeDataAndStartSyncing( |
| 409 syncer::SYNCED_NOTIFICATIONS, | 658 syncer::SYNCED_NOTIFICATIONS, |
| 410 initial_data, | 659 initial_data, |
| 411 PassProcessor(), | 660 PassProcessor(), |
| 412 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 661 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 413 | 662 |
| 414 // Ensure the local store still has only two notifications, and the read | 663 // Ensure the local store still has only two notifications, and the read |
| 415 // state of the first is now read. | 664 // state of the first is now read. |
| 416 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); | 665 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); |
| 417 SyncedNotification* notification1 = | 666 SyncedNotification* notification1 = |
| 418 notifier.FindNotificationById(kKey1); | 667 notifier.FindNotificationByKey(kKey1); |
| 419 EXPECT_FALSE(NULL == notification1); | 668 EXPECT_FALSE(NULL == notification1); |
| 420 EXPECT_EQ(SyncedNotification::kDismissed, notification1->read_state()); | 669 EXPECT_EQ(kDismissed, notification1->GetReadState()); |
| 421 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); | 670 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2)); |
| 422 EXPECT_FALSE(notifier.FindNotificationById(kKey3)); | 671 EXPECT_FALSE(notifier.FindNotificationByKey(kKey3)); |
| 423 | 672 |
| 424 // Ensure no new data will be sent to the remote store for notification1. | 673 // Ensure no new data will be sent to the remote store for notification1. |
| 425 EXPECT_EQ(0U, processor()->change_list_size()); | 674 EXPECT_EQ(0U, processor()->change_list_size()); |
| 426 EXPECT_FALSE(processor()->ContainsId(kKey1)); | 675 EXPECT_FALSE(processor()->ContainsId(kKey1)); |
| 427 } | 676 } |
| 428 | 677 |
| 429 // Test when the local store has the read bit set, and the remote store has | 678 // Test when the local store has the read bit set, and the remote store has |
| 430 // it unset. | 679 // it unset. |
| 431 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) { | 680 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) { |
| 432 StubNotificationUIManager notification_manager; | 681 StubNotificationUIManager notification_manager; |
| 433 ChromeNotifierService notifier(NULL, ¬ification_manager); | 682 ChromeNotifierService notifier(NULL, ¬ification_manager); |
| 434 | 683 |
| 435 // Create some local fake data. | 684 // Create some local fake data. |
| 436 scoped_ptr<SyncedNotification> n1(CreateNotification( | 685 scoped_ptr<SyncedNotification> n1(CreateNotification( |
| 437 "1", kAppId1, kKey1, "11", kDismissed)); | 686 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kDismissed)); |
| 438 notifier.AddForTest(n1.Pass()); | 687 notifier.AddForTest(n1.Pass()); |
| 439 scoped_ptr<SyncedNotification> n2(CreateNotification( | 688 scoped_ptr<SyncedNotification> n2(CreateNotification( |
| 440 "2", kAppId2, kKey2, "22", kUnread)); | 689 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread)); |
| 441 notifier.AddForTest(n2.Pass()); | 690 notifier.AddForTest(n2.Pass()); |
| 442 | 691 |
| 443 // Create some remote fake data, item 1 matches except for the read state. | 692 // Create some remote fake data, item 1 matches except for the read state. |
| 444 syncer::SyncDataList initial_data; | 693 syncer::SyncDataList initial_data; |
| 445 initial_data.push_back(CreateSyncData("1", kAppId1, kKey1, | 694 initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, |
| 446 "11", kUnread)); | 695 kAppId1, kKey1, kUnread)); |
| 447 // Merge the local and remote data. | 696 // Merge the local and remote data. |
| 448 notifier.MergeDataAndStartSyncing( | 697 notifier.MergeDataAndStartSyncing( |
| 449 syncer::SYNCED_NOTIFICATIONS, | 698 syncer::SYNCED_NOTIFICATIONS, |
| 450 initial_data, | 699 initial_data, |
| 451 PassProcessor(), | 700 PassProcessor(), |
| 452 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 701 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 453 | 702 |
| 454 // Ensure the local store still has only two notifications, and the read | 703 // Ensure the local store still has only two notifications, and the read |
| 455 // state of the first is now read. | 704 // state of the first is now read. |
| 456 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); | 705 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); |
| 457 SyncedNotification* notification1 = | 706 SyncedNotification* notification1 = |
| 458 notifier.FindNotificationById(kKey1); | 707 notifier.FindNotificationByKey(kKey1); |
| 459 EXPECT_FALSE(NULL == notification1); | 708 EXPECT_FALSE(NULL == notification1); |
| 460 EXPECT_EQ(SyncedNotification::kDismissed, notification1->read_state()); | 709 EXPECT_EQ(kDismissed, notification1->GetReadState()); |
| 461 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); | 710 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2)); |
| 462 EXPECT_FALSE(notifier.FindNotificationById(kKey3)); | 711 EXPECT_FALSE(notifier.FindNotificationByKey(kKey3)); |
| 463 | 712 |
| 464 // Ensure the new data will be sent to the remote store for notification1. | 713 // Ensure the new data will be sent to the remote store for notification1. |
| 465 EXPECT_EQ(1U, processor()->change_list_size()); | 714 EXPECT_EQ(1U, processor()->change_list_size()); |
| 466 EXPECT_TRUE(processor()->ContainsId(kKey1)); | 715 EXPECT_TRUE(processor()->ContainsId(kKey1)); |
| 467 EXPECT_EQ(SyncChange::ACTION_UPDATE, processor()->GetChangeById( | 716 EXPECT_EQ(SyncChange::ACTION_UPDATE, processor()->GetChangeById( |
| 468 kKey1).change_type()); | 717 kKey1).change_type()); |
| 469 } | 718 } |
| 470 | 719 |
| 471 // We have a notification in the local store, we get an updated version | 720 // We have a notification in the local store, we get an updated version |
| 472 // of the same notification remotely, it should take precedence. | 721 // of the same notification remotely, it should take precedence. |
| 473 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyWithUpdate) { | 722 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyWithUpdate) { |
| 474 StubNotificationUIManager notification_manager; | 723 StubNotificationUIManager notification_manager; |
| 475 ChromeNotifierService notifier(NULL, ¬ification_manager); | 724 ChromeNotifierService notifier(NULL, ¬ification_manager); |
| 476 | 725 |
| 477 // Create some local fake data. | 726 // Create some local fake data. |
| 478 scoped_ptr<SyncedNotification> n1(CreateNotification( | 727 scoped_ptr<SyncedNotification> n1(CreateNotification( |
| 479 "1", kAppId1, kKey1, "11", kDismissed)); | 728 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kDismissed)); |
| 480 notifier.AddForTest(n1.Pass()); | 729 notifier.AddForTest(n1.Pass()); |
| 481 | 730 |
| 482 // Create some remote fake data, item 1 matches the ID, but has different data | 731 // Create some remote fake data, item 1 matches the ID, but has different data |
| 483 syncer::SyncDataList initial_data; | 732 syncer::SyncDataList initial_data; |
| 484 initial_data.push_back(CreateSyncData("One", kAppId1, kKey1, | 733 initial_data.push_back(CreateSyncData(kTitle2, kText2, kIconUrl2, kImageUrl2, |
| 485 "Eleven", kUnread)); | 734 kAppId1, kKey1, kUnread)); |
| 486 // Merge the local and remote data. | 735 // Merge the local and remote data. |
| 487 notifier.MergeDataAndStartSyncing( | 736 notifier.MergeDataAndStartSyncing( |
| 488 syncer::SYNCED_NOTIFICATIONS, | 737 syncer::SYNCED_NOTIFICATIONS, |
| 489 initial_data, | 738 initial_data, |
| 490 PassProcessor(), | 739 PassProcessor(), |
| 491 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 740 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 492 | 741 |
| 493 // Ensure the local store still has only one notification | 742 // Ensure the local store still has only one notification |
| 494 EXPECT_EQ(1U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); | 743 EXPECT_EQ(1U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); |
| 495 SyncedNotification* notification1 = | 744 SyncedNotification* notification1 = |
| 496 notifier.FindNotificationById(kKey1); | 745 notifier.FindNotificationByKey(kKey1); |
| 746 | |
| 497 EXPECT_FALSE(NULL == notification1); | 747 EXPECT_FALSE(NULL == notification1); |
| 498 EXPECT_EQ(SyncedNotification::kUnread, notification1->read_state()); | 748 EXPECT_EQ(kUnread, notification1->GetReadState()); |
| 499 EXPECT_EQ("One", notification1->title()); | 749 EXPECT_EQ(kTitle2, notification1->GetTitle()); |
| 500 EXPECT_EQ("Eleven", notification1->first_external_id()); | |
| 501 | 750 |
| 502 // Ensure no new data will be sent to the remote store for notification1. | 751 // Ensure no new data will be sent to the remote store for notification1. |
| 503 EXPECT_EQ(0U, processor()->change_list_size()); | 752 EXPECT_EQ(0U, processor()->change_list_size()); |
| 504 EXPECT_FALSE(processor()->ContainsId(kKey1)); | 753 EXPECT_FALSE(processor()->ContainsId(kKey1)); |
| 505 } | 754 } |
| 506 | 755 |
| 756 TEST_F(ChromeNotifierServiceTest, ShowTest) { | |
| 757 StubNotificationUIManager notification_manager; | |
| 758 ChromeNotifierService notifier(NULL, ¬ification_manager); | |
| 759 | |
| 760 // Create some remote fake data | |
| 761 syncer::SyncDataList initial_data; | |
| 762 initial_data.push_back(CreateSyncData(kTitle1, kText1, kIconUrl1, kImageUrl1, | |
| 763 kAppId1, kKey1, kUnread)); | |
| 764 // Merge the local and remote data. | |
| 765 notifier.MergeDataAndStartSyncing( | |
| 766 syncer::SYNCED_NOTIFICATIONS, | |
| 767 initial_data, | |
| 768 PassProcessor(), | |
| 769 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | |
| 770 | |
| 771 // Check the base fields of the notification. | |
| 772 EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, | |
| 773 notification_manager.notification().type()); | |
| 774 EXPECT_EQ(kTitle1, | |
| 775 UTF16ToUTF8(notification_manager.notification().title())); | |
| 776 EXPECT_EQ(kText1, | |
| 777 UTF16ToUTF8(notification_manager.notification().body())); | |
| 778 EXPECT_EQ(kExpectedOriginUrl, | |
| 779 notification_manager.notification().origin_url().spec()); | |
| 780 EXPECT_EQ(kIconUrl, notification_manager.notification().icon_url().spec()); | |
| 781 EXPECT_EQ(kKey1, | |
| 782 UTF16ToUTF8(notification_manager.notification().replace_id())); | |
| 783 const DictionaryValue* optional_fields = | |
| 784 notification_manager.notification().optional_fields(); | |
| 785 | |
| 786 // 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.
| |
| 787 double creation_time = 0.0; | |
| 788 EXPECT_TRUE(optional_fields->GetDouble(message_center::kTimestampKey, | |
| 789 &creation_time)); | |
| 790 EXPECT_EQ(static_cast<double>(kFakeCreationTime), creation_time); | |
| 791 | |
| 792 int priority = -1; | |
| 793 EXPECT_TRUE(optional_fields->GetInteger(message_center::kPriorityKey, | |
| 794 &priority)); | |
| 795 EXPECT_EQ(kFakePriority, priority); | |
| 796 | |
| 797 // Buttons. | |
| 798 std::string button_one_title; | |
| 799 EXPECT_TRUE(optional_fields->GetString(message_center::kButtonOneTitleKey, | |
| 800 &button_one_title)); | |
| 801 EXPECT_EQ(kButtonOneTitle, button_one_title); | |
| 802 std::string button_one_icon_url; | |
| 803 EXPECT_TRUE(optional_fields->GetString(message_center::kButtonOneIconUrlKey, | |
| 804 &button_one_icon_url)); | |
| 805 EXPECT_EQ(kButtonOneIconUrl, button_one_icon_url); | |
| 806 std::string button_two_title; | |
| 807 EXPECT_TRUE(optional_fields->GetString(message_center::kButtonTwoTitleKey, | |
| 808 &button_two_title)); | |
| 809 EXPECT_EQ(kButtonTwoTitle, button_two_title); | |
| 810 std::string button_two_icon_url; | |
| 811 EXPECT_TRUE(optional_fields->GetString(message_center::kButtonTwoIconUrlKey, | |
| 812 &button_two_icon_url)); | |
| 813 EXPECT_EQ(kButtonTwoIconUrl, button_two_icon_url); | |
| 814 | |
| 815 // Check the contained notifications. Note that the list owns these pointers. | |
| 816 const ListValue* items; | |
| 817 EXPECT_TRUE(optional_fields->GetList(message_center::kItemsKey, &items)); | |
| 818 EXPECT_EQ(3, items->GetSize()); | |
| 819 | |
| 820 // Contained item 1. | |
| 821 const DictionaryValue* item1; | |
| 822 std::string item_title1; | |
| 823 std::string item_message1; | |
| 824 EXPECT_TRUE(items->GetDictionary(0, &item1)); | |
| 825 EXPECT_TRUE(item1->GetString(message_center::kItemTitleKey, &item_title1)); | |
| 826 EXPECT_TRUE(item1->GetString(message_center::kItemMessageKey, | |
| 827 &item_message1)); | |
| 828 EXPECT_EQ(kContainedTitle1, item_title1); | |
| 829 EXPECT_EQ(kContainedMessage1, item_message1); | |
| 830 | |
| 831 // Contained item 2. | |
| 832 const DictionaryValue* item2; | |
| 833 std::string item_title2; | |
| 834 std::string item_message2; | |
| 835 EXPECT_TRUE(items->GetDictionary(1, &item2)); | |
| 836 EXPECT_TRUE(item2->GetString(message_center::kItemTitleKey, &item_title2)); | |
| 837 EXPECT_TRUE(item2->GetString(message_center::kItemMessageKey, | |
| 838 &item_message2)); | |
| 839 EXPECT_EQ(kContainedTitle2, item_title2); | |
| 840 EXPECT_EQ(kContainedMessage2, item_message2); | |
| 841 | |
| 842 // Contained item 3. | |
| 843 const DictionaryValue* item3; | |
| 844 std::string item_title3; | |
| 845 std::string item_message3; | |
| 846 EXPECT_TRUE(items->GetDictionary(2, &item3)); | |
| 847 EXPECT_TRUE(item3->GetString(message_center::kItemTitleKey, &item_title3)); | |
| 848 EXPECT_TRUE(item3->GetString(message_center::kItemMessageKey, | |
| 849 &item_message3)); | |
| 850 EXPECT_EQ(kContainedTitle3, item_title3); | |
| 851 EXPECT_EQ(kContainedMessage3, item_message3); | |
| 852 } | |
| 853 | |
| 507 // TODO(petewil): There are more tests to add, such as when we add an API | 854 // TODO(petewil): There are more tests to add, such as when we add an API |
| 508 // to allow data entry from the client, we might have a more up to date | 855 // to allow data entry from the client, we might have a more up to date |
| 509 // item on the client than the server, or we might have a merge conflict. | 856 // item on the client than the server, or we might have a merge conflict. |
| OLD | NEW |