OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 return 1 == dir_->kernel_->metahandles_to_purge->count(metahandle); | 453 return 1 == dir_->kernel_->metahandles_to_purge->count(metahandle); |
454 } | 454 } |
455 | 455 |
456 void CheckPurgeEntriesWithTypeInSucceeded(ModelTypeSet types_to_purge, | 456 void CheckPurgeEntriesWithTypeInSucceeded(ModelTypeSet types_to_purge, |
457 bool before_reload) { | 457 bool before_reload) { |
458 SCOPED_TRACE(testing::Message("Before reload: ") << before_reload); | 458 SCOPED_TRACE(testing::Message("Before reload: ") << before_reload); |
459 { | 459 { |
460 ReadTransaction trans(FROM_HERE, dir_.get()); | 460 ReadTransaction trans(FROM_HERE, dir_.get()); |
461 MetahandleSet all_set; | 461 MetahandleSet all_set; |
462 dir_->GetAllMetaHandles(&trans, &all_set); | 462 dir_->GetAllMetaHandles(&trans, &all_set); |
463 EXPECT_EQ(3U, all_set.size()); | 463 EXPECT_EQ(4U, all_set.size()); |
464 if (before_reload) | 464 if (before_reload) |
465 EXPECT_EQ(4U, dir_->kernel_->metahandles_to_purge->size()); | 465 EXPECT_EQ(6U, dir_->kernel_->metahandles_to_purge->size()); |
466 for (MetahandleSet::iterator iter = all_set.begin(); | 466 for (MetahandleSet::iterator iter = all_set.begin(); |
467 iter != all_set.end(); ++iter) { | 467 iter != all_set.end(); ++iter) { |
468 Entry e(&trans, GET_BY_HANDLE, *iter); | 468 Entry e(&trans, GET_BY_HANDLE, *iter); |
469 const ModelType local_type = e.GetModelType(); | 469 const ModelType local_type = e.GetModelType(); |
470 const ModelType server_type = e.GetServerModelType(); | 470 const ModelType server_type = e.GetServerModelType(); |
471 | 471 |
472 // Note the dance around incrementing |it|, since we sometimes erase(). | 472 // Note the dance around incrementing |it|, since we sometimes erase(). |
473 if ((IsRealDataType(local_type) && | 473 if ((IsRealDataType(local_type) && |
474 types_to_purge.Has(local_type)) || | 474 types_to_purge.Has(local_type)) || |
475 (IsRealDataType(server_type) && | 475 (IsRealDataType(server_type) && |
476 types_to_purge.Has(server_type))) { | 476 types_to_purge.Has(server_type))) { |
477 FAIL() << "Illegal type should have been deleted."; | 477 FAIL() << "Illegal type should have been deleted."; |
478 } | 478 } |
479 } | 479 } |
480 } | 480 } |
481 | 481 |
482 for (ModelTypeSet::Iterator it = types_to_purge.First(); | 482 for (ModelTypeSet::Iterator it = types_to_purge.First(); |
483 it.Good(); it.Inc()) { | 483 it.Good(); it.Inc()) { |
484 EXPECT_FALSE(dir_->initial_sync_ended_for_type(it.Get())); | 484 EXPECT_FALSE(dir_->InitialSyncEndedForType(it.Get())); |
485 } | 485 } |
486 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS)); | 486 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS)); |
487 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS)); | 487 EXPECT_TRUE(dir_->InitialSyncEndedForType(BOOKMARKS)); |
488 } | 488 } |
489 | 489 |
490 FakeEncryptor encryptor_; | 490 FakeEncryptor encryptor_; |
491 TestUnrecoverableErrorHandler handler_; | 491 TestUnrecoverableErrorHandler handler_; |
492 scoped_ptr<Directory> dir_; | 492 scoped_ptr<Directory> dir_; |
493 NullDirectoryChangeDelegate delegate_; | 493 NullDirectoryChangeDelegate delegate_; |
494 | 494 |
495 // Creates an empty entry and sets the ID field to a default one. | 495 // Creates an empty entry and sets the ID field to a default one. |
496 void CreateEntry(const std::string& entryname) { | 496 void CreateEntry(const std::string& entryname) { |
497 CreateEntry(entryname, TestIdFactory::FromNumber(-99)); | 497 CreateEntry(entryname, TestIdFactory::FromNumber(-99)); |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 FilePath file_path_; | 1543 FilePath file_path_; |
1544 }; | 1544 }; |
1545 | 1545 |
1546 TEST_F(OnDiskSyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { | 1546 TEST_F(OnDiskSyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { |
1547 sync_pb::EntitySpecifics bookmark_specs; | 1547 sync_pb::EntitySpecifics bookmark_specs; |
1548 sync_pb::EntitySpecifics autofill_specs; | 1548 sync_pb::EntitySpecifics autofill_specs; |
1549 sync_pb::EntitySpecifics preference_specs; | 1549 sync_pb::EntitySpecifics preference_specs; |
1550 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); | 1550 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); |
1551 AddDefaultFieldValue(PREFERENCES, &preference_specs); | 1551 AddDefaultFieldValue(PREFERENCES, &preference_specs); |
1552 AddDefaultFieldValue(AUTOFILL, &autofill_specs); | 1552 AddDefaultFieldValue(AUTOFILL, &autofill_specs); |
1553 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); | |
1554 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); | |
1555 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); | |
1556 | 1553 |
1557 ModelTypeSet types_to_purge(PREFERENCES, AUTOFILL); | 1554 ModelTypeSet types_to_purge(PREFERENCES, AUTOFILL); |
1558 | 1555 |
1559 TestIdFactory id_factory; | 1556 TestIdFactory id_factory; |
1560 // Create some items for each type. | 1557 // Create some items for each type. |
1561 { | 1558 { |
1562 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1559 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 1560 |
| 1561 // Make it look like these types have completed initial sync. |
| 1562 CreateTypeRoot(&trans, dir_.get(), BOOKMARKS); |
| 1563 CreateTypeRoot(&trans, dir_.get(), PREFERENCES); |
| 1564 CreateTypeRoot(&trans, dir_.get(), AUTOFILL); |
| 1565 |
| 1566 // Add more nodes for this type. Technically, they should be placed under |
| 1567 // the proper type root nodes but the assertions in this test won't notice |
| 1568 // if their parent isn't quite right. |
1563 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); | 1569 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); |
1564 ASSERT_TRUE(item1.good()); | 1570 ASSERT_TRUE(item1.good()); |
1565 item1.Put(SPECIFICS, bookmark_specs); | 1571 item1.Put(SPECIFICS, bookmark_specs); |
1566 item1.Put(SERVER_SPECIFICS, bookmark_specs); | 1572 item1.Put(SERVER_SPECIFICS, bookmark_specs); |
1567 item1.Put(IS_UNSYNCED, true); | 1573 item1.Put(IS_UNSYNCED, true); |
1568 | 1574 |
1569 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM, | 1575 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM, |
1570 id_factory.NewServerId()); | 1576 id_factory.NewServerId()); |
1571 ASSERT_TRUE(item2.good()); | 1577 ASSERT_TRUE(item2.good()); |
1572 item2.Put(SERVER_SPECIFICS, bookmark_specs); | 1578 item2.Put(SERVER_SPECIFICS, bookmark_specs); |
(...skipping 22 matching lines...) Expand all Loading... |
1595 ASSERT_TRUE(item6.good()); | 1601 ASSERT_TRUE(item6.good()); |
1596 item6.Put(SERVER_SPECIFICS, autofill_specs); | 1602 item6.Put(SERVER_SPECIFICS, autofill_specs); |
1597 item6.Put(IS_UNAPPLIED_UPDATE, true); | 1603 item6.Put(IS_UNAPPLIED_UPDATE, true); |
1598 } | 1604 } |
1599 | 1605 |
1600 dir_->SaveChanges(); | 1606 dir_->SaveChanges(); |
1601 { | 1607 { |
1602 ReadTransaction trans(FROM_HERE, dir_.get()); | 1608 ReadTransaction trans(FROM_HERE, dir_.get()); |
1603 MetahandleSet all_set; | 1609 MetahandleSet all_set; |
1604 GetAllMetaHandles(&trans, &all_set); | 1610 GetAllMetaHandles(&trans, &all_set); |
1605 ASSERT_EQ(7U, all_set.size()); | 1611 ASSERT_EQ(10U, all_set.size()); |
1606 } | 1612 } |
1607 | 1613 |
1608 dir_->PurgeEntriesWithTypeIn(types_to_purge); | 1614 dir_->PurgeEntriesWithTypeIn(types_to_purge); |
1609 | 1615 |
1610 // We first query the in-memory data, and then reload the directory (without | 1616 // We first query the in-memory data, and then reload the directory (without |
1611 // saving) to verify that disk does not still have the data. | 1617 // saving) to verify that disk does not still have the data. |
1612 CheckPurgeEntriesWithTypeInSucceeded(types_to_purge, true); | 1618 CheckPurgeEntriesWithTypeInSucceeded(types_to_purge, true); |
1613 SaveAndReloadDir(); | 1619 SaveAndReloadDir(); |
1614 CheckPurgeEntriesWithTypeInSucceeded(types_to_purge, false); | 1620 CheckPurgeEntriesWithTypeInSucceeded(types_to_purge, false); |
1615 } | 1621 } |
1616 | 1622 |
1617 TEST_F(OnDiskSyncableDirectoryTest, TestShareInfo) { | 1623 TEST_F(OnDiskSyncableDirectoryTest, TestShareInfo) { |
1618 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); | |
1619 dir_->set_store_birthday("Jan 31st"); | 1624 dir_->set_store_birthday("Jan 31st"); |
1620 dir_->SetNotificationState("notification_state"); | 1625 dir_->SetNotificationState("notification_state"); |
1621 const char* const bag_of_chips_array = "\0bag of chips"; | 1626 const char* const bag_of_chips_array = "\0bag of chips"; |
1622 const std::string bag_of_chips_string = | 1627 const std::string bag_of_chips_string = |
1623 std::string(bag_of_chips_array, sizeof(bag_of_chips_array)); | 1628 std::string(bag_of_chips_array, sizeof(bag_of_chips_array)); |
1624 dir_->set_bag_of_chips(bag_of_chips_string); | 1629 dir_->set_bag_of_chips(bag_of_chips_string); |
1625 { | 1630 { |
1626 ReadTransaction trans(FROM_HERE, dir_.get()); | 1631 ReadTransaction trans(FROM_HERE, dir_.get()); |
1627 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); | |
1628 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); | |
1629 EXPECT_EQ("Jan 31st", dir_->store_birthday()); | 1632 EXPECT_EQ("Jan 31st", dir_->store_birthday()); |
1630 EXPECT_EQ("notification_state", dir_->GetNotificationState()); | 1633 EXPECT_EQ("notification_state", dir_->GetNotificationState()); |
1631 EXPECT_EQ(bag_of_chips_string, dir_->bag_of_chips()); | 1634 EXPECT_EQ(bag_of_chips_string, dir_->bag_of_chips()); |
1632 } | 1635 } |
1633 dir_->set_store_birthday("April 10th"); | 1636 dir_->set_store_birthday("April 10th"); |
1634 dir_->SetNotificationState("notification_state2"); | 1637 dir_->SetNotificationState("notification_state2"); |
1635 const char* const bag_of_chips2_array = "\0bag of chips2"; | 1638 const char* const bag_of_chips2_array = "\0bag of chips2"; |
1636 const std::string bag_of_chips2_string = | 1639 const std::string bag_of_chips2_string = |
1637 std::string(bag_of_chips2_array, sizeof(bag_of_chips2_array)); | 1640 std::string(bag_of_chips2_array, sizeof(bag_of_chips2_array)); |
1638 dir_->set_bag_of_chips(bag_of_chips2_string); | 1641 dir_->set_bag_of_chips(bag_of_chips2_string); |
1639 dir_->SaveChanges(); | 1642 dir_->SaveChanges(); |
1640 { | 1643 { |
1641 ReadTransaction trans(FROM_HERE, dir_.get()); | 1644 ReadTransaction trans(FROM_HERE, dir_.get()); |
1642 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); | |
1643 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); | |
1644 EXPECT_EQ("April 10th", dir_->store_birthday()); | 1645 EXPECT_EQ("April 10th", dir_->store_birthday()); |
1645 EXPECT_EQ("notification_state2", dir_->GetNotificationState()); | 1646 EXPECT_EQ("notification_state2", dir_->GetNotificationState()); |
1646 EXPECT_EQ(bag_of_chips2_string, dir_->bag_of_chips()); | 1647 EXPECT_EQ(bag_of_chips2_string, dir_->bag_of_chips()); |
1647 } | 1648 } |
1648 dir_->SetNotificationState("notification_state2"); | 1649 dir_->SetNotificationState("notification_state2"); |
1649 // Restore the directory from disk. Make sure that nothing's changed. | 1650 // Restore the directory from disk. Make sure that nothing's changed. |
1650 SaveAndReloadDir(); | 1651 SaveAndReloadDir(); |
1651 { | 1652 { |
1652 ReadTransaction trans(FROM_HERE, dir_.get()); | 1653 ReadTransaction trans(FROM_HERE, dir_.get()); |
1653 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); | |
1654 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); | |
1655 EXPECT_EQ("April 10th", dir_->store_birthday()); | 1654 EXPECT_EQ("April 10th", dir_->store_birthday()); |
1656 EXPECT_EQ("notification_state2", dir_->GetNotificationState()); | 1655 EXPECT_EQ("notification_state2", dir_->GetNotificationState()); |
1657 EXPECT_EQ(bag_of_chips2_string, dir_->bag_of_chips()); | 1656 EXPECT_EQ(bag_of_chips2_string, dir_->bag_of_chips()); |
1658 } | 1657 } |
1659 } | 1658 } |
1660 | 1659 |
1661 TEST_F(OnDiskSyncableDirectoryTest, | 1660 TEST_F(OnDiskSyncableDirectoryTest, |
1662 TestSimpleFieldsPreservedDuringSaveChanges) { | 1661 TestSimpleFieldsPreservedDuringSaveChanges) { |
1663 Id update_id = TestIdFactory::FromNumber(1); | 1662 Id update_id = TestIdFactory::FromNumber(1); |
1664 Id create_id; | 1663 Id create_id; |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2135 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2137 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2136 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2138 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 2137 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
2139 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 2138 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
2140 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 2139 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
2141 } | 2140 } |
2142 | 2141 |
2143 } // namespace | 2142 } // namespace |
2144 } // namespace syncable | 2143 } // namespace syncable |
2145 } // namespace syncer | 2144 } // namespace syncer |
OLD | NEW |