| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "net/http/http_transaction_test_util.h" | 24 #include "net/http/http_transaction_test_util.h" |
| 25 #include "net/log/net_log_event_type.h" | 25 #include "net/log/net_log_event_type.h" |
| 26 #include "net/log/test_net_log.h" | 26 #include "net/log/test_net_log.h" |
| 27 #include "net/log/test_net_log_entry.h" | 27 #include "net/log/test_net_log_entry.h" |
| 28 #include "net/log/test_net_log_util.h" | 28 #include "net/log/test_net_log_util.h" |
| 29 #include "net/net_features.h" | 29 #include "net/net_features.h" |
| 30 #include "net/socket/socket_test_util.h" | 30 #include "net/socket/socket_test_util.h" |
| 31 #include "net/test/cert_test_util.h" | 31 #include "net/test/cert_test_util.h" |
| 32 #include "net/test/gtest_util.h" | 32 #include "net/test/gtest_util.h" |
| 33 #include "net/test/test_data_directory.h" | 33 #include "net/test/test_data_directory.h" |
| 34 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 34 #include "net/url_request/url_request.h" | 35 #include "net/url_request/url_request.h" |
| 35 #include "net/url_request/url_request_job_factory_impl.h" | 36 #include "net/url_request/url_request_job_factory_impl.h" |
| 36 #include "net/url_request/url_request_status.h" | 37 #include "net/url_request/url_request_status.h" |
| 37 #include "net/url_request/url_request_test_util.h" | 38 #include "net/url_request/url_request_test_util.h" |
| 38 #include "net/websockets/websocket_handshake_stream_base.h" | 39 #include "net/websockets/websocket_handshake_stream_base.h" |
| 39 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
| 40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 41 #include "url/gurl.h" | 42 #include "url/gurl.h" |
| 42 #include "url/url_constants.h" | 43 #include "url/url_constants.h" |
| 43 | 44 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 TEST_F(URLRequestHttpJobSetUpSourceTest, SetUpSourceFails) { | 124 TEST_F(URLRequestHttpJobSetUpSourceTest, SetUpSourceFails) { |
| 124 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 125 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 125 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 126 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 126 "Content-Length: 12\r\n\r\n"), | 127 "Content-Length: 12\r\n\r\n"), |
| 127 MockRead("Test Content")}; | 128 MockRead("Test Content")}; |
| 128 | 129 |
| 129 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 130 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 130 arraysize(writes)); | 131 arraysize(writes)); |
| 131 socket_factory_.AddSocketDataProvider(&socket_data); | 132 socket_factory_.AddSocketDataProvider(&socket_data); |
| 132 | 133 |
| 133 std::unique_ptr<URLRequest> request = context_.CreateRequest( | 134 std::unique_ptr<URLRequest> request = |
| 134 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_); | 135 context_.CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 136 &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 135 std::unique_ptr<TestURLRequestHttpJob> job( | 137 std::unique_ptr<TestURLRequestHttpJob> job( |
| 136 new TestURLRequestHttpJob(request.get())); | 138 new TestURLRequestHttpJob(request.get())); |
| 137 job->set_use_null_source_stream(true); | 139 job->set_use_null_source_stream(true); |
| 138 test_job_interceptor_->set_main_intercept_job(std::move(job)); | 140 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
| 139 request->Start(); | 141 request->Start(); |
| 140 | 142 |
| 141 base::RunLoop().Run(); | 143 base::RunLoop().Run(); |
| 142 EXPECT_EQ(ERR_CONTENT_DECODING_INIT_FAILED, delegate_.request_status()); | 144 EXPECT_EQ(ERR_CONTENT_DECODING_INIT_FAILED, delegate_.request_status()); |
| 143 } | 145 } |
| 144 | 146 |
| 145 // Tests that if there is an unknown content-encoding type, the raw response | 147 // Tests that if there is an unknown content-encoding type, the raw response |
| 146 // body is passed through. | 148 // body is passed through. |
| 147 TEST_F(URLRequestHttpJobSetUpSourceTest, UnknownEncoding) { | 149 TEST_F(URLRequestHttpJobSetUpSourceTest, UnknownEncoding) { |
| 148 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 150 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 149 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 151 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 150 "Content-Encoding: foo, gzip\r\n" | 152 "Content-Encoding: foo, gzip\r\n" |
| 151 "Content-Length: 12\r\n\r\n"), | 153 "Content-Length: 12\r\n\r\n"), |
| 152 MockRead("Test Content")}; | 154 MockRead("Test Content")}; |
| 153 | 155 |
| 154 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 156 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 155 arraysize(writes)); | 157 arraysize(writes)); |
| 156 socket_factory_.AddSocketDataProvider(&socket_data); | 158 socket_factory_.AddSocketDataProvider(&socket_data); |
| 157 | 159 |
| 158 std::unique_ptr<URLRequest> request = context_.CreateRequest( | 160 std::unique_ptr<URLRequest> request = |
| 159 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_); | 161 context_.CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 162 &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 160 std::unique_ptr<TestURLRequestHttpJob> job( | 163 std::unique_ptr<TestURLRequestHttpJob> job( |
| 161 new TestURLRequestHttpJob(request.get())); | 164 new TestURLRequestHttpJob(request.get())); |
| 162 test_job_interceptor_->set_main_intercept_job(std::move(job)); | 165 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
| 163 request->Start(); | 166 request->Start(); |
| 164 | 167 |
| 165 base::RunLoop().Run(); | 168 base::RunLoop().Run(); |
| 166 EXPECT_EQ(OK, delegate_.request_status()); | 169 EXPECT_EQ(OK, delegate_.request_status()); |
| 167 EXPECT_EQ("Test Content", delegate_.data_received()); | 170 EXPECT_EQ("Test Content", delegate_.data_received()); |
| 168 } | 171 } |
| 169 | 172 |
| 170 // Received a malformed SDCH encoded response when there is no SdchManager. | 173 // Received a malformed SDCH encoded response when there is no SdchManager. |
| 171 TEST_F(URLRequestHttpJobSetUpSourceTest, SdchNotAdvertisedGotSdchResponse) { | 174 TEST_F(URLRequestHttpJobSetUpSourceTest, SdchNotAdvertisedGotSdchResponse) { |
| 172 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 175 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 173 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 176 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 174 "Content-Encoding: sdch\r\n" | 177 "Content-Encoding: sdch\r\n" |
| 175 "Content-Length: 12\r\n\r\n"), | 178 "Content-Length: 12\r\n\r\n"), |
| 176 MockRead("Test Content")}; | 179 MockRead("Test Content")}; |
| 177 | 180 |
| 178 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 181 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 179 arraysize(writes)); | 182 arraysize(writes)); |
| 180 socket_factory_.AddSocketDataProvider(&socket_data); | 183 socket_factory_.AddSocketDataProvider(&socket_data); |
| 181 | 184 |
| 182 // This test expects TestURLRequestContexts to have no SdchManager. | 185 // This test expects TestURLRequestContexts to have no SdchManager. |
| 183 DCHECK(!context_.sdch_manager()); | 186 DCHECK(!context_.sdch_manager()); |
| 184 | 187 |
| 185 std::unique_ptr<URLRequest> request = context_.CreateRequest( | 188 std::unique_ptr<URLRequest> request = |
| 186 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_); | 189 context_.CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 190 &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 187 std::unique_ptr<TestURLRequestHttpJob> job( | 191 std::unique_ptr<TestURLRequestHttpJob> job( |
| 188 new TestURLRequestHttpJob(request.get())); | 192 new TestURLRequestHttpJob(request.get())); |
| 189 test_job_interceptor_->set_main_intercept_job(std::move(job)); | 193 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
| 190 request->Start(); | 194 request->Start(); |
| 191 | 195 |
| 192 base::RunLoop().Run(); | 196 base::RunLoop().Run(); |
| 193 EXPECT_EQ(ERR_CONTENT_DECODING_FAILED, delegate_.request_status()); | 197 EXPECT_EQ(ERR_CONTENT_DECODING_FAILED, delegate_.request_status()); |
| 194 } | 198 } |
| 195 | 199 |
| 196 class URLRequestHttpJobTest : public ::testing::Test { | 200 class URLRequestHttpJobTest : public ::testing::Test { |
| 197 protected: | 201 protected: |
| 198 URLRequestHttpJobTest() : context_(true) { | 202 URLRequestHttpJobTest() : context_(true) { |
| 199 context_.set_http_transaction_factory(&network_layer_); | 203 context_.set_http_transaction_factory(&network_layer_); |
| 200 | 204 |
| 201 // The |test_job_factory_| takes ownership of the interceptor. | 205 // The |test_job_factory_| takes ownership of the interceptor. |
| 202 test_job_interceptor_ = new TestJobInterceptor(); | 206 test_job_interceptor_ = new TestJobInterceptor(); |
| 203 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( | 207 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( |
| 204 url::kHttpScheme, base::WrapUnique(test_job_interceptor_))); | 208 url::kHttpScheme, base::WrapUnique(test_job_interceptor_))); |
| 205 context_.set_job_factory(&test_job_factory_); | 209 context_.set_job_factory(&test_job_factory_); |
| 206 context_.set_net_log(&net_log_); | 210 context_.set_net_log(&net_log_); |
| 207 context_.Init(); | 211 context_.Init(); |
| 208 | 212 |
| 209 req_ = context_.CreateRequest(GURL("http://www.example.com"), | 213 req_ = |
| 210 DEFAULT_PRIORITY, &delegate_); | 214 context_.CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 215 &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 211 } | 216 } |
| 212 | 217 |
| 213 bool TransactionAcceptsSdchEncoding() { | 218 bool TransactionAcceptsSdchEncoding() { |
| 214 base::WeakPtr<MockNetworkTransaction> transaction( | 219 base::WeakPtr<MockNetworkTransaction> transaction( |
| 215 network_layer_.last_transaction()); | 220 network_layer_.last_transaction()); |
| 216 EXPECT_TRUE(transaction); | 221 EXPECT_TRUE(transaction); |
| 217 if (!transaction) return false; | 222 if (!transaction) return false; |
| 218 | 223 |
| 219 const HttpRequestInfo* request_info = transaction->request(); | 224 const HttpRequestInfo* request_info = transaction->request(); |
| 220 EXPECT_TRUE(request_info); | 225 EXPECT_TRUE(request_info); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 277 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 273 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 278 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 274 "Content-Length: 12\r\n\r\n"), | 279 "Content-Length: 12\r\n\r\n"), |
| 275 MockRead("Test Content")}; | 280 MockRead("Test Content")}; |
| 276 | 281 |
| 277 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 282 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 278 arraysize(writes)); | 283 arraysize(writes)); |
| 279 socket_factory_.AddSocketDataProvider(&socket_data); | 284 socket_factory_.AddSocketDataProvider(&socket_data); |
| 280 | 285 |
| 281 TestDelegate delegate; | 286 TestDelegate delegate; |
| 282 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 287 std::unique_ptr<URLRequest> request = |
| 283 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 288 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 289 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 284 | 290 |
| 285 request->Start(); | 291 request->Start(); |
| 286 ASSERT_TRUE(request->is_pending()); | 292 ASSERT_TRUE(request->is_pending()); |
| 287 base::RunLoop().Run(); | 293 base::RunLoop().Run(); |
| 288 | 294 |
| 289 EXPECT_THAT(delegate.request_status(), IsOk()); | 295 EXPECT_THAT(delegate.request_status(), IsOk()); |
| 290 EXPECT_EQ(12, request->received_response_content_length()); | 296 EXPECT_EQ(12, request->received_response_content_length()); |
| 291 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 297 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 292 request->GetTotalSentBytes()); | 298 request->GetTotalSentBytes()); |
| 293 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 299 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 294 request->GetTotalReceivedBytes()); | 300 request->GetTotalReceivedBytes()); |
| 295 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 301 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 296 network_delegate_.total_network_bytes_sent()); | 302 network_delegate_.total_network_bytes_sent()); |
| 297 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 303 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 298 network_delegate_.total_network_bytes_received()); | 304 network_delegate_.total_network_bytes_received()); |
| 299 } | 305 } |
| 300 | 306 |
| 301 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 307 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 302 TestContentLengthSuccessfulHttp09Request) { | 308 TestContentLengthSuccessfulHttp09Request) { |
| 303 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 309 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 304 MockRead reads[] = {MockRead("Test Content"), | 310 MockRead reads[] = {MockRead("Test Content"), |
| 305 MockRead(net::SYNCHRONOUS, net::OK)}; | 311 MockRead(net::SYNCHRONOUS, net::OK)}; |
| 306 | 312 |
| 307 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); | 313 StaticSocketDataProvider socket_data(reads, arraysize(reads), nullptr, 0); |
| 308 socket_factory_.AddSocketDataProvider(&socket_data); | 314 socket_factory_.AddSocketDataProvider(&socket_data); |
| 309 | 315 |
| 310 TestDelegate delegate; | 316 TestDelegate delegate; |
| 311 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 317 std::unique_ptr<URLRequest> request = |
| 312 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 318 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 319 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 313 | 320 |
| 314 request->Start(); | 321 request->Start(); |
| 315 ASSERT_TRUE(request->is_pending()); | 322 ASSERT_TRUE(request->is_pending()); |
| 316 base::RunLoop().Run(); | 323 base::RunLoop().Run(); |
| 317 | 324 |
| 318 EXPECT_THAT(delegate.request_status(), IsOk()); | 325 EXPECT_THAT(delegate.request_status(), IsOk()); |
| 319 EXPECT_EQ(12, request->received_response_content_length()); | 326 EXPECT_EQ(12, request->received_response_content_length()); |
| 320 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 327 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 321 request->GetTotalSentBytes()); | 328 request->GetTotalSentBytes()); |
| 322 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 329 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 323 request->GetTotalReceivedBytes()); | 330 request->GetTotalReceivedBytes()); |
| 324 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 331 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 325 network_delegate_.total_network_bytes_sent()); | 332 network_delegate_.total_network_bytes_sent()); |
| 326 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 333 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 327 network_delegate_.total_network_bytes_received()); | 334 network_delegate_.total_network_bytes_received()); |
| 328 } | 335 } |
| 329 | 336 |
| 330 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthFailedRequest) { | 337 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthFailedRequest) { |
| 331 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 338 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 332 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 339 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 333 "Content-Length: 20\r\n\r\n"), | 340 "Content-Length: 20\r\n\r\n"), |
| 334 MockRead("Test Content"), | 341 MockRead("Test Content"), |
| 335 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; | 342 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; |
| 336 | 343 |
| 337 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 344 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 338 arraysize(writes)); | 345 arraysize(writes)); |
| 339 socket_factory_.AddSocketDataProvider(&socket_data); | 346 socket_factory_.AddSocketDataProvider(&socket_data); |
| 340 | 347 |
| 341 TestDelegate delegate; | 348 TestDelegate delegate; |
| 342 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 349 std::unique_ptr<URLRequest> request = |
| 343 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 350 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 351 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 344 | 352 |
| 345 request->Start(); | 353 request->Start(); |
| 346 ASSERT_TRUE(request->is_pending()); | 354 ASSERT_TRUE(request->is_pending()); |
| 347 base::RunLoop().Run(); | 355 base::RunLoop().Run(); |
| 348 | 356 |
| 349 EXPECT_THAT(delegate.request_status(), IsError(ERR_FAILED)); | 357 EXPECT_THAT(delegate.request_status(), IsError(ERR_FAILED)); |
| 350 EXPECT_EQ(12, request->received_response_content_length()); | 358 EXPECT_EQ(12, request->received_response_content_length()); |
| 351 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 359 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 352 request->GetTotalSentBytes()); | 360 request->GetTotalSentBytes()); |
| 353 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 361 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 364 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 372 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 365 "Content-Length: 20\r\n\r\n"), | 373 "Content-Length: 20\r\n\r\n"), |
| 366 MockRead("Test Content"), | 374 MockRead("Test Content"), |
| 367 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; | 375 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; |
| 368 | 376 |
| 369 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 377 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 370 arraysize(writes)); | 378 arraysize(writes)); |
| 371 socket_factory_.AddSocketDataProvider(&socket_data); | 379 socket_factory_.AddSocketDataProvider(&socket_data); |
| 372 | 380 |
| 373 TestDelegate delegate; | 381 TestDelegate delegate; |
| 374 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 382 std::unique_ptr<URLRequest> request = |
| 375 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 383 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 384 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 376 | 385 |
| 377 delegate.set_cancel_in_received_data(true); | 386 delegate.set_cancel_in_received_data(true); |
| 378 request->Start(); | 387 request->Start(); |
| 379 base::RunLoop().RunUntilIdle(); | 388 base::RunLoop().RunUntilIdle(); |
| 380 | 389 |
| 381 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); | 390 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); |
| 382 EXPECT_EQ(12, request->received_response_content_length()); | 391 EXPECT_EQ(12, request->received_response_content_length()); |
| 383 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 392 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 384 request->GetTotalSentBytes()); | 393 request->GetTotalSentBytes()); |
| 385 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 394 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 401 | 410 |
| 402 MockRead reads[] = {MockRead(response_header.c_str()), | 411 MockRead reads[] = {MockRead(response_header.c_str()), |
| 403 MockRead(content_data.c_str()), | 412 MockRead(content_data.c_str()), |
| 404 MockRead(net::SYNCHRONOUS, net::OK)}; | 413 MockRead(net::SYNCHRONOUS, net::OK)}; |
| 405 | 414 |
| 406 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 415 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 407 arraysize(writes)); | 416 arraysize(writes)); |
| 408 socket_factory_.AddSocketDataProvider(&socket_data); | 417 socket_factory_.AddSocketDataProvider(&socket_data); |
| 409 | 418 |
| 410 TestDelegate delegate; | 419 TestDelegate delegate; |
| 411 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 420 std::unique_ptr<URLRequest> request = |
| 412 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 421 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 422 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 413 | 423 |
| 414 request->Start(); | 424 request->Start(); |
| 415 ASSERT_TRUE(request->is_pending()); | 425 ASSERT_TRUE(request->is_pending()); |
| 416 base::RunLoop().Run(); | 426 base::RunLoop().Run(); |
| 417 | 427 |
| 418 EXPECT_EQ(net::OK, request->status().error()); | 428 EXPECT_EQ(net::OK, request->status().error()); |
| 419 EXPECT_EQ(static_cast<int>(content_data.size()), | 429 EXPECT_EQ(static_cast<int>(content_data.size()), |
| 420 request->received_response_content_length()); | 430 request->received_response_content_length()); |
| 421 EXPECT_EQ(static_cast<int>(response_header.size()), | 431 EXPECT_EQ(static_cast<int>(response_header.size()), |
| 422 request->raw_header_size()); | 432 request->raw_header_size()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 436 | 446 |
| 437 MockRead reads[] = { | 447 MockRead reads[] = { |
| 438 MockRead(continue_header.c_str()), MockRead(response_header.c_str()), | 448 MockRead(continue_header.c_str()), MockRead(response_header.c_str()), |
| 439 MockRead(content_data.c_str()), MockRead(net::SYNCHRONOUS, net::OK)}; | 449 MockRead(content_data.c_str()), MockRead(net::SYNCHRONOUS, net::OK)}; |
| 440 | 450 |
| 441 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 451 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 442 arraysize(writes)); | 452 arraysize(writes)); |
| 443 socket_factory_.AddSocketDataProvider(&socket_data); | 453 socket_factory_.AddSocketDataProvider(&socket_data); |
| 444 | 454 |
| 445 TestDelegate delegate; | 455 TestDelegate delegate; |
| 446 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 456 std::unique_ptr<URLRequest> request = |
| 447 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 457 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 458 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 448 | 459 |
| 449 request->Start(); | 460 request->Start(); |
| 450 ASSERT_TRUE(request->is_pending()); | 461 ASSERT_TRUE(request->is_pending()); |
| 451 base::RunLoop().Run(); | 462 base::RunLoop().Run(); |
| 452 | 463 |
| 453 EXPECT_EQ(net::OK, request->status().error()); | 464 EXPECT_EQ(net::OK, request->status().error()); |
| 454 EXPECT_EQ(static_cast<int>(content_data.size()), | 465 EXPECT_EQ(static_cast<int>(content_data.size()), |
| 455 request->received_response_content_length()); | 466 request->received_response_content_length()); |
| 456 EXPECT_EQ(static_cast<int>(continue_header.size() + response_header.size()), | 467 EXPECT_EQ(static_cast<int>(continue_header.size() + response_header.size()), |
| 457 request->raw_header_size()); | 468 request->raw_header_size()); |
| 458 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 469 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 459 request->GetTotalReceivedBytes()); | 470 request->GetTotalReceivedBytes()); |
| 460 } | 471 } |
| 461 | 472 |
| 462 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 473 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 463 TestRawHeaderSizeFailureTruncatedHeaders) { | 474 TestRawHeaderSizeFailureTruncatedHeaders) { |
| 464 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 475 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 465 MockRead reads[] = {MockRead("HTTP/1.0 200 OK\r\n" | 476 MockRead reads[] = {MockRead("HTTP/1.0 200 OK\r\n" |
| 466 "Content-Len"), | 477 "Content-Len"), |
| 467 MockRead(net::SYNCHRONOUS, net::OK)}; | 478 MockRead(net::SYNCHRONOUS, net::OK)}; |
| 468 | 479 |
| 469 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 480 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 470 arraysize(writes)); | 481 arraysize(writes)); |
| 471 socket_factory_.AddSocketDataProvider(&socket_data); | 482 socket_factory_.AddSocketDataProvider(&socket_data); |
| 472 | 483 |
| 473 TestDelegate delegate; | 484 TestDelegate delegate; |
| 474 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 485 std::unique_ptr<URLRequest> request = |
| 475 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 486 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 487 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 476 | 488 |
| 477 delegate.set_cancel_in_response_started(true); | 489 delegate.set_cancel_in_response_started(true); |
| 478 request->Start(); | 490 request->Start(); |
| 479 base::RunLoop().RunUntilIdle(); | 491 base::RunLoop().RunUntilIdle(); |
| 480 | 492 |
| 481 EXPECT_EQ(ERR_ABORTED, request->status().error()); | 493 EXPECT_EQ(ERR_ABORTED, request->status().error()); |
| 482 EXPECT_EQ(0, request->received_response_content_length()); | 494 EXPECT_EQ(0, request->received_response_content_length()); |
| 483 EXPECT_EQ(28, request->raw_header_size()); | 495 EXPECT_EQ(28, request->raw_header_size()); |
| 484 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 496 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 485 request->GetTotalReceivedBytes()); | 497 request->GetTotalReceivedBytes()); |
| 486 } | 498 } |
| 487 | 499 |
| 488 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 500 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 489 TestRawHeaderSizeSuccessfullContinuiousRead) { | 501 TestRawHeaderSizeSuccessfullContinuiousRead) { |
| 490 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 502 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 491 const std::string& header_data = | 503 const std::string& header_data = |
| 492 "HTTP/1.1 200 OK\r\n" | 504 "HTTP/1.1 200 OK\r\n" |
| 493 "Content-Length: 12\r\n\r\n"; | 505 "Content-Length: 12\r\n\r\n"; |
| 494 const std::string& content_data = "Test Content"; | 506 const std::string& content_data = "Test Content"; |
| 495 std::string single_read_content = header_data; | 507 std::string single_read_content = header_data; |
| 496 single_read_content.append(content_data); | 508 single_read_content.append(content_data); |
| 497 MockRead reads[] = {MockRead(single_read_content.c_str())}; | 509 MockRead reads[] = {MockRead(single_read_content.c_str())}; |
| 498 | 510 |
| 499 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 511 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 500 arraysize(writes)); | 512 arraysize(writes)); |
| 501 socket_factory_.AddSocketDataProvider(&socket_data); | 513 socket_factory_.AddSocketDataProvider(&socket_data); |
| 502 | 514 |
| 503 TestDelegate delegate; | 515 TestDelegate delegate; |
| 504 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 516 std::unique_ptr<URLRequest> request = |
| 505 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 517 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 518 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 506 | 519 |
| 507 request->Start(); | 520 request->Start(); |
| 508 base::RunLoop().Run(); | 521 base::RunLoop().Run(); |
| 509 | 522 |
| 510 EXPECT_EQ(net::OK, request->status().error()); | 523 EXPECT_EQ(net::OK, request->status().error()); |
| 511 EXPECT_EQ(static_cast<int>(content_data.size()), | 524 EXPECT_EQ(static_cast<int>(content_data.size()), |
| 512 request->received_response_content_length()); | 525 request->received_response_content_length()); |
| 513 EXPECT_EQ(static_cast<int>(header_data.size()), request->raw_header_size()); | 526 EXPECT_EQ(static_cast<int>(header_data.size()), request->raw_header_size()); |
| 514 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 527 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 515 request->GetTotalReceivedBytes()); | 528 request->GetTotalReceivedBytes()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 537 MockWrite final_writes[] = {MockWrite(kSimpleGetMockWrite)}; | 550 MockWrite final_writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 538 MockRead final_reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 551 MockRead final_reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 539 "Content-Length: 12\r\n\r\n"), | 552 "Content-Length: 12\r\n\r\n"), |
| 540 MockRead("Test Content")}; | 553 MockRead("Test Content")}; |
| 541 StaticSocketDataProvider final_socket_data( | 554 StaticSocketDataProvider final_socket_data( |
| 542 final_reads, arraysize(final_reads), final_writes, | 555 final_reads, arraysize(final_reads), final_writes, |
| 543 arraysize(final_writes)); | 556 arraysize(final_writes)); |
| 544 socket_factory_.AddSocketDataProvider(&final_socket_data); | 557 socket_factory_.AddSocketDataProvider(&final_socket_data); |
| 545 | 558 |
| 546 TestDelegate delegate; | 559 TestDelegate delegate; |
| 547 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 560 std::unique_ptr<URLRequest> request = |
| 548 GURL("http://www.redirect.com"), DEFAULT_PRIORITY, &delegate); | 561 context_->CreateRequest(GURL("http://www.redirect.com"), DEFAULT_PRIORITY, |
| 562 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 549 | 563 |
| 550 request->Start(); | 564 request->Start(); |
| 551 ASSERT_TRUE(request->is_pending()); | 565 ASSERT_TRUE(request->is_pending()); |
| 552 base::RunLoop().RunUntilIdle(); | 566 base::RunLoop().RunUntilIdle(); |
| 553 | 567 |
| 554 EXPECT_THAT(delegate.request_status(), IsOk()); | 568 EXPECT_THAT(delegate.request_status(), IsOk()); |
| 555 EXPECT_EQ(12, request->received_response_content_length()); | 569 EXPECT_EQ(12, request->received_response_content_length()); |
| 556 // Should not include the redirect. | 570 // Should not include the redirect. |
| 557 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)), | 571 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)), |
| 558 request->GetTotalSentBytes()); | 572 request->GetTotalSentBytes()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 569 | 583 |
| 570 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 584 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 571 TestNetworkBytesCancelledAfterHeaders) { | 585 TestNetworkBytesCancelledAfterHeaders) { |
| 572 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 586 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 573 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n\r\n")}; | 587 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n\r\n")}; |
| 574 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 588 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 575 arraysize(writes)); | 589 arraysize(writes)); |
| 576 socket_factory_.AddSocketDataProvider(&socket_data); | 590 socket_factory_.AddSocketDataProvider(&socket_data); |
| 577 | 591 |
| 578 TestDelegate delegate; | 592 TestDelegate delegate; |
| 579 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 593 std::unique_ptr<URLRequest> request = |
| 580 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 594 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 595 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 581 | 596 |
| 582 delegate.set_cancel_in_response_started(true); | 597 delegate.set_cancel_in_response_started(true); |
| 583 request->Start(); | 598 request->Start(); |
| 584 base::RunLoop().RunUntilIdle(); | 599 base::RunLoop().RunUntilIdle(); |
| 585 | 600 |
| 586 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); | 601 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); |
| 587 EXPECT_EQ(0, request->received_response_content_length()); | 602 EXPECT_EQ(0, request->received_response_content_length()); |
| 588 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 603 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 589 request->GetTotalSentBytes()); | 604 request->GetTotalSentBytes()); |
| 590 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 605 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 591 request->GetTotalReceivedBytes()); | 606 request->GetTotalReceivedBytes()); |
| 592 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 607 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 593 network_delegate_.total_network_bytes_sent()); | 608 network_delegate_.total_network_bytes_sent()); |
| 594 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 609 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 595 network_delegate_.total_network_bytes_received()); | 610 network_delegate_.total_network_bytes_received()); |
| 596 } | 611 } |
| 597 | 612 |
| 598 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 613 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 599 TestNetworkBytesCancelledImmediately) { | 614 TestNetworkBytesCancelledImmediately) { |
| 600 StaticSocketDataProvider socket_data(nullptr, 0, nullptr, 0); | 615 StaticSocketDataProvider socket_data(nullptr, 0, nullptr, 0); |
| 601 socket_factory_.AddSocketDataProvider(&socket_data); | 616 socket_factory_.AddSocketDataProvider(&socket_data); |
| 602 | 617 |
| 603 TestDelegate delegate; | 618 TestDelegate delegate; |
| 604 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 619 std::unique_ptr<URLRequest> request = |
| 605 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 620 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 621 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 606 | 622 |
| 607 request->Start(); | 623 request->Start(); |
| 608 request->Cancel(); | 624 request->Cancel(); |
| 609 base::RunLoop().RunUntilIdle(); | 625 base::RunLoop().RunUntilIdle(); |
| 610 | 626 |
| 611 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); | 627 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); |
| 612 EXPECT_EQ(0, request->received_response_content_length()); | 628 EXPECT_EQ(0, request->received_response_content_length()); |
| 613 EXPECT_EQ(0, request->GetTotalSentBytes()); | 629 EXPECT_EQ(0, request->GetTotalSentBytes()); |
| 614 EXPECT_EQ(0, request->GetTotalReceivedBytes()); | 630 EXPECT_EQ(0, request->GetTotalReceivedBytes()); |
| 615 EXPECT_EQ(0, network_delegate_.total_network_bytes_received()); | 631 EXPECT_EQ(0, network_delegate_.total_network_bytes_received()); |
| 616 } | 632 } |
| 617 | 633 |
| 618 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestHttpTimeToFirstByte) { | 634 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestHttpTimeToFirstByte) { |
| 619 base::HistogramTester histograms; | 635 base::HistogramTester histograms; |
| 620 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 636 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 621 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 637 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 622 "Content-Length: 12\r\n\r\n"), | 638 "Content-Length: 12\r\n\r\n"), |
| 623 MockRead("Test Content")}; | 639 MockRead("Test Content")}; |
| 624 | 640 |
| 625 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 641 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 626 arraysize(writes)); | 642 arraysize(writes)); |
| 627 socket_factory_.AddSocketDataProvider(&socket_data); | 643 socket_factory_.AddSocketDataProvider(&socket_data); |
| 628 | 644 |
| 629 TestDelegate delegate; | 645 TestDelegate delegate; |
| 630 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 646 std::unique_ptr<URLRequest> request = |
| 631 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 647 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 648 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 632 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 0); | 649 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 0); |
| 633 | 650 |
| 634 request->Start(); | 651 request->Start(); |
| 635 base::RunLoop().Run(); | 652 base::RunLoop().Run(); |
| 636 | 653 |
| 637 EXPECT_THAT(delegate.request_status(), IsOk()); | 654 EXPECT_THAT(delegate.request_status(), IsOk()); |
| 638 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 1); | 655 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 1); |
| 639 } | 656 } |
| 640 | 657 |
| 641 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 658 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 642 TestHttpTimeToFirstByteForCancelledTask) { | 659 TestHttpTimeToFirstByteForCancelledTask) { |
| 643 base::HistogramTester histograms; | 660 base::HistogramTester histograms; |
| 644 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 661 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 645 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 662 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 646 "Content-Length: 12\r\n\r\n"), | 663 "Content-Length: 12\r\n\r\n"), |
| 647 MockRead("Test Content")}; | 664 MockRead("Test Content")}; |
| 648 | 665 |
| 649 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 666 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 650 arraysize(writes)); | 667 arraysize(writes)); |
| 651 socket_factory_.AddSocketDataProvider(&socket_data); | 668 socket_factory_.AddSocketDataProvider(&socket_data); |
| 652 | 669 |
| 653 TestDelegate delegate; | 670 TestDelegate delegate; |
| 654 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 671 std::unique_ptr<URLRequest> request = |
| 655 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 672 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 673 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 656 | 674 |
| 657 request->Start(); | 675 request->Start(); |
| 658 request->Cancel(); | 676 request->Cancel(); |
| 659 base::RunLoop().Run(); | 677 base::RunLoop().Run(); |
| 660 | 678 |
| 661 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); | 679 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); |
| 662 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 0); | 680 histograms.ExpectTotalCount("Net.HttpTimeToFirstByte", 0); |
| 663 } | 681 } |
| 664 | 682 |
| 665 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) { | 683 TEST_F(URLRequestHttpJobTest, TestCancelWhileReadingCookies) { |
| 666 DelayedCookieMonster cookie_monster; | 684 DelayedCookieMonster cookie_monster; |
| 667 TestURLRequestContext context(true); | 685 TestURLRequestContext context(true); |
| 668 context.set_cookie_store(&cookie_monster); | 686 context.set_cookie_store(&cookie_monster); |
| 669 context.Init(); | 687 context.Init(); |
| 670 | 688 |
| 671 TestDelegate delegate; | 689 TestDelegate delegate; |
| 672 std::unique_ptr<URLRequest> request = context.CreateRequest( | 690 std::unique_ptr<URLRequest> request = |
| 673 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 691 context.CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 692 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 674 | 693 |
| 675 request->Start(); | 694 request->Start(); |
| 676 request->Cancel(); | 695 request->Cancel(); |
| 677 base::RunLoop().Run(); | 696 base::RunLoop().Run(); |
| 678 | 697 |
| 679 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); | 698 EXPECT_THAT(delegate.request_status(), IsError(ERR_ABORTED)); |
| 680 } | 699 } |
| 681 | 700 |
| 682 // Make sure that SetPriority actually sets the URLRequestHttpJob's | 701 // Make sure that SetPriority actually sets the URLRequestHttpJob's |
| 683 // priority, before start. Other tests handle the after start case. | 702 // priority, before start. Other tests handle the after start case. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 {"ws://upgrade.test:123/", true, "wss://upgrade.test:123/"}, | 785 {"ws://upgrade.test:123/", true, "wss://upgrade.test:123/"}, |
| 767 {"ws://no-upgrade.test/", false, "ws://no-upgrade.test/"}, | 786 {"ws://no-upgrade.test/", false, "ws://no-upgrade.test/"}, |
| 768 {"ws://no-upgrade.test:123/", false, "ws://no-upgrade.test:123/"}, | 787 {"ws://no-upgrade.test:123/", false, "ws://no-upgrade.test:123/"}, |
| 769 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) | 788 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 770 }; | 789 }; |
| 771 | 790 |
| 772 for (const auto& test : cases) { | 791 for (const auto& test : cases) { |
| 773 SCOPED_TRACE(test.url); | 792 SCOPED_TRACE(test.url); |
| 774 TestDelegate d; | 793 TestDelegate d; |
| 775 TestNetworkDelegate network_delegate; | 794 TestNetworkDelegate network_delegate; |
| 776 std::unique_ptr<URLRequest> r( | 795 std::unique_ptr<URLRequest> r(context_.CreateRequest( |
| 777 context_.CreateRequest(GURL(test.url), DEFAULT_PRIORITY, &d)); | 796 GURL(test.url), DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 778 | 797 |
| 779 net_log_.Clear(); | 798 net_log_.Clear(); |
| 780 r->Start(); | 799 r->Start(); |
| 781 base::RunLoop().Run(); | 800 base::RunLoop().Run(); |
| 782 | 801 |
| 783 if (test.upgrade_expected) { | 802 if (test.upgrade_expected) { |
| 784 net::TestNetLogEntry::List entries; | 803 net::TestNetLogEntry::List entries; |
| 785 net_log_.GetEntries(&entries); | 804 net_log_.GetEntries(&entries); |
| 786 int redirects = 0; | 805 int redirects = 0; |
| 787 for (const auto& entry : entries) { | 806 for (const auto& entry : entries) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 | 865 |
| 847 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 866 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 848 arraysize(writes)); | 867 arraysize(writes)); |
| 849 socket_factory_.AddSocketDataProvider(&socket_data); | 868 socket_factory_.AddSocketDataProvider(&socket_data); |
| 850 | 869 |
| 851 MockSdchObserver sdch_observer; | 870 MockSdchObserver sdch_observer; |
| 852 SdchManager sdch_manager; | 871 SdchManager sdch_manager; |
| 853 sdch_manager.AddObserver(&sdch_observer); | 872 sdch_manager.AddObserver(&sdch_observer); |
| 854 context_.set_sdch_manager(&sdch_manager); | 873 context_.set_sdch_manager(&sdch_manager); |
| 855 TestDelegate delegate; | 874 TestDelegate delegate; |
| 856 std::unique_ptr<URLRequest> request = context_.CreateRequest( | 875 std::unique_ptr<URLRequest> request = |
| 857 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 876 context_.CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 877 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 858 request->Start(); | 878 request->Start(); |
| 859 | 879 |
| 860 base::RunLoop().Run(); | 880 base::RunLoop().Run(); |
| 861 // SdchPolicyDelegate::OnDictionaryIdError() detects that the response is | 881 // SdchPolicyDelegate::OnDictionaryIdError() detects that the response is |
| 862 // malformed (missing dictionary), and will issue a pass-through of the raw | 882 // malformed (missing dictionary), and will issue a pass-through of the raw |
| 863 // response. | 883 // response. |
| 864 EXPECT_EQ(OK, delegate.request_status()); | 884 EXPECT_EQ(OK, delegate.request_status()); |
| 865 EXPECT_EQ("Test Content", delegate.data_received()); | 885 EXPECT_EQ("Test Content", delegate.data_received()); |
| 866 // Cleanup manager. | 886 // Cleanup manager. |
| 867 sdch_manager.RemoveObserver(&sdch_observer); | 887 sdch_manager.RemoveObserver(&sdch_observer); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 889 SdchManager sdch_manager; | 909 SdchManager sdch_manager; |
| 890 sdch_manager.AddObserver(&sdch_observer); | 910 sdch_manager.AddObserver(&sdch_observer); |
| 891 context_.set_sdch_manager(&sdch_manager); | 911 context_.set_sdch_manager(&sdch_manager); |
| 892 | 912 |
| 893 // First response will be "from network" and we should have OnGetDictionary | 913 // First response will be "from network" and we should have OnGetDictionary |
| 894 // invoked. | 914 // invoked. |
| 895 GURL url("http://example.com"); | 915 GURL url("http://example.com"); |
| 896 EXPECT_CALL(sdch_observer, | 916 EXPECT_CALL(sdch_observer, |
| 897 OnGetDictionary(url, GURL("http://example.com/sdch.dict"))); | 917 OnGetDictionary(url, GURL("http://example.com/sdch.dict"))); |
| 898 TestDelegate delegate; | 918 TestDelegate delegate; |
| 899 std::unique_ptr<URLRequest> request = | 919 std::unique_ptr<URLRequest> request = context_.CreateRequest( |
| 900 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate); | 920 url, DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 901 request->Start(); | 921 request->Start(); |
| 902 base::RunLoop().RunUntilIdle(); | 922 base::RunLoop().RunUntilIdle(); |
| 903 | 923 |
| 904 EXPECT_THAT(delegate.request_status(), IsOk()); | 924 EXPECT_THAT(delegate.request_status(), IsOk()); |
| 905 | 925 |
| 906 // Second response should be from cache without notification of SdchObserver | 926 // Second response should be from cache without notification of SdchObserver |
| 907 TestDelegate delegate2; | 927 TestDelegate delegate2; |
| 908 std::unique_ptr<URLRequest> request2 = | 928 std::unique_ptr<URLRequest> request2 = context_.CreateRequest( |
| 909 context_.CreateRequest(url, DEFAULT_PRIORITY, &delegate2); | 929 url, DEFAULT_PRIORITY, &delegate2, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 910 request2->Start(); | 930 request2->Start(); |
| 911 base::RunLoop().RunUntilIdle(); | 931 base::RunLoop().RunUntilIdle(); |
| 912 | 932 |
| 913 EXPECT_THAT(delegate2.request_status(), IsOk()); | 933 EXPECT_THAT(delegate2.request_status(), IsOk()); |
| 914 | 934 |
| 915 // Cleanup manager. | 935 // Cleanup manager. |
| 916 sdch_manager.RemoveObserver(&sdch_observer); | 936 sdch_manager.RemoveObserver(&sdch_observer); |
| 917 } | 937 } |
| 918 | 938 |
| 919 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test { | 939 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 935 TEST_F(URLRequestHttpJobWithBrotliSupportTest, NoBrotliAdvertisementOverHttp) { | 955 TEST_F(URLRequestHttpJobWithBrotliSupportTest, NoBrotliAdvertisementOverHttp) { |
| 936 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 956 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 937 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 957 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 938 "Content-Length: 12\r\n\r\n"), | 958 "Content-Length: 12\r\n\r\n"), |
| 939 MockRead("Test Content")}; | 959 MockRead("Test Content")}; |
| 940 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 960 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 941 arraysize(writes)); | 961 arraysize(writes)); |
| 942 socket_factory_.AddSocketDataProvider(&socket_data); | 962 socket_factory_.AddSocketDataProvider(&socket_data); |
| 943 | 963 |
| 944 TestDelegate delegate; | 964 TestDelegate delegate; |
| 945 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 965 std::unique_ptr<URLRequest> request = |
| 946 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | 966 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 967 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 947 request->Start(); | 968 request->Start(); |
| 948 base::RunLoop().RunUntilIdle(); | 969 base::RunLoop().RunUntilIdle(); |
| 949 | 970 |
| 950 EXPECT_THAT(delegate.request_status(), IsOk()); | 971 EXPECT_THAT(delegate.request_status(), IsOk()); |
| 951 EXPECT_EQ(12, request->received_response_content_length()); | 972 EXPECT_EQ(12, request->received_response_content_length()); |
| 952 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 973 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 953 request->GetTotalSentBytes()); | 974 request->GetTotalSentBytes()); |
| 954 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 975 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 955 request->GetTotalReceivedBytes()); | 976 request->GetTotalReceivedBytes()); |
| 956 } | 977 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 970 "Accept-Encoding: gzip, deflate, br\r\n" | 991 "Accept-Encoding: gzip, deflate, br\r\n" |
| 971 "Accept-Language: en-us,fr\r\n\r\n")}; | 992 "Accept-Language: en-us,fr\r\n\r\n")}; |
| 972 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 993 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 973 "Content-Length: 12\r\n\r\n"), | 994 "Content-Length: 12\r\n\r\n"), |
| 974 MockRead("Test Content")}; | 995 MockRead("Test Content")}; |
| 975 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 996 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 976 arraysize(writes)); | 997 arraysize(writes)); |
| 977 socket_factory_.AddSocketDataProvider(&socket_data); | 998 socket_factory_.AddSocketDataProvider(&socket_data); |
| 978 | 999 |
| 979 TestDelegate delegate; | 1000 TestDelegate delegate; |
| 980 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 1001 std::unique_ptr<URLRequest> request = |
| 981 GURL("https://www.example.com"), DEFAULT_PRIORITY, &delegate); | 1002 context_->CreateRequest(GURL("https://www.example.com"), DEFAULT_PRIORITY, |
| 1003 &delegate, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 982 request->Start(); | 1004 request->Start(); |
| 983 base::RunLoop().RunUntilIdle(); | 1005 base::RunLoop().RunUntilIdle(); |
| 984 | 1006 |
| 985 EXPECT_THAT(delegate.request_status(), IsOk()); | 1007 EXPECT_THAT(delegate.request_status(), IsOk()); |
| 986 EXPECT_EQ(12, request->received_response_content_length()); | 1008 EXPECT_EQ(12, request->received_response_content_length()); |
| 987 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 1009 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 988 request->GetTotalSentBytes()); | 1010 request->GetTotalSentBytes()); |
| 989 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 1011 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 990 request->GetTotalReceivedBytes()); | 1012 request->GetTotalReceivedBytes()); |
| 991 } | 1013 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1005 {"https://blocked.test/", false, false}, | 1027 {"https://blocked.test/", false, false}, |
| 1006 }; | 1028 }; |
| 1007 | 1029 |
| 1008 for (const TestCase& test : cases) { | 1030 for (const TestCase& test : cases) { |
| 1009 JNIEnv* env = base::android::AttachCurrentThread(); | 1031 JNIEnv* env = base::android::AttachCurrentThread(); |
| 1010 Java_AndroidNetworkLibraryTestUtil_setUpSecurityPolicyForTesting( | 1032 Java_AndroidNetworkLibraryTestUtil_setUpSecurityPolicyForTesting( |
| 1011 env, test.cleartext_permitted); | 1033 env, test.cleartext_permitted); |
| 1012 | 1034 |
| 1013 TestDelegate delegate; | 1035 TestDelegate delegate; |
| 1014 std::unique_ptr<URLRequest> request = | 1036 std::unique_ptr<URLRequest> request = |
| 1015 context_.CreateRequest(GURL(test.url), DEFAULT_PRIORITY, &delegate); | 1037 context_.CreateRequest(GURL(test.url), DEFAULT_PRIORITY, &delegate, |
| 1038 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1016 request->Start(); | 1039 request->Start(); |
| 1017 base::RunLoop().Run(); | 1040 base::RunLoop().Run(); |
| 1018 | 1041 |
| 1019 int sdk_int = base::android::BuildInfo::GetInstance()->sdk_int(); | 1042 int sdk_int = base::android::BuildInfo::GetInstance()->sdk_int(); |
| 1020 bool expect_blocked = (sdk_int >= base::android::SDK_VERSION_MARSHMALLOW && | 1043 bool expect_blocked = (sdk_int >= base::android::SDK_VERSION_MARSHMALLOW && |
| 1021 test.should_block); | 1044 test.should_block); |
| 1022 if (expect_blocked) { | 1045 if (expect_blocked) { |
| 1023 EXPECT_THAT(delegate.request_status(), | 1046 EXPECT_THAT(delegate.request_status(), |
| 1024 IsError(ERR_CLEARTEXT_NOT_PERMITTED)); | 1047 IsError(ERR_CLEARTEXT_NOT_PERMITTED)); |
| 1025 } else { | 1048 } else { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1052 MockClientSocketFactory socket_factory_; | 1075 MockClientSocketFactory socket_factory_; |
| 1053 TestURLRequestContext context_; | 1076 TestURLRequestContext context_; |
| 1054 }; | 1077 }; |
| 1055 | 1078 |
| 1056 class URLRequestHttpJobWebSocketTest | 1079 class URLRequestHttpJobWebSocketTest |
| 1057 : public URLRequestHttpJobWebSocketTestBase { | 1080 : public URLRequestHttpJobWebSocketTestBase { |
| 1058 protected: | 1081 protected: |
| 1059 URLRequestHttpJobWebSocketTest() | 1082 URLRequestHttpJobWebSocketTest() |
| 1060 : req_(context_.CreateRequest(GURL("ws://www.example.com"), | 1083 : req_(context_.CreateRequest(GURL("ws://www.example.com"), |
| 1061 DEFAULT_PRIORITY, | 1084 DEFAULT_PRIORITY, |
| 1062 &delegate_)) { | 1085 &delegate_, |
| 1063 } | 1086 TRAFFIC_ANNOTATION_FOR_TESTS)) {} |
| 1064 | 1087 |
| 1065 TestDelegate delegate_; | 1088 TestDelegate delegate_; |
| 1066 std::unique_ptr<URLRequest> req_; | 1089 std::unique_ptr<URLRequest> req_; |
| 1067 }; | 1090 }; |
| 1068 | 1091 |
| 1069 class MockCreateHelper : public WebSocketHandshakeStreamBase::CreateHelper { | 1092 class MockCreateHelper : public WebSocketHandshakeStreamBase::CreateHelper { |
| 1070 public: | 1093 public: |
| 1071 // GoogleMock does not appear to play nicely with move-only types like | 1094 // GoogleMock does not appear to play nicely with move-only types like |
| 1072 // std::unique_ptr, so this forwarding method acts as a workaround. | 1095 // std::unique_ptr, so this forwarding method acts as a workaround. |
| 1073 WebSocketHandshakeStreamBase* CreateBasicStream( | 1096 WebSocketHandshakeStreamBase* CreateBasicStream( |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 base::RunLoop().RunUntilIdle(); | 1216 base::RunLoop().RunUntilIdle(); |
| 1194 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); | 1217 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); |
| 1195 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 1218 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 1196 } | 1219 } |
| 1197 | 1220 |
| 1198 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) | 1221 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 1199 | 1222 |
| 1200 } // namespace | 1223 } // namespace |
| 1201 | 1224 |
| 1202 } // namespace net | 1225 } // namespace net |
| OLD | NEW |