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

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

Issue 10310113: Add additional error logging to investigate Autocomplete Sync failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: De-nitting Created 8 years, 7 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 (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 // 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 // Makes a non-folder child of the root node. Returns the id of the 125 // Makes a non-folder child of the root node. Returns the id of the
126 // newly-created node. 126 // newly-created node.
127 int64 MakeNode(UserShare* share, 127 int64 MakeNode(UserShare* share,
128 ModelType model_type, 128 ModelType model_type,
129 const std::string& client_tag) { 129 const std::string& client_tag) {
130 WriteTransaction trans(FROM_HERE, share); 130 WriteTransaction trans(FROM_HERE, share);
131 ReadNode root_node(&trans); 131 ReadNode root_node(&trans);
132 root_node.InitByRootLookup(); 132 root_node.InitByRootLookup();
133 WriteNode node(&trans); 133 WriteNode node(&trans);
134 EXPECT_TRUE(node.InitUniqueByCreation(model_type, root_node, client_tag)); 134 sync_api::WriteNode::InitUniqueByCreationResult result =
135 node.InitUniqueByCreation(model_type, root_node, client_tag);
136 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
135 node.SetIsFolder(false); 137 node.SetIsFolder(false);
136 return node.GetId(); 138 return node.GetId();
137 } 139 }
138 140
139 // Makes a non-folder child of a non-root node. Returns the id of the 141 // Makes a non-folder child of a non-root node. Returns the id of the
140 // newly-created node. 142 // newly-created node.
141 int64 MakeNodeWithParent(UserShare* share, 143 int64 MakeNodeWithParent(UserShare* share,
142 ModelType model_type, 144 ModelType model_type,
143 const std::string& client_tag, 145 const std::string& client_tag,
144 int64 parent_id) { 146 int64 parent_id) {
145 WriteTransaction trans(FROM_HERE, share); 147 WriteTransaction trans(FROM_HERE, share);
146 ReadNode parent_node(&trans); 148 ReadNode parent_node(&trans);
147 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); 149 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id));
148 WriteNode node(&trans); 150 WriteNode node(&trans);
149 EXPECT_TRUE(node.InitUniqueByCreation(model_type, parent_node, client_tag)); 151 sync_api::WriteNode::InitUniqueByCreationResult result =
152 node.InitUniqueByCreation(model_type, parent_node, client_tag);
153 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
150 node.SetIsFolder(false); 154 node.SetIsFolder(false);
151 return node.GetId(); 155 return node.GetId();
152 } 156 }
153 157
154 // Makes a folder child of a non-root node. Returns the id of the 158 // Makes a folder child of a non-root node. Returns the id of the
155 // newly-created node. 159 // newly-created node.
156 int64 MakeFolderWithParent(UserShare* share, 160 int64 MakeFolderWithParent(UserShare* share,
157 ModelType model_type, 161 ModelType model_type,
158 int64 parent_id, 162 int64 parent_id,
159 BaseNode* predecessor) { 163 BaseNode* predecessor) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 ReadNode root_node(&trans); 372 ReadNode root_node(&trans);
369 root_node.InitByRootLookup(); 373 root_node.InitByRootLookup();
370 374
371 // we'll use this spare folder later 375 // we'll use this spare folder later
372 WriteNode folder_node(&trans); 376 WriteNode folder_node(&trans);
373 EXPECT_TRUE(folder_node.InitByCreation(syncable::BOOKMARKS, 377 EXPECT_TRUE(folder_node.InitByCreation(syncable::BOOKMARKS,
374 root_node, NULL)); 378 root_node, NULL));
375 folder_id = folder_node.GetId(); 379 folder_id = folder_node.GetId();
376 380
377 WriteNode wnode(&trans); 381 WriteNode wnode(&trans);
378 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, 382 sync_api::WriteNode::InitUniqueByCreationResult result =
379 root_node, "testtag")); 383 wnode.InitUniqueByCreation(syncable::BOOKMARKS, root_node, "testtag");
384 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
380 wnode.SetIsFolder(false); 385 wnode.SetIsFolder(false);
381 wnode.SetTitle(UTF8ToWide(test_title)); 386 wnode.SetTitle(UTF8ToWide(test_title));
382 387
383 node_id = wnode.GetId(); 388 node_id = wnode.GetId();
384 } 389 }
385 390
386 // Ensure we can delete something with a tag. 391 // Ensure we can delete something with a tag.
387 { 392 {
388 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 393 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
389 WriteNode wnode(&trans); 394 WriteNode wnode(&trans);
(...skipping 19 matching lines...) Expand all
409 EXPECT_EQ(node.GetTitle(), test_title); 414 EXPECT_EQ(node.GetTitle(), test_title);
410 } 415 }
411 416
412 { 417 {
413 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 418 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
414 ReadNode folder_node(&trans); 419 ReadNode folder_node(&trans);
415 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); 420 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id));
416 421
417 WriteNode wnode(&trans); 422 WriteNode wnode(&trans);
418 // This will undelete the tag. 423 // This will undelete the tag.
419 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, 424 sync_api::WriteNode::InitUniqueByCreationResult result =
420 folder_node, "testtag")); 425 wnode.InitUniqueByCreation(syncable::BOOKMARKS, folder_node, "testtag");
426 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
421 EXPECT_EQ(wnode.GetIsFolder(), false); 427 EXPECT_EQ(wnode.GetIsFolder(), false);
422 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); 428 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId());
423 EXPECT_EQ(wnode.GetId(), node_id); 429 EXPECT_EQ(wnode.GetId(), node_id);
424 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared 430 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared
425 wnode.SetTitle(UTF8ToWide(test_title)); 431 wnode.SetTitle(UTF8ToWide(test_title));
426 } 432 }
427 433
428 // Now look up should work. 434 // Now look up should work.
429 { 435 {
430 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 436 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
(...skipping 11 matching lines...) Expand all
442 { 448 {
443 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 449 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
444 trans.GetCryptographer()->AddKey(params); 450 trans.GetCryptographer()->AddKey(params);
445 } 451 }
446 { 452 {
447 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 453 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
448 ReadNode root_node(&trans); 454 ReadNode root_node(&trans);
449 root_node.InitByRootLookup(); 455 root_node.InitByRootLookup();
450 456
451 WriteNode password_node(&trans); 457 WriteNode password_node(&trans);
452 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS, 458 sync_api::WriteNode::InitUniqueByCreationResult result =
453 root_node, "foo")); 459 password_node.InitUniqueByCreation(syncable::PASSWORDS,
460 root_node, "foo");
461 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
454 sync_pb::PasswordSpecificsData data; 462 sync_pb::PasswordSpecificsData data;
455 data.set_password_value("secret"); 463 data.set_password_value("secret");
456 password_node.SetPasswordSpecifics(data); 464 password_node.SetPasswordSpecifics(data);
457 } 465 }
458 { 466 {
459 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 467 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
460 ReadNode root_node(&trans); 468 ReadNode root_node(&trans);
461 root_node.InitByRootLookup(); 469 root_node.InitByRootLookup();
462 470
463 ReadNode password_node(&trans); 471 ReadNode password_node(&trans);
(...skipping 12 matching lines...) Expand all
476 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 484 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
477 trans.GetCryptographer()->AddKey(params); 485 trans.GetCryptographer()->AddKey(params);
478 trans.GetCryptographer()->set_encrypt_everything(); 486 trans.GetCryptographer()->set_encrypt_everything();
479 } 487 }
480 { 488 {
481 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 489 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
482 ReadNode root_node(&trans); 490 ReadNode root_node(&trans);
483 root_node.InitByRootLookup(); 491 root_node.InitByRootLookup();
484 492
485 WriteNode bookmark_node(&trans); 493 WriteNode bookmark_node(&trans);
486 EXPECT_TRUE(bookmark_node.InitUniqueByCreation(syncable::BOOKMARKS, 494 sync_api::WriteNode::InitUniqueByCreationResult result =
487 root_node, "foo")); 495 bookmark_node.InitUniqueByCreation(syncable::BOOKMARKS,
496 root_node, "foo");
497 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
488 bookmark_node.SetTitle(UTF8ToWide("foo")); 498 bookmark_node.SetTitle(UTF8ToWide("foo"));
489 499
490 WriteNode pref_node(&trans); 500 WriteNode pref_node(&trans);
491 EXPECT_TRUE(pref_node.InitUniqueByCreation(syncable::PREFERENCES, 501 result =
492 root_node, "bar")); 502 pref_node.InitUniqueByCreation(syncable::PREFERENCES, root_node, "bar");
503 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
493 pref_node.SetTitle(UTF8ToWide("bar")); 504 pref_node.SetTitle(UTF8ToWide("bar"));
494 } 505 }
495 { 506 {
496 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 507 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
497 ReadNode root_node(&trans); 508 ReadNode root_node(&trans);
498 root_node.InitByRootLookup(); 509 root_node.InitByRootLookup();
499 510
500 ReadNode bookmark_node(&trans); 511 ReadNode bookmark_node(&trans);
501 EXPECT_EQ(BaseNode::INIT_OK, 512 EXPECT_EQ(BaseNode::INIT_OK,
502 bookmark_node.InitByClientTagLookup(syncable::BOOKMARKS, 513 bookmark_node.InitByClientTagLookup(syncable::BOOKMARKS,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 ADD_FAILURE(); 631 ADD_FAILURE();
621 } 632 }
622 } 633 }
623 634
624 TEST_F(SyncApiTest, EmptyTags) { 635 TEST_F(SyncApiTest, EmptyTags) {
625 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 636 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
626 ReadNode root_node(&trans); 637 ReadNode root_node(&trans);
627 root_node.InitByRootLookup(); 638 root_node.InitByRootLookup();
628 WriteNode node(&trans); 639 WriteNode node(&trans);
629 std::string empty_tag; 640 std::string empty_tag;
630 EXPECT_FALSE(node.InitUniqueByCreation( 641 sync_api::WriteNode::InitUniqueByCreationResult result =
631 syncable::TYPED_URLS, root_node, empty_tag)); 642 node.InitUniqueByCreation(syncable::TYPED_URLS, root_node, empty_tag);
643 EXPECT_NE(sync_api::WriteNode::INIT_SUCCESS, result);
632 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION, 644 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION,
633 node.InitByTagLookup(empty_tag)); 645 node.InitByTagLookup(empty_tag));
634 } 646 }
635 647
636 namespace { 648 namespace {
637 649
638 class TestHttpPostProviderInterface : public HttpPostProviderInterface { 650 class TestHttpPostProviderInterface : public HttpPostProviderInterface {
639 public: 651 public:
640 virtual ~TestHttpPostProviderInterface() {} 652 virtual ~TestHttpPostProviderInterface() {}
641 653
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 // Store the default (soon to be old) key. 1591 // Store the default (soon to be old) key.
1580 Cryptographer* cryptographer = trans.GetCryptographer(); 1592 Cryptographer* cryptographer = trans.GetCryptographer();
1581 std::string bootstrap_token; 1593 std::string bootstrap_token;
1582 cryptographer->GetBootstrapToken(&bootstrap_token); 1594 cryptographer->GetBootstrapToken(&bootstrap_token);
1583 verifier.Bootstrap(bootstrap_token); 1595 verifier.Bootstrap(bootstrap_token);
1584 1596
1585 ReadNode root_node(&trans); 1597 ReadNode root_node(&trans);
1586 root_node.InitByRootLookup(); 1598 root_node.InitByRootLookup();
1587 1599
1588 WriteNode password_node(&trans); 1600 WriteNode password_node(&trans);
1589 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS, 1601 sync_api::WriteNode::InitUniqueByCreationResult result =
1590 root_node, "foo")); 1602 password_node.InitUniqueByCreation(syncable::PASSWORDS,
1603 root_node, "foo");
1604 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
1591 sync_pb::PasswordSpecificsData data; 1605 sync_pb::PasswordSpecificsData data;
1592 data.set_password_value("secret"); 1606 data.set_password_value("secret");
1593 password_node.SetPasswordSpecifics(data); 1607 password_node.SetPasswordSpecifics(data);
1594 } 1608 }
1595 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1609 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
1596 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1610 EXPECT_CALL(observer_, OnPassphraseAccepted());
1597 EXPECT_CALL(observer_, OnEncryptionComplete()); 1611 EXPECT_CALL(observer_, OnEncryptionComplete());
1598 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 1612 sync_manager_.SetEncryptionPassphrase("new_passphrase", true);
1599 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); 1613 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
1600 { 1614 {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { 1825 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) {
1812 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1826 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1813 int64 node_id = 0; 1827 int64 node_id = 0;
1814 std::string tag = "foo"; 1828 std::string tag = "foo";
1815 { 1829 {
1816 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1830 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1817 ReadNode root_node(&trans); 1831 ReadNode root_node(&trans);
1818 root_node.InitByRootLookup(); 1832 root_node.InitByRootLookup();
1819 1833
1820 WriteNode password_node(&trans); 1834 WriteNode password_node(&trans);
1821 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS, 1835 sync_api::WriteNode::InitUniqueByCreationResult result =
1822 root_node, tag)); 1836 password_node.InitUniqueByCreation(syncable::PASSWORDS, root_node, tag);
1837 EXPECT_EQ(sync_api::WriteNode::INIT_SUCCESS, result);
1823 node_id = password_node.GetId(); 1838 node_id = password_node.GetId();
1824 } 1839 }
1825 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1840 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
1826 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1841 EXPECT_CALL(observer_, OnPassphraseAccepted());
1827 EXPECT_CALL(observer_, OnEncryptionComplete()); 1842 EXPECT_CALL(observer_, OnEncryptionComplete());
1828 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 1843 sync_manager_.SetEncryptionPassphrase("new_passphrase", true);
1829 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); 1844 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest());
1830 { 1845 {
1831 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1846 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1832 ReadNode password_node(&trans); 1847 ReadNode password_node(&trans);
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
2510 EXPECT_EQ(title, node.GetTitle()); 2525 EXPECT_EQ(title, node.GetTitle());
2511 EXPECT_EQ(GURL(url2), node.GetURL()); 2526 EXPECT_EQ(GURL(url2), node.GetURL());
2512 const syncable::Entry* node_entry = node.GetEntry(); 2527 const syncable::Entry* node_entry = node.GetEntry();
2513 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2528 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2514 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2529 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2515 EXPECT_TRUE(specifics.has_encrypted()); 2530 EXPECT_TRUE(specifics.has_encrypted());
2516 } 2531 }
2517 } 2532 }
2518 2533
2519 } // namespace browser_sync 2534 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_typed_url_unittest.cc ('k') | sync/internal_api/write_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698