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"); |
| 312 if (desired_value) |
| 313 *to_set = PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyEnabled; |
| 314 else |
| 315 *to_set = PerfLoggingPrefs::InspectorDomainStatus::kExplicitlyDisabled; |
| 316 return Status(kOk); |
| 317 } |
| 318 |
| 319 Status ParsePerfLoggingPrefs(const base::Value& option, |
| 320 Capabilities* capabilities) { |
| 321 const base::DictionaryValue* perf_logging_prefs = NULL; |
| 322 if (!option.GetAsDictionary(&perf_logging_prefs)) |
| 323 return Status(kUnknownError, "must be a dictionary"); |
| 324 |
| 325 std::map<std::string, Parser> parser_map; |
| 326 parser_map["enableNetwork"] = base::Bind( |
| 327 &ParseInspectorDomainStatus, &capabilities->perf_logging_prefs.network); |
| 328 parser_map["enablePage"] = base::Bind( |
| 329 &ParseInspectorDomainStatus, &capabilities->perf_logging_prefs.page); |
| 330 parser_map["enableTimeline"] = base::Bind( |
| 331 &ParseInspectorDomainStatus, &capabilities->perf_logging_prefs.timeline); |
| 332 parser_map["traceCategories"] = base::Bind( |
| 333 &ParseString, &capabilities->perf_logging_prefs.trace_categories); |
| 334 |
| 335 for (base::DictionaryValue::Iterator it(*perf_logging_prefs); !it.IsAtEnd(); |
| 336 it.Advance()) { |
| 337 if (parser_map.find(it.key()) == parser_map.end()) |
| 338 return Status(kUnknownError, "unrecognized performance logging " |
| 339 "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() {} |
| 526 |
| 527 PerfLoggingPrefs::~PerfLoggingPrefs() {} |
| 528 |
476 Capabilities::Capabilities() | 529 Capabilities::Capabilities() |
477 : android_use_running_app(false), | 530 : android_use_running_app(false), |
478 detach(false), | 531 detach(false), |
479 force_devtools_screenshot(false) {} | 532 force_devtools_screenshot(false) {} |
480 | 533 |
481 Capabilities::~Capabilities() {} | 534 Capabilities::~Capabilities() {} |
482 | 535 |
483 bool Capabilities::IsAndroid() const { | 536 bool Capabilities::IsAndroid() const { |
484 return !android_package.empty(); | 537 return !android_package.empty(); |
485 } | 538 } |
(...skipping 11 matching lines...) Expand all Loading... |
497 it != parser_map.end(); ++it) { | 550 it != parser_map.end(); ++it) { |
498 const base::Value* capability = NULL; | 551 const base::Value* capability = NULL; |
499 if (desired_caps.Get(it->first, &capability)) { | 552 if (desired_caps.Get(it->first, &capability)) { |
500 Status status = it->second.Run(*capability, this); | 553 Status status = it->second.Run(*capability, this); |
501 if (status.IsError()) { | 554 if (status.IsError()) { |
502 return Status( | 555 return Status( |
503 kUnknownError, "cannot parse capability: " + it->first, status); | 556 kUnknownError, "cannot parse capability: " + it->first, status); |
504 } | 557 } |
505 } | 558 } |
506 } | 559 } |
| 560 // Perf log must be enabled if perf log prefs are specified; otherwise, error. |
| 561 LoggingPrefs::const_iterator iter = logging_prefs.find( |
| 562 WebDriverLog::kPerformanceType); |
| 563 if (iter == logging_prefs.end() || iter->second == Log::kOff) { |
| 564 const base::DictionaryValue* chrome_options = NULL; |
| 565 if (desired_caps.GetDictionary("chromeOptions", &chrome_options) && |
| 566 chrome_options->HasKey("perfLoggingPrefs")) { |
| 567 return Status(kUnknownError, "perfLoggingPrefs specified, " |
| 568 "but performance logging was not enabled"); |
| 569 } |
| 570 } |
507 return Status(kOk); | 571 return Status(kOk); |
508 } | 572 } |
OLD | NEW |