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

Unified Diff: chrome/test/chromedriver/window_commands.cc

Issue 883083002: [chromedriver] Add Network Conditions Override Manager and tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Working implementation of emulating network conditions with chromedriver Created 5 years, 10 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 9a3c40512fa32d40afa8c6e46dcc08131266fa7d..f559fca9798a1c28e415db3e91259a7ad608be6f 100644
--- a/chrome/test/chromedriver/window_commands.cc
+++ b/chrome/test/chromedriver/window_commands.cc
@@ -869,6 +869,54 @@ Status ExecuteSetLocation(
return status;
}
+Status ExecuteSetNetworkConditions(
+ Session* session,
+ WebView* web_view,
+ const base::DictionaryValue& params,
+ scoped_ptr<base::Value>* value) {
+ const base::DictionaryValue* conditions = NULL;
+ NetworkConditions network_conditions;
+ // |latency| is required.
+ if (!params.GetDictionary("network_conditions", &conditions) ||
+ !conditions->GetInteger("latency", &network_conditions.latency))
+ return Status(kUnknownError, "missing or invalid 'network_conditions'");
+
+ // Either |throughput| or the pair |download_throughput| and
+ // |upload_throughput| is required.
+ if (conditions->HasKey("throughput")) {
+ if (!conditions->GetInteger("throughput",
+ &network_conditions.download_throughput))
+ return Status(kUnknownError, "invalid 'throughput'");
+ conditions->GetInteger("throughput", &network_conditions.upload_throughput);
+ } else if (conditions->HasKey("download_throughput") &&
+ conditions->HasKey("upload_throughput")) {
+ if (!conditions->GetInteger("download_throughput",
+ &network_conditions.download_throughput) ||
+ !conditions->GetInteger("upload_throughput",
+ &network_conditions.upload_throughput))
+ return Status(kUnknownError,
+ "invalid 'download_throughput' or 'upload_throughput'");
+ } else {
+ return Status(kUnknownError,
+ "invalid 'network_conditions' is missing 'throughput' or "
+ "'download_throughput'/'upload_throughput' pair");
+ }
+
+ // |offline| is optional.
+ if (conditions->HasKey("offline")) {
+ if (!conditions->GetBoolean("offline", &network_conditions.offline))
+ return Status(kUnknownError, "invalid 'offline'");
+ } else {
+ network_conditions.offline = false;
+ }
+
+ Status status = web_view->OverrideNetworkConditions(network_conditions);
+ if (status.IsOk())
+ session->overridden_network_conditions.reset(
+ new NetworkConditions(network_conditions));
+ return status;
+}
+
Status ExecuteTakeHeapSnapshot(
Session* session,
WebView* web_view,
« chrome/test/chromedriver/test/run_py_tests.py ('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