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..5572ba62849f8e9ccc3413bb8384ade7a477ce09 100644 |
| --- a/chrome/test/chromedriver/session_commands.cc |
| +++ b/chrome/test/chromedriver/session_commands.cc |
| @@ -38,6 +38,26 @@ |
| namespace { |
| +const int kAirplaneMask = 0x1; |
|
samuong
2016/06/20 21:43:23
nit: lets call it kAirplaneModeMask (same with kAi
roisinmcl
2016/06/21 18:55:11
Done.
|
| +const int kWifiMask = 0x2; |
| +const int k4GMask = 0x8; |
| +const int k3GMask = 0x10; |
| +const int k2GMask = 0x20; |
| + |
| +const int kAirplaneLatency = 0; |
| +const int kAirplaneThroughput = 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; |
| + |
| const char kWindowHandlePrefix[] = "CDwindow-"; |
| std::string WebViewIdToWindowHandle(const std::string& web_view_id) { |
| @@ -505,6 +525,76 @@ Status ExecuteGetNetworkConditions(Session* session, |
| return Status(kOk); |
| } |
| +Status ExecuteSetNetworkConnection(Session* session, |
| + const base::DictionaryValue& params, |
| + std::unique_ptr<Value>* value) { |
| + int connection_type; |
| + |
|
samuong
2016/06/20 21:43:23
nit: delete blank line
roisinmcl
2016/06/21 18:55:11
Done.
|
| + const base::DictionaryValue* parameters = NULL; |
|
samuong
2016/06/20 21:43:23
use nullptr instead of NULL
roisinmcl
2016/06/21 18:55:10
Done.
|
| + |
| + params.GetDictionary("parameters", ¶meters); |
| + |
|
samuong
2016/06/20 21:43:23
nit: delete blank line
roisinmcl
2016/06/21 18:55:10
Done.
|
| + if(!parameters->GetInteger("type", &connection_type)) { |
|
samuong
2016/06/20 21:43:23
nit: space after 'if'
roisinmcl
2016/06/21 18:55:11
Done.
|
| + return Status(kUnknownError, |
| + "invalid 'connection_type'"); |
|
samuong
2016/06/20 21:43:23
nit: join these two lines into one, remove braces
roisinmcl
2016/06/21 18:55:10
Done.
|
| + } |
| + |
| + std::unique_ptr<NetworkConditions> network_conditions( |
| + new NetworkConditions()); |
| + |
| + if (connection_type & kAirplaneMask) { |
| + network_conditions->latency = kAirplaneLatency; |
| + network_conditions->upload_throughput = kAirplaneThroughput; |
| + network_conditions->download_throughput = kAirplaneThroughput; |
| + network_conditions->offline = kOffline; |
| + } else 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 { |
| + return Status(kUnknownError, "invalid 'connection_type'"); |
| + } |
|
samuong
2016/06/20 21:43:23
if |connection_type| is 011 (airplane mode + wifi)
roisinmcl
2016/06/21 18:55:11
I changed the orders to set the connection to the
|
| + |
| + session->overridden_network_conditions.reset( |
| + network_conditions.release()); |
| + |
| + // get list of all webview objects |
| + // iterate through and override each one's network conditions |
|
samuong
2016/06/20 21:43:23
use full sentences for comments, and try to explai
roisinmcl
2016/06/21 18:55:11
Done.
|
| + std::list<std::string> web_view_ids; |
| + chrome->GetWebViewIds(web_view_ids); |
| + |
| + std::string web_view_id; |
|
samuong
2016/06/20 21:43:23
nit: since this is only used within the for loop,
roisinmcl
2016/06/21 18:55:11
Done.
|
| + |
| + for (int i = 0; i < web_view_ids.size; ++i) { |
| + WebView current_web_view; |
| + web_view_id = web_view_ids[i]; |
| + chrome->GetWebViewById(web_view_id, web_view) |
| + if (!web_view) { |
| + return Status(kUnknowError, "invalid web view"); |
| + } |
| + web_view->OverrideNetworkConditions( |
| + *session->overridden_network_conditions); |
| + } |
| + |
| + return Status(kOk); |
| +} |
| + |
| Status ExecuteGetWindowPosition(Session* session, |
| const base::DictionaryValue& params, |
| std::unique_ptr<base::Value>* value) { |