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

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

Issue 10545128: Unrevert r141537: Add extensions::StateStore and use that instead of (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix.crash Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return recipient_->ProcessSyncChanges(from_here, change_list); 160 return recipient_->ProcessSyncChanges(from_here, change_list);
161 } 161 }
162 162
163 private: 163 private:
164 // The recipient of all sync changes. 164 // The recipient of all sync changes.
165 SyncChangeProcessor* recipient_; 165 SyncChangeProcessor* recipient_;
166 166
167 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); 167 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate);
168 }; 168 };
169 169
170 // SettingsStorageFactory which always returns TestingSettingsStorage objects, 170 // SettingsStorageFactory which always returns TestingValueStore objects,
171 // and allows individually created objects to be returned. 171 // and allows individually created objects to be returned.
172 class TestingSettingsStorageFactory : public SettingsStorageFactory { 172 class TestingValueStoreFactory : public SettingsStorageFactory {
173 public: 173 public:
174 TestingSettingsStorage* GetExisting(const std::string& extension_id) { 174 TestingValueStore* GetExisting(const std::string& extension_id) {
175 DCHECK(created_.count(extension_id)); 175 DCHECK(created_.count(extension_id));
176 return created_[extension_id]; 176 return created_[extension_id];
177 } 177 }
178 178
179 // SettingsStorageFactory implementation. 179 // SettingsStorageFactory implementation.
180 virtual ValueStore* Create( 180 virtual ValueStore* Create(
181 const FilePath& base_path, const std::string& extension_id) OVERRIDE { 181 const FilePath& base_path, const std::string& extension_id) OVERRIDE {
182 TestingSettingsStorage* new_storage = new TestingSettingsStorage(); 182 TestingValueStore* new_storage = new TestingValueStore();
183 DCHECK(!created_.count(extension_id)); 183 DCHECK(!created_.count(extension_id));
184 created_[extension_id] = new_storage; 184 created_[extension_id] = new_storage;
185 return new_storage; 185 return new_storage;
186 } 186 }
187 187
188 private: 188 private:
189 // SettingsStorageFactory is refcounted. 189 // SettingsStorageFactory is refcounted.
190 virtual ~TestingSettingsStorageFactory() {} 190 virtual ~TestingValueStoreFactory() {}
191 191
192 // None of these storage areas are owned by this factory, so care must be 192 // None of these storage areas are owned by this factory, so care must be
193 // taken when calling GetExisting. 193 // taken when calling GetExisting.
194 std::map<std::string, TestingSettingsStorage*> created_; 194 std::map<std::string, TestingValueStore*> created_;
195 }; 195 };
196 196
197 void AssignSettingsService(SyncableService** dst, 197 void AssignSettingsService(SyncableService** dst,
198 const SettingsFrontend* frontend, 198 const SettingsFrontend* frontend,
199 syncable::ModelType type) { 199 syncable::ModelType type) {
200 *dst = frontend->GetBackendForSync(type); 200 *dst = frontend->GetBackendForSync(type);
201 } 201 }
202 202
203 } // namespace 203 } // namespace
204 204
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 690 }
691 691
692 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) { 692 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
693 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 693 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
694 Extension::Type type = Extension::TYPE_EXTENSION; 694 Extension::Type type = Extension::TYPE_EXTENSION;
695 695
696 StringValue fooValue("fooValue"); 696 StringValue fooValue("fooValue");
697 StringValue barValue("barValue"); 697 StringValue barValue("barValue");
698 698
699 // There is a bit of a convoluted method to get storage areas that can fail; 699 // There is a bit of a convoluted method to get storage areas that can fail;
700 // hand out TestingSettingsStorage object then toggle them failing/succeeding 700 // hand out TestingValueStore object then toggle them failing/succeeding
701 // as necessary. 701 // as necessary.
702 TestingSettingsStorageFactory* testing_factory = 702 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
703 new TestingSettingsStorageFactory();
704 storage_factory_->Reset(testing_factory); 703 storage_factory_->Reset(testing_factory);
705 704
706 ValueStore* good = AddExtensionAndGetStorage("good", type); 705 ValueStore* good = AddExtensionAndGetStorage("good", type);
707 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 706 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
708 707
709 // Make bad fail for incoming sync changes. 708 // Make bad fail for incoming sync changes.
710 testing_factory->GetExisting("bad")->SetFailAllRequests(true); 709 testing_factory->GetExisting("bad")->SetFailAllRequests(true);
711 { 710 {
712 SyncDataList sync_data; 711 SyncDataList sync_data;
713 sync_data.push_back(settings_sync_util::CreateData( 712 sync_data.push_back(settings_sync_util::CreateData(
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 888
890 TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) { 889 TEST_F(ExtensionSettingsSyncTest, FailingProcessChangesDisablesSync) {
891 // The test above tests a failing ProcessSyncChanges too, but here test with 890 // The test above tests a failing ProcessSyncChanges too, but here test with
892 // an initially passing MergeDataAndStartSyncing. 891 // an initially passing MergeDataAndStartSyncing.
893 syncable::ModelType model_type = syncable::APP_SETTINGS; 892 syncable::ModelType model_type = syncable::APP_SETTINGS;
894 Extension::Type type = Extension::TYPE_PACKAGED_APP; 893 Extension::Type type = Extension::TYPE_PACKAGED_APP;
895 894
896 StringValue fooValue("fooValue"); 895 StringValue fooValue("fooValue");
897 StringValue barValue("barValue"); 896 StringValue barValue("barValue");
898 897
899 TestingSettingsStorageFactory* testing_factory = 898 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
900 new TestingSettingsStorageFactory();
901 storage_factory_->Reset(testing_factory); 899 storage_factory_->Reset(testing_factory);
902 900
903 ValueStore* good = AddExtensionAndGetStorage("good", type); 901 ValueStore* good = AddExtensionAndGetStorage("good", type);
904 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 902 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
905 903
906 // Unlike before, initially succeeding MergeDataAndStartSyncing. 904 // Unlike before, initially succeeding MergeDataAndStartSyncing.
907 { 905 {
908 SyncDataList sync_data; 906 SyncDataList sync_data;
909 sync_data.push_back(settings_sync_util::CreateData( 907 sync_data.push_back(settings_sync_util::CreateData(
910 "good", "foo", fooValue, model_type)); 908 "good", "foo", fooValue, model_type));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 } 985 }
988 } 986 }
989 987
990 TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) { 988 TEST_F(ExtensionSettingsSyncTest, FailingGetAllSyncDataDoesntStopSync) {
991 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 989 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
992 Extension::Type type = Extension::TYPE_EXTENSION; 990 Extension::Type type = Extension::TYPE_EXTENSION;
993 991
994 StringValue fooValue("fooValue"); 992 StringValue fooValue("fooValue");
995 StringValue barValue("barValue"); 993 StringValue barValue("barValue");
996 994
997 TestingSettingsStorageFactory* testing_factory = 995 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
998 new TestingSettingsStorageFactory();
999 storage_factory_->Reset(testing_factory); 996 storage_factory_->Reset(testing_factory);
1000 997
1001 ValueStore* good = AddExtensionAndGetStorage("good", type); 998 ValueStore* good = AddExtensionAndGetStorage("good", type);
1002 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 999 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1003 1000
1004 good->Set(DEFAULTS, "foo", fooValue); 1001 good->Set(DEFAULTS, "foo", fooValue);
1005 bad->Set(DEFAULTS, "foo", fooValue); 1002 bad->Set(DEFAULTS, "foo", fooValue);
1006 1003
1007 // Even though bad will fail to get all sync data, sync data should still 1004 // Even though bad will fail to get all sync data, sync data should still
1008 // include that from good. 1005 // include that from good.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 EXPECT_EQ(2u, sync_processor_->changes().size()); 1040 EXPECT_EQ(2u, sync_processor_->changes().size());
1044 } 1041 }
1045 1042
1046 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { 1043 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) {
1047 syncable::ModelType model_type = syncable::APP_SETTINGS; 1044 syncable::ModelType model_type = syncable::APP_SETTINGS;
1048 Extension::Type type = Extension::TYPE_PACKAGED_APP; 1045 Extension::Type type = Extension::TYPE_PACKAGED_APP;
1049 1046
1050 StringValue fooValue("fooValue"); 1047 StringValue fooValue("fooValue");
1051 StringValue barValue("barValue"); 1048 StringValue barValue("barValue");
1052 1049
1053 TestingSettingsStorageFactory* testing_factory = 1050 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1054 new TestingSettingsStorageFactory();
1055 storage_factory_->Reset(testing_factory); 1051 storage_factory_->Reset(testing_factory);
1056 1052
1057 ValueStore* good = AddExtensionAndGetStorage("good", type); 1053 ValueStore* good = AddExtensionAndGetStorage("good", type);
1058 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1054 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1059 1055
1060 good->Set(DEFAULTS, "foo", fooValue); 1056 good->Set(DEFAULTS, "foo", fooValue);
1061 bad->Set(DEFAULTS, "foo", fooValue); 1057 bad->Set(DEFAULTS, "foo", fooValue);
1062 1058
1063 // good will successfully push foo:fooValue to sync, but bad will fail to 1059 // good will successfully push foo:fooValue to sync, but bad will fail to
1064 // get them so won't. 1060 // get them so won't.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 EXPECT_EQ(2u, sync_processor_->changes().size()); 1144 EXPECT_EQ(2u, sync_processor_->changes().size());
1149 } 1145 }
1150 1146
1151 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { 1147 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) {
1152 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 1148 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
1153 Extension::Type type = Extension::TYPE_EXTENSION; 1149 Extension::Type type = Extension::TYPE_EXTENSION;
1154 1150
1155 StringValue fooValue("fooValue"); 1151 StringValue fooValue("fooValue");
1156 StringValue barValue("barValue"); 1152 StringValue barValue("barValue");
1157 1153
1158 TestingSettingsStorageFactory* testing_factory = 1154 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1159 new TestingSettingsStorageFactory();
1160 storage_factory_->Reset(testing_factory); 1155 storage_factory_->Reset(testing_factory);
1161 1156
1162 ValueStore* good = AddExtensionAndGetStorage("good", type); 1157 ValueStore* good = AddExtensionAndGetStorage("good", type);
1163 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1158 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1164 1159
1165 // Only set bad; setting good will cause it to fail below. 1160 // Only set bad; setting good will cause it to fail below.
1166 bad->Set(DEFAULTS, "foo", fooValue); 1161 bad->Set(DEFAULTS, "foo", fooValue);
1167 1162
1168 sync_processor_->SetFailAllRequests(true); 1163 sync_processor_->SetFailAllRequests(true);
1169 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1164 GetSyncableService(model_type)->MergeDataAndStartSyncing(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 EXPECT_EQ(2u, sync_processor_->changes().size()); 1235 EXPECT_EQ(2u, sync_processor_->changes().size());
1241 } 1236 }
1242 1237
1243 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { 1238 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) {
1244 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 1239 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
1245 Extension::Type type = Extension::TYPE_EXTENSION; 1240 Extension::Type type = Extension::TYPE_EXTENSION;
1246 1241
1247 StringValue fooValue("fooValue"); 1242 StringValue fooValue("fooValue");
1248 StringValue barValue("barValue"); 1243 StringValue barValue("barValue");
1249 1244
1250 TestingSettingsStorageFactory* testing_factory = 1245 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1251 new TestingSettingsStorageFactory();
1252 storage_factory_->Reset(testing_factory); 1246 storage_factory_->Reset(testing_factory);
1253 1247
1254 ValueStore* good = AddExtensionAndGetStorage("good", type); 1248 ValueStore* good = AddExtensionAndGetStorage("good", type);
1255 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1249 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1256 1250
1257 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1251 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1258 model_type, 1252 model_type,
1259 SyncDataList(), 1253 SyncDataList(),
1260 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), 1254 sync_processor_delegate_.PassAs<SyncChangeProcessor>(),
1261 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); 1255 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock()));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 DictionaryValue expected; 1369 DictionaryValue expected;
1376 expected.Set("large_value", large_value.DeepCopy()); 1370 expected.Set("large_value", large_value.DeepCopy());
1377 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get()); 1371 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get());
1378 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get()); 1372 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get());
1379 } 1373 }
1380 1374
1381 GetSyncableService(model_type)->StopSyncing(model_type); 1375 GetSyncableService(model_type)->StopSyncing(model_type);
1382 } 1376 }
1383 1377
1384 } // namespace extensions 1378 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/settings/settings_quota_unittest.cc ('k') | chrome/browser/extensions/state_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698