Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698