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

Side by Side Diff: chrome/test/chromedriver/window_commands.cc

Issue 1004843002: [chromedriver] Add Network Presets to Network Throttling feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 9 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
« no previous file with comments | « chrome/test/chromedriver/test/run_py_tests.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <list> 7 #include <list>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/test/chromedriver/basic_types.h" 16 #include "chrome/test/chromedriver/basic_types.h"
17 #include "chrome/test/chromedriver/chrome/automation_extension.h" 17 #include "chrome/test/chromedriver/chrome/automation_extension.h"
18 #include "chrome/test/chromedriver/chrome/chrome.h" 18 #include "chrome/test/chromedriver/chrome/chrome.h"
19 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" 19 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h"
20 #include "chrome/test/chromedriver/chrome/devtools_client.h" 20 #include "chrome/test/chromedriver/chrome/devtools_client.h"
21 #include "chrome/test/chromedriver/chrome/geoposition.h" 21 #include "chrome/test/chromedriver/chrome/geoposition.h"
22 #include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h" 22 #include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h"
23 #include "chrome/test/chromedriver/chrome/js.h" 23 #include "chrome/test/chromedriver/chrome/js.h"
24 #include "chrome/test/chromedriver/chrome/network_conditions.h"
24 #include "chrome/test/chromedriver/chrome/status.h" 25 #include "chrome/test/chromedriver/chrome/status.h"
25 #include "chrome/test/chromedriver/chrome/ui_events.h" 26 #include "chrome/test/chromedriver/chrome/ui_events.h"
26 #include "chrome/test/chromedriver/chrome/web_view.h" 27 #include "chrome/test/chromedriver/chrome/web_view.h"
27 #include "chrome/test/chromedriver/element_util.h" 28 #include "chrome/test/chromedriver/element_util.h"
28 #include "chrome/test/chromedriver/session.h" 29 #include "chrome/test/chromedriver/session.h"
29 #include "chrome/test/chromedriver/util.h" 30 #include "chrome/test/chromedriver/util.h"
30 31
31 namespace { 32 namespace {
32 33
33 Status GetMouseButton(const base::DictionaryValue& params, 34 Status GetMouseButton(const base::DictionaryValue& params,
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 if (status.IsOk()) 868 if (status.IsOk())
868 session->overridden_geoposition.reset(new Geoposition(geoposition)); 869 session->overridden_geoposition.reset(new Geoposition(geoposition));
869 return status; 870 return status;
870 } 871 }
871 872
872 Status ExecuteSetNetworkConditions( 873 Status ExecuteSetNetworkConditions(
873 Session* session, 874 Session* session,
874 WebView* web_view, 875 WebView* web_view,
875 const base::DictionaryValue& params, 876 const base::DictionaryValue& params,
876 scoped_ptr<base::Value>* value) { 877 scoped_ptr<base::Value>* value) {
878 std::string network_name;
877 const base::DictionaryValue* conditions = NULL; 879 const base::DictionaryValue* conditions = NULL;
878 NetworkConditions network_conditions; 880 scoped_ptr<NetworkConditions> network_conditions(new NetworkConditions());
879 // |latency| is required. 881 if (params.GetString("network_name", &network_name)) {
880 if (!params.GetDictionary("network_conditions", &conditions) || 882 // Get conditions from preset list.
881 !conditions->GetDouble("latency", &network_conditions.latency)) 883 Status status = FindPresetNetwork(network_name, network_conditions.get());
882 return Status(kUnknownError, "missing or invalid 'network_conditions'"); 884 if (status.IsError())
885 return status;
886 } else if (params.GetDictionary("network_conditions", &conditions)) {
887 // |latency| is required.
888 if (!conditions->GetDouble("latency", &network_conditions->latency))
889 return Status(kUnknownError,
890 "invalid 'network_conditions' is missing 'latency'");
883 891
884 // Either |throughput| or the pair |download_throughput| and 892 // Either |throughput| or the pair |download_throughput| and
885 // |upload_throughput| is required. 893 // |upload_throughput| is required.
886 if (conditions->HasKey("throughput")) { 894 if (conditions->HasKey("throughput")) {
887 if (!conditions->GetDouble("throughput", 895 if (!conditions->GetDouble("throughput",
888 &network_conditions.download_throughput)) 896 &network_conditions->download_throughput))
889 return Status(kUnknownError, "invalid 'throughput'"); 897 return Status(kUnknownError, "invalid 'throughput'");
890 conditions->GetDouble("throughput", &network_conditions.upload_throughput); 898 conditions->GetDouble("throughput",
891 } else if (conditions->HasKey("download_throughput") && 899 &network_conditions->upload_throughput);
892 conditions->HasKey("upload_throughput")) { 900 } else if (conditions->HasKey("download_throughput") &&
893 if (!conditions->GetDouble("download_throughput", 901 conditions->HasKey("upload_throughput")) {
894 &network_conditions.download_throughput) || 902 if (!conditions->GetDouble("download_throughput",
895 !conditions->GetDouble("upload_throughput", 903 &network_conditions->download_throughput) ||
896 &network_conditions.upload_throughput)) 904 !conditions->GetDouble("upload_throughput",
905 &network_conditions->upload_throughput))
906 return Status(kUnknownError,
907 "invalid 'download_throughput' or 'upload_throughput'");
908 } else {
897 return Status(kUnknownError, 909 return Status(kUnknownError,
898 "invalid 'download_throughput' or 'upload_throughput'"); 910 "invalid 'network_conditions' is missing 'throughput' or "
911 "'download_throughput'/'upload_throughput' pair");
912 }
913
914 // |offline| is optional.
915 if (conditions->HasKey("offline")) {
916 if (!conditions->GetBoolean("offline", &network_conditions->offline))
917 return Status(kUnknownError, "invalid 'offline'");
918 } else {
919 network_conditions->offline = false;
920 }
899 } else { 921 } else {
900 return Status(kUnknownError, 922 return Status(kUnknownError,
901 "invalid 'network_conditions' is missing 'throughput' or " 923 "either 'network_conditions' or 'network_name' must be "
902 "'download_throughput'/'upload_throughput' pair"); 924 "supplied");
903 }
904
905 // |offline| is optional.
906 if (conditions->HasKey("offline")) {
907 if (!conditions->GetBoolean("offline", &network_conditions.offline))
908 return Status(kUnknownError, "invalid 'offline'");
909 } else {
910 network_conditions.offline = false;
911 } 925 }
912 926
913 session->overridden_network_conditions.reset( 927 session->overridden_network_conditions.reset(
914 new NetworkConditions(network_conditions)); 928 network_conditions.release());
915 return web_view->OverrideNetworkConditions( 929 return web_view->OverrideNetworkConditions(
916 *session->overridden_network_conditions); 930 *session->overridden_network_conditions);
917 } 931 }
918 932
919 Status ExecuteTakeHeapSnapshot( 933 Status ExecuteTakeHeapSnapshot(
920 Session* session, 934 Session* session,
921 WebView* web_view, 935 WebView* web_view,
922 const base::DictionaryValue& params, 936 const base::DictionaryValue& params,
923 scoped_ptr<base::Value>* value) { 937 scoped_ptr<base::Value>* value) {
924 return web_view->TakeHeapSnapshot(value); 938 return web_view->TakeHeapSnapshot(value);
925 } 939 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/test/run_py_tests.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698