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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "chrome/browser/extensions/app_notification.h" | 9 #include "chrome/browser/extensions/app_notification.h" |
| 10 #include "chrome/browser/extensions/app_notification_manager.h" | 10 #include "chrome/browser/extensions/app_notification_manager.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 | 54 |
| 55 int change_list_size() { return change_map_.size(); } | 55 int change_list_size() { return change_map_.size(); } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 // Track the changes received in ProcessSyncChanges. | 58 // Track the changes received in ProcessSyncChanges. |
| 59 std::map<std::string, SyncChange> change_map_; | 59 std::map<std::string, SyncChange> change_map_; |
| 60 | 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); | 61 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class SyncChangeProcessorDelegate : public SyncChangeProcessor { | |
| 65 public: | |
| 66 explicit SyncChangeProcessorDelegate(SyncChangeProcessor* recipient) | |
| 67 : recipient_(recipient) { | |
| 68 DCHECK(recipient_); | |
| 69 } | |
|
akalin
2012/03/21 01:23:19
virtual destructor
Nicolas Zea
2012/03/21 17:38:27
Done.
| |
| 70 | |
| 71 // SyncChangeProcessor implementation. | |
| 72 virtual SyncError ProcessSyncChanges( | |
| 73 const tracked_objects::Location& from_here, | |
| 74 const SyncChangeList& change_list) OVERRIDE { | |
| 75 return recipient_->ProcessSyncChanges(from_here, change_list); | |
| 76 } | |
| 77 | |
| 78 private: | |
| 79 // The recipient of all sync changes. | |
| 80 SyncChangeProcessor* recipient_; | |
| 81 }; | |
| 82 | |
| 64 } // namespace | 83 } // namespace |
| 65 | 84 |
| 66 class AppNotificationManagerSyncTest : public testing::Test { | 85 class AppNotificationManagerSyncTest : public testing::Test { |
| 67 public: | 86 public: |
| 68 AppNotificationManagerSyncTest() | 87 AppNotificationManagerSyncTest() |
| 69 : ui_thread_(BrowserThread::UI, &ui_loop_), | 88 : ui_thread_(BrowserThread::UI, &ui_loop_), |
| 70 file_thread_(BrowserThread::FILE) { } | 89 file_thread_(BrowserThread::FILE), |
| 90 sync_processor_(new TestChangeProcessor), | |
| 91 sync_processor_delegate_(new SyncChangeProcessorDelegate( | |
| 92 sync_processor_.get())) {} | |
| 71 | 93 |
| 72 ~AppNotificationManagerSyncTest() { | 94 ~AppNotificationManagerSyncTest() { |
| 73 model_ = NULL; | 95 model_ = NULL; |
| 74 } | 96 } |
| 75 | 97 |
| 76 virtual void SetUp() { | 98 virtual void SetUp() { |
| 77 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 78 file_thread_.Start(); | 100 file_thread_.Start(); |
| 79 | 101 |
| 80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 102 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 97 } | 119 } |
| 98 | 120 |
| 99 static void WaitForFileThread() { | 121 static void WaitForFileThread() { |
| 100 BrowserThread::PostTask(BrowserThread::FILE, | 122 BrowserThread::PostTask(BrowserThread::FILE, |
| 101 FROM_HERE, | 123 FROM_HERE, |
| 102 base::Bind(&PostQuitToUIThread)); | 124 base::Bind(&PostQuitToUIThread)); |
| 103 MessageLoop::current()->Run(); | 125 MessageLoop::current()->Run(); |
| 104 } | 126 } |
| 105 | 127 |
| 106 AppNotificationManager* model() { return model_.get(); } | 128 AppNotificationManager* model() { return model_.get(); } |
| 107 TestChangeProcessor* processor() { return &processor_; } | 129 TestChangeProcessor* processor() { return sync_processor_.get(); } |
| 130 | |
| 131 scoped_ptr<SyncChangeProcessor> PassProcessor() { | |
| 132 return sync_processor_delegate_.PassAs<SyncChangeProcessor>(); | |
|
akalin
2012/03/21 01:23:19
Perhaps instead of creating a delegate above, you
Nicolas Zea
2012/03/21 17:38:27
I prefer this approach as it lets you verify the b
| |
| 133 } | |
| 108 | 134 |
| 109 // Creates a notification whose properties are set from the given integer. | 135 // Creates a notification whose properties are set from the given integer. |
| 110 static AppNotification* CreateNotification(int suffix) { | 136 static AppNotification* CreateNotification(int suffix) { |
| 111 return CreateNotification(false, suffix); | 137 return CreateNotification(false, suffix); |
| 112 } | 138 } |
| 113 static AppNotification* CreateNotification(bool is_local, int suffix) { | 139 static AppNotification* CreateNotification(bool is_local, int suffix) { |
| 114 std::string s = base::IntToString(suffix); | 140 std::string s = base::IntToString(suffix); |
| 115 return CreateNotification( | 141 return CreateNotification( |
| 116 is_local, suffix, "guid" + s, "ext" + s, "text" + s, "body" + s, | 142 is_local, suffix, "guid" + s, "ext" + s, "text" + s, "body" + s, |
| 117 "http://www.url" + s + ".com", "link text " + s); | 143 "http://www.url" + s + ".com", "link text " + s); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 protected: | 213 protected: |
| 188 MessageLoop ui_loop_; | 214 MessageLoop ui_loop_; |
| 189 content::TestBrowserThread ui_thread_; | 215 content::TestBrowserThread ui_thread_; |
| 190 content::TestBrowserThread file_thread_; | 216 content::TestBrowserThread file_thread_; |
| 191 | 217 |
| 192 // We keep two TemplateURLServices to test syncing between them. | 218 // We keep two TemplateURLServices to test syncing between them. |
| 193 ScopedTempDir temp_dir_; | 219 ScopedTempDir temp_dir_; |
| 194 scoped_ptr<TestingProfile> profile_; | 220 scoped_ptr<TestingProfile> profile_; |
| 195 scoped_refptr<AppNotificationManager> model_; | 221 scoped_refptr<AppNotificationManager> model_; |
| 196 | 222 |
| 197 TestChangeProcessor processor_; | 223 scoped_ptr<TestChangeProcessor> sync_processor_; |
| 224 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; | |
| 198 | 225 |
| 199 DISALLOW_COPY_AND_ASSIGN(AppNotificationManagerSyncTest); | 226 DISALLOW_COPY_AND_ASSIGN(AppNotificationManagerSyncTest); |
| 200 }; | 227 }; |
| 201 | 228 |
| 202 // Create an AppNotification, convert it to SyncData and convert it back. | 229 // Create an AppNotification, convert it to SyncData and convert it back. |
| 203 TEST_F(AppNotificationManagerSyncTest, NotificationToSyncDataToNotification) { | 230 TEST_F(AppNotificationManagerSyncTest, NotificationToSyncDataToNotification) { |
| 204 { // Partial properties set. | 231 { // Partial properties set. |
| 205 scoped_ptr<AppNotification> notif1(CreateNotificationNoLink(1)); | 232 scoped_ptr<AppNotification> notif1(CreateNotificationNoLink(1)); |
| 206 SyncData sync_data = | 233 SyncData sync_data = |
| 207 AppNotificationManager::CreateSyncDataFromNotification(*notif1); | 234 AppNotificationManager::CreateSyncDataFromNotification(*notif1); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 293 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 267 ASSERT_TRUE(notif1->Equals(*notif2)); | 294 ASSERT_TRUE(notif1->Equals(*notif2)); |
| 268 } | 295 } |
| 269 } | 296 } |
| 270 | 297 |
| 271 // Model assocation: both models are empty. | 298 // Model assocation: both models are empty. |
| 272 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) { | 299 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) { |
| 273 model()->MergeDataAndStartSyncing( | 300 model()->MergeDataAndStartSyncing( |
| 274 syncable::APP_NOTIFICATIONS, | 301 syncable::APP_NOTIFICATIONS, |
| 275 SyncDataList(), // Empty. | 302 SyncDataList(), // Empty. |
| 276 processor()); | 303 PassProcessor()); |
| 277 | 304 |
| 278 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 305 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 279 EXPECT_EQ(0, processor()->change_list_size()); | 306 EXPECT_EQ(0, processor()->change_list_size()); |
| 280 } | 307 } |
| 281 | 308 |
| 282 // Model assocation: empty sync model and non-empty local model. | 309 // Model assocation: empty sync model and non-empty local model. |
| 283 TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) { | 310 TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) { |
| 284 SyncDataList initial_data; | 311 SyncDataList initial_data; |
| 285 initial_data.push_back(CreateSyncData(1)); | 312 initial_data.push_back(CreateSyncData(1)); |
| 286 initial_data.push_back(CreateSyncData(2)); | 313 initial_data.push_back(CreateSyncData(2)); |
| 287 initial_data.push_back(CreateSyncData(3)); | 314 initial_data.push_back(CreateSyncData(3)); |
| 288 initial_data.push_back(CreateSyncData(4)); | 315 initial_data.push_back(CreateSyncData(4)); |
| 289 | 316 |
| 290 model()->MergeDataAndStartSyncing( | 317 model()->MergeDataAndStartSyncing( |
| 291 syncable::APP_NOTIFICATIONS, | 318 syncable::APP_NOTIFICATIONS, |
| 292 initial_data, | 319 initial_data, |
| 293 processor()); | 320 PassProcessor()); |
| 294 | 321 |
| 295 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 322 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 296 // Model should all of the initial sync data. | 323 // Model should all of the initial sync data. |
| 297 for (SyncDataList::const_iterator iter = initial_data.begin(); | 324 for (SyncDataList::const_iterator iter = initial_data.begin(); |
| 298 iter != initial_data.end(); ++iter) { | 325 iter != initial_data.end(); ++iter) { |
| 299 scoped_ptr<AppNotification> notif1( | 326 scoped_ptr<AppNotification> notif1( |
| 300 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 327 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 301 const std::string& ext_id = notif1->extension_id(); | 328 const std::string& ext_id = notif1->extension_id(); |
| 302 const std::string& guid = notif1->guid(); | 329 const std::string& guid = notif1->guid(); |
| 303 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 330 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 320 | 347 |
| 321 SyncDataList initial_data; | 348 SyncDataList initial_data; |
| 322 initial_data.push_back(CreateSyncData(4)); | 349 initial_data.push_back(CreateSyncData(4)); |
| 323 initial_data.push_back(CreateSyncData(5)); | 350 initial_data.push_back(CreateSyncData(5)); |
| 324 initial_data.push_back(CreateSyncData(6)); | 351 initial_data.push_back(CreateSyncData(6)); |
| 325 initial_data.push_back(CreateSyncData(7)); | 352 initial_data.push_back(CreateSyncData(7)); |
| 326 | 353 |
| 327 model()->MergeDataAndStartSyncing( | 354 model()->MergeDataAndStartSyncing( |
| 328 syncable::APP_NOTIFICATIONS, | 355 syncable::APP_NOTIFICATIONS, |
| 329 initial_data, | 356 initial_data, |
| 330 processor()); | 357 PassProcessor()); |
| 331 | 358 |
| 332 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 359 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 333 for (SyncDataList::const_iterator iter = initial_data.begin(); | 360 for (SyncDataList::const_iterator iter = initial_data.begin(); |
| 334 iter != initial_data.end(); ++iter) { | 361 iter != initial_data.end(); ++iter) { |
| 335 scoped_ptr<AppNotification> notif1( | 362 scoped_ptr<AppNotification> notif1( |
| 336 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 363 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 337 const std::string& ext_id = notif1->extension_id(); | 364 const std::string& ext_id = notif1->extension_id(); |
| 338 const std::string& guid = notif1->guid(); | 365 const std::string& guid = notif1->guid(); |
| 339 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 366 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 340 EXPECT_TRUE(notif2); | 367 EXPECT_TRUE(notif2); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 371 initial_data.push_back( | 398 initial_data.push_back( |
| 372 AppNotificationManager::CreateSyncDataFromNotification(*n1)); | 399 AppNotificationManager::CreateSyncDataFromNotification(*n1)); |
| 373 initial_data.push_back(CreateSyncData(6)); | 400 initial_data.push_back(CreateSyncData(6)); |
| 374 initial_data.push_back( | 401 initial_data.push_back( |
| 375 AppNotificationManager::CreateSyncDataFromNotification(*n4)); | 402 AppNotificationManager::CreateSyncDataFromNotification(*n4)); |
| 376 initial_data.push_back(CreateSyncData(7)); | 403 initial_data.push_back(CreateSyncData(7)); |
| 377 | 404 |
| 378 model()->MergeDataAndStartSyncing( | 405 model()->MergeDataAndStartSyncing( |
| 379 syncable::APP_NOTIFICATIONS, | 406 syncable::APP_NOTIFICATIONS, |
| 380 initial_data, | 407 initial_data, |
| 381 processor()); | 408 PassProcessor()); |
| 382 | 409 |
| 383 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 410 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 384 for (SyncDataList::const_iterator iter = initial_data.begin(); | 411 for (SyncDataList::const_iterator iter = initial_data.begin(); |
| 385 iter != initial_data.end(); ++iter) { | 412 iter != initial_data.end(); ++iter) { |
| 386 scoped_ptr<AppNotification> notif1( | 413 scoped_ptr<AppNotification> notif1( |
| 387 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 414 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 388 const std::string& ext_id = notif1->extension_id(); | 415 const std::string& ext_id = notif1->extension_id(); |
| 389 const std::string& guid = notif1->guid(); | 416 const std::string& guid = notif1->guid(); |
| 390 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 417 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 391 EXPECT_TRUE(notif2); | 418 EXPECT_TRUE(notif2); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 419 n1->is_local(), n1->creation_time().ToInternalValue(), | 446 n1->is_local(), n1->creation_time().ToInternalValue(), |
| 420 n1->guid(), n1->extension_id(), | 447 n1->guid(), n1->extension_id(), |
| 421 n1->title() + "_changed", // different title | 448 n1->title() + "_changed", // different title |
| 422 n1->body(), n1->link_url().spec(), n1->link_text())); | 449 n1->body(), n1->link_url().spec(), n1->link_text())); |
| 423 initial_data.push_back( | 450 initial_data.push_back( |
| 424 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); | 451 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); |
| 425 | 452 |
| 426 SyncError sync_error = model()->MergeDataAndStartSyncing( | 453 SyncError sync_error = model()->MergeDataAndStartSyncing( |
| 427 syncable::APP_NOTIFICATIONS, | 454 syncable::APP_NOTIFICATIONS, |
| 428 initial_data, | 455 initial_data, |
| 429 processor()); | 456 PassProcessor()); |
| 430 | 457 |
| 431 EXPECT_TRUE(sync_error.IsSet()); | 458 EXPECT_TRUE(sync_error.IsSet()); |
| 432 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 459 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); |
| 433 EXPECT_EQ(0, processor()->change_list_size()); | 460 EXPECT_EQ(0, processor()->change_list_size()); |
| 434 } | 461 } |
| 435 | 462 |
| 436 // When an item in sync matches with a local-only item in model, an error | 463 // When an item in sync matches with a local-only item in model, an error |
| 437 // should be returned. | 464 // should be returned. |
| 438 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) { | 465 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) { |
| 439 AppNotification* n1 = CreateNotification(1); | 466 AppNotification* n1 = CreateNotification(1); |
| 440 model()->Add(n1); | 467 model()->Add(n1); |
| 441 AppNotification* n2 = CreateNotification(true, 2); | 468 AppNotification* n2 = CreateNotification(true, 2); |
| 442 model()->Add(n2); | 469 model()->Add(n2); |
| 443 | 470 |
| 444 SyncDataList initial_data; | 471 SyncDataList initial_data; |
| 445 initial_data.push_back(CreateSyncData(1)); | 472 initial_data.push_back(CreateSyncData(1)); |
| 446 scoped_ptr<AppNotification> n2_a(CreateNotification(2)); | 473 scoped_ptr<AppNotification> n2_a(CreateNotification(2)); |
| 447 initial_data.push_back( | 474 initial_data.push_back( |
| 448 AppNotificationManager::CreateSyncDataFromNotification(*n2_a)); | 475 AppNotificationManager::CreateSyncDataFromNotification(*n2_a)); |
| 449 | 476 |
| 450 SyncError sync_error = model()->MergeDataAndStartSyncing( | 477 SyncError sync_error = model()->MergeDataAndStartSyncing( |
| 451 syncable::APP_NOTIFICATIONS, | 478 syncable::APP_NOTIFICATIONS, |
| 452 initial_data, | 479 initial_data, |
| 453 processor()); | 480 PassProcessor()); |
| 454 | 481 |
| 455 EXPECT_TRUE(sync_error.IsSet()); | 482 EXPECT_TRUE(sync_error.IsSet()); |
| 456 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 483 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); |
| 457 EXPECT_EQ(0, processor()->change_list_size()); | 484 EXPECT_EQ(0, processor()->change_list_size()); |
| 458 } | 485 } |
| 459 | 486 |
| 460 // Process sync changes when model is empty. | 487 // Process sync changes when model is empty. |
| 461 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) { | 488 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) { |
| 462 // We initially have no data. | 489 // We initially have no data. |
| 463 model()->MergeDataAndStartSyncing( | 490 model()->MergeDataAndStartSyncing( |
| 464 syncable::APP_NOTIFICATIONS, | 491 syncable::APP_NOTIFICATIONS, |
| 465 SyncDataList(), | 492 SyncDataList(), |
| 466 processor()); | 493 PassProcessor()); |
| 467 | 494 |
| 468 // Set up a bunch of ADDs. | 495 // Set up a bunch of ADDs. |
| 469 SyncChangeList changes; | 496 SyncChangeList changes; |
| 470 changes.push_back(CreateSyncChange( | 497 changes.push_back(CreateSyncChange( |
| 471 SyncChange::ACTION_ADD, CreateNotification(1))); | 498 SyncChange::ACTION_ADD, CreateNotification(1))); |
| 472 changes.push_back(CreateSyncChange( | 499 changes.push_back(CreateSyncChange( |
| 473 SyncChange::ACTION_ADD, CreateNotification(2))); | 500 SyncChange::ACTION_ADD, CreateNotification(2))); |
| 474 changes.push_back(CreateSyncChange( | 501 changes.push_back(CreateSyncChange( |
| 475 SyncChange::ACTION_ADD, CreateNotification(3))); | 502 SyncChange::ACTION_ADD, CreateNotification(3))); |
| 476 | 503 |
| 477 model()->ProcessSyncChanges(FROM_HERE, changes); | 504 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 478 | 505 |
| 479 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 506 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 480 EXPECT_EQ(0, processor()->change_list_size()); | 507 EXPECT_EQ(0, processor()->change_list_size()); |
| 481 } | 508 } |
| 482 | 509 |
| 483 // Process sync changes when model is not empty. | 510 // Process sync changes when model is not empty. |
| 484 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { | 511 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { |
| 485 AppNotification* n1 = CreateNotification(1); | 512 AppNotification* n1 = CreateNotification(1); |
| 486 model()->Add(n1); | 513 model()->Add(n1); |
| 487 AppNotification* n2 = CreateNotification(2); | 514 AppNotification* n2 = CreateNotification(2); |
| 488 model()->Add(n2); | 515 model()->Add(n2); |
| 489 model()->MergeDataAndStartSyncing( | 516 model()->MergeDataAndStartSyncing( |
| 490 syncable::APP_NOTIFICATIONS, | 517 syncable::APP_NOTIFICATIONS, |
| 491 SyncDataList(), | 518 SyncDataList(), |
| 492 processor()); | 519 PassProcessor()); |
| 493 | 520 |
| 494 // Some adds and some deletes. | 521 // Some adds and some deletes. |
| 495 SyncChangeList changes; | 522 SyncChangeList changes; |
| 496 changes.push_back(CreateSyncChange( | 523 changes.push_back(CreateSyncChange( |
| 497 SyncChange::ACTION_ADD, CreateNotification(3))); | 524 SyncChange::ACTION_ADD, CreateNotification(3))); |
| 498 changes.push_back(CreateSyncChange(SyncChange::ACTION_DELETE, n1->Copy())); | 525 changes.push_back(CreateSyncChange(SyncChange::ACTION_DELETE, n1->Copy())); |
| 499 changes.push_back(CreateSyncChange( | 526 changes.push_back(CreateSyncChange( |
| 500 SyncChange::ACTION_ADD, CreateNotification(4))); | 527 SyncChange::ACTION_ADD, CreateNotification(4))); |
| 501 | 528 |
| 502 model()->ProcessSyncChanges(FROM_HERE, changes); | 529 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 503 | 530 |
| 504 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 531 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 505 EXPECT_EQ(2, processor()->change_list_size()); | 532 EXPECT_EQ(2, processor()->change_list_size()); |
| 506 } | 533 } |
| 507 | 534 |
| 508 // Process sync changes should ignore a bad ADD. | 535 // Process sync changes should ignore a bad ADD. |
| 509 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) { | 536 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) { |
| 510 AppNotification* n1 = CreateNotification(1); | 537 AppNotification* n1 = CreateNotification(1); |
| 511 model()->Add(n1); | 538 model()->Add(n1); |
| 512 AppNotification* n2 = CreateNotification(2); | 539 AppNotification* n2 = CreateNotification(2); |
| 513 model()->Add(n2); | 540 model()->Add(n2); |
| 514 model()->MergeDataAndStartSyncing( | 541 model()->MergeDataAndStartSyncing( |
| 515 syncable::APP_NOTIFICATIONS, | 542 syncable::APP_NOTIFICATIONS, |
| 516 SyncDataList(), | 543 SyncDataList(), |
| 517 processor()); | 544 PassProcessor()); |
| 518 | 545 |
| 519 // Some adds and some deletes. | 546 // Some adds and some deletes. |
| 520 SyncChangeList changes; | 547 SyncChangeList changes; |
| 521 changes.push_back(CreateSyncChange( | 548 changes.push_back(CreateSyncChange( |
| 522 SyncChange::ACTION_ADD, CreateNotification(1))); | 549 SyncChange::ACTION_ADD, CreateNotification(1))); |
| 523 | 550 |
| 524 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 551 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 525 EXPECT_FALSE(error.IsSet()); | 552 EXPECT_FALSE(error.IsSet()); |
| 526 | 553 |
| 527 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 554 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 528 EXPECT_EQ(2, processor()->change_list_size()); | 555 EXPECT_EQ(2, processor()->change_list_size()); |
| 529 } | 556 } |
| 530 | 557 |
| 531 // Process sync changes should ignore a bad DELETE. | 558 // Process sync changes should ignore a bad DELETE. |
| 532 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) { | 559 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) { |
| 533 AppNotification* n1 = CreateNotification(1); | 560 AppNotification* n1 = CreateNotification(1); |
| 534 model()->Add(n1); | 561 model()->Add(n1); |
| 535 AppNotification* n2 = CreateNotification(2); | 562 AppNotification* n2 = CreateNotification(2); |
| 536 model()->Add(n2); | 563 model()->Add(n2); |
| 537 model()->MergeDataAndStartSyncing( | 564 model()->MergeDataAndStartSyncing( |
| 538 syncable::APP_NOTIFICATIONS, | 565 syncable::APP_NOTIFICATIONS, |
| 539 SyncDataList(), | 566 SyncDataList(), |
| 540 processor()); | 567 PassProcessor()); |
| 541 | 568 |
| 542 // Some adds and some deletes. | 569 // Some adds and some deletes. |
| 543 SyncChangeList changes; | 570 SyncChangeList changes; |
| 544 changes.push_back(CreateSyncChange( | 571 changes.push_back(CreateSyncChange( |
| 545 SyncChange::ACTION_DELETE, CreateNotification(3))); | 572 SyncChange::ACTION_DELETE, CreateNotification(3))); |
| 546 | 573 |
| 547 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 574 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 548 EXPECT_FALSE(error.IsSet()); | 575 EXPECT_FALSE(error.IsSet()); |
| 549 | 576 |
| 550 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 577 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 551 EXPECT_EQ(2, processor()->change_list_size()); | 578 EXPECT_EQ(2, processor()->change_list_size()); |
| 552 } | 579 } |
| 553 | 580 |
| 554 // Process sync changes should ignore bad UPDATEs. | 581 // Process sync changes should ignore bad UPDATEs. |
| 555 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) { | 582 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) { |
| 556 AppNotification* n1 = CreateNotification(1); | 583 AppNotification* n1 = CreateNotification(1); |
| 557 model()->Add(n1); | 584 model()->Add(n1); |
| 558 AppNotification* n2 = CreateNotification(2); | 585 AppNotification* n2 = CreateNotification(2); |
| 559 model()->Add(n2); | 586 model()->Add(n2); |
| 560 model()->MergeDataAndStartSyncing( | 587 model()->MergeDataAndStartSyncing( |
| 561 syncable::APP_NOTIFICATIONS, | 588 syncable::APP_NOTIFICATIONS, |
| 562 SyncDataList(), | 589 SyncDataList(), |
| 563 processor()); | 590 PassProcessor()); |
| 564 | 591 |
| 565 // Some adds and some deletes. | 592 // Some adds and some deletes. |
| 566 SyncChangeList changes; | 593 SyncChangeList changes; |
| 567 changes.push_back(CreateSyncChange( | 594 changes.push_back(CreateSyncChange( |
| 568 SyncChange::ACTION_UPDATE, CreateNotification(3))); | 595 SyncChange::ACTION_UPDATE, CreateNotification(3))); |
| 569 AppNotification* n2_changed = n2->Copy(); | 596 AppNotification* n2_changed = n2->Copy(); |
| 570 n2_changed->set_link_text(n2_changed->link_text() + "-changed"); | 597 n2_changed->set_link_text(n2_changed->link_text() + "-changed"); |
| 571 changes.push_back(CreateSyncChange( | 598 changes.push_back(CreateSyncChange( |
| 572 SyncChange::ACTION_UPDATE, n2_changed)); | 599 SyncChange::ACTION_UPDATE, n2_changed)); |
| 573 | 600 |
| 574 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 601 SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 575 EXPECT_FALSE(error.IsSet()); | 602 EXPECT_FALSE(error.IsSet()); |
| 576 | 603 |
| 577 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 604 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 578 EXPECT_EQ(2, processor()->change_list_size()); | 605 EXPECT_EQ(2, processor()->change_list_size()); |
| 579 } | 606 } |
| 580 | 607 |
| 581 // Process over 15 changes when model is not empty. | 608 // Process over 15 changes when model is not empty. |
| 582 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { | 609 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { |
| 583 const std::string& ext_id = "e1"; | 610 const std::string& ext_id = "e1"; |
| 584 model()->MergeDataAndStartSyncing( | 611 model()->MergeDataAndStartSyncing( |
| 585 syncable::APP_NOTIFICATIONS, | 612 syncable::APP_NOTIFICATIONS, |
| 586 SyncDataList(), | 613 SyncDataList(), |
| 587 processor()); | 614 PassProcessor()); |
| 588 for (unsigned int i = 0; | 615 for (unsigned int i = 0; |
| 589 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { | 616 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { |
| 590 SyncChangeList changes; | 617 SyncChangeList changes; |
| 591 changes.push_back(CreateSyncChange( | 618 changes.push_back(CreateSyncChange( |
| 592 SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); | 619 SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); |
| 593 model()->ProcessSyncChanges(FROM_HERE, changes); | 620 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 594 if (i < AppNotificationManager::kMaxNotificationPerApp) { | 621 if (i < AppNotificationManager::kMaxNotificationPerApp) { |
| 595 EXPECT_EQ(i + 1, | 622 EXPECT_EQ(i + 1, |
| 596 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 623 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); |
| 597 } else { | 624 } else { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 612 SyncChangeList changes; | 639 SyncChangeList changes; |
| 613 | 640 |
| 614 SyncError sync_error = model()->ProcessSyncChanges(FROM_HERE, changes); | 641 SyncError sync_error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 615 EXPECT_TRUE(sync_error.IsSet()); | 642 EXPECT_TRUE(sync_error.IsSet()); |
| 616 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 643 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); |
| 617 EXPECT_EQ(0, processor()->change_list_size()); | 644 EXPECT_EQ(0, processor()->change_list_size()); |
| 618 } | 645 } |
| 619 | 646 |
| 620 // Stop syncing sets state correctly. | 647 // Stop syncing sets state correctly. |
| 621 TEST_F(AppNotificationManagerSyncTest, StopSyncing) { | 648 TEST_F(AppNotificationManagerSyncTest, StopSyncing) { |
| 622 EXPECT_FALSE(model()->sync_processor_); | 649 EXPECT_FALSE(model()->sync_processor_.get()); |
| 623 EXPECT_FALSE(model()->models_associated_); | 650 EXPECT_FALSE(model()->models_associated_); |
| 624 | 651 |
| 625 model()->MergeDataAndStartSyncing( | 652 model()->MergeDataAndStartSyncing( |
| 626 syncable::APP_NOTIFICATIONS, | 653 syncable::APP_NOTIFICATIONS, |
| 627 SyncDataList(), | 654 SyncDataList(), |
| 628 processor()); | 655 PassProcessor()); |
| 629 | 656 |
| 630 EXPECT_TRUE(model()->sync_processor_); | 657 EXPECT_TRUE(model()->sync_processor_.get()); |
| 631 EXPECT_TRUE(model()->models_associated_); | 658 EXPECT_TRUE(model()->models_associated_); |
| 632 | 659 |
| 633 model()->StopSyncing(syncable::APP_NOTIFICATIONS); | 660 model()->StopSyncing(syncable::APP_NOTIFICATIONS); |
| 634 EXPECT_FALSE(model()->sync_processor_); | 661 EXPECT_FALSE(model()->sync_processor_.get()); |
| 635 EXPECT_FALSE(model()->models_associated_); | 662 EXPECT_FALSE(model()->models_associated_); |
| 636 } | 663 } |
| 637 | 664 |
| 638 // Adds get pushed to sync but local only are skipped. | 665 // Adds get pushed to sync but local only are skipped. |
| 639 TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) { | 666 TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) { |
| 640 model()->MergeDataAndStartSyncing( | 667 model()->MergeDataAndStartSyncing( |
| 641 syncable::APP_NOTIFICATIONS, | 668 syncable::APP_NOTIFICATIONS, |
| 642 SyncDataList(), | 669 SyncDataList(), |
| 643 processor()); | 670 PassProcessor()); |
| 644 | 671 |
| 645 AppNotification* n1 = CreateNotification(1); | 672 AppNotification* n1 = CreateNotification(1); |
| 646 model()->Add(n1); | 673 model()->Add(n1); |
| 647 AppNotification* n2 = CreateNotification(2); | 674 AppNotification* n2 = CreateNotification(2); |
| 648 model()->Add(n2); | 675 model()->Add(n2); |
| 649 AppNotification* n3 = CreateNotification(true, 2); | 676 AppNotification* n3 = CreateNotification(true, 2); |
| 650 model()->Add(n3); | 677 model()->Add(n3); |
| 651 | 678 |
| 652 EXPECT_EQ(2, processor()->change_list_size()); | 679 EXPECT_EQ(2, processor()->change_list_size()); |
| 653 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); | 680 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 670 AppNotificationManager::CreateSyncDataFromNotification(*n1)); | 697 AppNotificationManager::CreateSyncDataFromNotification(*n1)); |
| 671 initial_data.push_back( | 698 initial_data.push_back( |
| 672 AppNotificationManager::CreateSyncDataFromNotification(*n2)); | 699 AppNotificationManager::CreateSyncDataFromNotification(*n2)); |
| 673 initial_data.push_back( | 700 initial_data.push_back( |
| 674 AppNotificationManager::CreateSyncDataFromNotification(*n3)); | 701 AppNotificationManager::CreateSyncDataFromNotification(*n3)); |
| 675 initial_data.push_back( | 702 initial_data.push_back( |
| 676 AppNotificationManager::CreateSyncDataFromNotification(*n4)); | 703 AppNotificationManager::CreateSyncDataFromNotification(*n4)); |
| 677 model()->MergeDataAndStartSyncing( | 704 model()->MergeDataAndStartSyncing( |
| 678 syncable::APP_NOTIFICATIONS, | 705 syncable::APP_NOTIFICATIONS, |
| 679 initial_data, | 706 initial_data, |
| 680 processor()); | 707 PassProcessor()); |
| 681 | 708 |
| 682 model()->ClearAll(ext_id); | 709 model()->ClearAll(ext_id); |
| 683 | 710 |
| 684 EXPECT_EQ(3, processor()->change_list_size()); | 711 EXPECT_EQ(3, processor()->change_list_size()); |
| 685 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); | 712 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); |
| 686 SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); | 713 SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); |
| 687 AssertSyncChange(c1, SyncChange::ACTION_DELETE, *n1); | 714 AssertSyncChange(c1, SyncChange::ACTION_DELETE, *n1); |
| 688 SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); | 715 SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); |
| 689 AssertSyncChange(c2, SyncChange::ACTION_DELETE, *n2); | 716 AssertSyncChange(c2, SyncChange::ACTION_DELETE, *n2); |
| 690 SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); | 717 SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); |
| 691 AssertSyncChange(c3, SyncChange::ACTION_DELETE, *n3); | 718 AssertSyncChange(c3, SyncChange::ACTION_DELETE, *n3); |
| 692 } | 719 } |
| OLD | NEW |