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

Unified Diff: chrome/test/chromedriver/window_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: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/window_commands.cc
diff --git a/chrome/test/chromedriver/window_commands.cc b/chrome/test/chromedriver/window_commands.cc
index 004947936ed4e219d9ffabea26f6f13dc601dd4a..de54878db470a37ea9776d0427931b57f8786529 100644
--- a/chrome/test/chromedriver/window_commands.cc
+++ b/chrome/test/chromedriver/window_commands.cc
@@ -9,6 +9,8 @@
#include <list>
#include <string>
+#include "base/json/json_reader.h"
samuong 2016/06/14 17:46:00 is this needed?
roisinmcl 2016/06/17 18:13:33 I have removed this.
+
#include "base/callback.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
@@ -25,6 +27,7 @@
#include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h"
#include "chrome/test/chromedriver/chrome/js.h"
#include "chrome/test/chromedriver/chrome/network_conditions.h"
+#include "chrome/test/chromedriver/chrome/network_list.h"
samuong 2016/06/14 17:46:00 is this for the bitmasks?
roisinmcl 2016/06/17 18:13:33 I removed this and declared the bitmasks within th
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/ui_events.h"
#include "chrome/test/chromedriver/chrome/web_view.h"
@@ -991,6 +994,7 @@ Status ExecuteSetNetworkConditions(Session* session,
if (status.IsError())
return status;
} else if (params.GetDictionary("network_conditions", &conditions)) {
+
samuong 2016/06/14 17:46:00 nitpick: delete this blank line
roisinmcl 2016/06/17 18:13:33 Done.
// |latency| is required.
if (!conditions->GetDouble("latency", &network_conditions->latency))
return Status(kUnknownError,
@@ -1037,6 +1041,63 @@ Status ExecuteSetNetworkConditions(Session* session,
*session->overridden_network_conditions);
}
+Status ExecuteSetEmulatedNetworkConditions(Session* session,
samuong 2016/06/14 17:46:00 i took a closer look into this and although you're
roisinmcl 2016/06/17 18:13:33 Moved this function to session_commands and iterat
+ WebView* web_view,
+ const base::DictionaryValue& params,
+ std::unique_ptr<base::Value>* value,
+ Timeout* timeout) {
samuong 2016/06/14 17:46:00 style nitpick: keep all parameters indented to the
roisinmcl 2016/06/17 18:13:33 Done.
+ const int kOfflineMask = 0x0;
samuong 2016/06/14 17:46:00 is this supposed to be 0x1?
roisinmcl 2016/06/17 18:13:33 Changed this to 0x1.
+ const int kWifiMask = 0x2;
+ const int k4GMask = 0x8;
+ const int k3GMask = 0x10;
+ const int k2GMask = 0x20;
+
+ int connection_type;
+
+ if(!params.GetInteger("connection_type", &connection_type)) {
samuong 2016/06/14 17:46:00 i think this is called "parameters.type" in the sp
roisinmcl 2016/06/17 18:13:33 Done.
+ return Status(kUnknownError,
+ "invalid network_connections is missing 'connection_type'");
+ }
+
+ std::unique_ptr<NetworkConditions> network_conditions(
+ new NetworkConditions());
+
+ if (connection_type == kOfflineMask) {
samuong 2016/06/14 17:46:00 use the bitwise and operator (&) instead of == to
roisinmcl 2016/06/17 18:13:33 Done.
+ 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;
+ 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'");
samuong 2016/06/14 17:46:00 style nitpick: join the two lines above
roisinmcl 2016/06/17 18:13:33 Done.
+ }
+
+ session->overridden_network_conditions.reset(
+ network_conditions.release());
+ return web_view->OverrideNetworkConditions(
+ *session->overridden_network_conditions);
+}
+
Status ExecuteDeleteNetworkConditions(Session* session,
WebView* web_view,
const base::DictionaryValue& params,
« chrome/test/chromedriver/window_commands.h ('K') | « chrome/test/chromedriver/window_commands.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698