| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 EXPECT_TRUE(notif1->Equals(*notif2)); | 256 EXPECT_TRUE(notif1->Equals(*notif2)); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 // GetAllSyncData returns all notifications since none are marked local only. | 260 // GetAllSyncData returns all notifications since none are marked local only. |
| 261 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataNoLocal) { | 261 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataNoLocal) { |
| 262 model()->Add(CreateNotificationNoLink(1)); | 262 model()->Add(CreateNotificationNoLink(1)); |
| 263 model()->Add(CreateNotification(2)); | 263 model()->Add(CreateNotification(2)); |
| 264 model()->Add(CreateNotification(3)); | 264 model()->Add(CreateNotification(3)); |
| 265 syncer::SyncDataList all_sync_data = | 265 syncer::SyncDataList all_sync_data = |
| 266 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS); | 266 model()->GetAllSyncData(syncer::APP_NOTIFICATIONS); |
| 267 | 267 |
| 268 EXPECT_EQ(3U, all_sync_data.size()); | 268 EXPECT_EQ(3U, all_sync_data.size()); |
| 269 | 269 |
| 270 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); | 270 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 271 iter != all_sync_data.end(); ++iter) { | 271 iter != all_sync_data.end(); ++iter) { |
| 272 scoped_ptr<AppNotification> notif1( | 272 scoped_ptr<AppNotification> notif1( |
| 273 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 273 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 274 | 274 |
| 275 const std::string& guid = notif1->guid(); | 275 const std::string& guid = notif1->guid(); |
| 276 const std::string& ext_id = notif1->extension_id(); | 276 const std::string& ext_id = notif1->extension_id(); |
| 277 | 277 |
| 278 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 278 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 279 ASSERT_TRUE(notif1->Equals(*notif2)); | 279 ASSERT_TRUE(notif1->Equals(*notif2)); |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 | 282 |
| 283 // GetAllSyncData should not return notifications marked as local only. | 283 // GetAllSyncData should not return notifications marked as local only. |
| 284 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataSomeLocal) { | 284 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataSomeLocal) { |
| 285 model()->Add(CreateNotificationNoLink(1)); | 285 model()->Add(CreateNotificationNoLink(1)); |
| 286 model()->Add(CreateNotification(true, 2)); | 286 model()->Add(CreateNotification(true, 2)); |
| 287 model()->Add(CreateNotification(3)); | 287 model()->Add(CreateNotification(3)); |
| 288 model()->Add(CreateNotification(true, 4)); | 288 model()->Add(CreateNotification(true, 4)); |
| 289 model()->Add(CreateNotification(5)); | 289 model()->Add(CreateNotification(5)); |
| 290 syncer::SyncDataList all_sync_data = | 290 syncer::SyncDataList all_sync_data = |
| 291 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS); | 291 model()->GetAllSyncData(syncer::APP_NOTIFICATIONS); |
| 292 | 292 |
| 293 EXPECT_EQ(3U, all_sync_data.size()); | 293 EXPECT_EQ(3U, all_sync_data.size()); |
| 294 | 294 |
| 295 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); | 295 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin(); |
| 296 iter != all_sync_data.end(); ++iter) { | 296 iter != all_sync_data.end(); ++iter) { |
| 297 scoped_ptr<AppNotification> notif1( | 297 scoped_ptr<AppNotification> notif1( |
| 298 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 298 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 299 const std::string& guid = notif1->guid(); | 299 const std::string& guid = notif1->guid(); |
| 300 const std::string& ext_id = notif1->extension_id(); | 300 const std::string& ext_id = notif1->extension_id(); |
| 301 | 301 |
| 302 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 302 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 303 ASSERT_TRUE(notif1->Equals(*notif2)); | 303 ASSERT_TRUE(notif1->Equals(*notif2)); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 // Model assocation: both models are empty. | 307 // Model assocation: both models are empty. |
| 308 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) { | 308 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) { |
| 309 model()->MergeDataAndStartSyncing( | 309 model()->MergeDataAndStartSyncing( |
| 310 syncable::APP_NOTIFICATIONS, | 310 syncer::APP_NOTIFICATIONS, |
| 311 syncer::SyncDataList(), // Empty. | 311 syncer::SyncDataList(), // Empty. |
| 312 PassProcessor(), | 312 PassProcessor(), |
| 313 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 313 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 314 | 314 |
| 315 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 315 EXPECT_EQ(0U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 316 EXPECT_EQ(0U, processor()->change_list_size()); | 316 EXPECT_EQ(0U, processor()->change_list_size()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Model assocation: empty sync model and non-empty local model. | 319 // Model assocation: empty sync model and non-empty local model. |
| 320 TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) { | 320 TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) { |
| 321 syncer::SyncDataList initial_data; | 321 syncer::SyncDataList initial_data; |
| 322 initial_data.push_back(CreateSyncData(1)); | 322 initial_data.push_back(CreateSyncData(1)); |
| 323 initial_data.push_back(CreateSyncData(2)); | 323 initial_data.push_back(CreateSyncData(2)); |
| 324 initial_data.push_back(CreateSyncData(3)); | 324 initial_data.push_back(CreateSyncData(3)); |
| 325 initial_data.push_back(CreateSyncData(4)); | 325 initial_data.push_back(CreateSyncData(4)); |
| 326 | 326 |
| 327 model()->MergeDataAndStartSyncing( | 327 model()->MergeDataAndStartSyncing( |
| 328 syncable::APP_NOTIFICATIONS, | 328 syncer::APP_NOTIFICATIONS, |
| 329 initial_data, | 329 initial_data, |
| 330 PassProcessor(), | 330 PassProcessor(), |
| 331 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 331 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 332 | 332 |
| 333 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 333 EXPECT_EQ(4U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 334 // Model should all of the initial sync data. | 334 // Model should all of the initial sync data. |
| 335 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 335 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 336 iter != initial_data.end(); ++iter) { | 336 iter != initial_data.end(); ++iter) { |
| 337 scoped_ptr<AppNotification> notif1( | 337 scoped_ptr<AppNotification> notif1( |
| 338 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 338 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 339 const std::string& ext_id = notif1->extension_id(); | 339 const std::string& ext_id = notif1->extension_id(); |
| 340 const std::string& guid = notif1->guid(); | 340 const std::string& guid = notif1->guid(); |
| 341 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 341 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 342 EXPECT_TRUE(notif2); | 342 EXPECT_TRUE(notif2); |
| 343 EXPECT_TRUE(notif1->Equals(*notif2)); | 343 EXPECT_TRUE(notif1->Equals(*notif2)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 356 AppNotification* n3 = CreateNotification(3); | 356 AppNotification* n3 = CreateNotification(3); |
| 357 model()->Add(n3); | 357 model()->Add(n3); |
| 358 | 358 |
| 359 syncer::SyncDataList initial_data; | 359 syncer::SyncDataList initial_data; |
| 360 initial_data.push_back(CreateSyncData(4)); | 360 initial_data.push_back(CreateSyncData(4)); |
| 361 initial_data.push_back(CreateSyncData(5)); | 361 initial_data.push_back(CreateSyncData(5)); |
| 362 initial_data.push_back(CreateSyncData(6)); | 362 initial_data.push_back(CreateSyncData(6)); |
| 363 initial_data.push_back(CreateSyncData(7)); | 363 initial_data.push_back(CreateSyncData(7)); |
| 364 | 364 |
| 365 model()->MergeDataAndStartSyncing( | 365 model()->MergeDataAndStartSyncing( |
| 366 syncable::APP_NOTIFICATIONS, | 366 syncer::APP_NOTIFICATIONS, |
| 367 initial_data, | 367 initial_data, |
| 368 PassProcessor(), | 368 PassProcessor(), |
| 369 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 369 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 370 | 370 |
| 371 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 371 EXPECT_EQ(6U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 372 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 372 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 373 iter != initial_data.end(); ++iter) { | 373 iter != initial_data.end(); ++iter) { |
| 374 scoped_ptr<AppNotification> notif1( | 374 scoped_ptr<AppNotification> notif1( |
| 375 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 375 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 376 const std::string& ext_id = notif1->extension_id(); | 376 const std::string& ext_id = notif1->extension_id(); |
| 377 const std::string& guid = notif1->guid(); | 377 const std::string& guid = notif1->guid(); |
| 378 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 378 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 379 EXPECT_TRUE(notif2); | 379 EXPECT_TRUE(notif2); |
| 380 EXPECT_TRUE(notif1->Equals(*notif2)); | 380 EXPECT_TRUE(notif1->Equals(*notif2)); |
| 381 } | 381 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 408 syncer::SyncDataList initial_data; | 408 syncer::SyncDataList initial_data; |
| 409 initial_data.push_back(CreateSyncData(5)); | 409 initial_data.push_back(CreateSyncData(5)); |
| 410 initial_data.push_back( | 410 initial_data.push_back( |
| 411 AppNotificationManager::CreateSyncDataFromNotification(*n1)); | 411 AppNotificationManager::CreateSyncDataFromNotification(*n1)); |
| 412 initial_data.push_back(CreateSyncData(6)); | 412 initial_data.push_back(CreateSyncData(6)); |
| 413 initial_data.push_back( | 413 initial_data.push_back( |
| 414 AppNotificationManager::CreateSyncDataFromNotification(*n4)); | 414 AppNotificationManager::CreateSyncDataFromNotification(*n4)); |
| 415 initial_data.push_back(CreateSyncData(7)); | 415 initial_data.push_back(CreateSyncData(7)); |
| 416 | 416 |
| 417 model()->MergeDataAndStartSyncing( | 417 model()->MergeDataAndStartSyncing( |
| 418 syncable::APP_NOTIFICATIONS, | 418 syncer::APP_NOTIFICATIONS, |
| 419 initial_data, | 419 initial_data, |
| 420 PassProcessor(), | 420 PassProcessor(), |
| 421 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 421 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 422 | 422 |
| 423 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 423 EXPECT_EQ(6U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 424 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); | 424 for (syncer::SyncDataList::const_iterator iter = initial_data.begin(); |
| 425 iter != initial_data.end(); ++iter) { | 425 iter != initial_data.end(); ++iter) { |
| 426 scoped_ptr<AppNotification> notif1( | 426 scoped_ptr<AppNotification> notif1( |
| 427 AppNotificationManager::CreateNotificationFromSyncData(*iter)); | 427 AppNotificationManager::CreateNotificationFromSyncData(*iter)); |
| 428 const std::string& ext_id = notif1->extension_id(); | 428 const std::string& ext_id = notif1->extension_id(); |
| 429 const std::string& guid = notif1->guid(); | 429 const std::string& guid = notif1->guid(); |
| 430 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); | 430 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); |
| 431 EXPECT_TRUE(notif2); | 431 EXPECT_TRUE(notif2); |
| 432 EXPECT_TRUE(notif1->Equals(*notif2)); | 432 EXPECT_TRUE(notif1->Equals(*notif2)); |
| 433 } | 433 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 462 n1->body(), n1->link_url().spec(), n1->link_text())); | 462 n1->body(), n1->link_url().spec(), n1->link_text())); |
| 463 initial_data.push_back( | 463 initial_data.push_back( |
| 464 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); | 464 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); |
| 465 | 465 |
| 466 scoped_ptr<syncer::SyncErrorFactoryMock> error_handler( | 466 scoped_ptr<syncer::SyncErrorFactoryMock> error_handler( |
| 467 new syncer::SyncErrorFactoryMock()); | 467 new syncer::SyncErrorFactoryMock()); |
| 468 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). | 468 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). |
| 469 WillOnce( | 469 WillOnce( |
| 470 Return( | 470 Return( |
| 471 syncer::SyncError( | 471 syncer::SyncError( |
| 472 FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); | 472 FROM_HERE, "error", syncer::APP_NOTIFICATIONS))); |
| 473 | 473 |
| 474 syncer::SyncError sync_error = model()->MergeDataAndStartSyncing( | 474 syncer::SyncError sync_error = model()->MergeDataAndStartSyncing( |
| 475 syncable::APP_NOTIFICATIONS, | 475 syncer::APP_NOTIFICATIONS, |
| 476 initial_data, | 476 initial_data, |
| 477 PassProcessor(), | 477 PassProcessor(), |
| 478 error_handler.PassAs<syncer::SyncErrorFactory>()); | 478 error_handler.PassAs<syncer::SyncErrorFactory>()); |
| 479 | 479 |
| 480 EXPECT_TRUE(sync_error.IsSet()); | 480 EXPECT_TRUE(sync_error.IsSet()); |
| 481 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 481 EXPECT_EQ(syncer::APP_NOTIFICATIONS, sync_error.type()); |
| 482 EXPECT_EQ(0U, processor()->change_list_size()); | 482 EXPECT_EQ(0U, processor()->change_list_size()); |
| 483 } | 483 } |
| 484 | 484 |
| 485 // When an item in sync matches with a local-only item in model, an error | 485 // When an item in sync matches with a local-only item in model, an error |
| 486 // should be returned. | 486 // should be returned. |
| 487 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) { | 487 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) { |
| 488 AppNotification* n1 = CreateNotification(1); | 488 AppNotification* n1 = CreateNotification(1); |
| 489 model()->Add(n1); | 489 model()->Add(n1); |
| 490 AppNotification* n2 = CreateNotification(true, 2); | 490 AppNotification* n2 = CreateNotification(true, 2); |
| 491 model()->Add(n2); | 491 model()->Add(n2); |
| 492 | 492 |
| 493 syncer::SyncDataList initial_data; | 493 syncer::SyncDataList initial_data; |
| 494 initial_data.push_back(CreateSyncData(1)); | 494 initial_data.push_back(CreateSyncData(1)); |
| 495 scoped_ptr<AppNotification> n2_a(CreateNotification(2)); | 495 scoped_ptr<AppNotification> n2_a(CreateNotification(2)); |
| 496 initial_data.push_back( | 496 initial_data.push_back( |
| 497 AppNotificationManager::CreateSyncDataFromNotification(*n2_a)); | 497 AppNotificationManager::CreateSyncDataFromNotification(*n2_a)); |
| 498 | 498 |
| 499 scoped_ptr<syncer::SyncErrorFactoryMock> error_handler( | 499 scoped_ptr<syncer::SyncErrorFactoryMock> error_handler( |
| 500 new syncer::SyncErrorFactoryMock()); | 500 new syncer::SyncErrorFactoryMock()); |
| 501 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). | 501 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). |
| 502 WillOnce( | 502 WillOnce( |
| 503 Return( | 503 Return( |
| 504 syncer::SyncError( | 504 syncer::SyncError( |
| 505 FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); | 505 FROM_HERE, "error", syncer::APP_NOTIFICATIONS))); |
| 506 | 506 |
| 507 syncer::SyncError sync_error = model()->MergeDataAndStartSyncing( | 507 syncer::SyncError sync_error = model()->MergeDataAndStartSyncing( |
| 508 syncable::APP_NOTIFICATIONS, | 508 syncer::APP_NOTIFICATIONS, |
| 509 initial_data, | 509 initial_data, |
| 510 PassProcessor(), | 510 PassProcessor(), |
| 511 error_handler.PassAs<syncer::SyncErrorFactory>()); | 511 error_handler.PassAs<syncer::SyncErrorFactory>()); |
| 512 | 512 |
| 513 EXPECT_TRUE(sync_error.IsSet()); | 513 EXPECT_TRUE(sync_error.IsSet()); |
| 514 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); | 514 EXPECT_EQ(syncer::APP_NOTIFICATIONS, sync_error.type()); |
| 515 EXPECT_EQ(0U, processor()->change_list_size()); | 515 EXPECT_EQ(0U, processor()->change_list_size()); |
| 516 } | 516 } |
| 517 | 517 |
| 518 // Process sync changes when model is empty. | 518 // Process sync changes when model is empty. |
| 519 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) { | 519 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) { |
| 520 // We initially have no data. | 520 // We initially have no data. |
| 521 model()->MergeDataAndStartSyncing( | 521 model()->MergeDataAndStartSyncing( |
| 522 syncable::APP_NOTIFICATIONS, | 522 syncer::APP_NOTIFICATIONS, |
| 523 syncer::SyncDataList(), | 523 syncer::SyncDataList(), |
| 524 PassProcessor(), | 524 PassProcessor(), |
| 525 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 525 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 526 | 526 |
| 527 // Set up a bunch of ADDs. | 527 // Set up a bunch of ADDs. |
| 528 syncer::SyncChangeList changes; | 528 syncer::SyncChangeList changes; |
| 529 changes.push_back(CreateSyncChange( | 529 changes.push_back(CreateSyncChange( |
| 530 syncer::SyncChange::ACTION_ADD, CreateNotification(1))); | 530 syncer::SyncChange::ACTION_ADD, CreateNotification(1))); |
| 531 changes.push_back(CreateSyncChange( | 531 changes.push_back(CreateSyncChange( |
| 532 syncer::SyncChange::ACTION_ADD, CreateNotification(2))); | 532 syncer::SyncChange::ACTION_ADD, CreateNotification(2))); |
| 533 changes.push_back(CreateSyncChange( | 533 changes.push_back(CreateSyncChange( |
| 534 syncer::SyncChange::ACTION_ADD, CreateNotification(3))); | 534 syncer::SyncChange::ACTION_ADD, CreateNotification(3))); |
| 535 | 535 |
| 536 model()->ProcessSyncChanges(FROM_HERE, changes); | 536 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 537 | 537 |
| 538 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 538 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 539 EXPECT_EQ(0U, processor()->change_list_size()); | 539 EXPECT_EQ(0U, processor()->change_list_size()); |
| 540 } | 540 } |
| 541 | 541 |
| 542 // Process sync changes when model is not empty. | 542 // Process sync changes when model is not empty. |
| 543 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { | 543 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { |
| 544 AppNotification* n1 = CreateNotification(1); | 544 AppNotification* n1 = CreateNotification(1); |
| 545 model()->Add(n1); | 545 model()->Add(n1); |
| 546 AppNotification* n2 = CreateNotification(2); | 546 AppNotification* n2 = CreateNotification(2); |
| 547 model()->Add(n2); | 547 model()->Add(n2); |
| 548 model()->MergeDataAndStartSyncing( | 548 model()->MergeDataAndStartSyncing( |
| 549 syncable::APP_NOTIFICATIONS, | 549 syncer::APP_NOTIFICATIONS, |
| 550 syncer::SyncDataList(), | 550 syncer::SyncDataList(), |
| 551 PassProcessor(), | 551 PassProcessor(), |
| 552 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 552 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 553 | 553 |
| 554 // Some adds and some deletes. | 554 // Some adds and some deletes. |
| 555 syncer::SyncChangeList changes; | 555 syncer::SyncChangeList changes; |
| 556 changes.push_back(CreateSyncChange( | 556 changes.push_back(CreateSyncChange( |
| 557 syncer::SyncChange::ACTION_ADD, CreateNotification(3))); | 557 syncer::SyncChange::ACTION_ADD, CreateNotification(3))); |
| 558 changes.push_back(CreateSyncChange( | 558 changes.push_back(CreateSyncChange( |
| 559 syncer::SyncChange::ACTION_DELETE, n1->Copy())); | 559 syncer::SyncChange::ACTION_DELETE, n1->Copy())); |
| 560 changes.push_back(CreateSyncChange( | 560 changes.push_back(CreateSyncChange( |
| 561 syncer::SyncChange::ACTION_ADD, CreateNotification(4))); | 561 syncer::SyncChange::ACTION_ADD, CreateNotification(4))); |
| 562 | 562 |
| 563 model()->ProcessSyncChanges(FROM_HERE, changes); | 563 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 564 | 564 |
| 565 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 565 EXPECT_EQ(3U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 566 EXPECT_EQ(2U, processor()->change_list_size()); | 566 EXPECT_EQ(2U, processor()->change_list_size()); |
| 567 } | 567 } |
| 568 | 568 |
| 569 // Process sync changes should ignore a bad ADD. | 569 // Process sync changes should ignore a bad ADD. |
| 570 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) { | 570 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) { |
| 571 AppNotification* n1 = CreateNotification(1); | 571 AppNotification* n1 = CreateNotification(1); |
| 572 model()->Add(n1); | 572 model()->Add(n1); |
| 573 AppNotification* n2 = CreateNotification(2); | 573 AppNotification* n2 = CreateNotification(2); |
| 574 model()->Add(n2); | 574 model()->Add(n2); |
| 575 model()->MergeDataAndStartSyncing( | 575 model()->MergeDataAndStartSyncing( |
| 576 syncable::APP_NOTIFICATIONS, | 576 syncer::APP_NOTIFICATIONS, |
| 577 syncer::SyncDataList(), | 577 syncer::SyncDataList(), |
| 578 PassProcessor(), | 578 PassProcessor(), |
| 579 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 579 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 580 | 580 |
| 581 // Some adds and some deletes. | 581 // Some adds and some deletes. |
| 582 syncer::SyncChangeList changes; | 582 syncer::SyncChangeList changes; |
| 583 changes.push_back(CreateSyncChange( | 583 changes.push_back(CreateSyncChange( |
| 584 syncer::SyncChange::ACTION_ADD, CreateNotification(1))); | 584 syncer::SyncChange::ACTION_ADD, CreateNotification(1))); |
| 585 | 585 |
| 586 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 586 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 587 EXPECT_FALSE(error.IsSet()); | 587 EXPECT_FALSE(error.IsSet()); |
| 588 | 588 |
| 589 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 589 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 590 EXPECT_EQ(2U, processor()->change_list_size()); | 590 EXPECT_EQ(2U, processor()->change_list_size()); |
| 591 } | 591 } |
| 592 | 592 |
| 593 // Process sync changes should ignore a bad DELETE. | 593 // Process sync changes should ignore a bad DELETE. |
| 594 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) { | 594 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) { |
| 595 AppNotification* n1 = CreateNotification(1); | 595 AppNotification* n1 = CreateNotification(1); |
| 596 model()->Add(n1); | 596 model()->Add(n1); |
| 597 AppNotification* n2 = CreateNotification(2); | 597 AppNotification* n2 = CreateNotification(2); |
| 598 model()->Add(n2); | 598 model()->Add(n2); |
| 599 model()->MergeDataAndStartSyncing( | 599 model()->MergeDataAndStartSyncing( |
| 600 syncable::APP_NOTIFICATIONS, | 600 syncer::APP_NOTIFICATIONS, |
| 601 syncer::SyncDataList(), | 601 syncer::SyncDataList(), |
| 602 PassProcessor(), | 602 PassProcessor(), |
| 603 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 603 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 604 | 604 |
| 605 // Some adds and some deletes. | 605 // Some adds and some deletes. |
| 606 syncer::SyncChangeList changes; | 606 syncer::SyncChangeList changes; |
| 607 changes.push_back(CreateSyncChange( | 607 changes.push_back(CreateSyncChange( |
| 608 syncer::SyncChange::ACTION_DELETE, CreateNotification(3))); | 608 syncer::SyncChange::ACTION_DELETE, CreateNotification(3))); |
| 609 | 609 |
| 610 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 610 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 611 EXPECT_FALSE(error.IsSet()); | 611 EXPECT_FALSE(error.IsSet()); |
| 612 | 612 |
| 613 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 613 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 614 EXPECT_EQ(2U, processor()->change_list_size()); | 614 EXPECT_EQ(2U, processor()->change_list_size()); |
| 615 } | 615 } |
| 616 | 616 |
| 617 // Process sync changes should ignore bad UPDATEs. | 617 // Process sync changes should ignore bad UPDATEs. |
| 618 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) { | 618 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) { |
| 619 AppNotification* n1 = CreateNotification(1); | 619 AppNotification* n1 = CreateNotification(1); |
| 620 model()->Add(n1); | 620 model()->Add(n1); |
| 621 AppNotification* n2 = CreateNotification(2); | 621 AppNotification* n2 = CreateNotification(2); |
| 622 model()->Add(n2); | 622 model()->Add(n2); |
| 623 model()->MergeDataAndStartSyncing( | 623 model()->MergeDataAndStartSyncing( |
| 624 syncable::APP_NOTIFICATIONS, | 624 syncer::APP_NOTIFICATIONS, |
| 625 syncer::SyncDataList(), | 625 syncer::SyncDataList(), |
| 626 PassProcessor(), | 626 PassProcessor(), |
| 627 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 627 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 628 | 628 |
| 629 // Some adds and some deletes. | 629 // Some adds and some deletes. |
| 630 syncer::SyncChangeList changes; | 630 syncer::SyncChangeList changes; |
| 631 changes.push_back(CreateSyncChange( | 631 changes.push_back(CreateSyncChange( |
| 632 syncer::SyncChange::ACTION_UPDATE, CreateNotification(3))); | 632 syncer::SyncChange::ACTION_UPDATE, CreateNotification(3))); |
| 633 AppNotification* n2_changed = n2->Copy(); | 633 AppNotification* n2_changed = n2->Copy(); |
| 634 n2_changed->set_link_text(n2_changed->link_text() + "-changed"); | 634 n2_changed->set_link_text(n2_changed->link_text() + "-changed"); |
| 635 changes.push_back(CreateSyncChange( | 635 changes.push_back(CreateSyncChange( |
| 636 syncer::SyncChange::ACTION_UPDATE, n2_changed)); | 636 syncer::SyncChange::ACTION_UPDATE, n2_changed)); |
| 637 | 637 |
| 638 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); | 638 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); |
| 639 EXPECT_FALSE(error.IsSet()); | 639 EXPECT_FALSE(error.IsSet()); |
| 640 | 640 |
| 641 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 641 EXPECT_EQ(2U, model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 642 EXPECT_EQ(2U, processor()->change_list_size()); | 642 EXPECT_EQ(2U, processor()->change_list_size()); |
| 643 } | 643 } |
| 644 | 644 |
| 645 // Process over 15 changes when model is not empty. | 645 // Process over 15 changes when model is not empty. |
| 646 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { | 646 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { |
| 647 const std::string& ext_id = "e1"; | 647 const std::string& ext_id = "e1"; |
| 648 model()->MergeDataAndStartSyncing( | 648 model()->MergeDataAndStartSyncing( |
| 649 syncable::APP_NOTIFICATIONS, | 649 syncer::APP_NOTIFICATIONS, |
| 650 syncer::SyncDataList(), | 650 syncer::SyncDataList(), |
| 651 PassProcessor(), | 651 PassProcessor(), |
| 652 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 652 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 653 for (unsigned int i = 0; | 653 for (unsigned int i = 0; |
| 654 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { | 654 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { |
| 655 syncer::SyncChangeList changes; | 655 syncer::SyncChangeList changes; |
| 656 changes.push_back(CreateSyncChange( | 656 changes.push_back(CreateSyncChange( |
| 657 syncer::SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); | 657 syncer::SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); |
| 658 model()->ProcessSyncChanges(FROM_HERE, changes); | 658 model()->ProcessSyncChanges(FROM_HERE, changes); |
| 659 if (i < AppNotificationManager::kMaxNotificationPerApp) { | 659 if (i < AppNotificationManager::kMaxNotificationPerApp) { |
| 660 EXPECT_EQ(i + 1, | 660 EXPECT_EQ(i + 1, |
| 661 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 661 model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 662 } else { | 662 } else { |
| 663 EXPECT_EQ(AppNotificationManager::kMaxNotificationPerApp, | 663 EXPECT_EQ(AppNotificationManager::kMaxNotificationPerApp, |
| 664 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 664 model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 665 for (unsigned int j = i; j > i - 5; j--) { | 665 for (unsigned int j = i; j > i - 5; j--) { |
| 666 EXPECT_EQ( | 666 EXPECT_EQ( |
| 667 AppNotificationManager::kMaxNotificationPerApp, | 667 AppNotificationManager::kMaxNotificationPerApp, |
| 668 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); | 668 model()->GetAllSyncData(syncer::APP_NOTIFICATIONS).size()); |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 } | 671 } |
| 672 } | 672 } |
| 673 | 673 |
| 674 // Stop syncing sets state correctly. | 674 // Stop syncing sets state correctly. |
| 675 TEST_F(AppNotificationManagerSyncTest, StopSyncing) { | 675 TEST_F(AppNotificationManagerSyncTest, StopSyncing) { |
| 676 EXPECT_FALSE(model()->sync_processor_.get()); | 676 EXPECT_FALSE(model()->sync_processor_.get()); |
| 677 EXPECT_FALSE(model()->models_associated_); | 677 EXPECT_FALSE(model()->models_associated_); |
| 678 | 678 |
| 679 model()->MergeDataAndStartSyncing( | 679 model()->MergeDataAndStartSyncing( |
| 680 syncable::APP_NOTIFICATIONS, | 680 syncer::APP_NOTIFICATIONS, |
| 681 syncer::SyncDataList(), | 681 syncer::SyncDataList(), |
| 682 PassProcessor(), | 682 PassProcessor(), |
| 683 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 683 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 684 | 684 |
| 685 EXPECT_TRUE(model()->sync_processor_.get()); | 685 EXPECT_TRUE(model()->sync_processor_.get()); |
| 686 EXPECT_TRUE(model()->models_associated_); | 686 EXPECT_TRUE(model()->models_associated_); |
| 687 | 687 |
| 688 model()->StopSyncing(syncable::APP_NOTIFICATIONS); | 688 model()->StopSyncing(syncer::APP_NOTIFICATIONS); |
| 689 EXPECT_FALSE(model()->sync_processor_.get()); | 689 EXPECT_FALSE(model()->sync_processor_.get()); |
| 690 EXPECT_FALSE(model()->models_associated_); | 690 EXPECT_FALSE(model()->models_associated_); |
| 691 } | 691 } |
| 692 | 692 |
| 693 // Adds get pushed to sync but local only are skipped. | 693 // Adds get pushed to sync but local only are skipped. |
| 694 TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) { | 694 TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) { |
| 695 model()->MergeDataAndStartSyncing( | 695 model()->MergeDataAndStartSyncing( |
| 696 syncable::APP_NOTIFICATIONS, | 696 syncer::APP_NOTIFICATIONS, |
| 697 syncer::SyncDataList(), | 697 syncer::SyncDataList(), |
| 698 PassProcessor(), | 698 PassProcessor(), |
| 699 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 699 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 700 | 700 |
| 701 AppNotification* n1 = CreateNotification(1); | 701 AppNotification* n1 = CreateNotification(1); |
| 702 model()->Add(n1); | 702 model()->Add(n1); |
| 703 AppNotification* n2 = CreateNotification(2); | 703 AppNotification* n2 = CreateNotification(2); |
| 704 model()->Add(n2); | 704 model()->Add(n2); |
| 705 AppNotification* n3 = CreateNotification(true, 2); | 705 AppNotification* n3 = CreateNotification(true, 2); |
| 706 model()->Add(n3); | 706 model()->Add(n3); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 724 syncer::SyncDataList initial_data; | 724 syncer::SyncDataList initial_data; |
| 725 initial_data.push_back( | 725 initial_data.push_back( |
| 726 AppNotificationManager::CreateSyncDataFromNotification(*n1)); | 726 AppNotificationManager::CreateSyncDataFromNotification(*n1)); |
| 727 initial_data.push_back( | 727 initial_data.push_back( |
| 728 AppNotificationManager::CreateSyncDataFromNotification(*n2)); | 728 AppNotificationManager::CreateSyncDataFromNotification(*n2)); |
| 729 initial_data.push_back( | 729 initial_data.push_back( |
| 730 AppNotificationManager::CreateSyncDataFromNotification(*n3)); | 730 AppNotificationManager::CreateSyncDataFromNotification(*n3)); |
| 731 initial_data.push_back( | 731 initial_data.push_back( |
| 732 AppNotificationManager::CreateSyncDataFromNotification(*n4)); | 732 AppNotificationManager::CreateSyncDataFromNotification(*n4)); |
| 733 model()->MergeDataAndStartSyncing( | 733 model()->MergeDataAndStartSyncing( |
| 734 syncable::APP_NOTIFICATIONS, | 734 syncer::APP_NOTIFICATIONS, |
| 735 initial_data, | 735 initial_data, |
| 736 PassProcessor(), | 736 PassProcessor(), |
| 737 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); | 737 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 738 | 738 |
| 739 model()->ClearAll(ext_id); | 739 model()->ClearAll(ext_id); |
| 740 | 740 |
| 741 EXPECT_EQ(3U, processor()->change_list_size()); | 741 EXPECT_EQ(3U, processor()->change_list_size()); |
| 742 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); | 742 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); |
| 743 syncer::SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); | 743 syncer::SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); |
| 744 AssertSyncChange(c1, syncer::SyncChange::ACTION_DELETE, *n1); | 744 AssertSyncChange(c1, syncer::SyncChange::ACTION_DELETE, *n1); |
| 745 syncer::SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); | 745 syncer::SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); |
| 746 AssertSyncChange(c2, syncer::SyncChange::ACTION_DELETE, *n2); | 746 AssertSyncChange(c2, syncer::SyncChange::ACTION_DELETE, *n2); |
| 747 syncer::SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); | 747 syncer::SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); |
| 748 AssertSyncChange(c3, syncer::SyncChange::ACTION_DELETE, *n3); | 748 AssertSyncChange(c3, syncer::SyncChange::ACTION_DELETE, *n3); |
| 749 } | 749 } |
| OLD | NEW |