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 option: " + it.key()); | |
stgao
2014/08/04 21:15:09
performance option?
johnmoore
2014/08/04 21:40:48
Done.
| |
339 Status status = parser_map[it.key()].Run(it.value(), capabilities); | |
340 if (status.IsError()) | |
341 return Status(kUnknownError, "cannot parse " + it.key(), status); | |
342 } | |
343 return Status(kOk); | |
344 } | |
345 | |
305 Status ParseChromeOptions( | 346 Status ParseChromeOptions( |
306 const base::Value& capability, | 347 const base::Value& capability, |
307 Capabilities* capabilities) { | 348 Capabilities* capabilities) { |
308 const base::DictionaryValue* chrome_options = NULL; | 349 const base::DictionaryValue* chrome_options = NULL; |
309 if (!capability.GetAsDictionary(&chrome_options)) | 350 if (!capability.GetAsDictionary(&chrome_options)) |
310 return Status(kUnknownError, "must be a dictionary"); | 351 return Status(kUnknownError, "must be a dictionary"); |
311 | 352 |
312 bool is_android = chrome_options->HasKey("androidPackage"); | 353 bool is_android = chrome_options->HasKey("androidPackage"); |
313 bool is_remote = chrome_options->HasKey("debuggerAddress"); | 354 bool is_remote = chrome_options->HasKey("debuggerAddress"); |
314 | 355 |
315 std::map<std::string, Parser> parser_map; | 356 std::map<std::string, Parser> parser_map; |
316 // Ignore 'args', 'binary' and 'extensions' capabilities by default, since the | 357 // Ignore 'args', 'binary' and 'extensions' capabilities by default, since the |
317 // Java client always passes them. | 358 // Java client always passes them. |
318 parser_map["args"] = base::Bind(&IgnoreCapability); | 359 parser_map["args"] = base::Bind(&IgnoreCapability); |
319 parser_map["binary"] = base::Bind(&IgnoreCapability); | 360 parser_map["binary"] = base::Bind(&IgnoreCapability); |
320 parser_map["extensions"] = base::Bind(&IgnoreCapability); | 361 parser_map["extensions"] = base::Bind(&IgnoreCapability); |
362 | |
363 parser_map["perfLoggingPrefs"] = base::Bind(&ParsePerfLoggingPrefs); | |
364 | |
321 if (is_android) { | 365 if (is_android) { |
322 parser_map["androidActivity"] = | 366 parser_map["androidActivity"] = |
323 base::Bind(&ParseString, &capabilities->android_activity); | 367 base::Bind(&ParseString, &capabilities->android_activity); |
324 parser_map["androidDeviceSerial"] = | 368 parser_map["androidDeviceSerial"] = |
325 base::Bind(&ParseString, &capabilities->android_device_serial); | 369 base::Bind(&ParseString, &capabilities->android_device_serial); |
326 parser_map["androidPackage"] = | 370 parser_map["androidPackage"] = |
327 base::Bind(&ParseString, &capabilities->android_package); | 371 base::Bind(&ParseString, &capabilities->android_package); |
328 parser_map["androidProcess"] = | 372 parser_map["androidProcess"] = |
329 base::Bind(&ParseString, &capabilities->android_process); | 373 base::Bind(&ParseString, &capabilities->android_process); |
330 parser_map["androidUseRunningApp"] = | 374 parser_map["androidUseRunningApp"] = |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 str += "=" + value; | 510 str += "=" + value; |
467 } | 511 } |
468 ++iter; | 512 ++iter; |
469 if (iter == switch_map_.end()) | 513 if (iter == switch_map_.end()) |
470 break; | 514 break; |
471 str += " "; | 515 str += " "; |
472 } | 516 } |
473 return str; | 517 return str; |
474 } | 518 } |
475 | 519 |
520 PerfLoggingPrefs::PerfLoggingPrefs() | |
521 : network(InspectorDomainStatus::kDefaultEnabled), | |
522 page(InspectorDomainStatus::kDefaultEnabled), | |
523 timeline(InspectorDomainStatus::kDefaultEnabled), | |
524 trace_categories() {} | |
525 | |
526 PerfLoggingPrefs::~PerfLoggingPrefs() {} | |
527 | |
476 Capabilities::Capabilities() | 528 Capabilities::Capabilities() |
477 : android_use_running_app(false), | 529 : android_use_running_app(false), |
478 detach(false), | 530 detach(false), |
479 force_devtools_screenshot(false) {} | 531 force_devtools_screenshot(false) {} |
480 | 532 |
481 Capabilities::~Capabilities() {} | 533 Capabilities::~Capabilities() {} |
482 | 534 |
483 bool Capabilities::IsAndroid() const { | 535 bool Capabilities::IsAndroid() const { |
484 return !android_package.empty(); | 536 return !android_package.empty(); |
485 } | 537 } |
(...skipping 11 matching lines...) Expand all Loading... | |
497 it != parser_map.end(); ++it) { | 549 it != parser_map.end(); ++it) { |
498 const base::Value* capability = NULL; | 550 const base::Value* capability = NULL; |
499 if (desired_caps.Get(it->first, &capability)) { | 551 if (desired_caps.Get(it->first, &capability)) { |
500 Status status = it->second.Run(*capability, this); | 552 Status status = it->second.Run(*capability, this); |
501 if (status.IsError()) { | 553 if (status.IsError()) { |
502 return Status( | 554 return Status( |
503 kUnknownError, "cannot parse capability: " + it->first, status); | 555 kUnknownError, "cannot parse capability: " + it->first, status); |
504 } | 556 } |
505 } | 557 } |
506 } | 558 } |
559 // Perf log must be enabled if perf log prefs are specified; otherwise, error. | |
560 LoggingPrefs::const_iterator iter = logging_prefs.find( | |
561 WebDriverLog::kPerformanceType); | |
562 if (iter == logging_prefs.end() || iter->second == Log::kOff) { | |
563 const base::DictionaryValue* chrome_options = NULL; | |
564 if (desired_caps.GetDictionary("chromeOptions", &chrome_options) && | |
565 chrome_options->HasKey("perfLoggingPrefs")) { | |
566 return Status(kUnknownError, "perfLoggingPrefs specified, " | |
567 "but performance logging was not enabled"); | |
568 } | |
569 } | |
507 return Status(kOk); | 570 return Status(kOk); |
508 } | 571 } |
OLD | NEW |