| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/sync/driver/glue/sync_backend_host_impl.h" | 5 #include "components/sync/driver/glue/sync_backend_host_impl.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
| 18 #include "base/threading/thread.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "components/invalidation/impl/invalidator_storage.h" | 21 #include "components/invalidation/impl/invalidator_storage.h" |
| 21 #include "components/invalidation/impl/profile_invalidation_provider.h" | 22 #include "components/invalidation/impl/profile_invalidation_provider.h" |
| 22 #include "components/invalidation/public/invalidator_state.h" | 23 #include "components/invalidation/public/invalidator_state.h" |
| 23 #include "components/invalidation/public/object_id_invalidation_map.h" | 24 #include "components/invalidation/public/object_id_invalidation_map.h" |
| 24 #include "components/sync/base/experiments.h" | 25 #include "components/sync/base/experiments.h" |
| 25 #include "components/sync/base/sync_prefs.h" | 26 #include "components/sync/base/sync_prefs.h" |
| 26 #include "components/sync/base/test_unrecoverable_error_handler.h" | 27 #include "components/sync/base/test_unrecoverable_error_handler.h" |
| 27 #include "components/sync/device_info/device_info.h" | 28 #include "components/sync/device_info/device_info.h" |
| 28 #include "components/sync/driver/fake_sync_client.h" | 29 #include "components/sync/driver/fake_sync_client.h" |
| 29 #include "components/sync/driver/sync_frontend.h" | |
| 30 #include "components/sync/engine/cycle/commit_counters.h" | 30 #include "components/sync/engine/cycle/commit_counters.h" |
| 31 #include "components/sync/engine/cycle/status_counters.h" | 31 #include "components/sync/engine/cycle/status_counters.h" |
| 32 #include "components/sync/engine/cycle/update_counters.h" | 32 #include "components/sync/engine/cycle/update_counters.h" |
| 33 #include "components/sync/engine/fake_sync_manager.h" | 33 #include "components/sync/engine/fake_sync_manager.h" |
| 34 #include "components/sync/engine/model_safe_worker.h" | 34 #include "components/sync/engine/model_safe_worker.h" |
| 35 #include "components/sync/engine/net/http_bridge_network_resources.h" | 35 #include "components/sync/engine/net/http_bridge_network_resources.h" |
| 36 #include "components/sync/engine/net/network_resources.h" | 36 #include "components/sync/engine/net/network_resources.h" |
| 37 #include "components/sync/engine/passive_model_worker.h" | 37 #include "components/sync/engine/passive_model_worker.h" |
| 38 #include "components/sync/engine/sync_engine_host.h" |
| 38 #include "components/sync/engine/sync_manager_factory.h" | 39 #include "components/sync/engine/sync_manager_factory.h" |
| 39 #include "components/sync/test/callback_counter.h" | 40 #include "components/sync/test/callback_counter.h" |
| 40 #include "components/sync_preferences/pref_service_syncable.h" | 41 #include "components/sync_preferences/pref_service_syncable.h" |
| 41 #include "components/sync_preferences/testing_pref_service_syncable.h" | 42 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 42 #include "google/cacheinvalidation/include/types.h" | 43 #include "google/cacheinvalidation/include/types.h" |
| 43 #include "google_apis/gaia/gaia_constants.h" | 44 #include "google_apis/gaia/gaia_constants.h" |
| 44 #include "net/url_request/test_url_fetcher_factory.h" | 45 #include "net/url_request/test_url_fetcher_factory.h" |
| 45 #include "net/url_request/url_request_context_getter.h" | 46 #include "net/url_request/url_request_context_getter.h" |
| 46 #include "testing/gmock/include/gmock/gmock.h" | 47 #include "testing/gmock/include/gmock/gmock.h" |
| 47 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 63 } | 64 } |
| 64 | 65 |
| 65 void EmptyNetworkTimeUpdate(const base::Time&, | 66 void EmptyNetworkTimeUpdate(const base::Time&, |
| 66 const base::TimeDelta&, | 67 const base::TimeDelta&, |
| 67 const base::TimeDelta&) {} | 68 const base::TimeDelta&) {} |
| 68 | 69 |
| 69 void QuitMessageLoop() { | 70 void QuitMessageLoop() { |
| 70 base::MessageLoop::current()->QuitWhenIdle(); | 71 base::MessageLoop::current()->QuitWhenIdle(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 class MockSyncFrontend : public SyncFrontend { | 74 class MockSyncEngineHost : public SyncEngineHost { |
| 74 public: | 75 public: |
| 75 virtual ~MockSyncFrontend() {} | 76 virtual ~MockSyncEngineHost() {} |
| 76 | 77 |
| 77 MOCK_METHOD4(OnBackendInitialized, | 78 MOCK_METHOD4(OnBackendInitialized, |
| 78 void(const WeakHandle<JsBackend>&, | 79 void(const WeakHandle<JsBackend>&, |
| 79 const WeakHandle<DataTypeDebugInfoListener>&, | 80 const WeakHandle<DataTypeDebugInfoListener>&, |
| 80 const std::string&, | 81 const std::string&, |
| 81 bool)); | 82 bool)); |
| 82 MOCK_METHOD0(OnSyncCycleCompleted, void()); | 83 MOCK_METHOD0(OnSyncCycleCompleted, void()); |
| 83 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus status)); | 84 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus status)); |
| 84 MOCK_METHOD0(OnClearServerDataSucceeded, void()); | 85 MOCK_METHOD0(OnClearServerDataSucceeded, void()); |
| 85 MOCK_METHOD0(OnClearServerDataFailed, void()); | 86 MOCK_METHOD0(OnClearServerDataFailed, void()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 ModelSafeGroup group) override { | 146 ModelSafeGroup group) override { |
| 146 switch (group) { | 147 switch (group) { |
| 147 case GROUP_PASSIVE: | 148 case GROUP_PASSIVE: |
| 148 return new PassiveModelWorker(); | 149 return new PassiveModelWorker(); |
| 149 default: | 150 default: |
| 150 return nullptr; | 151 return nullptr; |
| 151 } | 152 } |
| 152 } | 153 } |
| 153 }; | 154 }; |
| 154 | 155 |
| 155 class SyncBackendHostTest : public testing::Test { | 156 class SyncEngineTest : public testing::Test { |
| 156 protected: | 157 protected: |
| 157 SyncBackendHostTest() | 158 SyncEngineTest() |
| 158 : sync_thread_("SyncThreadForTest"), fake_manager_(nullptr) {} | 159 : sync_thread_("SyncThreadForTest"), fake_manager_(nullptr) {} |
| 159 | 160 |
| 160 ~SyncBackendHostTest() override {} | 161 ~SyncEngineTest() override {} |
| 161 | 162 |
| 162 void SetUp() override { | 163 void SetUp() override { |
| 163 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 164 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 164 | 165 |
| 165 SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); | 166 SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); |
| 166 | 167 |
| 167 sync_prefs_ = base::MakeUnique<SyncPrefs>(&pref_service_); | 168 sync_prefs_ = base::MakeUnique<SyncPrefs>(&pref_service_); |
| 168 sync_thread_.StartAndWaitForTesting(); | 169 sync_thread_.StartAndWaitForTesting(); |
| 169 backend_ = base::MakeUnique<SyncBackendHostImpl>( | 170 backend_ = base::MakeUnique<SyncBackendHostImpl>( |
| 170 "dummyDebugName", &sync_client_, nullptr, sync_prefs_->AsWeakPtr(), | 171 "dummyDebugName", &sync_client_, nullptr, sync_prefs_->AsWeakPtr(), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 197 backend_->Shutdown(STOP_SYNC); | 198 backend_->Shutdown(STOP_SYNC); |
| 198 } | 199 } |
| 199 backend_.reset(); | 200 backend_.reset(); |
| 200 sync_prefs_.reset(); | 201 sync_prefs_.reset(); |
| 201 // Pump messages posted by the sync thread. | 202 // Pump messages posted by the sync thread. |
| 202 base::RunLoop().RunUntilIdle(); | 203 base::RunLoop().RunUntilIdle(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 // Synchronously initializes the backend. | 206 // Synchronously initializes the backend. |
| 206 void InitializeBackend(bool expect_success) { | 207 void InitializeBackend(bool expect_success) { |
| 207 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success)) | 208 EXPECT_CALL(mock_host_, OnBackendInitialized(_, _, _, expect_success)) |
| 208 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 209 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 209 SyncBackendHost::HttpPostProviderFactoryGetter | 210 SyncEngine::HttpPostProviderFactoryGetter |
| 210 http_post_provider_factory_getter = | 211 http_post_provider_factory_getter = |
| 211 base::Bind(&NetworkResources::GetHttpPostProviderFactory, | 212 base::Bind(&NetworkResources::GetHttpPostProviderFactory, |
| 212 base::Unretained(network_resources_.get()), nullptr, | 213 base::Unretained(network_resources_.get()), nullptr, |
| 213 base::Bind(&EmptyNetworkTimeUpdate)); | 214 base::Bind(&EmptyNetworkTimeUpdate)); |
| 214 backend_->Initialize( | 215 backend_->Initialize( |
| 215 &mock_frontend_, sync_thread_.task_runner(), | 216 &mock_host_, sync_thread_.task_runner(), WeakHandle<JsEventHandler>(), |
| 216 WeakHandle<JsEventHandler>(), GURL(std::string()), std::string(), | 217 GURL(std::string()), std::string(), credentials_, true, false, |
| 217 credentials_, true, false, base::FilePath(), | 218 base::FilePath(), std::move(fake_manager_factory_), |
| 218 std::move(fake_manager_factory_), | |
| 219 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()), | 219 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()), |
| 220 base::Closure(), http_post_provider_factory_getter, | 220 base::Closure(), http_post_provider_factory_getter, |
| 221 std::move(saved_nigori_state_)); | 221 std::move(saved_nigori_state_)); |
| 222 base::RunLoop run_loop; | 222 base::RunLoop run_loop; |
| 223 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 223 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 224 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout()); | 224 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout()); |
| 225 run_loop.Run(); | 225 run_loop.Run(); |
| 226 // |fake_manager_factory_|'s fake_manager() is set on the sync | 226 // |fake_manager_factory_|'s fake_manager() is set on the sync |
| 227 // thread, but we can rely on the message loop barriers to | 227 // thread, but we can rely on the message loop barriers to |
| 228 // guarantee that we see the updated value. | 228 // guarantee that we see the updated value. |
| 229 DCHECK(fake_manager_); | 229 DCHECK(fake_manager_); |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Synchronously configures the backend's datatypes. | 232 // Synchronously configures the backend's datatypes. |
| 233 ModelTypeSet ConfigureDataTypes(ModelTypeSet types_to_add, | 233 ModelTypeSet ConfigureDataTypes(ModelTypeSet types_to_add, |
| 234 ModelTypeSet types_to_remove, | 234 ModelTypeSet types_to_remove, |
| 235 ModelTypeSet types_to_unapply) { | 235 ModelTypeSet types_to_unapply) { |
| 236 BackendDataTypeConfigurer::DataTypeConfigStateMap config_state_map; | 236 ModelTypeConfigurer::DataTypeConfigStateMap config_state_map; |
| 237 BackendDataTypeConfigurer::SetDataTypesState( | 237 ModelTypeConfigurer::SetDataTypesState( |
| 238 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, types_to_add, | 238 ModelTypeConfigurer::CONFIGURE_ACTIVE, types_to_add, &config_state_map); |
| 239 &config_state_map); | 239 ModelTypeConfigurer::SetDataTypesState(ModelTypeConfigurer::DISABLED, |
| 240 BackendDataTypeConfigurer::SetDataTypesState( | 240 types_to_remove, &config_state_map); |
| 241 BackendDataTypeConfigurer::DISABLED, types_to_remove, | 241 ModelTypeConfigurer::SetDataTypesState(ModelTypeConfigurer::UNREADY, |
| 242 &config_state_map); | 242 types_to_unapply, &config_state_map); |
| 243 BackendDataTypeConfigurer::SetDataTypesState( | |
| 244 BackendDataTypeConfigurer::UNREADY, types_to_unapply, | |
| 245 &config_state_map); | |
| 246 | 243 |
| 247 types_to_add.PutAll(ControlTypes()); | 244 types_to_add.PutAll(ControlTypes()); |
| 248 ModelTypeSet ready_types = backend_->ConfigureDataTypes( | 245 ModelTypeSet ready_types = backend_->ConfigureDataTypes( |
| 249 CONFIGURE_REASON_RECONFIGURATION, config_state_map, | 246 CONFIGURE_REASON_RECONFIGURATION, config_state_map, |
| 250 base::Bind(&SyncBackendHostTest::DownloadReady, base::Unretained(this)), | 247 base::Bind(&SyncEngineTest::DownloadReady, base::Unretained(this)), |
| 251 base::Bind(&SyncBackendHostTest::OnDownloadRetry, | 248 base::Bind(&SyncEngineTest::OnDownloadRetry, base::Unretained(this))); |
| 252 base::Unretained(this))); | |
| 253 base::RunLoop run_loop; | 249 base::RunLoop run_loop; |
| 254 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 250 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 255 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout()); | 251 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout()); |
| 256 run_loop.Run(); | 252 run_loop.Run(); |
| 257 return ready_types; | 253 return ready_types; |
| 258 } | 254 } |
| 259 | 255 |
| 260 protected: | 256 protected: |
| 261 void DownloadReady(ModelTypeSet succeeded_types, ModelTypeSet failed_types) { | 257 void DownloadReady(ModelTypeSet succeeded_types, ModelTypeSet failed_types) { |
| 262 base::MessageLoop::current()->QuitWhenIdle(); | 258 base::MessageLoop::current()->QuitWhenIdle(); |
| 263 } | 259 } |
| 264 | 260 |
| 265 void OnDownloadRetry() { NOTIMPLEMENTED(); } | 261 void OnDownloadRetry() { NOTIMPLEMENTED(); } |
| 266 | 262 |
| 267 base::MessageLoop message_loop_; | 263 base::MessageLoop message_loop_; |
| 268 base::ScopedTempDir temp_dir_; | 264 base::ScopedTempDir temp_dir_; |
| 269 sync_preferences::TestingPrefServiceSyncable pref_service_; | 265 sync_preferences::TestingPrefServiceSyncable pref_service_; |
| 270 base::Thread sync_thread_; | 266 base::Thread sync_thread_; |
| 271 StrictMock<MockSyncFrontend> mock_frontend_; | 267 StrictMock<MockSyncEngineHost> mock_host_; |
| 272 SyncCredentials credentials_; | 268 SyncCredentials credentials_; |
| 273 BackendSyncClient sync_client_; | 269 BackendSyncClient sync_client_; |
| 274 TestUnrecoverableErrorHandler test_unrecoverable_error_handler_; | 270 TestUnrecoverableErrorHandler test_unrecoverable_error_handler_; |
| 275 std::unique_ptr<SyncPrefs> sync_prefs_; | 271 std::unique_ptr<SyncPrefs> sync_prefs_; |
| 276 std::unique_ptr<SyncBackendHostImpl> backend_; | 272 std::unique_ptr<SyncBackendHostImpl> backend_; |
| 277 std::unique_ptr<FakeSyncManagerFactory> fake_manager_factory_; | 273 std::unique_ptr<FakeSyncManagerFactory> fake_manager_factory_; |
| 278 FakeSyncManager* fake_manager_; | 274 FakeSyncManager* fake_manager_; |
| 279 ModelTypeSet enabled_types_; | 275 ModelTypeSet enabled_types_; |
| 280 std::unique_ptr<NetworkResources> network_resources_; | 276 std::unique_ptr<NetworkResources> network_resources_; |
| 281 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state_; | 277 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state_; |
| 282 }; | 278 }; |
| 283 | 279 |
| 284 // Test basic initialization with no initial types (first time initialization). | 280 // Test basic initialization with no initial types (first time initialization). |
| 285 // Only the nigori should be configured. | 281 // Only the nigori should be configured. |
| 286 TEST_F(SyncBackendHostTest, InitShutdown) { | 282 TEST_F(SyncEngineTest, InitShutdown) { |
| 287 InitializeBackend(true); | 283 InitializeBackend(true); |
| 288 EXPECT_EQ(ControlTypes(), fake_manager_->GetAndResetDownloadedTypes()); | 284 EXPECT_EQ(ControlTypes(), fake_manager_->GetAndResetDownloadedTypes()); |
| 289 EXPECT_EQ(ControlTypes(), fake_manager_->InitialSyncEndedTypes()); | 285 EXPECT_EQ(ControlTypes(), fake_manager_->InitialSyncEndedTypes()); |
| 290 EXPECT_TRUE( | 286 EXPECT_TRUE( |
| 291 fake_manager_->GetTypesWithEmptyProgressMarkerToken(ControlTypes()) | 287 fake_manager_->GetTypesWithEmptyProgressMarkerToken(ControlTypes()) |
| 292 .Empty()); | 288 .Empty()); |
| 293 } | 289 } |
| 294 | 290 |
| 295 // Test first time sync scenario. All types should be properly configured. | 291 // Test first time sync scenario. All types should be properly configured. |
| 296 | 292 |
| 297 TEST_F(SyncBackendHostTest, FirstTimeSync) { | 293 TEST_F(SyncEngineTest, FirstTimeSync) { |
| 298 InitializeBackend(true); | 294 InitializeBackend(true); |
| 299 EXPECT_EQ(ControlTypes(), fake_manager_->GetAndResetDownloadedTypes()); | 295 EXPECT_EQ(ControlTypes(), fake_manager_->GetAndResetDownloadedTypes()); |
| 300 EXPECT_EQ(ControlTypes(), fake_manager_->InitialSyncEndedTypes()); | 296 EXPECT_EQ(ControlTypes(), fake_manager_->InitialSyncEndedTypes()); |
| 301 EXPECT_TRUE( | 297 EXPECT_TRUE( |
| 302 fake_manager_->GetTypesWithEmptyProgressMarkerToken(ControlTypes()) | 298 fake_manager_->GetTypesWithEmptyProgressMarkerToken(ControlTypes()) |
| 303 .Empty()); | 299 .Empty()); |
| 304 | 300 |
| 305 ModelTypeSet ready_types = ConfigureDataTypes( | 301 ModelTypeSet ready_types = ConfigureDataTypes( |
| 306 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), | 302 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), |
| 307 ModelTypeSet()); | 303 ModelTypeSet()); |
| 308 // Nigori is always downloaded so won't be ready. | 304 // Nigori is always downloaded so won't be ready. |
| 309 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); | 305 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); |
| 310 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( | 306 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( |
| 311 Difference(enabled_types_, ControlTypes()))); | 307 Difference(enabled_types_, ControlTypes()))); |
| 312 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 308 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 313 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 309 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 314 EXPECT_TRUE( | 310 EXPECT_TRUE( |
| 315 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 311 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 316 .Empty()); | 312 .Empty()); |
| 317 } | 313 } |
| 318 | 314 |
| 319 // Test the restart after setting up sync scenario. No enabled types should be | 315 // Test the restart after setting up sync scenario. No enabled types should be |
| 320 // downloaded or cleaned. | 316 // downloaded or cleaned. |
| 321 TEST_F(SyncBackendHostTest, Restart) { | 317 TEST_F(SyncEngineTest, Restart) { |
| 322 sync_prefs_->SetFirstSetupComplete(); | 318 sync_prefs_->SetFirstSetupComplete(); |
| 323 ModelTypeSet all_but_nigori = enabled_types_; | 319 ModelTypeSet all_but_nigori = enabled_types_; |
| 324 fake_manager_factory_->set_progress_marker_types(enabled_types_); | 320 fake_manager_factory_->set_progress_marker_types(enabled_types_); |
| 325 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); | 321 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); |
| 326 InitializeBackend(true); | 322 InitializeBackend(true); |
| 327 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); | 323 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); |
| 328 EXPECT_TRUE( | 324 EXPECT_TRUE( |
| 329 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) | 325 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) |
| 330 .Empty()); | 326 .Empty()); |
| 331 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 327 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 343 .Empty()); | 339 .Empty()); |
| 344 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 340 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 345 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 341 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 346 EXPECT_TRUE( | 342 EXPECT_TRUE( |
| 347 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 343 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 348 .Empty()); | 344 .Empty()); |
| 349 } | 345 } |
| 350 | 346 |
| 351 // Test a sync restart scenario where some types had never finished configuring. | 347 // Test a sync restart scenario where some types had never finished configuring. |
| 352 // The partial types should be purged, then reconfigured properly. | 348 // The partial types should be purged, then reconfigured properly. |
| 353 TEST_F(SyncBackendHostTest, PartialTypes) { | 349 TEST_F(SyncEngineTest, PartialTypes) { |
| 354 sync_prefs_->SetFirstSetupComplete(); | 350 sync_prefs_->SetFirstSetupComplete(); |
| 355 // Set sync manager behavior before passing it down. All types have progress | 351 // Set sync manager behavior before passing it down. All types have progress |
| 356 // markers, but nigori and bookmarks are missing initial sync ended. | 352 // markers, but nigori and bookmarks are missing initial sync ended. |
| 357 ModelTypeSet partial_types(NIGORI, BOOKMARKS); | 353 ModelTypeSet partial_types(NIGORI, BOOKMARKS); |
| 358 ModelTypeSet full_types = Difference(enabled_types_, partial_types); | 354 ModelTypeSet full_types = Difference(enabled_types_, partial_types); |
| 359 fake_manager_factory_->set_progress_marker_types(enabled_types_); | 355 fake_manager_factory_->set_progress_marker_types(enabled_types_); |
| 360 fake_manager_factory_->set_initial_sync_ended_types(full_types); | 356 fake_manager_factory_->set_initial_sync_ended_types(full_types); |
| 361 | 357 |
| 362 // Bringing up the backend should purge all partial types, then proceed to | 358 // Bringing up the backend should purge all partial types, then proceed to |
| 363 // download the Nigori. | 359 // download the Nigori. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 381 EXPECT_EQ(partial_types, fake_manager_->GetAndResetDownloadedTypes()); | 377 EXPECT_EQ(partial_types, fake_manager_->GetAndResetDownloadedTypes()); |
| 382 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 378 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 383 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 379 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 384 EXPECT_TRUE( | 380 EXPECT_TRUE( |
| 385 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 381 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 386 .Empty()); | 382 .Empty()); |
| 387 } | 383 } |
| 388 | 384 |
| 389 // Test the behavior when we lose the sync db. Although we already have types | 385 // Test the behavior when we lose the sync db. Although we already have types |
| 390 // enabled, we should re-download all of them because we lost their data. | 386 // enabled, we should re-download all of them because we lost their data. |
| 391 TEST_F(SyncBackendHostTest, LostDB) { | 387 TEST_F(SyncEngineTest, LostDB) { |
| 392 sync_prefs_->SetFirstSetupComplete(); | 388 sync_prefs_->SetFirstSetupComplete(); |
| 393 // Initialization should fetch the Nigori node. Everything else should be | 389 // Initialization should fetch the Nigori node. Everything else should be |
| 394 // left untouched. | 390 // left untouched. |
| 395 InitializeBackend(true); | 391 InitializeBackend(true); |
| 396 EXPECT_EQ(ModelTypeSet(ControlTypes()), | 392 EXPECT_EQ(ModelTypeSet(ControlTypes()), |
| 397 fake_manager_->GetAndResetDownloadedTypes()); | 393 fake_manager_->GetAndResetDownloadedTypes()); |
| 398 EXPECT_EQ(ModelTypeSet(ControlTypes()), | 394 EXPECT_EQ(ModelTypeSet(ControlTypes()), |
| 399 fake_manager_->InitialSyncEndedTypes()); | 395 fake_manager_->InitialSyncEndedTypes()); |
| 400 EXPECT_EQ( | 396 EXPECT_EQ( |
| 401 Difference(enabled_types_, ControlTypes()), | 397 Difference(enabled_types_, ControlTypes()), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 416 EXPECT_TRUE( | 412 EXPECT_TRUE( |
| 417 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) | 413 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) |
| 418 .Empty()); | 414 .Empty()); |
| 419 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 415 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 420 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 416 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 421 EXPECT_TRUE( | 417 EXPECT_TRUE( |
| 422 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 418 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 423 .Empty()); | 419 .Empty()); |
| 424 } | 420 } |
| 425 | 421 |
| 426 TEST_F(SyncBackendHostTest, DisableTypes) { | 422 TEST_F(SyncEngineTest, DisableTypes) { |
| 427 // Simulate first time sync. | 423 // Simulate first time sync. |
| 428 InitializeBackend(true); | 424 InitializeBackend(true); |
| 429 fake_manager_->GetAndResetCleanedTypes(); | 425 fake_manager_->GetAndResetCleanedTypes(); |
| 430 ModelTypeSet ready_types = ConfigureDataTypes( | 426 ModelTypeSet ready_types = ConfigureDataTypes( |
| 431 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), | 427 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), |
| 432 ModelTypeSet()); | 428 ModelTypeSet()); |
| 433 // Nigori is always downloaded so won't be ready. | 429 // Nigori is always downloaded so won't be ready. |
| 434 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); | 430 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); |
| 435 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); | 431 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); |
| 436 EXPECT_TRUE( | 432 EXPECT_TRUE( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 455 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); | 451 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); |
| 456 EXPECT_EQ(disabled_types, | 452 EXPECT_EQ(disabled_types, |
| 457 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)); | 453 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)); |
| 458 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 454 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 459 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 455 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 460 EXPECT_TRUE( | 456 EXPECT_TRUE( |
| 461 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 457 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 462 .Empty()); | 458 .Empty()); |
| 463 } | 459 } |
| 464 | 460 |
| 465 TEST_F(SyncBackendHostTest, AddTypes) { | 461 TEST_F(SyncEngineTest, AddTypes) { |
| 466 // Simulate first time sync. | 462 // Simulate first time sync. |
| 467 InitializeBackend(true); | 463 InitializeBackend(true); |
| 468 fake_manager_->GetAndResetCleanedTypes(); | 464 fake_manager_->GetAndResetCleanedTypes(); |
| 469 ModelTypeSet ready_types = ConfigureDataTypes( | 465 ModelTypeSet ready_types = ConfigureDataTypes( |
| 470 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), | 466 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), |
| 471 ModelTypeSet()); | 467 ModelTypeSet()); |
| 472 // Nigori is always downloaded so won't be ready. | 468 // Nigori is always downloaded so won't be ready. |
| 473 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); | 469 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); |
| 474 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); | 470 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); |
| 475 EXPECT_TRUE( | 471 EXPECT_TRUE( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 496 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) | 492 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) |
| 497 .Empty()); | 493 .Empty()); |
| 498 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 494 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 499 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 495 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 500 EXPECT_TRUE( | 496 EXPECT_TRUE( |
| 501 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 497 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 502 .Empty()); | 498 .Empty()); |
| 503 } | 499 } |
| 504 | 500 |
| 505 // And and disable in the same configuration. | 501 // And and disable in the same configuration. |
| 506 TEST_F(SyncBackendHostTest, AddDisableTypes) { | 502 TEST_F(SyncEngineTest, AddDisableTypes) { |
| 507 // Simulate first time sync. | 503 // Simulate first time sync. |
| 508 InitializeBackend(true); | 504 InitializeBackend(true); |
| 509 fake_manager_->GetAndResetCleanedTypes(); | 505 fake_manager_->GetAndResetCleanedTypes(); |
| 510 ModelTypeSet ready_types = ConfigureDataTypes( | 506 ModelTypeSet ready_types = ConfigureDataTypes( |
| 511 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), | 507 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), |
| 512 ModelTypeSet()); | 508 ModelTypeSet()); |
| 513 // Nigori is always downloaded so won't be ready. | 509 // Nigori is always downloaded so won't be ready. |
| 514 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); | 510 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types); |
| 515 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); | 511 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); |
| 516 EXPECT_TRUE( | 512 EXPECT_TRUE( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 539 EXPECT_EQ(disabled_types, | 535 EXPECT_EQ(disabled_types, |
| 540 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)); | 536 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)); |
| 541 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 537 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 542 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 538 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 543 EXPECT_EQ(disabled_types, | 539 EXPECT_EQ(disabled_types, |
| 544 fake_manager_->GetTypesWithEmptyProgressMarkerToken(old_types)); | 540 fake_manager_->GetTypesWithEmptyProgressMarkerToken(old_types)); |
| 545 } | 541 } |
| 546 | 542 |
| 547 // Test restarting the browser to newly supported datatypes. The new datatypes | 543 // Test restarting the browser to newly supported datatypes. The new datatypes |
| 548 // should be downloaded on the configuration after backend initialization. | 544 // should be downloaded on the configuration after backend initialization. |
| 549 TEST_F(SyncBackendHostTest, NewlySupportedTypes) { | 545 TEST_F(SyncEngineTest, NewlySupportedTypes) { |
| 550 sync_prefs_->SetFirstSetupComplete(); | 546 sync_prefs_->SetFirstSetupComplete(); |
| 551 // Set sync manager behavior before passing it down. All types have progress | 547 // Set sync manager behavior before passing it down. All types have progress |
| 552 // markers and initial sync ended except the new types. | 548 // markers and initial sync ended except the new types. |
| 553 ModelTypeSet old_types = enabled_types_; | 549 ModelTypeSet old_types = enabled_types_; |
| 554 fake_manager_factory_->set_progress_marker_types(old_types); | 550 fake_manager_factory_->set_progress_marker_types(old_types); |
| 555 fake_manager_factory_->set_initial_sync_ended_types(old_types); | 551 fake_manager_factory_->set_initial_sync_ended_types(old_types); |
| 556 ModelTypeSet new_types(APP_SETTINGS, EXTENSION_SETTINGS); | 552 ModelTypeSet new_types(APP_SETTINGS, EXTENSION_SETTINGS); |
| 557 enabled_types_.PutAll(new_types); | 553 enabled_types_.PutAll(new_types); |
| 558 | 554 |
| 559 // Does nothing. | 555 // Does nothing. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 579 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 575 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 580 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 576 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 581 EXPECT_TRUE( | 577 EXPECT_TRUE( |
| 582 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 578 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 583 .Empty()); | 579 .Empty()); |
| 584 } | 580 } |
| 585 | 581 |
| 586 // Test the newly supported types scenario, but with the presence of partial | 582 // Test the newly supported types scenario, but with the presence of partial |
| 587 // types as well. Both partial and newly supported types should be downloaded | 583 // types as well. Both partial and newly supported types should be downloaded |
| 588 // the configuration. | 584 // the configuration. |
| 589 TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) { | 585 TEST_F(SyncEngineTest, NewlySupportedTypesWithPartialTypes) { |
| 590 sync_prefs_->SetFirstSetupComplete(); | 586 sync_prefs_->SetFirstSetupComplete(); |
| 591 // Set sync manager behavior before passing it down. All types have progress | 587 // Set sync manager behavior before passing it down. All types have progress |
| 592 // markers and initial sync ended except the new types. | 588 // markers and initial sync ended except the new types. |
| 593 ModelTypeSet old_types = enabled_types_; | 589 ModelTypeSet old_types = enabled_types_; |
| 594 ModelTypeSet partial_types(NIGORI, BOOKMARKS); | 590 ModelTypeSet partial_types(NIGORI, BOOKMARKS); |
| 595 ModelTypeSet full_types = Difference(enabled_types_, partial_types); | 591 ModelTypeSet full_types = Difference(enabled_types_, partial_types); |
| 596 fake_manager_factory_->set_progress_marker_types(old_types); | 592 fake_manager_factory_->set_progress_marker_types(old_types); |
| 597 fake_manager_factory_->set_initial_sync_ended_types(full_types); | 593 fake_manager_factory_->set_initial_sync_ended_types(full_types); |
| 598 ModelTypeSet new_types(APP_SETTINGS, EXTENSION_SETTINGS); | 594 ModelTypeSet new_types(APP_SETTINGS, EXTENSION_SETTINGS); |
| 599 enabled_types_.PutAll(new_types); | 595 enabled_types_.PutAll(new_types); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 622 .Empty()); | 618 .Empty()); |
| 623 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 619 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 624 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); | 620 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); |
| 625 EXPECT_TRUE( | 621 EXPECT_TRUE( |
| 626 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 622 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 627 .Empty()); | 623 .Empty()); |
| 628 } | 624 } |
| 629 | 625 |
| 630 // Verify that downloading control types only downloads those types that do | 626 // Verify that downloading control types only downloads those types that do |
| 631 // not have initial sync ended set. | 627 // not have initial sync ended set. |
| 632 TEST_F(SyncBackendHostTest, DownloadControlTypes) { | 628 TEST_F(SyncEngineTest, DownloadControlTypes) { |
| 633 sync_prefs_->SetFirstSetupComplete(); | 629 sync_prefs_->SetFirstSetupComplete(); |
| 634 // Set sync manager behavior before passing it down. Experiments and device | 630 // Set sync manager behavior before passing it down. Experiments and device |
| 635 // info are new types without progress markers or initial sync ended, while | 631 // info are new types without progress markers or initial sync ended, while |
| 636 // all other types have been fully downloaded and applied. | 632 // all other types have been fully downloaded and applied. |
| 637 ModelTypeSet new_types(EXPERIMENTS, NIGORI); | 633 ModelTypeSet new_types(EXPERIMENTS, NIGORI); |
| 638 ModelTypeSet old_types = Difference(enabled_types_, new_types); | 634 ModelTypeSet old_types = Difference(enabled_types_, new_types); |
| 639 fake_manager_factory_->set_progress_marker_types(old_types); | 635 fake_manager_factory_->set_progress_marker_types(old_types); |
| 640 fake_manager_factory_->set_initial_sync_ended_types(old_types); | 636 fake_manager_factory_->set_initial_sync_ended_types(old_types); |
| 641 | 637 |
| 642 // Bringing up the backend should download the new types without downloading | 638 // Bringing up the backend should download the new types without downloading |
| 643 // any old types. | 639 // any old types. |
| 644 InitializeBackend(true); | 640 InitializeBackend(true); |
| 645 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); | 641 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); |
| 646 EXPECT_EQ(Difference(ModelTypeSet::All(), enabled_types_), | 642 EXPECT_EQ(Difference(ModelTypeSet::All(), enabled_types_), |
| 647 fake_manager_->GetAndResetCleanedTypes()); | 643 fake_manager_->GetAndResetCleanedTypes()); |
| 648 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); | 644 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); |
| 649 EXPECT_TRUE( | 645 EXPECT_TRUE( |
| 650 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) | 646 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) |
| 651 .Empty()); | 647 .Empty()); |
| 652 } | 648 } |
| 653 | 649 |
| 654 // Fail to download control types. It's believed that there is a server bug | 650 // Fail to download control types. It's believed that there is a server bug |
| 655 // which can allow this to happen (crbug.com/164288). The sync backend host | 651 // which can allow this to happen (crbug.com/164288). The sync backend host |
| 656 // should detect this condition and fail to initialize the backend. | 652 // should detect this condition and fail to initialize the backend. |
| 657 // | 653 // |
| 658 // The failure is "silent" in the sense that the GetUpdates request appears to | 654 // The failure is "silent" in the sense that the GetUpdates request appears to |
| 659 // be successful, but it returned no results. This means that the usual | 655 // be successful, but it returned no results. This means that the usual |
| 660 // download retry logic will not be invoked. | 656 // download retry logic will not be invoked. |
| 661 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) { | 657 TEST_F(SyncEngineTest, SilentlyFailToDownloadControlTypes) { |
| 662 fake_manager_factory_->set_configure_fail_types(ModelTypeSet::All()); | 658 fake_manager_factory_->set_configure_fail_types(ModelTypeSet::All()); |
| 663 InitializeBackend(false); | 659 InitializeBackend(false); |
| 664 } | 660 } |
| 665 | 661 |
| 666 // Test that local refresh requests are delivered to sync. | 662 // Test that local refresh requests are delivered to sync. |
| 667 TEST_F(SyncBackendHostTest, ForwardLocalRefreshRequest) { | 663 TEST_F(SyncEngineTest, ForwardLocalRefreshRequest) { |
| 668 InitializeBackend(true); | 664 InitializeBackend(true); |
| 669 | 665 |
| 670 ModelTypeSet set1 = ModelTypeSet::All(); | 666 ModelTypeSet set1 = ModelTypeSet::All(); |
| 671 backend_->TriggerRefresh(set1); | 667 backend_->TriggerRefresh(set1); |
| 672 fake_manager_->WaitForSyncThread(); | 668 fake_manager_->WaitForSyncThread(); |
| 673 EXPECT_EQ(set1, fake_manager_->GetLastRefreshRequestTypes()); | 669 EXPECT_EQ(set1, fake_manager_->GetLastRefreshRequestTypes()); |
| 674 | 670 |
| 675 ModelTypeSet set2 = ModelTypeSet(SESSIONS); | 671 ModelTypeSet set2 = ModelTypeSet(SESSIONS); |
| 676 backend_->TriggerRefresh(set2); | 672 backend_->TriggerRefresh(set2); |
| 677 fake_manager_->WaitForSyncThread(); | 673 fake_manager_->WaitForSyncThread(); |
| 678 EXPECT_EQ(set2, fake_manager_->GetLastRefreshRequestTypes()); | 674 EXPECT_EQ(set2, fake_manager_->GetLastRefreshRequestTypes()); |
| 679 } | 675 } |
| 680 | 676 |
| 681 // Test that configuration on signin sends the proper GU source. | 677 // Test that configuration on signin sends the proper GU source. |
| 682 TEST_F(SyncBackendHostTest, DownloadControlTypesNewClient) { | 678 TEST_F(SyncEngineTest, DownloadControlTypesNewClient) { |
| 683 InitializeBackend(true); | 679 InitializeBackend(true); |
| 684 EXPECT_EQ(CONFIGURE_REASON_NEW_CLIENT, | 680 EXPECT_EQ(CONFIGURE_REASON_NEW_CLIENT, |
| 685 fake_manager_->GetAndResetConfigureReason()); | 681 fake_manager_->GetAndResetConfigureReason()); |
| 686 } | 682 } |
| 687 | 683 |
| 688 // Test that configuration on restart sends the proper GU source. | 684 // Test that configuration on restart sends the proper GU source. |
| 689 TEST_F(SyncBackendHostTest, DownloadControlTypesRestart) { | 685 TEST_F(SyncEngineTest, DownloadControlTypesRestart) { |
| 690 sync_prefs_->SetFirstSetupComplete(); | 686 sync_prefs_->SetFirstSetupComplete(); |
| 691 fake_manager_factory_->set_progress_marker_types(enabled_types_); | 687 fake_manager_factory_->set_progress_marker_types(enabled_types_); |
| 692 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); | 688 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); |
| 693 InitializeBackend(true); | 689 InitializeBackend(true); |
| 694 EXPECT_EQ(CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, | 690 EXPECT_EQ(CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, |
| 695 fake_manager_->GetAndResetConfigureReason()); | 691 fake_manager_->GetAndResetConfigureReason()); |
| 696 } | 692 } |
| 697 | 693 |
| 698 // It is SyncBackendHostCore responsibility to cleanup Sync Data folder if sync | 694 // It is SyncBackendHostCore responsibility to cleanup Sync Data folder if sync |
| 699 // setup hasn't been completed. This test ensures that cleanup happens. | 695 // setup hasn't been completed. This test ensures that cleanup happens. |
| 700 TEST_F(SyncBackendHostTest, TestStartupWithOldSyncData) { | 696 TEST_F(SyncEngineTest, TestStartupWithOldSyncData) { |
| 701 const char* nonsense = "slon"; | 697 const char* nonsense = "slon"; |
| 702 base::FilePath temp_directory = | 698 base::FilePath temp_directory = |
| 703 temp_dir_.GetPath().Append(base::FilePath(kTestSyncDir)); | 699 temp_dir_.GetPath().Append(base::FilePath(kTestSyncDir)); |
| 704 base::FilePath sync_file = temp_directory.AppendASCII("SyncData.sqlite3"); | 700 base::FilePath sync_file = temp_directory.AppendASCII("SyncData.sqlite3"); |
| 705 ASSERT_TRUE(base::CreateDirectory(temp_directory)); | 701 ASSERT_TRUE(base::CreateDirectory(temp_directory)); |
| 706 ASSERT_NE(-1, base::WriteFile(sync_file, nonsense, strlen(nonsense))); | 702 ASSERT_NE(-1, base::WriteFile(sync_file, nonsense, strlen(nonsense))); |
| 707 | 703 |
| 708 InitializeBackend(true); | 704 InitializeBackend(true); |
| 709 | 705 |
| 710 EXPECT_FALSE(base::PathExists(sync_file)); | 706 EXPECT_FALSE(base::PathExists(sync_file)); |
| 711 } | 707 } |
| 712 | 708 |
| 713 // If bookmarks encounter an error that results in disabling without purging | 709 // If bookmarks encounter an error that results in disabling without purging |
| 714 // (such as when the type is unready), and then is explicitly disabled, the | 710 // (such as when the type is unready), and then is explicitly disabled, the |
| 715 // SyncBackendHost needs to tell the manager to purge the type, even though | 711 // SyncEngine needs to tell the manager to purge the type, even though |
| 716 // it's already disabled (crbug.com/386778). | 712 // it's already disabled (crbug.com/386778). |
| 717 TEST_F(SyncBackendHostTest, DisableThenPurgeType) { | 713 TEST_F(SyncEngineTest, DisableThenPurgeType) { |
| 718 ModelTypeSet error_types(BOOKMARKS); | 714 ModelTypeSet error_types(BOOKMARKS); |
| 719 | 715 |
| 720 InitializeBackend(true); | 716 InitializeBackend(true); |
| 721 | 717 |
| 722 // First enable the types. | 718 // First enable the types. |
| 723 ModelTypeSet ready_types = ConfigureDataTypes( | 719 ModelTypeSet ready_types = ConfigureDataTypes( |
| 724 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), | 720 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), |
| 725 ModelTypeSet()); | 721 ModelTypeSet()); |
| 726 | 722 |
| 727 // Nigori is always downloaded so won't be ready. | 723 // Nigori is always downloaded so won't be ready. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 740 ready_types = ConfigureDataTypes( | 736 ready_types = ConfigureDataTypes( |
| 741 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), | 737 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_), |
| 742 ModelTypeSet()); | 738 ModelTypeSet()); |
| 743 EXPECT_EQ(Difference(enabled_types_, error_types), ready_types); | 739 EXPECT_EQ(Difference(enabled_types_, error_types), ready_types); |
| 744 EXPECT_FALSE( | 740 EXPECT_FALSE( |
| 745 fake_manager_->GetTypesWithEmptyProgressMarkerToken(error_types).Empty()); | 741 fake_manager_->GetTypesWithEmptyProgressMarkerToken(error_types).Empty()); |
| 746 } | 742 } |
| 747 | 743 |
| 748 // Test that a call to ClearServerData is forwarded to the underlying | 744 // Test that a call to ClearServerData is forwarded to the underlying |
| 749 // SyncManager. | 745 // SyncManager. |
| 750 TEST_F(SyncBackendHostTest, ClearServerDataCallsAreForwarded) { | 746 TEST_F(SyncEngineTest, ClearServerDataCallsAreForwarded) { |
| 751 InitializeBackend(true); | 747 InitializeBackend(true); |
| 752 CallbackCounter callback_counter; | 748 CallbackCounter callback_counter; |
| 753 backend_->ClearServerData(base::Bind(&CallbackCounter::Callback, | 749 backend_->ClearServerData(base::Bind(&CallbackCounter::Callback, |
| 754 base::Unretained(&callback_counter))); | 750 base::Unretained(&callback_counter))); |
| 755 fake_manager_->WaitForSyncThread(); | 751 fake_manager_->WaitForSyncThread(); |
| 756 EXPECT_EQ(1, callback_counter.times_called()); | 752 EXPECT_EQ(1, callback_counter.times_called()); |
| 757 } | 753 } |
| 758 | 754 |
| 759 // Ensure that redundant invalidations are ignored and that the most recent | 755 // Ensure that redundant invalidations are ignored and that the most recent |
| 760 // set of invalidation version is persisted across restarts. | 756 // set of invalidation version is persisted across restarts. |
| 761 TEST_F(SyncBackendHostTest, IgnoreOldInvalidations) { | 757 TEST_F(SyncEngineTest, IgnoreOldInvalidations) { |
| 762 // Set up some old persisted invalidations. | 758 // Set up some old persisted invalidations. |
| 763 std::map<ModelType, int64_t> invalidation_versions; | 759 std::map<ModelType, int64_t> invalidation_versions; |
| 764 invalidation_versions[BOOKMARKS] = 20; | 760 invalidation_versions[BOOKMARKS] = 20; |
| 765 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); | 761 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); |
| 766 InitializeBackend(true); | 762 InitializeBackend(true); |
| 767 EXPECT_EQ(0, fake_manager_->GetInvalidationCount()); | 763 EXPECT_EQ(0, fake_manager_->GetInvalidationCount()); |
| 768 | 764 |
| 769 // Receiving an invalidation with an old version should do nothing. | 765 // Receiving an invalidation with an old version should do nothing. |
| 770 ObjectIdInvalidationMap invalidation_map; | 766 ObjectIdInvalidationMap invalidation_map; |
| 771 std::string notification_type; | 767 std::string notification_type; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 EXPECT_EQ(invalidation_versions.size(), | 808 EXPECT_EQ(invalidation_versions.size(), |
| 813 persisted_invalidation_versions.size()); | 809 persisted_invalidation_versions.size()); |
| 814 for (auto iter : persisted_invalidation_versions) { | 810 for (auto iter : persisted_invalidation_versions) { |
| 815 EXPECT_EQ(invalidation_versions[iter.first], iter.second); | 811 EXPECT_EQ(invalidation_versions[iter.first], iter.second); |
| 816 } | 812 } |
| 817 } | 813 } |
| 818 | 814 |
| 819 // Tests that SyncBackendHostImpl retains ModelTypeConnector after call to | 815 // Tests that SyncBackendHostImpl retains ModelTypeConnector after call to |
| 820 // StopSyncingForShutdown. This is needed for datatype deactivation during | 816 // StopSyncingForShutdown. This is needed for datatype deactivation during |
| 821 // DataTypeManager shutdown. | 817 // DataTypeManager shutdown. |
| 822 TEST_F(SyncBackendHostTest, ModelTypeConnectorValidDuringShutdown) { | 818 TEST_F(SyncEngineTest, ModelTypeConnectorValidDuringShutdown) { |
| 823 InitializeBackend(true); | 819 InitializeBackend(true); |
| 824 backend_->StopSyncingForShutdown(); | 820 backend_->StopSyncingForShutdown(); |
| 825 // Verify that call to DeactivateNonBlockingDataType doesn't assert. | 821 // Verify that call to DeactivateNonBlockingDataType doesn't assert. |
| 826 backend_->DeactivateNonBlockingDataType(AUTOFILL); | 822 backend_->DeactivateNonBlockingDataType(AUTOFILL); |
| 827 backend_->Shutdown(STOP_SYNC); | 823 backend_->Shutdown(STOP_SYNC); |
| 828 backend_.reset(); | 824 backend_.reset(); |
| 829 } | 825 } |
| 830 | 826 |
| 831 } // namespace | 827 } // namespace |
| 832 | 828 |
| 833 } // namespace syncer | 829 } // namespace syncer |
| OLD | NEW |