Chromium Code Reviews| 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/session_commands.h" | 5 #include "chrome/test/chromedriver/session_commands.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "chrome/test/chromedriver/chrome_launcher.h" | 31 #include "chrome/test/chromedriver/chrome_launcher.h" |
| 32 #include "chrome/test/chromedriver/command_listener.h" | 32 #include "chrome/test/chromedriver/command_listener.h" |
| 33 #include "chrome/test/chromedriver/logging.h" | 33 #include "chrome/test/chromedriver/logging.h" |
| 34 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 34 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
| 35 #include "chrome/test/chromedriver/session.h" | 35 #include "chrome/test/chromedriver/session.h" |
| 36 #include "chrome/test/chromedriver/util.h" | 36 #include "chrome/test/chromedriver/util.h" |
| 37 #include "chrome/test/chromedriver/version.h" | 37 #include "chrome/test/chromedriver/version.h" |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 | |
| 42 | |
|
samuong
2016/06/27 21:31:53
nit: delete these two blank lines
roisinmcl
2016/06/28 18:36:48
Done.
| |
| 43 const int kAirplaneModeMask = 0x1; | |
| 44 const int kWifiMask = 0x2; | |
| 45 const int k4GMask = 0x8; | |
| 46 const int k3GMask = 0x10; | |
| 47 const int k2GMask = 0x20; | |
| 48 | |
| 49 const int kAirplaneModeLatency = 0; | |
| 50 const int kAirplaneModeThroughput = 0; | |
| 51 const int kWifiLatency = 2; | |
| 52 const int kWifiThroughput = 30720 * 1024; | |
| 53 const int k4GLatency = 20; | |
| 54 const int k4GThroughput = 4096 * 1024; | |
| 55 const int k3GLatency = 100; | |
| 56 const int k3GThroughput = 750 * 1024; | |
| 57 const int k2GLatency = 300; | |
| 58 const int k2GThroughput = 250 * 1024; | |
| 59 | |
| 60 const bool kOnline = false; | |
| 61 const bool kOffline = true; | |
|
samuong
2016/06/27 21:31:53
i don't think these are necessary, saying "offline
roisinmcl
2016/06/28 18:36:48
Done.
| |
| 62 | |
| 41 const char kWindowHandlePrefix[] = "CDwindow-"; | 63 const char kWindowHandlePrefix[] = "CDwindow-"; |
| 42 | 64 |
| 43 std::string WebViewIdToWindowHandle(const std::string& web_view_id) { | 65 std::string WebViewIdToWindowHandle(const std::string& web_view_id) { |
| 44 return kWindowHandlePrefix + web_view_id; | 66 return kWindowHandlePrefix + web_view_id; |
| 45 } | 67 } |
| 46 | 68 |
| 47 bool WindowHandleToWebViewId(const std::string& window_handle, | 69 bool WindowHandleToWebViewId(const std::string& window_handle, |
| 48 std::string* web_view_id) { | 70 std::string* web_view_id) { |
| 49 if (window_handle.find(kWindowHandlePrefix) != 0u) | 71 if (window_handle.find(kWindowHandlePrefix) != 0u) |
| 50 return false; | 72 return false; |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 conditions.SetInteger( | 520 conditions.SetInteger( |
| 499 "download_throughput", | 521 "download_throughput", |
| 500 session->overridden_network_conditions->download_throughput); | 522 session->overridden_network_conditions->download_throughput); |
| 501 conditions.SetInteger( | 523 conditions.SetInteger( |
| 502 "upload_throughput", | 524 "upload_throughput", |
| 503 session->overridden_network_conditions->upload_throughput); | 525 session->overridden_network_conditions->upload_throughput); |
| 504 value->reset(conditions.DeepCopy()); | 526 value->reset(conditions.DeepCopy()); |
| 505 return Status(kOk); | 527 return Status(kOk); |
| 506 } | 528 } |
| 507 | 529 |
| 530 Status ExecuteSetNetworkConnection(Session* session, | |
| 531 const base::DictionaryValue& params, | |
| 532 std::unique_ptr<base::Value>* value) { | |
| 533 int connection_type; | |
| 534 const base::DictionaryValue* parameters = nullptr; | |
| 535 | |
| 536 params.GetDictionary("parameters", ¶meters); | |
|
samuong
2016/06/27 21:31:53
the return value for this call is not checked, and
roisinmcl
2016/06/29 17:55:12
Done.
| |
| 537 if (!parameters->GetInteger("type", &connection_type)) { | |
| 538 return Status(kUnknownError, "invalid connection_type"); | |
| 539 } | |
| 540 | |
| 541 ChromeDesktopImpl* desktop = nullptr; | |
| 542 Status status = session->chrome->GetAsDesktop(&desktop); | |
| 543 if (!desktop) { | |
|
samuong
2016/06/27 21:31:53
for consistency, use "if (status.IsError())"
also
roisinmcl
2016/06/28 18:36:48
Done.
| |
| 544 return status; | |
| 545 } | |
| 546 desktop.SetNetworkConnection(connection_type); | |
| 547 | |
| 548 std::unique_ptr<NetworkConditions> network_conditions( | |
| 549 new NetworkConditions()); | |
| 550 | |
| 551 if (connection_type & kWifiMask) { | |
| 552 network_conditions->latency = kWifiLatency; | |
| 553 network_conditions->upload_throughput = kWifiThroughput; | |
| 554 network_conditions->download_throughput = kWifiThroughput; | |
| 555 network_conditions->offline = kOnline; | |
| 556 } else if (connection_type & k4GMask) { | |
| 557 network_conditions->latency = k4GLatency; | |
| 558 network_conditions->upload_throughput = k4GThroughput; | |
| 559 network_conditions->download_throughput = k4GThroughput; | |
| 560 network_conditions->offline = kOnline; | |
| 561 } else if (connection_type & k3GMask) { | |
| 562 network_conditions->latency = k3GLatency; | |
| 563 network_conditions->upload_throughput = k3GThroughput; | |
| 564 network_conditions->download_throughput = k3GThroughput; | |
| 565 network_conditions->offline = kOnline; | |
| 566 } else if (connection_type & k2GMask) { | |
| 567 network_conditions->latency = k2GLatency; | |
| 568 network_conditions->upload_throughput = k2GThroughput; | |
| 569 network_conditions->download_throughput = k2GThroughput; | |
| 570 network_conditions->offline = kOnline; | |
| 571 } else if (connection_type & kAirplaneModeMask) { | |
| 572 network_conditions->latency = kAirplaneModeLatency; | |
| 573 network_conditions->upload_throughput = kAirplaneModeThroughput; | |
| 574 network_conditions->download_throughput = kAirplaneModeThroughput; | |
|
samuong
2016/06/27 21:31:53
do we actually need to set latency and throughput
roisinmcl
2016/06/28 18:36:48
I left these being set to zero in case the latency
samuong
2016/06/28 23:23:40
It's probably fine either way. Since this if branc
roisinmcl
2016/06/29 17:55:12
Done.
| |
| 575 network_conditions->offline = kOffline; | |
| 576 } else { | |
| 577 return Status(kUnknownError, "invalid 'connection_type'"); | |
|
samuong
2016/06/27 21:31:53
should this be an error? if i've got airplane mode
roisinmcl
2016/06/28 18:36:48
Done.
| |
| 578 } | |
| 579 | |
| 580 session->overridden_network_conditions.reset( | |
| 581 network_conditions.release()); | |
| 582 | |
| 583 // Applies overridden network connection to all WebViews of the session | |
| 584 // to ensure that network emulation is applied on a per-session basis | |
| 585 // rather than the just to the current WebView. | |
| 586 std::list<std::string> web_view_ids; | |
| 587 session->chrome->GetWebViewIds(&web_view_ids); | |
|
samuong
2016/06/27 21:31:53
don't forget to check the error status
roisinmcl
2016/06/28 18:36:48
Done.
| |
| 588 std::list<std::string>::const_iterator web_view_itr; | |
| 589 std::list<std::string>::const_iterator end; | |
| 590 | |
| 591 for (web_view_itr = web_view_ids.begin(), end = web_view_ids.end(); | |
| 592 web_view_itr != end; | |
| 593 ++web_view_itr) { | |
|
samuong
2016/06/27 21:31:53
you can use a range-based for loop here
for an exa
roisinmcl
2016/06/28 18:36:48
Done.
| |
| 594 std::string web_view_id = *web_view_itr; | |
| 595 WebView* web_view; | |
| 596 session->chrome->GetWebViewById(web_view_id, &web_view); | |
| 597 if (!web_view) { | |
| 598 return Status(kUnknownError, "invalid web view"); | |
| 599 } | |
|
samuong
2016/06/27 21:31:53
nit: remove braces for this, and any other single-
roisinmcl
2016/06/28 18:36:48
Done.
| |
| 600 web_view->OverrideNetworkConditions( | |
| 601 *session->overridden_network_conditions); | |
| 602 } | |
| 603 return Status(kOk); | |
| 604 } | |
| 605 | |
| 508 Status ExecuteGetWindowPosition(Session* session, | 606 Status ExecuteGetWindowPosition(Session* session, |
| 509 const base::DictionaryValue& params, | 607 const base::DictionaryValue& params, |
| 510 std::unique_ptr<base::Value>* value) { | 608 std::unique_ptr<base::Value>* value) { |
| 511 ChromeDesktopImpl* desktop = NULL; | 609 ChromeDesktopImpl* desktop = NULL; |
| 512 Status status = session->chrome->GetAsDesktop(&desktop); | 610 Status status = session->chrome->GetAsDesktop(&desktop); |
| 513 if (status.IsError()) | 611 if (status.IsError()) |
| 514 return status; | 612 return status; |
| 515 | 613 |
| 516 AutomationExtension* extension = NULL; | 614 AutomationExtension* extension = NULL; |
| 517 status = desktop->GetAutomationExtension(&extension); | 615 status = desktop->GetAutomationExtension(&extension); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 | 785 |
| 688 Status ExecuteSetAutoReporting(Session* session, | 786 Status ExecuteSetAutoReporting(Session* session, |
| 689 const base::DictionaryValue& params, | 787 const base::DictionaryValue& params, |
| 690 std::unique_ptr<base::Value>* value) { | 788 std::unique_ptr<base::Value>* value) { |
| 691 bool enabled; | 789 bool enabled; |
| 692 if (!params.GetBoolean("enabled", &enabled)) | 790 if (!params.GetBoolean("enabled", &enabled)) |
| 693 return Status(kUnknownError, "missing parameter 'enabled'"); | 791 return Status(kUnknownError, "missing parameter 'enabled'"); |
| 694 session->auto_reporting_enabled = enabled; | 792 session->auto_reporting_enabled = enabled; |
| 695 return Status(kOk); | 793 return Status(kOk); |
| 696 } | 794 } |
| OLD | NEW |