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

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

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (actual->HasError()) { 75 if (actual->HasError()) {
76 return testing::AssertionFailure() << 76 return testing::AssertionFailure() <<
77 "Expected: " << GetJson(expected) << 77 "Expected: " << GetJson(expected) <<
78 ", actual has error: " << actual->error(); 78 ", actual has error: " << actual->error();
79 } 79 }
80 return ValuesEq(_1, _2, &expected, actual->settings().get()); 80 return ValuesEq(_1, _2, &expected, actual->settings().get());
81 } 81 }
82 82
83 // SyncChangeProcessor which just records the changes made, accessed after 83 // SyncChangeProcessor which just records the changes made, accessed after
84 // being converted to the more useful SettingSyncData via changes(). 84 // being converted to the more useful SettingSyncData via changes().
85 class MockSyncChangeProcessor : public csync::SyncChangeProcessor { 85 class MockSyncChangeProcessor : public syncer::SyncChangeProcessor {
86 public: 86 public:
87 MockSyncChangeProcessor() : fail_all_requests_(false) {} 87 MockSyncChangeProcessor() : fail_all_requests_(false) {}
88 88
89 // csync::SyncChangeProcessor implementation. 89 // syncer::SyncChangeProcessor implementation.
90 virtual csync::SyncError ProcessSyncChanges( 90 virtual syncer::SyncError ProcessSyncChanges(
91 const tracked_objects::Location& from_here, 91 const tracked_objects::Location& from_here,
92 const csync::SyncChangeList& change_list) OVERRIDE { 92 const syncer::SyncChangeList& change_list) OVERRIDE {
93 if (fail_all_requests_) { 93 if (fail_all_requests_) {
94 return csync::SyncError( 94 return syncer::SyncError(
95 FROM_HERE, 95 FROM_HERE,
96 "MockSyncChangeProcessor: configured to fail", 96 "MockSyncChangeProcessor: configured to fail",
97 change_list[0].sync_data().GetDataType()); 97 change_list[0].sync_data().GetDataType());
98 } 98 }
99 for (csync::SyncChangeList::const_iterator it = change_list.begin(); 99 for (syncer::SyncChangeList::const_iterator it = change_list.begin();
100 it != change_list.end(); ++it) { 100 it != change_list.end(); ++it) {
101 changes_.push_back(SettingSyncData(*it)); 101 changes_.push_back(SettingSyncData(*it));
102 } 102 }
103 return csync::SyncError(); 103 return syncer::SyncError();
104 } 104 }
105 105
106 // Mock methods. 106 // Mock methods.
107 107
108 const SettingSyncDataList& changes() { return changes_; } 108 const SettingSyncDataList& changes() { return changes_; }
109 109
110 void ClearChanges() { 110 void ClearChanges() {
111 changes_.clear(); 111 changes_.clear();
112 } 112 }
113 113
114 void SetFailAllRequests(bool fail_all_requests) { 114 void SetFailAllRequests(bool fail_all_requests) {
115 fail_all_requests_ = fail_all_requests; 115 fail_all_requests_ = fail_all_requests;
116 } 116 }
117 117
118 // Returns the only change for a given extension setting. If there is not 118 // Returns the only change for a given extension setting. If there is not
119 // exactly 1 change for that key, a test assertion will fail. 119 // exactly 1 change for that key, a test assertion will fail.
120 SettingSyncData GetOnlyChange( 120 SettingSyncData GetOnlyChange(
121 const std::string& extension_id, const std::string& key) { 121 const std::string& extension_id, const std::string& key) {
122 SettingSyncDataList matching_changes; 122 SettingSyncDataList matching_changes;
123 for (SettingSyncDataList::iterator it = changes_.begin(); 123 for (SettingSyncDataList::iterator it = changes_.begin();
124 it != changes_.end(); ++it) { 124 it != changes_.end(); ++it) {
125 if (it->extension_id() == extension_id && it->key() == key) { 125 if (it->extension_id() == extension_id && it->key() == key) {
126 matching_changes.push_back(*it); 126 matching_changes.push_back(*it);
127 } 127 }
128 } 128 }
129 if (matching_changes.empty()) { 129 if (matching_changes.empty()) {
130 ADD_FAILURE() << "No matching changes for " << extension_id << "/" << 130 ADD_FAILURE() << "No matching changes for " << extension_id << "/" <<
131 key << " (out of " << changes_.size() << ")"; 131 key << " (out of " << changes_.size() << ")";
132 return SettingSyncData( 132 return SettingSyncData(
133 csync::SyncChange::ACTION_INVALID, "", "", 133 syncer::SyncChange::ACTION_INVALID, "", "",
134 scoped_ptr<Value>(new DictionaryValue())); 134 scoped_ptr<Value>(new DictionaryValue()));
135 } 135 }
136 if (matching_changes.size() != 1u) { 136 if (matching_changes.size() != 1u) {
137 ADD_FAILURE() << matching_changes.size() << " matching changes for " << 137 ADD_FAILURE() << matching_changes.size() << " matching changes for " <<
138 extension_id << "/" << key << " (out of " << changes_.size() << ")"; 138 extension_id << "/" << key << " (out of " << changes_.size() << ")";
139 } 139 }
140 return matching_changes[0]; 140 return matching_changes[0];
141 } 141 }
142 142
143 private: 143 private:
144 SettingSyncDataList changes_; 144 SettingSyncDataList changes_;
145 bool fail_all_requests_; 145 bool fail_all_requests_;
146 }; 146 };
147 147
148 class SyncChangeProcessorDelegate : public csync::SyncChangeProcessor { 148 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
149 public: 149 public:
150 explicit SyncChangeProcessorDelegate(csync::SyncChangeProcessor* recipient) 150 explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient)
151 : recipient_(recipient) { 151 : recipient_(recipient) {
152 DCHECK(recipient_); 152 DCHECK(recipient_);
153 } 153 }
154 virtual ~SyncChangeProcessorDelegate() {} 154 virtual ~SyncChangeProcessorDelegate() {}
155 155
156 // csync::SyncChangeProcessor implementation. 156 // syncer::SyncChangeProcessor implementation.
157 virtual csync::SyncError ProcessSyncChanges( 157 virtual syncer::SyncError ProcessSyncChanges(
158 const tracked_objects::Location& from_here, 158 const tracked_objects::Location& from_here,
159 const csync::SyncChangeList& change_list) OVERRIDE { 159 const syncer::SyncChangeList& change_list) OVERRIDE {
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 csync::SyncChangeProcessor* recipient_; 165 syncer::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 TestingValueStore 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 TestingValueStoreFactory : public SettingsStorageFactory { 172 class TestingValueStoreFactory : public SettingsStorageFactory {
173 public: 173 public:
174 TestingValueStore* 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));
(...skipping 11 matching lines...) Expand all
187 187
188 private: 188 private:
189 // SettingsStorageFactory is refcounted. 189 // SettingsStorageFactory is refcounted.
190 virtual ~TestingValueStoreFactory() {} 190 virtual ~TestingValueStoreFactory() {}
191 191
192 // None of these storage areas are owned by this factory, so care must be 192 // None of these storage areas are owned by this factory, so care must be
193 // taken when calling GetExisting. 193 // taken when calling GetExisting.
194 std::map<std::string, TestingValueStore*> created_; 194 std::map<std::string, TestingValueStore*> created_;
195 }; 195 };
196 196
197 void AssignSettingsService(csync::SyncableService** dst, 197 void AssignSettingsService(syncer::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
205 class ExtensionSettingsSyncTest : public testing::Test { 205 class ExtensionSettingsSyncTest : public testing::Test {
206 public: 206 public:
207 ExtensionSettingsSyncTest() 207 ExtensionSettingsSyncTest()
(...skipping 19 matching lines...) Expand all
227 227
228 protected: 228 protected:
229 // Adds a record of an extension or app to the extension service, then returns 229 // Adds a record of an extension or app to the extension service, then returns
230 // its storage area. 230 // its storage area.
231 ValueStore* AddExtensionAndGetStorage( 231 ValueStore* AddExtensionAndGetStorage(
232 const std::string& id, Extension::Type type) { 232 const std::string& id, Extension::Type type) {
233 profile_->GetMockExtensionService()->AddExtensionWithId(id, type); 233 profile_->GetMockExtensionService()->AddExtensionWithId(id, type);
234 return util::GetStorage(id, frontend_.get()); 234 return util::GetStorage(id, frontend_.get());
235 } 235 }
236 236
237 // Gets the csync::SyncableService for the given sync type. 237 // Gets the syncer::SyncableService for the given sync type.
238 csync::SyncableService* GetSyncableService(syncable::ModelType model_type) { 238 syncer::SyncableService* GetSyncableService(syncable::ModelType model_type) {
239 MessageLoop::current()->RunAllPending(); 239 MessageLoop::current()->RunAllPending();
240 return frontend_->GetBackendForSync(model_type); 240 return frontend_->GetBackendForSync(model_type);
241 } 241 }
242 242
243 // Gets all the sync data from the SyncableService for a sync type as a map 243 // Gets all the sync data from the SyncableService for a sync type as a map
244 // from extension id to its sync data. 244 // from extension id to its sync data.
245 std::map<std::string, SettingSyncDataList> GetAllSyncData( 245 std::map<std::string, SettingSyncDataList> GetAllSyncData(
246 syncable::ModelType model_type) { 246 syncable::ModelType model_type) {
247 csync::SyncDataList as_list = 247 syncer::SyncDataList as_list =
248 GetSyncableService(model_type)->GetAllSyncData(model_type); 248 GetSyncableService(model_type)->GetAllSyncData(model_type);
249 std::map<std::string, SettingSyncDataList> as_map; 249 std::map<std::string, SettingSyncDataList> as_map;
250 for (csync::SyncDataList::iterator it = as_list.begin(); 250 for (syncer::SyncDataList::iterator it = as_list.begin();
251 it != as_list.end(); ++it) { 251 it != as_list.end(); ++it) {
252 SettingSyncData sync_data(*it); 252 SettingSyncData sync_data(*it);
253 as_map[sync_data.extension_id()].push_back(sync_data); 253 as_map[sync_data.extension_id()].push_back(sync_data);
254 } 254 }
255 return as_map; 255 return as_map;
256 } 256 }
257 257
258 // Need these so that the DCHECKs for running on FILE or UI threads pass. 258 // Need these so that the DCHECKs for running on FILE or UI threads pass.
259 MessageLoop message_loop_; 259 MessageLoop message_loop_;
260 content::TestBrowserThread ui_thread_; 260 content::TestBrowserThread ui_thread_;
(...skipping 15 matching lines...) Expand all
276 Extension::Type type = Extension::TYPE_EXTENSION; 276 Extension::Type type = Extension::TYPE_EXTENSION;
277 277
278 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 278 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
279 279
280 // Have one extension created before sync is set up, the other created after. 280 // Have one extension created before sync is set up, the other created after.
281 AddExtensionAndGetStorage("s1", type); 281 AddExtensionAndGetStorage("s1", type);
282 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 282 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
283 283
284 GetSyncableService(model_type)->MergeDataAndStartSyncing( 284 GetSyncableService(model_type)->MergeDataAndStartSyncing(
285 model_type, 285 model_type,
286 csync::SyncDataList(), 286 syncer::SyncDataList(),
287 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 287 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
288 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 288 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
289 289
290 AddExtensionAndGetStorage("s2", type); 290 AddExtensionAndGetStorage("s2", type);
291 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 291 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
292 292
293 GetSyncableService(model_type)->StopSyncing(model_type); 293 GetSyncableService(model_type)->StopSyncing(model_type);
294 294
295 EXPECT_EQ(0u, sync_processor_->changes().size()); 295 EXPECT_EQ(0u, sync_processor_->changes().size());
296 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 296 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
297 } 297 }
298 298
(...skipping 12 matching lines...) Expand all
311 storage2->Set(DEFAULTS, "bar", value2); 311 storage2->Set(DEFAULTS, "bar", value2);
312 312
313 std::map<std::string, SettingSyncDataList> all_sync_data = 313 std::map<std::string, SettingSyncDataList> all_sync_data =
314 GetAllSyncData(model_type); 314 GetAllSyncData(model_type);
315 EXPECT_EQ(2u, all_sync_data.size()); 315 EXPECT_EQ(2u, all_sync_data.size());
316 EXPECT_EQ(1u, all_sync_data["s1"].size()); 316 EXPECT_EQ(1u, all_sync_data["s1"].size());
317 EXPECT_PRED_FORMAT2(ValuesEq, &value1, &all_sync_data["s1"][0].value()); 317 EXPECT_PRED_FORMAT2(ValuesEq, &value1, &all_sync_data["s1"][0].value());
318 EXPECT_EQ(1u, all_sync_data["s2"].size()); 318 EXPECT_EQ(1u, all_sync_data["s2"].size());
319 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &all_sync_data["s2"][0].value()); 319 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &all_sync_data["s2"][0].value());
320 320
321 csync::SyncDataList sync_data; 321 syncer::SyncDataList sync_data;
322 sync_data.push_back(settings_sync_util::CreateData( 322 sync_data.push_back(settings_sync_util::CreateData(
323 "s1", "foo", value1, model_type)); 323 "s1", "foo", value1, model_type));
324 sync_data.push_back(settings_sync_util::CreateData( 324 sync_data.push_back(settings_sync_util::CreateData(
325 "s2", "bar", value2, model_type)); 325 "s2", "bar", value2, model_type));
326 326
327 GetSyncableService(model_type)->MergeDataAndStartSyncing( 327 GetSyncableService(model_type)->MergeDataAndStartSyncing(
328 model_type, sync_data, 328 model_type, sync_data,
329 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 329 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
330 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 330 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
331 331
332 // Already in sync, so no changes. 332 // Already in sync, so no changes.
333 EXPECT_EQ(0u, sync_processor_->changes().size()); 333 EXPECT_EQ(0u, sync_processor_->changes().size());
334 334
335 // Regression test: not-changing the synced value shouldn't result in a sync 335 // Regression test: not-changing the synced value shouldn't result in a sync
336 // change, and changing the synced value should result in an update. 336 // change, and changing the synced value should result in an update.
337 storage1->Set(DEFAULTS, "foo", value1); 337 storage1->Set(DEFAULTS, "foo", value1);
338 EXPECT_EQ(0u, sync_processor_->changes().size()); 338 EXPECT_EQ(0u, sync_processor_->changes().size());
339 339
340 storage1->Set(DEFAULTS, "foo", value2); 340 storage1->Set(DEFAULTS, "foo", value2);
341 EXPECT_EQ(1u, sync_processor_->changes().size()); 341 EXPECT_EQ(1u, sync_processor_->changes().size());
342 SettingSyncData change = sync_processor_->GetOnlyChange("s1", "foo"); 342 SettingSyncData change = sync_processor_->GetOnlyChange("s1", "foo");
343 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); 343 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
344 EXPECT_TRUE(value2.Equals(&change.value())); 344 EXPECT_TRUE(value2.Equals(&change.value()));
345 345
346 GetSyncableService(model_type)->StopSyncing(model_type); 346 GetSyncableService(model_type)->StopSyncing(model_type);
347 } 347 }
348 348
349 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) { 349 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) {
350 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 350 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
351 Extension::Type type = Extension::TYPE_EXTENSION; 351 Extension::Type type = Extension::TYPE_EXTENSION;
352 352
353 StringValue value1("fooValue"); 353 StringValue value1("fooValue");
354 ListValue value2; 354 ListValue value2;
355 value2.Append(StringValue::CreateStringValue("barValue")); 355 value2.Append(StringValue::CreateStringValue("barValue"));
356 356
357 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 357 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
358 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 358 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
359 359
360 storage1->Set(DEFAULTS, "foo", value1); 360 storage1->Set(DEFAULTS, "foo", value1);
361 storage2->Set(DEFAULTS, "bar", value2); 361 storage2->Set(DEFAULTS, "bar", value2);
362 362
363 GetSyncableService(model_type)->MergeDataAndStartSyncing( 363 GetSyncableService(model_type)->MergeDataAndStartSyncing(
364 model_type, 364 model_type,
365 csync::SyncDataList(), 365 syncer::SyncDataList(),
366 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 366 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
367 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 367 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
368 368
369 // All settings should have been pushed to sync. 369 // All settings should have been pushed to sync.
370 EXPECT_EQ(2u, sync_processor_->changes().size()); 370 EXPECT_EQ(2u, sync_processor_->changes().size());
371 SettingSyncData change = sync_processor_->GetOnlyChange("s1", "foo"); 371 SettingSyncData change = sync_processor_->GetOnlyChange("s1", "foo");
372 EXPECT_EQ(csync::SyncChange::ACTION_ADD, change.change_type()); 372 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
373 EXPECT_TRUE(value1.Equals(&change.value())); 373 EXPECT_TRUE(value1.Equals(&change.value()));
374 change = sync_processor_->GetOnlyChange("s2", "bar"); 374 change = sync_processor_->GetOnlyChange("s2", "bar");
375 EXPECT_EQ(csync::SyncChange::ACTION_ADD, change.change_type()); 375 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
376 EXPECT_TRUE(value2.Equals(&change.value())); 376 EXPECT_TRUE(value2.Equals(&change.value()));
377 377
378 GetSyncableService(model_type)->StopSyncing(model_type); 378 GetSyncableService(model_type)->StopSyncing(model_type);
379 } 379 }
380 380
381 TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) { 381 TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) {
382 syncable::ModelType model_type = syncable::APP_SETTINGS; 382 syncable::ModelType model_type = syncable::APP_SETTINGS;
383 Extension::Type type = Extension::TYPE_PACKAGED_APP; 383 Extension::Type type = Extension::TYPE_PACKAGED_APP;
384 384
385 StringValue value1("fooValue"); 385 StringValue value1("fooValue");
386 ListValue value2; 386 ListValue value2;
387 value2.Append(StringValue::CreateStringValue("barValue")); 387 value2.Append(StringValue::CreateStringValue("barValue"));
388 388
389 // Maintain dictionaries mirrored to the expected values of the settings in 389 // Maintain dictionaries mirrored to the expected values of the settings in
390 // each storage area. 390 // each storage area.
391 DictionaryValue expected1, expected2; 391 DictionaryValue expected1, expected2;
392 392
393 // Pre-populate one of the storage areas. 393 // Pre-populate one of the storage areas.
394 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 394 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
395 storage1->Set(DEFAULTS, "overwriteMe", value1); 395 storage1->Set(DEFAULTS, "overwriteMe", value1);
396 396
397 csync::SyncDataList sync_data; 397 syncer::SyncDataList sync_data;
398 sync_data.push_back(settings_sync_util::CreateData( 398 sync_data.push_back(settings_sync_util::CreateData(
399 "s1", "foo", value1, model_type)); 399 "s1", "foo", value1, model_type));
400 sync_data.push_back(settings_sync_util::CreateData( 400 sync_data.push_back(settings_sync_util::CreateData(
401 "s2", "bar", value2, model_type)); 401 "s2", "bar", value2, model_type));
402 GetSyncableService(model_type)->MergeDataAndStartSyncing( 402 GetSyncableService(model_type)->MergeDataAndStartSyncing(
403 model_type, sync_data, 403 model_type, sync_data,
404 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 404 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
405 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 405 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
406 expected1.Set("foo", value1.DeepCopy()); 406 expected1.Set("foo", value1.DeepCopy());
407 expected2.Set("bar", value2.DeepCopy()); 407 expected2.Set("bar", value2.DeepCopy());
408 408
409 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 409 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
410 410
411 // All changes should be local, so no sync changes. 411 // All changes should be local, so no sync changes.
412 EXPECT_EQ(0u, sync_processor_->changes().size()); 412 EXPECT_EQ(0u, sync_processor_->changes().size());
413 413
414 // Sync settings should have been pushed to local settings. 414 // Sync settings should have been pushed to local settings.
415 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); 415 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
(...skipping 14 matching lines...) Expand all
430 // each storage area. 430 // each storage area.
431 DictionaryValue expected1, expected2; 431 DictionaryValue expected1, expected2;
432 432
433 // Make storage1 initialised from local data, storage2 initialised from sync. 433 // Make storage1 initialised from local data, storage2 initialised from sync.
434 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 434 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
435 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 435 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
436 436
437 storage1->Set(DEFAULTS, "foo", value1); 437 storage1->Set(DEFAULTS, "foo", value1);
438 expected1.Set("foo", value1.DeepCopy()); 438 expected1.Set("foo", value1.DeepCopy());
439 439
440 csync::SyncDataList sync_data; 440 syncer::SyncDataList sync_data;
441 sync_data.push_back(settings_sync_util::CreateData( 441 sync_data.push_back(settings_sync_util::CreateData(
442 "s2", "bar", value2, model_type)); 442 "s2", "bar", value2, model_type));
443 443
444 GetSyncableService(model_type)->MergeDataAndStartSyncing( 444 GetSyncableService(model_type)->MergeDataAndStartSyncing(
445 model_type, sync_data, 445 model_type, sync_data,
446 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 446 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
447 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 447 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
448 expected2.Set("bar", value2.DeepCopy()); 448 expected2.Set("bar", value2.DeepCopy());
449 449
450 // Make sync add some settings. 450 // Make sync add some settings.
451 csync::SyncChangeList change_list; 451 syncer::SyncChangeList change_list;
452 change_list.push_back(settings_sync_util::CreateAdd( 452 change_list.push_back(settings_sync_util::CreateAdd(
453 "s1", "bar", value2, model_type)); 453 "s1", "bar", value2, model_type));
454 change_list.push_back(settings_sync_util::CreateAdd( 454 change_list.push_back(settings_sync_util::CreateAdd(
455 "s2", "foo", value1, model_type)); 455 "s2", "foo", value1, model_type));
456 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 456 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
457 expected1.Set("bar", value2.DeepCopy()); 457 expected1.Set("bar", value2.DeepCopy());
458 expected2.Set("foo", value1.DeepCopy()); 458 expected2.Set("foo", value1.DeepCopy());
459 459
460 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); 460 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
461 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get()); 461 EXPECT_PRED_FORMAT2(SettingsEq, expected2, storage2->Get());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 // Make storage1/2 initialised from local data, storage3/4 initialised from 502 // Make storage1/2 initialised from local data, storage3/4 initialised from
503 // sync. 503 // sync.
504 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 504 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
505 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 505 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
506 ValueStore* storage3 = AddExtensionAndGetStorage("s3", type); 506 ValueStore* storage3 = AddExtensionAndGetStorage("s3", type);
507 ValueStore* storage4 = AddExtensionAndGetStorage("s4", type); 507 ValueStore* storage4 = AddExtensionAndGetStorage("s4", type);
508 508
509 storage1->Set(DEFAULTS, "foo", value1); 509 storage1->Set(DEFAULTS, "foo", value1);
510 storage2->Set(DEFAULTS, "foo", value1); 510 storage2->Set(DEFAULTS, "foo", value1);
511 511
512 csync::SyncDataList sync_data; 512 syncer::SyncDataList sync_data;
513 sync_data.push_back(settings_sync_util::CreateData( 513 sync_data.push_back(settings_sync_util::CreateData(
514 "s3", "bar", value2, model_type)); 514 "s3", "bar", value2, model_type));
515 sync_data.push_back(settings_sync_util::CreateData( 515 sync_data.push_back(settings_sync_util::CreateData(
516 "s4", "bar", value2, model_type)); 516 "s4", "bar", value2, model_type));
517 517
518 GetSyncableService(model_type)->MergeDataAndStartSyncing( 518 GetSyncableService(model_type)->MergeDataAndStartSyncing(
519 model_type, sync_data, 519 model_type, sync_data,
520 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 520 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
521 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 521 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
522 522
523 // Add something locally. 523 // Add something locally.
524 storage1->Set(DEFAULTS, "bar", value2); 524 storage1->Set(DEFAULTS, "bar", value2);
525 storage2->Set(DEFAULTS, "bar", value2); 525 storage2->Set(DEFAULTS, "bar", value2);
526 storage3->Set(DEFAULTS, "foo", value1); 526 storage3->Set(DEFAULTS, "foo", value1);
527 storage4->Set(DEFAULTS, "foo", value1); 527 storage4->Set(DEFAULTS, "foo", value1);
528 528
529 SettingSyncData change = sync_processor_->GetOnlyChange("s1", "bar"); 529 SettingSyncData change = sync_processor_->GetOnlyChange("s1", "bar");
530 EXPECT_EQ(csync::SyncChange::ACTION_ADD, change.change_type()); 530 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
531 EXPECT_TRUE(value2.Equals(&change.value())); 531 EXPECT_TRUE(value2.Equals(&change.value()));
532 sync_processor_->GetOnlyChange("s2", "bar"); 532 sync_processor_->GetOnlyChange("s2", "bar");
533 EXPECT_EQ(csync::SyncChange::ACTION_ADD, change.change_type()); 533 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
534 EXPECT_TRUE(value2.Equals(&change.value())); 534 EXPECT_TRUE(value2.Equals(&change.value()));
535 change = sync_processor_->GetOnlyChange("s3", "foo"); 535 change = sync_processor_->GetOnlyChange("s3", "foo");
536 EXPECT_EQ(csync::SyncChange::ACTION_ADD, change.change_type()); 536 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
537 EXPECT_TRUE(value1.Equals(&change.value())); 537 EXPECT_TRUE(value1.Equals(&change.value()));
538 change = sync_processor_->GetOnlyChange("s4", "foo"); 538 change = sync_processor_->GetOnlyChange("s4", "foo");
539 EXPECT_EQ(csync::SyncChange::ACTION_ADD, change.change_type()); 539 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change.change_type());
540 EXPECT_TRUE(value1.Equals(&change.value())); 540 EXPECT_TRUE(value1.Equals(&change.value()));
541 541
542 // Change something locally, storage1/3 the new setting and storage2/4 the 542 // Change something locally, storage1/3 the new setting and storage2/4 the
543 // initial setting, for all combinations of local vs sync intialisation and 543 // initial setting, for all combinations of local vs sync intialisation and
544 // new vs initial. 544 // new vs initial.
545 sync_processor_->ClearChanges(); 545 sync_processor_->ClearChanges();
546 storage1->Set(DEFAULTS, "bar", value1); 546 storage1->Set(DEFAULTS, "bar", value1);
547 storage2->Set(DEFAULTS, "foo", value2); 547 storage2->Set(DEFAULTS, "foo", value2);
548 storage3->Set(DEFAULTS, "bar", value1); 548 storage3->Set(DEFAULTS, "bar", value1);
549 storage4->Set(DEFAULTS, "foo", value2); 549 storage4->Set(DEFAULTS, "foo", value2);
550 550
551 change = sync_processor_->GetOnlyChange("s1", "bar"); 551 change = sync_processor_->GetOnlyChange("s1", "bar");
552 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); 552 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
553 EXPECT_TRUE(value1.Equals(&change.value())); 553 EXPECT_TRUE(value1.Equals(&change.value()));
554 change = sync_processor_->GetOnlyChange("s2", "foo"); 554 change = sync_processor_->GetOnlyChange("s2", "foo");
555 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); 555 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
556 EXPECT_TRUE(value2.Equals(&change.value())); 556 EXPECT_TRUE(value2.Equals(&change.value()));
557 change = sync_processor_->GetOnlyChange("s3", "bar"); 557 change = sync_processor_->GetOnlyChange("s3", "bar");
558 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); 558 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
559 EXPECT_TRUE(value1.Equals(&change.value())); 559 EXPECT_TRUE(value1.Equals(&change.value()));
560 change = sync_processor_->GetOnlyChange("s4", "foo"); 560 change = sync_processor_->GetOnlyChange("s4", "foo");
561 EXPECT_EQ(csync::SyncChange::ACTION_UPDATE, change.change_type()); 561 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, change.change_type());
562 EXPECT_TRUE(value2.Equals(&change.value())); 562 EXPECT_TRUE(value2.Equals(&change.value()));
563 563
564 // Remove something locally, storage1/3 the new setting and storage2/4 the 564 // Remove something locally, storage1/3 the new setting and storage2/4 the
565 // initial setting, for all combinations of local vs sync intialisation and 565 // initial setting, for all combinations of local vs sync intialisation and
566 // new vs initial. 566 // new vs initial.
567 sync_processor_->ClearChanges(); 567 sync_processor_->ClearChanges();
568 storage1->Remove("foo"); 568 storage1->Remove("foo");
569 storage2->Remove("bar"); 569 storage2->Remove("bar");
570 storage3->Remove("foo"); 570 storage3->Remove("foo");
571 storage4->Remove("bar"); 571 storage4->Remove("bar");
572 572
573 EXPECT_EQ( 573 EXPECT_EQ(
574 csync::SyncChange::ACTION_DELETE, 574 syncer::SyncChange::ACTION_DELETE,
575 sync_processor_->GetOnlyChange("s1", "foo").change_type()); 575 sync_processor_->GetOnlyChange("s1", "foo").change_type());
576 EXPECT_EQ( 576 EXPECT_EQ(
577 csync::SyncChange::ACTION_DELETE, 577 syncer::SyncChange::ACTION_DELETE,
578 sync_processor_->GetOnlyChange("s2", "bar").change_type()); 578 sync_processor_->GetOnlyChange("s2", "bar").change_type());
579 EXPECT_EQ( 579 EXPECT_EQ(
580 csync::SyncChange::ACTION_DELETE, 580 syncer::SyncChange::ACTION_DELETE,
581 sync_processor_->GetOnlyChange("s3", "foo").change_type()); 581 sync_processor_->GetOnlyChange("s3", "foo").change_type());
582 EXPECT_EQ( 582 EXPECT_EQ(
583 csync::SyncChange::ACTION_DELETE, 583 syncer::SyncChange::ACTION_DELETE,
584 sync_processor_->GetOnlyChange("s4", "bar").change_type()); 584 sync_processor_->GetOnlyChange("s4", "bar").change_type());
585 585
586 // Remove some nonexistent settings. 586 // Remove some nonexistent settings.
587 sync_processor_->ClearChanges(); 587 sync_processor_->ClearChanges();
588 storage1->Remove("foo"); 588 storage1->Remove("foo");
589 storage2->Remove("bar"); 589 storage2->Remove("bar");
590 storage3->Remove("foo"); 590 storage3->Remove("foo");
591 storage4->Remove("bar"); 591 storage4->Remove("bar");
592 592
593 EXPECT_EQ(0u, sync_processor_->changes().size()); 593 EXPECT_EQ(0u, sync_processor_->changes().size());
594 594
595 // Clear the rest of the settings. Add the removed ones back first so that 595 // Clear the rest of the settings. Add the removed ones back first so that
596 // more than one setting is cleared. 596 // more than one setting is cleared.
597 storage1->Set(DEFAULTS, "foo", value1); 597 storage1->Set(DEFAULTS, "foo", value1);
598 storage2->Set(DEFAULTS, "bar", value2); 598 storage2->Set(DEFAULTS, "bar", value2);
599 storage3->Set(DEFAULTS, "foo", value1); 599 storage3->Set(DEFAULTS, "foo", value1);
600 storage4->Set(DEFAULTS, "bar", value2); 600 storage4->Set(DEFAULTS, "bar", value2);
601 601
602 sync_processor_->ClearChanges(); 602 sync_processor_->ClearChanges();
603 storage1->Clear(); 603 storage1->Clear();
604 storage2->Clear(); 604 storage2->Clear();
605 storage3->Clear(); 605 storage3->Clear();
606 storage4->Clear(); 606 storage4->Clear();
607 607
608 EXPECT_EQ( 608 EXPECT_EQ(
609 csync::SyncChange::ACTION_DELETE, 609 syncer::SyncChange::ACTION_DELETE,
610 sync_processor_->GetOnlyChange("s1", "foo").change_type()); 610 sync_processor_->GetOnlyChange("s1", "foo").change_type());
611 EXPECT_EQ( 611 EXPECT_EQ(
612 csync::SyncChange::ACTION_DELETE, 612 syncer::SyncChange::ACTION_DELETE,
613 sync_processor_->GetOnlyChange("s1", "bar").change_type()); 613 sync_processor_->GetOnlyChange("s1", "bar").change_type());
614 EXPECT_EQ( 614 EXPECT_EQ(
615 csync::SyncChange::ACTION_DELETE, 615 syncer::SyncChange::ACTION_DELETE,
616 sync_processor_->GetOnlyChange("s2", "foo").change_type()); 616 sync_processor_->GetOnlyChange("s2", "foo").change_type());
617 EXPECT_EQ( 617 EXPECT_EQ(
618 csync::SyncChange::ACTION_DELETE, 618 syncer::SyncChange::ACTION_DELETE,
619 sync_processor_->GetOnlyChange("s2", "bar").change_type()); 619 sync_processor_->GetOnlyChange("s2", "bar").change_type());
620 EXPECT_EQ( 620 EXPECT_EQ(
621 csync::SyncChange::ACTION_DELETE, 621 syncer::SyncChange::ACTION_DELETE,
622 sync_processor_->GetOnlyChange("s3", "foo").change_type()); 622 sync_processor_->GetOnlyChange("s3", "foo").change_type());
623 EXPECT_EQ( 623 EXPECT_EQ(
624 csync::SyncChange::ACTION_DELETE, 624 syncer::SyncChange::ACTION_DELETE,
625 sync_processor_->GetOnlyChange("s3", "bar").change_type()); 625 sync_processor_->GetOnlyChange("s3", "bar").change_type());
626 EXPECT_EQ( 626 EXPECT_EQ(
627 csync::SyncChange::ACTION_DELETE, 627 syncer::SyncChange::ACTION_DELETE,
628 sync_processor_->GetOnlyChange("s4", "foo").change_type()); 628 sync_processor_->GetOnlyChange("s4", "foo").change_type());
629 EXPECT_EQ( 629 EXPECT_EQ(
630 csync::SyncChange::ACTION_DELETE, 630 syncer::SyncChange::ACTION_DELETE,
631 sync_processor_->GetOnlyChange("s4", "bar").change_type()); 631 sync_processor_->GetOnlyChange("s4", "bar").change_type());
632 632
633 GetSyncableService(model_type)->StopSyncing(model_type); 633 GetSyncableService(model_type)->StopSyncing(model_type);
634 } 634 }
635 635
636 TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) { 636 TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) {
637 StringValue value1("fooValue"); 637 StringValue value1("fooValue");
638 ListValue value2; 638 ListValue value2;
639 value2.Append(StringValue::CreateStringValue("barValue")); 639 value2.Append(StringValue::CreateStringValue("barValue"));
640 640
(...skipping 12 matching lines...) Expand all
653 EXPECT_EQ(1u, extension_sync_data["s1"].size()); 653 EXPECT_EQ(1u, extension_sync_data["s1"].size());
654 EXPECT_PRED_FORMAT2(ValuesEq, &value1, &extension_sync_data["s1"][0].value()); 654 EXPECT_PRED_FORMAT2(ValuesEq, &value1, &extension_sync_data["s1"][0].value());
655 655
656 std::map<std::string, SettingSyncDataList> app_sync_data = 656 std::map<std::string, SettingSyncDataList> app_sync_data =
657 GetAllSyncData(syncable::APP_SETTINGS); 657 GetAllSyncData(syncable::APP_SETTINGS);
658 EXPECT_EQ(1u, app_sync_data.size()); 658 EXPECT_EQ(1u, app_sync_data.size());
659 EXPECT_EQ(1u, app_sync_data["s2"].size()); 659 EXPECT_EQ(1u, app_sync_data["s2"].size());
660 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &app_sync_data["s2"][0].value()); 660 EXPECT_PRED_FORMAT2(ValuesEq, &value2, &app_sync_data["s2"][0].value());
661 661
662 // Stop each separately, there should be no changes either time. 662 // Stop each separately, there should be no changes either time.
663 csync::SyncDataList sync_data; 663 syncer::SyncDataList sync_data;
664 sync_data.push_back(settings_sync_util::CreateData( 664 sync_data.push_back(settings_sync_util::CreateData(
665 "s1", "foo", value1, syncable::EXTENSION_SETTINGS)); 665 "s1", "foo", value1, syncable::EXTENSION_SETTINGS));
666 666
667 GetSyncableService(syncable::EXTENSION_SETTINGS)->MergeDataAndStartSyncing( 667 GetSyncableService(syncable::EXTENSION_SETTINGS)->MergeDataAndStartSyncing(
668 syncable::EXTENSION_SETTINGS, 668 syncable::EXTENSION_SETTINGS,
669 sync_data, 669 sync_data,
670 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 670 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
671 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 671 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
672 GetSyncableService(syncable::EXTENSION_SETTINGS)-> 672 GetSyncableService(syncable::EXTENSION_SETTINGS)->
673 StopSyncing(syncable::EXTENSION_SETTINGS); 673 StopSyncing(syncable::EXTENSION_SETTINGS);
674 EXPECT_EQ(0u, sync_processor_->changes().size()); 674 EXPECT_EQ(0u, sync_processor_->changes().size());
675 675
676 sync_data.clear(); 676 sync_data.clear();
677 sync_data.push_back(settings_sync_util::CreateData( 677 sync_data.push_back(settings_sync_util::CreateData(
678 "s2", "bar", value2, syncable::APP_SETTINGS)); 678 "s2", "bar", value2, syncable::APP_SETTINGS));
679 679
680 scoped_ptr<SyncChangeProcessorDelegate> app_settings_delegate_( 680 scoped_ptr<SyncChangeProcessorDelegate> app_settings_delegate_(
681 new SyncChangeProcessorDelegate(sync_processor_.get())); 681 new SyncChangeProcessorDelegate(sync_processor_.get()));
682 GetSyncableService(syncable::APP_SETTINGS)->MergeDataAndStartSyncing( 682 GetSyncableService(syncable::APP_SETTINGS)->MergeDataAndStartSyncing(
683 syncable::APP_SETTINGS, 683 syncable::APP_SETTINGS,
684 sync_data, 684 sync_data,
685 app_settings_delegate_.PassAs<csync::SyncChangeProcessor>(), 685 app_settings_delegate_.PassAs<syncer::SyncChangeProcessor>(),
686 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 686 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
687 GetSyncableService(syncable::APP_SETTINGS)-> 687 GetSyncableService(syncable::APP_SETTINGS)->
688 StopSyncing(syncable::APP_SETTINGS); 688 StopSyncing(syncable::APP_SETTINGS);
689 EXPECT_EQ(0u, sync_processor_->changes().size()); 689 EXPECT_EQ(0u, sync_processor_->changes().size());
690 } 690 }
691 691
692 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) { 692 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
693 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 693 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 TestingValueStore object then toggle them failing/succeeding 700 // hand out TestingValueStore object then toggle them failing/succeeding
701 // as necessary. 701 // as necessary.
702 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 702 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
703 storage_factory_->Reset(testing_factory); 703 storage_factory_->Reset(testing_factory);
704 704
705 ValueStore* good = AddExtensionAndGetStorage("good", type); 705 ValueStore* good = AddExtensionAndGetStorage("good", type);
706 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 706 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
707 707
708 // Make bad fail for incoming sync changes. 708 // Make bad fail for incoming sync changes.
709 testing_factory->GetExisting("bad")->SetFailAllRequests(true); 709 testing_factory->GetExisting("bad")->SetFailAllRequests(true);
710 { 710 {
711 csync::SyncDataList sync_data; 711 syncer::SyncDataList sync_data;
712 sync_data.push_back(settings_sync_util::CreateData( 712 sync_data.push_back(settings_sync_util::CreateData(
713 "good", "foo", fooValue, model_type)); 713 "good", "foo", fooValue, model_type));
714 sync_data.push_back(settings_sync_util::CreateData( 714 sync_data.push_back(settings_sync_util::CreateData(
715 "bad", "foo", fooValue, model_type)); 715 "bad", "foo", fooValue, model_type));
716 GetSyncableService(model_type)->MergeDataAndStartSyncing( 716 GetSyncableService(model_type)->MergeDataAndStartSyncing(
717 model_type, 717 model_type,
718 sync_data, 718 sync_data,
719 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 719 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
720 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 720 scoped_ptr<syncer::SyncErrorFactory>(
721 new syncer::SyncErrorFactoryMock()));
721 } 722 }
722 testing_factory->GetExisting("bad")->SetFailAllRequests(false); 723 testing_factory->GetExisting("bad")->SetFailAllRequests(false);
723 724
724 { 725 {
725 DictionaryValue dict; 726 DictionaryValue dict;
726 dict.Set("foo", fooValue.DeepCopy()); 727 dict.Set("foo", fooValue.DeepCopy());
727 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 728 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
728 } 729 }
729 { 730 {
730 DictionaryValue dict; 731 DictionaryValue dict;
731 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 732 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
732 } 733 }
733 734
734 // Changes made to good should be sent to sync, changes from bad shouldn't. 735 // Changes made to good should be sent to sync, changes from bad shouldn't.
735 sync_processor_->ClearChanges(); 736 sync_processor_->ClearChanges();
736 good->Set(DEFAULTS, "bar", barValue); 737 good->Set(DEFAULTS, "bar", barValue);
737 bad->Set(DEFAULTS, "bar", barValue); 738 bad->Set(DEFAULTS, "bar", barValue);
738 739
739 EXPECT_EQ( 740 EXPECT_EQ(
740 csync::SyncChange::ACTION_ADD, 741 syncer::SyncChange::ACTION_ADD,
741 sync_processor_->GetOnlyChange("good", "bar").change_type()); 742 sync_processor_->GetOnlyChange("good", "bar").change_type());
742 EXPECT_EQ(1u, sync_processor_->changes().size()); 743 EXPECT_EQ(1u, sync_processor_->changes().size());
743 744
744 { 745 {
745 DictionaryValue dict; 746 DictionaryValue dict;
746 dict.Set("foo", fooValue.DeepCopy()); 747 dict.Set("foo", fooValue.DeepCopy());
747 dict.Set("bar", barValue.DeepCopy()); 748 dict.Set("bar", barValue.DeepCopy());
748 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 749 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
749 } 750 }
750 { 751 {
751 DictionaryValue dict; 752 DictionaryValue dict;
752 dict.Set("bar", barValue.DeepCopy()); 753 dict.Set("bar", barValue.DeepCopy());
753 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 754 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
754 } 755 }
755 756
756 // Changes received from sync should go to good but not bad (even when it's 757 // Changes received from sync should go to good but not bad (even when it's
757 // not failing). 758 // not failing).
758 { 759 {
759 csync::SyncChangeList change_list; 760 syncer::SyncChangeList change_list;
760 change_list.push_back(settings_sync_util::CreateUpdate( 761 change_list.push_back(settings_sync_util::CreateUpdate(
761 "good", "foo", barValue, model_type)); 762 "good", "foo", barValue, model_type));
762 // (Sending UPDATE here even though it's adding, since that's what the state 763 // (Sending UPDATE here even though it's adding, since that's what the state
763 // of sync is. In any case, it won't work.) 764 // of sync is. In any case, it won't work.)
764 change_list.push_back(settings_sync_util::CreateUpdate( 765 change_list.push_back(settings_sync_util::CreateUpdate(
765 "bad", "foo", barValue, model_type)); 766 "bad", "foo", barValue, model_type));
766 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 767 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
767 } 768 }
768 769
769 { 770 {
770 DictionaryValue dict; 771 DictionaryValue dict;
771 dict.Set("foo", barValue.DeepCopy()); 772 dict.Set("foo", barValue.DeepCopy());
772 dict.Set("bar", barValue.DeepCopy()); 773 dict.Set("bar", barValue.DeepCopy());
773 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 774 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
774 } 775 }
775 { 776 {
776 DictionaryValue dict; 777 DictionaryValue dict;
777 dict.Set("bar", barValue.DeepCopy()); 778 dict.Set("bar", barValue.DeepCopy());
778 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 779 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
779 } 780 }
780 781
781 // Changes made to bad still shouldn't go to sync, even though it didn't fail 782 // Changes made to bad still shouldn't go to sync, even though it didn't fail
782 // last time. 783 // last time.
783 sync_processor_->ClearChanges(); 784 sync_processor_->ClearChanges();
784 good->Set(DEFAULTS, "bar", fooValue); 785 good->Set(DEFAULTS, "bar", fooValue);
785 bad->Set(DEFAULTS, "bar", fooValue); 786 bad->Set(DEFAULTS, "bar", fooValue);
786 787
787 EXPECT_EQ( 788 EXPECT_EQ(
788 csync::SyncChange::ACTION_UPDATE, 789 syncer::SyncChange::ACTION_UPDATE,
789 sync_processor_->GetOnlyChange("good", "bar").change_type()); 790 sync_processor_->GetOnlyChange("good", "bar").change_type());
790 EXPECT_EQ(1u, sync_processor_->changes().size()); 791 EXPECT_EQ(1u, sync_processor_->changes().size());
791 792
792 { 793 {
793 DictionaryValue dict; 794 DictionaryValue dict;
794 dict.Set("foo", barValue.DeepCopy()); 795 dict.Set("foo", barValue.DeepCopy());
795 dict.Set("bar", fooValue.DeepCopy()); 796 dict.Set("bar", fooValue.DeepCopy());
796 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 797 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
797 } 798 }
798 { 799 {
799 DictionaryValue dict; 800 DictionaryValue dict;
800 dict.Set("bar", fooValue.DeepCopy()); 801 dict.Set("bar", fooValue.DeepCopy());
801 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 802 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
802 } 803 }
803 804
804 // Failing ProcessSyncChanges shouldn't go to the storage. 805 // Failing ProcessSyncChanges shouldn't go to the storage.
805 testing_factory->GetExisting("bad")->SetFailAllRequests(true); 806 testing_factory->GetExisting("bad")->SetFailAllRequests(true);
806 { 807 {
807 csync::SyncChangeList change_list; 808 syncer::SyncChangeList change_list;
808 change_list.push_back(settings_sync_util::CreateUpdate( 809 change_list.push_back(settings_sync_util::CreateUpdate(
809 "good", "foo", fooValue, model_type)); 810 "good", "foo", fooValue, model_type));
810 // (Ditto.) 811 // (Ditto.)
811 change_list.push_back(settings_sync_util::CreateUpdate( 812 change_list.push_back(settings_sync_util::CreateUpdate(
812 "bad", "foo", fooValue, model_type)); 813 "bad", "foo", fooValue, model_type));
813 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 814 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
814 } 815 }
815 testing_factory->GetExisting("bad")->SetFailAllRequests(false); 816 testing_factory->GetExisting("bad")->SetFailAllRequests(false);
816 817
817 { 818 {
818 DictionaryValue dict; 819 DictionaryValue dict;
819 dict.Set("foo", fooValue.DeepCopy()); 820 dict.Set("foo", fooValue.DeepCopy());
820 dict.Set("bar", fooValue.DeepCopy()); 821 dict.Set("bar", fooValue.DeepCopy());
821 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 822 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
822 } 823 }
823 { 824 {
824 DictionaryValue dict; 825 DictionaryValue dict;
825 dict.Set("bar", fooValue.DeepCopy()); 826 dict.Set("bar", fooValue.DeepCopy());
826 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 827 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
827 } 828 }
828 829
829 // Restarting sync should make bad start syncing again. 830 // Restarting sync should make bad start syncing again.
830 sync_processor_->ClearChanges(); 831 sync_processor_->ClearChanges();
831 GetSyncableService(model_type)->StopSyncing(model_type); 832 GetSyncableService(model_type)->StopSyncing(model_type);
832 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( 833 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
833 sync_processor_.get())); 834 sync_processor_.get()));
834 GetSyncableService(model_type)->MergeDataAndStartSyncing( 835 GetSyncableService(model_type)->MergeDataAndStartSyncing(
835 model_type, 836 model_type,
836 csync::SyncDataList(), 837 syncer::SyncDataList(),
837 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 838 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
838 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 839 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
839 840
840 // Local settings will have been pushed to sync, since it's empty (in this 841 // Local settings will have been pushed to sync, since it's empty (in this
841 // test; presumably it wouldn't be live, since we've been getting changes). 842 // test; presumably it wouldn't be live, since we've been getting changes).
842 EXPECT_EQ( 843 EXPECT_EQ(
843 csync::SyncChange::ACTION_ADD, 844 syncer::SyncChange::ACTION_ADD,
844 sync_processor_->GetOnlyChange("good", "foo").change_type()); 845 sync_processor_->GetOnlyChange("good", "foo").change_type());
845 EXPECT_EQ( 846 EXPECT_EQ(
846 csync::SyncChange::ACTION_ADD, 847 syncer::SyncChange::ACTION_ADD,
847 sync_processor_->GetOnlyChange("good", "bar").change_type()); 848 sync_processor_->GetOnlyChange("good", "bar").change_type());
848 EXPECT_EQ( 849 EXPECT_EQ(
849 csync::SyncChange::ACTION_ADD, 850 syncer::SyncChange::ACTION_ADD,
850 sync_processor_->GetOnlyChange("bad", "bar").change_type()); 851 sync_processor_->GetOnlyChange("bad", "bar").change_type());
851 EXPECT_EQ(3u, sync_processor_->changes().size()); 852 EXPECT_EQ(3u, sync_processor_->changes().size());
852 853
853 // Live local changes now get pushed, too. 854 // Live local changes now get pushed, too.
854 sync_processor_->ClearChanges(); 855 sync_processor_->ClearChanges();
855 good->Set(DEFAULTS, "bar", barValue); 856 good->Set(DEFAULTS, "bar", barValue);
856 bad->Set(DEFAULTS, "bar", barValue); 857 bad->Set(DEFAULTS, "bar", barValue);
857 858
858 EXPECT_EQ( 859 EXPECT_EQ(
859 csync::SyncChange::ACTION_UPDATE, 860 syncer::SyncChange::ACTION_UPDATE,
860 sync_processor_->GetOnlyChange("good", "bar").change_type()); 861 sync_processor_->GetOnlyChange("good", "bar").change_type());
861 EXPECT_EQ( 862 EXPECT_EQ(
862 csync::SyncChange::ACTION_UPDATE, 863 syncer::SyncChange::ACTION_UPDATE,
863 sync_processor_->GetOnlyChange("bad", "bar").change_type()); 864 sync_processor_->GetOnlyChange("bad", "bar").change_type());
864 EXPECT_EQ(2u, sync_processor_->changes().size()); 865 EXPECT_EQ(2u, sync_processor_->changes().size());
865 866
866 // And ProcessSyncChanges work, too. 867 // And ProcessSyncChanges work, too.
867 { 868 {
868 csync::SyncChangeList change_list; 869 syncer::SyncChangeList change_list;
869 change_list.push_back(settings_sync_util::CreateUpdate( 870 change_list.push_back(settings_sync_util::CreateUpdate(
870 "good", "bar", fooValue, model_type)); 871 "good", "bar", fooValue, model_type));
871 change_list.push_back(settings_sync_util::CreateUpdate( 872 change_list.push_back(settings_sync_util::CreateUpdate(
872 "bad", "bar", fooValue, model_type)); 873 "bad", "bar", fooValue, model_type));
873 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 874 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
874 } 875 }
875 876
876 { 877 {
877 DictionaryValue dict; 878 DictionaryValue dict;
878 dict.Set("foo", fooValue.DeepCopy()); 879 dict.Set("foo", fooValue.DeepCopy());
(...skipping 17 matching lines...) Expand all
896 StringValue barValue("barValue"); 897 StringValue barValue("barValue");
897 898
898 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 899 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
899 storage_factory_->Reset(testing_factory); 900 storage_factory_->Reset(testing_factory);
900 901
901 ValueStore* good = AddExtensionAndGetStorage("good", type); 902 ValueStore* good = AddExtensionAndGetStorage("good", type);
902 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 903 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
903 904
904 // Unlike before, initially succeeding MergeDataAndStartSyncing. 905 // Unlike before, initially succeeding MergeDataAndStartSyncing.
905 { 906 {
906 csync::SyncDataList sync_data; 907 syncer::SyncDataList sync_data;
907 sync_data.push_back(settings_sync_util::CreateData( 908 sync_data.push_back(settings_sync_util::CreateData(
908 "good", "foo", fooValue, model_type)); 909 "good", "foo", fooValue, model_type));
909 sync_data.push_back(settings_sync_util::CreateData( 910 sync_data.push_back(settings_sync_util::CreateData(
910 "bad", "foo", fooValue, model_type)); 911 "bad", "foo", fooValue, model_type));
911 GetSyncableService(model_type)->MergeDataAndStartSyncing( 912 GetSyncableService(model_type)->MergeDataAndStartSyncing(
912 model_type, 913 model_type,
913 sync_data, 914 sync_data,
914 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 915 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
915 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 916 scoped_ptr<syncer::SyncErrorFactory>(
917 new syncer::SyncErrorFactoryMock()));
916 } 918 }
917 919
918 EXPECT_EQ(0u, sync_processor_->changes().size()); 920 EXPECT_EQ(0u, sync_processor_->changes().size());
919 921
920 { 922 {
921 DictionaryValue dict; 923 DictionaryValue dict;
922 dict.Set("foo", fooValue.DeepCopy()); 924 dict.Set("foo", fooValue.DeepCopy());
923 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 925 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
924 } 926 }
925 { 927 {
926 DictionaryValue dict; 928 DictionaryValue dict;
927 dict.Set("foo", fooValue.DeepCopy()); 929 dict.Set("foo", fooValue.DeepCopy());
928 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 930 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
929 } 931 }
930 932
931 // Now fail ProcessSyncChanges for bad. 933 // Now fail ProcessSyncChanges for bad.
932 testing_factory->GetExisting("bad")->SetFailAllRequests(true); 934 testing_factory->GetExisting("bad")->SetFailAllRequests(true);
933 { 935 {
934 csync::SyncChangeList change_list; 936 syncer::SyncChangeList change_list;
935 change_list.push_back(settings_sync_util::CreateAdd( 937 change_list.push_back(settings_sync_util::CreateAdd(
936 "good", "bar", barValue, model_type)); 938 "good", "bar", barValue, model_type));
937 change_list.push_back(settings_sync_util::CreateAdd( 939 change_list.push_back(settings_sync_util::CreateAdd(
938 "bad", "bar", barValue, model_type)); 940 "bad", "bar", barValue, model_type));
939 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 941 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
940 } 942 }
941 testing_factory->GetExisting("bad")->SetFailAllRequests(false); 943 testing_factory->GetExisting("bad")->SetFailAllRequests(false);
942 944
943 { 945 {
944 DictionaryValue dict; 946 DictionaryValue dict;
945 dict.Set("foo", fooValue.DeepCopy()); 947 dict.Set("foo", fooValue.DeepCopy());
946 dict.Set("bar", barValue.DeepCopy()); 948 dict.Set("bar", barValue.DeepCopy());
947 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 949 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
948 } 950 }
949 { 951 {
950 DictionaryValue dict; 952 DictionaryValue dict;
951 dict.Set("foo", fooValue.DeepCopy()); 953 dict.Set("foo", fooValue.DeepCopy());
952 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 954 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
953 } 955 }
954 956
955 // No more changes sent to sync for bad. 957 // No more changes sent to sync for bad.
956 sync_processor_->ClearChanges(); 958 sync_processor_->ClearChanges();
957 good->Set(DEFAULTS, "foo", barValue); 959 good->Set(DEFAULTS, "foo", barValue);
958 bad->Set(DEFAULTS, "foo", barValue); 960 bad->Set(DEFAULTS, "foo", barValue);
959 961
960 EXPECT_EQ( 962 EXPECT_EQ(
961 csync::SyncChange::ACTION_UPDATE, 963 syncer::SyncChange::ACTION_UPDATE,
962 sync_processor_->GetOnlyChange("good", "foo").change_type()); 964 sync_processor_->GetOnlyChange("good", "foo").change_type());
963 EXPECT_EQ(1u, sync_processor_->changes().size()); 965 EXPECT_EQ(1u, sync_processor_->changes().size());
964 966
965 // No more changes received from sync should go to bad. 967 // No more changes received from sync should go to bad.
966 { 968 {
967 csync::SyncChangeList change_list; 969 syncer::SyncChangeList change_list;
968 change_list.push_back(settings_sync_util::CreateAdd( 970 change_list.push_back(settings_sync_util::CreateAdd(
969 "good", "foo", fooValue, model_type)); 971 "good", "foo", fooValue, model_type));
970 change_list.push_back(settings_sync_util::CreateAdd( 972 change_list.push_back(settings_sync_util::CreateAdd(
971 "bad", "foo", fooValue, model_type)); 973 "bad", "foo", fooValue, model_type));
972 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 974 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
973 } 975 }
974 976
975 { 977 {
976 DictionaryValue dict; 978 DictionaryValue dict;
977 dict.Set("foo", fooValue.DeepCopy()); 979 dict.Set("foo", fooValue.DeepCopy());
(...skipping 20 matching lines...) Expand all
998 ValueStore* good = AddExtensionAndGetStorage("good", type); 1000 ValueStore* good = AddExtensionAndGetStorage("good", type);
999 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1001 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1000 1002
1001 good->Set(DEFAULTS, "foo", fooValue); 1003 good->Set(DEFAULTS, "foo", fooValue);
1002 bad->Set(DEFAULTS, "foo", fooValue); 1004 bad->Set(DEFAULTS, "foo", fooValue);
1003 1005
1004 // Even though bad will fail to get all sync data, sync data should still 1006 // Even though bad will fail to get all sync data, sync data should still
1005 // include that from good. 1007 // include that from good.
1006 testing_factory->GetExisting("bad")->SetFailAllRequests(true); 1008 testing_factory->GetExisting("bad")->SetFailAllRequests(true);
1007 { 1009 {
1008 csync::SyncDataList all_sync_data = 1010 syncer::SyncDataList all_sync_data =
1009 GetSyncableService(model_type)->GetAllSyncData(model_type); 1011 GetSyncableService(model_type)->GetAllSyncData(model_type);
1010 EXPECT_EQ(1u, all_sync_data.size()); 1012 EXPECT_EQ(1u, all_sync_data.size());
1011 EXPECT_EQ("good/foo", all_sync_data[0].GetTag()); 1013 EXPECT_EQ("good/foo", all_sync_data[0].GetTag());
1012 } 1014 }
1013 testing_factory->GetExisting("bad")->SetFailAllRequests(false); 1015 testing_factory->GetExisting("bad")->SetFailAllRequests(false);
1014 1016
1015 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant). 1017 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant).
1016 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1018 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1017 model_type, 1019 model_type,
1018 csync::SyncDataList(), 1020 syncer::SyncDataList(),
1019 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 1021 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1020 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 1022 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
1021 1023
1022 EXPECT_EQ( 1024 EXPECT_EQ(
1023 csync::SyncChange::ACTION_ADD, 1025 syncer::SyncChange::ACTION_ADD,
1024 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1026 sync_processor_->GetOnlyChange("good", "foo").change_type());
1025 EXPECT_EQ( 1027 EXPECT_EQ(
1026 csync::SyncChange::ACTION_ADD, 1028 syncer::SyncChange::ACTION_ADD,
1027 sync_processor_->GetOnlyChange("bad", "foo").change_type()); 1029 sync_processor_->GetOnlyChange("bad", "foo").change_type());
1028 EXPECT_EQ(2u, sync_processor_->changes().size()); 1030 EXPECT_EQ(2u, sync_processor_->changes().size());
1029 1031
1030 sync_processor_->ClearChanges(); 1032 sync_processor_->ClearChanges();
1031 good->Set(DEFAULTS, "bar", barValue); 1033 good->Set(DEFAULTS, "bar", barValue);
1032 bad->Set(DEFAULTS, "bar", barValue); 1034 bad->Set(DEFAULTS, "bar", barValue);
1033 1035
1034 EXPECT_EQ( 1036 EXPECT_EQ(
1035 csync::SyncChange::ACTION_ADD, 1037 syncer::SyncChange::ACTION_ADD,
1036 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1038 sync_processor_->GetOnlyChange("good", "bar").change_type());
1037 EXPECT_EQ( 1039 EXPECT_EQ(
1038 csync::SyncChange::ACTION_ADD, 1040 syncer::SyncChange::ACTION_ADD,
1039 sync_processor_->GetOnlyChange("bad", "bar").change_type()); 1041 sync_processor_->GetOnlyChange("bad", "bar").change_type());
1040 EXPECT_EQ(2u, sync_processor_->changes().size()); 1042 EXPECT_EQ(2u, sync_processor_->changes().size());
1041 } 1043 }
1042 1044
1043 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { 1045 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) {
1044 syncable::ModelType model_type = syncable::APP_SETTINGS; 1046 syncable::ModelType model_type = syncable::APP_SETTINGS;
1045 Extension::Type type = Extension::TYPE_PACKAGED_APP; 1047 Extension::Type type = Extension::TYPE_PACKAGED_APP;
1046 1048
1047 StringValue fooValue("fooValue"); 1049 StringValue fooValue("fooValue");
1048 StringValue barValue("barValue"); 1050 StringValue barValue("barValue");
1049 1051
1050 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 1052 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1051 storage_factory_->Reset(testing_factory); 1053 storage_factory_->Reset(testing_factory);
1052 1054
1053 ValueStore* good = AddExtensionAndGetStorage("good", type); 1055 ValueStore* good = AddExtensionAndGetStorage("good", type);
1054 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1056 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1055 1057
1056 good->Set(DEFAULTS, "foo", fooValue); 1058 good->Set(DEFAULTS, "foo", fooValue);
1057 bad->Set(DEFAULTS, "foo", fooValue); 1059 bad->Set(DEFAULTS, "foo", fooValue);
1058 1060
1059 // good will successfully push foo:fooValue to sync, but bad will fail to 1061 // good will successfully push foo:fooValue to sync, but bad will fail to
1060 // get them so won't. 1062 // get them so won't.
1061 testing_factory->GetExisting("bad")->SetFailAllRequests(true); 1063 testing_factory->GetExisting("bad")->SetFailAllRequests(true);
1062 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1064 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1063 model_type, 1065 model_type,
1064 csync::SyncDataList(), 1066 syncer::SyncDataList(),
1065 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 1067 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1066 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 1068 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
1067 testing_factory->GetExisting("bad")->SetFailAllRequests(false); 1069 testing_factory->GetExisting("bad")->SetFailAllRequests(false);
1068 1070
1069 EXPECT_EQ( 1071 EXPECT_EQ(
1070 csync::SyncChange::ACTION_ADD, 1072 syncer::SyncChange::ACTION_ADD,
1071 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1073 sync_processor_->GetOnlyChange("good", "foo").change_type());
1072 EXPECT_EQ(1u, sync_processor_->changes().size()); 1074 EXPECT_EQ(1u, sync_processor_->changes().size());
1073 1075
1074 // bad should now be disabled for sync. 1076 // bad should now be disabled for sync.
1075 sync_processor_->ClearChanges(); 1077 sync_processor_->ClearChanges();
1076 good->Set(DEFAULTS, "bar", barValue); 1078 good->Set(DEFAULTS, "bar", barValue);
1077 bad->Set(DEFAULTS, "bar", barValue); 1079 bad->Set(DEFAULTS, "bar", barValue);
1078 1080
1079 EXPECT_EQ( 1081 EXPECT_EQ(
1080 csync::SyncChange::ACTION_ADD, 1082 syncer::SyncChange::ACTION_ADD,
1081 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1083 sync_processor_->GetOnlyChange("good", "bar").change_type());
1082 EXPECT_EQ(1u, sync_processor_->changes().size()); 1084 EXPECT_EQ(1u, sync_processor_->changes().size());
1083 1085
1084 { 1086 {
1085 csync::SyncChangeList change_list; 1087 syncer::SyncChangeList change_list;
1086 change_list.push_back(settings_sync_util::CreateUpdate( 1088 change_list.push_back(settings_sync_util::CreateUpdate(
1087 "good", "foo", barValue, model_type)); 1089 "good", "foo", barValue, model_type));
1088 // (Sending ADD here even though it's updating, since that's what the state 1090 // (Sending ADD here even though it's updating, since that's what the state
1089 // of sync is. In any case, it won't work.) 1091 // of sync is. In any case, it won't work.)
1090 change_list.push_back(settings_sync_util::CreateAdd( 1092 change_list.push_back(settings_sync_util::CreateAdd(
1091 "bad", "foo", barValue, model_type)); 1093 "bad", "foo", barValue, model_type));
1092 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 1094 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1093 } 1095 }
1094 1096
1095 { 1097 {
(...skipping 10 matching lines...) Expand all
1106 } 1108 }
1107 1109
1108 // Re-enabling sync without failing should cause the local changes from bad 1110 // Re-enabling sync without failing should cause the local changes from bad
1109 // to be pushed to sync successfully, as should future changes to bad. 1111 // to be pushed to sync successfully, as should future changes to bad.
1110 sync_processor_->ClearChanges(); 1112 sync_processor_->ClearChanges();
1111 GetSyncableService(model_type)->StopSyncing(model_type); 1113 GetSyncableService(model_type)->StopSyncing(model_type);
1112 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( 1114 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
1113 sync_processor_.get())); 1115 sync_processor_.get()));
1114 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1116 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1115 model_type, 1117 model_type,
1116 csync::SyncDataList(), 1118 syncer::SyncDataList(),
1117 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 1119 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1118 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 1120 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
1119 1121
1120 EXPECT_EQ( 1122 EXPECT_EQ(
1121 csync::SyncChange::ACTION_ADD, 1123 syncer::SyncChange::ACTION_ADD,
1122 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1124 sync_processor_->GetOnlyChange("good", "foo").change_type());
1123 EXPECT_EQ( 1125 EXPECT_EQ(
1124 csync::SyncChange::ACTION_ADD, 1126 syncer::SyncChange::ACTION_ADD,
1125 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1127 sync_processor_->GetOnlyChange("good", "bar").change_type());
1126 EXPECT_EQ( 1128 EXPECT_EQ(
1127 csync::SyncChange::ACTION_ADD, 1129 syncer::SyncChange::ACTION_ADD,
1128 sync_processor_->GetOnlyChange("bad", "foo").change_type()); 1130 sync_processor_->GetOnlyChange("bad", "foo").change_type());
1129 EXPECT_EQ( 1131 EXPECT_EQ(
1130 csync::SyncChange::ACTION_ADD, 1132 syncer::SyncChange::ACTION_ADD,
1131 sync_processor_->GetOnlyChange("bad", "bar").change_type()); 1133 sync_processor_->GetOnlyChange("bad", "bar").change_type());
1132 EXPECT_EQ(4u, sync_processor_->changes().size()); 1134 EXPECT_EQ(4u, sync_processor_->changes().size());
1133 1135
1134 sync_processor_->ClearChanges(); 1136 sync_processor_->ClearChanges();
1135 good->Set(DEFAULTS, "bar", fooValue); 1137 good->Set(DEFAULTS, "bar", fooValue);
1136 bad->Set(DEFAULTS, "bar", fooValue); 1138 bad->Set(DEFAULTS, "bar", fooValue);
1137 1139
1138 EXPECT_EQ( 1140 EXPECT_EQ(
1139 csync::SyncChange::ACTION_UPDATE, 1141 syncer::SyncChange::ACTION_UPDATE,
1140 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1142 sync_processor_->GetOnlyChange("good", "bar").change_type());
1141 EXPECT_EQ( 1143 EXPECT_EQ(
1142 csync::SyncChange::ACTION_UPDATE, 1144 syncer::SyncChange::ACTION_UPDATE,
1143 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1145 sync_processor_->GetOnlyChange("good", "bar").change_type());
1144 EXPECT_EQ(2u, sync_processor_->changes().size()); 1146 EXPECT_EQ(2u, sync_processor_->changes().size());
1145 } 1147 }
1146 1148
1147 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { 1149 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) {
1148 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 1150 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
1149 Extension::Type type = Extension::TYPE_EXTENSION; 1151 Extension::Type type = Extension::TYPE_EXTENSION;
1150 1152
1151 StringValue fooValue("fooValue"); 1153 StringValue fooValue("fooValue");
1152 StringValue barValue("barValue"); 1154 StringValue barValue("barValue");
1153 1155
1154 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 1156 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1155 storage_factory_->Reset(testing_factory); 1157 storage_factory_->Reset(testing_factory);
1156 1158
1157 ValueStore* good = AddExtensionAndGetStorage("good", type); 1159 ValueStore* good = AddExtensionAndGetStorage("good", type);
1158 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1160 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1159 1161
1160 // Only set bad; setting good will cause it to fail below. 1162 // Only set bad; setting good will cause it to fail below.
1161 bad->Set(DEFAULTS, "foo", fooValue); 1163 bad->Set(DEFAULTS, "foo", fooValue);
1162 1164
1163 sync_processor_->SetFailAllRequests(true); 1165 sync_processor_->SetFailAllRequests(true);
1164 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1166 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1165 model_type, 1167 model_type,
1166 csync::SyncDataList(), 1168 syncer::SyncDataList(),
1167 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 1169 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1168 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 1170 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
1169 sync_processor_->SetFailAllRequests(false); 1171 sync_processor_->SetFailAllRequests(false);
1170 1172
1171 // Changes from good will be send to sync, changes from bad won't. 1173 // Changes from good will be send to sync, changes from bad won't.
1172 sync_processor_->ClearChanges(); 1174 sync_processor_->ClearChanges();
1173 good->Set(DEFAULTS, "foo", barValue); 1175 good->Set(DEFAULTS, "foo", barValue);
1174 bad->Set(DEFAULTS, "foo", barValue); 1176 bad->Set(DEFAULTS, "foo", barValue);
1175 1177
1176 EXPECT_EQ( 1178 EXPECT_EQ(
1177 csync::SyncChange::ACTION_ADD, 1179 syncer::SyncChange::ACTION_ADD,
1178 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1180 sync_processor_->GetOnlyChange("good", "foo").change_type());
1179 EXPECT_EQ(1u, sync_processor_->changes().size()); 1181 EXPECT_EQ(1u, sync_processor_->changes().size());
1180 1182
1181 // Changes from sync will be sent to good, not to bad. 1183 // Changes from sync will be sent to good, not to bad.
1182 { 1184 {
1183 csync::SyncChangeList change_list; 1185 syncer::SyncChangeList change_list;
1184 change_list.push_back(settings_sync_util::CreateAdd( 1186 change_list.push_back(settings_sync_util::CreateAdd(
1185 "good", "bar", barValue, model_type)); 1187 "good", "bar", barValue, model_type));
1186 change_list.push_back(settings_sync_util::CreateAdd( 1188 change_list.push_back(settings_sync_util::CreateAdd(
1187 "bad", "bar", barValue, model_type)); 1189 "bad", "bar", barValue, model_type));
1188 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 1190 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1189 } 1191 }
1190 1192
1191 { 1193 {
1192 DictionaryValue dict; 1194 DictionaryValue dict;
1193 dict.Set("foo", barValue.DeepCopy()); 1195 dict.Set("foo", barValue.DeepCopy());
1194 dict.Set("bar", barValue.DeepCopy()); 1196 dict.Set("bar", barValue.DeepCopy());
1195 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 1197 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
1196 } 1198 }
1197 { 1199 {
1198 DictionaryValue dict; 1200 DictionaryValue dict;
1199 dict.Set("foo", barValue.DeepCopy()); 1201 dict.Set("foo", barValue.DeepCopy());
1200 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 1202 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
1201 } 1203 }
1202 1204
1203 // Restarting sync makes everything work again. 1205 // Restarting sync makes everything work again.
1204 sync_processor_->ClearChanges(); 1206 sync_processor_->ClearChanges();
1205 GetSyncableService(model_type)->StopSyncing(model_type); 1207 GetSyncableService(model_type)->StopSyncing(model_type);
1206 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( 1208 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
1207 sync_processor_.get())); 1209 sync_processor_.get()));
1208 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1210 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1209 model_type, 1211 model_type,
1210 csync::SyncDataList(), 1212 syncer::SyncDataList(),
1211 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 1213 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1212 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 1214 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
1213 1215
1214 EXPECT_EQ( 1216 EXPECT_EQ(
1215 csync::SyncChange::ACTION_ADD, 1217 syncer::SyncChange::ACTION_ADD,
1216 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1218 sync_processor_->GetOnlyChange("good", "foo").change_type());
1217 EXPECT_EQ( 1219 EXPECT_EQ(
1218 csync::SyncChange::ACTION_ADD, 1220 syncer::SyncChange::ACTION_ADD,
1219 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1221 sync_processor_->GetOnlyChange("good", "bar").change_type());
1220 EXPECT_EQ( 1222 EXPECT_EQ(
1221 csync::SyncChange::ACTION_ADD, 1223 syncer::SyncChange::ACTION_ADD,
1222 sync_processor_->GetOnlyChange("bad", "foo").change_type()); 1224 sync_processor_->GetOnlyChange("bad", "foo").change_type());
1223 EXPECT_EQ(3u, sync_processor_->changes().size()); 1225 EXPECT_EQ(3u, sync_processor_->changes().size());
1224 1226
1225 sync_processor_->ClearChanges(); 1227 sync_processor_->ClearChanges();
1226 good->Set(DEFAULTS, "foo", fooValue); 1228 good->Set(DEFAULTS, "foo", fooValue);
1227 bad->Set(DEFAULTS, "foo", fooValue); 1229 bad->Set(DEFAULTS, "foo", fooValue);
1228 1230
1229 EXPECT_EQ( 1231 EXPECT_EQ(
1230 csync::SyncChange::ACTION_UPDATE, 1232 syncer::SyncChange::ACTION_UPDATE,
1231 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1233 sync_processor_->GetOnlyChange("good", "foo").change_type());
1232 EXPECT_EQ( 1234 EXPECT_EQ(
1233 csync::SyncChange::ACTION_UPDATE, 1235 syncer::SyncChange::ACTION_UPDATE,
1234 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1236 sync_processor_->GetOnlyChange("good", "foo").change_type());
1235 EXPECT_EQ(2u, sync_processor_->changes().size()); 1237 EXPECT_EQ(2u, sync_processor_->changes().size());
1236 } 1238 }
1237 1239
1238 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { 1240 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) {
1239 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 1241 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
1240 Extension::Type type = Extension::TYPE_EXTENSION; 1242 Extension::Type type = Extension::TYPE_EXTENSION;
1241 1243
1242 StringValue fooValue("fooValue"); 1244 StringValue fooValue("fooValue");
1243 StringValue barValue("barValue"); 1245 StringValue barValue("barValue");
1244 1246
1245 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); 1247 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory();
1246 storage_factory_->Reset(testing_factory); 1248 storage_factory_->Reset(testing_factory);
1247 1249
1248 ValueStore* good = AddExtensionAndGetStorage("good", type); 1250 ValueStore* good = AddExtensionAndGetStorage("good", type);
1249 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1251 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1250 1252
1251 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1253 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1252 model_type, 1254 model_type,
1253 csync::SyncDataList(), 1255 syncer::SyncDataList(),
1254 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 1256 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1255 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 1257 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
1256 1258
1257 // bad will fail to send changes. 1259 // bad will fail to send changes.
1258 good->Set(DEFAULTS, "foo", fooValue); 1260 good->Set(DEFAULTS, "foo", fooValue);
1259 sync_processor_->SetFailAllRequests(true); 1261 sync_processor_->SetFailAllRequests(true);
1260 bad->Set(DEFAULTS, "foo", fooValue); 1262 bad->Set(DEFAULTS, "foo", fooValue);
1261 sync_processor_->SetFailAllRequests(false); 1263 sync_processor_->SetFailAllRequests(false);
1262 1264
1263 EXPECT_EQ( 1265 EXPECT_EQ(
1264 csync::SyncChange::ACTION_ADD, 1266 syncer::SyncChange::ACTION_ADD,
1265 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1267 sync_processor_->GetOnlyChange("good", "foo").change_type());
1266 EXPECT_EQ(1u, sync_processor_->changes().size()); 1268 EXPECT_EQ(1u, sync_processor_->changes().size());
1267 1269
1268 // No further changes should be sent from bad. 1270 // No further changes should be sent from bad.
1269 sync_processor_->ClearChanges(); 1271 sync_processor_->ClearChanges();
1270 good->Set(DEFAULTS, "foo", barValue); 1272 good->Set(DEFAULTS, "foo", barValue);
1271 bad->Set(DEFAULTS, "foo", barValue); 1273 bad->Set(DEFAULTS, "foo", barValue);
1272 1274
1273 EXPECT_EQ( 1275 EXPECT_EQ(
1274 csync::SyncChange::ACTION_UPDATE, 1276 syncer::SyncChange::ACTION_UPDATE,
1275 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1277 sync_processor_->GetOnlyChange("good", "foo").change_type());
1276 EXPECT_EQ(1u, sync_processor_->changes().size()); 1278 EXPECT_EQ(1u, sync_processor_->changes().size());
1277 1279
1278 // Changes from sync will be sent to good, not to bad. 1280 // Changes from sync will be sent to good, not to bad.
1279 { 1281 {
1280 csync::SyncChangeList change_list; 1282 syncer::SyncChangeList change_list;
1281 change_list.push_back(settings_sync_util::CreateAdd( 1283 change_list.push_back(settings_sync_util::CreateAdd(
1282 "good", "bar", barValue, model_type)); 1284 "good", "bar", barValue, model_type));
1283 change_list.push_back(settings_sync_util::CreateAdd( 1285 change_list.push_back(settings_sync_util::CreateAdd(
1284 "bad", "bar", barValue, model_type)); 1286 "bad", "bar", barValue, model_type));
1285 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 1287 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1286 } 1288 }
1287 1289
1288 { 1290 {
1289 DictionaryValue dict; 1291 DictionaryValue dict;
1290 dict.Set("foo", barValue.DeepCopy()); 1292 dict.Set("foo", barValue.DeepCopy());
1291 dict.Set("bar", barValue.DeepCopy()); 1293 dict.Set("bar", barValue.DeepCopy());
1292 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 1294 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
1293 } 1295 }
1294 { 1296 {
1295 DictionaryValue dict; 1297 DictionaryValue dict;
1296 dict.Set("foo", barValue.DeepCopy()); 1298 dict.Set("foo", barValue.DeepCopy());
1297 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 1299 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
1298 } 1300 }
1299 1301
1300 // Restarting sync makes everything work again. 1302 // Restarting sync makes everything work again.
1301 sync_processor_->ClearChanges(); 1303 sync_processor_->ClearChanges();
1302 GetSyncableService(model_type)->StopSyncing(model_type); 1304 GetSyncableService(model_type)->StopSyncing(model_type);
1303 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( 1305 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate(
1304 sync_processor_.get())); 1306 sync_processor_.get()));
1305 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1307 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1306 model_type, 1308 model_type,
1307 csync::SyncDataList(), 1309 syncer::SyncDataList(),
1308 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 1310 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1309 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 1311 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
1310 1312
1311 EXPECT_EQ( 1313 EXPECT_EQ(
1312 csync::SyncChange::ACTION_ADD, 1314 syncer::SyncChange::ACTION_ADD,
1313 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1315 sync_processor_->GetOnlyChange("good", "foo").change_type());
1314 EXPECT_EQ( 1316 EXPECT_EQ(
1315 csync::SyncChange::ACTION_ADD, 1317 syncer::SyncChange::ACTION_ADD,
1316 sync_processor_->GetOnlyChange("good", "bar").change_type()); 1318 sync_processor_->GetOnlyChange("good", "bar").change_type());
1317 EXPECT_EQ( 1319 EXPECT_EQ(
1318 csync::SyncChange::ACTION_ADD, 1320 syncer::SyncChange::ACTION_ADD,
1319 sync_processor_->GetOnlyChange("bad", "foo").change_type()); 1321 sync_processor_->GetOnlyChange("bad", "foo").change_type());
1320 EXPECT_EQ(3u, sync_processor_->changes().size()); 1322 EXPECT_EQ(3u, sync_processor_->changes().size());
1321 1323
1322 sync_processor_->ClearChanges(); 1324 sync_processor_->ClearChanges();
1323 good->Set(DEFAULTS, "foo", fooValue); 1325 good->Set(DEFAULTS, "foo", fooValue);
1324 bad->Set(DEFAULTS, "foo", fooValue); 1326 bad->Set(DEFAULTS, "foo", fooValue);
1325 1327
1326 EXPECT_EQ( 1328 EXPECT_EQ(
1327 csync::SyncChange::ACTION_UPDATE, 1329 syncer::SyncChange::ACTION_UPDATE,
1328 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1330 sync_processor_->GetOnlyChange("good", "foo").change_type());
1329 EXPECT_EQ( 1331 EXPECT_EQ(
1330 csync::SyncChange::ACTION_UPDATE, 1332 syncer::SyncChange::ACTION_UPDATE,
1331 sync_processor_->GetOnlyChange("good", "foo").change_type()); 1333 sync_processor_->GetOnlyChange("good", "foo").change_type());
1332 EXPECT_EQ(2u, sync_processor_->changes().size()); 1334 EXPECT_EQ(2u, sync_processor_->changes().size());
1333 } 1335 }
1334 1336
1335 TEST_F(ExtensionSettingsSyncTest, 1337 TEST_F(ExtensionSettingsSyncTest,
1336 LargeOutgoingChangeRejectedButIncomingAccepted) { 1338 LargeOutgoingChangeRejectedButIncomingAccepted) {
1337 syncable::ModelType model_type = syncable::APP_SETTINGS; 1339 syncable::ModelType model_type = syncable::APP_SETTINGS;
1338 Extension::Type type = Extension::TYPE_PACKAGED_APP; 1340 Extension::Type type = Extension::TYPE_PACKAGED_APP;
1339 1341
1340 // This value should be larger than the limit in settings_backend.cc. 1342 // This value should be larger than the limit in settings_backend.cc.
1341 std::string string_5k; 1343 std::string string_5k;
1342 for (size_t i = 0; i < 5000; ++i) { 1344 for (size_t i = 0; i < 5000; ++i) {
1343 string_5k.append("a"); 1345 string_5k.append("a");
1344 } 1346 }
1345 StringValue large_value(string_5k); 1347 StringValue large_value(string_5k);
1346 1348
1347 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1349 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1348 model_type, 1350 model_type,
1349 csync::SyncDataList(), 1351 syncer::SyncDataList(),
1350 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), 1352 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1351 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 1353 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
1352 1354
1353 // Large local change rejected and doesn't get sent out. 1355 // Large local change rejected and doesn't get sent out.
1354 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 1356 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
1355 EXPECT_TRUE(storage1->Set(DEFAULTS, "large_value", large_value)->HasError()); 1357 EXPECT_TRUE(storage1->Set(DEFAULTS, "large_value", large_value)->HasError());
1356 EXPECT_EQ(0u, sync_processor_->changes().size()); 1358 EXPECT_EQ(0u, sync_processor_->changes().size());
1357 1359
1358 // Large incoming change should still get accepted. 1360 // Large incoming change should still get accepted.
1359 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 1361 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
1360 { 1362 {
1361 csync::SyncChangeList change_list; 1363 syncer::SyncChangeList change_list;
1362 change_list.push_back(settings_sync_util::CreateAdd( 1364 change_list.push_back(settings_sync_util::CreateAdd(
1363 "s1", "large_value", large_value, model_type)); 1365 "s1", "large_value", large_value, model_type));
1364 change_list.push_back(settings_sync_util::CreateAdd( 1366 change_list.push_back(settings_sync_util::CreateAdd(
1365 "s2", "large_value", large_value, model_type)); 1367 "s2", "large_value", large_value, model_type));
1366 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 1368 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1367 } 1369 }
1368 { 1370 {
1369 DictionaryValue expected; 1371 DictionaryValue expected;
1370 expected.Set("large_value", large_value.DeepCopy()); 1372 expected.Set("large_value", large_value.DeepCopy());
1371 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get()); 1373 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get());
1372 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get()); 1374 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get());
1373 } 1375 }
1374 1376
1375 GetSyncableService(model_type)->StopSyncing(model_type); 1377 GetSyncableService(model_type)->StopSyncing(model_type);
1376 } 1378 }
1377 1379
1378 } // namespace extensions 1380 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/settings/settings_sync_processor.cc ('k') | chrome/browser/extensions/settings/settings_sync_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698