| 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 0537ad1eca2bf2f9c576ba2f4d330ffe4c8c39f0..d28e9c91aaa5956ba8c1f2d877a5934907dd71fd 100644
|
| --- a/net/url_request/url_fetcher_impl_unittest.cc
|
| +++ b/net/url_request/url_fetcher_impl_unittest.cc
|
| @@ -238,6 +238,16 @@ class URLFetcherPostTest : public URLFetcherTest {
|
| virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
|
| };
|
|
|
| +// Version of URLFetcherTest that does a POST instead
|
| +class URLFetcherPostRetryTest : public URLFetcherMockDnsTest {
|
| + public:
|
| + // URLFetcherMockDnsTest:
|
| + virtual void CreateFetcher(const GURL& url) OVERRIDE;
|
| +
|
| + // URLFetcherDelegate:
|
| + virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE;
|
| +};
|
| +
|
| // Version of URLFetcherTest that does a POST of a file using
|
| // SetUploadDataStream
|
| class URLFetcherPostFileTest : public URLFetcherTest {
|
| @@ -521,6 +531,22 @@ void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) {
|
| URLFetcherTest::OnURLFetchComplete(source);
|
| }
|
|
|
| +void URLFetcherPostRetryTest::CreateFetcher(const GURL& url) {
|
| + fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
|
| + fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
|
| + io_message_loop_proxy(), request_context()));
|
| + fetcher_->SetUploadData("application/x-www-form-urlencoded",
|
| + "bobsyeruncle");
|
| +}
|
| +
|
| +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("bobsyeruncle"), data);
|
| + completed_fetcher_.reset(fetcher_);
|
| +}
|
| +
|
| URLFetcherPostFileTest::URLFetcherPostFileTest() {
|
| PathService::Get(base::DIR_SOURCE_ROOT, &path_);
|
| path_ = path_.Append(FILE_PATH_LITERAL("net"));
|
| @@ -1052,6 +1078,52 @@ TEST_F(URLFetcherPostTest, Basic) {
|
| MessageLoop::current()->Run();
|
| }
|
|
|
| +TEST_F(URLFetcherPostRetryTest, RetryOnNetworkChangedWithUploadData) {
|
| + EXPECT_EQ(0, GetNumFetcherCores());
|
| + EXPECT_FALSE(resolver_.has_pending_requests());
|
| +
|
| + 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(URLFetcherPostFileTest, Basic) {
|
| TestServer test_server(TestServer::TYPE_HTTP,
|
| TestServer::kLocalhost,
|
|
|