Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: net/url_request/url_request_job_unittest.cc

Issue 10872044: Retry failed network requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix bug Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_job_unittest.cc
===================================================================
--- net/url_request/url_request_job_unittest.cc (revision 152798)
+++ net/url_request/url_request_job_unittest.cc (working copy)
@@ -4,6 +4,7 @@
#include "net/url_request/url_request_job.h"
+#include "base/basictypes.h"
#include "net/http/http_transaction_unittest.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -19,7 +20,15 @@
response_data->assign(kGzipGata, sizeof(kGzipGata));
}
+void NullServer(const net::HttpRequestInfo* request,
+ std::string* response_status,
+ std::string* response_headers,
+ std::string* response_data) {
+ FAIL();
+}
+
const MockTransaction kGZip_Transaction = {
+ net::OK,
"http://www.google.com/gzyp",
"GET",
base::Time(),
@@ -77,3 +86,58 @@
RemoveMockTransaction(&transaction);
}
+
+// Tests that automatic retry triggers for certain errors on GETs, and is not
+// triggered for other errors or with other methods.
+TEST(URLRequestJob, RetryRequests) {
+ const struct {
+ net::Error transaction_result;
+ const char* method;
+ int expected_transaction_count;
+ } tests[] = {
+ {net::ERR_EMPTY_RESPONSE, "GET", 2},
+ {net::ERR_CONNECTION_REFUSED, "GET", 2},
+ {net::ERR_CONNECTION_REFUSED, "POST", 1},
+ {net::ERR_CONNECTION_REFUSED, "PUT", 1},
+ {net::ERR_ACCESS_DENIED, "GET", 1},
+ {net::ERR_CONTENT_DECODING_FAILED, "GET", 1},
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ const MockTransaction dead_transaction = {
+ tests[i].transaction_result,
+ "http://www.dead.com/",
+ tests[i].method,
+ base::Time(),
+ "",
+ net::LOAD_NORMAL,
+ "",
+ "",
+ base::Time(),
+ "",
+ TEST_MODE_NORMAL,
+ &NullServer,
+ 0
+ };
+
+ MockNetworkLayer network_layer;
+ TestURLRequestContext context;
+ context.set_http_transaction_factory(&network_layer);
+
+ TestDelegate d;
+ TestURLRequest req(GURL(dead_transaction.url), &d, &context);
+ MockTransaction transaction(dead_transaction);
+ transaction.test_mode = TEST_MODE_SYNC_ALL;
+ AddMockTransaction(&transaction);
+
+ req.set_method(tests[i].method);
+ req.Start();
+
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ(tests[i].expected_transaction_count,
+ network_layer.transaction_count());
+
+ RemoveMockTransaction(&transaction);
+ }
+}
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698