| Index: chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
|
| diff --git a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
|
| index ee82421e9361bafcf6a0cc6d6ec12a338a1cbe11..39e6d74de0ea64c05b25bdfa7056549ba27eb6bb 100644
|
| --- a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
|
| +++ b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include <stack>
|
| #include <vector>
|
|
|
| +#include "base/command_line.h"
|
| #include "base/file_path.h"
|
| #include "base/file_util.h"
|
| #include "base/memory/scoped_ptr.h"
|
| @@ -23,6 +24,7 @@
|
| #include "chrome/browser/sync/glue/bookmark_change_processor.h"
|
| #include "chrome/browser/sync/glue/bookmark_model_associator.h"
|
| #include "chrome/browser/sync/syncable/directory_manager.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/test/sync/engine/test_id_factory.h"
|
| #include "chrome/test/sync/engine/test_user_share.h"
|
| #include "chrome/test/testing_profile.h"
|
| @@ -281,7 +283,8 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
|
| ProfileSyncServiceBookmarkTest()
|
| : ui_thread_(BrowserThread::UI, &message_loop_),
|
| file_thread_(BrowserThread::FILE, &message_loop_),
|
| - model_(NULL) {
|
| + model_(NULL),
|
| + original_command_line_(*CommandLine::ForCurrentProcess()) {
|
| }
|
|
|
| virtual ~ProfileSyncServiceBookmarkTest() {
|
| @@ -291,10 +294,13 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
|
|
|
| virtual void SetUp() {
|
| test_user_share_.SetUp();
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + switches::kEnableSyncedBookmarksFolder);
|
| }
|
|
|
| virtual void TearDown() {
|
| test_user_share_.TearDown();
|
| + *CommandLine::ForCurrentProcess() = original_command_line_;
|
| }
|
|
|
| // Load (or re-load) the bookmark model. |load| controls use of the
|
| @@ -359,8 +365,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
|
| sync_api::ReadNode gnode(trans);
|
| ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode));
|
| // Non-root node titles and parents must match.
|
| - if (bnode != model_->GetBookmarkBarNode() &&
|
| - bnode != model_->other_node()) {
|
| + if (!model_->is_permanent_node(bnode)) {
|
| EXPECT_EQ(bnode->GetTitle(), WideToUTF16Hack(gnode.GetTitle()));
|
| EXPECT_EQ(
|
| model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()),
|
| @@ -459,6 +464,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
|
| const BookmarkNode* root = model_->root_node();
|
| EXPECT_EQ(root->GetIndexOf(model_->GetBookmarkBarNode()), 0);
|
| EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1);
|
| + EXPECT_EQ(root->GetIndexOf(model_->synced_node()), 2);
|
|
|
| std::stack<int64> stack;
|
| stack.push(bookmark_bar_id());
|
| @@ -481,6 +487,11 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
|
| ExpectModelMatch(&trans);
|
| }
|
|
|
| + int64 synced_bookmarks_id() {
|
| + return
|
| + model_associator_->GetSyncIdFromChromeId(model_->synced_node()->id());
|
| + }
|
| +
|
| int64 other_bookmarks_id() {
|
| return
|
| model_associator_->GetSyncIdFromChromeId(model_->other_node()->id());
|
| @@ -503,6 +514,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
|
|
|
| protected:
|
| BookmarkModel* model_;
|
| + CommandLine original_command_line_;
|
| TestUserShare test_user_share_;
|
| scoped_ptr<BookmarkChangeProcessor> change_processor_;
|
| StrictMock<MockUnrecoverableErrorHandler> mock_unrecoverable_error_handler_;
|
| @@ -514,6 +526,7 @@ TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
|
|
|
| EXPECT_TRUE(other_bookmarks_id());
|
| EXPECT_TRUE(bookmark_bar_id());
|
| + EXPECT_TRUE(synced_bookmarks_id());
|
|
|
| ExpectModelMatch();
|
| }
|
| @@ -540,6 +553,11 @@ TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) {
|
| folder, 1, ASCIIToUTF16("Airplanes"), GURL("http://www.easyjet.com/"));
|
| ExpectSyncerNodeMatching(url2);
|
| ExpectModelMatch();
|
| + // Test addition.
|
| + const BookmarkNode* synced_folder =
|
| + model_->AddFolder(model_->synced_node(), 0, ASCIIToUTF16("pie"));
|
| + ExpectSyncerNodeMatching(synced_folder);
|
| + ExpectModelMatch();
|
|
|
| // Test modification.
|
| model_->SetTitle(url2, ASCIIToUTF16("EasyJet"));
|
| @@ -556,6 +574,8 @@ TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) {
|
| ExpectModelMatch();
|
| model_->Copy(url2, model_->GetBookmarkBarNode(), 0);
|
| ExpectModelMatch();
|
| + model_->SetTitle(synced_folder, ASCIIToUTF16("strawberry"));
|
| + ExpectModelMatch();
|
|
|
| // Test deletion.
|
| // Delete a single item.
|
| @@ -565,6 +585,8 @@ TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) {
|
| model_->Remove(folder2->parent(),
|
| folder2->parent()->GetIndexOf(folder2));
|
| ExpectModelMatch();
|
| + model_->Remove(model_->synced_node(), 0);
|
| + ExpectModelMatch();
|
| }
|
|
|
| TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
|
| @@ -591,6 +613,8 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
|
| "scrollbars=0,status=0,toolbar=0,width=300," \
|
| "height=300,resizable');});");
|
| adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0);
|
| + int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/",
|
| + synced_bookmarks_id(), 0);
|
|
|
| std::vector<sync_api::SyncManager::ChangeRecord>::const_iterator it;
|
| // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
|
| @@ -619,6 +643,8 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
|
| // Then add u3 after f1.
|
| int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1);
|
|
|
| + std::wstring u6_old_title = mods.ModifyTitle(u6, L"Synced Folder A");
|
| +
|
| // Test that the property changes have not yet taken effect.
|
| ExpectBrowserNodeTitle(u2, u2_old_title);
|
| /* ExpectBrowserNodeURL(u2, u2_old_url); */
|
| @@ -629,6 +655,8 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
|
|
|
| ExpectBrowserNodeParent(u3, u3_old_parent);
|
|
|
| + ExpectBrowserNodeTitle(u6, u6_old_title);
|
| +
|
| // Apply the changes.
|
| mods.ApplyPendingChanges(change_processor_.get());
|
|
|
| @@ -641,6 +669,7 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
|
| FakeServerChange dels(&trans);
|
| dels.Delete(u2);
|
| dels.Delete(u3);
|
| + dels.Delete(u6);
|
|
|
| ExpectBrowserNodeKnown(u2);
|
| ExpectBrowserNodeKnown(u3);
|
| @@ -649,6 +678,7 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
|
|
|
| ExpectBrowserNodeUnknown(u2);
|
| ExpectBrowserNodeUnknown(u3);
|
| + ExpectBrowserNodeUnknown(u6);
|
| ExpectModelMatch(&trans);
|
| }
|
|
|
| @@ -935,23 +965,31 @@ namespace {
|
| // | |-- f2u3, http://www.f2u3.com/
|
| // | +-- f2u1, http://www.f2u1.com/
|
| // +-- Other bookmarks
|
| -// |-- f3
|
| -// | |-- f3u4, http://www.f3u4.com/
|
| -// | |-- f3u2, http://www.f3u2.com/
|
| -// | |-- f3u3, http://www.f3u3.com/
|
| -// | +-- f3u1, http://www.f3u1.com/
|
| -// |-- u4, http://www.u4.com/
|
| -// |-- u3, http://www.u3.com/
|
| -// --- f4
|
| -// | |-- f4u1, http://www.f4u1.com/
|
| -// | |-- f4u2, http://www.f4u2.com/
|
| -// | |-- f4u3, http://www.f4u3.com/
|
| -// | +-- f4u4, http://www.f4u4.com/
|
| -// |-- dup
|
| -// | +-- dupu1, http://www.dupu1.com/
|
| -// +-- dup
|
| -// +-- dupu2, http://www.dupu1.com/
|
| -//
|
| +// | |-- f3
|
| +// | | |-- f3u4, http://www.f3u4.com/
|
| +// | | |-- f3u2, http://www.f3u2.com/
|
| +// | | |-- f3u3, http://www.f3u3.com/
|
| +// | | +-- f3u1, http://www.f3u1.com/
|
| +// | |-- u4, http://www.u4.com/
|
| +// | |-- u3, http://www.u3.com/
|
| +// | --- f4
|
| +// | | |-- f4u1, http://www.f4u1.com/
|
| +// | | |-- f4u2, http://www.f4u2.com/
|
| +// | | |-- f4u3, http://www.f4u3.com/
|
| +// | | +-- f4u4, http://www.f4u4.com/
|
| +// | |-- dup
|
| +// | | +-- dupu1, http://www.dupu1.com/
|
| +// | +-- dup
|
| +// | +-- dupu2, http://www.dupu1.com/
|
| +// |
|
| +// +-- Synced bookmarks
|
| +// |-- f5
|
| +// | |-- f5u1, http://www.f5u1.com/
|
| +// |-- f6
|
| +// | |-- f6u1, http://www.f6u1.com/
|
| +// | |-- f6u2, http://www.f6u2.com/
|
| +// +-- u5, http://www.u5.com/
|
| +
|
| static TestData kBookmarkBarChildren[] = {
|
| { L"u2", "http://www.u2.com/" },
|
| { L"f1", NULL },
|
| @@ -998,6 +1036,20 @@ static TestData kDup2Children[] = {
|
| { L"dupu2", "http://www.dupu2.com/" },
|
| };
|
|
|
| +static TestData kSyncedBookmarkChildren[] = {
|
| + { L"f5", NULL },
|
| + { L"f6", NULL },
|
| + { L"u5", "http://www.u5.com/" },
|
| +};
|
| +static TestData kF5Children[] = {
|
| + { L"f5u1", "http://www.f5u1.com/" },
|
| + { L"f5u2", "http://www.f5u2.com/" },
|
| +};
|
| +static TestData kF6Children[] = {
|
| + { L"f6u1", "http://www.f6u1.com/" },
|
| + { L"f6u2", "http://www.f6u2.com/" },
|
| +};
|
| +
|
| } // anonymous namespace.
|
|
|
| void ProfileSyncServiceBookmarkTestWithData::PopulateFromTestData(
|
| @@ -1065,6 +1117,17 @@ void ProfileSyncServiceBookmarkTestWithData::WriteTestDataToBookmarkModel() {
|
| dup_node = other_bookmarks_node->GetChild(5);
|
| PopulateFromTestData(dup_node, kDup2Children, arraysize(kDup2Children));
|
|
|
| + const BookmarkNode* synced_bookmarks_node = model_->synced_node();
|
| + PopulateFromTestData(synced_bookmarks_node,
|
| + kSyncedBookmarkChildren,
|
| + arraysize(kSyncedBookmarkChildren));
|
| +
|
| + ASSERT_GE(synced_bookmarks_node->child_count(), 3);
|
| + const BookmarkNode* f5_node = synced_bookmarks_node->GetChild(0);
|
| + PopulateFromTestData(f5_node, kF5Children, arraysize(kF5Children));
|
| + const BookmarkNode* f6_node = synced_bookmarks_node->GetChild(1);
|
| + PopulateFromTestData(f6_node, kF6Children, arraysize(kF6Children));
|
| +
|
| ExpectBookmarkModelMatchesTestData();
|
| }
|
|
|
| @@ -1095,6 +1158,18 @@ void ProfileSyncServiceBookmarkTestWithData::
|
| CompareWithTestData(dup_node, kDup1Children, arraysize(kDup1Children));
|
| dup_node = other_bookmarks_node->GetChild(5);
|
| CompareWithTestData(dup_node, kDup2Children, arraysize(kDup2Children));
|
| +
|
| + const BookmarkNode* synced_bookmarks_node = model_->synced_node();
|
| + CompareWithTestData(synced_bookmarks_node,
|
| + kSyncedBookmarkChildren,
|
| + arraysize(kSyncedBookmarkChildren));
|
| +
|
| + ASSERT_GE(synced_bookmarks_node->child_count(), 3);
|
| + const BookmarkNode* f5_node = synced_bookmarks_node->GetChild(0);
|
| + CompareWithTestData(f5_node, kF5Children, arraysize(kF5Children));
|
| + const BookmarkNode* f6_node = synced_bookmarks_node->GetChild(1);
|
| + CompareWithTestData(f6_node, kF6Children, arraysize(kF6Children));
|
| +
|
| }
|
|
|
| // Tests persistence of the profile sync service by unloading the
|
| @@ -1161,6 +1236,7 @@ TEST_F(ProfileSyncServiceBookmarkTestWithData, MergeWithEmptyBookmarkModel) {
|
| LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
|
| EXPECT_EQ(model_->GetBookmarkBarNode()->child_count(), 0);
|
| EXPECT_EQ(model_->other_node()->child_count(), 0);
|
| + EXPECT_EQ(model_->synced_node()->child_count(), 0);
|
|
|
| // Now restart the sync service. Starting it should populate the bookmark
|
| // model -- test for consistency.
|
|
|