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

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

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