summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/commands
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/test/webdriver/commands')
-rw-r--r--chrome/test/webdriver/commands/alert_commands.cc27
-rw-r--r--chrome/test/webdriver/commands/cookie_commands.cc123
-rw-r--r--chrome/test/webdriver/commands/create_session.cc41
-rw-r--r--chrome/test/webdriver/commands/create_session.h4
-rw-r--r--chrome/test/webdriver/commands/execute_async_script_command.cc18
-rw-r--r--chrome/test/webdriver/commands/execute_command.cc30
-rw-r--r--chrome/test/webdriver/commands/execute_command.h5
-rw-r--r--chrome/test/webdriver/commands/find_element_commands.cc34
-rw-r--r--chrome/test/webdriver/commands/find_element_commands.h2
-rw-r--r--chrome/test/webdriver/commands/mouse_commands.cc169
-rw-r--r--chrome/test/webdriver/commands/mouse_commands.h14
-rw-r--r--chrome/test/webdriver/commands/navigate_commands.cc43
-rw-r--r--chrome/test/webdriver/commands/navigate_commands.h9
-rw-r--r--chrome/test/webdriver/commands/response.cc46
-rw-r--r--chrome/test/webdriver/commands/response.h34
-rw-r--r--chrome/test/webdriver/commands/screenshot_command.cc14
-rw-r--r--chrome/test/webdriver/commands/session_with_id.cc7
-rw-r--r--chrome/test/webdriver/commands/session_with_id.h5
-rw-r--r--chrome/test/webdriver/commands/set_timeout_commands.cc16
-rw-r--r--chrome/test/webdriver/commands/set_timeout_commands_unittest.cc2
-rw-r--r--chrome/test/webdriver/commands/source_command.cc11
-rw-r--r--chrome/test/webdriver/commands/speed_command.cc108
-rw-r--r--chrome/test/webdriver/commands/speed_command.h46
-rw-r--r--chrome/test/webdriver/commands/target_locator_commands.cc65
-rw-r--r--chrome/test/webdriver/commands/title_command.cc16
-rw-r--r--chrome/test/webdriver/commands/title_command.h5
-rw-r--r--chrome/test/webdriver/commands/url_command.cc27
-rw-r--r--chrome/test/webdriver/commands/url_command.h5
-rw-r--r--chrome/test/webdriver/commands/webdriver_command.cc32
-rw-r--r--chrome/test/webdriver/commands/webdriver_command.h9
-rw-r--r--chrome/test/webdriver/commands/webelement_commands.cc219
31 files changed, 426 insertions, 760 deletions
diff --git a/chrome/test/webdriver/commands/alert_commands.cc b/chrome/test/webdriver/commands/alert_commands.cc
index 9fb7464..5b0df47 100644
--- a/chrome/test/webdriver/commands/alert_commands.cc
+++ b/chrome/test/webdriver/commands/alert_commands.cc
@@ -6,8 +6,8 @@
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -30,19 +30,24 @@ bool AlertTextCommand::DoesPost() {
void AlertTextCommand::ExecuteGet(Response* const response) {
std::string text;
- ErrorCode code = session_->GetAlertMessage(&text);
- if (code == kSuccess)
- response->SetValue(Value::CreateStringValue(text));
- response->SetStatus(code);
+ Error* error = session_->GetAlertMessage(&text);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
+ response->SetValue(Value::CreateStringValue(text));
}
void AlertTextCommand::ExecutePost(Response* const response) {
std::string text;
if (!GetStringParameter("text", &text)) {
- SET_WEBDRIVER_ERROR(response, "'text' is missing or invalid", kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "'text' is missing or invalid"));
return;
}
- response->SetStatus(session_->SetAlertPromptText(text));
+ Error* error = session_->SetAlertPromptText(text);
+ if (error)
+ response->SetError(error);
}
AcceptAlertCommand::AcceptAlertCommand(
@@ -59,7 +64,9 @@ bool AcceptAlertCommand::DoesPost() {
}
void AcceptAlertCommand::ExecutePost(Response* const response) {
- response->SetStatus(session_->AcceptOrDismissAlert(true));
+ Error* error = session_->AcceptOrDismissAlert(true);
+ if (error)
+ response->SetError(error);
}
DismissAlertCommand::DismissAlertCommand(
@@ -76,7 +83,9 @@ bool DismissAlertCommand::DoesPost() {
}
void DismissAlertCommand::ExecutePost(Response* const response) {
- response->SetStatus(session_->AcceptOrDismissAlert(false));
+ Error* error = session_->AcceptOrDismissAlert(false);
+ if (error)
+ response->SetError(error);
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/cookie_commands.cc b/chrome/test/webdriver/commands/cookie_commands.cc
index 3b6c725..657cd9f 100644
--- a/chrome/test/webdriver/commands/cookie_commands.cc
+++ b/chrome/test/webdriver/commands/cookie_commands.cc
@@ -33,16 +33,16 @@ CookieCommand::~CookieCommand() {}
bool CookieCommand::Init(Response* const response) {
if (!WebDriverCommand::Init(response))
return false;
- if (!session_->CompareBrowserVersion(kNewInterfaceBuildNo, 0,
- &uses_new_interface_)) {
- SET_WEBDRIVER_ERROR(response, "Failed to check Chrome version number",
- kUnknownError);
+
+ Error* error = session_->CompareBrowserVersion(
+ kNewInterfaceBuildNo, 0, &uses_new_interface_);
+ if (error) {
+ response->SetError(error);
return false;
}
- ErrorCode code = session_->GetURL(&current_url_);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to query current page URL",
- code);
+ error = session_->GetURL(&current_url_);
+ if (error) {
+ response->SetError(error);
return false;
}
return true;
@@ -63,9 +63,10 @@ bool CookieCommand::DoesPost() {
void CookieCommand::ExecuteGet(Response* const response) {
if (uses_new_interface_) {
ListValue* cookies;
- if (!session_->GetCookies(current_url_.possibly_invalid_spec(), &cookies)) {
- SET_WEBDRIVER_ERROR(response, "Failed to fetch cookies",
- kUnknownError);
+ Error* error = session_->GetCookies(current_url_.possibly_invalid_spec(),
+ &cookies);
+ if (error) {
+ response->SetError(error);
return;
}
response->SetStatus(kSuccess);
@@ -74,8 +75,7 @@ void CookieCommand::ExecuteGet(Response* const response) {
std::string cookies;
std::vector<std::string> tokens;
if (!session_->GetCookiesDeprecated(current_url_, &cookies)) {
- SET_WEBDRIVER_ERROR(response, "Failed to fetch cookies",
- kUnknownError);
+ response->SetError(new Error(kUnknownError, "Failed to fetch cookies"));
return;
}
// Note that ';' separates cookies while ':' separates name/value pairs.
@@ -87,9 +87,7 @@ void CookieCommand::ExecuteGet(Response* const response) {
if (cookie.valid()) {
cookie_list->Append(cookie.ToDictionary());
} else {
- LOG(ERROR) << "Failed to parse cookie: " << *i;
- SET_WEBDRIVER_ERROR(response, "Could not get all cookies",
- kInternalServerError);
+ response->SetError(new Error(kUnknownError, "Failed to parse cookies"));
return;
}
}
@@ -104,9 +102,7 @@ void CookieCommand::ExecutePost(Response* const response) {
// Check to see if the cookie was passed in as a JSON onject.
if (!GetDictionaryParameter("cookie", &cookie_dict)) {
- // No valid cookie sent.
- SET_WEBDRIVER_ERROR(response, "Cookie key not found",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Cookie key not found"));
return;
}
@@ -116,18 +112,18 @@ void CookieCommand::ExecutePost(Response* const response) {
std::vector<std::string> split_domain;
base::SplitString(domain, ':', &split_domain);
if (split_domain.size() > 2) {
- SET_WEBDRIVER_ERROR(response, "Cookie domain has too many colons",
- kInvalidCookieDomain);
+ response->SetError(new Error(
+ kInvalidCookieDomain, "Cookie domain has too many colons"));
return;
} else if (split_domain.size() == 2) {
// Remove the port number.
cookie_dict->SetString("domain", split_domain[0]);
}
}
- if (!session_->SetCookie(current_url_.possibly_invalid_spec(),
- cookie_dict)) {
- SET_WEBDRIVER_ERROR(response, "Failed to set cookie",
- kUnableToSetCookie);
+ Error* error = session_->SetCookie(
+ current_url_.possibly_invalid_spec(), cookie_dict);
+ if (error) {
+ response->SetError(error);
return;
}
} else {
@@ -135,14 +131,12 @@ void CookieCommand::ExecutePost(Response* const response) {
// Make sure the cookie is formated preoperly.
if (!cookie.valid()) {
- SET_WEBDRIVER_ERROR(response, "Invalid cookie",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Invalid cookie"));
return;
}
if (!session_->SetCookieDeprecated(current_url_, cookie.ToString())) {
- SET_WEBDRIVER_ERROR(response, "Failed to set cookie",
- kUnableToSetCookie);
+ response->SetError(new Error(kUnableToSetCookie, "Failed to set cookie"));
return;
}
response->SetValue(new StringValue(cookie.ToString()));
@@ -153,32 +147,31 @@ void CookieCommand::ExecutePost(Response* const response) {
void CookieCommand::ExecuteDelete(Response* const response) {
if (uses_new_interface_) {
ListValue* unscoped_cookies;
- if (!session_->GetCookies(current_url_.possibly_invalid_spec(),
- &unscoped_cookies)) {
- SET_WEBDRIVER_ERROR(response, "Failed to fetch cookies",
- kUnknownError);
+ Error* error = session_->GetCookies(
+ current_url_.possibly_invalid_spec(), &unscoped_cookies);
+ if (error) {
+ response->SetError(error);
return;
}
scoped_ptr<ListValue> cookies(unscoped_cookies);
for (size_t i = 0; i < cookies->GetSize(); ++i) {
DictionaryValue* cookie_dict;
if (!cookies->GetDictionary(i, &cookie_dict)) {
- SET_WEBDRIVER_ERROR(response, "GetCookies returned non-dict type",
- kUnknownError);
+ response->SetError(new Error(
+ kUnknownError, "GetCookies returned non-dict type"));
return;
}
std::string name;
if (!cookie_dict->GetString("name", &name)) {
- SET_WEBDRIVER_ERROR(
- response,
- "GetCookies returned cookie with missing or invalid 'name'",
- kUnknownError);
+ response->SetError(new Error(
+ kUnknownError,
+ "GetCookies returned cookie with missing or invalid 'name'"));
return;
}
- if (!session_->DeleteCookie(current_url_.possibly_invalid_spec(),
- name)) {
- SET_WEBDRIVER_ERROR(response, "Could not delete all cookies",
- kUnknownError);
+ Error* error = session_->DeleteCookie(
+ current_url_.possibly_invalid_spec(), name);
+ if (error) {
+ response->SetError(error);
return;
}
}
@@ -187,8 +180,8 @@ void CookieCommand::ExecuteDelete(Response* const response) {
std::vector<std::string> tokens;
if (!session_->GetCookiesDeprecated(current_url_, &cookies)) {
- SET_WEBDRIVER_ERROR(response, "Failed to fetch cookies",
- kUnableToSetCookie);
+ response->SetError(new Error(
+ kUnableToSetCookie, "Failed to fetch cookies"));
return;
}
@@ -199,16 +192,12 @@ void CookieCommand::ExecuteDelete(Response* const response) {
if (cookie.valid()) {
if (!session_->DeleteCookie(current_url_.possibly_invalid_spec(),
cookie.name())) {
- VLOG(1) << "Could not delete cookie: " << cookie.name() << "\n"
- << "Contents of cookie: " << cookie.ToString();
- SET_WEBDRIVER_ERROR(response, "Could not delete all cookies",
- kInternalServerError);
+ response->SetError(new Error(
+ kUnknownError, "Could not delete all cookies"));
return;
}
} else {
- LOG(ERROR) << "Failed to parse cookie: " << *i;
- SET_WEBDRIVER_ERROR(response, "Could not delete all cookies",
- kInternalServerError);
+ response->SetError(new Error(kUnknownError, "Failed to parse cookie"));
return;
}
}
@@ -228,17 +217,16 @@ bool NamedCookieCommand::Init(Response* const response) {
if (!WebDriverCommand::Init(response))
return false;
- if (!session_->CompareBrowserVersion(kNewInterfaceBuildNo, 0,
- &uses_new_interface_)) {
- SET_WEBDRIVER_ERROR(response, "Failed to check Chrome version number",
- kUnknownError);
+ Error* error = session_->CompareBrowserVersion(
+ kNewInterfaceBuildNo, 0, &uses_new_interface_);
+ if (error) {
+ response->SetError(error);
return false;
}
- ErrorCode code = session_->GetURL(&current_url_);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to query current page URL",
- code);
+ error = session_->GetURL(&current_url_);
+ if (error) {
+ response->SetError(error);
return false;
}
@@ -246,8 +234,7 @@ bool NamedCookieCommand::Init(Response* const response) {
// /session/:sessionId/cookie/:name
cookie_name_ = GetPathVariable(4);
if (cookie_name_ == "") {
- SET_WEBDRIVER_ERROR(response, "No cookie name specified",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "No cookie name specified"));
return false;
}
@@ -260,17 +247,15 @@ bool NamedCookieCommand::DoesDelete() {
void NamedCookieCommand::ExecuteDelete(Response* const response) {
if (uses_new_interface_) {
- if (!session_->DeleteCookie(current_url_.possibly_invalid_spec(),
- cookie_name_)) {
- SET_WEBDRIVER_ERROR(response,
- "Failed to delete cookie",
- kUnknownError);
+ Error* error = session_->DeleteCookie(
+ current_url_.possibly_invalid_spec(), cookie_name_);
+ if (error) {
+ response->SetError(error);
return;
}
} else {
if (!session_->DeleteCookieDeprecated(current_url_, cookie_name_)) {
- SET_WEBDRIVER_ERROR(response, "Failed to delete cookie",
- kUnknownError);
+ response->SetError(new Error(kUnknownError, "Failed to delete cookie"));
return;
}
}
diff --git a/chrome/test/webdriver/commands/create_session.cc b/chrome/test/webdriver/commands/create_session.cc
index c2f37e2..d6bab1c 100644
--- a/chrome/test/webdriver/commands/create_session.cc
+++ b/chrome/test/webdriver/commands/create_session.cc
@@ -16,12 +16,10 @@
#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/session_manager.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
-// The minimum supported version of Chrome for this version of ChromeDriver.
-const int kMinSupportedChromeVersion = 12;
-
CreateSession::CreateSession(const std::vector<std::string>& path_segments,
const DictionaryValue* const parameters)
: Command(path_segments, parameters) {}
@@ -46,9 +44,8 @@ void CreateSession::ExecutePost(Response* const response) {
while (i != added_options->end_keys()) {
FilePath::StringType value;
if (!added_options->GetString(*i, &value)) {
- SET_WEBDRIVER_ERROR(response,
- "Invalid format for added options to browser",
- kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "Invalid format for added options to browser"));
return;
} else {
if (!value.empty()) {
@@ -57,7 +54,7 @@ void CreateSession::ExecutePost(Response* const response) {
options.AppendSwitch(*i);
}
}
- ++i;
+ ++i;
}
FilePath::StringType path;
desiredCapabilities->GetString("chrome.binary", &path);
@@ -66,33 +63,9 @@ void CreateSession::ExecutePost(Response* const response) {
// Session manages its own liftime, so do not call delete.
Session* session = new Session();
- ErrorCode code = session->Init(user_browser_exe, options);
-
- if (code == kBrowserCouldNotBeFound) {
- SET_WEBDRIVER_ERROR(response,
- "Chrome could not be found.",
- kUnknownError);
- return;
- } else if (code == kBrowserFailedToStart) {
- std::string error_msg = base::StringPrintf(
- "Chrome could not be started successfully. "
- "Please update ChromeDriver and ensure you are using Chrome %d+.",
- kMinSupportedChromeVersion);
- SET_WEBDRIVER_ERROR(response, error_msg, kUnknownError);
- return;
- } else if (code == kIncompatibleBrowserVersion) {
- std::string error_msg = base::StringPrintf(
- "Version of Chrome is incompatible with version of ChromeDriver. "
- "Please update ChromeDriver and ensure you are using Chrome %d+.",
- kMinSupportedChromeVersion);
- SET_WEBDRIVER_ERROR(response, error_msg, kUnknownError);
- return;
- } else if (code != kSuccess) {
- std::string error_msg = base::StringPrintf(
- "Unknown error while initializing session. "
- "Ensure ChromeDriver is up-to-date and Chrome is version %d+.",
- kMinSupportedChromeVersion);
- SET_WEBDRIVER_ERROR(response, error_msg, kUnknownError);
+ Error* error = session->Init(user_browser_exe, options);
+ if (error) {
+ response->SetError(error);
return;
}
diff --git a/chrome/test/webdriver/commands/create_session.h b/chrome/test/webdriver/commands/create_session.h
index d401a7f..6595ae2 100644
--- a/chrome/test/webdriver/commands/create_session.h
+++ b/chrome/test/webdriver/commands/create_session.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -9,7 +9,6 @@
#include <vector>
#include "chrome/test/webdriver/commands/command.h"
-#include "chrome/test/webdriver/commands/webdriver_command.h"
namespace webdriver {
@@ -37,4 +36,3 @@ class CreateSession : public Command {
} // namespace webdriver
#endif // CHROME_TEST_WEBDRIVER_COMMANDS_CREATE_SESSION_H_
-
diff --git a/chrome/test/webdriver/commands/execute_async_script_command.cc b/chrome/test/webdriver/commands/execute_async_script_command.cc
index 9d5e370..747640e 100644
--- a/chrome/test/webdriver/commands/execute_async_script_command.cc
+++ b/chrome/test/webdriver/commands/execute_async_script_command.cc
@@ -6,8 +6,8 @@
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -25,24 +25,26 @@ bool ExecuteAsyncScriptCommand::DoesPost() {
void ExecuteAsyncScriptCommand::ExecutePost(Response* const response) {
std::string script;
if (!GetStringParameter("script", &script)) {
- SET_WEBDRIVER_ERROR(response, "No script to execute specified",
- kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "No script to execute specified"));
return;
}
ListValue* args;
if (!GetListParameter("args", &args)) {
- SET_WEBDRIVER_ERROR(response, "No script arguments specified",
- kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "No script arguments specified"));
return;
}
Value* result = NULL;
- ErrorCode status = session_->ExecuteAsyncScript(
+ Error* error = session_->ExecuteAsyncScript(
session_->current_target(), script, args, &result);
- response->SetStatus(status);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
} // namspace webdriver
-
diff --git a/chrome/test/webdriver/commands/execute_command.cc b/chrome/test/webdriver/commands/execute_command.cc
index e22264b..89bec72 100644
--- a/chrome/test/webdriver/commands/execute_command.cc
+++ b/chrome/test/webdriver/commands/execute_command.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -7,15 +7,12 @@
#include <string>
#include "base/values.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/commands/response.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
-const char kArgs[] = "args";
-const char kScript[] = "script";
-
ExecuteCommand::ExecuteCommand(const std::vector<std::string>& path_segments,
const DictionaryValue* const parameters)
: WebDriverCommand(path_segments, parameters) {}
@@ -28,28 +25,25 @@ bool ExecuteCommand::DoesPost() {
void ExecuteCommand::ExecutePost(Response* const response) {
std::string script;
- if (!GetStringParameter(kScript, &script)) {
- SET_WEBDRIVER_ERROR(response, "No script to execute specified",
- kBadRequest);
+ if (!GetStringParameter("script", &script)) {
+ response->SetError(new Error(kBadRequest, "No script specified"));
return;
}
ListValue* args;
- if (!GetListParameter(kArgs, &args)) {
- SET_WEBDRIVER_ERROR(response, "No script arguments specified",
- kBadRequest);
+ if (!GetListParameter("args", &args)) {
+ response->SetError(new Error(
+ kBadRequest, "No script arguments specified"));
return;
}
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args, &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
-bool ExecuteCommand::RequiresValidTab() {
- return true;
-}
-
} // namspace webdriver
-
diff --git a/chrome/test/webdriver/commands/execute_command.h b/chrome/test/webdriver/commands/execute_command.h
index a9f3fa2..c164b78 100644
--- a/chrome/test/webdriver/commands/execute_command.h
+++ b/chrome/test/webdriver/commands/execute_command.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -30,12 +30,9 @@ class ExecuteCommand : public WebDriverCommand {
virtual void ExecutePost(Response* const response);
private:
- virtual bool RequiresValidTab();
-
DISALLOW_COPY_AND_ASSIGN(ExecuteCommand);
};
} // namespace webdriver
#endif // CHROME_TEST_WEBDRIVER_COMMANDS_EXECUTE_COMMAND_H_
-
diff --git a/chrome/test/webdriver/commands/find_element_commands.cc b/chrome/test/webdriver/commands/find_element_commands.cc
index a40be0b..b0589bd 100644
--- a/chrome/test/webdriver/commands/find_element_commands.cc
+++ b/chrome/test/webdriver/commands/find_element_commands.cc
@@ -6,9 +6,9 @@
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/web_element_id.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -29,12 +29,12 @@ void FindElementCommand::ExecutePost(Response* const response) {
std::string locator, query;
if (!GetStringParameter("using", &locator) ||
!GetStringParameter("value", &query)) {
- SET_WEBDRIVER_ERROR(response,
- "Request is missing required 'using' and/or 'value' data", kBadRequest);
+ response->SetError(new Error(
+ kBadRequest,
+ "Request is missing required 'using' and/or 'value' data"));
return;
}
- // TODO(jmikhail): The findElement(s) atom should handle this conversion.
if (locator == "class name") {
locator = LocatorType::kClassName;
} else if (locator == "css selector") {
@@ -53,25 +53,29 @@ void FindElementCommand::ExecutePost(Response* const response) {
// "/session/$session/element/$id/element(s)"
WebElementId root_element(GetPathVariable(4));
- ErrorCode code = kUnknownError;
if (find_one_element_) {
WebElementId element;
- code = session_->FindElement(
+ Error* error = session_->FindElement(
session_->current_target(), root_element, locator, query, &element);
- if (code == kSuccess)
- response->SetValue(element.ToValue());
+ if (error) {
+ response->SetError(error);
+ return;
+ }
+ response->SetValue(element.ToValue());
} else {
std::vector<WebElementId> elements;
- code = session_->FindElements(
+ Error* error = session_->FindElements(
session_->current_target(), root_element, locator, query, &elements);
- if (code == kSuccess) {
- ListValue* element_list = new ListValue();
- for (size_t i = 0; i < elements.size(); ++i)
- element_list->Append(elements[i].ToValue());
- response->SetValue(element_list);
+ if (error) {
+ response->SetError(error);
+ return;
}
+ ListValue* element_list = new ListValue();
+ for (size_t i = 0; i < elements.size(); ++i)
+ element_list->Append(elements[i].ToValue());
+ response->SetValue(element_list);
}
- response->SetStatus(code);
+ response->SetStatus(kSuccess);
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/find_element_commands.h b/chrome/test/webdriver/commands/find_element_commands.h
index 4cf987e..46dfbae 100644
--- a/chrome/test/webdriver/commands/find_element_commands.h
+++ b/chrome/test/webdriver/commands/find_element_commands.h
@@ -8,7 +8,6 @@
#include <string>
#include <vector>
-#include "chrome/test/webdriver/commands/command.h"
#include "chrome/test/webdriver/commands/webdriver_command.h"
namespace webdriver {
@@ -68,4 +67,3 @@ class FindManyElementsCommand : public FindElementCommand {
} // namespace webdriver
#endif // CHROME_TEST_WEBDRIVER_COMMANDS_FIND_ELEMENT_COMMANDS_H_
-
diff --git a/chrome/test/webdriver/commands/mouse_commands.cc b/chrome/test/webdriver/commands/mouse_commands.cc
index 34281b1..c331cbc 100644
--- a/chrome/test/webdriver/commands/mouse_commands.cc
+++ b/chrome/test/webdriver/commands/mouse_commands.cc
@@ -7,17 +7,19 @@
#include "base/values.h"
#include "chrome/common/automation_constants.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/web_element_id.h"
+#include "chrome/test/webdriver/webdriver_error.h"
#include "ui/gfx/point.h"
#include "ui/gfx/size.h"
namespace {
-static const int kLeftButton = 0;
-static const int kMiddleButton = 1;
-static const int kRightButton = 2;
-}
+
+const int kLeftButton = 0;
+const int kMiddleButton = 1;
+const int kRightButton = 2;
+
+} // namespace
namespace webdriver {
@@ -33,40 +35,32 @@ bool ElementMouseCommand::DoesPost() {
}
void ElementMouseCommand::ExecutePost(Response* response) {
- bool is_displayed;
- ErrorCode code = session_->IsElementDisplayed(
- session_->current_target(), element, &is_displayed);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to determine element visibility",
- code);
- return;
- }
- if (!is_displayed) {
- SET_WEBDRIVER_ERROR(response, "Element must be displayed",
- kElementNotVisible);
+ Error* error = session_->CheckElementPreconditionsForClicking(element);
+ if (error) {
+ response->SetError(error);
return;
}
gfx::Point location;
- code = session_->GetElementLocationInView(element, &location);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to compute element location.",
- code);
+ error = session_->GetElementLocationInView(element, &location);
+ if (error) {
+ response->SetError(error);
return;
}
gfx::Size size;
- code = session_->GetElementSize(session_->current_target(), element, &size);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to compute element size.", code);
+ error = session_->GetElementSize(session_->current_target(), element, &size);
+ if (error) {
+ response->SetError(error);
return;
}
location.Offset(size.width() / 2, size.height() / 2);
- if (!Action(location, response))
+ error = Action(location);
+ if (error) {
+ response->SetError(error);
return;
-
- response->SetStatus(kSuccess);
+ }
}
MoveAndClickCommand::MoveAndClickCommand(
@@ -76,17 +70,8 @@ MoveAndClickCommand::MoveAndClickCommand(
MoveAndClickCommand::~MoveAndClickCommand() {}
-bool MoveAndClickCommand::Action(const gfx::Point& location,
- Response* const response) {
- VLOG(1) << "Mouse click at: (" << location.x() << ", "
- << location.y() << ")" << std::endl;
- if (!session_->MouseMoveAndClick(location, automation::kLeftButton)) {
- SET_WEBDRIVER_ERROR(response, "Performing mouse operation failed",
- kUnknownError);
- return false;
- }
-
- return true;
+Error* MoveAndClickCommand::Action(const gfx::Point& location) {
+ return session_->MouseMoveAndClick(location, automation::kLeftButton);
}
HoverCommand::HoverCommand(const std::vector<std::string>& path_segments,
@@ -95,17 +80,8 @@ HoverCommand::HoverCommand(const std::vector<std::string>& path_segments,
HoverCommand::~HoverCommand() {}
-bool HoverCommand::Action(const gfx::Point& location,
- Response* const response) {
- VLOG(1) << "Mouse hover at: (" << location.x() << ", "
- << location.y() << ")" << std::endl;
- if (!session_->MouseMove(location)) {
- SET_WEBDRIVER_ERROR(response, "Performing mouse operation failed",
- kUnknownError);
- return false;
- }
-
- return true;
+Error* HoverCommand::Action(const gfx::Point& location) {
+ return session_->MouseMove(location);
}
DragCommand::DragCommand(const std::vector<std::string>& path_segments,
@@ -120,37 +96,21 @@ bool DragCommand::Init(Response* const response) {
if (!GetIntegerParameter("x", &drag_x_) ||
!GetIntegerParameter("y", &drag_y_)) {
- SET_WEBDRIVER_ERROR(response,
- "Request is missing the required positional data",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Missing (x,y) coordinates"));
return false;
}
return true;
}
-bool DragCommand::Action(const gfx::Point& location, Response* const response) {
+Error* DragCommand::Action(const gfx::Point& location) {
gfx::Point drag_from(location);
gfx::Point drag_to(drag_from);
drag_to.Offset(drag_x_, drag_y_);
- if (drag_to.x() < 0 || drag_to.y() < 0) {
- SET_WEBDRIVER_ERROR(response, "Invalid pos to drag to", kBadRequest);
- return false;
- }
+ if (drag_to.x() < 0 || drag_to.y() < 0)
+ return new Error(kBadRequest, "Invalid (x,y) coordinates");
- // click on the element
- VLOG(1) << "Dragging mouse from: "
- << "(" << location.x() << ", " << location.y() << ") "
- << "to: (" << drag_to.x() << ", " << drag_to.y() << ")"
- << std::endl;
- if (!session_->MouseDrag(location, drag_to)) {
- SET_WEBDRIVER_ERROR(response,
- "Request is missing the required positional data",
- kBadRequest);
- return false;
- }
-
- return true;
+ return session_->MouseDrag(location, drag_to);
}
AdvancedMouseCommand::AdvancedMouseCommand(
@@ -187,9 +147,8 @@ bool MoveToCommand::Init(Response* const response) {
GetIntegerParameter("yoffset", &y_offset_);
if (!has_element_ && !has_offset_) {
- SET_WEBDRIVER_ERROR(response,
- "Request is missing the required data",
- kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "Invalid command arguments"));
return false;
}
@@ -201,63 +160,45 @@ void MoveToCommand::ExecutePost(Response* const response) {
if (has_element_) {
// If an element is specified, calculate the coordinate.
- bool is_displayed;
- ErrorCode code = session_->IsElementDisplayed(session_->current_target(),
- element_, &is_displayed);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to determine element visibility",
- code);
+ Error* error = session_->CheckElementPreconditionsForClicking(element_);
+ if (error) {
+ response->SetError(error);
return;
}
- if (!is_displayed) {
- SET_WEBDRIVER_ERROR(response, "Element must be displayed",
- kElementNotVisible);
+ error = session_->GetElementLocationInView(element_, &location);
+ if (error) {
+ response->SetError(error);
return;
}
-
- code = session_->GetElementLocationInView(element_, &location);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to compute element location.",
- code);
- return;
- }
-
- VLOG(1) << "An element requested. x:" << location.x() << " y:"
- << location.y();
-
} else {
// If not, use the current mouse position.
- VLOG(1) << "No element requested, using current mouse position";
location = session_->get_mouse_position();
}
if (has_offset_) {
// If an offset is specified, translate by the offset.
location.Offset(x_offset_, y_offset_);
-
- VLOG(1) << "An offset requested. x:" << x_offset_ << " y:" << y_offset_;
-
} else {
DCHECK(has_element_);
// If not, calculate the half of the element size and translate by it.
gfx::Size size;
- ErrorCode code = session_->GetElementSize(session_->current_target(),
- element_, &size);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to compute element size.", code);
+ Error* error = session_->GetElementSize(session_->current_target(),
+ element_, &size);
+ if (error) {
+ response->SetError(error);
return;
}
location.Offset(size.width() / 2, size.height() / 2);
-
- VLOG(1) << "No offset requested. The element size is " << size.width()
- << "x" << size.height();
}
- VLOG(1) << "Mouse moved to: (" << location.x() << ", " << location.y() << ")";
- session_->MouseMove(location);
+ Error* error = session_->MouseMove(location);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
}
ClickCommand::ClickCommand(const std::vector<std::string>& path_segments,
@@ -271,9 +212,7 @@ bool ClickCommand::Init(Response* const response) {
return false;
if (!GetIntegerParameter("button", &button_)) {
- SET_WEBDRIVER_ERROR(response,
- "Request is missing the required button data",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Missing mouse button argument"));
return false;
}
@@ -290,11 +229,15 @@ void ClickCommand::ExecutePost(Response* const response) {
} else if (button_ == kRightButton) {
button = automation::kRightButton;
} else {
- SET_WEBDRIVER_ERROR(response, "Invalid button", kBadRequest);
+ response->SetError(new Error(kBadRequest, "Invalid mouse button"));
return;
}
- session_->MouseClick(button);
+ Error* error = session_->MouseClick(button);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
}
ButtonDownCommand::ButtonDownCommand(
@@ -326,7 +269,11 @@ DoubleClickCommand::DoubleClickCommand(
DoubleClickCommand::~DoubleClickCommand() {}
void DoubleClickCommand::ExecutePost(Response* const response) {
- session_->MouseDoubleClick();
+ Error* error = session_->MouseDoubleClick();
+ if (error) {
+ response->SetError(error);
+ return;
+ }
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/mouse_commands.h b/chrome/test/webdriver/commands/mouse_commands.h
index 4510ccf..cc6f931 100644
--- a/chrome/test/webdriver/commands/mouse_commands.h
+++ b/chrome/test/webdriver/commands/mouse_commands.h
@@ -9,11 +9,17 @@
#include <vector>
#include "chrome/test/webdriver/commands/webelement_commands.h"
+#include "chrome/test/webdriver/web_element_id.h"
class DictionaryValue;
+namespace gfx {
+class Point;
+}
+
namespace webdriver {
+class Error;
class Response;
// Base class for the following API command classes.
@@ -28,7 +34,7 @@ class ElementMouseCommand : public WebElementCommand {
virtual bool DoesPost();
virtual void ExecutePost(Response* const response);
- virtual bool Action(const gfx::Point& location, Response* const response) = 0;
+ virtual Error* Action(const gfx::Point& location) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(ElementMouseCommand);
@@ -46,7 +52,7 @@ class MoveAndClickCommand : public ElementMouseCommand {
const DictionaryValue* const parameters);
virtual ~MoveAndClickCommand();
- virtual bool Action(const gfx::Point& location, Response* const response);
+ virtual Error* Action(const gfx::Point& location);
private:
DISALLOW_COPY_AND_ASSIGN(MoveAndClickCommand);
@@ -60,7 +66,7 @@ class HoverCommand : public ElementMouseCommand {
const DictionaryValue* const parameters);
virtual ~HoverCommand();
- virtual bool Action(const gfx::Point& location, Response* const response);
+ virtual Error* Action(const gfx::Point& location);
private:
DISALLOW_COPY_AND_ASSIGN(HoverCommand);
@@ -76,7 +82,7 @@ class DragCommand : public ElementMouseCommand {
virtual ~DragCommand();
virtual bool Init(Response* const response);
- virtual bool Action(const gfx::Point& location, Response* const response);
+ virtual Error* Action(const gfx::Point& location);
private:
int drag_x_, drag_y_;
diff --git a/chrome/test/webdriver/commands/navigate_commands.cc b/chrome/test/webdriver/commands/navigate_commands.cc
index ffc5396..f61ed85 100644
--- a/chrome/test/webdriver/commands/navigate_commands.cc
+++ b/chrome/test/webdriver/commands/navigate_commands.cc
@@ -1,10 +1,12 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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 "chrome/test/webdriver/commands/navigate_commands.h"
#include "chrome/test/webdriver/commands/response.h"
+#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -19,16 +21,9 @@ bool ForwardCommand::DoesPost() {
}
void ForwardCommand::ExecutePost(Response* const response) {
- if (!session_->GoForward()) {
- SET_WEBDRIVER_ERROR(response, "GoForward failed", kInternalServerError);
- return;
- }
-
- response->SetStatus(kSuccess);
-}
-
-bool ForwardCommand::RequiresValidTab() {
- return true;
+ Error* error = session_->GoForward();
+ if (error)
+ response->SetError(error);
}
BackCommand::BackCommand(const std::vector<std::string>& path_segments,
@@ -42,16 +37,9 @@ bool BackCommand::DoesPost() {
}
void BackCommand::ExecutePost(Response* const response) {
- if (!session_->GoBack()) {
- SET_WEBDRIVER_ERROR(response, "GoBack failed", kInternalServerError);
- return;
- }
-
- response->SetStatus(kSuccess);
-}
-
-bool BackCommand::RequiresValidTab() {
- return true;
+ Error* error = session_->GoBack();
+ if (error)
+ response->SetError(error);
}
RefreshCommand::RefreshCommand(const std::vector<std::string>& path_segments,
@@ -65,16 +53,9 @@ bool RefreshCommand::DoesPost() {
}
void RefreshCommand::ExecutePost(Response* const response) {
- if (!session_->Reload()) {
- SET_WEBDRIVER_ERROR(response, "Reload failed", kInternalServerError);
- return;
- }
-
- response->SetStatus(kSuccess);
-}
-
-bool RefreshCommand::RequiresValidTab() {
- return true;
+ Error* error = session_->Reload();
+ if (error)
+ response->SetError(error);
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/navigate_commands.h b/chrome/test/webdriver/commands/navigate_commands.h
index c4960f9..a5777b22 100644
--- a/chrome/test/webdriver/commands/navigate_commands.h
+++ b/chrome/test/webdriver/commands/navigate_commands.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -26,8 +26,6 @@ class ForwardCommand : public WebDriverCommand {
virtual void ExecutePost(Response* const response);
private:
- virtual bool RequiresValidTab();
-
DISALLOW_COPY_AND_ASSIGN(ForwardCommand);
};
@@ -43,8 +41,6 @@ class BackCommand : public WebDriverCommand {
virtual void ExecutePost(Response* const response);
private:
- virtual bool RequiresValidTab();
-
DISALLOW_COPY_AND_ASSIGN(BackCommand);
};
@@ -60,12 +56,9 @@ class RefreshCommand : public WebDriverCommand {
virtual void ExecutePost(Response* const response);
private:
- virtual bool RequiresValidTab();
-
DISALLOW_COPY_AND_ASSIGN(RefreshCommand);
};
} // namespace webdriver
#endif // CHROME_TEST_WEBDRIVER_COMMANDS_NAVIGATE_COMMANDS_H_
-
diff --git a/chrome/test/webdriver/commands/response.cc b/chrome/test/webdriver/commands/response.cc
index bb711efa..0060fa0 100644
--- a/chrome/test/webdriver/commands/response.cc
+++ b/chrome/test/webdriver/commands/response.cc
@@ -57,49 +57,15 @@ void Response::SetValue(Value* value) {
data_.Set(kValueKey, value);
}
-void Response::SetError(ErrorCode error_code, const std::string& message,
- const std::string& file, int line) {
- DictionaryValue* error = new DictionaryValue;
- error->SetString(kMessageKey, message);
-
- DictionaryValue* stack = new DictionaryValue;
- stack->SetString(kStackTraceFileNameKey, file);
- stack->SetString(kStackTraceClassNameKey, "");
- stack->SetString(kStackTraceMethodNameKey, "");
- stack->SetInteger(kStackTraceLineNumberKey, line);
- ListValue* stack_list = new ListValue;
- stack_list->Append(stack);
- error->Set(kStackTraceKey, stack_list);
-
- SetStatus(error_code);
- SetValue(error);
-}
+void Response::SetError(Error* error) {
+ DictionaryValue* error_dict = new DictionaryValue();
+ error_dict->SetString(kMessageKey, error->ToString());
-void Response::SetError(ErrorCode error_code,
- const std::string& message,
- const std::string& file,
- int line,
- const std::string& png) {
- DictionaryValue* error = new DictionaryValue;
-
- error->SetString(kMessageKey, message);
- error->SetString(kStackTraceFileNameKey, file);
- error->SetInteger(kStackTraceLineNumberKey, line);
- std::string base64_png;
-
- // Convert the raw binary data to base 64 encoding for webdriver.
- if (!base::Base64Encode(png, &base64_png)) {
- LOG(ERROR) << "Failed to encode screenshot to base64 "
- << "sending back an empty string instead.";
- } else {
- error->SetString(kScreenKey, base64_png);
- }
-
- SetStatus(error_code);
- SetValue(error);
+ SetStatus(error->code());
+ SetValue(error_dict);
+ delete error;
}
-
void Response::SetField(const std::string& key, Value* value) {
data_.Set(key, value);
}
diff --git a/chrome/test/webdriver/commands/response.h b/chrome/test/webdriver/commands/response.h
index 678851f..9c44e60 100644
--- a/chrome/test/webdriver/commands/response.h
+++ b/chrome/test/webdriver/commands/response.h
@@ -9,23 +9,10 @@
#include <string>
#include "base/values.h"
-#include "chrome/test/webdriver/error_codes.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
-// All errors in webdriver must use this macro in order to send back
-// a proper stack trace to the client.
-#define SET_WEBDRIVER_ERROR(response, msg, err) \
- response->SetError(err, msg, __FILE__, __LINE__); \
- LOG(ERROR) << msg
-
-// Error which need to send back a screenshot should use this macro.
-// |png| needs to be a string which contains the raw binary data of
-// the PNG file.
-#define SET_WEBDRIVER_ERROR_WITH_SCREENSHOT(response, msg, err , png) \
- response->SetError(err, msg, __FILE__, __LINE__, png); \
- LOG(ERROR) << msg
-
// A simple class that encapsulates the information describing the response to
// a |Command|. In Webdriver all responses must be sent back as a JSON value,
// conforming to the spec found at:
@@ -47,21 +34,9 @@ class Response {
// process.
void SetValue(Value* value);
- // Configures this response to report an error. The |file| and |line|
- // parameters, which identify where in the source the error occurred, can be
- // set using the |SET_WEBDRIVER_ERROR| macro above.
- void SetError(ErrorCode error, const std::string& message,
- const std::string& file, int line);
-
- // Configures this response to report an error. The |file| and |line|
- // parameters, which identify where in the source the error occurred, can be
- // set using the |SET_WEBDRIVER_ERROR_WITH_SCREENSHOT| macro above. Includes
- // a screen shot of the tab which caused the error.
- void SetError(ErrorCode error,
- const std::string& message,
- const std::string& file,
- int line,
- const std::string& png);
+ // Configures this response to report the given error. Ownership of the error
+ // is taken from the caller.
+ void SetError(Error* error);
// Sets a JSON field in this response. The |key| may be a "." delimitted
// string to indicate the value should be set in a nested object. Any
@@ -81,4 +56,3 @@ class Response {
} // namespace webdriver
#endif // CHROME_TEST_WEBDRIVER_COMMANDS_RESPONSE_H_
-
diff --git a/chrome/test/webdriver/commands/screenshot_command.cc b/chrome/test/webdriver/commands/screenshot_command.cc
index bec6d98..352b062 100644
--- a/chrome/test/webdriver/commands/screenshot_command.cc
+++ b/chrome/test/webdriver/commands/screenshot_command.cc
@@ -10,8 +10,8 @@
#include "base/base64.h"
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -27,23 +27,21 @@ bool ScreenshotCommand::DoesGet() {
void ScreenshotCommand::ExecuteGet(Response* const response) {
std::string raw_bytes;
- if (!session_->GetScreenShot(&raw_bytes)) {
- SET_WEBDRIVER_ERROR(response, "Screenshot of current page failed",
- kInternalServerError);
+ Error* error = session_->GetScreenShot(&raw_bytes);
+ if (error) {
+ response->SetError(error);
return;
}
// Convert the raw binary data to base 64 encoding for webdriver.
std::string base64_screenshot;
if (!base::Base64Encode(raw_bytes, &base64_screenshot)) {
- SET_WEBDRIVER_ERROR(response, "Encoding the PNG to base64 format failed",
- kInternalServerError);
+ response->SetError(new Error(
+ kUnknownError, "Encoding the PNG to base64 format failed"));
return;
}
response->SetValue(new StringValue(base64_screenshot));
- response->SetStatus(kSuccess);
}
} // namespace webdriver
-
diff --git a/chrome/test/webdriver/commands/session_with_id.cc b/chrome/test/webdriver/commands/session_with_id.cc
index 651a1cc..5889be4 100644
--- a/chrome/test/webdriver/commands/session_with_id.cc
+++ b/chrome/test/webdriver/commands/session_with_id.cc
@@ -11,7 +11,6 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/session_manager.h"
@@ -56,18 +55,12 @@ void SessionWithID::ExecuteGet(Response* const response) {
temp_value->SetString("chrome.automationVersion", chrome::kChromeVersion);
temp_value->SetBoolean("chrome.nativeEvents", session_->use_native_events());
- response->SetStatus(kSuccess);
response->SetValue(temp_value);
}
void SessionWithID::ExecuteDelete(Response* const response) {
// Session manages its own lifetime, so do not call delete.
session_->Terminate();
- response->SetStatus(kSuccess);
-}
-
-bool SessionWithID::RequiresValidTab() {
- return false;
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/session_with_id.h b/chrome/test/webdriver/commands/session_with_id.h
index 4b03cda..e634c65 100644
--- a/chrome/test/webdriver/commands/session_with_id.h
+++ b/chrome/test/webdriver/commands/session_with_id.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -35,12 +35,9 @@ class SessionWithID : public WebDriverCommand {
virtual void ExecuteDelete(Response* const response);
private:
- virtual bool RequiresValidTab();
-
DISALLOW_COPY_AND_ASSIGN(SessionWithID);
};
} // namespace webdriver
#endif // CHROME_TEST_WEBDRIVER_COMMANDS_SESSION_WITH_ID_H_
-
diff --git a/chrome/test/webdriver/commands/set_timeout_commands.cc b/chrome/test/webdriver/commands/set_timeout_commands.cc
index 92f68f5..73d55aa 100644
--- a/chrome/test/webdriver/commands/set_timeout_commands.cc
+++ b/chrome/test/webdriver/commands/set_timeout_commands.cc
@@ -9,8 +9,8 @@
#include "base/stringprintf.h"
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -30,7 +30,7 @@ void SetTimeoutCommand::ExecutePost(Response* const response) {
const char kTimeoutMsKey[] = "ms";
if (!HasParameter(kTimeoutMsKey)) {
- SET_WEBDRIVER_ERROR(response, "Request missing ms parameter", kBadRequest);
+ response->SetError(new Error(kBadRequest, "Request missing ms parameter"));
return;
}
@@ -42,8 +42,8 @@ void SetTimeoutCommand::ExecutePost(Response* const response) {
// we are safe to downcast.
double ms;
if (!GetDoubleParameter(kTimeoutMsKey, &ms)) {
- SET_WEBDRIVER_ERROR(response, "ms parameter is not a number",
- kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "ms parameter is not a number"));
return;
}
ms_to_wait = static_cast<int>(ms);
@@ -51,16 +51,11 @@ void SetTimeoutCommand::ExecutePost(Response* const response) {
// Validate the wait time before setting it to the session.
if (ms_to_wait < 0) {
- SET_WEBDRIVER_ERROR(
- response,
- base::StringPrintf("timeout must be non-negative: %d",
- ms_to_wait),
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Timeout must be non-negative"));
return;
}
SetTimeout(ms_to_wait);
- response->SetStatus(kSuccess);
}
SetAsyncScriptTimeoutCommand::SetAsyncScriptTimeoutCommand(
@@ -86,4 +81,3 @@ void ImplicitWaitCommand::SetTimeout(int timeout_ms) {
}
} // namespace webdriver
-
diff --git a/chrome/test/webdriver/commands/set_timeout_commands_unittest.cc b/chrome/test/webdriver/commands/set_timeout_commands_unittest.cc
index 4df283b..5bc4554 100644
--- a/chrome/test/webdriver/commands/set_timeout_commands_unittest.cc
+++ b/chrome/test/webdriver/commands/set_timeout_commands_unittest.cc
@@ -9,8 +9,8 @@
#include "base/values.h"
#include "chrome/test/webdriver/commands/set_timeout_commands.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace webdriver {
diff --git a/chrome/test/webdriver/commands/source_command.cc b/chrome/test/webdriver/commands/source_command.cc
index 94c5e8e..7030410 100644
--- a/chrome/test/webdriver/commands/source_command.cc
+++ b/chrome/test/webdriver/commands/source_command.cc
@@ -8,8 +8,8 @@
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -30,15 +30,12 @@ bool SourceCommand::DoesGet() {
void SourceCommand::ExecuteGet(Response* const response) {
ListValue args;
Value* result = NULL;
- ErrorCode code = session_->ExecuteScript(kSource, &args, &result);
-
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "ExecuteAndExtractString failed",
- kInternalServerError);
+ Error* error = session_->ExecuteScript(kSource, &args, &result);
+ if (error) {
+ response->SetError(error);
return;
}
response->SetValue(result);
- response->SetStatus(kSuccess);
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/speed_command.cc b/chrome/test/webdriver/commands/speed_command.cc
deleted file mode 100644
index 9755305..0000000
--- a/chrome/test/webdriver/commands/speed_command.cc
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright (c) 2010 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 "chrome/test/webdriver/commands/speed_command.h"
-
-#include <string>
-
-#include "base/utf_string_conversions.h"
-#include "chrome/test/webdriver/commands/response.h"
-
-namespace webdriver {
-
-SpeedCommand::SpeedCommand(const std::vector<std::string>& path_segments,
- const DictionaryValue* const parameters)
- : WebDriverCommand(path_segments, parameters),
- speed_(Session::kMedium) {
-}
-
-SpeedCommand::~SpeedCommand() {}
-
-bool SpeedCommand::Init(Response* const response) {
- std::string speed;
-
- if (!WebDriverCommand::Init(response)) {
- SET_WEBDRIVER_ERROR(response, "Failure on Init for setting speed",
- kInternalServerError);
- return false;
- }
-
- // The speed parameter must be passed in as SLOW, MEDIUM, or FAST.
- // The command must also be in all upper case letters.
- if (!GetStringASCIIParameter("speed", &speed)) {
- SET_WEBDRIVER_ERROR(response, "Request missing speed parameter",
- kBadRequest);
- return false;
- }
-
- if (speed.compare("SLOW") == 0) {
- LOG(INFO) << "Speed set to slow";
- speed_ = Session::kSlow;
- } else if (speed.compare("MEDIUM") == 0) {
- LOG(INFO) << "Speed set to medium";
- speed_ = Session::kMedium;
- } else if (speed.compare("FAST") == 0) {
- LOG(INFO) << "Speed set to fast" << std::endl;
- speed_ = Session::kFast;
- } else {
- // If the speed is invalid throw and error in the POST response.
- LOG(INFO) << "Requested an unknown speed: " << speed;
- speed_ = Session::kUnknown;
- }
-
- return true;
-}
-
-bool SpeedCommand::DoesGet() {
- return true;
-}
-
-bool SpeedCommand::DoesPost() {
- return true;
-}
-
-void SpeedCommand::ExecuteGet(Response* const response) {
- switch (session_->speed()) {
- case Session::kSlow:
- response->SetValue(new StringValue("SLOW"));
- response->SetStatus(kSuccess);
- break;
-
- case Session::kMedium:
- response->SetValue(new StringValue("MEDIUM"));
- response->SetStatus(kSuccess);
- break;
-
- case Session::kFast:
- response->SetValue(new StringValue("FAST"));
- response->SetStatus(kSuccess);
- break;
-
- default:
- // The speed should have never been set to unknown.
- SET_WEBDRIVER_ERROR(response, "Unknown speed set",
- kInternalServerError);
- NOTREACHED();
- break;
- }
-}
-
-void SpeedCommand::ExecutePost(Response* const response) {
- if (speed_ == Session::kUnknown) {
- SET_WEBDRIVER_ERROR(response, "Invalid speed requested",
- kInternalServerError);
- return;
- }
-
- session_->set_speed(speed_);
- response->SetValue(new StringValue("success"));
- response->SetStatus(kSuccess);
-}
-
-bool SpeedCommand::RequiresValidTab() {
- return true;
-}
-
-} // namespace webdriver
-
diff --git a/chrome/test/webdriver/commands/speed_command.h b/chrome/test/webdriver/commands/speed_command.h
deleted file mode 100644
index 9846fa5..0000000
--- a/chrome/test/webdriver/commands/speed_command.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef CHROME_TEST_WEBDRIVER_COMMANDS_SPEED_COMMAND_H_
-#define CHROME_TEST_WEBDRIVER_COMMANDS_SPEED_COMMAND_H_
-
-#include <string>
-#include <vector>
-
-#include "chrome/test/webdriver/session.h"
-#include "chrome/test/webdriver/commands/webdriver_command.h"
-
-namespace webdriver {
-
-class Response;
-
-// Controls how fast chrome should simulate user typing and mouse movements.
-// By default the speed is set to medium however webdriver has not defined
-// what this speed means accross browsers. Currently speed is ignored.
-// See: http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/speed
-class SpeedCommand : public WebDriverCommand {
- public:
- SpeedCommand(const std::vector<std::string>& path_segments,
- const DictionaryValue* const parameters);
- virtual ~SpeedCommand();
-
- virtual bool Init(Response* const response);
-
- virtual bool DoesGet();
- virtual bool DoesPost();
- virtual void ExecuteGet(Response* const response);
- virtual void ExecutePost(Response* const response);
-
- private:
- virtual bool RequiresValidTab();
-
- Session::Speed speed_;
-
- DISALLOW_COPY_AND_ASSIGN(SpeedCommand);
-};
-
-} // namespace webdriver
-
-#endif // CHROME_TEST_WEBDRIVER_COMMANDS_SPEED_COMMAND_H_
-
diff --git a/chrome/test/webdriver/commands/target_locator_commands.cc b/chrome/test/webdriver/commands/target_locator_commands.cc
index b0b7ff5..d738fe0 100644
--- a/chrome/test/webdriver/commands/target_locator_commands.cc
+++ b/chrome/test/webdriver/commands/target_locator_commands.cc
@@ -7,9 +7,9 @@
#include "base/string_number_conversions.h"
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/web_element_id.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -25,7 +25,6 @@ bool WindowHandleCommand::DoesGet() {
}
void WindowHandleCommand::ExecuteGet(Response* const response) {
- response->SetStatus(kSuccess);
response->SetValue(new StringValue(
base::IntToString(session_->current_target().window_id)));
}
@@ -43,15 +42,14 @@ bool WindowHandlesCommand::DoesGet() {
void WindowHandlesCommand::ExecuteGet(Response* const response) {
std::vector<int> window_ids;
- if (!session_->GetWindowIds(&window_ids)) {
- SET_WEBDRIVER_ERROR(
- response, "Could not get window handles", kInternalServerError);
+ Error* error = session_->GetWindowIds(&window_ids);
+ if (error) {
+ response->SetError(error);
return;
}
ListValue* id_list = new ListValue();
for (size_t i = 0; i < window_ids.size(); ++i)
id_list->Append(new StringValue(base::IntToString(window_ids[i])));
- response->SetStatus(kSuccess);
response->SetValue(id_list);
}
@@ -73,26 +71,20 @@ bool WindowCommand::DoesDelete() {
void WindowCommand::ExecutePost(Response* const response) {
std::string name;
if (!GetStringParameter("name", &name)) {
- SET_WEBDRIVER_ERROR(
- response, "Missing or invalid 'name' parameter", kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "Missing or invalid 'name' parameter"));
return;
}
- ErrorCode code = session_->SwitchToWindow(name);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Could not switch window", code);
- return;
- }
- response->SetStatus(kSuccess);
+ Error* error = session_->SwitchToWindow(name);
+ if (error)
+ response->SetError(error);
}
void WindowCommand::ExecuteDelete(Response* const response) {
- if (!session_->CloseWindow()) {
- SET_WEBDRIVER_ERROR(
- response, "Could not close window", kInternalServerError);
- return;
- }
- response->SetStatus(kSuccess);
+ Error* error = session_->CloseWindow();
+ if (error)
+ response->SetError(error);
}
SwitchFrameCommand::SwitchFrameCommand(
@@ -110,34 +102,22 @@ void SwitchFrameCommand::ExecutePost(Response* const response) {
std::string id;
int index = 0;
WebElementId element;
+ Error* error = NULL;
if (GetStringParameter("id", &id)) {
- ErrorCode code = session_->SwitchToFrameWithNameOrId(id);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code);
- return;
- }
+ error = session_->SwitchToFrameWithNameOrId(id);
} else if (GetIntegerParameter("id", &index)) {
- ErrorCode code = session_->SwitchToFrameWithIndex(index);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code);
- return;
- }
+ error = session_->SwitchToFrameWithIndex(index);
} else if (GetWebElementParameter("id", &element)) {
- ErrorCode code = session_->SwitchToFrameWithElement(element);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Could not switch to frame", code);
- return;
- }
+ error = session_->SwitchToFrameWithElement(element);
} else if (IsNullParameter("id") || !HasParameter("id")) {
// Treat null 'id' and no 'id' as the same.
// See http://code.google.com/p/selenium/issues/detail?id=1479.
session_->SwitchToTopFrame();
} else {
- SET_WEBDRIVER_ERROR(
- response, "Invalid 'id' parameter", kBadRequest);
- return;
+ error = new Error(kBadRequest, "Invalid 'id' parameter");
}
- response->SetStatus(kSuccess);
+ if (error)
+ response->SetError(error);
}
bool SwitchFrameCommand::GetWebElementParameter(const std::string& key,
@@ -168,9 +148,12 @@ bool ActiveElementCommand::DoesPost() {
void ActiveElementCommand::ExecutePost(Response* const response) {
ListValue args;
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(
+ Error* error = session_->ExecuteScript(
"return document.activeElement || document.body", &args, &result);
- response->SetStatus(status);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
diff --git a/chrome/test/webdriver/commands/title_command.cc b/chrome/test/webdriver/commands/title_command.cc
index a6cc20a..4898d5f 100644
--- a/chrome/test/webdriver/commands/title_command.cc
+++ b/chrome/test/webdriver/commands/title_command.cc
@@ -7,6 +7,8 @@
#include <string>
#include "chrome/test/webdriver/commands/response.h"
+#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -22,14 +24,12 @@ bool TitleCommand::DoesGet() {
void TitleCommand::ExecuteGet(Response* const response) {
std::string title;
- ErrorCode code = session_->GetTitle(&title);
- if (code == kSuccess)
- response->SetValue(new StringValue(title));
- response->SetStatus(code);
-}
-
-bool TitleCommand::RequiresValidTab() {
- return true;
+ Error* error = session_->GetTitle(&title);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
+ response->SetValue(new StringValue(title));
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/title_command.h b/chrome/test/webdriver/commands/title_command.h
index 3ec5fe81..4a4723e 100644
--- a/chrome/test/webdriver/commands/title_command.h
+++ b/chrome/test/webdriver/commands/title_command.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -26,12 +26,9 @@ class TitleCommand : public WebDriverCommand {
virtual void ExecuteGet(Response* const response);
private:
- virtual bool RequiresValidTab();
-
DISALLOW_COPY_AND_ASSIGN(TitleCommand);
};
} // namespace webdriver
#endif // CHROME_TEST_WEBDRIVER_COMMANDS_TITLE_COMMAND_H_
-
diff --git a/chrome/test/webdriver/commands/url_command.cc b/chrome/test/webdriver/commands/url_command.cc
index 22efa1e..7a495d9 100644
--- a/chrome/test/webdriver/commands/url_command.cc
+++ b/chrome/test/webdriver/commands/url_command.cc
@@ -7,6 +7,8 @@
#include <string>
#include "chrome/test/webdriver/commands/response.h"
+#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
@@ -26,32 +28,29 @@ bool URLCommand::DoesPost() {
void URLCommand::ExecuteGet(Response* const response) {
std::string url;
- ErrorCode code = session_->GetURL(&url);
- if (code == kSuccess)
- response->SetValue(new StringValue(url));
- response->SetStatus(code);
+ Error* error = session_->GetURL(&url);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
+ response->SetValue(new StringValue(url));
}
void URLCommand::ExecutePost(Response* const response) {
std::string url;
if (!GetStringASCIIParameter("url", &url)) {
- SET_WEBDRIVER_ERROR(response, "URL field not found", kInternalServerError);
+ response->SetError(new Error(kBadRequest, "Missing 'url' parameter"));
return;
}
- // TODO(jmikhail): sniff for meta-redirects.
- if (!session_->NavigateToURL(url)) {
- SET_WEBDRIVER_ERROR(response, "NavigateToURL failed",
- kInternalServerError);
+
+ Error* error = session_->NavigateToURL(url);
+ if (error) {
+ response->SetError(error);
return;
}
-
response->SetValue(new StringValue(url));
- response->SetStatus(kSuccess);
}
-bool URLCommand::RequiresValidTab() {
- return true;
-}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/url_command.h b/chrome/test/webdriver/commands/url_command.h
index 0f5c1e8..075a4a8 100644
--- a/chrome/test/webdriver/commands/url_command.h
+++ b/chrome/test/webdriver/commands/url_command.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -29,12 +29,9 @@ class URLCommand : public WebDriverCommand {
virtual void ExecutePost(Response* const response);
private:
- virtual bool RequiresValidTab();
-
DISALLOW_COPY_AND_ASSIGN(URLCommand);
};
} // namespace webdriver
#endif // CHROME_TEST_WEBDRIVER_COMMANDS_URL_COMMAND_H_
-
diff --git a/chrome/test/webdriver/commands/webdriver_command.cc b/chrome/test/webdriver/commands/webdriver_command.cc
index 1a30191..133b6a0 100644
--- a/chrome/test/webdriver/commands/webdriver_command.cc
+++ b/chrome/test/webdriver/commands/webdriver_command.cc
@@ -7,33 +7,51 @@
#include <string>
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
+#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/session_manager.h"
-#include "chrome/test/webdriver/error_codes.h"
+#include "chrome/test/webdriver/webdriver_error.h"
namespace webdriver {
+WebDriverCommand::WebDriverCommand(
+ const std::vector<std::string>& path_segments,
+ const DictionaryValue* const parameters)
+ : Command(path_segments, parameters), session_(NULL) {
+}
+
+WebDriverCommand::~WebDriverCommand() {}
+
bool WebDriverCommand::Init(Response* const response) {
// There should be at least 3 path segments to match "/session/$id".
std::string session_id = GetPathVariable(2);
if (session_id.length() == 0) {
- SET_WEBDRIVER_ERROR(response, "No session ID specified", kBadRequest);
+ response->SetError(
+ new Error(kBadRequest, "No session ID specified"));
return false;
}
VLOG(1) << "Fetching session: " << session_id;
session_ = SessionManager::GetInstance()->GetSession(session_id);
if (session_ == NULL) {
- SET_WEBDRIVER_ERROR(response, "Session not found: " + session_id,
- kSessionNotFound);
+ response->SetError(
+ new Error(kSessionNotFound, "Session not found: " + session_id));
return false;
}
- if (!session_->WaitForAllTabsToStopLoading()) {
- LOG(WARNING) << "Failed to wait for all tabs to stop loading";
+
+ // TODO(kkania): Do not use the standard automation timeout for this,
+ // and throw an error if it does not succeed.
+ scoped_ptr<Error> error(session_->WaitForAllTabsToStopLoading());
+ if (error.get()) {
+ LOG(WARNING) << error->ToString();
+ }
+ error.reset(session_->SwitchToTopFrameIfCurrentFrameInvalid());
+ if (error.get()) {
+ LOG(WARNING) << error->ToString();
}
- session_->SwitchToTopFrameIfCurrentFrameInvalid();
response->SetField("sessionId", Value::CreateStringValue(session_id));
return true;
diff --git a/chrome/test/webdriver/commands/webdriver_command.h b/chrome/test/webdriver/commands/webdriver_command.h
index 633a02d..c4e759d 100644
--- a/chrome/test/webdriver/commands/webdriver_command.h
+++ b/chrome/test/webdriver/commands/webdriver_command.h
@@ -9,13 +9,13 @@
#include <vector>
#include "chrome/test/webdriver/commands/command.h"
-#include "chrome/test/webdriver/session.h"
class DictionaryValue;
namespace webdriver {
class Response;
+class Session;
// All URLs that are found in the document:
// http://code.google.com/p/selenium/wiki/JsonWireProtocol
@@ -25,10 +25,9 @@ class Response;
// directly.
class WebDriverCommand : public Command {
public:
- WebDriverCommand(const std::vector<std::string> path_segments,
- const DictionaryValue* const parameters)
- : Command(path_segments, parameters), session_(NULL) {}
- virtual ~WebDriverCommand() {}
+ WebDriverCommand(const std::vector<std::string>& path_segments,
+ const DictionaryValue* const parameters);
+ virtual ~WebDriverCommand();
// Initializes this webdriver command by fetching the command session.
virtual bool Init(Response* const response);
diff --git a/chrome/test/webdriver/commands/webelement_commands.cc b/chrome/test/webdriver/commands/webelement_commands.cc
index de68aef..dae3e4eb 100644
--- a/chrome/test/webdriver/commands/webelement_commands.cc
+++ b/chrome/test/webdriver/commands/webelement_commands.cc
@@ -9,8 +9,8 @@
#include "base/third_party/icu/icu_utf.h"
#include "base/values.h"
#include "chrome/test/webdriver/commands/response.h"
-#include "chrome/test/webdriver/error_codes.h"
#include "chrome/test/webdriver/session.h"
+#include "chrome/test/webdriver/webdriver_error.h"
#include "third_party/webdriver/atoms.h"
#include "ui/gfx/point.h"
#include "ui/gfx/size.h"
@@ -34,8 +34,7 @@ bool WebElementCommand::Init(Response* const response) {
// There should be at least 5 segments to match
// "/session/$session/element/$id"
if (path_segments_.size() < 5) {
- SET_WEBDRIVER_ERROR(response, "Path segments is less than 5",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Path segments is less than 5"));
return false;
}
@@ -62,21 +61,23 @@ void ElementAttributeCommand::ExecuteGet(Response* const response) {
// There should be at least 7 segments to match
// "/session/$session/element/$id/attribute/$name"
if (path_segments_.size() < 7) {
- SET_WEBDRIVER_ERROR(response, "Path segments is less than 7",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Path segments is less than 7"));
return;
}
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::GET_ATTRIBUTE);
- scoped_ptr<ListValue> args(new ListValue);
- args->Append(element.ToValue());
- args->Append(Value::CreateStringValue(path_segments_.at(6)));
+ ListValue args;
+ args.Append(element.ToValue());
+ args.Append(Value::CreateStringValue(path_segments_.at(6)));
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args.get(), &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -94,15 +95,18 @@ bool ElementClearCommand::DoesPost() {
}
void ElementClearCommand::ExecutePost(Response* const response) {
- scoped_ptr<ListValue> args(new ListValue);
- args->Append(element.ToValue());
+ ListValue args;
+ args.Append(element.ToValue());
std::string script = base::StringPrintf(
"(%s).apply(null, arguments);", atoms::CLEAR);
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args.get(), &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -123,21 +127,23 @@ void ElementCssCommand::ExecuteGet(Response* const response) {
// There should be at least 7 segments to match
// "/session/$session/element/$id/css/$propertyName"
if (path_segments_.size() < 7) {
- SET_WEBDRIVER_ERROR(response, "Path segments is less than 7",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Path segments is less than 7"));
return;
}
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::GET_EFFECTIVE_STYLE);
- scoped_ptr<ListValue> args(new ListValue);
- args->Append(element.ToValue());
- args->Append(Value::CreateStringValue(path_segments_.at(6)));
+ ListValue args;
+ args.Append(element.ToValue());
+ args.Append(Value::CreateStringValue(path_segments_.at(6)));
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args.get(), &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -156,11 +162,13 @@ bool ElementDisplayedCommand::DoesGet() {
void ElementDisplayedCommand::ExecuteGet(Response* const response) {
bool is_displayed;
- ErrorCode status = session_->IsElementDisplayed(
+ Error* error = session_->IsElementDisplayed(
session_->current_target(), element, &is_displayed);
- if (status == kSuccess)
- response->SetValue(Value::CreateBooleanValue(is_displayed));
- response->SetStatus(status);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
+ response->SetValue(Value::CreateBooleanValue(is_displayed));
}
///////////////////// ElementEnabledCommand ////////////////////
@@ -177,15 +185,18 @@ bool ElementEnabledCommand::DoesGet() {
}
void ElementEnabledCommand::ExecuteGet(Response* const response) {
- scoped_ptr<ListValue> args(new ListValue);
- args->Append(element.ToValue());
+ ListValue args;
+ args.Append(element.ToValue());
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::IS_ENABLED);
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args.get(), &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -206,22 +217,24 @@ void ElementEqualsCommand::ExecuteGet(Response* const response) {
// There should be at least 7 segments to match
// "/session/$session/element/$id/equals/$other"
if (path_segments_.size() < 7) {
- SET_WEBDRIVER_ERROR(response, "Path segments is less than 7",
- kBadRequest);
+ response->SetError(new Error(kBadRequest, "Path segments is less than 7"));
return;
}
std::string script = "return arguments[0] == arguments[1];";
- scoped_ptr<ListValue> args(new ListValue);
- args->Append(element.ToValue());
+ ListValue args;
+ args.Append(element.ToValue());
WebElementId other_element(path_segments_.at(6));
- args->Append(other_element.ToValue());
+ args.Append(other_element.ToValue());
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args.get(), &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -246,8 +259,11 @@ void ElementLocationCommand::ExecuteGet(Response* const response) {
args.Append(element.ToValue());
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, &args, &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -266,14 +282,15 @@ bool ElementLocationInViewCommand::DoesGet() {
void ElementLocationInViewCommand::ExecuteGet(Response* const response) {
gfx::Point location;
- ErrorCode code = session_->GetElementLocationInView(element, &location);
- response->SetStatus(code);
- if (code == kSuccess) {
- DictionaryValue* coord_dict = new DictionaryValue();
- coord_dict->SetInteger("x", location.x());
- coord_dict->SetInteger("y", location.y());
- response->SetValue(coord_dict);
+ Error* error = session_->GetElementLocationInView(element, &location);
+ if (error) {
+ response->SetError(error);
+ return;
}
+ DictionaryValue* coord_dict = new DictionaryValue();
+ coord_dict->SetInteger("x", location.x());
+ coord_dict->SetInteger("y", location.y());
+ response->SetValue(coord_dict);
}
///////////////////// ElementNameCommand ////////////////////
@@ -290,14 +307,17 @@ bool ElementNameCommand::DoesGet() {
}
void ElementNameCommand::ExecuteGet(Response* const response) {
- scoped_ptr<ListValue> args(new ListValue);
- args->Append(element.ToValue());
+ ListValue args;
+ args.Append(element.ToValue());
std::string script = "return arguments[0].tagName.toLocaleLowerCase();";
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args.get(), &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -319,29 +339,35 @@ bool ElementSelectedCommand::DoesPost() {
}
void ElementSelectedCommand::ExecuteGet(Response* const response) {
- scoped_ptr<ListValue> args(new ListValue);
- args->Append(element.ToValue());
+ ListValue args;
+ args.Append(element.ToValue());
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::IS_SELECTED);
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args.get(), &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
void ElementSelectedCommand::ExecutePost(Response* const response) {
- scoped_ptr<ListValue> args(new ListValue);
- args->Append(element.ToValue());
- args->Append(Value::CreateBooleanValue(true));
+ ListValue args;
+ args.Append(element.ToValue());
+ args.Append(Value::CreateBooleanValue(true));
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::SET_SELECTED);
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, args.get(), &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -360,15 +386,16 @@ bool ElementSizeCommand::DoesGet() {
void ElementSizeCommand::ExecuteGet(Response* const response) {
gfx::Size size;
- ErrorCode status = session_->GetElementSize(
+ Error* error = session_->GetElementSize(
session_->current_target(), element, &size);
- if (status == kSuccess) {
- DictionaryValue* dict = new DictionaryValue();
- dict->SetInteger("width", size.width());
- dict->SetInteger("height", size.height());
- response->SetValue(dict);
+ if (error) {
+ response->SetError(error);
+ return;
}
- response->SetStatus(status);
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("width", size.width());
+ dict->SetInteger("height", size.height());
+ response->SetValue(dict);
}
///////////////////// ElementSubmitCommand ////////////////////
@@ -394,8 +421,11 @@ void ElementSubmitCommand::ExecutePost(Response* const response) {
args.Append(element.ToValue());
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, &args, &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -420,8 +450,11 @@ void ElementToggleCommand::ExecutePost(Response* const response) {
args.Append(element.ToValue());
Value* result = NULL;
- ErrorCode status = session_->ExecuteScript(script, &args, &result);
- response->SetStatus(status);
+ Error* error = session_->ExecuteScript(script, &args, &result);
+ if (error) {
+ response->SetError(error);
+ return;
+ }
response->SetValue(result);
}
@@ -447,30 +480,28 @@ void ElementValueCommand::ExecuteGet(Response* const response) {
ListValue args;
std::string script = "return arguments[0]['value']";
args.Append(element.ToValue());
- ErrorCode code =
+
+ Error* error =
session_->ExecuteScript(script, &args, &unscoped_result);
scoped_ptr<Value> result(unscoped_result);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to execute script", code);
+ if (error) {
+ response->SetError(error);
return;
}
if (!result->IsType(Value::TYPE_STRING) &&
!result->IsType(Value::TYPE_NULL)) {
- SET_WEBDRIVER_ERROR(response,
- "Result is not string or null type",
- kInternalServerError);
+ response->SetError(new Error(
+ kUnknownError, "Result is not string or null type"));
return;
}
- response->SetStatus(kSuccess);
response->SetValue(result.release());
}
void ElementValueCommand::ExecutePost(Response* const response) {
ListValue* key_list;
if (!GetListParameter("value", &key_list)) {
- SET_WEBDRIVER_ERROR(response,
- "Missing or invalid 'value' parameter",
- kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "Missing or invalid 'value' parameter"));
return;
}
// Flatten the given array of strings into one.
@@ -480,24 +511,17 @@ void ElementValueCommand::ExecutePost(Response* const response) {
key_list->GetString(i, &keys_list_part);
for (size_t j = 0; j < keys_list_part.size(); ++j) {
if (CBU16_IS_SURROGATE(keys_list_part[j])) {
- SET_WEBDRIVER_ERROR(
- response,
- "ChromeDriver only supports characters in the BMP",
- kBadRequest);
+ response->SetError(new Error(
+ kBadRequest, "ChromeDriver only supports characters in the BMP"));
return;
}
}
keys.append(keys_list_part);
}
- ErrorCode code = session_->SendKeys(element, keys);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response,
- "Internal SendKeys error",
- code);
- return;
- }
- response->SetStatus(kSuccess);
+ Error* error = session_->SendKeys(element, keys);
+ if (error)
+ response->SetError(error);
}
///////////////////// ElementTextCommand ////////////////////
@@ -521,20 +545,17 @@ void ElementTextCommand::ExecuteGet(Response* const response) {
std::string script = base::StringPrintf(
"return (%s).apply(null, arguments);", atoms::GET_TEXT);
- ErrorCode code = session_->ExecuteScript(script, &args,
- &unscoped_result);
+ Error* error = session_->ExecuteScript(script, &args,
+ &unscoped_result);
scoped_ptr<Value> result(unscoped_result);
- if (code != kSuccess) {
- SET_WEBDRIVER_ERROR(response, "Failed to execute script", code);
+ if (error) {
+ response->SetError(error);
return;
}
if (!result->IsType(Value::TYPE_STRING)) {
- SET_WEBDRIVER_ERROR(response,
- "Result is not string type",
- kInternalServerError);
+ response->SetError(new Error(kUnknownError, "Result is not string type"));
return;
}
- response->SetStatus(kSuccess);
response->SetValue(result.release());
}