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

Side by Side Diff: chrome/browser/extensions/api/storage/settings_sync_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6
7 #include <memory>
6 #include <utility> 8 #include <utility>
7 9
8 #include "base/bind.h" 10 #include "base/bind.h"
9 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
10 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
12 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
16 #include "build/build_config.h" 18 #include "build/build_config.h"
17 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" 19 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
18 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h" 20 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h"
19 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" 21 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h"
20 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
21 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
22 #include "extensions/browser/api/storage/settings_test_util.h" 24 #include "extensions/browser/api/storage/settings_test_util.h"
23 #include "extensions/browser/api/storage/storage_frontend.h" 25 #include "extensions/browser/api/storage/storage_frontend.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 extension_id << "/" << key << " (out of " << changes_.size() << ")"; 161 extension_id << "/" << key << " (out of " << changes_.size() << ")";
160 } 162 }
161 return matching_changes[0]; 163 return matching_changes[0];
162 } 164 }
163 165
164 private: 166 private:
165 SettingSyncDataList changes_; 167 SettingSyncDataList changes_;
166 bool fail_all_requests_; 168 bool fail_all_requests_;
167 }; 169 };
168 170
169 scoped_ptr<KeyedService> MockExtensionSystemFactoryFunction( 171 std::unique_ptr<KeyedService> MockExtensionSystemFactoryFunction(
170 content::BrowserContext* context) { 172 content::BrowserContext* context) {
171 return make_scoped_ptr(new MockExtensionSystem(context)); 173 return base::WrapUnique(new MockExtensionSystem(context));
172 } 174 }
173 175
174 scoped_ptr<KeyedService> BuildEventRouter(content::BrowserContext* profile) { 176 std::unique_ptr<KeyedService> BuildEventRouter(
175 return make_scoped_ptr(new extensions::EventRouter(profile, nullptr)); 177 content::BrowserContext* profile) {
178 return base::WrapUnique(new extensions::EventRouter(profile, nullptr));
176 } 179 }
177 180
178 } // namespace 181 } // namespace
179 182
180 class ExtensionSettingsSyncTest : public testing::Test { 183 class ExtensionSettingsSyncTest : public testing::Test {
181 public: 184 public:
182 ExtensionSettingsSyncTest() 185 ExtensionSettingsSyncTest()
183 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), 186 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
184 file_thread_(BrowserThread::FILE, base::MessageLoop::current()), 187 file_thread_(BrowserThread::FILE, base::MessageLoop::current()),
185 storage_factory_(new TestValueStoreFactory()), 188 storage_factory_(new TestValueStoreFactory()),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return static_cast<TestingValueStore*>( 255 return static_cast<TestingValueStore*>(
253 storage_factory_->GetExisting(extension_id)); 256 storage_factory_->GetExisting(extension_id));
254 } 257 }
255 258
256 // Need these so that the DCHECKs for running on FILE or UI threads pass. 259 // Need these so that the DCHECKs for running on FILE or UI threads pass.
257 base::MessageLoop message_loop_; 260 base::MessageLoop message_loop_;
258 content::TestBrowserThread ui_thread_; 261 content::TestBrowserThread ui_thread_;
259 content::TestBrowserThread file_thread_; 262 content::TestBrowserThread file_thread_;
260 263
261 base::ScopedTempDir temp_dir_; 264 base::ScopedTempDir temp_dir_;
262 scoped_ptr<TestingProfile> profile_; 265 std::unique_ptr<TestingProfile> profile_;
263 scoped_ptr<StorageFrontend> frontend_; 266 std::unique_ptr<StorageFrontend> frontend_;
264 scoped_refptr<TestValueStoreFactory> storage_factory_; 267 scoped_refptr<TestValueStoreFactory> storage_factory_;
265 scoped_ptr<MockSyncChangeProcessor> sync_processor_; 268 std::unique_ptr<MockSyncChangeProcessor> sync_processor_;
266 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> sync_processor_wrapper_; 269 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest>
270 sync_processor_wrapper_;
267 }; 271 };
268 272
269 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS 273 // Get a semblance of coverage for both EXTENSION_SETTINGS and APP_SETTINGS
270 // sync by roughly alternative which one to test. 274 // sync by roughly alternative which one to test.
271 275
272 TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) { 276 TEST_F(ExtensionSettingsSyncTest, NoDataDoesNotInvokeSync) {
273 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; 277 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
274 Manifest::Type type = Manifest::TYPE_EXTENSION; 278 Manifest::Type type = Manifest::TYPE_EXTENSION;
275 279
276 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 280 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
277 281
278 // Have one extension created before sync is set up, the other created after. 282 // Have one extension created before sync is set up, the other created after.
279 AddExtensionAndGetStorage("s1", type); 283 AddExtensionAndGetStorage("s1", type);
280 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 284 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
281 285
282 GetSyncableService(model_type) 286 GetSyncableService(model_type)
283 ->MergeDataAndStartSyncing( 287 ->MergeDataAndStartSyncing(
284 model_type, syncer::SyncDataList(), 288 model_type, syncer::SyncDataList(),
285 std::move(sync_processor_wrapper_), 289 std::move(sync_processor_wrapper_),
286 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 290 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
287 291
288 AddExtensionAndGetStorage("s2", type); 292 AddExtensionAndGetStorage("s2", type);
289 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 293 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
290 294
291 GetSyncableService(model_type)->StopSyncing(model_type); 295 GetSyncableService(model_type)->StopSyncing(model_type);
292 296
293 EXPECT_EQ(0u, sync_processor_->changes().size()); 297 EXPECT_EQ(0u, sync_processor_->changes().size());
294 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 298 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
295 } 299 }
296 300
(...skipping 20 matching lines...) Expand all
317 321
318 syncer::SyncDataList sync_data; 322 syncer::SyncDataList sync_data;
319 sync_data.push_back(settings_sync_util::CreateData( 323 sync_data.push_back(settings_sync_util::CreateData(
320 "s1", "foo", value1, model_type)); 324 "s1", "foo", value1, model_type));
321 sync_data.push_back(settings_sync_util::CreateData( 325 sync_data.push_back(settings_sync_util::CreateData(
322 "s2", "bar", value2, model_type)); 326 "s2", "bar", value2, model_type));
323 327
324 GetSyncableService(model_type) 328 GetSyncableService(model_type)
325 ->MergeDataAndStartSyncing( 329 ->MergeDataAndStartSyncing(
326 model_type, sync_data, std::move(sync_processor_wrapper_), 330 model_type, sync_data, std::move(sync_processor_wrapper_),
327 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 331 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
328 332
329 // Already in sync, so no changes. 333 // Already in sync, so no changes.
330 EXPECT_EQ(0u, sync_processor_->changes().size()); 334 EXPECT_EQ(0u, sync_processor_->changes().size());
331 335
332 // Regression test: not-changing the synced value shouldn't result in a sync 336 // Regression test: not-changing the synced value shouldn't result in a sync
333 // change, and changing the synced value should result in an update. 337 // change, and changing the synced value should result in an update.
334 storage1->Set(DEFAULTS, "foo", value1); 338 storage1->Set(DEFAULTS, "foo", value1);
335 EXPECT_EQ(0u, sync_processor_->changes().size()); 339 EXPECT_EQ(0u, sync_processor_->changes().size());
336 340
337 storage1->Set(DEFAULTS, "foo", value2); 341 storage1->Set(DEFAULTS, "foo", value2);
(...skipping 16 matching lines...) Expand all
354 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 358 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
355 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 359 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
356 360
357 storage1->Set(DEFAULTS, "foo", value1); 361 storage1->Set(DEFAULTS, "foo", value1);
358 storage2->Set(DEFAULTS, "bar", value2); 362 storage2->Set(DEFAULTS, "bar", value2);
359 363
360 GetSyncableService(model_type) 364 GetSyncableService(model_type)
361 ->MergeDataAndStartSyncing( 365 ->MergeDataAndStartSyncing(
362 model_type, syncer::SyncDataList(), 366 model_type, syncer::SyncDataList(),
363 std::move(sync_processor_wrapper_), 367 std::move(sync_processor_wrapper_),
364 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 368 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
365 369
366 // All settings should have been pushed to sync. 370 // All settings should have been pushed to sync.
367 EXPECT_EQ(2u, sync_processor_->changes().size()); 371 EXPECT_EQ(2u, sync_processor_->changes().size());
368 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "foo"); 372 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "foo");
369 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); 373 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type());
370 EXPECT_TRUE(value1.Equals(&change->value())); 374 EXPECT_TRUE(value1.Equals(&change->value()));
371 change = sync_processor_->GetOnlyChange("s2", "bar"); 375 change = sync_processor_->GetOnlyChange("s2", "bar");
372 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); 376 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type());
373 EXPECT_TRUE(value2.Equals(&change->value())); 377 EXPECT_TRUE(value2.Equals(&change->value()));
374 378
(...skipping 17 matching lines...) Expand all
392 storage1->Set(DEFAULTS, "overwriteMe", value1); 396 storage1->Set(DEFAULTS, "overwriteMe", value1);
393 397
394 syncer::SyncDataList sync_data; 398 syncer::SyncDataList sync_data;
395 sync_data.push_back(settings_sync_util::CreateData( 399 sync_data.push_back(settings_sync_util::CreateData(
396 "s1", "foo", value1, model_type)); 400 "s1", "foo", value1, model_type));
397 sync_data.push_back(settings_sync_util::CreateData( 401 sync_data.push_back(settings_sync_util::CreateData(
398 "s2", "bar", value2, model_type)); 402 "s2", "bar", value2, model_type));
399 GetSyncableService(model_type) 403 GetSyncableService(model_type)
400 ->MergeDataAndStartSyncing( 404 ->MergeDataAndStartSyncing(
401 model_type, sync_data, std::move(sync_processor_wrapper_), 405 model_type, sync_data, std::move(sync_processor_wrapper_),
402 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 406 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
403 expected1.Set("foo", value1.DeepCopy()); 407 expected1.Set("foo", value1.DeepCopy());
404 expected2.Set("bar", value2.DeepCopy()); 408 expected2.Set("bar", value2.DeepCopy());
405 409
406 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 410 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
407 411
408 // All changes should be local, so no sync changes. 412 // All changes should be local, so no sync changes.
409 EXPECT_EQ(0u, sync_processor_->changes().size()); 413 EXPECT_EQ(0u, sync_processor_->changes().size());
410 414
411 // Sync settings should have been pushed to local settings. 415 // Sync settings should have been pushed to local settings.
412 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get()); 416 EXPECT_PRED_FORMAT2(SettingsEq, expected1, storage1->Get());
(...skipping 21 matching lines...) Expand all
434 storage1->Set(DEFAULTS, "foo", value1); 438 storage1->Set(DEFAULTS, "foo", value1);
435 expected1.Set("foo", value1.DeepCopy()); 439 expected1.Set("foo", value1.DeepCopy());
436 440
437 syncer::SyncDataList sync_data; 441 syncer::SyncDataList sync_data;
438 sync_data.push_back(settings_sync_util::CreateData( 442 sync_data.push_back(settings_sync_util::CreateData(
439 "s2", "bar", value2, model_type)); 443 "s2", "bar", value2, model_type));
440 444
441 GetSyncableService(model_type) 445 GetSyncableService(model_type)
442 ->MergeDataAndStartSyncing( 446 ->MergeDataAndStartSyncing(
443 model_type, sync_data, std::move(sync_processor_wrapper_), 447 model_type, sync_data, std::move(sync_processor_wrapper_),
444 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 448 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
445 expected2.Set("bar", value2.DeepCopy()); 449 expected2.Set("bar", value2.DeepCopy());
446 450
447 // Make sync add some settings. 451 // Make sync add some settings.
448 syncer::SyncChangeList change_list; 452 syncer::SyncChangeList change_list;
449 change_list.push_back(settings_sync_util::CreateAdd( 453 change_list.push_back(settings_sync_util::CreateAdd(
450 "s1", "bar", value2, model_type)); 454 "s1", "bar", value2, model_type));
451 change_list.push_back(settings_sync_util::CreateAdd( 455 change_list.push_back(settings_sync_util::CreateAdd(
452 "s2", "foo", value1, model_type)); 456 "s2", "foo", value1, model_type));
453 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list); 457 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
454 expected1.Set("bar", value2.DeepCopy()); 458 expected1.Set("bar", value2.DeepCopy());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 512
509 syncer::SyncDataList sync_data; 513 syncer::SyncDataList sync_data;
510 sync_data.push_back(settings_sync_util::CreateData( 514 sync_data.push_back(settings_sync_util::CreateData(
511 "s3", "bar", value2, model_type)); 515 "s3", "bar", value2, model_type));
512 sync_data.push_back(settings_sync_util::CreateData( 516 sync_data.push_back(settings_sync_util::CreateData(
513 "s4", "bar", value2, model_type)); 517 "s4", "bar", value2, model_type));
514 518
515 GetSyncableService(model_type) 519 GetSyncableService(model_type)
516 ->MergeDataAndStartSyncing( 520 ->MergeDataAndStartSyncing(
517 model_type, sync_data, std::move(sync_processor_wrapper_), 521 model_type, sync_data, std::move(sync_processor_wrapper_),
518 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 522 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
519 523
520 // Add something locally. 524 // Add something locally.
521 storage1->Set(DEFAULTS, "bar", value2); 525 storage1->Set(DEFAULTS, "bar", value2);
522 storage2->Set(DEFAULTS, "bar", value2); 526 storage2->Set(DEFAULTS, "bar", value2);
523 storage3->Set(DEFAULTS, "foo", value1); 527 storage3->Set(DEFAULTS, "foo", value1);
524 storage4->Set(DEFAULTS, "foo", value1); 528 storage4->Set(DEFAULTS, "foo", value1);
525 529
526 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "bar"); 530 SettingSyncData* change = sync_processor_->GetOnlyChange("s1", "bar");
527 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type()); 531 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, change->change_type());
528 EXPECT_TRUE(value2.Equals(&change->value())); 532 EXPECT_TRUE(value2.Equals(&change->value()));
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 650
647 // Stop each separately, there should be no changes either time. 651 // Stop each separately, there should be no changes either time.
648 syncer::SyncDataList sync_data; 652 syncer::SyncDataList sync_data;
649 sync_data.push_back(settings_sync_util::CreateData( 653 sync_data.push_back(settings_sync_util::CreateData(
650 "s1", "foo", value1, syncer::EXTENSION_SETTINGS)); 654 "s1", "foo", value1, syncer::EXTENSION_SETTINGS));
651 655
652 GetSyncableService(syncer::EXTENSION_SETTINGS) 656 GetSyncableService(syncer::EXTENSION_SETTINGS)
653 ->MergeDataAndStartSyncing( 657 ->MergeDataAndStartSyncing(
654 syncer::EXTENSION_SETTINGS, sync_data, 658 syncer::EXTENSION_SETTINGS, sync_data,
655 std::move(sync_processor_wrapper_), 659 std::move(sync_processor_wrapper_),
656 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 660 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
657 GetSyncableService(syncer::EXTENSION_SETTINGS)-> 661 GetSyncableService(syncer::EXTENSION_SETTINGS)->
658 StopSyncing(syncer::EXTENSION_SETTINGS); 662 StopSyncing(syncer::EXTENSION_SETTINGS);
659 EXPECT_EQ(0u, sync_processor_->changes().size()); 663 EXPECT_EQ(0u, sync_processor_->changes().size());
660 664
661 sync_data.clear(); 665 sync_data.clear();
662 sync_data.push_back(settings_sync_util::CreateData( 666 sync_data.push_back(settings_sync_util::CreateData(
663 "s2", "bar", value2, syncer::APP_SETTINGS)); 667 "s2", "bar", value2, syncer::APP_SETTINGS));
664 668
665 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> app_settings_delegate_( 669 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest>
666 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 670 app_settings_delegate_(
671 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
667 GetSyncableService(syncer::APP_SETTINGS) 672 GetSyncableService(syncer::APP_SETTINGS)
668 ->MergeDataAndStartSyncing( 673 ->MergeDataAndStartSyncing(
669 syncer::APP_SETTINGS, sync_data, std::move(app_settings_delegate_), 674 syncer::APP_SETTINGS, sync_data, std::move(app_settings_delegate_),
670 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 675 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
671 GetSyncableService(syncer::APP_SETTINGS)-> 676 GetSyncableService(syncer::APP_SETTINGS)->
672 StopSyncing(syncer::APP_SETTINGS); 677 StopSyncing(syncer::APP_SETTINGS);
673 EXPECT_EQ(0u, sync_processor_->changes().size()); 678 EXPECT_EQ(0u, sync_processor_->changes().size());
674 } 679 }
675 680
676 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) { 681 TEST_F(ExtensionSettingsSyncTest, FailingStartSyncingDisablesSync) {
677 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; 682 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
678 Manifest::Type type = Manifest::TYPE_EXTENSION; 683 Manifest::Type type = Manifest::TYPE_EXTENSION;
679 684
680 base::StringValue fooValue("fooValue"); 685 base::StringValue fooValue("fooValue");
(...skipping 10 matching lines...) Expand all
691 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); 696 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION);
692 { 697 {
693 syncer::SyncDataList sync_data; 698 syncer::SyncDataList sync_data;
694 sync_data.push_back(settings_sync_util::CreateData( 699 sync_data.push_back(settings_sync_util::CreateData(
695 "good", "foo", fooValue, model_type)); 700 "good", "foo", fooValue, model_type));
696 sync_data.push_back(settings_sync_util::CreateData( 701 sync_data.push_back(settings_sync_util::CreateData(
697 "bad", "foo", fooValue, model_type)); 702 "bad", "foo", fooValue, model_type));
698 GetSyncableService(model_type) 703 GetSyncableService(model_type)
699 ->MergeDataAndStartSyncing( 704 ->MergeDataAndStartSyncing(
700 model_type, sync_data, std::move(sync_processor_wrapper_), 705 model_type, sync_data, std::move(sync_processor_wrapper_),
701 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 706 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
702 } 707 }
703 GetExisting("bad")->set_status_code(ValueStore::OK); 708 GetExisting("bad")->set_status_code(ValueStore::OK);
704 709
705 { 710 {
706 base::DictionaryValue dict; 711 base::DictionaryValue dict;
707 dict.Set("foo", fooValue.DeepCopy()); 712 dict.Set("foo", fooValue.DeepCopy());
708 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 713 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
709 } 714 }
710 { 715 {
711 base::DictionaryValue dict; 716 base::DictionaryValue dict;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 812
808 // Restarting sync should make bad start syncing again. 813 // Restarting sync should make bad start syncing again.
809 sync_processor_->ClearChanges(); 814 sync_processor_->ClearChanges();
810 GetSyncableService(model_type)->StopSyncing(model_type); 815 GetSyncableService(model_type)->StopSyncing(model_type);
811 sync_processor_wrapper_.reset( 816 sync_processor_wrapper_.reset(
812 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 817 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
813 GetSyncableService(model_type) 818 GetSyncableService(model_type)
814 ->MergeDataAndStartSyncing( 819 ->MergeDataAndStartSyncing(
815 model_type, syncer::SyncDataList(), 820 model_type, syncer::SyncDataList(),
816 std::move(sync_processor_wrapper_), 821 std::move(sync_processor_wrapper_),
817 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 822 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
818 823
819 // Local settings will have been pushed to sync, since it's empty (in this 824 // Local settings will have been pushed to sync, since it's empty (in this
820 // test; presumably it wouldn't be live, since we've been getting changes). 825 // test; presumably it wouldn't be live, since we've been getting changes).
821 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 826 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
822 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 827 sync_processor_->GetOnlyChange("good", "foo")->change_type());
823 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 828 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
824 sync_processor_->GetOnlyChange("good", "bar")->change_type()); 829 sync_processor_->GetOnlyChange("good", "bar")->change_type());
825 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 830 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
826 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); 831 sync_processor_->GetOnlyChange("bad", "bar")->change_type());
827 EXPECT_EQ(3u, sync_processor_->changes().size()); 832 EXPECT_EQ(3u, sync_processor_->changes().size());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 // Unlike before, initially succeeding MergeDataAndStartSyncing. 880 // Unlike before, initially succeeding MergeDataAndStartSyncing.
876 { 881 {
877 syncer::SyncDataList sync_data; 882 syncer::SyncDataList sync_data;
878 sync_data.push_back(settings_sync_util::CreateData( 883 sync_data.push_back(settings_sync_util::CreateData(
879 "good", "foo", fooValue, model_type)); 884 "good", "foo", fooValue, model_type));
880 sync_data.push_back(settings_sync_util::CreateData( 885 sync_data.push_back(settings_sync_util::CreateData(
881 "bad", "foo", fooValue, model_type)); 886 "bad", "foo", fooValue, model_type));
882 GetSyncableService(model_type) 887 GetSyncableService(model_type)
883 ->MergeDataAndStartSyncing( 888 ->MergeDataAndStartSyncing(
884 model_type, sync_data, std::move(sync_processor_wrapper_), 889 model_type, sync_data, std::move(sync_processor_wrapper_),
885 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 890 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
886 } 891 }
887 892
888 EXPECT_EQ(0u, sync_processor_->changes().size()); 893 EXPECT_EQ(0u, sync_processor_->changes().size());
889 894
890 { 895 {
891 base::DictionaryValue dict; 896 base::DictionaryValue dict;
892 dict.Set("foo", fooValue.DeepCopy()); 897 dict.Set("foo", fooValue.DeepCopy());
893 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 898 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
894 } 899 }
895 { 900 {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 EXPECT_EQ(1u, all_sync_data.size()); 981 EXPECT_EQ(1u, all_sync_data.size());
977 EXPECT_EQ("good/foo", syncer::SyncDataLocal(all_sync_data[0]).GetTag()); 982 EXPECT_EQ("good/foo", syncer::SyncDataLocal(all_sync_data[0]).GetTag());
978 } 983 }
979 GetExisting("bad")->set_status_code(ValueStore::OK); 984 GetExisting("bad")->set_status_code(ValueStore::OK);
980 985
981 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant). 986 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant).
982 GetSyncableService(model_type) 987 GetSyncableService(model_type)
983 ->MergeDataAndStartSyncing( 988 ->MergeDataAndStartSyncing(
984 model_type, syncer::SyncDataList(), 989 model_type, syncer::SyncDataList(),
985 std::move(sync_processor_wrapper_), 990 std::move(sync_processor_wrapper_),
986 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 991 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
987 992
988 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 993 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
989 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 994 sync_processor_->GetOnlyChange("good", "foo")->change_type());
990 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 995 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
991 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); 996 sync_processor_->GetOnlyChange("bad", "foo")->change_type());
992 EXPECT_EQ(2u, sync_processor_->changes().size()); 997 EXPECT_EQ(2u, sync_processor_->changes().size());
993 998
994 sync_processor_->ClearChanges(); 999 sync_processor_->ClearChanges();
995 good->Set(DEFAULTS, "bar", barValue); 1000 good->Set(DEFAULTS, "bar", barValue);
996 bad->Set(DEFAULTS, "bar", barValue); 1001 bad->Set(DEFAULTS, "bar", barValue);
(...skipping 18 matching lines...) Expand all
1015 good->Set(DEFAULTS, "foo", fooValue); 1020 good->Set(DEFAULTS, "foo", fooValue);
1016 bad->Set(DEFAULTS, "foo", fooValue); 1021 bad->Set(DEFAULTS, "foo", fooValue);
1017 1022
1018 // good will successfully push foo:fooValue to sync, but bad will fail to 1023 // good will successfully push foo:fooValue to sync, but bad will fail to
1019 // get them so won't. 1024 // get them so won't.
1020 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION); 1025 GetExisting("bad")->set_status_code(ValueStore::CORRUPTION);
1021 GetSyncableService(model_type) 1026 GetSyncableService(model_type)
1022 ->MergeDataAndStartSyncing( 1027 ->MergeDataAndStartSyncing(
1023 model_type, syncer::SyncDataList(), 1028 model_type, syncer::SyncDataList(),
1024 std::move(sync_processor_wrapper_), 1029 std::move(sync_processor_wrapper_),
1025 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 1030 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1026 GetExisting("bad")->set_status_code(ValueStore::OK); 1031 GetExisting("bad")->set_status_code(ValueStore::OK);
1027 1032
1028 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1033 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1029 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 1034 sync_processor_->GetOnlyChange("good", "foo")->change_type());
1030 EXPECT_EQ(1u, sync_processor_->changes().size()); 1035 EXPECT_EQ(1u, sync_processor_->changes().size());
1031 1036
1032 // bad should now be disabled for sync. 1037 // bad should now be disabled for sync.
1033 sync_processor_->ClearChanges(); 1038 sync_processor_->ClearChanges();
1034 good->Set(DEFAULTS, "bar", barValue); 1039 good->Set(DEFAULTS, "bar", barValue);
1035 bad->Set(DEFAULTS, "bar", barValue); 1040 bad->Set(DEFAULTS, "bar", barValue);
(...skipping 29 matching lines...) Expand all
1065 // Re-enabling sync without failing should cause the local changes from bad 1070 // Re-enabling sync without failing should cause the local changes from bad
1066 // to be pushed to sync successfully, as should future changes to bad. 1071 // to be pushed to sync successfully, as should future changes to bad.
1067 sync_processor_->ClearChanges(); 1072 sync_processor_->ClearChanges();
1068 GetSyncableService(model_type)->StopSyncing(model_type); 1073 GetSyncableService(model_type)->StopSyncing(model_type);
1069 sync_processor_wrapper_.reset( 1074 sync_processor_wrapper_.reset(
1070 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 1075 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
1071 GetSyncableService(model_type) 1076 GetSyncableService(model_type)
1072 ->MergeDataAndStartSyncing( 1077 ->MergeDataAndStartSyncing(
1073 model_type, syncer::SyncDataList(), 1078 model_type, syncer::SyncDataList(),
1074 std::move(sync_processor_wrapper_), 1079 std::move(sync_processor_wrapper_),
1075 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 1080 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1076 1081
1077 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1082 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1078 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 1083 sync_processor_->GetOnlyChange("good", "foo")->change_type());
1079 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1084 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1080 sync_processor_->GetOnlyChange("good", "bar")->change_type()); 1085 sync_processor_->GetOnlyChange("good", "bar")->change_type());
1081 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1086 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1082 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); 1087 sync_processor_->GetOnlyChange("bad", "foo")->change_type());
1083 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1088 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1084 sync_processor_->GetOnlyChange("bad", "bar")->change_type()); 1089 sync_processor_->GetOnlyChange("bad", "bar")->change_type());
1085 EXPECT_EQ(4u, sync_processor_->changes().size()); 1090 EXPECT_EQ(4u, sync_processor_->changes().size());
(...skipping 20 matching lines...) Expand all
1106 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1111 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1107 1112
1108 // Only set bad; setting good will cause it to fail below. 1113 // Only set bad; setting good will cause it to fail below.
1109 bad->Set(DEFAULTS, "foo", fooValue); 1114 bad->Set(DEFAULTS, "foo", fooValue);
1110 1115
1111 sync_processor_->set_fail_all_requests(true); 1116 sync_processor_->set_fail_all_requests(true);
1112 GetSyncableService(model_type) 1117 GetSyncableService(model_type)
1113 ->MergeDataAndStartSyncing( 1118 ->MergeDataAndStartSyncing(
1114 model_type, syncer::SyncDataList(), 1119 model_type, syncer::SyncDataList(),
1115 std::move(sync_processor_wrapper_), 1120 std::move(sync_processor_wrapper_),
1116 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 1121 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1117 sync_processor_->set_fail_all_requests(false); 1122 sync_processor_->set_fail_all_requests(false);
1118 1123
1119 // Changes from good will be send to sync, changes from bad won't. 1124 // Changes from good will be send to sync, changes from bad won't.
1120 sync_processor_->ClearChanges(); 1125 sync_processor_->ClearChanges();
1121 good->Set(DEFAULTS, "foo", barValue); 1126 good->Set(DEFAULTS, "foo", barValue);
1122 bad->Set(DEFAULTS, "foo", barValue); 1127 bad->Set(DEFAULTS, "foo", barValue);
1123 1128
1124 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1129 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1125 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 1130 sync_processor_->GetOnlyChange("good", "foo")->change_type());
1126 EXPECT_EQ(1u, sync_processor_->changes().size()); 1131 EXPECT_EQ(1u, sync_processor_->changes().size());
(...skipping 22 matching lines...) Expand all
1149 1154
1150 // Restarting sync makes everything work again. 1155 // Restarting sync makes everything work again.
1151 sync_processor_->ClearChanges(); 1156 sync_processor_->ClearChanges();
1152 GetSyncableService(model_type)->StopSyncing(model_type); 1157 GetSyncableService(model_type)->StopSyncing(model_type);
1153 sync_processor_wrapper_.reset( 1158 sync_processor_wrapper_.reset(
1154 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 1159 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
1155 GetSyncableService(model_type) 1160 GetSyncableService(model_type)
1156 ->MergeDataAndStartSyncing( 1161 ->MergeDataAndStartSyncing(
1157 model_type, syncer::SyncDataList(), 1162 model_type, syncer::SyncDataList(),
1158 std::move(sync_processor_wrapper_), 1163 std::move(sync_processor_wrapper_),
1159 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 1164 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1160 1165
1161 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1166 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1162 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 1167 sync_processor_->GetOnlyChange("good", "foo")->change_type());
1163 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1168 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1164 sync_processor_->GetOnlyChange("good", "bar")->change_type()); 1169 sync_processor_->GetOnlyChange("good", "bar")->change_type());
1165 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1170 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1166 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); 1171 sync_processor_->GetOnlyChange("bad", "foo")->change_type());
1167 EXPECT_EQ(3u, sync_processor_->changes().size()); 1172 EXPECT_EQ(3u, sync_processor_->changes().size());
1168 1173
1169 sync_processor_->ClearChanges(); 1174 sync_processor_->ClearChanges();
(...skipping 14 matching lines...) Expand all
1184 base::StringValue fooValue("fooValue"); 1189 base::StringValue fooValue("fooValue");
1185 base::StringValue barValue("barValue"); 1190 base::StringValue barValue("barValue");
1186 1191
1187 ValueStore* good = AddExtensionAndGetStorage("good", type); 1192 ValueStore* good = AddExtensionAndGetStorage("good", type);
1188 ValueStore* bad = AddExtensionAndGetStorage("bad", type); 1193 ValueStore* bad = AddExtensionAndGetStorage("bad", type);
1189 1194
1190 GetSyncableService(model_type) 1195 GetSyncableService(model_type)
1191 ->MergeDataAndStartSyncing( 1196 ->MergeDataAndStartSyncing(
1192 model_type, syncer::SyncDataList(), 1197 model_type, syncer::SyncDataList(),
1193 std::move(sync_processor_wrapper_), 1198 std::move(sync_processor_wrapper_),
1194 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 1199 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1195 1200
1196 // bad will fail to send changes. 1201 // bad will fail to send changes.
1197 good->Set(DEFAULTS, "foo", fooValue); 1202 good->Set(DEFAULTS, "foo", fooValue);
1198 sync_processor_->set_fail_all_requests(true); 1203 sync_processor_->set_fail_all_requests(true);
1199 bad->Set(DEFAULTS, "foo", fooValue); 1204 bad->Set(DEFAULTS, "foo", fooValue);
1200 sync_processor_->set_fail_all_requests(false); 1205 sync_processor_->set_fail_all_requests(false);
1201 1206
1202 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1207 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1203 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 1208 sync_processor_->GetOnlyChange("good", "foo")->change_type());
1204 EXPECT_EQ(1u, sync_processor_->changes().size()); 1209 EXPECT_EQ(1u, sync_processor_->changes().size());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 1241
1237 // Restarting sync makes everything work again. 1242 // Restarting sync makes everything work again.
1238 sync_processor_->ClearChanges(); 1243 sync_processor_->ClearChanges();
1239 GetSyncableService(model_type)->StopSyncing(model_type); 1244 GetSyncableService(model_type)->StopSyncing(model_type);
1240 sync_processor_wrapper_.reset( 1245 sync_processor_wrapper_.reset(
1241 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); 1246 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get()));
1242 GetSyncableService(model_type) 1247 GetSyncableService(model_type)
1243 ->MergeDataAndStartSyncing( 1248 ->MergeDataAndStartSyncing(
1244 model_type, syncer::SyncDataList(), 1249 model_type, syncer::SyncDataList(),
1245 std::move(sync_processor_wrapper_), 1250 std::move(sync_processor_wrapper_),
1246 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 1251 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1247 1252
1248 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1253 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1249 sync_processor_->GetOnlyChange("good", "foo")->change_type()); 1254 sync_processor_->GetOnlyChange("good", "foo")->change_type());
1250 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1255 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1251 sync_processor_->GetOnlyChange("good", "bar")->change_type()); 1256 sync_processor_->GetOnlyChange("good", "bar")->change_type());
1252 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, 1257 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
1253 sync_processor_->GetOnlyChange("bad", "foo")->change_type()); 1258 sync_processor_->GetOnlyChange("bad", "foo")->change_type());
1254 EXPECT_EQ(3u, sync_processor_->changes().size()); 1259 EXPECT_EQ(3u, sync_processor_->changes().size());
1255 1260
1256 sync_processor_->ClearChanges(); 1261 sync_processor_->ClearChanges();
(...skipping 16 matching lines...) Expand all
1273 std::string string_10k; 1278 std::string string_10k;
1274 for (size_t i = 0; i < 10000; ++i) { 1279 for (size_t i = 0; i < 10000; ++i) {
1275 string_10k.append("a"); 1280 string_10k.append("a");
1276 } 1281 }
1277 base::StringValue large_value(string_10k); 1282 base::StringValue large_value(string_10k);
1278 1283
1279 GetSyncableService(model_type) 1284 GetSyncableService(model_type)
1280 ->MergeDataAndStartSyncing( 1285 ->MergeDataAndStartSyncing(
1281 model_type, syncer::SyncDataList(), 1286 model_type, syncer::SyncDataList(),
1282 std::move(sync_processor_wrapper_), 1287 std::move(sync_processor_wrapper_),
1283 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 1288 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1284 1289
1285 // Large local change rejected and doesn't get sent out. 1290 // Large local change rejected and doesn't get sent out.
1286 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 1291 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
1287 EXPECT_FALSE( 1292 EXPECT_FALSE(
1288 storage1->Set(DEFAULTS, "large_value", large_value)->status().ok()); 1293 storage1->Set(DEFAULTS, "large_value", large_value)->status().ok());
1289 EXPECT_EQ(0u, sync_processor_->changes().size()); 1294 EXPECT_EQ(0u, sync_processor_->changes().size());
1290 1295
1291 // Large incoming change should still get accepted. 1296 // Large incoming change should still get accepted.
1292 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 1297 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
1293 { 1298 {
(...skipping 15 matching lines...) Expand all
1309 } 1314 }
1310 1315
1311 TEST_F(ExtensionSettingsSyncTest, Dots) { 1316 TEST_F(ExtensionSettingsSyncTest, Dots) {
1312 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; 1317 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
1313 Manifest::Type type = Manifest::TYPE_EXTENSION; 1318 Manifest::Type type = Manifest::TYPE_EXTENSION;
1314 1319
1315 ValueStore* storage = AddExtensionAndGetStorage("ext", type); 1320 ValueStore* storage = AddExtensionAndGetStorage("ext", type);
1316 1321
1317 { 1322 {
1318 syncer::SyncDataList sync_data_list; 1323 syncer::SyncDataList sync_data_list;
1319 scoped_ptr<base::Value> string_value(new base::StringValue("value")); 1324 std::unique_ptr<base::Value> string_value(new base::StringValue("value"));
1320 sync_data_list.push_back(settings_sync_util::CreateData( 1325 sync_data_list.push_back(settings_sync_util::CreateData(
1321 "ext", "key.with.dot", *string_value, model_type)); 1326 "ext", "key.with.dot", *string_value, model_type));
1322 1327
1323 GetSyncableService(model_type) 1328 GetSyncableService(model_type)
1324 ->MergeDataAndStartSyncing( 1329 ->MergeDataAndStartSyncing(
1325 model_type, sync_data_list, std::move(sync_processor_wrapper_), 1330 model_type, sync_data_list, std::move(sync_processor_wrapper_),
1326 make_scoped_ptr(new syncer::SyncErrorFactoryMock())); 1331 base::WrapUnique(new syncer::SyncErrorFactoryMock()));
1327 } 1332 }
1328 1333
1329 // Test dots in keys that come from sync. 1334 // Test dots in keys that come from sync.
1330 { 1335 {
1331 ValueStore::ReadResult data = storage->Get(); 1336 ValueStore::ReadResult data = storage->Get();
1332 ASSERT_TRUE(data->status().ok()); 1337 ASSERT_TRUE(data->status().ok());
1333 1338
1334 base::DictionaryValue expected_data; 1339 base::DictionaryValue expected_data;
1335 expected_data.SetWithoutPathExpansion( 1340 expected_data.SetWithoutPathExpansion(
1336 "key.with.dot", 1341 "key.with.dot",
1337 new base::StringValue("value")); 1342 new base::StringValue("value"));
1338 EXPECT_TRUE(base::Value::Equals(&expected_data, &data->settings())); 1343 EXPECT_TRUE(base::Value::Equals(&expected_data, &data->settings()));
1339 } 1344 }
1340 1345
1341 // Test dots in keys going to sync. 1346 // Test dots in keys going to sync.
1342 { 1347 {
1343 scoped_ptr<base::Value> string_value(new base::StringValue("spot")); 1348 std::unique_ptr<base::Value> string_value(new base::StringValue("spot"));
1344 storage->Set(DEFAULTS, "key.with.spot", *string_value); 1349 storage->Set(DEFAULTS, "key.with.spot", *string_value);
1345 1350
1346 ASSERT_EQ(1u, sync_processor_->changes().size()); 1351 ASSERT_EQ(1u, sync_processor_->changes().size());
1347 SettingSyncData* sync_data = sync_processor_->changes()[0]; 1352 SettingSyncData* sync_data = sync_processor_->changes()[0];
1348 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data->change_type()); 1353 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data->change_type());
1349 EXPECT_EQ("ext", sync_data->extension_id()); 1354 EXPECT_EQ("ext", sync_data->extension_id());
1350 EXPECT_EQ("key.with.spot", sync_data->key()); 1355 EXPECT_EQ("key.with.spot", sync_data->key());
1351 EXPECT_TRUE(sync_data->value().Equals(string_value.get())); 1356 EXPECT_TRUE(sync_data->value().Equals(string_value.get()));
1352 } 1357 }
1353 } 1358 }
1354 1359
1355 // In other (frontend) tests, we assume that the result of GetStorage 1360 // In other (frontend) tests, we assume that the result of GetStorage
1356 // is a pointer to the a Storage owned by a Frontend object, but for 1361 // is a pointer to the a Storage owned by a Frontend object, but for
1357 // the unlimitedStorage case, this might not be true. So, write the 1362 // the unlimitedStorage case, this might not be true. So, write the
1358 // tests in a "callback" style. We should really rewrite all tests to 1363 // tests in a "callback" style. We should really rewrite all tests to
1359 // be asynchronous in this way. 1364 // be asynchronous in this way.
1360 1365
1361 namespace { 1366 namespace {
1362 1367
1363 static void UnlimitedSyncStorageTestCallback(ValueStore* sync_storage) { 1368 static void UnlimitedSyncStorageTestCallback(ValueStore* sync_storage) {
1364 // Sync storage should still run out after ~100K; the unlimitedStorage 1369 // Sync storage should still run out after ~100K; the unlimitedStorage
1365 // permission can't apply to sync. 1370 // permission can't apply to sync.
1366 scoped_ptr<base::Value> kilobyte = util::CreateKilobyte(); 1371 std::unique_ptr<base::Value> kilobyte = util::CreateKilobyte();
1367 for (int i = 0; i < 100; ++i) { 1372 for (int i = 0; i < 100; ++i) {
1368 sync_storage->Set(ValueStore::DEFAULTS, base::IntToString(i), *kilobyte); 1373 sync_storage->Set(ValueStore::DEFAULTS, base::IntToString(i), *kilobyte);
1369 } 1374 }
1370 1375
1371 EXPECT_FALSE(sync_storage->Set(ValueStore::DEFAULTS, "WillError", *kilobyte) 1376 EXPECT_FALSE(sync_storage->Set(ValueStore::DEFAULTS, "WillError", *kilobyte)
1372 ->status().ok()); 1377 ->status().ok());
1373 } 1378 }
1374 1379
1375 static void UnlimitedLocalStorageTestCallback(ValueStore* local_storage) { 1380 static void UnlimitedLocalStorageTestCallback(ValueStore* local_storage) {
1376 // Local storage should never run out. 1381 // Local storage should never run out.
1377 scoped_ptr<base::Value> megabyte = util::CreateMegabyte(); 1382 std::unique_ptr<base::Value> megabyte = util::CreateMegabyte();
1378 for (int i = 0; i < 7; ++i) { 1383 for (int i = 0; i < 7; ++i) {
1379 local_storage->Set(ValueStore::DEFAULTS, base::IntToString(i), *megabyte); 1384 local_storage->Set(ValueStore::DEFAULTS, base::IntToString(i), *megabyte);
1380 } 1385 }
1381 1386
1382 EXPECT_TRUE(local_storage->Set(ValueStore::DEFAULTS, "WontError", *megabyte) 1387 EXPECT_TRUE(local_storage->Set(ValueStore::DEFAULTS, "WontError", *megabyte)
1383 ->status().ok()); 1388 ->status().ok());
1384 } 1389 }
1385 1390
1386 } // namespace 1391 } // namespace
1387 1392
(...skipping 17 matching lines...) Expand all
1405 settings_namespace::SYNC, 1410 settings_namespace::SYNC,
1406 base::Bind(&UnlimitedSyncStorageTestCallback)); 1411 base::Bind(&UnlimitedSyncStorageTestCallback));
1407 frontend_->RunWithStorage(extension, 1412 frontend_->RunWithStorage(extension,
1408 settings_namespace::LOCAL, 1413 settings_namespace::LOCAL,
1409 base::Bind(&UnlimitedLocalStorageTestCallback)); 1414 base::Bind(&UnlimitedLocalStorageTestCallback));
1410 1415
1411 base::MessageLoop::current()->RunUntilIdle(); 1416 base::MessageLoop::current()->RunUntilIdle();
1412 } 1417 }
1413 1418
1414 } // namespace extensions 1419 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698