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