OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
7 | 7 |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 bool received_data_before_response_; | 178 bool received_data_before_response_; |
179 bool request_failed_; | 179 bool request_failed_; |
180 std::string data_received_; | 180 std::string data_received_; |
181 | 181 |
182 // our read buffer | 182 // our read buffer |
183 char buf_[4096]; | 183 char buf_[4096]; |
184 }; | 184 }; |
185 | 185 |
186 // This object bounds the lifetime of an external python-based HTTP server | 186 // This object bounds the lifetime of an external python-based HTTP server |
187 // that can provide various responses useful for testing. | 187 // that can provide various responses useful for testing. |
188 class TestServer : public process_util::ProcessFilter { | 188 class TestServer : public base::ProcessFilter { |
189 public: | 189 public: |
190 TestServer(const std::wstring& document_root) | 190 TestServer(const std::wstring& document_root) |
191 : process_handle_(NULL), | 191 : process_handle_(NULL), |
192 is_shutdown_(true) { | 192 is_shutdown_(true) { |
193 Init(kDefaultHostName, kDefaultPort, document_root, std::wstring()); | 193 Init(kDefaultHostName, kDefaultPort, document_root, std::wstring()); |
194 } | 194 } |
195 | 195 |
196 virtual ~TestServer() { | 196 virtual ~TestServer() { |
197 Shutdown(); | 197 Shutdown(); |
198 } | 198 } |
199 | 199 |
200 // Implementation of ProcessFilter | 200 // Implementation of ProcessFilter |
201 virtual bool Includes(uint32 pid, uint32 parent_pid) const { | 201 virtual bool Includes(uint32 pid, uint32 parent_pid) const { |
202 // This function may be called after Shutdown(), in which process_handle_ is | 202 // This function may be called after Shutdown(), in which process_handle_ is |
203 // set to NULL. Since no process handle is set, it can't be included in the | 203 // set to NULL. Since no process handle is set, it can't be included in the |
204 // filter. | 204 // filter. |
205 if (!process_handle_) | 205 if (!process_handle_) |
206 return false; | 206 return false; |
207 // TODO(port): rationalize return value of GetProcId | 207 // TODO(port): rationalize return value of GetProcId |
208 return pid == (uint32)process_util::GetProcId(process_handle_); | 208 return pid == (uint32)base::GetProcId(process_handle_); |
209 } | 209 } |
210 | 210 |
211 GURL TestServerPage(const std::string& path) { | 211 GURL TestServerPage(const std::string& path) { |
212 return GURL(base_address_ + path); | 212 return GURL(base_address_ + path); |
213 } | 213 } |
214 | 214 |
215 GURL TestServerPageW(const std::wstring& path) { | 215 GURL TestServerPageW(const std::wstring& path) { |
216 return GURL(base_address_ + WideToUTF8(path)); | 216 return GURL(base_address_ + WideToUTF8(path)); |
217 } | 217 } |
218 | 218 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 L"\"" + python_runtime_ + L"\" " + L"\"" + testserver_path + | 286 L"\"" + python_runtime_ + L"\" " + L"\"" + testserver_path + |
287 L"\" --port=" + UTF8ToWide(port_str) + L" --data-dir=\"" + | 287 L"\" --port=" + UTF8ToWide(port_str) + L" --data-dir=\"" + |
288 test_data_directory + L"\""; | 288 test_data_directory + L"\""; |
289 if (!cert_path.empty()) { | 289 if (!cert_path.empty()) { |
290 command_line.append(L" --https=\""); | 290 command_line.append(L" --https=\""); |
291 command_line.append(cert_path); | 291 command_line.append(cert_path); |
292 command_line.append(L"\""); | 292 command_line.append(L"\""); |
293 } | 293 } |
294 | 294 |
295 ASSERT_TRUE( | 295 ASSERT_TRUE( |
296 process_util::LaunchApp(command_line, false, true, &process_handle_)) << | 296 base::LaunchApp(command_line, false, true, &process_handle_)) << |
297 "Failed to launch " << command_line; | 297 "Failed to launch " << command_line; |
298 #elif defined(OS_LINUX) | 298 #elif defined(OS_LINUX) |
299 bool tlslite_installed = !access("/usr/bin/tls.py", X_OK); | 299 bool tlslite_installed = !access("/usr/bin/tls.py", X_OK); |
300 ASSERT_TRUE(tlslite_installed) << "tlslite not installed? Please run 'pytho
n setup.py install' in third_party/tlslite."; | 300 ASSERT_TRUE(tlslite_installed) << "tlslite not installed? Please run 'pytho
n setup.py install' in third_party/tlslite."; |
301 | 301 |
302 std::vector<std::string> command_line; | 302 std::vector<std::string> command_line; |
303 command_line.push_back("python"); | 303 command_line.push_back("python"); |
304 command_line.push_back(WideToUTF8(testserver_path)); | 304 command_line.push_back(WideToUTF8(testserver_path)); |
305 command_line.push_back("--port=" + port_str); | 305 command_line.push_back("--port=" + port_str); |
306 command_line.push_back("--data-dir=" + WideToUTF8(test_data_directory)); | 306 command_line.push_back("--data-dir=" + WideToUTF8(test_data_directory)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 if (process_handle_) { | 350 if (process_handle_) { |
351 #if defined(OS_WIN) | 351 #if defined(OS_WIN) |
352 CloseHandle(process_handle_); | 352 CloseHandle(process_handle_); |
353 #endif | 353 #endif |
354 process_handle_ = NULL; | 354 process_handle_ = NULL; |
355 } | 355 } |
356 | 356 |
357 // Make sure we don't leave any stray testserver processes laying around. | 357 // Make sure we don't leave any stray testserver processes laying around. |
358 std::wstring testserver_name = | 358 std::wstring testserver_name = |
359 file_util::GetFilenameFromPath(python_runtime_); | 359 file_util::GetFilenameFromPath(python_runtime_); |
360 process_util::CleanupProcesses(testserver_name, 10000, 1, this); | 360 base::CleanupProcesses(testserver_name, 10000, 1, this); |
361 EXPECT_EQ(0, process_util::GetProcessCount(testserver_name, this)); | 361 EXPECT_EQ(0, base::GetProcessCount(testserver_name, this)); |
362 | 362 |
363 is_shutdown_ = true; | 363 is_shutdown_ = true; |
364 } | 364 } |
365 | 365 |
366 private: | 366 private: |
367 // Used by MakeGETRequest to implement sync load behavior. | 367 // Used by MakeGETRequest to implement sync load behavior. |
368 class SyncTestDelegate : public TestDelegate { | 368 class SyncTestDelegate : public TestDelegate { |
369 public: | 369 public: |
370 SyncTestDelegate() : event_(false, false), success_(false) { | 370 SyncTestDelegate() : event_(false, false), success_(false) { |
371 } | 371 } |
(...skipping 12 matching lines...) Expand all Loading... |
384 static void StartGETRequest(const GURL& url, URLRequest::Delegate* delegate) { | 384 static void StartGETRequest(const GURL& url, URLRequest::Delegate* delegate) { |
385 URLRequest* request = new URLRequest(url, delegate); | 385 URLRequest* request = new URLRequest(url, delegate); |
386 request->set_context(new TestURLRequestContext()); | 386 request->set_context(new TestURLRequestContext()); |
387 request->set_method("GET"); | 387 request->set_method("GET"); |
388 request->Start(); | 388 request->Start(); |
389 EXPECT_TRUE(request->is_pending()); | 389 EXPECT_TRUE(request->is_pending()); |
390 } | 390 } |
391 | 391 |
392 std::string base_address_; | 392 std::string base_address_; |
393 std::wstring python_runtime_; | 393 std::wstring python_runtime_; |
394 ProcessHandle process_handle_; | 394 base::ProcessHandle process_handle_; |
395 bool is_shutdown_; | 395 bool is_shutdown_; |
396 }; | 396 }; |
397 | 397 |
398 class HTTPSTestServer : public TestServer { | 398 class HTTPSTestServer : public TestServer { |
399 public: | 399 public: |
400 HTTPSTestServer(const std::string& host_name, int port, | 400 HTTPSTestServer(const std::string& host_name, int port, |
401 const std::wstring& document_root, | 401 const std::wstring& document_root, |
402 const std::wstring& cert_path) : TestServer(ManualInit()) { | 402 const std::wstring& cert_path) : TestServer(ManualInit()) { |
403 Init(host_name, port, document_root, cert_path); | 403 Init(host_name, port, document_root, cert_path); |
404 } | 404 } |
405 | 405 |
406 virtual std::string scheme() { return std::string("https"); } | 406 virtual std::string scheme() { return std::string("https"); } |
407 }; | 407 }; |
408 | 408 |
409 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ | 409 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
410 | 410 |
OLD | NEW |