summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-25 23:23:27 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-25 23:23:27 +0000
commit781dbd7d16db4fbf7073f1e389120e052d2831aa (patch)
tree91ca96778bef46bbd639d100a53f645dfb34497f /chrome/test/webdriver
parent30fdaad8397236d319832dd33fe3fd72e693693e (diff)
downloadchromium_src-781dbd7d16db4fbf7073f1e389120e052d2831aa.zip
chromium_src-781dbd7d16db4fbf7073f1e389120e052d2831aa.tar.gz
chromium_src-781dbd7d16db4fbf7073f1e389120e052d2831aa.tar.bz2
In ChromeDriver, wait for all tabs to stop loading before executing a session command.
This is required by the WebDriver spec. BUG=none TEST=none Review URL: http://codereview.chromium.org/6580040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76113 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/webdriver')
-rw-r--r--chrome/test/webdriver/automation.cc8
-rw-r--r--chrome/test/webdriver/automation.h3
-rw-r--r--chrome/test/webdriver/commands/webdriver_command.cc3
-rw-r--r--chrome/test/webdriver/session.cc11
-rw-r--r--chrome/test/webdriver/session.h3
5 files changed, 28 insertions, 0 deletions
diff --git a/chrome/test/webdriver/automation.cc b/chrome/test/webdriver/automation.cc
index d3ba016..f40d8e9 100644
--- a/chrome/test/webdriver/automation.cc
+++ b/chrome/test/webdriver/automation.cc
@@ -434,6 +434,14 @@ void Automation::GetVersion(std::string* version) {
*version = launcher_->automation()->server_version();
}
+void Automation::WaitForAllTabsToStopLoading(bool* success) {
+ DictionaryValue dict;
+ dict.SetString("command", "WaitForAllTabsToStopLoading");
+ std::string request, reply;
+ base::JSONWriter::Write(&dict, false, &request);
+ *success = launcher_->automation()->SendJSONRequest(request, &reply);
+}
+
TabProxy* Automation::GetTabById(int tab_id) {
TabIdMap::const_iterator iter = tab_id_map_.find(tab_id);
if (iter != tab_id_map_.end()) {
diff --git a/chrome/test/webdriver/automation.h b/chrome/test/webdriver/automation.h
index 0bbdb27..0be141a 100644
--- a/chrome/test/webdriver/automation.h
+++ b/chrome/test/webdriver/automation.h
@@ -109,6 +109,9 @@ class Automation {
// Gets the version of the runing browser.
void GetVersion(std::string* version);
+ // Waits for all tabs to stop loading.
+ void WaitForAllTabsToStopLoading(bool* success);
+
private:
typedef std::map<int, scoped_refptr<TabProxy> > TabIdMap;
TabProxy* GetTabById(int tab_id);
diff --git a/chrome/test/webdriver/commands/webdriver_command.cc b/chrome/test/webdriver/commands/webdriver_command.cc
index efa0f8a..8d038f1 100644
--- a/chrome/test/webdriver/commands/webdriver_command.cc
+++ b/chrome/test/webdriver/commands/webdriver_command.cc
@@ -30,6 +30,9 @@ bool WebDriverCommand::Init(Response* const response) {
kSessionNotFound);
return false;
}
+ if (!session_->WaitForAllTabsToStopLoading()) {
+ LOG(WARNING) << "Failed to wait for all tabs to stop loading";
+ }
response->SetField("sessionId", Value::CreateStringValue(session_id));
return true;
diff --git a/chrome/test/webdriver/session.cc b/chrome/test/webdriver/session.cc
index c8d9054..400c7eb 100644
--- a/chrome/test/webdriver/session.cc
+++ b/chrome/test/webdriver/session.cc
@@ -549,6 +549,17 @@ ErrorCode Session::GetElementLocationInView(
return kSuccess;
}
+bool Session::WaitForAllTabsToStopLoading() {
+ if (!automation_.get())
+ return true;
+ bool success = false;
+ RunSessionTask(NewRunnableMethod(
+ automation_.get(),
+ &Automation::WaitForAllTabsToStopLoading,
+ &success));
+ return success;
+}
+
void Session::RunSessionTask(Task* task) {
base::WaitableEvent done_event(false, false);
thread_.message_loop_proxy()->PostTask(FROM_HERE, NewRunnableMethod(
diff --git a/chrome/test/webdriver/session.h b/chrome/test/webdriver/session.h
index d48444f..222823c 100644
--- a/chrome/test/webdriver/session.h
+++ b/chrome/test/webdriver/session.h
@@ -144,6 +144,9 @@ class Session {
ErrorCode GetElementLocationInView(
const WebElementId& element, int* x, int* y);
+ // Waits for all tabs to stop loading. Returns true on success.
+ bool WaitForAllTabsToStopLoading();
+
inline const std::string& id() const { return id_; }
inline int implicit_wait() const { return implicit_wait_; }