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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/chromedriver/window_commands.h" 5 #include "chrome/test/chromedriver/window_commands.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
11 11
12 #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.
13
12 #include "base/callback.h" 14 #include "base/callback.h"
13 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
15 #include "base/threading/platform_thread.h" 17 #include "base/threading/platform_thread.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
17 #include "base/values.h" 19 #include "base/values.h"
18 #include "chrome/test/chromedriver/basic_types.h" 20 #include "chrome/test/chromedriver/basic_types.h"
19 #include "chrome/test/chromedriver/chrome/automation_extension.h" 21 #include "chrome/test/chromedriver/chrome/automation_extension.h"
20 #include "chrome/test/chromedriver/chrome/browser_info.h" 22 #include "chrome/test/chromedriver/chrome/browser_info.h"
21 #include "chrome/test/chromedriver/chrome/chrome.h" 23 #include "chrome/test/chromedriver/chrome/chrome.h"
22 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" 24 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h"
23 #include "chrome/test/chromedriver/chrome/devtools_client.h" 25 #include "chrome/test/chromedriver/chrome/devtools_client.h"
24 #include "chrome/test/chromedriver/chrome/geoposition.h" 26 #include "chrome/test/chromedriver/chrome/geoposition.h"
25 #include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h" 27 #include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h"
26 #include "chrome/test/chromedriver/chrome/js.h" 28 #include "chrome/test/chromedriver/chrome/js.h"
27 #include "chrome/test/chromedriver/chrome/network_conditions.h" 29 #include "chrome/test/chromedriver/chrome/network_conditions.h"
30 #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
28 #include "chrome/test/chromedriver/chrome/status.h" 31 #include "chrome/test/chromedriver/chrome/status.h"
29 #include "chrome/test/chromedriver/chrome/ui_events.h" 32 #include "chrome/test/chromedriver/chrome/ui_events.h"
30 #include "chrome/test/chromedriver/chrome/web_view.h" 33 #include "chrome/test/chromedriver/chrome/web_view.h"
31 #include "chrome/test/chromedriver/element_util.h" 34 #include "chrome/test/chromedriver/element_util.h"
32 #include "chrome/test/chromedriver/net/timeout.h" 35 #include "chrome/test/chromedriver/net/timeout.h"
33 #include "chrome/test/chromedriver/session.h" 36 #include "chrome/test/chromedriver/session.h"
34 #include "chrome/test/chromedriver/util.h" 37 #include "chrome/test/chromedriver/util.h"
35 38
36 namespace { 39 namespace {
37 40
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 std::string network_name; 987 std::string network_name;
985 const base::DictionaryValue* conditions = NULL; 988 const base::DictionaryValue* conditions = NULL;
986 std::unique_ptr<NetworkConditions> network_conditions( 989 std::unique_ptr<NetworkConditions> network_conditions(
987 new NetworkConditions()); 990 new NetworkConditions());
988 if (params.GetString("network_name", &network_name)) { 991 if (params.GetString("network_name", &network_name)) {
989 // Get conditions from preset list. 992 // Get conditions from preset list.
990 Status status = FindPresetNetwork(network_name, network_conditions.get()); 993 Status status = FindPresetNetwork(network_name, network_conditions.get());
991 if (status.IsError()) 994 if (status.IsError())
992 return status; 995 return status;
993 } else if (params.GetDictionary("network_conditions", &conditions)) { 996 } else if (params.GetDictionary("network_conditions", &conditions)) {
997
samuong 2016/06/14 17:46:00 nitpick: delete this blank line
roisinmcl 2016/06/17 18:13:33 Done.
994 // |latency| is required. 998 // |latency| is required.
995 if (!conditions->GetDouble("latency", &network_conditions->latency)) 999 if (!conditions->GetDouble("latency", &network_conditions->latency))
996 return Status(kUnknownError, 1000 return Status(kUnknownError,
997 "invalid 'network_conditions' is missing 'latency'"); 1001 "invalid 'network_conditions' is missing 'latency'");
998 1002
999 // Either |throughput| or the pair |download_throughput| and 1003 // Either |throughput| or the pair |download_throughput| and
1000 // |upload_throughput| is required. 1004 // |upload_throughput| is required.
1001 if (conditions->HasKey("throughput")) { 1005 if (conditions->HasKey("throughput")) {
1002 if (!conditions->GetDouble("throughput", 1006 if (!conditions->GetDouble("throughput",
1003 &network_conditions->download_throughput)) 1007 &network_conditions->download_throughput))
(...skipping 26 matching lines...) Expand all
1030 "either 'network_conditions' or 'network_name' must be " 1034 "either 'network_conditions' or 'network_name' must be "
1031 "supplied"); 1035 "supplied");
1032 } 1036 }
1033 1037
1034 session->overridden_network_conditions.reset( 1038 session->overridden_network_conditions.reset(
1035 network_conditions.release()); 1039 network_conditions.release());
1036 return web_view->OverrideNetworkConditions( 1040 return web_view->OverrideNetworkConditions(
1037 *session->overridden_network_conditions); 1041 *session->overridden_network_conditions);
1038 } 1042 }
1039 1043
1044 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
1045 WebView* web_view,
1046 const base::DictionaryValue& params,
1047 std::unique_ptr<base::Value>* value,
1048 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.
1049 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.
1050 const int kWifiMask = 0x2;
1051 const int k4GMask = 0x8;
1052 const int k3GMask = 0x10;
1053 const int k2GMask = 0x20;
1054
1055 int connection_type;
1056
1057 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.
1058 return Status(kUnknownError,
1059 "invalid network_connections is missing 'connection_type'");
1060 }
1061
1062 std::unique_ptr<NetworkConditions> network_conditions(
1063 new NetworkConditions());
1064
1065 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.
1066 network_conditions->latency = 0;
1067 network_conditions->upload_throughput = 0;
1068 network_conditions->download_throughput = 0;
1069 network_conditions->offline = true;
1070 } else if (connection_type == kWifiMask) {
1071 network_conditions->latency = 2;
1072 network_conditions->upload_throughput = 30720 * 1024;
1073 network_conditions->download_throughput = 30720 * 1024;
1074 network_conditions->offline = false;
1075 } else if (connection_type == k4GMask) {
1076 network_conditions->latency = 20;
1077 network_conditions->upload_throughput = 4096 * 1024;
1078 network_conditions->download_throughput = 4096 * 1024;
1079 network_conditions->offline = false;
1080 } else if (connection_type == k3GMask) {
1081 network_conditions->latency = 100;
1082 network_conditions->upload_throughput = 750 * 1024;
1083 network_conditions->download_throughput = 750 * 1024;
1084 network_conditions->offline = false;
1085 } else if (connection_type == k2GMask) {
1086 network_conditions->latency = 300;
1087 network_conditions->upload_throughput = 250 * 1024;
1088 network_conditions->download_throughput = 250 * 1024;
1089 network_conditions->offline = false;
1090 } else {
1091 return Status(kUnknownError,
1092 "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.
1093 }
1094
1095 session->overridden_network_conditions.reset(
1096 network_conditions.release());
1097 return web_view->OverrideNetworkConditions(
1098 *session->overridden_network_conditions);
1099 }
1100
1040 Status ExecuteDeleteNetworkConditions(Session* session, 1101 Status ExecuteDeleteNetworkConditions(Session* session,
1041 WebView* web_view, 1102 WebView* web_view,
1042 const base::DictionaryValue& params, 1103 const base::DictionaryValue& params,
1043 std::unique_ptr<base::Value>* value, 1104 std::unique_ptr<base::Value>* value,
1044 Timeout* timeout) { 1105 Timeout* timeout) {
1045 // Chrome does not have any command to stop overriding network conditions, so 1106 // Chrome does not have any command to stop overriding network conditions, so
1046 // we just override the network conditions with the "No throttling" preset. 1107 // we just override the network conditions with the "No throttling" preset.
1047 NetworkConditions network_conditions; 1108 NetworkConditions network_conditions;
1048 // Get conditions from preset list. 1109 // Get conditions from preset list.
1049 Status status = FindPresetNetwork("No throttling", &network_conditions); 1110 Status status = FindPresetNetwork("No throttling", &network_conditions);
(...skipping 10 matching lines...) Expand all
1060 return status; 1121 return status;
1061 } 1122 }
1062 1123
1063 Status ExecuteTakeHeapSnapshot(Session* session, 1124 Status ExecuteTakeHeapSnapshot(Session* session,
1064 WebView* web_view, 1125 WebView* web_view,
1065 const base::DictionaryValue& params, 1126 const base::DictionaryValue& params,
1066 std::unique_ptr<base::Value>* value, 1127 std::unique_ptr<base::Value>* value,
1067 Timeout* timeout) { 1128 Timeout* timeout) {
1068 return web_view->TakeHeapSnapshot(value); 1129 return web_view->TakeHeapSnapshot(value);
1069 } 1130 }
OLDNEW
« 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