| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
| 6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
| 7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
| 8 | 8 |
| 9 #include "components/sync/core_impl/sync_manager_impl.h" | 9 #include "components/sync/core_impl/sync_manager_impl.h" |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "components/sync/core/test/test_entry_factory.h" | 42 #include "components/sync/core/test/test_entry_factory.h" |
| 43 #include "components/sync/core/test/test_internal_components_factory.h" | 43 #include "components/sync/core/test/test_internal_components_factory.h" |
| 44 #include "components/sync/core/test/test_user_share.h" | 44 #include "components/sync/core/test/test_user_share.h" |
| 45 #include "components/sync/core/write_node.h" | 45 #include "components/sync/core/write_node.h" |
| 46 #include "components/sync/core/write_transaction.h" | 46 #include "components/sync/core/write_transaction.h" |
| 47 #include "components/sync/core_impl/sync_encryption_handler_impl.h" | 47 #include "components/sync/core_impl/sync_encryption_handler_impl.h" |
| 48 #include "components/sync/core_impl/syncapi_internal.h" | 48 #include "components/sync/core_impl/syncapi_internal.h" |
| 49 #include "components/sync/engine/events/protocol_event.h" | 49 #include "components/sync/engine/events/protocol_event.h" |
| 50 #include "components/sync/engine/model_safe_worker.h" | 50 #include "components/sync/engine/model_safe_worker.h" |
| 51 #include "components/sync/engine/polling_constants.h" | 51 #include "components/sync/engine/polling_constants.h" |
| 52 #include "components/sync/engine_impl/cycle/sync_cycle.h" |
| 52 #include "components/sync/engine_impl/sync_scheduler.h" | 53 #include "components/sync/engine_impl/sync_scheduler.h" |
| 53 #include "components/sync/js/js_backend.h" | 54 #include "components/sync/js/js_backend.h" |
| 54 #include "components/sync/js/js_event_handler.h" | 55 #include "components/sync/js/js_event_handler.h" |
| 55 #include "components/sync/js/js_test_util.h" | 56 #include "components/sync/js/js_test_util.h" |
| 56 #include "components/sync/protocol/bookmark_specifics.pb.h" | 57 #include "components/sync/protocol/bookmark_specifics.pb.h" |
| 57 #include "components/sync/protocol/encryption.pb.h" | 58 #include "components/sync/protocol/encryption.pb.h" |
| 58 #include "components/sync/protocol/extension_specifics.pb.h" | 59 #include "components/sync/protocol/extension_specifics.pb.h" |
| 59 #include "components/sync/protocol/password_specifics.pb.h" | 60 #include "components/sync/protocol/password_specifics.pb.h" |
| 60 #include "components/sync/protocol/preference_specifics.pb.h" | 61 #include "components/sync/protocol/preference_specifics.pb.h" |
| 61 #include "components/sync/protocol/proto_value_conversions.h" | 62 #include "components/sync/protocol/proto_value_conversions.h" |
| 62 #include "components/sync/protocol/sync.pb.h" | 63 #include "components/sync/protocol/sync.pb.h" |
| 63 #include "components/sync/sessions_impl/sync_session.h" | |
| 64 #include "components/sync/syncable/directory.h" | 64 #include "components/sync/syncable/directory.h" |
| 65 #include "components/sync/syncable/entry.h" | 65 #include "components/sync/syncable/entry.h" |
| 66 #include "components/sync/syncable/mutable_entry.h" | 66 #include "components/sync/syncable/mutable_entry.h" |
| 67 #include "components/sync/syncable/nigori_util.h" | 67 #include "components/sync/syncable/nigori_util.h" |
| 68 #include "components/sync/syncable/syncable_id.h" | 68 #include "components/sync/syncable/syncable_id.h" |
| 69 #include "components/sync/syncable/syncable_read_transaction.h" | 69 #include "components/sync/syncable/syncable_read_transaction.h" |
| 70 #include "components/sync/syncable/syncable_util.h" | 70 #include "components/sync/syncable/syncable_util.h" |
| 71 #include "components/sync/syncable/syncable_write_transaction.h" | 71 #include "components/sync/syncable/syncable_write_transaction.h" |
| 72 #include "components/sync/test/callback_counter.h" | 72 #include "components/sync/test/callback_counter.h" |
| 73 #include "components/sync/test/engine/fake_model_worker.h" | 73 #include "components/sync/test/engine/fake_model_worker.h" |
| 74 #include "components/sync/test/engine/fake_sync_scheduler.h" | 74 #include "components/sync/test/engine/fake_sync_scheduler.h" |
| 75 #include "components/sync/test/engine/test_id_factory.h" | 75 #include "components/sync/test/engine/test_id_factory.h" |
| 76 #include "google_apis/gaia/gaia_constants.h" | 76 #include "google_apis/gaia/gaia_constants.h" |
| 77 #include "testing/gmock/include/gmock/gmock.h" | 77 #include "testing/gmock/include/gmock/gmock.h" |
| 78 #include "testing/gtest/include/gtest/gtest.h" | 78 #include "testing/gtest/include/gtest/gtest.h" |
| 79 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | 79 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" |
| 80 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" | 80 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" |
| 81 #include "url/gurl.h" | 81 #include "url/gurl.h" |
| 82 | 82 |
| 83 using base::ExpectDictStringValue; | 83 using base::ExpectDictStringValue; |
| 84 using testing::_; | 84 using testing::_; |
| 85 using testing::DoAll; | 85 using testing::DoAll; |
| 86 using testing::InSequence; | 86 using testing::InSequence; |
| 87 using testing::Return; | 87 using testing::Return; |
| 88 using testing::SaveArg; | 88 using testing::SaveArg; |
| 89 using testing::StrictMock; | 89 using testing::StrictMock; |
| 90 | 90 |
| 91 namespace syncer { | 91 namespace syncer { |
| 92 | 92 |
| 93 using sessions::SyncSessionSnapshot; | |
| 94 using syncable::GET_BY_HANDLE; | 93 using syncable::GET_BY_HANDLE; |
| 95 using syncable::IS_DEL; | 94 using syncable::IS_DEL; |
| 96 using syncable::IS_UNSYNCED; | 95 using syncable::IS_UNSYNCED; |
| 97 using syncable::NON_UNIQUE_NAME; | 96 using syncable::NON_UNIQUE_NAME; |
| 98 using syncable::SPECIFICS; | 97 using syncable::SPECIFICS; |
| 99 using syncable::kEncryptedString; | 98 using syncable::kEncryptedString; |
| 100 | 99 |
| 101 namespace { | 100 namespace { |
| 102 | 101 |
| 103 // Makes a child node under the type root folder. Returns the id of the | 102 // Makes a child node under the type root folder. Returns the id of the |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 HttpPostProviderInterface* Create() override { | 886 HttpPostProviderInterface* Create() override { |
| 888 return new TestHttpPostProviderInterface(); | 887 return new TestHttpPostProviderInterface(); |
| 889 } | 888 } |
| 890 void Destroy(HttpPostProviderInterface* http) override { | 889 void Destroy(HttpPostProviderInterface* http) override { |
| 891 delete static_cast<TestHttpPostProviderInterface*>(http); | 890 delete static_cast<TestHttpPostProviderInterface*>(http); |
| 892 } | 891 } |
| 893 }; | 892 }; |
| 894 | 893 |
| 895 class SyncManagerObserverMock : public SyncManager::Observer { | 894 class SyncManagerObserverMock : public SyncManager::Observer { |
| 896 public: | 895 public: |
| 897 MOCK_METHOD1(OnSyncCycleCompleted, | 896 MOCK_METHOD1(OnSyncCycleCompleted, void(const SyncCycleSnapshot&)); // NOLINT |
| 898 void(const SyncSessionSnapshot&)); // NOLINT | |
| 899 MOCK_METHOD4(OnInitializationComplete, | 897 MOCK_METHOD4(OnInitializationComplete, |
| 900 void(const WeakHandle<JsBackend>&, | 898 void(const WeakHandle<JsBackend>&, |
| 901 const WeakHandle<DataTypeDebugInfoListener>&, | 899 const WeakHandle<DataTypeDebugInfoListener>&, |
| 902 bool, | 900 bool, |
| 903 syncer::ModelTypeSet)); // NOLINT | 901 syncer::ModelTypeSet)); // NOLINT |
| 904 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT | 902 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT |
| 905 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT | 903 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT |
| 906 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); // NOLINT | 904 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); // NOLINT |
| 907 MOCK_METHOD1(OnMigrationRequested, void(syncer::ModelTypeSet)); // NOLINT | 905 MOCK_METHOD1(OnMigrationRequested, void(syncer::ModelTypeSet)); // NOLINT |
| 908 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); // NOLINT | 906 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); // NOLINT |
| (...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2529 virtual ~MockSyncScheduler() {} | 2527 virtual ~MockSyncScheduler() {} |
| 2530 | 2528 |
| 2531 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); | 2529 MOCK_METHOD2(Start, void(SyncScheduler::Mode, base::Time)); |
| 2532 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); | 2530 MOCK_METHOD1(ScheduleConfiguration, void(const ConfigurationParams&)); |
| 2533 }; | 2531 }; |
| 2534 | 2532 |
| 2535 class ComponentsFactory : public TestInternalComponentsFactory { | 2533 class ComponentsFactory : public TestInternalComponentsFactory { |
| 2536 public: | 2534 public: |
| 2537 ComponentsFactory(const Switches& switches, | 2535 ComponentsFactory(const Switches& switches, |
| 2538 SyncScheduler* scheduler_to_use, | 2536 SyncScheduler* scheduler_to_use, |
| 2539 sessions::SyncSessionContext** session_context, | 2537 SyncCycleContext** cycle_context, |
| 2540 InternalComponentsFactory::StorageOption* storage_used) | 2538 InternalComponentsFactory::StorageOption* storage_used) |
| 2541 : TestInternalComponentsFactory( | 2539 : TestInternalComponentsFactory( |
| 2542 switches, | 2540 switches, |
| 2543 InternalComponentsFactory::STORAGE_IN_MEMORY, | 2541 InternalComponentsFactory::STORAGE_IN_MEMORY, |
| 2544 storage_used), | 2542 storage_used), |
| 2545 scheduler_to_use_(scheduler_to_use), | 2543 scheduler_to_use_(scheduler_to_use), |
| 2546 session_context_(session_context) {} | 2544 cycle_context_(cycle_context) {} |
| 2547 ~ComponentsFactory() override {} | 2545 ~ComponentsFactory() override {} |
| 2548 | 2546 |
| 2549 std::unique_ptr<SyncScheduler> BuildScheduler( | 2547 std::unique_ptr<SyncScheduler> BuildScheduler( |
| 2550 const std::string& name, | 2548 const std::string& name, |
| 2551 sessions::SyncSessionContext* context, | 2549 SyncCycleContext* context, |
| 2552 CancelationSignal* stop_handle) override { | 2550 CancelationSignal* stop_handle) override { |
| 2553 *session_context_ = context; | 2551 *cycle_context_ = context; |
| 2554 return std::move(scheduler_to_use_); | 2552 return std::move(scheduler_to_use_); |
| 2555 } | 2553 } |
| 2556 | 2554 |
| 2557 private: | 2555 private: |
| 2558 std::unique_ptr<SyncScheduler> scheduler_to_use_; | 2556 std::unique_ptr<SyncScheduler> scheduler_to_use_; |
| 2559 sessions::SyncSessionContext** session_context_; | 2557 SyncCycleContext** cycle_context_; |
| 2560 }; | 2558 }; |
| 2561 | 2559 |
| 2562 class SyncManagerTestWithMockScheduler : public SyncManagerTest { | 2560 class SyncManagerTestWithMockScheduler : public SyncManagerTest { |
| 2563 public: | 2561 public: |
| 2564 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} | 2562 SyncManagerTestWithMockScheduler() : scheduler_(NULL) {} |
| 2565 InternalComponentsFactory* GetFactory() override { | 2563 InternalComponentsFactory* GetFactory() override { |
| 2566 scheduler_ = new MockSyncScheduler(); | 2564 scheduler_ = new MockSyncScheduler(); |
| 2567 return new ComponentsFactory(GetSwitches(), scheduler_, &session_context_, | 2565 return new ComponentsFactory(GetSwitches(), scheduler_, &cycle_context_, |
| 2568 &storage_used_); | 2566 &storage_used_); |
| 2569 } | 2567 } |
| 2570 | 2568 |
| 2571 MockSyncScheduler* scheduler() { return scheduler_; } | 2569 MockSyncScheduler* scheduler() { return scheduler_; } |
| 2572 sessions::SyncSessionContext* session_context() { return session_context_; } | 2570 SyncCycleContext* cycle_context() { return cycle_context_; } |
| 2573 | 2571 |
| 2574 private: | 2572 private: |
| 2575 MockSyncScheduler* scheduler_; | 2573 MockSyncScheduler* scheduler_; |
| 2576 sessions::SyncSessionContext* session_context_; | 2574 SyncCycleContext* cycle_context_; |
| 2577 }; | 2575 }; |
| 2578 | 2576 |
| 2579 // Test that the configuration params are properly created and sent to | 2577 // Test that the configuration params are properly created and sent to |
| 2580 // ScheduleConfigure. No callback should be invoked. Any disabled datatypes | 2578 // ScheduleConfigure. No callback should be invoked. Any disabled datatypes |
| 2581 // should be purged. | 2579 // should be purged. |
| 2582 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { | 2580 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { |
| 2583 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; | 2581 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; |
| 2584 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); | 2582 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); |
| 2585 ModelSafeRoutingInfo new_routing_info; | 2583 ModelSafeRoutingInfo new_routing_info; |
| 2586 GetModelSafeRoutingInfo(&new_routing_info); | 2584 GetModelSafeRoutingInfo(&new_routing_info); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2644 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | 2642 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); |
| 2645 iter.Inc()) { | 2643 iter.Inc()) { |
| 2646 if (!disabled_types.Has(iter.Get())) { | 2644 if (!disabled_types.Has(iter.Get())) { |
| 2647 SetProgressMarkerForType(iter.Get(), true); | 2645 SetProgressMarkerForType(iter.Get(), true); |
| 2648 } else { | 2646 } else { |
| 2649 SetProgressMarkerForType(iter.Get(), false); | 2647 SetProgressMarkerForType(iter.Get(), false); |
| 2650 } | 2648 } |
| 2651 } | 2649 } |
| 2652 | 2650 |
| 2653 // Set the context to have the old routing info. | 2651 // Set the context to have the old routing info. |
| 2654 session_context()->SetRoutingInfo(old_routing_info); | 2652 cycle_context()->SetRoutingInfo(old_routing_info); |
| 2655 | 2653 |
| 2656 CallbackCounter ready_task_counter, retry_task_counter; | 2654 CallbackCounter ready_task_counter, retry_task_counter; |
| 2657 sync_manager_.ConfigureSyncer( | 2655 sync_manager_.ConfigureSyncer( |
| 2658 reason, types_to_download, ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), | 2656 reason, types_to_download, ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), |
| 2659 new_routing_info, base::Bind(&CallbackCounter::Callback, | 2657 new_routing_info, base::Bind(&CallbackCounter::Callback, |
| 2660 base::Unretained(&ready_task_counter)), | 2658 base::Unretained(&ready_task_counter)), |
| 2661 base::Bind(&CallbackCounter::Callback, | 2659 base::Bind(&CallbackCounter::Callback, |
| 2662 base::Unretained(&retry_task_counter))); | 2660 base::Unretained(&retry_task_counter))); |
| 2663 EXPECT_EQ(0, ready_task_counter.times_called()); | 2661 EXPECT_EQ(0, ready_task_counter.times_called()); |
| 2664 EXPECT_EQ(0, retry_task_counter.times_called()); | 2662 EXPECT_EQ(0, retry_task_counter.times_called()); |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3342 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3340 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3343 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3341 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3344 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3342 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3345 // task is to ensure that SyncManagerImpl reported initialization failure in | 3343 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3346 // OnInitializationComplete callback. | 3344 // OnInitializationComplete callback. |
| 3347 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3345 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3348 EXPECT_FALSE(initialization_succeeded_); | 3346 EXPECT_FALSE(initialization_succeeded_); |
| 3349 } | 3347 } |
| 3350 | 3348 |
| 3351 } // namespace syncer | 3349 } // namespace syncer |
| OLD | NEW |