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