| 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/webdriver/webdriver_capabilities_parser.h" | 5 #include "chrome/test/webdriver/webdriver_capabilities_parser.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 struct NameAndParser { | 66 struct NameAndParser { |
| 67 const char* name; | 67 const char* name; |
| 68 Parser parser; | 68 Parser parser; |
| 69 }; | 69 }; |
| 70 NameAndParser name_and_parser[] = { | 70 NameAndParser name_and_parser[] = { |
| 71 { "proxy", &CapabilitiesParser::ParseProxy }, | 71 { "proxy", &CapabilitiesParser::ParseProxy }, |
| 72 { "loggingPrefs", &CapabilitiesParser::ParseLoggingPrefs } | 72 { "loggingPrefs", &CapabilitiesParser::ParseLoggingPrefs } |
| 73 }; | 73 }; |
| 74 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(name_and_parser); ++i) { | 74 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(name_and_parser); ++i) { |
| 75 Value* value; | 75 const Value* value; |
| 76 if (dict_->Get(name_and_parser[i].name, &value)) { | 76 if (dict_->Get(name_and_parser[i].name, &value)) { |
| 77 Error* error = (this->*name_and_parser[i].parser)(value); | 77 Error* error = (this->*name_and_parser[i].parser)(value); |
| 78 if (error) | 78 if (error) |
| 79 return error; | 79 return error; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Parse Chrome custom capabilities (a.k.a., ChromeOptions). | 83 // Parse Chrome custom capabilities (a.k.a., ChromeOptions). |
| 84 const char kOptionsKey[] = "chromeOptions"; | 84 const char kOptionsKey[] = "chromeOptions"; |
| 85 const DictionaryValue* options = dict_; | 85 const DictionaryValue* options = dict_; |
| 86 bool legacy_options = true; | 86 bool legacy_options = true; |
| 87 Value* options_value; | 87 const Value* options_value; |
| 88 if (dict_->Get(kOptionsKey, &options_value)) { | 88 if (dict_->Get(kOptionsKey, &options_value)) { |
| 89 legacy_options = false; | 89 legacy_options = false; |
| 90 if (options_value->IsType(Value::TYPE_DICTIONARY)) { | 90 if (options_value->IsType(Value::TYPE_DICTIONARY)) { |
| 91 options = static_cast<DictionaryValue*>(options_value); | 91 options = static_cast<const DictionaryValue*>(options_value); |
| 92 } else { | 92 } else { |
| 93 return CreateBadInputError( | 93 return CreateBadInputError( |
| 94 kOptionsKey, Value::TYPE_DICTIONARY, options_value); | 94 kOptionsKey, Value::TYPE_DICTIONARY, options_value); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 std::map<std::string, Parser> parser_map; | 98 std::map<std::string, Parser> parser_map; |
| 99 if (legacy_options) { | 99 if (legacy_options) { |
| 100 parser_map["chrome.binary"] = &CapabilitiesParser::ParseBinary; | 100 parser_map["chrome.binary"] = &CapabilitiesParser::ParseBinary; |
| 101 parser_map["chrome.channel"] = &CapabilitiesParser::ParseChannel; | 101 parser_map["chrome.channel"] = &CapabilitiesParser::ParseChannel; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 DictionaryValue::key_iterator key_iter = options->begin_keys(); | 127 DictionaryValue::key_iterator key_iter = options->begin_keys(); |
| 128 for (; key_iter != options->end_keys(); ++key_iter) { | 128 for (; key_iter != options->end_keys(); ++key_iter) { |
| 129 if (parser_map.find(*key_iter) == parser_map.end()) { | 129 if (parser_map.find(*key_iter) == parser_map.end()) { |
| 130 if (!legacy_options) | 130 if (!legacy_options) |
| 131 return new Error(kBadRequest, | 131 return new Error(kBadRequest, |
| 132 "Unrecognized chrome capability: " + *key_iter); | 132 "Unrecognized chrome capability: " + *key_iter); |
| 133 continue; | 133 continue; |
| 134 } | 134 } |
| 135 Value* option = NULL; | 135 const Value* option = NULL; |
| 136 options->GetWithoutPathExpansion(*key_iter, &option); | 136 options->GetWithoutPathExpansion(*key_iter, &option); |
| 137 Error* error = (this->*parser_map[*key_iter])(option); | 137 Error* error = (this->*parser_map[*key_iter])(option); |
| 138 if (error) { | 138 if (error) { |
| 139 error->AddDetails(base::StringPrintf( | 139 error->AddDetails(base::StringPrintf( |
| 140 "Error occurred while processing capability '%s'", | 140 "Error occurred while processing capability '%s'", |
| 141 (*key_iter).c_str())); | 141 (*key_iter).c_str())); |
| 142 return error; | 142 return error; |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 return NULL; | 145 return NULL; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 const DictionaryValue* logging_prefs; | 231 const DictionaryValue* logging_prefs; |
| 232 if (!option->GetAsDictionary(&logging_prefs)) | 232 if (!option->GetAsDictionary(&logging_prefs)) |
| 233 return CreateBadInputError("loggingPrefs", Value::TYPE_DICTIONARY, option); | 233 return CreateBadInputError("loggingPrefs", Value::TYPE_DICTIONARY, option); |
| 234 | 234 |
| 235 DictionaryValue::key_iterator key_iter = logging_prefs->begin_keys(); | 235 DictionaryValue::key_iterator key_iter = logging_prefs->begin_keys(); |
| 236 for (; key_iter != logging_prefs->end_keys(); ++key_iter) { | 236 for (; key_iter != logging_prefs->end_keys(); ++key_iter) { |
| 237 LogType log_type; | 237 LogType log_type; |
| 238 if (!LogType::FromString(*key_iter, &log_type)) | 238 if (!LogType::FromString(*key_iter, &log_type)) |
| 239 continue; | 239 continue; |
| 240 | 240 |
| 241 Value* level_value; | 241 const Value* level_value; |
| 242 logging_prefs->Get(*key_iter, &level_value); | 242 logging_prefs->Get(*key_iter, &level_value); |
| 243 std::string level_name; | 243 std::string level_name; |
| 244 if (!level_value->GetAsString(&level_name)) { | 244 if (!level_value->GetAsString(&level_name)) { |
| 245 return CreateBadInputError( | 245 return CreateBadInputError( |
| 246 std::string("loggingPrefs.") + *key_iter, | 246 std::string("loggingPrefs.") + *key_iter, |
| 247 Value::TYPE_STRING, | 247 Value::TYPE_STRING, |
| 248 level_value); | 248 level_value); |
| 249 } | 249 } |
| 250 caps_->log_levels[log_type.type()] = LogLevelFromString(level_name); | 250 caps_->log_levels[log_type.type()] = LogLevelFromString(level_name); |
| 251 } | 251 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 typedef Error* (CapabilitiesParser::*Parser)(const DictionaryValue*); | 303 typedef Error* (CapabilitiesParser::*Parser)(const DictionaryValue*); |
| 304 std::map<std::string, Parser> proxy_type_parser_map; | 304 std::map<std::string, Parser> proxy_type_parser_map; |
| 305 proxy_type_parser_map["autodetect"] = | 305 proxy_type_parser_map["autodetect"] = |
| 306 &CapabilitiesParser::ParseProxyAutoDetect; | 306 &CapabilitiesParser::ParseProxyAutoDetect; |
| 307 proxy_type_parser_map["pac"] = | 307 proxy_type_parser_map["pac"] = |
| 308 &CapabilitiesParser::ParseProxyAutoconfigUrl; | 308 &CapabilitiesParser::ParseProxyAutoconfigUrl; |
| 309 proxy_type_parser_map["manual"] = &CapabilitiesParser::ParseProxyServers; | 309 proxy_type_parser_map["manual"] = &CapabilitiesParser::ParseProxyServers; |
| 310 proxy_type_parser_map["direct"] = NULL; | 310 proxy_type_parser_map["direct"] = NULL; |
| 311 proxy_type_parser_map["system"] = NULL; | 311 proxy_type_parser_map["system"] = NULL; |
| 312 | 312 |
| 313 Value* proxy_type_value; | 313 const Value* proxy_type_value; |
| 314 if (!options->Get("proxyType", &proxy_type_value)) | 314 if (!options->Get("proxyType", &proxy_type_value)) |
| 315 return new Error(kBadRequest, "Missing 'proxyType' capability."); | 315 return new Error(kBadRequest, "Missing 'proxyType' capability."); |
| 316 | 316 |
| 317 std::string proxy_type; | 317 std::string proxy_type; |
| 318 if (!proxy_type_value->GetAsString(&proxy_type)) | 318 if (!proxy_type_value->GetAsString(&proxy_type)) |
| 319 return CreateBadInputError("proxyType", Value::TYPE_STRING, | 319 return CreateBadInputError("proxyType", Value::TYPE_STRING, |
| 320 proxy_type_value); | 320 proxy_type_value); |
| 321 | 321 |
| 322 proxy_type = StringToLowerASCII(proxy_type); | 322 proxy_type = StringToLowerASCII(proxy_type); |
| 323 if (proxy_type_parser_map.find(proxy_type) == proxy_type_parser_map.end()) | 323 if (proxy_type_parser_map.find(proxy_type) == proxy_type_parser_map.end()) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 const char kFtpProxy[] = "ftpProxy"; | 367 const char kFtpProxy[] = "ftpProxy"; |
| 368 const char kHttpProxy[] = "httpProxy"; | 368 const char kHttpProxy[] = "httpProxy"; |
| 369 const char kSslProxy[] = "sslProxy"; | 369 const char kSslProxy[] = "sslProxy"; |
| 370 | 370 |
| 371 std::set<std::string> proxy_servers_options; | 371 std::set<std::string> proxy_servers_options; |
| 372 proxy_servers_options.insert(kFtpProxy); | 372 proxy_servers_options.insert(kFtpProxy); |
| 373 proxy_servers_options.insert(kHttpProxy); | 373 proxy_servers_options.insert(kHttpProxy); |
| 374 proxy_servers_options.insert(kSslProxy); | 374 proxy_servers_options.insert(kSslProxy); |
| 375 | 375 |
| 376 Error* error = NULL; | 376 Error* error = NULL; |
| 377 Value* option = NULL; | 377 const Value* option = NULL; |
| 378 bool has_manual_settings = false; | 378 bool has_manual_settings = false; |
| 379 if (options->Get(kNoProxy, &option) && !option->IsType(Value::TYPE_NULL)) { | 379 if (options->Get(kNoProxy, &option) && !option->IsType(Value::TYPE_NULL)) { |
| 380 error = ParseNoProxy(option); | 380 error = ParseNoProxy(option); |
| 381 if (error) | 381 if (error) |
| 382 return error; | 382 return error; |
| 383 has_manual_settings = true; | 383 has_manual_settings = true; |
| 384 } | 384 } |
| 385 | 385 |
| 386 std::vector<std::string> proxy_servers; | 386 std::vector<std::string> proxy_servers; |
| 387 std::set<std::string>::const_iterator iter = proxy_servers_options.begin(); | 387 std::set<std::string>::const_iterator iter = proxy_servers_options.begin(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 424 } |
| 425 | 425 |
| 426 Error* CapabilitiesParser::ParseNoWebsiteTestingDefaults(const Value* option) { | 426 Error* CapabilitiesParser::ParseNoWebsiteTestingDefaults(const Value* option) { |
| 427 if (!option->GetAsBoolean(&caps_->no_website_testing_defaults)) | 427 if (!option->GetAsBoolean(&caps_->no_website_testing_defaults)) |
| 428 return CreateBadInputError("noWebsiteTestingDefaults", | 428 return CreateBadInputError("noWebsiteTestingDefaults", |
| 429 Value::TYPE_BOOLEAN, option); | 429 Value::TYPE_BOOLEAN, option); |
| 430 return NULL; | 430 return NULL; |
| 431 } | 431 } |
| 432 | 432 |
| 433 } // namespace webdriver | 433 } // namespace webdriver |
| OLD | NEW |