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