Chromium Code Reviews| Index: chrome/test/chromedriver/session_commands.cc |
| diff --git a/chrome/test/chromedriver/session_commands.cc b/chrome/test/chromedriver/session_commands.cc |
| index e96a44ac728cb0279574d2c0888b19c2916e858c..77972b15a7525aa71b2c451c29f9bdbb4d4974ab 100644 |
| --- a/chrome/test/chromedriver/session_commands.cc |
| +++ b/chrome/test/chromedriver/session_commands.cc |
| @@ -38,6 +38,28 @@ |
| namespace { |
| + |
| + |
|
samuong
2016/06/27 21:31:53
nit: delete these two blank lines
roisinmcl
2016/06/28 18:36:48
Done.
|
| +const int kAirplaneModeMask = 0x1; |
| +const int kWifiMask = 0x2; |
| +const int k4GMask = 0x8; |
| +const int k3GMask = 0x10; |
| +const int k2GMask = 0x20; |
| + |
| +const int kAirplaneModeLatency = 0; |
| +const int kAirplaneModeThroughput = 0; |
| +const int kWifiLatency = 2; |
| +const int kWifiThroughput = 30720 * 1024; |
| +const int k4GLatency = 20; |
| +const int k4GThroughput = 4096 * 1024; |
| +const int k3GLatency = 100; |
| +const int k3GThroughput = 750 * 1024; |
| +const int k2GLatency = 300; |
| +const int k2GThroughput = 250 * 1024; |
| + |
| +const bool kOnline = false; |
| +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.
|
| + |
| const char kWindowHandlePrefix[] = "CDwindow-"; |
| std::string WebViewIdToWindowHandle(const std::string& web_view_id) { |
| @@ -505,6 +527,82 @@ Status ExecuteGetNetworkConditions(Session* session, |
| return Status(kOk); |
| } |
| +Status ExecuteSetNetworkConnection(Session* session, |
| + const base::DictionaryValue& params, |
| + std::unique_ptr<base::Value>* value) { |
| + int connection_type; |
| + const base::DictionaryValue* parameters = nullptr; |
| + |
| + 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.
|
| + if (!parameters->GetInteger("type", &connection_type)) { |
| + return Status(kUnknownError, "invalid connection_type"); |
| + } |
| + |
| + ChromeDesktopImpl* desktop = nullptr; |
| + Status status = session->chrome->GetAsDesktop(&desktop); |
| + if (!desktop) { |
|
samuong
2016/06/27 21:31:53
for consistency, use "if (status.IsError())"
also
roisinmcl
2016/06/28 18:36:48
Done.
|
| + return status; |
| + } |
| + desktop.SetNetworkConnection(connection_type); |
| + |
| + std::unique_ptr<NetworkConditions> network_conditions( |
| + new NetworkConditions()); |
| + |
| + if (connection_type & kWifiMask) { |
| + network_conditions->latency = kWifiLatency; |
| + network_conditions->upload_throughput = kWifiThroughput; |
| + network_conditions->download_throughput = kWifiThroughput; |
| + network_conditions->offline = kOnline; |
| + } else if (connection_type & k4GMask) { |
| + network_conditions->latency = k4GLatency; |
| + network_conditions->upload_throughput = k4GThroughput; |
| + network_conditions->download_throughput = k4GThroughput; |
| + network_conditions->offline = kOnline; |
| + } else if (connection_type & k3GMask) { |
| + network_conditions->latency = k3GLatency; |
| + network_conditions->upload_throughput = k3GThroughput; |
| + network_conditions->download_throughput = k3GThroughput; |
| + network_conditions->offline = kOnline; |
| + } else if (connection_type & k2GMask) { |
| + network_conditions->latency = k2GLatency; |
| + network_conditions->upload_throughput = k2GThroughput; |
| + network_conditions->download_throughput = k2GThroughput; |
| + network_conditions->offline = kOnline; |
| + } else if (connection_type & kAirplaneModeMask) { |
| + network_conditions->latency = kAirplaneModeLatency; |
| + network_conditions->upload_throughput = kAirplaneModeThroughput; |
| + 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.
|
| + network_conditions->offline = kOffline; |
| + } else { |
| + 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.
|
| + } |
| + |
| + session->overridden_network_conditions.reset( |
| + network_conditions.release()); |
| + |
| + // Applies overridden network connection to all WebViews of the session |
| + // to ensure that network emulation is applied on a per-session basis |
| + // rather than the just to the current WebView. |
| + std::list<std::string> web_view_ids; |
| + 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.
|
| + std::list<std::string>::const_iterator web_view_itr; |
| + std::list<std::string>::const_iterator end; |
| + |
| + for (web_view_itr = web_view_ids.begin(), end = web_view_ids.end(); |
| + web_view_itr != end; |
| + ++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.
|
| + std::string web_view_id = *web_view_itr; |
| + WebView* web_view; |
| + session->chrome->GetWebViewById(web_view_id, &web_view); |
| + if (!web_view) { |
| + return Status(kUnknownError, "invalid web view"); |
| + } |
|
samuong
2016/06/27 21:31:53
nit: remove braces for this, and any other single-
roisinmcl
2016/06/28 18:36:48
Done.
|
| + web_view->OverrideNetworkConditions( |
| + *session->overridden_network_conditions); |
| + } |
| + return Status(kOk); |
| +} |
| + |
| Status ExecuteGetWindowPosition(Session* session, |
| const base::DictionaryValue& params, |
| std::unique_ptr<base::Value>* value) { |