| Index: chrome/common/net/url_fetcher_unittest.cc
|
| diff --git a/chrome/common/net/url_fetcher_unittest.cc b/chrome/common/net/url_fetcher_unittest.cc
|
| index 82171f925b2f167bdbdd63aee71b6fbf117434a8..af87b191beb03e90b48fb10af1a6954557677312 100644
|
| --- a/chrome/common/net/url_fetcher_unittest.cc
|
| +++ b/chrome/common/net/url_fetcher_unittest.cc
|
| @@ -26,6 +26,7 @@ using base::TimeDelta;
|
| namespace {
|
|
|
| const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
|
| +const std::string kTestServerFilePrefix = "files/";
|
|
|
| class CurriedTask : public Task {
|
| public:
|
| @@ -124,6 +125,8 @@ void URLFetcherTest::CreateFetcher(const GURL& url) {
|
| fetcher_ = new URLFetcher(url, URLFetcher::GET, this);
|
| fetcher_->set_request_context(new TestURLRequestContextGetter(
|
| io_message_loop_proxy()));
|
| +
|
| + // Do file ops on the io thead.
|
| fetcher_->Start();
|
| }
|
|
|
| @@ -305,6 +308,70 @@ class URLFetcherMultipleAttemptTest : public URLFetcherTest {
|
| std::string data_;
|
| };
|
|
|
| +class URLFetcherTempFileTest : public URLFetcherTest {
|
| + public:
|
| + // URLFetcher::Delegate
|
| + virtual void OnURLFetchComplete(const URLFetcher* source,
|
| + const GURL& url,
|
| + const net::URLRequestStatus& status,
|
| + int response_code,
|
| + const net::ResponseCookies& cookies);
|
| +
|
| + virtual void CreateFetcher(const GURL& url);
|
| +
|
| + protected:
|
| + FilePath expected_file_;
|
| + FilePath temp_file_;
|
| +};
|
| +
|
| +void URLFetcherTempFileTest::CreateFetcher(const GURL& url) {
|
| + fetcher_ = new URLFetcher(url, URLFetcher::GET, this);
|
| + fetcher_->set_request_context(new TestURLRequestContextGetter(
|
| + io_message_loop_proxy()));
|
| +
|
| + // Use the IO message loop to do the file operations in this test.
|
| + fetcher_->set_file_message_loop_proxy(
|
| + io_message_loop_proxy());
|
| +
|
| + fetcher_->set_response_destination(URLFetcher::TEMP_FILE);
|
| + fetcher_->Start();
|
| +}
|
| +
|
| +TEST_F(URLFetcherTempFileTest, SmallGet) {
|
| + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
|
| + ASSERT_TRUE(test_server.Start());
|
| +
|
| + // Get a small file.
|
| + const char* kFileToFetch = "simple.html";
|
| + expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
|
| + CreateFetcher(test_server.GetURL(kTestServerFilePrefix + kFileToFetch));
|
| +
|
| + MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
|
| +
|
| + ASSERT_TRUE(file_util::PathExists(temp_file_))
|
| + << temp_file_.value() << " not found.";
|
| +
|
| + // Deleting the fetcher should remove the file.
|
| + delete fetcher_;
|
| +
|
| + MessageLoop::current()->RunAllPending();
|
| + ASSERT_FALSE(file_util::PathExists(temp_file_))
|
| + << temp_file_.value() << " not removed.";
|
| +}
|
| +
|
| +TEST_F(URLFetcherTempFileTest, LargeGet) {
|
| + net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
|
| + ASSERT_TRUE(test_server.Start());
|
| +
|
| + // Get a file large enough to require more than one read into
|
| + // URLFetcher::Core's IOBuffer.
|
| + const char* kFileToFetch = "animate1.gif";
|
| + expected_file_ = test_server.document_root().AppendASCII(kFileToFetch);
|
| + CreateFetcher(test_server.GetURL(kTestServerFilePrefix + kFileToFetch));
|
| +
|
| + MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
|
| +}
|
| +
|
| // Wrapper that lets us call CreateFetcher() on a thread of our choice. We
|
| // could make URLFetcherTest refcounted and use PostTask(FROM_HERE.. ) to call
|
| // CreateFetcher() directly, but the ownership of the URLFetcherTest is a bit
|
| @@ -539,6 +606,23 @@ void URLFetcherMultipleAttemptTest::OnURLFetchComplete(
|
| }
|
| }
|
|
|
| +void URLFetcherTempFileTest::OnURLFetchComplete(
|
| + const URLFetcher* source,
|
| + const GURL& url,
|
| + const net::URLRequestStatus& status,
|
| + int response_code,
|
| + const net::ResponseCookies& cookies) {
|
| + ASSERT_TRUE(source->GetResponseAsFilePath(&temp_file_));
|
| +
|
| + ASSERT_TRUE(file_util::PathExists(temp_file_))
|
| + << temp_file_.value() << " not found.";
|
| + ASSERT_TRUE(file_util::PathExists(expected_file_))
|
| + << expected_file_.value() << " not found.";
|
| + ASSERT_TRUE(file_util::ContentsEqual(expected_file_, temp_file_));
|
| +
|
| + io_message_loop_proxy()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
|
| +}
|
| +
|
| TEST_F(URLFetcherTest, SameThreadsTest) {
|
| net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
|
| ASSERT_TRUE(test_server.Start());
|
| @@ -705,7 +789,7 @@ TEST_F(URLFetcherCancelTest, ReleasesContext) {
|
| GURL url(test_server.GetURL("files/server-unavailable.html"));
|
|
|
| // Registers an entry for test url. The backoff time is calculated by:
|
| - // new_backoff = 2.0 * old_backoff + 0
|
| + // new_backoff = 2.0 * old_backoff +0
|
| // The initial backoff is 2 seconds and maximum backoff is 4 seconds.
|
| // Maximum retries allowed is set to 2.
|
| net::URLRequestThrottlerManager* manager =
|
|
|