OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/local_test_server.h" | 5 #include "net/test/local_test_server.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 const FilePath& document_root) | 69 const FilePath& document_root) |
70 : BaseTestServer(https_options) { | 70 : BaseTestServer(https_options) { |
71 if (!Init(document_root)) | 71 if (!Init(document_root)) |
72 NOTREACHED(); | 72 NOTREACHED(); |
73 } | 73 } |
74 | 74 |
75 LocalTestServer::~LocalTestServer() { | 75 LocalTestServer::~LocalTestServer() { |
76 Stop(); | 76 Stop(); |
77 } | 77 } |
78 | 78 |
| 79 // static |
| 80 bool LocalTestServer::GetTestServerDirectory(FilePath* directory) { |
| 81 // Get path to python server script. |
| 82 FilePath testserver_dir; |
| 83 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) { |
| 84 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
| 85 return false; |
| 86 } |
| 87 |
| 88 testserver_dir = testserver_dir |
| 89 .Append(FILE_PATH_LITERAL("net")) |
| 90 .Append(FILE_PATH_LITERAL("tools")) |
| 91 .Append(FILE_PATH_LITERAL("testserver")); |
| 92 *directory = testserver_dir; |
| 93 return true; |
| 94 } |
| 95 |
79 bool LocalTestServer::Start() { | 96 bool LocalTestServer::Start() { |
80 // Get path to Python server script. | 97 // Get path to Python server script. |
81 FilePath testserver_path; | 98 FilePath testserver_path; |
82 if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)) { | 99 if (!GetTestServerDirectory(&testserver_path)) |
83 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | |
84 return false; | 100 return false; |
85 } | 101 testserver_path = |
86 testserver_path = testserver_path | 102 testserver_path.Append(FILE_PATH_LITERAL("testserver.py")); |
87 .Append(FILE_PATH_LITERAL("net")) | |
88 .Append(FILE_PATH_LITERAL("tools")) | |
89 .Append(FILE_PATH_LITERAL("testserver")) | |
90 .Append(FILE_PATH_LITERAL("testserver.py")); | |
91 | 103 |
92 if (!SetPythonPath()) | 104 if (!SetPythonPath()) |
93 return false; | 105 return false; |
94 | 106 |
95 if (!LaunchPython(testserver_path)) | 107 if (!LaunchPython(testserver_path)) |
96 return false; | 108 return false; |
97 | 109 |
98 if (!WaitToStart()) { | 110 if (!WaitToStart()) { |
99 Stop(); | 111 Stop(); |
100 return false; | 112 return false; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) | 151 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) |
140 return false; | 152 return false; |
141 SetResourcePath(src_dir.Append(document_root), | 153 SetResourcePath(src_dir.Append(document_root), |
142 src_dir.AppendASCII("net") | 154 src_dir.AppendASCII("net") |
143 .AppendASCII("data") | 155 .AppendASCII("data") |
144 .AppendASCII("ssl") | 156 .AppendASCII("ssl") |
145 .AppendASCII("certificates")); | 157 .AppendASCII("certificates")); |
146 return true; | 158 return true; |
147 } | 159 } |
148 | 160 |
149 bool LocalTestServer::SetPythonPath() const { | 161 // static |
| 162 bool LocalTestServer::SetPythonPath() { |
150 FilePath third_party_dir; | 163 FilePath third_party_dir; |
151 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { | 164 if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { |
152 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; | 165 LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; |
153 return false; | 166 return false; |
154 } | 167 } |
155 third_party_dir = third_party_dir.AppendASCII("third_party"); | 168 third_party_dir = third_party_dir.AppendASCII("third_party"); |
156 | 169 |
157 // For simplejson. (simplejson, unlike all the other Python modules | 170 // For simplejson. (simplejson, unlike all the other Python modules |
158 // we include, doesn't have an extra 'simplejson' directory, so we | 171 // we include, doesn't have an extra 'simplejson' directory, so we |
159 // need to include its parent directory, i.e. third_party_dir). | 172 // need to include its parent directory, i.e. third_party_dir). |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 break; | 244 break; |
232 default: | 245 default: |
233 NOTREACHED(); | 246 NOTREACHED(); |
234 return false; | 247 return false; |
235 } | 248 } |
236 | 249 |
237 return true; | 250 return true; |
238 } | 251 } |
239 | 252 |
240 } // namespace net | 253 } // namespace net |
OLD | NEW |