OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/capabilities.h" | 5 #include "chrome/test/chromedriver/capabilities.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/test/chromedriver/chrome/log.h" |
14 #include "chrome/test/chromedriver/chrome/status.h" | 15 #include "chrome/test/chromedriver/chrome/status.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 typedef base::Callback<Status(const base::Value&, Capabilities*)> Parser; | 19 typedef base::Callback<Status(const base::Value&, Capabilities*)> Parser; |
19 | 20 |
20 Status ParseDetach( | 21 Status ParseDetach( |
21 const base::Value& option, | 22 const base::Value& option, |
22 Capabilities* capabilities) { | 23 Capabilities* capabilities) { |
23 if (!option.GetAsBoolean(&capabilities->detach)) | 24 if (!option.GetAsBoolean(&capabilities->detach)) |
24 return Status(kUnknownError, "'detach' must be a boolean"); | 25 return Status(kUnknownError, "'detach' must be a boolean"); |
25 return Status(kOk); | 26 return Status(kOk); |
26 } | 27 } |
27 | 28 |
| 29 Status IgnoreDeprecatedOption( |
| 30 Log* log, |
| 31 const char* option_name, |
| 32 const base::Value& option, |
| 33 Capabilities* capabilities) { |
| 34 log->AddEntry(Log::kWarning, |
| 35 base::StringPrintf("deprecated chrome option is ignored: '%s'", |
| 36 option_name)); |
| 37 return Status(kOk); |
| 38 } |
| 39 |
28 Status ParseChromeBinary( | 40 Status ParseChromeBinary( |
29 const base::Value& option, | 41 const base::Value& option, |
30 Capabilities* capabilities) { | 42 Capabilities* capabilities) { |
31 base::FilePath::StringType path_str; | 43 base::FilePath::StringType path_str; |
32 if (!option.GetAsString(&path_str)) | 44 if (!option.GetAsString(&path_str)) |
33 return Status(kUnknownError, "'binary' must be a string"); | 45 return Status(kUnknownError, "'binary' must be a string"); |
34 base::FilePath chrome_exe(path_str); | 46 base::FilePath chrome_exe(path_str); |
35 capabilities->command.SetProgram(chrome_exe); | 47 capabilities->command.SetProgram(chrome_exe); |
36 return Status(kOk); | 48 return Status(kOk); |
37 } | 49 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 capabilities->command.AppendSwitchASCII("proxy-bypass-list", | 176 capabilities->command.AppendSwitchASCII("proxy-bypass-list", |
165 proxy_bypass_list); | 177 proxy_bypass_list); |
166 } | 178 } |
167 } else { | 179 } else { |
168 return Status(kUnknownError, "unrecognized proxy type:" + proxy_type); | 180 return Status(kUnknownError, "unrecognized proxy type:" + proxy_type); |
169 } | 181 } |
170 return Status(kOk); | 182 return Status(kOk); |
171 } | 183 } |
172 | 184 |
173 Status ParseDesktopChromeCapabilities( | 185 Status ParseDesktopChromeCapabilities( |
| 186 Log* log, |
174 const base::Value& capability, | 187 const base::Value& capability, |
175 Capabilities* capabilities) { | 188 Capabilities* capabilities) { |
176 const base::DictionaryValue* chrome_options = NULL; | 189 const base::DictionaryValue* chrome_options = NULL; |
177 if (!capability.GetAsDictionary(&chrome_options)) | 190 if (!capability.GetAsDictionary(&chrome_options)) |
178 return Status(kUnknownError, "'chromeOptions' must be a dictionary"); | 191 return Status(kUnknownError, "'chromeOptions' must be a dictionary"); |
179 | 192 |
180 std::map<std::string, Parser> parser_map; | 193 std::map<std::string, Parser> parser_map; |
181 | 194 |
182 parser_map["detach"] = base::Bind(&ParseDetach); | 195 parser_map["detach"] = base::Bind(&ParseDetach); |
| 196 parser_map["loadAsync"] = |
| 197 base::Bind(&IgnoreDeprecatedOption, log, "loadAsync"); |
183 parser_map["binary"] = base::Bind(&ParseChromeBinary); | 198 parser_map["binary"] = base::Bind(&ParseChromeBinary); |
184 parser_map["logPath"] = base::Bind(&ParseLogPath); | 199 parser_map["logPath"] = base::Bind(&ParseLogPath); |
185 parser_map["args"] = base::Bind(&ParseArgs, false); | 200 parser_map["args"] = base::Bind(&ParseArgs, false); |
186 parser_map["prefs"] = base::Bind(&ParsePrefs); | 201 parser_map["prefs"] = base::Bind(&ParsePrefs); |
187 parser_map["localState"] = base::Bind(&ParseLocalState); | 202 parser_map["localState"] = base::Bind(&ParseLocalState); |
188 parser_map["extensions"] = base::Bind(&ParseExtensions); | 203 parser_map["extensions"] = base::Bind(&ParseExtensions); |
189 | 204 |
190 for (base::DictionaryValue::Iterator it(*chrome_options); !it.IsAtEnd(); | 205 for (base::DictionaryValue::Iterator it(*chrome_options); !it.IsAtEnd(); |
191 it.Advance()) { | 206 it.Advance()) { |
192 if (parser_map.find(it.key()) == parser_map.end()) { | 207 if (parser_map.find(it.key()) == parser_map.end()) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 Capabilities::Capabilities() | 292 Capabilities::Capabilities() |
278 : detach(false), | 293 : detach(false), |
279 command(CommandLine::NO_PROGRAM) {} | 294 command(CommandLine::NO_PROGRAM) {} |
280 | 295 |
281 Capabilities::~Capabilities() {} | 296 Capabilities::~Capabilities() {} |
282 | 297 |
283 bool Capabilities::IsAndroid() const { | 298 bool Capabilities::IsAndroid() const { |
284 return !android_package.empty(); | 299 return !android_package.empty(); |
285 } | 300 } |
286 | 301 |
287 Status Capabilities::Parse(const base::DictionaryValue& desired_caps) { | 302 Status Capabilities::Parse( |
| 303 const base::DictionaryValue& desired_caps, |
| 304 Log* log) { |
288 Status status = ParseLoggingPrefs(desired_caps, this); | 305 Status status = ParseLoggingPrefs(desired_caps, this); |
289 if (status.IsError()) | 306 if (status.IsError()) |
290 return status; | 307 return status; |
291 status = ParseAndroidChromeCapabilities(desired_caps, this); | 308 status = ParseAndroidChromeCapabilities(desired_caps, this); |
292 if (status.IsError()) | 309 if (status.IsError()) |
293 return status; | 310 return status; |
294 if (IsAndroid()) | 311 if (IsAndroid()) |
295 return Status(kOk); | 312 return Status(kOk); |
296 | 313 |
297 std::map<std::string, Parser> parser_map; | 314 std::map<std::string, Parser> parser_map; |
298 parser_map["proxy"] = base::Bind(&ParseProxy); | 315 parser_map["proxy"] = base::Bind(&ParseProxy); |
299 parser_map["chromeOptions"] = base::Bind(&ParseDesktopChromeCapabilities); | 316 parser_map["chromeOptions"] = |
| 317 base::Bind(&ParseDesktopChromeCapabilities, log); |
300 for (std::map<std::string, Parser>::iterator it = parser_map.begin(); | 318 for (std::map<std::string, Parser>::iterator it = parser_map.begin(); |
301 it != parser_map.end(); ++it) { | 319 it != parser_map.end(); ++it) { |
302 const base::Value* capability = NULL; | 320 const base::Value* capability = NULL; |
303 if (desired_caps.Get(it->first, &capability)) { | 321 if (desired_caps.Get(it->first, &capability)) { |
304 status = it->second.Run(*capability, this); | 322 status = it->second.Run(*capability, this); |
305 if (status.IsError()) | 323 if (status.IsError()) |
306 return status; | 324 return status; |
307 } | 325 } |
308 } | 326 } |
309 return Status(kOk); | 327 return Status(kOk); |
310 } | 328 } |
OLD | NEW |