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

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

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

Powered by Google App Engine
This is Rietveld 408576698