Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; |
| 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); |
|
samuong
2015/03/13 22:30:51
I think your code would be simpler if you made Fin
srawlins
2015/03/16 18:26:28
Good call. Done.
samuong
2015/03/16 18:43:10
Oh, I meant just change FindPresetNetwork() to use
srawlins
2015/03/16 19:23:11
Done.
| |
| 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 network_conditions.reset(new NetworkConditions()); | |
| 888 // |latency| is required. | |
| 889 if (!conditions->GetDouble("latency", &network_conditions->latency)) | |
| 890 return Status(kUnknownError, | |
| 891 "invalid 'network_conditions' is missing 'latency'"); | |
| 883 | 892 |
| 884 // Either |throughput| or the pair |download_throughput| and | 893 // Either |throughput| or the pair |download_throughput| and |
| 885 // |upload_throughput| is required. | 894 // |upload_throughput| is required. |
| 886 if (conditions->HasKey("throughput")) { | 895 if (conditions->HasKey("throughput")) { |
| 887 if (!conditions->GetDouble("throughput", | 896 if (!conditions->GetDouble("throughput", |
| 888 &network_conditions.download_throughput)) | 897 &network_conditions->download_throughput)) |
| 889 return Status(kUnknownError, "invalid 'throughput'"); | 898 return Status(kUnknownError, "invalid 'throughput'"); |
| 890 conditions->GetDouble("throughput", &network_conditions.upload_throughput); | 899 conditions->GetDouble("throughput", |
| 891 } else if (conditions->HasKey("download_throughput") && | 900 &network_conditions->upload_throughput); |
| 892 conditions->HasKey("upload_throughput")) { | 901 } else if (conditions->HasKey("download_throughput") && |
| 893 if (!conditions->GetDouble("download_throughput", | 902 conditions->HasKey("upload_throughput")) { |
| 894 &network_conditions.download_throughput) || | 903 if (!conditions->GetDouble("download_throughput", |
| 895 !conditions->GetDouble("upload_throughput", | 904 &network_conditions->download_throughput) || |
|
samuong
2015/03/13 22:30:51
nit: unindent by 1 char
srawlins
2015/03/16 18:26:28
Done.
| |
| 896 &network_conditions.upload_throughput)) | 905 !conditions->GetDouble("upload_throughput", |
| 906 &network_conditions->upload_throughput)) | |
|
samuong
2015/03/13 22:30:51
nit: unindent by 1 char
srawlins
2015/03/16 18:26:28
Done.
| |
| 907 return Status(kUnknownError, | |
| 908 "invalid 'download_throughput' or 'upload_throughput'"); | |
| 909 } else { | |
| 897 return Status(kUnknownError, | 910 return Status(kUnknownError, |
| 898 "invalid 'download_throughput' or 'upload_throughput'"); | 911 "invalid 'network_conditions' is missing 'throughput' or " |
| 912 "'download_throughput'/'upload_throughput' pair"); | |
| 913 } | |
| 914 | |
| 915 // |offline| is optional. | |
| 916 if (conditions->HasKey("offline")) { | |
| 917 if (!conditions->GetBoolean("offline", &network_conditions->offline)) | |
| 918 return Status(kUnknownError, "invalid 'offline'"); | |
| 919 } else { | |
| 920 network_conditions->offline = false; | |
| 921 } | |
| 899 } else { | 922 } else { |
| 900 return Status(kUnknownError, | 923 return Status(kUnknownError, |
| 901 "invalid 'network_conditions' is missing 'throughput' or " | 924 "either 'network_conditions' or 'network_name' must be " |
| 902 "'download_throughput'/'upload_throughput' pair"); | 925 "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 } | 926 } |
| 912 | 927 |
| 913 session->overridden_network_conditions.reset( | 928 session->overridden_network_conditions.reset( |
| 914 new NetworkConditions(network_conditions)); | 929 new NetworkConditions(*network_conditions.release())); |
| 915 return web_view->OverrideNetworkConditions( | 930 return web_view->OverrideNetworkConditions( |
| 916 *session->overridden_network_conditions); | 931 *session->overridden_network_conditions); |
| 917 } | 932 } |
| 918 | 933 |
| 919 Status ExecuteTakeHeapSnapshot( | 934 Status ExecuteTakeHeapSnapshot( |
| 920 Session* session, | 935 Session* session, |
| 921 WebView* web_view, | 936 WebView* web_view, |
| 922 const base::DictionaryValue& params, | 937 const base::DictionaryValue& params, |
| 923 scoped_ptr<base::Value>* value) { | 938 scoped_ptr<base::Value>* value) { |
| 924 return web_view->TakeHeapSnapshot(value); | 939 return web_view->TakeHeapSnapshot(value); |
| 925 } | 940 } |
| OLD | NEW |