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

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

Issue 22885002: c/b/extensions, json_schema_compiler: Do not use Value::Create*. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed C-style casts. Created 7 years, 4 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 EXPECT_EQ(0u, sync_processor_->changes().size()); 300 EXPECT_EQ(0u, sync_processor_->changes().size());
301 EXPECT_EQ(0u, GetAllSyncData(model_type).size()); 301 EXPECT_EQ(0u, GetAllSyncData(model_type).size());
302 } 302 }
303 303
304 TEST_F(ExtensionSettingsSyncTest, InSyncDataDoesNotInvokeSync) { 304 TEST_F(ExtensionSettingsSyncTest, InSyncDataDoesNotInvokeSync) {
305 syncer::ModelType model_type = syncer::APP_SETTINGS; 305 syncer::ModelType model_type = syncer::APP_SETTINGS;
306 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; 306 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP;
307 307
308 StringValue value1("fooValue"); 308 StringValue value1("fooValue");
309 ListValue value2; 309 ListValue value2;
310 value2.Append(StringValue::CreateStringValue("barValue")); 310 value2.Append(new base::StringValue("barValue"));
311 311
312 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 312 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
313 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 313 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
314 314
315 storage1->Set(DEFAULTS, "foo", value1); 315 storage1->Set(DEFAULTS, "foo", value1);
316 storage2->Set(DEFAULTS, "bar", value2); 316 storage2->Set(DEFAULTS, "bar", value2);
317 317
318 std::map<std::string, SettingSyncDataList> all_sync_data = 318 std::map<std::string, SettingSyncDataList> all_sync_data =
319 GetAllSyncData(model_type); 319 GetAllSyncData(model_type);
320 EXPECT_EQ(2u, all_sync_data.size()); 320 EXPECT_EQ(2u, all_sync_data.size());
(...skipping 29 matching lines...) Expand all
350 350
351 GetSyncableService(model_type)->StopSyncing(model_type); 351 GetSyncableService(model_type)->StopSyncing(model_type);
352 } 352 }
353 353
354 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) { 354 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) {
355 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; 355 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
356 Manifest::Type type = Manifest::TYPE_EXTENSION; 356 Manifest::Type type = Manifest::TYPE_EXTENSION;
357 357
358 StringValue value1("fooValue"); 358 StringValue value1("fooValue");
359 ListValue value2; 359 ListValue value2;
360 value2.Append(StringValue::CreateStringValue("barValue")); 360 value2.Append(new base::StringValue("barValue"));
361 361
362 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 362 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
363 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 363 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
364 364
365 storage1->Set(DEFAULTS, "foo", value1); 365 storage1->Set(DEFAULTS, "foo", value1);
366 storage2->Set(DEFAULTS, "bar", value2); 366 storage2->Set(DEFAULTS, "bar", value2);
367 367
368 GetSyncableService(model_type)->MergeDataAndStartSyncing( 368 GetSyncableService(model_type)->MergeDataAndStartSyncing(
369 model_type, 369 model_type,
370 syncer::SyncDataList(), 370 syncer::SyncDataList(),
(...skipping 11 matching lines...) Expand all
382 382
383 GetSyncableService(model_type)->StopSyncing(model_type); 383 GetSyncableService(model_type)->StopSyncing(model_type);
384 } 384 }
385 385
386 TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) { 386 TEST_F(ExtensionSettingsSyncTest, AnySyncDataOverwritesLocalData) {
387 syncer::ModelType model_type = syncer::APP_SETTINGS; 387 syncer::ModelType model_type = syncer::APP_SETTINGS;
388 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; 388 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP;
389 389
390 StringValue value1("fooValue"); 390 StringValue value1("fooValue");
391 ListValue value2; 391 ListValue value2;
392 value2.Append(StringValue::CreateStringValue("barValue")); 392 value2.Append(new base::StringValue("barValue"));
393 393
394 // Maintain dictionaries mirrored to the expected values of the settings in 394 // Maintain dictionaries mirrored to the expected values of the settings in
395 // each storage area. 395 // each storage area.
396 DictionaryValue expected1, expected2; 396 DictionaryValue expected1, expected2;
397 397
398 // Pre-populate one of the storage areas. 398 // Pre-populate one of the storage areas.
399 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 399 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
400 storage1->Set(DEFAULTS, "overwriteMe", value1); 400 storage1->Set(DEFAULTS, "overwriteMe", value1);
401 401
402 syncer::SyncDataList sync_data; 402 syncer::SyncDataList sync_data;
(...skipping 19 matching lines...) Expand all
422 422
423 GetSyncableService(model_type)->StopSyncing(model_type); 423 GetSyncableService(model_type)->StopSyncing(model_type);
424 } 424 }
425 425
426 TEST_F(ExtensionSettingsSyncTest, ProcessSyncChanges) { 426 TEST_F(ExtensionSettingsSyncTest, ProcessSyncChanges) {
427 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; 427 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
428 Manifest::Type type = Manifest::TYPE_EXTENSION; 428 Manifest::Type type = Manifest::TYPE_EXTENSION;
429 429
430 StringValue value1("fooValue"); 430 StringValue value1("fooValue");
431 ListValue value2; 431 ListValue value2;
432 value2.Append(StringValue::CreateStringValue("barValue")); 432 value2.Append(new base::StringValue("barValue"));
433 433
434 // Maintain dictionaries mirrored to the expected values of the settings in 434 // Maintain dictionaries mirrored to the expected values of the settings in
435 // each storage area. 435 // each storage area.
436 DictionaryValue expected1, expected2; 436 DictionaryValue expected1, expected2;
437 437
438 // Make storage1 initialised from local data, storage2 initialised from sync. 438 // Make storage1 initialised from local data, storage2 initialised from sync.
439 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 439 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
440 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 440 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
441 441
442 storage1->Set(DEFAULTS, "foo", value1); 442 storage1->Set(DEFAULTS, "foo", value1);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 495
496 GetSyncableService(model_type)->StopSyncing(model_type); 496 GetSyncableService(model_type)->StopSyncing(model_type);
497 } 497 }
498 498
499 TEST_F(ExtensionSettingsSyncTest, PushToSync) { 499 TEST_F(ExtensionSettingsSyncTest, PushToSync) {
500 syncer::ModelType model_type = syncer::APP_SETTINGS; 500 syncer::ModelType model_type = syncer::APP_SETTINGS;
501 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP; 501 Manifest::Type type = Manifest::TYPE_LEGACY_PACKAGED_APP;
502 502
503 StringValue value1("fooValue"); 503 StringValue value1("fooValue");
504 ListValue value2; 504 ListValue value2;
505 value2.Append(StringValue::CreateStringValue("barValue")); 505 value2.Append(new base::StringValue("barValue"));
506 506
507 // Make storage1/2 initialised from local data, storage3/4 initialised from 507 // Make storage1/2 initialised from local data, storage3/4 initialised from
508 // sync. 508 // sync.
509 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type); 509 ValueStore* storage1 = AddExtensionAndGetStorage("s1", type);
510 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type); 510 ValueStore* storage2 = AddExtensionAndGetStorage("s2", type);
511 ValueStore* storage3 = AddExtensionAndGetStorage("s3", type); 511 ValueStore* storage3 = AddExtensionAndGetStorage("s3", type);
512 ValueStore* storage4 = AddExtensionAndGetStorage("s4", type); 512 ValueStore* storage4 = AddExtensionAndGetStorage("s4", type);
513 513
514 storage1->Set(DEFAULTS, "foo", value1); 514 storage1->Set(DEFAULTS, "foo", value1);
515 storage2->Set(DEFAULTS, "foo", value1); 515 storage2->Set(DEFAULTS, "foo", value1);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 EXPECT_EQ( 634 EXPECT_EQ(
635 syncer::SyncChange::ACTION_DELETE, 635 syncer::SyncChange::ACTION_DELETE,
636 sync_processor_->GetOnlyChange("s4", "bar").change_type()); 636 sync_processor_->GetOnlyChange("s4", "bar").change_type());
637 637
638 GetSyncableService(model_type)->StopSyncing(model_type); 638 GetSyncableService(model_type)->StopSyncing(model_type);
639 } 639 }
640 640
641 TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) { 641 TEST_F(ExtensionSettingsSyncTest, ExtensionAndAppSettingsSyncSeparately) {
642 StringValue value1("fooValue"); 642 StringValue value1("fooValue");
643 ListValue value2; 643 ListValue value2;
644 value2.Append(StringValue::CreateStringValue("barValue")); 644 value2.Append(new base::StringValue("barValue"));
645 645
646 // storage1 is an extension, storage2 is an app. 646 // storage1 is an extension, storage2 is an app.
647 ValueStore* storage1 = AddExtensionAndGetStorage( 647 ValueStore* storage1 = AddExtensionAndGetStorage(
648 "s1", Manifest::TYPE_EXTENSION); 648 "s1", Manifest::TYPE_EXTENSION);
649 ValueStore* storage2 = AddExtensionAndGetStorage( 649 ValueStore* storage2 = AddExtensionAndGetStorage(
650 "s2", Manifest::TYPE_LEGACY_PACKAGED_APP); 650 "s2", Manifest::TYPE_LEGACY_PACKAGED_APP);
651 651
652 storage1->Set(DEFAULTS, "foo", value1); 652 storage1->Set(DEFAULTS, "foo", value1);
653 storage2->Set(DEFAULTS, "bar", value2); 653 storage2->Set(DEFAULTS, "bar", value2);
654 654
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 } 1383 }
1384 1384
1385 TEST_F(ExtensionSettingsSyncTest, Dots) { 1385 TEST_F(ExtensionSettingsSyncTest, Dots) {
1386 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS; 1386 syncer::ModelType model_type = syncer::EXTENSION_SETTINGS;
1387 Manifest::Type type = Manifest::TYPE_EXTENSION; 1387 Manifest::Type type = Manifest::TYPE_EXTENSION;
1388 1388
1389 ValueStore* storage = AddExtensionAndGetStorage("ext", type); 1389 ValueStore* storage = AddExtensionAndGetStorage("ext", type);
1390 1390
1391 { 1391 {
1392 syncer::SyncDataList sync_data_list; 1392 syncer::SyncDataList sync_data_list;
1393 scoped_ptr<Value> string_value(Value::CreateStringValue("value")); 1393 scoped_ptr<Value> string_value(new base::StringValue("value"));
1394 sync_data_list.push_back(settings_sync_util::CreateData( 1394 sync_data_list.push_back(settings_sync_util::CreateData(
1395 "ext", "key.with.dot", *string_value, model_type)); 1395 "ext", "key.with.dot", *string_value, model_type));
1396 1396
1397 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1397 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1398 model_type, 1398 model_type,
1399 sync_data_list, 1399 sync_data_list,
1400 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(), 1400 sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>(),
1401 scoped_ptr<syncer::SyncErrorFactory>( 1401 scoped_ptr<syncer::SyncErrorFactory>(
1402 new syncer::SyncErrorFactoryMock())); 1402 new syncer::SyncErrorFactoryMock()));
1403 } 1403 }
1404 1404
1405 // Test dots in keys that come from sync. 1405 // Test dots in keys that come from sync.
1406 { 1406 {
1407 ValueStore::ReadResult data = storage->Get(); 1407 ValueStore::ReadResult data = storage->Get();
1408 ASSERT_FALSE(data->HasError()); 1408 ASSERT_FALSE(data->HasError());
1409 1409
1410 DictionaryValue expected_data; 1410 DictionaryValue expected_data;
1411 expected_data.SetWithoutPathExpansion( 1411 expected_data.SetWithoutPathExpansion(
1412 "key.with.dot", 1412 "key.with.dot",
1413 Value::CreateStringValue("value")); 1413 new base::StringValue("value"));
1414 EXPECT_TRUE(Value::Equals(&expected_data, data->settings().get())); 1414 EXPECT_TRUE(Value::Equals(&expected_data, data->settings().get()));
1415 } 1415 }
1416 1416
1417 // Test dots in keys going to sync. 1417 // Test dots in keys going to sync.
1418 { 1418 {
1419 scoped_ptr<Value> string_value(Value::CreateStringValue("spot")); 1419 scoped_ptr<Value> string_value(new base::StringValue("spot"));
1420 storage->Set(DEFAULTS, "key.with.spot", *string_value); 1420 storage->Set(DEFAULTS, "key.with.spot", *string_value);
1421 1421
1422 ASSERT_EQ(1u, sync_processor_->changes().size()); 1422 ASSERT_EQ(1u, sync_processor_->changes().size());
1423 SettingSyncData sync_data = sync_processor_->changes()[0]; 1423 SettingSyncData sync_data = sync_processor_->changes()[0];
1424 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data.change_type()); 1424 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data.change_type());
1425 EXPECT_EQ("ext", sync_data.extension_id()); 1425 EXPECT_EQ("ext", sync_data.extension_id());
1426 EXPECT_EQ("key.with.spot", sync_data.key()); 1426 EXPECT_EQ("key.with.spot", sync_data.key());
1427 EXPECT_TRUE(sync_data.value().Equals(string_value.get())); 1427 EXPECT_TRUE(sync_data.value().Equals(string_value.get()));
1428 } 1428 }
1429 } 1429 }
1430 1430
1431 } // namespace extensions 1431 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698