Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 ValueStore::ReadResult actual) { | 74 ValueStore::ReadResult actual) { |
| 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(). |
|
asargent_no_longer_on_chrome
2012/06/26 18:08:17
nit: double space
akalin
2012/06/26 20:28:28
Done.
| |
| 85 class MockSyncChangeProcessor : public SyncChangeProcessor { | 85 class MockSyncChangeProcessor : public csync::SyncChangeProcessor { |
| 86 public: | 86 public: |
| 87 MockSyncChangeProcessor() : fail_all_requests_(false) {} | 87 MockSyncChangeProcessor() : fail_all_requests_(false) {} |
| 88 | 88 |
| 89 // SyncChangeProcessor implementation. | 89 // csync::SyncChangeProcessor implementation. |
| 90 virtual SyncError ProcessSyncChanges( | 90 virtual csync::SyncError ProcessSyncChanges( |
| 91 const tracked_objects::Location& from_here, | 91 const tracked_objects::Location& from_here, |
| 92 const SyncChangeList& change_list) OVERRIDE { | 92 const csync::SyncChangeList& change_list) OVERRIDE { |
| 93 if (fail_all_requests_) { | 93 if (fail_all_requests_) { |
| 94 return SyncError( | 94 return csync::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 (SyncChangeList::const_iterator it = change_list.begin(); | 99 for (csync::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 SyncError(); | 103 return csync::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( |
|
asargent_no_longer_on_chrome
2012/06/26 18:08:17
nit: double space
akalin
2012/06/26 20:28:28
Done.
| |
| 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 SyncChange::ACTION_INVALID, "", "", | 133 csync::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 SyncChangeProcessor { | 148 class SyncChangeProcessorDelegate : public csync::SyncChangeProcessor { |
| 149 public: | 149 public: |
| 150 explicit SyncChangeProcessorDelegate(SyncChangeProcessor* recipient) | 150 explicit SyncChangeProcessorDelegate(csync::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 // SyncChangeProcessor implementation. | 156 // csync::SyncChangeProcessor implementation. |
| 157 virtual SyncError ProcessSyncChanges( | 157 virtual csync::SyncError ProcessSyncChanges( |
| 158 const tracked_objects::Location& from_here, | 158 const tracked_objects::Location& from_here, |
| 159 const SyncChangeList& change_list) OVERRIDE { | 159 const csync::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 SyncChangeProcessor* recipient_; | 165 csync::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 Loading... | |
| 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(SyncableService** dst, | 197 void AssignSettingsService(csync::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 Loading... | |
| 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 SyncableService for the given sync type. | 237 // Gets the csync::SyncableService for the given sync type. |
| 238 SyncableService* GetSyncableService(syncable::ModelType model_type) { | 238 csync::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 SyncDataList as_list = | 247 csync::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 (SyncDataList::iterator it = as_list.begin(); | 250 for (csync::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); |
|
asargent_no_longer_on_chrome
2012/06/26 18:08:17
nit: double space
akalin
2012/06/26 20:28:28
Done.
| |
| 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_; |
| 261 content::TestBrowserThread file_thread_; | 261 content::TestBrowserThread file_thread_; |
| 262 | 262 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 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 SyncDataList(), | 286 csync::SyncDataList(), |
| 287 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 287 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 288 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 288 scoped_ptr<csync::SyncErrorFactory>(new csync::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 Loading... | |
| 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 SyncDataList sync_data; | 321 csync::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<SyncChangeProcessor>(), | 329 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 330 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 330 scoped_ptr<csync::SyncErrorFactory>(new csync::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(SyncChange::ACTION_UPDATE, change.change_type()); | 343 EXPECT_EQ(csync::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 SyncDataList(), | 365 csync::SyncDataList(), |
| 366 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 366 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 367 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 367 scoped_ptr<csync::SyncErrorFactory>(new csync::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"); |
|
asargent_no_longer_on_chrome
2012/06/26 18:08:17
nit: double space
akalin
2012/06/26 20:28:28
Done.
| |
| 372 EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type()); | 372 EXPECT_EQ(csync::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(SyncChange::ACTION_ADD, change.change_type()); | 375 EXPECT_EQ(csync::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 SyncDataList sync_data; | 397 csync::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<SyncChangeProcessor>(), | 404 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 405 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 405 scoped_ptr<csync::SyncErrorFactory>(new csync::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 Loading... | |
| 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 SyncDataList sync_data; | 440 csync::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<SyncChangeProcessor>(), | 446 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 447 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 447 scoped_ptr<csync::SyncErrorFactory>(new csync::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 SyncChangeList change_list; | 451 csync::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 Loading... | |
| 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 SyncDataList sync_data; | 512 csync::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<SyncChangeProcessor>(), | 520 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 521 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 521 scoped_ptr<csync::SyncErrorFactory>(new csync::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"); |
|
asargent_no_longer_on_chrome
2012/06/26 18:08:17
nit: double space
akalin
2012/06/26 20:28:28
Done.
| |
| 530 EXPECT_EQ(SyncChange::ACTION_ADD, change.change_type()); | 530 EXPECT_EQ(csync::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(SyncChange::ACTION_ADD, change.change_type()); | 533 EXPECT_EQ(csync::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(SyncChange::ACTION_ADD, change.change_type()); | 536 EXPECT_EQ(csync::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(SyncChange::ACTION_ADD, change.change_type()); | 539 EXPECT_EQ(csync::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(SyncChange::ACTION_UPDATE, change.change_type()); | 552 EXPECT_EQ(csync::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(SyncChange::ACTION_UPDATE, change.change_type()); | 555 EXPECT_EQ(csync::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(SyncChange::ACTION_UPDATE, change.change_type()); | 558 EXPECT_EQ(csync::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(SyncChange::ACTION_UPDATE, change.change_type()); | 561 EXPECT_EQ(csync::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 SyncChange::ACTION_DELETE, | 574 csync::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 SyncChange::ACTION_DELETE, | 577 csync::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 SyncChange::ACTION_DELETE, | 580 csync::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 SyncChange::ACTION_DELETE, | 583 csync::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 SyncChange::ACTION_DELETE, | 609 csync::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 SyncChange::ACTION_DELETE, | 612 csync::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 SyncChange::ACTION_DELETE, | 615 csync::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 SyncChange::ACTION_DELETE, | 618 csync::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 SyncChange::ACTION_DELETE, | 621 csync::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 SyncChange::ACTION_DELETE, | 624 csync::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 SyncChange::ACTION_DELETE, | 627 csync::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 SyncChange::ACTION_DELETE, | 630 csync::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 Loading... | |
| 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 SyncDataList sync_data; | 663 csync::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<SyncChangeProcessor>(), | 670 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 671 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 671 scoped_ptr<csync::SyncErrorFactory>(new csync::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<SyncChangeProcessor>(), | 685 app_settings_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 686 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 686 scoped_ptr<csync::SyncErrorFactory>(new csync::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 SyncDataList sync_data; | 711 csync::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<SyncChangeProcessor>(), | 719 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 720 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 720 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 721 } | 721 } |
| 722 testing_factory->GetExisting("bad")->SetFailAllRequests(false); | 722 testing_factory->GetExisting("bad")->SetFailAllRequests(false); |
| 723 | 723 |
| 724 { | 724 { |
| 725 DictionaryValue dict; | 725 DictionaryValue dict; |
| 726 dict.Set("foo", fooValue.DeepCopy()); | 726 dict.Set("foo", fooValue.DeepCopy()); |
| 727 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 727 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 728 } | 728 } |
| 729 { | 729 { |
| 730 DictionaryValue dict; | 730 DictionaryValue dict; |
| 731 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 731 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 732 } | 732 } |
| 733 | 733 |
| 734 // Changes made to good should be sent to sync, changes from bad shouldn't. | 734 // Changes made to good should be sent to sync, changes from bad shouldn't. |
| 735 sync_processor_->ClearChanges(); | 735 sync_processor_->ClearChanges(); |
| 736 good->Set(DEFAULTS, "bar", barValue); | 736 good->Set(DEFAULTS, "bar", barValue); |
| 737 bad->Set(DEFAULTS, "bar", barValue); | 737 bad->Set(DEFAULTS, "bar", barValue); |
| 738 | 738 |
| 739 EXPECT_EQ( | 739 EXPECT_EQ( |
| 740 SyncChange::ACTION_ADD, | 740 csync::SyncChange::ACTION_ADD, |
| 741 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 741 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 742 EXPECT_EQ(1u, sync_processor_->changes().size()); | 742 EXPECT_EQ(1u, sync_processor_->changes().size()); |
| 743 | 743 |
| 744 { | 744 { |
| 745 DictionaryValue dict; | 745 DictionaryValue dict; |
| 746 dict.Set("foo", fooValue.DeepCopy()); | 746 dict.Set("foo", fooValue.DeepCopy()); |
| 747 dict.Set("bar", barValue.DeepCopy()); | 747 dict.Set("bar", barValue.DeepCopy()); |
| 748 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 748 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 749 } | 749 } |
| 750 { | 750 { |
| 751 DictionaryValue dict; | 751 DictionaryValue dict; |
| 752 dict.Set("bar", barValue.DeepCopy()); | 752 dict.Set("bar", barValue.DeepCopy()); |
| 753 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 753 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 754 } | 754 } |
| 755 | 755 |
| 756 // Changes received from sync should go to good but not bad (even when it's | 756 // Changes received from sync should go to good but not bad (even when it's |
| 757 // not failing). | 757 // not failing). |
| 758 { | 758 { |
| 759 SyncChangeList change_list; | 759 csync::SyncChangeList change_list; |
| 760 change_list.push_back(settings_sync_util::CreateUpdate( | 760 change_list.push_back(settings_sync_util::CreateUpdate( |
| 761 "good", "foo", barValue, model_type)); | 761 "good", "foo", barValue, model_type)); |
| 762 // (Sending UPDATE here even though it's adding, since that's what the state | 762 // (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.) | 763 // of sync is. In any case, it won't work.) |
| 764 change_list.push_back(settings_sync_util::CreateUpdate( | 764 change_list.push_back(settings_sync_util::CreateUpdate( |
| 765 "bad", "foo", barValue, model_type)); | 765 "bad", "foo", barValue, model_type)); |
| 766 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 766 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 767 } | 767 } |
| 768 | 768 |
| 769 { | 769 { |
| 770 DictionaryValue dict; | 770 DictionaryValue dict; |
| 771 dict.Set("foo", barValue.DeepCopy()); | 771 dict.Set("foo", barValue.DeepCopy()); |
| 772 dict.Set("bar", barValue.DeepCopy()); | 772 dict.Set("bar", barValue.DeepCopy()); |
| 773 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 773 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 774 } | 774 } |
| 775 { | 775 { |
| 776 DictionaryValue dict; | 776 DictionaryValue dict; |
| 777 dict.Set("bar", barValue.DeepCopy()); | 777 dict.Set("bar", barValue.DeepCopy()); |
| 778 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 778 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 779 } | 779 } |
| 780 | 780 |
| 781 // Changes made to bad still shouldn't go to sync, even though it didn't fail | 781 // Changes made to bad still shouldn't go to sync, even though it didn't fail |
| 782 // last time. | 782 // last time. |
| 783 sync_processor_->ClearChanges(); | 783 sync_processor_->ClearChanges(); |
| 784 good->Set(DEFAULTS, "bar", fooValue); | 784 good->Set(DEFAULTS, "bar", fooValue); |
| 785 bad->Set(DEFAULTS, "bar", fooValue); | 785 bad->Set(DEFAULTS, "bar", fooValue); |
| 786 | 786 |
| 787 EXPECT_EQ( | 787 EXPECT_EQ( |
| 788 SyncChange::ACTION_UPDATE, | 788 csync::SyncChange::ACTION_UPDATE, |
| 789 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 789 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 790 EXPECT_EQ(1u, sync_processor_->changes().size()); | 790 EXPECT_EQ(1u, sync_processor_->changes().size()); |
| 791 | 791 |
| 792 { | 792 { |
| 793 DictionaryValue dict; | 793 DictionaryValue dict; |
| 794 dict.Set("foo", barValue.DeepCopy()); | 794 dict.Set("foo", barValue.DeepCopy()); |
| 795 dict.Set("bar", fooValue.DeepCopy()); | 795 dict.Set("bar", fooValue.DeepCopy()); |
| 796 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 796 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 797 } | 797 } |
| 798 { | 798 { |
| 799 DictionaryValue dict; | 799 DictionaryValue dict; |
| 800 dict.Set("bar", fooValue.DeepCopy()); | 800 dict.Set("bar", fooValue.DeepCopy()); |
| 801 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 801 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 802 } | 802 } |
| 803 | 803 |
| 804 // Failing ProcessSyncChanges shouldn't go to the storage. | 804 // Failing ProcessSyncChanges shouldn't go to the storage. |
| 805 testing_factory->GetExisting("bad")->SetFailAllRequests(true); | 805 testing_factory->GetExisting("bad")->SetFailAllRequests(true); |
| 806 { | 806 { |
| 807 SyncChangeList change_list; | 807 csync::SyncChangeList change_list; |
| 808 change_list.push_back(settings_sync_util::CreateUpdate( | 808 change_list.push_back(settings_sync_util::CreateUpdate( |
| 809 "good", "foo", fooValue, model_type)); | 809 "good", "foo", fooValue, model_type)); |
| 810 // (Ditto.) | 810 // (Ditto.) |
| 811 change_list.push_back(settings_sync_util::CreateUpdate( | 811 change_list.push_back(settings_sync_util::CreateUpdate( |
| 812 "bad", "foo", fooValue, model_type)); | 812 "bad", "foo", fooValue, model_type)); |
| 813 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 813 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 814 } | 814 } |
| 815 testing_factory->GetExisting("bad")->SetFailAllRequests(false); | 815 testing_factory->GetExisting("bad")->SetFailAllRequests(false); |
| 816 | 816 |
| 817 { | 817 { |
| 818 DictionaryValue dict; | 818 DictionaryValue dict; |
| 819 dict.Set("foo", fooValue.DeepCopy()); | 819 dict.Set("foo", fooValue.DeepCopy()); |
| 820 dict.Set("bar", fooValue.DeepCopy()); | 820 dict.Set("bar", fooValue.DeepCopy()); |
| 821 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 821 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 822 } | 822 } |
| 823 { | 823 { |
| 824 DictionaryValue dict; | 824 DictionaryValue dict; |
| 825 dict.Set("bar", fooValue.DeepCopy()); | 825 dict.Set("bar", fooValue.DeepCopy()); |
| 826 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 826 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 827 } | 827 } |
| 828 | 828 |
| 829 // Restarting sync should make bad start syncing again. | 829 // Restarting sync should make bad start syncing again. |
| 830 sync_processor_->ClearChanges(); | 830 sync_processor_->ClearChanges(); |
| 831 GetSyncableService(model_type)->StopSyncing(model_type); | 831 GetSyncableService(model_type)->StopSyncing(model_type); |
| 832 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( | 832 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( |
| 833 sync_processor_.get())); | 833 sync_processor_.get())); |
| 834 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 834 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 835 model_type, | 835 model_type, |
| 836 SyncDataList(), | 836 csync::SyncDataList(), |
| 837 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 837 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 838 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 838 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 839 | 839 |
| 840 // Local settings will have been pushed to sync, since it's empty (in this | 840 // 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). | 841 // test; presumably it wouldn't be live, since we've been getting changes). |
| 842 EXPECT_EQ( | 842 EXPECT_EQ( |
| 843 SyncChange::ACTION_ADD, | 843 csync::SyncChange::ACTION_ADD, |
| 844 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 844 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 845 EXPECT_EQ( | 845 EXPECT_EQ( |
| 846 SyncChange::ACTION_ADD, | 846 csync::SyncChange::ACTION_ADD, |
| 847 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 847 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 848 EXPECT_EQ( | 848 EXPECT_EQ( |
| 849 SyncChange::ACTION_ADD, | 849 csync::SyncChange::ACTION_ADD, |
| 850 sync_processor_->GetOnlyChange("bad", "bar").change_type()); | 850 sync_processor_->GetOnlyChange("bad", "bar").change_type()); |
| 851 EXPECT_EQ(3u, sync_processor_->changes().size()); | 851 EXPECT_EQ(3u, sync_processor_->changes().size()); |
| 852 | 852 |
| 853 // Live local changes now get pushed, too. | 853 // Live local changes now get pushed, too. |
| 854 sync_processor_->ClearChanges(); | 854 sync_processor_->ClearChanges(); |
| 855 good->Set(DEFAULTS, "bar", barValue); | 855 good->Set(DEFAULTS, "bar", barValue); |
| 856 bad->Set(DEFAULTS, "bar", barValue); | 856 bad->Set(DEFAULTS, "bar", barValue); |
| 857 | 857 |
| 858 EXPECT_EQ( | 858 EXPECT_EQ( |
| 859 SyncChange::ACTION_UPDATE, | 859 csync::SyncChange::ACTION_UPDATE, |
| 860 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 860 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 861 EXPECT_EQ( | 861 EXPECT_EQ( |
| 862 SyncChange::ACTION_UPDATE, | 862 csync::SyncChange::ACTION_UPDATE, |
| 863 sync_processor_->GetOnlyChange("bad", "bar").change_type()); | 863 sync_processor_->GetOnlyChange("bad", "bar").change_type()); |
| 864 EXPECT_EQ(2u, sync_processor_->changes().size()); | 864 EXPECT_EQ(2u, sync_processor_->changes().size()); |
| 865 | 865 |
| 866 // And ProcessSyncChanges work, too. | 866 // And ProcessSyncChanges work, too. |
| 867 { | 867 { |
| 868 SyncChangeList change_list; | 868 csync::SyncChangeList change_list; |
| 869 change_list.push_back(settings_sync_util::CreateUpdate( | 869 change_list.push_back(settings_sync_util::CreateUpdate( |
| 870 "good", "bar", fooValue, model_type)); | 870 "good", "bar", fooValue, model_type)); |
| 871 change_list.push_back(settings_sync_util::CreateUpdate( | 871 change_list.push_back(settings_sync_util::CreateUpdate( |
| 872 "bad", "bar", fooValue, model_type)); | 872 "bad", "bar", fooValue, model_type)); |
| 873 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 873 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 874 } | 874 } |
| 875 | 875 |
| 876 { | 876 { |
| 877 DictionaryValue dict; | 877 DictionaryValue dict; |
| 878 dict.Set("foo", fooValue.DeepCopy()); | 878 dict.Set("foo", fooValue.DeepCopy()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 896 StringValue barValue("barValue"); | 896 StringValue barValue("barValue"); |
| 897 | 897 |
| 898 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); | 898 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); |
| 899 storage_factory_->Reset(testing_factory); | 899 storage_factory_->Reset(testing_factory); |
| 900 | 900 |
| 901 ValueStore* good = AddExtensionAndGetStorage("good", type); | 901 ValueStore* good = AddExtensionAndGetStorage("good", type); |
| 902 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 902 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
| 903 | 903 |
| 904 // Unlike before, initially succeeding MergeDataAndStartSyncing. | 904 // Unlike before, initially succeeding MergeDataAndStartSyncing. |
| 905 { | 905 { |
| 906 SyncDataList sync_data; | 906 csync::SyncDataList sync_data; |
| 907 sync_data.push_back(settings_sync_util::CreateData( | 907 sync_data.push_back(settings_sync_util::CreateData( |
| 908 "good", "foo", fooValue, model_type)); | 908 "good", "foo", fooValue, model_type)); |
| 909 sync_data.push_back(settings_sync_util::CreateData( | 909 sync_data.push_back(settings_sync_util::CreateData( |
| 910 "bad", "foo", fooValue, model_type)); | 910 "bad", "foo", fooValue, model_type)); |
| 911 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 911 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 912 model_type, | 912 model_type, |
| 913 sync_data, | 913 sync_data, |
| 914 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 914 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 915 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 915 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 916 } | 916 } |
| 917 | 917 |
| 918 EXPECT_EQ(0u, sync_processor_->changes().size()); | 918 EXPECT_EQ(0u, sync_processor_->changes().size()); |
| 919 | 919 |
| 920 { | 920 { |
| 921 DictionaryValue dict; | 921 DictionaryValue dict; |
| 922 dict.Set("foo", fooValue.DeepCopy()); | 922 dict.Set("foo", fooValue.DeepCopy()); |
| 923 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 923 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 924 } | 924 } |
| 925 { | 925 { |
| 926 DictionaryValue dict; | 926 DictionaryValue dict; |
| 927 dict.Set("foo", fooValue.DeepCopy()); | 927 dict.Set("foo", fooValue.DeepCopy()); |
| 928 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 928 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 929 } | 929 } |
| 930 | 930 |
| 931 // Now fail ProcessSyncChanges for bad. | 931 // Now fail ProcessSyncChanges for bad. |
| 932 testing_factory->GetExisting("bad")->SetFailAllRequests(true); | 932 testing_factory->GetExisting("bad")->SetFailAllRequests(true); |
| 933 { | 933 { |
| 934 SyncChangeList change_list; | 934 csync::SyncChangeList change_list; |
| 935 change_list.push_back(settings_sync_util::CreateAdd( | 935 change_list.push_back(settings_sync_util::CreateAdd( |
| 936 "good", "bar", barValue, model_type)); | 936 "good", "bar", barValue, model_type)); |
| 937 change_list.push_back(settings_sync_util::CreateAdd( | 937 change_list.push_back(settings_sync_util::CreateAdd( |
| 938 "bad", "bar", barValue, model_type)); | 938 "bad", "bar", barValue, model_type)); |
| 939 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 939 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 940 } | 940 } |
| 941 testing_factory->GetExisting("bad")->SetFailAllRequests(false); | 941 testing_factory->GetExisting("bad")->SetFailAllRequests(false); |
| 942 | 942 |
| 943 { | 943 { |
| 944 DictionaryValue dict; | 944 DictionaryValue dict; |
| 945 dict.Set("foo", fooValue.DeepCopy()); | 945 dict.Set("foo", fooValue.DeepCopy()); |
| 946 dict.Set("bar", barValue.DeepCopy()); | 946 dict.Set("bar", barValue.DeepCopy()); |
| 947 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 947 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 948 } | 948 } |
| 949 { | 949 { |
| 950 DictionaryValue dict; | 950 DictionaryValue dict; |
| 951 dict.Set("foo", fooValue.DeepCopy()); | 951 dict.Set("foo", fooValue.DeepCopy()); |
| 952 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 952 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 953 } | 953 } |
| 954 | 954 |
| 955 // No more changes sent to sync for bad. | 955 // No more changes sent to sync for bad. |
| 956 sync_processor_->ClearChanges(); | 956 sync_processor_->ClearChanges(); |
| 957 good->Set(DEFAULTS, "foo", barValue); | 957 good->Set(DEFAULTS, "foo", barValue); |
| 958 bad->Set(DEFAULTS, "foo", barValue); | 958 bad->Set(DEFAULTS, "foo", barValue); |
| 959 | 959 |
| 960 EXPECT_EQ( | 960 EXPECT_EQ( |
| 961 SyncChange::ACTION_UPDATE, | 961 csync::SyncChange::ACTION_UPDATE, |
| 962 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 962 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 963 EXPECT_EQ(1u, sync_processor_->changes().size()); | 963 EXPECT_EQ(1u, sync_processor_->changes().size()); |
| 964 | 964 |
| 965 // No more changes received from sync should go to bad. | 965 // No more changes received from sync should go to bad. |
| 966 { | 966 { |
| 967 SyncChangeList change_list; | 967 csync::SyncChangeList change_list; |
| 968 change_list.push_back(settings_sync_util::CreateAdd( | 968 change_list.push_back(settings_sync_util::CreateAdd( |
| 969 "good", "foo", fooValue, model_type)); | 969 "good", "foo", fooValue, model_type)); |
| 970 change_list.push_back(settings_sync_util::CreateAdd( | 970 change_list.push_back(settings_sync_util::CreateAdd( |
| 971 "bad", "foo", fooValue, model_type)); | 971 "bad", "foo", fooValue, model_type)); |
| 972 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 972 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 973 } | 973 } |
| 974 | 974 |
| 975 { | 975 { |
| 976 DictionaryValue dict; | 976 DictionaryValue dict; |
| 977 dict.Set("foo", fooValue.DeepCopy()); | 977 dict.Set("foo", fooValue.DeepCopy()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 998 ValueStore* good = AddExtensionAndGetStorage("good", type); | 998 ValueStore* good = AddExtensionAndGetStorage("good", type); |
| 999 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 999 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
| 1000 | 1000 |
| 1001 good->Set(DEFAULTS, "foo", fooValue); | 1001 good->Set(DEFAULTS, "foo", fooValue); |
| 1002 bad->Set(DEFAULTS, "foo", fooValue); | 1002 bad->Set(DEFAULTS, "foo", fooValue); |
| 1003 | 1003 |
| 1004 // 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 |
| 1005 // include that from good. | 1005 // include that from good. |
| 1006 testing_factory->GetExisting("bad")->SetFailAllRequests(true); | 1006 testing_factory->GetExisting("bad")->SetFailAllRequests(true); |
| 1007 { | 1007 { |
| 1008 SyncDataList all_sync_data = | 1008 csync::SyncDataList all_sync_data = |
| 1009 GetSyncableService(model_type)->GetAllSyncData(model_type); | 1009 GetSyncableService(model_type)->GetAllSyncData(model_type); |
| 1010 EXPECT_EQ(1u, all_sync_data.size()); | 1010 EXPECT_EQ(1u, all_sync_data.size()); |
| 1011 EXPECT_EQ("good/foo", all_sync_data[0].GetTag()); | 1011 EXPECT_EQ("good/foo", all_sync_data[0].GetTag()); |
| 1012 } | 1012 } |
| 1013 testing_factory->GetExisting("bad")->SetFailAllRequests(false); | 1013 testing_factory->GetExisting("bad")->SetFailAllRequests(false); |
| 1014 | 1014 |
| 1015 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant). | 1015 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant). |
| 1016 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 1016 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 1017 model_type, | 1017 model_type, |
| 1018 SyncDataList(), | 1018 csync::SyncDataList(), |
| 1019 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 1019 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 1020 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 1020 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 1021 | 1021 |
| 1022 EXPECT_EQ( | 1022 EXPECT_EQ( |
| 1023 SyncChange::ACTION_ADD, | 1023 csync::SyncChange::ACTION_ADD, |
| 1024 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1024 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1025 EXPECT_EQ( | 1025 EXPECT_EQ( |
| 1026 SyncChange::ACTION_ADD, | 1026 csync::SyncChange::ACTION_ADD, |
| 1027 sync_processor_->GetOnlyChange("bad", "foo").change_type()); | 1027 sync_processor_->GetOnlyChange("bad", "foo").change_type()); |
| 1028 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1028 EXPECT_EQ(2u, sync_processor_->changes().size()); |
| 1029 | 1029 |
| 1030 sync_processor_->ClearChanges(); | 1030 sync_processor_->ClearChanges(); |
| 1031 good->Set(DEFAULTS, "bar", barValue); | 1031 good->Set(DEFAULTS, "bar", barValue); |
| 1032 bad->Set(DEFAULTS, "bar", barValue); | 1032 bad->Set(DEFAULTS, "bar", barValue); |
| 1033 | 1033 |
| 1034 EXPECT_EQ( | 1034 EXPECT_EQ( |
| 1035 SyncChange::ACTION_ADD, | 1035 csync::SyncChange::ACTION_ADD, |
| 1036 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 1036 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 1037 EXPECT_EQ( | 1037 EXPECT_EQ( |
| 1038 SyncChange::ACTION_ADD, | 1038 csync::SyncChange::ACTION_ADD, |
| 1039 sync_processor_->GetOnlyChange("bad", "bar").change_type()); | 1039 sync_processor_->GetOnlyChange("bad", "bar").change_type()); |
| 1040 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1040 EXPECT_EQ(2u, sync_processor_->changes().size()); |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { | 1043 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { |
| 1044 syncable::ModelType model_type = syncable::APP_SETTINGS; | 1044 syncable::ModelType model_type = syncable::APP_SETTINGS; |
| 1045 Extension::Type type = Extension::TYPE_PACKAGED_APP; | 1045 Extension::Type type = Extension::TYPE_PACKAGED_APP; |
| 1046 | 1046 |
| 1047 StringValue fooValue("fooValue"); | 1047 StringValue fooValue("fooValue"); |
| 1048 StringValue barValue("barValue"); | 1048 StringValue barValue("barValue"); |
| 1049 | 1049 |
| 1050 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); | 1050 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); |
| 1051 storage_factory_->Reset(testing_factory); | 1051 storage_factory_->Reset(testing_factory); |
| 1052 | 1052 |
| 1053 ValueStore* good = AddExtensionAndGetStorage("good", type); | 1053 ValueStore* good = AddExtensionAndGetStorage("good", type); |
| 1054 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 1054 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
| 1055 | 1055 |
| 1056 good->Set(DEFAULTS, "foo", fooValue); | 1056 good->Set(DEFAULTS, "foo", fooValue); |
| 1057 bad->Set(DEFAULTS, "foo", fooValue); | 1057 bad->Set(DEFAULTS, "foo", fooValue); |
| 1058 | 1058 |
| 1059 // 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 |
| 1060 // get them so won't. | 1060 // get them so won't. |
| 1061 testing_factory->GetExisting("bad")->SetFailAllRequests(true); | 1061 testing_factory->GetExisting("bad")->SetFailAllRequests(true); |
| 1062 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 1062 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 1063 model_type, | 1063 model_type, |
| 1064 SyncDataList(), | 1064 csync::SyncDataList(), |
| 1065 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 1065 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 1066 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 1066 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 1067 testing_factory->GetExisting("bad")->SetFailAllRequests(false); | 1067 testing_factory->GetExisting("bad")->SetFailAllRequests(false); |
| 1068 | 1068 |
| 1069 EXPECT_EQ( | 1069 EXPECT_EQ( |
| 1070 SyncChange::ACTION_ADD, | 1070 csync::SyncChange::ACTION_ADD, |
| 1071 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1071 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1072 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1072 EXPECT_EQ(1u, sync_processor_->changes().size()); |
| 1073 | 1073 |
| 1074 // bad should now be disabled for sync. | 1074 // bad should now be disabled for sync. |
| 1075 sync_processor_->ClearChanges(); | 1075 sync_processor_->ClearChanges(); |
| 1076 good->Set(DEFAULTS, "bar", barValue); | 1076 good->Set(DEFAULTS, "bar", barValue); |
| 1077 bad->Set(DEFAULTS, "bar", barValue); | 1077 bad->Set(DEFAULTS, "bar", barValue); |
| 1078 | 1078 |
| 1079 EXPECT_EQ( | 1079 EXPECT_EQ( |
| 1080 SyncChange::ACTION_ADD, | 1080 csync::SyncChange::ACTION_ADD, |
| 1081 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 1081 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 1082 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1082 EXPECT_EQ(1u, sync_processor_->changes().size()); |
| 1083 | 1083 |
| 1084 { | 1084 { |
| 1085 SyncChangeList change_list; | 1085 csync::SyncChangeList change_list; |
| 1086 change_list.push_back(settings_sync_util::CreateUpdate( | 1086 change_list.push_back(settings_sync_util::CreateUpdate( |
| 1087 "good", "foo", barValue, model_type)); | 1087 "good", "foo", barValue, model_type)); |
| 1088 // (Sending ADD here even though it's updating, since that's what the state | 1088 // (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.) | 1089 // of sync is. In any case, it won't work.) |
| 1090 change_list.push_back(settings_sync_util::CreateAdd( | 1090 change_list.push_back(settings_sync_util::CreateAdd( |
| 1091 "bad", "foo", barValue, model_type)); | 1091 "bad", "foo", barValue, model_type)); |
| 1092 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 1092 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 1093 } | 1093 } |
| 1094 | 1094 |
| 1095 { | 1095 { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 // Re-enabling sync without failing should cause the local changes from bad | 1108 // 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. | 1109 // to be pushed to sync successfully, as should future changes to bad. |
| 1110 sync_processor_->ClearChanges(); | 1110 sync_processor_->ClearChanges(); |
| 1111 GetSyncableService(model_type)->StopSyncing(model_type); | 1111 GetSyncableService(model_type)->StopSyncing(model_type); |
| 1112 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( | 1112 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( |
| 1113 sync_processor_.get())); | 1113 sync_processor_.get())); |
| 1114 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 1114 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 1115 model_type, | 1115 model_type, |
| 1116 SyncDataList(), | 1116 csync::SyncDataList(), |
| 1117 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 1117 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 1118 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 1118 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 1119 | 1119 |
| 1120 EXPECT_EQ( | 1120 EXPECT_EQ( |
| 1121 SyncChange::ACTION_ADD, | 1121 csync::SyncChange::ACTION_ADD, |
| 1122 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1122 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1123 EXPECT_EQ( | 1123 EXPECT_EQ( |
| 1124 SyncChange::ACTION_ADD, | 1124 csync::SyncChange::ACTION_ADD, |
| 1125 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 1125 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 1126 EXPECT_EQ( | 1126 EXPECT_EQ( |
| 1127 SyncChange::ACTION_ADD, | 1127 csync::SyncChange::ACTION_ADD, |
| 1128 sync_processor_->GetOnlyChange("bad", "foo").change_type()); | 1128 sync_processor_->GetOnlyChange("bad", "foo").change_type()); |
| 1129 EXPECT_EQ( | 1129 EXPECT_EQ( |
| 1130 SyncChange::ACTION_ADD, | 1130 csync::SyncChange::ACTION_ADD, |
| 1131 sync_processor_->GetOnlyChange("bad", "bar").change_type()); | 1131 sync_processor_->GetOnlyChange("bad", "bar").change_type()); |
| 1132 EXPECT_EQ(4u, sync_processor_->changes().size()); | 1132 EXPECT_EQ(4u, sync_processor_->changes().size()); |
| 1133 | 1133 |
| 1134 sync_processor_->ClearChanges(); | 1134 sync_processor_->ClearChanges(); |
| 1135 good->Set(DEFAULTS, "bar", fooValue); | 1135 good->Set(DEFAULTS, "bar", fooValue); |
| 1136 bad->Set(DEFAULTS, "bar", fooValue); | 1136 bad->Set(DEFAULTS, "bar", fooValue); |
| 1137 | 1137 |
| 1138 EXPECT_EQ( | 1138 EXPECT_EQ( |
| 1139 SyncChange::ACTION_UPDATE, | 1139 csync::SyncChange::ACTION_UPDATE, |
| 1140 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 1140 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 1141 EXPECT_EQ( | 1141 EXPECT_EQ( |
| 1142 SyncChange::ACTION_UPDATE, | 1142 csync::SyncChange::ACTION_UPDATE, |
| 1143 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 1143 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 1144 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1144 EXPECT_EQ(2u, sync_processor_->changes().size()); |
| 1145 } | 1145 } |
| 1146 | 1146 |
| 1147 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { | 1147 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { |
| 1148 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; | 1148 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; |
| 1149 Extension::Type type = Extension::TYPE_EXTENSION; | 1149 Extension::Type type = Extension::TYPE_EXTENSION; |
| 1150 | 1150 |
| 1151 StringValue fooValue("fooValue"); | 1151 StringValue fooValue("fooValue"); |
| 1152 StringValue barValue("barValue"); | 1152 StringValue barValue("barValue"); |
| 1153 | 1153 |
| 1154 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); | 1154 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); |
| 1155 storage_factory_->Reset(testing_factory); | 1155 storage_factory_->Reset(testing_factory); |
| 1156 | 1156 |
| 1157 ValueStore* good = AddExtensionAndGetStorage("good", type); | 1157 ValueStore* good = AddExtensionAndGetStorage("good", type); |
| 1158 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 1158 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
| 1159 | 1159 |
| 1160 // Only set bad; setting good will cause it to fail below. | 1160 // Only set bad; setting good will cause it to fail below. |
| 1161 bad->Set(DEFAULTS, "foo", fooValue); | 1161 bad->Set(DEFAULTS, "foo", fooValue); |
| 1162 | 1162 |
| 1163 sync_processor_->SetFailAllRequests(true); | 1163 sync_processor_->SetFailAllRequests(true); |
| 1164 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 1164 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 1165 model_type, | 1165 model_type, |
| 1166 SyncDataList(), | 1166 csync::SyncDataList(), |
| 1167 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 1167 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 1168 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 1168 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 1169 sync_processor_->SetFailAllRequests(false); | 1169 sync_processor_->SetFailAllRequests(false); |
| 1170 | 1170 |
| 1171 // Changes from good will be send to sync, changes from bad won't. | 1171 // Changes from good will be send to sync, changes from bad won't. |
| 1172 sync_processor_->ClearChanges(); | 1172 sync_processor_->ClearChanges(); |
| 1173 good->Set(DEFAULTS, "foo", barValue); | 1173 good->Set(DEFAULTS, "foo", barValue); |
| 1174 bad->Set(DEFAULTS, "foo", barValue); | 1174 bad->Set(DEFAULTS, "foo", barValue); |
| 1175 | 1175 |
| 1176 EXPECT_EQ( | 1176 EXPECT_EQ( |
| 1177 SyncChange::ACTION_ADD, | 1177 csync::SyncChange::ACTION_ADD, |
| 1178 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1178 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1179 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1179 EXPECT_EQ(1u, sync_processor_->changes().size()); |
| 1180 | 1180 |
| 1181 // Changes from sync will be sent to good, not to bad. | 1181 // Changes from sync will be sent to good, not to bad. |
| 1182 { | 1182 { |
| 1183 SyncChangeList change_list; | 1183 csync::SyncChangeList change_list; |
| 1184 change_list.push_back(settings_sync_util::CreateAdd( | 1184 change_list.push_back(settings_sync_util::CreateAdd( |
| 1185 "good", "bar", barValue, model_type)); | 1185 "good", "bar", barValue, model_type)); |
| 1186 change_list.push_back(settings_sync_util::CreateAdd( | 1186 change_list.push_back(settings_sync_util::CreateAdd( |
| 1187 "bad", "bar", barValue, model_type)); | 1187 "bad", "bar", barValue, model_type)); |
| 1188 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 1188 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 1189 } | 1189 } |
| 1190 | 1190 |
| 1191 { | 1191 { |
| 1192 DictionaryValue dict; | 1192 DictionaryValue dict; |
| 1193 dict.Set("foo", barValue.DeepCopy()); | 1193 dict.Set("foo", barValue.DeepCopy()); |
| 1194 dict.Set("bar", barValue.DeepCopy()); | 1194 dict.Set("bar", barValue.DeepCopy()); |
| 1195 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 1195 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 1196 } | 1196 } |
| 1197 { | 1197 { |
| 1198 DictionaryValue dict; | 1198 DictionaryValue dict; |
| 1199 dict.Set("foo", barValue.DeepCopy()); | 1199 dict.Set("foo", barValue.DeepCopy()); |
| 1200 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 1200 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 1201 } | 1201 } |
| 1202 | 1202 |
| 1203 // Restarting sync makes everything work again. | 1203 // Restarting sync makes everything work again. |
| 1204 sync_processor_->ClearChanges(); | 1204 sync_processor_->ClearChanges(); |
| 1205 GetSyncableService(model_type)->StopSyncing(model_type); | 1205 GetSyncableService(model_type)->StopSyncing(model_type); |
| 1206 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( | 1206 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( |
| 1207 sync_processor_.get())); | 1207 sync_processor_.get())); |
| 1208 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 1208 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 1209 model_type, | 1209 model_type, |
| 1210 SyncDataList(), | 1210 csync::SyncDataList(), |
| 1211 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 1211 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 1212 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 1212 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 1213 | 1213 |
| 1214 EXPECT_EQ( | 1214 EXPECT_EQ( |
| 1215 SyncChange::ACTION_ADD, | 1215 csync::SyncChange::ACTION_ADD, |
| 1216 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1216 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1217 EXPECT_EQ( | 1217 EXPECT_EQ( |
| 1218 SyncChange::ACTION_ADD, | 1218 csync::SyncChange::ACTION_ADD, |
| 1219 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 1219 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 1220 EXPECT_EQ( | 1220 EXPECT_EQ( |
| 1221 SyncChange::ACTION_ADD, | 1221 csync::SyncChange::ACTION_ADD, |
| 1222 sync_processor_->GetOnlyChange("bad", "foo").change_type()); | 1222 sync_processor_->GetOnlyChange("bad", "foo").change_type()); |
| 1223 EXPECT_EQ(3u, sync_processor_->changes().size()); | 1223 EXPECT_EQ(3u, sync_processor_->changes().size()); |
| 1224 | 1224 |
| 1225 sync_processor_->ClearChanges(); | 1225 sync_processor_->ClearChanges(); |
| 1226 good->Set(DEFAULTS, "foo", fooValue); | 1226 good->Set(DEFAULTS, "foo", fooValue); |
| 1227 bad->Set(DEFAULTS, "foo", fooValue); | 1227 bad->Set(DEFAULTS, "foo", fooValue); |
| 1228 | 1228 |
| 1229 EXPECT_EQ( | 1229 EXPECT_EQ( |
| 1230 SyncChange::ACTION_UPDATE, | 1230 csync::SyncChange::ACTION_UPDATE, |
| 1231 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1231 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1232 EXPECT_EQ( | 1232 EXPECT_EQ( |
| 1233 SyncChange::ACTION_UPDATE, | 1233 csync::SyncChange::ACTION_UPDATE, |
| 1234 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1234 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1235 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1235 EXPECT_EQ(2u, sync_processor_->changes().size()); |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { | 1238 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { |
| 1239 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; | 1239 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; |
| 1240 Extension::Type type = Extension::TYPE_EXTENSION; | 1240 Extension::Type type = Extension::TYPE_EXTENSION; |
| 1241 | 1241 |
| 1242 StringValue fooValue("fooValue"); | 1242 StringValue fooValue("fooValue"); |
| 1243 StringValue barValue("barValue"); | 1243 StringValue barValue("barValue"); |
| 1244 | 1244 |
| 1245 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); | 1245 TestingValueStoreFactory* testing_factory = new TestingValueStoreFactory(); |
| 1246 storage_factory_->Reset(testing_factory); | 1246 storage_factory_->Reset(testing_factory); |
| 1247 | 1247 |
| 1248 ValueStore* good = AddExtensionAndGetStorage("good", type); | 1248 ValueStore* good = AddExtensionAndGetStorage("good", type); |
| 1249 ValueStore* bad = AddExtensionAndGetStorage("bad", type); | 1249 ValueStore* bad = AddExtensionAndGetStorage("bad", type); |
| 1250 | 1250 |
| 1251 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 1251 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 1252 model_type, | 1252 model_type, |
| 1253 SyncDataList(), | 1253 csync::SyncDataList(), |
| 1254 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 1254 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 1255 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 1255 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 1256 | 1256 |
| 1257 // bad will fail to send changes. | 1257 // bad will fail to send changes. |
| 1258 good->Set(DEFAULTS, "foo", fooValue); | 1258 good->Set(DEFAULTS, "foo", fooValue); |
| 1259 sync_processor_->SetFailAllRequests(true); | 1259 sync_processor_->SetFailAllRequests(true); |
| 1260 bad->Set(DEFAULTS, "foo", fooValue); | 1260 bad->Set(DEFAULTS, "foo", fooValue); |
| 1261 sync_processor_->SetFailAllRequests(false); | 1261 sync_processor_->SetFailAllRequests(false); |
| 1262 | 1262 |
| 1263 EXPECT_EQ( | 1263 EXPECT_EQ( |
| 1264 SyncChange::ACTION_ADD, | 1264 csync::SyncChange::ACTION_ADD, |
| 1265 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1265 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1266 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1266 EXPECT_EQ(1u, sync_processor_->changes().size()); |
| 1267 | 1267 |
| 1268 // No further changes should be sent from bad. | 1268 // No further changes should be sent from bad. |
| 1269 sync_processor_->ClearChanges(); | 1269 sync_processor_->ClearChanges(); |
| 1270 good->Set(DEFAULTS, "foo", barValue); | 1270 good->Set(DEFAULTS, "foo", barValue); |
| 1271 bad->Set(DEFAULTS, "foo", barValue); | 1271 bad->Set(DEFAULTS, "foo", barValue); |
| 1272 | 1272 |
| 1273 EXPECT_EQ( | 1273 EXPECT_EQ( |
| 1274 SyncChange::ACTION_UPDATE, | 1274 csync::SyncChange::ACTION_UPDATE, |
| 1275 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1275 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1276 EXPECT_EQ(1u, sync_processor_->changes().size()); | 1276 EXPECT_EQ(1u, sync_processor_->changes().size()); |
| 1277 | 1277 |
| 1278 // Changes from sync will be sent to good, not to bad. | 1278 // Changes from sync will be sent to good, not to bad. |
| 1279 { | 1279 { |
| 1280 SyncChangeList change_list; | 1280 csync::SyncChangeList change_list; |
| 1281 change_list.push_back(settings_sync_util::CreateAdd( | 1281 change_list.push_back(settings_sync_util::CreateAdd( |
| 1282 "good", "bar", barValue, model_type)); | 1282 "good", "bar", barValue, model_type)); |
| 1283 change_list.push_back(settings_sync_util::CreateAdd( | 1283 change_list.push_back(settings_sync_util::CreateAdd( |
| 1284 "bad", "bar", barValue, model_type)); | 1284 "bad", "bar", barValue, model_type)); |
| 1285 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 1285 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 { | 1288 { |
| 1289 DictionaryValue dict; | 1289 DictionaryValue dict; |
| 1290 dict.Set("foo", barValue.DeepCopy()); | 1290 dict.Set("foo", barValue.DeepCopy()); |
| 1291 dict.Set("bar", barValue.DeepCopy()); | 1291 dict.Set("bar", barValue.DeepCopy()); |
| 1292 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); | 1292 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); |
| 1293 } | 1293 } |
| 1294 { | 1294 { |
| 1295 DictionaryValue dict; | 1295 DictionaryValue dict; |
| 1296 dict.Set("foo", barValue.DeepCopy()); | 1296 dict.Set("foo", barValue.DeepCopy()); |
| 1297 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); | 1297 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 // Restarting sync makes everything work again. | 1300 // Restarting sync makes everything work again. |
| 1301 sync_processor_->ClearChanges(); | 1301 sync_processor_->ClearChanges(); |
| 1302 GetSyncableService(model_type)->StopSyncing(model_type); | 1302 GetSyncableService(model_type)->StopSyncing(model_type); |
| 1303 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( | 1303 sync_processor_delegate_.reset(new SyncChangeProcessorDelegate( |
| 1304 sync_processor_.get())); | 1304 sync_processor_.get())); |
| 1305 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 1305 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 1306 model_type, | 1306 model_type, |
| 1307 SyncDataList(), | 1307 csync::SyncDataList(), |
| 1308 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 1308 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 1309 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 1309 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 1310 | 1310 |
| 1311 EXPECT_EQ( | 1311 EXPECT_EQ( |
| 1312 SyncChange::ACTION_ADD, | 1312 csync::SyncChange::ACTION_ADD, |
| 1313 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1313 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1314 EXPECT_EQ( | 1314 EXPECT_EQ( |
| 1315 SyncChange::ACTION_ADD, | 1315 csync::SyncChange::ACTION_ADD, |
| 1316 sync_processor_->GetOnlyChange("good", "bar").change_type()); | 1316 sync_processor_->GetOnlyChange("good", "bar").change_type()); |
| 1317 EXPECT_EQ( | 1317 EXPECT_EQ( |
| 1318 SyncChange::ACTION_ADD, | 1318 csync::SyncChange::ACTION_ADD, |
| 1319 sync_processor_->GetOnlyChange("bad", "foo").change_type()); | 1319 sync_processor_->GetOnlyChange("bad", "foo").change_type()); |
| 1320 EXPECT_EQ(3u, sync_processor_->changes().size()); | 1320 EXPECT_EQ(3u, sync_processor_->changes().size()); |
| 1321 | 1321 |
| 1322 sync_processor_->ClearChanges(); | 1322 sync_processor_->ClearChanges(); |
| 1323 good->Set(DEFAULTS, "foo", fooValue); | 1323 good->Set(DEFAULTS, "foo", fooValue); |
| 1324 bad->Set(DEFAULTS, "foo", fooValue); | 1324 bad->Set(DEFAULTS, "foo", fooValue); |
| 1325 | 1325 |
| 1326 EXPECT_EQ( | 1326 EXPECT_EQ( |
| 1327 SyncChange::ACTION_UPDATE, | 1327 csync::SyncChange::ACTION_UPDATE, |
| 1328 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1328 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1329 EXPECT_EQ( | 1329 EXPECT_EQ( |
| 1330 SyncChange::ACTION_UPDATE, | 1330 csync::SyncChange::ACTION_UPDATE, |
| 1331 sync_processor_->GetOnlyChange("good", "foo").change_type()); | 1331 sync_processor_->GetOnlyChange("good", "foo").change_type()); |
| 1332 EXPECT_EQ(2u, sync_processor_->changes().size()); | 1332 EXPECT_EQ(2u, sync_processor_->changes().size()); |
| 1333 } | 1333 } |
| 1334 | 1334 |
| 1335 TEST_F(ExtensionSettingsSyncTest, | 1335 TEST_F(ExtensionSettingsSyncTest, |
| 1336 LargeOutgoingChangeRejectedButIncomingAccepted) { | 1336 LargeOutgoingChangeRejectedButIncomingAccepted) { |
| 1337 syncable::ModelType model_type = syncable::APP_SETTINGS; | 1337 syncable::ModelType model_type = syncable::APP_SETTINGS; |
| 1338 Extension::Type type = Extension::TYPE_PACKAGED_APP; | 1338 Extension::Type type = Extension::TYPE_PACKAGED_APP; |
| 1339 | 1339 |
| 1340 // This value should be larger than the limit in settings_backend.cc. | 1340 // This value should be larger than the limit in settings_backend.cc. |
| 1341 std::string string_5k; | 1341 std::string string_5k; |
| 1342 for (size_t i = 0; i < 5000; ++i) { | 1342 for (size_t i = 0; i < 5000; ++i) { |
| 1343 string_5k.append("a"); | 1343 string_5k.append("a"); |
| 1344 } | 1344 } |
| 1345 StringValue large_value(string_5k); | 1345 StringValue large_value(string_5k); |
| 1346 | 1346 |
| 1347 GetSyncableService(model_type)->MergeDataAndStartSyncing( | 1347 GetSyncableService(model_type)->MergeDataAndStartSyncing( |
| 1348 model_type, | 1348 model_type, |
| 1349 SyncDataList(), | 1349 csync::SyncDataList(), |
| 1350 sync_processor_delegate_.PassAs<SyncChangeProcessor>(), | 1350 sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(), |
| 1351 scoped_ptr<SyncErrorFactory>(new SyncErrorFactoryMock())); | 1351 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); |
| 1352 | 1352 |
| 1353 // Large local change rejected and doesn't get sent out. | 1353 // Large local change rejected and doesn't get sent out. |
| 1354 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); | 1354 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); |
| 1355 EXPECT_TRUE(storage1->Set(DEFAULTS, "large_value", large_value)->HasError()); | 1355 EXPECT_TRUE(storage1->Set(DEFAULTS, "large_value", large_value)->HasError()); |
| 1356 EXPECT_EQ(0u, sync_processor_->changes().size()); | 1356 EXPECT_EQ(0u, sync_processor_->changes().size()); |
| 1357 | 1357 |
| 1358 // Large incoming change should still get accepted. | 1358 // Large incoming change should still get accepted. |
| 1359 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); | 1359 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); |
| 1360 { | 1360 { |
| 1361 SyncChangeList change_list; | 1361 csync::SyncChangeList change_list; |
| 1362 change_list.push_back(settings_sync_util::CreateAdd( | 1362 change_list.push_back(settings_sync_util::CreateAdd( |
| 1363 "s1", "large_value", large_value, model_type)); | 1363 "s1", "large_value", large_value, model_type)); |
| 1364 change_list.push_back(settings_sync_util::CreateAdd( | 1364 change_list.push_back(settings_sync_util::CreateAdd( |
| 1365 "s2", "large_value", large_value, model_type)); | 1365 "s2", "large_value", large_value, model_type)); |
| 1366 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); | 1366 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); |
| 1367 } | 1367 } |
| 1368 { | 1368 { |
| 1369 DictionaryValue expected; | 1369 DictionaryValue expected; |
| 1370 expected.Set("large_value", large_value.DeepCopy()); | 1370 expected.Set("large_value", large_value.DeepCopy()); |
| 1371 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get()); | 1371 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get()); |
| 1372 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get()); | 1372 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get()); |
| 1373 } | 1373 } |
| 1374 | 1374 |
| 1375 GetSyncableService(model_type)->StopSyncing(model_type); | 1375 GetSyncableService(model_type)->StopSyncing(model_type); |
| 1376 } | 1376 } |
| 1377 | 1377 |
| 1378 } // namespace extensions | 1378 } // namespace extensions |
| OLD | NEW |