Chromium Code Reviews| 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 <stack> | 5 #include <stack> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 using browser_sync::SyncBackendHost; | 47 using browser_sync::SyncBackendHost; |
| 48 using browser_sync::SyncBackendHostMock; | 48 using browser_sync::SyncBackendHostMock; |
| 49 using browser_sync::UnrecoverableErrorHandler; | 49 using browser_sync::UnrecoverableErrorHandler; |
| 50 using testing::_; | 50 using testing::_; |
| 51 using testing::Return; | 51 using testing::Return; |
| 52 using testing::WithArg; | 52 using testing::WithArg; |
| 53 using testing::Invoke; | 53 using testing::Invoke; |
| 54 | 54 |
| 55 class TestBookmarkModelAssociator : public BookmarkModelAssociator { | 55 class TestBookmarkModelAssociator : public BookmarkModelAssociator { |
| 56 public: | 56 public: |
| 57 TestBookmarkModelAssociator(TestProfileSyncService* service, | 57 TestBookmarkModelAssociator( |
| 58 TestProfileSyncService* service, | |
| 58 UnrecoverableErrorHandler* persist_ids_error_handler) | 59 UnrecoverableErrorHandler* persist_ids_error_handler) |
| 59 : BookmarkModelAssociator(service, persist_ids_error_handler), | 60 : BookmarkModelAssociator(service, persist_ids_error_handler), |
| 60 helper_(new TestModelAssociatorHelper(service->id_factory())) { | 61 id_factory_(service->id_factory()) {} |
| 62 | |
| 63 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { | |
|
tim (not reviewing)
2011/01/21 18:17:00
Im not sure I get what happened in here. Are you s
akalin
2011/01/21 21:21:09
So this logic basically lazily creates any tagged
| |
| 64 std::wstring tag_wide; | |
| 65 if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) { | |
| 66 NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag; | |
| 67 return false; | |
| 68 } | |
| 69 | |
| 70 browser_sync::SyncBackendHost::UserShareHandle share( | |
| 71 sync_service_->GetUserShareHandle()); | |
| 72 bool root_exists = false; | |
| 73 syncable::ModelType type = model_type(); | |
| 74 { | |
| 75 sync_api::WriteTransaction trans(share); | |
| 76 sync_api::ReadNode uber_root(&trans); | |
| 77 uber_root.InitByRootLookup(); | |
| 78 | |
| 79 sync_api::ReadNode root(&trans); | |
| 80 root_exists = root.InitByTagLookup( | |
| 81 ProfileSyncServiceTestHelper::GetTagForType(type)); | |
| 82 } | |
| 83 | |
| 84 if (!root_exists) { | |
| 85 bool created = ProfileSyncServiceTestHelper::CreateRoot( | |
| 86 type, | |
| 87 sync_service_->GetUserShareHandle(), | |
| 88 id_factory_); | |
| 89 if (!created) | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 sync_api::WriteTransaction trans(share); | |
| 94 sync_api::ReadNode root(&trans); | |
| 95 EXPECT_TRUE(root.InitByTagLookup( | |
| 96 ProfileSyncServiceTestHelper::GetTagForType(type))); | |
| 97 | |
| 98 // First, try to find a node with the title among the root's children. | |
| 99 // This will be the case if we are testing model persistence, and | |
| 100 // are reloading a sync repository created earlier in the test. | |
| 101 int64 last_child_id = sync_api::kInvalidId; | |
| 102 for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) { | |
| 103 sync_api::ReadNode child(&trans); | |
| 104 child.InitByIdLookup(id); | |
| 105 last_child_id = id; | |
| 106 if (tag_wide == child.GetTitle()) { | |
| 107 *sync_id = id; | |
| 108 return true; | |
| 109 } | |
| 110 id = child.GetSuccessorId(); | |
| 111 } | |
| 112 | |
| 113 sync_api::ReadNode predecessor_node(&trans); | |
| 114 sync_api::ReadNode* predecessor = NULL; | |
| 115 if (last_child_id != sync_api::kInvalidId) { | |
| 116 predecessor_node.InitByIdLookup(last_child_id); | |
| 117 predecessor = &predecessor_node; | |
| 118 } | |
| 119 sync_api::WriteNode node(&trans); | |
| 120 // Create new fake tagged nodes at the end of the ordering. | |
| 121 node.InitByCreation(type, root, predecessor); | |
| 122 node.SetIsFolder(true); | |
| 123 node.SetTitle(tag_wide); | |
| 124 node.SetExternalId(0); | |
| 125 *sync_id = node.GetId(); | |
| 126 return true; | |
| 61 } | 127 } |
| 62 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { | 128 |
| 63 return helper_->GetSyncIdForTaggedNode(this, tag, sync_id); | |
| 64 } | |
| 65 private: | 129 private: |
| 66 scoped_ptr<TestModelAssociatorHelper> helper_; | 130 browser_sync::TestIdFactory* id_factory_; |
| 67 }; | 131 }; |
| 68 | 132 |
| 69 // FakeServerChange constructs a list of sync_api::ChangeRecords while modifying | 133 // FakeServerChange constructs a list of sync_api::ChangeRecords while modifying |
| 70 // the sync model, and can pass the ChangeRecord list to a | 134 // the sync model, and can pass the ChangeRecord list to a |
| 71 // sync_api::SyncObserver (i.e., the ProfileSyncService) to test the client | 135 // sync_api::SyncObserver (i.e., the ProfileSyncService) to test the client |
| 72 // change-application behavior. | 136 // change-application behavior. |
| 73 // Tests using FakeServerChange should be careful to avoid back-references, | 137 // Tests using FakeServerChange should be careful to avoid back-references, |
| 74 // since FakeServerChange will send the edits in the order specified. | 138 // since FakeServerChange will send the edits in the order specified. |
| 75 class FakeServerChange { | 139 class FakeServerChange { |
| 76 public: | 140 public: |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 &gnext)); | 399 &gnext)); |
| 336 EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId()); | 400 EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId()); |
| 337 EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId()); | 401 EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId()); |
| 338 } | 402 } |
| 339 if (bnode->GetChildCount()) { | 403 if (bnode->GetChildCount()) { |
| 340 EXPECT_TRUE(gnode.GetFirstChildId()); | 404 EXPECT_TRUE(gnode.GetFirstChildId()); |
| 341 } | 405 } |
| 342 } | 406 } |
| 343 | 407 |
| 344 void ExpectSyncerNodeMatching(const BookmarkNode* bnode) { | 408 void ExpectSyncerNodeMatching(const BookmarkNode* bnode) { |
| 345 sync_api::ReadTransaction trans(service_->backend_->GetUserShareHandle()); | 409 sync_api::ReadTransaction trans(service_->GetUserShareHandle()); |
| 346 ExpectSyncerNodeMatching(&trans, bnode); | 410 ExpectSyncerNodeMatching(&trans, bnode); |
| 347 } | 411 } |
| 348 | 412 |
| 349 void ExpectBrowserNodeMatching(sync_api::BaseTransaction* trans, | 413 void ExpectBrowserNodeMatching(sync_api::BaseTransaction* trans, |
| 350 int64 sync_id) { | 414 int64 sync_id) { |
| 351 EXPECT_TRUE(sync_id); | 415 EXPECT_TRUE(sync_id); |
| 352 const BookmarkNode* bnode = | 416 const BookmarkNode* bnode = |
| 353 associator()->GetChromeNodeFromSyncId(sync_id); | 417 associator()->GetChromeNodeFromSyncId(sync_id); |
| 354 ASSERT_TRUE(bnode); | 418 ASSERT_TRUE(bnode); |
| 355 int64 id = associator()->GetSyncIdFromChromeId(bnode->id()); | 419 int64 id = associator()->GetSyncIdFromChromeId(bnode->id()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 ExpectBrowserNodeMatching(trans, id); | 477 ExpectBrowserNodeMatching(trans, id); |
| 414 | 478 |
| 415 sync_api::ReadNode gnode(trans); | 479 sync_api::ReadNode gnode(trans); |
| 416 ASSERT_TRUE(gnode.InitByIdLookup(id)); | 480 ASSERT_TRUE(gnode.InitByIdLookup(id)); |
| 417 stack.push(gnode.GetFirstChildId()); | 481 stack.push(gnode.GetFirstChildId()); |
| 418 stack.push(gnode.GetSuccessorId()); | 482 stack.push(gnode.GetSuccessorId()); |
| 419 } | 483 } |
| 420 } | 484 } |
| 421 | 485 |
| 422 void ExpectModelMatch() { | 486 void ExpectModelMatch() { |
| 423 sync_api::ReadTransaction trans(service_->backend_->GetUserShareHandle()); | 487 sync_api::ReadTransaction trans(service_->GetUserShareHandle()); |
| 424 ExpectModelMatch(&trans); | 488 ExpectModelMatch(&trans); |
| 425 } | 489 } |
| 426 | 490 |
| 427 int64 other_bookmarks_id() { | 491 int64 other_bookmarks_id() { |
| 428 return associator()->GetSyncIdFromChromeId(model_->other_node()->id()); | 492 return associator()->GetSyncIdFromChromeId(model_->other_node()->id()); |
| 429 } | 493 } |
| 430 | 494 |
| 431 int64 bookmark_bar_id() { | 495 int64 bookmark_bar_id() { |
| 432 return associator()->GetSyncIdFromChromeId( | 496 return associator()->GetSyncIdFromChromeId( |
| 433 model_->GetBookmarkBarNode()->id()); | 497 model_->GetBookmarkBarNode()->id()); |
| 434 } | 498 } |
| 435 | 499 |
| 436 SyncBackendHost* backend() { return service_->backend_.get(); } | |
| 437 | |
| 438 // This serves as the "UI loop" on which the ProfileSyncService lives and | 500 // This serves as the "UI loop" on which the ProfileSyncService lives and |
| 439 // operates. It is needed because the SyncBackend can post tasks back to | 501 // operates. It is needed because the SyncBackend can post tasks back to |
| 440 // the service, meaning it can't be null. It doesn't have to be running, | 502 // the service, meaning it can't be null. It doesn't have to be running, |
| 441 // though -- OnInitializationCompleted is the only example (so far) in this | 503 // though -- OnInitializationCompleted is the only example (so far) in this |
| 442 // test where we need to Run the loop to swallow a task and then quit, to | 504 // test where we need to Run the loop to swallow a task and then quit, to |
| 443 // avoid leaking the ProfileSyncService (the PostTask will retain the callee | 505 // avoid leaking the ProfileSyncService (the PostTask will retain the callee |
| 444 // and caller until the task is run). | 506 // and caller until the task is run). |
| 445 MessageLoop message_loop_; | 507 MessageLoop message_loop_; |
| 446 BrowserThread ui_thread_; | 508 BrowserThread ui_thread_; |
| 447 BrowserThread file_thread_; | 509 BrowserThread file_thread_; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 // Delete an item with several children. | 603 // Delete an item with several children. |
| 542 model_->Remove(folder2->GetParent(), | 604 model_->Remove(folder2->GetParent(), |
| 543 folder2->GetParent()->IndexOfChild(folder2)); | 605 folder2->GetParent()->IndexOfChild(folder2)); |
| 544 ExpectModelMatch(); | 606 ExpectModelMatch(); |
| 545 } | 607 } |
| 546 | 608 |
| 547 TEST_F(ProfileSyncServiceTest, ServerChangeProcessing) { | 609 TEST_F(ProfileSyncServiceTest, ServerChangeProcessing) { |
| 548 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 610 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
| 549 StartSyncService(); | 611 StartSyncService(); |
| 550 | 612 |
| 551 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 613 sync_api::WriteTransaction trans(service_->GetUserShareHandle()); |
| 552 | 614 |
| 553 FakeServerChange adds(&trans); | 615 FakeServerChange adds(&trans); |
| 554 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0); | 616 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0); |
| 555 int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1); | 617 int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1); |
| 556 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/", | 618 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/", |
| 557 bookmark_bar_id(), f2); | 619 bookmark_bar_id(), f2); |
| 558 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0); | 620 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0); |
| 559 // u3 is a duplicate URL | 621 // u3 is a duplicate URL |
| 560 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2); | 622 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2); |
| 561 // u4 is a duplicate title, different URL. | 623 // u4 is a duplicate title, different URL. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 } | 692 } |
| 631 | 693 |
| 632 // Tests a specific case in ApplyModelChanges where we move the | 694 // Tests a specific case in ApplyModelChanges where we move the |
| 633 // children out from under a parent, and then delete the parent | 695 // children out from under a parent, and then delete the parent |
| 634 // in the same changelist. The delete shows up first in the changelist, | 696 // in the same changelist. The delete shows up first in the changelist, |
| 635 // requiring the children to be moved to a temporary location. | 697 // requiring the children to be moved to a temporary location. |
| 636 TEST_F(ProfileSyncServiceTest, ServerChangeRequiringFosterParent) { | 698 TEST_F(ProfileSyncServiceTest, ServerChangeRequiringFosterParent) { |
| 637 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 699 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
| 638 StartSyncService(); | 700 StartSyncService(); |
| 639 | 701 |
| 640 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 702 sync_api::WriteTransaction trans(service_->GetUserShareHandle()); |
| 641 | 703 |
| 642 // Stress the immediate children of other_node because that's where | 704 // Stress the immediate children of other_node because that's where |
| 643 // ApplyModelChanges puts a temporary foster parent node. | 705 // ApplyModelChanges puts a temporary foster parent node. |
| 644 std::string url("http://dev.chromium.org/"); | 706 std::string url("http://dev.chromium.org/"); |
| 645 FakeServerChange adds(&trans); | 707 FakeServerChange adds(&trans); |
| 646 int64 f0 = other_bookmarks_id(); // + other_node | 708 int64 f0 = other_bookmarks_id(); // + other_node |
| 647 int64 f1 = adds.AddFolder(L"f1", f0, 0); // + f1 | 709 int64 f1 = adds.AddFolder(L"f1", f0, 0); // + f1 |
| 648 int64 f2 = adds.AddFolder(L"f2", f1, 0); // + f2 | 710 int64 f2 = adds.AddFolder(L"f2", f1, 0); // + f2 |
| 649 int64 u3 = adds.AddURL( L"u3", url, f2, 0); // + u3 NOLINT | 711 int64 u3 = adds.AddURL( L"u3", url, f2, 0); // + u3 NOLINT |
| 650 int64 u4 = adds.AddURL( L"u4", url, f2, u3); // + u4 NOLINT | 712 int64 u4 = adds.AddURL( L"u4", url, f2, u3); // + u4 NOLINT |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 679 | 741 |
| 680 ExpectModelMatch(&trans); | 742 ExpectModelMatch(&trans); |
| 681 } | 743 } |
| 682 | 744 |
| 683 // Simulate a server change record containing a valid but non-canonical URL. | 745 // Simulate a server change record containing a valid but non-canonical URL. |
| 684 TEST_F(ProfileSyncServiceTest, ServerChangeWithNonCanonicalURL) { | 746 TEST_F(ProfileSyncServiceTest, ServerChangeWithNonCanonicalURL) { |
| 685 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); | 747 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); |
| 686 StartSyncService(); | 748 StartSyncService(); |
| 687 | 749 |
| 688 { | 750 { |
| 689 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 751 sync_api::WriteTransaction trans(service_->GetUserShareHandle()); |
| 690 | 752 |
| 691 FakeServerChange adds(&trans); | 753 FakeServerChange adds(&trans); |
| 692 std::string url("http://dev.chromium.org"); | 754 std::string url("http://dev.chromium.org"); |
| 693 EXPECT_NE(GURL(url).spec(), url); | 755 EXPECT_NE(GURL(url).spec(), url); |
| 694 adds.AddURL(L"u1", url, other_bookmarks_id(), 0); | 756 adds.AddURL(L"u1", url, other_bookmarks_id(), 0); |
| 695 | 757 |
| 696 adds.ApplyPendingChanges(change_processor()); | 758 adds.ApplyPendingChanges(change_processor()); |
| 697 | 759 |
| 698 EXPECT_TRUE(model_->other_node()->GetChildCount() == 1); | 760 EXPECT_TRUE(model_->other_node()->GetChildCount() == 1); |
| 699 ExpectModelMatch(&trans); | 761 ExpectModelMatch(&trans); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 710 } | 772 } |
| 711 | 773 |
| 712 // Simulate a server change record containing an invalid URL (per GURL). | 774 // Simulate a server change record containing an invalid URL (per GURL). |
| 713 // TODO(ncarter): Disabled due to crashes. Fix bug 1677563. | 775 // TODO(ncarter): Disabled due to crashes. Fix bug 1677563. |
| 714 TEST_F(ProfileSyncServiceTest, DISABLED_ServerChangeWithInvalidURL) { | 776 TEST_F(ProfileSyncServiceTest, DISABLED_ServerChangeWithInvalidURL) { |
| 715 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); | 777 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); |
| 716 StartSyncService(); | 778 StartSyncService(); |
| 717 | 779 |
| 718 int child_count = 0; | 780 int child_count = 0; |
| 719 { | 781 { |
| 720 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 782 sync_api::WriteTransaction trans(service_->GetUserShareHandle()); |
| 721 | 783 |
| 722 FakeServerChange adds(&trans); | 784 FakeServerChange adds(&trans); |
| 723 std::string url("x"); | 785 std::string url("x"); |
| 724 EXPECT_FALSE(GURL(url).is_valid()); | 786 EXPECT_FALSE(GURL(url).is_valid()); |
| 725 adds.AddURL(L"u1", url, other_bookmarks_id(), 0); | 787 adds.AddURL(L"u1", url, other_bookmarks_id(), 0); |
| 726 | 788 |
| 727 adds.ApplyPendingChanges(change_processor()); | 789 adds.ApplyPendingChanges(change_processor()); |
| 728 | 790 |
| 729 // We're lenient about what should happen -- the model could wind up with | 791 // We're lenient about what should happen -- the model could wind up with |
| 730 // the node or without it; but things should be consistent, and we | 792 // the node or without it; but things should be consistent, and we |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 827 | 889 |
| 828 // Add a node which will be the target of the consistency violation. | 890 // Add a node which will be the target of the consistency violation. |
| 829 const BookmarkNode* node = | 891 const BookmarkNode* node = |
| 830 model_->AddGroup(model_->other_node(), 0, ASCIIToUTF16("node")); | 892 model_->AddGroup(model_->other_node(), 0, ASCIIToUTF16("node")); |
| 831 ExpectSyncerNodeMatching(node); | 893 ExpectSyncerNodeMatching(node); |
| 832 | 894 |
| 833 // Now destroy the syncer node as if we were the ProfileSyncService without | 895 // Now destroy the syncer node as if we were the ProfileSyncService without |
| 834 // updating the ProfileSyncService state. This should introduce | 896 // updating the ProfileSyncService state. This should introduce |
| 835 // inconsistency between the two models. | 897 // inconsistency between the two models. |
| 836 { | 898 { |
| 837 sync_api::WriteTransaction trans(service_->backend_->GetUserShareHandle()); | 899 sync_api::WriteTransaction trans(service_->GetUserShareHandle()); |
| 838 sync_api::WriteNode sync_node(&trans); | 900 sync_api::WriteNode sync_node(&trans); |
| 839 EXPECT_TRUE(associator()->InitSyncNodeFromChromeId(node->id(), | 901 EXPECT_TRUE(associator()->InitSyncNodeFromChromeId(node->id(), |
| 840 &sync_node)); | 902 &sync_node)); |
| 841 sync_node.Remove(); | 903 sync_node.Remove(); |
| 842 } | 904 } |
| 843 // The models don't match at this point, but the ProfileSyncService | 905 // The models don't match at this point, but the ProfileSyncService |
| 844 // doesn't know it yet. | 906 // doesn't know it yet. |
| 845 ExpectSyncerNodeKnown(node); | 907 ExpectSyncerNodeKnown(node); |
| 846 EXPECT_TRUE(service_->ShouldPushChanges()); | 908 EXPECT_TRUE(service_->ShouldPushChanges()); |
| 847 | 909 |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 | 1378 |
| 1317 // See what happens if we enable sync but then delete the "Sync Data" | 1379 // See what happens if we enable sync but then delete the "Sync Data" |
| 1318 // folder. | 1380 // folder. |
| 1319 TEST_F(ProfileSyncServiceTestWithData, RecoverAfterDeletingSyncDataDirectory) { | 1381 TEST_F(ProfileSyncServiceTestWithData, RecoverAfterDeletingSyncDataDirectory) { |
| 1320 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); | 1382 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); |
| 1321 StartSyncService(); | 1383 StartSyncService(); |
| 1322 | 1384 |
| 1323 WriteTestDataToBookmarkModel(); | 1385 WriteTestDataToBookmarkModel(); |
| 1324 | 1386 |
| 1325 // While the service is running. | 1387 // While the service is running. |
| 1326 FilePath sync_data_directory = backend()->sync_data_folder_path(); | 1388 FilePath sync_data_directory = |
| 1389 service_->GetTestBackend()->sync_data_folder_path(); | |
| 1327 | 1390 |
| 1328 // Simulate a normal shutdown for the sync service (don't disable it for | 1391 // Simulate a normal shutdown for the sync service (don't disable it for |
| 1329 // the user, which would reset the preferences and delete the sync data | 1392 // the user, which would reset the preferences and delete the sync data |
| 1330 // directory). | 1393 // directory). |
| 1331 StopSyncService(SAVE_TO_STORAGE); | 1394 StopSyncService(SAVE_TO_STORAGE); |
| 1332 | 1395 |
| 1333 // Now pretend that the user has deleted this directory from the disk. | 1396 // Now pretend that the user has deleted this directory from the disk. |
| 1334 file_util::Delete(sync_data_directory, true); | 1397 file_util::Delete(sync_data_directory, true); |
| 1335 | 1398 |
| 1336 // Restart the sync service. Don't fake out setting initial sync ended; lets | 1399 // Restart the sync service. Don't fake out setting initial sync ended; lets |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1381 | 1444 |
| 1382 service_->RegisterDataTypeController( | 1445 service_->RegisterDataTypeController( |
| 1383 new browser_sync::BookmarkDataTypeController(&factory_, | 1446 new browser_sync::BookmarkDataTypeController(&factory_, |
| 1384 profile_.get(), | 1447 profile_.get(), |
| 1385 service_.get())); | 1448 service_.get())); |
| 1386 | 1449 |
| 1387 service_->Initialize(); // will call disableForUser because sync setup | 1450 service_->Initialize(); // will call disableForUser because sync setup |
| 1388 // hasn't been completed. | 1451 // hasn't been completed. |
| 1389 } | 1452 } |
| 1390 | 1453 |
| 1391 ASSERT_FALSE(service_->backend()); | |
| 1392 ASSERT_FALSE(service_->HasSyncSetupCompleted()); | 1454 ASSERT_FALSE(service_->HasSyncSetupCompleted()); |
| 1393 | 1455 |
| 1394 // Create some tokens in the token service; the service will startup when | 1456 // Create some tokens in the token service; the service will startup when |
| 1395 // it is notified that tokens are available. | 1457 // it is notified that tokens are available. |
| 1396 profile_->GetTokenService()->IssueAuthTokenForTest( | 1458 profile_->GetTokenService()->IssueAuthTokenForTest( |
| 1397 GaiaConstants::kSyncService, "sync_token"); | 1459 GaiaConstants::kSyncService, "sync_token"); |
| 1398 | 1460 |
| 1399 syncable::ModelTypeSet set; | 1461 syncable::ModelTypeSet set; |
| 1400 set.insert(syncable::BOOKMARKS); | 1462 set.insert(syncable::BOOKMARKS); |
| 1401 service_->OnUserChoseDatatypes(false, set); | 1463 service_->OnUserChoseDatatypes(false, set); |
| 1402 | 1464 |
| 1403 MessageLoop::current()->RunAllPending(); | 1465 MessageLoop::current()->RunAllPending(); |
| 1404 | 1466 |
| 1405 // Stop the service so we can read the new Sync Data files that were created. | 1467 // Stop the service so we can read the new Sync Data files that were created. |
| 1406 service_.reset(); | 1468 service_.reset(); |
| 1407 | 1469 |
| 1408 // This file should have been deleted when the whole directory was nuked. | 1470 // This file should have been deleted when the whole directory was nuked. |
| 1409 ASSERT_FALSE(file_util::PathExists(sync_file3)); | 1471 ASSERT_FALSE(file_util::PathExists(sync_file3)); |
| 1410 ASSERT_FALSE(file_util::PathExists(sync_file1)); | 1472 ASSERT_FALSE(file_util::PathExists(sync_file1)); |
| 1411 | 1473 |
| 1412 // This will still exist, but the text should have changed. | 1474 // This will still exist, but the text should have changed. |
| 1413 ASSERT_TRUE(file_util::PathExists(sync_file2)); | 1475 ASSERT_TRUE(file_util::PathExists(sync_file2)); |
| 1414 std::string file2text; | 1476 std::string file2text; |
| 1415 file_util::ReadFileToString(sync_file2, &file2text); | 1477 file_util::ReadFileToString(sync_file2, &file2text); |
| 1416 ASSERT_FALSE(file2text.compare(nonsense2) == 0); | 1478 ASSERT_FALSE(file2text.compare(nonsense2) == 0); |
| 1417 } | 1479 } |
| OLD | NEW |