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 const int kWifiMask = 0x2; |
| 42 const int k4GMask = 0x8; |
| 43 const int k3GMask = 0x10; |
| 44 const int k2GMask = 0x20; |
| 45 |
| 46 const int kAirplaneModeLatency = 0; |
| 47 const int kAirplaneModeThroughput = 0; |
| 48 const int kWifiLatency = 2; |
| 49 const int kWifiThroughput = 30720 * 1024; |
| 50 const int k4GLatency = 20; |
| 51 const int k4GThroughput = 4096 * 1024; |
| 52 const int k3GLatency = 100; |
| 53 const int k3GThroughput = 750 * 1024; |
| 54 const int k2GLatency = 300; |
| 55 const int k2GThroughput = 250 * 1024; |
| 56 |
41 const char kWindowHandlePrefix[] = "CDwindow-"; | 57 const char kWindowHandlePrefix[] = "CDwindow-"; |
42 | 58 |
43 std::string WebViewIdToWindowHandle(const std::string& web_view_id) { | 59 std::string WebViewIdToWindowHandle(const std::string& web_view_id) { |
44 return kWindowHandlePrefix + web_view_id; | 60 return kWindowHandlePrefix + web_view_id; |
45 } | 61 } |
46 | 62 |
47 bool WindowHandleToWebViewId(const std::string& window_handle, | 63 bool WindowHandleToWebViewId(const std::string& window_handle, |
48 std::string* web_view_id) { | 64 std::string* web_view_id) { |
49 if (window_handle.find(kWindowHandlePrefix) != 0u) | 65 if (window_handle.find(kWindowHandlePrefix) != 0u) |
50 return false; | 66 return false; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 conditions.SetInteger( | 514 conditions.SetInteger( |
499 "download_throughput", | 515 "download_throughput", |
500 session->overridden_network_conditions->download_throughput); | 516 session->overridden_network_conditions->download_throughput); |
501 conditions.SetInteger( | 517 conditions.SetInteger( |
502 "upload_throughput", | 518 "upload_throughput", |
503 session->overridden_network_conditions->upload_throughput); | 519 session->overridden_network_conditions->upload_throughput); |
504 value->reset(conditions.DeepCopy()); | 520 value->reset(conditions.DeepCopy()); |
505 return Status(kOk); | 521 return Status(kOk); |
506 } | 522 } |
507 | 523 |
| 524 Status ExecuteSetNetworkConnection(Session* session, |
| 525 const base::DictionaryValue& params, |
| 526 std::unique_ptr<base::Value>* value) { |
| 527 int connection_type; |
| 528 if (!params.GetInteger("parameters.type", &connection_type)) |
| 529 return Status(kUnknownError, "invalid connection_type"); |
| 530 |
| 531 ChromeDesktopImpl* desktop = nullptr; |
| 532 Status status = session->chrome->GetAsDesktop(&desktop); |
| 533 if (status.IsError()) |
| 534 return status; |
| 535 |
| 536 desktop->SetNetworkConnection(connection_type); |
| 537 |
| 538 std::unique_ptr<NetworkConditions> network_conditions( |
| 539 new NetworkConditions()); |
| 540 |
| 541 if (connection_type & kWifiMask) { |
| 542 network_conditions->latency = kWifiLatency; |
| 543 network_conditions->upload_throughput = kWifiThroughput; |
| 544 network_conditions->download_throughput = kWifiThroughput; |
| 545 network_conditions->offline = false; |
| 546 } else if (connection_type & k4GMask) { |
| 547 network_conditions->latency = k4GLatency; |
| 548 network_conditions->upload_throughput = k4GThroughput; |
| 549 network_conditions->download_throughput = k4GThroughput; |
| 550 network_conditions->offline = false; |
| 551 } else if (connection_type & k3GMask) { |
| 552 network_conditions->latency = k3GLatency; |
| 553 network_conditions->upload_throughput = k3GThroughput; |
| 554 network_conditions->download_throughput = k3GThroughput; |
| 555 network_conditions->offline = false; |
| 556 } else if (connection_type & k2GMask) { |
| 557 network_conditions->latency = k2GLatency; |
| 558 network_conditions->upload_throughput = k2GThroughput; |
| 559 network_conditions->download_throughput = k2GThroughput; |
| 560 network_conditions->offline = false; |
| 561 } else { |
| 562 network_conditions->latency = kAirplaneModeLatency; |
| 563 network_conditions->upload_throughput = kAirplaneModeThroughput; |
| 564 network_conditions->download_throughput = kAirplaneModeThroughput; |
| 565 network_conditions->offline = true; |
| 566 } |
| 567 |
| 568 session->overridden_network_conditions.reset( |
| 569 network_conditions.release()); |
| 570 |
| 571 // Applies overridden network connection to all WebViews of the session |
| 572 // to ensure that network emulation is applied on a per-session basis |
| 573 // rather than the just to the current WebView. |
| 574 std::list<std::string> web_view_ids; |
| 575 status = session->chrome->GetWebViewIds(&web_view_ids); |
| 576 if (status.IsError()) |
| 577 return status; |
| 578 |
| 579 for (std::string web_view_id : web_view_ids) { |
| 580 WebView* web_view; |
| 581 status = session->chrome->GetWebViewById(web_view_id, &web_view); |
| 582 if (status.IsError()) |
| 583 return status; |
| 584 web_view->OverrideNetworkConditions( |
| 585 *session->overridden_network_conditions); |
| 586 } |
| 587 return Status(kOk); |
| 588 } |
| 589 |
508 Status ExecuteGetWindowPosition(Session* session, | 590 Status ExecuteGetWindowPosition(Session* session, |
509 const base::DictionaryValue& params, | 591 const base::DictionaryValue& params, |
510 std::unique_ptr<base::Value>* value) { | 592 std::unique_ptr<base::Value>* value) { |
511 ChromeDesktopImpl* desktop = NULL; | 593 ChromeDesktopImpl* desktop = NULL; |
512 Status status = session->chrome->GetAsDesktop(&desktop); | 594 Status status = session->chrome->GetAsDesktop(&desktop); |
513 if (status.IsError()) | 595 if (status.IsError()) |
514 return status; | 596 return status; |
515 | 597 |
516 AutomationExtension* extension = NULL; | 598 AutomationExtension* extension = NULL; |
517 status = desktop->GetAutomationExtension(&extension); | 599 status = desktop->GetAutomationExtension(&extension); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 | 769 |
688 Status ExecuteSetAutoReporting(Session* session, | 770 Status ExecuteSetAutoReporting(Session* session, |
689 const base::DictionaryValue& params, | 771 const base::DictionaryValue& params, |
690 std::unique_ptr<base::Value>* value) { | 772 std::unique_ptr<base::Value>* value) { |
691 bool enabled; | 773 bool enabled; |
692 if (!params.GetBoolean("enabled", &enabled)) | 774 if (!params.GetBoolean("enabled", &enabled)) |
693 return Status(kUnknownError, "missing parameter 'enabled'"); | 775 return Status(kUnknownError, "missing parameter 'enabled'"); |
694 session->auto_reporting_enabled = enabled; | 776 session->auto_reporting_enabled = enabled; |
695 return Status(kOk); | 777 return Status(kOk); |
696 } | 778 } |
OLD | NEW |