Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / performance / bookmarks_sync_perf_test.cc
blob557e68677a44b25d0baac77b9ddcceb20dc5934d
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
6 #include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/sync_test.h"
10 using bookmarks_helper::AddURL;
11 using bookmarks_helper::AllModelsMatch;
12 using bookmarks_helper::GetBookmarkBarNode;
13 using bookmarks_helper::IndexedURL;
14 using bookmarks_helper::IndexedURLTitle;
15 using bookmarks_helper::Remove;
16 using bookmarks_helper::SetURL;
18 static const int kNumBookmarks = 150;
20 class BookmarksSyncPerfTest : public SyncTest {
21 public:
22 BookmarksSyncPerfTest()
23 : SyncTest(TWO_CLIENT),
24 url_number_(0),
25 url_title_number_(0) {}
27 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|.
28 void AddURLs(int profile, int num_urls);
30 // Updates the URL for all bookmarks in the bookmark bar for |profile|.
31 void UpdateURLs(int profile);
33 // Removes all bookmarks in the bookmark bar for |profile|.
34 void RemoveURLs(int profile);
36 // Returns the number of bookmarks stored in the bookmark bar for |profile|.
37 int GetURLCount(int profile);
39 private:
40 // Returns a new unique bookmark URL.
41 std::string NextIndexedURL();
43 // Returns a new unique bookmark title.
44 std::wstring NextIndexedURLTitle();
46 int url_number_;
47 int url_title_number_;
48 DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest);
51 void BookmarksSyncPerfTest::AddURLs(int profile, int num_urls) {
52 for (int i = 0; i < num_urls; ++i) {
53 ASSERT_TRUE(AddURL(
54 profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL);
58 void BookmarksSyncPerfTest::UpdateURLs(int profile) {
59 for (int i = 0;
60 i < GetBookmarkBarNode(profile)->child_count();
61 ++i) {
62 ASSERT_TRUE(SetURL(profile,
63 GetBookmarkBarNode(profile)->GetChild(i),
64 GURL(NextIndexedURL())));
68 void BookmarksSyncPerfTest::RemoveURLs(int profile) {
69 while (!GetBookmarkBarNode(profile)->empty()) {
70 Remove(profile, GetBookmarkBarNode(profile), 0);
74 int BookmarksSyncPerfTest::GetURLCount(int profile) {
75 return GetBookmarkBarNode(profile)->child_count();
78 std::string BookmarksSyncPerfTest::NextIndexedURL() {
79 return IndexedURL(url_number_++);
82 std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() {
83 return IndexedURLTitle(url_title_number_++);
86 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, P0) {
87 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
89 // TCM ID - 7556828.
90 AddURLs(0, kNumBookmarks);
91 base::TimeDelta dt =
92 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
93 ASSERT_EQ(kNumBookmarks, GetURLCount(1));
94 SyncTimingHelper::PrintResult("bookmarks", "add_bookmarks", dt);
96 // TCM ID - 7564762.
97 UpdateURLs(0);
98 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
99 ASSERT_EQ(kNumBookmarks, GetURLCount(1));
100 SyncTimingHelper::PrintResult("bookmarks", "update_bookmarks", dt);
102 // TCM ID - 7566626.
103 RemoveURLs(0);
104 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
105 ASSERT_EQ(0, GetURLCount(1));
106 SyncTimingHelper::PrintResult("bookmarks", "delete_bookmarks", dt);