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/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 6476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6487 AuthCredentials(kFirst, kBar), callback4.callback()); | 6487 AuthCredentials(kFirst, kBar), callback4.callback()); |
6488 EXPECT_EQ(ERR_IO_PENDING, rv); | 6488 EXPECT_EQ(ERR_IO_PENDING, rv); |
6489 rv = callback4.WaitForResult(); | 6489 rv = callback4.WaitForResult(); |
6490 EXPECT_EQ(OK, rv); | 6490 EXPECT_EQ(OK, rv); |
6491 response = trans->GetResponseInfo(); | 6491 response = trans->GetResponseInfo(); |
6492 ASSERT_TRUE(response != NULL); | 6492 ASSERT_TRUE(response != NULL); |
6493 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 6493 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
6494 } | 6494 } |
6495 | 6495 |
6496 TEST_F(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { | 6496 TEST_F(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
6497 HttpStreamFactory::set_next_protos(MakeNextProtos("foo", "bar", NULL)); | |
6498 HttpStreamFactory::set_use_alternate_protocols(true); | 6497 HttpStreamFactory::set_use_alternate_protocols(true); |
| 6498 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
6499 | 6499 |
6500 SessionDependencies session_deps; | 6500 SessionDependencies session_deps; |
6501 | 6501 |
6502 MockRead data_reads[] = { | 6502 MockRead data_reads[] = { |
6503 MockRead("HTTP/1.1 200 OK\r\n"), | 6503 MockRead("HTTP/1.1 200 OK\r\n"), |
6504 MockRead(kAlternateProtocolHttpHeader), | 6504 MockRead(kAlternateProtocolHttpHeader), |
6505 MockRead("hello world"), | 6505 MockRead("hello world"), |
6506 MockRead(SYNCHRONOUS, OK), | 6506 MockRead(SYNCHRONOUS, OK), |
6507 }; | 6507 }; |
6508 | 6508 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6544 | 6544 |
6545 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); | 6545 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair)); |
6546 const PortAlternateProtocolPair alternate = | 6546 const PortAlternateProtocolPair alternate = |
6547 http_server_properties.GetAlternateProtocol(http_host_port_pair); | 6547 http_server_properties.GetAlternateProtocol(http_host_port_pair); |
6548 PortAlternateProtocolPair expected_alternate; | 6548 PortAlternateProtocolPair expected_alternate; |
6549 expected_alternate.port = 443; | 6549 expected_alternate.port = 443; |
6550 expected_alternate.protocol = NPN_SPDY_21; | 6550 expected_alternate.protocol = NPN_SPDY_21; |
6551 EXPECT_TRUE(expected_alternate.Equals(alternate)); | 6551 EXPECT_TRUE(expected_alternate.Equals(alternate)); |
6552 | 6552 |
6553 HttpStreamFactory::set_use_alternate_protocols(false); | 6553 HttpStreamFactory::set_use_alternate_protocols(false); |
6554 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 6554 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
6555 } | 6555 } |
6556 | 6556 |
6557 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { | 6557 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
6558 HttpStreamFactory::set_use_alternate_protocols(true); | 6558 HttpStreamFactory::set_use_alternate_protocols(true); |
6559 SessionDependencies session_deps; | 6559 SessionDependencies session_deps; |
6560 | 6560 |
6561 HttpRequestInfo request; | 6561 HttpRequestInfo request; |
6562 request.method = "GET"; | 6562 request.method = "GET"; |
6563 request.url = GURL("http://www.google.com/"); | 6563 request.url = GURL("http://www.google.com/"); |
6564 request.load_flags = 0; | 6564 request.load_flags = 0; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6858 ASSERT_TRUE(response->headers != NULL); | 6858 ASSERT_TRUE(response->headers != NULL); |
6859 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 6859 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
6860 | 6860 |
6861 std::string response_data; | 6861 std::string response_data; |
6862 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 6862 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
6863 EXPECT_EQ("hello world", response_data); | 6863 EXPECT_EQ("hello world", response_data); |
6864 } | 6864 } |
6865 | 6865 |
6866 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { | 6866 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
6867 HttpStreamFactory::set_use_alternate_protocols(true); | 6867 HttpStreamFactory::set_use_alternate_protocols(true); |
6868 HttpStreamFactory::set_next_protos(SpdyNextProtos()); | 6868 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
6869 SessionDependencies session_deps; | 6869 SessionDependencies session_deps; |
6870 | 6870 |
6871 HttpRequestInfo request; | 6871 HttpRequestInfo request; |
6872 request.method = "GET"; | 6872 request.method = "GET"; |
6873 request.url = GURL("http://www.google.com/"); | 6873 request.url = GURL("http://www.google.com/"); |
6874 request.load_flags = 0; | 6874 request.load_flags = 0; |
6875 | 6875 |
6876 MockRead data_reads[] = { | 6876 MockRead data_reads[] = { |
6877 MockRead("HTTP/1.1 200 OK\r\n"), | 6877 MockRead("HTTP/1.1 200 OK\r\n"), |
6878 MockRead(kAlternateProtocolHttpHeader), | 6878 MockRead(kAlternateProtocolHttpHeader), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6941 response = trans->GetResponseInfo(); | 6941 response = trans->GetResponseInfo(); |
6942 ASSERT_TRUE(response != NULL); | 6942 ASSERT_TRUE(response != NULL); |
6943 ASSERT_TRUE(response->headers != NULL); | 6943 ASSERT_TRUE(response->headers != NULL); |
6944 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 6944 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
6945 EXPECT_TRUE(response->was_fetched_via_spdy); | 6945 EXPECT_TRUE(response->was_fetched_via_spdy); |
6946 EXPECT_TRUE(response->was_npn_negotiated); | 6946 EXPECT_TRUE(response->was_npn_negotiated); |
6947 | 6947 |
6948 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 6948 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
6949 EXPECT_EQ("hello!", response_data); | 6949 EXPECT_EQ("hello!", response_data); |
6950 | 6950 |
6951 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 6951 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
6952 HttpStreamFactory::set_use_alternate_protocols(false); | 6952 HttpStreamFactory::set_use_alternate_protocols(false); |
6953 } | 6953 } |
6954 | 6954 |
6955 TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { | 6955 TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
6956 HttpStreamFactory::set_use_alternate_protocols(true); | 6956 HttpStreamFactory::set_use_alternate_protocols(true); |
6957 HttpStreamFactory::set_next_protos(SpdyNextProtos()); | 6957 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
6958 SessionDependencies session_deps; | 6958 SessionDependencies session_deps; |
6959 | 6959 |
6960 HttpRequestInfo request; | 6960 HttpRequestInfo request; |
6961 request.method = "GET"; | 6961 request.method = "GET"; |
6962 request.url = GURL("http://www.google.com/"); | 6962 request.url = GURL("http://www.google.com/"); |
6963 request.load_flags = 0; | 6963 request.load_flags = 0; |
6964 | 6964 |
6965 MockRead data_reads[] = { | 6965 MockRead data_reads[] = { |
6966 MockRead("HTTP/1.1 200 OK\r\n"), | 6966 MockRead("HTTP/1.1 200 OK\r\n"), |
6967 MockRead(kAlternateProtocolHttpHeader), | 6967 MockRead(kAlternateProtocolHttpHeader), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7057 | 7057 |
7058 response = trans3.GetResponseInfo(); | 7058 response = trans3.GetResponseInfo(); |
7059 ASSERT_TRUE(response != NULL); | 7059 ASSERT_TRUE(response != NULL); |
7060 ASSERT_TRUE(response->headers != NULL); | 7060 ASSERT_TRUE(response->headers != NULL); |
7061 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 7061 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
7062 EXPECT_TRUE(response->was_fetched_via_spdy); | 7062 EXPECT_TRUE(response->was_fetched_via_spdy); |
7063 EXPECT_TRUE(response->was_npn_negotiated); | 7063 EXPECT_TRUE(response->was_npn_negotiated); |
7064 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); | 7064 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
7065 EXPECT_EQ("hello!", response_data); | 7065 EXPECT_EQ("hello!", response_data); |
7066 | 7066 |
7067 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 7067 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
7068 HttpStreamFactory::set_use_alternate_protocols(false); | 7068 HttpStreamFactory::set_use_alternate_protocols(false); |
7069 } | 7069 } |
7070 | 7070 |
7071 TEST_F(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { | 7071 TEST_F(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
7072 HttpStreamFactory::set_use_alternate_protocols(true); | 7072 HttpStreamFactory::set_use_alternate_protocols(true); |
7073 HttpStreamFactory::set_next_protos(SpdyNextProtos()); | 7073 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
7074 SessionDependencies session_deps; | 7074 SessionDependencies session_deps; |
7075 | 7075 |
7076 HttpRequestInfo request; | 7076 HttpRequestInfo request; |
7077 request.method = "GET"; | 7077 request.method = "GET"; |
7078 request.url = GURL("http://www.google.com/"); | 7078 request.url = GURL("http://www.google.com/"); |
7079 request.load_flags = 0; | 7079 request.load_flags = 0; |
7080 | 7080 |
7081 MockRead data_reads[] = { | 7081 MockRead data_reads[] = { |
7082 MockRead("HTTP/1.1 200 OK\r\n"), | 7082 MockRead("HTTP/1.1 200 OK\r\n"), |
7083 MockRead(kAlternateProtocolHttpHeader), | 7083 MockRead(kAlternateProtocolHttpHeader), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7131 response = trans->GetResponseInfo(); | 7131 response = trans->GetResponseInfo(); |
7132 ASSERT_TRUE(response != NULL); | 7132 ASSERT_TRUE(response != NULL); |
7133 ASSERT_TRUE(response->headers != NULL); | 7133 ASSERT_TRUE(response->headers != NULL); |
7134 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 7134 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
7135 EXPECT_FALSE(response->was_fetched_via_spdy); | 7135 EXPECT_FALSE(response->was_fetched_via_spdy); |
7136 EXPECT_FALSE(response->was_npn_negotiated); | 7136 EXPECT_FALSE(response->was_npn_negotiated); |
7137 | 7137 |
7138 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 7138 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
7139 EXPECT_EQ("hello world", response_data); | 7139 EXPECT_EQ("hello world", response_data); |
7140 | 7140 |
7141 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 7141 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
7142 HttpStreamFactory::set_use_alternate_protocols(false); | 7142 HttpStreamFactory::set_use_alternate_protocols(false); |
7143 } | 7143 } |
7144 | 7144 |
7145 class CapturingProxyResolver : public ProxyResolver { | 7145 class CapturingProxyResolver : public ProxyResolver { |
7146 public: | 7146 public: |
7147 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} | 7147 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
7148 virtual ~CapturingProxyResolver() {} | 7148 virtual ~CapturingProxyResolver() {} |
7149 | 7149 |
7150 virtual int GetProxyForURL(const GURL& url, | 7150 virtual int GetProxyForURL(const GURL& url, |
7151 ProxyInfo* results, | 7151 ProxyInfo* results, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7186 const std::vector<GURL>& resolved() const { return resolved_; } | 7186 const std::vector<GURL>& resolved() const { return resolved_; } |
7187 | 7187 |
7188 private: | 7188 private: |
7189 std::vector<GURL> resolved_; | 7189 std::vector<GURL> resolved_; |
7190 | 7190 |
7191 DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); | 7191 DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
7192 }; | 7192 }; |
7193 | 7193 |
7194 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { | 7194 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { |
7195 HttpStreamFactory::set_use_alternate_protocols(true); | 7195 HttpStreamFactory::set_use_alternate_protocols(true); |
7196 HttpStreamFactory::set_next_protos(SpdyNextProtos()); | 7196 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
7197 | 7197 |
7198 ProxyConfig proxy_config; | 7198 ProxyConfig proxy_config; |
7199 proxy_config.set_auto_detect(true); | 7199 proxy_config.set_auto_detect(true); |
7200 proxy_config.set_pac_url(GURL("http://fooproxyurl")); | 7200 proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
7201 | 7201 |
7202 CapturingProxyResolver* capturing_proxy_resolver = | 7202 CapturingProxyResolver* capturing_proxy_resolver = |
7203 new CapturingProxyResolver(); | 7203 new CapturingProxyResolver(); |
7204 SessionDependencies session_deps(new ProxyService( | 7204 SessionDependencies session_deps(new ProxyService( |
7205 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, | 7205 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
7206 NULL)); | 7206 NULL)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7292 EXPECT_TRUE(response->was_npn_negotiated); | 7292 EXPECT_TRUE(response->was_npn_negotiated); |
7293 | 7293 |
7294 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 7294 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
7295 EXPECT_EQ("hello!", response_data); | 7295 EXPECT_EQ("hello!", response_data); |
7296 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); | 7296 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); |
7297 EXPECT_EQ("http://www.google.com/", | 7297 EXPECT_EQ("http://www.google.com/", |
7298 capturing_proxy_resolver->resolved()[0].spec()); | 7298 capturing_proxy_resolver->resolved()[0].spec()); |
7299 EXPECT_EQ("https://www.google.com/", | 7299 EXPECT_EQ("https://www.google.com/", |
7300 capturing_proxy_resolver->resolved()[1].spec()); | 7300 capturing_proxy_resolver->resolved()[1].spec()); |
7301 | 7301 |
7302 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 7302 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
7303 HttpStreamFactory::set_use_alternate_protocols(false); | 7303 HttpStreamFactory::set_use_alternate_protocols(false); |
7304 } | 7304 } |
7305 | 7305 |
7306 TEST_F(HttpNetworkTransactionTest, | 7306 TEST_F(HttpNetworkTransactionTest, |
7307 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { | 7307 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
7308 HttpStreamFactory::set_use_alternate_protocols(true); | 7308 HttpStreamFactory::set_use_alternate_protocols(true); |
7309 HttpStreamFactory::set_next_protos(SpdyNextProtos()); | 7309 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
7310 SessionDependencies session_deps; | 7310 SessionDependencies session_deps; |
7311 | 7311 |
7312 HttpRequestInfo request; | 7312 HttpRequestInfo request; |
7313 request.method = "GET"; | 7313 request.method = "GET"; |
7314 request.url = GURL("http://www.google.com/"); | 7314 request.url = GURL("http://www.google.com/"); |
7315 request.load_flags = 0; | 7315 request.load_flags = 0; |
7316 | 7316 |
7317 MockRead data_reads[] = { | 7317 MockRead data_reads[] = { |
7318 MockRead("HTTP/1.1 200 OK\r\n"), | 7318 MockRead("HTTP/1.1 200 OK\r\n"), |
7319 MockRead(kAlternateProtocolHttpHeader), | 7319 MockRead(kAlternateProtocolHttpHeader), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7410 response = trans->GetResponseInfo(); | 7410 response = trans->GetResponseInfo(); |
7411 ASSERT_TRUE(response != NULL); | 7411 ASSERT_TRUE(response != NULL); |
7412 ASSERT_TRUE(response->headers != NULL); | 7412 ASSERT_TRUE(response->headers != NULL); |
7413 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 7413 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
7414 EXPECT_TRUE(response->was_fetched_via_spdy); | 7414 EXPECT_TRUE(response->was_fetched_via_spdy); |
7415 EXPECT_TRUE(response->was_npn_negotiated); | 7415 EXPECT_TRUE(response->was_npn_negotiated); |
7416 | 7416 |
7417 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 7417 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
7418 EXPECT_EQ("hello!", response_data); | 7418 EXPECT_EQ("hello!", response_data); |
7419 | 7419 |
7420 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 7420 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
7421 HttpStreamFactory::set_use_alternate_protocols(false); | 7421 HttpStreamFactory::set_use_alternate_protocols(false); |
7422 } | 7422 } |
7423 | 7423 |
7424 // GenerateAuthToken is a mighty big test. | 7424 // GenerateAuthToken is a mighty big test. |
7425 // It tests all permutation of GenerateAuthToken behavior: | 7425 // It tests all permutation of GenerateAuthToken behavior: |
7426 // - Synchronous and Asynchronous completion. | 7426 // - Synchronous and Asynchronous completion. |
7427 // - OK or error on completion. | 7427 // - OK or error on completion. |
7428 // - Direct connection, non-authenticating proxy, and authenticating proxy. | 7428 // - Direct connection, non-authenticating proxy, and authenticating proxy. |
7429 // - HTTP or HTTPS backend (to include proxy tunneling). | 7429 // - HTTP or HTTPS backend (to include proxy tunneling). |
7430 // - Non-authenticating and authenticating backend. | 7430 // - Non-authenticating and authenticating backend. |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8131 | 8131 |
8132 std::string response_data; | 8132 std::string response_data; |
8133 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8133 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
8134 EXPECT_EQ("ok.", response_data); | 8134 EXPECT_EQ("ok.", response_data); |
8135 } | 8135 } |
8136 | 8136 |
8137 // This tests the case that a request is issued via http instead of spdy after | 8137 // This tests the case that a request is issued via http instead of spdy after |
8138 // npn is negotiated. | 8138 // npn is negotiated. |
8139 TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { | 8139 TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
8140 HttpStreamFactory::set_use_alternate_protocols(true); | 8140 HttpStreamFactory::set_use_alternate_protocols(true); |
8141 HttpStreamFactory::set_next_protos( | 8141 HttpStreamFactory::SetNextProtos( |
8142 MakeNextProtos("http/1.1", "http1.1", NULL)); | 8142 MakeNextProtos("http/1.1", "http1.1", NULL)); |
8143 SessionDependencies session_deps; | 8143 SessionDependencies session_deps; |
8144 HttpRequestInfo request; | 8144 HttpRequestInfo request; |
8145 request.method = "GET"; | 8145 request.method = "GET"; |
8146 request.url = GURL("https://www.google.com/"); | 8146 request.url = GURL("https://www.google.com/"); |
8147 request.load_flags = 0; | 8147 request.load_flags = 0; |
8148 | 8148 |
8149 MockWrite data_writes[] = { | 8149 MockWrite data_writes[] = { |
8150 MockWrite("GET / HTTP/1.1\r\n" | 8150 MockWrite("GET / HTTP/1.1\r\n" |
8151 "Host: www.google.com\r\n" | 8151 "Host: www.google.com\r\n" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8185 ASSERT_TRUE(response->headers != NULL); | 8185 ASSERT_TRUE(response->headers != NULL); |
8186 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8186 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
8187 | 8187 |
8188 std::string response_data; | 8188 std::string response_data; |
8189 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8189 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
8190 EXPECT_EQ("hello world", response_data); | 8190 EXPECT_EQ("hello world", response_data); |
8191 | 8191 |
8192 EXPECT_FALSE(response->was_fetched_via_spdy); | 8192 EXPECT_FALSE(response->was_fetched_via_spdy); |
8193 EXPECT_TRUE(response->was_npn_negotiated); | 8193 EXPECT_TRUE(response->was_npn_negotiated); |
8194 | 8194 |
8195 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 8195 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
8196 HttpStreamFactory::set_use_alternate_protocols(false); | 8196 HttpStreamFactory::set_use_alternate_protocols(false); |
8197 } | 8197 } |
8198 | 8198 |
8199 TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { | 8199 TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
8200 // Simulate the SSL handshake completing with an NPN negotiation | 8200 // Simulate the SSL handshake completing with an NPN negotiation |
8201 // followed by an immediate server closing of the socket. | 8201 // followed by an immediate server closing of the socket. |
8202 // Fix crash: http://crbug.com/46369 | 8202 // Fix crash: http://crbug.com/46369 |
8203 HttpStreamFactory::set_use_alternate_protocols(true); | 8203 HttpStreamFactory::set_use_alternate_protocols(true); |
8204 HttpStreamFactory::set_next_protos(SpdyNextProtos()); | 8204 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
8205 SessionDependencies session_deps; | 8205 SessionDependencies session_deps; |
8206 | 8206 |
8207 HttpRequestInfo request; | 8207 HttpRequestInfo request; |
8208 request.method = "GET"; | 8208 request.method = "GET"; |
8209 request.url = GURL("https://www.google.com/"); | 8209 request.url = GURL("https://www.google.com/"); |
8210 request.load_flags = 0; | 8210 request.load_flags = 0; |
8211 | 8211 |
8212 SSLSocketDataProvider ssl(ASYNC, OK); | 8212 SSLSocketDataProvider ssl(ASYNC, OK); |
8213 ssl.SetNextProto(SSLClientSocket::kProtoSPDY21); | 8213 ssl.SetNextProto(SSLClientSocket::kProtoSPDY21); |
8214 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); | 8214 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
(...skipping 14 matching lines...) Expand all Loading... |
8229 | 8229 |
8230 TestCompletionCallback callback; | 8230 TestCompletionCallback callback; |
8231 | 8231 |
8232 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 8232 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
8233 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); | 8233 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); |
8234 | 8234 |
8235 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 8235 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
8236 EXPECT_EQ(ERR_IO_PENDING, rv); | 8236 EXPECT_EQ(ERR_IO_PENDING, rv); |
8237 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); | 8237 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
8238 | 8238 |
8239 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 8239 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
8240 HttpStreamFactory::set_use_alternate_protocols(false); | 8240 HttpStreamFactory::set_use_alternate_protocols(false); |
8241 } | 8241 } |
8242 | 8242 |
8243 TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { | 8243 TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
8244 // This test ensures that the URL passed into the proxy is upgraded | 8244 // This test ensures that the URL passed into the proxy is upgraded |
8245 // to https when doing an Alternate Protocol upgrade. | 8245 // to https when doing an Alternate Protocol upgrade. |
8246 HttpStreamFactory::set_use_alternate_protocols(true); | 8246 HttpStreamFactory::set_use_alternate_protocols(true); |
8247 HttpStreamFactory::set_next_protos( | 8247 HttpStreamFactory::SetNextProtos( |
8248 MakeNextProtos( | 8248 MakeNextProtos( |
8249 "http/1.1", "http1.1", "spdy/2.1", "spdy/2", "spdy", NULL)); | 8249 "http/1.1", "http1.1", "spdy/2.1", "spdy/2", "spdy", NULL)); |
8250 | 8250 |
8251 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); | 8251 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); |
8252 HttpAuthHandlerMock::Factory* auth_factory = | 8252 HttpAuthHandlerMock::Factory* auth_factory = |
8253 new HttpAuthHandlerMock::Factory(); | 8253 new HttpAuthHandlerMock::Factory(); |
8254 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); | 8254 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); |
8255 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); | 8255 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
8256 auth_factory->set_do_init_from_challenge(true); | 8256 auth_factory->set_do_init_from_challenge(true); |
8257 session_deps.http_auth_handler_factory.reset(auth_factory); | 8257 session_deps.http_auth_handler_factory.reset(auth_factory); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8382 AuthCredentials(kFoo, kBar), callback_3.callback()); | 8382 AuthCredentials(kFoo, kBar), callback_3.callback()); |
8383 EXPECT_EQ(ERR_IO_PENDING, rv); | 8383 EXPECT_EQ(ERR_IO_PENDING, rv); |
8384 EXPECT_EQ(OK, callback_3.WaitForResult()); | 8384 EXPECT_EQ(OK, callback_3.WaitForResult()); |
8385 | 8385 |
8386 // After all that work, these two lines (or actually, just the scheme) are | 8386 // After all that work, these two lines (or actually, just the scheme) are |
8387 // what this test is all about. Make sure it happens correctly. | 8387 // what this test is all about. Make sure it happens correctly. |
8388 const GURL& request_url = auth_handler->request_url(); | 8388 const GURL& request_url = auth_handler->request_url(); |
8389 EXPECT_EQ("https", request_url.scheme()); | 8389 EXPECT_EQ("https", request_url.scheme()); |
8390 EXPECT_EQ("www.google.com", request_url.host()); | 8390 EXPECT_EQ("www.google.com", request_url.host()); |
8391 | 8391 |
8392 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 8392 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
8393 HttpStreamFactory::set_use_alternate_protocols(false); | 8393 HttpStreamFactory::set_use_alternate_protocols(false); |
8394 } | 8394 } |
8395 | 8395 |
8396 // Test that if we cancel the transaction as the connection is completing, that | 8396 // Test that if we cancel the transaction as the connection is completing, that |
8397 // everything tears down correctly. | 8397 // everything tears down correctly. |
8398 TEST_F(HttpNetworkTransactionTest, SimpleCancel) { | 8398 TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
8399 // Setup everything about the connection to complete synchronously, so that | 8399 // Setup everything about the connection to complete synchronously, so that |
8400 // after calling HttpNetworkTransaction::Start, the only thing we're waiting | 8400 // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
8401 // for is the callback from the HttpStreamRequest. | 8401 // for is the callback from the HttpStreamRequest. |
8402 // Then cancel the transaction. | 8402 // Then cancel the transaction. |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9028 // MockClientSocket::GetPeerAddress but that returns 192.0.2.33 whereas | 9028 // MockClientSocket::GetPeerAddress but that returns 192.0.2.33 whereas |
9029 // MockHostResolver returns 127.0.0.1 (MockHostResolverBase::Reset). So we use | 9029 // MockHostResolver returns 127.0.0.1 (MockHostResolverBase::Reset). So we use |
9030 // the first address (127.0.0.1) returned by MockHostResolver as an alias for | 9030 // the first address (127.0.0.1) returned by MockHostResolver as an alias for |
9031 // the |pair|. | 9031 // the |pair|. |
9032 const addrinfo* address = addresses.head(); | 9032 const addrinfo* address = addresses.head(); |
9033 pool_peer->AddAlias(address, pair); | 9033 pool_peer->AddAlias(address, pair); |
9034 } | 9034 } |
9035 | 9035 |
9036 TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { | 9036 TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
9037 HttpStreamFactory::set_use_alternate_protocols(true); | 9037 HttpStreamFactory::set_use_alternate_protocols(true); |
9038 HttpStreamFactory::set_next_protos(SpdyNextProtos()); | 9038 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
9039 | 9039 |
9040 // Set up a special HttpNetworkSession with a MockCachingHostResolver. | 9040 // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
9041 SessionDependencies session_deps; | 9041 SessionDependencies session_deps; |
9042 MockCachingHostResolver host_resolver; | 9042 MockCachingHostResolver host_resolver; |
9043 net::HttpNetworkSession::Params params; | 9043 net::HttpNetworkSession::Params params; |
9044 params.client_socket_factory = &session_deps.socket_factory; | 9044 params.client_socket_factory = &session_deps.socket_factory; |
9045 params.host_resolver = &host_resolver; | 9045 params.host_resolver = &host_resolver; |
9046 params.cert_verifier = session_deps.cert_verifier.get(); | 9046 params.cert_verifier = session_deps.cert_verifier.get(); |
9047 params.proxy_service = session_deps.proxy_service.get(); | 9047 params.proxy_service = session_deps.proxy_service.get(); |
9048 params.ssl_config_service = session_deps.ssl_config_service; | 9048 params.ssl_config_service = session_deps.ssl_config_service; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9135 | 9135 |
9136 response = trans2.GetResponseInfo(); | 9136 response = trans2.GetResponseInfo(); |
9137 ASSERT_TRUE(response != NULL); | 9137 ASSERT_TRUE(response != NULL); |
9138 ASSERT_TRUE(response->headers != NULL); | 9138 ASSERT_TRUE(response->headers != NULL); |
9139 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 9139 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
9140 EXPECT_TRUE(response->was_fetched_via_spdy); | 9140 EXPECT_TRUE(response->was_fetched_via_spdy); |
9141 EXPECT_TRUE(response->was_npn_negotiated); | 9141 EXPECT_TRUE(response->was_npn_negotiated); |
9142 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | 9142 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
9143 EXPECT_EQ("hello!", response_data); | 9143 EXPECT_EQ("hello!", response_data); |
9144 | 9144 |
9145 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 9145 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
9146 HttpStreamFactory::set_use_alternate_protocols(false); | 9146 HttpStreamFactory::set_use_alternate_protocols(false); |
9147 } | 9147 } |
9148 | 9148 |
9149 class OneTimeCachingHostResolver : public net::HostResolver { | 9149 class OneTimeCachingHostResolver : public net::HostResolver { |
9150 public: | 9150 public: |
9151 explicit OneTimeCachingHostResolver(const HostPortPair& host_port) | 9151 explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
9152 : host_port_(host_port) {} | 9152 : host_port_(host_port) {} |
9153 virtual ~OneTimeCachingHostResolver() {} | 9153 virtual ~OneTimeCachingHostResolver() {} |
9154 | 9154 |
9155 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } | 9155 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
(...skipping 26 matching lines...) Expand all Loading... |
9182 } | 9182 } |
9183 | 9183 |
9184 private: | 9184 private: |
9185 MockCachingHostResolver host_resolver_; | 9185 MockCachingHostResolver host_resolver_; |
9186 const HostPortPair host_port_; | 9186 const HostPortPair host_port_; |
9187 }; | 9187 }; |
9188 | 9188 |
9189 TEST_F(HttpNetworkTransactionTest, | 9189 TEST_F(HttpNetworkTransactionTest, |
9190 UseIPConnectionPoolingWithHostCacheExpiration) { | 9190 UseIPConnectionPoolingWithHostCacheExpiration) { |
9191 HttpStreamFactory::set_use_alternate_protocols(true); | 9191 HttpStreamFactory::set_use_alternate_protocols(true); |
9192 HttpStreamFactory::set_next_protos(SpdyNextProtos()); | 9192 HttpStreamFactory::SetNextProtos(SpdyNextProtos()); |
9193 | 9193 |
9194 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. | 9194 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
9195 SessionDependencies session_deps; | 9195 SessionDependencies session_deps; |
9196 OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); | 9196 OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
9197 net::HttpNetworkSession::Params params; | 9197 net::HttpNetworkSession::Params params; |
9198 params.client_socket_factory = &session_deps.socket_factory; | 9198 params.client_socket_factory = &session_deps.socket_factory; |
9199 params.host_resolver = &host_resolver; | 9199 params.host_resolver = &host_resolver; |
9200 params.cert_verifier = session_deps.cert_verifier.get(); | 9200 params.cert_verifier = session_deps.cert_verifier.get(); |
9201 params.proxy_service = session_deps.proxy_service.get(); | 9201 params.proxy_service = session_deps.proxy_service.get(); |
9202 params.ssl_config_service = session_deps.ssl_config_service; | 9202 params.ssl_config_service = session_deps.ssl_config_service; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9288 | 9288 |
9289 response = trans2.GetResponseInfo(); | 9289 response = trans2.GetResponseInfo(); |
9290 ASSERT_TRUE(response != NULL); | 9290 ASSERT_TRUE(response != NULL); |
9291 ASSERT_TRUE(response->headers != NULL); | 9291 ASSERT_TRUE(response->headers != NULL); |
9292 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 9292 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
9293 EXPECT_TRUE(response->was_fetched_via_spdy); | 9293 EXPECT_TRUE(response->was_fetched_via_spdy); |
9294 EXPECT_TRUE(response->was_npn_negotiated); | 9294 EXPECT_TRUE(response->was_npn_negotiated); |
9295 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | 9295 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
9296 EXPECT_EQ("hello!", response_data); | 9296 EXPECT_EQ("hello!", response_data); |
9297 | 9297 |
9298 HttpStreamFactory::set_next_protos(std::vector<std::string>()); | 9298 HttpStreamFactory::SetNextProtos(std::vector<std::string>()); |
9299 HttpStreamFactory::set_use_alternate_protocols(false); | 9299 HttpStreamFactory::set_use_alternate_protocols(false); |
9300 } | 9300 } |
9301 | 9301 |
9302 TEST_F(HttpNetworkTransactionTest, ReadPipelineEvictionFallback) { | 9302 TEST_F(HttpNetworkTransactionTest, ReadPipelineEvictionFallback) { |
9303 MockRead data_reads1[] = { | 9303 MockRead data_reads1[] = { |
9304 MockRead(SYNCHRONOUS, ERR_PIPELINE_EVICTION), | 9304 MockRead(SYNCHRONOUS, ERR_PIPELINE_EVICTION), |
9305 }; | 9305 }; |
9306 MockRead data_reads2[] = { | 9306 MockRead data_reads2[] = { |
9307 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 9307 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
9308 MockRead("hello world"), | 9308 MockRead("hello world"), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9340 StaticSocketDataProvider* data[] = { &data1, &data2 }; | 9340 StaticSocketDataProvider* data[] = { &data1, &data2 }; |
9341 | 9341 |
9342 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); | 9342 SimpleGetHelperResult out = SimpleGetHelperForData(data, arraysize(data)); |
9343 | 9343 |
9344 EXPECT_EQ(OK, out.rv); | 9344 EXPECT_EQ(OK, out.rv); |
9345 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | 9345 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
9346 EXPECT_EQ("hello world", out.response_data); | 9346 EXPECT_EQ("hello world", out.response_data); |
9347 } | 9347 } |
9348 | 9348 |
9349 } // namespace net | 9349 } // namespace net |
OLD | NEW |