OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> | |
9 #include <string> | |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
12 #include "base/file_path.h" | 14 #include "base/file_path.h" |
13 #include "base/file_util.h" | 15 #include "base/file_util.h" |
14 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
15 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
16 #include "base/test/test_file_util.h" | 18 #include "base/test/test_file_util.h" |
17 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 const string16 kFoo3(ASCIIToUTF16("foo3")); | 66 const string16 kFoo3(ASCIIToUTF16("foo3")); |
65 const string16 kFou(ASCIIToUTF16("fou")); | 67 const string16 kFou(ASCIIToUTF16("fou")); |
66 const string16 kSecond(ASCIIToUTF16("second")); | 68 const string16 kSecond(ASCIIToUTF16("second")); |
67 const string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); | 69 const string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
68 const string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); | 70 const string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
69 | 71 |
70 } // namespace | 72 } // namespace |
71 | 73 |
72 namespace net { | 74 namespace net { |
73 | 75 |
76 // MakeNextProtos is a utility function that returns a vector of std::strings | |
77 // from its arguments. Don't forget to terminate the argument list with a NULL. | |
78 static std::vector<std::string> MakeNextProtos(const char* a, ...) { | |
79 std::vector<std::string> ret; | |
80 ret.push_back(a); | |
81 | |
82 va_list args; | |
83 va_start(args, a); | |
84 | |
85 for (;;) { | |
86 const char* value = va_arg(args, const char*); | |
87 if (value == NULL) | |
88 break; | |
89 ret.push_back(value); | |
90 } | |
91 va_end(args); | |
92 | |
93 return ret; | |
94 } | |
95 | |
96 // SpdyNextProtos returns a vector of NPN protocol strings for negotiating | |
97 // SPDY. | |
98 static std::vector<std::string> SpdyNextProtos() { | |
99 return MakeNextProtos("http/1.1", "spdy/2", NULL); | |
100 } | |
wtc
2011/10/11 23:43:04
I suggest moving these two functions into the anon
agl
2011/10/17 17:37:24
Done.
| |
101 | |
74 // Helper to manage the lifetimes of the dependencies for a | 102 // Helper to manage the lifetimes of the dependencies for a |
75 // HttpNetworkTransaction. | 103 // HttpNetworkTransaction. |
76 struct SessionDependencies { | 104 struct SessionDependencies { |
77 // Default set of dependencies -- "null" proxy service. | 105 // Default set of dependencies -- "null" proxy service. |
78 SessionDependencies() | 106 SessionDependencies() |
79 : host_resolver(new MockHostResolver), | 107 : host_resolver(new MockHostResolver), |
80 cert_verifier(new CertVerifier), | 108 cert_verifier(new CertVerifier), |
81 proxy_service(ProxyService::CreateDirect()), | 109 proxy_service(ProxyService::CreateDirect()), |
82 ssl_config_service(new SSLConfigServiceDefaults), | 110 ssl_config_service(new SSLConfigServiceDefaults), |
83 http_auth_handler_factory( | 111 http_auth_handler_factory( |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( | 352 CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
325 HostResolver* host_resolver, | 353 HostResolver* host_resolver, |
326 CertVerifier* cert_verifier) | 354 CertVerifier* cert_verifier) |
327 : SSLClientSocketPool(0, 0, NULL, host_resolver, cert_verifier, NULL, NULL, | 355 : SSLClientSocketPool(0, 0, NULL, host_resolver, cert_verifier, NULL, NULL, |
328 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) {} | 356 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) {} |
329 | 357 |
330 //----------------------------------------------------------------------------- | 358 //----------------------------------------------------------------------------- |
331 | 359 |
332 // This is the expected list of advertised protocols from the browser's NPN | 360 // This is the expected list of advertised protocols from the browser's NPN |
333 // list. | 361 // list. |
334 static const char kExpectedNPNString[] = "\x08http/1.1\x06spdy/2"; | 362 static const char kExpectedNPNString[] = "\x08http/1.1\x06spdy/2"; |
wtc
2011/10/11 23:43:04
kExpectedNPNString can be removed now.
agl
2011/10/17 17:37:24
Done.
| |
335 | 363 |
336 // This is the expected return from a current server advertising SPDY. | 364 // This is the expected return from a current server advertising SPDY. |
337 static const char kAlternateProtocolHttpHeader[] = | 365 static const char kAlternateProtocolHttpHeader[] = |
338 "Alternate-Protocol: 443:npn-spdy/2\r\n\r\n"; | 366 "Alternate-Protocol: 443:npn-spdy/2\r\n\r\n"; |
339 | 367 |
340 // Helper functions for validating that AuthChallengeInfo's are correctly | 368 // Helper functions for validating that AuthChallengeInfo's are correctly |
341 // configured for common cases. | 369 // configured for common cases. |
342 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { | 370 bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
343 if (!auth_challenge) | 371 if (!auth_challenge) |
344 return false; | 372 return false; |
(...skipping 6117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6462 rv = trans->RestartWithAuth(kFirst, kBar, &callback4); | 6490 rv = trans->RestartWithAuth(kFirst, kBar, &callback4); |
6463 EXPECT_EQ(ERR_IO_PENDING, rv); | 6491 EXPECT_EQ(ERR_IO_PENDING, rv); |
6464 rv = callback4.WaitForResult(); | 6492 rv = callback4.WaitForResult(); |
6465 EXPECT_EQ(OK, rv); | 6493 EXPECT_EQ(OK, rv); |
6466 response = trans->GetResponseInfo(); | 6494 response = trans->GetResponseInfo(); |
6467 ASSERT_TRUE(response != NULL); | 6495 ASSERT_TRUE(response != NULL); |
6468 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 6496 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
6469 } | 6497 } |
6470 | 6498 |
6471 TEST_F(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { | 6499 TEST_F(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
6472 HttpStreamFactory::set_next_protos("needs_to_be_set_for_this_test"); | 6500 HttpStreamFactory::set_next_protos(MakeNextProtos("foo", "bar", NULL)); |
6473 HttpStreamFactory::set_use_alternate_protocols(true); | 6501 HttpStreamFactory::set_use_alternate_protocols(true); |
6474 | 6502 |
6475 SessionDependencies session_deps; | 6503 SessionDependencies session_deps; |
6476 | 6504 |
6477 MockRead data_reads[] = { | 6505 MockRead data_reads[] = { |
6478 MockRead("HTTP/1.1 200 OK\r\n"), | 6506 MockRead("HTTP/1.1 200 OK\r\n"), |
6479 MockRead(kAlternateProtocolHttpHeader), | 6507 MockRead(kAlternateProtocolHttpHeader), |
6480 MockRead("hello world"), | 6508 MockRead("hello world"), |
6481 MockRead(false, OK), | 6509 MockRead(false, OK), |
6482 }; | 6510 }; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6519 | 6547 |
6520 ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(http_host_port_pair)); | 6548 ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(http_host_port_pair)); |
6521 const HttpAlternateProtocols::PortProtocolPair alternate = | 6549 const HttpAlternateProtocols::PortProtocolPair alternate = |
6522 alternate_protocols.GetAlternateProtocolFor(http_host_port_pair); | 6550 alternate_protocols.GetAlternateProtocolFor(http_host_port_pair); |
6523 HttpAlternateProtocols::PortProtocolPair expected_alternate; | 6551 HttpAlternateProtocols::PortProtocolPair expected_alternate; |
6524 expected_alternate.port = 443; | 6552 expected_alternate.port = 443; |
6525 expected_alternate.protocol = HttpAlternateProtocols::NPN_SPDY_2; | 6553 expected_alternate.protocol = HttpAlternateProtocols::NPN_SPDY_2; |
6526 EXPECT_TRUE(expected_alternate.Equals(alternate)); | 6554 EXPECT_TRUE(expected_alternate.Equals(alternate)); |
6527 | 6555 |
6528 HttpStreamFactory::set_use_alternate_protocols(false); | 6556 HttpStreamFactory::set_use_alternate_protocols(false); |
6529 HttpStreamFactory::set_next_protos(""); | 6557 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
6530 } | 6558 } |
6531 | 6559 |
6532 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { | 6560 TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
6533 HttpStreamFactory::set_use_alternate_protocols(true); | 6561 HttpStreamFactory::set_use_alternate_protocols(true); |
6534 SessionDependencies session_deps; | 6562 SessionDependencies session_deps; |
6535 | 6563 |
6536 HttpRequestInfo request; | 6564 HttpRequestInfo request; |
6537 request.method = "GET"; | 6565 request.method = "GET"; |
6538 request.url = GURL("http://www.google.com/"); | 6566 request.url = GURL("http://www.google.com/"); |
6539 request.load_flags = 0; | 6567 request.load_flags = 0; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6775 int rv = trans->Start(&unrestricted_port_request, &callback, BoundNetLog()); | 6803 int rv = trans->Start(&unrestricted_port_request, &callback, BoundNetLog()); |
6776 EXPECT_EQ(ERR_IO_PENDING, rv); | 6804 EXPECT_EQ(ERR_IO_PENDING, rv); |
6777 // Valid change to an unrestricted port should pass. | 6805 // Valid change to an unrestricted port should pass. |
6778 EXPECT_EQ(OK, callback.WaitForResult()); | 6806 EXPECT_EQ(OK, callback.WaitForResult()); |
6779 | 6807 |
6780 HttpStreamFactory::set_use_alternate_protocols(false); | 6808 HttpStreamFactory::set_use_alternate_protocols(false); |
6781 } | 6809 } |
6782 | 6810 |
6783 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { | 6811 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
6784 HttpStreamFactory::set_use_alternate_protocols(true); | 6812 HttpStreamFactory::set_use_alternate_protocols(true); |
6785 HttpStreamFactory::set_next_protos(kExpectedNPNString); | 6813 HttpStreamFactory::set_next_protos(SpdyNextProtos()); |
6786 SessionDependencies session_deps; | 6814 SessionDependencies session_deps; |
6787 | 6815 |
6788 HttpRequestInfo request; | 6816 HttpRequestInfo request; |
6789 request.method = "GET"; | 6817 request.method = "GET"; |
6790 request.url = GURL("http://www.google.com/"); | 6818 request.url = GURL("http://www.google.com/"); |
6791 request.load_flags = 0; | 6819 request.load_flags = 0; |
6792 | 6820 |
6793 MockRead data_reads[] = { | 6821 MockRead data_reads[] = { |
6794 MockRead("HTTP/1.1 200 OK\r\n"), | 6822 MockRead("HTTP/1.1 200 OK\r\n"), |
6795 MockRead(kAlternateProtocolHttpHeader), | 6823 MockRead(kAlternateProtocolHttpHeader), |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6860 response = trans->GetResponseInfo(); | 6888 response = trans->GetResponseInfo(); |
6861 ASSERT_TRUE(response != NULL); | 6889 ASSERT_TRUE(response != NULL); |
6862 ASSERT_TRUE(response->headers != NULL); | 6890 ASSERT_TRUE(response->headers != NULL); |
6863 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 6891 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
6864 EXPECT_TRUE(response->was_fetched_via_spdy); | 6892 EXPECT_TRUE(response->was_fetched_via_spdy); |
6865 EXPECT_TRUE(response->was_npn_negotiated); | 6893 EXPECT_TRUE(response->was_npn_negotiated); |
6866 | 6894 |
6867 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 6895 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
6868 EXPECT_EQ("hello!", response_data); | 6896 EXPECT_EQ("hello!", response_data); |
6869 | 6897 |
6870 HttpStreamFactory::set_next_protos(""); | 6898 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
6871 HttpStreamFactory::set_use_alternate_protocols(false); | 6899 HttpStreamFactory::set_use_alternate_protocols(false); |
6872 } | 6900 } |
6873 | 6901 |
6874 TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { | 6902 TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
6875 HttpStreamFactory::set_use_alternate_protocols(true); | 6903 HttpStreamFactory::set_use_alternate_protocols(true); |
6876 HttpStreamFactory::set_next_protos(kExpectedNPNString); | 6904 HttpStreamFactory::set_next_protos(SpdyNextProtos()); |
6877 SessionDependencies session_deps; | 6905 SessionDependencies session_deps; |
6878 | 6906 |
6879 HttpRequestInfo request; | 6907 HttpRequestInfo request; |
6880 request.method = "GET"; | 6908 request.method = "GET"; |
6881 request.url = GURL("http://www.google.com/"); | 6909 request.url = GURL("http://www.google.com/"); |
6882 request.load_flags = 0; | 6910 request.load_flags = 0; |
6883 | 6911 |
6884 MockRead data_reads[] = { | 6912 MockRead data_reads[] = { |
6885 MockRead("HTTP/1.1 200 OK\r\n"), | 6913 MockRead("HTTP/1.1 200 OK\r\n"), |
6886 MockRead(kAlternateProtocolHttpHeader), | 6914 MockRead(kAlternateProtocolHttpHeader), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6978 | 7006 |
6979 response = trans3.GetResponseInfo(); | 7007 response = trans3.GetResponseInfo(); |
6980 ASSERT_TRUE(response != NULL); | 7008 ASSERT_TRUE(response != NULL); |
6981 ASSERT_TRUE(response->headers != NULL); | 7009 ASSERT_TRUE(response->headers != NULL); |
6982 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 7010 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
6983 EXPECT_TRUE(response->was_fetched_via_spdy); | 7011 EXPECT_TRUE(response->was_fetched_via_spdy); |
6984 EXPECT_TRUE(response->was_npn_negotiated); | 7012 EXPECT_TRUE(response->was_npn_negotiated); |
6985 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); | 7013 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
6986 EXPECT_EQ("hello!", response_data); | 7014 EXPECT_EQ("hello!", response_data); |
6987 | 7015 |
6988 HttpStreamFactory::set_next_protos(""); | 7016 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
6989 HttpStreamFactory::set_use_alternate_protocols(false); | 7017 HttpStreamFactory::set_use_alternate_protocols(false); |
6990 } | 7018 } |
6991 | 7019 |
6992 TEST_F(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { | 7020 TEST_F(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
6993 HttpStreamFactory::set_use_alternate_protocols(true); | 7021 HttpStreamFactory::set_use_alternate_protocols(true); |
6994 HttpStreamFactory::set_next_protos(kExpectedNPNString); | 7022 HttpStreamFactory::set_next_protos(SpdyNextProtos()); |
6995 SessionDependencies session_deps; | 7023 SessionDependencies session_deps; |
6996 | 7024 |
6997 HttpRequestInfo request; | 7025 HttpRequestInfo request; |
6998 request.method = "GET"; | 7026 request.method = "GET"; |
6999 request.url = GURL("http://www.google.com/"); | 7027 request.url = GURL("http://www.google.com/"); |
7000 request.load_flags = 0; | 7028 request.load_flags = 0; |
7001 | 7029 |
7002 MockRead data_reads[] = { | 7030 MockRead data_reads[] = { |
7003 MockRead("HTTP/1.1 200 OK\r\n"), | 7031 MockRead("HTTP/1.1 200 OK\r\n"), |
7004 MockRead(kAlternateProtocolHttpHeader), | 7032 MockRead(kAlternateProtocolHttpHeader), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7054 response = trans->GetResponseInfo(); | 7082 response = trans->GetResponseInfo(); |
7055 ASSERT_TRUE(response != NULL); | 7083 ASSERT_TRUE(response != NULL); |
7056 ASSERT_TRUE(response->headers != NULL); | 7084 ASSERT_TRUE(response->headers != NULL); |
7057 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 7085 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
7058 EXPECT_FALSE(response->was_fetched_via_spdy); | 7086 EXPECT_FALSE(response->was_fetched_via_spdy); |
7059 EXPECT_FALSE(response->was_npn_negotiated); | 7087 EXPECT_FALSE(response->was_npn_negotiated); |
7060 | 7088 |
7061 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 7089 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
7062 EXPECT_EQ("hello world", response_data); | 7090 EXPECT_EQ("hello world", response_data); |
7063 | 7091 |
7064 HttpStreamFactory::set_next_protos(""); | 7092 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
7065 HttpStreamFactory::set_use_alternate_protocols(false); | 7093 HttpStreamFactory::set_use_alternate_protocols(false); |
7066 } | 7094 } |
7067 | 7095 |
7068 class CapturingProxyResolver : public ProxyResolver { | 7096 class CapturingProxyResolver : public ProxyResolver { |
7069 public: | 7097 public: |
7070 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} | 7098 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} |
7071 virtual ~CapturingProxyResolver() {} | 7099 virtual ~CapturingProxyResolver() {} |
7072 | 7100 |
7073 virtual int GetProxyForURL(const GURL& url, | 7101 virtual int GetProxyForURL(const GURL& url, |
7074 ProxyInfo* results, | 7102 ProxyInfo* results, |
(...skipping 23 matching lines...) Expand all Loading... | |
7098 const std::vector<GURL>& resolved() const { return resolved_; } | 7126 const std::vector<GURL>& resolved() const { return resolved_; } |
7099 | 7127 |
7100 private: | 7128 private: |
7101 std::vector<GURL> resolved_; | 7129 std::vector<GURL> resolved_; |
7102 | 7130 |
7103 DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); | 7131 DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
7104 }; | 7132 }; |
7105 | 7133 |
7106 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { | 7134 TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { |
7107 HttpStreamFactory::set_use_alternate_protocols(true); | 7135 HttpStreamFactory::set_use_alternate_protocols(true); |
7108 HttpStreamFactory::set_next_protos(kExpectedNPNString); | 7136 HttpStreamFactory::set_next_protos(SpdyNextProtos()); |
7109 | 7137 |
7110 ProxyConfig proxy_config; | 7138 ProxyConfig proxy_config; |
7111 proxy_config.set_auto_detect(true); | 7139 proxy_config.set_auto_detect(true); |
7112 proxy_config.set_pac_url(GURL("http://fooproxyurl")); | 7140 proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
7113 | 7141 |
7114 CapturingProxyResolver* capturing_proxy_resolver = | 7142 CapturingProxyResolver* capturing_proxy_resolver = |
7115 new CapturingProxyResolver(); | 7143 new CapturingProxyResolver(); |
7116 SessionDependencies session_deps(new ProxyService( | 7144 SessionDependencies session_deps(new ProxyService( |
7117 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, | 7145 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
7118 NULL)); | 7146 NULL)); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7206 EXPECT_TRUE(response->was_npn_negotiated); | 7234 EXPECT_TRUE(response->was_npn_negotiated); |
7207 | 7235 |
7208 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 7236 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
7209 EXPECT_EQ("hello!", response_data); | 7237 EXPECT_EQ("hello!", response_data); |
7210 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); | 7238 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size()); |
7211 EXPECT_EQ("http://www.google.com/", | 7239 EXPECT_EQ("http://www.google.com/", |
7212 capturing_proxy_resolver->resolved()[0].spec()); | 7240 capturing_proxy_resolver->resolved()[0].spec()); |
7213 EXPECT_EQ("https://www.google.com/", | 7241 EXPECT_EQ("https://www.google.com/", |
7214 capturing_proxy_resolver->resolved()[1].spec()); | 7242 capturing_proxy_resolver->resolved()[1].spec()); |
7215 | 7243 |
7216 HttpStreamFactory::set_next_protos(""); | 7244 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
7217 HttpStreamFactory::set_use_alternate_protocols(false); | 7245 HttpStreamFactory::set_use_alternate_protocols(false); |
7218 } | 7246 } |
7219 | 7247 |
7220 TEST_F(HttpNetworkTransactionTest, | 7248 TEST_F(HttpNetworkTransactionTest, |
7221 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { | 7249 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
7222 HttpStreamFactory::set_use_alternate_protocols(true); | 7250 HttpStreamFactory::set_use_alternate_protocols(true); |
7223 HttpStreamFactory::set_next_protos(kExpectedNPNString); | 7251 HttpStreamFactory::set_next_protos(SpdyNextProtos()); |
7224 SessionDependencies session_deps; | 7252 SessionDependencies session_deps; |
7225 | 7253 |
7226 HttpRequestInfo request; | 7254 HttpRequestInfo request; |
7227 request.method = "GET"; | 7255 request.method = "GET"; |
7228 request.url = GURL("http://www.google.com/"); | 7256 request.url = GURL("http://www.google.com/"); |
7229 request.load_flags = 0; | 7257 request.load_flags = 0; |
7230 | 7258 |
7231 MockRead data_reads[] = { | 7259 MockRead data_reads[] = { |
7232 MockRead("HTTP/1.1 200 OK\r\n"), | 7260 MockRead("HTTP/1.1 200 OK\r\n"), |
7233 MockRead(kAlternateProtocolHttpHeader), | 7261 MockRead(kAlternateProtocolHttpHeader), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7325 response = trans->GetResponseInfo(); | 7353 response = trans->GetResponseInfo(); |
7326 ASSERT_TRUE(response != NULL); | 7354 ASSERT_TRUE(response != NULL); |
7327 ASSERT_TRUE(response->headers != NULL); | 7355 ASSERT_TRUE(response->headers != NULL); |
7328 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 7356 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
7329 EXPECT_TRUE(response->was_fetched_via_spdy); | 7357 EXPECT_TRUE(response->was_fetched_via_spdy); |
7330 EXPECT_TRUE(response->was_npn_negotiated); | 7358 EXPECT_TRUE(response->was_npn_negotiated); |
7331 | 7359 |
7332 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 7360 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
7333 EXPECT_EQ("hello!", response_data); | 7361 EXPECT_EQ("hello!", response_data); |
7334 | 7362 |
7335 HttpStreamFactory::set_next_protos(""); | 7363 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
7336 HttpStreamFactory::set_use_alternate_protocols(false); | 7364 HttpStreamFactory::set_use_alternate_protocols(false); |
7337 } | 7365 } |
7338 | 7366 |
7339 // GenerateAuthToken is a mighty big test. | 7367 // GenerateAuthToken is a mighty big test. |
7340 // It tests all permutation of GenerateAuthToken behavior: | 7368 // It tests all permutation of GenerateAuthToken behavior: |
7341 // - Synchronous and Asynchronous completion. | 7369 // - Synchronous and Asynchronous completion. |
7342 // - OK or error on completion. | 7370 // - OK or error on completion. |
7343 // - Direct connection, non-authenticating proxy, and authenticating proxy. | 7371 // - Direct connection, non-authenticating proxy, and authenticating proxy. |
7344 // - HTTP or HTTPS backend (to include proxy tunneling). | 7372 // - HTTP or HTTPS backend (to include proxy tunneling). |
7345 // - Non-authenticating and authenticating backend. | 7373 // - Non-authenticating and authenticating backend. |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8041 | 8069 |
8042 std::string response_data; | 8070 std::string response_data; |
8043 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8071 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
8044 EXPECT_EQ("ok.", response_data); | 8072 EXPECT_EQ("ok.", response_data); |
8045 } | 8073 } |
8046 | 8074 |
8047 // This tests the case that a request is issued via http instead of spdy after | 8075 // This tests the case that a request is issued via http instead of spdy after |
8048 // npn is negotiated. | 8076 // npn is negotiated. |
8049 TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { | 8077 TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
8050 HttpStreamFactory::set_use_alternate_protocols(true); | 8078 HttpStreamFactory::set_use_alternate_protocols(true); |
8051 HttpStreamFactory::set_next_protos("\x08http/1.1\x07http1.1"); | 8079 HttpStreamFactory::set_next_protos( |
8080 MakeNextProtos("http/1.1", "http1.1", NULL)); | |
8052 SessionDependencies session_deps; | 8081 SessionDependencies session_deps; |
8053 HttpRequestInfo request; | 8082 HttpRequestInfo request; |
8054 request.method = "GET"; | 8083 request.method = "GET"; |
8055 request.url = GURL("https://www.google.com/"); | 8084 request.url = GURL("https://www.google.com/"); |
8056 request.load_flags = 0; | 8085 request.load_flags = 0; |
8057 | 8086 |
8058 MockWrite data_writes[] = { | 8087 MockWrite data_writes[] = { |
8059 MockWrite("GET / HTTP/1.1\r\n" | 8088 MockWrite("GET / HTTP/1.1\r\n" |
8060 "Host: www.google.com\r\n" | 8089 "Host: www.google.com\r\n" |
8061 "Connection: keep-alive\r\n\r\n"), | 8090 "Connection: keep-alive\r\n\r\n"), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8093 ASSERT_TRUE(response->headers != NULL); | 8122 ASSERT_TRUE(response->headers != NULL); |
8094 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8123 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
8095 | 8124 |
8096 std::string response_data; | 8125 std::string response_data; |
8097 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8126 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
8098 EXPECT_EQ("hello world", response_data); | 8127 EXPECT_EQ("hello world", response_data); |
8099 | 8128 |
8100 EXPECT_FALSE(response->was_fetched_via_spdy); | 8129 EXPECT_FALSE(response->was_fetched_via_spdy); |
8101 EXPECT_TRUE(response->was_npn_negotiated); | 8130 EXPECT_TRUE(response->was_npn_negotiated); |
8102 | 8131 |
8103 HttpStreamFactory::set_next_protos(""); | 8132 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
8104 HttpStreamFactory::set_use_alternate_protocols(false); | 8133 HttpStreamFactory::set_use_alternate_protocols(false); |
8105 } | 8134 } |
8106 | 8135 |
8107 TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { | 8136 TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
8108 // Simulate the SSL handshake completing with an NPN negotiation | 8137 // Simulate the SSL handshake completing with an NPN negotiation |
8109 // followed by an immediate server closing of the socket. | 8138 // followed by an immediate server closing of the socket. |
8110 // Fix crash: http://crbug.com/46369 | 8139 // Fix crash: http://crbug.com/46369 |
8111 HttpStreamFactory::set_use_alternate_protocols(true); | 8140 HttpStreamFactory::set_use_alternate_protocols(true); |
8112 HttpStreamFactory::set_next_protos(kExpectedNPNString); | 8141 HttpStreamFactory::set_next_protos(SpdyNextProtos()); |
8113 SessionDependencies session_deps; | 8142 SessionDependencies session_deps; |
8114 | 8143 |
8115 HttpRequestInfo request; | 8144 HttpRequestInfo request; |
8116 request.method = "GET"; | 8145 request.method = "GET"; |
8117 request.url = GURL("https://www.google.com/"); | 8146 request.url = GURL("https://www.google.com/"); |
8118 request.load_flags = 0; | 8147 request.load_flags = 0; |
8119 | 8148 |
8120 SSLSocketDataProvider ssl(true, OK); | 8149 SSLSocketDataProvider ssl(true, OK); |
8121 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; | 8150 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
8122 ssl.next_proto = "spdy/2"; | 8151 ssl.next_proto = "spdy/2"; |
(...skipping 16 matching lines...) Expand all Loading... | |
8139 | 8168 |
8140 TestOldCompletionCallback callback; | 8169 TestOldCompletionCallback callback; |
8141 | 8170 |
8142 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 8171 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
8143 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); | 8172 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); |
8144 | 8173 |
8145 int rv = trans->Start(&request, &callback, BoundNetLog()); | 8174 int rv = trans->Start(&request, &callback, BoundNetLog()); |
8146 EXPECT_EQ(ERR_IO_PENDING, rv); | 8175 EXPECT_EQ(ERR_IO_PENDING, rv); |
8147 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); | 8176 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
8148 | 8177 |
8149 HttpStreamFactory::set_next_protos(""); | 8178 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
8150 HttpStreamFactory::set_use_alternate_protocols(false); | 8179 HttpStreamFactory::set_use_alternate_protocols(false); |
8151 } | 8180 } |
8152 | 8181 |
8153 TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { | 8182 TEST_F(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
8154 // This test ensures that the URL passed into the proxy is upgraded | 8183 // This test ensures that the URL passed into the proxy is upgraded |
8155 // to https when doing an Alternate Protocol upgrade. | 8184 // to https when doing an Alternate Protocol upgrade. |
8156 HttpStreamFactory::set_use_alternate_protocols(true); | 8185 HttpStreamFactory::set_use_alternate_protocols(true); |
8157 HttpStreamFactory::set_next_protos( | 8186 HttpStreamFactory::set_next_protos( |
8158 "\x08http/1.1\x07http1.1\x06spdy/2\x04spdy"); | 8187 MakeNextProtos("http/1.1", "http1.1", "spdy/2", "spdy", NULL)); |
8159 | 8188 |
8160 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); | 8189 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); |
8161 HttpAuthHandlerMock::Factory* auth_factory = | 8190 HttpAuthHandlerMock::Factory* auth_factory = |
8162 new HttpAuthHandlerMock::Factory(); | 8191 new HttpAuthHandlerMock::Factory(); |
8163 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); | 8192 HttpAuthHandlerMock* auth_handler = new HttpAuthHandlerMock(); |
8164 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); | 8193 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
8165 auth_factory->set_do_init_from_challenge(true); | 8194 auth_factory->set_do_init_from_challenge(true); |
8166 session_deps.http_auth_handler_factory.reset(auth_factory); | 8195 session_deps.http_auth_handler_factory.reset(auth_factory); |
8167 | 8196 |
8168 HttpRequestInfo request; | 8197 HttpRequestInfo request; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8289 rv = trans_2->RestartWithAuth(kFoo, kBar, &callback_3); | 8318 rv = trans_2->RestartWithAuth(kFoo, kBar, &callback_3); |
8290 EXPECT_EQ(ERR_IO_PENDING, rv); | 8319 EXPECT_EQ(ERR_IO_PENDING, rv); |
8291 EXPECT_EQ(OK, callback_3.WaitForResult()); | 8320 EXPECT_EQ(OK, callback_3.WaitForResult()); |
8292 | 8321 |
8293 // After all that work, these two lines (or actually, just the scheme) are | 8322 // After all that work, these two lines (or actually, just the scheme) are |
8294 // what this test is all about. Make sure it happens correctly. | 8323 // what this test is all about. Make sure it happens correctly. |
8295 const GURL& request_url = auth_handler->request_url(); | 8324 const GURL& request_url = auth_handler->request_url(); |
8296 EXPECT_EQ("https", request_url.scheme()); | 8325 EXPECT_EQ("https", request_url.scheme()); |
8297 EXPECT_EQ("www.google.com", request_url.host()); | 8326 EXPECT_EQ("www.google.com", request_url.host()); |
8298 | 8327 |
8299 HttpStreamFactory::set_next_protos(""); | 8328 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
8300 HttpStreamFactory::set_use_alternate_protocols(false); | 8329 HttpStreamFactory::set_use_alternate_protocols(false); |
8301 } | 8330 } |
8302 | 8331 |
8303 // Test that if we cancel the transaction as the connection is completing, that | 8332 // Test that if we cancel the transaction as the connection is completing, that |
8304 // everything tears down correctly. | 8333 // everything tears down correctly. |
8305 TEST_F(HttpNetworkTransactionTest, SimpleCancel) { | 8334 TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
8306 // Setup everything about the connection to complete synchronously, so that | 8335 // Setup everything about the connection to complete synchronously, so that |
8307 // after calling HttpNetworkTransaction::Start, the only thing we're waiting | 8336 // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
8308 // for is the callback from the HttpStreamRequest. | 8337 // for is the callback from the HttpStreamRequest. |
8309 // Then cancel the transaction. | 8338 // Then cancel the transaction. |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8940 // MockClientSocket::GetPeerAddress but that returns 192.0.2.33 whereas | 8969 // MockClientSocket::GetPeerAddress but that returns 192.0.2.33 whereas |
8941 // MockHostResolver returns 127.0.0.1 (MockHostResolverBase::Reset). So we use | 8970 // MockHostResolver returns 127.0.0.1 (MockHostResolverBase::Reset). So we use |
8942 // the first address (127.0.0.1) returned by MockHostResolver as an alias for | 8971 // the first address (127.0.0.1) returned by MockHostResolver as an alias for |
8943 // the |pair|. | 8972 // the |pair|. |
8944 const addrinfo* address = addresses.head(); | 8973 const addrinfo* address = addresses.head(); |
8945 pool_peer->AddAlias(address, pair); | 8974 pool_peer->AddAlias(address, pair); |
8946 } | 8975 } |
8947 | 8976 |
8948 TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { | 8977 TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
8949 HttpStreamFactory::set_use_alternate_protocols(true); | 8978 HttpStreamFactory::set_use_alternate_protocols(true); |
8950 HttpStreamFactory::set_next_protos(kExpectedNPNString); | 8979 HttpStreamFactory::set_next_protos(SpdyNextProtos()); |
8951 | 8980 |
8952 // Set up a special HttpNetworkSession with a MockCachingHostResolver. | 8981 // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
8953 SessionDependencies session_deps; | 8982 SessionDependencies session_deps; |
8954 MockCachingHostResolver host_resolver; | 8983 MockCachingHostResolver host_resolver; |
8955 net::HttpNetworkSession::Params params; | 8984 net::HttpNetworkSession::Params params; |
8956 params.client_socket_factory = &session_deps.socket_factory; | 8985 params.client_socket_factory = &session_deps.socket_factory; |
8957 params.host_resolver = &host_resolver; | 8986 params.host_resolver = &host_resolver; |
8958 params.cert_verifier = session_deps.cert_verifier.get(); | 8987 params.cert_verifier = session_deps.cert_verifier.get(); |
8959 params.proxy_service = session_deps.proxy_service.get(); | 8988 params.proxy_service = session_deps.proxy_service.get(); |
8960 params.ssl_config_service = session_deps.ssl_config_service; | 8989 params.ssl_config_service = session_deps.ssl_config_service; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9045 | 9074 |
9046 response = trans2.GetResponseInfo(); | 9075 response = trans2.GetResponseInfo(); |
9047 ASSERT_TRUE(response != NULL); | 9076 ASSERT_TRUE(response != NULL); |
9048 ASSERT_TRUE(response->headers != NULL); | 9077 ASSERT_TRUE(response->headers != NULL); |
9049 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 9078 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
9050 EXPECT_TRUE(response->was_fetched_via_spdy); | 9079 EXPECT_TRUE(response->was_fetched_via_spdy); |
9051 EXPECT_TRUE(response->was_npn_negotiated); | 9080 EXPECT_TRUE(response->was_npn_negotiated); |
9052 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | 9081 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
9053 EXPECT_EQ("hello!", response_data); | 9082 EXPECT_EQ("hello!", response_data); |
9054 | 9083 |
9055 HttpStreamFactory::set_next_protos(""); | 9084 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
9056 HttpStreamFactory::set_use_alternate_protocols(false); | 9085 HttpStreamFactory::set_use_alternate_protocols(false); |
9057 } | 9086 } |
9058 | 9087 |
9059 class OneTimeCachingHostResolver : public net::HostResolver { | 9088 class OneTimeCachingHostResolver : public net::HostResolver { |
9060 public: | 9089 public: |
9061 explicit OneTimeCachingHostResolver(const HostPortPair& host_port) | 9090 explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
9062 : host_port_(host_port) {} | 9091 : host_port_(host_port) {} |
9063 virtual ~OneTimeCachingHostResolver() {} | 9092 virtual ~OneTimeCachingHostResolver() {} |
9064 | 9093 |
9065 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } | 9094 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9100 } | 9129 } |
9101 | 9130 |
9102 private: | 9131 private: |
9103 MockCachingHostResolver host_resolver_; | 9132 MockCachingHostResolver host_resolver_; |
9104 const HostPortPair host_port_; | 9133 const HostPortPair host_port_; |
9105 }; | 9134 }; |
9106 | 9135 |
9107 TEST_F(HttpNetworkTransactionTest, | 9136 TEST_F(HttpNetworkTransactionTest, |
9108 UseIPConnectionPoolingWithHostCacheExpiration) { | 9137 UseIPConnectionPoolingWithHostCacheExpiration) { |
9109 HttpStreamFactory::set_use_alternate_protocols(true); | 9138 HttpStreamFactory::set_use_alternate_protocols(true); |
9110 HttpStreamFactory::set_next_protos(kExpectedNPNString); | 9139 HttpStreamFactory::set_next_protos(SpdyNextProtos()); |
9111 | 9140 |
9112 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. | 9141 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
9113 SessionDependencies session_deps; | 9142 SessionDependencies session_deps; |
9114 OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); | 9143 OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
9115 net::HttpNetworkSession::Params params; | 9144 net::HttpNetworkSession::Params params; |
9116 params.client_socket_factory = &session_deps.socket_factory; | 9145 params.client_socket_factory = &session_deps.socket_factory; |
9117 params.host_resolver = &host_resolver; | 9146 params.host_resolver = &host_resolver; |
9118 params.cert_verifier = session_deps.cert_verifier.get(); | 9147 params.cert_verifier = session_deps.cert_verifier.get(); |
9119 params.proxy_service = session_deps.proxy_service.get(); | 9148 params.proxy_service = session_deps.proxy_service.get(); |
9120 params.ssl_config_service = session_deps.ssl_config_service; | 9149 params.ssl_config_service = session_deps.ssl_config_service; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9204 | 9233 |
9205 response = trans2.GetResponseInfo(); | 9234 response = trans2.GetResponseInfo(); |
9206 ASSERT_TRUE(response != NULL); | 9235 ASSERT_TRUE(response != NULL); |
9207 ASSERT_TRUE(response->headers != NULL); | 9236 ASSERT_TRUE(response->headers != NULL); |
9208 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 9237 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
9209 EXPECT_TRUE(response->was_fetched_via_spdy); | 9238 EXPECT_TRUE(response->was_fetched_via_spdy); |
9210 EXPECT_TRUE(response->was_npn_negotiated); | 9239 EXPECT_TRUE(response->was_npn_negotiated); |
9211 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); | 9240 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
9212 EXPECT_EQ("hello!", response_data); | 9241 EXPECT_EQ("hello!", response_data); |
9213 | 9242 |
9214 HttpStreamFactory::set_next_protos(""); | 9243 HttpStreamFactory::set_next_protos(std::vector<std::string>()); |
9215 HttpStreamFactory::set_use_alternate_protocols(false); | 9244 HttpStreamFactory::set_use_alternate_protocols(false); |
9216 } | 9245 } |
9217 | 9246 |
9218 } // namespace net | 9247 } // namespace net |
OLD | NEW |