| 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/fake_sync_notifier_observer.h" | 28 #include "sync/notifier/fake_invalidation_handler.h" |
| 29 #include "sync/notifier/object_id_state_map_test_util.h" | 29 #include "sync/notifier/object_id_state_map_test_util.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "webkit/glue/webkit_glue.h" | 32 #include "webkit/glue/webkit_glue.h" |
| 33 | 33 |
| 34 // TODO(akalin): Add tests here that exercise the whole | 34 // TODO(akalin): Add tests here that exercise the whole |
| 35 // ProfileSyncService/SyncBackendHost stack while mocking out as | 35 // ProfileSyncService/SyncBackendHost stack while mocking out as |
| 36 // little as possible. | 36 // little as possible. |
| 37 | 37 |
| 38 namespace browser_sync { | 38 namespace browser_sync { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 // expectations are not very interesting. | 364 // expectations are not very interesting. |
| 365 TEST_F(ProfileSyncServiceTest, FailToOpenDatabase) { | 365 TEST_F(ProfileSyncServiceTest, FailToOpenDatabase) { |
| 366 StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, | 366 StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, |
| 367 syncer::STORAGE_INVALID); | 367 syncer::STORAGE_INVALID); |
| 368 | 368 |
| 369 // The backend is not ready. Ensure the PSS knows this. | 369 // The backend is not ready. Ensure the PSS knows this. |
| 370 EXPECT_FALSE(service_->sync_initialized()); | 370 EXPECT_FALSE(service_->sync_initialized()); |
| 371 } | 371 } |
| 372 | 372 |
| 373 // Register for some IDs with the ProfileSyncService and trigger some | 373 // Register for some IDs with the ProfileSyncService and trigger some |
| 374 // invalidation messages. They should be received by the observer. | 374 // invalidation messages. They should be received by the handler. |
| 375 // Then unregister and trigger the invalidation messages again. Those | 375 // Then unregister and trigger the invalidation messages again. Those |
| 376 // shouldn't be received by the observer. | 376 // shouldn't be received by the handler. |
| 377 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { | 377 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { |
| 378 StartSyncService(); | 378 StartSyncService(); |
| 379 | 379 |
| 380 syncer::ObjectIdSet ids; | 380 syncer::ObjectIdSet ids; |
| 381 ids.insert(invalidation::ObjectId(1, "id1")); | 381 ids.insert(invalidation::ObjectId(1, "id1")); |
| 382 ids.insert(invalidation::ObjectId(2, "id2")); | 382 ids.insert(invalidation::ObjectId(2, "id2")); |
| 383 const syncer::ObjectIdStateMap& states = | 383 const syncer::ObjectIdStateMap& states = |
| 384 syncer::ObjectIdSetToStateMap(ids, "payload"); | 384 syncer::ObjectIdSetToStateMap(ids, "payload"); |
| 385 | 385 |
| 386 syncer::FakeSyncNotifierObserver observer; | 386 syncer::FakeInvalidationHandler handler; |
| 387 | 387 |
| 388 service_->RegisterInvalidationHandler(&observer); | 388 service_->RegisterInvalidationHandler(&handler); |
| 389 service_->UpdateRegisteredInvalidationIds(&observer, ids); | 389 service_->UpdateRegisteredInvalidationIds(&handler, ids); |
| 390 | 390 |
| 391 SyncBackendHostForProfileSyncTest* const backend = | 391 SyncBackendHostForProfileSyncTest* const backend = |
| 392 service_->GetBackendForTest(); | 392 service_->GetBackendForTest(); |
| 393 | 393 |
| 394 backend->EmitOnNotificationsEnabled(); | 394 backend->EmitOnNotificationsEnabled(); |
| 395 EXPECT_EQ(syncer::NO_NOTIFICATION_ERROR, | 395 EXPECT_EQ(syncer::NO_NOTIFICATION_ERROR, |
| 396 observer.GetNotificationsDisabledReason()); | 396 handler.GetNotificationsDisabledReason()); |
| 397 | 397 |
| 398 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); | 398 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); |
| 399 EXPECT_THAT(states, Eq(observer.GetLastNotificationIdStateMap())); | 399 EXPECT_THAT(states, Eq(handler.GetLastNotificationIdStateMap())); |
| 400 EXPECT_EQ(syncer::REMOTE_NOTIFICATION, observer.GetLastNotificationSource()); | 400 EXPECT_EQ(syncer::REMOTE_NOTIFICATION, handler.GetLastNotificationSource()); |
| 401 | 401 |
| 402 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); | 402 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); |
| 403 EXPECT_EQ(syncer::TRANSIENT_NOTIFICATION_ERROR, | 403 EXPECT_EQ(syncer::TRANSIENT_NOTIFICATION_ERROR, |
| 404 observer.GetNotificationsDisabledReason()); | 404 handler.GetNotificationsDisabledReason()); |
| 405 | 405 |
| 406 Mock::VerifyAndClearExpectations(&observer); | 406 Mock::VerifyAndClearExpectations(&handler); |
| 407 | 407 |
| 408 service_->UnregisterInvalidationHandler(&observer); | 408 service_->UnregisterInvalidationHandler(&handler); |
| 409 | 409 |
| 410 backend->EmitOnNotificationsEnabled(); | 410 backend->EmitOnNotificationsEnabled(); |
| 411 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); | 411 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); |
| 412 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); | 412 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // Register for some IDs with the ProfileSyncService, restart sync, | 415 // Register for some IDs with the ProfileSyncService, restart sync, |
| 416 // and trigger some invalidation messages. They should still be | 416 // and trigger some invalidation messages. They should still be |
| 417 // received by the observer. | 417 // received by the handler. |
| 418 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { | 418 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { |
| 419 StartSyncService(); | 419 StartSyncService(); |
| 420 | 420 |
| 421 syncer::ObjectIdSet ids; | 421 syncer::ObjectIdSet ids; |
| 422 ids.insert(invalidation::ObjectId(3, "id3")); | 422 ids.insert(invalidation::ObjectId(3, "id3")); |
| 423 const syncer::ObjectIdStateMap& states = | 423 const syncer::ObjectIdStateMap& states = |
| 424 syncer::ObjectIdSetToStateMap(ids, "payload"); | 424 syncer::ObjectIdSetToStateMap(ids, "payload"); |
| 425 | 425 |
| 426 syncer::FakeSyncNotifierObserver observer; | 426 syncer::FakeInvalidationHandler handler; |
| 427 | 427 |
| 428 service_->RegisterInvalidationHandler(&observer); | 428 service_->RegisterInvalidationHandler(&handler); |
| 429 service_->UpdateRegisteredInvalidationIds(&observer, ids); | 429 service_->UpdateRegisteredInvalidationIds(&handler, ids); |
| 430 | 430 |
| 431 service_->StopAndSuppress(); | 431 service_->StopAndSuppress(); |
| 432 service_->UnsuppressAndStart(); | 432 service_->UnsuppressAndStart(); |
| 433 | 433 |
| 434 SyncBackendHostForProfileSyncTest* const backend = | 434 SyncBackendHostForProfileSyncTest* const backend = |
| 435 service_->GetBackendForTest(); | 435 service_->GetBackendForTest(); |
| 436 | 436 |
| 437 backend->EmitOnNotificationsEnabled(); | 437 backend->EmitOnNotificationsEnabled(); |
| 438 EXPECT_EQ(syncer::NO_NOTIFICATION_ERROR, | 438 EXPECT_EQ(syncer::NO_NOTIFICATION_ERROR, |
| 439 observer.GetNotificationsDisabledReason()); | 439 handler.GetNotificationsDisabledReason()); |
| 440 | 440 |
| 441 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); | 441 backend->EmitOnIncomingNotification(states, syncer::REMOTE_NOTIFICATION); |
| 442 EXPECT_THAT(states, Eq(observer.GetLastNotificationIdStateMap())); | 442 EXPECT_THAT(states, Eq(handler.GetLastNotificationIdStateMap())); |
| 443 EXPECT_EQ(syncer::REMOTE_NOTIFICATION, observer.GetLastNotificationSource()); | 443 EXPECT_EQ(syncer::REMOTE_NOTIFICATION, handler.GetLastNotificationSource()); |
| 444 | 444 |
| 445 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); | 445 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); |
| 446 EXPECT_EQ(syncer::TRANSIENT_NOTIFICATION_ERROR, | 446 EXPECT_EQ(syncer::TRANSIENT_NOTIFICATION_ERROR, |
| 447 observer.GetNotificationsDisabledReason()); | 447 handler.GetNotificationsDisabledReason()); |
| 448 } | 448 } |
| 449 | 449 |
| 450 } // namespace | 450 } // namespace |
| 451 } // namespace browser_sync | 451 } // namespace browser_sync |
| OLD | NEW |