Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/test/chromedriver/capabilities.cc

Issue 1827003004: [Chromedriver] Chromedriver should handle unexpected alert automatically. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New modifications Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 Status ParsePageLoadStrategy(const base::Value& option, 183 Status ParsePageLoadStrategy(const base::Value& option,
184 Capabilities* capabilities) { 184 Capabilities* capabilities) {
185 if (!option.GetAsString(&capabilities->page_load_strategy)) 185 if (!option.GetAsString(&capabilities->page_load_strategy))
186 return Status(kUnknownError, "must be a string"); 186 return Status(kUnknownError, "must be a string");
187 if (capabilities->page_load_strategy == PageLoadStrategy::kNormal || 187 if (capabilities->page_load_strategy == PageLoadStrategy::kNormal ||
188 capabilities->page_load_strategy == PageLoadStrategy::kNone) 188 capabilities->page_load_strategy == PageLoadStrategy::kNone)
189 return Status(kOk); 189 return Status(kOk);
190 return Status(kUnknownError, "page load strategy unsupported"); 190 return Status(kUnknownError, "page load strategy unsupported");
191 } 191 }
192 192
193 Status ParseUnexpectedAlertBehaviour(const base::Value& option,
194 Capabilities* capabilities) {
195 if (!option.GetAsString(&capabilities->unexpected_alert_behaviour))
196 return Status(kUnknownError, "must be a string");
197 if (capabilities->unexpected_alert_behaviour == "accept" ||
198 capabilities->unexpected_alert_behaviour == "dismiss" ||
199 capabilities->unexpected_alert_behaviour == "ignore")
200 return Status(kOk);
201 return Status(kUnknownError, "unexpected alert behaviour unsupported");
202 }
203
193 Status ParseSwitches(const base::Value& option, 204 Status ParseSwitches(const base::Value& option,
194 Capabilities* capabilities) { 205 Capabilities* capabilities) {
195 const base::ListValue* switches_list = NULL; 206 const base::ListValue* switches_list = NULL;
196 if (!option.GetAsList(&switches_list)) 207 if (!option.GetAsList(&switches_list))
197 return Status(kUnknownError, "must be a list"); 208 return Status(kUnknownError, "must be a list");
198 for (size_t i = 0; i < switches_list->GetSize(); ++i) { 209 for (size_t i = 0; i < switches_list->GetSize(); ++i) {
199 std::string arg_string; 210 std::string arg_string;
200 if (!switches_list->GetString(i, &arg_string)) 211 if (!switches_list->GetString(i, &arg_string))
201 return Status(kUnknownError, "each argument must be a string"); 212 return Status(kUnknownError, "each argument must be a string");
202 capabilities->switches.SetUnparsedSwitch(arg_string); 213 capabilities->switches.SetUnparsedSwitch(arg_string);
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 trace_categories(), 606 trace_categories(),
596 buffer_usage_reporting_interval(1000) {} 607 buffer_usage_reporting_interval(1000) {}
597 608
598 PerfLoggingPrefs::~PerfLoggingPrefs() {} 609 PerfLoggingPrefs::~PerfLoggingPrefs() {}
599 610
600 Capabilities::Capabilities() 611 Capabilities::Capabilities()
601 : android_use_running_app(false), 612 : android_use_running_app(false),
602 detach(false), 613 detach(false),
603 force_devtools_screenshot(false), 614 force_devtools_screenshot(false),
604 page_load_strategy(PageLoadStrategy::kNormal), 615 page_load_strategy(PageLoadStrategy::kNormal),
616 unexpected_alert_behaviour(""),
samuong 2016/11/02 22:48:48 should this be the empty string, or "ignore"?
gmanikpure 2016/11/04 00:23:24 Done.Making ignore value as default.
605 network_emulation_enabled(false) {} 617 network_emulation_enabled(false) {}
606 618
607 Capabilities::~Capabilities() {} 619 Capabilities::~Capabilities() {}
608 620
609 bool Capabilities::IsAndroid() const { 621 bool Capabilities::IsAndroid() const {
610 return !android_package.empty(); 622 return !android_package.empty();
611 } 623 }
612 624
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698