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..13fe462f203ef94b9cc4f7a9d3c2111c33d802a0 100644 |
--- a/chrome/test/chromedriver/session_commands.cc |
+++ b/chrome/test/chromedriver/session_commands.cc |
@@ -505,6 +505,88 @@ Status ExecuteGetNetworkConditions(Session* session, |
return Status(kOk); |
} |
+Status ExecuteSetNetworkConnection(Session* session, |
+ const base::DictionaryValue& params, |
+ std::unique_ptr<Value>* value) { |
+ const int kAirplaneMask = 0x1; |
+ const int kWifiMask = 0x2; |
+ const int k4GMask = 0x8; |
+ const int k3GMask = 0x10; |
+ const int k2GMask = 0x20; |
samuong
2016/06/17 22:01:30
You should put these at the top of the file in an
roisinmcl
2016/06/20 18:14:17
Done.
|
+ |
+ int connection_type; |
+ |
+ const base::DictionaryValue* parameters = NULL; |
+ |
+ params.GetDictionary("parameters", ¶meters); |
+ |
+ if(!parameters->GetInteger("type", &connection_type)) { |
+ return Status(kUnknownError, |
+ "invalid network_connections is missing 'connection_type'"); |
prasadv
2016/06/17 18:43:35
Error message is confusing.
Do we have anything as
roisinmcl
2016/06/20 18:14:17
I changed this error message to be more clear. I c
|
+ } |
+ |
+ std::unique_ptr<NetworkConditions> network_conditions( |
+ new NetworkConditions()); |
+ |
+ if (connection_type & kAirplaneMask) { |
+ network_conditions->latency = 0; |
+ network_conditions->upload_throughput = 0; |
+ network_conditions->download_throughput = 0; |
+ network_conditions->offline = true; |
+ } else if (connection_type & kWifiMask) { |
+ network_conditions->latency = 2; |
+ network_conditions->upload_throughput = 30720 * 1024; |
prasadv
2016/06/17 18:43:35
I prefer using constants instant of using hard cod
samuong
2016/06/17 22:01:30
Agreed. Roisin can you add them and coordinate wit
roisinmcl
2016/06/20 18:14:17
Done.
roisinmcl
2016/06/20 18:14:17
Done.
|
+ network_conditions->download_throughput = 30720 * 1024; |
+ network_conditions->offline = false; |
+ } else if (connection_type & k4GMask) { |
+ network_conditions->latency = 20; |
+ network_conditions->upload_throughput = 4096 * 1024; |
+ network_conditions->download_throughput = 4096 * 1024; |
+ network_conditions->offline = false; |
+ } else if (connection_type & k3GMask) { |
+ network_conditions->latency = 100; |
+ network_conditions->upload_throughput = 750 * 1024; |
+ network_conditions->download_throughput = 750 * 1024; |
+ network_conditions->offline = false; |
+ } else if (connection_type & k2GMask) { |
+ network_conditions->latency = 300; |
+ network_conditions->upload_throughput = 250 * 1024; |
+ network_conditions->download_throughput = 250 * 1024; |
+ network_conditions->offline = false; |
+ } else { |
+ return Status(kUnknownError, "invalid 'connection_type'"); |
+ } |
+ |
+ session->overridden_network_conditions.reset( |
+ network_conditions.release()); |
+ |
+ // get list of all webview objects |
+ // iterate through and override each one's network conditions to the new ones |
+ // if any has an error, return that |
+ // otherwise return Status(kOk) |
+ std::list<std::string> web_view_ids; |
+ chrome->GetWebViewIds(web_view_ids); |
+ |
+ std::string web_view_id; |
+ |
+ 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); |
+ |
+ //return web_view->OverrideNetworkConditions( |
prasadv
2016/06/17 18:43:35
Remove these lines if not needed.
roisinmcl
2016/06/20 18:14:16
Done.
|
+ // *session->overridden_network_conditions); |
+ |
+} |
+ |
Status ExecuteGetWindowPosition(Session* session, |
const base::DictionaryValue& params, |
std::unique_ptr<base::Value>* value) { |