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

Side by Side Diff: net/url_request/url_request_job_unittest.cc

Issue 10933022: Revert 153131 (Histograms showed it doesn't help much) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/url_request/url_request_job.h" 5 #include "net/url_request/url_request_job.h"
6 6
7 #include "base/basictypes.h"
8 #include "net/http/http_transaction_unittest.h" 7 #include "net/http/http_transaction_unittest.h"
9 #include "net/url_request/url_request_test_util.h" 8 #include "net/url_request/url_request_test_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
11 10
12 namespace { 11 namespace {
13 12
14 // This is a header that signals the end of the data. 13 // This is a header that signals the end of the data.
15 const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; 14 const char kGzipGata[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0";
16 15
17 void GZipServer(const net::HttpRequestInfo* request, 16 void GZipServer(const net::HttpRequestInfo* request,
18 std::string* response_status, std::string* response_headers, 17 std::string* response_status, std::string* response_headers,
19 std::string* response_data) { 18 std::string* response_data) {
20 response_data->assign(kGzipGata, sizeof(kGzipGata)); 19 response_data->assign(kGzipGata, sizeof(kGzipGata));
21 } 20 }
22 21
23 void NullServer(const net::HttpRequestInfo* request,
24 std::string* response_status,
25 std::string* response_headers,
26 std::string* response_data) {
27 FAIL();
28 }
29
30 const MockTransaction kGZip_Transaction = { 22 const MockTransaction kGZip_Transaction = {
31 net::OK,
32 "http://www.google.com/gzyp", 23 "http://www.google.com/gzyp",
33 "GET", 24 "GET",
34 base::Time(), 25 base::Time(),
35 "", 26 "",
36 net::LOAD_NORMAL, 27 net::LOAD_NORMAL,
37 "HTTP/1.1 200 OK", 28 "HTTP/1.1 200 OK",
38 "Cache-Control: max-age=10000\n" 29 "Cache-Control: max-age=10000\n"
39 "Content-Encoding: gzip\n" 30 "Content-Encoding: gzip\n"
40 "Content-Length: 30\n", // Intentionally wrong. 31 "Content-Length: 30\n", // Intentionally wrong.
41 base::Time(), 32 base::Time(),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 70
80 req.set_method("GET"); 71 req.set_method("GET");
81 req.Start(); 72 req.Start();
82 73
83 MessageLoop::current()->Run(); 74 MessageLoop::current()->Run();
84 75
85 EXPECT_TRUE(network_layer.done_reading_called()); 76 EXPECT_TRUE(network_layer.done_reading_called());
86 77
87 RemoveMockTransaction(&transaction); 78 RemoveMockTransaction(&transaction);
88 } 79 }
89
90 // Tests that automatic retry triggers for certain errors on GETs, and is not
91 // triggered for other errors or with other methods.
92 TEST(URLRequestJob, RetryRequests) {
93 const struct {
94 net::Error transaction_result;
95 const char* method;
96 int expected_transaction_count;
97 } tests[] = {
98 {net::ERR_EMPTY_RESPONSE, "GET", 2},
99 {net::ERR_CONNECTION_REFUSED, "GET", 2},
100 {net::ERR_CONNECTION_REFUSED, "POST", 1},
101 {net::ERR_CONNECTION_REFUSED, "PUT", 1},
102 {net::ERR_ACCESS_DENIED, "GET", 1},
103 {net::ERR_CONTENT_DECODING_FAILED, "GET", 1},
104 };
105
106 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
107 const MockTransaction dead_transaction = {
108 tests[i].transaction_result,
109 "http://www.dead.com/",
110 tests[i].method,
111 base::Time(),
112 "",
113 net::LOAD_NORMAL,
114 "",
115 "",
116 base::Time(),
117 "",
118 TEST_MODE_NORMAL,
119 &NullServer,
120 0
121 };
122
123 MockNetworkLayer network_layer;
124 TestURLRequestContext context;
125 context.set_http_transaction_factory(&network_layer);
126
127 TestDelegate d;
128 TestURLRequest req(GURL(dead_transaction.url), &d, &context);
129 MockTransaction transaction(dead_transaction);
130 transaction.test_mode = TEST_MODE_SYNC_ALL;
131 AddMockTransaction(&transaction);
132
133 req.set_method(tests[i].method);
134 req.Start();
135
136 MessageLoop::current()->Run();
137
138 EXPECT_EQ(tests[i].expected_transaction_count,
139 network_layer.transaction_count());
140
141 RemoveMockTransaction(&transaction);
142 }
143 }
OLDNEW
« 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