| Index: net/url_request/url_fetcher_impl_unittest.cc
|
| diff --git a/net/url_request/url_fetcher_impl_unittest.cc b/net/url_request/url_fetcher_impl_unittest.cc
|
| index d49d2c37735955cf1350b1f76214e1ff4f48d01a..192389b2efef27769a87184e2970168f1d1203f5 100644
|
| --- a/net/url_request/url_fetcher_impl_unittest.cc
|
| +++ b/net/url_request/url_fetcher_impl_unittest.cc
|
| @@ -17,8 +17,6 @@
|
| #include "crypto/nss_util.h"
|
| #include "net/base/mock_host_resolver.h"
|
| #include "net/base/network_change_notifier.h"
|
| -#include "net/base/upload_data_stream.h"
|
| -#include "net/base/upload_file_element_reader.h"
|
| #include "net/http/http_response_headers.h"
|
| #include "net/test/test_server.h"
|
| #include "net/url_request/url_fetcher_delegate.h"
|
| @@ -239,20 +237,14 @@ class URLFetcherPostTest : public URLFetcherTest {
|
| virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
|
| };
|
|
|
| -// Version of URLFetcherTest that does a POST of a file using
|
| -// SetUploadDataStream
|
| -class URLFetcherPostFileTest : public URLFetcherTest {
|
| +// Version of URLFetcherTest that does a POST and retries it.
|
| +class URLFetcherPostRetryTest : public URLFetcherMockDnsTest {
|
| public:
|
| - URLFetcherPostFileTest();
|
| -
|
| - // URLFetcherTest:
|
| + // URLFetcherMockDnsTest:
|
| virtual void CreateFetcher(const GURL& url) OVERRIDE;
|
|
|
| // URLFetcherDelegate:
|
| virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
|
| -
|
| - private:
|
| - base::FilePath path_;
|
| };
|
|
|
| // Version of URLFetcherTest that does a POST instead with empty upload body
|
| @@ -522,36 +514,20 @@ void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) {
|
| URLFetcherTest::OnURLFetchComplete(source);
|
| }
|
|
|
| -URLFetcherPostFileTest::URLFetcherPostFileTest() {
|
| - PathService::Get(base::DIR_SOURCE_ROOT, &path_);
|
| - path_ = path_.Append(FILE_PATH_LITERAL("net"));
|
| - path_ = path_.Append(FILE_PATH_LITERAL("data"));
|
| - path_ = path_.Append(FILE_PATH_LITERAL("url_request_unittest"));
|
| - path_ = path_.Append(FILE_PATH_LITERAL("BullRunSpeech.txt"));
|
| -}
|
| -
|
| -void URLFetcherPostFileTest::CreateFetcher(const GURL& url) {
|
| +void URLFetcherPostRetryTest::CreateFetcher(const GURL& url) {
|
| fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
|
| fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
|
| io_message_loop_proxy(), request_context()));
|
| - scoped_ptr<UploadElementReader> reader(new UploadFileElementReader(
|
| - base::MessageLoopProxy::current(), path_, 0, kuint64max, base::Time()));
|
| - fetcher_->SetUploadDataStream(
|
| - "application/x-www-form-urlencoded",
|
| - make_scoped_ptr(UploadDataStream::CreateWithReader(reader.Pass(), 0)));
|
| - fetcher_->Start();
|
| + fetcher_->SetUploadData("application/x-www-form-urlencoded",
|
| + "bobsyeruncle");
|
| }
|
|
|
| -void URLFetcherPostFileTest::OnURLFetchComplete(const URLFetcher* source) {
|
| - int64 size = 0;
|
| - ASSERT_EQ(true, file_util::GetFileSize(path_, &size));
|
| - scoped_array<char> expected(new char[size]);
|
| - ASSERT_EQ(size, file_util::ReadFile(path_, expected.get(), size));
|
| -
|
| +void URLFetcherPostRetryTest::OnURLFetchComplete(const URLFetcher* source) {
|
| + io_message_loop_proxy()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
|
| std::string data;
|
| EXPECT_TRUE(source->GetResponseAsString(&data));
|
| - EXPECT_EQ(std::string(&expected[0], size), data);
|
| - URLFetcherTest::OnURLFetchComplete(source);
|
| + EXPECT_EQ(std::string("bobsyeruncle"), data);
|
| + completed_fetcher_.reset(fetcher_);
|
| }
|
|
|
| void URLFetcherEmptyPostTest::CreateFetcher(const GURL& url) {
|
| @@ -1046,21 +1022,57 @@ TEST_F(URLFetcherMockDnsTest, RetryOnNetworkChangedAndSucceed) {
|
| TEST_F(URLFetcherPostTest, Basic) {
|
| TestServer test_server(TestServer::TYPE_HTTP,
|
| TestServer::kLocalhost,
|
| - base::FilePath(kDocRoot));
|
| + FilePath(kDocRoot));
|
| ASSERT_TRUE(test_server.Start());
|
|
|
| CreateFetcher(test_server.GetURL("echo"));
|
| MessageLoop::current()->Run();
|
| }
|
|
|
| -TEST_F(URLFetcherPostFileTest, Basic) {
|
| - TestServer test_server(TestServer::TYPE_HTTP,
|
| - TestServer::kLocalhost,
|
| - base::FilePath(kDocRoot));
|
| - ASSERT_TRUE(test_server.Start());
|
| +TEST_F(URLFetcherPostRetryTest, RetryOnNetworkChangedWithUploadData) {
|
| + EXPECT_EQ(0, GetNumFetcherCores());
|
| + EXPECT_FALSE(resolver_.has_pending_requests());
|
|
|
| - CreateFetcher(test_server.GetURL("echo"));
|
| + GURL url = GURL(
|
| + base::StringPrintf("http://example.com:%d/echo",
|
| + test_server_->host_port_pair().port()));
|
| +
|
| + // This posts a task to start the fetcher.
|
| + CreateFetcher(url);
|
| + fetcher_->SetAutomaticallyRetryOnNetworkChanges(3);
|
| + fetcher_->Start();
|
| + EXPECT_EQ(0, GetNumFetcherCores());
|
| + MessageLoop::current()->RunUntilIdle();
|
| +
|
| + // The fetcher is now running, but is pending the host resolve.
|
| + EXPECT_EQ(1, GetNumFetcherCores());
|
| + EXPECT_TRUE(resolver_.has_pending_requests());
|
| + ASSERT_FALSE(completed_fetcher_);
|
| +
|
| + // Make it fail 3 times.
|
| + for (int i = 0; i < 3; ++i) {
|
| + // A network change notification aborts the connect job.
|
| + NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
|
| + MessageLoop::current()->RunUntilIdle();
|
| +
|
| + // But the fetcher retries automatically.
|
| + EXPECT_EQ(1, GetNumFetcherCores());
|
| + EXPECT_TRUE(resolver_.has_pending_requests());
|
| + ASSERT_FALSE(completed_fetcher_);
|
| + }
|
| +
|
| + // Now let it succeed by resolving the pending request.
|
| + resolver_.ResolveAllPending();
|
| MessageLoop::current()->Run();
|
| +
|
| + // URLFetcherMockDnsTest::OnURLFetchComplete() will quit the loop.
|
| + EXPECT_EQ(0, GetNumFetcherCores());
|
| + EXPECT_FALSE(resolver_.has_pending_requests());
|
| + ASSERT_TRUE(completed_fetcher_);
|
| +
|
| + // This time the request succeeded.
|
| + EXPECT_EQ(OK, completed_fetcher_->GetStatus().error());
|
| + EXPECT_EQ(200, completed_fetcher_->GetResponseCode());
|
| }
|
|
|
| TEST_F(URLFetcherEmptyPostTest, Basic) {
|
|
|