| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 protected: | 241 protected: |
| 242 BaseTestServer() { } | 242 BaseTestServer() { } |
| 243 BaseTestServer(int connection_attempts, int connection_timeout) | 243 BaseTestServer(int connection_attempts, int connection_timeout) |
| 244 : launcher_(connection_attempts, connection_timeout) { } | 244 : launcher_(connection_attempts, connection_timeout) { } |
| 245 | 245 |
| 246 public: | 246 public: |
| 247 void set_forking(bool forking) { | 247 void set_forking(bool forking) { |
| 248 launcher_.set_forking(forking); | 248 launcher_.set_forking(forking); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void set_ftp_enable_anonymous(bool enable) { |
| 252 launcher_.set_ftp_enable_anonymous(enable); |
| 253 } |
| 254 |
| 251 // Used with e.g. HTTPTestServer::SendQuit() | 255 // Used with e.g. HTTPTestServer::SendQuit() |
| 252 bool WaitToFinish(int milliseconds) { | 256 bool WaitToFinish(int milliseconds) { |
| 253 return launcher_.WaitToFinish(milliseconds); | 257 return launcher_.WaitToFinish(milliseconds); |
| 254 } | 258 } |
| 255 | 259 |
| 256 bool Stop() { | 260 bool Stop() { |
| 257 return launcher_.Stop(); | 261 return launcher_.Stop(); |
| 258 } | 262 } |
| 259 | 263 |
| 260 GURL TestServerPage(const std::string& base_address, | 264 GURL TestServerPage(const std::string& base_address, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 std::wstring cert_path_; | 569 std::wstring cert_path_; |
| 566 }; | 570 }; |
| 567 | 571 |
| 568 | 572 |
| 569 class FTPTestServer : public BaseTestServer { | 573 class FTPTestServer : public BaseTestServer { |
| 570 public: | 574 public: |
| 571 FTPTestServer() { | 575 FTPTestServer() { |
| 572 } | 576 } |
| 573 | 577 |
| 574 static scoped_refptr<FTPTestServer> CreateServer( | 578 static scoped_refptr<FTPTestServer> CreateServer( |
| 575 const std::wstring& document_root) { | 579 const std::wstring& document_root, bool enable_anonymous) { |
| 576 scoped_refptr<FTPTestServer> test_server = new FTPTestServer(); | 580 scoped_refptr<FTPTestServer> test_server = new FTPTestServer(); |
| 581 test_server->set_ftp_enable_anonymous(enable_anonymous); |
| 577 FilePath docroot = FilePath::FromWStringHack(document_root); | 582 FilePath docroot = FilePath::FromWStringHack(document_root); |
| 578 FilePath no_cert; | 583 FilePath no_cert; |
| 579 if (!test_server->Start(net::TestServerLauncher::ProtoFTP, | 584 if (!test_server->Start(net::TestServerLauncher::ProtoFTP, |
| 580 kDefaultHostName, kFTPDefaultPort, docroot, no_cert, std::wstring())) { | 585 kDefaultHostName, kFTPDefaultPort, docroot, no_cert, std::wstring())) { |
| 581 return NULL; | 586 return NULL; |
| 582 } | 587 } |
| 583 return test_server; | 588 return test_server; |
| 584 } | 589 } |
| 585 | 590 |
| 586 virtual bool MakeGETRequest(const std::string& page_name) { | 591 virtual bool MakeGETRequest(const std::string& page_name) { |
| 587 const GURL& url = TestServerPage(page_name); | 592 const GURL& url = TestServerPage(page_name); |
| 588 TestDelegate d; | 593 TestDelegate d; |
| 589 URLRequest request(url, &d); | 594 URLRequest request(url, &d); |
| 590 request.set_context(new TestURLRequestContext()); | 595 request.set_context(new TestURLRequestContext()); |
| 591 request.set_method("GET"); | 596 request.set_method("GET"); |
| 592 request.Start(); | 597 request.Start(); |
| 593 EXPECT_TRUE(request.is_pending()); | 598 EXPECT_TRUE(request.is_pending()); |
| 594 | 599 |
| 595 MessageLoop::current()->Run(); | 600 MessageLoop::current()->Run(); |
| 596 if (request.is_pending()) | 601 if (request.is_pending()) |
| 597 return false; | 602 return false; |
| 598 | 603 |
| 599 return true; | 604 return true; |
| 600 } | 605 } |
| 601 }; | 606 }; |
| 602 | 607 |
| 603 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ | 608 #endif // NET_URL_REQUEST_URL_REQUEST_UNITTEST_H_ |
| OLD | NEW |