Index: chrome/test/webdriver/commands/execute_command.cc |
diff --git a/chrome/test/webdriver/commands/execute_command.cc b/chrome/test/webdriver/commands/execute_command.cc |
index dc68e415197387543ed34cc4173e53fd00e6f299..b94741702a9060a9515e0e61e6459042d08fa3a8 100644 |
--- a/chrome/test/webdriver/commands/execute_command.cc |
+++ b/chrome/test/webdriver/commands/execute_command.cc |
@@ -2,11 +2,14 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include <string> |
+#include "chrome/test/webdriver/commands/execute_command.h" |
-#include "base/json/json_reader.h" |
+#include <string> |
-#include "chrome/test/webdriver/commands/execute_command.h" |
+#include "base/values.h" |
+#include "chrome/test/webdriver/error_codes.h" |
+#include "chrome/test/webdriver/session.h" |
+#include "chrome/test/webdriver/commands/response.h" |
namespace webdriver { |
@@ -19,69 +22,29 @@ ExecuteCommand::ExecuteCommand(const std::vector<std::string>& path_segments, |
ExecuteCommand::~ExecuteCommand() {} |
- |
-bool ExecuteCommand::Init(Response* const response) { |
- if (!WebDriverCommand::Init(response)) { |
- SET_WEBDRIVER_ERROR(response, "Failure on Init for execute command", |
- kInternalServerError); |
- return false; |
- } |
- |
- if (!GetStringParameter(kScript, &script_)) { |
- SET_WEBDRIVER_ERROR(response, "No script to execute specified", |
- kBadRequest); |
- return false; |
- } |
- |
- has_args_= GetStringASCIIParameter(kArgs, &args_); |
- return true; |
-} |
- |
bool ExecuteCommand::DoesPost() { |
return true; |
} |
void ExecuteCommand::ExecutePost(Response* const response) { |
- int error_code = 0; |
- std::string error_msg; |
- Value* params = NULL; |
- Value* result = NULL; |
- |
- if (has_args_) { |
- params = base::JSONReader::ReadAndReturnError(args_, true, |
- &error_code, &error_msg); |
- if (error_code != 0) { |
- LOG(INFO) << "Could not parse the JSON arguments passed in " |
- << "got error code: " << error_code << ", " << error_msg; |
- SET_WEBDRIVER_ERROR(response, "Arguments are not valid json objects", |
- kBadRequest); |
- return; |
- } |
- } else { |
- LOG(INFO) << "No args for this script"; |
- // If there are no args required just use an empty list. |
- params = new ListValue(); |
- } |
- |
- if (params->GetType() != Value::TYPE_LIST) { |
- LOG(INFO) << "Data passed in to script must be a json list"; |
- SET_WEBDRIVER_ERROR(response, "Arguments are not in list format", |
+ std::string script; |
+ if (!GetStringParameter(kScript, &script)) { |
+ SET_WEBDRIVER_ERROR(response, "No script to execute specified", |
kBadRequest); |
return; |
} |
- ListValue* script_args = static_cast<ListValue*>(params); |
- ErrorCode error = session_->ExecuteScript(script_, |
- script_args, &result); |
- |
- if (error != kSuccess) { |
- SET_WEBDRIVER_ERROR(response, "Failed to execute script", |
- kInternalServerError); |
+ ListValue* args; |
+ if (!GetListParameter(kArgs, &args)) { |
+ SET_WEBDRIVER_ERROR(response, "No script arguments specified", |
+ kBadRequest); |
return; |
} |
+ Value* result = NULL; |
+ ErrorCode status = session_->ExecuteScript(script, args, &result); |
+ response->set_status(status); |
response->set_value(result); |
- response->set_status(kSuccess); |
} |
bool ExecuteCommand::RequiresValidTab() { |