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

Unified Diff: chrome/browser/sync/profile_sync_service_bookmark_unittest.cc

Issue 15308003: sync: Test and improve bookmark performance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comments Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sync/syncable/syncable_write_transaction.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6711fe6cfd2805920d1d500084a17866b0da7bcb..3c58b5cc80a1aa4b2e2a82b7c90589247bf9de5b 100644
--- a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
@@ -19,6 +19,7 @@
#include "base/message_loop.h"
#include "base/string16.h"
#include "base/string_util.h"
+#include "base/stringprintf.h"
#include "base/strings/string_number_conversions.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
@@ -287,6 +288,58 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
test_user_share_.TearDown();
}
+ // Inserts a folder directly to the share.
+ // Do not use this after model association is complete.
+ //
+ // This function differs from the AddFolder() function declared elsewhere in
+ // this file in that it only affects the sync model. It would be invalid to
+ // change the sync model directly after ModelAssociation. This function can
+ // be invoked prior to model association to set up first-time sync model
+ // association scenarios.
+ int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) {
+ EXPECT_FALSE(model_associator_);
+
+ // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail.
+ syncer::ReadNode bookmark_bar(trans);
+ EXPECT_EQ(BaseNode::INIT_OK, bookmark_bar.InitByTagLookup("bookmark_bar"));
+
+ syncer::WriteNode node(trans);
+ EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL));
+ node.SetIsFolder(true);
+ node.SetTitle(ASCIIToWide(title));
+
+ return node.GetId();
+ }
+
+ // Inserts a bookmark directly to the share.
+ // Do not use this after model association is complete.
+ //
+ // This function differs from the AddURL() function declared elsewhere in this
+ // file in that it only affects the sync model. It would be invalid to change
+ // the sync model directly after ModelAssociation. This function can be
+ // invoked prior to model association to set up first-time sync model
+ // association scenarios.
+ int64 AddBookmarkToShare(syncer::WriteTransaction *trans,
+ int64 parent_id,
+ std::string title) {
+ EXPECT_FALSE(model_associator_);
+
+ syncer::ReadNode parent(trans);
+ EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
+
+ sync_pb::BookmarkSpecifics specifics;
+ specifics.set_url("http://www.google.com/search?q=" + title);
+ specifics.set_title(title);
+
+ syncer::WriteNode node(trans);
+ EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL));
+ node.SetIsFolder(false);
+ node.SetTitle(ASCIIToWide(title));
+ node.SetBookmarkSpecifics(specifics);
+
+ return node.GetId();
+ }
+
// Load (or re-load) the bookmark model. |load| controls use of the
// bookmarks file on disk. |save| controls whether the newly loaded
// bookmark model will write out a bookmark file as it goes.
@@ -625,6 +678,41 @@ TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
ExpectModelMatch();
}
+// Populate the sync database then start model association. Sync's bookmarks
+// should end up being copied into the native model, resulting in a successful
+// "ExpectModelMatch()".
+//
+// This code has some use for verifying correctness. It's also a very useful
+// for profiling bookmark ModelAssociation, an important part of some first-time
+// sync scenarios. Simply increase the kNumFolders and kNumBookmarksPerFolder
+// as desired, then run the test under a profiler to find hot spots in the model
+// association code.
+TEST_F(ProfileSyncServiceBookmarkTest, InitialModelAssociate) {
+ const int kNumBookmarksPerFolder = 10;
+ const int kNumFolders = 10;
+
+ CreatePermanentBookmarkNodes();
+
+ {
+ syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
+ for (int i = 0; i < kNumFolders; ++i) {
+ int64 folder_id = AddFolderToShare(&trans,
+ base::StringPrintf("folder%05d", i));
+ for (int j = 0; j < kNumBookmarksPerFolder; ++j) {
+ AddBookmarkToShare(&trans,
+ folder_id,
+ base::StringPrintf("bookmark%05d", j));
+ }
+ }
+ }
+
+ LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
+ StartSync();
+
+ ExpectModelMatch();
+}
+
+
TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) {
LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
StartSync();
« no previous file with comments | « no previous file | sync/syncable/syncable_write_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698