OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "net/test/spawned_test_server/remote_test_server.h" | 5 #include "net/test/spawned_test_server/remote_test_server.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 9 #include <limits> |
7 #include <vector> | 10 #include <vector> |
8 | 11 |
9 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
10 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
12 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 16 #include "base/logging.h" |
14 #include "base/path_service.h" | 17 #include "base/path_service.h" |
15 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // pass right server type to Python test server. | 104 // pass right server type to Python test server. |
102 arguments_dict.SetString("server-type", GetServerTypeString(type())); | 105 arguments_dict.SetString("server-type", GetServerTypeString(type())); |
103 | 106 |
104 // Generate JSON-formatted argument string. | 107 // Generate JSON-formatted argument string. |
105 std::string arguments_string; | 108 std::string arguments_string; |
106 base::JSONWriter::Write(arguments_dict, &arguments_string); | 109 base::JSONWriter::Write(arguments_dict, &arguments_string); |
107 if (arguments_string.empty()) | 110 if (arguments_string.empty()) |
108 return false; | 111 return false; |
109 | 112 |
110 // Start the Python test server on the remote machine. | 113 // Start the Python test server on the remote machine. |
111 uint16 test_server_port; | 114 uint16_t test_server_port; |
112 if (!spawner_communicator_->StartServer(arguments_string, | 115 if (!spawner_communicator_->StartServer(arguments_string, |
113 &test_server_port)) { | 116 &test_server_port)) { |
114 return false; | 117 return false; |
115 } | 118 } |
116 if (0 == test_server_port) | 119 if (0 == test_server_port) |
117 return false; | 120 return false; |
118 | 121 |
119 // Construct server data to initialize BaseTestServer::server_data_. | 122 // Construct server data to initialize BaseTestServer::server_data_. |
120 base::DictionaryValue server_data_dict; | 123 base::DictionaryValue server_data_dict; |
121 // At this point, the test server should be spawned on the host. Update the | 124 // At this point, the test server should be spawned on the host. Update the |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 180 } |
178 | 181 |
179 std::vector<std::string> ports = base::SplitString( | 182 std::vector<std::string> ports = base::SplitString( |
180 port_info, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 183 port_info, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
181 if (ports.size() != 2u) | 184 if (ports.size() != 2u) |
182 return false; | 185 return false; |
183 | 186 |
184 // Verify the ports information. | 187 // Verify the ports information. |
185 base::StringToInt(ports[0], &spawner_server_port_); | 188 base::StringToInt(ports[0], &spawner_server_port_); |
186 if (!spawner_server_port_ || | 189 if (!spawner_server_port_ || |
187 static_cast<uint32>(spawner_server_port_) >= kuint16max) | 190 static_cast<uint32_t>(spawner_server_port_) >= |
| 191 std::numeric_limits<uint16_t>::max()) |
188 return false; | 192 return false; |
189 | 193 |
190 // Allow the test_server_port to be 0, which means the test server spawner | 194 // Allow the test_server_port to be 0, which means the test server spawner |
191 // will pick up a random port to run the test server. | 195 // will pick up a random port to run the test server. |
192 base::StringToInt(ports[1], &test_server_port); | 196 base::StringToInt(ports[1], &test_server_port); |
193 if (static_cast<uint32>(test_server_port) >= kuint16max) | 197 if (static_cast<uint32_t>(test_server_port) >= |
| 198 std::numeric_limits<uint16_t>::max()) |
194 return false; | 199 return false; |
195 SetPort(test_server_port); | 200 SetPort(test_server_port); |
196 | 201 |
197 // Unlike LocalTestServer, RemoteTestServer passes relative paths to the test | 202 // Unlike LocalTestServer, RemoteTestServer passes relative paths to the test |
198 // server. The test server fails on empty strings in some configurations. | 203 // server. The test server fails on empty strings in some configurations. |
199 base::FilePath fixed_root = document_root; | 204 base::FilePath fixed_root = document_root; |
200 if (fixed_root.empty()) | 205 if (fixed_root.empty()) |
201 fixed_root = base::FilePath(base::FilePath::kCurrentDirectory); | 206 fixed_root = base::FilePath(base::FilePath::kCurrentDirectory); |
202 SetResourcePath(fixed_root, base::FilePath().AppendASCII("net") | 207 SetResourcePath(fixed_root, base::FilePath().AppendASCII("net") |
203 .AppendASCII("data") | 208 .AppendASCII("data") |
204 .AppendASCII("ssl") | 209 .AppendASCII("ssl") |
205 .AppendASCII("certificates")); | 210 .AppendASCII("certificates")); |
206 return true; | 211 return true; |
207 } | 212 } |
208 | 213 |
209 } // namespace net | 214 } // namespace net |
210 | 215 |
OLD | NEW |