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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 ProxyConfig config_; | 154 ProxyConfig config_; |
155 ObserverList<Observer, true> observers_; | 155 ObserverList<Observer, true> observers_; |
156 }; | 156 }; |
157 | 157 |
158 // A test network delegate that exercises the OnResolveProxy callback. | 158 // A test network delegate that exercises the OnResolveProxy callback. |
159 class TestResolveProxyNetworkDelegate : public NetworkDelegate { | 159 class TestResolveProxyNetworkDelegate : public NetworkDelegate { |
160 public: | 160 public: |
161 TestResolveProxyNetworkDelegate() | 161 TestResolveProxyNetworkDelegate() |
162 : on_resolve_proxy_called_(false), | 162 : on_resolve_proxy_called_(false), |
163 add_proxy_(false), | 163 add_proxy_(false), |
164 remove_proxy_(false) { | 164 remove_proxy_(false), |
| 165 proxy_service_(NULL) { |
165 } | 166 } |
166 | 167 |
167 virtual void OnResolveProxy( | 168 virtual void OnResolveProxy(const GURL& url, |
168 const GURL& url, int load_flags, ProxyInfo* result) OVERRIDE { | 169 int load_flags, |
| 170 const ProxyService& proxy_service, |
| 171 ProxyInfo* result) OVERRIDE { |
169 on_resolve_proxy_called_ = true; | 172 on_resolve_proxy_called_ = true; |
| 173 proxy_service_ = &proxy_service; |
170 DCHECK(!add_proxy_ || !remove_proxy_); | 174 DCHECK(!add_proxy_ || !remove_proxy_); |
171 if (add_proxy_) { | 175 if (add_proxy_) { |
172 result->UseNamedProxy("delegate_proxy.com"); | 176 result->UseNamedProxy("delegate_proxy.com"); |
173 } else if (remove_proxy_) { | 177 } else if (remove_proxy_) { |
174 result->UseDirect(); | 178 result->UseDirect(); |
175 } | 179 } |
176 } | 180 } |
177 | 181 |
178 bool on_resolve_proxy_called() const { | 182 bool on_resolve_proxy_called() const { |
179 return on_resolve_proxy_called_; | 183 return on_resolve_proxy_called_; |
180 } | 184 } |
181 | 185 |
182 void set_add_proxy(bool add_proxy) { | 186 void set_add_proxy(bool add_proxy) { |
183 add_proxy_ = add_proxy; | 187 add_proxy_ = add_proxy; |
184 } | 188 } |
185 | 189 |
186 void set_remove_proxy(bool remove_proxy) { | 190 void set_remove_proxy(bool remove_proxy) { |
187 remove_proxy_ = remove_proxy; | 191 remove_proxy_ = remove_proxy; |
188 } | 192 } |
189 | 193 |
| 194 const ProxyService* proxy_service() const { |
| 195 return proxy_service_; |
| 196 } |
| 197 |
190 private: | 198 private: |
191 bool on_resolve_proxy_called_; | 199 bool on_resolve_proxy_called_; |
192 bool add_proxy_; | 200 bool add_proxy_; |
193 bool remove_proxy_; | 201 bool remove_proxy_; |
| 202 const ProxyService* proxy_service_; |
194 }; | 203 }; |
195 | 204 |
196 // A test network delegate that exercises the OnProxyFallback callback. | 205 // A test network delegate that exercises the OnProxyFallback callback. |
197 class TestProxyFallbackNetworkDelegate : public NetworkDelegate { | 206 class TestProxyFallbackNetworkDelegate : public NetworkDelegate { |
198 public: | 207 public: |
199 TestProxyFallbackNetworkDelegate() | 208 TestProxyFallbackNetworkDelegate() |
200 : on_proxy_fallback_called_(false), | 209 : on_proxy_fallback_called_(false), |
201 proxy_fallback_net_error_(0), | 210 proxy_fallback_net_error_(0), |
202 proxy_did_fallback_(false) { | 211 proxy_did_fallback_(false) { |
203 } | 212 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, | 301 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, |
293 log.bound()); | 302 log.bound()); |
294 EXPECT_EQ(OK, rv); | 303 EXPECT_EQ(OK, rv); |
295 | 304 |
296 // Verify that network delegate is invoked. | 305 // Verify that network delegate is invoked. |
297 TestResolveProxyNetworkDelegate delegate; | 306 TestResolveProxyNetworkDelegate delegate; |
298 rv = service.ResolveProxy( | 307 rv = service.ResolveProxy( |
299 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, | 308 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, |
300 log.bound()); | 309 log.bound()); |
301 EXPECT_TRUE(delegate.on_resolve_proxy_called()); | 310 EXPECT_TRUE(delegate.on_resolve_proxy_called()); |
| 311 EXPECT_EQ(&service, delegate.proxy_service()); |
302 | 312 |
303 // Verify that the NetworkDelegate's behavior is stateless across | 313 // Verify that the NetworkDelegate's behavior is stateless across |
304 // invocations of ResolveProxy. Start by having the callback add a proxy | 314 // invocations of ResolveProxy. Start by having the callback add a proxy |
305 // and checking that subsequent requests are not affected. | 315 // and checking that subsequent requests are not affected. |
306 delegate.set_add_proxy(true); | 316 delegate.set_add_proxy(true); |
307 | 317 |
308 // Callback should interpose: | 318 // Callback should interpose: |
309 rv = service.ResolveProxy( | 319 rv = service.ResolveProxy( |
310 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, | 320 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, |
311 log.bound()); | 321 log.bound()); |
(...skipping 2783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3095 ProxyInfo info3; | 3105 ProxyInfo info3; |
3096 TestCompletionCallback callback3; | 3106 TestCompletionCallback callback3; |
3097 rv = service.ResolveProxy( | 3107 rv = service.ResolveProxy( |
3098 GURL("http://request3"), net::LOAD_NORMAL, &info3, callback3.callback(), | 3108 GURL("http://request3"), net::LOAD_NORMAL, &info3, callback3.callback(), |
3099 NULL, NULL, BoundNetLog()); | 3109 NULL, NULL, BoundNetLog()); |
3100 EXPECT_EQ(OK, rv); | 3110 EXPECT_EQ(OK, rv); |
3101 EXPECT_TRUE(info3.is_direct()); | 3111 EXPECT_TRUE(info3.is_direct()); |
3102 } | 3112 } |
3103 | 3113 |
3104 } // namespace net | 3114 } // namespace net |
OLD | NEW |