OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/run_loop.h" | |
16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
17 #include "base/values.h" | 16 #include "base/values.h" |
18 #include "build/build_config.h" | 17 #include "build/build_config.h" |
19 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" | 18 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" |
20 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h" | 19 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h" |
21 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" | 20 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" |
22 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
23 #include "components/sync/model/sync_change_processor.h" | 22 #include "components/sync/model/sync_change_processor.h" |
24 #include "components/sync/model/sync_change_processor_wrapper_for_test.h" | 23 #include "components/sync/model/sync_change_processor_wrapper_for_test.h" |
25 #include "components/sync/model/sync_error_factory.h" | 24 #include "components/sync/model/sync_error_factory.h" |
26 #include "components/sync/model/sync_error_factory_mock.h" | 25 #include "components/sync/model/sync_error_factory_mock.h" |
27 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
27 #include "content/public/test/test_utils.h" | |
28 #include "extensions/browser/api/storage/backend_task_runner.h" | |
28 #include "extensions/browser/api/storage/settings_test_util.h" | 29 #include "extensions/browser/api/storage/settings_test_util.h" |
29 #include "extensions/browser/api/storage/storage_frontend.h" | 30 #include "extensions/browser/api/storage/storage_frontend.h" |
30 #include "extensions/browser/event_router.h" | 31 #include "extensions/browser/event_router.h" |
31 #include "extensions/browser/event_router_factory.h" | 32 #include "extensions/browser/event_router_factory.h" |
32 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
33 #include "extensions/browser/mock_extension_system.h" | 34 #include "extensions/browser/mock_extension_system.h" |
34 #include "extensions/browser/value_store/test_value_store_factory.h" | 35 #include "extensions/browser/value_store/test_value_store_factory.h" |
35 #include "extensions/browser/value_store/testing_value_store.h" | 36 #include "extensions/browser/value_store/testing_value_store.h" |
36 #include "extensions/common/manifest.h" | 37 #include "extensions/common/manifest.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 &MockExtensionSystemFactoryFunction); | 198 &MockExtensionSystemFactoryFunction); |
198 | 199 |
199 EventRouterFactory::GetInstance()->SetTestingFactory(profile_.get(), | 200 EventRouterFactory::GetInstance()->SetTestingFactory(profile_.get(), |
200 &BuildEventRouter); | 201 &BuildEventRouter); |
201 } | 202 } |
202 | 203 |
203 void TearDown() override { | 204 void TearDown() override { |
204 frontend_.reset(); | 205 frontend_.reset(); |
205 profile_.reset(); | 206 profile_.reset(); |
206 // Execute any pending deletion tasks. | 207 // Execute any pending deletion tasks. |
207 base::RunLoop().RunUntilIdle(); | 208 content::RunAllBlockingPoolTasksUntilIdle(); |
208 } | 209 } |
209 | 210 |
210 protected: | 211 protected: |
211 // Adds a record of an extension or app to the extension service, then returns | 212 // Adds a record of an extension or app to the extension service, then returns |
212 // its storage area. | 213 // its storage area. |
213 ValueStore* AddExtensionAndGetStorage( | 214 ValueStore* AddExtensionAndGetStorage( |
214 const std::string& id, Manifest::Type type) { | 215 const std::string& id, Manifest::Type type) { |
215 scoped_refptr<const Extension> extension = | 216 scoped_refptr<const Extension> extension = |
216 util::AddExtensionWithId(profile_.get(), id, type); | 217 util::AddExtensionWithId(profile_.get(), id, type); |
217 return util::GetStorage(extension, frontend_.get()); | 218 return util::GetStorage(extension, frontend_.get()); |
218 } | 219 } |
219 | 220 |
220 // Gets the syncer::SyncableService for the given sync type. | 221 // Gets the syncer::SyncableService for the given sync type. |
221 syncer::SyncableService* GetSyncableService(syncer::ModelType model_type) { | 222 syncer::SyncableService* GetSyncableService(syncer::ModelType model_type) { |
222 base::RunLoop().RunUntilIdle(); | |
223 SyncValueStoreCache* sync_cache = static_cast<SyncValueStoreCache*>( | 223 SyncValueStoreCache* sync_cache = static_cast<SyncValueStoreCache*>( |
224 frontend_->GetValueStoreCache(settings_namespace::SYNC)); | 224 frontend_->GetValueStoreCache(settings_namespace::SYNC)); |
225 return sync_cache->GetSyncableService(model_type); | 225 return sync_cache->GetSyncableService(model_type); |
226 } | 226 } |
227 | 227 |
228 // Gets all the sync data from the SyncableService for a sync type as a map | 228 // Gets all the sync data from the SyncableService for a sync type as a map |
229 // from extension id to its sync data. | 229 // from extension id to its sync data. |
230 SettingSyncDataMultimap GetAllSyncData(syncer::ModelType model_type) { | 230 SettingSyncDataMultimap GetAllSyncData(syncer::ModelType model_type) { |
231 syncer::SyncDataList as_list = | 231 syncer::SyncDataList as_list = |
232 GetSyncableService(model_type)->GetAllSyncData(model_type); | 232 GetSyncableService(model_type)->GetAllSyncData(model_type); |
(...skipping 10 matching lines...) Expand all Loading... | |
243 return as_map; | 243 return as_map; |
244 } | 244 } |
245 | 245 |
246 // This class uses it's TestingValueStore in such a way that it always mints | 246 // This class uses it's TestingValueStore in such a way that it always mints |
247 // new TestingValueStore instances. | 247 // new TestingValueStore instances. |
248 TestingValueStore* GetExisting(const ExtensionId& extension_id) { | 248 TestingValueStore* GetExisting(const ExtensionId& extension_id) { |
249 return static_cast<TestingValueStore*>( | 249 return static_cast<TestingValueStore*>( |
250 storage_factory_->GetExisting(extension_id)); | 250 storage_factory_->GetExisting(extension_id)); |
251 } | 251 } |
252 | 252 |
253 template <typename Func> | |
254 static void RunFunc(Func func) { | |
255 func(); | |
256 } | |
257 | |
258 template <typename Func> | |
259 void PostOnBackendSequenceAndWait(const tracked_objects::Location& from_here, | |
Devlin
2017/07/12 22:58:00
Heh, clever. :)
stanisc
2017/07/12 23:42:49
After failing to use lambda directly with base::Bi
| |
260 Func func) { | |
261 GetBackendTaskRunner()->PostTask( | |
262 from_here, base::Bind(&ExtensionSettingsSyncTest::RunFunc<Func>, func)); | |
263 content::RunAllBlockingPoolTasksUntilIdle(); | |
264 } | |
265 | |
253 // Needed so that the DCHECKs for running on FILE or UI threads pass. | 266 // Needed so that the DCHECKs for running on FILE or UI threads pass. |
254 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 267 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
255 | 268 |
256 base::ScopedTempDir temp_dir_; | 269 base::ScopedTempDir temp_dir_; |
257 std::unique_ptr<TestingProfile> profile_; | 270 std::unique_ptr<TestingProfile> profile_; |
258 std::unique_ptr<StorageFrontend> frontend_; | 271 std::unique_ptr<StorageFrontend> frontend_; |
259 scoped_refptr<TestValueStoreFactory> storage_factory_; | 272 scoped_refptr<TestValueStoreFactory> storage_factory_; |
260 std::unique_ptr<MockSyncChangeProcessor> sync_processor_; | 273 std::unique_ptr<MockSyncChangeProcessor> sync_processor_; |
261 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> | 274 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> |
262 sync_processor_wrapper_; | 275 sync_processor_wrapper_; |
263 }; | 276 }; |
264 | 277 |
265 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS | 278 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS |
266 // sync by roughly alternative which one to test. | 279 // sync by roughly alternative which one to test. |
267 | 280 |
268 TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) { | 281 TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) { |
269 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; | 282 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; |
270 Manifest::Type type = Manifest::TYPE_EXTENSION; | 283 Manifest::Type type = Manifest::TYPE_EXTENSION; |
271 | 284 |
272 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); | 285 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
286 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); | |
287 }); | |
273 | 288 |
274 // Have one extension created before sync is set up, the other created after. | 289 // Have one extension created before sync is set up, the other created after. |
275 AddExtensionAndGetStorage("s1", type); | 290 AddExtensionAndGetStorage("s1", type); |
276 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); | |
277 | 291 |
278 GetSyncableService(model_type) | 292 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
279 ->MergeDataAndStartSyncing( | 293 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); |
280 model_type, syncer::SyncDataList(), | 294 |
281 std::move(sync_processor_wrapper_), | 295 GetSyncableService(model_type) |
282 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 296 ->MergeDataAndStartSyncing( |
297 model_type, syncer::SyncDataList(), | |
298 std::move(sync_processor_wrapper_), | |
299 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
300 }); | |
283 | 301 |
284 AddExtensionAndGetStorage("s2", type); | 302 AddExtensionAndGetStorage("s2", type); |
285 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); | |
286 | 303 |
287 GetSyncableService(model_type)->StopSyncing(model_type); | 304 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
305 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); | |
288 | 306 |
289 EXPECT_EQ(0u, sync_processor_->changes().size()); | 307 GetSyncableService(model_type)->StopSyncing(model_type); |
290 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); | 308 |
309 EXPECT_EQ(0u, sync_processor_->changes().size()); | |
310 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); | |
311 }); | |
291 } | 312 } |
292 | 313 |
293 TEST_F(ExtensionSettingsSyncTest, InSyncDataDoesNotInvokeSync) { | 314 TEST_F(ExtensionSettingsSyncTest, InSyncDataDoesNotInvokeSync) { |
294 syncer::ModelType model_type = syncer::APP_SETTINGS; | 315 syncer::ModelType model_type = syncer::APP_SETTINGS; |
295 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; | 316 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; |
296 | 317 |
297 base::Value value1("fooValue"); | 318 base::Value value1("fooValue"); |
298 base::ListValue value2; | 319 base::ListValue value2; |
299 value2.AppendString("barValue"); | 320 value2.AppendString("barValue"); |
300 | 321 |
301 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); | 322 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); |
302 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); | 323 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); |
303 | 324 |
304 storage1->Set(DEFAULTS, "foo", value1); | 325 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
305 storage2->Set(DEFAULTS, "bar", value2); | 326 storage1->Set(DEFAULTS, "foo", value1); |
327 storage2->Set(DEFAULTS, "bar", value2); | |
306 | 328 |
307 SettingSyncDataMultimap all_sync_data = GetAllSyncData(model_type); | 329 SettingSyncDataMultimap all_sync_data = GetAllSyncData(model_type); |
308 EXPECT_EQ(2u, all_sync_data.size()); | 330 EXPECT_EQ(2u, all_sync_data.size()); |
309 EXPECT_EQ(1u, all_sync_data["s1"]->size()); | 331 EXPECT_EQ(1u, all_sync_data["s1"]->size()); |
310 EXPECT_PRED_FORMAT2(ValuesEq, &value1, &(*all_sync_data["s1"])[0]->value()); | 332 EXPECT_PRED_FORMAT2(ValuesEq, &value1, &(*all_sync_data["s1"])[0]->value()); |
311 EXPECT_EQ(1u, all_sync_data["s2"]->size()); | 333 EXPECT_EQ(1u, all_sync_data["s2"]->size()); |
312 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &(*all_sync_data["s2"])[0]->value()); | 334 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &(*all_sync_data["s2"])[0]->value()); |
313 | 335 |
314 syncer::SyncDataList sync_data; | 336 syncer::SyncDataList sync_data; |
315 sync_data.push_back(settings_sync_util::CreateData( | 337 sync_data.push_back( |
316 "s1", "foo", value1, model_type)); | 338 settings_sync_util::CreateData("s1", "foo", value1, model_type)); |
317 sync_data.push_back(settings_sync_util::CreateData( | 339 sync_data.push_back( |
318 "s2", "bar", value2, model_type)); | 340 settings_sync_util::CreateData("s2", "bar", value2, model_type)); |
319 | 341 |
320 GetSyncableService(model_type) | 342 GetSyncableService(model_type) |
321 ->MergeDataAndStartSyncing( | 343 ->MergeDataAndStartSyncing( |
322 model_type, sync_data, std::move(sync_processor_wrapper_), | 344 model_type, sync_data, std::move(sync_processor_wrapper_), |
323 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 345 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
324 | 346 |
325 // Already in sync, so no changes. | 347 // Already in sync, so no changes. |
326 EXPECT_EQ(0u, sync_processor_->changes().size()); | 348 EXPECT_EQ(0u, sync_processor_->changes().size()); |
327 | 349 |
328 // Regression test: not-changing the synced value shouldn't result in a sync | 350 // Regression test: not-changing the synced value shouldn't result in a sync |
329 // change, and changing the synced value should result in an update. | 351 // change, and changing the synced value should result in an update. |
330 storage1->Set(DEFAULTS, "foo", value1); | 352 storage1->Set(DEFAULTS, "foo", value1); |
331 EXPECT_EQ(0u, sync_processor_->changes().size()); | 353 EXPECT_EQ(0u, sync_processor_->changes().size()); |
332 | 354 |
333 storage1->Set(DEFAULTS, "foo", value2); | 355 storage1->Set(DEFAULTS, "foo", value2); |
334 EXPECT_EQ(1u, sync_processor_->changes().size()); | 356 EXPECT_EQ(1u, sync_processor_->changes().size()); |
335 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "foo"); | 357 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "foo"); |
336 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); | 358 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); |
337 EXPECT_TRUE(value2.Equals(&change->value())); | 359 EXPECT_TRUE(value2.Equals(&change->value())); |
338 | 360 |
339 GetSyncableService(model_type)->StopSyncing(model_type); | 361 GetSyncableService(model_type)->StopSyncing(model_type); |
362 }); | |
340 } | 363 } |
341 | 364 |
342 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) { | 365 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) { |
343 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; | 366 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; |
344 Manifest::Type type = Manifest::TYPE_EXTENSION; | 367 Manifest::Type type = Manifest::TYPE_EXTENSION; |
345 | 368 |
346 base::Value value1("fooValue"); | 369 base::Value value1("fooValue"); |
347 base::ListValue value2; | 370 base::ListValue value2; |
348 value2.AppendString("barValue"); | 371 value2.AppendString("barValue"); |
349 | 372 |
350 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); | 373 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); |
351 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); | 374 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); |
352 | 375 |
353 storage1->Set(DEFAULTS, "foo", value1); | 376 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
354 storage2->Set(DEFAULTS, "bar", value2); | 377 storage1->Set(DEFAULTS, "foo", value1); |
378 storage2->Set(DEFAULTS, "bar", value2); | |
355 | 379 |
356 GetSyncableService(model_type) | 380 GetSyncableService(model_type) |
357 ->MergeDataAndStartSyncing( | 381 ->MergeDataAndStartSyncing( |
358 model_type, syncer::SyncDataList(), | 382 model_type, syncer::SyncDataList(), |
359 std::move(sync_processor_wrapper_), | 383 std::move(sync_processor_wrapper_), |
360 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 384 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
361 | 385 |
362 // All settings should have been pushed to sync. | 386 // All settings should have been pushed to sync. |
363 EXPECT_EQ(2u, sync_processor_->changes().size()); | 387 EXPECT_EQ(2u, sync_processor_->changes().size()); |
364 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "foo"); | 388 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "foo"); |
365 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); | 389 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); |
366 EXPECT_TRUE(value1.Equals(&change->value())); | 390 EXPECT_TRUE(value1.Equals(&change->value())); |
367 change = sync_processor_->GetOnlyChange("s2", "bar"); | 391 change = sync_processor_->GetOnlyChange("s2", "bar"); |
368 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); | 392 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); |
369 EXPECT_TRUE(value2.Equals(&change->value())); | 393 EXPECT_TRUE(value2.Equals(&change->value())); |
370 | 394 |
371 GetSyncableService(model_type)->StopSyncing(model_type); | 395 GetSyncableService(model_type)->StopSyncing(model_type); |
396 }); | |
372 } | 397 } |
373 | 398 |
374 TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) { | 399 TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) { |
375 syncer::ModelType model_type = syncer::APP_SETTINGS; | 400 syncer::ModelType model_type = syncer::APP_SETTINGS; |
376 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; | 401 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; |
377 | 402 |
378 base::Value value1("fooValue"); | 403 base::Value value1("fooValue"); |
379 base::ListValue value2; | 404 base::ListValue value2; |
380 value2.AppendString("barValue"); | 405 value2.AppendString("barValue"); |
381 | 406 |
382 // Maintain dictionaries mirrored to the expected values of the settings in | 407 // Maintain dictionaries mirrored to the expected values of the settings in |
383 // each storage area. | 408 // each storage area. |
384 base::DictionaryValue expected1, expected2; | 409 base::DictionaryValue expected1, expected2; |
385 | 410 |
386 // Pre-populate one of the storage areas. | 411 // Pre-populate one of the storage areas. |
387 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); | 412 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); |
388 storage1->Set(DEFAULTS, "overwriteMe", value1); | |
389 | 413 |
390 syncer::SyncDataList sync_data; | 414 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
391 sync_data.push_back(settings_sync_util::CreateData( | 415 storage1->Set(DEFAULTS, "overwriteMe", value1); |
392 "s1", "foo", value1, model_type)); | 416 |
393 sync_data.push_back(settings_sync_util::CreateData( | 417 syncer::SyncDataList sync_data; |
394 "s2", "bar", value2, model_type)); | 418 sync_data.push_back( |
395 GetSyncableService(model_type) | 419 settings_sync_util::CreateData("s1", "foo", value1, model_type)); |
396 ->MergeDataAndStartSyncing( | 420 sync_data.push_back( |
397 model_type, sync_data, std::move(sync_processor_wrapper_), | 421 settings_sync_util::CreateData("s2", "bar", value2, model_type)); |
398 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 422 GetSyncableService(model_type) |
399 expected1.Set("foo", value1.CreateDeepCopy()); | 423 ->MergeDataAndStartSyncing( |
400 expected2.Set("bar", value2.CreateDeepCopy()); | 424 model_type, sync_data, std::move(sync_processor_wrapper_), |
425 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
426 expected1.Set("foo", value1.CreateDeepCopy()); | |
427 expected2.Set("bar", value2.CreateDeepCopy()); | |
428 }); | |
401 | 429 |
402 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); | 430 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); |
403 | 431 |
404 // All changes should be local, so no sync changes. | 432 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
405 EXPECT_EQ(0u, sync_processor_->changes().size()); | 433 // All changes should be local, so no sync changes. |
434 EXPECT_EQ(0u, sync_processor_->changes().size()); | |
406 | 435 |
407 // Sync settings should have been pushed to local settings. | 436 // Sync settings should have been pushed to local settings. |
408 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); | 437 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); |
409 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); | 438 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); |
410 | 439 |
411 GetSyncableService(model_type)->StopSyncing(model_type); | 440 GetSyncableService(model_type)->StopSyncing(model_type); |
441 }); | |
412 } | 442 } |
413 | 443 |
414 TEST_F(ExtensionSettingsSyncTest, ProcessSyncChanges) { | 444 TEST_F(ExtensionSettingsSyncTest, ProcessSyncChanges) { |
415 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; | 445 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; |
416 Manifest::Type type = Manifest::TYPE_EXTENSION; | 446 Manifest::Type type = Manifest::TYPE_EXTENSION; |
417 | 447 |
418 base::Value value1("fooValue"); | 448 base::Value value1("fooValue"); |
419 base::ListValue value2; | 449 base::ListValue value2; |
420 value2.AppendString("barValue"); | 450 value2.AppendString("barValue"); |
421 | 451 |
422 // Maintain dictionaries mirrored to the expected values of the settings in | |
Devlin
2017/07/12 22:58:00
Reitveld's struggling with some of these diffs - a
stanisc
2017/07/12 23:42:49
Yes, more or less. Some of code blocks had to be m
| |
423 // each storage area. | |
424 base::DictionaryValue expected1, expected2; | |
425 | |
426 // Make storage1 initialised from local data, storage2 initialised from sync. | 452 // Make storage1 initialised from local data, storage2 initialised from sync. |
427 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); | 453 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); |
428 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); | 454 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); |
429 | 455 |
430 storage1->Set(DEFAULTS, "foo", value1); | 456 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
431 expected1.Set("foo", value1.CreateDeepCopy()); | 457 // Maintain dictionaries mirrored to the expected values of the settings in |
458 // each storage area. | |
459 base::DictionaryValue expected1, expected2; | |
432 | 460 |
433 syncer::SyncDataList sync_data; | 461 storage1->Set(DEFAULTS, "foo", value1); |
434 sync_data.push_back(settings_sync_util::CreateData( | 462 expected1.Set("foo", value1.CreateDeepCopy()); |
435 "s2", "bar", value2, model_type)); | |
436 | 463 |
437 GetSyncableService(model_type) | 464 syncer::SyncDataList sync_data; |
438 ->MergeDataAndStartSyncing( | 465 sync_data.push_back( |
439 model_type, sync_data, std::move(sync_processor_wrapper_), | 466 settings_sync_util::CreateData("s2", "bar", value2, model_type)); |
440 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
441 expected2.Set("bar", value2.CreateDeepCopy()); | |
442 | 467 |
443 // Make sync add some settings. | 468 GetSyncableService(model_type) |
444 syncer::SyncChangeList change_list; | 469 ->MergeDataAndStartSyncing( |
445 change_list.push_back(settings_sync_util::CreateAdd( | 470 model_type, sync_data, std::move(sync_processor_wrapper_), |
446 "s1", "bar", value2, model_type)); | 471 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
447 change_list.push_back(settings_sync_util::CreateAdd( | 472 expected2.Set("bar", value2.CreateDeepCopy()); |
448 "s2", "foo", value1, model_type)); | |
449 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | |
450 expected1.Set("bar", value2.CreateDeepCopy()); | |
451 expected2.Set("foo", value1.CreateDeepCopy()); | |
452 | 473 |
453 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); | 474 // Make sync add some settings. |
454 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); | 475 syncer::SyncChangeList change_list; |
476 change_list.push_back( | |
477 settings_sync_util::CreateAdd("s1", "bar", value2, model_type)); | |
478 change_list.push_back( | |
479 settings_sync_util::CreateAdd("s2", "foo", value1, model_type)); | |
480 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | |
481 expected1.Set("bar", value2.CreateDeepCopy()); | |
482 expected2.Set("foo", value1.CreateDeepCopy()); | |
455 | 483 |
456 // Make sync update some settings, storage1 the new setting, storage2 the | 484 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); |
457 // initial setting. | 485 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); |
458 change_list.clear(); | |
459 change_list.push_back(settings_sync_util::CreateUpdate( | |
460 "s1", "bar", value2, model_type)); | |
461 change_list.push_back(settings_sync_util::CreateUpdate( | |
462 "s2", "bar", value1, model_type)); | |
463 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | |
464 expected1.Set("bar", value2.CreateDeepCopy()); | |
465 expected2.Set("bar", value1.CreateDeepCopy()); | |
466 | 486 |
467 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); | 487 // Make sync update some settings, storage1 the new setting, storage2 the |
468 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); | 488 // initial setting. |
489 change_list.clear(); | |
490 change_list.push_back( | |
491 settings_sync_util::CreateUpdate("s1", "bar", value2, model_type)); | |
492 change_list.push_back( | |
493 settings_sync_util::CreateUpdate("s2", "bar", value1, model_type)); | |
494 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | |
495 expected1.Set("bar", value2.CreateDeepCopy()); | |
496 expected2.Set("bar", value1.CreateDeepCopy()); | |
469 | 497 |
470 // Make sync remove some settings, storage1 the initial setting, storage2 the | 498 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); |
471 // new setting. | 499 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); |
472 change_list.clear(); | |
473 change_list.push_back(settings_sync_util::CreateDelete( | |
474 "s1", "foo", model_type)); | |
475 change_list.push_back(settings_sync_util::CreateDelete( | |
476 "s2", "foo", model_type)); | |
477 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | |
478 expected1.Remove("foo", NULL); | |
479 expected2.Remove("foo", NULL); | |
480 | 500 |
481 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); | 501 // Make sync remove some settings, storage1 the initial setting, storage2 |
482 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); | 502 // the new setting. |
503 change_list.clear(); | |
504 change_list.push_back( | |
505 settings_sync_util::CreateDelete("s1", "foo", model_type)); | |
506 change_list.push_back( | |
507 settings_sync_util::CreateDelete("s2", "foo", model_type)); | |
508 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | |
509 expected1.Remove("foo", NULL); | |
510 expected2.Remove("foo", NULL); | |
483 | 511 |
484 GetSyncableService(model_type)->StopSyncing(model_type); | 512 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); |
513 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); | |
514 | |
515 GetSyncableService(model_type)->StopSyncing(model_type); | |
516 }); | |
485 } | 517 } |
486 | 518 |
487 TEST_F(ExtensionSettingsSyncTest, PushToSync) { | 519 TEST_F(ExtensionSettingsSyncTest, PushToSync) { |
488 syncer::ModelType model_type = syncer::APP_SETTINGS; | 520 syncer::ModelType model_type = syncer::APP_SETTINGS; |
489 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; | 521 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; |
490 | 522 |
491 base::Value value1("fooValue"); | 523 base::Value value1("fooValue"); |
492 base::ListValue value2; | 524 base::ListValue value2; |
493 value2.AppendString("barValue"); | 525 value2.AppendString("barValue"); |
494 | 526 |
495 // Make storage1/2 initialised from local data, storage3/4 initialised from | 527 // Make storage1/2 initialised from local data, storage3/4 initialised from |
496 // sync. | 528 // sync. |
497 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); | 529 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); |
498 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); | 530 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); |
499 ValueStore* storage3 = AddExtensionAndGetStorage("s3", type); | 531 ValueStore* storage3 = AddExtensionAndGetStorage("s3", type); |
500 ValueStore* storage4 = AddExtensionAndGetStorage("s4", type); | 532 ValueStore* storage4 = AddExtensionAndGetStorage("s4", type); |
501 | 533 |
502 storage1->Set(DEFAULTS, "foo", value1); | 534 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
503 storage2->Set(DEFAULTS, "foo", value1); | 535 storage1->Set(DEFAULTS, "foo", value1); |
536 storage2->Set(DEFAULTS, "foo", value1); | |
504 | 537 |
505 syncer::SyncDataList sync_data; | 538 syncer::SyncDataList sync_data; |
506 sync_data.push_back(settings_sync_util::CreateData( | 539 sync_data.push_back( |
507 "s3", "bar", value2, model_type)); | 540 settings_sync_util::CreateData("s3", "bar", value2, model_type)); |
508 sync_data.push_back(settings_sync_util::CreateData( | 541 sync_data.push_back( |
509 "s4", "bar", value2, model_type)); | 542 settings_sync_util::CreateData("s4", "bar", value2, model_type)); |
510 | 543 |
511 GetSyncableService(model_type) | 544 GetSyncableService(model_type) |
512 ->MergeDataAndStartSyncing( | 545 ->MergeDataAndStartSyncing( |
513 model_type, sync_data, std::move(sync_processor_wrapper_), | 546 model_type, sync_data, std::move(sync_processor_wrapper_), |
514 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 547 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
515 | 548 |
516 // Add something locally. | 549 // Add something locally. |
517 storage1->Set(DEFAULTS, "bar", value2); | 550 storage1->Set(DEFAULTS, "bar", value2); |
518 storage2->Set(DEFAULTS, "bar", value2); | 551 storage2->Set(DEFAULTS, "bar", value2); |
519 storage3->Set(DEFAULTS, "foo", value1); | 552 storage3->Set(DEFAULTS, "foo", value1); |
520 storage4->Set(DEFAULTS, "foo", value1); | 553 storage4->Set(DEFAULTS, "foo", value1); |
521 | 554 |
522 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "bar"); | 555 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "bar"); |
523 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); | 556 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); |
524 EXPECT_TRUE(value2.Equals(&change->value())); | 557 EXPECT_TRUE(value2.Equals(&change->value())); |
525 sync_processor_->GetOnlyChange("s2", "bar"); | 558 sync_processor_->GetOnlyChange("s2", "bar"); |
526 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); | 559 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); |
527 EXPECT_TRUE(value2.Equals(&change->value())); | 560 EXPECT_TRUE(value2.Equals(&change->value())); |
528 change = sync_processor_->GetOnlyChange("s3", "foo"); | 561 change = sync_processor_->GetOnlyChange("s3", "foo"); |
529 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); | 562 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); |
530 EXPECT_TRUE(value1.Equals(&change->value())); | 563 EXPECT_TRUE(value1.Equals(&change->value())); |
531 change = sync_processor_->GetOnlyChange("s4", "foo"); | 564 change = sync_processor_->GetOnlyChange("s4", "foo"); |
532 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); | 565 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); |
533 EXPECT_TRUE(value1.Equals(&change->value())); | 566 EXPECT_TRUE(value1.Equals(&change->value())); |
534 | 567 |
535 // Change something locally, storage1/3 the new setting and storage2/4 the | 568 // Change something locally, storage1/3 the new setting and storage2/4 the |
536 // initial setting, for all combinations of local vs sync intialisation and | 569 // initial setting, for all combinations of local vs sync intialisation and |
537 // new vs initial. | 570 // new vs initial. |
538 sync_processor_->ClearChanges(); | 571 sync_processor_->ClearChanges(); |
539 storage1->Set(DEFAULTS, "bar", value1); | 572 storage1->Set(DEFAULTS, "bar", value1); |
540 storage2->Set(DEFAULTS, "foo", value2); | 573 storage2->Set(DEFAULTS, "foo", value2); |
541 storage3->Set(DEFAULTS, "bar", value1); | 574 storage3->Set(DEFAULTS, "bar", value1); |
542 storage4->Set(DEFAULTS, "foo", value2); | 575 storage4->Set(DEFAULTS, "foo", value2); |
543 | 576 |
544 change = sync_processor_->GetOnlyChange("s1", "bar"); | 577 change = sync_processor_->GetOnlyChange("s1", "bar"); |
545 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); | 578 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); |
546 EXPECT_TRUE(value1.Equals(&change->value())); | 579 EXPECT_TRUE(value1.Equals(&change->value())); |
547 change = sync_processor_->GetOnlyChange("s2", "foo"); | 580 change = sync_processor_->GetOnlyChange("s2", "foo"); |
548 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); | 581 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); |
549 EXPECT_TRUE(value2.Equals(&change->value())); | 582 EXPECT_TRUE(value2.Equals(&change->value())); |
550 change = sync_processor_->GetOnlyChange("s3", "bar"); | 583 change = sync_processor_->GetOnlyChange("s3", "bar"); |
551 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); | 584 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); |
552 EXPECT_TRUE(value1.Equals(&change->value())); | 585 EXPECT_TRUE(value1.Equals(&change->value())); |
553 change = sync_processor_->GetOnlyChange("s4", "foo"); | 586 change = sync_processor_->GetOnlyChange("s4", "foo"); |
554 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); | 587 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change->change_type()); |
555 EXPECT_TRUE(value2.Equals(&change->value())); | 588 EXPECT_TRUE(value2.Equals(&change->value())); |
556 | 589 |
557 // Remove something locally, storage1/3 the new setting and storage2/4 the | 590 // Remove something locally, storage1/3 the new setting and storage2/4 the |
558 // initial setting, for all combinations of local vs sync intialisation and | 591 // initial setting, for all combinations of local vs sync intialisation and |
559 // new vs initial. | 592 // new vs initial. |
560 sync_processor_->ClearChanges(); | 593 sync_processor_->ClearChanges(); |
561 storage1->Remove("foo"); | 594 storage1->Remove("foo"); |
562 storage2->Remove("bar"); | 595 storage2->Remove("bar"); |
563 storage3->Remove("foo"); | 596 storage3->Remove("foo"); |
564 storage4->Remove("bar"); | 597 storage4->Remove("bar"); |
565 | 598 |
566 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 599 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
567 sync_processor_->GetOnlyChange("s1", "foo")->change_type()); | 600 sync_processor_->GetOnlyChange("s1", "foo")->change_type()); |
568 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 601 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
569 sync_processor_->GetOnlyChange("s2", "bar")->change_type()); | 602 sync_processor_->GetOnlyChange("s2", "bar")->change_type()); |
570 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 603 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
571 sync_processor_->GetOnlyChange("s3", "foo")->change_type()); | 604 sync_processor_->GetOnlyChange("s3", "foo")->change_type()); |
572 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 605 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
573 sync_processor_->GetOnlyChange("s4", "bar")->change_type()); | 606 sync_processor_->GetOnlyChange("s4", "bar")->change_type()); |
574 | 607 |
575 // Remove some nonexistent settings. | 608 // Remove some nonexistent settings. |
576 sync_processor_->ClearChanges(); | 609 sync_processor_->ClearChanges(); |
577 storage1->Remove("foo"); | 610 storage1->Remove("foo"); |
578 storage2->Remove("bar"); | 611 storage2->Remove("bar"); |
579 storage3->Remove("foo"); | 612 storage3->Remove("foo"); |
580 storage4->Remove("bar"); | 613 storage4->Remove("bar"); |
581 | 614 |
582 EXPECT_EQ(0u, sync_processor_->changes().size()); | 615 EXPECT_EQ(0u, sync_processor_->changes().size()); |
583 | 616 |
584 // Clear the rest of the settings. Add the removed ones back first so that | 617 // Clear the rest of the settings. Add the removed ones back first so that |
585 // more than one setting is cleared. | 618 // more than one setting is cleared. |
586 storage1->Set(DEFAULTS, "foo", value1); | 619 storage1->Set(DEFAULTS, "foo", value1); |
587 storage2->Set(DEFAULTS, "bar", value2); | 620 storage2->Set(DEFAULTS, "bar", value2); |
588 storage3->Set(DEFAULTS, "foo", value1); | 621 storage3->Set(DEFAULTS, "foo", value1); |
589 storage4->Set(DEFAULTS, "bar", value2); | 622 storage4->Set(DEFAULTS, "bar", value2); |
590 | 623 |
591 sync_processor_->ClearChanges(); | 624 sync_processor_->ClearChanges(); |
592 storage1->Clear(); | 625 storage1->Clear(); |
593 storage2->Clear(); | 626 storage2->Clear(); |
594 storage3->Clear(); | 627 storage3->Clear(); |
595 storage4->Clear(); | 628 storage4->Clear(); |
596 | 629 |
597 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 630 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
598 sync_processor_->GetOnlyChange("s1", "foo")->change_type()); | 631 sync_processor_->GetOnlyChange("s1", "foo")->change_type()); |
599 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 632 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
600 sync_processor_->GetOnlyChange("s1", "bar")->change_type()); | 633 sync_processor_->GetOnlyChange("s1", "bar")->change_type()); |
601 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 634 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
602 sync_processor_->GetOnlyChange("s2", "foo")->change_type()); | 635 sync_processor_->GetOnlyChange("s2", "foo")->change_type()); |
603 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 636 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
604 sync_processor_->GetOnlyChange("s2", "bar")->change_type()); | 637 sync_processor_->GetOnlyChange("s2", "bar")->change_type()); |
605 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 638 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
606 sync_processor_->GetOnlyChange("s3", "foo")->change_type()); | 639 sync_processor_->GetOnlyChange("s3", "foo")->change_type()); |
607 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 640 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
608 sync_processor_->GetOnlyChange("s3", "bar")->change_type()); | 641 sync_processor_->GetOnlyChange("s3", "bar")->change_type()); |
609 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 642 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
610 sync_processor_->GetOnlyChange("s4", "foo")->change_type()); | 643 sync_processor_->GetOnlyChange("s4", "foo")->change_type()); |
611 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, | 644 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, |
612 sync_processor_->GetOnlyChange("s4", "bar")->change_type()); | 645 sync_processor_->GetOnlyChange("s4", "bar")->change_type()); |
613 | 646 |
614 GetSyncableService(model_type)->StopSyncing(model_type); | 647 GetSyncableService(model_type)->StopSyncing(model_type); |
648 }); | |
615 } | 649 } |
616 | 650 |
617 TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) { | 651 TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) { |
618 base::Value value1("fooValue"); | 652 base::Value value1("fooValue"); |
619 base::ListValue value2; | 653 base::ListValue value2; |
620 value2.AppendString("barValue"); | 654 value2.AppendString("barValue"); |
621 | 655 |
622 // storage1 is an extension, storage2 is an app. | 656 // storage1 is an extension, storage2 is an app. |
623 ValueStore* storage1 = AddExtensionAndGetStorage( | 657 ValueStore* storage1 = AddExtensionAndGetStorage( |
624 "s1", Manifest::TYPE_EXTENSION); | 658 "s1", Manifest::TYPE_EXTENSION); |
625 ValueStore* storage2 = AddExtensionAndGetStorage( | 659 ValueStore* storage2 = AddExtensionAndGetStorage( |
626 "s2", Manifest::TYPE_LEGACY_PACKAGED_APP); | 660 "s2", Manifest::TYPE_LEGACY_PACKAGED_APP); |
627 | 661 |
628 storage1->Set(DEFAULTS, "foo", value1); | 662 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
629 storage2->Set(DEFAULTS, "bar", value2); | 663 storage1->Set(DEFAULTS, "foo", value1); |
664 storage2->Set(DEFAULTS, "bar", value2); | |
630 | 665 |
631 SettingSyncDataMultimap extension_sync_data = | 666 SettingSyncDataMultimap extension_sync_data = |
632 GetAllSyncData(syncer::EXTENSION_SETTINGS); | 667 GetAllSyncData(syncer::EXTENSION_SETTINGS); |
633 EXPECT_EQ(1u, extension_sync_data.size()); | 668 EXPECT_EQ(1u, extension_sync_data.size()); |
634 EXPECT_EQ(1u, extension_sync_data["s1"]->size()); | 669 EXPECT_EQ(1u, extension_sync_data["s1"]->size()); |
635 EXPECT_PRED_FORMAT2(ValuesEq, &value1, | 670 EXPECT_PRED_FORMAT2(ValuesEq, &value1, |
636 &(*extension_sync_data["s1"])[0]->value()); | 671 &(*extension_sync_data["s1"])[0]->value()); |
637 | 672 |
638 SettingSyncDataMultimap app_sync_data = GetAllSyncData(syncer::APP_SETTINGS); | 673 SettingSyncDataMultimap app_sync_data = |
639 EXPECT_EQ(1u, app_sync_data.size()); | 674 GetAllSyncData(syncer::APP_SETTINGS); |
640 EXPECT_EQ(1u, app_sync_data["s2"]->size()); | 675 EXPECT_EQ(1u, app_sync_data.size()); |
641 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &(*app_sync_data["s2"])[0]->value()); | 676 EXPECT_EQ(1u, app_sync_data["s2"]->size()); |
677 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &(*app_sync_data["s2"])[0]->value()); | |
642 | 678 |
643 // Stop each separately, there should be no changes either time. | 679 // Stop each separately, there should be no changes either time. |
644 syncer::SyncDataList sync_data; | 680 syncer::SyncDataList sync_data; |
645 sync_data.push_back(settings_sync_util::CreateData( | 681 sync_data.push_back(settings_sync_util::CreateData( |
646 "s1", "foo", value1, syncer::EXTENSION_SETTINGS)); | 682 "s1", "foo", value1, syncer::EXTENSION_SETTINGS)); |
647 | 683 |
648 GetSyncableService(syncer::EXTENSION_SETTINGS) | 684 GetSyncableService(syncer::EXTENSION_SETTINGS) |
649 ->MergeDataAndStartSyncing( | 685 ->MergeDataAndStartSyncing( |
650 syncer::EXTENSION_SETTINGS, sync_data, | 686 syncer::EXTENSION_SETTINGS, sync_data, |
651 std::move(sync_processor_wrapper_), | 687 std::move(sync_processor_wrapper_), |
652 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 688 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
653 GetSyncableService(syncer::EXTENSION_SETTINGS)-> | 689 GetSyncableService(syncer::EXTENSION_SETTINGS) |
654 StopSyncing(syncer::EXTENSION_SETTINGS); | 690 ->StopSyncing(syncer::EXTENSION_SETTINGS); |
655 EXPECT_EQ(0u, sync_processor_->changes().size()); | 691 EXPECT_EQ(0u, sync_processor_->changes().size()); |
656 | 692 |
657 sync_data.clear(); | 693 sync_data.clear(); |
658 sync_data.push_back(settings_sync_util::CreateData( | 694 sync_data.push_back(settings_sync_util::CreateData("s2", "bar", value2, |
659 "s2", "bar", value2, syncer::APP_SETTINGS)); | 695 syncer::APP_SETTINGS)); |
660 | 696 |
661 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> | 697 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> |
662 app_settings_delegate_( | 698 app_settings_delegate_(new syncer::SyncChangeProcessorWrapperForTest( |
663 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); | 699 sync_processor_.get())); |
664 GetSyncableService(syncer::APP_SETTINGS) | 700 GetSyncableService(syncer::APP_SETTINGS) |
665 ->MergeDataAndStartSyncing( | 701 ->MergeDataAndStartSyncing( |
666 syncer::APP_SETTINGS, sync_data, std::move(app_settings_delegate_), | 702 syncer::APP_SETTINGS, sync_data, std::move(app_settings_delegate_), |
667 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 703 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
668 GetSyncableService(syncer::APP_SETTINGS)-> | 704 GetSyncableService(syncer::APP_SETTINGS)->StopSyncing(syncer::APP_SETTINGS); |
669 StopSyncing(syncer::APP_SETTINGS); | 705 EXPECT_EQ(0u, sync_processor_->changes().size()); |
670 EXPECT_EQ(0u, sync_processor_->changes().size()); | 706 }); |
671 } | 707 } |
672 | 708 |
673 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) { | 709 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) { |
674 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; | 710 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; |
675 Manifest::Type type = Manifest::TYPE_EXTENSION; | 711 Manifest::Type type = Manifest::TYPE_EXTENSION; |
676 | 712 |
677 base::Value fooValue("fooValue"); | 713 base::Value fooValue("fooValue"); |
678 base::Value barValue("barValue"); | 714 base::Value barValue("barValue"); |
679 | 715 |
680 // There is a bit of a convoluted method to get storage areas that can fail; | 716 // There is a bit of a convoluted method to get storage areas that can fail; |
681 // hand out TestingValueStore object then toggle them failing/succeeding | 717 // hand out TestingValueStore object then toggle them failing/succeeding |
682 // as necessary. | 718 // as necessary. |
683 | 719 |
684 ValueStore* good = AddExtensionAndGetStorage("good", type); | 720 ValueStore* good = AddExtensionAndGetStorage("good", type); |
685 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 721 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
686 | 722 |
687 // Make bad fail for incoming sync changes. | 723 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
688 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); | 724 // Make bad fail for incoming sync changes. |
689 { | 725 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); |
690 syncer::SyncDataList sync_data; | 726 { |
691 sync_data.push_back(settings_sync_util::CreateData( | 727 syncer::SyncDataList sync_data; |
728 sync_data.push_back( | |
729 settings_sync_util::CreateData("good", "foo", fooValue, model_type)); | |
730 sync_data.push_back( | |
731 settings_sync_util::CreateData("bad", "foo", fooValue, model_type)); | |
732 GetSyncableService(model_type) | |
733 ->MergeDataAndStartSyncing( | |
734 model_type, sync_data, std::move(sync_processor_wrapper_), | |
735 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
736 } | |
737 GetExisting("bad")->set_status_code(ValueStore::OK); | |
738 | |
739 { | |
740 base::DictionaryValue dict; | |
741 dict.Set("foo", fooValue.CreateDeepCopy()); | |
742 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
743 } | |
744 { | |
745 base::DictionaryValue dict; | |
746 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
747 } | |
748 | |
749 // Changes made to good should be sent to sync, changes from bad shouldn't. | |
750 sync_processor_->ClearChanges(); | |
751 good->Set(DEFAULTS, "bar", barValue); | |
752 bad->Set(DEFAULTS, "bar", barValue); | |
753 | |
754 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | |
755 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | |
756 EXPECT_EQ(1u, sync_processor_->changes().size()); | |
757 | |
758 { | |
759 base::DictionaryValue dict; | |
760 dict.Set("foo", fooValue.CreateDeepCopy()); | |
761 dict.Set("bar", barValue.CreateDeepCopy()); | |
762 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
763 } | |
764 { | |
765 base::DictionaryValue dict; | |
766 dict.Set("bar", barValue.CreateDeepCopy()); | |
767 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
768 } | |
769 | |
770 // Changes received from sync should go to good but not bad (even when it's | |
771 // not failing). | |
772 { | |
773 syncer::SyncChangeList change_list; | |
774 change_list.push_back(settings_sync_util::CreateUpdate( | |
775 "good", "foo", barValue, model_type)); | |
776 // (Sending UPDATE here even though it's adding, since that's what the | |
777 // state of sync is. In any case, it won't work.) | |
778 change_list.push_back( | |
779 settings_sync_util::CreateUpdate("bad", "foo", barValue, model_type)); | |
780 GetSyncableService(model_type) | |
781 ->ProcessSyncChanges(FROM_HERE, change_list); | |
782 } | |
783 | |
784 { | |
785 base::DictionaryValue dict; | |
786 dict.Set("foo", barValue.CreateDeepCopy()); | |
787 dict.Set("bar", barValue.CreateDeepCopy()); | |
788 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
789 } | |
790 { | |
791 base::DictionaryValue dict; | |
792 dict.Set("bar", barValue.CreateDeepCopy()); | |
793 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
794 } | |
795 | |
796 // Changes made to bad still shouldn't go to sync, even though it didn't | |
797 // fail last time. | |
798 sync_processor_->ClearChanges(); | |
799 good->Set(DEFAULTS, "bar", fooValue); | |
800 bad->Set(DEFAULTS, "bar", fooValue); | |
801 | |
802 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | |
803 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | |
804 EXPECT_EQ(1u, sync_processor_->changes().size()); | |
805 | |
806 { | |
807 base::DictionaryValue dict; | |
808 dict.Set("foo", barValue.CreateDeepCopy()); | |
809 dict.Set("bar", fooValue.CreateDeepCopy()); | |
810 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
811 } | |
812 { | |
813 base::DictionaryValue dict; | |
814 dict.Set("bar", fooValue.CreateDeepCopy()); | |
815 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
816 } | |
817 | |
818 // Failing ProcessSyncChanges shouldn't go to the storage. | |
819 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); | |
820 { | |
821 syncer::SyncChangeList change_list; | |
822 change_list.push_back(settings_sync_util::CreateUpdate( | |
692 "good", "foo", fooValue, model_type)); | 823 "good", "foo", fooValue, model_type)); |
693 sync_data.push_back(settings_sync_util::CreateData( | 824 // (Ditto.) |
694 "bad", "foo", fooValue, model_type)); | 825 change_list.push_back( |
826 settings_sync_util::CreateUpdate("bad", "foo", fooValue, model_type)); | |
827 GetSyncableService(model_type) | |
828 ->ProcessSyncChanges(FROM_HERE, change_list); | |
829 } | |
830 GetExisting("bad")->set_status_code(ValueStore::OK); | |
831 | |
832 { | |
833 base::DictionaryValue dict; | |
834 dict.Set("foo", fooValue.CreateDeepCopy()); | |
835 dict.Set("bar", fooValue.CreateDeepCopy()); | |
836 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
837 } | |
838 { | |
839 base::DictionaryValue dict; | |
840 dict.Set("bar", fooValue.CreateDeepCopy()); | |
841 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
842 } | |
843 | |
844 // Restarting sync should make bad start syncing again. | |
845 sync_processor_->ClearChanges(); | |
846 GetSyncableService(model_type)->StopSyncing(model_type); | |
847 sync_processor_wrapper_.reset( | |
848 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); | |
695 GetSyncableService(model_type) | 849 GetSyncableService(model_type) |
696 ->MergeDataAndStartSyncing( | 850 ->MergeDataAndStartSyncing( |
697 model_type, sync_data, std::move(sync_processor_wrapper_), | 851 model_type, syncer::SyncDataList(), |
852 std::move(sync_processor_wrapper_), | |
698 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 853 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
699 } | |
700 GetExisting("bad")->set_status_code(ValueStore::OK); | |
701 | 854 |
702 { | 855 // Local settings will have been pushed to sync, since it's empty (in this |
703 base::DictionaryValue dict; | 856 // test; presumably it wouldn't be live, since we've been getting changes). |
704 dict.Set("foo", fooValue.CreateDeepCopy()); | 857 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
705 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 858 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
706 } | 859 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
707 { | 860 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
708 base::DictionaryValue dict; | 861 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
709 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 862 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); |
710 } | 863 EXPECT_EQ(3u, sync_processor_->changes().size()); |
711 | 864 |
712 // Changes made to good should be sent to sync, changes from bad shouldn't. | 865 // Live local changes now get pushed, too. |
713 sync_processor_->ClearChanges(); | 866 sync_processor_->ClearChanges(); |
714 good->Set(DEFAULTS, "bar", barValue); | 867 good->Set(DEFAULTS, "bar", barValue); |
715 bad->Set(DEFAULTS, "bar", barValue); | 868 bad->Set(DEFAULTS, "bar", barValue); |
716 | 869 |
717 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 870 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
718 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | 871 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
719 EXPECT_EQ(1u, sync_processor_->changes().size()); | 872 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
873 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); | |
874 EXPECT_EQ(2u, sync_processor_->changes().size()); | |
720 | 875 |
721 { | 876 // And ProcessSyncChanges work, too. |
722 base::DictionaryValue dict; | 877 { |
723 dict.Set("foo", fooValue.CreateDeepCopy()); | 878 syncer::SyncChangeList change_list; |
724 dict.Set("bar", barValue.CreateDeepCopy()); | 879 change_list.push_back(settings_sync_util::CreateUpdate( |
725 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 880 "good", "bar", fooValue, model_type)); |
726 } | 881 change_list.push_back( |
727 { | 882 settings_sync_util::CreateUpdate("bad", "bar", fooValue, model_type)); |
728 base::DictionaryValue dict; | 883 GetSyncableService(model_type) |
729 dict.Set("bar", barValue.CreateDeepCopy()); | 884 ->ProcessSyncChanges(FROM_HERE, change_list); |
730 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 885 } |
731 } | |
732 | 886 |
733 // Changes received from sync should go to good but not bad (even when it's | 887 { |
734 // not failing). | 888 base::DictionaryValue dict; |
735 { | 889 dict.Set("foo", fooValue.CreateDeepCopy()); |
736 syncer::SyncChangeList change_list; | 890 dict.Set("bar", fooValue.CreateDeepCopy()); |
737 change_list.push_back(settings_sync_util::CreateUpdate( | 891 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
738 "good", "foo", barValue, model_type)); | 892 } |
739 // (Sending UPDATE here even though it's adding, since that's what the state | 893 { |
740 // of sync is. In any case, it won't work.) | 894 base::DictionaryValue dict; |
741 change_list.push_back(settings_sync_util::CreateUpdate( | 895 dict.Set("bar", fooValue.CreateDeepCopy()); |
742 "bad", "foo", barValue, model_type)); | 896 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
743 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 897 } |
744 } | 898 }); |
745 | |
746 { | |
747 base::DictionaryValue dict; | |
748 dict.Set("foo", barValue.CreateDeepCopy()); | |
749 dict.Set("bar", barValue.CreateDeepCopy()); | |
750 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
751 } | |
752 { | |
753 base::DictionaryValue dict; | |
754 dict.Set("bar", barValue.CreateDeepCopy()); | |
755 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
756 } | |
757 | |
758 // Changes made to bad still shouldn't go to sync, even though it didn't fail | |
759 // last time. | |
760 sync_processor_->ClearChanges(); | |
761 good->Set(DEFAULTS, "bar", fooValue); | |
762 bad->Set(DEFAULTS, "bar", fooValue); | |
763 | |
764 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | |
765 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | |
766 EXPECT_EQ(1u, sync_processor_->changes().size()); | |
767 | |
768 { | |
769 base::DictionaryValue dict; | |
770 dict.Set("foo", barValue.CreateDeepCopy()); | |
771 dict.Set("bar", fooValue.CreateDeepCopy()); | |
772 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
773 } | |
774 { | |
775 base::DictionaryValue dict; | |
776 dict.Set("bar", fooValue.CreateDeepCopy()); | |
777 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
778 } | |
779 | |
780 // Failing ProcessSyncChanges shouldn't go to the storage. | |
781 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); | |
782 { | |
783 syncer::SyncChangeList change_list; | |
784 change_list.push_back(settings_sync_util::CreateUpdate( | |
785 "good", "foo", fooValue, model_type)); | |
786 // (Ditto.) | |
787 change_list.push_back(settings_sync_util::CreateUpdate( | |
788 "bad", "foo", fooValue, model_type)); | |
789 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | |
790 } | |
791 GetExisting("bad")->set_status_code(ValueStore::OK); | |
792 | |
793 { | |
794 base::DictionaryValue dict; | |
795 dict.Set("foo", fooValue.CreateDeepCopy()); | |
796 dict.Set("bar", fooValue.CreateDeepCopy()); | |
797 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
798 } | |
799 { | |
800 base::DictionaryValue dict; | |
801 dict.Set("bar", fooValue.CreateDeepCopy()); | |
802 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
803 } | |
804 | |
805 // Restarting sync should make bad start syncing again. | |
806 sync_processor_->ClearChanges(); | |
807 GetSyncableService(model_type)->StopSyncing(model_type); | |
808 sync_processor_wrapper_.reset( | |
809 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); | |
810 GetSyncableService(model_type) | |
811 ->MergeDataAndStartSyncing( | |
812 model_type, syncer::SyncDataList(), | |
813 std::move(sync_processor_wrapper_), | |
814 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
815 | |
816 // Local settings will have been pushed to sync, since it's empty (in this | |
817 // test; presumably it wouldn't be live, since we've been getting changes). | |
818 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | |
819 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | |
820 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | |
821 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | |
822 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | |
823 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); | |
824 EXPECT_EQ(3u, sync_processor_->changes().size()); | |
825 | |
826 // Live local changes now get pushed, too. | |
827 sync_processor_->ClearChanges(); | |
828 good->Set(DEFAULTS, "bar", barValue); | |
829 bad->Set(DEFAULTS, "bar", barValue); | |
830 | |
831 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | |
832 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | |
833 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | |
834 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); | |
835 EXPECT_EQ(2u, sync_processor_->changes().size()); | |
836 | |
837 // And ProcessSyncChanges work, too. | |
838 { | |
839 syncer::SyncChangeList change_list; | |
840 change_list.push_back(settings_sync_util::CreateUpdate( | |
841 "good", "bar", fooValue, model_type)); | |
842 change_list.push_back(settings_sync_util::CreateUpdate( | |
843 "bad", "bar", fooValue, model_type)); | |
844 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | |
845 } | |
846 | |
847 { | |
848 base::DictionaryValue dict; | |
849 dict.Set("foo", fooValue.CreateDeepCopy()); | |
850 dict.Set("bar", fooValue.CreateDeepCopy()); | |
851 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | |
852 } | |
853 { | |
854 base::DictionaryValue dict; | |
855 dict.Set("bar", fooValue.CreateDeepCopy()); | |
856 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | |
857 } | |
858 } | 899 } |
859 | 900 |
860 TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) { | 901 TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) { |
861 // The test above tests a failing ProcessSyncChanges too, but here test with | 902 // The test above tests a failing ProcessSyncChanges too, but here test with |
862 // an initially passing MergeDataAndStartSyncing. | 903 // an initially passing MergeDataAndStartSyncing. |
863 syncer::ModelType model_type = syncer::APP_SETTINGS; | 904 syncer::ModelType model_type = syncer::APP_SETTINGS; |
864 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; | 905 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; |
865 | 906 |
866 base::Value fooValue("fooValue"); | 907 base::Value fooValue("fooValue"); |
867 base::Value barValue("barValue"); | 908 base::Value barValue("barValue"); |
868 | 909 |
869 ValueStore* good = AddExtensionAndGetStorage("good", type); | 910 ValueStore* good = AddExtensionAndGetStorage("good", type); |
870 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 911 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
871 | 912 |
872 // Unlike before, initially succeeding MergeDataAndStartSyncing. | 913 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
873 { | 914 // Unlike before, initially succeeding MergeDataAndStartSyncing. |
874 syncer::SyncDataList sync_data; | 915 { |
875 sync_data.push_back(settings_sync_util::CreateData( | 916 syncer::SyncDataList sync_data; |
876 "good", "foo", fooValue, model_type)); | 917 sync_data.push_back( |
877 sync_data.push_back(settings_sync_util::CreateData( | 918 settings_sync_util::CreateData("good", "foo", fooValue, model_type)); |
878 "bad", "foo", fooValue, model_type)); | 919 sync_data.push_back( |
879 GetSyncableService(model_type) | 920 settings_sync_util::CreateData("bad", "foo", fooValue, model_type)); |
880 ->MergeDataAndStartSyncing( | 921 GetSyncableService(model_type) |
881 model_type, sync_data, std::move(sync_processor_wrapper_), | 922 ->MergeDataAndStartSyncing( |
882 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 923 model_type, sync_data, std::move(sync_processor_wrapper_), |
883 } | 924 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
925 } | |
884 | 926 |
885 EXPECT_EQ(0u, sync_processor_->changes().size()); | 927 EXPECT_EQ(0u, sync_processor_->changes().size()); |
886 | 928 |
887 { | 929 { |
888 base::DictionaryValue dict; | 930 base::DictionaryValue dict; |
889 dict.Set("foo", fooValue.CreateDeepCopy()); | 931 dict.Set("foo", fooValue.CreateDeepCopy()); |
890 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 932 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
891 } | 933 } |
892 { | 934 { |
893 base::DictionaryValue dict; | 935 base::DictionaryValue dict; |
894 dict.Set("foo", fooValue.CreateDeepCopy()); | 936 dict.Set("foo", fooValue.CreateDeepCopy()); |
895 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 937 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
896 } | 938 } |
897 | 939 |
898 // Now fail ProcessSyncChanges for bad. | 940 // Now fail ProcessSyncChanges for bad. |
899 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); | 941 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); |
900 { | 942 { |
901 syncer::SyncChangeList change_list; | 943 syncer::SyncChangeList change_list; |
902 change_list.push_back(settings_sync_util::CreateAdd( | 944 change_list.push_back( |
903 "good", "bar", barValue, model_type)); | 945 settings_sync_util::CreateAdd("good", "bar", barValue, model_type)); |
904 change_list.push_back(settings_sync_util::CreateAdd( | 946 change_list.push_back( |
905 "bad", "bar", barValue, model_type)); | 947 settings_sync_util::CreateAdd("bad", "bar", barValue, model_type)); |
906 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 948 GetSyncableService(model_type) |
907 } | 949 ->ProcessSyncChanges(FROM_HERE, change_list); |
908 GetExisting("bad")->set_status_code(ValueStore::OK); | 950 } |
951 GetExisting("bad")->set_status_code(ValueStore::OK); | |
909 | 952 |
910 { | 953 { |
911 base::DictionaryValue dict; | 954 base::DictionaryValue dict; |
912 dict.Set("foo", fooValue.CreateDeepCopy()); | 955 dict.Set("foo", fooValue.CreateDeepCopy()); |
913 dict.Set("bar", barValue.CreateDeepCopy()); | 956 dict.Set("bar", barValue.CreateDeepCopy()); |
914 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 957 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
915 } | 958 } |
916 { | 959 { |
917 base::DictionaryValue dict; | 960 base::DictionaryValue dict; |
918 dict.Set("foo", fooValue.CreateDeepCopy()); | 961 dict.Set("foo", fooValue.CreateDeepCopy()); |
919 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 962 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
920 } | 963 } |
921 | 964 |
922 // No more changes sent to sync for bad. | 965 // No more changes sent to sync for bad. |
923 sync_processor_->ClearChanges(); | 966 sync_processor_->ClearChanges(); |
924 good->Set(DEFAULTS, "foo", barValue); | 967 good->Set(DEFAULTS, "foo", barValue); |
925 bad->Set(DEFAULTS, "foo", barValue); | 968 bad->Set(DEFAULTS, "foo", barValue); |
926 | 969 |
927 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 970 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
928 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 971 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
929 EXPECT_EQ(1u, sync_processor_->changes().size()); | 972 EXPECT_EQ(1u, sync_processor_->changes().size()); |
930 | 973 |
931 // No more changes received from sync should go to bad. | 974 // No more changes received from sync should go to bad. |
932 { | 975 { |
933 syncer::SyncChangeList change_list; | 976 syncer::SyncChangeList change_list; |
934 change_list.push_back(settings_sync_util::CreateAdd( | 977 change_list.push_back( |
935 "good", "foo", fooValue, model_type)); | 978 settings_sync_util::CreateAdd("good", "foo", fooValue, model_type)); |
936 change_list.push_back(settings_sync_util::CreateAdd( | 979 change_list.push_back( |
937 "bad", "foo", fooValue, model_type)); | 980 settings_sync_util::CreateAdd("bad", "foo", fooValue, model_type)); |
938 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 981 GetSyncableService(model_type) |
939 } | 982 ->ProcessSyncChanges(FROM_HERE, change_list); |
983 } | |
940 | 984 |
941 { | 985 { |
942 base::DictionaryValue dict; | 986 base::DictionaryValue dict; |
943 dict.Set("foo", fooValue.CreateDeepCopy()); | 987 dict.Set("foo", fooValue.CreateDeepCopy()); |
944 dict.Set("bar", barValue.CreateDeepCopy()); | 988 dict.Set("bar", barValue.CreateDeepCopy()); |
945 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 989 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
946 } | 990 } |
947 { | 991 { |
948 base::DictionaryValue dict; | 992 base::DictionaryValue dict; |
949 dict.Set("foo", barValue.CreateDeepCopy()); | 993 dict.Set("foo", barValue.CreateDeepCopy()); |
950 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 994 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
951 } | 995 } |
996 }); | |
952 } | 997 } |
953 | 998 |
954 TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) { | 999 TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) { |
955 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; | 1000 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; |
956 Manifest::Type type = Manifest::TYPE_EXTENSION; | 1001 Manifest::Type type = Manifest::TYPE_EXTENSION; |
957 | 1002 |
958 base::Value fooValue("fooValue"); | 1003 base::Value fooValue("fooValue"); |
959 base::Value barValue("barValue"); | 1004 base::Value barValue("barValue"); |
960 | 1005 |
961 ValueStore* good = AddExtensionAndGetStorage("good", type); | 1006 ValueStore* good = AddExtensionAndGetStorage("good", type); |
962 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 1007 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
963 | 1008 |
964 good->Set(DEFAULTS, "foo", fooValue); | 1009 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
965 bad->Set(DEFAULTS, "foo", fooValue); | 1010 good->Set(DEFAULTS, "foo", fooValue); |
1011 bad->Set(DEFAULTS, "foo", fooValue); | |
966 | 1012 |
967 // Even though bad will fail to get all sync data, sync data should still | 1013 // Even though bad will fail to get all sync data, sync data should still |
968 // include that from good. | 1014 // include that from good. |
969 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); | 1015 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); |
970 { | 1016 { |
971 syncer::SyncDataList all_sync_data = | 1017 syncer::SyncDataList all_sync_data = |
972 GetSyncableService(model_type)->GetAllSyncData(model_type); | 1018 GetSyncableService(model_type)->GetAllSyncData(model_type); |
973 EXPECT_EQ(1u, all_sync_data.size()); | 1019 EXPECT_EQ(1u, all_sync_data.size()); |
974 EXPECT_EQ("good/foo", syncer::SyncDataLocal(all_sync_data[0]).GetTag()); | 1020 EXPECT_EQ("good/foo", syncer::SyncDataLocal(all_sync_data[0]).GetTag()); |
975 } | 1021 } |
976 GetExisting("bad")->set_status_code(ValueStore::OK); | 1022 GetExisting("bad")->set_status_code(ValueStore::OK); |
977 | 1023 |
978 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant). | 1024 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant). |
979 GetSyncableService(model_type) | 1025 GetSyncableService(model_type) |
980 ->MergeDataAndStartSyncing( | 1026 ->MergeDataAndStartSyncing( |
981 model_type, syncer::SyncDataList(), | 1027 model_type, syncer::SyncDataList(), |
982 std::move(sync_processor_wrapper_), | 1028 std::move(sync_processor_wrapper_), |
983 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1029 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
984 | 1030 |
985 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1031 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
986 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1032 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
987 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1033 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
988 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); | 1034 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); |
989 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1035 EXPECT_EQ(2u, sync_processor_->changes().size()); |
990 | 1036 |
991 sync_processor_->ClearChanges(); | 1037 sync_processor_->ClearChanges(); |
992 good->Set(DEFAULTS, "bar", barValue); | 1038 good->Set(DEFAULTS, "bar", barValue); |
993 bad->Set(DEFAULTS, "bar", barValue); | 1039 bad->Set(DEFAULTS, "bar", barValue); |
994 | 1040 |
995 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1041 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
996 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | 1042 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
997 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1043 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
998 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); | 1044 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); |
999 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1045 EXPECT_EQ(2u, sync_processor_->changes().size()); |
1046 }); | |
1000 } | 1047 } |
1001 | 1048 |
1002 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { | 1049 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { |
1003 syncer::ModelType model_type = syncer::APP_SETTINGS; | 1050 syncer::ModelType model_type = syncer::APP_SETTINGS; |
1004 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; | 1051 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; |
1005 | 1052 |
1006 base::Value fooValue("fooValue"); | 1053 base::Value fooValue("fooValue"); |
1007 base::Value barValue("barValue"); | 1054 base::Value barValue("barValue"); |
1008 | 1055 |
1009 ValueStore* good = AddExtensionAndGetStorage("good", type); | 1056 ValueStore* good = AddExtensionAndGetStorage("good", type); |
1010 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 1057 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
1011 | 1058 |
1012 good->Set(DEFAULTS, "foo", fooValue); | 1059 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
1013 bad->Set(DEFAULTS, "foo", fooValue); | 1060 good->Set(DEFAULTS, "foo", fooValue); |
1061 bad->Set(DEFAULTS, "foo", fooValue); | |
1014 | 1062 |
1015 // good will successfully push foo:fooValue to sync, but bad will fail to | 1063 // good will successfully push foo:fooValue to sync, but bad will fail to |
1016 // get them so won't. | 1064 // get them so won't. |
1017 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); | 1065 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); |
1018 GetSyncableService(model_type) | 1066 GetSyncableService(model_type) |
1019 ->MergeDataAndStartSyncing( | 1067 ->MergeDataAndStartSyncing( |
1020 model_type, syncer::SyncDataList(), | 1068 model_type, syncer::SyncDataList(), |
1021 std::move(sync_processor_wrapper_), | 1069 std::move(sync_processor_wrapper_), |
1022 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1070 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
1023 GetExisting("bad")->set_status_code(ValueStore::OK); | 1071 GetExisting("bad")->set_status_code(ValueStore::OK); |
1024 | 1072 |
1025 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1073 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1026 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1074 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1027 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1075 EXPECT_EQ(1u, sync_processor_->changes().size()); |
1028 | 1076 |
1029 // bad should now be disabled for sync. | 1077 // bad should now be disabled for sync. |
1030 sync_processor_->ClearChanges(); | 1078 sync_processor_->ClearChanges(); |
1031 good->Set(DEFAULTS, "bar", barValue); | 1079 good->Set(DEFAULTS, "bar", barValue); |
1032 bad->Set(DEFAULTS, "bar", barValue); | 1080 bad->Set(DEFAULTS, "bar", barValue); |
1033 | 1081 |
1034 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1082 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1035 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | 1083 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
1036 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1084 EXPECT_EQ(1u, sync_processor_->changes().size()); |
1037 | 1085 |
1038 { | 1086 { |
1039 syncer::SyncChangeList change_list; | 1087 syncer::SyncChangeList change_list; |
1040 change_list.push_back(settings_sync_util::CreateUpdate( | 1088 change_list.push_back(settings_sync_util::CreateUpdate( |
1041 "good", "foo", barValue, model_type)); | 1089 "good", "foo", barValue, model_type)); |
1042 // (Sending ADD here even though it's updating, since that's what the state | 1090 // (Sending ADD here even though it's updating, since that's what the |
1043 // of sync is. In any case, it won't work.) | 1091 // state of sync is. In any case, it won't work.) |
1044 change_list.push_back(settings_sync_util::CreateAdd( | 1092 change_list.push_back( |
1045 "bad", "foo", barValue, model_type)); | 1093 settings_sync_util::CreateAdd("bad", "foo", barValue, model_type)); |
1046 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 1094 GetSyncableService(model_type) |
1047 } | 1095 ->ProcessSyncChanges(FROM_HERE, change_list); |
1096 } | |
1048 | 1097 |
1049 { | 1098 { |
1050 base::DictionaryValue dict; | 1099 base::DictionaryValue dict; |
1051 dict.Set("foo", barValue.CreateDeepCopy()); | 1100 dict.Set("foo", barValue.CreateDeepCopy()); |
1052 dict.Set("bar", barValue.CreateDeepCopy()); | 1101 dict.Set("bar", barValue.CreateDeepCopy()); |
1053 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 1102 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
1054 } | 1103 } |
1055 { | 1104 { |
1056 base::DictionaryValue dict; | 1105 base::DictionaryValue dict; |
1057 dict.Set("foo", fooValue.CreateDeepCopy()); | 1106 dict.Set("foo", fooValue.CreateDeepCopy()); |
1058 dict.Set("bar", barValue.CreateDeepCopy()); | 1107 dict.Set("bar", barValue.CreateDeepCopy()); |
1059 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 1108 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
1060 } | 1109 } |
1061 | 1110 |
1062 // Re-enabling sync without failing should cause the local changes from bad | 1111 // Re-enabling sync without failing should cause the local changes from bad |
1063 // to be pushed to sync successfully, as should future changes to bad. | 1112 // to be pushed to sync successfully, as should future changes to bad. |
1064 sync_processor_->ClearChanges(); | 1113 sync_processor_->ClearChanges(); |
1065 GetSyncableService(model_type)->StopSyncing(model_type); | 1114 GetSyncableService(model_type)->StopSyncing(model_type); |
1066 sync_processor_wrapper_.reset( | 1115 sync_processor_wrapper_.reset( |
1067 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); | 1116 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); |
1068 GetSyncableService(model_type) | 1117 GetSyncableService(model_type) |
1069 ->MergeDataAndStartSyncing( | 1118 ->MergeDataAndStartSyncing( |
1070 model_type, syncer::SyncDataList(), | 1119 model_type, syncer::SyncDataList(), |
1071 std::move(sync_processor_wrapper_), | 1120 std::move(sync_processor_wrapper_), |
1072 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1121 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
1073 | 1122 |
1074 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1123 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1075 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1124 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1076 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1125 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1077 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | 1126 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
1078 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1127 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1079 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); | 1128 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); |
1080 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1129 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1081 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); | 1130 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); |
1082 EXPECT_EQ(4u, sync_processor_->changes().size()); | 1131 EXPECT_EQ(4u, sync_processor_->changes().size()); |
1083 | 1132 |
1084 sync_processor_->ClearChanges(); | 1133 sync_processor_->ClearChanges(); |
1085 good->Set(DEFAULTS, "bar", fooValue); | 1134 good->Set(DEFAULTS, "bar", fooValue); |
1086 bad->Set(DEFAULTS, "bar", fooValue); | 1135 bad->Set(DEFAULTS, "bar", fooValue); |
1087 | 1136 |
1088 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1137 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
1089 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | 1138 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
1090 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1139 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
1091 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | 1140 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
1092 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1141 EXPECT_EQ(2u, sync_processor_->changes().size()); |
1142 }); | |
1093 } | 1143 } |
1094 | 1144 |
1095 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { | 1145 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { |
1096 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; | 1146 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; |
1097 Manifest::Type type = Manifest::TYPE_EXTENSION; | 1147 Manifest::Type type = Manifest::TYPE_EXTENSION; |
1098 | 1148 |
1099 base::Value fooValue("fooValue"); | 1149 base::Value fooValue("fooValue"); |
1100 base::Value barValue("barValue"); | 1150 base::Value barValue("barValue"); |
1101 | 1151 |
1102 ValueStore* good = AddExtensionAndGetStorage("good", type); | 1152 ValueStore* good = AddExtensionAndGetStorage("good", type); |
1103 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 1153 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
1104 | 1154 |
1105 // Only set bad; setting good will cause it to fail below. | 1155 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
1106 bad->Set(DEFAULTS, "foo", fooValue); | 1156 // Only set bad; setting good will cause it to fail below. |
1157 bad->Set(DEFAULTS, "foo", fooValue); | |
1107 | 1158 |
1108 sync_processor_->set_fail_all_requests(true); | 1159 sync_processor_->set_fail_all_requests(true); |
1109 GetSyncableService(model_type) | 1160 GetSyncableService(model_type) |
1110 ->MergeDataAndStartSyncing( | 1161 ->MergeDataAndStartSyncing( |
1111 model_type, syncer::SyncDataList(), | 1162 model_type, syncer::SyncDataList(), |
1112 std::move(sync_processor_wrapper_), | 1163 std::move(sync_processor_wrapper_), |
1113 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1164 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
1114 sync_processor_->set_fail_all_requests(false); | 1165 sync_processor_->set_fail_all_requests(false); |
1115 | 1166 |
1116 // Changes from good will be send to sync, changes from bad won't. | 1167 // Changes from good will be send to sync, changes from bad won't. |
1117 sync_processor_->ClearChanges(); | 1168 sync_processor_->ClearChanges(); |
1118 good->Set(DEFAULTS, "foo", barValue); | 1169 good->Set(DEFAULTS, "foo", barValue); |
1119 bad->Set(DEFAULTS, "foo", barValue); | 1170 bad->Set(DEFAULTS, "foo", barValue); |
1120 | 1171 |
1121 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1172 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1122 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1173 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1123 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1174 EXPECT_EQ(1u, sync_processor_->changes().size()); |
1124 | 1175 |
1125 // Changes from sync will be sent to good, not to bad. | 1176 // Changes from sync will be sent to good, not to bad. |
1126 { | 1177 { |
1127 syncer::SyncChangeList change_list; | 1178 syncer::SyncChangeList change_list; |
1128 change_list.push_back(settings_sync_util::CreateAdd( | 1179 change_list.push_back( |
1129 "good", "bar", barValue, model_type)); | 1180 settings_sync_util::CreateAdd("good", "bar", barValue, model_type)); |
1130 change_list.push_back(settings_sync_util::CreateAdd( | 1181 change_list.push_back( |
1131 "bad", "bar", barValue, model_type)); | 1182 settings_sync_util::CreateAdd("bad", "bar", barValue, model_type)); |
1132 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 1183 GetSyncableService(model_type) |
1133 } | 1184 ->ProcessSyncChanges(FROM_HERE, change_list); |
1185 } | |
1134 | 1186 |
1135 { | 1187 { |
1136 base::DictionaryValue dict; | 1188 base::DictionaryValue dict; |
1137 dict.Set("foo", barValue.CreateDeepCopy()); | 1189 dict.Set("foo", barValue.CreateDeepCopy()); |
1138 dict.Set("bar", barValue.CreateDeepCopy()); | 1190 dict.Set("bar", barValue.CreateDeepCopy()); |
1139 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 1191 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
1140 } | 1192 } |
1141 { | 1193 { |
1142 base::DictionaryValue dict; | 1194 base::DictionaryValue dict; |
1143 dict.Set("foo", barValue.CreateDeepCopy()); | 1195 dict.Set("foo", barValue.CreateDeepCopy()); |
1144 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 1196 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
1145 } | 1197 } |
1146 | 1198 |
1147 // Restarting sync makes everything work again. | 1199 // Restarting sync makes everything work again. |
1148 sync_processor_->ClearChanges(); | 1200 sync_processor_->ClearChanges(); |
1149 GetSyncableService(model_type)->StopSyncing(model_type); | 1201 GetSyncableService(model_type)->StopSyncing(model_type); |
1150 sync_processor_wrapper_.reset( | 1202 sync_processor_wrapper_.reset( |
1151 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); | 1203 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); |
1152 GetSyncableService(model_type) | 1204 GetSyncableService(model_type) |
1153 ->MergeDataAndStartSyncing( | 1205 ->MergeDataAndStartSyncing( |
1154 model_type, syncer::SyncDataList(), | 1206 model_type, syncer::SyncDataList(), |
1155 std::move(sync_processor_wrapper_), | 1207 std::move(sync_processor_wrapper_), |
1156 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1208 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
1157 | 1209 |
1158 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1210 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1159 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1211 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1160 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1212 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1161 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | 1213 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
1162 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1214 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1163 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); | 1215 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); |
1164 EXPECT_EQ(3u, sync_processor_->changes().size()); | 1216 EXPECT_EQ(3u, sync_processor_->changes().size()); |
1165 | 1217 |
1166 sync_processor_->ClearChanges(); | 1218 sync_processor_->ClearChanges(); |
1167 good->Set(DEFAULTS, "foo", fooValue); | 1219 good->Set(DEFAULTS, "foo", fooValue); |
1168 bad->Set(DEFAULTS, "foo", fooValue); | 1220 bad->Set(DEFAULTS, "foo", fooValue); |
1169 | 1221 |
1170 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1222 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
1171 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1223 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1172 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1224 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
1173 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1225 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1174 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1226 EXPECT_EQ(2u, sync_processor_->changes().size()); |
1227 }); | |
1175 } | 1228 } |
1176 | 1229 |
1177 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { | 1230 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { |
1178 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; | 1231 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; |
1179 Manifest::Type type = Manifest::TYPE_EXTENSION; | 1232 Manifest::Type type = Manifest::TYPE_EXTENSION; |
1180 | 1233 |
1181 base::Value fooValue("fooValue"); | 1234 base::Value fooValue("fooValue"); |
1182 base::Value barValue("barValue"); | 1235 base::Value barValue("barValue"); |
1183 | 1236 |
1184 ValueStore* good = AddExtensionAndGetStorage("good", type); | 1237 ValueStore* good = AddExtensionAndGetStorage("good", type); |
1185 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 1238 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
1186 | 1239 |
1187 GetSyncableService(model_type) | 1240 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
1188 ->MergeDataAndStartSyncing( | 1241 GetSyncableService(model_type) |
1189 model_type, syncer::SyncDataList(), | 1242 ->MergeDataAndStartSyncing( |
1190 std::move(sync_processor_wrapper_), | 1243 model_type, syncer::SyncDataList(), |
1191 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1244 std::move(sync_processor_wrapper_), |
1245 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
1192 | 1246 |
1193 // bad will fail to send changes. | 1247 // bad will fail to send changes. |
1194 good->Set(DEFAULTS, "foo", fooValue); | 1248 good->Set(DEFAULTS, "foo", fooValue); |
1195 sync_processor_->set_fail_all_requests(true); | 1249 sync_processor_->set_fail_all_requests(true); |
1196 bad->Set(DEFAULTS, "foo", fooValue); | 1250 bad->Set(DEFAULTS, "foo", fooValue); |
1197 sync_processor_->set_fail_all_requests(false); | 1251 sync_processor_->set_fail_all_requests(false); |
1198 | 1252 |
1199 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1253 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1200 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1254 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1201 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1255 EXPECT_EQ(1u, sync_processor_->changes().size()); |
1202 | 1256 |
1203 // No further changes should be sent from bad. | 1257 // No further changes should be sent from bad. |
1204 sync_processor_->ClearChanges(); | 1258 sync_processor_->ClearChanges(); |
1205 good->Set(DEFAULTS, "foo", barValue); | 1259 good->Set(DEFAULTS, "foo", barValue); |
1206 bad->Set(DEFAULTS, "foo", barValue); | 1260 bad->Set(DEFAULTS, "foo", barValue); |
1207 | 1261 |
1208 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1262 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
1209 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1263 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1210 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1264 EXPECT_EQ(1u, sync_processor_->changes().size()); |
1211 | 1265 |
1212 // Changes from sync will be sent to good, not to bad. | 1266 // Changes from sync will be sent to good, not to bad. |
1213 { | 1267 { |
1214 syncer::SyncChangeList change_list; | 1268 syncer::SyncChangeList change_list; |
1215 change_list.push_back(settings_sync_util::CreateAdd( | 1269 change_list.push_back( |
1216 "good", "bar", barValue, model_type)); | 1270 settings_sync_util::CreateAdd("good", "bar", barValue, model_type)); |
1217 change_list.push_back(settings_sync_util::CreateAdd( | 1271 change_list.push_back( |
1218 "bad", "bar", barValue, model_type)); | 1272 settings_sync_util::CreateAdd("bad", "bar", barValue, model_type)); |
1219 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 1273 GetSyncableService(model_type) |
1220 } | 1274 ->ProcessSyncChanges(FROM_HERE, change_list); |
1275 } | |
1221 | 1276 |
1222 { | 1277 { |
1223 base::DictionaryValue dict; | 1278 base::DictionaryValue dict; |
1224 dict.Set("foo", barValue.CreateDeepCopy()); | 1279 dict.Set("foo", barValue.CreateDeepCopy()); |
1225 dict.Set("bar", barValue.CreateDeepCopy()); | 1280 dict.Set("bar", barValue.CreateDeepCopy()); |
1226 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 1281 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
1227 } | 1282 } |
1228 { | 1283 { |
1229 base::DictionaryValue dict; | 1284 base::DictionaryValue dict; |
1230 dict.Set("foo", barValue.CreateDeepCopy()); | 1285 dict.Set("foo", barValue.CreateDeepCopy()); |
1231 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 1286 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
1232 } | 1287 } |
1233 | 1288 |
1234 // Restarting sync makes everything work again. | 1289 // Restarting sync makes everything work again. |
1235 sync_processor_->ClearChanges(); | 1290 sync_processor_->ClearChanges(); |
1236 GetSyncableService(model_type)->StopSyncing(model_type); | 1291 GetSyncableService(model_type)->StopSyncing(model_type); |
1237 sync_processor_wrapper_.reset( | 1292 sync_processor_wrapper_.reset( |
1238 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); | 1293 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); |
1239 GetSyncableService(model_type) | 1294 GetSyncableService(model_type) |
1240 ->MergeDataAndStartSyncing( | 1295 ->MergeDataAndStartSyncing( |
1241 model_type, syncer::SyncDataList(), | 1296 model_type, syncer::SyncDataList(), |
1242 std::move(sync_processor_wrapper_), | 1297 std::move(sync_processor_wrapper_), |
1243 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1298 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
1244 | 1299 |
1245 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1300 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1246 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1301 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1247 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1302 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1248 sync_processor_->GetOnlyChange("good", "bar")->change_type()); | 1303 sync_processor_->GetOnlyChange("good", "bar")->change_type()); |
1249 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, | 1304 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, |
1250 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); | 1305 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); |
1251 EXPECT_EQ(3u, sync_processor_->changes().size()); | 1306 EXPECT_EQ(3u, sync_processor_->changes().size()); |
1252 | 1307 |
1253 sync_processor_->ClearChanges(); | 1308 sync_processor_->ClearChanges(); |
1254 good->Set(DEFAULTS, "foo", fooValue); | 1309 good->Set(DEFAULTS, "foo", fooValue); |
1255 bad->Set(DEFAULTS, "foo", fooValue); | 1310 bad->Set(DEFAULTS, "foo", fooValue); |
1256 | 1311 |
1257 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1312 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
1258 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1313 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1259 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, | 1314 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, |
1260 sync_processor_->GetOnlyChange("good", "foo")->change_type()); | 1315 sync_processor_->GetOnlyChange("good", "foo")->change_type()); |
1261 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1316 EXPECT_EQ(2u, sync_processor_->changes().size()); |
1317 }); | |
1262 } | 1318 } |
1263 | 1319 |
1264 TEST_F(ExtensionSettingsSyncTest, | 1320 TEST_F(ExtensionSettingsSyncTest, |
1265 LargeOutgoingChangeRejectedButIncomingAccepted) { | 1321 LargeOutgoingChangeRejectedButIncomingAccepted) { |
1266 syncer::ModelType model_type = syncer::APP_SETTINGS; | 1322 syncer::ModelType model_type = syncer::APP_SETTINGS; |
1267 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; | 1323 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; |
1268 | 1324 |
1269 // This value should be larger than the limit in sync_storage_backend.cc. | 1325 // This value should be larger than the limit in sync_storage_backend.cc. |
1270 std::string string_10k; | 1326 std::string string_10k; |
1271 for (size_t i = 0; i < 10000; ++i) { | 1327 for (size_t i = 0; i < 10000; ++i) { |
1272 string_10k.append("a"); | 1328 string_10k.append("a"); |
1273 } | 1329 } |
1274 base::Value large_value(string_10k); | 1330 base::Value large_value(string_10k); |
1275 | 1331 |
1276 GetSyncableService(model_type) | 1332 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
1277 ->MergeDataAndStartSyncing( | 1333 GetSyncableService(model_type) |
1278 model_type, syncer::SyncDataList(), | 1334 ->MergeDataAndStartSyncing( |
1279 std::move(sync_processor_wrapper_), | 1335 model_type, syncer::SyncDataList(), |
1280 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1336 std::move(sync_processor_wrapper_), |
1337 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
1338 }); | |
1281 | 1339 |
1282 // Large local change rejected and doesn't get sent out. | 1340 // Large local change rejected and doesn't get sent out. |
1283 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); | 1341 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); |
1284 EXPECT_FALSE( | 1342 |
1285 storage1->Set(DEFAULTS, "large_value", large_value)->status().ok()); | 1343 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
1286 EXPECT_EQ(0u, sync_processor_->changes().size()); | 1344 EXPECT_FALSE( |
1345 storage1->Set(DEFAULTS, "large_value", large_value)->status().ok()); | |
1346 EXPECT_EQ(0u, sync_processor_->changes().size()); | |
1347 }); | |
1287 | 1348 |
1288 // Large incoming change should still get accepted. | 1349 // Large incoming change should still get accepted. |
1289 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); | 1350 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); |
1290 { | 1351 |
1291 syncer::SyncChangeList change_list; | 1352 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
1292 change_list.push_back(settings_sync_util::CreateAdd( | 1353 { |
1354 syncer::SyncChangeList change_list; | |
1355 change_list.push_back(settings_sync_util::CreateAdd( | |
1293 "s1", "large_value", large_value, model_type)); | 1356 "s1", "large_value", large_value, model_type)); |
1294 change_list.push_back(settings_sync_util::CreateAdd( | 1357 change_list.push_back(settings_sync_util::CreateAdd( |
1295 "s2", "large_value", large_value, model_type)); | 1358 "s2", "large_value", large_value, model_type)); |
1296 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 1359 GetSyncableService(model_type) |
1297 } | 1360 ->ProcessSyncChanges(FROM_HERE, change_list); |
1298 { | 1361 } |
1299 base::DictionaryValue expected; | 1362 { |
1300 expected.Set("large_value", large_value.CreateDeepCopy()); | 1363 base::DictionaryValue expected; |
1301 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get()); | 1364 expected.Set("large_value", large_value.CreateDeepCopy()); |
1302 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get()); | 1365 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get()); |
1303 } | 1366 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get()); |
1367 } | |
1304 | 1368 |
1305 GetSyncableService(model_type)->StopSyncing(model_type); | 1369 GetSyncableService(model_type)->StopSyncing(model_type); |
1370 }); | |
1306 } | 1371 } |
1307 | 1372 |
1308 TEST_F(ExtensionSettingsSyncTest, Dots) { | 1373 TEST_F(ExtensionSettingsSyncTest, Dots) { |
1309 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; | 1374 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; |
1310 Manifest::Type type = Manifest::TYPE_EXTENSION; | 1375 Manifest::Type type = Manifest::TYPE_EXTENSION; |
1311 | 1376 |
1312 ValueStore* storage = AddExtensionAndGetStorage("ext", type); | 1377 ValueStore* storage = AddExtensionAndGetStorage("ext", type); |
1313 | 1378 |
1314 { | 1379 PostOnBackendSequenceAndWait(FROM_HERE, [&, this]() { |
1315 syncer::SyncDataList sync_data_list; | 1380 { |
1316 std::unique_ptr<base::Value> string_value(new base::Value("value")); | 1381 syncer::SyncDataList sync_data_list; |
1317 sync_data_list.push_back(settings_sync_util::CreateData( | 1382 std::unique_ptr<base::Value> string_value(new base::Value("value")); |
1318 "ext", "key.with.dot", *string_value, model_type)); | 1383 sync_data_list.push_back(settings_sync_util::CreateData( |
1384 "ext", "key.with.dot", *string_value, model_type)); | |
1319 | 1385 |
1320 GetSyncableService(model_type) | 1386 GetSyncableService(model_type) |
1321 ->MergeDataAndStartSyncing( | 1387 ->MergeDataAndStartSyncing( |
1322 model_type, sync_data_list, std::move(sync_processor_wrapper_), | 1388 model_type, sync_data_list, std::move(sync_processor_wrapper_), |
1323 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1389 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
1324 } | 1390 } |
1325 | 1391 |
1326 // Test dots in keys that come from sync. | 1392 // Test dots in keys that come from sync. |
1327 { | 1393 { |
1328 ValueStore::ReadResult data = storage->Get(); | 1394 ValueStore::ReadResult data = storage->Get(); |
1329 ASSERT_TRUE(data->status().ok()); | 1395 ASSERT_TRUE(data->status().ok()); |
1330 | 1396 |
1331 base::DictionaryValue expected_data; | 1397 base::DictionaryValue expected_data; |
1332 expected_data.SetWithoutPathExpansion( | 1398 expected_data.SetWithoutPathExpansion( |
1333 "key.with.dot", base::MakeUnique<base::Value>("value")); | 1399 "key.with.dot", base::MakeUnique<base::Value>("value")); |
1334 EXPECT_TRUE(base::Value::Equals(&expected_data, &data->settings())); | 1400 EXPECT_TRUE(base::Value::Equals(&expected_data, &data->settings())); |
1335 } | 1401 } |
1336 | 1402 |
1337 // Test dots in keys going to sync. | 1403 // Test dots in keys going to sync. |
1338 { | 1404 { |
1339 std::unique_ptr<base::Value> string_value(new base::Value("spot")); | 1405 std::unique_ptr<base::Value> string_value(new base::Value("spot")); |
1340 storage->Set(DEFAULTS, "key.with.spot", *string_value); | 1406 storage->Set(DEFAULTS, "key.with.spot", *string_value); |
1341 | 1407 |
1342 ASSERT_EQ(1u, sync_processor_->changes().size()); | 1408 ASSERT_EQ(1u, sync_processor_->changes().size()); |
1343 SettingSyncData* sync_data = sync_processor_->changes()[0].get(); | 1409 SettingSyncData* sync_data = sync_processor_->changes()[0].get(); |
1344 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data->change_type()); | 1410 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data->change_type()); |
1345 EXPECT_EQ("ext", sync_data->extension_id()); | 1411 EXPECT_EQ("ext", sync_data->extension_id()); |
1346 EXPECT_EQ("key.with.spot", sync_data->key()); | 1412 EXPECT_EQ("key.with.spot", sync_data->key()); |
1347 EXPECT_TRUE(sync_data->value().Equals(string_value.get())); | 1413 EXPECT_TRUE(sync_data->value().Equals(string_value.get())); |
1348 } | 1414 } |
1415 }); | |
1349 } | 1416 } |
1350 | 1417 |
1351 // In other (frontend) tests, we assume that the result of GetStorage | 1418 // In other (frontend) tests, we assume that the result of GetStorage |
1352 // is a pointer to the a Storage owned by a Frontend object, but for | 1419 // is a pointer to the a Storage owned by a Frontend object, but for |
1353 // the unlimitedStorage case, this might not be true. So, write the | 1420 // the unlimitedStorage case, this might not be true. So, write the |
1354 // tests in a "callback" style. We should really rewrite all tests to | 1421 // tests in a "callback" style. We should really rewrite all tests to |
1355 // be asynchronous in this way. | 1422 // be asynchronous in this way. |
1356 | 1423 |
1357 namespace { | 1424 namespace { |
1358 | 1425 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1397 util::AddExtensionWithIdAndPermissions( | 1464 util::AddExtensionWithIdAndPermissions( |
1398 profile_.get(), id, Manifest::TYPE_EXTENSION, permissions); | 1465 profile_.get(), id, Manifest::TYPE_EXTENSION, permissions); |
1399 | 1466 |
1400 frontend_->RunWithStorage(extension, | 1467 frontend_->RunWithStorage(extension, |
1401 settings_namespace::SYNC, | 1468 settings_namespace::SYNC, |
1402 base::Bind(&UnlimitedSyncStorageTestCallback)); | 1469 base::Bind(&UnlimitedSyncStorageTestCallback)); |
1403 frontend_->RunWithStorage(extension, | 1470 frontend_->RunWithStorage(extension, |
1404 settings_namespace::LOCAL, | 1471 settings_namespace::LOCAL, |
1405 base::Bind(&UnlimitedLocalStorageTestCallback)); | 1472 base::Bind(&UnlimitedLocalStorageTestCallback)); |
1406 | 1473 |
1407 base::RunLoop().RunUntilIdle(); | 1474 content::RunAllBlockingPoolTasksUntilIdle(); |
1408 } | 1475 } |
1409 | 1476 |
1410 } // namespace extensions | 1477 } // namespace extensions |
OLD | NEW |