| 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/file_util.h" | 5 #include "base/file_util.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/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/signin/signin_manager.h" | 9 #include "chrome/browser/signin/signin_manager.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "chrome/browser/signin/token_service.h" | 11 #include "chrome/browser/signin/token_service.h" |
| 12 #include "chrome/browser/signin/token_service_factory.h" | 12 #include "chrome/browser/signin/token_service_factory.h" |
| 13 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" | 13 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" |
| 14 #include "chrome/browser/sync/glue/data_type_controller.h" | 14 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 15 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" | 15 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
| 16 #include "chrome/browser/sync/test_profile_sync_service.h" | 16 #include "chrome/browser/sync/test_profile_sync_service.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 18 #include "chrome/common/net/gaia/gaia_constants.h" | 18 #include "chrome/common/net/gaia/gaia_constants.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/testing_pref_service.h" | 20 #include "chrome/test/base/testing_pref_service.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "content/public/common/content_client.h" | 22 #include "content/public/common/content_client.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 24 #include "google/cacheinvalidation/include/types.h" | 24 #include "google/cacheinvalidation/include/types.h" |
| 25 #include "sync/js/js_arg_list.h" | 25 #include "sync/js/js_arg_list.h" |
| 26 #include "sync/js/js_event_details.h" | 26 #include "sync/js/js_event_details.h" |
| 27 #include "sync/js/js_test_util.h" | 27 #include "sync/js/js_test_util.h" |
| 28 #include "sync/notifier/mock_sync_notifier_observer.h" | 28 #include "sync/notifier/mock_sync_notifier_observer.h" |
| 29 #include "sync/notifier/object_id_state_map_test_util.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "webkit/glue/webkit_glue.h" | 32 #include "webkit/glue/webkit_glue.h" |
| 32 | 33 |
| 33 // TODO(akalin): Add tests here that exercise the whole | 34 // TODO(akalin): Add tests here that exercise the whole |
| 34 // ProfileSyncService/SyncBackendHost stack while mocking out as | 35 // ProfileSyncService/SyncBackendHost stack while mocking out as |
| 35 // little as possible. | 36 // little as possible. |
| 36 | 37 |
| 37 namespace browser_sync { | 38 namespace browser_sync { |
| 38 | 39 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // Register for some IDs with the ProfileSyncService and trigger some | 373 // Register for some IDs with the ProfileSyncService and trigger some |
| 373 // invalidation messages. They should be received by the observer. | 374 // invalidation messages. They should be received by the observer. |
| 374 // Then unregister and trigger the invalidation messages again. Those | 375 // Then unregister and trigger the invalidation messages again. Those |
| 375 // shouldn't be received by the observer. | 376 // shouldn't be received by the observer. |
| 376 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { | 377 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { |
| 377 StartSyncService(); | 378 StartSyncService(); |
| 378 | 379 |
| 379 syncer::ObjectIdSet ids; | 380 syncer::ObjectIdSet ids; |
| 380 ids.insert(invalidation::ObjectId(1, "id1")); | 381 ids.insert(invalidation::ObjectId(1, "id1")); |
| 381 ids.insert(invalidation::ObjectId(2, "id2")); | 382 ids.insert(invalidation::ObjectId(2, "id2")); |
| 382 const syncer::ObjectIdPayloadMap& payloads = | 383 const syncer::ObjectIdStateMap& states = |
| 383 syncer::ObjectIdSetToPayloadMap(ids, "payload"); | 384 syncer::ObjectIdSetToStateMap(ids, "payload"); |
| 384 | 385 |
| 385 StrictMock<syncer::MockSyncNotifierObserver> observer; | 386 StrictMock<syncer::MockSyncNotifierObserver> observer; |
| 386 EXPECT_CALL(observer, OnNotificationsEnabled()); | 387 EXPECT_CALL(observer, OnNotificationsEnabled()); |
| 387 EXPECT_CALL(observer, OnIncomingNotification( | 388 EXPECT_CALL(observer, OnIncomingNotification( |
| 388 payloads, syncer::REMOTE_NOTIFICATION)); | 389 states, syncer::REMOTE_NOTIFICATION)); |
| 389 EXPECT_CALL(observer, OnNotificationsDisabled( | 390 EXPECT_CALL(observer, OnNotificationsDisabled( |
| 390 syncer::TRANSIENT_NOTIFICATION_ERROR)); | 391 syncer::TRANSIENT_NOTIFICATION_ERROR)); |
| 391 | 392 |
| 392 service_->RegisterInvalidationHandler(&observer); | 393 service_->RegisterInvalidationHandler(&observer); |
| 393 service_->UpdateRegisteredInvalidationIds(&observer, ids); | 394 service_->UpdateRegisteredInvalidationIds(&observer, ids); |
| 394 | 395 |
| 395 SyncBackendHostForProfileSyncTest* const backend = | 396 SyncBackendHostForProfileSyncTest* const backend = |
| 396 service_->GetBackendForTest(); | 397 service_->GetBackendForTest(); |
| 397 | 398 |
| 398 backend->EmitOnNotificationsEnabled(); | 399 backend->EmitOnNotificationsEnabled(); |
| 399 backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); | 400 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); |
| 400 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); | 401 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); |
| 401 | 402 |
| 402 Mock::VerifyAndClearExpectations(&observer); | 403 Mock::VerifyAndClearExpectations(&observer); |
| 403 | 404 |
| 404 service_->UnregisterInvalidationHandler(&observer); | 405 service_->UnregisterInvalidationHandler(&observer); |
| 405 | 406 |
| 406 backend->EmitOnNotificationsEnabled(); | 407 backend->EmitOnNotificationsEnabled(); |
| 407 backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); | 408 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); |
| 408 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); | 409 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); |
| 409 } | 410 } |
| 410 | 411 |
| 411 // Register for some IDs with the ProfileSyncService, restart sync, | 412 // Register for some IDs with the ProfileSyncService, restart sync, |
| 412 // and trigger some invalidation messages. They should still be | 413 // and trigger some invalidation messages. They should still be |
| 413 // received by the observer. | 414 // received by the observer. |
| 414 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { | 415 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { |
| 415 StartSyncService(); | 416 StartSyncService(); |
| 416 | 417 |
| 417 syncer::ObjectIdSet ids; | 418 syncer::ObjectIdSet ids; |
| 418 ids.insert(invalidation::ObjectId(3, "id3")); | 419 ids.insert(invalidation::ObjectId(3, "id3")); |
| 419 const syncer::ObjectIdPayloadMap& payloads = | 420 const syncer::ObjectIdStateMap& states = |
| 420 syncer::ObjectIdSetToPayloadMap(ids, "payload"); | 421 syncer::ObjectIdSetToStateMap(ids, "payload"); |
| 421 | 422 |
| 422 StrictMock<syncer::MockSyncNotifierObserver> observer; | 423 StrictMock<syncer::MockSyncNotifierObserver> observer; |
| 423 EXPECT_CALL(observer, OnNotificationsEnabled()); | 424 EXPECT_CALL(observer, OnNotificationsEnabled()); |
| 424 EXPECT_CALL(observer, OnIncomingNotification( | 425 EXPECT_CALL(observer, OnIncomingNotification( |
| 425 payloads, syncer::REMOTE_NOTIFICATION)); | 426 states, syncer::REMOTE_NOTIFICATION)); |
| 426 // This may get called more than once, as a real notifier is | 427 // This may get called more than once, as a real notifier is |
| 427 // created. | 428 // created. |
| 428 EXPECT_CALL(observer, OnNotificationsDisabled( | 429 EXPECT_CALL(observer, OnNotificationsDisabled( |
| 429 syncer::TRANSIENT_NOTIFICATION_ERROR)).Times(AtLeast(1)); | 430 syncer::TRANSIENT_NOTIFICATION_ERROR)).Times(AtLeast(1)); |
| 430 | 431 |
| 431 service_->RegisterInvalidationHandler(&observer); | 432 service_->RegisterInvalidationHandler(&observer); |
| 432 service_->UpdateRegisteredInvalidationIds(&observer, ids); | 433 service_->UpdateRegisteredInvalidationIds(&observer, ids); |
| 433 | 434 |
| 434 service_->StopAndSuppress(); | 435 service_->StopAndSuppress(); |
| 435 service_->UnsuppressAndStart(); | 436 service_->UnsuppressAndStart(); |
| 436 | 437 |
| 437 SyncBackendHostForProfileSyncTest* const backend = | 438 SyncBackendHostForProfileSyncTest* const backend = |
| 438 service_->GetBackendForTest(); | 439 service_->GetBackendForTest(); |
| 439 | 440 |
| 440 backend->EmitOnNotificationsEnabled(); | 441 backend->EmitOnNotificationsEnabled(); |
| 441 backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); | 442 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); |
| 442 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); | 443 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); |
| 443 } | 444 } |
| 444 | 445 |
| 445 } // namespace | 446 } // namespace |
| 446 } // namespace browser_sync | 447 } // namespace browser_sync |
| OLD | NEW |