| 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 <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 // This URLRequestContext does not use a local cache. | 39 // This URLRequestContext does not use a local cache. |
| 40 class TestURLRequestContext : public URLRequestContext { | 40 class TestURLRequestContext : public URLRequestContext { |
| 41 public: | 41 public: |
| 42 TestURLRequestContext() { | 42 TestURLRequestContext() { |
| 43 proxy_service_ = net::ProxyService::CreateNull(); | 43 proxy_service_ = net::ProxyService::CreateNull(); |
| 44 http_transaction_factory_ = | 44 http_transaction_factory_ = |
| 45 net::HttpNetworkLayer::CreateFactory(proxy_service_); | 45 net::HttpNetworkLayer::CreateFactory(proxy_service_); |
| 46 } | 46 } |
| 47 | 47 |
| 48 explicit TestURLRequestContext(const std::string& proxy) { |
| 49 net::ProxyInfo proxy_info; |
| 50 proxy_info.UseNamedProxy(proxy); |
| 51 proxy_service_ = net::ProxyService::Create(&proxy_info); |
| 52 http_transaction_factory_ = |
| 53 net::HttpNetworkLayer::CreateFactory(proxy_service_); |
| 54 } |
| 55 |
| 48 virtual ~TestURLRequestContext() { | 56 virtual ~TestURLRequestContext() { |
| 49 delete http_transaction_factory_; | 57 delete http_transaction_factory_; |
| 50 delete proxy_service_; | 58 delete proxy_service_; |
| 51 } | 59 } |
| 52 }; | 60 }; |
| 53 | 61 |
| 54 class TestDelegate : public URLRequest::Delegate { | 62 class TestDelegate : public URLRequest::Delegate { |
| 55 public: | 63 public: |
| 56 TestDelegate() | 64 TestDelegate() |
| 57 : cancel_in_rr_(false), | 65 : cancel_in_rr_(false), |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 std::wstring normalized_document_root = document_root; | 356 std::wstring normalized_document_root = document_root; |
| 349 | 357 |
| 350 #if defined(OS_WIN) | 358 #if defined(OS_WIN) |
| 351 // It is just for windows only and have no effect on other OS | 359 // It is just for windows only and have no effect on other OS |
| 352 std::replace(normalized_document_root.begin(), | 360 std::replace(normalized_document_root.begin(), |
| 353 normalized_document_root.end(), | 361 normalized_document_root.end(), |
| 354 L'/', FilePath::kSeparators[0]); | 362 L'/', FilePath::kSeparators[0]); |
| 355 #endif | 363 #endif |
| 356 if (!normalized_document_root.empty()) | 364 if (!normalized_document_root.empty()) |
| 357 file_util::AppendToPath(test_data_directory, normalized_document_root); | 365 file_util::AppendToPath(test_data_directory, normalized_document_root); |
| 358 | |
| 359 data_directory_ = *test_data_directory; | 366 data_directory_ = *test_data_directory; |
| 360 } | 367 } |
| 361 | 368 |
| 362 #if defined(OS_WIN) | 369 #if defined(OS_WIN) |
| 363 void LaunchApp(const std::wstring& command_line) { | 370 void LaunchApp(const std::wstring& command_line) { |
| 364 ASSERT_TRUE(base::LaunchApp(command_line, false, true, &process_handle_)) << | 371 ASSERT_TRUE(base::LaunchApp(command_line, false, true, &process_handle_)) << |
| 365 "Failed to launch " << command_line; | 372 "Failed to launch " << command_line; |
| 366 } | 373 } |
| 367 #elif defined(OS_POSIX) | 374 #elif defined(OS_POSIX) |
| 368 void LaunchApp(const std::vector<std::string>& command_line) { | 375 void LaunchApp(const std::vector<std::string>& command_line) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 virtual bool MakeGETRequest(const std::string& page_name) { | 482 virtual bool MakeGETRequest(const std::string& page_name) { |
| 476 const GURL& url = TestServerPage(page_name); | 483 const GURL& url = TestServerPage(page_name); |
| 477 | 484 |
| 478 // Spin up a background thread for this request so that we have access to | 485 // Spin up a background thread for this request so that we have access to |
| 479 // an IO message loop, and in cases where this thread already has an IO | 486 // an IO message loop, and in cases where this thread already has an IO |
| 480 // message loop, we also want to avoid spinning a nested message loop. | 487 // message loop, we also want to avoid spinning a nested message loop. |
| 481 SyncTestDelegate d; | 488 SyncTestDelegate d; |
| 482 { | 489 { |
| 483 MessageLoop* loop = loop_; | 490 MessageLoop* loop = loop_; |
| 484 scoped_ptr<base::Thread> io_thread; | 491 scoped_ptr<base::Thread> io_thread; |
| 485 | 492 |
| 486 if (!loop) { | 493 if (!loop) { |
| 487 io_thread.reset(new base::Thread("MakeGETRequest")); | 494 io_thread.reset(new base::Thread("MakeGETRequest")); |
| 488 base::Thread::Options options; | 495 base::Thread::Options options; |
| 489 options.message_loop_type = MessageLoop::TYPE_IO; | 496 options.message_loop_type = MessageLoop::TYPE_IO; |
| 490 io_thread->StartWithOptions(options); | 497 io_thread->StartWithOptions(options); |
| 491 loop = io_thread->message_loop(); | 498 loop = io_thread->message_loop(); |
| 492 } | 499 } |
| 493 loop->PostTask(FROM_HERE, NewRunnableFunction( | 500 loop->PostTask(FROM_HERE, NewRunnableFunction( |
| 494 &HTTPTestServer::StartGETRequest, url, &d)); | 501 &HTTPTestServer::StartGETRequest, url, &d)); |
| 495 | 502 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 command_line->push_back("python"); | 738 command_line->push_back("python"); |
| 732 command_line->push_back(WideToUTF8(testserver_path)); | 739 command_line->push_back(WideToUTF8(testserver_path)); |
| 733 command_line->push_back(" -f "); | 740 command_line->push_back(" -f "); |
| 734 command_line->push_back("--data-dir=" + WideToUTF8(test_data_directory)); | 741 command_line->push_back("--data-dir=" + WideToUTF8(test_data_directory)); |
| 735 command_line->push_back("--port=" + port_str_); | 742 command_line->push_back("--port=" + port_str_); |
| 736 } | 743 } |
| 737 #endif | 744 #endif |
| 738 }; | 745 }; |
| 739 | 746 |
| 740 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ | 747 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
| OLD | NEW |