OLD | NEW |
---|---|
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" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 base::Time(), | 69 base::Time(), |
70 "hello", | 70 "hello", |
71 TEST_MODE_NORMAL, | 71 TEST_MODE_NORMAL, |
72 nullptr, | 72 nullptr, |
73 nullptr, | 73 nullptr, |
74 0, | 74 0, |
75 0, | 75 0, |
76 OK, | 76 OK, |
77 }; | 77 }; |
78 | 78 |
79 const MockTransaction kEmptyBody_Transaction = { | |
mmenke
2015/11/17 18:57:32
Maybe kEmptyBodyGzip_Transaction?
xunjieli
2015/11/17 20:28:35
Done.
| |
80 "http://www.google.com/empty_body", | |
81 "GET", | |
82 base::Time(), | |
83 "", | |
84 LOAD_NORMAL, | |
85 "HTTP/1.1 200 OK", | |
86 "Content-Encoding: gzip\n", | |
87 base::Time(), | |
88 "", | |
89 TEST_MODE_NORMAL, | |
90 nullptr, | |
91 nullptr, | |
92 0, | |
93 0, | |
94 OK, | |
95 }; | |
96 | |
79 } // namespace | 97 } // namespace |
80 | 98 |
81 TEST(URLRequestJob, TransactionNotifiedWhenDone) { | 99 TEST(URLRequestJob, TransactionNotifiedWhenDone) { |
82 MockNetworkLayer network_layer; | 100 MockNetworkLayer network_layer; |
83 TestURLRequestContext context; | 101 TestURLRequestContext context; |
84 context.set_http_transaction_factory(&network_layer); | 102 context.set_http_transaction_factory(&network_layer); |
85 | 103 |
86 TestDelegate d; | 104 TestDelegate d; |
87 scoped_ptr<URLRequest> req( | 105 scoped_ptr<URLRequest> req( |
88 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); | 106 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 req->set_method("GET"); | 198 req->set_method("GET"); |
181 req->Start(); | 199 req->Start(); |
182 | 200 |
183 base::RunLoop().Run(); | 201 base::RunLoop().Run(); |
184 | 202 |
185 EXPECT_TRUE(network_layer.stop_caching_called()); | 203 EXPECT_TRUE(network_layer.stop_caching_called()); |
186 | 204 |
187 RemoveMockTransaction(&kGZip_Transaction); | 205 RemoveMockTransaction(&kGZip_Transaction); |
188 } | 206 } |
189 | 207 |
208 // Makes sure that ReadRawDataComplete correctly updates request status before | |
209 // calling ReadFilteredData. | |
210 // Regression test for crbug.com/553300. | |
211 TEST(URLRequestJob, EmptyBodySkipFilter) { | |
212 MockNetworkLayer network_layer; | |
213 TestURLRequestContext context; | |
214 context.set_http_transaction_factory(&network_layer); | |
215 | |
216 TestDelegate d; | |
217 scoped_ptr<URLRequest> req(context.CreateRequest( | |
218 GURL(kEmptyBody_Transaction.url), DEFAULT_PRIORITY, &d)); | |
219 AddMockTransaction(&kEmptyBody_Transaction); | |
220 | |
221 req->set_method("GET"); | |
222 req->Start(); | |
223 | |
224 base::MessageLoop::current()->Run(); | |
225 | |
226 EXPECT_FALSE(d.request_failed()); | |
227 EXPECT_EQ(200, req->GetResponseCode()); | |
228 EXPECT_TRUE(d.data_received().empty()); | |
229 EXPECT_TRUE(network_layer.done_reading_called()); | |
230 | |
231 RemoveMockTransaction(&kEmptyBody_Transaction); | |
232 } | |
233 | |
190 } // namespace net | 234 } // namespace net |
OLD | NEW |