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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | sync/syncable/syncable_write_transaction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // TODO(akalin): This file is basically just a unit test for 5 // TODO(akalin): This file is basically just a unit test for
6 // BookmarkChangeProcessor. Write unit tests for 6 // BookmarkChangeProcessor. Write unit tests for
7 // BookmarkModelAssociator separately. 7 // BookmarkModelAssociator separately.
8 8
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
11 #include <stack> 11 #include <stack>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/string16.h" 20 #include "base/string16.h"
21 #include "base/string_util.h" 21 #include "base/string_util.h"
22 #include "base/stringprintf.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "base/time.h" 24 #include "base/time.h"
24 #include "base/utf_string_conversions.h" 25 #include "base/utf_string_conversions.h"
25 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" 26 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
26 #include "chrome/browser/bookmarks/bookmark_model.h" 27 #include "chrome/browser/bookmarks/bookmark_model.h"
27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 28 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
28 #include "chrome/browser/sync/glue/bookmark_change_processor.h" 29 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
29 #include "chrome/browser/sync/glue/bookmark_model_associator.h" 30 #include "chrome/browser/sync/glue/bookmark_model_associator.h"
30 #include "chrome/browser/sync/glue/data_type_error_handler.h" 31 #include "chrome/browser/sync/glue/data_type_error_handler.h"
31 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" 32 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 281 }
281 282
282 virtual void SetUp() { 283 virtual void SetUp() {
283 test_user_share_.SetUp(); 284 test_user_share_.SetUp();
284 } 285 }
285 286
286 virtual void TearDown() { 287 virtual void TearDown() {
287 test_user_share_.TearDown(); 288 test_user_share_.TearDown();
288 } 289 }
289 290
291 // Inserts a folder directly to the share.
292 // Do not use this after model association is complete.
293 //
294 // This function differs from the AddFolder() function declared elsewhere in
295 // this file in that it only affects the sync model. It would be invalid to
296 // change the sync model directly after ModelAssociation. This function can
297 // be invoked prior to model association to set up first-time sync model
298 // association scenarios.
299 int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) {
300 EXPECT_FALSE(model_associator_);
301
302 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail.
303 syncer::ReadNode bookmark_bar(trans);
304 EXPECT_EQ(BaseNode::INIT_OK, bookmark_bar.InitByTagLookup("bookmark_bar"));
305
306 syncer::WriteNode node(trans);
307 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL));
308 node.SetIsFolder(true);
309 node.SetTitle(ASCIIToWide(title));
310
311 return node.GetId();
312 }
313
314 // Inserts a bookmark directly to the share.
315 // Do not use this after model association is complete.
316 //
317 // This function differs from the AddURL() function declared elsewhere in this
318 // file in that it only affects the sync model. It would be invalid to change
319 // the sync model directly after ModelAssociation. This function can be
320 // invoked prior to model association to set up first-time sync model
321 // association scenarios.
322 int64 AddBookmarkToShare(syncer::WriteTransaction *trans,
323 int64 parent_id,
324 std::string title) {
325 EXPECT_FALSE(model_associator_);
326
327 syncer::ReadNode parent(trans);
328 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id));
329
330 sync_pb::BookmarkSpecifics specifics;
331 specifics.set_url("http://www.google.com/search?q=" + title);
332 specifics.set_title(title);
333
334 syncer::WriteNode node(trans);
335 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL));
336 node.SetIsFolder(false);
337 node.SetTitle(ASCIIToWide(title));
338 node.SetBookmarkSpecifics(specifics);
339
340 return node.GetId();
341 }
342
290 // Load (or re-load) the bookmark model. |load| controls use of the 343 // Load (or re-load) the bookmark model. |load| controls use of the
291 // bookmarks file on disk. |save| controls whether the newly loaded 344 // bookmarks file on disk. |save| controls whether the newly loaded
292 // bookmark model will write out a bookmark file as it goes. 345 // bookmark model will write out a bookmark file as it goes.
293 void LoadBookmarkModel(LoadOption load, SaveOption save) { 346 void LoadBookmarkModel(LoadOption load, SaveOption save) {
294 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; 347 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE;
295 profile_.CreateBookmarkModel(delete_bookmarks); 348 profile_.CreateBookmarkModel(delete_bookmarks);
296 model_ = BookmarkModelFactory::GetForProfile(&profile_); 349 model_ = BookmarkModelFactory::GetForProfile(&profile_);
297 ui_test_utils::WaitForBookmarkModelToLoad(model_); 350 ui_test_utils::WaitForBookmarkModelToLoad(model_);
298 // This noticeably speeds up the unit tests that request it. 351 // This noticeably speeds up the unit tests that request it.
299 if (save == DONT_SAVE_TO_STORAGE) 352 if (save == DONT_SAVE_TO_STORAGE)
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 671 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
619 StartSync(); 672 StartSync();
620 673
621 EXPECT_TRUE(other_bookmarks_id()); 674 EXPECT_TRUE(other_bookmarks_id());
622 EXPECT_TRUE(bookmark_bar_id()); 675 EXPECT_TRUE(bookmark_bar_id());
623 EXPECT_TRUE(mobile_bookmarks_id()); 676 EXPECT_TRUE(mobile_bookmarks_id());
624 677
625 ExpectModelMatch(); 678 ExpectModelMatch();
626 } 679 }
627 680
681 // Populate the sync database then start model association. Sync's bookmarks
682 // should end up being copied into the native model, resulting in a successful
683 // "ExpectModelMatch()".
684 //
685 // This code has some use for verifying correctness. It's also a very useful
686 // for profiling bookmark ModelAssociation, an important part of some first-time
687 // sync scenarios. Simply increase the kNumFolders and kNumBookmarksPerFolder
688 // as desired, then run the test under a profiler to find hot spots in the model
689 // association code.
690 TEST_F(ProfileSyncServiceBookmarkTest, InitialModelAssociate) {
691 const int kNumBookmarksPerFolder = 10;
692 const int kNumFolders = 10;
693
694 CreatePermanentBookmarkNodes();
695
696 {
697 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
698 for (int i = 0; i < kNumFolders; ++i) {
699 int64 folder_id = AddFolderToShare(&trans,
700 base::StringPrintf("folder%05d", i));
701 for (int j = 0; j < kNumBookmarksPerFolder; ++j) {
702 AddBookmarkToShare(&trans,
703 folder_id,
704 base::StringPrintf("bookmark%05d", j));
705 }
706 }
707 }
708
709 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
710 StartSync();
711
712 ExpectModelMatch();
713 }
714
715
628 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) { 716 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) {
629 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 717 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
630 StartSync(); 718 StartSync();
631 719
632 // Test addition. 720 // Test addition.
633 const BookmarkNode* folder = 721 const BookmarkNode* folder =
634 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar")); 722 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar"));
635 ExpectSyncerNodeMatching(folder); 723 ExpectSyncerNodeMatching(folder);
636 ExpectModelMatch(); 724 ExpectModelMatch();
637 const BookmarkNode* folder2 = 725 const BookmarkNode* folder2 =
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 new_versions[changed_bookmark->id()]); 1916 new_versions[changed_bookmark->id()]);
1829 initial_versions.erase(changed_bookmark->id()); 1917 initial_versions.erase(changed_bookmark->id());
1830 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); 1918 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions);
1831 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); 1919 ExpectTransactionVersionMatch(model_->other_node(), initial_versions);
1832 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); 1920 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions);
1833 } 1921 }
1834 1922
1835 } // namespace 1923 } // namespace
1836 1924
1837 } // namespace browser_sync 1925 } // namespace browser_sync
OLDNEW
« 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