summaryrefslogtreecommitdiffstats
path: root/chrome/test/automation
diff options
context:
space:
mode:
authortedvessenes@gmail.com <tedvessenes@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-20 19:41:56 +0000
committertedvessenes@gmail.com <tedvessenes@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-20 19:41:56 +0000
commita0b900be2e35012f904a15ed278f31124c4b955e (patch)
tree5218149018d4d4db6640d8d6f05ac23edef3bd60 /chrome/test/automation
parent1e9db21babb70b7d861ad65a09d96ced486ab513 (diff)
downloadchromium_src-a0b900be2e35012f904a15ed278f31124c4b955e.zip
chromium_src-a0b900be2e35012f904a15ed278f31124c4b955e.tar.gz
chromium_src-a0b900be2e35012f904a15ed278f31124c4b955e.tar.bz2
Switch to TimeDelta interfaces in chrome automation test infrastructure.
This is a resubmit of a previously reverted commit: https://chromiumcodereview.appspot.com/10736064/ BUG=108171 Review URL: https://chromiumcodereview.appspot.com/10787010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147700 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automation')
-rw-r--r--chrome/test/automation/automation_proxy.cc7
-rw-r--r--chrome/test/automation/automation_proxy.h17
-rw-r--r--chrome/test/automation/browser_proxy.cc10
-rw-r--r--chrome/test/automation/browser_proxy.h8
-rw-r--r--chrome/test/automation/dom_automation_browsertest.cc3
-rw-r--r--chrome/test/automation/javascript_execution_controller.h5
-rw-r--r--chrome/test/automation/proxy_launcher.cc29
-rw-r--r--chrome/test/automation/proxy_launcher.h12
8 files changed, 51 insertions, 40 deletions
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc
index 0137200..d5f1a60 100644
--- a/chrome/test/automation/automation_proxy.cc
+++ b/chrome/test/automation/automation_proxy.cc
@@ -97,7 +97,7 @@ class AutomationMessageFilter : public IPC::ChannelProxy::MessageFilter {
} // anonymous namespace
-AutomationProxy::AutomationProxy(int action_timeout_ms,
+AutomationProxy::AutomationProxy(base::TimeDelta action_timeout,
bool disconnect_on_failure)
: app_launched_(true, false),
initial_loads_complete_(true, false),
@@ -106,13 +106,12 @@ AutomationProxy::AutomationProxy(int action_timeout_ms,
perform_version_check_(false),
disconnect_on_failure_(disconnect_on_failure),
channel_disconnected_on_failure_(false),
- action_timeout_(
- TimeDelta::FromMilliseconds(action_timeout_ms)),
+ action_timeout_(action_timeout),
listener_thread_id_(0) {
// base::WaitableEvent::TimedWait() will choke if we give it a negative value.
// Zero also seems unreasonable, since we need to wait for IPC, but at
// least it is legal... ;-)
- DCHECK_GE(action_timeout_ms, 0);
+ DCHECK_GE(action_timeout.InMilliseconds(), 0);
listener_thread_id_ = base::PlatformThread::CurrentId();
InitializeHandleTracker();
InitializeThread();
diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h
index 21823a5..a829620 100644
--- a/chrome/test/automation/automation_proxy.h
+++ b/chrome/test/automation/automation_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -54,7 +54,7 @@ class AutomationMessageSender : public IPC::Sender {
// a running instance of the app.
class AutomationProxy : public IPC::Listener, public AutomationMessageSender {
public:
- AutomationProxy(int action_timeout_ms, bool disconnect_on_failure);
+ AutomationProxy(base::TimeDelta action_timeout, bool disconnect_on_failure);
virtual ~AutomationProxy();
// Creates a previously unused channel id.
@@ -192,15 +192,16 @@ class AutomationProxy : public IPC::Listener, public AutomationMessageSender {
gfx::NativeWindow* external_tab_container,
gfx::NativeWindow* tab);
- int action_timeout_ms() const {
- return static_cast<int>(action_timeout_.InMilliseconds());
+ base::TimeDelta action_timeout() const {
+ return action_timeout_;
}
// Sets the timeout for subsequent automation calls.
- void set_action_timeout_ms(int timeout_ms) {
- DCHECK(timeout_ms <= 10 * 60 * 1000 ) << "10+ min of automation timeout "
- "can make the test hang and be killed by buildbot";
- action_timeout_ = base::TimeDelta::FromMilliseconds(timeout_ms);
+ void set_action_timeout(base::TimeDelta timeout) {
+ DCHECK(timeout <= base::TimeDelta::FromMinutes(10))
+ << "10+ min of automation timeout "
+ "can make the test hang and be killed by buildbot";
+ action_timeout_ = timeout;
}
// Returns the server version of the server connected. You may only call this
diff --git a/chrome/test/automation/browser_proxy.cc b/chrome/test/automation/browser_proxy.cc
index 867de74..25b3c58 100644
--- a/chrome/test/automation/browser_proxy.cc
+++ b/chrome/test/automation/browser_proxy.cc
@@ -200,10 +200,9 @@ bool BrowserProxy::WaitForTabCountToBecome(int count) {
}
bool BrowserProxy::WaitForTabToBecomeActive(int tab,
- int wait_timeout) {
+ base::TimeDelta wait_timeout) {
const TimeTicks start = TimeTicks::Now();
- const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout);
- while (TimeTicks::Now() - start < timeout) {
+ while (TimeTicks::Now() - start < wait_timeout) {
base::PlatformThread::Sleep(
base::TimeDelta::FromMilliseconds(automation::kSleepTime));
int active_tab;
@@ -438,7 +437,7 @@ bool BrowserProxy::SendJSONRequest(const std::string& request,
return result;
}
-bool BrowserProxy::GetInitialLoadTimes(int timeout_ms,
+bool BrowserProxy::GetInitialLoadTimes(base::TimeDelta timeout,
float* min_start_time,
float* max_stop_time,
std::vector<float>* stop_times) {
@@ -447,7 +446,8 @@ bool BrowserProxy::GetInitialLoadTimes(int timeout_ms,
*max_stop_time = 0;
*min_start_time = -1;
- if (!SendJSONRequest(kJSONCommand, timeout_ms, &json_response)) {
+ if (!SendJSONRequest(
+ kJSONCommand, timeout.InMilliseconds(), &json_response)) {
// Older browser versions do not support GetInitialLoadTimes.
// Fail gracefully and do not record them in this case.
return false;
diff --git a/chrome/test/automation/browser_proxy.h b/chrome/test/automation/browser_proxy.h
index d764e49..69f97b27 100644
--- a/chrome/test/automation/browser_proxy.h
+++ b/chrome/test/automation/browser_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -106,7 +106,9 @@ class BrowserProxy : public AutomationResourceProxy {
// Block the thread until the specified tab is the active tab.
// |wait_timeout| is the timeout, in milliseconds, for waiting.
// Returns false if the tab does not become active.
- bool WaitForTabToBecomeActive(int tab, int wait_timeout) WARN_UNUSED_RESULT;
+ bool WaitForTabToBecomeActive(
+ int tab,
+ base::TimeDelta wait_timeout) WARN_UNUSED_RESULT;
// Opens the FindInPage box. Note: If you just want to search within a tab
// you don't need to call this function, just use FindInPage(...) directly.
@@ -180,7 +182,7 @@ class BrowserProxy : public AutomationResourceProxy {
// the delay that WaitForInitialLoads waits for), and a list of all
// finished timestamps into |stop_times|. Returns true on success.
bool GetInitialLoadTimes(
- int timeout_ms,
+ base::TimeDelta timeout,
float* min_start_time,
float* max_stop_time,
std::vector<float>* stop_times);
diff --git a/chrome/test/automation/dom_automation_browsertest.cc b/chrome/test/automation/dom_automation_browsertest.cc
index cb149e4..2467f7a 100644
--- a/chrome/test/automation/dom_automation_browsertest.cc
+++ b/chrome/test/automation/dom_automation_browsertest.cc
@@ -55,7 +55,8 @@ void EnsureAttributeEventuallyMatches(
class DOMAutomationTest : public InProcessBrowserTest {
public:
DOMAutomationTest() {
- JavaScriptExecutionController::set_timeout(30000);
+ JavaScriptExecutionController::set_timeout(
+ base::TimeDelta::FromSeconds(30));
}
GURL GetTestURL(const char* path) {
diff --git a/chrome/test/automation/javascript_execution_controller.h b/chrome/test/automation/javascript_execution_controller.h
index 90fa6b7..db78db9 100644
--- a/chrome/test/automation/javascript_execution_controller.h
+++ b/chrome/test/automation/javascript_execution_controller.h
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "base/time.h"
#include "base/values.h"
#include "chrome/test/automation/javascript_message_utils.h"
@@ -71,7 +72,9 @@ class JavaScriptExecutionController
// Sets a timeout to be used for all JavaScript methods in which a response
// is returned asynchronously.
- static void set_timeout(int timeout_ms) { timeout_ms_ = timeout_ms; }
+ static void set_timeout(base::TimeDelta timeout) {
+ timeout_ms_ = timeout.InMilliseconds();
+ }
protected:
virtual ~JavaScriptExecutionController();
diff --git a/chrome/test/automation/proxy_launcher.cc b/chrome/test/automation/proxy_launcher.cc
index c86c8b1..d387aef 100644
--- a/chrome/test/automation/proxy_launcher.cc
+++ b/chrome/test/automation/proxy_launcher.cc
@@ -130,7 +130,7 @@ bool ProxyLauncher::LaunchBrowserAndServer(const LaunchState& state,
bool wait_for_initial_loads) {
// Set up IPC testing interface as a server.
automation_proxy_.reset(CreateAutomationProxy(
- TestTimeouts::action_max_timeout_ms()));
+ TestTimeouts::action_max_timeout()));
if (!LaunchBrowser(state))
return false;
@@ -144,7 +144,7 @@ bool ProxyLauncher::LaunchBrowserAndServer(const LaunchState& state,
bool ProxyLauncher::ConnectToRunningBrowser(bool wait_for_initial_loads) {
// Set up IPC testing interface as a client.
automation_proxy_.reset(CreateAutomationProxy(
- TestTimeouts::action_max_timeout_ms()));
+ TestTimeouts::action_max_timeout()));
return WaitForBrowserLaunch(wait_for_initial_loads);
}
@@ -271,7 +271,7 @@ void ProxyLauncher::QuitBrowser() {
// been closed.
int exit_code = -1;
EXPECT_TRUE(WaitForBrowserProcessToQuit(
- TestTimeouts::action_max_timeout_ms(), &exit_code));
+ TestTimeouts::action_max_timeout(), &exit_code));
EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
browser_quit_time_ = base::TimeTicks::Now() - quit_start;
@@ -302,7 +302,7 @@ void ProxyLauncher::TerminateBrowser() {
int exit_code = -1;
EXPECT_TRUE(WaitForBrowserProcessToQuit(
- TestTimeouts::action_max_timeout_ms(), &exit_code));
+ TestTimeouts::action_max_timeout(), &exit_code));
EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
browser_quit_time_ = base::TimeTicks::Now() - quit_start;
@@ -323,9 +323,11 @@ void ProxyLauncher::AssertAppNotRunning(const std::string& error_message) {
ASSERT_TRUE(processes.empty()) << final_error_message;
}
-bool ProxyLauncher::WaitForBrowserProcessToQuit(int timeout, int* exit_code) {
+bool ProxyLauncher::WaitForBrowserProcessToQuit(
+ base::TimeDelta timeout,
+ int* exit_code) {
#ifdef WAIT_FOR_DEBUGGER_ON_OPEN
- timeout = 500000;
+ timeout = base::TimeDelta::FromSeconds(500);
#endif
bool success = false;
@@ -511,7 +513,7 @@ NamedProxyLauncher::NamedProxyLauncher(const std::string& channel_id,
}
AutomationProxy* NamedProxyLauncher::CreateAutomationProxy(
- int execution_timeout) {
+ base::TimeDelta execution_timeout) {
AutomationProxy* proxy = new AutomationProxy(execution_timeout,
disconnect_on_failure_);
proxy->InitializeChannel(channel_id_, true);
@@ -538,14 +540,15 @@ bool NamedProxyLauncher::InitializeConnection(const LaunchState& state,
// Wait for browser to be ready for connections.
bool channel_initialized = false;
- for (int wait_time = 0;
- wait_time < TestTimeouts::action_max_timeout_ms();
- wait_time += automation::kSleepTime) {
+ base::TimeDelta sleep_time = base::TimeDelta::FromMilliseconds(
+ automation::kSleepTime);
+ for (base::TimeDelta wait_time = base::TimeDelta();
+ wait_time < TestTimeouts::action_max_timeout();
+ wait_time += sleep_time) {
channel_initialized = IPC::Channel::IsNamedServerInitialized(channel_id_);
if (channel_initialized)
break;
- base::PlatformThread::Sleep(
- base::TimeDelta::FromMilliseconds(automation::kSleepTime));
+ base::PlatformThread::Sleep(sleep_time);
}
if (!channel_initialized) {
LOG(ERROR) << "Failed to wait for testing channel presence.";
@@ -580,7 +583,7 @@ AnonymousProxyLauncher::AnonymousProxyLauncher(bool disconnect_on_failure)
}
AutomationProxy* AnonymousProxyLauncher::CreateAutomationProxy(
- int execution_timeout) {
+ base::TimeDelta execution_timeout) {
AutomationProxy* proxy = new AutomationProxy(execution_timeout,
disconnect_on_failure_);
proxy->InitializeChannel(channel_id_, false);
diff --git a/chrome/test/automation/proxy_launcher.h b/chrome/test/automation/proxy_launcher.h
index d6886e1..763012d 100644
--- a/chrome/test/automation/proxy_launcher.h
+++ b/chrome/test/automation/proxy_launcher.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -105,7 +105,7 @@ class ProxyLauncher {
// Wait for the browser process to shut down on its own (i.e. as a result of
// some action that your test has taken). If it has exited within |timeout|,
// puts the exit code in |exit_code| and returns true.
- bool WaitForBrowserProcessToQuit(int timeout, int* exit_code);
+ bool WaitForBrowserProcessToQuit(base::TimeDelta timeout, int* exit_code);
AutomationProxy* automation() const;
@@ -134,7 +134,7 @@ class ProxyLauncher {
protected:
// Creates an automation proxy.
virtual AutomationProxy* CreateAutomationProxy(
- int execution_timeout) = 0;
+ base::TimeDelta execution_timeout) = 0;
// Returns the automation proxy's channel with any prefixes prepended,
// for passing as a command line parameter over to the browser.
@@ -218,7 +218,8 @@ class NamedProxyLauncher : public ProxyLauncher {
NamedProxyLauncher(const std::string& channel_id,
bool launch_browser, bool disconnect_on_failure);
- virtual AutomationProxy* CreateAutomationProxy(int execution_timeout);
+ virtual AutomationProxy* CreateAutomationProxy(
+ base::TimeDelta execution_timeout);
virtual bool InitializeConnection(
const LaunchState& state,
bool wait_for_initial_loads) OVERRIDE WARN_UNUSED_RESULT;
@@ -238,7 +239,8 @@ class NamedProxyLauncher : public ProxyLauncher {
class AnonymousProxyLauncher : public ProxyLauncher {
public:
explicit AnonymousProxyLauncher(bool disconnect_on_failure);
- virtual AutomationProxy* CreateAutomationProxy(int execution_timeout);
+ virtual AutomationProxy* CreateAutomationProxy(
+ base::TimeDelta execution_timeout);
virtual bool InitializeConnection(
const LaunchState& state,
bool wait_for_initial_loads) OVERRIDE WARN_UNUSED_RESULT;