| Index: net/proxy/proxy_service_unittest.cc
|
| diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
|
| index a2dcf3fd8101a18985741d9af990ea4b26ac4877..2c09c6523f5a6474b1061ef8eed58c9f049e6d17 100644
|
| --- a/net/proxy/proxy_service_unittest.cc
|
| +++ b/net/proxy/proxy_service_unittest.cc
|
| @@ -155,6 +155,32 @@ class MockProxyConfigService: public ProxyConfigService {
|
| ObserverList<Observer, true> observers_;
|
| };
|
|
|
| +// A test network delegate that exercises NotifyProxyFallback.
|
| +class TestNotifyProxyFallbackNetworkDelegate : public NetworkDelegate {
|
| + public:
|
| + TestNotifyProxyFallbackNetworkDelegate()
|
| + : net_error_(0) {
|
| + }
|
| +
|
| + virtual void NotifyProxyFallback(const ProxyServer& bad_proxy,
|
| + int net_error) OVERRIDE {
|
| + bad_proxy_ = bad_proxy;
|
| + net_error_ = net_error;
|
| + }
|
| +
|
| + ProxyServer& bad_proxy() {
|
| + return bad_proxy_;
|
| + }
|
| +
|
| + int net_error() {
|
| + return net_error_;
|
| + }
|
| +
|
| + private:
|
| + ProxyServer bad_proxy_;
|
| + int net_error_;
|
| +};
|
| +
|
| // A test network delegate that exercises the OnResolveProxy callback.
|
| class TestResolveProxyNetworkDelegate : public NetworkDelegate {
|
| public:
|
| @@ -193,48 +219,6 @@ class TestResolveProxyNetworkDelegate : public NetworkDelegate {
|
| bool remove_proxy_;
|
| };
|
|
|
| -// A test network delegate that exercises the OnProxyFallback callback.
|
| -class TestProxyFallbackNetworkDelegate : public NetworkDelegate {
|
| - public:
|
| - TestProxyFallbackNetworkDelegate()
|
| - : on_proxy_fallback_called_(false),
|
| - proxy_fallback_net_error_(0),
|
| - proxy_did_fallback_(false) {
|
| - }
|
| -
|
| - virtual void OnProxyFallback(
|
| - const ProxyServer& proxy_server,
|
| - int net_error,
|
| - bool did_fallback) OVERRIDE {
|
| - proxy_server_ = proxy_server;
|
| - proxy_fallback_net_error_ = net_error;
|
| - proxy_did_fallback_ = did_fallback;
|
| - on_proxy_fallback_called_ = true;
|
| - }
|
| -
|
| - bool on_proxy_fallback_called() const {
|
| - return on_proxy_fallback_called_;
|
| - }
|
| -
|
| - const ProxyServer& proxy_server() const {
|
| - return proxy_server_;
|
| - }
|
| -
|
| - int proxy_fallback_net_error() const {
|
| - return proxy_fallback_net_error_;
|
| - }
|
| -
|
| - bool proxy_did_fallback() const {
|
| - return proxy_did_fallback_;
|
| - }
|
| -
|
| - private:
|
| - bool on_proxy_fallback_called_;
|
| - ProxyServer proxy_server_;
|
| - int proxy_fallback_net_error_;
|
| - bool proxy_did_fallback_;
|
| -};
|
| -
|
| } // namespace
|
|
|
| TEST_F(ProxyServiceTest, Direct) {
|
| @@ -504,7 +488,7 @@ TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) {
|
| // Now, imagine that connecting to foopy:8080 fails: there is nothing
|
| // left to fallback to, since our proxy list was NOT terminated by
|
| // DIRECT.
|
| - TestProxyFallbackNetworkDelegate network_delegate;
|
| + NetworkDelegate network_delegate;
|
| TestCompletionCallback callback2;
|
| ProxyServer expected_proxy_server = info.proxy_server();
|
| rv = service.ReconsiderProxyAfterError(
|
| @@ -513,11 +497,6 @@ TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) {
|
| // ReconsiderProxyAfterError returns error indicating nothing left.
|
| EXPECT_EQ(ERR_FAILED, rv);
|
| EXPECT_TRUE(info.is_empty());
|
| - EXPECT_TRUE(network_delegate.on_proxy_fallback_called());
|
| - EXPECT_EQ(expected_proxy_server, network_delegate.proxy_server());
|
| - EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED,
|
| - network_delegate.proxy_fallback_net_error());
|
| - EXPECT_FALSE(network_delegate.proxy_did_fallback());
|
| }
|
|
|
| // Test that if the execution of the PAC script fails (i.e. javascript runtime
|
| @@ -610,7 +589,6 @@ TEST_F(ProxyServiceTest, PAC_FailoverAfterDirect) {
|
| EXPECT_TRUE(info.is_direct());
|
|
|
| // Fallback 1.
|
| - TestProxyFallbackNetworkDelegate network_delegate2;
|
| TestCompletionCallback callback2;
|
| rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
|
| net::ERR_PROXY_CONNECTION_FAILED,
|
| @@ -619,57 +597,38 @@ TEST_F(ProxyServiceTest, PAC_FailoverAfterDirect) {
|
| EXPECT_EQ(OK, rv);
|
| EXPECT_FALSE(info.is_direct());
|
| EXPECT_EQ("foobar:10", info.proxy_server().ToURI());
|
| - // No network delegate provided.
|
| - EXPECT_FALSE(network_delegate2.on_proxy_fallback_called());
|
|
|
| // Fallback 2.
|
| - TestProxyFallbackNetworkDelegate network_delegate3;
|
| + NetworkDelegate network_delegate;
|
| ProxyServer expected_proxy_server3 = info.proxy_server();
|
| TestCompletionCallback callback3;
|
| rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
|
| net::ERR_PROXY_CONNECTION_FAILED,
|
| &info, callback3.callback(), NULL,
|
| - &network_delegate3, BoundNetLog());
|
| + &network_delegate, BoundNetLog());
|
| EXPECT_EQ(OK, rv);
|
| EXPECT_TRUE(info.is_direct());
|
| - EXPECT_TRUE(network_delegate3.on_proxy_fallback_called());
|
| - EXPECT_EQ(expected_proxy_server3, network_delegate3.proxy_server());
|
| - EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED,
|
| - network_delegate3.proxy_fallback_net_error());
|
| - EXPECT_TRUE(network_delegate3.proxy_did_fallback());
|
|
|
| // Fallback 3.
|
| - TestProxyFallbackNetworkDelegate network_delegate4;
|
| ProxyServer expected_proxy_server4 = info.proxy_server();
|
| TestCompletionCallback callback4;
|
| rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
|
| net::ERR_PROXY_CONNECTION_FAILED,
|
| &info, callback4.callback(), NULL,
|
| - &network_delegate4, BoundNetLog());
|
| + &network_delegate, BoundNetLog());
|
| EXPECT_EQ(OK, rv);
|
| EXPECT_FALSE(info.is_direct());
|
| EXPECT_EQ("foobar:20", info.proxy_server().ToURI());
|
| - EXPECT_TRUE(network_delegate4.on_proxy_fallback_called());
|
| - EXPECT_EQ(expected_proxy_server4, network_delegate4.proxy_server());
|
| - EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED,
|
| - network_delegate4.proxy_fallback_net_error());
|
| - EXPECT_TRUE(network_delegate4.proxy_did_fallback());
|
|
|
| // Fallback 4 -- Nothing to fall back to!
|
| - TestProxyFallbackNetworkDelegate network_delegate5;
|
| ProxyServer expected_proxy_server5 = info.proxy_server();
|
| TestCompletionCallback callback5;
|
| rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
|
| net::ERR_PROXY_CONNECTION_FAILED,
|
| &info, callback5.callback(), NULL,
|
| - &network_delegate5, BoundNetLog());
|
| + &network_delegate, BoundNetLog());
|
| EXPECT_EQ(ERR_FAILED, rv);
|
| EXPECT_TRUE(info.is_empty());
|
| - EXPECT_TRUE(network_delegate5.on_proxy_fallback_called());
|
| - EXPECT_EQ(expected_proxy_server5, network_delegate5.proxy_server());
|
| - EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED,
|
| - network_delegate5.proxy_fallback_net_error());
|
| - EXPECT_FALSE(network_delegate5.proxy_did_fallback());
|
| }
|
|
|
| TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) {
|
| @@ -984,7 +943,10 @@ TEST_F(ProxyServiceTest, ProxyFallback) {
|
| EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
|
| // Report back that the second proxy worked. This will globally mark the
|
| // first proxy as bad.
|
| - service.ReportSuccess(info);
|
| + TestNotifyProxyFallbackNetworkDelegate test_delegate;
|
| + service.ReportSuccess(info, &test_delegate);
|
| + EXPECT_EQ(info.proxy_server(), test_delegate.bad_proxy());
|
| + EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED, test_delegate.net_error());
|
|
|
| TestCompletionCallback callback3;
|
| rv = service.ResolveProxy(
|
|
|