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

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

Issue 2125123002: [chromedriver] Add page loading strategy to capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed unittests, renamed py tests Created 4 years, 4 months 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
« no previous file with comments | « chrome/test/chromedriver/capabilities.h ('k') | chrome/test/chromedriver/chrome/chrome.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
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/status.h" 24 #include "chrome/test/chromedriver/chrome/status.h"
24 #include "chrome/test/chromedriver/logging.h" 25 #include "chrome/test/chromedriver/logging.h"
25 26
26 namespace { 27 namespace {
27 28
28 typedef base::Callback<Status(const base::Value&, Capabilities*)> Parser; 29 typedef base::Callback<Status(const base::Value&, Capabilities*)> Parser;
29 30
30 Status ParseBoolean( 31 Status ParseBoolean(
31 bool* to_set, 32 bool* to_set,
32 const base::Value& option, 33 const base::Value& option,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 std::string user_agent; 173 std::string user_agent;
173 if (!mobile_emulation->GetString("userAgent", &user_agent)) 174 if (!mobile_emulation->GetString("userAgent", &user_agent))
174 return Status(kUnknownError, "'userAgent' must be a string"); 175 return Status(kUnknownError, "'userAgent' must be a string");
175 176
176 capabilities->switches.SetSwitch("user-agent", user_agent); 177 capabilities->switches.SetSwitch("user-agent", user_agent);
177 } 178 }
178 179
179 return Status(kOk); 180 return Status(kOk);
180 } 181 }
181 182
183 Status ParsePageLoadStrategy(const base::Value& option,
184 Capabilities* capabilities) {
185 if (!option.GetAsString(&capabilities->page_load_strategy))
186 return Status(kUnknownError, "must be a string");
187 if (capabilities->page_load_strategy == PageLoadStrategy::kNormal ||
188 capabilities->page_load_strategy == PageLoadStrategy::kNone)
189 return Status(kOk);
190 return Status(kUnknownError, "page load strategy unsupported");
191 }
192
182 Status ParseSwitches(const base::Value& option, 193 Status ParseSwitches(const base::Value& option,
183 Capabilities* capabilities) { 194 Capabilities* capabilities) {
184 const base::ListValue* switches_list = NULL; 195 const base::ListValue* switches_list = NULL;
185 if (!option.GetAsList(&switches_list)) 196 if (!option.GetAsList(&switches_list))
186 return Status(kUnknownError, "must be a list"); 197 return Status(kUnknownError, "must be a list");
187 for (size_t i = 0; i < switches_list->GetSize(); ++i) { 198 for (size_t i = 0; i < switches_list->GetSize(); ++i) {
188 std::string arg_string; 199 std::string arg_string;
189 if (!switches_list->GetString(i, &arg_string)) 200 if (!switches_list->GetString(i, &arg_string))
190 return Status(kUnknownError, "each argument must be a string"); 201 return Status(kUnknownError, "each argument must be a string");
191 capabilities->switches.SetUnparsedSwitch(arg_string); 202 capabilities->switches.SetUnparsedSwitch(arg_string);
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 timeline(InspectorDomainStatus::kDefaultDisabled), 591 timeline(InspectorDomainStatus::kDefaultDisabled),
581 trace_categories(), 592 trace_categories(),
582 buffer_usage_reporting_interval(1000) {} 593 buffer_usage_reporting_interval(1000) {}
583 594
584 PerfLoggingPrefs::~PerfLoggingPrefs() {} 595 PerfLoggingPrefs::~PerfLoggingPrefs() {}
585 596
586 Capabilities::Capabilities() 597 Capabilities::Capabilities()
587 : android_use_running_app(false), 598 : android_use_running_app(false),
588 detach(false), 599 detach(false),
589 force_devtools_screenshot(false), 600 force_devtools_screenshot(false),
601 page_load_strategy(PageLoadStrategy::kNormal),
590 network_emulation_enabled(false) {} 602 network_emulation_enabled(false) {}
591 603
592 Capabilities::~Capabilities() {} 604 Capabilities::~Capabilities() {}
593 605
594 bool Capabilities::IsAndroid() const { 606 bool Capabilities::IsAndroid() const {
595 return !android_package.empty(); 607 return !android_package.empty();
596 } 608 }
597 609
598 bool Capabilities::IsRemoteBrowser() const { 610 bool Capabilities::IsRemoteBrowser() const {
599 return debugger_address.IsValid(); 611 return debugger_address.IsValid();
600 } 612 }
601 613
602 Status Capabilities::Parse(const base::DictionaryValue& desired_caps) { 614 Status Capabilities::Parse(const base::DictionaryValue& desired_caps) {
603 std::map<std::string, Parser> parser_map; 615 std::map<std::string, Parser> parser_map;
604 parser_map["chromeOptions"] = base::Bind(&ParseChromeOptions); 616 parser_map["chromeOptions"] = base::Bind(&ParseChromeOptions);
605 parser_map["loggingPrefs"] = base::Bind(&ParseLoggingPrefs); 617 parser_map["loggingPrefs"] = base::Bind(&ParseLoggingPrefs);
606 parser_map["proxy"] = base::Bind(&ParseProxy); 618 parser_map["proxy"] = base::Bind(&ParseProxy);
619 parser_map["pageLoadStrategy"] = base::Bind(&ParsePageLoadStrategy);
607 // Network emulation requires device mode, which is only enabled when 620 // Network emulation requires device mode, which is only enabled when
608 // mobile emulation is on. 621 // mobile emulation is on.
609 if (desired_caps.GetDictionary("chromeOptions.mobileEmulation", nullptr)) { 622 if (desired_caps.GetDictionary("chromeOptions.mobileEmulation", nullptr)) {
610 parser_map["networkConnectionEnabled"] = 623 parser_map["networkConnectionEnabled"] =
611 base::Bind(&ParseBoolean, &network_emulation_enabled); 624 base::Bind(&ParseBoolean, &network_emulation_enabled);
612 } 625 }
613 for (std::map<std::string, Parser>::iterator it = parser_map.begin(); 626 for (std::map<std::string, Parser>::iterator it = parser_map.begin();
614 it != parser_map.end(); ++it) { 627 it != parser_map.end(); ++it) {
615 const base::Value* capability = NULL; 628 const base::Value* capability = NULL;
616 if (desired_caps.Get(it->first, &capability)) { 629 if (desired_caps.Get(it->first, &capability)) {
(...skipping 10 matching lines...) Expand all
627 if (iter == logging_prefs.end() || iter->second == Log::kOff) { 640 if (iter == logging_prefs.end() || iter->second == Log::kOff) {
628 const base::DictionaryValue* chrome_options = NULL; 641 const base::DictionaryValue* chrome_options = NULL;
629 if (desired_caps.GetDictionary("chromeOptions", &chrome_options) && 642 if (desired_caps.GetDictionary("chromeOptions", &chrome_options) &&
630 chrome_options->HasKey("perfLoggingPrefs")) { 643 chrome_options->HasKey("perfLoggingPrefs")) {
631 return Status(kUnknownError, "perfLoggingPrefs specified, " 644 return Status(kUnknownError, "perfLoggingPrefs specified, "
632 "but performance logging was not enabled"); 645 "but performance logging was not enabled");
633 } 646 }
634 } 647 }
635 return Status(kOk); 648 return Status(kOk);
636 } 649 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/capabilities.h ('k') | chrome/test/chromedriver/chrome/chrome.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698