OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webdriver/webdriver_capabilities_parser.h" | 5 #include "chrome/test/webdriver/webdriver_capabilities_parser.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 JsonStringifyForDisplay(option).c_str())); | 30 JsonStringifyForDisplay(option).c_str())); |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 Capabilities::Capabilities() | 35 Capabilities::Capabilities() |
36 : command(CommandLine::NO_PROGRAM), | 36 : command(CommandLine::NO_PROGRAM), |
37 detach(false), | 37 detach(false), |
38 load_async(false), | 38 load_async(false), |
39 native_events(false), | 39 native_events(false), |
| 40 no_website_testing_defaults(false), |
40 verbose(false) { } | 41 verbose(false) { } |
41 | 42 |
42 Capabilities::~Capabilities() { } | 43 Capabilities::~Capabilities() { } |
43 | 44 |
44 CapabilitiesParser::CapabilitiesParser( | 45 CapabilitiesParser::CapabilitiesParser( |
45 const base::DictionaryValue* capabilities_dict, | 46 const base::DictionaryValue* capabilities_dict, |
46 const FilePath& root_path, | 47 const FilePath& root_path, |
47 Capabilities* capabilities) | 48 Capabilities* capabilities) |
48 : dict_(capabilities_dict), | 49 : dict_(capabilities_dict), |
49 root_(root_path), | 50 root_(root_path), |
(...skipping 21 matching lines...) Expand all Loading... |
71 std::map<std::string, Parser> parser_map; | 72 std::map<std::string, Parser> parser_map; |
72 if (legacy_options) { | 73 if (legacy_options) { |
73 parser_map["chrome.binary"] = &CapabilitiesParser::ParseBinary; | 74 parser_map["chrome.binary"] = &CapabilitiesParser::ParseBinary; |
74 parser_map["chrome.channel"] = &CapabilitiesParser::ParseChannel; | 75 parser_map["chrome.channel"] = &CapabilitiesParser::ParseChannel; |
75 parser_map["chrome.detach"] = &CapabilitiesParser::ParseDetach; | 76 parser_map["chrome.detach"] = &CapabilitiesParser::ParseDetach; |
76 parser_map["chrome.extensions"] = &CapabilitiesParser::ParseExtensions; | 77 parser_map["chrome.extensions"] = &CapabilitiesParser::ParseExtensions; |
77 parser_map["chrome.loadAsync"] = &CapabilitiesParser::ParseLoadAsync; | 78 parser_map["chrome.loadAsync"] = &CapabilitiesParser::ParseLoadAsync; |
78 parser_map["chrome.nativeEvents"] = &CapabilitiesParser::ParseNativeEvents; | 79 parser_map["chrome.nativeEvents"] = &CapabilitiesParser::ParseNativeEvents; |
79 parser_map["chrome.profile"] = &CapabilitiesParser::ParseProfile; | 80 parser_map["chrome.profile"] = &CapabilitiesParser::ParseProfile; |
80 parser_map["chrome.switches"] = &CapabilitiesParser::ParseArgs; | 81 parser_map["chrome.switches"] = &CapabilitiesParser::ParseArgs; |
| 82 parser_map["chrome.noWebsiteTestingDefaults"] = |
| 83 &CapabilitiesParser::ParseNoWebsiteTestingDefaults; |
81 parser_map["chrome.verbose"] = &CapabilitiesParser::ParseVerbose; | 84 parser_map["chrome.verbose"] = &CapabilitiesParser::ParseVerbose; |
82 } else { | 85 } else { |
83 parser_map["args"] = &CapabilitiesParser::ParseArgs; | 86 parser_map["args"] = &CapabilitiesParser::ParseArgs; |
84 parser_map["binary"] = &CapabilitiesParser::ParseBinary; | 87 parser_map["binary"] = &CapabilitiesParser::ParseBinary; |
85 parser_map["channel"] = &CapabilitiesParser::ParseChannel; | 88 parser_map["channel"] = &CapabilitiesParser::ParseChannel; |
86 parser_map["detach"] = &CapabilitiesParser::ParseDetach; | 89 parser_map["detach"] = &CapabilitiesParser::ParseDetach; |
87 parser_map["extensions"] = &CapabilitiesParser::ParseExtensions; | 90 parser_map["extensions"] = &CapabilitiesParser::ParseExtensions; |
88 parser_map["loadAsync"] = &CapabilitiesParser::ParseLoadAsync; | 91 parser_map["loadAsync"] = &CapabilitiesParser::ParseLoadAsync; |
89 parser_map["nativeEvents"] = &CapabilitiesParser::ParseNativeEvents; | 92 parser_map["nativeEvents"] = &CapabilitiesParser::ParseNativeEvents; |
90 parser_map["profile"] = &CapabilitiesParser::ParseProfile; | 93 parser_map["profile"] = &CapabilitiesParser::ParseProfile; |
| 94 parser_map["noWebsiteTestingDefaults"] = |
| 95 &CapabilitiesParser::ParseNoWebsiteTestingDefaults; |
91 parser_map["verbose"] = &CapabilitiesParser::ParseVerbose; | 96 parser_map["verbose"] = &CapabilitiesParser::ParseVerbose; |
92 } | 97 } |
93 | 98 |
94 base::DictionaryValue::key_iterator key_iter = options->begin_keys(); | 99 base::DictionaryValue::key_iterator key_iter = options->begin_keys(); |
95 for (; key_iter != options->end_keys(); ++key_iter) { | 100 for (; key_iter != options->end_keys(); ++key_iter) { |
96 if (parser_map.find(*key_iter) == parser_map.end()) { | 101 if (parser_map.find(*key_iter) == parser_map.end()) { |
97 LOG(WARNING) << "Ignoring unrecognized capability: " << *key_iter; | 102 LOG(WARNING) << "Ignoring unrecognized capability: " << *key_iter; |
98 continue; | 103 continue; |
99 } | 104 } |
100 Value* option = NULL; | 105 Value* option = NULL; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 if (!option->GetAsString(&profile_base64)) | 200 if (!option->GetAsString(&profile_base64)) |
196 return CreateBadInputError("profile", Value::TYPE_STRING, option); | 201 return CreateBadInputError("profile", Value::TYPE_STRING, option); |
197 std::string error_msg; | 202 std::string error_msg; |
198 caps_->profile = root_.AppendASCII("profile"); | 203 caps_->profile = root_.AppendASCII("profile"); |
199 if (!DecodeAndWriteFile(caps_->profile, profile_base64, true /* unzip */, | 204 if (!DecodeAndWriteFile(caps_->profile, profile_base64, true /* unzip */, |
200 &error_msg)) | 205 &error_msg)) |
201 return new Error(kUnknownError, "unable to unpack profile: " + error_msg); | 206 return new Error(kUnknownError, "unable to unpack profile: " + error_msg); |
202 return NULL; | 207 return NULL; |
203 } | 208 } |
204 | 209 |
| 210 Error* CapabilitiesParser::ParseNoWebsiteTestingDefaults(const Value* option) { |
| 211 if (!option->GetAsBoolean(&caps_->no_website_testing_defaults)) |
| 212 return CreateBadInputError("noWebsiteTestingDefaults", |
| 213 Value::TYPE_BOOLEAN, option); |
| 214 return NULL; |
| 215 } |
| 216 |
205 Error* CapabilitiesParser::ParseVerbose(const Value* option) { | 217 Error* CapabilitiesParser::ParseVerbose(const Value* option) { |
206 if (!option->GetAsBoolean(&caps_->verbose)) | 218 if (!option->GetAsBoolean(&caps_->verbose)) |
207 return CreateBadInputError("verbose", Value::TYPE_BOOLEAN, option); | 219 return CreateBadInputError("verbose", Value::TYPE_BOOLEAN, option); |
208 return NULL; | 220 return NULL; |
209 } | 221 } |
210 | 222 |
211 bool CapabilitiesParser::DecodeAndWriteFile( | 223 bool CapabilitiesParser::DecodeAndWriteFile( |
212 const FilePath& path, | 224 const FilePath& path, |
213 const std::string& base64, | 225 const std::string& base64, |
214 bool unzip, | 226 bool unzip, |
(...skipping 16 matching lines...) Expand all Loading... |
231 } else { | 243 } else { |
232 if (!file_util::WriteFile(path, data.c_str(), data.length())) { | 244 if (!file_util::WriteFile(path, data.c_str(), data.length())) { |
233 *error_msg = "Could not write file"; | 245 *error_msg = "Could not write file"; |
234 return false; | 246 return false; |
235 } | 247 } |
236 } | 248 } |
237 return true; | 249 return true; |
238 } | 250 } |
239 | 251 |
240 } // namespace webdriver | 252 } // namespace webdriver |
OLD | NEW |