| 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 #include "base/thread.h" | 5 #include "base/thread.h" |
| 6 #include "base/time.h" | 6 #include "base/time.h" |
| 7 #include "chrome/browser/net/url_fetcher.h" | 7 #include "chrome/browser/net/url_fetcher.h" |
| 8 #include "chrome/browser/net/url_fetcher_protect.h" | 8 #include "chrome/browser/net/url_fetcher_protect.h" |
| 9 #include "chrome/common/chrome_plugin_lib.h" | 9 #include "chrome/common/chrome_plugin_lib.h" |
| 10 #include "net/base/ssl_test_util.h" | 10 #include "net/base/ssl_test_util.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 URLFetcherBadHTTPSTest(); | 97 URLFetcherBadHTTPSTest(); |
| 98 | 98 |
| 99 // URLFetcher::Delegate | 99 // URLFetcher::Delegate |
| 100 virtual void OnURLFetchComplete(const URLFetcher* source, | 100 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 101 const GURL& url, | 101 const GURL& url, |
| 102 const URLRequestStatus& status, | 102 const URLRequestStatus& status, |
| 103 int response_code, | 103 int response_code, |
| 104 const ResponseCookies& cookies, | 104 const ResponseCookies& cookies, |
| 105 const std::string& data); | 105 const std::string& data); |
| 106 | 106 |
| 107 protected: | |
| 108 FilePath GetExpiredCertPath(); | |
| 109 SSLTestUtil util_; | |
| 110 | |
| 111 private: | 107 private: |
| 112 FilePath cert_dir_; | 108 FilePath cert_dir_; |
| 113 }; | 109 }; |
| 114 | 110 |
| 115 // Version of URLFetcherTest that tests request cancellation on shutdown. | 111 // Version of URLFetcherTest that tests request cancellation on shutdown. |
| 116 class URLFetcherCancelTest : public URLFetcherTest { | 112 class URLFetcherCancelTest : public URLFetcherTest { |
| 117 public: | 113 public: |
| 118 virtual void CreateFetcher(const GURL& url); | 114 virtual void CreateFetcher(const GURL& url); |
| 119 // URLFetcher::Delegate | 115 // URLFetcher::Delegate |
| 120 virtual void OnURLFetchComplete(const URLFetcher* source, | 116 virtual void OnURLFetchComplete(const URLFetcher* source, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 EXPECT_EQ(net::ERR_ABORTED, status.os_error()); | 288 EXPECT_EQ(net::ERR_ABORTED, status.os_error()); |
| 293 EXPECT_EQ(-1, response_code); | 289 EXPECT_EQ(-1, response_code); |
| 294 EXPECT_TRUE(cookies.empty()); | 290 EXPECT_TRUE(cookies.empty()); |
| 295 EXPECT_TRUE(data.empty()); | 291 EXPECT_TRUE(data.empty()); |
| 296 | 292 |
| 297 // The rest is the same as URLFetcherTest::OnURLFetchComplete. | 293 // The rest is the same as URLFetcherTest::OnURLFetchComplete. |
| 298 delete fetcher_; | 294 delete fetcher_; |
| 299 io_loop_.Quit(); | 295 io_loop_.Quit(); |
| 300 } | 296 } |
| 301 | 297 |
| 302 FilePath URLFetcherBadHTTPSTest::GetExpiredCertPath() { | |
| 303 return cert_dir_.AppendASCII("expired_cert.pem"); | |
| 304 } | |
| 305 | |
| 306 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { | 298 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { |
| 307 fetcher_ = new URLFetcher(url, URLFetcher::GET, this); | 299 fetcher_ = new URLFetcher(url, URLFetcher::GET, this); |
| 308 fetcher_->set_request_context( | 300 fetcher_->set_request_context( |
| 309 new CancelTestURLRequestContext(&context_released_)); | 301 new CancelTestURLRequestContext(&context_released_)); |
| 310 fetcher_->set_io_loop(&io_loop_); | 302 fetcher_->set_io_loop(&io_loop_); |
| 311 fetcher_->Start(); | 303 fetcher_->Start(); |
| 312 // Make sure we give the IO thread a chance to run. | 304 // Make sure we give the IO thread a chance to run. |
| 313 timer_.Start(TimeDelta::FromMilliseconds(100), this, | 305 timer_.Start(TimeDelta::FromMilliseconds(100), this, |
| 314 &URLFetcherCancelTest::CancelRequest); | 306 &URLFetcherCancelTest::CancelRequest); |
| 315 } | 307 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 420 } |
| 429 | 421 |
| 430 #if defined(OS_WIN) | 422 #if defined(OS_WIN) |
| 431 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { | 423 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { |
| 432 #else | 424 #else |
| 433 // TODO(port): Enable BadHTTPSTest. Currently asserts in | 425 // TODO(port): Enable BadHTTPSTest. Currently asserts in |
| 434 // URLFetcherBadHTTPSTest::OnURLFetchComplete don't pass. | 426 // URLFetcherBadHTTPSTest::OnURLFetchComplete don't pass. |
| 435 TEST_F(URLFetcherBadHTTPSTest, DISABLED_BadHTTPSTest) { | 427 TEST_F(URLFetcherBadHTTPSTest, DISABLED_BadHTTPSTest) { |
| 436 #endif | 428 #endif |
| 437 scoped_refptr<HTTPSTestServer> server = | 429 scoped_refptr<HTTPSTestServer> server = |
| 438 HTTPSTestServer::CreateServer(util_.kHostName, util_.kBadHTTPSPort, | 430 HTTPSTestServer::CreateExpiredServer(kDocRoot); |
| 439 kDocRoot, util_.GetExpiredCertPath().ToWStringHack()); | |
| 440 ASSERT_TRUE(NULL != server.get()); | 431 ASSERT_TRUE(NULL != server.get()); |
| 441 | 432 |
| 442 CreateFetcher(GURL(server->TestServerPage("defaultresponse"))); | 433 CreateFetcher(GURL(server->TestServerPage("defaultresponse"))); |
| 443 | 434 |
| 444 MessageLoop::current()->Run(); | 435 MessageLoop::current()->Run(); |
| 445 } | 436 } |
| 446 | 437 |
| 447 TEST_F(URLFetcherCancelTest, ReleasesContext) { | 438 TEST_F(URLFetcherCancelTest, ReleasesContext) { |
| 448 scoped_refptr<HTTPTestServer> server = | 439 scoped_refptr<HTTPTestServer> server = |
| 449 HTTPTestServer::CreateServer(L"chrome/test/data", NULL); | 440 HTTPTestServer::CreateServer(L"chrome/test/data", NULL); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 463 // (main) thread will do the IO, and when the fetch is complete it will | 454 // (main) thread will do the IO, and when the fetch is complete it will |
| 464 // terminate the main thread's message loop; then the other thread's | 455 // terminate the main thread's message loop; then the other thread's |
| 465 // message loop will be shut down automatically as the thread goes out of | 456 // message loop will be shut down automatically as the thread goes out of |
| 466 // scope. | 457 // scope. |
| 467 base::Thread t("URLFetcher test thread"); | 458 base::Thread t("URLFetcher test thread"); |
| 468 t.Start(); | 459 t.Start(); |
| 469 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); | 460 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); |
| 470 | 461 |
| 471 MessageLoop::current()->Run(); | 462 MessageLoop::current()->Run(); |
| 472 } | 463 } |
| OLD | NEW |