Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: components/sync/driver/glue/sync_backend_host_impl_unittest.cc

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "base/test/test_timeouts.h" 20 #include "base/test/test_timeouts.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "components/invalidation/impl/invalidator_storage.h" 23 #include "components/invalidation/impl/invalidator_storage.h"
24 #include "components/invalidation/impl/profile_invalidation_provider.h" 24 #include "components/invalidation/impl/profile_invalidation_provider.h"
25 #include "components/invalidation/public/invalidator_state.h" 25 #include "components/invalidation/public/invalidator_state.h"
26 #include "components/invalidation/public/object_id_invalidation_map.h" 26 #include "components/invalidation/public/object_id_invalidation_map.h"
27 #include "components/sync/base/experiments.h" 27 #include "components/sync/base/experiments.h"
28 #include "components/sync/base/model_type.h" 28 #include "components/sync/base/model_type.h"
29 #include "components/sync/base/test_unrecoverable_error_handler.h" 29 #include "components/sync/base/test_unrecoverable_error_handler.h"
30 #include "components/sync/core/http_bridge_network_resources.h" 30 #include "components/sync/core/http_bridge_network_resources.h"
31 #include "components/sync/core/network_resources.h" 31 #include "components/sync/core/network_resources.h"
32 #include "components/sync/core/sync_manager_factory.h" 32 #include "components/sync/core/sync_manager_factory.h"
33 #include "components/sync/core/test/fake_sync_manager.h" 33 #include "components/sync/core/test/fake_sync_manager.h"
34 #include "components/sync/driver/device_info.h"
35 #include "components/sync/driver/fake_sync_client.h"
36 #include "components/sync/driver/sync_frontend.h"
37 #include "components/sync/driver/sync_prefs.h"
34 #include "components/sync/engine/model_safe_worker.h" 38 #include "components/sync/engine/model_safe_worker.h"
35 #include "components/sync/engine/passive_model_worker.h" 39 #include "components/sync/engine/passive_model_worker.h"
36 #include "components/sync/protocol/encryption.pb.h" 40 #include "components/sync/protocol/encryption.pb.h"
37 #include "components/sync/protocol/sync_protocol_error.h" 41 #include "components/sync/protocol/sync_protocol_error.h"
38 #include "components/sync/sessions/commit_counters.h" 42 #include "components/sync/sessions/commit_counters.h"
39 #include "components/sync/sessions/status_counters.h" 43 #include "components/sync/sessions/status_counters.h"
40 #include "components/sync/sessions/update_counters.h" 44 #include "components/sync/sessions/update_counters.h"
41 #include "components/sync/test/callback_counter.h" 45 #include "components/sync/test/callback_counter.h"
42 #include "components/sync_driver/device_info.h"
43 #include "components/sync_driver/fake_sync_client.h"
44 #include "components/sync_driver/sync_frontend.h"
45 #include "components/sync_driver/sync_prefs.h"
46 #include "components/syncable_prefs/pref_service_syncable.h" 46 #include "components/syncable_prefs/pref_service_syncable.h"
47 #include "components/syncable_prefs/testing_pref_service_syncable.h" 47 #include "components/syncable_prefs/testing_pref_service_syncable.h"
48 #include "google/cacheinvalidation/include/types.h" 48 #include "google/cacheinvalidation/include/types.h"
49 #include "google_apis/gaia/gaia_constants.h" 49 #include "google_apis/gaia/gaia_constants.h"
50 #include "net/url_request/test_url_fetcher_factory.h" 50 #include "net/url_request/test_url_fetcher_factory.h"
51 #include "net/url_request/url_request_context_getter.h" 51 #include "net/url_request/url_request_context_getter.h"
52 #include "testing/gmock/include/gmock/gmock.h" 52 #include "testing/gmock/include/gmock/gmock.h"
53 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
54 #include "url/gurl.h" 54 #include "url/gurl.h"
55 55
(...skipping 26 matching lines...) Expand all
82 public: 82 public:
83 virtual ~MockSyncFrontend() {} 83 virtual ~MockSyncFrontend() {}
84 84
85 MOCK_METHOD4( 85 MOCK_METHOD4(
86 OnBackendInitialized, 86 OnBackendInitialized,
87 void(const syncer::WeakHandle<syncer::JsBackend>&, 87 void(const syncer::WeakHandle<syncer::JsBackend>&,
88 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&, 88 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&,
89 const std::string&, 89 const std::string&,
90 bool)); 90 bool));
91 MOCK_METHOD0(OnSyncCycleCompleted, void()); 91 MOCK_METHOD0(OnSyncCycleCompleted, void());
92 MOCK_METHOD1(OnConnectionStatusChange, 92 MOCK_METHOD1(OnConnectionStatusChange, void(syncer::ConnectionStatus status));
93 void(syncer::ConnectionStatus status));
94 MOCK_METHOD0(OnClearServerDataSucceeded, void()); 93 MOCK_METHOD0(OnClearServerDataSucceeded, void());
95 MOCK_METHOD0(OnClearServerDataFailed, void()); 94 MOCK_METHOD0(OnClearServerDataFailed, void());
96 MOCK_METHOD2(OnPassphraseRequired, 95 MOCK_METHOD2(OnPassphraseRequired,
97 void(syncer::PassphraseRequiredReason, 96 void(syncer::PassphraseRequiredReason,
98 const sync_pb::EncryptedData&)); 97 const sync_pb::EncryptedData&));
99 MOCK_METHOD0(OnPassphraseAccepted, void()); 98 MOCK_METHOD0(OnPassphraseAccepted, void());
100 MOCK_METHOD2(OnEncryptedTypesChanged, 99 MOCK_METHOD2(OnEncryptedTypesChanged, void(syncer::ModelTypeSet, bool));
101 void(syncer::ModelTypeSet, bool));
102 MOCK_METHOD0(OnEncryptionComplete, void()); 100 MOCK_METHOD0(OnEncryptionComplete, void());
103 MOCK_METHOD1(OnMigrationNeededForTypes, void(syncer::ModelTypeSet)); 101 MOCK_METHOD1(OnMigrationNeededForTypes, void(syncer::ModelTypeSet));
104 MOCK_METHOD1(OnProtocolEvent, void(const syncer::ProtocolEvent&)); 102 MOCK_METHOD1(OnProtocolEvent, void(const syncer::ProtocolEvent&));
105 MOCK_METHOD2(OnDirectoryTypeCommitCounterUpdated, 103 MOCK_METHOD2(OnDirectoryTypeCommitCounterUpdated,
106 void(syncer::ModelType, const syncer::CommitCounters&)); 104 void(syncer::ModelType, const syncer::CommitCounters&));
107 MOCK_METHOD2(OnDirectoryTypeUpdateCounterUpdated, 105 MOCK_METHOD2(OnDirectoryTypeUpdateCounterUpdated,
108 void(syncer::ModelType, const syncer::UpdateCounters&)); 106 void(syncer::ModelType, const syncer::UpdateCounters&));
109 MOCK_METHOD2(OnDirectoryTypeStatusCounterUpdated, 107 MOCK_METHOD2(OnDirectoryTypeStatusCounterUpdated,
110 void(syncer::ModelType, const syncer::StatusCounters&)); 108 void(syncer::ModelType, const syncer::StatusCounters&));
111 MOCK_METHOD1(OnExperimentsChanged, 109 MOCK_METHOD1(OnExperimentsChanged, void(const syncer::Experiments&));
112 void(const syncer::Experiments&));
113 MOCK_METHOD1(OnActionableError, 110 MOCK_METHOD1(OnActionableError,
114 void(const syncer::SyncProtocolError& sync_error)); 111 void(const syncer::SyncProtocolError& sync_error));
115 MOCK_METHOD0(OnSyncConfigureRetry, void()); 112 MOCK_METHOD0(OnSyncConfigureRetry, void());
116 MOCK_METHOD1( 113 MOCK_METHOD1(
117 OnLocalSetPassphraseEncryption, 114 OnLocalSetPassphraseEncryption,
118 void(const syncer::SyncEncryptionHandler::NigoriState& nigori_state)); 115 void(const syncer::SyncEncryptionHandler::NigoriState& nigori_state));
119 }; 116 };
120 117
121 class FakeSyncManagerFactory : public syncer::SyncManagerFactory { 118 class FakeSyncManagerFactory : public syncer::SyncManagerFactory {
122 public: 119 public:
123 explicit FakeSyncManagerFactory(FakeSyncManager** fake_manager) 120 explicit FakeSyncManagerFactory(FakeSyncManager** fake_manager)
124 : fake_manager_(fake_manager) { 121 : fake_manager_(fake_manager) {
125 *fake_manager_ = NULL; 122 *fake_manager_ = NULL;
126 } 123 }
127 ~FakeSyncManagerFactory() override {} 124 ~FakeSyncManagerFactory() override {}
128 125
129 // SyncManagerFactory implementation. Called on the sync thread. 126 // SyncManagerFactory implementation. Called on the sync thread.
130 std::unique_ptr<SyncManager> CreateSyncManager( 127 std::unique_ptr<SyncManager> CreateSyncManager(
131 const std::string& /* name */) override { 128 const std::string& /* name */) override {
132 *fake_manager_ = new FakeSyncManager(initial_sync_ended_types_, 129 *fake_manager_ =
133 progress_marker_types_, 130 new FakeSyncManager(initial_sync_ended_types_, progress_marker_types_,
134 configure_fail_types_); 131 configure_fail_types_);
135 return std::unique_ptr<SyncManager>(*fake_manager_); 132 return std::unique_ptr<SyncManager>(*fake_manager_);
136 } 133 }
137 134
138 void set_initial_sync_ended_types(syncer::ModelTypeSet types) { 135 void set_initial_sync_ended_types(syncer::ModelTypeSet types) {
139 initial_sync_ended_types_ = types; 136 initial_sync_ended_types_ = types;
140 } 137 }
141 138
142 void set_progress_marker_types(syncer::ModelTypeSet types) { 139 void set_progress_marker_types(syncer::ModelTypeSet types) {
143 progress_marker_types_ = types; 140 progress_marker_types_ = types;
144 } 141 }
(...skipping 18 matching lines...) Expand all
163 case syncer::GROUP_PASSIVE: 160 case syncer::GROUP_PASSIVE:
164 return new syncer::PassiveModelWorker(observer); 161 return new syncer::PassiveModelWorker(observer);
165 default: 162 default:
166 return nullptr; 163 return nullptr;
167 } 164 }
168 } 165 }
169 }; 166 };
170 167
171 class SyncBackendHostTest : public testing::Test { 168 class SyncBackendHostTest : public testing::Test {
172 protected: 169 protected:
173 SyncBackendHostTest() 170 SyncBackendHostTest() : fake_manager_(NULL) {}
174 : fake_manager_(NULL) {}
175 171
176 ~SyncBackendHostTest() override {} 172 ~SyncBackendHostTest() override {}
177 173
178 void SetUp() override { 174 void SetUp() override {
179 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 175 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
180 176
181 sync_driver::SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); 177 sync_driver::SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
182 178
183 sync_prefs_.reset(new sync_driver::SyncPrefs(&pref_service_)); 179 sync_prefs_.reset(new sync_driver::SyncPrefs(&pref_service_));
184 backend_.reset(new SyncBackendHostImpl( 180 backend_.reset(new SyncBackendHostImpl(
185 "dummyDebugName", &sync_client_, 181 "dummyDebugName", &sync_client_, base::ThreadTaskRunnerHandle::Get(),
186 base::ThreadTaskRunnerHandle::Get(), 182 nullptr, sync_prefs_->AsWeakPtr(),
187 nullptr,
188 sync_prefs_->AsWeakPtr(),
189 temp_dir_.path().Append(base::FilePath(kTestSyncDir)))); 183 temp_dir_.path().Append(base::FilePath(kTestSyncDir))));
190 credentials_.account_id = "user@example.com"; 184 credentials_.account_id = "user@example.com";
191 credentials_.email = "user@example.com"; 185 credentials_.email = "user@example.com";
192 credentials_.sync_token = "sync_token"; 186 credentials_.sync_token = "sync_token";
193 credentials_.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); 187 credentials_.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope);
194 188
195 fake_manager_factory_.reset(new FakeSyncManagerFactory(&fake_manager_)); 189 fake_manager_factory_.reset(new FakeSyncManagerFactory(&fake_manager_));
196 190
197 // These types are always implicitly enabled. 191 // These types are always implicitly enabled.
198 enabled_types_.PutAll(syncer::ControlTypes()); 192 enabled_types_.PutAll(syncer::ControlTypes());
(...skipping 15 matching lines...) Expand all
214 backend_->Shutdown(syncer::STOP_SYNC); 208 backend_->Shutdown(syncer::STOP_SYNC);
215 } 209 }
216 backend_.reset(); 210 backend_.reset();
217 sync_prefs_.reset(); 211 sync_prefs_.reset();
218 // Pump messages posted by the sync thread. 212 // Pump messages posted by the sync thread.
219 base::RunLoop().RunUntilIdle(); 213 base::RunLoop().RunUntilIdle();
220 } 214 }
221 215
222 // Synchronously initializes the backend. 216 // Synchronously initializes the backend.
223 void InitializeBackend(bool expect_success) { 217 void InitializeBackend(bool expect_success) {
224 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success)). 218 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success))
225 WillOnce(InvokeWithoutArgs(QuitMessageLoop)); 219 .WillOnce(InvokeWithoutArgs(QuitMessageLoop));
226 SyncBackendHost::HttpPostProviderFactoryGetter 220 SyncBackendHost::HttpPostProviderFactoryGetter
227 http_post_provider_factory_getter = 221 http_post_provider_factory_getter =
228 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, 222 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory,
229 base::Unretained(network_resources_.get()), 223 base::Unretained(network_resources_.get()), nullptr,
230 nullptr,
231 base::Bind(&EmptyNetworkTimeUpdate)); 224 base::Bind(&EmptyNetworkTimeUpdate));
232 backend_->Initialize( 225 backend_->Initialize(
233 &mock_frontend_, std::unique_ptr<base::Thread>(), 226 &mock_frontend_, std::unique_ptr<base::Thread>(),
234 base::ThreadTaskRunnerHandle::Get(), 227 base::ThreadTaskRunnerHandle::Get(),
235 base::ThreadTaskRunnerHandle::Get(), 228 base::ThreadTaskRunnerHandle::Get(),
236 syncer::WeakHandle<syncer::JsEventHandler>(), GURL(std::string()), 229 syncer::WeakHandle<syncer::JsEventHandler>(), GURL(std::string()),
237 std::string(), credentials_, true, std::move(fake_manager_factory_), 230 std::string(), credentials_, true, std::move(fake_manager_factory_),
238 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()), 231 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()),
239 base::Closure(), http_post_provider_factory_getter, 232 base::Closure(), http_post_provider_factory_getter,
240 std::move(saved_nigori_state_)); 233 std::move(saved_nigori_state_));
241 base::RunLoop run_loop; 234 base::RunLoop run_loop;
242 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, 235 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
243 run_loop.QuitClosure(), 236 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout());
244 TestTimeouts::action_timeout());
245 run_loop.Run(); 237 run_loop.Run();
246 // |fake_manager_factory_|'s fake_manager() is set on the sync 238 // |fake_manager_factory_|'s fake_manager() is set on the sync
247 // thread, but we can rely on the message loop barriers to 239 // thread, but we can rely on the message loop barriers to
248 // guarantee that we see the updated value. 240 // guarantee that we see the updated value.
249 DCHECK(fake_manager_); 241 DCHECK(fake_manager_);
250 } 242 }
251 243
252 // Synchronously configures the backend's datatypes. 244 // Synchronously configures the backend's datatypes.
253 syncer::ModelTypeSet ConfigureDataTypes( 245 syncer::ModelTypeSet ConfigureDataTypes(
254 syncer::ModelTypeSet types_to_add, 246 syncer::ModelTypeSet types_to_add,
255 syncer::ModelTypeSet types_to_remove, 247 syncer::ModelTypeSet types_to_remove,
256 syncer::ModelTypeSet types_to_unapply) { 248 syncer::ModelTypeSet types_to_unapply) {
257 sync_driver::BackendDataTypeConfigurer::DataTypeConfigStateMap 249 sync_driver::BackendDataTypeConfigurer::DataTypeConfigStateMap
258 config_state_map; 250 config_state_map;
259 sync_driver::BackendDataTypeConfigurer::SetDataTypesState( 251 sync_driver::BackendDataTypeConfigurer::SetDataTypesState(
260 sync_driver::BackendDataTypeConfigurer::CONFIGURE_ACTIVE, 252 sync_driver::BackendDataTypeConfigurer::CONFIGURE_ACTIVE, types_to_add,
261 types_to_add,
262 &config_state_map); 253 &config_state_map);
263 sync_driver::BackendDataTypeConfigurer::SetDataTypesState( 254 sync_driver::BackendDataTypeConfigurer::SetDataTypesState(
264 sync_driver::BackendDataTypeConfigurer::DISABLED, 255 sync_driver::BackendDataTypeConfigurer::DISABLED, types_to_remove,
265 types_to_remove, &config_state_map); 256 &config_state_map);
266 sync_driver::BackendDataTypeConfigurer::SetDataTypesState( 257 sync_driver::BackendDataTypeConfigurer::SetDataTypesState(
267 sync_driver::BackendDataTypeConfigurer::UNREADY, 258 sync_driver::BackendDataTypeConfigurer::UNREADY, types_to_unapply,
268 types_to_unapply, &config_state_map); 259 &config_state_map);
269 260
270 types_to_add.PutAll(syncer::ControlTypes()); 261 types_to_add.PutAll(syncer::ControlTypes());
271 syncer::ModelTypeSet ready_types = backend_->ConfigureDataTypes( 262 syncer::ModelTypeSet ready_types = backend_->ConfigureDataTypes(
272 syncer::CONFIGURE_REASON_RECONFIGURATION, config_state_map, 263 syncer::CONFIGURE_REASON_RECONFIGURATION, config_state_map,
273 base::Bind(&SyncBackendHostTest::DownloadReady, base::Unretained(this)), 264 base::Bind(&SyncBackendHostTest::DownloadReady, base::Unretained(this)),
274 base::Bind(&SyncBackendHostTest::OnDownloadRetry, 265 base::Bind(&SyncBackendHostTest::OnDownloadRetry,
275 base::Unretained(this))); 266 base::Unretained(this)));
276 base::RunLoop run_loop; 267 base::RunLoop run_loop;
277 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, 268 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
278 run_loop.QuitClosure(), 269 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout());
279 TestTimeouts::action_timeout());
280 run_loop.Run(); 270 run_loop.Run();
281 return ready_types; 271 return ready_types;
282 } 272 }
283 273
284 protected: 274 protected:
285 void DownloadReady(syncer::ModelTypeSet succeeded_types, 275 void DownloadReady(syncer::ModelTypeSet succeeded_types,
286 syncer::ModelTypeSet failed_types) { 276 syncer::ModelTypeSet failed_types) {
287 base::MessageLoop::current()->QuitWhenIdle(); 277 base::MessageLoop::current()->QuitWhenIdle();
288 } 278 }
289 279
290 void OnDownloadRetry() { 280 void OnDownloadRetry() { NOTIMPLEMENTED(); }
291 NOTIMPLEMENTED();
292 }
293 281
294 base::MessageLoop message_loop_; 282 base::MessageLoop message_loop_;
295 base::ScopedTempDir temp_dir_; 283 base::ScopedTempDir temp_dir_;
296 syncable_prefs::TestingPrefServiceSyncable pref_service_; 284 syncable_prefs::TestingPrefServiceSyncable pref_service_;
297 StrictMock<MockSyncFrontend> mock_frontend_; 285 StrictMock<MockSyncFrontend> mock_frontend_;
298 syncer::SyncCredentials credentials_; 286 syncer::SyncCredentials credentials_;
299 BackendSyncClient sync_client_; 287 BackendSyncClient sync_client_;
300 syncer::TestUnrecoverableErrorHandler test_unrecoverable_error_handler_; 288 syncer::TestUnrecoverableErrorHandler test_unrecoverable_error_handler_;
301 std::unique_ptr<sync_driver::SyncPrefs> sync_prefs_; 289 std::unique_ptr<sync_driver::SyncPrefs> sync_prefs_;
302 std::unique_ptr<SyncBackendHostImpl> backend_; 290 std::unique_ptr<SyncBackendHostImpl> backend_;
303 std::unique_ptr<FakeSyncManagerFactory> fake_manager_factory_; 291 std::unique_ptr<FakeSyncManagerFactory> fake_manager_factory_;
304 FakeSyncManager* fake_manager_; 292 FakeSyncManager* fake_manager_;
305 syncer::ModelTypeSet enabled_types_; 293 syncer::ModelTypeSet enabled_types_;
306 std::unique_ptr<syncer::NetworkResources> network_resources_; 294 std::unique_ptr<syncer::NetworkResources> network_resources_;
307 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> 295 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>
308 saved_nigori_state_; 296 saved_nigori_state_;
309 }; 297 };
310 298
311 // Test basic initialization with no initial types (first time initialization). 299 // Test basic initialization with no initial types (first time initialization).
312 // Only the nigori should be configured. 300 // Only the nigori should be configured.
313 TEST_F(SyncBackendHostTest, InitShutdown) { 301 TEST_F(SyncBackendHostTest, InitShutdown) {
314 InitializeBackend(true); 302 InitializeBackend(true);
315 EXPECT_EQ(syncer::ControlTypes(), 303 EXPECT_EQ(syncer::ControlTypes(),
316 fake_manager_->GetAndResetDownloadedTypes()); 304 fake_manager_->GetAndResetDownloadedTypes());
317 EXPECT_EQ(syncer::ControlTypes(), fake_manager_->InitialSyncEndedTypes()); 305 EXPECT_EQ(syncer::ControlTypes(), fake_manager_->InitialSyncEndedTypes());
318 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 306 EXPECT_TRUE(fake_manager_
319 syncer::ControlTypes()).Empty()); 307 ->GetTypesWithEmptyProgressMarkerToken(syncer::ControlTypes())
308 .Empty());
320 } 309 }
321 310
322 // Test first time sync scenario. All types should be properly configured. 311 // Test first time sync scenario. All types should be properly configured.
323 TEST_F(SyncBackendHostTest, FirstTimeSync) { 312 TEST_F(SyncBackendHostTest, FirstTimeSync) {
324 InitializeBackend(true); 313 InitializeBackend(true);
325 EXPECT_EQ(syncer::ControlTypes(), 314 EXPECT_EQ(syncer::ControlTypes(),
326 fake_manager_->GetAndResetDownloadedTypes()); 315 fake_manager_->GetAndResetDownloadedTypes());
327 EXPECT_EQ(syncer::ControlTypes(), fake_manager_->InitialSyncEndedTypes()); 316 EXPECT_EQ(syncer::ControlTypes(), fake_manager_->InitialSyncEndedTypes());
328 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 317 EXPECT_TRUE(fake_manager_
329 syncer::ControlTypes()).Empty()); 318 ->GetTypesWithEmptyProgressMarkerToken(syncer::ControlTypes())
319 .Empty());
330 320
331 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 321 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
332 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 322 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
333 syncer::ModelTypeSet()); 323 syncer::ModelTypeSet());
334 // Nigori is always downloaded so won't be ready. 324 // Nigori is always downloaded so won't be ready.
335 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 325 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(),
336 syncer::ModelTypeSet(syncer::NIGORI)), 326 syncer::ModelTypeSet(syncer::NIGORI)),
337 ready_types); 327 ready_types);
338 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( 328 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
339 Difference(enabled_types_, syncer::ControlTypes()))); 329 Difference(enabled_types_, syncer::ControlTypes())));
340 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 330 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
341 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 331 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
342 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 332 EXPECT_TRUE(
343 enabled_types_).Empty()); 333 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
334 .Empty());
344 } 335 }
345 336
346 // Test the restart after setting up sync scenario. No enabled types should be 337 // Test the restart after setting up sync scenario. No enabled types should be
347 // downloaded or cleaned. 338 // downloaded or cleaned.
348 TEST_F(SyncBackendHostTest, Restart) { 339 TEST_F(SyncBackendHostTest, Restart) {
349 sync_prefs_->SetFirstSetupComplete(); 340 sync_prefs_->SetFirstSetupComplete();
350 syncer::ModelTypeSet all_but_nigori = enabled_types_; 341 syncer::ModelTypeSet all_but_nigori = enabled_types_;
351 fake_manager_factory_->set_progress_marker_types(enabled_types_); 342 fake_manager_factory_->set_progress_marker_types(enabled_types_);
352 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); 343 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_);
353 InitializeBackend(true); 344 InitializeBackend(true);
354 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 345 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
355 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 346 EXPECT_TRUE(
356 enabled_types_).Empty()); 347 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
348 .Empty());
357 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 349 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
358 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 350 EXPECT_TRUE(
359 enabled_types_).Empty()); 351 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
352 .Empty());
360 353
361 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 354 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
362 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 355 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
363 syncer::ModelTypeSet()); 356 syncer::ModelTypeSet());
364 EXPECT_EQ(enabled_types_, ready_types); 357 EXPECT_EQ(enabled_types_, ready_types);
365 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 358 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
366 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 359 EXPECT_TRUE(
367 enabled_types_).Empty()); 360 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
361 .Empty());
368 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 362 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
369 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 363 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
370 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 364 EXPECT_TRUE(
371 enabled_types_).Empty()); 365 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
366 .Empty());
372 } 367 }
373 368
374 // Test a sync restart scenario where some types had never finished configuring. 369 // Test a sync restart scenario where some types had never finished configuring.
375 // The partial types should be purged, then reconfigured properly. 370 // The partial types should be purged, then reconfigured properly.
376 TEST_F(SyncBackendHostTest, PartialTypes) { 371 TEST_F(SyncBackendHostTest, PartialTypes) {
377 sync_prefs_->SetFirstSetupComplete(); 372 sync_prefs_->SetFirstSetupComplete();
378 // Set sync manager behavior before passing it down. All types have progress 373 // Set sync manager behavior before passing it down. All types have progress
379 // markers, but nigori and bookmarks are missing initial sync ended. 374 // markers, but nigori and bookmarks are missing initial sync ended.
380 syncer::ModelTypeSet partial_types(syncer::NIGORI, syncer::BOOKMARKS); 375 syncer::ModelTypeSet partial_types(syncer::NIGORI, syncer::BOOKMARKS);
381 syncer::ModelTypeSet full_types = 376 syncer::ModelTypeSet full_types = Difference(enabled_types_, partial_types);
382 Difference(enabled_types_, partial_types);
383 fake_manager_factory_->set_progress_marker_types(enabled_types_); 377 fake_manager_factory_->set_progress_marker_types(enabled_types_);
384 fake_manager_factory_->set_initial_sync_ended_types(full_types); 378 fake_manager_factory_->set_initial_sync_ended_types(full_types);
385 379
386 // Bringing up the backend should purge all partial types, then proceed to 380 // Bringing up the backend should purge all partial types, then proceed to
387 // download the Nigori. 381 // download the Nigori.
388 InitializeBackend(true); 382 InitializeBackend(true);
389 EXPECT_EQ(syncer::ModelTypeSet(syncer::NIGORI), 383 EXPECT_EQ(syncer::ModelTypeSet(syncer::NIGORI),
390 fake_manager_->GetAndResetDownloadedTypes()); 384 fake_manager_->GetAndResetDownloadedTypes());
391 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types)); 385 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types));
392 EXPECT_EQ(Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)), 386 EXPECT_EQ(Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)),
393 fake_manager_->InitialSyncEndedTypes()); 387 fake_manager_->InitialSyncEndedTypes());
394 EXPECT_EQ( 388 EXPECT_EQ(
395 Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI)), 389 Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI)),
396 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)); 390 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_));
397 391
398 // Now do the actual configuration, which should download and apply bookmarks. 392 // Now do the actual configuration, which should download and apply bookmarks.
399 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 393 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
400 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 394 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
401 syncer::ModelTypeSet()); 395 syncer::ModelTypeSet());
402 EXPECT_EQ(full_types, ready_types); 396 EXPECT_EQ(full_types, ready_types);
403 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 397 EXPECT_TRUE(
404 enabled_types_).Empty()); 398 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
399 .Empty());
405 EXPECT_EQ(partial_types, fake_manager_->GetAndResetDownloadedTypes()); 400 EXPECT_EQ(partial_types, fake_manager_->GetAndResetDownloadedTypes());
406 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 401 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
407 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 402 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
408 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 403 EXPECT_TRUE(
409 enabled_types_).Empty()); 404 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
405 .Empty());
410 } 406 }
411 407
412 // Test the behavior when we lose the sync db. Although we already have types 408 // Test the behavior when we lose the sync db. Although we already have types
413 // enabled, we should re-download all of them because we lost their data. 409 // enabled, we should re-download all of them because we lost their data.
414 TEST_F(SyncBackendHostTest, LostDB) { 410 TEST_F(SyncBackendHostTest, LostDB) {
415 sync_prefs_->SetFirstSetupComplete(); 411 sync_prefs_->SetFirstSetupComplete();
416 // Initialization should fetch the Nigori node. Everything else should be 412 // Initialization should fetch the Nigori node. Everything else should be
417 // left untouched. 413 // left untouched.
418 InitializeBackend(true); 414 InitializeBackend(true);
419 EXPECT_EQ(syncer::ModelTypeSet(syncer::ControlTypes()), 415 EXPECT_EQ(syncer::ModelTypeSet(syncer::ControlTypes()),
(...skipping 11 matching lines...) Expand all
431 // The actual configuration should redownload and apply all the enabled types. 427 // The actual configuration should redownload and apply all the enabled types.
432 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 428 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
433 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 429 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
434 syncer::ModelTypeSet()); 430 syncer::ModelTypeSet());
435 // Nigori is always downloaded so won't be ready. 431 // Nigori is always downloaded so won't be ready.
436 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 432 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(),
437 syncer::ModelTypeSet(syncer::NIGORI)), 433 syncer::ModelTypeSet(syncer::NIGORI)),
438 ready_types); 434 ready_types);
439 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( 435 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
440 Difference(enabled_types_, syncer::ControlTypes()))); 436 Difference(enabled_types_, syncer::ControlTypes())));
441 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 437 EXPECT_TRUE(
442 enabled_types_).Empty()); 438 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
439 .Empty());
443 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 440 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
444 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 441 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
445 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 442 EXPECT_TRUE(
446 enabled_types_).Empty()); 443 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
444 .Empty());
447 } 445 }
448 446
449 TEST_F(SyncBackendHostTest, DisableTypes) { 447 TEST_F(SyncBackendHostTest, DisableTypes) {
450 // Simulate first time sync. 448 // Simulate first time sync.
451 InitializeBackend(true); 449 InitializeBackend(true);
452 fake_manager_->GetAndResetCleanedTypes(); 450 fake_manager_->GetAndResetCleanedTypes();
453 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 451 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
454 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 452 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
455 syncer::ModelTypeSet()); 453 syncer::ModelTypeSet());
456 // Nigori is always downloaded so won't be ready. 454 // Nigori is always downloaded so won't be ready.
457 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 455 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(),
458 syncer::ModelTypeSet(syncer::NIGORI)), 456 syncer::ModelTypeSet(syncer::NIGORI)),
459 ready_types); 457 ready_types);
460 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); 458 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes());
461 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 459 EXPECT_TRUE(
462 enabled_types_).Empty()); 460 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
461 .Empty());
463 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 462 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
464 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 463 EXPECT_TRUE(
465 enabled_types_).Empty()); 464 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
465 .Empty());
466 466
467 // Then disable two datatypes. 467 // Then disable two datatypes.
468 syncer::ModelTypeSet disabled_types(syncer::BOOKMARKS, 468 syncer::ModelTypeSet disabled_types(syncer::BOOKMARKS,
469 syncer::SEARCH_ENGINES); 469 syncer::SEARCH_ENGINES);
470 syncer::ModelTypeSet old_types = enabled_types_; 470 syncer::ModelTypeSet old_types = enabled_types_;
471 enabled_types_.RemoveAll(disabled_types); 471 enabled_types_.RemoveAll(disabled_types);
472 ready_types = ConfigureDataTypes( 472 ready_types = ConfigureDataTypes(
473 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 473 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
474 syncer::ModelTypeSet()); 474 syncer::ModelTypeSet());
475 475
476 // Only those datatypes disabled should be cleaned. Nothing should be 476 // Only those datatypes disabled should be cleaned. Nothing should be
477 // downloaded. 477 // downloaded.
478 EXPECT_EQ(enabled_types_, ready_types); 478 EXPECT_EQ(enabled_types_, ready_types);
479 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 479 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
480 EXPECT_EQ(disabled_types, 480 EXPECT_EQ(disabled_types,
481 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)); 481 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types));
482 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 482 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
483 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 483 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
484 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 484 EXPECT_TRUE(
485 enabled_types_).Empty()); 485 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
486 .Empty());
486 } 487 }
487 488
488 TEST_F(SyncBackendHostTest, AddTypes) { 489 TEST_F(SyncBackendHostTest, AddTypes) {
489 // Simulate first time sync. 490 // Simulate first time sync.
490 InitializeBackend(true); 491 InitializeBackend(true);
491 fake_manager_->GetAndResetCleanedTypes(); 492 fake_manager_->GetAndResetCleanedTypes();
492 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 493 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
493 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 494 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
494 syncer::ModelTypeSet()); 495 syncer::ModelTypeSet());
495 // Nigori is always downloaded so won't be ready. 496 // Nigori is always downloaded so won't be ready.
496 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 497 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(),
497 syncer::ModelTypeSet(syncer::NIGORI)), 498 syncer::ModelTypeSet(syncer::NIGORI)),
498 ready_types); 499 ready_types);
499 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); 500 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes());
500 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 501 EXPECT_TRUE(
501 enabled_types_).Empty()); 502 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
503 .Empty());
502 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 504 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
503 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 505 EXPECT_TRUE(
504 enabled_types_).Empty()); 506 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
507 .Empty());
505 508
506 // Then add two datatypes. 509 // Then add two datatypes.
507 syncer::ModelTypeSet new_types(syncer::EXTENSIONS, 510 syncer::ModelTypeSet new_types(syncer::EXTENSIONS, syncer::APPS);
508 syncer::APPS);
509 enabled_types_.PutAll(new_types); 511 enabled_types_.PutAll(new_types);
510 ready_types = ConfigureDataTypes( 512 ready_types = ConfigureDataTypes(
511 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 513 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
512 syncer::ModelTypeSet()); 514 syncer::ModelTypeSet());
513 515
514 // Only those datatypes added should be downloaded (plus nigori). Nothing 516 // Only those datatypes added should be downloaded (plus nigori). Nothing
515 // should be cleaned aside from the disabled types. 517 // should be cleaned aside from the disabled types.
516 new_types.Put(syncer::NIGORI); 518 new_types.Put(syncer::NIGORI);
517 EXPECT_EQ(syncer::Difference(enabled_types_, new_types), ready_types); 519 EXPECT_EQ(syncer::Difference(enabled_types_, new_types), ready_types);
518 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 520 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
519 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 521 EXPECT_TRUE(
520 enabled_types_).Empty()); 522 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
523 .Empty());
521 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 524 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
522 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 525 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
523 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 526 EXPECT_TRUE(
524 enabled_types_).Empty()); 527 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
528 .Empty());
525 } 529 }
526 530
527 // And and disable in the same configuration. 531 // And and disable in the same configuration.
528 TEST_F(SyncBackendHostTest, AddDisableTypes) { 532 TEST_F(SyncBackendHostTest, AddDisableTypes) {
529 // Simulate first time sync. 533 // Simulate first time sync.
530 InitializeBackend(true); 534 InitializeBackend(true);
531 fake_manager_->GetAndResetCleanedTypes(); 535 fake_manager_->GetAndResetCleanedTypes();
532 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 536 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
533 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 537 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
534 syncer::ModelTypeSet()); 538 syncer::ModelTypeSet());
535 // Nigori is always downloaded so won't be ready. 539 // Nigori is always downloaded so won't be ready.
536 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 540 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(),
537 syncer::ModelTypeSet(syncer::NIGORI)), 541 syncer::ModelTypeSet(syncer::NIGORI)),
538 ready_types); 542 ready_types);
539 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); 543 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes());
540 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 544 EXPECT_TRUE(
541 enabled_types_).Empty()); 545 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
546 .Empty());
542 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 547 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
543 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 548 EXPECT_TRUE(
544 enabled_types_).Empty()); 549 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
550 .Empty());
545 551
546 // Then add two datatypes. 552 // Then add two datatypes.
547 syncer::ModelTypeSet old_types = enabled_types_; 553 syncer::ModelTypeSet old_types = enabled_types_;
548 syncer::ModelTypeSet disabled_types(syncer::BOOKMARKS, 554 syncer::ModelTypeSet disabled_types(syncer::BOOKMARKS,
549 syncer::SEARCH_ENGINES); 555 syncer::SEARCH_ENGINES);
550 syncer::ModelTypeSet new_types(syncer::EXTENSIONS, 556 syncer::ModelTypeSet new_types(syncer::EXTENSIONS, syncer::APPS);
551 syncer::APPS);
552 enabled_types_.PutAll(new_types); 557 enabled_types_.PutAll(new_types);
553 enabled_types_.RemoveAll(disabled_types); 558 enabled_types_.RemoveAll(disabled_types);
554 ready_types = ConfigureDataTypes( 559 ready_types = ConfigureDataTypes(
555 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 560 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
556 syncer::ModelTypeSet()); 561 syncer::ModelTypeSet());
557 562
558 // Only those datatypes added should be downloaded (plus nigori). Nothing 563 // Only those datatypes added should be downloaded (plus nigori). Nothing
559 // should be cleaned aside from the disabled types. 564 // should be cleaned aside from the disabled types.
560 new_types.Put(syncer::NIGORI); 565 new_types.Put(syncer::NIGORI);
561 EXPECT_EQ(syncer::Difference(enabled_types_, new_types), ready_types); 566 EXPECT_EQ(syncer::Difference(enabled_types_, new_types), ready_types);
(...skipping 15 matching lines...) Expand all
577 syncer::ModelTypeSet old_types = enabled_types_; 582 syncer::ModelTypeSet old_types = enabled_types_;
578 fake_manager_factory_->set_progress_marker_types(old_types); 583 fake_manager_factory_->set_progress_marker_types(old_types);
579 fake_manager_factory_->set_initial_sync_ended_types(old_types); 584 fake_manager_factory_->set_initial_sync_ended_types(old_types);
580 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS, 585 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS,
581 syncer::EXTENSION_SETTINGS); 586 syncer::EXTENSION_SETTINGS);
582 enabled_types_.PutAll(new_types); 587 enabled_types_.PutAll(new_types);
583 588
584 // Does nothing. 589 // Does nothing.
585 InitializeBackend(true); 590 InitializeBackend(true);
586 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 591 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
587 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 592 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)
588 old_types).Empty()); 593 .Empty());
589 EXPECT_EQ(old_types, fake_manager_->InitialSyncEndedTypes()); 594 EXPECT_EQ(old_types, fake_manager_->InitialSyncEndedTypes());
590 EXPECT_EQ(new_types, fake_manager_->GetTypesWithEmptyProgressMarkerToken( 595 EXPECT_EQ(new_types, fake_manager_->GetTypesWithEmptyProgressMarkerToken(
591 enabled_types_)); 596 enabled_types_));
592 597
593 // Downloads and applies the new types (plus nigori). 598 // Downloads and applies the new types (plus nigori).
594 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 599 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
595 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 600 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
596 syncer::ModelTypeSet()); 601 syncer::ModelTypeSet());
597 602
598 new_types.Put(syncer::NIGORI); 603 new_types.Put(syncer::NIGORI);
599 EXPECT_EQ(syncer::Difference(old_types, syncer::ModelTypeSet(syncer::NIGORI)), 604 EXPECT_EQ(syncer::Difference(old_types, syncer::ModelTypeSet(syncer::NIGORI)),
600 ready_types); 605 ready_types);
601 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 606 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
602 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 607 EXPECT_TRUE(
603 enabled_types_).Empty()); 608 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
609 .Empty());
604 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 610 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
605 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 611 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
606 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 612 EXPECT_TRUE(
607 enabled_types_).Empty()); 613 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
614 .Empty());
608 } 615 }
609 616
610 // Test the newly supported types scenario, but with the presence of partial 617 // Test the newly supported types scenario, but with the presence of partial
611 // types as well. Both partial and newly supported types should be downloaded 618 // types as well. Both partial and newly supported types should be downloaded
612 // the configuration. 619 // the configuration.
613 TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) { 620 TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) {
614 sync_prefs_->SetFirstSetupComplete(); 621 sync_prefs_->SetFirstSetupComplete();
615 // Set sync manager behavior before passing it down. All types have progress 622 // Set sync manager behavior before passing it down. All types have progress
616 // markers and initial sync ended except the new types. 623 // markers and initial sync ended except the new types.
617 syncer::ModelTypeSet old_types = enabled_types_; 624 syncer::ModelTypeSet old_types = enabled_types_;
618 syncer::ModelTypeSet partial_types(syncer::NIGORI, syncer::BOOKMARKS); 625 syncer::ModelTypeSet partial_types(syncer::NIGORI, syncer::BOOKMARKS);
619 syncer::ModelTypeSet full_types = 626 syncer::ModelTypeSet full_types = Difference(enabled_types_, partial_types);
620 Difference(enabled_types_, partial_types);
621 fake_manager_factory_->set_progress_marker_types(old_types); 627 fake_manager_factory_->set_progress_marker_types(old_types);
622 fake_manager_factory_->set_initial_sync_ended_types(full_types); 628 fake_manager_factory_->set_initial_sync_ended_types(full_types);
623 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS, 629 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS,
624 syncer::EXTENSION_SETTINGS); 630 syncer::EXTENSION_SETTINGS);
625 enabled_types_.PutAll(new_types); 631 enabled_types_.PutAll(new_types);
626 632
627 // Purge the partial types. The nigori will be among the purged types, but 633 // Purge the partial types. The nigori will be among the purged types, but
628 // the syncer will re-download it by the time the initialization is complete. 634 // the syncer will re-download it by the time the initialization is complete.
629 InitializeBackend(true); 635 InitializeBackend(true);
630 EXPECT_EQ(syncer::ModelTypeSet(syncer::NIGORI), 636 EXPECT_EQ(syncer::ModelTypeSet(syncer::NIGORI),
631 fake_manager_->GetAndResetDownloadedTypes()); 637 fake_manager_->GetAndResetDownloadedTypes());
632 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types)); 638 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types));
633 EXPECT_EQ(syncer::Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)), 639 EXPECT_EQ(syncer::Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)),
634 fake_manager_->InitialSyncEndedTypes()); 640 fake_manager_->InitialSyncEndedTypes());
635 EXPECT_EQ( 641 EXPECT_EQ(
636 Union(new_types, 642 Union(new_types,
637 Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI))), 643 Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI))),
638 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)); 644 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_));
639 645
640 // Downloads and applies the new types and partial types (which includes 646 // Downloads and applies the new types and partial types (which includes
641 // nigori anyways). 647 // nigori anyways).
642 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 648 syncer::ModelTypeSet ready_types = ConfigureDataTypes(
643 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 649 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
644 syncer::ModelTypeSet()); 650 syncer::ModelTypeSet());
645 EXPECT_EQ(full_types, ready_types); 651 EXPECT_EQ(full_types, ready_types);
646 EXPECT_EQ(Union(new_types, partial_types), 652 EXPECT_EQ(Union(new_types, partial_types),
647 fake_manager_->GetAndResetDownloadedTypes()); 653 fake_manager_->GetAndResetDownloadedTypes());
648 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 654 EXPECT_TRUE(
649 enabled_types_).Empty()); 655 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
656 .Empty());
650 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 657 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
651 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 658 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
652 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 659 EXPECT_TRUE(
653 enabled_types_).Empty()); 660 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
661 .Empty());
654 } 662 }
655 663
656 // Verify that downloading control types only downloads those types that do 664 // Verify that downloading control types only downloads those types that do
657 // not have initial sync ended set. 665 // not have initial sync ended set.
658 TEST_F(SyncBackendHostTest, DownloadControlTypes) { 666 TEST_F(SyncBackendHostTest, DownloadControlTypes) {
659 sync_prefs_->SetFirstSetupComplete(); 667 sync_prefs_->SetFirstSetupComplete();
660 // Set sync manager behavior before passing it down. Experiments and device 668 // Set sync manager behavior before passing it down. Experiments and device
661 // info are new types without progress markers or initial sync ended, while 669 // info are new types without progress markers or initial sync ended, while
662 // all other types have been fully downloaded and applied. 670 // all other types have been fully downloaded and applied.
663 syncer::ModelTypeSet new_types(syncer::EXPERIMENTS, syncer::NIGORI); 671 syncer::ModelTypeSet new_types(syncer::EXPERIMENTS, syncer::NIGORI);
664 syncer::ModelTypeSet old_types = 672 syncer::ModelTypeSet old_types = Difference(enabled_types_, new_types);
665 Difference(enabled_types_, new_types);
666 fake_manager_factory_->set_progress_marker_types(old_types); 673 fake_manager_factory_->set_progress_marker_types(old_types);
667 fake_manager_factory_->set_initial_sync_ended_types(old_types); 674 fake_manager_factory_->set_initial_sync_ended_types(old_types);
668 675
669 // Bringing up the backend should download the new types without downloading 676 // Bringing up the backend should download the new types without downloading
670 // any old types. 677 // any old types.
671 InitializeBackend(true); 678 InitializeBackend(true);
672 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 679 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
673 EXPECT_EQ(Difference(syncer::ModelTypeSet::All(), enabled_types_), 680 EXPECT_EQ(Difference(syncer::ModelTypeSet::All(), enabled_types_),
674 fake_manager_->GetAndResetCleanedTypes()); 681 fake_manager_->GetAndResetCleanedTypes());
675 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 682 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
676 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 683 EXPECT_TRUE(
677 enabled_types_).Empty()); 684 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
685 .Empty());
678 } 686 }
679 687
680 // Fail to download control types. It's believed that there is a server bug 688 // Fail to download control types. It's believed that there is a server bug
681 // which can allow this to happen (crbug.com/164288). The sync backend host 689 // which can allow this to happen (crbug.com/164288). The sync backend host
682 // should detect this condition and fail to initialize the backend. 690 // should detect this condition and fail to initialize the backend.
683 // 691 //
684 // The failure is "silent" in the sense that the GetUpdates request appears to 692 // The failure is "silent" in the sense that the GetUpdates request appears to
685 // be successful, but it returned no results. This means that the usual 693 // be successful, but it returned no results. This means that the usual
686 // download retry logic will not be invoked. 694 // download retry logic will not be invoked.
687 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) { 695 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) {
(...skipping 30 matching lines...) Expand all
718 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); 726 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_);
719 InitializeBackend(true); 727 InitializeBackend(true);
720 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, 728 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE,
721 fake_manager_->GetAndResetConfigureReason()); 729 fake_manager_->GetAndResetConfigureReason());
722 } 730 }
723 731
724 // It is SyncBackendHostCore responsibility to cleanup Sync Data folder if sync 732 // It is SyncBackendHostCore responsibility to cleanup Sync Data folder if sync
725 // setup hasn't been completed. This test ensures that cleanup happens. 733 // setup hasn't been completed. This test ensures that cleanup happens.
726 TEST_F(SyncBackendHostTest, TestStartupWithOldSyncData) { 734 TEST_F(SyncBackendHostTest, TestStartupWithOldSyncData) {
727 const char* nonsense = "slon"; 735 const char* nonsense = "slon";
728 base::FilePath temp_directory = temp_dir_.path().Append( 736 base::FilePath temp_directory =
729 base::FilePath(kTestSyncDir)); 737 temp_dir_.path().Append(base::FilePath(kTestSyncDir));
730 base::FilePath sync_file = temp_directory.AppendASCII("SyncData.sqlite3"); 738 base::FilePath sync_file = temp_directory.AppendASCII("SyncData.sqlite3");
731 ASSERT_TRUE(base::CreateDirectory(temp_directory)); 739 ASSERT_TRUE(base::CreateDirectory(temp_directory));
732 ASSERT_NE(-1, base::WriteFile(sync_file, nonsense, strlen(nonsense))); 740 ASSERT_NE(-1, base::WriteFile(sync_file, nonsense, strlen(nonsense)));
733 741
734 InitializeBackend(true); 742 InitializeBackend(true);
735 743
736 EXPECT_FALSE(base::PathExists(sync_file)); 744 EXPECT_FALSE(base::PathExists(sync_file));
737 } 745 }
738 746
739 // If bookmarks encounter an error that results in disabling without purging 747 // If bookmarks encounter an error that results in disabling without purging
(...skipping 13 matching lines...) Expand all
753 // Nigori is always downloaded so won't be ready. 761 // Nigori is always downloaded so won't be ready.
754 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 762 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(),
755 syncer::ModelTypeSet(syncer::NIGORI)), 763 syncer::ModelTypeSet(syncer::NIGORI)),
756 ready_types); 764 ready_types);
757 765
758 // Then mark the error types as unready (disables without purging). 766 // Then mark the error types as unready (disables without purging).
759 ready_types = ConfigureDataTypes( 767 ready_types = ConfigureDataTypes(
760 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 768 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
761 error_types); 769 error_types);
762 EXPECT_EQ(syncer::Difference(enabled_types_, error_types), ready_types); 770 EXPECT_EQ(syncer::Difference(enabled_types_, error_types), ready_types);
763 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 771 EXPECT_TRUE(
764 error_types).Empty()); 772 fake_manager_->GetTypesWithEmptyProgressMarkerToken(error_types).Empty());
765 773
766 // Lastly explicitly disable the error types, which should result in a purge. 774 // Lastly explicitly disable the error types, which should result in a purge.
767 enabled_types_.RemoveAll(error_types); 775 enabled_types_.RemoveAll(error_types);
768 ready_types = ConfigureDataTypes( 776 ready_types = ConfigureDataTypes(
769 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 777 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_),
770 syncer::ModelTypeSet()); 778 syncer::ModelTypeSet());
771 EXPECT_EQ(syncer::Difference(enabled_types_, error_types), ready_types); 779 EXPECT_EQ(syncer::Difference(enabled_types_, error_types), ready_types);
772 EXPECT_FALSE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 780 EXPECT_FALSE(
773 error_types).Empty()); 781 fake_manager_->GetTypesWithEmptyProgressMarkerToken(error_types).Empty());
774 } 782 }
775 783
776 // Test that a call to ClearServerData is forwarded to the underlying 784 // Test that a call to ClearServerData is forwarded to the underlying
777 // SyncManager. 785 // SyncManager.
778 TEST_F(SyncBackendHostTest, ClearServerDataCallsAreForwarded) { 786 TEST_F(SyncBackendHostTest, ClearServerDataCallsAreForwarded) {
779 InitializeBackend(true); 787 InitializeBackend(true);
780 syncer::CallbackCounter callback_counter; 788 syncer::CallbackCounter callback_counter;
781 backend_->ClearServerData(base::Bind(&syncer::CallbackCounter::Callback, 789 backend_->ClearServerData(base::Bind(&syncer::CallbackCounter::Callback,
782 base::Unretained(&callback_counter))); 790 base::Unretained(&callback_counter)));
783 fake_manager_->WaitForSyncThread(); 791 fake_manager_->WaitForSyncThread();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 backend_->StopSyncingForShutdown(); 861 backend_->StopSyncingForShutdown();
854 // Verify that call to DeactivateNonBlockingDataType doesn't assert. 862 // Verify that call to DeactivateNonBlockingDataType doesn't assert.
855 backend_->DeactivateNonBlockingDataType(syncer::AUTOFILL); 863 backend_->DeactivateNonBlockingDataType(syncer::AUTOFILL);
856 backend_->Shutdown(syncer::STOP_SYNC); 864 backend_->Shutdown(syncer::STOP_SYNC);
857 backend_.reset(); 865 backend_.reset();
858 } 866 }
859 867
860 } // namespace 868 } // namespace
861 869
862 } // namespace browser_sync 870 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync/driver/glue/sync_backend_host_impl.cc ('k') | components/sync/driver/glue/sync_backend_host_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698