| 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 8490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8501 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8501 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8502 scoped_ptr<HttpTransaction> trans( | 8502 scoped_ptr<HttpTransaction> trans( |
| 8503 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8503 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8504 | 8504 |
| 8505 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 8505 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8506 EXPECT_EQ(ERR_IO_PENDING, rv); | 8506 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8507 | 8507 |
| 8508 HostPortPair http_host_port_pair("www.google.com", 80); | 8508 HostPortPair http_host_port_pair("www.google.com", 80); |
| 8509 HttpServerProperties& http_server_properties = | 8509 HttpServerProperties& http_server_properties = |
| 8510 *session->http_server_properties(); | 8510 *session->http_server_properties(); |
| 8511 EXPECT_FALSE( | 8511 AlternateProtocolInfo alternate = |
| 8512 http_server_properties.HasAlternateProtocol(http_host_port_pair)); | 8512 http_server_properties.GetAlternateProtocol(http_host_port_pair); |
| 8513 EXPECT_EQ(alternate.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); |
| 8513 | 8514 |
| 8514 EXPECT_EQ(OK, callback.WaitForResult()); | 8515 EXPECT_EQ(OK, callback.WaitForResult()); |
| 8515 | 8516 |
| 8516 const HttpResponseInfo* response = trans->GetResponseInfo(); | 8517 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8517 ASSERT_TRUE(response != NULL); | 8518 ASSERT_TRUE(response != NULL); |
| 8518 ASSERT_TRUE(response->headers.get() != NULL); | 8519 ASSERT_TRUE(response->headers.get() != NULL); |
| 8519 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8520 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8520 EXPECT_FALSE(response->was_fetched_via_spdy); | 8521 EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8521 EXPECT_FALSE(response->was_npn_negotiated); | 8522 EXPECT_FALSE(response->was_npn_negotiated); |
| 8522 | 8523 |
| 8523 std::string response_data; | 8524 std::string response_data; |
| 8524 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8525 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8525 EXPECT_EQ("hello world", response_data); | 8526 EXPECT_EQ("hello world", response_data); |
| 8526 | 8527 |
| 8527 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); | 8528 alternate = http_server_properties.GetAlternateProtocol(http_host_port_pair); |
| 8528 const AlternateProtocolInfo alternate = | 8529 EXPECT_EQ(443, alternate.port); |
| 8529 http_server_properties.GetAlternateProtocol(http_host_port_pair); | 8530 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), alternate.protocol); |
| 8530 AlternateProtocolInfo expected_alternate( | 8531 EXPECT_EQ(1.0, alternate.probability); |
| 8531 443, AlternateProtocolFromNextProto(GetParam()), 1); | |
| 8532 EXPECT_TRUE(expected_alternate.Equals(alternate)); | |
| 8533 } | 8532 } |
| 8534 | 8533 |
| 8535 TEST_P(HttpNetworkTransactionTest, | 8534 TEST_P(HttpNetworkTransactionTest, |
| 8536 MarkBrokenAlternateProtocolAndFallback) { | 8535 MarkBrokenAlternateProtocolAndFallback) { |
| 8537 session_deps_.use_alternate_protocols = true; | 8536 session_deps_.use_alternate_protocols = true; |
| 8538 | 8537 |
| 8539 HttpRequestInfo request; | 8538 HttpRequestInfo request; |
| 8540 request.method = "GET"; | 8539 request.method = "GET"; |
| 8541 request.url = GURL("http://www.google.com/"); | 8540 request.url = GURL("http://www.google.com/"); |
| 8542 request.load_flags = 0; | 8541 request.load_flags = 0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8576 | 8575 |
| 8577 const HttpResponseInfo* response = trans->GetResponseInfo(); | 8576 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8578 ASSERT_TRUE(response != NULL); | 8577 ASSERT_TRUE(response != NULL); |
| 8579 ASSERT_TRUE(response->headers.get() != NULL); | 8578 ASSERT_TRUE(response->headers.get() != NULL); |
| 8580 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8579 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8581 | 8580 |
| 8582 std::string response_data; | 8581 std::string response_data; |
| 8583 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8582 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8584 EXPECT_EQ("hello world", response_data); | 8583 EXPECT_EQ("hello world", response_data); |
| 8585 | 8584 |
| 8586 ASSERT_TRUE(http_server_properties->HasAlternateProtocol( | |
| 8587 HostPortPair::FromURL(request.url))); | |
| 8588 const AlternateProtocolInfo alternate = | 8585 const AlternateProtocolInfo alternate = |
| 8589 http_server_properties->GetAlternateProtocol( | 8586 http_server_properties->GetAlternateProtocol( |
| 8590 HostPortPair::FromURL(request.url)); | 8587 HostPortPair::FromURL(request.url)); |
| 8588 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate.protocol); |
| 8591 EXPECT_TRUE(alternate.is_broken); | 8589 EXPECT_TRUE(alternate.is_broken); |
| 8592 } | 8590 } |
| 8593 | 8591 |
| 8594 TEST_P(HttpNetworkTransactionTest, | 8592 TEST_P(HttpNetworkTransactionTest, |
| 8595 AlternateProtocolPortRestrictedBlocked) { | 8593 AlternateProtocolPortRestrictedBlocked) { |
| 8596 // Ensure that we're not allowed to redirect traffic via an alternate | 8594 // Ensure that we're not allowed to redirect traffic via an alternate |
| 8597 // protocol to an unrestricted (port >= 1024) when the original traffic was | 8595 // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8598 // on a restricted port (port < 1024). Ensure that we can redirect in all | 8596 // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8599 // other cases. | 8597 // other cases. |
| 8600 session_deps_.use_alternate_protocols = true; | 8598 session_deps_.use_alternate_protocols = true; |
| (...skipping 4954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13555 ASSERT_TRUE(response); | 13553 ASSERT_TRUE(response); |
| 13556 ASSERT_TRUE(response->headers.get()); | 13554 ASSERT_TRUE(response->headers.get()); |
| 13557 | 13555 |
| 13558 EXPECT_EQ(101, response->headers->response_code()); | 13556 EXPECT_EQ(101, response->headers->response_code()); |
| 13559 | 13557 |
| 13560 trans.reset(); | 13558 trans.reset(); |
| 13561 session->CloseAllConnections(); | 13559 session->CloseAllConnections(); |
| 13562 } | 13560 } |
| 13563 | 13561 |
| 13564 } // namespace net | 13562 } // namespace net |
| OLD | NEW |