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