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/logging.h" | |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 14 #include "base/values.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 const char* option_name, | |
31 const base::Value& option, | |
32 Capabilities* capabilities) { | |
33 LOG(WARNING) << "deprecated option is ignored:" << option_name; | |
kkania
2013/08/12 17:13:04
really this should go in the per session log
chrisgao (Use stgao instead)
2013/08/12 20:14:34
Done.
| |
34 return Status(kOk); | |
35 } | |
36 | |
28 Status ParseChromeBinary( | 37 Status ParseChromeBinary( |
29 const base::Value& option, | 38 const base::Value& option, |
30 Capabilities* capabilities) { | 39 Capabilities* capabilities) { |
31 base::FilePath::StringType path_str; | 40 base::FilePath::StringType path_str; |
32 if (!option.GetAsString(&path_str)) | 41 if (!option.GetAsString(&path_str)) |
33 return Status(kUnknownError, "'binary' must be a string"); | 42 return Status(kUnknownError, "'binary' must be a string"); |
34 base::FilePath chrome_exe(path_str); | 43 base::FilePath chrome_exe(path_str); |
35 capabilities->command.SetProgram(chrome_exe); | 44 capabilities->command.SetProgram(chrome_exe); |
36 return Status(kOk); | 45 return Status(kOk); |
37 } | 46 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 Status ParseDesktopChromeCapabilities( | 182 Status ParseDesktopChromeCapabilities( |
174 const base::Value& capability, | 183 const base::Value& capability, |
175 Capabilities* capabilities) { | 184 Capabilities* capabilities) { |
176 const base::DictionaryValue* chrome_options = NULL; | 185 const base::DictionaryValue* chrome_options = NULL; |
177 if (!capability.GetAsDictionary(&chrome_options)) | 186 if (!capability.GetAsDictionary(&chrome_options)) |
178 return Status(kUnknownError, "'chromeOptions' must be a dictionary"); | 187 return Status(kUnknownError, "'chromeOptions' must be a dictionary"); |
179 | 188 |
180 std::map<std::string, Parser> parser_map; | 189 std::map<std::string, Parser> parser_map; |
181 | 190 |
182 parser_map["detach"] = base::Bind(&ParseDetach); | 191 parser_map["detach"] = base::Bind(&ParseDetach); |
192 parser_map["loadAsync"] = base::Bind(&IgnoreDeprecatedOption, "loadAsync"); | |
183 parser_map["binary"] = base::Bind(&ParseChromeBinary); | 193 parser_map["binary"] = base::Bind(&ParseChromeBinary); |
184 parser_map["logPath"] = base::Bind(&ParseLogPath); | 194 parser_map["logPath"] = base::Bind(&ParseLogPath); |
185 parser_map["args"] = base::Bind(&ParseArgs, false); | 195 parser_map["args"] = base::Bind(&ParseArgs, false); |
186 parser_map["prefs"] = base::Bind(&ParsePrefs); | 196 parser_map["prefs"] = base::Bind(&ParsePrefs); |
187 parser_map["localState"] = base::Bind(&ParseLocalState); | 197 parser_map["localState"] = base::Bind(&ParseLocalState); |
188 parser_map["extensions"] = base::Bind(&ParseExtensions); | 198 parser_map["extensions"] = base::Bind(&ParseExtensions); |
189 | 199 |
190 for (base::DictionaryValue::Iterator it(*chrome_options); !it.IsAtEnd(); | 200 for (base::DictionaryValue::Iterator it(*chrome_options); !it.IsAtEnd(); |
191 it.Advance()) { | 201 it.Advance()) { |
192 if (parser_map.find(it.key()) == parser_map.end()) { | 202 if (parser_map.find(it.key()) == parser_map.end()) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 it != parser_map.end(); ++it) { | 311 it != parser_map.end(); ++it) { |
302 const base::Value* capability = NULL; | 312 const base::Value* capability = NULL; |
303 if (desired_caps.Get(it->first, &capability)) { | 313 if (desired_caps.Get(it->first, &capability)) { |
304 status = it->second.Run(*capability, this); | 314 status = it->second.Run(*capability, this); |
305 if (status.IsError()) | 315 if (status.IsError()) |
306 return status; | 316 return status; |
307 } | 317 } |
308 } | 318 } |
309 return Status(kOk); | 319 return Status(kOk); |
310 } | 320 } |
OLD | NEW |