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

Side by Side Diff: chrome/browser/extensions/settings/settings_sync_unittest.cc

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
13 #include "chrome/browser/value_store/failing_value_store.h"
14 #include "chrome/browser/extensions/settings/leveldb_settings_storage_factory.h" 13 #include "chrome/browser/extensions/settings/leveldb_settings_storage_factory.h"
15 #include "chrome/browser/extensions/settings/settings_frontend.h" 14 #include "chrome/browser/extensions/settings/settings_frontend.h"
16 #include "chrome/browser/extensions/settings/settings_storage_factory.h" 15 #include "chrome/browser/extensions/settings/settings_storage_factory.h"
17 #include "chrome/browser/extensions/settings/settings_sync_util.h" 16 #include "chrome/browser/extensions/settings/settings_sync_util.h"
18 #include "chrome/browser/extensions/settings/settings_test_util.h" 17 #include "chrome/browser/extensions/settings/settings_test_util.h"
19 #include "chrome/browser/extensions/settings/syncable_settings_storage.h" 18 #include "chrome/browser/extensions/settings/syncable_settings_storage.h"
19 #include "chrome/browser/value_store/failing_value_store.h"
20 #include "chrome/browser/value_store/testing_value_store.h" 20 #include "chrome/browser/value_store/testing_value_store.h"
21 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread.h"
22 #include "sync/api/sync_change_processor.h" 22 #include "sync/api/sync_change_processor.h"
23 #include "sync/api/sync_error_factory.h" 23 #include "sync/api/sync_error_factory.h"
24 #include "sync/api/sync_error_factory_mock.h" 24 #include "sync/api/sync_error_factory_mock.h"
25 25
26 using content::BrowserThread; 26 using content::BrowserThread;
27 27
28 namespace extensions { 28 namespace extensions {
29 29
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // SettingsStorageFactory is refcounted. 189 // SettingsStorageFactory is refcounted.
190 virtual ~TestingValueStoreFactory() {} 190 virtual ~TestingValueStoreFactory() {}
191 191
192 // None of these storage areas are owned by this factory, so care must be 192 // None of these storage areas are owned by this factory, so care must be
193 // taken when calling GetExisting. 193 // taken when calling GetExisting.
194 std::map<std::string, TestingValueStore*> created_; 194 std::map<std::string, TestingValueStore*> created_;
195 }; 195 };
196 196
197 void AssignSettingsService(syncer::SyncableService** dst, 197 void AssignSettingsService(syncer::SyncableService** dst,
198 const SettingsFrontend* frontend, 198 const SettingsFrontend* frontend,
199 syncable::ModelType type) { 199 syncer::ModelType type) {
200 *dst = frontend->GetBackendForSync(type); 200 *dst = frontend->GetBackendForSync(type);
201 } 201 }
202 202
203 } // namespace 203 } // namespace
204 204
205 class ExtensionSettingsSyncTest : public testing::Test { 205 class ExtensionSettingsSyncTest : public testing::Test {
206 public: 206 public:
207 ExtensionSettingsSyncTest() 207 ExtensionSettingsSyncTest()
208 : ui_thread_(BrowserThread::UI, MessageLoop::current()), 208 : ui_thread_(BrowserThread::UI, MessageLoop::current()),
209 file_thread_(BrowserThread::FILE, MessageLoop::current()), 209 file_thread_(BrowserThread::FILE, MessageLoop::current()),
(...skipping 18 matching lines...) Expand all
228 protected: 228 protected:
229 // Adds a record of an extension or app to the extension service, then returns 229 // Adds a record of an extension or app to the extension service, then returns
230 // its storage area. 230 // its storage area.
231 ValueStore* AddExtensionAndGetStorage( 231 ValueStore* AddExtensionAndGetStorage(
232 const std::string& id, Extension::Type type) { 232 const std::string& id, Extension::Type type) {
233 profile_->GetMockExtensionService()->AddExtensionWithId(id, type); 233 profile_->GetMockExtensionService()->AddExtensionWithId(id, type);
234 return util::GetStorage(id, frontend_.get()); 234 return util::GetStorage(id, frontend_.get());
235 } 235 }
236 236
237 // Gets the syncer::SyncableService for the given sync type. 237 // Gets the syncer::SyncableService for the given sync type.
238 syncer::SyncableService* GetSyncableService(syncable::ModelType model_type) { 238 syncer::SyncableService* GetSyncableService(syncer::ModelType model_type) {
239 MessageLoop::current()->RunAllPending(); 239 MessageLoop::current()->RunAllPending();
240 return frontend_->GetBackendForSync(model_type); 240 return frontend_->GetBackendForSync(model_type);
241 } 241 }
242 242
243 // Gets all the sync data from the SyncableService for a sync type as a map 243 // Gets all the sync data from the SyncableService for a sync type as a map
244 // from extension id to its sync data. 244 // from extension id to its sync data.
245 std::map<std::string, SettingSyncDataList> GetAllSyncData( 245 std::map<std::string, SettingSyncDataList> GetAllSyncData(
246 syncable::ModelType model_type) { 246 syncer::ModelType model_type) {
247 syncer::SyncDataList as_list = 247 syncer::SyncDataList as_list =
248 GetSyncableService(model_type)->GetAllSyncData(model_type); 248 GetSyncableService(model_type)->GetAllSyncData(model_type);
249 std::map<std::string, SettingSyncDataList> as_map; 249 std::map<std::string, SettingSyncDataList> as_map;
250 for (syncer::SyncDataList::iterator it = as_list.begin(); 250 for (syncer::SyncDataList::iterator it = as_list.begin();
251 it != as_list.end(); ++it) { 251 it != as_list.end(); ++it) {
252 SettingSyncData sync_data(*it); 252 SettingSyncData sync_data(*it);
253 as_map[sync_data.extension_id()].push_back(sync_data); 253 as_map[sync_data.extension_id()].push_back(sync_data);
254 } 254 }
255 return as_map; 255 return as_map;
256 } 256 }
257 257
258 // Need these so that the DCHECKs for running on FILE or UI threads pass. 258 // Need these so that the DCHECKs for running on FILE or UI threads pass.
259 MessageLoop message_loop_; 259 MessageLoop message_loop_;
260 content::TestBrowserThread ui_thread_; 260 content::TestBrowserThread ui_thread_;
261 content::TestBrowserThread file_thread_; 261 content::TestBrowserThread file_thread_;
262 262
263 ScopedTempDir temp_dir_; 263 ScopedTempDir temp_dir_;
264 scoped_ptr<util::MockProfile> profile_; 264 scoped_ptr<util::MockProfile> profile_;
265 scoped_ptr<SettingsFrontend> frontend_; 265 scoped_ptr<SettingsFrontend> frontend_;
266 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; 266 scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_;
267 scoped_ptr<MockSyncChangeProcessor> sync_processor_; 267 scoped_ptr<MockSyncChangeProcessor> sync_processor_;
268 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; 268 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_;
269 }; 269 };
270 270
271 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS 271 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS
272 // sync by roughly alternative which one to test. 272 // sync by roughly alternative which one to test.
273 273
274 TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) { 274 TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) {
275 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 275 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
276 Extension::Type type = Extension::TYPE_EXTENSION; 276 Extension::Type type = Extension::TYPE_EXTENSION;
277 277
278 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 278 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
279 279
280 // Have one extension created before sync is set up, the other created after. 280 // Have one extension created before sync is set up, the other created after.
281 AddExtensionAndGetStorage("s1", type); 281 AddExtensionAndGetStorage("s1", type);
282 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 282 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
283 283
284 GetSyncableService(model_type)->MergeDataAndStartSyncing( 284 GetSyncableService(model_type)->MergeDataAndStartSyncing(
285 model_type, 285 model_type,
286 syncer::SyncDataList(), 286 syncer::SyncDataList(),
287 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(), 287 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
288 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 288 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
289 289
290 AddExtensionAndGetStorage("s2", type); 290 AddExtensionAndGetStorage("s2", type);
291 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 291 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
292 292
293 GetSyncableService(model_type)->StopSyncing(model_type); 293 GetSyncableService(model_type)->StopSyncing(model_type);
294 294
295 EXPECT_EQ(0u, sync_processor_->changes().size()); 295 EXPECT_EQ(0u, sync_processor_->changes().size());
296 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 296 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
297 } 297 }
298 298
299 TEST_F(ExtensionSettingsSyncTest, InSyncDataDoesNotInvokeSync) { 299 TEST_F(ExtensionSettingsSyncTest, InSyncDataDoesNotInvokeSync) {
300 syncable::ModelType model_type = syncable::APP_SETTINGS; 300 syncer::ModelType model_type = syncer::APP_SETTINGS;
301 Extension::Type type = Extension::TYPE_PACKAGED_APP; 301 Extension::Type type = Extension::TYPE_PACKAGED_APP;
302 302
303 StringValue value1("fooValue"); 303 StringValue value1("fooValue");
304 ListValue value2; 304 ListValue value2;
305 value2.Append(StringValue::CreateStringValue("barValue")); 305 value2.Append(StringValue::CreateStringValue("barValue"));
306 306
307 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 307 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
308 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 308 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
309 309
310 storage1->Set(DEFAULTS, "foo", value1); 310 storage1->Set(DEFAULTS, "foo", value1);
(...skipping 29 matching lines...) Expand all
340 storage1->Set(DEFAULTS, "foo", value2); 340 storage1->Set(DEFAULTS, "foo", value2);
341 EXPECT_EQ(1u, sync_processor_->changes().size()); 341 EXPECT_EQ(1u, sync_processor_->changes().size());
342 SettingSyncData change = sync_processor_->GetOnlyChange("s1", "foo"); 342 SettingSyncData change = sync_processor_->GetOnlyChange("s1", "foo");
343 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type()); 343 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
344 EXPECT_TRUE(value2.Equals(&change.value())); 344 EXPECT_TRUE(value2.Equals(&change.value()));
345 345
346 GetSyncableService(model_type)->StopSyncing(model_type); 346 GetSyncableService(model_type)->StopSyncing(model_type);
347 } 347 }
348 348
349 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) { 349 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) {
350 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 350 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
351 Extension::Type type = Extension::TYPE_EXTENSION; 351 Extension::Type type = Extension::TYPE_EXTENSION;
352 352
353 StringValue value1("fooValue"); 353 StringValue value1("fooValue");
354 ListValue value2; 354 ListValue value2;
355 value2.Append(StringValue::CreateStringValue("barValue")); 355 value2.Append(StringValue::CreateStringValue("barValue"));
356 356
357 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 357 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
358 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 358 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
359 359
360 storage1->Set(DEFAULTS, "foo", value1); 360 storage1->Set(DEFAULTS, "foo", value1);
(...skipping 11 matching lines...) Expand all
372 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type()); 372 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
373 EXPECT_TRUE(value1.Equals(&change.value())); 373 EXPECT_TRUE(value1.Equals(&change.value()));
374 change = sync_processor_->GetOnlyChange("s2", "bar"); 374 change = sync_processor_->GetOnlyChange("s2", "bar");
375 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type()); 375 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
376 EXPECT_TRUE(value2.Equals(&change.value())); 376 EXPECT_TRUE(value2.Equals(&change.value()));
377 377
378 GetSyncableService(model_type)->StopSyncing(model_type); 378 GetSyncableService(model_type)->StopSyncing(model_type);
379 } 379 }
380 380
381 TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) { 381 TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) {
382 syncable::ModelType model_type = syncable::APP_SETTINGS; 382 syncer::ModelType model_type = syncer::APP_SETTINGS;
383 Extension::Type type = Extension::TYPE_PACKAGED_APP; 383 Extension::Type type = Extension::TYPE_PACKAGED_APP;
384 384
385 StringValue value1("fooValue"); 385 StringValue value1("fooValue");
386 ListValue value2; 386 ListValue value2;
387 value2.Append(StringValue::CreateStringValue("barValue")); 387 value2.Append(StringValue::CreateStringValue("barValue"));
388 388
389 // Maintain dictionaries mirrored to the expected values of the settings in 389 // Maintain dictionaries mirrored to the expected values of the settings in
390 // each storage area. 390 // each storage area.
391 DictionaryValue expected1, expected2; 391 DictionaryValue expected1, expected2;
392 392
(...skipping 19 matching lines...) Expand all
412 EXPECT_EQ(0u, sync_processor_->changes().size()); 412 EXPECT_EQ(0u, sync_processor_->changes().size());
413 413
414 // Sync settings should have been pushed to local settings. 414 // Sync settings should have been pushed to local settings.
415 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); 415 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
416 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); 416 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get());
417 417
418 GetSyncableService(model_type)->StopSyncing(model_type); 418 GetSyncableService(model_type)->StopSyncing(model_type);
419 } 419 }
420 420
421 TEST_F(ExtensionSettingsSyncTest, ProcessSyncChanges) { 421 TEST_F(ExtensionSettingsSyncTest, ProcessSyncChanges) {
422 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 422 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
423 Extension::Type type = Extension::TYPE_EXTENSION; 423 Extension::Type type = Extension::TYPE_EXTENSION;
424 424
425 StringValue value1("fooValue"); 425 StringValue value1("fooValue");
426 ListValue value2; 426 ListValue value2;
427 value2.Append(StringValue::CreateStringValue("barValue")); 427 value2.Append(StringValue::CreateStringValue("barValue"));
428 428
429 // Maintain dictionaries mirrored to the expected values of the settings in 429 // Maintain dictionaries mirrored to the expected values of the settings in
430 // each storage area. 430 // each storage area.
431 DictionaryValue expected1, expected2; 431 DictionaryValue expected1, expected2;
432 432
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 expected1.Remove("foo", NULL); 485 expected1.Remove("foo", NULL);
486 expected2.Remove("foo", NULL); 486 expected2.Remove("foo", NULL);
487 487
488 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); 488 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
489 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); 489 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get());
490 490
491 GetSyncableService(model_type)->StopSyncing(model_type); 491 GetSyncableService(model_type)->StopSyncing(model_type);
492 } 492 }
493 493
494 TEST_F(ExtensionSettingsSyncTest, PushToSync) { 494 TEST_F(ExtensionSettingsSyncTest, PushToSync) {
495 syncable::ModelType model_type = syncable::APP_SETTINGS; 495 syncer::ModelType model_type = syncer::APP_SETTINGS;
496 Extension::Type type = Extension::TYPE_PACKAGED_APP; 496 Extension::Type type = Extension::TYPE_PACKAGED_APP;
497 497
498 StringValue value1("fooValue"); 498 StringValue value1("fooValue");
499 ListValue value2; 499 ListValue value2;
500 value2.Append(StringValue::CreateStringValue("barValue")); 500 value2.Append(StringValue::CreateStringValue("barValue"));
501 501
502 // Make storage1/2 initialised from local data, storage3/4 initialised from 502 // Make storage1/2 initialised from local data, storage3/4 initialised from
503 // sync. 503 // sync.
504 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 504 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
505 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 505 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 // storage1 is an extension, storage2 is an app. 641 // storage1 is an extension, storage2 is an app.
642 ValueStore* storage1 = AddExtensionAndGetStorage( 642 ValueStore* storage1 = AddExtensionAndGetStorage(
643 "s1", Extension::TYPE_EXTENSION); 643 "s1", Extension::TYPE_EXTENSION);
644 ValueStore* storage2 = AddExtensionAndGetStorage( 644 ValueStore* storage2 = AddExtensionAndGetStorage(
645 "s2", Extension::TYPE_PACKAGED_APP); 645 "s2", Extension::TYPE_PACKAGED_APP);
646 646
647 storage1->Set(DEFAULTS, "foo", value1); 647 storage1->Set(DEFAULTS, "foo", value1);
648 storage2->Set(DEFAULTS, "bar", value2); 648 storage2->Set(DEFAULTS, "bar", value2);
649 649
650 std::map<std::string, SettingSyncDataList> extension_sync_data = 650 std::map<std::string, SettingSyncDataList> extension_sync_data =
651 GetAllSyncData(syncable::EXTENSION_SETTINGS); 651 GetAllSyncData(syncer::EXTENSION_SETTINGS);
652 EXPECT_EQ(1u, extension_sync_data.size()); 652 EXPECT_EQ(1u, extension_sync_data.size());
653 EXPECT_EQ(1u, extension_sync_data["s1"].size()); 653 EXPECT_EQ(1u, extension_sync_data["s1"].size());
654 EXPECT_PRED_FORMAT2(ValuesEq, &value1, &extension_sync_data["s1"][0].value()); 654 EXPECT_PRED_FORMAT2(ValuesEq, &value1, &extension_sync_data["s1"][0].value());
655 655
656 std::map<std::string, SettingSyncDataList> app_sync_data = 656 std::map<std::string, SettingSyncDataList> app_sync_data =
657 GetAllSyncData(syncable::APP_SETTINGS); 657 GetAllSyncData(syncer::APP_SETTINGS);
658 EXPECT_EQ(1u, app_sync_data.size()); 658 EXPECT_EQ(1u, app_sync_data.size());
659 EXPECT_EQ(1u, app_sync_data["s2"].size()); 659 EXPECT_EQ(1u, app_sync_data["s2"].size());
660 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &app_sync_data["s2"][0].value()); 660 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &app_sync_data["s2"][0].value());
661 661
662 // Stop each separately, there should be no changes either time. 662 // Stop each separately, there should be no changes either time.
663 syncer::SyncDataList sync_data; 663 syncer::SyncDataList sync_data;
664 sync_data.push_back(settings_sync_util::CreateData( 664 sync_data.push_back(settings_sync_util::CreateData(
665 "s1", "foo", value1, syncable::EXTENSION_SETTINGS)); 665 "s1", "foo", value1, syncer::EXTENSION_SETTINGS));
666 666
667 GetSyncableService(syncable::EXTENSION_SETTINGS)->MergeDataAndStartSyncing( 667 GetSyncableService(syncer::EXTENSION_SETTINGS)->MergeDataAndStartSyncing(
668 syncable::EXTENSION_SETTINGS, 668 syncer::EXTENSION_SETTINGS,
669 sync_data, 669 sync_data,
670 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(), 670 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
671 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 671 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
672 GetSyncableService(syncable::EXTENSION_SETTINGS)-> 672 GetSyncableService(syncer::EXTENSION_SETTINGS)->
673 StopSyncing(syncable::EXTENSION_SETTINGS); 673 StopSyncing(syncer::EXTENSION_SETTINGS);
674 EXPECT_EQ(0u, sync_processor_->changes().size()); 674 EXPECT_EQ(0u, sync_processor_->changes().size());
675 675
676 sync_data.clear(); 676 sync_data.clear();
677 sync_data.push_back(settings_sync_util::CreateData( 677 sync_data.push_back(settings_sync_util::CreateData(
678 "s2", "bar", value2, syncable::APP_SETTINGS)); 678 "s2", "bar", value2, syncer::APP_SETTINGS));
679 679
680 scoped_ptr<SyncChangeProcessorDelegate> app_settings_delegate_( 680 scoped_ptr<SyncChangeProcessorDelegate> app_settings_delegate_(
681 new SyncChangeProcessorDelegate(sync_processor_.get())); 681 new SyncChangeProcessorDelegate(sync_processor_.get()));
682 GetSyncableService(syncable::APP_SETTINGS)->MergeDataAndStartSyncing( 682 GetSyncableService(syncer::APP_SETTINGS)->MergeDataAndStartSyncing(
683 syncable::APP_SETTINGS, 683 syncer::APP_SETTINGS,
684 sync_data, 684 sync_data,
685 app_settings_delegate_.PassAs<syncer::SyncChangeProcessor>(), 685 app_settings_delegate_.PassAs<syncer::SyncChangeProcessor>(),
686 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 686 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
687 GetSyncableService(syncable::APP_SETTINGS)-> 687 GetSyncableService(syncer::APP_SETTINGS)->
688 StopSyncing(syncable::APP_SETTINGS); 688 StopSyncing(syncer::APP_SETTINGS);
689 EXPECT_EQ(0u, sync_processor_->changes().size()); 689 EXPECT_EQ(0u, sync_processor_->changes().size());
690 } 690 }
691 691
692 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) { 692 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
693 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 693 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
694 Extension::Type type = Extension::TYPE_EXTENSION; 694 Extension::Type type = Extension::TYPE_EXTENSION;
695 695
696 StringValue fooValue("fooValue"); 696 StringValue fooValue("fooValue");
697 StringValue barValue("barValue"); 697 StringValue barValue("barValue");
698 698
699 // There is a bit of a convoluted method to get storage areas that can fail; 699 // There is a bit of a convoluted method to get storage areas that can fail;
700 // hand out TestingValueStore object then toggle them failing/succeeding 700 // hand out TestingValueStore object then toggle them failing/succeeding
701 // as necessary. 701 // as necessary.
702 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 702 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
703 storage_factory_->Reset(testing_factory); 703 storage_factory_->Reset(testing_factory);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 { 883 {
884 DictionaryValue dict; 884 DictionaryValue dict;
885 dict.Set("bar", fooValue.DeepCopy()); 885 dict.Set("bar", fooValue.DeepCopy());
886 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 886 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
887 } 887 }
888 } 888 }
889 889
890 TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) { 890 TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) {
891 // The test above tests a failing ProcessSyncChanges too, but here test with 891 // The test above tests a failing ProcessSyncChanges too, but here test with
892 // an initially passing MergeDataAndStartSyncing. 892 // an initially passing MergeDataAndStartSyncing.
893 syncable::ModelType model_type = syncable::APP_SETTINGS; 893 syncer::ModelType model_type = syncer::APP_SETTINGS;
894 Extension::Type type = Extension::TYPE_PACKAGED_APP; 894 Extension::Type type = Extension::TYPE_PACKAGED_APP;
895 895
896 StringValue fooValue("fooValue"); 896 StringValue fooValue("fooValue");
897 StringValue barValue("barValue"); 897 StringValue barValue("barValue");
898 898
899 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 899 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
900 storage_factory_->Reset(testing_factory); 900 storage_factory_->Reset(testing_factory);
901 901
902 ValueStore* good = AddExtensionAndGetStorage("good", type); 902 ValueStore* good = AddExtensionAndGetStorage("good", type);
903 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 903 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 981 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
982 } 982 }
983 { 983 {
984 DictionaryValue dict; 984 DictionaryValue dict;
985 dict.Set("foo", barValue.DeepCopy()); 985 dict.Set("foo", barValue.DeepCopy());
986 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 986 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
987 } 987 }
988 } 988 }
989 989
990 TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) { 990 TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) {
991 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 991 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
992 Extension::Type type = Extension::TYPE_EXTENSION; 992 Extension::Type type = Extension::TYPE_EXTENSION;
993 993
994 StringValue fooValue("fooValue"); 994 StringValue fooValue("fooValue");
995 StringValue barValue("barValue"); 995 StringValue barValue("barValue");
996 996
997 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 997 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
998 storage_factory_->Reset(testing_factory); 998 storage_factory_->Reset(testing_factory);
999 999
1000 ValueStore* good = AddExtensionAndGetStorage("good", type); 1000 ValueStore* good = AddExtensionAndGetStorage("good", type);
1001 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1001 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 EXPECT_EQ( 1036 EXPECT_EQ(
1037 syncer::SyncChange::ACTION_ADD, 1037 syncer::SyncChange::ACTION_ADD,
1038 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1038 sync_processor_->GetOnlyChange("good", "bar").change_type());
1039 EXPECT_EQ( 1039 EXPECT_EQ(
1040 syncer::SyncChange::ACTION_ADD, 1040 syncer::SyncChange::ACTION_ADD,
1041 sync_processor_->GetOnlyChange("bad", "bar").change_type()); 1041 sync_processor_->GetOnlyChange("bad", "bar").change_type());
1042 EXPECT_EQ(2u, sync_processor_->changes().size()); 1042 EXPECT_EQ(2u, sync_processor_->changes().size());
1043 } 1043 }
1044 1044
1045 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { 1045 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) {
1046 syncable::ModelType model_type = syncable::APP_SETTINGS; 1046 syncer::ModelType model_type = syncer::APP_SETTINGS;
1047 Extension::Type type = Extension::TYPE_PACKAGED_APP; 1047 Extension::Type type = Extension::TYPE_PACKAGED_APP;
1048 1048
1049 StringValue fooValue("fooValue"); 1049 StringValue fooValue("fooValue");
1050 StringValue barValue("barValue"); 1050 StringValue barValue("barValue");
1051 1051
1052 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 1052 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1053 storage_factory_->Reset(testing_factory); 1053 storage_factory_->Reset(testing_factory);
1054 1054
1055 ValueStore* good = AddExtensionAndGetStorage("good", type); 1055 ValueStore* good = AddExtensionAndGetStorage("good", type);
1056 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1056 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 EXPECT_EQ( 1140 EXPECT_EQ(
1141 syncer::SyncChange::ACTION_UPDATE, 1141 syncer::SyncChange::ACTION_UPDATE,
1142 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1142 sync_processor_->GetOnlyChange("good", "bar").change_type());
1143 EXPECT_EQ( 1143 EXPECT_EQ(
1144 syncer::SyncChange::ACTION_UPDATE, 1144 syncer::SyncChange::ACTION_UPDATE,
1145 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1145 sync_processor_->GetOnlyChange("good", "bar").change_type());
1146 EXPECT_EQ(2u, sync_processor_->changes().size()); 1146 EXPECT_EQ(2u, sync_processor_->changes().size());
1147 } 1147 }
1148 1148
1149 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { 1149 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) {
1150 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 1150 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
1151 Extension::Type type = Extension::TYPE_EXTENSION; 1151 Extension::Type type = Extension::TYPE_EXTENSION;
1152 1152
1153 StringValue fooValue("fooValue"); 1153 StringValue fooValue("fooValue");
1154 StringValue barValue("barValue"); 1154 StringValue barValue("barValue");
1155 1155
1156 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 1156 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1157 storage_factory_->Reset(testing_factory); 1157 storage_factory_->Reset(testing_factory);
1158 1158
1159 ValueStore* good = AddExtensionAndGetStorage("good", type); 1159 ValueStore* good = AddExtensionAndGetStorage("good", type);
1160 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1160 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 EXPECT_EQ( 1231 EXPECT_EQ(
1232 syncer::SyncChange::ACTION_UPDATE, 1232 syncer::SyncChange::ACTION_UPDATE,
1233 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1233 sync_processor_->GetOnlyChange("good", "foo").change_type());
1234 EXPECT_EQ( 1234 EXPECT_EQ(
1235 syncer::SyncChange::ACTION_UPDATE, 1235 syncer::SyncChange::ACTION_UPDATE,
1236 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1236 sync_processor_->GetOnlyChange("good", "foo").change_type());
1237 EXPECT_EQ(2u, sync_processor_->changes().size()); 1237 EXPECT_EQ(2u, sync_processor_->changes().size());
1238 } 1238 }
1239 1239
1240 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { 1240 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) {
1241 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 1241 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
1242 Extension::Type type = Extension::TYPE_EXTENSION; 1242 Extension::Type type = Extension::TYPE_EXTENSION;
1243 1243
1244 StringValue fooValue("fooValue"); 1244 StringValue fooValue("fooValue");
1245 StringValue barValue("barValue"); 1245 StringValue barValue("barValue");
1246 1246
1247 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 1247 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1248 storage_factory_->Reset(testing_factory); 1248 storage_factory_->Reset(testing_factory);
1249 1249
1250 ValueStore* good = AddExtensionAndGetStorage("good", type); 1250 ValueStore* good = AddExtensionAndGetStorage("good", type);
1251 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1251 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 syncer::SyncChange::ACTION_UPDATE, 1329 syncer::SyncChange::ACTION_UPDATE,
1330 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1330 sync_processor_->GetOnlyChange("good", "foo").change_type());
1331 EXPECT_EQ( 1331 EXPECT_EQ(
1332 syncer::SyncChange::ACTION_UPDATE, 1332 syncer::SyncChange::ACTION_UPDATE,
1333 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1333 sync_processor_->GetOnlyChange("good", "foo").change_type());
1334 EXPECT_EQ(2u, sync_processor_->changes().size()); 1334 EXPECT_EQ(2u, sync_processor_->changes().size());
1335 } 1335 }
1336 1336
1337 TEST_F(ExtensionSettingsSyncTest, 1337 TEST_F(ExtensionSettingsSyncTest,
1338 LargeOutgoingChangeRejectedButIncomingAccepted) { 1338 LargeOutgoingChangeRejectedButIncomingAccepted) {
1339 syncable::ModelType model_type = syncable::APP_SETTINGS; 1339 syncer::ModelType model_type = syncer::APP_SETTINGS;
1340 Extension::Type type = Extension::TYPE_PACKAGED_APP; 1340 Extension::Type type = Extension::TYPE_PACKAGED_APP;
1341 1341
1342 // This value should be larger than the limit in settings_backend.cc. 1342 // This value should be larger than the limit in settings_backend.cc.
1343 std::string string_5k; 1343 std::string string_5k;
1344 for (size_t i = 0; i < 5000; ++i) { 1344 for (size_t i = 0; i < 5000; ++i) {
1345 string_5k.append("a"); 1345 string_5k.append("a");
1346 } 1346 }
1347 StringValue large_value(string_5k); 1347 StringValue large_value(string_5k);
1348 1348
1349 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1349 GetSyncableService(model_type)->MergeDataAndStartSyncing(
(...skipping 21 matching lines...) Expand all
1371 DictionaryValue expected; 1371 DictionaryValue expected;
1372 expected.Set("large_value", large_value.DeepCopy()); 1372 expected.Set("large_value", large_value.DeepCopy());
1373 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get()); 1373 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get());
1374 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get()); 1374 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get());
1375 } 1375 }
1376 1376
1377 GetSyncableService(model_type)->StopSyncing(model_type); 1377 GetSyncableService(model_type)->StopSyncing(model_type);
1378 } 1378 }
1379 1379
1380 } // namespace extensions 1380 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/settings/settings_sync_processor.cc ('k') | chrome/browser/extensions/settings/settings_sync_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698