summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/dispatch.h
diff options
context:
space:
mode:
authorjmikhail@google.com <jmikhail@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-19 00:57:51 +0000
committerjmikhail@google.com <jmikhail@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-19 00:57:51 +0000
commit35a369575ad34881580ed0724f8c0304f7342c20 (patch)
treedba8ec8d9ae4679a6dd571a2c65c7328e0e0a465 /chrome/test/webdriver/dispatch.h
parentbc073ca8358c8edd5b21f61d5194120a838e3530 (diff)
downloadchromium_src-35a369575ad34881580ed0724f8c0304f7342c20.zip
chromium_src-35a369575ad34881580ed0724f8c0304f7342c20.tar.gz
chromium_src-35a369575ad34881580ed0724f8c0304f7342c20.tar.bz2
Base implementation of WebDriver for Chrome.
WebDriver is a tool for automating testing web applications, and in particular to verify that they work as expected. It aims to provide a friendly API that's easy to explore and understand, which will help make your tests easier to read and maintain. It's not tied to any particular test framework, so it can be used equally well with JUnit, TestNG or from a plain old "main" method. This checkin includes all that it necessary to implement the JSON over HTTP protocol for WebDriver along with the /session and /session/sessionID URLs. Each URL is added under the webdriver/command directory. To run simply run execute webdriver command, on linux you may need to add the path to chrome to your enviroment settings. A port can be specified with the --port option, by default webdriver will listen in on port 8080. Note: A total refactor of my original code was done by Jason Leyba (jleyba). All of his changes are included in this checkin For further reference on the WebDriver remote protocol see: http://code.google.com/p/selenium/wiki/JsonWireProtocol BUG=none TEST=Start webdriver then run the file webdriver_tests.py Review URL: http://codereview.chromium.org/3064012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56626 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/webdriver/dispatch.h')
-rw-r--r--chrome/test/webdriver/dispatch.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/chrome/test/webdriver/dispatch.h b/chrome/test/webdriver/dispatch.h
new file mode 100644
index 0000000..f612602
--- /dev/null
+++ b/chrome/test/webdriver/dispatch.h
@@ -0,0 +1,77 @@
+// 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_DISPATCH_H_
+#define CHROME_TEST_WEBDRIVER_DISPATCH_H_
+
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "base/string_util.h"
+#include "chrome/test/webdriver/utility_functions.h"
+#include "chrome/test/webdriver/commands/command.h"
+
+#include "third_party/mongoose/mongoose.h"
+
+namespace webdriver {
+
+class Command;
+
+// Sends a |response| to a WebDriver command back to the client.
+// |connection| is the communication pipe to the HTTP server and
+// |request_info| contains any data sent by the user.
+void SendResponse(struct mg_connection* const connection,
+ const struct mg_request_info* const request_info,
+ const Response& response);
+
+
+// Serves as a link to the mongoose server to find if the user request
+// is an HTTP POST, GET, or DELETE and then executes the proper function
+// calls for the class that inherts from Command. An HTTP CREATE is not
+// handled and is reserved only for the establishment of a session.
+void DispatchCommand(Command* const command, const std::string& method,
+ Response* response);
+
+// Template function for dispatching commands sent to the WebDriver REST
+// service. |CommandType| must be a subtype of |webdriver::Command|.
+template<typename CommandType>
+void Dispatch(struct mg_connection* connection,
+ const struct mg_request_info* request_info,
+ void* user_data) {
+ Response response;
+
+ std::string method(request_info->request_method);
+
+ std::vector<std::string> path_segments;
+ std::string uri(request_info->uri);
+ SplitString(uri, '/', &path_segments);
+
+ DictionaryValue* parameters = NULL;
+ if ((method == "POST" || method == "PUT") &&
+ request_info->post_data_len > 0) {
+ LOG(INFO) << "...parsing request body";
+ 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);
+ SendResponse(connection, request_info, response);
+ return;
+ }
+ }
+
+ LOG(INFO) << "Dispatching " << method << " " << uri
+ << std::string(request_info->post_data,
+ request_info->post_data_len) << std::endl;
+ scoped_ptr<CommandType> ptr(new CommandType(path_segments, parameters));
+ DispatchCommand(ptr.get(), method, &response);
+ SendResponse(connection, request_info, response);
+}
+} // namespace webdriver
+#endif // CHROME_TEST_WEBDRIVER_DISPATCH_H_
+