This source file includes following definitions.
- url_number_
- AddURLs
- UpdateURLs
- RemoveURLs
- GetURLCount
- NextURL
- IntToURL
- IN_PROC_BROWSER_TEST_F
#include "base/basictypes.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/typed_urls_helper.h"
#include "sync/sessions/sync_session_context.h"
using typed_urls_helper::AddUrlToHistory;
using typed_urls_helper::AssertAllProfilesHaveSameURLsAsVerifier;
using typed_urls_helper::DeleteUrlsFromHistory;
using typed_urls_helper::GetTypedUrlsFromClient;
static const int kNumUrls = 163;
COMPILE_ASSERT(
((kNumUrls % syncer::kDefaultMaxCommitBatchSize) >=
(syncer::kDefaultMaxCommitBatchSize / 2)) &&
((kNumUrls % syncer::kDefaultMaxCommitBatchSize) <=
((syncer::kDefaultMaxCommitBatchSize + 1) / 2)),
kNumUrlsShouldBeBetweenTwoMultiplesOfkDefaultMaxCommitBatchSize);
class TypedUrlsSyncPerfTest : public SyncTest {
public:
TypedUrlsSyncPerfTest()
: SyncTest(TWO_CLIENT),
url_number_(0) {}
void AddURLs(int profile, int num_urls);
void UpdateURLs(int profile);
void RemoveURLs(int profile);
int GetURLCount(int profile);
private:
GURL NextURL();
GURL IntToURL(int n);
int url_number_;
DISALLOW_COPY_AND_ASSIGN(TypedUrlsSyncPerfTest);
};
void TypedUrlsSyncPerfTest::AddURLs(int profile, int num_urls) {
for (int i = 0; i < num_urls; ++i) {
AddUrlToHistory(profile, NextURL());
}
}
void TypedUrlsSyncPerfTest::UpdateURLs(int profile) {
history::URLRows urls = GetTypedUrlsFromClient(profile);
for (history::URLRows::const_iterator it = urls.begin(); it != urls.end();
++it) {
AddUrlToHistory(profile, it->url());
}
}
void TypedUrlsSyncPerfTest::RemoveURLs(int profile) {
const history::URLRows& urls = GetTypedUrlsFromClient(profile);
std::vector<GURL> gurls;
for (history::URLRows::const_iterator it = urls.begin(); it != urls.end();
++it) {
gurls.push_back(it->url());
}
DeleteUrlsFromHistory(profile, gurls);
}
int TypedUrlsSyncPerfTest::GetURLCount(int profile) {
return GetTypedUrlsFromClient(profile).size();
}
GURL TypedUrlsSyncPerfTest::NextURL() {
return IntToURL(url_number_++);
}
GURL TypedUrlsSyncPerfTest::IntToURL(int n) {
return GURL(base::StringPrintf("http://history%d.google.com/", n));
}
IN_PROC_BROWSER_TEST_F(TypedUrlsSyncPerfTest, P0) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
AddURLs(0, kNumUrls);
base::TimeDelta dt =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(kNumUrls, GetURLCount(1));
SyncTimingHelper::PrintResult("typed_urls", "add_typed_urls", dt);
UpdateURLs(0);
dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(kNumUrls, GetURLCount(1));
SyncTimingHelper::PrintResult("typed_urls", "update_typed_urls", dt);
RemoveURLs(0);
dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(0, GetURLCount(1));
SyncTimingHelper::PrintResult("typed_urls", "delete_typed_urls", dt);
}