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

Side by Side Diff: chrome/browser/extensions/api/storage/settings_sync_unittest.cc

Issue 2777063003: Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions (Closed)
Patch Set: Just rebased Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (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/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/values.h"
18 #include "build/build_config.h" 19 #include "build/build_config.h"
19 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" 20 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
20 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h" 21 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h"
21 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" 22 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "components/sync/model/sync_change_processor.h" 24 #include "components/sync/model/sync_change_processor.h"
24 #include "components/sync/model/sync_change_processor_wrapper_for_test.h" 25 #include "components/sync/model/sync_change_processor_wrapper_for_test.h"
25 #include "components/sync/model/sync_error_factory.h" 26 #include "components/sync/model/sync_error_factory.h"
26 #include "components/sync/model/sync_error_factory_mock.h" 27 #include "components/sync/model/sync_error_factory_mock.h"
27 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/test/test_browser_thread.h"
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 396
396 syncer::SyncDataList sync_data; 397 syncer::SyncDataList sync_data;
397 sync_data.push_back(settings_sync_util::CreateData( 398 sync_data.push_back(settings_sync_util::CreateData(
398 "s1", "foo", value1, model_type)); 399 "s1", "foo", value1, model_type));
399 sync_data.push_back(settings_sync_util::CreateData( 400 sync_data.push_back(settings_sync_util::CreateData(
400 "s2", "bar", value2, model_type)); 401 "s2", "bar", value2, model_type));
401 GetSyncableService(model_type) 402 GetSyncableService(model_type)
402 ->MergeDataAndStartSyncing( 403 ->MergeDataAndStartSyncing(
403 model_type, sync_data, std::move(sync_processor_wrapper_), 404 model_type, sync_data, std::move(sync_processor_wrapper_),
404 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 405 base::MakeUnique<syncer::SyncErrorFactoryMock>());
405 expected1.Set("foo", value1.DeepCopy()); 406 expected1.Set("foo", value1.CreateDeepCopy());
406 expected2.Set("bar", value2.DeepCopy()); 407 expected2.Set("bar", value2.CreateDeepCopy());
407 408
408 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 409 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
409 410
410 // All changes should be local, so no sync changes. 411 // All changes should be local, so no sync changes.
411 EXPECT_EQ(0u, sync_processor_->changes().size()); 412 EXPECT_EQ(0u, sync_processor_->changes().size());
412 413
413 // Sync settings should have been pushed to local settings. 414 // Sync settings should have been pushed to local settings.
414 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); 415 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
415 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); 416 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get());
416 417
(...skipping 10 matching lines...) Expand all
427 428
428 // Maintain dictionaries mirrored to the expected values of the settings in 429 // Maintain dictionaries mirrored to the expected values of the settings in
429 // each storage area. 430 // each storage area.
430 base::DictionaryValue expected1, expected2; 431 base::DictionaryValue expected1, expected2;
431 432
432 // Make storage1 initialised from local data, storage2 initialised from sync. 433 // Make storage1 initialised from local data, storage2 initialised from sync.
433 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 434 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
434 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 435 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
435 436
436 storage1->Set(DEFAULTS, "foo", value1); 437 storage1->Set(DEFAULTS, "foo", value1);
437 expected1.Set("foo", value1.DeepCopy()); 438 expected1.Set("foo", value1.CreateDeepCopy());
438 439
439 syncer::SyncDataList sync_data; 440 syncer::SyncDataList sync_data;
440 sync_data.push_back(settings_sync_util::CreateData( 441 sync_data.push_back(settings_sync_util::CreateData(
441 "s2", "bar", value2, model_type)); 442 "s2", "bar", value2, model_type));
442 443
443 GetSyncableService(model_type) 444 GetSyncableService(model_type)
444 ->MergeDataAndStartSyncing( 445 ->MergeDataAndStartSyncing(
445 model_type, sync_data, std::move(sync_processor_wrapper_), 446 model_type, sync_data, std::move(sync_processor_wrapper_),
446 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 447 base::MakeUnique<syncer::SyncErrorFactoryMock>());
447 expected2.Set("bar", value2.DeepCopy()); 448 expected2.Set("bar", value2.CreateDeepCopy());
448 449
449 // Make sync add some settings. 450 // Make sync add some settings.
450 syncer::SyncChangeList change_list; 451 syncer::SyncChangeList change_list;
451 change_list.push_back(settings_sync_util::CreateAdd( 452 change_list.push_back(settings_sync_util::CreateAdd(
452 "s1", "bar", value2, model_type)); 453 "s1", "bar", value2, model_type));
453 change_list.push_back(settings_sync_util::CreateAdd( 454 change_list.push_back(settings_sync_util::CreateAdd(
454 "s2", "foo", value1, model_type)); 455 "s2", "foo", value1, model_type));
455 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 456 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
456 expected1.Set("bar", value2.DeepCopy()); 457 expected1.Set("bar", value2.CreateDeepCopy());
457 expected2.Set("foo", value1.DeepCopy()); 458 expected2.Set("foo", value1.CreateDeepCopy());
458 459
459 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); 460 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
460 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); 461 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get());
461 462
462 // Make sync update some settings, storage1 the new setting, storage2 the 463 // Make sync update some settings, storage1 the new setting, storage2 the
463 // initial setting. 464 // initial setting.
464 change_list.clear(); 465 change_list.clear();
465 change_list.push_back(settings_sync_util::CreateUpdate( 466 change_list.push_back(settings_sync_util::CreateUpdate(
466 "s1", "bar", value2, model_type)); 467 "s1", "bar", value2, model_type));
467 change_list.push_back(settings_sync_util::CreateUpdate( 468 change_list.push_back(settings_sync_util::CreateUpdate(
468 "s2", "bar", value1, model_type)); 469 "s2", "bar", value1, model_type));
469 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 470 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
470 expected1.Set("bar", value2.DeepCopy()); 471 expected1.Set("bar", value2.CreateDeepCopy());
471 expected2.Set("bar", value1.DeepCopy()); 472 expected2.Set("bar", value1.CreateDeepCopy());
472 473
473 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); 474 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
474 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); 475 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get());
475 476
476 // Make sync remove some settings, storage1 the initial setting, storage2 the 477 // Make sync remove some settings, storage1 the initial setting, storage2 the
477 // new setting. 478 // new setting.
478 change_list.clear(); 479 change_list.clear();
479 change_list.push_back(settings_sync_util::CreateDelete( 480 change_list.push_back(settings_sync_util::CreateDelete(
480 "s1", "foo", model_type)); 481 "s1", "foo", model_type));
481 change_list.push_back(settings_sync_util::CreateDelete( 482 change_list.push_back(settings_sync_util::CreateDelete(
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 "bad", "foo", fooValue, model_type)); 701 "bad", "foo", fooValue, model_type));
701 GetSyncableService(model_type) 702 GetSyncableService(model_type)
702 ->MergeDataAndStartSyncing( 703 ->MergeDataAndStartSyncing(
703 model_type, sync_data, std::move(sync_processor_wrapper_), 704 model_type, sync_data, std::move(sync_processor_wrapper_),
704 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 705 base::MakeUnique<syncer::SyncErrorFactoryMock>());
705 } 706 }
706 GetExisting("bad")->set_status_code(ValueStore::OK); 707 GetExisting("bad")->set_status_code(ValueStore::OK);
707 708
708 { 709 {
709 base::DictionaryValue dict; 710 base::DictionaryValue dict;
710 dict.Set("foo", fooValue.DeepCopy()); 711 dict.Set("foo", fooValue.CreateDeepCopy());
711 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 712 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
712 } 713 }
713 { 714 {
714 base::DictionaryValue dict; 715 base::DictionaryValue dict;
715 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 716 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
716 } 717 }
717 718
718 // Changes made to good should be sent to sync, changes from bad shouldn't. 719 // Changes made to good should be sent to sync, changes from bad shouldn't.
719 sync_processor_->ClearChanges(); 720 sync_processor_->ClearChanges();
720 good->Set(DEFAULTS, "bar", barValue); 721 good->Set(DEFAULTS, "bar", barValue);
721 bad->Set(DEFAULTS, "bar", barValue); 722 bad->Set(DEFAULTS, "bar", barValue);
722 723
723 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 724 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
724 sync_processor_->GetOnlyChange("good", "bar")->change_type()); 725 sync_processor_->GetOnlyChange("good", "bar")->change_type());
725 EXPECT_EQ(1u, sync_processor_->changes().size()); 726 EXPECT_EQ(1u, sync_processor_->changes().size());
726 727
727 { 728 {
728 base::DictionaryValue dict; 729 base::DictionaryValue dict;
729 dict.Set("foo", fooValue.DeepCopy()); 730 dict.Set("foo", fooValue.CreateDeepCopy());
730 dict.Set("bar", barValue.DeepCopy()); 731 dict.Set("bar", barValue.CreateDeepCopy());
731 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 732 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
732 } 733 }
733 { 734 {
734 base::DictionaryValue dict; 735 base::DictionaryValue dict;
735 dict.Set("bar", barValue.DeepCopy()); 736 dict.Set("bar", barValue.CreateDeepCopy());
736 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 737 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
737 } 738 }
738 739
739 // Changes received from sync should go to good but not bad (even when it's 740 // Changes received from sync should go to good but not bad (even when it's
740 // not failing). 741 // not failing).
741 { 742 {
742 syncer::SyncChangeList change_list; 743 syncer::SyncChangeList change_list;
743 change_list.push_back(settings_sync_util::CreateUpdate( 744 change_list.push_back(settings_sync_util::CreateUpdate(
744 "good", "foo", barValue, model_type)); 745 "good", "foo", barValue, model_type));
745 // (Sending UPDATE here even though it's adding, since that's what the state 746 // (Sending UPDATE here even though it's adding, since that's what the state
746 // of sync is. In any case, it won't work.) 747 // of sync is. In any case, it won't work.)
747 change_list.push_back(settings_sync_util::CreateUpdate( 748 change_list.push_back(settings_sync_util::CreateUpdate(
748 "bad", "foo", barValue, model_type)); 749 "bad", "foo", barValue, model_type));
749 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 750 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
750 } 751 }
751 752
752 { 753 {
753 base::DictionaryValue dict; 754 base::DictionaryValue dict;
754 dict.Set("foo", barValue.DeepCopy()); 755 dict.Set("foo", barValue.CreateDeepCopy());
755 dict.Set("bar", barValue.DeepCopy()); 756 dict.Set("bar", barValue.CreateDeepCopy());
756 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 757 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
757 } 758 }
758 { 759 {
759 base::DictionaryValue dict; 760 base::DictionaryValue dict;
760 dict.Set("bar", barValue.DeepCopy()); 761 dict.Set("bar", barValue.CreateDeepCopy());
761 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 762 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
762 } 763 }
763 764
764 // Changes made to bad still shouldn't go to sync, even though it didn't fail 765 // Changes made to bad still shouldn't go to sync, even though it didn't fail
765 // last time. 766 // last time.
766 sync_processor_->ClearChanges(); 767 sync_processor_->ClearChanges();
767 good->Set(DEFAULTS, "bar", fooValue); 768 good->Set(DEFAULTS, "bar", fooValue);
768 bad->Set(DEFAULTS, "bar", fooValue); 769 bad->Set(DEFAULTS, "bar", fooValue);
769 770
770 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, 771 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE,
771 sync_processor_->GetOnlyChange("good", "bar")->change_type()); 772 sync_processor_->GetOnlyChange("good", "bar")->change_type());
772 EXPECT_EQ(1u, sync_processor_->changes().size()); 773 EXPECT_EQ(1u, sync_processor_->changes().size());
773 774
774 { 775 {
775 base::DictionaryValue dict; 776 base::DictionaryValue dict;
776 dict.Set("foo", barValue.DeepCopy()); 777 dict.Set("foo", barValue.CreateDeepCopy());
777 dict.Set("bar", fooValue.DeepCopy()); 778 dict.Set("bar", fooValue.CreateDeepCopy());
778 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 779 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
779 } 780 }
780 { 781 {
781 base::DictionaryValue dict; 782 base::DictionaryValue dict;
782 dict.Set("bar", fooValue.DeepCopy()); 783 dict.Set("bar", fooValue.CreateDeepCopy());
783 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 784 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
784 } 785 }
785 786
786 // Failing ProcessSyncChanges shouldn't go to the storage. 787 // Failing ProcessSyncChanges shouldn't go to the storage.
787 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); 788 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION);
788 { 789 {
789 syncer::SyncChangeList change_list; 790 syncer::SyncChangeList change_list;
790 change_list.push_back(settings_sync_util::CreateUpdate( 791 change_list.push_back(settings_sync_util::CreateUpdate(
791 "good", "foo", fooValue, model_type)); 792 "good", "foo", fooValue, model_type));
792 // (Ditto.) 793 // (Ditto.)
793 change_list.push_back(settings_sync_util::CreateUpdate( 794 change_list.push_back(settings_sync_util::CreateUpdate(
794 "bad", "foo", fooValue, model_type)); 795 "bad", "foo", fooValue, model_type));
795 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 796 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
796 } 797 }
797 GetExisting("bad")->set_status_code(ValueStore::OK); 798 GetExisting("bad")->set_status_code(ValueStore::OK);
798 799
799 { 800 {
800 base::DictionaryValue dict; 801 base::DictionaryValue dict;
801 dict.Set("foo", fooValue.DeepCopy()); 802 dict.Set("foo", fooValue.CreateDeepCopy());
802 dict.Set("bar", fooValue.DeepCopy()); 803 dict.Set("bar", fooValue.CreateDeepCopy());
803 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 804 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
804 } 805 }
805 { 806 {
806 base::DictionaryValue dict; 807 base::DictionaryValue dict;
807 dict.Set("bar", fooValue.DeepCopy()); 808 dict.Set("bar", fooValue.CreateDeepCopy());
808 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 809 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
809 } 810 }
810 811
811 // Restarting sync should make bad start syncing again. 812 // Restarting sync should make bad start syncing again.
812 sync_processor_->ClearChanges(); 813 sync_processor_->ClearChanges();
813 GetSyncableService(model_type)->StopSyncing(model_type); 814 GetSyncableService(model_type)->StopSyncing(model_type);
814 sync_processor_wrapper_.reset( 815 sync_processor_wrapper_.reset(
815 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 816 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
816 GetSyncableService(model_type) 817 GetSyncableService(model_type)
817 ->MergeDataAndStartSyncing( 818 ->MergeDataAndStartSyncing(
(...skipping 27 matching lines...) Expand all
845 syncer::SyncChangeList change_list; 846 syncer::SyncChangeList change_list;
846 change_list.push_back(settings_sync_util::CreateUpdate( 847 change_list.push_back(settings_sync_util::CreateUpdate(
847 "good", "bar", fooValue, model_type)); 848 "good", "bar", fooValue, model_type));
848 change_list.push_back(settings_sync_util::CreateUpdate( 849 change_list.push_back(settings_sync_util::CreateUpdate(
849 "bad", "bar", fooValue, model_type)); 850 "bad", "bar", fooValue, model_type));
850 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 851 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
851 } 852 }
852 853
853 { 854 {
854 base::DictionaryValue dict; 855 base::DictionaryValue dict;
855 dict.Set("foo", fooValue.DeepCopy()); 856 dict.Set("foo", fooValue.CreateDeepCopy());
856 dict.Set("bar", fooValue.DeepCopy()); 857 dict.Set("bar", fooValue.CreateDeepCopy());
857 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 858 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
858 } 859 }
859 { 860 {
860 base::DictionaryValue dict; 861 base::DictionaryValue dict;
861 dict.Set("bar", fooValue.DeepCopy()); 862 dict.Set("bar", fooValue.CreateDeepCopy());
862 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 863 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
863 } 864 }
864 } 865 }
865 866
866 TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) { 867 TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) {
867 // The test above tests a failing ProcessSyncChanges too, but here test with 868 // The test above tests a failing ProcessSyncChanges too, but here test with
868 // an initially passing MergeDataAndStartSyncing. 869 // an initially passing MergeDataAndStartSyncing.
869 syncer::ModelType model_type = syncer::APP_SETTINGS; 870 syncer::ModelType model_type = syncer::APP_SETTINGS;
870 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; 871 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP;
871 872
(...skipping 13 matching lines...) Expand all
885 GetSyncableService(model_type) 886 GetSyncableService(model_type)
886 ->MergeDataAndStartSyncing( 887 ->MergeDataAndStartSyncing(
887 model_type, sync_data, std::move(sync_processor_wrapper_), 888 model_type, sync_data, std::move(sync_processor_wrapper_),
888 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 889 base::MakeUnique<syncer::SyncErrorFactoryMock>());
889 } 890 }
890 891
891 EXPECT_EQ(0u, sync_processor_->changes().size()); 892 EXPECT_EQ(0u, sync_processor_->changes().size());
892 893
893 { 894 {
894 base::DictionaryValue dict; 895 base::DictionaryValue dict;
895 dict.Set("foo", fooValue.DeepCopy()); 896 dict.Set("foo", fooValue.CreateDeepCopy());
896 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 897 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
897 } 898 }
898 { 899 {
899 base::DictionaryValue dict; 900 base::DictionaryValue dict;
900 dict.Set("foo", fooValue.DeepCopy()); 901 dict.Set("foo", fooValue.CreateDeepCopy());
901 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 902 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
902 } 903 }
903 904
904 // Now fail ProcessSyncChanges for bad. 905 // Now fail ProcessSyncChanges for bad.
905 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); 906 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION);
906 { 907 {
907 syncer::SyncChangeList change_list; 908 syncer::SyncChangeList change_list;
908 change_list.push_back(settings_sync_util::CreateAdd( 909 change_list.push_back(settings_sync_util::CreateAdd(
909 "good", "bar", barValue, model_type)); 910 "good", "bar", barValue, model_type));
910 change_list.push_back(settings_sync_util::CreateAdd( 911 change_list.push_back(settings_sync_util::CreateAdd(
911 "bad", "bar", barValue, model_type)); 912 "bad", "bar", barValue, model_type));
912 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 913 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
913 } 914 }
914 GetExisting("bad")->set_status_code(ValueStore::OK); 915 GetExisting("bad")->set_status_code(ValueStore::OK);
915 916
916 { 917 {
917 base::DictionaryValue dict; 918 base::DictionaryValue dict;
918 dict.Set("foo", fooValue.DeepCopy()); 919 dict.Set("foo", fooValue.CreateDeepCopy());
919 dict.Set("bar", barValue.DeepCopy()); 920 dict.Set("bar", barValue.CreateDeepCopy());
920 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 921 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
921 } 922 }
922 { 923 {
923 base::DictionaryValue dict; 924 base::DictionaryValue dict;
924 dict.Set("foo", fooValue.DeepCopy()); 925 dict.Set("foo", fooValue.CreateDeepCopy());
925 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 926 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
926 } 927 }
927 928
928 // No more changes sent to sync for bad. 929 // No more changes sent to sync for bad.
929 sync_processor_->ClearChanges(); 930 sync_processor_->ClearChanges();
930 good->Set(DEFAULTS, "foo", barValue); 931 good->Set(DEFAULTS, "foo", barValue);
931 bad->Set(DEFAULTS, "foo", barValue); 932 bad->Set(DEFAULTS, "foo", barValue);
932 933
933 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, 934 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE,
934 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 935 sync_processor_->GetOnlyChange("good", "foo")->change_type());
935 EXPECT_EQ(1u, sync_processor_->changes().size()); 936 EXPECT_EQ(1u, sync_processor_->changes().size());
936 937
937 // No more changes received from sync should go to bad. 938 // No more changes received from sync should go to bad.
938 { 939 {
939 syncer::SyncChangeList change_list; 940 syncer::SyncChangeList change_list;
940 change_list.push_back(settings_sync_util::CreateAdd( 941 change_list.push_back(settings_sync_util::CreateAdd(
941 "good", "foo", fooValue, model_type)); 942 "good", "foo", fooValue, model_type));
942 change_list.push_back(settings_sync_util::CreateAdd( 943 change_list.push_back(settings_sync_util::CreateAdd(
943 "bad", "foo", fooValue, model_type)); 944 "bad", "foo", fooValue, model_type));
944 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 945 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
945 } 946 }
946 947
947 { 948 {
948 base::DictionaryValue dict; 949 base::DictionaryValue dict;
949 dict.Set("foo", fooValue.DeepCopy()); 950 dict.Set("foo", fooValue.CreateDeepCopy());
950 dict.Set("bar", barValue.DeepCopy()); 951 dict.Set("bar", barValue.CreateDeepCopy());
951 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 952 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
952 } 953 }
953 { 954 {
954 base::DictionaryValue dict; 955 base::DictionaryValue dict;
955 dict.Set("foo", barValue.DeepCopy()); 956 dict.Set("foo", barValue.CreateDeepCopy());
956 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 957 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
957 } 958 }
958 } 959 }
959 960
960 TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) { 961 TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) {
961 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; 962 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
962 Manifest::Type type = Manifest::TYPE_EXTENSION; 963 Manifest::Type type = Manifest::TYPE_EXTENSION;
963 964
964 base::Value fooValue("fooValue"); 965 base::Value fooValue("fooValue");
965 base::Value barValue("barValue"); 966 base::Value barValue("barValue");
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 "good", "foo", barValue, model_type)); 1048 "good", "foo", barValue, model_type));
1048 // (Sending ADD here even though it's updating, since that's what the state 1049 // (Sending ADD here even though it's updating, since that's what the state
1049 // of sync is. In any case, it won't work.) 1050 // of sync is. In any case, it won't work.)
1050 change_list.push_back(settings_sync_util::CreateAdd( 1051 change_list.push_back(settings_sync_util::CreateAdd(
1051 "bad", "foo", barValue, model_type)); 1052 "bad", "foo", barValue, model_type));
1052 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 1053 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1053 } 1054 }
1054 1055
1055 { 1056 {
1056 base::DictionaryValue dict; 1057 base::DictionaryValue dict;
1057 dict.Set("foo", barValue.DeepCopy()); 1058 dict.Set("foo", barValue.CreateDeepCopy());
1058 dict.Set("bar", barValue.DeepCopy()); 1059 dict.Set("bar", barValue.CreateDeepCopy());
1059 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 1060 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
1060 } 1061 }
1061 { 1062 {
1062 base::DictionaryValue dict; 1063 base::DictionaryValue dict;
1063 dict.Set("foo", fooValue.DeepCopy()); 1064 dict.Set("foo", fooValue.CreateDeepCopy());
1064 dict.Set("bar", barValue.DeepCopy()); 1065 dict.Set("bar", barValue.CreateDeepCopy());
1065 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 1066 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
1066 } 1067 }
1067 1068
1068 // Re-enabling sync without failing should cause the local changes from bad 1069 // Re-enabling sync without failing should cause the local changes from bad
1069 // to be pushed to sync successfully, as should future changes to bad. 1070 // to be pushed to sync successfully, as should future changes to bad.
1070 sync_processor_->ClearChanges(); 1071 sync_processor_->ClearChanges();
1071 GetSyncableService(model_type)->StopSyncing(model_type); 1072 GetSyncableService(model_type)->StopSyncing(model_type);
1072 sync_processor_wrapper_.reset( 1073 sync_processor_wrapper_.reset(
1073 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 1074 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
1074 GetSyncableService(model_type) 1075 GetSyncableService(model_type)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 syncer::SyncChangeList change_list; 1134 syncer::SyncChangeList change_list;
1134 change_list.push_back(settings_sync_util::CreateAdd( 1135 change_list.push_back(settings_sync_util::CreateAdd(
1135 "good", "bar", barValue, model_type)); 1136 "good", "bar", barValue, model_type));
1136 change_list.push_back(settings_sync_util::CreateAdd( 1137 change_list.push_back(settings_sync_util::CreateAdd(
1137 "bad", "bar", barValue, model_type)); 1138 "bad", "bar", barValue, model_type));
1138 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 1139 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1139 } 1140 }
1140 1141
1141 { 1142 {
1142 base::DictionaryValue dict; 1143 base::DictionaryValue dict;
1143 dict.Set("foo", barValue.DeepCopy()); 1144 dict.Set("foo", barValue.CreateDeepCopy());
1144 dict.Set("bar", barValue.DeepCopy()); 1145 dict.Set("bar", barValue.CreateDeepCopy());
1145 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 1146 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
1146 } 1147 }
1147 { 1148 {
1148 base::DictionaryValue dict; 1149 base::DictionaryValue dict;
1149 dict.Set("foo", barValue.DeepCopy()); 1150 dict.Set("foo", barValue.CreateDeepCopy());
1150 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 1151 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
1151 } 1152 }
1152 1153
1153 // Restarting sync makes everything work again. 1154 // Restarting sync makes everything work again.
1154 sync_processor_->ClearChanges(); 1155 sync_processor_->ClearChanges();
1155 GetSyncableService(model_type)->StopSyncing(model_type); 1156 GetSyncableService(model_type)->StopSyncing(model_type);
1156 sync_processor_wrapper_.reset( 1157 sync_processor_wrapper_.reset(
1157 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 1158 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
1158 GetSyncableService(model_type) 1159 GetSyncableService(model_type)
1159 ->MergeDataAndStartSyncing( 1160 ->MergeDataAndStartSyncing(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 syncer::SyncChangeList change_list; 1221 syncer::SyncChangeList change_list;
1221 change_list.push_back(settings_sync_util::CreateAdd( 1222 change_list.push_back(settings_sync_util::CreateAdd(
1222 "good", "bar", barValue, model_type)); 1223 "good", "bar", barValue, model_type));
1223 change_list.push_back(settings_sync_util::CreateAdd( 1224 change_list.push_back(settings_sync_util::CreateAdd(
1224 "bad", "bar", barValue, model_type)); 1225 "bad", "bar", barValue, model_type));
1225 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 1226 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1226 } 1227 }
1227 1228
1228 { 1229 {
1229 base::DictionaryValue dict; 1230 base::DictionaryValue dict;
1230 dict.Set("foo", barValue.DeepCopy()); 1231 dict.Set("foo", barValue.CreateDeepCopy());
1231 dict.Set("bar", barValue.DeepCopy()); 1232 dict.Set("bar", barValue.CreateDeepCopy());
1232 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 1233 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
1233 } 1234 }
1234 { 1235 {
1235 base::DictionaryValue dict; 1236 base::DictionaryValue dict;
1236 dict.Set("foo", barValue.DeepCopy()); 1237 dict.Set("foo", barValue.CreateDeepCopy());
1237 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 1238 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
1238 } 1239 }
1239 1240
1240 // Restarting sync makes everything work again. 1241 // Restarting sync makes everything work again.
1241 sync_processor_->ClearChanges(); 1242 sync_processor_->ClearChanges();
1242 GetSyncableService(model_type)->StopSyncing(model_type); 1243 GetSyncableService(model_type)->StopSyncing(model_type);
1243 sync_processor_wrapper_.reset( 1244 sync_processor_wrapper_.reset(
1244 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 1245 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
1245 GetSyncableService(model_type) 1246 GetSyncableService(model_type)
1246 ->MergeDataAndStartSyncing( 1247 ->MergeDataAndStartSyncing(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 { 1297 {
1297 syncer::SyncChangeList change_list; 1298 syncer::SyncChangeList change_list;
1298 change_list.push_back(settings_sync_util::CreateAdd( 1299 change_list.push_back(settings_sync_util::CreateAdd(
1299 "s1", "large_value", large_value, model_type)); 1300 "s1", "large_value", large_value, model_type));
1300 change_list.push_back(settings_sync_util::CreateAdd( 1301 change_list.push_back(settings_sync_util::CreateAdd(
1301 "s2", "large_value", large_value, model_type)); 1302 "s2", "large_value", large_value, model_type));
1302 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 1303 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1303 } 1304 }
1304 { 1305 {
1305 base::DictionaryValue expected; 1306 base::DictionaryValue expected;
1306 expected.Set("large_value", large_value.DeepCopy()); 1307 expected.Set("large_value", large_value.CreateDeepCopy());
1307 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get()); 1308 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get());
1308 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get()); 1309 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get());
1309 } 1310 }
1310 1311
1311 GetSyncableService(model_type)->StopSyncing(model_type); 1312 GetSyncableService(model_type)->StopSyncing(model_type);
1312 } 1313 }
1313 1314
1314 TEST_F(ExtensionSettingsSyncTest, Dots) { 1315 TEST_F(ExtensionSettingsSyncTest, Dots) {
1315 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; 1316 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
1316 Manifest::Type type = Manifest::TYPE_EXTENSION; 1317 Manifest::Type type = Manifest::TYPE_EXTENSION;
(...skipping 11 matching lines...) Expand all
1328 model_type, sync_data_list, std::move(sync_processor_wrapper_), 1329 model_type, sync_data_list, std::move(sync_processor_wrapper_),
1329 base::MakeUnique<syncer::SyncErrorFactoryMock>()); 1330 base::MakeUnique<syncer::SyncErrorFactoryMock>());
1330 } 1331 }
1331 1332
1332 // Test dots in keys that come from sync. 1333 // Test dots in keys that come from sync.
1333 { 1334 {
1334 ValueStore::ReadResult data = storage->Get(); 1335 ValueStore::ReadResult data = storage->Get();
1335 ASSERT_TRUE(data->status().ok()); 1336 ASSERT_TRUE(data->status().ok());
1336 1337
1337 base::DictionaryValue expected_data; 1338 base::DictionaryValue expected_data;
1338 expected_data.SetWithoutPathExpansion("key.with.dot", 1339 expected_data.SetWithoutPathExpansion(
1339 new base::Value("value")); 1340 "key.with.dot", base::MakeUnique<base::Value>("value"));
1340 EXPECT_TRUE(base::Value::Equals(&expected_data, &data->settings())); 1341 EXPECT_TRUE(base::Value::Equals(&expected_data, &data->settings()));
1341 } 1342 }
1342 1343
1343 // Test dots in keys going to sync. 1344 // Test dots in keys going to sync.
1344 { 1345 {
1345 std::unique_ptr<base::Value> string_value(new base::Value("spot")); 1346 std::unique_ptr<base::Value> string_value(new base::Value("spot"));
1346 storage->Set(DEFAULTS, "key.with.spot", *string_value); 1347 storage->Set(DEFAULTS, "key.with.spot", *string_value);
1347 1348
1348 ASSERT_EQ(1u, sync_processor_->changes().size()); 1349 ASSERT_EQ(1u, sync_processor_->changes().size());
1349 SettingSyncData* sync_data = sync_processor_->changes()[0].get(); 1350 SettingSyncData* sync_data = sync_processor_->changes()[0].get();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 settings_namespace::SYNC, 1408 settings_namespace::SYNC,
1408 base::Bind(&UnlimitedSyncStorageTestCallback)); 1409 base::Bind(&UnlimitedSyncStorageTestCallback));
1409 frontend_->RunWithStorage(extension, 1410 frontend_->RunWithStorage(extension,
1410 settings_namespace::LOCAL, 1411 settings_namespace::LOCAL,
1411 base::Bind(&UnlimitedLocalStorageTestCallback)); 1412 base::Bind(&UnlimitedLocalStorageTestCallback));
1412 1413
1413 base::RunLoop().RunUntilIdle(); 1414 base::RunLoop().RunUntilIdle();
1414 } 1415 }
1415 1416
1416 } // namespace extensions 1417 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698