summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/webdriver_capabilities_parser.h
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-27 21:39:25 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-27 21:39:25 +0000
commit582b55d4a0ee1c0ceea48b1b337b4b71597f9fe0 (patch)
tree3da47bb3e93368d73e9767af039341dd1db244e6 /chrome/test/webdriver/webdriver_capabilities_parser.h
parent91a5ded4aa5088c26916a5eb81d52ff7d1cc1821 (diff)
downloadchromium_src-582b55d4a0ee1c0ceea48b1b337b4b71597f9fe0.zip
chromium_src-582b55d4a0ee1c0ceea48b1b337b4b71597f9fe0.tar.gz
chromium_src-582b55d4a0ee1c0ceea48b1b337b4b71597f9fe0.tar.bz2
Enhance and refactor ChromeDriver's capability handling. Log warning for
non-recognized capabilities, return errors on incorrect input types, and allow new format where all options are placed under a chromeOptions dictionary. The latter is needed to simplify handling capabilities on the WebDriver client side. See http://codereview.appspot.com/5307047/. BUG=82895,94721 TEST=none Review URL: http://codereview.chromium.org/8341044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107629 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/webdriver/webdriver_capabilities_parser.h')
-rw-r--r--chrome/test/webdriver/webdriver_capabilities_parser.h109
1 files changed, 109 insertions, 0 deletions
diff --git a/chrome/test/webdriver/webdriver_capabilities_parser.h b/chrome/test/webdriver/webdriver_capabilities_parser.h
new file mode 100644
index 0000000..8f9320d
--- /dev/null
+++ b/chrome/test/webdriver/webdriver_capabilities_parser.h
@@ -0,0 +1,109 @@
+// 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.
+
+#ifndef CHROME_TEST_WEBDRIVER_WEBDRIVER_CAPABILITIES_PARSER_H_
+#define CHROME_TEST_WEBDRIVER_WEBDRIVER_CAPABILITIES_PARSER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
+
+namespace base {
+class DictionaryValue;
+class Value;
+}
+
+namespace webdriver {
+
+class Error;
+
+// Contains all the capabilities that a user may request when starting a
+// new session.
+struct Capabilities {
+ Capabilities();
+ ~Capabilities();
+
+ // Command line to use for starting Chrome.
+ CommandLine command;
+
+ // Channel ID to use for connecting to an already running Chrome.
+ std::string channel;
+
+ // Whether the lifetime of the started Chrome browser process should be
+ // bound to ChromeDriver's process. If true, Chrome will not quit if
+ // ChromeDriver dies.
+ bool detach;
+
+ // List of paths for extensions to install on startup.
+ std::vector<FilePath> extensions;
+
+ // Whether Chrome should not block when loading.
+ bool load_async;
+
+ // Whether Chrome should simulate input events using OS APIs instead of
+ // WebKit APIs.
+ bool native_events;
+
+ // Path to a custom profile to use.
+ FilePath profile;
+
+ // Whether ChromeDriver should log verbosely.
+ bool verbose;
+};
+
+// Parses the given capabilities dictionary to produce a |Capabilities|
+// instance.
+// See webdriver's desired capabilities for more info.
+class CapabilitiesParser {
+ public:
+ // Create a new parser. |capabilities_dict| is the dictionary for all
+ // of the user's desired capabilities. |root_path| is the root directory
+ // to use for writing any necessary files to disk. This function will not
+ // create it or delete it. All files written to disk will be placed in
+ // this directory.
+ CapabilitiesParser(const base::DictionaryValue* capabilities_dict,
+ const FilePath& root_path,
+ Capabilities* capabilities);
+ ~CapabilitiesParser();
+
+ // Parses the capabilities. May return an error.
+ Error* Parse();
+
+ private:
+ Error* ParseArgs(const base::Value* option);
+ Error* ParseBinary(const base::Value* option);
+ Error* ParseChannel(const base::Value* option);
+ Error* ParseDetach(const base::Value* option);
+ Error* ParseExtensions(const base::Value* option);
+ Error* ParseLoadAsync(const base::Value* option);
+ Error* ParseNativeEvents(const base::Value* option);
+ Error* ParseProfile(const base::Value* option);
+ Error* ParseVerbose(const base::Value* option);
+ // Decodes the given base64-encoded string, optionally unzips it, and
+ // writes the result to |path|.
+ // On error, false will be returned and |error_msg| will be set.
+ bool DecodeAndWriteFile(const FilePath& path,
+ const std::string& base64,
+ bool unzip,
+ std::string* error_msg);
+
+ // The capabilities dictionary to parse.
+ const base::DictionaryValue* dict_;
+
+ // The root directory under which to write all files.
+ const FilePath root_;
+
+ // A pointer to the capabilities to modify while parsing.
+ Capabilities* caps_;
+
+ DISALLOW_COPY_AND_ASSIGN(CapabilitiesParser);
+};
+
+} // namespace webdriver
+
+#endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_CAPABILITIES_PARSER_H_