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

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

Issue 2388163002: [Sync] Move //components/sync to the syncer namespace, take 2. (Closed)
Patch Set: Rebase. Created 4 years, 2 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>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
56 using syncer::FakeSyncManager;
57 using syncer::SyncManager;
58 using ::testing::InvokeWithoutArgs; 56 using ::testing::InvokeWithoutArgs;
59 using ::testing::StrictMock; 57 using ::testing::StrictMock;
60 using ::testing::_; 58 using ::testing::_;
61 59
62 namespace browser_sync { 60 namespace syncer {
63 61
64 namespace { 62 namespace {
65 63
66 static const base::FilePath::CharType kTestSyncDir[] = 64 static const base::FilePath::CharType kTestSyncDir[] =
67 FILE_PATH_LITERAL("sync-test"); 65 FILE_PATH_LITERAL("sync-test");
68 66
69 ACTION_P(Signal, event) { 67 ACTION_P(Signal, event) {
70 event->Signal(); 68 event->Signal();
71 } 69 }
72 70
73 void EmptyNetworkTimeUpdate(const base::Time&, 71 void EmptyNetworkTimeUpdate(const base::Time&,
74 const base::TimeDelta&, 72 const base::TimeDelta&,
75 const base::TimeDelta&) {} 73 const base::TimeDelta&) {}
76 74
77 void QuitMessageLoop() { 75 void QuitMessageLoop() {
78 base::MessageLoop::current()->QuitWhenIdle(); 76 base::MessageLoop::current()->QuitWhenIdle();
79 } 77 }
80 78
81 class MockSyncFrontend : public sync_driver::SyncFrontend { 79 class MockSyncFrontend : public SyncFrontend {
82 public: 80 public:
83 virtual ~MockSyncFrontend() {} 81 virtual ~MockSyncFrontend() {}
84 82
85 MOCK_METHOD4( 83 MOCK_METHOD4(OnBackendInitialized,
86 OnBackendInitialized, 84 void(const WeakHandle<JsBackend>&,
87 void(const syncer::WeakHandle<syncer::JsBackend>&, 85 const WeakHandle<DataTypeDebugInfoListener>&,
88 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&, 86 const std::string&,
89 const std::string&, 87 bool));
90 bool));
91 MOCK_METHOD0(OnSyncCycleCompleted, void()); 88 MOCK_METHOD0(OnSyncCycleCompleted, void());
92 MOCK_METHOD1(OnConnectionStatusChange, void(syncer::ConnectionStatus status)); 89 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus status));
93 MOCK_METHOD0(OnClearServerDataSucceeded, void()); 90 MOCK_METHOD0(OnClearServerDataSucceeded, void());
94 MOCK_METHOD0(OnClearServerDataFailed, void()); 91 MOCK_METHOD0(OnClearServerDataFailed, void());
95 MOCK_METHOD2(OnPassphraseRequired, 92 MOCK_METHOD2(OnPassphraseRequired,
96 void(syncer::PassphraseRequiredReason, 93 void(PassphraseRequiredReason, const sync_pb::EncryptedData&));
97 const sync_pb::EncryptedData&));
98 MOCK_METHOD0(OnPassphraseAccepted, void()); 94 MOCK_METHOD0(OnPassphraseAccepted, void());
99 MOCK_METHOD2(OnEncryptedTypesChanged, void(syncer::ModelTypeSet, bool)); 95 MOCK_METHOD2(OnEncryptedTypesChanged, void(ModelTypeSet, bool));
100 MOCK_METHOD0(OnEncryptionComplete, void()); 96 MOCK_METHOD0(OnEncryptionComplete, void());
101 MOCK_METHOD1(OnMigrationNeededForTypes, void(syncer::ModelTypeSet)); 97 MOCK_METHOD1(OnMigrationNeededForTypes, void(ModelTypeSet));
102 MOCK_METHOD1(OnProtocolEvent, void(const syncer::ProtocolEvent&)); 98 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&));
103 MOCK_METHOD2(OnDirectoryTypeCommitCounterUpdated, 99 MOCK_METHOD2(OnDirectoryTypeCommitCounterUpdated,
104 void(syncer::ModelType, const syncer::CommitCounters&)); 100 void(ModelType, const CommitCounters&));
105 MOCK_METHOD2(OnDirectoryTypeUpdateCounterUpdated, 101 MOCK_METHOD2(OnDirectoryTypeUpdateCounterUpdated,
106 void(syncer::ModelType, const syncer::UpdateCounters&)); 102 void(ModelType, const UpdateCounters&));
107 MOCK_METHOD2(OnDirectoryTypeStatusCounterUpdated, 103 MOCK_METHOD2(OnDirectoryTypeStatusCounterUpdated,
108 void(syncer::ModelType, const syncer::StatusCounters&)); 104 void(ModelType, const StatusCounters&));
109 MOCK_METHOD1(OnExperimentsChanged, void(const syncer::Experiments&)); 105 MOCK_METHOD1(OnExperimentsChanged, void(const Experiments&));
110 MOCK_METHOD1(OnActionableError, 106 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError& sync_error));
111 void(const syncer::SyncProtocolError& sync_error));
112 MOCK_METHOD0(OnSyncConfigureRetry, void()); 107 MOCK_METHOD0(OnSyncConfigureRetry, void());
113 MOCK_METHOD1( 108 MOCK_METHOD1(OnLocalSetPassphraseEncryption,
114 OnLocalSetPassphraseEncryption, 109 void(const SyncEncryptionHandler::NigoriState& nigori_state));
115 void(const syncer::SyncEncryptionHandler::NigoriState& nigori_state));
116 }; 110 };
117 111
118 class FakeSyncManagerFactory : public syncer::SyncManagerFactory { 112 class FakeSyncManagerFactory : public SyncManagerFactory {
119 public: 113 public:
120 explicit FakeSyncManagerFactory(FakeSyncManager** fake_manager) 114 explicit FakeSyncManagerFactory(FakeSyncManager** fake_manager)
121 : fake_manager_(fake_manager) { 115 : fake_manager_(fake_manager) {
122 *fake_manager_ = NULL; 116 *fake_manager_ = NULL;
123 } 117 }
124 ~FakeSyncManagerFactory() override {} 118 ~FakeSyncManagerFactory() override {}
125 119
126 // SyncManagerFactory implementation. Called on the sync thread. 120 // SyncManagerFactory implementation. Called on the sync thread.
127 std::unique_ptr<SyncManager> CreateSyncManager( 121 std::unique_ptr<SyncManager> CreateSyncManager(
128 const std::string& /* name */) override { 122 const std::string& /* name */) override {
129 *fake_manager_ = 123 *fake_manager_ =
130 new FakeSyncManager(initial_sync_ended_types_, progress_marker_types_, 124 new FakeSyncManager(initial_sync_ended_types_, progress_marker_types_,
131 configure_fail_types_); 125 configure_fail_types_);
132 return std::unique_ptr<SyncManager>(*fake_manager_); 126 return std::unique_ptr<SyncManager>(*fake_manager_);
133 } 127 }
134 128
135 void set_initial_sync_ended_types(syncer::ModelTypeSet types) { 129 void set_initial_sync_ended_types(ModelTypeSet types) {
136 initial_sync_ended_types_ = types; 130 initial_sync_ended_types_ = types;
137 } 131 }
138 132
139 void set_progress_marker_types(syncer::ModelTypeSet types) { 133 void set_progress_marker_types(ModelTypeSet types) {
140 progress_marker_types_ = types; 134 progress_marker_types_ = types;
141 } 135 }
142 136
143 void set_configure_fail_types(syncer::ModelTypeSet types) { 137 void set_configure_fail_types(ModelTypeSet types) {
144 configure_fail_types_ = types; 138 configure_fail_types_ = types;
145 } 139 }
146 140
147 private: 141 private:
148 syncer::ModelTypeSet initial_sync_ended_types_; 142 ModelTypeSet initial_sync_ended_types_;
149 syncer::ModelTypeSet progress_marker_types_; 143 ModelTypeSet progress_marker_types_;
150 syncer::ModelTypeSet configure_fail_types_; 144 ModelTypeSet configure_fail_types_;
151 FakeSyncManager** fake_manager_; 145 FakeSyncManager** fake_manager_;
152 }; 146 };
153 147
154 class BackendSyncClient : public sync_driver::FakeSyncClient { 148 class BackendSyncClient : public FakeSyncClient {
155 public: 149 public:
156 scoped_refptr<syncer::ModelSafeWorker> CreateModelWorkerForGroup( 150 scoped_refptr<ModelSafeWorker> CreateModelWorkerForGroup(
157 syncer::ModelSafeGroup group, 151 ModelSafeGroup group,
158 syncer::WorkerLoopDestructionObserver* observer) override { 152 WorkerLoopDestructionObserver* observer) override {
159 switch (group) { 153 switch (group) {
160 case syncer::GROUP_PASSIVE: 154 case GROUP_PASSIVE:
161 return new syncer::PassiveModelWorker(observer); 155 return new PassiveModelWorker(observer);
162 default: 156 default:
163 return nullptr; 157 return nullptr;
164 } 158 }
165 } 159 }
166 }; 160 };
167 161
168 class SyncBackendHostTest : public testing::Test { 162 class SyncBackendHostTest : public testing::Test {
169 protected: 163 protected:
170 SyncBackendHostTest() : fake_manager_(NULL) {} 164 SyncBackendHostTest() : fake_manager_(NULL) {}
171 165
172 ~SyncBackendHostTest() override {} 166 ~SyncBackendHostTest() override {}
173 167
174 void SetUp() override { 168 void SetUp() override {
175 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 169 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
176 170
177 sync_driver::SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); 171 SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
178 172
179 sync_prefs_.reset(new sync_driver::SyncPrefs(&pref_service_)); 173 sync_prefs_.reset(new SyncPrefs(&pref_service_));
180 backend_.reset(new SyncBackendHostImpl( 174 backend_.reset(new SyncBackendHostImpl(
181 "dummyDebugName", &sync_client_, base::ThreadTaskRunnerHandle::Get(), 175 "dummyDebugName", &sync_client_, base::ThreadTaskRunnerHandle::Get(),
182 nullptr, sync_prefs_->AsWeakPtr(), 176 nullptr, sync_prefs_->AsWeakPtr(),
183 temp_dir_.GetPath().Append(base::FilePath(kTestSyncDir)))); 177 temp_dir_.GetPath().Append(base::FilePath(kTestSyncDir))));
184 credentials_.account_id = "user@example.com"; 178 credentials_.account_id = "user@example.com";
185 credentials_.email = "user@example.com"; 179 credentials_.email = "user@example.com";
186 credentials_.sync_token = "sync_token"; 180 credentials_.sync_token = "sync_token";
187 credentials_.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope); 181 credentials_.scope_set.insert(GaiaConstants::kChromeSyncOAuth2Scope);
188 182
189 fake_manager_factory_.reset(new FakeSyncManagerFactory(&fake_manager_)); 183 fake_manager_factory_.reset(new FakeSyncManagerFactory(&fake_manager_));
190 184
191 // These types are always implicitly enabled. 185 // These types are always implicitly enabled.
192 enabled_types_.PutAll(syncer::ControlTypes()); 186 enabled_types_.PutAll(ControlTypes());
193 187
194 // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend 188 // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend
195 // Registrar removing them if it can't find their model workers. 189 // Registrar removing them if it can't find their model workers.
196 enabled_types_.Put(syncer::BOOKMARKS); 190 enabled_types_.Put(BOOKMARKS);
197 enabled_types_.Put(syncer::PREFERENCES); 191 enabled_types_.Put(PREFERENCES);
198 enabled_types_.Put(syncer::SESSIONS); 192 enabled_types_.Put(SESSIONS);
199 enabled_types_.Put(syncer::SEARCH_ENGINES); 193 enabled_types_.Put(SEARCH_ENGINES);
200 enabled_types_.Put(syncer::AUTOFILL); 194 enabled_types_.Put(AUTOFILL);
201 195
202 network_resources_.reset(new syncer::HttpBridgeNetworkResources()); 196 network_resources_.reset(new HttpBridgeNetworkResources());
203 } 197 }
204 198
205 void TearDown() override { 199 void TearDown() override {
206 if (backend_) { 200 if (backend_) {
207 backend_->StopSyncingForShutdown(); 201 backend_->StopSyncingForShutdown();
208 backend_->Shutdown(syncer::STOP_SYNC); 202 backend_->Shutdown(STOP_SYNC);
209 } 203 }
210 backend_.reset(); 204 backend_.reset();
211 sync_prefs_.reset(); 205 sync_prefs_.reset();
212 // Pump messages posted by the sync thread. 206 // Pump messages posted by the sync thread.
213 base::RunLoop().RunUntilIdle(); 207 base::RunLoop().RunUntilIdle();
214 } 208 }
215 209
216 // Synchronously initializes the backend. 210 // Synchronously initializes the backend.
217 void InitializeBackend(bool expect_success) { 211 void InitializeBackend(bool expect_success) {
218 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success)) 212 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success))
219 .WillOnce(InvokeWithoutArgs(QuitMessageLoop)); 213 .WillOnce(InvokeWithoutArgs(QuitMessageLoop));
220 SyncBackendHost::HttpPostProviderFactoryGetter 214 SyncBackendHost::HttpPostProviderFactoryGetter
221 http_post_provider_factory_getter = 215 http_post_provider_factory_getter =
222 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, 216 base::Bind(&NetworkResources::GetHttpPostProviderFactory,
223 base::Unretained(network_resources_.get()), nullptr, 217 base::Unretained(network_resources_.get()), nullptr,
224 base::Bind(&EmptyNetworkTimeUpdate)); 218 base::Bind(&EmptyNetworkTimeUpdate));
225 backend_->Initialize( 219 backend_->Initialize(
226 &mock_frontend_, std::unique_ptr<base::Thread>(), 220 &mock_frontend_, std::unique_ptr<base::Thread>(),
227 base::ThreadTaskRunnerHandle::Get(), 221 base::ThreadTaskRunnerHandle::Get(),
228 base::ThreadTaskRunnerHandle::Get(), 222 base::ThreadTaskRunnerHandle::Get(), WeakHandle<JsEventHandler>(),
229 syncer::WeakHandle<syncer::JsEventHandler>(), GURL(std::string()), 223 GURL(std::string()), std::string(), credentials_, true,
230 std::string(), credentials_, true, std::move(fake_manager_factory_), 224 std::move(fake_manager_factory_),
231 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()), 225 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()),
232 base::Closure(), http_post_provider_factory_getter, 226 base::Closure(), http_post_provider_factory_getter,
233 std::move(saved_nigori_state_)); 227 std::move(saved_nigori_state_));
234 base::RunLoop run_loop; 228 base::RunLoop run_loop;
235 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 229 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
236 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout()); 230 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout());
237 run_loop.Run(); 231 run_loop.Run();
238 // |fake_manager_factory_|'s fake_manager() is set on the sync 232 // |fake_manager_factory_|'s fake_manager() is set on the sync
239 // thread, but we can rely on the message loop barriers to 233 // thread, but we can rely on the message loop barriers to
240 // guarantee that we see the updated value. 234 // guarantee that we see the updated value.
241 DCHECK(fake_manager_); 235 DCHECK(fake_manager_);
242 } 236 }
243 237
244 // Synchronously configures the backend's datatypes. 238 // Synchronously configures the backend's datatypes.
245 syncer::ModelTypeSet ConfigureDataTypes( 239 ModelTypeSet ConfigureDataTypes(ModelTypeSet types_to_add,
246 syncer::ModelTypeSet types_to_add, 240 ModelTypeSet types_to_remove,
247 syncer::ModelTypeSet types_to_remove, 241 ModelTypeSet types_to_unapply) {
248 syncer::ModelTypeSet types_to_unapply) { 242 BackendDataTypeConfigurer::DataTypeConfigStateMap config_state_map;
249 sync_driver::BackendDataTypeConfigurer::DataTypeConfigStateMap 243 BackendDataTypeConfigurer::SetDataTypesState(
250 config_state_map; 244 BackendDataTypeConfigurer::CONFIGURE_ACTIVE, types_to_add,
251 sync_driver::BackendDataTypeConfigurer::SetDataTypesState(
252 sync_driver::BackendDataTypeConfigurer::CONFIGURE_ACTIVE, types_to_add,
253 &config_state_map); 245 &config_state_map);
254 sync_driver::BackendDataTypeConfigurer::SetDataTypesState( 246 BackendDataTypeConfigurer::SetDataTypesState(
255 sync_driver::BackendDataTypeConfigurer::DISABLED, types_to_remove, 247 BackendDataTypeConfigurer::DISABLED, types_to_remove,
256 &config_state_map); 248 &config_state_map);
257 sync_driver::BackendDataTypeConfigurer::SetDataTypesState( 249 BackendDataTypeConfigurer::SetDataTypesState(
258 sync_driver::BackendDataTypeConfigurer::UNREADY, types_to_unapply, 250 BackendDataTypeConfigurer::UNREADY, types_to_unapply,
259 &config_state_map); 251 &config_state_map);
260 252
261 types_to_add.PutAll(syncer::ControlTypes()); 253 types_to_add.PutAll(ControlTypes());
262 syncer::ModelTypeSet ready_types = backend_->ConfigureDataTypes( 254 ModelTypeSet ready_types = backend_->ConfigureDataTypes(
263 syncer::CONFIGURE_REASON_RECONFIGURATION, config_state_map, 255 CONFIGURE_REASON_RECONFIGURATION, config_state_map,
264 base::Bind(&SyncBackendHostTest::DownloadReady, base::Unretained(this)), 256 base::Bind(&SyncBackendHostTest::DownloadReady, base::Unretained(this)),
265 base::Bind(&SyncBackendHostTest::OnDownloadRetry, 257 base::Bind(&SyncBackendHostTest::OnDownloadRetry,
266 base::Unretained(this))); 258 base::Unretained(this)));
267 base::RunLoop run_loop; 259 base::RunLoop run_loop;
268 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 260 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
269 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout()); 261 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout());
270 run_loop.Run(); 262 run_loop.Run();
271 return ready_types; 263 return ready_types;
272 } 264 }
273 265
274 protected: 266 protected:
275 void DownloadReady(syncer::ModelTypeSet succeeded_types, 267 void DownloadReady(ModelTypeSet succeeded_types, ModelTypeSet failed_types) {
276 syncer::ModelTypeSet failed_types) {
277 base::MessageLoop::current()->QuitWhenIdle(); 268 base::MessageLoop::current()->QuitWhenIdle();
278 } 269 }
279 270
280 void OnDownloadRetry() { NOTIMPLEMENTED(); } 271 void OnDownloadRetry() { NOTIMPLEMENTED(); }
281 272
282 base::MessageLoop message_loop_; 273 base::MessageLoop message_loop_;
283 base::ScopedTempDir temp_dir_; 274 base::ScopedTempDir temp_dir_;
284 syncable_prefs::TestingPrefServiceSyncable pref_service_; 275 syncable_prefs::TestingPrefServiceSyncable pref_service_;
285 StrictMock<MockSyncFrontend> mock_frontend_; 276 StrictMock<MockSyncFrontend> mock_frontend_;
286 syncer::SyncCredentials credentials_; 277 SyncCredentials credentials_;
287 BackendSyncClient sync_client_; 278 BackendSyncClient sync_client_;
288 syncer::TestUnrecoverableErrorHandler test_unrecoverable_error_handler_; 279 TestUnrecoverableErrorHandler test_unrecoverable_error_handler_;
289 std::unique_ptr<sync_driver::SyncPrefs> sync_prefs_; 280 std::unique_ptr<SyncPrefs> sync_prefs_;
290 std::unique_ptr<SyncBackendHostImpl> backend_; 281 std::unique_ptr<SyncBackendHostImpl> backend_;
291 std::unique_ptr<FakeSyncManagerFactory> fake_manager_factory_; 282 std::unique_ptr<FakeSyncManagerFactory> fake_manager_factory_;
292 FakeSyncManager* fake_manager_; 283 FakeSyncManager* fake_manager_;
293 syncer::ModelTypeSet enabled_types_; 284 ModelTypeSet enabled_types_;
294 std::unique_ptr<syncer::NetworkResources> network_resources_; 285 std::unique_ptr<NetworkResources> network_resources_;
295 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> 286 std::unique_ptr<SyncEncryptionHandler::NigoriState> saved_nigori_state_;
296 saved_nigori_state_;
297 }; 287 };
298 288
299 // Test basic initialization with no initial types (first time initialization). 289 // Test basic initialization with no initial types (first time initialization).
300 // Only the nigori should be configured. 290 // Only the nigori should be configured.
301 TEST_F(SyncBackendHostTest, InitShutdown) { 291 TEST_F(SyncBackendHostTest, InitShutdown) {
302 InitializeBackend(true); 292 InitializeBackend(true);
303 EXPECT_EQ(syncer::ControlTypes(), 293 EXPECT_EQ(ControlTypes(), fake_manager_->GetAndResetDownloadedTypes());
304 fake_manager_->GetAndResetDownloadedTypes()); 294 EXPECT_EQ(ControlTypes(), fake_manager_->InitialSyncEndedTypes());
305 EXPECT_EQ(syncer::ControlTypes(), fake_manager_->InitialSyncEndedTypes()); 295 EXPECT_TRUE(
306 EXPECT_TRUE(fake_manager_ 296 fake_manager_->GetTypesWithEmptyProgressMarkerToken(ControlTypes())
307 ->GetTypesWithEmptyProgressMarkerToken(syncer::ControlTypes()) 297 .Empty());
308 .Empty());
309 } 298 }
310 299
311 // Test first time sync scenario. All types should be properly configured. 300 // Test first time sync scenario. All types should be properly configured.
312 TEST_F(SyncBackendHostTest, FirstTimeSync) { 301 TEST_F(SyncBackendHostTest, FirstTimeSync) {
313 InitializeBackend(true); 302 InitializeBackend(true);
314 EXPECT_EQ(syncer::ControlTypes(), 303 EXPECT_EQ(ControlTypes(), fake_manager_->GetAndResetDownloadedTypes());
315 fake_manager_->GetAndResetDownloadedTypes()); 304 EXPECT_EQ(ControlTypes(), fake_manager_->InitialSyncEndedTypes());
316 EXPECT_EQ(syncer::ControlTypes(), fake_manager_->InitialSyncEndedTypes()); 305 EXPECT_TRUE(
317 EXPECT_TRUE(fake_manager_ 306 fake_manager_->GetTypesWithEmptyProgressMarkerToken(ControlTypes())
318 ->GetTypesWithEmptyProgressMarkerToken(syncer::ControlTypes()) 307 .Empty());
319 .Empty());
320 308
321 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 309 ModelTypeSet ready_types = ConfigureDataTypes(
322 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 310 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
323 syncer::ModelTypeSet()); 311 ModelTypeSet());
324 // Nigori is always downloaded so won't be ready. 312 // Nigori is always downloaded so won't be ready.
325 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 313 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types);
326 syncer::ModelTypeSet(syncer::NIGORI)),
327 ready_types);
328 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( 314 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
329 Difference(enabled_types_, syncer::ControlTypes()))); 315 Difference(enabled_types_, ControlTypes())));
330 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 316 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
331 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 317 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
332 EXPECT_TRUE( 318 EXPECT_TRUE(
333 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 319 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
334 .Empty()); 320 .Empty());
335 } 321 }
336 322
337 // Test the restart after setting up sync scenario. No enabled types should be 323 // Test the restart after setting up sync scenario. No enabled types should be
338 // downloaded or cleaned. 324 // downloaded or cleaned.
339 TEST_F(SyncBackendHostTest, Restart) { 325 TEST_F(SyncBackendHostTest, Restart) {
340 sync_prefs_->SetFirstSetupComplete(); 326 sync_prefs_->SetFirstSetupComplete();
341 syncer::ModelTypeSet all_but_nigori = enabled_types_; 327 ModelTypeSet all_but_nigori = enabled_types_;
342 fake_manager_factory_->set_progress_marker_types(enabled_types_); 328 fake_manager_factory_->set_progress_marker_types(enabled_types_);
343 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); 329 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_);
344 InitializeBackend(true); 330 InitializeBackend(true);
345 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 331 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
346 EXPECT_TRUE( 332 EXPECT_TRUE(
347 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 333 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
348 .Empty()); 334 .Empty());
349 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 335 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
350 EXPECT_TRUE( 336 EXPECT_TRUE(
351 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 337 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
352 .Empty()); 338 .Empty());
353 339
354 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 340 ModelTypeSet ready_types = ConfigureDataTypes(
355 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 341 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
356 syncer::ModelTypeSet()); 342 ModelTypeSet());
357 EXPECT_EQ(enabled_types_, ready_types); 343 EXPECT_EQ(enabled_types_, ready_types);
358 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 344 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
359 EXPECT_TRUE( 345 EXPECT_TRUE(
360 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 346 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
361 .Empty()); 347 .Empty());
362 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 348 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
363 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 349 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
364 EXPECT_TRUE( 350 EXPECT_TRUE(
365 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 351 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
366 .Empty()); 352 .Empty());
367 } 353 }
368 354
369 // Test a sync restart scenario where some types had never finished configuring. 355 // Test a sync restart scenario where some types had never finished configuring.
370 // The partial types should be purged, then reconfigured properly. 356 // The partial types should be purged, then reconfigured properly.
371 TEST_F(SyncBackendHostTest, PartialTypes) { 357 TEST_F(SyncBackendHostTest, PartialTypes) {
372 sync_prefs_->SetFirstSetupComplete(); 358 sync_prefs_->SetFirstSetupComplete();
373 // Set sync manager behavior before passing it down. All types have progress 359 // Set sync manager behavior before passing it down. All types have progress
374 // markers, but nigori and bookmarks are missing initial sync ended. 360 // markers, but nigori and bookmarks are missing initial sync ended.
375 syncer::ModelTypeSet partial_types(syncer::NIGORI, syncer::BOOKMARKS); 361 ModelTypeSet partial_types(NIGORI, BOOKMARKS);
376 syncer::ModelTypeSet full_types = Difference(enabled_types_, partial_types); 362 ModelTypeSet full_types = Difference(enabled_types_, partial_types);
377 fake_manager_factory_->set_progress_marker_types(enabled_types_); 363 fake_manager_factory_->set_progress_marker_types(enabled_types_);
378 fake_manager_factory_->set_initial_sync_ended_types(full_types); 364 fake_manager_factory_->set_initial_sync_ended_types(full_types);
379 365
380 // Bringing up the backend should purge all partial types, then proceed to 366 // Bringing up the backend should purge all partial types, then proceed to
381 // download the Nigori. 367 // download the Nigori.
382 InitializeBackend(true); 368 InitializeBackend(true);
383 EXPECT_EQ(syncer::ModelTypeSet(syncer::NIGORI), 369 EXPECT_EQ(ModelTypeSet(NIGORI), fake_manager_->GetAndResetDownloadedTypes());
384 fake_manager_->GetAndResetDownloadedTypes());
385 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types)); 370 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types));
386 EXPECT_EQ(Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)), 371 EXPECT_EQ(Union(full_types, ModelTypeSet(NIGORI)),
387 fake_manager_->InitialSyncEndedTypes()); 372 fake_manager_->InitialSyncEndedTypes());
388 EXPECT_EQ( 373 EXPECT_EQ(
389 Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI)), 374 Difference(partial_types, ModelTypeSet(NIGORI)),
390 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)); 375 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_));
391 376
392 // Now do the actual configuration, which should download and apply bookmarks. 377 // Now do the actual configuration, which should download and apply bookmarks.
393 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 378 ModelTypeSet ready_types = ConfigureDataTypes(
394 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 379 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
395 syncer::ModelTypeSet()); 380 ModelTypeSet());
396 EXPECT_EQ(full_types, ready_types); 381 EXPECT_EQ(full_types, ready_types);
397 EXPECT_TRUE( 382 EXPECT_TRUE(
398 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 383 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
399 .Empty()); 384 .Empty());
400 EXPECT_EQ(partial_types, fake_manager_->GetAndResetDownloadedTypes()); 385 EXPECT_EQ(partial_types, fake_manager_->GetAndResetDownloadedTypes());
401 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 386 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
402 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 387 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
403 EXPECT_TRUE( 388 EXPECT_TRUE(
404 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 389 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
405 .Empty()); 390 .Empty());
406 } 391 }
407 392
408 // Test the behavior when we lose the sync db. Although we already have types 393 // Test the behavior when we lose the sync db. Although we already have types
409 // enabled, we should re-download all of them because we lost their data. 394 // enabled, we should re-download all of them because we lost their data.
410 TEST_F(SyncBackendHostTest, LostDB) { 395 TEST_F(SyncBackendHostTest, LostDB) {
411 sync_prefs_->SetFirstSetupComplete(); 396 sync_prefs_->SetFirstSetupComplete();
412 // Initialization should fetch the Nigori node. Everything else should be 397 // Initialization should fetch the Nigori node. Everything else should be
413 // left untouched. 398 // left untouched.
414 InitializeBackend(true); 399 InitializeBackend(true);
415 EXPECT_EQ(syncer::ModelTypeSet(syncer::ControlTypes()), 400 EXPECT_EQ(ModelTypeSet(ControlTypes()),
416 fake_manager_->GetAndResetDownloadedTypes()); 401 fake_manager_->GetAndResetDownloadedTypes());
417 EXPECT_EQ(syncer::ModelTypeSet(syncer::ControlTypes()), 402 EXPECT_EQ(ModelTypeSet(ControlTypes()),
418 fake_manager_->InitialSyncEndedTypes()); 403 fake_manager_->InitialSyncEndedTypes());
419 EXPECT_EQ( 404 EXPECT_EQ(
420 Difference(enabled_types_, syncer::ControlTypes()), 405 Difference(enabled_types_, ControlTypes()),
421 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)); 406 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_));
422 407
423 // The database was empty, so any cleaning is entirely optional. We want to 408 // The database was empty, so any cleaning is entirely optional. We want to
424 // reset this value before running the next part of the test, though. 409 // reset this value before running the next part of the test, though.
425 fake_manager_->GetAndResetCleanedTypes(); 410 fake_manager_->GetAndResetCleanedTypes();
426 411
427 // The actual configuration should redownload and apply all the enabled types. 412 // The actual configuration should redownload and apply all the enabled types.
428 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 413 ModelTypeSet ready_types = ConfigureDataTypes(
429 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 414 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
430 syncer::ModelTypeSet()); 415 ModelTypeSet());
431 // Nigori is always downloaded so won't be ready. 416 // Nigori is always downloaded so won't be ready.
432 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 417 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types);
433 syncer::ModelTypeSet(syncer::NIGORI)),
434 ready_types);
435 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll( 418 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().HasAll(
436 Difference(enabled_types_, syncer::ControlTypes()))); 419 Difference(enabled_types_, ControlTypes())));
437 EXPECT_TRUE( 420 EXPECT_TRUE(
438 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 421 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
439 .Empty()); 422 .Empty());
440 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 423 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
441 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 424 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
442 EXPECT_TRUE( 425 EXPECT_TRUE(
443 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 426 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
444 .Empty()); 427 .Empty());
445 } 428 }
446 429
447 TEST_F(SyncBackendHostTest, DisableTypes) { 430 TEST_F(SyncBackendHostTest, DisableTypes) {
448 // Simulate first time sync. 431 // Simulate first time sync.
449 InitializeBackend(true); 432 InitializeBackend(true);
450 fake_manager_->GetAndResetCleanedTypes(); 433 fake_manager_->GetAndResetCleanedTypes();
451 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 434 ModelTypeSet ready_types = ConfigureDataTypes(
452 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 435 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
453 syncer::ModelTypeSet()); 436 ModelTypeSet());
454 // Nigori is always downloaded so won't be ready. 437 // Nigori is always downloaded so won't be ready.
455 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 438 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types);
456 syncer::ModelTypeSet(syncer::NIGORI)),
457 ready_types);
458 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); 439 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes());
459 EXPECT_TRUE( 440 EXPECT_TRUE(
460 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 441 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
461 .Empty()); 442 .Empty());
462 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 443 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
463 EXPECT_TRUE( 444 EXPECT_TRUE(
464 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 445 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
465 .Empty()); 446 .Empty());
466 447
467 // Then disable two datatypes. 448 // Then disable two datatypes.
468 syncer::ModelTypeSet disabled_types(syncer::BOOKMARKS, 449 ModelTypeSet disabled_types(BOOKMARKS, SEARCH_ENGINES);
469 syncer::SEARCH_ENGINES); 450 ModelTypeSet old_types = enabled_types_;
470 syncer::ModelTypeSet old_types = enabled_types_;
471 enabled_types_.RemoveAll(disabled_types); 451 enabled_types_.RemoveAll(disabled_types);
472 ready_types = ConfigureDataTypes( 452 ready_types = ConfigureDataTypes(
473 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 453 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
474 syncer::ModelTypeSet()); 454 ModelTypeSet());
475 455
476 // Only those datatypes disabled should be cleaned. Nothing should be 456 // Only those datatypes disabled should be cleaned. Nothing should be
477 // downloaded. 457 // downloaded.
478 EXPECT_EQ(enabled_types_, ready_types); 458 EXPECT_EQ(enabled_types_, ready_types);
479 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 459 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
480 EXPECT_EQ(disabled_types, 460 EXPECT_EQ(disabled_types,
481 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)); 461 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types));
482 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 462 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
483 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 463 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
484 EXPECT_TRUE( 464 EXPECT_TRUE(
485 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 465 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
486 .Empty()); 466 .Empty());
487 } 467 }
488 468
489 TEST_F(SyncBackendHostTest, AddTypes) { 469 TEST_F(SyncBackendHostTest, AddTypes) {
490 // Simulate first time sync. 470 // Simulate first time sync.
491 InitializeBackend(true); 471 InitializeBackend(true);
492 fake_manager_->GetAndResetCleanedTypes(); 472 fake_manager_->GetAndResetCleanedTypes();
493 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 473 ModelTypeSet ready_types = ConfigureDataTypes(
494 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 474 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
495 syncer::ModelTypeSet()); 475 ModelTypeSet());
496 // Nigori is always downloaded so won't be ready. 476 // Nigori is always downloaded so won't be ready.
497 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 477 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types);
498 syncer::ModelTypeSet(syncer::NIGORI)),
499 ready_types);
500 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); 478 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes());
501 EXPECT_TRUE( 479 EXPECT_TRUE(
502 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 480 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
503 .Empty()); 481 .Empty());
504 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 482 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
505 EXPECT_TRUE( 483 EXPECT_TRUE(
506 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 484 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
507 .Empty()); 485 .Empty());
508 486
509 // Then add two datatypes. 487 // Then add two datatypes.
510 syncer::ModelTypeSet new_types(syncer::EXTENSIONS, syncer::APPS); 488 ModelTypeSet new_types(EXTENSIONS, APPS);
511 enabled_types_.PutAll(new_types); 489 enabled_types_.PutAll(new_types);
512 ready_types = ConfigureDataTypes( 490 ready_types = ConfigureDataTypes(
513 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 491 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
514 syncer::ModelTypeSet()); 492 ModelTypeSet());
515 493
516 // Only those datatypes added should be downloaded (plus nigori). Nothing 494 // Only those datatypes added should be downloaded (plus nigori). Nothing
517 // should be cleaned aside from the disabled types. 495 // should be cleaned aside from the disabled types.
518 new_types.Put(syncer::NIGORI); 496 new_types.Put(NIGORI);
519 EXPECT_EQ(syncer::Difference(enabled_types_, new_types), ready_types); 497 EXPECT_EQ(Difference(enabled_types_, new_types), ready_types);
520 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 498 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
521 EXPECT_TRUE( 499 EXPECT_TRUE(
522 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 500 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
523 .Empty()); 501 .Empty());
524 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 502 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
525 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 503 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
526 EXPECT_TRUE( 504 EXPECT_TRUE(
527 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 505 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
528 .Empty()); 506 .Empty());
529 } 507 }
530 508
531 // And and disable in the same configuration. 509 // And and disable in the same configuration.
532 TEST_F(SyncBackendHostTest, AddDisableTypes) { 510 TEST_F(SyncBackendHostTest, AddDisableTypes) {
533 // Simulate first time sync. 511 // Simulate first time sync.
534 InitializeBackend(true); 512 InitializeBackend(true);
535 fake_manager_->GetAndResetCleanedTypes(); 513 fake_manager_->GetAndResetCleanedTypes();
536 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 514 ModelTypeSet ready_types = ConfigureDataTypes(
537 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 515 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
538 syncer::ModelTypeSet()); 516 ModelTypeSet());
539 // Nigori is always downloaded so won't be ready. 517 // Nigori is always downloaded so won't be ready.
540 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 518 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types);
541 syncer::ModelTypeSet(syncer::NIGORI)),
542 ready_types);
543 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes()); 519 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetDownloadedTypes());
544 EXPECT_TRUE( 520 EXPECT_TRUE(
545 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 521 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
546 .Empty()); 522 .Empty());
547 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 523 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
548 EXPECT_TRUE( 524 EXPECT_TRUE(
549 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 525 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
550 .Empty()); 526 .Empty());
551 527
552 // Then add two datatypes. 528 // Then add two datatypes.
553 syncer::ModelTypeSet old_types = enabled_types_; 529 ModelTypeSet old_types = enabled_types_;
554 syncer::ModelTypeSet disabled_types(syncer::BOOKMARKS, 530 ModelTypeSet disabled_types(BOOKMARKS, SEARCH_ENGINES);
555 syncer::SEARCH_ENGINES); 531 ModelTypeSet new_types(EXTENSIONS, APPS);
556 syncer::ModelTypeSet new_types(syncer::EXTENSIONS, syncer::APPS);
557 enabled_types_.PutAll(new_types); 532 enabled_types_.PutAll(new_types);
558 enabled_types_.RemoveAll(disabled_types); 533 enabled_types_.RemoveAll(disabled_types);
559 ready_types = ConfigureDataTypes( 534 ready_types = ConfigureDataTypes(
560 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 535 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
561 syncer::ModelTypeSet()); 536 ModelTypeSet());
562 537
563 // Only those datatypes added should be downloaded (plus nigori). Nothing 538 // Only those datatypes added should be downloaded (plus nigori). Nothing
564 // should be cleaned aside from the disabled types. 539 // should be cleaned aside from the disabled types.
565 new_types.Put(syncer::NIGORI); 540 new_types.Put(NIGORI);
566 EXPECT_EQ(syncer::Difference(enabled_types_, new_types), ready_types); 541 EXPECT_EQ(Difference(enabled_types_, new_types), ready_types);
567 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 542 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
568 EXPECT_EQ(disabled_types, 543 EXPECT_EQ(disabled_types,
569 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)); 544 Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types));
570 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 545 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
571 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 546 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
572 EXPECT_EQ(disabled_types, 547 EXPECT_EQ(disabled_types,
573 fake_manager_->GetTypesWithEmptyProgressMarkerToken(old_types)); 548 fake_manager_->GetTypesWithEmptyProgressMarkerToken(old_types));
574 } 549 }
575 550
576 // Test restarting the browser to newly supported datatypes. The new datatypes 551 // Test restarting the browser to newly supported datatypes. The new datatypes
577 // should be downloaded on the configuration after backend initialization. 552 // should be downloaded on the configuration after backend initialization.
578 TEST_F(SyncBackendHostTest, NewlySupportedTypes) { 553 TEST_F(SyncBackendHostTest, NewlySupportedTypes) {
579 sync_prefs_->SetFirstSetupComplete(); 554 sync_prefs_->SetFirstSetupComplete();
580 // Set sync manager behavior before passing it down. All types have progress 555 // Set sync manager behavior before passing it down. All types have progress
581 // markers and initial sync ended except the new types. 556 // markers and initial sync ended except the new types.
582 syncer::ModelTypeSet old_types = enabled_types_; 557 ModelTypeSet old_types = enabled_types_;
583 fake_manager_factory_->set_progress_marker_types(old_types); 558 fake_manager_factory_->set_progress_marker_types(old_types);
584 fake_manager_factory_->set_initial_sync_ended_types(old_types); 559 fake_manager_factory_->set_initial_sync_ended_types(old_types);
585 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS, 560 ModelTypeSet new_types(APP_SETTINGS, EXTENSION_SETTINGS);
586 syncer::EXTENSION_SETTINGS);
587 enabled_types_.PutAll(new_types); 561 enabled_types_.PutAll(new_types);
588 562
589 // Does nothing. 563 // Does nothing.
590 InitializeBackend(true); 564 InitializeBackend(true);
591 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty()); 565 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Empty());
592 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types) 566 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), old_types)
593 .Empty()); 567 .Empty());
594 EXPECT_EQ(old_types, fake_manager_->InitialSyncEndedTypes()); 568 EXPECT_EQ(old_types, fake_manager_->InitialSyncEndedTypes());
595 EXPECT_EQ(new_types, fake_manager_->GetTypesWithEmptyProgressMarkerToken( 569 EXPECT_EQ(new_types, fake_manager_->GetTypesWithEmptyProgressMarkerToken(
596 enabled_types_)); 570 enabled_types_));
597 571
598 // Downloads and applies the new types (plus nigori). 572 // Downloads and applies the new types (plus nigori).
599 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 573 ModelTypeSet ready_types = ConfigureDataTypes(
600 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 574 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
601 syncer::ModelTypeSet()); 575 ModelTypeSet());
602 576
603 new_types.Put(syncer::NIGORI); 577 new_types.Put(NIGORI);
604 EXPECT_EQ(syncer::Difference(old_types, syncer::ModelTypeSet(syncer::NIGORI)), 578 EXPECT_EQ(Difference(old_types, ModelTypeSet(NIGORI)), ready_types);
605 ready_types);
606 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 579 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
607 EXPECT_TRUE( 580 EXPECT_TRUE(
608 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 581 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
609 .Empty()); 582 .Empty());
610 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 583 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
611 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 584 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
612 EXPECT_TRUE( 585 EXPECT_TRUE(
613 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 586 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
614 .Empty()); 587 .Empty());
615 } 588 }
616 589
617 // Test the newly supported types scenario, but with the presence of partial 590 // Test the newly supported types scenario, but with the presence of partial
618 // types as well. Both partial and newly supported types should be downloaded 591 // types as well. Both partial and newly supported types should be downloaded
619 // the configuration. 592 // the configuration.
620 TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) { 593 TEST_F(SyncBackendHostTest, NewlySupportedTypesWithPartialTypes) {
621 sync_prefs_->SetFirstSetupComplete(); 594 sync_prefs_->SetFirstSetupComplete();
622 // Set sync manager behavior before passing it down. All types have progress 595 // Set sync manager behavior before passing it down. All types have progress
623 // markers and initial sync ended except the new types. 596 // markers and initial sync ended except the new types.
624 syncer::ModelTypeSet old_types = enabled_types_; 597 ModelTypeSet old_types = enabled_types_;
625 syncer::ModelTypeSet partial_types(syncer::NIGORI, syncer::BOOKMARKS); 598 ModelTypeSet partial_types(NIGORI, BOOKMARKS);
626 syncer::ModelTypeSet full_types = Difference(enabled_types_, partial_types); 599 ModelTypeSet full_types = Difference(enabled_types_, partial_types);
627 fake_manager_factory_->set_progress_marker_types(old_types); 600 fake_manager_factory_->set_progress_marker_types(old_types);
628 fake_manager_factory_->set_initial_sync_ended_types(full_types); 601 fake_manager_factory_->set_initial_sync_ended_types(full_types);
629 syncer::ModelTypeSet new_types(syncer::APP_SETTINGS, 602 ModelTypeSet new_types(APP_SETTINGS, EXTENSION_SETTINGS);
630 syncer::EXTENSION_SETTINGS);
631 enabled_types_.PutAll(new_types); 603 enabled_types_.PutAll(new_types);
632 604
633 // Purge the partial types. The nigori will be among the purged types, but 605 // Purge the partial types. The nigori will be among the purged types, but
634 // the syncer will re-download it by the time the initialization is complete. 606 // the syncer will re-download it by the time the initialization is complete.
635 InitializeBackend(true); 607 InitializeBackend(true);
636 EXPECT_EQ(syncer::ModelTypeSet(syncer::NIGORI), 608 EXPECT_EQ(ModelTypeSet(NIGORI), fake_manager_->GetAndResetDownloadedTypes());
637 fake_manager_->GetAndResetDownloadedTypes());
638 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types)); 609 EXPECT_TRUE(fake_manager_->GetAndResetCleanedTypes().HasAll(partial_types));
639 EXPECT_EQ(syncer::Union(full_types, syncer::ModelTypeSet(syncer::NIGORI)), 610 EXPECT_EQ(Union(full_types, ModelTypeSet(NIGORI)),
640 fake_manager_->InitialSyncEndedTypes()); 611 fake_manager_->InitialSyncEndedTypes());
641 EXPECT_EQ( 612 EXPECT_EQ(
642 Union(new_types, 613 Union(new_types, Difference(partial_types, ModelTypeSet(NIGORI))),
643 Difference(partial_types, syncer::ModelTypeSet(syncer::NIGORI))),
644 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)); 614 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_));
645 615
646 // Downloads and applies the new types and partial types (which includes 616 // Downloads and applies the new types and partial types (which includes
647 // nigori anyways). 617 // nigori anyways).
648 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 618 ModelTypeSet ready_types = ConfigureDataTypes(
649 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 619 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
650 syncer::ModelTypeSet()); 620 ModelTypeSet());
651 EXPECT_EQ(full_types, ready_types); 621 EXPECT_EQ(full_types, ready_types);
652 EXPECT_EQ(Union(new_types, partial_types), 622 EXPECT_EQ(Union(new_types, partial_types),
653 fake_manager_->GetAndResetDownloadedTypes()); 623 fake_manager_->GetAndResetDownloadedTypes());
654 EXPECT_TRUE( 624 EXPECT_TRUE(
655 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_) 625 Intersection(fake_manager_->GetAndResetCleanedTypes(), enabled_types_)
656 .Empty()); 626 .Empty());
657 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 627 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
658 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes()); 628 EXPECT_EQ(enabled_types_, fake_manager_->GetAndResetEnabledTypes());
659 EXPECT_TRUE( 629 EXPECT_TRUE(
660 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 630 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
661 .Empty()); 631 .Empty());
662 } 632 }
663 633
664 // Verify that downloading control types only downloads those types that do 634 // Verify that downloading control types only downloads those types that do
665 // not have initial sync ended set. 635 // not have initial sync ended set.
666 TEST_F(SyncBackendHostTest, DownloadControlTypes) { 636 TEST_F(SyncBackendHostTest, DownloadControlTypes) {
667 sync_prefs_->SetFirstSetupComplete(); 637 sync_prefs_->SetFirstSetupComplete();
668 // Set sync manager behavior before passing it down. Experiments and device 638 // Set sync manager behavior before passing it down. Experiments and device
669 // info are new types without progress markers or initial sync ended, while 639 // info are new types without progress markers or initial sync ended, while
670 // all other types have been fully downloaded and applied. 640 // all other types have been fully downloaded and applied.
671 syncer::ModelTypeSet new_types(syncer::EXPERIMENTS, syncer::NIGORI); 641 ModelTypeSet new_types(EXPERIMENTS, NIGORI);
672 syncer::ModelTypeSet old_types = Difference(enabled_types_, new_types); 642 ModelTypeSet old_types = Difference(enabled_types_, new_types);
673 fake_manager_factory_->set_progress_marker_types(old_types); 643 fake_manager_factory_->set_progress_marker_types(old_types);
674 fake_manager_factory_->set_initial_sync_ended_types(old_types); 644 fake_manager_factory_->set_initial_sync_ended_types(old_types);
675 645
676 // Bringing up the backend should download the new types without downloading 646 // Bringing up the backend should download the new types without downloading
677 // any old types. 647 // any old types.
678 InitializeBackend(true); 648 InitializeBackend(true);
679 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes()); 649 EXPECT_EQ(new_types, fake_manager_->GetAndResetDownloadedTypes());
680 EXPECT_EQ(Difference(syncer::ModelTypeSet::All(), enabled_types_), 650 EXPECT_EQ(Difference(ModelTypeSet::All(), enabled_types_),
681 fake_manager_->GetAndResetCleanedTypes()); 651 fake_manager_->GetAndResetCleanedTypes());
682 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes()); 652 EXPECT_EQ(enabled_types_, fake_manager_->InitialSyncEndedTypes());
683 EXPECT_TRUE( 653 EXPECT_TRUE(
684 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_) 654 fake_manager_->GetTypesWithEmptyProgressMarkerToken(enabled_types_)
685 .Empty()); 655 .Empty());
686 } 656 }
687 657
688 // Fail to download control types. It's believed that there is a server bug 658 // Fail to download control types. It's believed that there is a server bug
689 // which can allow this to happen (crbug.com/164288). The sync backend host 659 // which can allow this to happen (crbug.com/164288). The sync backend host
690 // should detect this condition and fail to initialize the backend. 660 // should detect this condition and fail to initialize the backend.
691 // 661 //
692 // The failure is "silent" in the sense that the GetUpdates request appears to 662 // The failure is "silent" in the sense that the GetUpdates request appears to
693 // be successful, but it returned no results. This means that the usual 663 // be successful, but it returned no results. This means that the usual
694 // download retry logic will not be invoked. 664 // download retry logic will not be invoked.
695 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) { 665 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) {
696 fake_manager_factory_->set_configure_fail_types(syncer::ModelTypeSet::All()); 666 fake_manager_factory_->set_configure_fail_types(ModelTypeSet::All());
697 InitializeBackend(false); 667 InitializeBackend(false);
698 } 668 }
699 669
700 // Test that local refresh requests are delivered to sync. 670 // Test that local refresh requests are delivered to sync.
701 TEST_F(SyncBackendHostTest, ForwardLocalRefreshRequest) { 671 TEST_F(SyncBackendHostTest, ForwardLocalRefreshRequest) {
702 InitializeBackend(true); 672 InitializeBackend(true);
703 673
704 syncer::ModelTypeSet set1 = syncer::ModelTypeSet::All(); 674 ModelTypeSet set1 = ModelTypeSet::All();
705 backend_->TriggerRefresh(set1); 675 backend_->TriggerRefresh(set1);
706 fake_manager_->WaitForSyncThread(); 676 fake_manager_->WaitForSyncThread();
707 EXPECT_EQ(set1, fake_manager_->GetLastRefreshRequestTypes()); 677 EXPECT_EQ(set1, fake_manager_->GetLastRefreshRequestTypes());
708 678
709 syncer::ModelTypeSet set2 = syncer::ModelTypeSet(syncer::SESSIONS); 679 ModelTypeSet set2 = ModelTypeSet(SESSIONS);
710 backend_->TriggerRefresh(set2); 680 backend_->TriggerRefresh(set2);
711 fake_manager_->WaitForSyncThread(); 681 fake_manager_->WaitForSyncThread();
712 EXPECT_EQ(set2, fake_manager_->GetLastRefreshRequestTypes()); 682 EXPECT_EQ(set2, fake_manager_->GetLastRefreshRequestTypes());
713 } 683 }
714 684
715 // Test that configuration on signin sends the proper GU source. 685 // Test that configuration on signin sends the proper GU source.
716 TEST_F(SyncBackendHostTest, DownloadControlTypesNewClient) { 686 TEST_F(SyncBackendHostTest, DownloadControlTypesNewClient) {
717 InitializeBackend(true); 687 InitializeBackend(true);
718 EXPECT_EQ(syncer::CONFIGURE_REASON_NEW_CLIENT, 688 EXPECT_EQ(CONFIGURE_REASON_NEW_CLIENT,
719 fake_manager_->GetAndResetConfigureReason()); 689 fake_manager_->GetAndResetConfigureReason());
720 } 690 }
721 691
722 // Test that configuration on restart sends the proper GU source. 692 // Test that configuration on restart sends the proper GU source.
723 TEST_F(SyncBackendHostTest, DownloadControlTypesRestart) { 693 TEST_F(SyncBackendHostTest, DownloadControlTypesRestart) {
724 sync_prefs_->SetFirstSetupComplete(); 694 sync_prefs_->SetFirstSetupComplete();
725 fake_manager_factory_->set_progress_marker_types(enabled_types_); 695 fake_manager_factory_->set_progress_marker_types(enabled_types_);
726 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_); 696 fake_manager_factory_->set_initial_sync_ended_types(enabled_types_);
727 InitializeBackend(true); 697 InitializeBackend(true);
728 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, 698 EXPECT_EQ(CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE,
729 fake_manager_->GetAndResetConfigureReason()); 699 fake_manager_->GetAndResetConfigureReason());
730 } 700 }
731 701
732 // It is SyncBackendHostCore responsibility to cleanup Sync Data folder if sync 702 // It is SyncBackendHostCore responsibility to cleanup Sync Data folder if sync
733 // setup hasn't been completed. This test ensures that cleanup happens. 703 // setup hasn't been completed. This test ensures that cleanup happens.
734 TEST_F(SyncBackendHostTest, TestStartupWithOldSyncData) { 704 TEST_F(SyncBackendHostTest, TestStartupWithOldSyncData) {
735 const char* nonsense = "slon"; 705 const char* nonsense = "slon";
736 base::FilePath temp_directory = 706 base::FilePath temp_directory =
737 temp_dir_.GetPath().Append(base::FilePath(kTestSyncDir)); 707 temp_dir_.GetPath().Append(base::FilePath(kTestSyncDir));
738 base::FilePath sync_file = temp_directory.AppendASCII("SyncData.sqlite3"); 708 base::FilePath sync_file = temp_directory.AppendASCII("SyncData.sqlite3");
739 ASSERT_TRUE(base::CreateDirectory(temp_directory)); 709 ASSERT_TRUE(base::CreateDirectory(temp_directory));
740 ASSERT_NE(-1, base::WriteFile(sync_file, nonsense, strlen(nonsense))); 710 ASSERT_NE(-1, base::WriteFile(sync_file, nonsense, strlen(nonsense)));
741 711
742 InitializeBackend(true); 712 InitializeBackend(true);
743 713
744 EXPECT_FALSE(base::PathExists(sync_file)); 714 EXPECT_FALSE(base::PathExists(sync_file));
745 } 715 }
746 716
747 // If bookmarks encounter an error that results in disabling without purging 717 // If bookmarks encounter an error that results in disabling without purging
748 // (such as when the type is unready), and then is explicitly disabled, the 718 // (such as when the type is unready), and then is explicitly disabled, the
749 // SyncBackendHost needs to tell the manager to purge the type, even though 719 // SyncBackendHost needs to tell the manager to purge the type, even though
750 // it's already disabled (crbug.com/386778). 720 // it's already disabled (crbug.com/386778).
751 TEST_F(SyncBackendHostTest, DisableThenPurgeType) { 721 TEST_F(SyncBackendHostTest, DisableThenPurgeType) {
752 syncer::ModelTypeSet error_types(syncer::BOOKMARKS); 722 ModelTypeSet error_types(BOOKMARKS);
753 723
754 InitializeBackend(true); 724 InitializeBackend(true);
755 725
756 // First enable the types. 726 // First enable the types.
757 syncer::ModelTypeSet ready_types = ConfigureDataTypes( 727 ModelTypeSet ready_types = ConfigureDataTypes(
758 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 728 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
759 syncer::ModelTypeSet()); 729 ModelTypeSet());
760 730
761 // Nigori is always downloaded so won't be ready. 731 // Nigori is always downloaded so won't be ready.
762 EXPECT_EQ(syncer::Difference(syncer::ControlTypes(), 732 EXPECT_EQ(Difference(ControlTypes(), ModelTypeSet(NIGORI)), ready_types);
763 syncer::ModelTypeSet(syncer::NIGORI)),
764 ready_types);
765 733
766 // Then mark the error types as unready (disables without purging). 734 // Then mark the error types as unready (disables without purging).
767 ready_types = ConfigureDataTypes( 735 ready_types = ConfigureDataTypes(
768 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 736 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
769 error_types); 737 error_types);
770 EXPECT_EQ(syncer::Difference(enabled_types_, error_types), ready_types); 738 EXPECT_EQ(Difference(enabled_types_, error_types), ready_types);
771 EXPECT_TRUE( 739 EXPECT_TRUE(
772 fake_manager_->GetTypesWithEmptyProgressMarkerToken(error_types).Empty()); 740 fake_manager_->GetTypesWithEmptyProgressMarkerToken(error_types).Empty());
773 741
774 // Lastly explicitly disable the error types, which should result in a purge. 742 // Lastly explicitly disable the error types, which should result in a purge.
775 enabled_types_.RemoveAll(error_types); 743 enabled_types_.RemoveAll(error_types);
776 ready_types = ConfigureDataTypes( 744 ready_types = ConfigureDataTypes(
777 enabled_types_, Difference(syncer::ModelTypeSet::All(), enabled_types_), 745 enabled_types_, Difference(ModelTypeSet::All(), enabled_types_),
778 syncer::ModelTypeSet()); 746 ModelTypeSet());
779 EXPECT_EQ(syncer::Difference(enabled_types_, error_types), ready_types); 747 EXPECT_EQ(Difference(enabled_types_, error_types), ready_types);
780 EXPECT_FALSE( 748 EXPECT_FALSE(
781 fake_manager_->GetTypesWithEmptyProgressMarkerToken(error_types).Empty()); 749 fake_manager_->GetTypesWithEmptyProgressMarkerToken(error_types).Empty());
782 } 750 }
783 751
784 // Test that a call to ClearServerData is forwarded to the underlying 752 // Test that a call to ClearServerData is forwarded to the underlying
785 // SyncManager. 753 // SyncManager.
786 TEST_F(SyncBackendHostTest, ClearServerDataCallsAreForwarded) { 754 TEST_F(SyncBackendHostTest, ClearServerDataCallsAreForwarded) {
787 InitializeBackend(true); 755 InitializeBackend(true);
788 syncer::CallbackCounter callback_counter; 756 CallbackCounter callback_counter;
789 backend_->ClearServerData(base::Bind(&syncer::CallbackCounter::Callback, 757 backend_->ClearServerData(base::Bind(&CallbackCounter::Callback,
790 base::Unretained(&callback_counter))); 758 base::Unretained(&callback_counter)));
791 fake_manager_->WaitForSyncThread(); 759 fake_manager_->WaitForSyncThread();
792 EXPECT_EQ(1, callback_counter.times_called()); 760 EXPECT_EQ(1, callback_counter.times_called());
793 } 761 }
794 762
795 // Ensure that redundant invalidations are ignored and that the most recent 763 // Ensure that redundant invalidations are ignored and that the most recent
796 // set of invalidation version is persisted across restarts. 764 // set of invalidation version is persisted across restarts.
797 TEST_F(SyncBackendHostTest, IgnoreOldInvalidations) { 765 TEST_F(SyncBackendHostTest, IgnoreOldInvalidations) {
798 // Set up some old persisted invalidations. 766 // Set up some old persisted invalidations.
799 std::map<syncer::ModelType, int64_t> invalidation_versions; 767 std::map<ModelType, int64_t> invalidation_versions;
800 invalidation_versions[syncer::BOOKMARKS] = 20; 768 invalidation_versions[BOOKMARKS] = 20;
801 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); 769 sync_prefs_->UpdateInvalidationVersions(invalidation_versions);
802 InitializeBackend(true); 770 InitializeBackend(true);
803 EXPECT_EQ(0, fake_manager_->GetInvalidationCount()); 771 EXPECT_EQ(0, fake_manager_->GetInvalidationCount());
804 772
805 // Receiving an invalidation with an old version should do nothing. 773 // Receiving an invalidation with an old version should do nothing.
806 syncer::ObjectIdInvalidationMap invalidation_map; 774 ObjectIdInvalidationMap invalidation_map;
807 std::string notification_type; 775 std::string notification_type;
808 syncer::RealModelTypeToNotificationType(syncer::BOOKMARKS, 776 RealModelTypeToNotificationType(BOOKMARKS, &notification_type);
809 &notification_type); 777 invalidation_map.Insert(Invalidation::Init(
810 invalidation_map.Insert(syncer::Invalidation::Init(
811 invalidation::ObjectId(0, notification_type), 10, "payload")); 778 invalidation::ObjectId(0, notification_type), 10, "payload"));
812 backend_->OnIncomingInvalidation(invalidation_map); 779 backend_->OnIncomingInvalidation(invalidation_map);
813 fake_manager_->WaitForSyncThread(); 780 fake_manager_->WaitForSyncThread();
814 EXPECT_EQ(0, fake_manager_->GetInvalidationCount()); 781 EXPECT_EQ(0, fake_manager_->GetInvalidationCount());
815 782
816 // Invalidations with new versions should be acted upon. 783 // Invalidations with new versions should be acted upon.
817 invalidation_map.Insert(syncer::Invalidation::Init( 784 invalidation_map.Insert(Invalidation::Init(
818 invalidation::ObjectId(0, notification_type), 30, "payload")); 785 invalidation::ObjectId(0, notification_type), 30, "payload"));
819 backend_->OnIncomingInvalidation(invalidation_map); 786 backend_->OnIncomingInvalidation(invalidation_map);
820 fake_manager_->WaitForSyncThread(); 787 fake_manager_->WaitForSyncThread();
821 EXPECT_EQ(1, fake_manager_->GetInvalidationCount()); 788 EXPECT_EQ(1, fake_manager_->GetInvalidationCount());
822 789
823 // Invalidation for new data types should be acted on. 790 // Invalidation for new data types should be acted on.
824 syncer::RealModelTypeToNotificationType(syncer::SESSIONS, &notification_type); 791 RealModelTypeToNotificationType(SESSIONS, &notification_type);
825 invalidation_map.Insert(syncer::Invalidation::Init( 792 invalidation_map.Insert(Invalidation::Init(
826 invalidation::ObjectId(0, notification_type), 10, "payload")); 793 invalidation::ObjectId(0, notification_type), 10, "payload"));
827 backend_->OnIncomingInvalidation(invalidation_map); 794 backend_->OnIncomingInvalidation(invalidation_map);
828 fake_manager_->WaitForSyncThread(); 795 fake_manager_->WaitForSyncThread();
829 EXPECT_EQ(2, fake_manager_->GetInvalidationCount()); 796 EXPECT_EQ(2, fake_manager_->GetInvalidationCount());
830 797
831 // But redelivering that same invalidation should be ignored. 798 // But redelivering that same invalidation should be ignored.
832 backend_->OnIncomingInvalidation(invalidation_map); 799 backend_->OnIncomingInvalidation(invalidation_map);
833 fake_manager_->WaitForSyncThread(); 800 fake_manager_->WaitForSyncThread();
834 EXPECT_EQ(2, fake_manager_->GetInvalidationCount()); 801 EXPECT_EQ(2, fake_manager_->GetInvalidationCount());
835 802
836 // If an invalidation with an unknown version is received, it should be 803 // If an invalidation with an unknown version is received, it should be
837 // acted on, but should not affect the persisted versions. 804 // acted on, but should not affect the persisted versions.
838 invalidation_map.Insert(syncer::Invalidation::InitUnknownVersion( 805 invalidation_map.Insert(Invalidation::InitUnknownVersion(
839 invalidation::ObjectId(0, notification_type))); 806 invalidation::ObjectId(0, notification_type)));
840 backend_->OnIncomingInvalidation(invalidation_map); 807 backend_->OnIncomingInvalidation(invalidation_map);
841 fake_manager_->WaitForSyncThread(); 808 fake_manager_->WaitForSyncThread();
842 EXPECT_EQ(3, fake_manager_->GetInvalidationCount()); 809 EXPECT_EQ(3, fake_manager_->GetInvalidationCount());
843 810
844 // Verify that the invalidation versions were updated in the prefs. 811 // Verify that the invalidation versions were updated in the prefs.
845 invalidation_versions[syncer::BOOKMARKS] = 30; 812 invalidation_versions[BOOKMARKS] = 30;
846 invalidation_versions[syncer::SESSIONS] = 10; 813 invalidation_versions[SESSIONS] = 10;
847 std::map<syncer::ModelType, int64_t> persisted_invalidation_versions; 814 std::map<ModelType, int64_t> persisted_invalidation_versions;
848 sync_prefs_->GetInvalidationVersions(&persisted_invalidation_versions); 815 sync_prefs_->GetInvalidationVersions(&persisted_invalidation_versions);
849 EXPECT_EQ(invalidation_versions.size(), 816 EXPECT_EQ(invalidation_versions.size(),
850 persisted_invalidation_versions.size()); 817 persisted_invalidation_versions.size());
851 for (auto iter : persisted_invalidation_versions) { 818 for (auto iter : persisted_invalidation_versions) {
852 EXPECT_EQ(invalidation_versions[iter.first], iter.second); 819 EXPECT_EQ(invalidation_versions[iter.first], iter.second);
853 } 820 }
854 } 821 }
855 822
856 // Tests that SyncBackendHostImpl retains ModelTypeConnector after call to 823 // Tests that SyncBackendHostImpl retains ModelTypeConnector after call to
857 // StopSyncingForShutdown. This is needed for datatype deactivation during 824 // StopSyncingForShutdown. This is needed for datatype deactivation during
858 // DataTypeManager shutdown. 825 // DataTypeManager shutdown.
859 TEST_F(SyncBackendHostTest, ModelTypeConnectorValidDuringShutdown) { 826 TEST_F(SyncBackendHostTest, ModelTypeConnectorValidDuringShutdown) {
860 InitializeBackend(true); 827 InitializeBackend(true);
861 backend_->StopSyncingForShutdown(); 828 backend_->StopSyncingForShutdown();
862 // Verify that call to DeactivateNonBlockingDataType doesn't assert. 829 // Verify that call to DeactivateNonBlockingDataType doesn't assert.
863 backend_->DeactivateNonBlockingDataType(syncer::AUTOFILL); 830 backend_->DeactivateNonBlockingDataType(AUTOFILL);
864 backend_->Shutdown(syncer::STOP_SYNC); 831 backend_->Shutdown(STOP_SYNC);
865 backend_.reset(); 832 backend_.reset();
866 } 833 }
867 834
868 } // namespace 835 } // namespace
869 836
870 } // namespace browser_sync 837 } // namespace syncer
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