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