| 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/json/string_escape.h" | 11 #include "base/json/string_escape.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 16 #include "base/strings/string_tokenizer.h" | 16 #include "base/strings/string_tokenizer.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "chrome/test/chromedriver/chrome/mobile_device.h" | 22 #include "chrome/test/chromedriver/chrome/mobile_device.h" |
| 23 #include "chrome/test/chromedriver/chrome/page_load_strategy.h" | 23 #include "chrome/test/chromedriver/chrome/page_load_strategy.h" |
| 24 #include "chrome/test/chromedriver/chrome/status.h" | 24 #include "chrome/test/chromedriver/chrome/status.h" |
| 25 #include "chrome/test/chromedriver/logging.h" | 25 #include "chrome/test/chromedriver/logging.h" |
| 26 #include "chrome/test/chromedriver/session.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 typedef base::Callback<Status(const base::Value&, Capabilities*)> Parser; | 30 typedef base::Callback<Status(const base::Value&, Capabilities*)> Parser; |
| 30 | 31 |
| 31 Status ParseBoolean( | 32 Status ParseBoolean( |
| 32 bool* to_set, | 33 bool* to_set, |
| 33 const base::Value& option, | 34 const base::Value& option, |
| 34 Capabilities* capabilities) { | 35 Capabilities* capabilities) { |
| 35 if (!option.GetAsBoolean(to_set)) | 36 if (!option.GetAsBoolean(to_set)) |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 Status ParsePageLoadStrategy(const base::Value& option, | 184 Status ParsePageLoadStrategy(const base::Value& option, |
| 184 Capabilities* capabilities) { | 185 Capabilities* capabilities) { |
| 185 if (!option.GetAsString(&capabilities->page_load_strategy)) | 186 if (!option.GetAsString(&capabilities->page_load_strategy)) |
| 186 return Status(kUnknownError, "must be a string"); | 187 return Status(kUnknownError, "must be a string"); |
| 187 if (capabilities->page_load_strategy == PageLoadStrategy::kNormal || | 188 if (capabilities->page_load_strategy == PageLoadStrategy::kNormal || |
| 188 capabilities->page_load_strategy == PageLoadStrategy::kNone) | 189 capabilities->page_load_strategy == PageLoadStrategy::kNone) |
| 189 return Status(kOk); | 190 return Status(kOk); |
| 190 return Status(kUnknownError, "page load strategy unsupported"); | 191 return Status(kUnknownError, "page load strategy unsupported"); |
| 191 } | 192 } |
| 192 | 193 |
| 194 Status ParseUnexpectedAlertBehaviour(const base::Value& option, |
| 195 Capabilities* capabilities) { |
| 196 if (!option.GetAsString(&capabilities->unexpected_alert_behaviour)) |
| 197 return Status(kUnknownError, "must be a string"); |
| 198 if (capabilities->unexpected_alert_behaviour == Session::kAccept || |
| 199 capabilities->unexpected_alert_behaviour == Session::kDismiss || |
| 200 capabilities->unexpected_alert_behaviour == Session::kIgnore) |
| 201 return Status(kOk); |
| 202 return Status(kUnknownError, "unexpected alert behaviour unsupported"); |
| 203 } |
| 204 |
| 193 Status ParseSwitches(const base::Value& option, | 205 Status ParseSwitches(const base::Value& option, |
| 194 Capabilities* capabilities) { | 206 Capabilities* capabilities) { |
| 195 const base::ListValue* switches_list = NULL; | 207 const base::ListValue* switches_list = NULL; |
| 196 if (!option.GetAsList(&switches_list)) | 208 if (!option.GetAsList(&switches_list)) |
| 197 return Status(kUnknownError, "must be a list"); | 209 return Status(kUnknownError, "must be a list"); |
| 198 for (size_t i = 0; i < switches_list->GetSize(); ++i) { | 210 for (size_t i = 0; i < switches_list->GetSize(); ++i) { |
| 199 std::string arg_string; | 211 std::string arg_string; |
| 200 if (!switches_list->GetString(i, &arg_string)) | 212 if (!switches_list->GetString(i, &arg_string)) |
| 201 return Status(kUnknownError, "each argument must be a string"); | 213 return Status(kUnknownError, "each argument must be a string"); |
| 202 capabilities->switches.SetUnparsedSwitch(arg_string); | 214 capabilities->switches.SetUnparsedSwitch(arg_string); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 bool Capabilities::IsRemoteBrowser() const { | 625 bool Capabilities::IsRemoteBrowser() const { |
| 614 return debugger_address.IsValid(); | 626 return debugger_address.IsValid(); |
| 615 } | 627 } |
| 616 | 628 |
| 617 Status Capabilities::Parse(const base::DictionaryValue& desired_caps) { | 629 Status Capabilities::Parse(const base::DictionaryValue& desired_caps) { |
| 618 std::map<std::string, Parser> parser_map; | 630 std::map<std::string, Parser> parser_map; |
| 619 parser_map["chromeOptions"] = base::Bind(&ParseChromeOptions); | 631 parser_map["chromeOptions"] = base::Bind(&ParseChromeOptions); |
| 620 parser_map["loggingPrefs"] = base::Bind(&ParseLoggingPrefs); | 632 parser_map["loggingPrefs"] = base::Bind(&ParseLoggingPrefs); |
| 621 parser_map["proxy"] = base::Bind(&ParseProxy); | 633 parser_map["proxy"] = base::Bind(&ParseProxy); |
| 622 parser_map["pageLoadStrategy"] = base::Bind(&ParsePageLoadStrategy); | 634 parser_map["pageLoadStrategy"] = base::Bind(&ParsePageLoadStrategy); |
| 635 parser_map["unexpectedAlertBehaviour"] = |
| 636 base::Bind(&ParseUnexpectedAlertBehaviour); |
| 623 // Network emulation requires device mode, which is only enabled when | 637 // Network emulation requires device mode, which is only enabled when |
| 624 // mobile emulation is on. | 638 // mobile emulation is on. |
| 625 if (desired_caps.GetDictionary("chromeOptions.mobileEmulation", nullptr)) { | 639 if (desired_caps.GetDictionary("chromeOptions.mobileEmulation", nullptr)) { |
| 626 parser_map["networkConnectionEnabled"] = | 640 parser_map["networkConnectionEnabled"] = |
| 627 base::Bind(&ParseBoolean, &network_emulation_enabled); | 641 base::Bind(&ParseBoolean, &network_emulation_enabled); |
| 628 } | 642 } |
| 629 for (std::map<std::string, Parser>::iterator it = parser_map.begin(); | 643 for (std::map<std::string, Parser>::iterator it = parser_map.begin(); |
| 630 it != parser_map.end(); ++it) { | 644 it != parser_map.end(); ++it) { |
| 631 const base::Value* capability = NULL; | 645 const base::Value* capability = NULL; |
| 632 if (desired_caps.Get(it->first, &capability)) { | 646 if (desired_caps.Get(it->first, &capability)) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 643 if (iter == logging_prefs.end() || iter->second == Log::kOff) { | 657 if (iter == logging_prefs.end() || iter->second == Log::kOff) { |
| 644 const base::DictionaryValue* chrome_options = NULL; | 658 const base::DictionaryValue* chrome_options = NULL; |
| 645 if (desired_caps.GetDictionary("chromeOptions", &chrome_options) && | 659 if (desired_caps.GetDictionary("chromeOptions", &chrome_options) && |
| 646 chrome_options->HasKey("perfLoggingPrefs")) { | 660 chrome_options->HasKey("perfLoggingPrefs")) { |
| 647 return Status(kUnknownError, "perfLoggingPrefs specified, " | 661 return Status(kUnknownError, "perfLoggingPrefs specified, " |
| 648 "but performance logging was not enabled"); | 662 "but performance logging was not enabled"); |
| 649 } | 663 } |
| 650 } | 664 } |
| 651 return Status(kOk); | 665 return Status(kOk); |
| 652 } | 666 } |
| OLD | NEW |