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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/sync/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h"
9 #include "chrome/browser/sync/test/integration/sync_test.h"
10 #include "chrome/browser/sync/test/integration/typed_urls_helper.h"
11 #include "sync/sessions/sync_session_context.h"
13 using typed_urls_helper::AddUrlToHistory;
14 using typed_urls_helper::AssertAllProfilesHaveSameURLsAsVerifier;
15 using typed_urls_helper::DeleteUrlsFromHistory;
16 using typed_urls_helper::GetTypedUrlsFromClient;
18 // This number should be as far away from a multiple of
19 // kDefaultMaxCommitBatchSize as possible, so that sync cycle counts
20 // for batch operations stay the same even if some batches end up not
21 // being completely full.
22 static const int kNumUrls = 163;
23 // This compile assert basically asserts that kNumUrls is right in the
24 // middle between two multiples of kDefaultMaxCommitBatchSize.
26 ((kNumUrls % syncer::kDefaultMaxCommitBatchSize) >=
27 (syncer::kDefaultMaxCommitBatchSize / 2)) &&
28 ((kNumUrls % syncer::kDefaultMaxCommitBatchSize) <=
29 ((syncer::kDefaultMaxCommitBatchSize + 1) / 2)),
30 kNumUrlsShouldBeBetweenTwoMultiplesOfkDefaultMaxCommitBatchSize);
32 class TypedUrlsSyncPerfTest : public SyncTest {
34 TypedUrlsSyncPerfTest()
35 : SyncTest(TWO_CLIENT),
38 // Adds |num_urls| new unique typed urls to |profile|.
39 void AddURLs(int profile, int num_urls);
41 // Update all typed urls in |profile| by visiting them once again.
42 void UpdateURLs(int profile);
44 // Removes all typed urls for |profile|.
45 void RemoveURLs(int profile);
47 // Returns the number of typed urls stored in |profile|.
48 int GetURLCount(int profile);
51 // Returns a new unique typed URL.
54 // Returns a unique URL according to the integer |n|.
58 DISALLOW_COPY_AND_ASSIGN(TypedUrlsSyncPerfTest);
61 void TypedUrlsSyncPerfTest::AddURLs(int profile, int num_urls) {
62 for (int i = 0; i < num_urls; ++i) {
63 AddUrlToHistory(profile, NextURL());
67 void TypedUrlsSyncPerfTest::UpdateURLs(int profile) {
68 history::URLRows urls = GetTypedUrlsFromClient(profile);
69 for (history::URLRows::const_iterator it = urls.begin(); it != urls.end();
71 AddUrlToHistory(profile, it->url());
75 void TypedUrlsSyncPerfTest::RemoveURLs(int profile) {
76 const history::URLRows& urls = GetTypedUrlsFromClient(profile);
77 std::vector<GURL> gurls;
78 for (history::URLRows::const_iterator it = urls.begin(); it != urls.end();
80 gurls.push_back(it->url());
82 DeleteUrlsFromHistory(profile, gurls);
85 int TypedUrlsSyncPerfTest::GetURLCount(int profile) {
86 return GetTypedUrlsFromClient(profile).size();
89 GURL TypedUrlsSyncPerfTest::NextURL() {
90 return IntToURL(url_number_++);
93 GURL TypedUrlsSyncPerfTest::IntToURL(int n) {
94 return GURL(base::StringPrintf("http://history%d.google.com/", n));
97 IN_PROC_BROWSER_TEST_F(TypedUrlsSyncPerfTest, P0) {
98 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
101 AddURLs(0, kNumUrls);
103 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
104 ASSERT_EQ(kNumUrls, GetURLCount(1));
105 SyncTimingHelper::PrintResult("typed_urls", "add_typed_urls", dt);
109 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
110 ASSERT_EQ(kNumUrls, GetURLCount(1));
111 SyncTimingHelper::PrintResult("typed_urls", "update_typed_urls", dt);
115 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
116 ASSERT_EQ(0, GetURLCount(1));
117 SyncTimingHelper::PrintResult("typed_urls", "delete_typed_urls", dt);