| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "net/base/request_priority.h" | 10 #include "net/base/request_priority.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 context.set_http_transaction_factory(&network_layer); | 153 context.set_http_transaction_factory(&network_layer); |
| 154 | 154 |
| 155 TestDelegate d; | 155 TestDelegate d; |
| 156 std::unique_ptr<URLRequest> req( | 156 std::unique_ptr<URLRequest> req( |
| 157 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); | 157 context.CreateRequest(GURL(kGZip_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 158 AddMockTransaction(&kGZip_Transaction); | 158 AddMockTransaction(&kGZip_Transaction); |
| 159 | 159 |
| 160 req->set_method("GET"); | 160 req->set_method("GET"); |
| 161 req->Start(); | 161 req->Start(); |
| 162 | 162 |
| 163 base::MessageLoop::current()->Run(); | 163 base::RunLoop().Run(); |
| 164 | 164 |
| 165 EXPECT_TRUE(network_layer.done_reading_called()); | 165 EXPECT_TRUE(network_layer.done_reading_called()); |
| 166 | 166 |
| 167 RemoveMockTransaction(&kGZip_Transaction); | 167 RemoveMockTransaction(&kGZip_Transaction); |
| 168 } | 168 } |
| 169 | 169 |
| 170 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { | 170 TEST(URLRequestJob, SyncTransactionNotifiedWhenDone) { |
| 171 MockNetworkLayer network_layer; | 171 MockNetworkLayer network_layer; |
| 172 TestURLRequestContext context; | 172 TestURLRequestContext context; |
| 173 context.set_http_transaction_factory(&network_layer); | 173 context.set_http_transaction_factory(&network_layer); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 context.set_http_transaction_factory(&network_layer); | 265 context.set_http_transaction_factory(&network_layer); |
| 266 | 266 |
| 267 TestDelegate d; | 267 TestDelegate d; |
| 268 std::unique_ptr<URLRequest> req(context.CreateRequest( | 268 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 269 GURL(kEmptyBodyGzip_Transaction.url), DEFAULT_PRIORITY, &d)); | 269 GURL(kEmptyBodyGzip_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 270 AddMockTransaction(&kEmptyBodyGzip_Transaction); | 270 AddMockTransaction(&kEmptyBodyGzip_Transaction); |
| 271 | 271 |
| 272 req->set_method("GET"); | 272 req->set_method("GET"); |
| 273 req->Start(); | 273 req->Start(); |
| 274 | 274 |
| 275 base::MessageLoop::current()->Run(); | 275 base::RunLoop().Run(); |
| 276 | 276 |
| 277 EXPECT_FALSE(d.request_failed()); | 277 EXPECT_FALSE(d.request_failed()); |
| 278 EXPECT_EQ(200, req->GetResponseCode()); | 278 EXPECT_EQ(200, req->GetResponseCode()); |
| 279 EXPECT_TRUE(d.data_received().empty()); | 279 EXPECT_TRUE(d.data_received().empty()); |
| 280 EXPECT_TRUE(network_layer.done_reading_called()); | 280 EXPECT_TRUE(network_layer.done_reading_called()); |
| 281 | 281 |
| 282 RemoveMockTransaction(&kEmptyBodyGzip_Transaction); | 282 RemoveMockTransaction(&kEmptyBodyGzip_Transaction); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // Regression test for crbug.com/575213. | 285 // Regression test for crbug.com/575213. |
| 286 TEST(URLRequestJob, InvalidContentGZipTransaction) { | 286 TEST(URLRequestJob, InvalidContentGZipTransaction) { |
| 287 MockNetworkLayer network_layer; | 287 MockNetworkLayer network_layer; |
| 288 TestURLRequestContext context; | 288 TestURLRequestContext context; |
| 289 context.set_http_transaction_factory(&network_layer); | 289 context.set_http_transaction_factory(&network_layer); |
| 290 | 290 |
| 291 TestDelegate d; | 291 TestDelegate d; |
| 292 std::unique_ptr<URLRequest> req(context.CreateRequest( | 292 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 293 GURL(kInvalidContentGZip_Transaction.url), DEFAULT_PRIORITY, &d)); | 293 GURL(kInvalidContentGZip_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 294 AddMockTransaction(&kInvalidContentGZip_Transaction); | 294 AddMockTransaction(&kInvalidContentGZip_Transaction); |
| 295 | 295 |
| 296 req->set_method("GET"); | 296 req->set_method("GET"); |
| 297 req->Start(); | 297 req->Start(); |
| 298 | 298 |
| 299 base::MessageLoop::current()->Run(); | 299 base::RunLoop().Run(); |
| 300 | 300 |
| 301 // Request failed indicates the request failed before headers were received, | 301 // Request failed indicates the request failed before headers were received, |
| 302 // so should be false. | 302 // so should be false. |
| 303 EXPECT_FALSE(d.request_failed()); | 303 EXPECT_FALSE(d.request_failed()); |
| 304 EXPECT_EQ(200, req->GetResponseCode()); | 304 EXPECT_EQ(200, req->GetResponseCode()); |
| 305 EXPECT_FALSE(req->status().is_success()); | 305 EXPECT_FALSE(req->status().is_success()); |
| 306 EXPECT_EQ(ERR_CONTENT_DECODING_FAILED, req->status().error()); | 306 EXPECT_EQ(ERR_CONTENT_DECODING_FAILED, req->status().error()); |
| 307 EXPECT_TRUE(d.data_received().empty()); | 307 EXPECT_TRUE(d.data_received().empty()); |
| 308 EXPECT_FALSE(network_layer.done_reading_called()); | 308 EXPECT_FALSE(network_layer.done_reading_called()); |
| 309 | 309 |
| 310 RemoveMockTransaction(&kInvalidContentGZip_Transaction); | 310 RemoveMockTransaction(&kInvalidContentGZip_Transaction); |
| 311 } | 311 } |
| 312 | 312 |
| 313 // Regression test for crbug.com/553300. | 313 // Regression test for crbug.com/553300. |
| 314 TEST(URLRequestJob, SlowFilterRead) { | 314 TEST(URLRequestJob, SlowFilterRead) { |
| 315 MockNetworkLayer network_layer; | 315 MockNetworkLayer network_layer; |
| 316 TestURLRequestContext context; | 316 TestURLRequestContext context; |
| 317 context.set_http_transaction_factory(&network_layer); | 317 context.set_http_transaction_factory(&network_layer); |
| 318 | 318 |
| 319 TestDelegate d; | 319 TestDelegate d; |
| 320 std::unique_ptr<URLRequest> req(context.CreateRequest( | 320 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 321 GURL(kGzip_Slow_Transaction.url), DEFAULT_PRIORITY, &d)); | 321 GURL(kGzip_Slow_Transaction.url), DEFAULT_PRIORITY, &d)); |
| 322 AddMockTransaction(&kGzip_Slow_Transaction); | 322 AddMockTransaction(&kGzip_Slow_Transaction); |
| 323 | 323 |
| 324 req->set_method("GET"); | 324 req->set_method("GET"); |
| 325 req->Start(); | 325 req->Start(); |
| 326 | 326 |
| 327 base::MessageLoop::current()->Run(); | 327 base::RunLoop().Run(); |
| 328 | 328 |
| 329 EXPECT_FALSE(d.request_failed()); | 329 EXPECT_FALSE(d.request_failed()); |
| 330 EXPECT_EQ(200, req->GetResponseCode()); | 330 EXPECT_EQ(200, req->GetResponseCode()); |
| 331 EXPECT_EQ("hello\n", d.data_received()); | 331 EXPECT_EQ("hello\n", d.data_received()); |
| 332 EXPECT_TRUE(network_layer.done_reading_called()); | 332 EXPECT_TRUE(network_layer.done_reading_called()); |
| 333 | 333 |
| 334 RemoveMockTransaction(&kGzip_Slow_Transaction); | 334 RemoveMockTransaction(&kGzip_Slow_Transaction); |
| 335 } | 335 } |
| 336 | 336 |
| 337 TEST(URLRequestJob, SlowBrotliRead) { | 337 TEST(URLRequestJob, SlowBrotliRead) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 351 | 351 |
| 352 EXPECT_FALSE(d.request_failed()); | 352 EXPECT_FALSE(d.request_failed()); |
| 353 EXPECT_EQ(200, req->GetResponseCode()); | 353 EXPECT_EQ(200, req->GetResponseCode()); |
| 354 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received()); | 354 EXPECT_EQ(kBrotliDecodedHelloData, d.data_received()); |
| 355 EXPECT_TRUE(network_layer.done_reading_called()); | 355 EXPECT_TRUE(network_layer.done_reading_called()); |
| 356 | 356 |
| 357 RemoveMockTransaction(&kBrotli_Slow_Transaction); | 357 RemoveMockTransaction(&kBrotli_Slow_Transaction); |
| 358 } | 358 } |
| 359 | 359 |
| 360 } // namespace net | 360 } // namespace net |
| OLD | NEW |