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" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 std::string level_name; | 295 std::string level_name; |
296 if (!pref.value().GetAsString(&level_name) || | 296 if (!pref.value().GetAsString(&level_name) || |
297 !WebDriverLog::NameToLevel(level_name, &level)) { | 297 !WebDriverLog::NameToLevel(level_name, &level)) { |
298 return Status(kUnknownError, "invalid log level for '" + type + "' log"); | 298 return Status(kUnknownError, "invalid log level for '" + type + "' log"); |
299 } | 299 } |
300 capabilities->logging_prefs.insert(std::make_pair(type, level)); | 300 capabilities->logging_prefs.insert(std::make_pair(type, level)); |
301 } | 301 } |
302 return Status(kOk); | 302 return Status(kOk); |
303 } | 303 } |
304 | 304 |
305 Status ParseInspectorDomainStatus( | |
306 PerfLoggingPrefs::InspectorDomainStatus* to_set, | |
307 const base::Value& option, | |
308 Capabilities* capabilities) { | |
309 bool desired_value; | |
310 if (!option.GetAsBoolean(&desired_value)) | |
311 return Status(kUnknownError, "must be a boolean"); | |
samuong
2014/08/04 06:08:22
Please also include what parameter was set incorre
johnmoore
2014/08/04 17:37:57
The parameter name will be appended to the status
| |
312 if (desired_value) { | |
313 *to_set = PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyEnabled; | |
314 } else { | |
315 *to_set = PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyDisabled; | |
316 } | |
samuong
2014/08/04 06:08:22
Don't need the braces in this if-else statement.
johnmoore
2014/08/04 17:37:57
Done.
| |
317 return Status(kOk); | |
318 } | |
319 | |
320 Status ParsePerfLoggingPrefs(const base::Value& option, | |
321 Capabilities* capabilities) { | |
322 const base::DictionaryValue* perf_logging_prefs = NULL; | |
323 if (!option.GetAsDictionary(&perf_logging_prefs)) | |
324 return Status(kUnknownError, "must be a dictionary"); | |
samuong
2014/08/04 06:08:22
Please also include what parameter was set incorre
johnmoore
2014/08/04 17:37:57
Similar to above, the parameter name will be appen
| |
325 | |
326 std::map<std::string, Parser> parser_map; | |
327 parser_map["enableNetwork"] = base::Bind( | |
328 &ParseInspectorDomainStatus, &capabilities->perf_logging_prefs.network); | |
329 parser_map["enablePage"] = base::Bind( | |
330 &ParseInspectorDomainStatus, &capabilities->perf_logging_prefs.page); | |
331 parser_map["enableTimeline"] = base::Bind( | |
332 &ParseInspectorDomainStatus, &capabilities->perf_logging_prefs.timeline); | |
333 parser_map["traceCategories"] = base::Bind( | |
334 &ParseString, &capabilities->perf_logging_prefs.trace_categories); | |
335 | |
336 for (base::DictionaryValue::Iterator it(*perf_logging_prefs); !it.IsAtEnd(); | |
337 it.Advance()) { | |
338 if (parser_map.find(it.key()) == parser_map.end()) | |
339 return Status(kUnknownError, "unrecognized option: " + it.key()); | |
340 Status status = parser_map[it.key()].Run(it.value(), capabilities); | |
341 if (status.IsError()) | |
342 return Status(kUnknownError, "cannot parse " + it.key(), status); | |
343 } | |
344 return Status(kOk); | |
345 } | |
346 | |
305 Status ParseChromeOptions( | 347 Status ParseChromeOptions( |
306 const base::Value& capability, | 348 const base::Value& capability, |
307 Capabilities* capabilities) { | 349 Capabilities* capabilities) { |
308 const base::DictionaryValue* chrome_options = NULL; | 350 const base::DictionaryValue* chrome_options = NULL; |
309 if (!capability.GetAsDictionary(&chrome_options)) | 351 if (!capability.GetAsDictionary(&chrome_options)) |
310 return Status(kUnknownError, "must be a dictionary"); | 352 return Status(kUnknownError, "must be a dictionary"); |
311 | 353 |
312 bool is_android = chrome_options->HasKey("androidPackage"); | 354 bool is_android = chrome_options->HasKey("androidPackage"); |
313 bool is_remote = chrome_options->HasKey("debuggerAddress"); | 355 bool is_remote = chrome_options->HasKey("debuggerAddress"); |
314 | 356 |
315 std::map<std::string, Parser> parser_map; | 357 std::map<std::string, Parser> parser_map; |
316 // Ignore 'args', 'binary' and 'extensions' capabilities by default, since the | 358 // Ignore 'args', 'binary' and 'extensions' capabilities by default, since the |
317 // Java client always passes them. | 359 // Java client always passes them. |
318 parser_map["args"] = base::Bind(&IgnoreCapability); | 360 parser_map["args"] = base::Bind(&IgnoreCapability); |
319 parser_map["binary"] = base::Bind(&IgnoreCapability); | 361 parser_map["binary"] = base::Bind(&IgnoreCapability); |
320 parser_map["extensions"] = base::Bind(&IgnoreCapability); | 362 parser_map["extensions"] = base::Bind(&IgnoreCapability); |
363 | |
364 parser_map["perfLoggingPrefs"] = base::Bind(&ParsePerfLoggingPrefs); | |
365 | |
321 if (is_android) { | 366 if (is_android) { |
322 parser_map["androidActivity"] = | 367 parser_map["androidActivity"] = |
323 base::Bind(&ParseString, &capabilities->android_activity); | 368 base::Bind(&ParseString, &capabilities->android_activity); |
324 parser_map["androidDeviceSerial"] = | 369 parser_map["androidDeviceSerial"] = |
325 base::Bind(&ParseString, &capabilities->android_device_serial); | 370 base::Bind(&ParseString, &capabilities->android_device_serial); |
326 parser_map["androidPackage"] = | 371 parser_map["androidPackage"] = |
327 base::Bind(&ParseString, &capabilities->android_package); | 372 base::Bind(&ParseString, &capabilities->android_package); |
328 parser_map["androidProcess"] = | 373 parser_map["androidProcess"] = |
329 base::Bind(&ParseString, &capabilities->android_process); | 374 base::Bind(&ParseString, &capabilities->android_process); |
330 parser_map["androidUseRunningApp"] = | 375 parser_map["androidUseRunningApp"] = |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 str += "=" + value; | 511 str += "=" + value; |
467 } | 512 } |
468 ++iter; | 513 ++iter; |
469 if (iter == switch_map_.end()) | 514 if (iter == switch_map_.end()) |
470 break; | 515 break; |
471 str += " "; | 516 str += " "; |
472 } | 517 } |
473 return str; | 518 return str; |
474 } | 519 } |
475 | 520 |
521 PerfLoggingPrefs::PerfLoggingPrefs() | |
522 : network(InspectorDomainStatus::kDefaultEnabled), | |
523 page(InspectorDomainStatus::kDefaultEnabled), | |
524 timeline(InspectorDomainStatus::kDefaultEnabled), | |
525 trace_categories("") {} | |
samuong
2014/08/04 06:08:22
the default constructor for std::string creates an
johnmoore
2014/08/04 17:37:57
Done.
| |
526 | |
527 PerfLoggingPrefs::~PerfLoggingPrefs() {} | |
528 | |
529 bool PerfLoggingPrefs::IsEnabled(const InspectorDomainStatus& domain_status) { | |
530 return domain_status == InspectorDomainStatus::kDefaultEnabled || | |
531 domain_status == InspectorDomainStatus::kExplicitlyEnabled; | |
532 } | |
533 | |
476 Capabilities::Capabilities() | 534 Capabilities::Capabilities() |
477 : android_use_running_app(false), | 535 : android_use_running_app(false), |
478 detach(false), | 536 detach(false), |
479 force_devtools_screenshot(false) {} | 537 force_devtools_screenshot(false) {} |
480 | 538 |
481 Capabilities::~Capabilities() {} | 539 Capabilities::~Capabilities() {} |
482 | 540 |
483 bool Capabilities::IsAndroid() const { | 541 bool Capabilities::IsAndroid() const { |
484 return !android_package.empty(); | 542 return !android_package.empty(); |
485 } | 543 } |
(...skipping 11 matching lines...) Expand all Loading... | |
497 it != parser_map.end(); ++it) { | 555 it != parser_map.end(); ++it) { |
498 const base::Value* capability = NULL; | 556 const base::Value* capability = NULL; |
499 if (desired_caps.Get(it->first, &capability)) { | 557 if (desired_caps.Get(it->first, &capability)) { |
500 Status status = it->second.Run(*capability, this); | 558 Status status = it->second.Run(*capability, this); |
501 if (status.IsError()) { | 559 if (status.IsError()) { |
502 return Status( | 560 return Status( |
503 kUnknownError, "cannot parse capability: " + it->first, status); | 561 kUnknownError, "cannot parse capability: " + it->first, status); |
504 } | 562 } |
505 } | 563 } |
506 } | 564 } |
565 // Perf log must be enabled if perf log prefs are specified; otherwise, error. | |
566 LoggingPrefs::const_iterator iter = logging_prefs.find( | |
567 WebDriverLog::kPerformanceType); | |
568 if (iter == logging_prefs.end() || iter->second == Log::kOff) { | |
569 const base::DictionaryValue* chrome_options = NULL; | |
570 if (desired_caps.GetDictionary("chromeOptions", &chrome_options) && | |
571 chrome_options->HasKey("perfLoggingPrefs")) { | |
572 return Status(kUnknownError, "perfLoggingPrefs specified, " | |
573 "but performance logging was not enabled"); | |
574 } | |
575 } | |
507 return Status(kOk); | 576 return Status(kOk); |
508 } | 577 } |
OLD | NEW |