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

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

Issue 8587025: Extension settings API: force through changes that come from sync (ignoring (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 14 matching lines...) Expand all
25 // TODO(kalman): Integration tests for sync. 25 // TODO(kalman): Integration tests for sync.
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 28
29 namespace extensions { 29 namespace extensions {
30 30
31 using namespace settings_test_util; 31 using namespace settings_test_util;
32 32
33 namespace { 33 namespace {
34 34
35 // To save typing SettingsStorage::DEFAULTS everywhere.
36 const SettingsStorage::WriteOptions DEFAULTS = SettingsStorage::DEFAULTS;
37
35 // Gets the pretty-printed JSON for a value. 38 // Gets the pretty-printed JSON for a value.
36 static std::string GetJson(const Value& value) { 39 static std::string GetJson(const Value& value) {
37 std::string json; 40 std::string json;
38 base::JSONWriter::Write(&value, true, &json); 41 base::JSONWriter::Write(&value, true, &json);
39 return json; 42 return json;
40 } 43 }
41 44
42 // Returns whether two Values are equal. 45 // Returns whether two Values are equal.
43 testing::AssertionResult ValuesEq( 46 testing::AssertionResult ValuesEq(
44 const char* _1, const char* _2, 47 const char* _1, const char* _2,
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 syncable::ModelType model_type = syncable::APP_SETTINGS; 268 syncable::ModelType model_type = syncable::APP_SETTINGS;
266 Extension::Type type = Extension::TYPE_PACKAGED_APP; 269 Extension::Type type = Extension::TYPE_PACKAGED_APP;
267 270
268 StringValue value1("fooValue"); 271 StringValue value1("fooValue");
269 ListValue value2; 272 ListValue value2;
270 value2.Append(StringValue::CreateStringValue("barValue")); 273 value2.Append(StringValue::CreateStringValue("barValue"));
271 274
272 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type); 275 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type);
273 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type); 276 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type);
274 277
275 storage1->Set("foo", value1); 278 storage1->Set(DEFAULTS, "foo", value1);
276 storage2->Set("bar", value2); 279 storage2->Set(DEFAULTS, "bar", value2);
277 280
278 std::map<std::string, SettingSyncDataList> all_sync_data = 281 std::map<std::string, SettingSyncDataList> all_sync_data =
279 GetAllSyncData(model_type); 282 GetAllSyncData(model_type);
280 ASSERT_EQ(2u, all_sync_data.size()); 283 ASSERT_EQ(2u, all_sync_data.size());
281 ASSERT_EQ(1u, all_sync_data["s1"].size()); 284 ASSERT_EQ(1u, all_sync_data["s1"].size());
282 ASSERT_PRED_FORMAT2(ValuesEq, &value1, &all_sync_data["s1"][0].value()); 285 ASSERT_PRED_FORMAT2(ValuesEq, &value1, &all_sync_data["s1"][0].value());
283 ASSERT_EQ(1u, all_sync_data["s2"].size()); 286 ASSERT_EQ(1u, all_sync_data["s2"].size());
284 ASSERT_PRED_FORMAT2(ValuesEq, &value2, &all_sync_data["s2"][0].value()); 287 ASSERT_PRED_FORMAT2(ValuesEq, &value2, &all_sync_data["s2"][0].value());
285 288
286 SyncDataList sync_data; 289 SyncDataList sync_data;
287 sync_data.push_back(settings_sync_util::CreateData( 290 sync_data.push_back(settings_sync_util::CreateData(
288 "s1", "foo", value1)); 291 "s1", "foo", value1));
289 sync_data.push_back(settings_sync_util::CreateData( 292 sync_data.push_back(settings_sync_util::CreateData(
290 "s2", "bar", value2)); 293 "s2", "bar", value2));
291 294
292 GetSyncableService(model_type)->MergeDataAndStartSyncing( 295 GetSyncableService(model_type)->MergeDataAndStartSyncing(
293 model_type, sync_data, &sync_); 296 model_type, sync_data, &sync_);
294 297
295 // Already in sync, so no changes. 298 // Already in sync, so no changes.
296 ASSERT_EQ(0u, sync_.changes().size()); 299 ASSERT_EQ(0u, sync_.changes().size());
297 300
298 // Regression test: not-changing the synced value shouldn't result in a sync 301 // Regression test: not-changing the synced value shouldn't result in a sync
299 // change, and changing the synced value should result in an update. 302 // change, and changing the synced value should result in an update.
300 storage1->Set("foo", value1); 303 storage1->Set(DEFAULTS, "foo", value1);
301 ASSERT_EQ(0u, sync_.changes().size()); 304 ASSERT_EQ(0u, sync_.changes().size());
302 305
303 storage1->Set("foo", value2); 306 storage1->Set(DEFAULTS, "foo", value2);
304 ASSERT_EQ(1u, sync_.changes().size()); 307 ASSERT_EQ(1u, sync_.changes().size());
305 SettingSyncData change = sync_.GetOnlyChange("s1", "foo"); 308 SettingSyncData change = sync_.GetOnlyChange("s1", "foo");
306 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); 309 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
307 ASSERT_TRUE(value2.Equals(&change.value())); 310 ASSERT_TRUE(value2.Equals(&change.value()));
308 311
309 GetSyncableService(model_type)->StopSyncing(model_type); 312 GetSyncableService(model_type)->StopSyncing(model_type);
310 } 313 }
311 314
312 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) { 315 TEST_F(ExtensionSettingsSyncTest, LocalDataWithNoSyncDataIsPushedToSync) {
313 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 316 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
314 Extension::Type type = Extension::TYPE_EXTENSION; 317 Extension::Type type = Extension::TYPE_EXTENSION;
315 318
316 StringValue value1("fooValue"); 319 StringValue value1("fooValue");
317 ListValue value2; 320 ListValue value2;
318 value2.Append(StringValue::CreateStringValue("barValue")); 321 value2.Append(StringValue::CreateStringValue("barValue"));
319 322
320 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type); 323 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type);
321 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type); 324 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type);
322 325
323 storage1->Set("foo", value1); 326 storage1->Set(DEFAULTS, "foo", value1);
324 storage2->Set("bar", value2); 327 storage2->Set(DEFAULTS, "bar", value2);
325 328
326 GetSyncableService(model_type)->MergeDataAndStartSyncing( 329 GetSyncableService(model_type)->MergeDataAndStartSyncing(
327 model_type, SyncDataList(), &sync_); 330 model_type, SyncDataList(), &sync_);
328 331
329 // All settings should have been pushed to sync. 332 // All settings should have been pushed to sync.
330 ASSERT_EQ(2u, sync_.changes().size()); 333 ASSERT_EQ(2u, sync_.changes().size());
331 SettingSyncData change = sync_.GetOnlyChange("s1", "foo"); 334 SettingSyncData change = sync_.GetOnlyChange("s1", "foo");
332 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type()); 335 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type());
333 ASSERT_TRUE(value1.Equals(&change.value())); 336 ASSERT_TRUE(value1.Equals(&change.value()));
334 change = sync_.GetOnlyChange("s2", "bar"); 337 change = sync_.GetOnlyChange("s2", "bar");
(...skipping 10 matching lines...) Expand all
345 StringValue value1("fooValue"); 348 StringValue value1("fooValue");
346 ListValue value2; 349 ListValue value2;
347 value2.Append(StringValue::CreateStringValue("barValue")); 350 value2.Append(StringValue::CreateStringValue("barValue"));
348 351
349 // Maintain dictionaries mirrored to the expected values of the settings in 352 // Maintain dictionaries mirrored to the expected values of the settings in
350 // each storage area. 353 // each storage area.
351 DictionaryValue expected1, expected2; 354 DictionaryValue expected1, expected2;
352 355
353 // Pre-populate one of the storage areas. 356 // Pre-populate one of the storage areas.
354 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type); 357 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type);
355 storage1->Set("overwriteMe", value1); 358 storage1->Set(DEFAULTS, "overwriteMe", value1);
356 359
357 SyncDataList sync_data; 360 SyncDataList sync_data;
358 sync_data.push_back(settings_sync_util::CreateData( 361 sync_data.push_back(settings_sync_util::CreateData(
359 "s1", "foo", value1)); 362 "s1", "foo", value1));
360 sync_data.push_back(settings_sync_util::CreateData( 363 sync_data.push_back(settings_sync_util::CreateData(
361 "s2", "bar", value2)); 364 "s2", "bar", value2));
362 GetSyncableService(model_type)->MergeDataAndStartSyncing( 365 GetSyncableService(model_type)->MergeDataAndStartSyncing(
363 model_type, sync_data, &sync_); 366 model_type, sync_data, &sync_);
364 expected1.Set("foo", value1.DeepCopy()); 367 expected1.Set("foo", value1.DeepCopy());
365 expected2.Set("bar", value2.DeepCopy()); 368 expected2.Set("bar", value2.DeepCopy());
(...skipping 19 matching lines...) Expand all
385 value2.Append(StringValue::CreateStringValue("barValue")); 388 value2.Append(StringValue::CreateStringValue("barValue"));
386 389
387 // Maintain dictionaries mirrored to the expected values of the settings in 390 // Maintain dictionaries mirrored to the expected values of the settings in
388 // each storage area. 391 // each storage area.
389 DictionaryValue expected1, expected2; 392 DictionaryValue expected1, expected2;
390 393
391 // Make storage1 initialised from local data, storage2 initialised from sync. 394 // Make storage1 initialised from local data, storage2 initialised from sync.
392 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type); 395 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type);
393 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type); 396 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type);
394 397
395 storage1->Set("foo", value1); 398 storage1->Set(DEFAULTS, "foo", value1);
396 expected1.Set("foo", value1.DeepCopy()); 399 expected1.Set("foo", value1.DeepCopy());
397 400
398 SyncDataList sync_data; 401 SyncDataList sync_data;
399 sync_data.push_back(settings_sync_util::CreateData( 402 sync_data.push_back(settings_sync_util::CreateData(
400 "s2", "bar", value2)); 403 "s2", "bar", value2));
401 404
402 GetSyncableService(model_type)->MergeDataAndStartSyncing( 405 GetSyncableService(model_type)->MergeDataAndStartSyncing(
403 model_type, sync_data, &sync_); 406 model_type, sync_data, &sync_);
404 expected2.Set("bar", value2.DeepCopy()); 407 expected2.Set("bar", value2.DeepCopy());
405 408
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 ListValue value2; 458 ListValue value2;
456 value2.Append(StringValue::CreateStringValue("barValue")); 459 value2.Append(StringValue::CreateStringValue("barValue"));
457 460
458 // Make storage1/2 initialised from local data, storage3/4 initialised from 461 // Make storage1/2 initialised from local data, storage3/4 initialised from
459 // sync. 462 // sync.
460 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type); 463 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type);
461 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type); 464 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type);
462 SettingsStorage* storage3 = AddExtensionAndGetStorage("s3", type); 465 SettingsStorage* storage3 = AddExtensionAndGetStorage("s3", type);
463 SettingsStorage* storage4 = AddExtensionAndGetStorage("s4", type); 466 SettingsStorage* storage4 = AddExtensionAndGetStorage("s4", type);
464 467
465 storage1->Set("foo", value1); 468 storage1->Set(DEFAULTS, "foo", value1);
466 storage2->Set("foo", value1); 469 storage2->Set(DEFAULTS, "foo", value1);
467 470
468 SyncDataList sync_data; 471 SyncDataList sync_data;
469 sync_data.push_back(settings_sync_util::CreateData( 472 sync_data.push_back(settings_sync_util::CreateData(
470 "s3", "bar", value2)); 473 "s3", "bar", value2));
471 sync_data.push_back(settings_sync_util::CreateData( 474 sync_data.push_back(settings_sync_util::CreateData(
472 "s4", "bar", value2)); 475 "s4", "bar", value2));
473 476
474 GetSyncableService(model_type)->MergeDataAndStartSyncing( 477 GetSyncableService(model_type)->MergeDataAndStartSyncing(
475 model_type, sync_data, &sync_); 478 model_type, sync_data, &sync_);
476 479
477 // Add something locally. 480 // Add something locally.
478 storage1->Set("bar", value2); 481 storage1->Set(DEFAULTS, "bar", value2);
479 storage2->Set("bar", value2); 482 storage2->Set(DEFAULTS, "bar", value2);
480 storage3->Set("foo", value1); 483 storage3->Set(DEFAULTS, "foo", value1);
481 storage4->Set("foo", value1); 484 storage4->Set(DEFAULTS, "foo", value1);
482 485
483 SettingSyncData change = sync_.GetOnlyChange("s1", "bar"); 486 SettingSyncData change = sync_.GetOnlyChange("s1", "bar");
484 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type()); 487 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type());
485 ASSERT_TRUE(value2.Equals(&change.value())); 488 ASSERT_TRUE(value2.Equals(&change.value()));
486 sync_.GetOnlyChange("s2", "bar"); 489 sync_.GetOnlyChange("s2", "bar");
487 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type()); 490 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type());
488 ASSERT_TRUE(value2.Equals(&change.value())); 491 ASSERT_TRUE(value2.Equals(&change.value()));
489 change = sync_.GetOnlyChange("s3", "foo"); 492 change = sync_.GetOnlyChange("s3", "foo");
490 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type()); 493 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type());
491 ASSERT_TRUE(value1.Equals(&change.value())); 494 ASSERT_TRUE(value1.Equals(&change.value()));
492 change = sync_.GetOnlyChange("s4", "foo"); 495 change = sync_.GetOnlyChange("s4", "foo");
493 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type()); 496 ASSERT_EQ(SyncChange::ACTION_ADD, change.change_type());
494 ASSERT_TRUE(value1.Equals(&change.value())); 497 ASSERT_TRUE(value1.Equals(&change.value()));
495 498
496 // Change something locally, storage1/3 the new setting and storage2/4 the 499 // Change something locally, storage1/3 the new setting and storage2/4 the
497 // initial setting, for all combinations of local vs sync intialisation and 500 // initial setting, for all combinations of local vs sync intialisation and
498 // new vs initial. 501 // new vs initial.
499 sync_.ClearChanges(); 502 sync_.ClearChanges();
500 storage1->Set("bar", value1); 503 storage1->Set(DEFAULTS, "bar", value1);
501 storage2->Set("foo", value2); 504 storage2->Set(DEFAULTS, "foo", value2);
502 storage3->Set("bar", value1); 505 storage3->Set(DEFAULTS, "bar", value1);
503 storage4->Set("foo", value2); 506 storage4->Set(DEFAULTS, "foo", value2);
504 507
505 change = sync_.GetOnlyChange("s1", "bar"); 508 change = sync_.GetOnlyChange("s1", "bar");
506 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); 509 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
507 ASSERT_TRUE(value1.Equals(&change.value())); 510 ASSERT_TRUE(value1.Equals(&change.value()));
508 change = sync_.GetOnlyChange("s2", "foo"); 511 change = sync_.GetOnlyChange("s2", "foo");
509 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); 512 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
510 ASSERT_TRUE(value2.Equals(&change.value())); 513 ASSERT_TRUE(value2.Equals(&change.value()));
511 change = sync_.GetOnlyChange("s3", "bar"); 514 change = sync_.GetOnlyChange("s3", "bar");
512 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); 515 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
513 ASSERT_TRUE(value1.Equals(&change.value())); 516 ASSERT_TRUE(value1.Equals(&change.value()));
514 change = sync_.GetOnlyChange("s4", "foo"); 517 change = sync_.GetOnlyChange("s4", "foo");
515 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); 518 ASSERT_EQ(SyncChange::ACTION_UPDATE, change.change_type());
516 ASSERT_TRUE(value2.Equals(&change.value())); 519 ASSERT_TRUE(value2.Equals(&change.value()));
517 520
518 // Remove something locally, storage1/3 the new setting and storage2/4 the 521 // Remove something locally, storage1/3 the new setting and storage2/4 the
519 // initial setting, for all combinations of local vs sync intialisation and 522 // initial setting, for all combinations of local vs sync intialisation and
520 // new vs initial. 523 // new vs initial.
521 sync_.ClearChanges(); 524 sync_.ClearChanges();
522 storage1->Remove("foo"); 525 storage1->Remove(DEFAULTS, "foo");
523 storage2->Remove("bar"); 526 storage2->Remove(DEFAULTS, "bar");
524 storage3->Remove("foo"); 527 storage3->Remove(DEFAULTS, "foo");
525 storage4->Remove("bar"); 528 storage4->Remove(DEFAULTS, "bar");
526 529
527 ASSERT_EQ( 530 ASSERT_EQ(
528 SyncChange::ACTION_DELETE, 531 SyncChange::ACTION_DELETE,
529 sync_.GetOnlyChange("s1", "foo").change_type()); 532 sync_.GetOnlyChange("s1", "foo").change_type());
530 ASSERT_EQ( 533 ASSERT_EQ(
531 SyncChange::ACTION_DELETE, 534 SyncChange::ACTION_DELETE,
532 sync_.GetOnlyChange("s2", "bar").change_type()); 535 sync_.GetOnlyChange("s2", "bar").change_type());
533 ASSERT_EQ( 536 ASSERT_EQ(
534 SyncChange::ACTION_DELETE, 537 SyncChange::ACTION_DELETE,
535 sync_.GetOnlyChange("s3", "foo").change_type()); 538 sync_.GetOnlyChange("s3", "foo").change_type());
536 ASSERT_EQ( 539 ASSERT_EQ(
537 SyncChange::ACTION_DELETE, 540 SyncChange::ACTION_DELETE,
538 sync_.GetOnlyChange("s4", "bar").change_type()); 541 sync_.GetOnlyChange("s4", "bar").change_type());
539 542
540 // Remove some nonexistent settings. 543 // Remove some nonexistent settings.
541 sync_.ClearChanges(); 544 sync_.ClearChanges();
542 storage1->Remove("foo"); 545 storage1->Remove(DEFAULTS, "foo");
543 storage2->Remove("bar"); 546 storage2->Remove(DEFAULTS, "bar");
544 storage3->Remove("foo"); 547 storage3->Remove(DEFAULTS, "foo");
545 storage4->Remove("bar"); 548 storage4->Remove(DEFAULTS, "bar");
546 549
547 ASSERT_EQ(0u, sync_.changes().size()); 550 ASSERT_EQ(0u, sync_.changes().size());
548 551
549 // Clear the rest of the settings. Add the removed ones back first so that 552 // Clear the rest of the settings. Add the removed ones back first so that
550 // more than one setting is cleared. 553 // more than one setting is cleared.
551 storage1->Set("foo", value1); 554 storage1->Set(DEFAULTS, "foo", value1);
552 storage2->Set("bar", value2); 555 storage2->Set(DEFAULTS, "bar", value2);
553 storage3->Set("foo", value1); 556 storage3->Set(DEFAULTS, "foo", value1);
554 storage4->Set("bar", value2); 557 storage4->Set(DEFAULTS, "bar", value2);
555 558
556 sync_.ClearChanges(); 559 sync_.ClearChanges();
557 storage1->Clear(); 560 storage1->Clear(DEFAULTS);
558 storage2->Clear(); 561 storage2->Clear(DEFAULTS);
559 storage3->Clear(); 562 storage3->Clear(DEFAULTS);
560 storage4->Clear(); 563 storage4->Clear(DEFAULTS);
561 564
562 ASSERT_EQ( 565 ASSERT_EQ(
563 SyncChange::ACTION_DELETE, 566 SyncChange::ACTION_DELETE,
564 sync_.GetOnlyChange("s1", "foo").change_type()); 567 sync_.GetOnlyChange("s1", "foo").change_type());
565 ASSERT_EQ( 568 ASSERT_EQ(
566 SyncChange::ACTION_DELETE, 569 SyncChange::ACTION_DELETE,
567 sync_.GetOnlyChange("s1", "bar").change_type()); 570 sync_.GetOnlyChange("s1", "bar").change_type());
568 ASSERT_EQ( 571 ASSERT_EQ(
569 SyncChange::ACTION_DELETE, 572 SyncChange::ACTION_DELETE,
570 sync_.GetOnlyChange("s2", "foo").change_type()); 573 sync_.GetOnlyChange("s2", "foo").change_type());
(...skipping 20 matching lines...) Expand all
591 StringValue value1("fooValue"); 594 StringValue value1("fooValue");
592 ListValue value2; 595 ListValue value2;
593 value2.Append(StringValue::CreateStringValue("barValue")); 596 value2.Append(StringValue::CreateStringValue("barValue"));
594 597
595 // storage1 is an extension, storage2 is an app. 598 // storage1 is an extension, storage2 is an app.
596 SettingsStorage* storage1 = AddExtensionAndGetStorage( 599 SettingsStorage* storage1 = AddExtensionAndGetStorage(
597 "s1", Extension::TYPE_EXTENSION); 600 "s1", Extension::TYPE_EXTENSION);
598 SettingsStorage* storage2 = AddExtensionAndGetStorage( 601 SettingsStorage* storage2 = AddExtensionAndGetStorage(
599 "s2", Extension::TYPE_PACKAGED_APP); 602 "s2", Extension::TYPE_PACKAGED_APP);
600 603
601 storage1->Set("foo", value1); 604 storage1->Set(DEFAULTS, "foo", value1);
602 storage2->Set("bar", value2); 605 storage2->Set(DEFAULTS, "bar", value2);
603 606
604 std::map<std::string, SettingSyncDataList> extension_sync_data = 607 std::map<std::string, SettingSyncDataList> extension_sync_data =
605 GetAllSyncData(syncable::EXTENSION_SETTINGS); 608 GetAllSyncData(syncable::EXTENSION_SETTINGS);
606 ASSERT_EQ(1u, extension_sync_data.size()); 609 ASSERT_EQ(1u, extension_sync_data.size());
607 ASSERT_EQ(1u, extension_sync_data["s1"].size()); 610 ASSERT_EQ(1u, extension_sync_data["s1"].size());
608 ASSERT_PRED_FORMAT2(ValuesEq, &value1, &extension_sync_data["s1"][0].value()); 611 ASSERT_PRED_FORMAT2(ValuesEq, &value1, &extension_sync_data["s1"][0].value());
609 612
610 std::map<std::string, SettingSyncDataList> app_sync_data = 613 std::map<std::string, SettingSyncDataList> app_sync_data =
611 GetAllSyncData(syncable::APP_SETTINGS); 614 GetAllSyncData(syncable::APP_SETTINGS);
612 ASSERT_EQ(1u, app_sync_data.size()); 615 ASSERT_EQ(1u, app_sync_data.size());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 dict.Set("foo", fooValue.DeepCopy()); 673 dict.Set("foo", fooValue.DeepCopy());
671 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 674 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
672 } 675 }
673 { 676 {
674 DictionaryValue dict; 677 DictionaryValue dict;
675 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 678 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
676 } 679 }
677 680
678 // Changes made to good should be sent to sync, changes from bad shouldn't. 681 // Changes made to good should be sent to sync, changes from bad shouldn't.
679 sync_.ClearChanges(); 682 sync_.ClearChanges();
680 good->Set("bar", barValue); 683 good->Set(DEFAULTS, "bar", barValue);
681 bad->Set("bar", barValue); 684 bad->Set(DEFAULTS, "bar", barValue);
682 685
683 EXPECT_EQ( 686 EXPECT_EQ(
684 SyncChange::ACTION_ADD, 687 SyncChange::ACTION_ADD,
685 sync_.GetOnlyChange("good", "bar").change_type()); 688 sync_.GetOnlyChange("good", "bar").change_type());
686 EXPECT_EQ(1u, sync_.changes().size()); 689 EXPECT_EQ(1u, sync_.changes().size());
687 690
688 { 691 {
689 DictionaryValue dict; 692 DictionaryValue dict;
690 dict.Set("foo", fooValue.DeepCopy()); 693 dict.Set("foo", fooValue.DeepCopy());
691 dict.Set("bar", barValue.DeepCopy()); 694 dict.Set("bar", barValue.DeepCopy());
(...skipping 26 matching lines...) Expand all
718 } 721 }
719 { 722 {
720 DictionaryValue dict; 723 DictionaryValue dict;
721 dict.Set("bar", barValue.DeepCopy()); 724 dict.Set("bar", barValue.DeepCopy());
722 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 725 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
723 } 726 }
724 727
725 // Changes made to bad still shouldn't go to sync, even though it didn't fail 728 // Changes made to bad still shouldn't go to sync, even though it didn't fail
726 // last time. 729 // last time.
727 sync_.ClearChanges(); 730 sync_.ClearChanges();
728 good->Set("bar", fooValue); 731 good->Set(DEFAULTS, "bar", fooValue);
729 bad->Set("bar", fooValue); 732 bad->Set(DEFAULTS, "bar", fooValue);
730 733
731 EXPECT_EQ( 734 EXPECT_EQ(
732 SyncChange::ACTION_UPDATE, 735 SyncChange::ACTION_UPDATE,
733 sync_.GetOnlyChange("good", "bar").change_type()); 736 sync_.GetOnlyChange("good", "bar").change_type());
734 EXPECT_EQ(1u, sync_.changes().size()); 737 EXPECT_EQ(1u, sync_.changes().size());
735 738
736 { 739 {
737 DictionaryValue dict; 740 DictionaryValue dict;
738 dict.Set("foo", barValue.DeepCopy()); 741 dict.Set("foo", barValue.DeepCopy());
739 dict.Set("bar", fooValue.DeepCopy()); 742 dict.Set("bar", fooValue.DeepCopy());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 EXPECT_EQ( 787 EXPECT_EQ(
785 SyncChange::ACTION_ADD, 788 SyncChange::ACTION_ADD,
786 sync_.GetOnlyChange("good", "bar").change_type()); 789 sync_.GetOnlyChange("good", "bar").change_type());
787 EXPECT_EQ( 790 EXPECT_EQ(
788 SyncChange::ACTION_ADD, 791 SyncChange::ACTION_ADD,
789 sync_.GetOnlyChange("bad", "bar").change_type()); 792 sync_.GetOnlyChange("bad", "bar").change_type());
790 EXPECT_EQ(3u, sync_.changes().size()); 793 EXPECT_EQ(3u, sync_.changes().size());
791 794
792 // Live local changes now get pushed, too. 795 // Live local changes now get pushed, too.
793 sync_.ClearChanges(); 796 sync_.ClearChanges();
794 good->Set("bar", barValue); 797 good->Set(DEFAULTS, "bar", barValue);
795 bad->Set("bar", barValue); 798 bad->Set(DEFAULTS, "bar", barValue);
796 799
797 EXPECT_EQ( 800 EXPECT_EQ(
798 SyncChange::ACTION_UPDATE, 801 SyncChange::ACTION_UPDATE,
799 sync_.GetOnlyChange("good", "bar").change_type()); 802 sync_.GetOnlyChange("good", "bar").change_type());
800 EXPECT_EQ( 803 EXPECT_EQ(
801 SyncChange::ACTION_UPDATE, 804 SyncChange::ACTION_UPDATE,
802 sync_.GetOnlyChange("bad", "bar").change_type()); 805 sync_.GetOnlyChange("bad", "bar").change_type());
803 EXPECT_EQ(2u, sync_.changes().size()); 806 EXPECT_EQ(2u, sync_.changes().size());
804 807
805 // And ProcessSyncChanges work, too. 808 // And ProcessSyncChanges work, too.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get()); 887 EXPECT_PRED_FORMAT2(SettingsEq, dict, good->Get());
885 } 888 }
886 { 889 {
887 DictionaryValue dict; 890 DictionaryValue dict;
888 dict.Set("foo", fooValue.DeepCopy()); 891 dict.Set("foo", fooValue.DeepCopy());
889 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get()); 892 EXPECT_PRED_FORMAT2(SettingsEq, dict, bad->Get());
890 } 893 }
891 894
892 // No more changes sent to sync for bad. 895 // No more changes sent to sync for bad.
893 sync_.ClearChanges(); 896 sync_.ClearChanges();
894 good->Set("foo", barValue); 897 good->Set(DEFAULTS, "foo", barValue);
895 bad->Set("foo", barValue); 898 bad->Set(DEFAULTS, "foo", barValue);
896 899
897 EXPECT_EQ( 900 EXPECT_EQ(
898 SyncChange::ACTION_UPDATE, 901 SyncChange::ACTION_UPDATE,
899 sync_.GetOnlyChange("good", "foo").change_type()); 902 sync_.GetOnlyChange("good", "foo").change_type());
900 EXPECT_EQ(1u, sync_.changes().size()); 903 EXPECT_EQ(1u, sync_.changes().size());
901 904
902 // No more changes received from sync should go to bad. 905 // No more changes received from sync should go to bad.
903 { 906 {
904 SyncChangeList change_list; 907 SyncChangeList change_list;
905 change_list.push_back( 908 change_list.push_back(
(...skipping 23 matching lines...) Expand all
929 StringValue fooValue("fooValue"); 932 StringValue fooValue("fooValue");
930 StringValue barValue("barValue"); 933 StringValue barValue("barValue");
931 934
932 TestingSettingsStorageFactory* testing_factory = 935 TestingSettingsStorageFactory* testing_factory =
933 new TestingSettingsStorageFactory(); 936 new TestingSettingsStorageFactory();
934 storage_factory_->Reset(testing_factory); 937 storage_factory_->Reset(testing_factory);
935 938
936 SettingsStorage* good = AddExtensionAndGetStorage("good", type); 939 SettingsStorage* good = AddExtensionAndGetStorage("good", type);
937 SettingsStorage* bad = AddExtensionAndGetStorage("bad", type); 940 SettingsStorage* bad = AddExtensionAndGetStorage("bad", type);
938 941
939 good->Set("foo", fooValue); 942 good->Set(DEFAULTS, "foo", fooValue);
940 bad->Set("foo", fooValue); 943 bad->Set(DEFAULTS, "foo", fooValue);
941 944
942 // Even though bad will fail to get all sync data, sync data should still 945 // Even though bad will fail to get all sync data, sync data should still
943 // include that from good. 946 // include that from good.
944 testing_factory->GetExisting("bad")->SetFailAllRequests(true); 947 testing_factory->GetExisting("bad")->SetFailAllRequests(true);
945 { 948 {
946 SyncDataList all_sync_data = 949 SyncDataList all_sync_data =
947 GetSyncableService(model_type)->GetAllSyncData(model_type); 950 GetSyncableService(model_type)->GetAllSyncData(model_type);
948 EXPECT_EQ(1u, all_sync_data.size()); 951 EXPECT_EQ(1u, all_sync_data.size());
949 EXPECT_EQ("good/foo", all_sync_data[0].GetTag()); 952 EXPECT_EQ("good/foo", all_sync_data[0].GetTag());
950 } 953 }
951 testing_factory->GetExisting("bad")->SetFailAllRequests(false); 954 testing_factory->GetExisting("bad")->SetFailAllRequests(false);
952 955
953 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant). 956 // Sync shouldn't be disabled for good (nor bad -- but this is unimportant).
954 GetSyncableService(model_type)->MergeDataAndStartSyncing( 957 GetSyncableService(model_type)->MergeDataAndStartSyncing(
955 model_type, SyncDataList(), &sync_); 958 model_type, SyncDataList(), &sync_);
956 959
957 EXPECT_EQ( 960 EXPECT_EQ(
958 SyncChange::ACTION_ADD, 961 SyncChange::ACTION_ADD,
959 sync_.GetOnlyChange("good", "foo").change_type()); 962 sync_.GetOnlyChange("good", "foo").change_type());
960 EXPECT_EQ( 963 EXPECT_EQ(
961 SyncChange::ACTION_ADD, 964 SyncChange::ACTION_ADD,
962 sync_.GetOnlyChange("bad", "foo").change_type()); 965 sync_.GetOnlyChange("bad", "foo").change_type());
963 EXPECT_EQ(2u, sync_.changes().size()); 966 EXPECT_EQ(2u, sync_.changes().size());
964 967
965 sync_.ClearChanges(); 968 sync_.ClearChanges();
966 good->Set("bar", barValue); 969 good->Set(DEFAULTS, "bar", barValue);
967 bad->Set("bar", barValue); 970 bad->Set(DEFAULTS, "bar", barValue);
968 971
969 EXPECT_EQ( 972 EXPECT_EQ(
970 SyncChange::ACTION_ADD, 973 SyncChange::ACTION_ADD,
971 sync_.GetOnlyChange("good", "bar").change_type()); 974 sync_.GetOnlyChange("good", "bar").change_type());
972 EXPECT_EQ( 975 EXPECT_EQ(
973 SyncChange::ACTION_ADD, 976 SyncChange::ACTION_ADD,
974 sync_.GetOnlyChange("bad", "bar").change_type()); 977 sync_.GetOnlyChange("bad", "bar").change_type());
975 EXPECT_EQ(2u, sync_.changes().size()); 978 EXPECT_EQ(2u, sync_.changes().size());
976 } 979 }
977 980
978 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) { 981 TEST_F(ExtensionSettingsSyncTest, FailureToReadChangesToPushDisablesSync) {
979 syncable::ModelType model_type = syncable::APP_SETTINGS; 982 syncable::ModelType model_type = syncable::APP_SETTINGS;
980 Extension::Type type = Extension::TYPE_PACKAGED_APP; 983 Extension::Type type = Extension::TYPE_PACKAGED_APP;
981 984
982 StringValue fooValue("fooValue"); 985 StringValue fooValue("fooValue");
983 StringValue barValue("barValue"); 986 StringValue barValue("barValue");
984 987
985 TestingSettingsStorageFactory* testing_factory = 988 TestingSettingsStorageFactory* testing_factory =
986 new TestingSettingsStorageFactory(); 989 new TestingSettingsStorageFactory();
987 storage_factory_->Reset(testing_factory); 990 storage_factory_->Reset(testing_factory);
988 991
989 SettingsStorage* good = AddExtensionAndGetStorage("good", type); 992 SettingsStorage* good = AddExtensionAndGetStorage("good", type);
990 SettingsStorage* bad = AddExtensionAndGetStorage("bad", type); 993 SettingsStorage* bad = AddExtensionAndGetStorage("bad", type);
991 994
992 good->Set("foo", fooValue); 995 good->Set(DEFAULTS, "foo", fooValue);
993 bad->Set("foo", fooValue); 996 bad->Set(DEFAULTS, "foo", fooValue);
994 997
995 // good will successfully push foo:fooValue to sync, but bad will fail to 998 // good will successfully push foo:fooValue to sync, but bad will fail to
996 // get them so won't. 999 // get them so won't.
997 testing_factory->GetExisting("bad")->SetFailAllRequests(true); 1000 testing_factory->GetExisting("bad")->SetFailAllRequests(true);
998 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1001 GetSyncableService(model_type)->MergeDataAndStartSyncing(
999 model_type, SyncDataList(), &sync_); 1002 model_type, SyncDataList(), &sync_);
1000 testing_factory->GetExisting("bad")->SetFailAllRequests(false); 1003 testing_factory->GetExisting("bad")->SetFailAllRequests(false);
1001 1004
1002 EXPECT_EQ( 1005 EXPECT_EQ(
1003 SyncChange::ACTION_ADD, 1006 SyncChange::ACTION_ADD,
1004 sync_.GetOnlyChange("good", "foo").change_type()); 1007 sync_.GetOnlyChange("good", "foo").change_type());
1005 EXPECT_EQ(1u, sync_.changes().size()); 1008 EXPECT_EQ(1u, sync_.changes().size());
1006 1009
1007 // bad should now be disabled for sync. 1010 // bad should now be disabled for sync.
1008 sync_.ClearChanges(); 1011 sync_.ClearChanges();
1009 good->Set("bar", barValue); 1012 good->Set(DEFAULTS, "bar", barValue);
1010 bad->Set("bar", barValue); 1013 bad->Set(DEFAULTS, "bar", barValue);
1011 1014
1012 EXPECT_EQ( 1015 EXPECT_EQ(
1013 SyncChange::ACTION_ADD, 1016 SyncChange::ACTION_ADD,
1014 sync_.GetOnlyChange("good", "bar").change_type()); 1017 sync_.GetOnlyChange("good", "bar").change_type());
1015 EXPECT_EQ(1u, sync_.changes().size()); 1018 EXPECT_EQ(1u, sync_.changes().size());
1016 1019
1017 { 1020 {
1018 SyncChangeList change_list; 1021 SyncChangeList change_list;
1019 change_list.push_back( 1022 change_list.push_back(
1020 settings_sync_util::CreateUpdate("good", "foo", barValue)); 1023 settings_sync_util::CreateUpdate("good", "foo", barValue));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 sync_.GetOnlyChange("good", "bar").change_type()); 1056 sync_.GetOnlyChange("good", "bar").change_type());
1054 EXPECT_EQ( 1057 EXPECT_EQ(
1055 SyncChange::ACTION_ADD, 1058 SyncChange::ACTION_ADD,
1056 sync_.GetOnlyChange("bad", "foo").change_type()); 1059 sync_.GetOnlyChange("bad", "foo").change_type());
1057 EXPECT_EQ( 1060 EXPECT_EQ(
1058 SyncChange::ACTION_ADD, 1061 SyncChange::ACTION_ADD,
1059 sync_.GetOnlyChange("bad", "bar").change_type()); 1062 sync_.GetOnlyChange("bad", "bar").change_type());
1060 EXPECT_EQ(4u, sync_.changes().size()); 1063 EXPECT_EQ(4u, sync_.changes().size());
1061 1064
1062 sync_.ClearChanges(); 1065 sync_.ClearChanges();
1063 good->Set("bar", fooValue); 1066 good->Set(DEFAULTS, "bar", fooValue);
1064 bad->Set("bar", fooValue); 1067 bad->Set(DEFAULTS, "bar", fooValue);
1065 1068
1066 EXPECT_EQ( 1069 EXPECT_EQ(
1067 SyncChange::ACTION_UPDATE, 1070 SyncChange::ACTION_UPDATE,
1068 sync_.GetOnlyChange("good", "bar").change_type()); 1071 sync_.GetOnlyChange("good", "bar").change_type());
1069 EXPECT_EQ( 1072 EXPECT_EQ(
1070 SyncChange::ACTION_UPDATE, 1073 SyncChange::ACTION_UPDATE,
1071 sync_.GetOnlyChange("good", "bar").change_type()); 1074 sync_.GetOnlyChange("good", "bar").change_type());
1072 EXPECT_EQ(2u, sync_.changes().size()); 1075 EXPECT_EQ(2u, sync_.changes().size());
1073 } 1076 }
1074 1077
1075 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) { 1078 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalStateDisablesSync) {
1076 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 1079 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
1077 Extension::Type type = Extension::TYPE_EXTENSION; 1080 Extension::Type type = Extension::TYPE_EXTENSION;
1078 1081
1079 StringValue fooValue("fooValue"); 1082 StringValue fooValue("fooValue");
1080 StringValue barValue("barValue"); 1083 StringValue barValue("barValue");
1081 1084
1082 TestingSettingsStorageFactory* testing_factory = 1085 TestingSettingsStorageFactory* testing_factory =
1083 new TestingSettingsStorageFactory(); 1086 new TestingSettingsStorageFactory();
1084 storage_factory_->Reset(testing_factory); 1087 storage_factory_->Reset(testing_factory);
1085 1088
1086 SettingsStorage* good = AddExtensionAndGetStorage("good", type); 1089 SettingsStorage* good = AddExtensionAndGetStorage("good", type);
1087 SettingsStorage* bad = AddExtensionAndGetStorage("bad", type); 1090 SettingsStorage* bad = AddExtensionAndGetStorage("bad", type);
1088 1091
1089 // Only set bad; setting good will cause it to fail below. 1092 // Only set bad; setting good will cause it to fail below.
1090 bad->Set("foo", fooValue); 1093 bad->Set(DEFAULTS, "foo", fooValue);
1091 1094
1092 sync_.SetFailAllRequests(true); 1095 sync_.SetFailAllRequests(true);
1093 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1096 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1094 model_type, SyncDataList(), &sync_); 1097 model_type, SyncDataList(), &sync_);
1095 sync_.SetFailAllRequests(false); 1098 sync_.SetFailAllRequests(false);
1096 1099
1097 // Changes from good will be send to sync, changes from bad won't. 1100 // Changes from good will be send to sync, changes from bad won't.
1098 sync_.ClearChanges(); 1101 sync_.ClearChanges();
1099 good->Set("foo", barValue); 1102 good->Set(DEFAULTS, "foo", barValue);
1100 bad->Set("foo", barValue); 1103 bad->Set(DEFAULTS, "foo", barValue);
1101 1104
1102 EXPECT_EQ( 1105 EXPECT_EQ(
1103 SyncChange::ACTION_ADD, 1106 SyncChange::ACTION_ADD,
1104 sync_.GetOnlyChange("good", "foo").change_type()); 1107 sync_.GetOnlyChange("good", "foo").change_type());
1105 EXPECT_EQ(1u, sync_.changes().size()); 1108 EXPECT_EQ(1u, sync_.changes().size());
1106 1109
1107 // Changes from sync will be sent to good, not to bad. 1110 // Changes from sync will be sent to good, not to bad.
1108 { 1111 {
1109 SyncChangeList change_list; 1112 SyncChangeList change_list;
1110 change_list.push_back( 1113 change_list.push_back(
(...skipping 26 matching lines...) Expand all
1137 sync_.GetOnlyChange("good", "foo").change_type()); 1140 sync_.GetOnlyChange("good", "foo").change_type());
1138 EXPECT_EQ( 1141 EXPECT_EQ(
1139 SyncChange::ACTION_ADD, 1142 SyncChange::ACTION_ADD,
1140 sync_.GetOnlyChange("good", "bar").change_type()); 1143 sync_.GetOnlyChange("good", "bar").change_type());
1141 EXPECT_EQ( 1144 EXPECT_EQ(
1142 SyncChange::ACTION_ADD, 1145 SyncChange::ACTION_ADD,
1143 sync_.GetOnlyChange("bad", "foo").change_type()); 1146 sync_.GetOnlyChange("bad", "foo").change_type());
1144 EXPECT_EQ(3u, sync_.changes().size()); 1147 EXPECT_EQ(3u, sync_.changes().size());
1145 1148
1146 sync_.ClearChanges(); 1149 sync_.ClearChanges();
1147 good->Set("foo", fooValue); 1150 good->Set(DEFAULTS, "foo", fooValue);
1148 bad->Set("foo", fooValue); 1151 bad->Set(DEFAULTS, "foo", fooValue);
1149 1152
1150 EXPECT_EQ( 1153 EXPECT_EQ(
1151 SyncChange::ACTION_UPDATE, 1154 SyncChange::ACTION_UPDATE,
1152 sync_.GetOnlyChange("good", "foo").change_type()); 1155 sync_.GetOnlyChange("good", "foo").change_type());
1153 EXPECT_EQ( 1156 EXPECT_EQ(
1154 SyncChange::ACTION_UPDATE, 1157 SyncChange::ACTION_UPDATE,
1155 sync_.GetOnlyChange("good", "foo").change_type()); 1158 sync_.GetOnlyChange("good", "foo").change_type());
1156 EXPECT_EQ(2u, sync_.changes().size()); 1159 EXPECT_EQ(2u, sync_.changes().size());
1157 } 1160 }
1158 1161
1159 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) { 1162 TEST_F(ExtensionSettingsSyncTest, FailureToPushLocalChangeDisablesSync) {
1160 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS; 1163 syncable::ModelType model_type = syncable::EXTENSION_SETTINGS;
1161 Extension::Type type = Extension::TYPE_EXTENSION; 1164 Extension::Type type = Extension::TYPE_EXTENSION;
1162 1165
1163 StringValue fooValue("fooValue"); 1166 StringValue fooValue("fooValue");
1164 StringValue barValue("barValue"); 1167 StringValue barValue("barValue");
1165 1168
1166 TestingSettingsStorageFactory* testing_factory = 1169 TestingSettingsStorageFactory* testing_factory =
1167 new TestingSettingsStorageFactory(); 1170 new TestingSettingsStorageFactory();
1168 storage_factory_->Reset(testing_factory); 1171 storage_factory_->Reset(testing_factory);
1169 1172
1170 SettingsStorage* good = AddExtensionAndGetStorage("good", type); 1173 SettingsStorage* good = AddExtensionAndGetStorage("good", type);
1171 SettingsStorage* bad = AddExtensionAndGetStorage("bad", type); 1174 SettingsStorage* bad = AddExtensionAndGetStorage("bad", type);
1172 1175
1173 GetSyncableService(model_type)->MergeDataAndStartSyncing( 1176 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1174 model_type, SyncDataList(), &sync_); 1177 model_type, SyncDataList(), &sync_);
1175 1178
1176 // bad will fail to send changes. 1179 // bad will fail to send changes.
1177 good->Set("foo", fooValue); 1180 good->Set(DEFAULTS, "foo", fooValue);
1178 sync_.SetFailAllRequests(true); 1181 sync_.SetFailAllRequests(true);
1179 bad->Set("foo", fooValue); 1182 bad->Set(DEFAULTS, "foo", fooValue);
1180 sync_.SetFailAllRequests(false); 1183 sync_.SetFailAllRequests(false);
1181 1184
1182 EXPECT_EQ( 1185 EXPECT_EQ(
1183 SyncChange::ACTION_ADD, 1186 SyncChange::ACTION_ADD,
1184 sync_.GetOnlyChange("good", "foo").change_type()); 1187 sync_.GetOnlyChange("good", "foo").change_type());
1185 EXPECT_EQ(1u, sync_.changes().size()); 1188 EXPECT_EQ(1u, sync_.changes().size());
1186 1189
1187 // No further changes should be sent from bad. 1190 // No further changes should be sent from bad.
1188 sync_.ClearChanges(); 1191 sync_.ClearChanges();
1189 good->Set("foo", barValue); 1192 good->Set(DEFAULTS, "foo", barValue);
1190 bad->Set("foo", barValue); 1193 bad->Set(DEFAULTS, "foo", barValue);
1191 1194
1192 EXPECT_EQ( 1195 EXPECT_EQ(
1193 SyncChange::ACTION_UPDATE, 1196 SyncChange::ACTION_UPDATE,
1194 sync_.GetOnlyChange("good", "foo").change_type()); 1197 sync_.GetOnlyChange("good", "foo").change_type());
1195 EXPECT_EQ(1u, sync_.changes().size()); 1198 EXPECT_EQ(1u, sync_.changes().size());
1196 1199
1197 // Changes from sync will be sent to good, not to bad. 1200 // Changes from sync will be sent to good, not to bad.
1198 { 1201 {
1199 SyncChangeList change_list; 1202 SyncChangeList change_list;
1200 change_list.push_back( 1203 change_list.push_back(
(...skipping 26 matching lines...) Expand all
1227 sync_.GetOnlyChange("good", "foo").change_type()); 1230 sync_.GetOnlyChange("good", "foo").change_type());
1228 EXPECT_EQ( 1231 EXPECT_EQ(
1229 SyncChange::ACTION_ADD, 1232 SyncChange::ACTION_ADD,
1230 sync_.GetOnlyChange("good", "bar").change_type()); 1233 sync_.GetOnlyChange("good", "bar").change_type());
1231 EXPECT_EQ( 1234 EXPECT_EQ(
1232 SyncChange::ACTION_ADD, 1235 SyncChange::ACTION_ADD,
1233 sync_.GetOnlyChange("bad", "foo").change_type()); 1236 sync_.GetOnlyChange("bad", "foo").change_type());
1234 EXPECT_EQ(3u, sync_.changes().size()); 1237 EXPECT_EQ(3u, sync_.changes().size());
1235 1238
1236 sync_.ClearChanges(); 1239 sync_.ClearChanges();
1237 good->Set("foo", fooValue); 1240 good->Set(DEFAULTS, "foo", fooValue);
1238 bad->Set("foo", fooValue); 1241 bad->Set(DEFAULTS, "foo", fooValue);
1239 1242
1240 EXPECT_EQ( 1243 EXPECT_EQ(
1241 SyncChange::ACTION_UPDATE, 1244 SyncChange::ACTION_UPDATE,
1242 sync_.GetOnlyChange("good", "foo").change_type()); 1245 sync_.GetOnlyChange("good", "foo").change_type());
1243 EXPECT_EQ( 1246 EXPECT_EQ(
1244 SyncChange::ACTION_UPDATE, 1247 SyncChange::ACTION_UPDATE,
1245 sync_.GetOnlyChange("good", "foo").change_type()); 1248 sync_.GetOnlyChange("good", "foo").change_type());
1246 EXPECT_EQ(2u, sync_.changes().size()); 1249 EXPECT_EQ(2u, sync_.changes().size());
1247 } 1250 }
1248 1251
1252 TEST_F(ExtensionSettingsSyncTest,
1253 LargeOutgoingChangeRejectedButIncomingAccepted) {
not at google - send to devlin 2011/11/17 07:02:53 Change #4: another test
1254 syncable::ModelType model_type = syncable::APP_SETTINGS;
1255 Extension::Type type = Extension::TYPE_PACKAGED_APP;
1256
1257 // This value should be larger than the limit in settings_backend.cc.
1258 std::string string_5k;
1259 for (size_t i = 0; i < 5000; ++i) {
1260 string_5k.append("a");
1261 }
1262 StringValue large_value(string_5k);
1263
1264 GetSyncableService(model_type)->MergeDataAndStartSyncing(
1265 model_type, SyncDataList(), &sync_);
1266
1267 // Large local change rejected and doesn't get sent out.
1268 SettingsStorage* storage1 = AddExtensionAndGetStorage("s1", type);
1269 EXPECT_TRUE(storage1->Set(DEFAULTS, "large_value", large_value).HasError());
1270 EXPECT_EQ(0u, sync_.changes().size());
1271
1272 // Large incoming change should still get accepted.
1273 SettingsStorage* storage2 = AddExtensionAndGetStorage("s2", type);
1274 {
1275 SyncChangeList change_list;
1276 change_list.push_back(
1277 settings_sync_util::CreateAdd("s1", "large_value", large_value));
1278 change_list.push_back(
1279 settings_sync_util::CreateAdd("s2", "large_value", large_value));
1280 GetSyncableService(model_type)->ProcessSyncChanges(FROM_HERE, change_list);
1281 }
1282 {
1283 DictionaryValue expected;
1284 expected.Set("large_value", large_value.DeepCopy());
1285 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage1->Get());
1286 EXPECT_PRED_FORMAT2(SettingsEq, expected, storage2->Get());
1287 }
1288
1289 GetSyncableService(model_type)->StopSyncing(model_type);
1290 }
1291
1249 } // namespace extensions 1292 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698