summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-19 23:32:55 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-19 23:32:55 +0000
commitb7448dc7eac020055d9bc9aee12d1b9ed7dbd466 (patch)
treec2689890eff1a27bcb9c50167f015daa21b55f08
parent86469503a695e2ede48244c846053dd9ae91e5fa (diff)
downloadchromium_src-b7448dc7eac020055d9bc9aee12d1b9ed7dbd466.zip
chromium_src-b7448dc7eac020055d9bc9aee12d1b9ed7dbd466.tar.gz
chromium_src-b7448dc7eac020055d9bc9aee12d1b9ed7dbd466.tar.bz2
Cleaning up response.h and moving all of the logic into the .cc file.
Patch by jleyba@chromium.org. Original review at http://codereview.chromium.org/6543015 BUG=none TEST=none Review URL: http://codereview.chromium.org/6469071 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75506 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/webdriver/commands/command.cc11
-rw-r--r--chrome/test/webdriver/commands/command.h5
-rw-r--r--chrome/test/webdriver/commands/cookie_commands.cc16
-rw-r--r--chrome/test/webdriver/commands/create_session.cc5
-rw-r--r--chrome/test/webdriver/commands/create_session.h2
-rw-r--r--chrome/test/webdriver/commands/execute_command.cc4
-rw-r--r--chrome/test/webdriver/commands/execute_command.h2
-rw-r--r--chrome/test/webdriver/commands/find_element_commands.cc5
-rw-r--r--chrome/test/webdriver/commands/find_element_commands.h2
-rw-r--r--chrome/test/webdriver/commands/implicit_wait_command.cc8
-rw-r--r--chrome/test/webdriver/commands/implicit_wait_command.h2
-rw-r--r--chrome/test/webdriver/commands/navigate_commands.cc8
-rw-r--r--chrome/test/webdriver/commands/navigate_commands.h2
-rw-r--r--chrome/test/webdriver/commands/response.h88
-rw-r--r--chrome/test/webdriver/commands/session_with_id.cc7
-rw-r--r--chrome/test/webdriver/commands/session_with_id.h2
-rw-r--r--chrome/test/webdriver/commands/source_command.cc8
-rw-r--r--chrome/test/webdriver/commands/source_command.h2
-rw-r--r--chrome/test/webdriver/commands/speed_command.cc20
-rw-r--r--chrome/test/webdriver/commands/speed_command.h2
-rw-r--r--chrome/test/webdriver/commands/target_locator_commands.cc14
-rw-r--r--chrome/test/webdriver/commands/title_command.cc8
-rw-r--r--chrome/test/webdriver/commands/title_command.h2
-rw-r--r--chrome/test/webdriver/commands/url_command.cc12
-rw-r--r--chrome/test/webdriver/commands/url_command.h2
-rw-r--r--chrome/test/webdriver/commands/webdriver_command.cc9
-rw-r--r--chrome/test/webdriver/commands/webelement_commands.cc10
-rw-r--r--chrome/test/webdriver/dispatch.cc19
-rw-r--r--chrome/test/webdriver/dispatch_unittest.cc24
30 files changed, 141 insertions, 161 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 72fcf03..b5d0e38 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -762,6 +762,7 @@
'test/webdriver/commands/execute_command.cc',
'test/webdriver/commands/navigate_commands.h',
'test/webdriver/commands/navigate_commands.cc',
+ 'test/webdriver/commands/response.cc',
'test/webdriver/commands/response.h',
'test/webdriver/commands/session_with_id.h',
'test/webdriver/commands/session_with_id.cc',
diff --git a/chrome/test/webdriver/commands/command.cc b/chrome/test/webdriver/commands/command.cc
index cb9e670..b333e1f 100644
--- a/chrome/test/webdriver/commands/command.cc
+++ b/chrome/test/webdriver/commands/command.cc
@@ -6,17 +6,6 @@
namespace webdriver {
-// Error message taken from:
-// http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes
-const char* const Response::kStatusKey = "status";
-const char* const Response::kValueKey = "value";
-const char* const Response::kMessageKey = "message";
-const char* const Response::kScreenKey = "screen";
-const char* const Response::kClassKey = "class";
-const char* const Response::kStackTrace = "stackTrace";
-const char* const Response::kFileName = "fileName";
-const char* const Response::kLineNumber = "lineNumber";
-
Command::Command(const std::vector<std::string>& path_segments,
const DictionaryValue* const parameters)
: path_segments_(path_segments),
diff --git a/chrome/test/webdriver/commands/command.h b/chrome/test/webdriver/commands/command.h
index 9d3cd4e..7e7e764 100644
--- a/chrome/test/webdriver/commands/command.h
+++ b/chrome/test/webdriver/commands/command.h
@@ -11,13 +11,12 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "base/values.h"
-#include "base/json/json_writer.h"
#include "base/mac/scoped_nsautorelease_pool.h"
-#include "chrome/test/webdriver/error_codes.h"
-#include "chrome/test/webdriver/commands/response.h"
namespace webdriver {
+class Response;
+
// Base class for a command mapped to a URL in the WebDriver REST API. Each
// URL may respond to commands sent with a DELETE, GET/HEAD, or POST HTTP
// request. For more information on the WebDriver REST API, see
diff --git a/chrome/test/webdriver/commands/cookie_commands.cc b/chrome/test/webdriver/commands/cookie_commands.cc
index 04b9637..38d4eca 100644
--- a/chrome/test/webdriver/commands/cookie_commands.cc
+++ b/chrome/test/webdriver/commands/cookie_commands.cc
@@ -76,8 +76,8 @@ void CookieCommand::ExecuteGet(Response* const response) {
}
}
- response->set_status(kSuccess);
- response->set_value(cookie_list.release());
+ response->SetStatus(kSuccess);
+ response->SetValue(cookie_list.release());
}
void CookieCommand::ExecutePost(Response* const response) {
@@ -106,8 +106,8 @@ void CookieCommand::ExecutePost(Response* const response) {
return;
}
- response->set_status(kSuccess);
- response->set_value(new StringValue(cookie.ToString()));
+ response->SetStatus(kSuccess);
+ response->SetValue(new StringValue(cookie.ToString()));
}
void CookieCommand::ExecuteDelete(Response* const response) {
@@ -140,7 +140,7 @@ void CookieCommand::ExecuteDelete(Response* const response) {
}
}
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
NamedCookieCommand::NamedCookieCommand(
@@ -190,8 +190,8 @@ void NamedCookieCommand::ExecuteGet(Response* const response) {
return;
}
- response->set_status(kSuccess);
- response->set_value(new StringValue(cookie));
+ response->SetStatus(kSuccess);
+ response->SetValue(new StringValue(cookie));
}
void NamedCookieCommand::ExecuteDelete(Response* const response) {
@@ -201,7 +201,7 @@ void NamedCookieCommand::ExecuteDelete(Response* const response) {
return;
}
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/create_session.cc b/chrome/test/webdriver/commands/create_session.cc
index 8634444..0b16efa 100644
--- a/chrome/test/webdriver/commands/create_session.cc
+++ b/chrome/test/webdriver/commands/create_session.cc
@@ -10,6 +10,7 @@
#include "base/values.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/session.h"
#include "chrome/test/webdriver/session_manager.h"
@@ -38,8 +39,8 @@ void CreateSession::ExecutePost(Response* const response) {
std::ostringstream stream;
stream << "http://" << session_manager->GetAddress() << "/session/"
<< session->id();
- response->set_status(kSeeOther);
- response->set_value(Value::CreateStringValue(stream.str()));
+ response->SetStatus(kSeeOther);
+ response->SetValue(Value::CreateStringValue(stream.str()));
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/create_session.h b/chrome/test/webdriver/commands/create_session.h
index 5e8a2c0..d401a7f 100644
--- a/chrome/test/webdriver/commands/create_session.h
+++ b/chrome/test/webdriver/commands/create_session.h
@@ -13,6 +13,8 @@
namespace webdriver {
+class Response;
+
// Create a new session which is a new instance of the chrome browser with no
// page loaded. A new session ID is passed back to the user which is used for
// all future commands that are sent to control this new instance. The
diff --git a/chrome/test/webdriver/commands/execute_command.cc b/chrome/test/webdriver/commands/execute_command.cc
index b947417..e22264b 100644
--- a/chrome/test/webdriver/commands/execute_command.cc
+++ b/chrome/test/webdriver/commands/execute_command.cc
@@ -43,8 +43,8 @@ void ExecuteCommand::ExecutePost(Response* const response) {
Value* result = NULL;
ErrorCode status = session_->ExecuteScript(script, args, &result);
- response->set_status(status);
- response->set_value(result);
+ response->SetStatus(status);
+ response->SetValue(result);
}
bool ExecuteCommand::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/execute_command.h b/chrome/test/webdriver/commands/execute_command.h
index 5981919..a9f3fa2 100644
--- a/chrome/test/webdriver/commands/execute_command.h
+++ b/chrome/test/webdriver/commands/execute_command.h
@@ -12,6 +12,8 @@
namespace webdriver {
+class Response;
+
// Inject a snippet of javascript into the page and return its result.
// WebElements that should be passed to the script as an argument should be
// specified in the arguments array as WebElement JSON arguments. Likewise,
diff --git a/chrome/test/webdriver/commands/find_element_commands.cc b/chrome/test/webdriver/commands/find_element_commands.cc
index 36a82ff..6ee01e6 100644
--- a/chrome/test/webdriver/commands/find_element_commands.cc
+++ b/chrome/test/webdriver/commands/find_element_commands.cc
@@ -14,6 +14,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "third_party/webdriver/atoms.h"
+#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/error_codes.h"
namespace webdriver {
@@ -120,8 +121,8 @@ void FindElementCommand::ExecutePost(Response* const response) {
base::PlatformThread::Sleep(50); // Prevent a busy loop that eats the cpu.
}
- response->set_value(result);
- response->set_status(error);
+ response->SetValue(result);
+ response->SetStatus(error);
}
bool FindElementCommand::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/find_element_commands.h b/chrome/test/webdriver/commands/find_element_commands.h
index b9a6250..0488d49 100644
--- a/chrome/test/webdriver/commands/find_element_commands.h
+++ b/chrome/test/webdriver/commands/find_element_commands.h
@@ -13,6 +13,8 @@
namespace webdriver {
+class Response;
+
// Base class for searching a page, this class can find either a single
// webelement or return multiple matches.
class FindElementCommand : public WebDriverCommand {
diff --git a/chrome/test/webdriver/commands/implicit_wait_command.cc b/chrome/test/webdriver/commands/implicit_wait_command.cc
index e7eb725..c115936 100644
--- a/chrome/test/webdriver/commands/implicit_wait_command.cc
+++ b/chrome/test/webdriver/commands/implicit_wait_command.cc
@@ -2,10 +2,12 @@
// 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/implicit_wait_command.h"
+
#include <string>
#include "base/utf_string_conversions.h"
-#include "chrome/test/webdriver/commands/implicit_wait_command.h"
+#include "chrome/test/webdriver/commands/response.h"
namespace webdriver {
@@ -49,8 +51,8 @@ void ImplicitWaitCommand::ExecutePost(Response* const response) {
session_->set_implicit_wait(ms_to_wait_);
LOG(INFO) << "Implicit wait set to: " << ms_to_wait_ << " ms";
- response->set_value(new StringValue("success"));
- response->set_status(kSuccess);
+ response->SetValue(new StringValue("success"));
+ response->SetStatus(kSuccess);
}
bool ImplicitWaitCommand::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/implicit_wait_command.h b/chrome/test/webdriver/commands/implicit_wait_command.h
index f0abf5b..f4e6d3a 100644
--- a/chrome/test/webdriver/commands/implicit_wait_command.h
+++ b/chrome/test/webdriver/commands/implicit_wait_command.h
@@ -12,6 +12,8 @@
namespace webdriver {
+class Response;
+
// Set the amount of time the driver should wait when searching for elements.
// If this command is never sent, the driver will default to an implicit wait
// of 0 ms. Until the webelement commands are checked in we do no use this
diff --git a/chrome/test/webdriver/commands/navigate_commands.cc b/chrome/test/webdriver/commands/navigate_commands.cc
index 75f9a1a..f65c695 100644
--- a/chrome/test/webdriver/commands/navigate_commands.cc
+++ b/chrome/test/webdriver/commands/navigate_commands.cc
@@ -4,6 +4,8 @@
#include "chrome/test/webdriver/commands/navigate_commands.h"
+#include "chrome/test/webdriver/commands/response.h"
+
namespace webdriver {
ForwardCommand::ForwardCommand(const std::vector<std::string>& path_segments,
@@ -23,7 +25,7 @@ void ForwardCommand::ExecutePost(Response* const response) {
}
session_->set_current_frame_xpath("");
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
bool ForwardCommand::RequiresValidTab() {
@@ -47,7 +49,7 @@ void BackCommand::ExecutePost(Response* const response) {
}
session_->set_current_frame_xpath("");
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
bool BackCommand::RequiresValidTab() {
@@ -71,7 +73,7 @@ void RefreshCommand::ExecutePost(Response* const response) {
}
session_->set_current_frame_xpath("");
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
bool RefreshCommand::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/navigate_commands.h b/chrome/test/webdriver/commands/navigate_commands.h
index 754e868..c4960f9 100644
--- a/chrome/test/webdriver/commands/navigate_commands.h
+++ b/chrome/test/webdriver/commands/navigate_commands.h
@@ -12,6 +12,8 @@
namespace webdriver {
+class Response;
+
// Navigate forward in the browser history, if possible. See:
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/forward
class ForwardCommand : public WebDriverCommand {
diff --git a/chrome/test/webdriver/commands/response.h b/chrome/test/webdriver/commands/response.h
index 3b39302..b77404d 100644
--- a/chrome/test/webdriver/commands/response.h
+++ b/chrome/test/webdriver/commands/response.h
@@ -8,9 +8,6 @@
#include <sstream>
#include <string>
-#include "base/basictypes.h"
-#include "base/json/json_writer.h"
-#include "base/logging.h"
#include "base/values.h"
#include "chrome/test/webdriver/error_codes.h"
@@ -18,11 +15,9 @@ 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) { \
- LOG(ERROR) << msg; \
- response->set_error(msg, __FILE__, __LINE__); \
- response->set_status(err); \
-}
+#define SET_WEBDRIVER_ERROR(response, msg, err) \
+ response->SetError(err, msg, __FILE__, __LINE__); \
+ 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,
@@ -30,76 +25,37 @@ namespace webdriver {
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#Messages
class Response {
public:
- inline Response() : status_(kSuccess) {
- set_value(Value::CreateNullValue());
- }
-
- inline ErrorCode status() const { return status_; }
- inline void set_status(const ErrorCode status) {
- status_ = status;
- data_.SetInteger(kStatusKey, status_);
- }
-
- // Ownership of the returned pointer is kept by the class and held in
- // the Dictiionary Value data_.
- inline const Value* value() const {
- Value* out = NULL;
- LOG_IF(WARNING, !data_.Get(kValueKey, &out))
- << "Accessing unset response value."; // Should never happen.
- return out;
- }
+ // Creates a new |Response| with a default status of |kSuccess| and a
+ // |NullValue|.
+ Response();
+ ~Response();
- // Sets the |value| of this response, assuming ownership of the object in the
- // process.
- inline void set_value(Value* value) {
- data_.Set(kValueKey, value);
- }
+ ErrorCode GetStatus() const;
+ void SetStatus(ErrorCode status);
- // Sets the |value| of this response, assuming ownership of the object in the
- // process. This function is mostly used to report error values.
- inline void set_error(const char msg[], const char file[], const int line) {
- DictionaryValue* error = new DictionaryValue();
- DictionaryValue* stack = new DictionaryValue();
+ // Ownership of the returned pointer is kept by this object.
+ const Value* GetValue() const;
- error->SetString(std::string(kMessageKey), msg);
- stack->SetString(std::string(kFileName), std::string(file));
- stack->SetInteger(std::string(kLineNumber), line);
+ // Sets the |value| of this response, assuming ownership of the object in the
+ // process.
+ void SetValue(Value* value);
- error->Set(std::string(kStackTrace), stack);
- data_.Set(kValueKey, error);
- }
+ // 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);
// 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
// previously set value for the |key| will be deleted.
- // This object assumes ownership of |in_value|.
- inline void SetField(const std::string& key, Value* value) {
- data_.Set(key, value);
- }
+ // This object assumes ownership of |value|.
+ void SetField(const std::string& key, Value* value);
// Returns this response as a JSON string.
- std::string ToJSON() const {
- std::string json;
- base::JSONWriter::Write(static_cast<const Value*>(&data_), false, &json);
- return json;
- }
+ std::string ToJSON() const;
private:
- // The hard coded values for the keys below are set in the command.cc file.
- static const char* const kStatusKey;
- static const char* const kValueKey;
-
- // Optional values used for errors.
- static const char* const kMessageKey;
- static const char* const kScreenKey;
- static const char* const kClassKey;
- static const char* const kStackTrace;
- static const char* const kFileName;
- static const char* const kLineNumber;
-
- // The response status code. Stored outside of |data_| since it is
- // likely to be queried often.
- ErrorCode status_;
DictionaryValue data_;
DISALLOW_COPY_AND_ASSIGN(Response);
diff --git a/chrome/test/webdriver/commands/session_with_id.cc b/chrome/test/webdriver/commands/session_with_id.cc
index ef7c1da..befde4b 100644
--- a/chrome/test/webdriver/commands/session_with_id.cc
+++ b/chrome/test/webdriver/commands/session_with_id.cc
@@ -10,6 +10,7 @@
#include "base/values.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/session_manager.h"
namespace webdriver {
@@ -50,14 +51,14 @@ void SessionWithID::ExecuteGet(Response* const response) {
temp_value->SetBoolean(std::string("javascriptEnabled"), true);
- response->set_status(kSuccess);
- response->set_value(temp_value);
+ response->SetStatus(kSuccess);
+ response->SetValue(temp_value);
}
void SessionWithID::ExecuteDelete(Response* const response) {
// Session manages its own liftime, so do not call delete.
session_->Terminate();
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
bool SessionWithID::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/session_with_id.h b/chrome/test/webdriver/commands/session_with_id.h
index 8084716..4b03cda 100644
--- a/chrome/test/webdriver/commands/session_with_id.h
+++ b/chrome/test/webdriver/commands/session_with_id.h
@@ -13,6 +13,8 @@
namespace webdriver {
+class Response;
+
// Retrieve the capabilities of the specified session. If the HTTP Delete
// method is used then all chrome instances linked to the session ID are
// closed. The session's capabilities will be returned in a JSON object
diff --git a/chrome/test/webdriver/commands/source_command.cc b/chrome/test/webdriver/commands/source_command.cc
index 65ce877..bd68b2f 100644
--- a/chrome/test/webdriver/commands/source_command.cc
+++ b/chrome/test/webdriver/commands/source_command.cc
@@ -2,9 +2,11 @@
// 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/source_command.h"
+
#include <string>
-#include "chrome/test/webdriver/commands/source_command.h"
+#include "chrome/test/webdriver/commands/response.h"
namespace webdriver {
@@ -36,8 +38,8 @@ void SourceCommand::ExecuteGet(Response* const response) {
kInternalServerError);
return;
}
- response->set_value(result);
- response->set_status(kSuccess);
+ response->SetValue(result);
+ response->SetStatus(kSuccess);
}
bool SourceCommand::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/source_command.h b/chrome/test/webdriver/commands/source_command.h
index f259e0e..cc8b1e7 100644
--- a/chrome/test/webdriver/commands/source_command.h
+++ b/chrome/test/webdriver/commands/source_command.h
@@ -12,6 +12,8 @@
namespace webdriver {
+class Response;
+
// Controls navigate to new web pages for the current tab. A call with
// an HTTP GET will return the source of the tab. See:
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/source
diff --git a/chrome/test/webdriver/commands/speed_command.cc b/chrome/test/webdriver/commands/speed_command.cc
index 95b4abd..9755305 100644
--- a/chrome/test/webdriver/commands/speed_command.cc
+++ b/chrome/test/webdriver/commands/speed_command.cc
@@ -2,10 +2,12 @@
// 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/speed_command.h"
+#include "chrome/test/webdriver/commands/response.h"
namespace webdriver {
@@ -63,18 +65,18 @@ bool SpeedCommand::DoesPost() {
void SpeedCommand::ExecuteGet(Response* const response) {
switch (session_->speed()) {
case Session::kSlow:
- response->set_value(new StringValue("SLOW"));
- response->set_status(kSuccess);
+ response->SetValue(new StringValue("SLOW"));
+ response->SetStatus(kSuccess);
break;
case Session::kMedium:
- response->set_value(new StringValue("MEDIUM"));
- response->set_status(kSuccess);
+ response->SetValue(new StringValue("MEDIUM"));
+ response->SetStatus(kSuccess);
break;
case Session::kFast:
- response->set_value(new StringValue("FAST"));
- response->set_status(kSuccess);
+ response->SetValue(new StringValue("FAST"));
+ response->SetStatus(kSuccess);
break;
default:
@@ -94,8 +96,8 @@ void SpeedCommand::ExecutePost(Response* const response) {
}
session_->set_speed(speed_);
- response->set_value(new StringValue("success"));
- response->set_status(kSuccess);
+ response->SetValue(new StringValue("success"));
+ response->SetStatus(kSuccess);
}
bool SpeedCommand::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/speed_command.h b/chrome/test/webdriver/commands/speed_command.h
index 6bd84a3..9846fa5 100644
--- a/chrome/test/webdriver/commands/speed_command.h
+++ b/chrome/test/webdriver/commands/speed_command.h
@@ -13,6 +13,8 @@
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.
diff --git a/chrome/test/webdriver/commands/target_locator_commands.cc b/chrome/test/webdriver/commands/target_locator_commands.cc
index 8808ca4..841173c 100644
--- a/chrome/test/webdriver/commands/target_locator_commands.cc
+++ b/chrome/test/webdriver/commands/target_locator_commands.cc
@@ -24,8 +24,8 @@ bool WindowHandleCommand::DoesGet() {
}
void WindowHandleCommand::ExecuteGet(Response* const response) {
- response->set_status(kSuccess);
- response->set_value(new StringValue(
+ response->SetStatus(kSuccess);
+ response->SetValue(new StringValue(
base::IntToString(session_->current_window_id())));
}
@@ -50,8 +50,8 @@ void WindowHandlesCommand::ExecuteGet(Response* const response) {
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->set_status(kSuccess);
- response->set_value(id_list);
+ response->SetStatus(kSuccess);
+ response->SetValue(id_list);
}
WindowCommand::WindowCommand(
@@ -82,7 +82,7 @@ void WindowCommand::ExecutePost(Response* const response) {
SET_WEBDRIVER_ERROR(response, "Could not switch window", code);
return;
}
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
void WindowCommand::ExecuteDelete(Response* const response) {
@@ -91,7 +91,7 @@ void WindowCommand::ExecuteDelete(Response* const response) {
response, "Could not close window", kInternalServerError);
return;
}
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
SwitchFrameCommand::SwitchFrameCommand(
@@ -127,7 +127,7 @@ void SwitchFrameCommand::ExecutePost(Response* const response) {
response, "Missing or invalid 'id' parameter", kBadRequest);
return;
}
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/commands/title_command.cc b/chrome/test/webdriver/commands/title_command.cc
index 12eaa37..6bb344f 100644
--- a/chrome/test/webdriver/commands/title_command.cc
+++ b/chrome/test/webdriver/commands/title_command.cc
@@ -2,9 +2,11 @@
// 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/title_command.h"
+
#include <string>
-#include "chrome/test/webdriver/commands/title_command.h"
+#include "chrome/test/webdriver/commands/response.h"
namespace webdriver {
@@ -25,8 +27,8 @@ void TitleCommand::ExecuteGet(Response* const response) {
return;
}
- response->set_value(new StringValue(title));
- response->set_status(kSuccess);
+ response->SetValue(new StringValue(title));
+ response->SetStatus(kSuccess);
}
bool TitleCommand::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/title_command.h b/chrome/test/webdriver/commands/title_command.h
index e017b29..3ec5fe81 100644
--- a/chrome/test/webdriver/commands/title_command.h
+++ b/chrome/test/webdriver/commands/title_command.h
@@ -12,6 +12,8 @@
namespace webdriver {
+class Response;
+
// A call with HTTP GET will return the title of the tab. See:
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/title
class TitleCommand : public WebDriverCommand {
diff --git a/chrome/test/webdriver/commands/url_command.cc b/chrome/test/webdriver/commands/url_command.cc
index d84dc31..34fa108 100644
--- a/chrome/test/webdriver/commands/url_command.cc
+++ b/chrome/test/webdriver/commands/url_command.cc
@@ -2,9 +2,11 @@
// 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/url_command.h"
+
#include <string>
-#include "chrome/test/webdriver/commands/url_command.h"
+#include "chrome/test/webdriver/commands/response.h"
namespace webdriver {
@@ -29,8 +31,8 @@ void URLCommand::ExecuteGet(Response* const response) {
return;
}
- response->set_value(new StringValue(url));
- response->set_status(kSuccess);
+ response->SetValue(new StringValue(url));
+ response->SetStatus(kSuccess);
}
void URLCommand::ExecutePost(Response* const response) {
@@ -48,8 +50,8 @@ void URLCommand::ExecutePost(Response* const response) {
}
session_->set_current_frame_xpath("");
- response->set_value(new StringValue(url));
- response->set_status(kSuccess);
+ response->SetValue(new StringValue(url));
+ response->SetStatus(kSuccess);
}
bool URLCommand::RequiresValidTab() {
diff --git a/chrome/test/webdriver/commands/url_command.h b/chrome/test/webdriver/commands/url_command.h
index 06c6200..0f5c1e8 100644
--- a/chrome/test/webdriver/commands/url_command.h
+++ b/chrome/test/webdriver/commands/url_command.h
@@ -12,6 +12,8 @@
namespace webdriver {
+class Response;
+
// Controls navigate to new web pages for the current tab. A call with
// and HTTP GET will return the URL of the tab. See:
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/url
diff --git a/chrome/test/webdriver/commands/webdriver_command.cc b/chrome/test/webdriver/commands/webdriver_command.cc
index 9aee251..f861374 100644
--- a/chrome/test/webdriver/commands/webdriver_command.cc
+++ b/chrome/test/webdriver/commands/webdriver_command.cc
@@ -18,6 +18,7 @@
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
+#include "chrome/test/webdriver/commands/response.h"
#include "chrome/test/webdriver/session_manager.h"
#include "chrome/test/webdriver/utility_functions.h"
@@ -44,17 +45,15 @@ 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) {
- response->set_value(Value::CreateStringValue("No session ID specified"));
- response->set_status(kBadRequest);
+ SET_WEBDRIVER_ERROR(response, "No session ID specified", kBadRequest);
return false;
}
VLOG(1) << "Fetching session: " << session_id;
session_ = SessionManager::GetInstance()->GetSession(session_id);
if (session_ == NULL) {
- response->set_value(Value::CreateStringValue(
- "Session not found: " + session_id));
- response->set_status(kSessionNotFound);
+ SET_WEBDRIVER_ERROR(response, "Session not found: " + session_id,
+ kSessionNotFound);
return false;
}
diff --git a/chrome/test/webdriver/commands/webelement_commands.cc b/chrome/test/webdriver/commands/webelement_commands.cc
index 907fb81..f240326 100644
--- a/chrome/test/webdriver/commands/webelement_commands.cc
+++ b/chrome/test/webdriver/commands/webelement_commands.cc
@@ -130,8 +130,8 @@ void ElementValueCommand::ExecuteGet(Response* const response) {
kInternalServerError);
return;
}
- response->set_status(kSuccess);
- response->set_value(result.release());
+ response->SetStatus(kSuccess);
+ response->SetValue(result.release());
}
void ElementValueCommand::ExecutePost(Response* const response) {
@@ -167,7 +167,7 @@ void ElementValueCommand::ExecutePost(Response* const response) {
code);
return;
}
- response->set_status(kSuccess);
+ response->SetStatus(kSuccess);
}
ElementTextCommand::ElementTextCommand(
@@ -202,8 +202,8 @@ void ElementTextCommand::ExecuteGet(Response* const response) {
kInternalServerError);
return;
}
- response->set_status(kSuccess);
- response->set_value(result.release());
+ response->SetStatus(kSuccess);
+ response->SetValue(result.release());
}
} // namespace webdriver
diff --git a/chrome/test/webdriver/dispatch.cc b/chrome/test/webdriver/dispatch.cc
index 28a94da..26b9738 100644
--- a/chrome/test/webdriver/dispatch.cc
+++ b/chrome/test/webdriver/dispatch.cc
@@ -54,7 +54,8 @@ namespace internal {
void PrepareHttpResponse(const Response& command_response,
HttpResponse* const http_response) {
- switch (command_response.status()) {
+ ErrorCode status = command_response.GetStatus();
+ switch (status) {
case kSuccess:
http_response->set_status(HttpResponse::kOk);
break;
@@ -63,7 +64,7 @@ void PrepareHttpResponse(const Response& command_response,
// and kMethodNotAllowed should be detected before creating
// a command_response, and should thus not need conversion.
case kSeeOther: {
- const Value* const value = command_response.value();
+ const Value* const value = command_response.GetValue();
std::string location;
if (!value->GetAsString(&location)) {
// This should never happen.
@@ -80,11 +81,11 @@ void PrepareHttpResponse(const Response& command_response,
case kBadRequest:
case kSessionNotFound:
- http_response->set_status(command_response.status());
+ http_response->set_status(status);
break;
case kMethodNotAllowed: {
- const Value* const value = command_response.value();
+ const Value* const value = command_response.GetValue();
if (!value->IsType(Value::TYPE_LIST)) {
// This should never happen.
http_response->set_status(HttpResponse::kInternalServerError);
@@ -169,9 +170,9 @@ bool ParseRequestInfo(const struct mg_request_info* const request_info,
std::string json(request_info->post_data, request_info->post_data_len);
std::string error;
if (!ParseJSONDictionary(json, parameters, &error)) {
- response->set_value(Value::CreateStringValue(
- "Failed to parse command data: " + error + "\n Data: " + json));
- response->set_status(kBadRequest);
+ SET_WEBDRIVER_ERROR(response,
+ "Failed to parse command data: " + error + "\n Data: " + json,
+ kBadRequest);
return false;
}
}
@@ -198,8 +199,8 @@ void DispatchHelper(Command* command_ptr,
}
if (command->DoesDelete())
methods->Append(Value::CreateStringValue("DELETE"));
- response->set_status(kMethodNotAllowed);
- response->set_value(methods);
+ response->SetStatus(kMethodNotAllowed);
+ response->SetValue(methods);
return;
}
diff --git a/chrome/test/webdriver/dispatch_unittest.cc b/chrome/test/webdriver/dispatch_unittest.cc
index c724041..6da3288 100644
--- a/chrome/test/webdriver/dispatch_unittest.cc
+++ b/chrome/test/webdriver/dispatch_unittest.cc
@@ -33,7 +33,7 @@ void ExpectHttpStatus(int expected_status,
void ExpectInternalError(ErrorCode command_status,
Response* command_response,
HttpResponse* const http_response) {
- command_response->set_status(command_status);
+ command_response->SetStatus(command_status);
http_response->set_status(HttpResponse::kOk); // Reset to detect changes.
ExpectHttpStatus(HttpResponse::kInternalServerError,
*command_response, http_response);
@@ -45,29 +45,29 @@ TEST(DispatchTest, CorrectlyConvertsResponseCodesToHttpStatusCodes) {
HttpResponse http_response;
Response command_response;
- command_response.set_value(Value::CreateStringValue("foobar"));
+ command_response.SetValue(Value::CreateStringValue("foobar"));
- command_response.set_status(kSuccess);
+ command_response.SetStatus(kSuccess);
ExpectHttpStatus(HttpResponse::kOk, command_response, &http_response);
- command_response.set_status(kSeeOther);
+ command_response.SetStatus(kSeeOther);
ExpectHttpStatus(HttpResponse::kSeeOther, command_response, &http_response);
ExpectHeaderValue(http_response, "location", "foobar");
http_response.ClearHeaders();
- command_response.set_status(kBadRequest);
+ command_response.SetStatus(kBadRequest);
ExpectHttpStatus(HttpResponse::kBadRequest, command_response,
&http_response);
- command_response.set_status(kSessionNotFound);
+ command_response.SetStatus(kSessionNotFound);
ExpectHttpStatus(HttpResponse::kNotFound, command_response,
&http_response);
ListValue* methods = new ListValue;
methods->Append(Value::CreateStringValue("POST"));
methods->Append(Value::CreateStringValue("GET"));
- command_response.set_value(methods);
- command_response.set_status(kMethodNotAllowed);
+ command_response.SetValue(methods);
+ command_response.SetStatus(kMethodNotAllowed);
ExpectHttpStatus(HttpResponse::kMethodNotAllowed, command_response,
&http_response);
ExpectHeaderValue(http_response, "allow", "POST,GET");
@@ -99,8 +99,8 @@ TEST(DispatchTest,
methods->Append(Value::CreateStringValue("DELETE"));
Response command_response;
- command_response.set_status(kMethodNotAllowed);
- command_response.set_value(methods);
+ command_response.SetStatus(kMethodNotAllowed);
+ command_response.SetValue(methods);
HttpResponse http_response;
ExpectHttpStatus(HttpResponse::kInternalServerError, command_response,
@@ -111,8 +111,8 @@ TEST(DispatchTest, ReturnsCommandResponseAsJson) {
const std::string kExpectedData = "{\"status\":0,\"value\":\"foobar\"}";
Response command_response;
- command_response.set_status(kSuccess);
- command_response.set_value(Value::CreateStringValue("foobar"));
+ command_response.SetStatus(kSuccess);
+ command_response.SetValue(Value::CreateStringValue("foobar"));
HttpResponse http_response;
internal::PrepareHttpResponse(command_response, &http_response);