diff options
author | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-08 23:04:01 +0000 |
---|---|---|
committer | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-08 23:04:01 +0000 |
commit | 042e15a81d4953d124a9bad49209bef7f3f6e4d7 (patch) | |
tree | a0f8c7b67b7535ebc30c4cbcfa66bbf384abcb27 | |
parent | c8d5fca97530b8c80eaa6b750643a804ff072256 (diff) | |
download | chromium_src-042e15a81d4953d124a9bad49209bef7f3f6e4d7.zip chromium_src-042e15a81d4953d124a9bad49209bef7f3f6e4d7.tar.gz chromium_src-042e15a81d4953d124a9bad49209bef7f3f6e4d7.tar.bz2 |
5 new bookmark sync tests
Add 5 more new bookmark sync tests and a bookmark verifier method to bookmark_model_verifier, it checks duplicate
bookmarks and bookmark folders count in a given bookmark model.
Patch by Vivian Zhi <vivianz@chromium.org>.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4345002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65445 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/live_sync/bookmark_model_verifier.cc | 17 | ||||
-rw-r--r-- | chrome/test/live_sync/bookmark_model_verifier.h | 10 | ||||
-rw-r--r-- | chrome/test/live_sync/live_bookmarks_sync_test.h | 16 | ||||
-rw-r--r-- | chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc | 146 |
4 files changed, 186 insertions, 3 deletions
diff --git a/chrome/test/live_sync/bookmark_model_verifier.cc b/chrome/test/live_sync/bookmark_model_verifier.cc index 7f900ae..16f027d 100644 --- a/chrome/test/live_sync/bookmark_model_verifier.cc +++ b/chrome/test/live_sync/bookmark_model_verifier.cc @@ -89,6 +89,23 @@ bool BookmarkModelVerifier::ContainsDuplicateBookmarks(BookmarkModel* model) { return false; } +// static +int BookmarkModelVerifier::CountNodesWithTitlesMatching( + BookmarkModel* model, + BookmarkNode::Type node_type, + const string16& title) { + TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); + // Walk through the model tree looking for bookmark nodes of node type + // |node_type| whose titles match |title|. + int count = 0; + while (iterator.has_next()) { + const BookmarkNode* node = iterator.Next(); + if ((node->type() == node_type) && (node->GetTitle() == title)) + ++count; + } + return count; +} + void BookmarkModelVerifier::FindNodeInVerifier(BookmarkModel* foreign_model, const BookmarkNode* foreign_node, const BookmarkNode** result) { diff --git a/chrome/test/live_sync/bookmark_model_verifier.h b/chrome/test/live_sync/bookmark_model_verifier.h index a500e16..3051ddc 100644 --- a/chrome/test/live_sync/bookmark_model_verifier.h +++ b/chrome/test/live_sync/bookmark_model_verifier.h @@ -9,13 +9,11 @@ #include <string> #include "base/compiler_specific.h" +#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profile.h" #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" -class BookmarkModel; -class BookmarkNode; - // Helper class that performs operations on a bookmark model and echoes the // changes in a verifier model that can be used as an expected hierarchy to // compare against. @@ -112,6 +110,12 @@ class BookmarkModelVerifier { use_verifier_model_ = use_verifier_model; } + // Returns the number of nodes of node type |node_type| in |model| whose + // titles match the string |title|. + static int CountNodesWithTitlesMatching(BookmarkModel* model, + BookmarkNode::Type node_type, + const string16& title); + private: // A pointer to the BookmarkModel object within the verifier_profile_ object // in class LiveSyncTest. All verifications are done against this object. diff --git a/chrome/test/live_sync/live_bookmarks_sync_test.h b/chrome/test/live_sync/live_bookmarks_sync_test.h index 9e8bfa0..e34bf4d 100644 --- a/chrome/test/live_sync/live_bookmarks_sync_test.h +++ b/chrome/test/live_sync/live_bookmarks_sync_test.h @@ -262,6 +262,22 @@ class LiveBookmarksSyncTest : public LiveSyncTest { return nodes[0]; } + // Returns the number of bookmarks in bookmark model of profile |profile| + // whose titles match the string |title|. + int CountBookmarksWithTitlesMatching(int profile, const std::wstring& title) + WARN_UNUSED_RESULT { + return verifier_helper_->CountNodesWithTitlesMatching( + GetBookmarkModel(profile), BookmarkNode::URL, WideToUTF16(title)); + } + + // Returns the number of bookmark folders in the bookmark model of profile + // |profile| whose titles contain the query string |title|. + int CountFoldersWithTitlesMatching(int profile, + const std::wstring& title) WARN_UNUSED_RESULT { + return verifier_helper_->CountNodesWithTitlesMatching( + GetBookmarkModel(profile), BookmarkNode::FOLDER, WideToUTF16(title)); + } + private: // Helper object that has the functionality to verify changes made to the // bookmarks of individual profiles. diff --git a/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc b/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc index 11e5ed0..d91258f 100644 --- a/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc @@ -1305,3 +1305,149 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, ASSERT_TRUE(AllModelsMatch()); ASSERT_FALSE(ContainsDuplicateBookmarks(0)); } + +// Test Scribe ID - 386587 - Merge subsets of bookmark under bookmark bar. +IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, + MC_MergeSimpleBMHierarchySubsetUnderBookmarkBar) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + DisableVerifier(); + + for (int i = 0; i < 4; ++i) { + std::wstring title = IndexedURLTitle(i); + GURL url = GURL(IndexedURL(i)); + ASSERT_TRUE(AddURL(0, i, title, url) != NULL); + } + + for (int j = 0; j < 2; ++j) { + std::wstring title = IndexedURLTitle(j); + GURL url = GURL(IndexedURL(j)); + ASSERT_TRUE(AddURL(1, j, title, url) != NULL); + } + + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AllModelsMatch()); + ASSERT_FALSE(ContainsDuplicateBookmarks(0)); + ASSERT_FALSE(ContainsDuplicateBookmarks(1)); +} + +// Test Scribe ID - 386590 - Merge subsets of bookmark under bookmark folder. +IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, + MC_MergeSimpleBMHierarchyUnderBMFolder) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + DisableVerifier(); + + const BookmarkNode* folder0 = AddGroup(0, 0, kGenericFolderName); + ASSERT_TRUE(folder0 != NULL); + ASSERT_TRUE(AddURL(0, folder0, 0, IndexedURLTitle(1), + GURL(IndexedURL(1))) != NULL); + ASSERT_TRUE(AddGroup(0, folder0, 1, IndexedSubfolderName(2)) != NULL); + ASSERT_TRUE(AddURL(0, folder0, 2, IndexedURLTitle(3), + GURL(IndexedURL(3))) != NULL); + ASSERT_TRUE(AddGroup(0, folder0, 3, IndexedSubfolderName(4)) != NULL); + + const BookmarkNode* folder1 = AddGroup(1, 0, kGenericFolderName); + ASSERT_TRUE(folder1 != NULL); + ASSERT_TRUE(AddGroup(1, folder1, 0, IndexedSubfolderName(0)) != NULL); + ASSERT_TRUE(AddGroup(1, folder1, 1, IndexedSubfolderName(2)) != NULL); + ASSERT_TRUE(AddURL(1, folder1, 2, IndexedURLTitle(3), + GURL(IndexedURL(3))) != NULL); + ASSERT_TRUE(AddGroup(1, folder1, 3, IndexedSubfolderName(5)) != NULL); + ASSERT_TRUE(AddURL(1, folder1, 4, IndexedURLTitle(1), + GURL(IndexedURL(1))) != NULL); + + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AllModelsMatch()); + ASSERT_FALSE(ContainsDuplicateBookmarks(0)); +} + +// Test Scribe ID - 386592 - Merge disjoint sets of bookmark hierarchy under +// bookmark folder. +IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, + MC_MergeSimpleBMHierarchyDisjointSetsUnderBMFolder) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + DisableVerifier(); + + const BookmarkNode* folder0 = AddGroup(0, 0, kGenericFolderName); + ASSERT_TRUE(folder0 != NULL); + ASSERT_TRUE(AddURL(0, folder0, 0, IndexedURLTitle(1), + GURL(IndexedURL(1))) != NULL); + ASSERT_TRUE(AddGroup(0, folder0, 1, IndexedSubfolderName(2)) != NULL); + ASSERT_TRUE(AddURL(0, folder0, 2, IndexedURLTitle(3), + GURL(IndexedURL(3))) != NULL); + ASSERT_TRUE(AddGroup(0, folder0, 3, IndexedSubfolderName(4)) != NULL); + + const BookmarkNode* folder1 = AddGroup(1, 0, kGenericFolderName); + ASSERT_TRUE(folder1 != NULL); + ASSERT_TRUE(AddGroup(1, folder1, 0, IndexedSubfolderName(5)) != NULL); + ASSERT_TRUE(AddGroup(1, folder1, 1, IndexedSubfolderName(6)) != NULL); + ASSERT_TRUE(AddURL(1, folder1, 2, IndexedURLTitle(7), + GURL(IndexedURL(7))) != NULL); + ASSERT_TRUE(AddURL(1, folder1, 3, IndexedURLTitle(8), + GURL(IndexedURL(8))) != NULL); + + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AllModelsMatch()); + ASSERT_FALSE(ContainsDuplicateBookmarks(0)); +} + +// Test Scribe ID - 386588 - Merge disjoint sets of bookmark hierarchy under +// bookmark bar. +IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, + MC_MergeSimpleBMHierarchyDisjointSetsUnderBookmarkBar) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + DisableVerifier(); + + for (int i = 0; i < 3; ++i) { + std::wstring title = IndexedURLTitle(i+1); + GURL url = GURL(IndexedURL(i+1)); + ASSERT_TRUE(AddURL(0, i, title, url) != NULL); + } + + for (int j = 0; j < 3; ++j) { + std::wstring title = IndexedURLTitle(j+4); + GURL url = GURL(IndexedURL(j+4)); + ASSERT_TRUE(AddURL(0, j, title, url) != NULL); + } + + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AllModelsMatch()); + ASSERT_FALSE(ContainsDuplicateBookmarks(0)); +} + +// Test Scribe ID - 386593 - Merge sets of duplicate bookmarks under bookmark +// bar. +IN_PROC_BROWSER_TEST_F(TwoClientLiveBookmarksSyncTest, + MC_MergeSimpleBMHierarchyDuplicateBMsUnderBMBar) { + ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; + DisableVerifier(); + + // Let's add duplicate set of bookmark {1,2,2,3,3,3,4,4,4,4} to client0. + int node_index = 0; + for (int i = 1; i < 5 ; ++i) { + for (int j = 0; j < i; ++j) { + std::wstring title = IndexedURLTitle(i); + GURL url = GURL(IndexedURL(i)); + ASSERT_TRUE(AddURL(0, node_index, title, url) != NULL); + ++node_index; + } + } + // Let's add a set of bookmarks {1,2,3,4} to client1. + for (int i = 0; i < 4; ++i) { + std::wstring title = IndexedURLTitle(i+1); + GURL url = GURL(IndexedURL(i+1)); + ASSERT_TRUE(AddURL(1, i, title, url) != NULL); + } + + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + ASSERT_TRUE(AwaitQuiescence()); + ASSERT_TRUE(AllModelsMatch()); + + for (int i = 1; i < 5 ; ++i) { + ASSERT_TRUE(CountBookmarksWithTitlesMatching(1, IndexedURLTitle(i)) == i); + } +} + |