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"
9 #include "components/bookmarks/browser/bookmark_node.h"
11 using bookmarks_helper::AddURL
;
12 using bookmarks_helper::AllModelsMatch
;
13 using bookmarks_helper::GetBookmarkBarNode
;
14 using bookmarks_helper::IndexedURL
;
15 using bookmarks_helper::IndexedURLTitle
;
16 using bookmarks_helper::Remove
;
17 using bookmarks_helper::SetURL
;
19 static const int kNumBookmarks
= 150;
21 class BookmarksSyncPerfTest
: public SyncTest
{
23 BookmarksSyncPerfTest()
24 : SyncTest(TWO_CLIENT
),
26 url_title_number_(0) {}
28 // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|.
29 void AddURLs(int profile
, int num_urls
);
31 // Updates the URL for all bookmarks in the bookmark bar for |profile|.
32 void UpdateURLs(int profile
);
34 // Removes all bookmarks in the bookmark bar for |profile|.
35 void RemoveURLs(int profile
);
37 // Returns the number of bookmarks stored in the bookmark bar for |profile|.
38 int GetURLCount(int profile
);
41 // Returns a new unique bookmark URL.
42 std::string
NextIndexedURL();
44 // Returns a new unique bookmark title.
45 std::string
NextIndexedURLTitle();
48 int url_title_number_
;
49 DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest
);
52 void BookmarksSyncPerfTest::AddURLs(int profile
, int num_urls
) {
53 for (int i
= 0; i
< num_urls
; ++i
) {
55 profile
, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL
);
59 void BookmarksSyncPerfTest::UpdateURLs(int profile
) {
61 i
< GetBookmarkBarNode(profile
)->child_count();
63 ASSERT_TRUE(SetURL(profile
,
64 GetBookmarkBarNode(profile
)->GetChild(i
),
65 GURL(NextIndexedURL())));
69 void BookmarksSyncPerfTest::RemoveURLs(int profile
) {
70 while (!GetBookmarkBarNode(profile
)->empty()) {
71 Remove(profile
, GetBookmarkBarNode(profile
), 0);
75 int BookmarksSyncPerfTest::GetURLCount(int profile
) {
76 return GetBookmarkBarNode(profile
)->child_count();
79 std::string
BookmarksSyncPerfTest::NextIndexedURL() {
80 return IndexedURL(url_number_
++);
83 std::string
BookmarksSyncPerfTest::NextIndexedURLTitle() {
84 return IndexedURLTitle(url_title_number_
++);
87 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest
, P0
) {
88 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
91 AddURLs(0, kNumBookmarks
);
93 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
94 ASSERT_EQ(kNumBookmarks
, GetURLCount(1));
95 SyncTimingHelper::PrintResult("bookmarks", "add_bookmarks", dt
);
99 dt
= SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
100 ASSERT_EQ(kNumBookmarks
, GetURLCount(1));
101 SyncTimingHelper::PrintResult("bookmarks", "update_bookmarks", dt
);
105 dt
= SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
106 ASSERT_EQ(0, GetURLCount(1));
107 SyncTimingHelper::PrintResult("bookmarks", "delete_bookmarks", dt
);