Commit d22bd660 authored by braffert@chromium.org's avatar braffert@chromium.org

Session/tab sync performance tests.

This patch adds tab sync performance tests, similar to the tests for the existing datatypes in live_sync/performance.  Changes to LiveSessionsSyncTest were required - most significantly the addition of AwaitSessionPropagation, which waits until a vector of urls can all be found in the model associator.  This type of wait loop previously existed as part of OpenTab, and worked with a single url.  AwaitSessionPropagation supports multiple urls, and is called from OpenTab, OpenMultipleTabs, and SessionsSyncPerfTest::UpdateTabs.

BUG=none
TEST=sync_performance_tests, sync_integration_tests

Review URL: http://codereview.chromium.org/7575026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95675 0039d316-1c4b-4281-b951-d872f2087c98
parent 437c2c67
...@@ -3427,6 +3427,8 @@ ...@@ -3427,6 +3427,8 @@
'test/live_sync/live_extensions_sync_test.h', 'test/live_sync/live_extensions_sync_test.h',
'test/live_sync/live_passwords_sync_test.cc', 'test/live_sync/live_passwords_sync_test.cc',
'test/live_sync/live_passwords_sync_test.h', 'test/live_sync/live_passwords_sync_test.h',
'test/live_sync/live_sessions_sync_test.cc',
'test/live_sync/live_sessions_sync_test.h',
'test/live_sync/live_typed_urls_sync_test.cc', 'test/live_sync/live_typed_urls_sync_test.cc',
'test/live_sync/live_typed_urls_sync_test.h', 'test/live_sync/live_typed_urls_sync_test.h',
'test/live_sync/live_sync_extension_helper.cc', 'test/live_sync/live_sync_extension_helper.cc',
...@@ -3439,6 +3441,7 @@ ...@@ -3439,6 +3441,7 @@
'test/live_sync/performance/sync_timing_helper.cc', 'test/live_sync/performance/sync_timing_helper.cc',
'test/live_sync/performance/sync_timing_helper.h', 'test/live_sync/performance/sync_timing_helper.h',
'test/live_sync/performance/passwords_sync_perf_test.cc', 'test/live_sync/performance/passwords_sync_perf_test.cc',
'test/live_sync/performance/sessions_sync_perf_test.cc',
'test/live_sync/performance/typed_urls_sync_perf_test.cc', 'test/live_sync/performance/typed_urls_sync_perf_test.cc',
'test/live_sync/sync_datatype_helper.cc', 'test/live_sync/sync_datatype_helper.cc',
'test/live_sync/sync_datatype_helper.h', 'test/live_sync/sync_datatype_helper.h',
......
...@@ -89,27 +89,50 @@ bool LiveSessionsSyncTest::ModelAssociatorHasTabWithUrl(int index, ...@@ -89,27 +89,50 @@ bool LiveSessionsSyncTest::ModelAssociatorHasTabWithUrl(int index,
} }
bool LiveSessionsSyncTest::OpenTab(int index, const GURL& url) { bool LiveSessionsSyncTest::OpenTab(int index, const GURL& url) {
static const int timeout_milli = TestTimeouts::action_max_timeout_ms(); VLOG(1) << "Opening tab: " << url.spec() << " using profile " << index << ".";
VLOG(1) << "Opening tab: " << url.spec();
GetBrowser(index)->ShowSingletonTab(url); GetBrowser(index)->ShowSingletonTab(url);
return WaitForTabsToLoad(index, std::vector<GURL>(1, url));
}
bool LiveSessionsSyncTest::OpenMultipleTabs(int index,
const std::vector<GURL>& urls) {
Browser* browser = GetBrowser(index);
for (std::vector<GURL>::const_iterator it = urls.begin();
it != urls.end(); ++it) {
VLOG(1) << "Opening tab: " << it->spec() << " using profile " << index
<< ".";
browser->ShowSingletonTab(*it);
}
return WaitForTabsToLoad(index, urls);
}
bool LiveSessionsSyncTest::WaitForTabsToLoad(
int index, const std::vector<GURL>& urls) {
VLOG(1) << "Waiting for session to propagate to associator."; VLOG(1) << "Waiting for session to propagate to associator.";
static const int timeout_milli = TestTimeouts::action_max_timeout_ms();
base::TimeTicks start_time = base::TimeTicks::Now(); base::TimeTicks start_time = base::TimeTicks::Now();
base::TimeTicks end_time = start_time + base::TimeTicks end_time = start_time +
base::TimeDelta::FromMilliseconds(timeout_milli); base::TimeDelta::FromMilliseconds(timeout_milli);
do { bool found;
if (ModelAssociatorHasTabWithUrl(index, url)) for (std::vector<GURL>::const_iterator it = urls.begin();
return true; it != urls.end(); ++it) {
GetProfile(index)->GetProfileSyncService()->GetSessionModelAssociator()-> found = false;
BlockUntilLocalChangeForTest(timeout_milli); while (!found) {
ui_test_utils::RunMessageLoop(); found = ModelAssociatorHasTabWithUrl(index, *it);
} while (base::TimeTicks::Now() < end_time); if (base::TimeTicks::Now() >= end_time) {
LOG(ERROR) << "Failed to find all tabs after " << timeout_milli/1000.0
if (ModelAssociatorHasTabWithUrl(index, url)) << " seconds.";
return true; return false;
}
LOG(ERROR) << "Failed to find tab after " << timeout_milli/1000.0 if (!found) {
<< " seconds."; GetProfile(index)->GetProfileSyncService()->
return false; GetSessionModelAssociator()->
BlockUntilLocalChangeForTest(timeout_milli);
ui_test_utils::RunMessageLoop();
}
}
}
return true;
} }
std::vector<SessionWindow*>* LiveSessionsSyncTest::GetLocalWindows(int index) { std::vector<SessionWindow*>* LiveSessionsSyncTest::GetLocalWindows(int index) {
......
...@@ -111,6 +111,14 @@ class LiveSessionsSyncTest : public LiveSyncTest { ...@@ -111,6 +111,14 @@ class LiveSessionsSyncTest : public LiveSyncTest {
// of it. Returns true upon success, false otherwise. // of it. Returns true upon success, false otherwise.
bool OpenTab(int index, const GURL& url) WARN_UNUSED_RESULT; bool OpenTab(int index, const GURL& url) WARN_UNUSED_RESULT;
// Open multiple tabs and block until the session model associator is aware
// of all of them. Returns true on success, false on failure.
bool OpenMultipleTabs(int index, const std::vector<GURL>& urls);
// Wait for a session change to propagate to the model associator. Will not
// return until each url in |urls| has been found.
bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls);
// Check if the session model associator's knows that the current open tab // Check if the session model associator's knows that the current open tab
// has this url. // has this url.
bool ModelAssociatorHasTabWithUrl(int index, const GURL& url); bool ModelAssociatorHasTabWithUrl(int index, const GURL& url);
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/stringprintf.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/sync/profile_sync_service_harness.h"
#include "chrome/test/live_sync/performance/sync_timing_helper.h"
#include "chrome/test/live_sync/live_sessions_sync_test.h"
static const int kNumTabs = 150;
class SessionsSyncPerfTest: public TwoClientLiveSessionsSyncTest {
public:
SessionsSyncPerfTest() : url_number_(0) {}
// Opens |num_tabs| new tabs on |profile|.
void AddTabs(int profile, int num_tabs);
// Update all tabs in |profile| by visiting a new URL.
void UpdateTabs(int profile);
// Close all tabs in |profile|.
void RemoveTabs(int profile);
// Returns the number of open tabs in all sessions (local + foreign) for
// |profile|. Returns -1 on failure.
int GetTabCount(int profile);
private:
// Returns a new unique URL.
GURL NextURL();
// Returns a unique URL according to the integer |n|.
GURL IntToURL(int n);
int url_number_;
DISALLOW_COPY_AND_ASSIGN(SessionsSyncPerfTest);
};
void SessionsSyncPerfTest::AddTabs(int profile, int num_tabs) {
std::vector<GURL> urls;
for (int i = 0; i < num_tabs; ++i) {
urls.push_back(NextURL());
}
OpenMultipleTabs(profile, urls);
}
void SessionsSyncPerfTest::UpdateTabs(int profile) {
Browser* browser = GetBrowser(profile);
GURL url;
std::vector<GURL> urls;
for (int i = 0; i < browser->tab_count(); ++i) {
browser->SelectNumberedTab(i);
url = NextURL();
browser->OpenURL(
OpenURLParams(url, GURL("www.google.com"), CURRENT_TAB, 0));
urls.push_back(url);
}
WaitForTabsToLoad(profile, urls);
}
void SessionsSyncPerfTest::RemoveTabs(int profile) {
GetBrowser(profile)->CloseAllTabs();
}
int SessionsSyncPerfTest::GetTabCount(int profile) {
int tab_count = 0;
const SyncedSession* local_session;
std::vector<const SyncedSession*> sessions;
if (!GetLocalSession(profile, &local_session)) {
VLOG(1) << "GetLocalSession returned false";
return -1;
}
if (!GetSessionData(profile, &sessions)) {
// Foreign session data may be empty. In this case we only count tabs in
// the local session.
VLOG(1) << "GetSessionData returned false";
}
sessions.push_back(local_session);
for (std::vector<const SyncedSession*>::const_iterator it = sessions.begin();
it != sessions.end(); ++it) {
for (std::vector<SessionWindow*>::const_iterator win_it =
(*it)->windows.begin(); win_it != (*it)->windows.end(); ++win_it) {
tab_count += (*win_it)->tabs.size();
}
}
return tab_count;
}
GURL SessionsSyncPerfTest::NextURL() {
return IntToURL(url_number_++);
}
GURL SessionsSyncPerfTest::IntToURL(int n) {
return GURL(StringPrintf("http://history%d.google.com/", n));
}
IN_PROC_BROWSER_TEST_F(SessionsSyncPerfTest, P0) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
AddTabs(0, kNumTabs);
base::TimeDelta dt =
SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(kNumTabs, GetTabCount(0));
ASSERT_EQ(kNumTabs, GetTabCount(1));
SyncTimingHelper::PrintResult("tabs", "add", dt);
UpdateTabs(0);
dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
ASSERT_EQ(kNumTabs, GetTabCount(0));
ASSERT_EQ(kNumTabs, GetTabCount(1));
SyncTimingHelper::PrintResult("tabs", "update", dt);
RemoveTabs(0);
dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
// New tab page remains open on profile 0 after closing all tabs.
ASSERT_EQ(1, GetTabCount(0));
ASSERT_EQ(0, GetTabCount(1));
SyncTimingHelper::PrintResult("tabs", "delete", dt);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment