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
{
22 BookmarksSyncPerfTest()
23 : SyncTest(TWO_CLIENT
),
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
);
40 // Returns a new unique bookmark URL.
41 std::string
NextIndexedURL();
43 // Returns a new unique bookmark title.
44 std::wstring
NextIndexedURLTitle();
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
) {
54 profile
, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL
);
58 void BookmarksSyncPerfTest::UpdateURLs(int profile
) {
60 i
< GetBookmarkBarNode(profile
)->child_count();
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.";
90 AddURLs(0, kNumBookmarks
);
92 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
93 ASSERT_EQ(kNumBookmarks
, GetURLCount(1));
94 SyncTimingHelper::PrintResult("bookmarks", "add_bookmarks", dt
);
98 dt
= SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
99 ASSERT_EQ(kNumBookmarks
, GetURLCount(1));
100 SyncTimingHelper::PrintResult("bookmarks", "update_bookmarks", dt
);
104 dt
= SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
105 ASSERT_EQ(0, GetURLCount(1));
106 SyncTimingHelper::PrintResult("bookmarks", "delete_bookmarks", dt
);