Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: chrome/test/chromedriver/session_commands.cc

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

Powered by Google App Engine
This is Rietveld 408576698