OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/sync/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 | 10 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 if ((types_to_purge.count(e.GetModelType()) || | 316 if ((types_to_purge.count(e.GetModelType()) || |
317 types_to_purge.count(e.GetServerModelType()))) { | 317 types_to_purge.count(e.GetServerModelType()))) { |
318 FAIL() << "Illegal type should have been deleted."; | 318 FAIL() << "Illegal type should have been deleted."; |
319 } | 319 } |
320 } | 320 } |
321 } | 321 } |
322 | 322 |
323 EXPECT_FALSE(dir_->initial_sync_ended_for_type(PREFERENCES)); | 323 EXPECT_FALSE(dir_->initial_sync_ended_for_type(PREFERENCES)); |
324 EXPECT_FALSE(dir_->initial_sync_ended_for_type(AUTOFILL)); | 324 EXPECT_FALSE(dir_->initial_sync_ended_for_type(AUTOFILL)); |
325 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS)); | 325 EXPECT_TRUE(dir_->initial_sync_ended_for_type(BOOKMARKS)); |
326 | |
327 EXPECT_EQ(0, dir_->last_download_timestamp(PREFERENCES)); | |
328 EXPECT_EQ(0, dir_->last_download_timestamp(AUTOFILL)); | |
329 EXPECT_EQ(1, dir_->last_download_timestamp(BOOKMARKS)); | |
330 } | 326 } |
331 | 327 |
332 scoped_ptr<Directory> dir_; | 328 scoped_ptr<Directory> dir_; |
333 FilePath file_path_; | 329 FilePath file_path_; |
334 | 330 |
335 // Creates an empty entry and sets the ID field to the default kId. | 331 // Creates an empty entry and sets the ID field to the default kId. |
336 void CreateEntry(const std::string& entryname) { | 332 void CreateEntry(const std::string& entryname) { |
337 CreateEntry(entryname, kId); | 333 CreateEntry(entryname, kId); |
338 } | 334 } |
339 | 335 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 } | 458 } |
463 | 459 |
464 TEST_F(SyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { | 460 TEST_F(SyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { |
465 sync_pb::EntitySpecifics bookmark_specs; | 461 sync_pb::EntitySpecifics bookmark_specs; |
466 sync_pb::EntitySpecifics autofill_specs; | 462 sync_pb::EntitySpecifics autofill_specs; |
467 sync_pb::EntitySpecifics preference_specs; | 463 sync_pb::EntitySpecifics preference_specs; |
468 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs); | 464 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs); |
469 AddDefaultExtensionValue(PREFERENCES, &preference_specs); | 465 AddDefaultExtensionValue(PREFERENCES, &preference_specs); |
470 AddDefaultExtensionValue(AUTOFILL, &autofill_specs); | 466 AddDefaultExtensionValue(AUTOFILL, &autofill_specs); |
471 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); | 467 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); |
472 dir_->set_last_download_timestamp(BOOKMARKS, 1); | |
473 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); | 468 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); |
474 dir_->set_last_download_timestamp(PREFERENCES, 1); | |
475 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); | 469 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); |
476 dir_->set_last_download_timestamp(AUTOFILL, 1); | |
477 | |
478 | 470 |
479 std::set<ModelType> types_to_purge; | 471 std::set<ModelType> types_to_purge; |
480 types_to_purge.insert(PREFERENCES); | 472 types_to_purge.insert(PREFERENCES); |
481 types_to_purge.insert(AUTOFILL); | 473 types_to_purge.insert(AUTOFILL); |
482 | 474 |
483 TestIdFactory id_factory; | 475 TestIdFactory id_factory; |
484 // Create some items for each type. | 476 // Create some items for each type. |
485 { | 477 { |
486 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); | 478 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); |
487 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); | 479 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 TEST_F(SyncableDirectoryTest, TestCaseChangeRename) { | 985 TEST_F(SyncableDirectoryTest, TestCaseChangeRename) { |
994 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); | 986 WriteTransaction trans(dir_.get(), UNITTEST, __FILE__, __LINE__); |
995 MutableEntry folder(&trans, CREATE, trans.root_id(), "CaseChange"); | 987 MutableEntry folder(&trans, CREATE, trans.root_id(), "CaseChange"); |
996 ASSERT_TRUE(folder.good()); | 988 ASSERT_TRUE(folder.good()); |
997 EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id())); | 989 EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id())); |
998 EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE")); | 990 EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE")); |
999 EXPECT_TRUE(folder.Put(IS_DEL, true)); | 991 EXPECT_TRUE(folder.Put(IS_DEL, true)); |
1000 } | 992 } |
1001 | 993 |
1002 TEST_F(SyncableDirectoryTest, TestShareInfo) { | 994 TEST_F(SyncableDirectoryTest, TestShareInfo) { |
1003 dir_->set_last_download_timestamp(AUTOFILL, 100); | |
1004 dir_->set_last_download_timestamp(BOOKMARKS, 1000); | |
1005 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); | 995 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); |
1006 dir_->set_store_birthday("Jan 31st"); | 996 dir_->set_store_birthday("Jan 31st"); |
1007 dir_->SetNotificationState("notification_state"); | 997 dir_->SetNotificationState("notification_state"); |
1008 { | 998 { |
1009 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); | 999 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); |
1010 EXPECT_EQ(100, dir_->last_download_timestamp(AUTOFILL)); | |
1011 EXPECT_EQ(1000, dir_->last_download_timestamp(BOOKMARKS)); | |
1012 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); | 1000 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); |
1013 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); | 1001 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); |
1014 EXPECT_EQ("Jan 31st", dir_->store_birthday()); | 1002 EXPECT_EQ("Jan 31st", dir_->store_birthday()); |
1015 EXPECT_EQ("notification_state", dir_->GetAndClearNotificationState()); | 1003 EXPECT_EQ("notification_state", dir_->GetAndClearNotificationState()); |
1016 EXPECT_EQ("", dir_->GetAndClearNotificationState()); | 1004 EXPECT_EQ("", dir_->GetAndClearNotificationState()); |
1017 } | 1005 } |
1018 dir_->set_last_download_timestamp(AUTOFILL, 200); | |
1019 dir_->set_store_birthday("April 10th"); | 1006 dir_->set_store_birthday("April 10th"); |
1020 dir_->SetNotificationState("notification_state2"); | 1007 dir_->SetNotificationState("notification_state2"); |
1021 dir_->SaveChanges(); | 1008 dir_->SaveChanges(); |
1022 { | 1009 { |
1023 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); | 1010 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); |
1024 EXPECT_EQ(200, dir_->last_download_timestamp(AUTOFILL)); | |
1025 EXPECT_EQ(1000, dir_->last_download_timestamp(BOOKMARKS)); | |
1026 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); | 1011 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); |
1027 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); | 1012 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); |
1028 EXPECT_EQ("April 10th", dir_->store_birthday()); | 1013 EXPECT_EQ("April 10th", dir_->store_birthday()); |
1029 EXPECT_EQ("notification_state2", dir_->GetAndClearNotificationState()); | 1014 EXPECT_EQ("notification_state2", dir_->GetAndClearNotificationState()); |
1030 EXPECT_EQ("", dir_->GetAndClearNotificationState()); | 1015 EXPECT_EQ("", dir_->GetAndClearNotificationState()); |
1031 } | 1016 } |
1032 dir_->SetNotificationState("notification_state2"); | 1017 dir_->SetNotificationState("notification_state2"); |
1033 // Restore the directory from disk. Make sure that nothing's changed. | 1018 // Restore the directory from disk. Make sure that nothing's changed. |
1034 SaveAndReloadDir(); | 1019 SaveAndReloadDir(); |
1035 { | 1020 { |
1036 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); | 1021 ReadTransaction trans(dir_.get(), __FILE__, __LINE__); |
1037 EXPECT_EQ(200, dir_->last_download_timestamp(AUTOFILL)); | |
1038 EXPECT_EQ(1000, dir_->last_download_timestamp(BOOKMARKS)); | |
1039 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); | 1022 EXPECT_TRUE(dir_->initial_sync_ended_for_type(AUTOFILL)); |
1040 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); | 1023 EXPECT_FALSE(dir_->initial_sync_ended_for_type(BOOKMARKS)); |
1041 EXPECT_EQ("April 10th", dir_->store_birthday()); | 1024 EXPECT_EQ("April 10th", dir_->store_birthday()); |
1042 EXPECT_EQ("notification_state2", dir_->GetAndClearNotificationState()); | 1025 EXPECT_EQ("notification_state2", dir_->GetAndClearNotificationState()); |
1043 EXPECT_EQ("", dir_->GetAndClearNotificationState()); | 1026 EXPECT_EQ("", dir_->GetAndClearNotificationState()); |
1044 } | 1027 } |
1045 } | 1028 } |
1046 | 1029 |
1047 TEST_F(SyncableDirectoryTest, TestSimpleFieldsPreservedDuringSaveChanges) { | 1030 TEST_F(SyncableDirectoryTest, TestSimpleFieldsPreservedDuringSaveChanges) { |
1048 Id update_id = TestIdFactory::FromNumber(1); | 1031 Id update_id = TestIdFactory::FromNumber(1); |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { | 1741 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { |
1759 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1742 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
1760 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1743 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
1761 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 1744 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
1762 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 1745 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
1763 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 1746 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
1764 } | 1747 } |
1765 | 1748 |
1766 } // namespace | 1749 } // namespace |
1767 } // namespace syncable | 1750 } // namespace syncable |
OLD | NEW |