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