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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // TODO(eroman): Write a test which exercises | 30 // TODO(eroman): Write a test which exercises |
31 // ProxyService::SuspendAllPendingRequests(). | 31 // ProxyService::SuspendAllPendingRequests(). |
32 namespace net { | 32 namespace net { |
33 namespace { | 33 namespace { |
34 | 34 |
35 // This polling policy will decide to poll every 1 ms. | 35 // This polling policy will decide to poll every 1 ms. |
36 class ImmediatePollPolicy : public ProxyService::PacPollPolicy { | 36 class ImmediatePollPolicy : public ProxyService::PacPollPolicy { |
37 public: | 37 public: |
38 ImmediatePollPolicy() {} | 38 ImmediatePollPolicy() {} |
39 | 39 |
40 virtual Mode GetNextDelay(int error, base::TimeDelta current_delay, | 40 Mode GetNextDelay(int error, |
41 base::TimeDelta* next_delay) const override { | 41 base::TimeDelta current_delay, |
| 42 base::TimeDelta* next_delay) const override { |
42 *next_delay = base::TimeDelta::FromMilliseconds(1); | 43 *next_delay = base::TimeDelta::FromMilliseconds(1); |
43 return MODE_USE_TIMER; | 44 return MODE_USE_TIMER; |
44 } | 45 } |
45 | 46 |
46 private: | 47 private: |
47 DISALLOW_COPY_AND_ASSIGN(ImmediatePollPolicy); | 48 DISALLOW_COPY_AND_ASSIGN(ImmediatePollPolicy); |
48 }; | 49 }; |
49 | 50 |
50 // This polling policy chooses a fantastically large delay. In other words, it | 51 // This polling policy chooses a fantastically large delay. In other words, it |
51 // will never trigger a poll | 52 // will never trigger a poll |
52 class NeverPollPolicy : public ProxyService::PacPollPolicy { | 53 class NeverPollPolicy : public ProxyService::PacPollPolicy { |
53 public: | 54 public: |
54 NeverPollPolicy() {} | 55 NeverPollPolicy() {} |
55 | 56 |
56 virtual Mode GetNextDelay(int error, base::TimeDelta current_delay, | 57 Mode GetNextDelay(int error, |
57 base::TimeDelta* next_delay) const override { | 58 base::TimeDelta current_delay, |
| 59 base::TimeDelta* next_delay) const override { |
58 *next_delay = base::TimeDelta::FromDays(60); | 60 *next_delay = base::TimeDelta::FromDays(60); |
59 return MODE_USE_TIMER; | 61 return MODE_USE_TIMER; |
60 } | 62 } |
61 | 63 |
62 private: | 64 private: |
63 DISALLOW_COPY_AND_ASSIGN(NeverPollPolicy); | 65 DISALLOW_COPY_AND_ASSIGN(NeverPollPolicy); |
64 }; | 66 }; |
65 | 67 |
66 // This polling policy starts a poll immediately after network activity. | 68 // This polling policy starts a poll immediately after network activity. |
67 class ImmediateAfterActivityPollPolicy : public ProxyService::PacPollPolicy { | 69 class ImmediateAfterActivityPollPolicy : public ProxyService::PacPollPolicy { |
68 public: | 70 public: |
69 ImmediateAfterActivityPollPolicy() {} | 71 ImmediateAfterActivityPollPolicy() {} |
70 | 72 |
71 virtual Mode GetNextDelay(int error, base::TimeDelta current_delay, | 73 Mode GetNextDelay(int error, |
72 base::TimeDelta* next_delay) const override { | 74 base::TimeDelta current_delay, |
| 75 base::TimeDelta* next_delay) const override { |
73 *next_delay = base::TimeDelta(); | 76 *next_delay = base::TimeDelta(); |
74 return MODE_START_AFTER_ACTIVITY; | 77 return MODE_START_AFTER_ACTIVITY; |
75 } | 78 } |
76 | 79 |
77 private: | 80 private: |
78 DISALLOW_COPY_AND_ASSIGN(ImmediateAfterActivityPollPolicy); | 81 DISALLOW_COPY_AND_ASSIGN(ImmediateAfterActivityPollPolicy); |
79 }; | 82 }; |
80 | 83 |
81 // This test fixture is used to partially disable the background polling done by | 84 // This test fixture is used to partially disable the background polling done by |
82 // the ProxyService (which it uses to detect whenever its PAC script contents or | 85 // the ProxyService (which it uses to detect whenever its PAC script contents or |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 explicit MockProxyConfigService(const ProxyConfig& config) | 123 explicit MockProxyConfigService(const ProxyConfig& config) |
121 : availability_(CONFIG_VALID), | 124 : availability_(CONFIG_VALID), |
122 config_(config) { | 125 config_(config) { |
123 } | 126 } |
124 | 127 |
125 explicit MockProxyConfigService(const std::string& pac_url) | 128 explicit MockProxyConfigService(const std::string& pac_url) |
126 : availability_(CONFIG_VALID), | 129 : availability_(CONFIG_VALID), |
127 config_(ProxyConfig::CreateFromCustomPacURL(GURL(pac_url))) { | 130 config_(ProxyConfig::CreateFromCustomPacURL(GURL(pac_url))) { |
128 } | 131 } |
129 | 132 |
130 virtual void AddObserver(Observer* observer) override { | 133 void AddObserver(Observer* observer) override { |
131 observers_.AddObserver(observer); | 134 observers_.AddObserver(observer); |
132 } | 135 } |
133 | 136 |
134 virtual void RemoveObserver(Observer* observer) override { | 137 void RemoveObserver(Observer* observer) override { |
135 observers_.RemoveObserver(observer); | 138 observers_.RemoveObserver(observer); |
136 } | 139 } |
137 | 140 |
138 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* results) | 141 ConfigAvailability GetLatestProxyConfig(ProxyConfig* results) override { |
139 override { | |
140 if (availability_ == CONFIG_VALID) | 142 if (availability_ == CONFIG_VALID) |
141 *results = config_; | 143 *results = config_; |
142 return availability_; | 144 return availability_; |
143 } | 145 } |
144 | 146 |
145 void SetConfig(const ProxyConfig& config) { | 147 void SetConfig(const ProxyConfig& config) { |
146 availability_ = CONFIG_VALID; | 148 availability_ = CONFIG_VALID; |
147 config_ = config; | 149 config_ = config; |
148 FOR_EACH_OBSERVER(Observer, observers_, | 150 FOR_EACH_OBSERVER(Observer, observers_, |
149 OnProxyConfigChanged(config_, availability_)); | 151 OnProxyConfigChanged(config_, availability_)); |
150 } | 152 } |
151 | 153 |
152 private: | 154 private: |
153 ConfigAvailability availability_; | 155 ConfigAvailability availability_; |
154 ProxyConfig config_; | 156 ProxyConfig config_; |
155 ObserverList<Observer, true> observers_; | 157 ObserverList<Observer, true> observers_; |
156 }; | 158 }; |
157 | 159 |
158 // A test network delegate that exercises the OnResolveProxy callback. | 160 // A test network delegate that exercises the OnResolveProxy callback. |
159 class TestResolveProxyNetworkDelegate : public NetworkDelegate { | 161 class TestResolveProxyNetworkDelegate : public NetworkDelegate { |
160 public: | 162 public: |
161 TestResolveProxyNetworkDelegate() | 163 TestResolveProxyNetworkDelegate() |
162 : on_resolve_proxy_called_(false), | 164 : on_resolve_proxy_called_(false), |
163 add_proxy_(false), | 165 add_proxy_(false), |
164 remove_proxy_(false), | 166 remove_proxy_(false), |
165 proxy_service_(NULL) { | 167 proxy_service_(NULL) { |
166 } | 168 } |
167 | 169 |
168 virtual void OnResolveProxy(const GURL& url, | 170 void OnResolveProxy(const GURL& url, |
169 int load_flags, | 171 int load_flags, |
170 const ProxyService& proxy_service, | 172 const ProxyService& proxy_service, |
171 ProxyInfo* result) override { | 173 ProxyInfo* result) override { |
172 on_resolve_proxy_called_ = true; | 174 on_resolve_proxy_called_ = true; |
173 proxy_service_ = &proxy_service; | 175 proxy_service_ = &proxy_service; |
174 DCHECK(!add_proxy_ || !remove_proxy_); | 176 DCHECK(!add_proxy_ || !remove_proxy_); |
175 if (add_proxy_) { | 177 if (add_proxy_) { |
176 result->UseNamedProxy("delegate_proxy.com"); | 178 result->UseNamedProxy("delegate_proxy.com"); |
177 } else if (remove_proxy_) { | 179 } else if (remove_proxy_) { |
178 result->UseDirect(); | 180 result->UseDirect(); |
179 } | 181 } |
180 } | 182 } |
181 | 183 |
(...skipping 21 matching lines...) Expand all Loading... |
203 }; | 205 }; |
204 | 206 |
205 // A test network delegate that exercises the OnProxyFallback callback. | 207 // A test network delegate that exercises the OnProxyFallback callback. |
206 class TestProxyFallbackNetworkDelegate : public NetworkDelegate { | 208 class TestProxyFallbackNetworkDelegate : public NetworkDelegate { |
207 public: | 209 public: |
208 TestProxyFallbackNetworkDelegate() | 210 TestProxyFallbackNetworkDelegate() |
209 : on_proxy_fallback_called_(false), | 211 : on_proxy_fallback_called_(false), |
210 proxy_fallback_net_error_(OK) { | 212 proxy_fallback_net_error_(OK) { |
211 } | 213 } |
212 | 214 |
213 virtual void OnProxyFallback(const ProxyServer& proxy_server, | 215 void OnProxyFallback(const ProxyServer& proxy_server, |
214 int net_error) override { | 216 int net_error) override { |
215 proxy_server_ = proxy_server; | 217 proxy_server_ = proxy_server; |
216 proxy_fallback_net_error_ = net_error; | 218 proxy_fallback_net_error_ = net_error; |
217 on_proxy_fallback_called_ = true; | 219 on_proxy_fallback_called_ = true; |
218 } | 220 } |
219 | 221 |
220 bool on_proxy_fallback_called() const { | 222 bool on_proxy_fallback_called() const { |
221 return on_proxy_fallback_called_; | 223 return on_proxy_fallback_called_; |
222 } | 224 } |
223 | 225 |
224 const ProxyServer& proxy_server() const { | 226 const ProxyServer& proxy_server() const { |
(...skipping 2902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3127 url, net::LOAD_NORMAL, &info, NULL, log.bound()); | 3129 url, net::LOAD_NORMAL, &info, NULL, log.bound()); |
3128 EXPECT_TRUE(synchronous_success); | 3130 EXPECT_TRUE(synchronous_success); |
3129 EXPECT_FALSE(info.is_direct()); | 3131 EXPECT_FALSE(info.is_direct()); |
3130 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); | 3132 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); |
3131 | 3133 |
3132 // No request should have been queued. | 3134 // No request should have been queued. |
3133 EXPECT_EQ(0u, resolver->pending_requests().size()); | 3135 EXPECT_EQ(0u, resolver->pending_requests().size()); |
3134 } | 3136 } |
3135 | 3137 |
3136 } // namespace net | 3138 } // namespace net |
OLD | NEW |