Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4963)

Unified Diff: chrome/test/chromedriver/commands.cc

Issue 13185004: [chromedriver] Implement proxy capability. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/commands.cc
diff --git a/chrome/test/chromedriver/commands.cc b/chrome/test/chromedriver/commands.cc
index d6ccc8f8ad634377776b5d2fd481dc6bcb6d36bd..67a05ad771de86c975e237009bebc246869b613d 100644
--- a/chrome/test/chromedriver/commands.cc
+++ b/chrome/test/chromedriver/commands.cc
@@ -6,6 +6,7 @@
#include "base/callback.h"
#include "base/file_util.h"
+#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/sys_info.h"
#include "base/values.h"
@@ -41,6 +42,70 @@ Status ExecuteGetStatus(
return Status(kOk);
}
+namespace {
+
+// Parse information of proxy, add them as chrome switches to |args_list|.
+Status ParseProxy(const base::DictionaryValue& proxy_dict,
kkania 2013/03/29 20:52:46 Can we factor the capability parsing out into its
+ base::ListValue* args_list) {
+ std::string proxy_type;
+ if (!proxy_dict.GetString("proxyType", &proxy_type))
+ return Status(kUnknownError, "'proxyType' must be a string");
+ proxy_type = StringToLowerASCII(proxy_type);
+ if (proxy_type == "direct") {
+ args_list->AppendString("no-proxy-server");
+ } else if (proxy_type == "system") {
+ // Chrome default.
+ } else if (proxy_type == "pac") {
+ std::string proxy_pac_url;
+ if (!proxy_dict.GetString("proxyAutoconfigUrl", &proxy_pac_url))
+ return Status(kUnknownError, "'proxyAutoconfigUrl' must be a string");
+ args_list->AppendString("proxy-pac-url=" + proxy_pac_url);
+ } else if (proxy_type == "autodetect") {
+ args_list->AppendString("proxy-auto-detect");
+ } else if (proxy_type == "manual") {
+ const char* proxy_servers_options[][2] = {
+ {"ftpProxy", "ftp"}, {"httpProxy", "http"}, {"sslProxy", "https"}};
+ std::string proxy_servers;
+ for (size_t i = 0; i < arraysize(proxy_servers_options); ++i) {
+ if (!proxy_dict.HasKey(proxy_servers_options[i][0]))
+ continue;
+ std::string value;
+ if (!proxy_dict.GetString(proxy_servers_options[i][0], &value)) {
+ return Status(
+ kUnknownError,
+ base::StringPrintf("'%s' must be a string",
+ proxy_servers_options[i][0]));
+ }
+ // Converts into Chrome proxy scheme.
+ // Example: "http=localhost:9000;ftp=localhost:8000".
+ if (!proxy_servers.empty())
+ proxy_servers += ";";
+ proxy_servers += base::StringPrintf(
+ "%s=%s", proxy_servers_options[i][1], value.c_str());
+ }
+
+ std::string proxy_bypass_list;
+ if (proxy_dict.HasKey("noProxy")) {
+ if (!proxy_dict.GetString("noProxy", & proxy_bypass_list))
+ return Status(kUnknownError, "'noProxy' must be a string");
+ }
+
+ if (proxy_servers.empty() && proxy_bypass_list.empty()) {
+ return Status(kUnknownError, "proxyType is 'manual' but no manual "
+ "proxy capabilities were found");
+ }
+ if (!proxy_servers.empty())
+ args_list->AppendString("proxy-server=" + proxy_servers);
+ if (!proxy_bypass_list.empty())
+ args_list->AppendString("proxy-bypass-list=" + proxy_bypass_list);
+ } else {
+ return Status(kUnknownError, "unrecognized proxy type:" + proxy_type);
+ }
+ return Status(kOk);
+}
+
+}
+
Status ExecuteNewSession(
SessionMap* session_map,
scoped_refptr<URLRequestContextGetter> context_getter,
@@ -109,6 +174,19 @@ Status ExecuteNewSession(
"chrome extensions must be a list");
}
+ const base::Value* proxy = NULL;
+ scoped_ptr<base::ListValue> new_args_list;
+ if (desired_caps->Get("chromeOptions.proxy", &proxy)) {
+ const base::DictionaryValue* proxy_dict = NULL;
+ if (!proxy->GetAsDictionary(&proxy_dict))
+ return Status(kUnknownError, "proxy must be a dictionary");
+ new_args_list.reset(args_list->DeepCopy());
+ status = ParseProxy(*proxy_dict, new_args_list.get());
+ if (status.IsError())
+ return status;
+ args_list = new_args_list.get();
+ }
+
scoped_ptr<ChromeDesktopImpl> chrome_desktop(new ChromeDesktopImpl(
context_getter, port, socket_factory));
status = chrome_desktop->Launch(chrome_exe, args_list, extensions_list,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698