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/remote_test_server.h" | 5 #include "net/test/remote_test_server.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // root in the host machine where the test server is launched. So prepend | 154 // root in the host machine where the test server is launched. So prepend |
155 // DIR_SOURCE_ROOT here to get the actual path of document root on the Android | 155 // DIR_SOURCE_ROOT here to get the actual path of document root on the Android |
156 // device. | 156 // device. |
157 FilePath RemoteTestServer::GetDocumentRoot() const { | 157 FilePath RemoteTestServer::GetDocumentRoot() const { |
158 FilePath src_dir; | 158 FilePath src_dir; |
159 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir); | 159 PathService::Get(base::DIR_SOURCE_ROOT, &src_dir); |
160 return src_dir.Append(document_root()); | 160 return src_dir.Append(document_root()); |
161 } | 161 } |
162 | 162 |
163 bool RemoteTestServer::Init(const FilePath& document_root) { | 163 bool RemoteTestServer::Init(const FilePath& document_root) { |
164 if (document_root.IsAbsolute()) | |
165 return false; | |
166 | |
167 // Gets ports information used by test server spawner and Python test server. | 164 // Gets ports information used by test server spawner and Python test server. |
168 int test_server_port = 0; | 165 int test_server_port = 0; |
169 | 166 |
170 // Parse file to extract the ports information. | 167 // Parse file to extract the ports information. |
171 std::string port_info; | 168 std::string port_info; |
172 if (!file_util::ReadFileToString(GetTestServerPortInfoFile(), | 169 if (!file_util::ReadFileToString(GetTestServerPortInfoFile(), |
173 &port_info) || | 170 &port_info) || |
174 port_info.empty()) { | 171 port_info.empty()) { |
175 return false; | 172 return false; |
176 } | 173 } |
177 | 174 |
178 std::vector<std::string> ports; | 175 std::vector<std::string> ports; |
179 base::SplitString(port_info, ':', &ports); | 176 base::SplitString(port_info, ':', &ports); |
180 if (ports.size() != 2u) | 177 if (ports.size() != 2u) |
181 return false; | 178 return false; |
182 | 179 |
183 // Verify the ports information. | 180 // Verify the ports information. |
184 base::StringToInt(ports[0], &spawner_server_port_); | 181 base::StringToInt(ports[0], &spawner_server_port_); |
185 if (!spawner_server_port_ || | 182 if (!spawner_server_port_ || |
186 static_cast<uint32>(spawner_server_port_) >= kuint16max) | 183 static_cast<uint32>(spawner_server_port_) >= kuint16max) |
187 return false; | 184 return false; |
188 | 185 |
189 // Allow the test_server_port to be 0, which means the test server spawner | 186 // Allow the test_server_port to be 0, which means the test server spawner |
190 // will pick up a random port to run the test server. | 187 // will pick up a random port to run the test server. |
191 base::StringToInt(ports[1], &test_server_port); | 188 base::StringToInt(ports[1], &test_server_port); |
192 if (static_cast<uint32>(test_server_port) >= kuint16max) | 189 if (static_cast<uint32>(test_server_port) >= kuint16max) |
193 return false; | 190 return false; |
194 SetPort(test_server_port); | 191 SetPort(test_server_port); |
195 | 192 |
196 SetResourcePath(document_root, FilePath().AppendASCII("net") | 193 FilePath root; |
197 .AppendASCII("data") | 194 if (document_root.IsAbsolute()) { |
198 .AppendASCII("ssl") | 195 root = document_root; |
199 .AppendASCII("certificates")); | 196 } else { |
| 197 FilePath src_dir; |
| 198 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) |
| 199 return false; |
| 200 root = src_dir.Append(document_root); |
| 201 } |
| 202 |
| 203 SetResourcePath(root, FilePath().AppendASCII("net") |
| 204 .AppendASCII("data") |
| 205 .AppendASCII("ssl") |
| 206 .AppendASCII("certificates")); |
200 return true; | 207 return true; |
201 } | 208 } |
202 | 209 |
203 } // namespace net | 210 } // namespace net |
204 | 211 |
OLD | NEW |