OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 void TearDown() override { | 261 void TearDown() override { |
262 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 262 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
263 base::MessageLoop::current()->RunUntilIdle(); | 263 base::MessageLoop::current()->RunUntilIdle(); |
264 // Empty the current queue. | 264 // Empty the current queue. |
265 base::MessageLoop::current()->RunUntilIdle(); | 265 base::MessageLoop::current()->RunUntilIdle(); |
266 PlatformTest::TearDown(); | 266 PlatformTest::TearDown(); |
267 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 267 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
268 base::MessageLoop::current()->RunUntilIdle(); | 268 base::MessageLoop::current()->RunUntilIdle(); |
269 } | 269 } |
270 | 270 |
| 271 const char* GetAlternateProtocolFromParam() { |
| 272 return |
| 273 AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())); |
| 274 } |
| 275 |
271 // This is the expected return from a current server advertising SPDY. | 276 // This is the expected return from a current server advertising SPDY. |
272 std::string GetAlternateProtocolHttpHeader() { | 277 std::string GetAlternateProtocolHttpHeader() { |
273 return | 278 return std::string("Alternate-Protocol: 443:") + |
274 std::string("Alternate-Protocol: 443:") + | 279 GetAlternateProtocolFromParam() + "\r\n\r\n"; |
275 AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam())) + | |
276 "\r\n\r\n"; | |
277 } | 280 } |
278 | 281 |
279 // Either |write_failure| specifies a write failure or |read_failure| | 282 // Either |write_failure| specifies a write failure or |read_failure| |
280 // specifies a read failure when using a reused socket. In either case, the | 283 // specifies a read failure when using a reused socket. In either case, the |
281 // failure should cause the network transaction to resend the request, and the | 284 // failure should cause the network transaction to resend the request, and the |
282 // other argument should be NULL. | 285 // other argument should be NULL. |
283 void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, | 286 void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
284 const MockRead* read_failure); | 287 const MockRead* read_failure); |
285 | 288 |
286 // Either |write_failure| specifies a write failure or |read_failure| | 289 // Either |write_failure| specifies a write failure or |read_failure| |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 403 |
401 // Original socket limits. Some tests set these. Safest to always restore | 404 // Original socket limits. Some tests set these. Safest to always restore |
402 // them once each test has been run. | 405 // them once each test has been run. |
403 int old_max_group_sockets_; | 406 int old_max_group_sockets_; |
404 int old_max_pool_sockets_; | 407 int old_max_pool_sockets_; |
405 }; | 408 }; |
406 | 409 |
407 INSTANTIATE_TEST_CASE_P( | 410 INSTANTIATE_TEST_CASE_P( |
408 NextProto, | 411 NextProto, |
409 HttpNetworkTransactionTest, | 412 HttpNetworkTransactionTest, |
410 testing::Values(kProtoDeprecatedSPDY2, | 413 testing::Values(kProtoSPDY31, kProtoSPDY4_14, kProtoSPDY4_15)); |
411 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4_14, kProtoSPDY4_15)); | |
412 | 414 |
413 namespace { | 415 namespace { |
414 | 416 |
415 class BeforeNetworkStartHandler { | 417 class BeforeNetworkStartHandler { |
416 public: | 418 public: |
417 explicit BeforeNetworkStartHandler(bool defer) | 419 explicit BeforeNetworkStartHandler(bool defer) |
418 : defer_on_before_network_start_(defer), | 420 : defer_on_before_network_start_(defer), |
419 observed_before_network_start_(false) {} | 421 observed_before_network_start_(false) {} |
420 | 422 |
421 void OnBeforeNetworkStart(bool* defer) { | 423 void OnBeforeNetworkStart(bool* defer) { |
(...skipping 9678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10100 | 10102 |
10101 // First round goes unauthenticated through the proxy. | 10103 // First round goes unauthenticated through the proxy. |
10102 MockWrite data_writes_1[] = { | 10104 MockWrite data_writes_1[] = { |
10103 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | 10105 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
10104 "Host: www.google.com\r\n" | 10106 "Host: www.google.com\r\n" |
10105 "Proxy-Connection: keep-alive\r\n" | 10107 "Proxy-Connection: keep-alive\r\n" |
10106 "\r\n"), | 10108 "\r\n"), |
10107 }; | 10109 }; |
10108 MockRead data_reads_1[] = { | 10110 MockRead data_reads_1[] = { |
10109 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 10111 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
10110 MockRead("HTTP/1.1 200 OK\r\n" | 10112 MockRead("HTTP/1.1 200 OK\r\n"), |
10111 "Alternate-Protocol: 443:npn-spdy/2\r\n" | 10113 MockRead("Alternate-Protocol: 443:"), |
10112 "Proxy-Connection: close\r\n" | 10114 MockRead(GetAlternateProtocolFromParam()), |
10113 "\r\n"), | 10115 MockRead("\r\n"), |
| 10116 MockRead("Proxy-Connection: close\r\n"), |
| 10117 MockRead("\r\n"), |
10114 }; | 10118 }; |
10115 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), | 10119 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
10116 data_writes_1, arraysize(data_writes_1)); | 10120 data_writes_1, arraysize(data_writes_1)); |
10117 | 10121 |
10118 // Second round tries to tunnel to www.google.com due to the | 10122 // Second round tries to tunnel to www.google.com due to the |
10119 // Alternate-Protocol announcement in the first round. It fails due | 10123 // Alternate-Protocol announcement in the first round. It fails due |
10120 // to a proxy authentication challenge. | 10124 // to a proxy authentication challenge. |
10121 // After the failure, a tunnel is established to www.google.com using | 10125 // After the failure, a tunnel is established to www.google.com using |
10122 // Proxy-Authorization headers. There is then a SPDY request round. | 10126 // Proxy-Authorization headers. There is then a SPDY request round. |
10123 // | 10127 // |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11395 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, | 11399 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
11396 LOWEST)); | 11400 LOWEST)); |
11397 scoped_ptr<SpdyFrame> req1( | 11401 scoped_ptr<SpdyFrame> req1( |
11398 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); | 11402 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
11399 scoped_ptr<SpdyFrame> wrapped_req1( | 11403 scoped_ptr<SpdyFrame> wrapped_req1( |
11400 spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); | 11404 spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
11401 | 11405 |
11402 // SPDY GET for HTTP URL (through the proxy, but not the tunnel). | 11406 // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
11403 SpdyHeaderBlock req2_block; | 11407 SpdyHeaderBlock req2_block; |
11404 req2_block[spdy_util_.GetMethodKey()] = "GET"; | 11408 req2_block[spdy_util_.GetMethodKey()] = "GET"; |
11405 req2_block[spdy_util_.GetPathKey()] = | 11409 req2_block[spdy_util_.GetPathKey()] = "/"; |
11406 spdy_util_.is_spdy2() ? http_url.c_str() : "/"; | |
11407 req2_block[spdy_util_.GetHostKey()] = "www.google.com:443"; | 11410 req2_block[spdy_util_.GetHostKey()] = "www.google.com:443"; |
11408 req2_block[spdy_util_.GetSchemeKey()] = "http"; | 11411 req2_block[spdy_util_.GetSchemeKey()] = "http"; |
11409 spdy_util_.MaybeAddVersionHeader(&req2_block); | 11412 spdy_util_.MaybeAddVersionHeader(&req2_block); |
11410 scoped_ptr<SpdyFrame> req2( | 11413 scoped_ptr<SpdyFrame> req2( |
11411 spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); | 11414 spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
11412 | 11415 |
11413 MockWrite writes1[] = { | 11416 MockWrite writes1[] = { |
11414 CreateMockWrite(*connect, 0), | 11417 CreateMockWrite(*connect, 0), |
11415 CreateMockWrite(*wrapped_req1, 2), | 11418 CreateMockWrite(*wrapped_req1, 2), |
11416 CreateMockWrite(*req2, 5), | 11419 CreateMockWrite(*req2, 5), |
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13181 EXPECT_EQ(ERR_IO_PENDING, rv); | 13184 EXPECT_EQ(ERR_IO_PENDING, rv); |
13182 | 13185 |
13183 rv = callback.WaitForResult(); | 13186 rv = callback.WaitForResult(); |
13184 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 13187 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
13185 | 13188 |
13186 const HttpResponseInfo* response = trans->GetResponseInfo(); | 13189 const HttpResponseInfo* response = trans->GetResponseInfo(); |
13187 EXPECT_TRUE(response == NULL); | 13190 EXPECT_TRUE(response == NULL); |
13188 } | 13191 } |
13189 | 13192 |
13190 } // namespace net | 13193 } // namespace net |
OLD | NEW |