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

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 11863011: Revert 176340 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 // Unit tests for the SyncApi. Note that a lot of the underlying 5 // Unit tests for the SyncApi. Note that a lot of the underlying
6 // functionality is provided by the Syncable layer, which has its own 6 // functionality is provided by the Syncable layer, which has its own
7 // unit tests. We'll test SyncApi specific things in this harness. 7 // unit tests. We'll test SyncApi specific things in this harness.
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 ReadNode root_node(&trans); 123 ReadNode root_node(&trans);
124 root_node.InitByRootLookup(); 124 root_node.InitByRootLookup();
125 WriteNode node(&trans); 125 WriteNode node(&trans);
126 WriteNode::InitUniqueByCreationResult result = 126 WriteNode::InitUniqueByCreationResult result =
127 node.InitUniqueByCreation(model_type, root_node, client_tag); 127 node.InitUniqueByCreation(model_type, root_node, client_tag);
128 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 128 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
129 node.SetIsFolder(false); 129 node.SetIsFolder(false);
130 return node.GetId(); 130 return node.GetId();
131 } 131 }
132 132
133 // Makes a non-folder child of a non-root node. Returns the id of the
134 // newly-created node.
135 int64 MakeNodeWithParent(UserShare* share,
136 ModelType model_type,
137 const std::string& client_tag,
138 int64 parent_id) {
139 WriteTransaction trans(FROM_HERE, share);
140 ReadNode parent_node(&trans);
141 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id));
142 WriteNode node(&trans);
143 WriteNode::InitUniqueByCreationResult result =
144 node.InitUniqueByCreation(model_type, parent_node, client_tag);
145 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
146 node.SetIsFolder(false);
147 return node.GetId();
148 }
149
133 // Makes a folder child of a non-root node. Returns the id of the 150 // Makes a folder child of a non-root node. Returns the id of the
134 // newly-created node. 151 // newly-created node.
135 int64 MakeFolderWithParent(UserShare* share, 152 int64 MakeFolderWithParent(UserShare* share,
136 ModelType model_type, 153 ModelType model_type,
137 int64 parent_id, 154 int64 parent_id,
138 BaseNode* predecessor) { 155 BaseNode* predecessor) {
139 WriteTransaction trans(FROM_HERE, share); 156 WriteTransaction trans(FROM_HERE, share);
140 ReadNode parent_node(&trans); 157 ReadNode parent_node(&trans);
141 DCHECK_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); 158 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id));
142 WriteNode node(&trans); 159 WriteNode node(&trans);
143 DCHECK(node.InitBookmarkByCreation(parent_node, predecessor)); 160 EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor));
144 node.SetIsFolder(true); 161 node.SetIsFolder(true);
145 return node.GetId(); 162 return node.GetId();
146 } 163 }
147 164
148 int64 MakeBookmarkWithParent(UserShare* share,
149 int64 parent_id,
150 BaseNode* predecessor) {
151 WriteTransaction trans(FROM_HERE, share);
152 ReadNode parent_node(&trans);
153 DCHECK_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id));
154 WriteNode node(&trans);
155 DCHECK(node.InitBookmarkByCreation(parent_node, predecessor));
156 return node.GetId();
157 }
158
159 // Creates the "synced" root node for a particular datatype. We use the syncable 165 // Creates the "synced" root node for a particular datatype. We use the syncable
160 // methods here so that the syncer treats these nodes as if they were already 166 // methods here so that the syncer treats these nodes as if they were already
161 // received from the server. 167 // received from the server.
162 int64 MakeServerNodeForType(UserShare* share, 168 int64 MakeServerNodeForType(UserShare* share,
163 ModelType model_type) { 169 ModelType model_type) {
164 sync_pb::EntitySpecifics specifics; 170 sync_pb::EntitySpecifics specifics;
165 AddDefaultFieldValue(model_type, &specifics); 171 AddDefaultFieldValue(model_type, &specifics);
166 syncable::WriteTransaction trans( 172 syncable::WriteTransaction trans(
167 FROM_HERE, syncable::UNITTEST, share->directory.get()); 173 FROM_HERE, syncable::UNITTEST, share->directory.get());
168 // Attempt to lookup by nigori tag. 174 // Attempt to lookup by nigori tag.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 int64 folder_id; 343 int64 folder_id;
338 std::string test_title("test1"); 344 std::string test_title("test1");
339 345
340 { 346 {
341 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 347 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
342 ReadNode root_node(&trans); 348 ReadNode root_node(&trans);
343 root_node.InitByRootLookup(); 349 root_node.InitByRootLookup();
344 350
345 // we'll use this spare folder later 351 // we'll use this spare folder later
346 WriteNode folder_node(&trans); 352 WriteNode folder_node(&trans);
347 EXPECT_TRUE(folder_node.InitBookmarkByCreation(root_node, NULL)); 353 EXPECT_TRUE(folder_node.InitByCreation(BOOKMARKS,
354 root_node, NULL));
348 folder_id = folder_node.GetId(); 355 folder_id = folder_node.GetId();
349 356
350 WriteNode wnode(&trans); 357 WriteNode wnode(&trans);
351 WriteNode::InitUniqueByCreationResult result = 358 WriteNode::InitUniqueByCreationResult result =
352 wnode.InitUniqueByCreation(BOOKMARKS, root_node, "testtag"); 359 wnode.InitUniqueByCreation(BOOKMARKS, root_node, "testtag");
353 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 360 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
354 wnode.SetIsFolder(false); 361 wnode.SetIsFolder(false);
355 wnode.SetTitle(UTF8ToWide(test_title)); 362 wnode.SetTitle(UTF8ToWide(test_title));
356 363
357 node_id = wnode.GetId(); 364 node_id = wnode.GetId();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 453 }
447 } 454 }
448 455
449 TEST_F(SyncApiTest, WriteEncryptedTitle) { 456 TEST_F(SyncApiTest, WriteEncryptedTitle) {
450 KeyParams params = {"localhost", "username", "passphrase"}; 457 KeyParams params = {"localhost", "username", "passphrase"};
451 { 458 {
452 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 459 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
453 trans.GetCryptographer()->AddKey(params); 460 trans.GetCryptographer()->AddKey(params);
454 } 461 }
455 test_user_share_.encryption_handler()->EnableEncryptEverything(); 462 test_user_share_.encryption_handler()->EnableEncryptEverything();
456 int bookmark_id;
457 { 463 {
458 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 464 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
459 ReadNode root_node(&trans); 465 ReadNode root_node(&trans);
460 root_node.InitByRootLookup(); 466 root_node.InitByRootLookup();
461 467
462 WriteNode bookmark_node(&trans); 468 WriteNode bookmark_node(&trans);
463 ASSERT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, NULL)); 469 WriteNode::InitUniqueByCreationResult result =
464 bookmark_id = bookmark_node.GetId(); 470 bookmark_node.InitUniqueByCreation(BOOKMARKS,
471 root_node, "foo");
472 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
465 bookmark_node.SetTitle(UTF8ToWide("foo")); 473 bookmark_node.SetTitle(UTF8ToWide("foo"));
466 474
467 WriteNode pref_node(&trans); 475 WriteNode pref_node(&trans);
468 WriteNode::InitUniqueByCreationResult result = 476 result =
469 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); 477 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar");
470 ASSERT_EQ(WriteNode::INIT_SUCCESS, result); 478 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
471 pref_node.SetTitle(UTF8ToWide("bar")); 479 pref_node.SetTitle(UTF8ToWide("bar"));
472 } 480 }
473 { 481 {
474 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 482 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
475 ReadNode root_node(&trans); 483 ReadNode root_node(&trans);
476 root_node.InitByRootLookup(); 484 root_node.InitByRootLookup();
477 485
478 ReadNode bookmark_node(&trans); 486 ReadNode bookmark_node(&trans);
479 ASSERT_EQ(BaseNode::INIT_OK, bookmark_node.InitByIdLookup(bookmark_id)); 487 EXPECT_EQ(BaseNode::INIT_OK,
488 bookmark_node.InitByClientTagLookup(BOOKMARKS,
489 "foo"));
480 EXPECT_EQ("foo", bookmark_node.GetTitle()); 490 EXPECT_EQ("foo", bookmark_node.GetTitle());
481 EXPECT_EQ(kEncryptedString, 491 EXPECT_EQ(kEncryptedString,
482 bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME)); 492 bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME));
483 493
484 ReadNode pref_node(&trans); 494 ReadNode pref_node(&trans);
485 ASSERT_EQ(BaseNode::INIT_OK, 495 EXPECT_EQ(BaseNode::INIT_OK,
486 pref_node.InitByClientTagLookup(PREFERENCES, 496 pref_node.InitByClientTagLookup(PREFERENCES,
487 "bar")); 497 "bar"));
488 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); 498 EXPECT_EQ(kEncryptedString, pref_node.GetTitle());
489 } 499 }
490 } 500 }
491 501
492 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { 502 TEST_F(SyncApiTest, BaseNodeSetSpecifics) {
493 int64 child_id = MakeNode(test_user_share_.user_share(), 503 int64 child_id = MakeNode(test_user_share_.user_share(),
494 BOOKMARKS, "testtag"); 504 BOOKMARKS, "testtag");
495 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 505 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 NULL); 665 NULL);
656 ignore_result(MakeFolderWithParent(test_user_share_.user_share(), 666 ignore_result(MakeFolderWithParent(test_user_share_.user_share(),
657 BOOKMARKS, 667 BOOKMARKS,
658 type_root, 668 type_root,
659 NULL)); 669 NULL));
660 int64 child1 = MakeFolderWithParent( 670 int64 child1 = MakeFolderWithParent(
661 test_user_share_.user_share(), 671 test_user_share_.user_share(),
662 BOOKMARKS, 672 BOOKMARKS,
663 parent, 673 parent,
664 NULL); 674 NULL);
665 ignore_result(MakeBookmarkWithParent( 675 ignore_result(MakeNodeWithParent(
666 test_user_share_.user_share(), 676 test_user_share_.user_share(),
667 parent, 677 BOOKMARKS,
668 NULL)); 678 "c2",
669 ignore_result(MakeBookmarkWithParent( 679 parent));
680 ignore_result(MakeNodeWithParent(
670 test_user_share_.user_share(), 681 test_user_share_.user_share(),
671 child1, 682 BOOKMARKS,
672 NULL)); 683 "c1c1",
684 child1));
673 685
674 { 686 {
675 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 687 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
676 ReadNode type_root_node(&trans); 688 ReadNode type_root_node(&trans);
677 EXPECT_EQ(BaseNode::INIT_OK, 689 EXPECT_EQ(BaseNode::INIT_OK,
678 type_root_node.InitByIdLookup(type_root)); 690 type_root_node.InitByIdLookup(type_root));
679 EXPECT_EQ(6, type_root_node.GetTotalNodeCount()); 691 EXPECT_EQ(6, type_root_node.GetTotalNodeCount());
680 ReadNode node(&trans); 692 ReadNode node(&trans);
681 EXPECT_EQ(BaseNode::INIT_OK, 693 EXPECT_EQ(BaseNode::INIT_OK,
682 node.InitByIdLookup(parent)); 694 node.InitByIdLookup(parent));
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1533 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1522 1534
1523 // Create some unencrypted unsynced data. 1535 // Create some unencrypted unsynced data.
1524 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), 1536 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(),
1525 BOOKMARKS, 1537 BOOKMARKS,
1526 GetIdForDataType(BOOKMARKS), 1538 GetIdForDataType(BOOKMARKS),
1527 NULL); 1539 NULL);
1528 // First batch_size nodes are children of folder. 1540 // First batch_size nodes are children of folder.
1529 size_t i; 1541 size_t i;
1530 for (i = 0; i < batch_size; ++i) { 1542 for (i = 0; i < batch_size; ++i) {
1531 MakeBookmarkWithParent(sync_manager_.GetUserShare(), folder, NULL); 1543 MakeNodeWithParent(sync_manager_.GetUserShare(), BOOKMARKS,
1544 base::StringPrintf("%"PRIuS"", i), folder);
1532 } 1545 }
1533 // Next batch_size nodes are a different type and on their own. 1546 // Next batch_size nodes are a different type and on their own.
1534 for (; i < 2*batch_size; ++i) { 1547 for (; i < 2*batch_size; ++i) {
1535 MakeNode(sync_manager_.GetUserShare(), SESSIONS, 1548 MakeNodeWithParent(sync_manager_.GetUserShare(), SESSIONS,
1536 base::StringPrintf("%"PRIuS"", i)); 1549 base::StringPrintf("%"PRIuS"", i),
1550 GetIdForDataType(SESSIONS));
1537 } 1551 }
1538 // Last batch_size nodes are a third type that will not need encryption. 1552 // Last batch_size nodes are a third type that will not need encryption.
1539 for (; i < 3*batch_size; ++i) { 1553 for (; i < 3*batch_size; ++i) {
1540 MakeNode(sync_manager_.GetUserShare(), THEMES, 1554 MakeNodeWithParent(sync_manager_.GetUserShare(), THEMES,
1541 base::StringPrintf("%"PRIuS"", i)); 1555 base::StringPrintf("%"PRIuS"", i),
1556 GetIdForDataType(THEMES));
1542 } 1557 }
1543 1558
1544 { 1559 {
1545 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1560 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1546 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals( 1561 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(
1547 SyncEncryptionHandler::SensitiveTypes())); 1562 SyncEncryptionHandler::SensitiveTypes()));
1548 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1563 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1549 trans.GetWrappedTrans(), 1564 trans.GetWrappedTrans(),
1550 BOOKMARKS, 1565 BOOKMARKS,
1551 false /* not encrypted */)); 1566 false /* not encrypted */));
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 } 2143 }
2129 2144
2130 // Create a bookmark and set the title/url, then verify the data was properly 2145 // Create a bookmark and set the title/url, then verify the data was properly
2131 // set. This replicates the unique way bookmarks have of creating sync nodes. 2146 // set. This replicates the unique way bookmarks have of creating sync nodes.
2132 // See BookmarkChangeProcessor::PlaceSyncNode(..). 2147 // See BookmarkChangeProcessor::PlaceSyncNode(..).
2133 TEST_F(SyncManagerTest, CreateLocalBookmark) { 2148 TEST_F(SyncManagerTest, CreateLocalBookmark) {
2134 std::string title = "title"; 2149 std::string title = "title";
2135 std::string url = "url"; 2150 std::string url = "url";
2136 { 2151 {
2137 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2152 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2138 ReadNode bookmark_root(&trans); 2153 ReadNode root_node(&trans);
2139 ASSERT_EQ(BaseNode::INIT_OK, 2154 root_node.InitByRootLookup();
2140 bookmark_root.InitByTagLookup(ModelTypeToRootTag(BOOKMARKS)));
2141 WriteNode node(&trans); 2155 WriteNode node(&trans);
2142 ASSERT_TRUE(node.InitBookmarkByCreation(bookmark_root, NULL)); 2156 ASSERT_TRUE(node.InitByCreation(BOOKMARKS, root_node, NULL));
2143 node.SetIsFolder(false); 2157 node.SetIsFolder(false);
2144 node.SetTitle(UTF8ToWide(title)); 2158 node.SetTitle(UTF8ToWide(title));
2145 2159
2146 sync_pb::BookmarkSpecifics bookmark_specifics(node.GetBookmarkSpecifics()); 2160 sync_pb::BookmarkSpecifics bookmark_specifics(node.GetBookmarkSpecifics());
2147 bookmark_specifics.set_url(url); 2161 bookmark_specifics.set_url(url);
2148 node.SetBookmarkSpecifics(bookmark_specifics); 2162 node.SetBookmarkSpecifics(bookmark_specifics);
2149 } 2163 }
2150 { 2164 {
2151 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2165 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2152 ReadNode bookmark_root(&trans); 2166 ReadNode root_node(&trans);
2153 ASSERT_EQ(BaseNode::INIT_OK, 2167 root_node.InitByRootLookup();
2154 bookmark_root.InitByTagLookup(ModelTypeToRootTag(BOOKMARKS))); 2168 int64 child_id = root_node.GetFirstChildId();
2155 int64 child_id = bookmark_root.GetFirstChildId();
2156 2169
2157 ReadNode node(&trans); 2170 ReadNode node(&trans);
2158 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); 2171 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id));
2159 EXPECT_FALSE(node.GetIsFolder()); 2172 EXPECT_FALSE(node.GetIsFolder());
2160 EXPECT_EQ(title, node.GetTitle()); 2173 EXPECT_EQ(title, node.GetTitle());
2161 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); 2174 EXPECT_EQ(url, node.GetBookmarkSpecifics().url());
2162 } 2175 }
2163 } 2176 }
2164 2177
2165 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary 2178 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
3045 Difference(ModelTypeSet::All(), disabled_types); 3058 Difference(ModelTypeSet::All(), disabled_types);
3046 3059
3047 // Verify only the non-disabled types remain after cleanup. 3060 // Verify only the non-disabled types remain after cleanup.
3048 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 3061 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
3049 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); 3062 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes()));
3050 EXPECT_TRUE(disabled_types.Equals( 3063 EXPECT_TRUE(disabled_types.Equals(
3051 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 3064 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
3052 } 3065 }
3053 3066
3054 } // namespace 3067 } // namespace
OLDNEW
« no previous file with comments | « sync/internal_api/sync_encryption_handler_impl_unittest.cc ('k') | sync/internal_api/test/test_entry_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698