| OLD | NEW |
| 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/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 16 #include "net/base/net_log_unittest.h" | 16 #include "net/base/net_log_unittest.h" |
| 17 #include "net/base/network_delegate.h" | 17 #include "net/base/network_delegate_impl.h" |
| 18 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
| 19 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 19 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
| 20 #include "net/proxy/mock_proxy_resolver.h" | 20 #include "net/proxy/mock_proxy_resolver.h" |
| 21 #include "net/proxy/mock_proxy_script_fetcher.h" | 21 #include "net/proxy/mock_proxy_script_fetcher.h" |
| 22 #include "net/proxy/proxy_config_service.h" | 22 #include "net/proxy/proxy_config_service.h" |
| 23 #include "net/proxy/proxy_resolver.h" | 23 #include "net/proxy/proxy_resolver.h" |
| 24 #include "net/proxy/proxy_script_fetcher.h" | 24 #include "net/proxy/proxy_script_fetcher.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 OnProxyConfigChanged(config_, availability_)); | 151 OnProxyConfigChanged(config_, availability_)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 ConfigAvailability availability_; | 155 ConfigAvailability availability_; |
| 156 ProxyConfig config_; | 156 ProxyConfig config_; |
| 157 ObserverList<Observer, true> observers_; | 157 ObserverList<Observer, true> observers_; |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 // A test network delegate that exercises the OnResolveProxy callback. | 160 // A test network delegate that exercises the OnResolveProxy callback. |
| 161 class TestResolveProxyNetworkDelegate : public NetworkDelegate { | 161 class TestResolveProxyNetworkDelegate : public NetworkDelegateImpl { |
| 162 public: | 162 public: |
| 163 TestResolveProxyNetworkDelegate() | 163 TestResolveProxyNetworkDelegate() |
| 164 : on_resolve_proxy_called_(false), | 164 : on_resolve_proxy_called_(false), |
| 165 add_proxy_(false), | 165 add_proxy_(false), |
| 166 remove_proxy_(false), | 166 remove_proxy_(false), |
| 167 proxy_service_(NULL) { | 167 proxy_service_(NULL) { |
| 168 } | 168 } |
| 169 | 169 |
| 170 void OnResolveProxy(const GURL& url, | 170 void OnResolveProxy(const GURL& url, |
| 171 int load_flags, | 171 int load_flags, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 198 } | 198 } |
| 199 | 199 |
| 200 private: | 200 private: |
| 201 bool on_resolve_proxy_called_; | 201 bool on_resolve_proxy_called_; |
| 202 bool add_proxy_; | 202 bool add_proxy_; |
| 203 bool remove_proxy_; | 203 bool remove_proxy_; |
| 204 const ProxyService* proxy_service_; | 204 const ProxyService* proxy_service_; |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 // A test network delegate that exercises the OnProxyFallback callback. | 207 // A test network delegate that exercises the OnProxyFallback callback. |
| 208 class TestProxyFallbackNetworkDelegate : public NetworkDelegate { | 208 class TestProxyFallbackNetworkDelegate : public NetworkDelegateImpl { |
| 209 public: | 209 public: |
| 210 TestProxyFallbackNetworkDelegate() | 210 TestProxyFallbackNetworkDelegate() |
| 211 : on_proxy_fallback_called_(false), | 211 : on_proxy_fallback_called_(false), |
| 212 proxy_fallback_net_error_(OK) { | 212 proxy_fallback_net_error_(OK) { |
| 213 } | 213 } |
| 214 | 214 |
| 215 void OnProxyFallback(const ProxyServer& proxy_server, | 215 void OnProxyFallback(const ProxyServer& proxy_server, |
| 216 int net_error) override { | 216 int net_error) override { |
| 217 proxy_server_ = proxy_server; | 217 proxy_server_ = proxy_server; |
| 218 proxy_fallback_net_error_ = net_error; | 218 proxy_fallback_net_error_ = net_error; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 500 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
| 501 EXPECT_TRUE(info.did_use_pac_script()); | 501 EXPECT_TRUE(info.did_use_pac_script()); |
| 502 | 502 |
| 503 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 503 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 504 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 504 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 505 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 505 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 506 | 506 |
| 507 // Now, imagine that connecting to foopy:8080 fails: there is nothing | 507 // Now, imagine that connecting to foopy:8080 fails: there is nothing |
| 508 // left to fallback to, since our proxy list was NOT terminated by | 508 // left to fallback to, since our proxy list was NOT terminated by |
| 509 // DIRECT. | 509 // DIRECT. |
| 510 NetworkDelegate network_delegate; | 510 NetworkDelegateImpl network_delegate; |
| 511 TestCompletionCallback callback2; | 511 TestCompletionCallback callback2; |
| 512 ProxyServer expected_proxy_server = info.proxy_server(); | 512 ProxyServer expected_proxy_server = info.proxy_server(); |
| 513 rv = service.ReconsiderProxyAfterError( | 513 rv = service.ReconsiderProxyAfterError( |
| 514 url, net::LOAD_NORMAL, net::ERR_PROXY_CONNECTION_FAILED, | 514 url, net::LOAD_NORMAL, net::ERR_PROXY_CONNECTION_FAILED, |
| 515 &info, callback2.callback(), NULL, &network_delegate, BoundNetLog()); | 515 &info, callback2.callback(), NULL, &network_delegate, BoundNetLog()); |
| 516 // ReconsiderProxyAfterError returns error indicating nothing left. | 516 // ReconsiderProxyAfterError returns error indicating nothing left. |
| 517 EXPECT_EQ(ERR_FAILED, rv); | 517 EXPECT_EQ(ERR_FAILED, rv); |
| 518 EXPECT_TRUE(info.is_empty()); | 518 EXPECT_TRUE(info.is_empty()); |
| 519 } | 519 } |
| 520 | 520 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 TestCompletionCallback callback2; | 611 TestCompletionCallback callback2; |
| 612 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, | 612 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 613 net::ERR_PROXY_CONNECTION_FAILED, | 613 net::ERR_PROXY_CONNECTION_FAILED, |
| 614 &info, callback2.callback(), NULL, | 614 &info, callback2.callback(), NULL, |
| 615 NULL, BoundNetLog()); | 615 NULL, BoundNetLog()); |
| 616 EXPECT_EQ(OK, rv); | 616 EXPECT_EQ(OK, rv); |
| 617 EXPECT_FALSE(info.is_direct()); | 617 EXPECT_FALSE(info.is_direct()); |
| 618 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); | 618 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); |
| 619 | 619 |
| 620 // Fallback 2. | 620 // Fallback 2. |
| 621 NetworkDelegate network_delegate; | 621 NetworkDelegateImpl network_delegate; |
| 622 ProxyServer expected_proxy_server3 = info.proxy_server(); | 622 ProxyServer expected_proxy_server3 = info.proxy_server(); |
| 623 TestCompletionCallback callback3; | 623 TestCompletionCallback callback3; |
| 624 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, | 624 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 625 net::ERR_PROXY_CONNECTION_FAILED, | 625 net::ERR_PROXY_CONNECTION_FAILED, |
| 626 &info, callback3.callback(), NULL, | 626 &info, callback3.callback(), NULL, |
| 627 &network_delegate, BoundNetLog()); | 627 &network_delegate, BoundNetLog()); |
| 628 EXPECT_EQ(OK, rv); | 628 EXPECT_EQ(OK, rv); |
| 629 EXPECT_TRUE(info.is_direct()); | 629 EXPECT_TRUE(info.is_direct()); |
| 630 | 630 |
| 631 // Fallback 3. | 631 // Fallback 3. |
| (...skipping 2497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3129 url, net::LOAD_NORMAL, &info, NULL, log.bound()); | 3129 url, net::LOAD_NORMAL, &info, NULL, log.bound()); |
| 3130 EXPECT_TRUE(synchronous_success); | 3130 EXPECT_TRUE(synchronous_success); |
| 3131 EXPECT_FALSE(info.is_direct()); | 3131 EXPECT_FALSE(info.is_direct()); |
| 3132 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); | 3132 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); |
| 3133 | 3133 |
| 3134 // No request should have been queued. | 3134 // No request should have been queued. |
| 3135 EXPECT_EQ(0u, resolver->pending_requests().size()); | 3135 EXPECT_EQ(0u, resolver->pending_requests().size()); |
| 3136 } | 3136 } |
| 3137 | 3137 |
| 3138 } // namespace net | 3138 } // namespace net |
| OLD | NEW |