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