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

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

Issue 1467603002: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add done_reading_called_ to MockNetworkTransaction Created 5 years, 1 month 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
« no previous file with comments | « net/url_request/url_request_job.cc ('k') | net/url_request/url_request_simple_job.h » ('j') | 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/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "net/base/request_priority.h" 9 #include "net/base/request_priority.h"
10 #include "net/http/http_transaction_test_util.h" 10 #include "net/http/http_transaction_test_util.h"
11 #include "net/url_request/url_request.h" 11 #include "net/url_request/url_request.h"
12 #include "net/url_request/url_request_test_util.h" 12 #include "net/url_request/url_request_test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace net { 15 namespace net {
16 16
17 namespace { 17 namespace {
18 18
19 // This is a header that signals the end of the data. 19 // This is a header that signals the end of the data.
20 const char kGzipData[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0"; 20 const char kGzipData[] = "\x1f\x08b\x08\0\0\0\0\0\0\3\3\0\0\0\0\0\0\0\0";
21 const char kGzipDataWithName[] = 21 const char kGzipDataWithName[] =
22 "\x1f\x08b\x08\x08\0\0\0\0\0\0name\0\3\0\0\0\0\0\0\0\0"; 22 "\x1f\x08b\x08\x08\0\0\0\0\0\0name\0\3\0\0\0\0\0\0\0\0";
23 // Gzip data that contains the word hello with a newline character.
24 const char kGzipHelloData[] =
25 "\x1f\x8b\x08\x08\x46\x7d\x4e\x56\x00\x03\x67\x7a\x69\x70\x2e\x74\x78\x74"
26 "\x00\xcb\x48\xcd\xc9\xc9\xe7\x02\x00\x20\x30\x3a\x36\x06\x00\x00\x00";
23 27
24 void GZipServer(const HttpRequestInfo* request, 28 void GZipServer(const HttpRequestInfo* request,
25 std::string* response_status, 29 std::string* response_status,
26 std::string* response_headers, 30 std::string* response_headers,
27 std::string* response_data) { 31 std::string* response_data) {
28 response_data->assign(kGzipData, sizeof(kGzipData)); 32 response_data->assign(kGzipData, sizeof(kGzipData));
29 } 33 }
30 34
35 void GZipHelloServer(const HttpRequestInfo* request,
36 std::string* response_status,
37 std::string* response_headers,
38 std::string* response_data) {
39 response_data->assign(kGzipHelloData, sizeof(kGzipHelloData));
40 }
41
31 void BigGZipServer(const HttpRequestInfo* request, 42 void BigGZipServer(const HttpRequestInfo* request,
32 std::string* response_status, 43 std::string* response_status,
33 std::string* response_headers, 44 std::string* response_headers,
34 std::string* response_data) { 45 std::string* response_data) {
35 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName)); 46 response_data->assign(kGzipDataWithName, sizeof(kGzipDataWithName));
36 response_data->insert(10, 64 * 1024, 'a'); 47 response_data->insert(10, 64 * 1024, 'a');
37 } 48 }
38 49
39 const MockTransaction kGZip_Transaction = { 50 const MockTransaction kGZip_Transaction = {
40 "http://www.google.com/gzyp", 51 "http://www.google.com/gzyp",
41 "GET", 52 "GET",
42 base::Time(), 53 base::Time(),
43 "", 54 "",
44 LOAD_NORMAL, 55 LOAD_NORMAL,
45 "HTTP/1.1 200 OK", 56 "HTTP/1.1 200 OK",
46 "Cache-Control: max-age=10000\n" 57 "Cache-Control: max-age=10000\n"
47 "Content-Encoding: gzip\n" 58 "Content-Encoding: gzip\n"
48 "Content-Length: 30\n", // Intentionally wrong. 59 "Content-Length: 30\n", // Intentionally wrong.
49 base::Time(), 60 base::Time(),
50 "", 61 "",
51 TEST_MODE_NORMAL, 62 TEST_MODE_NORMAL,
52 &GZipServer, 63 &GZipServer,
53 nullptr, 64 nullptr,
54 0, 65 0,
55 0, 66 0,
56 OK, 67 OK,
57 }; 68 };
58 69
70 const MockTransaction kGzip_Slow_Transaction = {
71 "http://www.google.com/gzyp", "GET", base::Time(), "", LOAD_NORMAL,
72 "HTTP/1.1 200 OK",
73 "Cache-Control: max-age=10000\n"
74 "Content-Encoding: gzip\n",
75 base::Time(), "", TEST_MODE_SLOW_READ, &GZipHelloServer, nullptr, 0, 0, OK,
76 };
77
59 const MockTransaction kRedirect_Transaction = { 78 const MockTransaction kRedirect_Transaction = {
60 "http://www.google.com/redirect", 79 "http://www.google.com/redirect",
61 "GET", 80 "GET",
62 base::Time(), 81 base::Time(),
63 "", 82 "",
64 LOAD_NORMAL, 83 LOAD_NORMAL,
65 "HTTP/1.1 302 Found", 84 "HTTP/1.1 302 Found",
66 "Cache-Control: max-age=10000\n" 85 "Cache-Control: max-age=10000\n"
67 "Location: http://www.google.com/destination\n" 86 "Location: http://www.google.com/destination\n"
68 "Content-Length: 5\n", 87 "Content-Length: 5\n",
69 base::Time(), 88 base::Time(),
70 "hello", 89 "hello",
71 TEST_MODE_NORMAL, 90 TEST_MODE_NORMAL,
72 nullptr, 91 nullptr,
73 nullptr, 92 nullptr,
74 0, 93 0,
75 0, 94 0,
76 OK, 95 OK,
77 }; 96 };
78 97
98 const MockTransaction kEmptyBodyGzip_Transaction = {
99 "http://www.google.com/empty_body",
100 "GET",
101 base::Time(),
102 "",
103 LOAD_NORMAL,
104 "HTTP/1.1 200 OK",
105 "Content-Encoding: gzip\n",
106 base::Time(),
107 "",
108 TEST_MODE_NORMAL,
109 nullptr,
110 nullptr,
111 0,
112 0,
113 OK,
114 };
115
79 } // namespace 116 } // namespace
80 117
81 TEST(URLRequestJob, TransactionNotifiedWhenDone) { 118 TEST(URLRequestJob, TransactionNotifiedWhenDone) {
82 MockNetworkLayer network_layer; 119 MockNetworkLayer network_layer;
83 TestURLRequestContext context; 120 TestURLRequestContext context;
84 context.set_http_transaction_factory(&network_layer); 121 context.set_http_transaction_factory(&network_layer);
85 122
86 TestDelegate d; 123 TestDelegate d;
87 scoped_ptr<URLRequest> req( 124 scoped_ptr<URLRequest> req(
88 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); 125 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 req->set_method("GET"); 217 req->set_method("GET");
181 req->Start(); 218 req->Start();
182 219
183 base::RunLoop().Run(); 220 base::RunLoop().Run();
184 221
185 EXPECT_TRUE(network_layer.stop_caching_called()); 222 EXPECT_TRUE(network_layer.stop_caching_called());
186 223
187 RemoveMockTransaction(&kGZip_Transaction); 224 RemoveMockTransaction(&kGZip_Transaction);
188 } 225 }
189 226
227 // Makes sure that ReadRawDataComplete correctly updates request status before
228 // calling ReadFilteredData.
229 // Regression test for crbug.com/553300.
230 TEST(URLRequestJob, EmptyBodySkipFilter) {
231 MockNetworkLayer network_layer;
232 TestURLRequestContext context;
233 context.set_http_transaction_factory(&network_layer);
234
235 TestDelegate d;
236 scoped_ptr<URLRequest> req(context.CreateRequest(
237 GURL(kEmptyBodyGzip_Transaction.url), DEFAULT_PRIORITY, &d));
238 AddMockTransaction(&kEmptyBodyGzip_Transaction);
239
240 req->set_method("GET");
241 req->Start();
242
243 base::MessageLoop::current()->Run();
244
245 EXPECT_FALSE(d.request_failed());
246 EXPECT_EQ(200, req->GetResponseCode());
247 EXPECT_TRUE(d.data_received().empty());
248 EXPECT_TRUE(network_layer.done_reading_called());
249
250 RemoveMockTransaction(&kEmptyBodyGzip_Transaction);
251 }
252
253 // Regression test for crbug.com/553300.
254 TEST(URLRequestJob, SlowFilterRead) {
255 MockNetworkLayer network_layer;
256 TestURLRequestContext context;
257 context.set_http_transaction_factory(&network_layer);
258
259 TestDelegate d;
260 scoped_ptr<URLRequest> req(context.CreateRequest(
261 GURL(kGzip_Slow_Transaction.url), DEFAULT_PRIORITY, &d));
262 AddMockTransaction(&kGzip_Slow_Transaction);
263
264 req->set_method("GET");
265 req->Start();
266
267 base::MessageLoop::current()->Run();
268
269 EXPECT_FALSE(d.request_failed());
270 EXPECT_EQ(200, req->GetResponseCode());
271 EXPECT_EQ("hello\n", d.data_received());
272 EXPECT_TRUE(network_layer.done_reading_called());
273
274 RemoveMockTransaction(&kGzip_Slow_Transaction);
275 }
276
190 } // namespace net 277 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_job.cc ('k') | net/url_request/url_request_simple_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698