Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/chromedriver/commands.h" | 5 #include "chrome/test/chromedriver/commands.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/string_util.h" | |
| 9 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 10 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/test/chromedriver/chrome/chrome.h" | 13 #include "chrome/test/chromedriver/chrome/chrome.h" |
| 13 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" | 14 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" |
| 14 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" | 15 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" |
| 15 #include "chrome/test/chromedriver/chrome/status.h" | 16 #include "chrome/test/chromedriver/chrome/status.h" |
| 16 #include "chrome/test/chromedriver/chrome/version.h" | 17 #include "chrome/test/chromedriver/chrome/version.h" |
| 17 #include "chrome/test/chromedriver/chrome/web_view.h" | 18 #include "chrome/test/chromedriver/chrome/web_view.h" |
| 18 #include "chrome/test/chromedriver/net/net_util.h" | 19 #include "chrome/test/chromedriver/net/net_util.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 34 os.SetString("version", base::SysInfo::OperatingSystemVersion()); | 35 os.SetString("version", base::SysInfo::OperatingSystemVersion()); |
| 35 os.SetString("arch", base::SysInfo::OperatingSystemArchitecture()); | 36 os.SetString("arch", base::SysInfo::OperatingSystemArchitecture()); |
| 36 | 37 |
| 37 base::DictionaryValue info; | 38 base::DictionaryValue info; |
| 38 info.Set("build", build.DeepCopy()); | 39 info.Set("build", build.DeepCopy()); |
| 39 info.Set("os", os.DeepCopy()); | 40 info.Set("os", os.DeepCopy()); |
| 40 out_value->reset(info.DeepCopy()); | 41 out_value->reset(info.DeepCopy()); |
| 41 return Status(kOk); | 42 return Status(kOk); |
| 42 } | 43 } |
| 43 | 44 |
| 45 namespace { | |
| 46 | |
| 47 // Parse information of proxy, add them as chrome switches to |args_list|. | |
| 48 Status ParseProxy(const base::DictionaryValue& proxy_dict, | |
|
kkania
2013/03/29 20:52:46
Can we factor the capability parsing out into its
| |
| 49 base::ListValue* args_list) { | |
| 50 std::string proxy_type; | |
| 51 if (!proxy_dict.GetString("proxyType", &proxy_type)) | |
| 52 return Status(kUnknownError, "'proxyType' must be a string"); | |
| 53 proxy_type = StringToLowerASCII(proxy_type); | |
| 54 if (proxy_type == "direct") { | |
| 55 args_list->AppendString("no-proxy-server"); | |
| 56 } else if (proxy_type == "system") { | |
| 57 // Chrome default. | |
| 58 } else if (proxy_type == "pac") { | |
| 59 std::string proxy_pac_url; | |
| 60 if (!proxy_dict.GetString("proxyAutoconfigUrl", &proxy_pac_url)) | |
| 61 return Status(kUnknownError, "'proxyAutoconfigUrl' must be a string"); | |
| 62 args_list->AppendString("proxy-pac-url=" + proxy_pac_url); | |
| 63 } else if (proxy_type == "autodetect") { | |
| 64 args_list->AppendString("proxy-auto-detect"); | |
| 65 } else if (proxy_type == "manual") { | |
| 66 const char* proxy_servers_options[][2] = { | |
| 67 {"ftpProxy", "ftp"}, {"httpProxy", "http"}, {"sslProxy", "https"}}; | |
| 68 std::string proxy_servers; | |
| 69 for (size_t i = 0; i < arraysize(proxy_servers_options); ++i) { | |
| 70 if (!proxy_dict.HasKey(proxy_servers_options[i][0])) | |
| 71 continue; | |
| 72 std::string value; | |
| 73 if (!proxy_dict.GetString(proxy_servers_options[i][0], &value)) { | |
| 74 return Status( | |
| 75 kUnknownError, | |
| 76 base::StringPrintf("'%s' must be a string", | |
| 77 proxy_servers_options[i][0])); | |
| 78 } | |
| 79 // Converts into Chrome proxy scheme. | |
| 80 // Example: "http=localhost:9000;ftp=localhost:8000". | |
| 81 if (!proxy_servers.empty()) | |
| 82 proxy_servers += ";"; | |
| 83 proxy_servers += base::StringPrintf( | |
| 84 "%s=%s", proxy_servers_options[i][1], value.c_str()); | |
| 85 } | |
| 86 | |
| 87 std::string proxy_bypass_list; | |
| 88 if (proxy_dict.HasKey("noProxy")) { | |
| 89 if (!proxy_dict.GetString("noProxy", & proxy_bypass_list)) | |
| 90 return Status(kUnknownError, "'noProxy' must be a string"); | |
| 91 } | |
| 92 | |
| 93 if (proxy_servers.empty() && proxy_bypass_list.empty()) { | |
| 94 return Status(kUnknownError, "proxyType is 'manual' but no manual " | |
| 95 "proxy capabilities were found"); | |
| 96 } | |
| 97 if (!proxy_servers.empty()) | |
| 98 args_list->AppendString("proxy-server=" + proxy_servers); | |
| 99 if (!proxy_bypass_list.empty()) | |
| 100 args_list->AppendString("proxy-bypass-list=" + proxy_bypass_list); | |
| 101 } else { | |
| 102 return Status(kUnknownError, "unrecognized proxy type:" + proxy_type); | |
| 103 } | |
| 104 return Status(kOk); | |
| 105 } | |
| 106 | |
| 107 } | |
| 108 | |
| 44 Status ExecuteNewSession( | 109 Status ExecuteNewSession( |
| 45 SessionMap* session_map, | 110 SessionMap* session_map, |
| 46 scoped_refptr<URLRequestContextGetter> context_getter, | 111 scoped_refptr<URLRequestContextGetter> context_getter, |
| 47 const SyncWebSocketFactory& socket_factory, | 112 const SyncWebSocketFactory& socket_factory, |
| 48 const base::DictionaryValue& params, | 113 const base::DictionaryValue& params, |
| 49 const std::string& session_id, | 114 const std::string& session_id, |
| 50 scoped_ptr<base::Value>* out_value, | 115 scoped_ptr<base::Value>* out_value, |
| 51 std::string* out_session_id) { | 116 std::string* out_session_id) { |
| 52 int port; | 117 int port; |
| 53 if (!FindOpenPort(&port)) | 118 if (!FindOpenPort(&port)) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 } | 167 } |
| 103 | 168 |
| 104 const base::Value* extensions = NULL; | 169 const base::Value* extensions = NULL; |
| 105 const base::ListValue* extensions_list = NULL; | 170 const base::ListValue* extensions_list = NULL; |
| 106 if (desired_caps->Get("chromeOptions.extensions", &extensions) | 171 if (desired_caps->Get("chromeOptions.extensions", &extensions) |
| 107 && !extensions->GetAsList(&extensions_list)) { | 172 && !extensions->GetAsList(&extensions_list)) { |
| 108 return Status(kUnknownError, | 173 return Status(kUnknownError, |
| 109 "chrome extensions must be a list"); | 174 "chrome extensions must be a list"); |
| 110 } | 175 } |
| 111 | 176 |
| 177 const base::Value* proxy = NULL; | |
| 178 scoped_ptr<base::ListValue> new_args_list; | |
| 179 if (desired_caps->Get("chromeOptions.proxy", &proxy)) { | |
| 180 const base::DictionaryValue* proxy_dict = NULL; | |
| 181 if (!proxy->GetAsDictionary(&proxy_dict)) | |
| 182 return Status(kUnknownError, "proxy must be a dictionary"); | |
| 183 new_args_list.reset(args_list->DeepCopy()); | |
| 184 status = ParseProxy(*proxy_dict, new_args_list.get()); | |
| 185 if (status.IsError()) | |
| 186 return status; | |
| 187 args_list = new_args_list.get(); | |
| 188 } | |
| 189 | |
| 112 scoped_ptr<ChromeDesktopImpl> chrome_desktop(new ChromeDesktopImpl( | 190 scoped_ptr<ChromeDesktopImpl> chrome_desktop(new ChromeDesktopImpl( |
| 113 context_getter, port, socket_factory)); | 191 context_getter, port, socket_factory)); |
| 114 status = chrome_desktop->Launch(chrome_exe, args_list, extensions_list, | 192 status = chrome_desktop->Launch(chrome_exe, args_list, extensions_list, |
| 115 prefs_dict, local_state_dict); | 193 prefs_dict, local_state_dict); |
| 116 chrome.reset(chrome_desktop.release()); | 194 chrome.reset(chrome_desktop.release()); |
| 117 } | 195 } |
| 118 if (status.IsError()) | 196 if (status.IsError()) |
| 119 return Status(kSessionNotCreatedException, status.message()); | 197 return Status(kSessionNotCreatedException, status.message()); |
| 120 | 198 |
| 121 std::list<std::string> web_view_ids; | 199 std::list<std::string> web_view_ids; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 std::string* out_session_id) { | 233 std::string* out_session_id) { |
| 156 std::vector<std::string> session_ids; | 234 std::vector<std::string> session_ids; |
| 157 session_map->GetKeys(&session_ids); | 235 session_map->GetKeys(&session_ids); |
| 158 for (size_t i = 0; i < session_ids.size(); ++i) { | 236 for (size_t i = 0; i < session_ids.size(); ++i) { |
| 159 scoped_ptr<base::Value> unused_value; | 237 scoped_ptr<base::Value> unused_value; |
| 160 std::string unused_session_id; | 238 std::string unused_session_id; |
| 161 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); | 239 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); |
| 162 } | 240 } |
| 163 return Status(kOk); | 241 return Status(kOk); |
| 164 } | 242 } |
| OLD | NEW |