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 "chrome/browser/sync/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 ADD_FAILURE(); | 57 ADD_FAILURE(); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 namespace { | 61 namespace { |
62 void PutDataAsBookmarkFavicon(WriteTransaction* wtrans, | 62 void PutDataAsBookmarkFavicon(WriteTransaction* wtrans, |
63 MutableEntry* e, | 63 MutableEntry* e, |
64 const char* bytes, | 64 const char* bytes, |
65 size_t bytes_length) { | 65 size_t bytes_length) { |
66 sync_pb::EntitySpecifics specifics; | 66 sync_pb::EntitySpecifics specifics; |
67 specifics.MutableExtension(sync_pb::bookmark)->set_url("http://demo/"); | 67 specifics.mutable_bookmark()->set_url("http://demo/"); |
68 specifics.MutableExtension(sync_pb::bookmark)->set_favicon(bytes, | 68 specifics.mutable_bookmark()->set_favicon(bytes, bytes_length); |
69 bytes_length); | |
70 e->Put(SPECIFICS, specifics); | 69 e->Put(SPECIFICS, specifics); |
71 } | 70 } |
72 | 71 |
73 void ExpectDataFromBookmarkFaviconEquals(BaseTransaction* trans, | 72 void ExpectDataFromBookmarkFaviconEquals(BaseTransaction* trans, |
74 Entry* e, | 73 Entry* e, |
75 const char* bytes, | 74 const char* bytes, |
76 size_t bytes_length) { | 75 size_t bytes_length) { |
77 ASSERT_TRUE(e->good()); | 76 ASSERT_TRUE(e->good()); |
78 ASSERT_TRUE(e->Get(SPECIFICS).HasExtension(sync_pb::bookmark)); | 77 ASSERT_TRUE(e->Get(SPECIFICS).has_bookmark()); |
79 ASSERT_EQ("http://demo/", | 78 ASSERT_EQ("http://demo/", e->Get(SPECIFICS).bookmark().url()); |
80 e->Get(SPECIFICS).GetExtension(sync_pb::bookmark).url()); | |
81 ASSERT_EQ(std::string(bytes, bytes_length), | 79 ASSERT_EQ(std::string(bytes, bytes_length), |
82 e->Get(SPECIFICS).GetExtension(sync_pb::bookmark).favicon()); | 80 e->Get(SPECIFICS).bookmark().favicon()); |
83 } | 81 } |
84 } // namespace | 82 } // namespace |
85 | 83 |
86 class SyncableGeneralTest : public testing::Test { | 84 class SyncableGeneralTest : public testing::Test { |
87 public: | 85 public: |
88 virtual void SetUp() { | 86 virtual void SetUp() { |
89 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 87 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
90 db_path_ = temp_dir_.path().Append( | 88 db_path_ = temp_dir_.path().Append( |
91 FILE_PATH_LITERAL("SyncableTest.sqlite3")); | 89 FILE_PATH_LITERAL("SyncableTest.sqlite3")); |
92 } | 90 } |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 const int metas_to_create = 50; | 522 const int metas_to_create = 50; |
525 MetahandleSet expected_purges; | 523 MetahandleSet expected_purges; |
526 MetahandleSet all_handles; | 524 MetahandleSet all_handles; |
527 { | 525 { |
528 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 526 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
529 for (int i = 0; i < metas_to_create; i++) { | 527 for (int i = 0; i < metas_to_create; i++) { |
530 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); | 528 MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); |
531 e.Put(IS_UNSYNCED, true); | 529 e.Put(IS_UNSYNCED, true); |
532 sync_pb::EntitySpecifics specs; | 530 sync_pb::EntitySpecifics specs; |
533 if (i % 2 == 0) { | 531 if (i % 2 == 0) { |
534 AddDefaultExtensionValue(BOOKMARKS, &specs); | 532 AddDefaultFieldValue(BOOKMARKS, &specs); |
535 expected_purges.insert(e.Get(META_HANDLE)); | 533 expected_purges.insert(e.Get(META_HANDLE)); |
536 all_handles.insert(e.Get(META_HANDLE)); | 534 all_handles.insert(e.Get(META_HANDLE)); |
537 } else { | 535 } else { |
538 AddDefaultExtensionValue(PREFERENCES, &specs); | 536 AddDefaultFieldValue(PREFERENCES, &specs); |
539 all_handles.insert(e.Get(META_HANDLE)); | 537 all_handles.insert(e.Get(META_HANDLE)); |
540 } | 538 } |
541 e.Put(SPECIFICS, specs); | 539 e.Put(SPECIFICS, specs); |
542 e.Put(SERVER_SPECIFICS, specs); | 540 e.Put(SERVER_SPECIFICS, specs); |
543 } | 541 } |
544 } | 542 } |
545 | 543 |
546 syncable::ModelTypeSet to_purge(BOOKMARKS); | 544 syncable::ModelTypeSet to_purge(BOOKMARKS); |
547 dir_->PurgeEntriesWithTypeIn(to_purge); | 545 dir_->PurgeEntriesWithTypeIn(to_purge); |
548 | 546 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 EXPECT_TRUE(i->is_dirty()); | 617 EXPECT_TRUE(i->is_dirty()); |
620 } | 618 } |
621 dir_->VacuumAfterSaveChanges(snapshot); | 619 dir_->VacuumAfterSaveChanges(snapshot); |
622 } | 620 } |
623 } | 621 } |
624 | 622 |
625 TEST_F(SyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { | 623 TEST_F(SyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { |
626 sync_pb::EntitySpecifics bookmark_specs; | 624 sync_pb::EntitySpecifics bookmark_specs; |
627 sync_pb::EntitySpecifics autofill_specs; | 625 sync_pb::EntitySpecifics autofill_specs; |
628 sync_pb::EntitySpecifics preference_specs; | 626 sync_pb::EntitySpecifics preference_specs; |
629 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs); | 627 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); |
630 AddDefaultExtensionValue(PREFERENCES, &preference_specs); | 628 AddDefaultFieldValue(PREFERENCES, &preference_specs); |
631 AddDefaultExtensionValue(AUTOFILL, &autofill_specs); | 629 AddDefaultFieldValue(AUTOFILL, &autofill_specs); |
632 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); | 630 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); |
633 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); | 631 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); |
634 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); | 632 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); |
635 | 633 |
636 syncable::ModelTypeSet types_to_purge(PREFERENCES, AUTOFILL); | 634 syncable::ModelTypeSet types_to_purge(PREFERENCES, AUTOFILL); |
637 | 635 |
638 TestIdFactory id_factory; | 636 TestIdFactory id_factory; |
639 // Create some items for each type. | 637 // Create some items for each type. |
640 { | 638 { |
641 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 639 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 EntryKernel create_post_save, update_post_save; | 1191 EntryKernel create_post_save, update_post_save; |
1194 std::string create_name = "Create"; | 1192 std::string create_name = "Create"; |
1195 | 1193 |
1196 { | 1194 { |
1197 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1195 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1198 MutableEntry create(&trans, CREATE, trans.root_id(), create_name); | 1196 MutableEntry create(&trans, CREATE, trans.root_id(), create_name); |
1199 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id); | 1197 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id); |
1200 create.Put(IS_UNSYNCED, true); | 1198 create.Put(IS_UNSYNCED, true); |
1201 update.Put(IS_UNAPPLIED_UPDATE, true); | 1199 update.Put(IS_UNAPPLIED_UPDATE, true); |
1202 sync_pb::EntitySpecifics specifics; | 1200 sync_pb::EntitySpecifics specifics; |
1203 specifics.MutableExtension(sync_pb::bookmark)->set_favicon("PNG"); | 1201 specifics.mutable_bookmark()->set_favicon("PNG"); |
1204 specifics.MutableExtension(sync_pb::bookmark)->set_url("http://nowhere"); | 1202 specifics.mutable_bookmark()->set_url("http://nowhere"); |
1205 create.Put(SPECIFICS, specifics); | 1203 create.Put(SPECIFICS, specifics); |
1206 create_pre_save = create.GetKernelCopy(); | 1204 create_pre_save = create.GetKernelCopy(); |
1207 update_pre_save = update.GetKernelCopy(); | 1205 update_pre_save = update.GetKernelCopy(); |
1208 create_id = create.Get(ID); | 1206 create_id = create.Get(ID); |
1209 } | 1207 } |
1210 | 1208 |
1211 dir_->SaveChanges(); | 1209 dir_->SaveChanges(); |
1212 dir_.reset(new Directory(&encryptor_, &handler_, NULL)); | 1210 dir_.reset(new Directory(&encryptor_, &handler_, NULL)); |
1213 ASSERT_TRUE(dir_.get()); | 1211 ASSERT_TRUE(dir_.get()); |
1214 ASSERT_EQ(OPENED, dir_->Open(file_path_, kName, | 1212 ASSERT_EQ(OPENED, dir_->Open(file_path_, kName, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1363 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1366 | 1364 |
1367 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); | 1365 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); |
1368 ASSERT_TRUE(e1.good()); | 1366 ASSERT_TRUE(e1.good()); |
1369 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); | 1367 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); |
1370 handle1 = e1.Get(META_HANDLE); | 1368 handle1 = e1.Get(META_HANDLE); |
1371 e1.Put(BASE_VERSION, 1); | 1369 e1.Put(BASE_VERSION, 1); |
1372 e1.Put(IS_DIR, true); | 1370 e1.Put(IS_DIR, true); |
1373 e1.Put(ID, TestIdFactory::FromNumber(101)); | 1371 e1.Put(ID, TestIdFactory::FromNumber(101)); |
1374 sync_pb::EntitySpecifics bookmark_specs; | 1372 sync_pb::EntitySpecifics bookmark_specs; |
1375 AddDefaultExtensionValue(BOOKMARKS, &bookmark_specs); | 1373 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); |
1376 e1.Put(SPECIFICS, bookmark_specs); | 1374 e1.Put(SPECIFICS, bookmark_specs); |
1377 e1.Put(SERVER_SPECIFICS, bookmark_specs); | 1375 e1.Put(SERVER_SPECIFICS, bookmark_specs); |
1378 e1.Put(ID, TestIdFactory::FromNumber(101)); | 1376 e1.Put(ID, TestIdFactory::FromNumber(101)); |
1379 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); | 1377 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); |
1380 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); | 1378 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); |
1381 } | 1379 } |
1382 ASSERT_TRUE(dir_->SaveChanges()); | 1380 ASSERT_TRUE(dir_->SaveChanges()); |
1383 | 1381 |
1384 // Now do some operations using a directory for which SaveChanges will | 1382 // Now do some operations using a directory for which SaveChanges will |
1385 // always fail. | 1383 // always fail. |
(...skipping 18 matching lines...) Expand all Loading... |
1404 ModelType datatype = ModelTypeFromInt(i); | 1402 ModelType datatype = ModelTypeFromInt(i); |
1405 SCOPED_TRACE(testing::Message("Testing model type ") << datatype); | 1403 SCOPED_TRACE(testing::Message("Testing model type ") << datatype); |
1406 switch (datatype) { | 1404 switch (datatype) { |
1407 case UNSPECIFIED: | 1405 case UNSPECIFIED: |
1408 case TOP_LEVEL_FOLDER: | 1406 case TOP_LEVEL_FOLDER: |
1409 continue; // Datatype isn't a function of Specifics. | 1407 continue; // Datatype isn't a function of Specifics. |
1410 default: | 1408 default: |
1411 break; | 1409 break; |
1412 } | 1410 } |
1413 sync_pb::EntitySpecifics specifics; | 1411 sync_pb::EntitySpecifics specifics; |
1414 AddDefaultExtensionValue(datatype, &specifics); | 1412 AddDefaultFieldValue(datatype, &specifics); |
1415 | 1413 |
1416 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1414 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
1417 | 1415 |
1418 MutableEntry folder(&trans, CREATE, trans.root_id(), "Folder"); | 1416 MutableEntry folder(&trans, CREATE, trans.root_id(), "Folder"); |
1419 ASSERT_TRUE(folder.good()); | 1417 ASSERT_TRUE(folder.good()); |
1420 folder.Put(ID, id_factory.NewServerId()); | 1418 folder.Put(ID, id_factory.NewServerId()); |
1421 folder.Put(SPECIFICS, specifics); | 1419 folder.Put(SPECIFICS, specifics); |
1422 folder.Put(BASE_VERSION, 1); | 1420 folder.Put(BASE_VERSION, 1); |
1423 folder.Put(IS_DIR, true); | 1421 folder.Put(IS_DIR, true); |
1424 folder.Put(IS_DEL, false); | 1422 folder.Put(IS_DEL, false); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { | 1688 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { |
1691 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1689 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
1692 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1690 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
1693 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 1691 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
1694 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 1692 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
1695 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 1693 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
1696 } | 1694 } |
1697 | 1695 |
1698 } // namespace | 1696 } // namespace |
1699 } // namespace syncable | 1697 } // namespace syncable |
OLD | NEW |