http_network_layer_unittest.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_network_layer.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/basictypes.h" 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/stringprintf.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_log.h" 10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "net/cert/mock_cert_verifier.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/dns/mock_host_resolver.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_network_session.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_server_properties_impl.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_transaction_unittest.h" 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "net/http/transport_security_state.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/proxy/proxy_service.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/socket/socket_test_util.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/spdy/spdy_session_pool.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/ssl/ssl_config_service_defaults.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/platform_test.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HttpNetworkLayerTest : public PlatformTest { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpNetworkLayerTest() : ssl_config_service_(new SSLConfigServiceDefaults) {} 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() { 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateDirect()); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ConfigureTestDependencies(ProxyService* proxy_service) { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cert_verifier_.reset(new MockCertVerifier); 377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) transport_security_state_.reset(new TransportSecurityState); 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) proxy_service_.reset(proxy_service); 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpNetworkSession::Params session_params; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) session_params.client_socket_factory = &mock_socket_factory_; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) session_params.host_resolver = &host_resolver_; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) session_params.cert_verifier = cert_verifier_.get(); 437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) session_params.transport_security_state = transport_security_state_.get(); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) session_params.proxy_service = proxy_service_.get(); 45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) session_params.ssl_config_service = ssl_config_service_.get(); 46ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch session_params.http_server_properties = 47ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch http_server_properties_.GetWeakPtr(); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) network_session_ = new HttpNetworkSession(session_params); 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) factory_.reset(new HttpNetworkLayer(network_session_.get())); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(SPDY_PROXY_AUTH_ORIGIN) 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string GetChromeProxy() { 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return HostPortPair::FromURL(GURL(SPDY_PROXY_AUTH_ORIGIN)).ToString(); 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(SPDY_PROXY_AUTH_ORIGIN) && defined(DATA_REDUCTION_FALLBACK_HOST) 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string GetChromeFallbackProxy() { 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString(); 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void ExecuteRequestExpectingContentAndHeader(const std::string& method, 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& content, 668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const std::string& header, 678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const std::string& value) { 688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) TestCompletionCallback callback; 698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) HttpRequestInfo request_info; 718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) request_info.url = GURL("http://www.google.com/"); 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) request_info.method = method; 738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) request_info.load_flags = LOAD_NORMAL; 748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) scoped_ptr<HttpTransaction> trans; 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EXPECT_EQ(OK, rv); 788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); 808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (rv == ERR_IO_PENDING) 818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) rv = callback.WaitForResult(); 828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ASSERT_EQ(OK, rv); 838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) std::string contents; 858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) rv = ReadTransaction(trans.get(), &contents); 868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EXPECT_EQ(OK, rv); 878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EXPECT_EQ(content, contents); 888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (!header.empty()) { 908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // We also have a server header here that isn't set by the proxy. 918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue( 928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) header, value)); 938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Check that |proxy_count| proxies are in the retry list. 971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // These will be, in order, |bad_proxy| and |bad_proxy2|". 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void TestBadProxies(unsigned int proxy_count, const std::string& bad_proxy, 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& bad_proxy2) { 1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const ProxyRetryInfoMap& retry_info = proxy_service_->proxy_retry_info(); 1018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ASSERT_EQ(proxy_count, retry_info.size()); 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (proxy_count > 0) 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASSERT_TRUE(retry_info.find(bad_proxy) != retry_info.end()); 1048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (proxy_count > 1) 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(retry_info.find(bad_proxy2) != retry_info.end()); 1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Simulates a request through a proxy which returns a bypass, which is then 1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // retried through a second proxy that doesn't bypass. 1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Checks that the expected requests were issued, the expected content was 1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // recieved, and the first proxy |bad_proxy| was marked as bad. 1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void TestProxyFallback(const std::string& bad_proxy) { 1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead data_reads[] = { 1148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Chrome-Proxy: bypass=0\r\n\r\n"), 1168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead("Bypass message"), 1178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead(SYNCHRONOUS, OK), 1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackWithMockReads(bad_proxy, "", data_reads, 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) arraysize(data_reads), 1u); 1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void TestProxyFallbackWithMockReads(const std::string& bad_proxy, 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& bad_proxy2, 1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) MockRead data_reads[], 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int data_reads_size, 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) unsigned int expected_retry_info_size) { 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackByMethodWithMockReads(bad_proxy, bad_proxy2, data_reads, 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_reads_size, "GET", "content", 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) true, expected_retry_info_size); 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void TestProxyFallbackByMethodWithMockReads( 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& bad_proxy, 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& bad_proxy2, 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead data_reads[], 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int data_reads_size, 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string method, 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::string content, 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool retry_expected, 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) unsigned int expected_retry_info_size) { 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string trailer = 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (method == "HEAD" || method == "PUT" || method == "POST") ? 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Content-Length: 0\r\n\r\n" : "\r\n"; 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string request = 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::StringPrintf("%s http://www.google.com/ HTTP/1.1\r\n" 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Host: www.google.com\r\n" 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Proxy-Connection: keep-alive\r\n" 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "%s", method.c_str(), trailer.c_str()); 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockWrite data_writes[] = { 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockWrite(request.c_str()), 1538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 1548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StaticSocketDataProvider data1(data_reads, data_reads_size, 1568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) data_writes, arraysize(data_writes)); 1578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data1); 1588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Second data provider returns the expected content. 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead data_reads2[3]; 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) size_t data_reads2_index = 0; 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_reads2[data_reads2_index++] = MockRead("HTTP/1.0 200 OK\r\n" 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Server: not-proxy\r\n\r\n"); 164a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!content.empty()) 165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) data_reads2[data_reads2_index++] = MockRead(content.c_str()); 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_reads2[data_reads2_index++] = MockRead(SYNCHRONOUS, OK); 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockWrite data_writes2[] = { 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockWrite(request.c_str()), 1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StaticSocketDataProvider data2(data_reads2, data_reads2_index, 1728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) data_writes2, arraysize(data_writes2)); 1738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data2); 1748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Expect that we get "content" and not "Bypass message", and that there's 1768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // a "not-proxy" "Server:" header in the final response. 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (retry_expected) { 178a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteRequestExpectingContentAndHeader(method, content, 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "server", "not-proxy"); 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 181a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ExecuteRequestExpectingContentAndHeader(method, content, "", ""); 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // We should also observe the bad proxy in the retry list. 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestBadProxies(expected_retry_info_size, bad_proxy, bad_proxy2); 1868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Simulates a request through a proxy which returns a bypass, which is then 1898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // retried through a direct connection to the origin site. 1908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Checks that the expected requests were issued, the expected content was 1911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // received, and the proxy |bad_proxy| was marked as bad. 1921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void TestProxyFallbackToDirect(const std::string& bad_proxy) { 1938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead data_reads[] = { 1948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Chrome-Proxy: bypass=0\r\n\r\n"), 1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead("Bypass message"), 1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead(SYNCHRONOUS, OK), 1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockWrite data_writes[] = { 2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) "Host: www.google.com\r\n" 2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) "Proxy-Connection: keep-alive\r\n\r\n"), 2038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StaticSocketDataProvider data1(data_reads, arraysize(data_reads), 2058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) data_writes, arraysize(data_writes)); 2068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data1); 2078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Second data provider returns the expected content. 2098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead data_reads2[] = { 2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead("HTTP/1.0 200 OK\r\n" 2118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) "Server: not-proxy\r\n\r\n"), 2128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead("content"), 2138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead(SYNCHRONOUS, OK), 2148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 2158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockWrite data_writes2[] = { 2168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockWrite("GET / HTTP/1.1\r\n" 2178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) "Host: www.google.com\r\n" 2188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) "Connection: keep-alive\r\n\r\n"), 2198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 2208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), 2218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) data_writes2, arraysize(data_writes2)); 2228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data2); 2238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Expect that we get "content" and not "Bypass message", and that there's 2258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // a "not-proxy" "Server:" header in the final response. 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExecuteRequestExpectingContentAndHeader("GET", "content", 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "server", "not-proxy"); 2288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // We should also observe the bad proxy in the retry list. 2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestBadProxies(1u, bad_proxy, ""); 2318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 2328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Simulates a request through a proxy which returns a bypass, under a 2348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // configuration where there is no valid bypass. |proxy_count| proxies 2358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // are expected to be configured. 2368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Checks that the expected requests were issued, the bypass message was the 2378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // final received content, and all proxies were marked as bad. 2381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void TestProxyFallbackFail(unsigned int proxy_count, 2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& bad_proxy, 2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& bad_proxy2) { 2418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead data_reads[] = { 2428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Chrome-Proxy: bypass=0\r\n\r\n"), 2448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead("Bypass message"), 2458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockRead(SYNCHRONOUS, OK), 2468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 2478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockWrite data_writes[] = { 2488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 2498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) "Host: www.google.com\r\n" 2508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) "Proxy-Connection: keep-alive\r\n\r\n"), 2518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 2528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StaticSocketDataProvider data1(data_reads, arraysize(data_reads), 2538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) data_writes, arraysize(data_writes)); 2548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StaticSocketDataProvider data2(data_reads, arraysize(data_reads), 2558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) data_writes, arraysize(data_writes)); 2568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data1); 2588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (proxy_count > 1) 2598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data2); 2608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Expect that we get "Bypass message", and not "content".. 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ExecuteRequestExpectingContentAndHeader("GET", "Bypass message", "", ""); 2638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // We should also observe the bad proxy or proxies in the retry list. 2651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestBadProxies(proxy_count, bad_proxy, bad_proxy2); 2668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 2678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockClientSocketFactory mock_socket_factory_; 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockHostResolver host_resolver_; 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<CertVerifier> cert_verifier_; 2717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) scoped_ptr<TransportSecurityState> transport_security_state_; 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<ProxyService> proxy_service_; 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const scoped_refptr<SSLConfigService> ssl_config_service_; 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<HttpNetworkSession> network_session_; 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<HttpNetworkLayer> factory_; 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpServerPropertiesImpl http_server_properties_; 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<HttpTransaction> trans; 2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(OK, rv); 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(trans.get() != NULL); 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, Suspend) { 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<HttpTransaction> trans; 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(OK, rv); 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) trans.reset(); 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) factory_->OnSuspend(); 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, rv); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(trans == NULL); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) factory_->OnResume(); 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(OK, rv); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, GET) { 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockRead data_reads[] = { 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockRead("HTTP/1.0 200 OK\r\n\r\n"), 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockRead("hello world"), 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockWrite data_writes[] = { 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockWrite("GET / HTTP/1.1\r\n" 314c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Host: www.google.com\r\n" 315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Connection: keep-alive\r\n" 316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "User-Agent: Foo/1.0\r\n\r\n"), 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StaticSocketDataProvider data(data_reads, arraysize(data_reads), 319c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) data_writes, arraysize(data_writes)); 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data); 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestCompletionCallback callback; 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpRequestInfo request_info; 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_info.url = GURL("http://www.google.com/"); 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_info.method = "GET"; 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Foo/1.0"); 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_info.load_flags = LOAD_NORMAL; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<HttpTransaction> trans; 3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(OK, rv); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); 336c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) rv = callback.GetResult(rv); 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(OK, rv); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string contents; 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rv = ReadTransaction(trans.get(), &contents); 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(OK, rv); 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("hello world", contents); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Proxy bypass tests. These tests run through various server-induced 3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// proxy bypass scenarios using both PAC file and fixed proxy params. 3478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// The test scenarios are: 3488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// - bypass with two proxies configured and the first but not the second 3498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// is bypassed. 3508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// - bypass with one proxy configured and an explicit fallback to direct 3518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// connections 3528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// - bypass with two proxies configured and both are bypassed 3538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// - bypass with one proxy configured which is bypassed with no defined 3548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// fallback 3558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(SPDY_PROXY_AUTH_ORIGIN) 3578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerTwoProxyBypassPac) { 3581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 3601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "PROXY " + bad_proxy + "; PROXY good:8080")); 3611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestProxyFallback(bad_proxy); 3628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerTwoProxyBypassFixed) { 3651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 3661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ConfigureTestDependencies( 3671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ProxyService::CreateFixed(bad_proxy +", good:8080")); 3681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestProxyFallback(bad_proxy); 3698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, BypassAndRetryIdempotentMethods) { 3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const struct { 3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string method; 3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string content; 3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool expected_to_retry; 3775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } tests[] = { 3785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "GET", 3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "content", 3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) true, 3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "OPTIONS", 3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "content", 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) true, 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "HEAD", 3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "", 3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) true, 3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "PUT", 3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "", 3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) true, 3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "DELETE", 4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "content", 4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) true, 4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "TRACE", 4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "content", 4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) true, 4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "POST", 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Bypass message", 4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) false, 4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }, 4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConfigureTestDependencies( 4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProxyService::CreateFixed(bad_proxy +", good:8080")); 4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead data_reads[] = { 4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 4205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Chrome-Proxy: bypass=0\r\n\r\n"), 4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("Bypass message"), 4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackByMethodWithMockReads(bad_proxy, "", data_reads, 4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) arraysize(data_reads), 4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) tests[i].method, 4275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) tests[i].content, 4285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) tests[i].expected_to_retry, 1u); 4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerOneProxyWithDirectBypassPac) { 4331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 4348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 4351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "PROXY " + bad_proxy + "; DIRECT")); 4361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestProxyFallbackToDirect(bad_proxy); 4378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerOneProxyWithDirectBypassFixed) { 4401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 4411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ConfigureTestDependencies( 4421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ProxyService::CreateFixed(bad_proxy + ", direct://")); 4431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestProxyFallbackToDirect(bad_proxy); 4448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(DATA_REDUCTION_FALLBACK_HOST) 4478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerTwoProxyDoubleBypassPac) { 4481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 4491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy2 = 4501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString(); 4518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 4521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "PROXY " + bad_proxy + "; PROXY " + bad_proxy2)); 4531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestProxyFallbackFail(2u, bad_proxy, bad_proxy2); 4548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerTwoProxyDoubleBypassFixed) { 4571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 4581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy2 = 4591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString(); 4608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixed( 4611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bad_proxy + ", " + bad_proxy2)); 4621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestProxyFallbackFail(2u, bad_proxy, bad_proxy2); 4638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassPac) { 4671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 4688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 4691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "PROXY " + bad_proxy)); 4701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestProxyFallbackFail(1u, bad_proxy, ""); 4718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassFixed) { 4741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 4751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixed(bad_proxy)); 4761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TestProxyFallbackFail(1u, bad_proxy, ""); 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 479a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerFallbackOn5xxError) { 480a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Verify that "500 Internal Server Error", "502 Bad Gateway", and 481a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // "503 Service Unavailable" via the data reduction proxy induce proxy 482a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // fallback to a second proxy, if configured. 48390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 48490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // To configure this test, we need to wire up a custom proxy service to use 48590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // a pair of proxies. We'll induce fallback via the first and return 48690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // the expected data via the second. 48790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::string data_reduction_proxy( 48890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) HostPortPair::FromURL(GURL(SPDY_PROXY_AUTH_ORIGIN)).ToString()); 48990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::string pac_string = base::StringPrintf( 49090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) "PROXY %s; PROXY good:8080", data_reduction_proxy.data()); 49190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 492a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string headers[] = { 493a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "HTTP/1.1 500 Internal Server Error\r\n\r\n", 494a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "HTTP/1.1 502 Bad Gateway\r\n\r\n", 495a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "HTTP/1.1 503 Service Unavailable\r\n\r\n" 49690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) }; 49790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 498a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (size_t i = 0; i < arraysize(headers); ++i) { 499a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ConfigureTestDependencies( 500a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ProxyService::CreateFixedFromPacResult(pac_string)); 50190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 502a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockRead data_reads[] = { 503a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockRead(headers[i].c_str()), 504a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockRead("Bypass message"), 505a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 506a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }; 50790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 508a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockWrite data_writes[] = { 509a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 510a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "Host: www.google.com\r\n" 511a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "Proxy-Connection: keep-alive\r\n\r\n"), 512a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }; 51390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 514a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) StaticSocketDataProvider data1(data_reads, arraysize(data_reads), 515a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) data_writes, arraysize(data_writes)); 516a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data1); 51790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 518a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Second data provider returns the expected content. 519a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockRead data_reads2[] = { 520a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockRead("HTTP/1.0 200 OK\r\n" 521a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "Server: not-proxy\r\n\r\n"), 522a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockRead("content"), 523a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 524a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }; 525a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockWrite data_writes2[] = { 526a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 527a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "Host: www.google.com\r\n" 528a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "Proxy-Connection: keep-alive\r\n\r\n"), 529a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }; 53090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 531a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), 532a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) data_writes2, arraysize(data_writes2)); 533a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data2); 534a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 535a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) TestCompletionCallback callback; 53690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 537a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) HttpRequestInfo request_info; 538a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) request_info.url = GURL("http://www.google.com/"); 539a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) request_info.method = "GET"; 540a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) request_info.load_flags = LOAD_NORMAL; 541a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 542a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<HttpTransaction> trans; 5435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 544a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(OK, rv); 545a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 546a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); 547a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (rv == ERR_IO_PENDING) 548a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) rv = callback.WaitForResult(); 549a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(OK, rv); 550a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 551a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string contents; 552a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) rv = ReadTransaction(trans.get(), &contents); 553a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(OK, rv); 554a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 555a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // We should obtain content from the second socket provider write 556a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // corresponding to the fallback proxy. 557a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ("content", contents); 558a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // We also have a server header here that isn't set by the proxy. 559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue( 560a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) "server", "not-proxy")); 561a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // We should also observe the data reduction proxy in the retry list. 562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ASSERT_EQ(1u, proxy_service_->proxy_retry_info().size()); 563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(data_reduction_proxy, 564a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) (*proxy_service_->proxy_retry_info().begin()).first); 565a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 56690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 56790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // defined(SPDY_PROXY_AUTH_ORIGIN) 56890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 5698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) { 5705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify that a Chrome-Proxy header is ignored when returned from a directly 5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // connected origin server. 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockRead data_reads[] = { 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 5765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Chrome-Proxy: bypass=0\r\n\r\n"), 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockRead("Bypass message"), 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockWrite data_writes[] = { 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockWrite("GET / HTTP/1.1\r\n" 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Host: www.google.com\r\n" 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "Connection: keep-alive\r\n\r\n"), 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StaticSocketDataProvider data1(data_reads, arraysize(data_reads), 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data_writes, arraysize(data_writes)); 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data1); 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestCompletionCallback callback; 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpRequestInfo request_info; 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_info.url = GURL("http://www.google.com/"); 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_info.method = "GET"; 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_info.load_flags = LOAD_NORMAL; 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<HttpTransaction> trans; 5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(OK, rv); 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (rv == ERR_IO_PENDING) 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rv = callback.WaitForResult(); 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(OK, rv); 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We should have read the original page data. 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string contents; 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rv = ReadTransaction(trans.get(), &contents); 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(OK, rv); 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ("Bypass message", contents); 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We should have no entries in our bad proxy list. 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(0u, proxy_service_->proxy_retry_info().size()); 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(SPDY_PROXY_AUTH_ORIGIN) 6151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerFallbackWithProxyTimedBypass) { 6161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Verify that a Chrome-Proxy: bypass=<seconds> header induces proxy 6171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // fallback to a second proxy, if configured. 6181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 6191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 6201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "PROXY " + bad_proxy + "; PROXY good:8080")); 6211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 6221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) MockRead data_reads[] = { 6231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 6241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "Connection: keep-alive\r\n" 6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Chrome-Proxy: bypass=86400\r\n" 6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"), 6275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("Bypass message"), 6285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 6305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackWithMockReads(bad_proxy, "", data_reads, 6325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) arraysize(data_reads), 1u); 6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(base::TimeDelta::FromSeconds(86400), 6345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (*proxy_service_->proxy_retry_info().begin()).second.current_delay); 6355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerFallbackWithWrongViaHeader) { 6385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify that a Via header that lacks the Chrome-Proxy induces proxy fallback 6395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // to a second proxy, if configured. 6405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string chrome_proxy = GetChromeProxy(); 6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 6425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "PROXY " + chrome_proxy + "; PROXY good:8080")); 6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead data_reads[] = { 6455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 6465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Connection: keep-alive\r\n" 6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Via: 1.0 some-other-proxy\r\n\r\n"), 6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("Bypass message"), 6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads, 6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) arraysize(data_reads), 1u); 6545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerFallbackWithNoViaHeader) { 6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify that the lack of a Via header induces proxy fallback to a second 6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // proxy, if configured. 6595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string chrome_proxy = GetChromeProxy(); 6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 6615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "PROXY " + chrome_proxy + "; PROXY good:8080")); 6625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead data_reads[] = { 6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Connection: keep-alive\r\n\r\n"), 6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("Bypass message"), 6675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 6685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 6695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads, 6715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) arraysize(data_reads), 1u); 6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 674a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) { 675a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Verify that Chrome will not be induced to bypass the Chrome proxy when 676a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // the Chrome Proxy via header is absent on a 304. 677a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::string chrome_proxy = GetChromeProxy(); 678a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 679a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) "PROXY " + chrome_proxy + "; PROXY good:8080")); 680a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 681a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MockRead data_reads[] = { 682a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MockRead("HTTP/1.1 304 Not Modified\r\n" 683a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) "Connection: keep-alive\r\n\r\n"), 684a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 685a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) }; 686a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 687a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(), 688a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) data_reads, arraysize(data_reads), 689a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) "GET", std::string(), false, 0); 690a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 691a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 6925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, NoServerFallbackWithChainedViaHeader) { 6935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify that Chrome will not be induced to bypass the Chrome proxy when 6945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the Chrome Proxy via header is present, even if that header is chained. 6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string chrome_proxy = GetChromeProxy(); 6965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "PROXY " + chrome_proxy + "; PROXY good:8080")); 6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead data_reads[] = { 7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 7015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Connection: keep-alive\r\n" 7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Via: 1.1 Chrome-Compression-Proxy, 1.0 some-other-proxy\r\n\r\n"), 7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("Bypass message"), 7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(), 7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_reads, arraysize(data_reads), 709a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) "GET", "Bypass message", false, 0); 7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, NoServerFallbackWithDeprecatedViaHeader) { 7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify that Chrome will not be induced to bypass the Chrome proxy when 714a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // the deprecated Chrome Proxy via header is present, even if that header is 715a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // chained. 7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string chrome_proxy = GetChromeProxy(); 7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "PROXY " + chrome_proxy + "; PROXY good:8080")); 7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead data_reads[] = { 7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Connection: keep-alive\r\n" 7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Via: 1.1 Chrome Compression Proxy\r\n\r\n"), 7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("Bypass message"), 7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 7265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(), 7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_reads, arraysize(data_reads), 730a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) "GET", "Bypass message", false, 0); 7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(DATA_REDUCTION_FALLBACK_HOST) 7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(HttpNetworkLayerTest, ServerFallbackWithProxyTimedBypassAll) { 7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify that a Chrome-Proxy: block=<seconds> header bypasses a 7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // a configured Chrome-Proxy and fallback and induces proxy fallback to a 7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // third proxy, if configured. 7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string bad_proxy = GetChromeProxy(); 7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string fallback_proxy = GetChromeFallbackProxy(); 7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "PROXY " + bad_proxy + "; PROXY " + fallback_proxy + 7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "; PROXY good:8080")); 7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead data_reads[] = { 7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockRead("HTTP/1.1 200 OK\r\n" 7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Connection: keep-alive\r\n" 7475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Chrome-Proxy: block=86400\r\n" 7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"), 7491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) MockRead("Bypass message"), 7501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) MockRead(SYNCHRONOUS, OK), 7511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }; 7521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestProxyFallbackWithMockReads(bad_proxy, fallback_proxy, data_reads, 7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) arraysize(data_reads), 2u); 7551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(base::TimeDelta::FromSeconds(86400), 7561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) (*proxy_service_->proxy_retry_info().begin()).second.current_delay); 7571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif // defined(DATA_REDUCTION_FALLBACK_HOST) 7591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif // defined(SPDY_PROXY_AUTH_ORIGIN) 7601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 761c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, NetworkVerified) { 762c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockRead data_reads[] = { 763c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockRead("HTTP/1.0 200 OK\r\n\r\n"), 764c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockRead("hello world"), 765c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockRead(SYNCHRONOUS, OK), 766c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }; 767c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockWrite data_writes[] = { 768c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockWrite("GET / HTTP/1.1\r\n" 769c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Host: www.google.com\r\n" 770c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Connection: keep-alive\r\n" 771c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "User-Agent: Foo/1.0\r\n\r\n"), 772c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }; 773c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) StaticSocketDataProvider data(data_reads, arraysize(data_reads), 774c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) data_writes, arraysize(data_writes)); 775c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data); 776c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 777c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TestCompletionCallback callback; 778c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 779c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) HttpRequestInfo request_info; 780c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) request_info.url = GURL("http://www.google.com/"); 781c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) request_info.method = "GET"; 782c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 783c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Foo/1.0"); 784c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) request_info.load_flags = LOAD_NORMAL; 785c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 786c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<HttpTransaction> trans; 7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 788c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(OK, rv); 789c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 790c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); 791c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_EQ(OK, callback.GetResult(rv)); 792c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 793c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(trans->GetResponseInfo()->network_accessed); 794c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 795c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 796c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(HttpNetworkLayerTest, NetworkUnVerified) { 797c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockRead data_reads[] = { 798c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockRead(ASYNC, ERR_CONNECTION_RESET), 799c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }; 800c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockWrite data_writes[] = { 801c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MockWrite("GET / HTTP/1.1\r\n" 802c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Host: www.google.com\r\n" 803c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Connection: keep-alive\r\n" 804c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "User-Agent: Foo/1.0\r\n\r\n"), 805c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }; 806c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) StaticSocketDataProvider data(data_reads, arraysize(data_reads), 807c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) data_writes, arraysize(data_writes)); 808c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) mock_socket_factory_.AddSocketDataProvider(&data); 809c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 810c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TestCompletionCallback callback; 811c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 812c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) HttpRequestInfo request_info; 813c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) request_info.url = GURL("http://www.google.com/"); 814c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) request_info.method = "GET"; 815c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) request_info.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 816c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Foo/1.0"); 817c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) request_info.load_flags = LOAD_NORMAL; 818c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 819c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<HttpTransaction> trans; 8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int rv = factory_->CreateTransaction(DEFAULT_PRIORITY, &trans); 821c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(OK, rv); 822c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 823c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); 824c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv)); 825c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 826c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // If the response info is null, that means that any consumer won't 827c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // see the network accessed bit set. 828c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(NULL, trans->GetResponseInfo()); 829c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 830c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 834