| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "net/base/load_log.h" | 10 #include "net/base/load_log.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 GURL pending_request_url_; | 84 GURL pending_request_url_; |
| 85 CompletionCallback* pending_request_callback_; | 85 CompletionCallback* pending_request_callback_; |
| 86 std::string* pending_request_bytes_; | 86 std::string* pending_request_bytes_; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 TEST(ProxyServiceTest, Direct) { | 89 TEST(ProxyServiceTest, Direct) { |
| 90 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 90 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 91 ProxyService service(new MockProxyConfigService, resolver); | 91 scoped_refptr<ProxyService> service( |
| 92 new ProxyService(new MockProxyConfigService, resolver)); |
| 92 | 93 |
| 93 GURL url("http://www.google.com/"); | 94 GURL url("http://www.google.com/"); |
| 94 | 95 |
| 95 ProxyInfo info; | 96 ProxyInfo info; |
| 96 TestCompletionCallback callback; | 97 TestCompletionCallback callback; |
| 97 scoped_refptr<LoadLog> log(new LoadLog); | 98 scoped_refptr<LoadLog> log(new LoadLog); |
| 98 int rv = service.ResolveProxy(url, &info, &callback, NULL, log); | 99 int rv = service->ResolveProxy(url, &info, &callback, NULL, log); |
| 99 EXPECT_EQ(OK, rv); | 100 EXPECT_EQ(OK, rv); |
| 100 EXPECT_TRUE(resolver->pending_requests().empty()); | 101 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 101 EXPECT_TRUE(NULL == service.init_proxy_resolver_log()); | 102 EXPECT_TRUE(NULL == service->init_proxy_resolver_log()); |
| 102 | 103 |
| 103 EXPECT_TRUE(info.is_direct()); | 104 EXPECT_TRUE(info.is_direct()); |
| 104 | 105 |
| 105 // Check the LoadLog was filled correctly. | 106 // Check the LoadLog was filled correctly. |
| 106 EXPECT_EQ(2u, log->events().size()); | 107 EXPECT_EQ(2u, log->events().size()); |
| 107 ExpectLogContains(log, 0, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_BEGIN); | 108 ExpectLogContains(log, 0, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_BEGIN); |
| 108 ExpectLogContains(log, 1, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_END); | 109 ExpectLogContains(log, 1, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_END); |
| 109 } | 110 } |
| 110 | 111 |
| 111 TEST(ProxyServiceTest, PAC) { | 112 TEST(ProxyServiceTest, PAC) { |
| 112 MockProxyConfigService* config_service = | 113 MockProxyConfigService* config_service = |
| 113 new MockProxyConfigService("http://foopy/proxy.pac"); | 114 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 114 | 115 |
| 115 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 116 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 116 | 117 |
| 117 ProxyService service(config_service, resolver); | 118 scoped_refptr<ProxyService> service( |
| 119 new ProxyService(config_service, resolver)); |
| 118 | 120 |
| 119 GURL url("http://www.google.com/"); | 121 GURL url("http://www.google.com/"); |
| 120 | 122 |
| 121 ProxyInfo info; | 123 ProxyInfo info; |
| 122 TestCompletionCallback callback; | 124 TestCompletionCallback callback; |
| 123 scoped_refptr<LoadLog> log(new LoadLog); | 125 scoped_refptr<LoadLog> log(new LoadLog); |
| 124 int rv = service.ResolveProxy(url, &info, &callback, NULL, log); | 126 int rv = service->ResolveProxy(url, &info, &callback, NULL, log); |
| 125 EXPECT_EQ(ERR_IO_PENDING, rv); | 127 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 126 | 128 |
| 127 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 129 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 128 resolver->pending_set_pac_script_request()->pac_url()); | 130 resolver->pending_set_pac_script_request()->pac_url()); |
| 129 EXPECT_FALSE(NULL == service.init_proxy_resolver_log()); | 131 EXPECT_FALSE(NULL == service->init_proxy_resolver_log()); |
| 130 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 132 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 131 | 133 |
| 132 ASSERT_EQ(1u, resolver->pending_requests().size()); | 134 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 133 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 135 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 134 | 136 |
| 135 // Set the result in proxy resolver. | 137 // Set the result in proxy resolver. |
| 136 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); | 138 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); |
| 137 resolver->pending_requests()[0]->CompleteNow(OK); | 139 resolver->pending_requests()[0]->CompleteNow(OK); |
| 138 | 140 |
| 139 EXPECT_EQ(OK, callback.WaitForResult()); | 141 EXPECT_EQ(OK, callback.WaitForResult()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 151 } | 153 } |
| 152 | 154 |
| 153 // Test that the proxy resolver does not see the URL's username/password | 155 // Test that the proxy resolver does not see the URL's username/password |
| 154 // or its reference section. | 156 // or its reference section. |
| 155 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { | 157 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { |
| 156 MockProxyConfigService* config_service = | 158 MockProxyConfigService* config_service = |
| 157 new MockProxyConfigService("http://foopy/proxy.pac"); | 159 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 158 | 160 |
| 159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 161 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 160 | 162 |
| 161 ProxyService service(config_service, resolver); | 163 scoped_refptr<ProxyService> service( |
| 164 new ProxyService(config_service, resolver)); |
| 162 | 165 |
| 163 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 166 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
| 164 | 167 |
| 165 ProxyInfo info; | 168 ProxyInfo info; |
| 166 TestCompletionCallback callback; | 169 TestCompletionCallback callback; |
| 167 int rv = service.ResolveProxy(url, &info, &callback, NULL, NULL); | 170 int rv = service->ResolveProxy(url, &info, &callback, NULL, NULL); |
| 168 EXPECT_EQ(ERR_IO_PENDING, rv); | 171 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 169 | 172 |
| 170 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 173 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 171 resolver->pending_set_pac_script_request()->pac_url()); | 174 resolver->pending_set_pac_script_request()->pac_url()); |
| 172 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 175 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 173 | 176 |
| 174 ASSERT_EQ(1u, resolver->pending_requests().size()); | 177 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 175 // The URL should have been simplified, stripping the username/password/hash. | 178 // The URL should have been simplified, stripping the username/password/hash. |
| 176 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 179 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
| 177 resolver->pending_requests()[0]->url()); | 180 resolver->pending_requests()[0]->url()); |
| 178 | 181 |
| 179 // We end here without ever completing the request -- destruction of | 182 // We end here without ever completing the request -- destruction of |
| 180 // ProxyService will cancel the outstanding request. | 183 // ProxyService will cancel the outstanding request. |
| 181 } | 184 } |
| 182 | 185 |
| 183 TEST(ProxyServiceTest, PAC_FailoverToDirect) { | 186 TEST(ProxyServiceTest, PAC_FailoverToDirect) { |
| 184 MockProxyConfigService* config_service = | 187 MockProxyConfigService* config_service = |
| 185 new MockProxyConfigService("http://foopy/proxy.pac"); | 188 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 186 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 189 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 187 | 190 |
| 188 ProxyService service(config_service, resolver); | 191 scoped_refptr<ProxyService> service( |
| 192 new ProxyService(config_service, resolver)); |
| 189 | 193 |
| 190 GURL url("http://www.google.com/"); | 194 GURL url("http://www.google.com/"); |
| 191 | 195 |
| 192 ProxyInfo info; | 196 ProxyInfo info; |
| 193 TestCompletionCallback callback1; | 197 TestCompletionCallback callback1; |
| 194 int rv = service.ResolveProxy(url, &info, &callback1, NULL, NULL); | 198 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 195 EXPECT_EQ(ERR_IO_PENDING, rv); | 199 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 196 | 200 |
| 197 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 201 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 198 resolver->pending_set_pac_script_request()->pac_url()); | 202 resolver->pending_set_pac_script_request()->pac_url()); |
| 199 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 203 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 200 | 204 |
| 201 ASSERT_EQ(1u, resolver->pending_requests().size()); | 205 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 202 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 206 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 203 | 207 |
| 204 // Set the result in proxy resolver. | 208 // Set the result in proxy resolver. |
| 205 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 209 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
| 206 resolver->pending_requests()[0]->CompleteNow(OK); | 210 resolver->pending_requests()[0]->CompleteNow(OK); |
| 207 | 211 |
| 208 EXPECT_EQ(OK, callback1.WaitForResult()); | 212 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 209 EXPECT_FALSE(info.is_direct()); | 213 EXPECT_FALSE(info.is_direct()); |
| 210 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 214 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
| 211 | 215 |
| 212 // Now, imagine that connecting to foopy:8080 fails. | 216 // Now, imagine that connecting to foopy:8080 fails. |
| 213 TestCompletionCallback callback2; | 217 TestCompletionCallback callback2; |
| 214 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); | 218 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); |
| 215 EXPECT_EQ(OK, rv); | 219 EXPECT_EQ(OK, rv); |
| 216 EXPECT_TRUE(info.is_direct()); | 220 EXPECT_TRUE(info.is_direct()); |
| 217 } | 221 } |
| 218 | 222 |
| 219 TEST(ProxyServiceTest, ProxyResolverFails) { | 223 TEST(ProxyServiceTest, ProxyResolverFails) { |
| 220 // Test what happens when the ProxyResolver fails (this could represent | 224 // Test what happens when the ProxyResolver fails (this could represent |
| 221 // a failure to download the PAC script in the case of ProxyResolvers which | 225 // a failure to download the PAC script in the case of ProxyResolvers which |
| 222 // do the fetch internally.) | 226 // do the fetch internally.) |
| 223 // TODO(eroman): change this comment. | 227 // TODO(eroman): change this comment. |
| 224 | 228 |
| 225 MockProxyConfigService* config_service = | 229 MockProxyConfigService* config_service = |
| 226 new MockProxyConfigService("http://foopy/proxy.pac"); | 230 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 227 | 231 |
| 228 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 232 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 229 | 233 |
| 230 ProxyService service(config_service, resolver); | 234 scoped_refptr<ProxyService> service( |
| 235 new ProxyService(config_service, resolver)); |
| 231 | 236 |
| 232 // Start first resolve request. | 237 // Start first resolve request. |
| 233 GURL url("http://www.google.com/"); | 238 GURL url("http://www.google.com/"); |
| 234 ProxyInfo info; | 239 ProxyInfo info; |
| 235 TestCompletionCallback callback1; | 240 TestCompletionCallback callback1; |
| 236 int rv = service.ResolveProxy(url, &info, &callback1, NULL, NULL); | 241 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 237 EXPECT_EQ(ERR_IO_PENDING, rv); | 242 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 238 | 243 |
| 239 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 244 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 240 resolver->pending_set_pac_script_request()->pac_url()); | 245 resolver->pending_set_pac_script_request()->pac_url()); |
| 241 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 246 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 242 | 247 |
| 243 ASSERT_EQ(1u, resolver->pending_requests().size()); | 248 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 244 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 249 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 245 | 250 |
| 246 // Fail the first resolve request in MockAsyncProxyResolver. | 251 // Fail the first resolve request in MockAsyncProxyResolver. |
| 247 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 252 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 248 | 253 |
| 249 EXPECT_EQ(ERR_FAILED, callback1.WaitForResult()); | 254 EXPECT_EQ(ERR_FAILED, callback1.WaitForResult()); |
| 250 | 255 |
| 251 // The second resolve request will automatically select direct connect, | 256 // The second resolve request will automatically select direct connect, |
| 252 // because it has cached the configuration as being bad. | 257 // because it has cached the configuration as being bad. |
| 253 TestCompletionCallback callback2; | 258 TestCompletionCallback callback2; |
| 254 rv = service.ResolveProxy(url, &info, &callback2, NULL, NULL); | 259 rv = service->ResolveProxy(url, &info, &callback2, NULL, NULL); |
| 255 EXPECT_EQ(OK, rv); | 260 EXPECT_EQ(OK, rv); |
| 256 EXPECT_TRUE(info.is_direct()); | 261 EXPECT_TRUE(info.is_direct()); |
| 257 EXPECT_TRUE(resolver->pending_requests().empty()); | 262 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 258 | 263 |
| 259 // But, if that fails, then we should give the proxy config another shot | 264 // But, if that fails, then we should give the proxy config another shot |
| 260 // since we have never tried it with this URL before. | 265 // since we have never tried it with this URL before. |
| 261 TestCompletionCallback callback3; | 266 TestCompletionCallback callback3; |
| 262 rv = service.ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL); | 267 rv = service->ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL); |
| 263 EXPECT_EQ(ERR_IO_PENDING, rv); | 268 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 264 | 269 |
| 265 ASSERT_EQ(1u, resolver->pending_requests().size()); | 270 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 266 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 271 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 267 | 272 |
| 268 // Set the result in proxy resolver. | 273 // Set the result in proxy resolver. |
| 269 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 274 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
| 270 resolver->pending_requests()[0]->CompleteNow(OK); | 275 resolver->pending_requests()[0]->CompleteNow(OK); |
| 271 | 276 |
| 272 EXPECT_EQ(OK, callback3.WaitForResult()); | 277 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 273 EXPECT_FALSE(info.is_direct()); | 278 EXPECT_FALSE(info.is_direct()); |
| 274 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 279 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
| 275 } | 280 } |
| 276 | 281 |
| 277 TEST(ProxyServiceTest, ProxyFallback) { | 282 TEST(ProxyServiceTest, ProxyFallback) { |
| 278 // Test what happens when we specify multiple proxy servers and some of them | 283 // Test what happens when we specify multiple proxy servers and some of them |
| 279 // are bad. | 284 // are bad. |
| 280 | 285 |
| 281 MockProxyConfigService* config_service = | 286 MockProxyConfigService* config_service = |
| 282 new MockProxyConfigService("http://foopy/proxy.pac"); | 287 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 283 | 288 |
| 284 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 289 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 285 | 290 |
| 286 ProxyService service(config_service, resolver); | 291 scoped_refptr<ProxyService> service( |
| 292 new ProxyService(config_service, resolver)); |
| 287 | 293 |
| 288 GURL url("http://www.google.com/"); | 294 GURL url("http://www.google.com/"); |
| 289 | 295 |
| 290 // Get the proxy information. | 296 // Get the proxy information. |
| 291 ProxyInfo info; | 297 ProxyInfo info; |
| 292 TestCompletionCallback callback1; | 298 TestCompletionCallback callback1; |
| 293 int rv = service.ResolveProxy(url, &info, &callback1, NULL, NULL); | 299 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 294 EXPECT_EQ(ERR_IO_PENDING, rv); | 300 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 295 | 301 |
| 296 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 302 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 297 resolver->pending_set_pac_script_request()->pac_url()); | 303 resolver->pending_set_pac_script_request()->pac_url()); |
| 298 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 304 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 299 | 305 |
| 300 ASSERT_EQ(1u, resolver->pending_requests().size()); | 306 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 301 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 307 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 302 | 308 |
| 303 // Set the result in proxy resolver. | 309 // Set the result in proxy resolver. |
| 304 resolver->pending_requests()[0]->results()->UseNamedProxy( | 310 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 305 "foopy1:8080;foopy2:9090"); | 311 "foopy1:8080;foopy2:9090"); |
| 306 resolver->pending_requests()[0]->CompleteNow(OK); | 312 resolver->pending_requests()[0]->CompleteNow(OK); |
| 307 | 313 |
| 308 // The first item is valid. | 314 // The first item is valid. |
| 309 EXPECT_EQ(OK, callback1.WaitForResult()); | 315 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 310 EXPECT_FALSE(info.is_direct()); | 316 EXPECT_FALSE(info.is_direct()); |
| 311 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 317 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 312 | 318 |
| 313 // Fake an error on the proxy. | 319 // Fake an error on the proxy. |
| 314 TestCompletionCallback callback2; | 320 TestCompletionCallback callback2; |
| 315 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); | 321 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); |
| 316 EXPECT_EQ(OK, rv); | 322 EXPECT_EQ(OK, rv); |
| 317 | 323 |
| 318 // The second proxy should be specified. | 324 // The second proxy should be specified. |
| 319 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 325 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 320 | 326 |
| 321 TestCompletionCallback callback3; | 327 TestCompletionCallback callback3; |
| 322 rv = service.ResolveProxy(url, &info, &callback3, NULL, NULL); | 328 rv = service->ResolveProxy(url, &info, &callback3, NULL, NULL); |
| 323 EXPECT_EQ(ERR_IO_PENDING, rv); | 329 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 324 | 330 |
| 325 ASSERT_EQ(1u, resolver->pending_requests().size()); | 331 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 326 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 332 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 327 | 333 |
| 328 // Set the result in proxy resolver -- the second result is already known | 334 // Set the result in proxy resolver -- the second result is already known |
| 329 // to be bad. | 335 // to be bad. |
| 330 resolver->pending_requests()[0]->results()->UseNamedProxy( | 336 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 331 "foopy3:7070;foopy1:8080;foopy2:9090"); | 337 "foopy3:7070;foopy1:8080;foopy2:9090"); |
| 332 resolver->pending_requests()[0]->CompleteNow(OK); | 338 resolver->pending_requests()[0]->CompleteNow(OK); |
| 333 | 339 |
| 334 EXPECT_EQ(OK, callback3.WaitForResult()); | 340 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 335 EXPECT_FALSE(info.is_direct()); | 341 EXPECT_FALSE(info.is_direct()); |
| 336 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 342 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
| 337 | 343 |
| 338 // We fake another error. It should now try the third one. | 344 // We fake another error. It should now try the third one. |
| 339 TestCompletionCallback callback4; | 345 TestCompletionCallback callback4; |
| 340 rv = service.ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); | 346 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); |
| 341 EXPECT_EQ(OK, rv); | 347 EXPECT_EQ(OK, rv); |
| 342 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 348 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 343 | 349 |
| 344 // Fake another error, the last proxy is gone, the list should now be empty. | 350 // Fake another error, the last proxy is gone, the list should now be empty. |
| 345 TestCompletionCallback callback5; | 351 TestCompletionCallback callback5; |
| 346 rv = service.ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL); | 352 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL); |
| 347 EXPECT_EQ(OK, rv); // We try direct. | 353 EXPECT_EQ(OK, rv); // We try direct. |
| 348 EXPECT_TRUE(info.is_direct()); | 354 EXPECT_TRUE(info.is_direct()); |
| 349 | 355 |
| 350 // If it fails again, we don't have anything else to try. | 356 // If it fails again, we don't have anything else to try. |
| 351 TestCompletionCallback callback6; | 357 TestCompletionCallback callback6; |
| 352 rv = service.ReconsiderProxyAfterError(url, &info, &callback6, NULL, NULL); | 358 rv = service->ReconsiderProxyAfterError(url, &info, &callback6, NULL, NULL); |
| 353 EXPECT_EQ(ERR_FAILED, rv); | 359 EXPECT_EQ(ERR_FAILED, rv); |
| 354 | 360 |
| 355 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 361 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
| 356 } | 362 } |
| 357 | 363 |
| 358 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { | 364 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { |
| 359 // Test proxy failover when new settings are available. | 365 // Test proxy failover when new settings are available. |
| 360 | 366 |
| 361 MockProxyConfigService* config_service = | 367 MockProxyConfigService* config_service = |
| 362 new MockProxyConfigService("http://foopy/proxy.pac"); | 368 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 363 | 369 |
| 364 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 370 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 365 | 371 |
| 366 ProxyService service(config_service, resolver); | 372 scoped_refptr<ProxyService> service( |
| 373 new ProxyService(config_service, resolver)); |
| 367 | 374 |
| 368 GURL url("http://www.google.com/"); | 375 GURL url("http://www.google.com/"); |
| 369 | 376 |
| 370 // Get the proxy information. | 377 // Get the proxy information. |
| 371 ProxyInfo info; | 378 ProxyInfo info; |
| 372 TestCompletionCallback callback1; | 379 TestCompletionCallback callback1; |
| 373 int rv = service.ResolveProxy(url, &info, &callback1, NULL, NULL); | 380 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 374 EXPECT_EQ(ERR_IO_PENDING, rv); | 381 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 375 | 382 |
| 376 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 383 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 377 resolver->pending_set_pac_script_request()->pac_url()); | 384 resolver->pending_set_pac_script_request()->pac_url()); |
| 378 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 385 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 379 | 386 |
| 380 ASSERT_EQ(1u, resolver->pending_requests().size()); | 387 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 381 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 388 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 382 | 389 |
| 383 // Set the result in proxy resolver. | 390 // Set the result in proxy resolver. |
| 384 resolver->pending_requests()[0]->results()->UseNamedProxy( | 391 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 385 "foopy1:8080;foopy2:9090"); | 392 "foopy1:8080;foopy2:9090"); |
| 386 resolver->pending_requests()[0]->CompleteNow(OK); | 393 resolver->pending_requests()[0]->CompleteNow(OK); |
| 387 | 394 |
| 388 // The first item is valid. | 395 // The first item is valid. |
| 389 EXPECT_EQ(OK, callback1.WaitForResult()); | 396 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 390 EXPECT_FALSE(info.is_direct()); | 397 EXPECT_FALSE(info.is_direct()); |
| 391 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 398 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 392 | 399 |
| 393 // Fake an error on the proxy, and also a new configuration on the proxy. | 400 // Fake an error on the proxy, and also a new configuration on the proxy. |
| 394 config_service->config = ProxyConfig(); | 401 config_service->config = ProxyConfig(); |
| 395 config_service->config.pac_url = GURL("http://foopy-new/proxy.pac"); | 402 config_service->config.pac_url = GURL("http://foopy-new/proxy.pac"); |
| 396 | 403 |
| 397 TestCompletionCallback callback2; | 404 TestCompletionCallback callback2; |
| 398 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); | 405 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); |
| 399 EXPECT_EQ(ERR_IO_PENDING, rv); | 406 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 400 | 407 |
| 401 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 408 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
| 402 resolver->pending_set_pac_script_request()->pac_url()); | 409 resolver->pending_set_pac_script_request()->pac_url()); |
| 403 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 410 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 404 | 411 |
| 405 ASSERT_EQ(1u, resolver->pending_requests().size()); | 412 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 406 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 413 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 407 | 414 |
| 408 resolver->pending_requests()[0]->results()->UseNamedProxy( | 415 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 409 "foopy1:8080;foopy2:9090"); | 416 "foopy1:8080;foopy2:9090"); |
| 410 resolver->pending_requests()[0]->CompleteNow(OK); | 417 resolver->pending_requests()[0]->CompleteNow(OK); |
| 411 | 418 |
| 412 // The first proxy is still there since the configuration changed. | 419 // The first proxy is still there since the configuration changed. |
| 413 EXPECT_EQ(OK, callback2.WaitForResult()); | 420 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 414 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 421 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 415 | 422 |
| 416 // We fake another error. It should now ignore the first one. | 423 // We fake another error. It should now ignore the first one. |
| 417 TestCompletionCallback callback3; | 424 TestCompletionCallback callback3; |
| 418 rv = service.ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL); | 425 rv = service->ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL); |
| 419 EXPECT_EQ(OK, rv); | 426 EXPECT_EQ(OK, rv); |
| 420 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 427 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 421 | 428 |
| 422 // We simulate a new configuration. | 429 // We simulate a new configuration. |
| 423 config_service->config = ProxyConfig(); | 430 config_service->config = ProxyConfig(); |
| 424 config_service->config.pac_url = GURL("http://foopy-new2/proxy.pac"); | 431 config_service->config.pac_url = GURL("http://foopy-new2/proxy.pac"); |
| 425 | 432 |
| 426 // We fake another error. It should go back to the first proxy. | 433 // We fake another error. It should go back to the first proxy. |
| 427 TestCompletionCallback callback4; | 434 TestCompletionCallback callback4; |
| 428 rv = service.ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); | 435 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); |
| 429 EXPECT_EQ(ERR_IO_PENDING, rv); | 436 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 430 | 437 |
| 431 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 438 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
| 432 resolver->pending_set_pac_script_request()->pac_url()); | 439 resolver->pending_set_pac_script_request()->pac_url()); |
| 433 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 440 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 434 | 441 |
| 435 ASSERT_EQ(1u, resolver->pending_requests().size()); | 442 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 436 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 443 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 437 | 444 |
| 438 resolver->pending_requests()[0]->results()->UseNamedProxy( | 445 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 439 "foopy1:8080;foopy2:9090"); | 446 "foopy1:8080;foopy2:9090"); |
| 440 resolver->pending_requests()[0]->CompleteNow(OK); | 447 resolver->pending_requests()[0]->CompleteNow(OK); |
| 441 | 448 |
| 442 EXPECT_EQ(OK, callback4.WaitForResult()); | 449 EXPECT_EQ(OK, callback4.WaitForResult()); |
| 443 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 450 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 444 } | 451 } |
| 445 | 452 |
| 446 TEST(ProxyServiceTest, ProxyFallback_BadConfig) { | 453 TEST(ProxyServiceTest, ProxyFallback_BadConfig) { |
| 447 // Test proxy failover when the configuration is bad. | 454 // Test proxy failover when the configuration is bad. |
| 448 | 455 |
| 449 MockProxyConfigService* config_service = | 456 MockProxyConfigService* config_service = |
| 450 new MockProxyConfigService("http://foopy/proxy.pac"); | 457 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 451 | 458 |
| 452 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 459 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 453 | 460 |
| 454 ProxyService service(config_service, resolver); | 461 scoped_refptr<ProxyService> service( |
| 462 new ProxyService(config_service, resolver)); |
| 455 | 463 |
| 456 GURL url("http://www.google.com/"); | 464 GURL url("http://www.google.com/"); |
| 457 | 465 |
| 458 // Get the proxy information. | 466 // Get the proxy information. |
| 459 ProxyInfo info; | 467 ProxyInfo info; |
| 460 TestCompletionCallback callback1; | 468 TestCompletionCallback callback1; |
| 461 int rv = service.ResolveProxy(url, &info, &callback1, NULL, NULL); | 469 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); |
| 462 EXPECT_EQ(ERR_IO_PENDING, rv); | 470 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 463 | 471 |
| 464 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 472 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 465 resolver->pending_set_pac_script_request()->pac_url()); | 473 resolver->pending_set_pac_script_request()->pac_url()); |
| 466 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 474 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 467 ASSERT_EQ(1u, resolver->pending_requests().size()); | 475 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 468 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 476 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 469 | 477 |
| 470 resolver->pending_requests()[0]->results()->UseNamedProxy( | 478 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 471 "foopy1:8080;foopy2:9090"); | 479 "foopy1:8080;foopy2:9090"); |
| 472 resolver->pending_requests()[0]->CompleteNow(OK); | 480 resolver->pending_requests()[0]->CompleteNow(OK); |
| 473 | 481 |
| 474 // The first item is valid. | 482 // The first item is valid. |
| 475 EXPECT_EQ(OK, callback1.WaitForResult()); | 483 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 476 EXPECT_FALSE(info.is_direct()); | 484 EXPECT_FALSE(info.is_direct()); |
| 477 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 485 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 478 | 486 |
| 479 // Fake a proxy error. | 487 // Fake a proxy error. |
| 480 TestCompletionCallback callback2; | 488 TestCompletionCallback callback2; |
| 481 rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); | 489 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); |
| 482 EXPECT_EQ(OK, rv); | 490 EXPECT_EQ(OK, rv); |
| 483 | 491 |
| 484 // The first proxy is ignored, and the second one is selected. | 492 // The first proxy is ignored, and the second one is selected. |
| 485 EXPECT_FALSE(info.is_direct()); | 493 EXPECT_FALSE(info.is_direct()); |
| 486 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 494 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
| 487 | 495 |
| 488 // Fake a PAC failure. | 496 // Fake a PAC failure. |
| 489 ProxyInfo info2; | 497 ProxyInfo info2; |
| 490 TestCompletionCallback callback3; | 498 TestCompletionCallback callback3; |
| 491 rv = service.ResolveProxy(url, &info2, &callback3, NULL, NULL); | 499 rv = service->ResolveProxy(url, &info2, &callback3, NULL, NULL); |
| 492 EXPECT_EQ(ERR_IO_PENDING, rv); | 500 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 493 | 501 |
| 494 ASSERT_EQ(1u, resolver->pending_requests().size()); | 502 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 495 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 503 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 496 | 504 |
| 497 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 505 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 498 | 506 |
| 499 // No proxy servers are returned. It's a direct connection. | 507 // No proxy servers are returned. It's a direct connection. |
| 500 EXPECT_EQ(ERR_FAILED, callback3.WaitForResult()); | 508 EXPECT_EQ(ERR_FAILED, callback3.WaitForResult()); |
| 501 EXPECT_TRUE(info2.is_direct()); | 509 EXPECT_TRUE(info2.is_direct()); |
| 502 | 510 |
| 503 // The PAC will now be fixed and will return a proxy server. | 511 // The PAC will now be fixed and will return a proxy server. |
| 504 // It should also clear the list of bad proxies. | 512 // It should also clear the list of bad proxies. |
| 505 | 513 |
| 506 // Try to resolve, it will still return "direct" because we have no reason | 514 // Try to resolve, it will still return "direct" because we have no reason |
| 507 // to check the config since everything works. | 515 // to check the config since everything works. |
| 508 ProxyInfo info3; | 516 ProxyInfo info3; |
| 509 TestCompletionCallback callback4; | 517 TestCompletionCallback callback4; |
| 510 rv = service.ResolveProxy(url, &info3, &callback4, NULL, NULL); | 518 rv = service->ResolveProxy(url, &info3, &callback4, NULL, NULL); |
| 511 EXPECT_EQ(OK, rv); | 519 EXPECT_EQ(OK, rv); |
| 512 EXPECT_TRUE(info3.is_direct()); | 520 EXPECT_TRUE(info3.is_direct()); |
| 513 | 521 |
| 514 // But if the direct connection fails, we check if the ProxyInfo tried to | 522 // But if the direct connection fails, we check if the ProxyInfo tried to |
| 515 // resolve the proxy before, and if not (like in this case), we give the | 523 // resolve the proxy before, and if not (like in this case), we give the |
| 516 // PAC another try. | 524 // PAC another try. |
| 517 TestCompletionCallback callback5; | 525 TestCompletionCallback callback5; |
| 518 rv = service.ReconsiderProxyAfterError(url, &info3, &callback5, NULL, NULL); | 526 rv = service->ReconsiderProxyAfterError(url, &info3, &callback5, NULL, NULL); |
| 519 EXPECT_EQ(ERR_IO_PENDING, rv); | 527 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 520 | 528 |
| 521 ASSERT_EQ(1u, resolver->pending_requests().size()); | 529 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 522 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 530 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
| 523 | 531 |
| 524 resolver->pending_requests()[0]->results()->UseNamedProxy( | 532 resolver->pending_requests()[0]->results()->UseNamedProxy( |
| 525 "foopy1:8080;foopy2:9090"); | 533 "foopy1:8080;foopy2:9090"); |
| 526 resolver->pending_requests()[0]->CompleteNow(OK); | 534 resolver->pending_requests()[0]->CompleteNow(OK); |
| 527 | 535 |
| 528 // The first proxy is still there since the list of bad proxies got cleared. | 536 // The first proxy is still there since the list of bad proxies got cleared. |
| 529 EXPECT_EQ(OK, callback5.WaitForResult()); | 537 EXPECT_EQ(OK, callback5.WaitForResult()); |
| 530 EXPECT_FALSE(info3.is_direct()); | 538 EXPECT_FALSE(info3.is_direct()); |
| 531 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 539 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
| 532 } | 540 } |
| 533 | 541 |
| 534 TEST(ProxyServiceTest, ProxyBypassList) { | 542 TEST(ProxyServiceTest, ProxyBypassList) { |
| 535 // Test what happens when a proxy bypass list is specified. | 543 // Test what happens when a proxy bypass list is specified. |
| 536 | 544 |
| 537 ProxyInfo info; | 545 ProxyInfo info; |
| 538 ProxyConfig config; | 546 ProxyConfig config; |
| 539 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); | 547 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); |
| 540 config.auto_detect = false; | 548 config.auto_detect = false; |
| 541 config.proxy_bypass_local_names = true; | 549 config.proxy_bypass_local_names = true; |
| 542 | 550 |
| 543 { | 551 { |
| 544 ProxyService service(new MockProxyConfigService(config), | 552 scoped_refptr<ProxyService> service(new ProxyService( |
| 545 new MockAsyncProxyResolver()); | 553 new MockProxyConfigService(config), new MockAsyncProxyResolver())); |
| 546 GURL url("http://www.google.com/"); | 554 GURL url("http://www.google.com/"); |
| 547 // Get the proxy information. | 555 // Get the proxy information. |
| 548 TestCompletionCallback callback; | 556 TestCompletionCallback callback; |
| 549 int rv = service.ResolveProxy(url, &info, &callback, NULL, NULL); | 557 int rv = service->ResolveProxy(url, &info, &callback, NULL, NULL); |
| 550 EXPECT_EQ(OK, rv); | 558 EXPECT_EQ(OK, rv); |
| 551 EXPECT_FALSE(info.is_direct()); | 559 EXPECT_FALSE(info.is_direct()); |
| 552 } | 560 } |
| 553 | 561 |
| 554 { | 562 { |
| 555 ProxyService service(new MockProxyConfigService(config), | 563 scoped_refptr<ProxyService> service(new ProxyService( |
| 556 new MockAsyncProxyResolver()); | 564 new MockProxyConfigService(config), new MockAsyncProxyResolver())); |
| 557 GURL test_url("http://local"); | 565 GURL test_url("http://local"); |
| 558 TestCompletionCallback callback; | 566 TestCompletionCallback callback; |
| 559 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 567 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 560 EXPECT_EQ(OK, rv); | 568 EXPECT_EQ(OK, rv); |
| 561 EXPECT_TRUE(info.is_direct()); | 569 EXPECT_TRUE(info.is_direct()); |
| 562 } | 570 } |
| 563 | 571 |
| 564 config.proxy_bypass.clear(); | 572 config.proxy_bypass.clear(); |
| 565 config.proxy_bypass.push_back("*.org"); | 573 config.proxy_bypass.push_back("*.org"); |
| 566 config.proxy_bypass_local_names = true; | 574 config.proxy_bypass_local_names = true; |
| 567 { | 575 { |
| 568 ProxyService service(new MockProxyConfigService(config), | 576 scoped_refptr<ProxyService> service(new ProxyService( |
| 569 new MockAsyncProxyResolver); | 577 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 570 GURL test_url("http://www.webkit.org"); | 578 GURL test_url("http://www.webkit.org"); |
| 571 TestCompletionCallback callback; | 579 TestCompletionCallback callback; |
| 572 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 580 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 573 EXPECT_EQ(OK, rv); | 581 EXPECT_EQ(OK, rv); |
| 574 EXPECT_TRUE(info.is_direct()); | 582 EXPECT_TRUE(info.is_direct()); |
| 575 } | 583 } |
| 576 | 584 |
| 577 config.proxy_bypass.clear(); | 585 config.proxy_bypass.clear(); |
| 578 config.proxy_bypass.push_back("*.org"); | 586 config.proxy_bypass.push_back("*.org"); |
| 579 config.proxy_bypass.push_back("7*"); | 587 config.proxy_bypass.push_back("7*"); |
| 580 config.proxy_bypass_local_names = true; | 588 config.proxy_bypass_local_names = true; |
| 581 { | 589 { |
| 582 ProxyService service(new MockProxyConfigService(config), | 590 scoped_refptr<ProxyService> service(new ProxyService( |
| 583 new MockAsyncProxyResolver); | 591 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 584 GURL test_url("http://74.125.19.147"); | 592 GURL test_url("http://74.125.19.147"); |
| 585 TestCompletionCallback callback; | 593 TestCompletionCallback callback; |
| 586 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 594 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 587 EXPECT_EQ(OK, rv); | 595 EXPECT_EQ(OK, rv); |
| 588 EXPECT_TRUE(info.is_direct()); | 596 EXPECT_TRUE(info.is_direct()); |
| 589 } | 597 } |
| 590 | 598 |
| 591 config.proxy_bypass.clear(); | 599 config.proxy_bypass.clear(); |
| 592 config.proxy_bypass.push_back("*.org"); | 600 config.proxy_bypass.push_back("*.org"); |
| 593 config.proxy_bypass_local_names = true; | 601 config.proxy_bypass_local_names = true; |
| 594 { | 602 { |
| 595 ProxyService service(new MockProxyConfigService(config), | 603 scoped_refptr<ProxyService> service(new ProxyService( |
| 596 new MockAsyncProxyResolver); | 604 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 597 GURL test_url("http://www.msn.com"); | 605 GURL test_url("http://www.msn.com"); |
| 598 TestCompletionCallback callback; | 606 TestCompletionCallback callback; |
| 599 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 607 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 600 EXPECT_EQ(OK, rv); | 608 EXPECT_EQ(OK, rv); |
| 601 EXPECT_FALSE(info.is_direct()); | 609 EXPECT_FALSE(info.is_direct()); |
| 602 } | 610 } |
| 603 | 611 |
| 604 config.proxy_bypass.clear(); | 612 config.proxy_bypass.clear(); |
| 605 config.proxy_bypass.push_back("*.MSN.COM"); | 613 config.proxy_bypass.push_back("*.MSN.COM"); |
| 606 config.proxy_bypass_local_names = true; | 614 config.proxy_bypass_local_names = true; |
| 607 { | 615 { |
| 608 ProxyService service(new MockProxyConfigService(config), | 616 scoped_refptr<ProxyService> service(new ProxyService( |
| 609 new MockAsyncProxyResolver); | 617 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 610 GURL test_url("http://www.msnbc.msn.com"); | 618 GURL test_url("http://www.msnbc.msn.com"); |
| 611 TestCompletionCallback callback; | 619 TestCompletionCallback callback; |
| 612 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 620 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 613 EXPECT_EQ(OK, rv); | 621 EXPECT_EQ(OK, rv); |
| 614 EXPECT_TRUE(info.is_direct()); | 622 EXPECT_TRUE(info.is_direct()); |
| 615 } | 623 } |
| 616 | 624 |
| 617 config.proxy_bypass.clear(); | 625 config.proxy_bypass.clear(); |
| 618 config.proxy_bypass.push_back("*.msn.com"); | 626 config.proxy_bypass.push_back("*.msn.com"); |
| 619 config.proxy_bypass_local_names = true; | 627 config.proxy_bypass_local_names = true; |
| 620 { | 628 { |
| 621 ProxyService service(new MockProxyConfigService(config), | 629 scoped_refptr<ProxyService> service(new ProxyService( |
| 622 new MockAsyncProxyResolver); | 630 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 623 GURL test_url("HTTP://WWW.MSNBC.MSN.COM"); | 631 GURL test_url("HTTP://WWW.MSNBC.MSN.COM"); |
| 624 TestCompletionCallback callback; | 632 TestCompletionCallback callback; |
| 625 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 633 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 626 EXPECT_EQ(OK, rv); | 634 EXPECT_EQ(OK, rv); |
| 627 EXPECT_TRUE(info.is_direct()); | 635 EXPECT_TRUE(info.is_direct()); |
| 628 } | 636 } |
| 629 } | 637 } |
| 630 | 638 |
| 631 TEST(ProxyServiceTest, ProxyBypassListWithPorts) { | 639 TEST(ProxyServiceTest, ProxyBypassListWithPorts) { |
| 632 // Test port specification in bypass list entries. | 640 // Test port specification in bypass list entries. |
| 633 ProxyInfo info; | 641 ProxyInfo info; |
| 634 ProxyConfig config; | 642 ProxyConfig config; |
| 635 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); | 643 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); |
| 636 config.auto_detect = false; | 644 config.auto_detect = false; |
| 637 config.proxy_bypass_local_names = false; | 645 config.proxy_bypass_local_names = false; |
| 638 | 646 |
| 639 config.proxy_bypass.clear(); | 647 config.proxy_bypass.clear(); |
| 640 config.proxy_bypass.push_back("*.example.com:99"); | 648 config.proxy_bypass.push_back("*.example.com:99"); |
| 641 { | 649 { |
| 642 ProxyService service(new MockProxyConfigService(config), | 650 scoped_refptr<ProxyService> service(new ProxyService( |
| 643 new MockAsyncProxyResolver); | 651 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 644 { | 652 { |
| 645 GURL test_url("http://www.example.com:99"); | 653 GURL test_url("http://www.example.com:99"); |
| 646 TestCompletionCallback callback; | 654 TestCompletionCallback callback; |
| 647 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 655 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 648 EXPECT_EQ(OK, rv); | 656 EXPECT_EQ(OK, rv); |
| 649 EXPECT_TRUE(info.is_direct()); | 657 EXPECT_TRUE(info.is_direct()); |
| 650 } | 658 } |
| 651 { | 659 { |
| 652 GURL test_url("http://www.example.com:100"); | 660 GURL test_url("http://www.example.com:100"); |
| 653 TestCompletionCallback callback; | 661 TestCompletionCallback callback; |
| 654 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 662 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 655 EXPECT_EQ(OK, rv); | 663 EXPECT_EQ(OK, rv); |
| 656 EXPECT_FALSE(info.is_direct()); | 664 EXPECT_FALSE(info.is_direct()); |
| 657 } | 665 } |
| 658 { | 666 { |
| 659 GURL test_url("http://www.example.com"); | 667 GURL test_url("http://www.example.com"); |
| 660 TestCompletionCallback callback; | 668 TestCompletionCallback callback; |
| 661 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 669 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 662 EXPECT_EQ(OK, rv); | 670 EXPECT_EQ(OK, rv); |
| 663 EXPECT_FALSE(info.is_direct()); | 671 EXPECT_FALSE(info.is_direct()); |
| 664 } | 672 } |
| 665 } | 673 } |
| 666 | 674 |
| 667 config.proxy_bypass.clear(); | 675 config.proxy_bypass.clear(); |
| 668 config.proxy_bypass.push_back("*.example.com:80"); | 676 config.proxy_bypass.push_back("*.example.com:80"); |
| 669 { | 677 { |
| 670 ProxyService service(new MockProxyConfigService(config), | 678 scoped_refptr<ProxyService> service(new ProxyService( |
| 671 new MockAsyncProxyResolver); | 679 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 672 GURL test_url("http://www.example.com"); | 680 GURL test_url("http://www.example.com"); |
| 673 TestCompletionCallback callback; | 681 TestCompletionCallback callback; |
| 674 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 682 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 675 EXPECT_EQ(OK, rv); | 683 EXPECT_EQ(OK, rv); |
| 676 EXPECT_TRUE(info.is_direct()); | 684 EXPECT_TRUE(info.is_direct()); |
| 677 } | 685 } |
| 678 | 686 |
| 679 config.proxy_bypass.clear(); | 687 config.proxy_bypass.clear(); |
| 680 config.proxy_bypass.push_back("*.example.com"); | 688 config.proxy_bypass.push_back("*.example.com"); |
| 681 { | 689 { |
| 682 ProxyService service(new MockProxyConfigService(config), | 690 scoped_refptr<ProxyService> service(new ProxyService( |
| 683 new MockAsyncProxyResolver); | 691 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 684 GURL test_url("http://www.example.com:99"); | 692 GURL test_url("http://www.example.com:99"); |
| 685 TestCompletionCallback callback; | 693 TestCompletionCallback callback; |
| 686 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 694 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 687 EXPECT_EQ(OK, rv); | 695 EXPECT_EQ(OK, rv); |
| 688 EXPECT_TRUE(info.is_direct()); | 696 EXPECT_TRUE(info.is_direct()); |
| 689 } | 697 } |
| 690 | 698 |
| 691 // IPv6 with port. | 699 // IPv6 with port. |
| 692 config.proxy_bypass.clear(); | 700 config.proxy_bypass.clear(); |
| 693 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]:99"); | 701 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]:99"); |
| 694 { | 702 { |
| 695 ProxyService service(new MockProxyConfigService(config), | 703 scoped_refptr<ProxyService> service(new ProxyService( |
| 696 new MockAsyncProxyResolver); | 704 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 697 { | 705 { |
| 698 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); | 706 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); |
| 699 TestCompletionCallback callback; | 707 TestCompletionCallback callback; |
| 700 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 708 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 701 EXPECT_EQ(OK, rv); | 709 EXPECT_EQ(OK, rv); |
| 702 EXPECT_TRUE(info.is_direct()); | 710 EXPECT_TRUE(info.is_direct()); |
| 703 } | 711 } |
| 704 { | 712 { |
| 705 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); | 713 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); |
| 706 TestCompletionCallback callback; | 714 TestCompletionCallback callback; |
| 707 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 715 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 708 EXPECT_EQ(OK, rv); | 716 EXPECT_EQ(OK, rv); |
| 709 EXPECT_FALSE(info.is_direct()); | 717 EXPECT_FALSE(info.is_direct()); |
| 710 } | 718 } |
| 711 } | 719 } |
| 712 | 720 |
| 713 // IPv6 without port. The bypass entry ought to work without the | 721 // IPv6 without port. The bypass entry ought to work without the |
| 714 // brackets, but the bypass matching logic in ProxyService is | 722 // brackets, but the bypass matching logic in ProxyService is |
| 715 // currently limited. | 723 // currently limited. |
| 716 config.proxy_bypass.clear(); | 724 config.proxy_bypass.clear(); |
| 717 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]"); | 725 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]"); |
| 718 { | 726 { |
| 719 ProxyService service(new MockProxyConfigService(config), | 727 scoped_refptr<ProxyService> service(new ProxyService( |
| 720 new MockAsyncProxyResolver); | 728 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 721 { | 729 { |
| 722 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); | 730 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); |
| 723 TestCompletionCallback callback; | 731 TestCompletionCallback callback; |
| 724 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 732 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 725 EXPECT_EQ(OK, rv); | 733 EXPECT_EQ(OK, rv); |
| 726 EXPECT_TRUE(info.is_direct()); | 734 EXPECT_TRUE(info.is_direct()); |
| 727 } | 735 } |
| 728 { | 736 { |
| 729 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); | 737 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); |
| 730 TestCompletionCallback callback; | 738 TestCompletionCallback callback; |
| 731 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 739 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 732 EXPECT_EQ(OK, rv); | 740 EXPECT_EQ(OK, rv); |
| 733 EXPECT_TRUE(info.is_direct()); | 741 EXPECT_TRUE(info.is_direct()); |
| 734 } | 742 } |
| 735 } | 743 } |
| 736 } | 744 } |
| 737 | 745 |
| 738 TEST(ProxyServiceTest, PerProtocolProxyTests) { | 746 TEST(ProxyServiceTest, PerProtocolProxyTests) { |
| 739 ProxyConfig config; | 747 ProxyConfig config; |
| 740 config.proxy_rules.ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 748 config.proxy_rules.ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
| 741 config.auto_detect = false; | 749 config.auto_detect = false; |
| 742 { | 750 { |
| 743 ProxyService service(new MockProxyConfigService(config), | 751 scoped_refptr<ProxyService> service(new ProxyService( |
| 744 new MockAsyncProxyResolver); | 752 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 745 GURL test_url("http://www.msn.com"); | 753 GURL test_url("http://www.msn.com"); |
| 746 ProxyInfo info; | 754 ProxyInfo info; |
| 747 TestCompletionCallback callback; | 755 TestCompletionCallback callback; |
| 748 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 756 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 749 EXPECT_EQ(OK, rv); | 757 EXPECT_EQ(OK, rv); |
| 750 EXPECT_FALSE(info.is_direct()); | 758 EXPECT_FALSE(info.is_direct()); |
| 751 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 759 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 752 } | 760 } |
| 753 { | 761 { |
| 754 ProxyService service(new MockProxyConfigService(config), | 762 scoped_refptr<ProxyService> service(new ProxyService( |
| 755 new MockAsyncProxyResolver); | 763 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 756 GURL test_url("ftp://ftp.google.com"); | 764 GURL test_url("ftp://ftp.google.com"); |
| 757 ProxyInfo info; | 765 ProxyInfo info; |
| 758 TestCompletionCallback callback; | 766 TestCompletionCallback callback; |
| 759 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 767 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 760 EXPECT_EQ(OK, rv); | 768 EXPECT_EQ(OK, rv); |
| 761 EXPECT_TRUE(info.is_direct()); | 769 EXPECT_TRUE(info.is_direct()); |
| 762 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 770 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
| 763 } | 771 } |
| 764 { | 772 { |
| 765 ProxyService service(new MockProxyConfigService(config), | 773 scoped_refptr<ProxyService> service(new ProxyService( |
| 766 new MockAsyncProxyResolver); | 774 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 767 GURL test_url("https://webbranch.techcu.com"); | 775 GURL test_url("https://webbranch.techcu.com"); |
| 768 ProxyInfo info; | 776 ProxyInfo info; |
| 769 TestCompletionCallback callback; | 777 TestCompletionCallback callback; |
| 770 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 778 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 771 EXPECT_EQ(OK, rv); | 779 EXPECT_EQ(OK, rv); |
| 772 EXPECT_FALSE(info.is_direct()); | 780 EXPECT_FALSE(info.is_direct()); |
| 773 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 781 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
| 774 } | 782 } |
| 775 { | 783 { |
| 776 config.proxy_rules.ParseFromString("foopy1:8080"); | 784 config.proxy_rules.ParseFromString("foopy1:8080"); |
| 777 ProxyService service(new MockProxyConfigService(config), | 785 scoped_refptr<ProxyService> service(new ProxyService( |
| 778 new MockAsyncProxyResolver); | 786 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 779 GURL test_url("http://www.microsoft.com"); | 787 GURL test_url("http://www.microsoft.com"); |
| 780 ProxyInfo info; | 788 ProxyInfo info; |
| 781 TestCompletionCallback callback; | 789 TestCompletionCallback callback; |
| 782 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 790 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 783 EXPECT_EQ(OK, rv); | 791 EXPECT_EQ(OK, rv); |
| 784 EXPECT_FALSE(info.is_direct()); | 792 EXPECT_FALSE(info.is_direct()); |
| 785 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 793 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 786 } | 794 } |
| 787 } | 795 } |
| 788 | 796 |
| 789 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 797 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
| 790 // fall back to the SOCKS proxy. | 798 // fall back to the SOCKS proxy. |
| 791 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 799 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
| 792 ProxyConfig config; | 800 ProxyConfig config; |
| 793 config.proxy_rules.ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 801 config.proxy_rules.ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
| 794 config.auto_detect = false; | 802 config.auto_detect = false; |
| 795 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 803 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
| 796 config.proxy_rules.type); | 804 config.proxy_rules.type); |
| 797 | 805 |
| 798 { | 806 { |
| 799 ProxyService service(new MockProxyConfigService(config), | 807 scoped_refptr<ProxyService> service(new ProxyService( |
| 800 new MockAsyncProxyResolver); | 808 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 801 GURL test_url("http://www.msn.com"); | 809 GURL test_url("http://www.msn.com"); |
| 802 ProxyInfo info; | 810 ProxyInfo info; |
| 803 TestCompletionCallback callback; | 811 TestCompletionCallback callback; |
| 804 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 812 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 805 EXPECT_EQ(OK, rv); | 813 EXPECT_EQ(OK, rv); |
| 806 EXPECT_FALSE(info.is_direct()); | 814 EXPECT_FALSE(info.is_direct()); |
| 807 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 815 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 808 } | 816 } |
| 809 { | 817 { |
| 810 ProxyService service(new MockProxyConfigService(config), | 818 scoped_refptr<ProxyService> service(new ProxyService( |
| 811 new MockAsyncProxyResolver); | 819 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 812 GURL test_url("ftp://ftp.google.com"); | 820 GURL test_url("ftp://ftp.google.com"); |
| 813 ProxyInfo info; | 821 ProxyInfo info; |
| 814 TestCompletionCallback callback; | 822 TestCompletionCallback callback; |
| 815 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 823 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 816 EXPECT_EQ(OK, rv); | 824 EXPECT_EQ(OK, rv); |
| 817 EXPECT_FALSE(info.is_direct()); | 825 EXPECT_FALSE(info.is_direct()); |
| 818 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 826 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
| 819 } | 827 } |
| 820 { | 828 { |
| 821 ProxyService service(new MockProxyConfigService(config), | 829 scoped_refptr<ProxyService> service(new ProxyService( |
| 822 new MockAsyncProxyResolver); | 830 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 823 GURL test_url("https://webbranch.techcu.com"); | 831 GURL test_url("https://webbranch.techcu.com"); |
| 824 ProxyInfo info; | 832 ProxyInfo info; |
| 825 TestCompletionCallback callback; | 833 TestCompletionCallback callback; |
| 826 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 834 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 827 EXPECT_EQ(OK, rv); | 835 EXPECT_EQ(OK, rv); |
| 828 EXPECT_FALSE(info.is_direct()); | 836 EXPECT_FALSE(info.is_direct()); |
| 829 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 837 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
| 830 } | 838 } |
| 831 { | 839 { |
| 832 ProxyService service(new MockProxyConfigService(config), | 840 scoped_refptr<ProxyService> service(new ProxyService( |
| 833 new MockAsyncProxyResolver); | 841 new MockProxyConfigService(config), new MockAsyncProxyResolver)); |
| 834 GURL test_url("unknown://www.microsoft.com"); | 842 GURL test_url("unknown://www.microsoft.com"); |
| 835 ProxyInfo info; | 843 ProxyInfo info; |
| 836 TestCompletionCallback callback; | 844 TestCompletionCallback callback; |
| 837 int rv = service.ResolveProxy(test_url, &info, &callback, NULL, NULL); | 845 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); |
| 838 EXPECT_EQ(OK, rv); | 846 EXPECT_EQ(OK, rv); |
| 839 EXPECT_FALSE(info.is_direct()); | 847 EXPECT_FALSE(info.is_direct()); |
| 840 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 848 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
| 841 } | 849 } |
| 842 } | 850 } |
| 843 | 851 |
| 844 // Test cancellation of an in-progress request. | 852 // Test cancellation of an in-progress request. |
| 845 TEST(ProxyServiceTest, CancelInProgressRequest) { | 853 TEST(ProxyServiceTest, CancelInProgressRequest) { |
| 846 MockProxyConfigService* config_service = | 854 MockProxyConfigService* config_service = |
| 847 new MockProxyConfigService("http://foopy/proxy.pac"); | 855 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 848 | 856 |
| 849 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 857 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 850 | 858 |
| 851 ProxyService service(config_service, resolver); | 859 scoped_refptr<ProxyService> service( |
| 860 new ProxyService(config_service, resolver)); |
| 852 | 861 |
| 853 // Start 3 requests. | 862 // Start 3 requests. |
| 854 | 863 |
| 855 ProxyInfo info1; | 864 ProxyInfo info1; |
| 856 TestCompletionCallback callback1; | 865 TestCompletionCallback callback1; |
| 857 int rv = service.ResolveProxy( | 866 int rv = service->ResolveProxy( |
| 858 GURL("http://request1"), &info1, &callback1, NULL, NULL); | 867 GURL("http://request1"), &info1, &callback1, NULL, NULL); |
| 859 EXPECT_EQ(ERR_IO_PENDING, rv); | 868 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 860 | 869 |
| 861 // Nothing has been sent to the proxy resolver yet, since the proxy | 870 // Nothing has been sent to the proxy resolver yet, since the proxy |
| 862 // resolver has not been configured yet. | 871 // resolver has not been configured yet. |
| 863 ASSERT_EQ(0u, resolver->pending_requests().size()); | 872 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 864 | 873 |
| 865 // Successfully initialize the PAC script. | 874 // Successfully initialize the PAC script. |
| 866 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 875 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 867 resolver->pending_set_pac_script_request()->pac_url()); | 876 resolver->pending_set_pac_script_request()->pac_url()); |
| 868 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 877 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 869 | 878 |
| 870 ASSERT_EQ(1u, resolver->pending_requests().size()); | 879 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 871 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 880 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 872 | 881 |
| 873 ProxyInfo info2; | 882 ProxyInfo info2; |
| 874 TestCompletionCallback callback2; | 883 TestCompletionCallback callback2; |
| 875 ProxyService::PacRequest* request2; | 884 ProxyService::PacRequest* request2; |
| 876 rv = service.ResolveProxy( | 885 rv = service->ResolveProxy( |
| 877 GURL("http://request2"), &info2, &callback2, &request2, NULL); | 886 GURL("http://request2"), &info2, &callback2, &request2, NULL); |
| 878 EXPECT_EQ(ERR_IO_PENDING, rv); | 887 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 879 ASSERT_EQ(2u, resolver->pending_requests().size()); | 888 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 880 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 889 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
| 881 | 890 |
| 882 ProxyInfo info3; | 891 ProxyInfo info3; |
| 883 TestCompletionCallback callback3; | 892 TestCompletionCallback callback3; |
| 884 rv = service.ResolveProxy( | 893 rv = service->ResolveProxy( |
| 885 GURL("http://request3"), &info3, &callback3, NULL, NULL); | 894 GURL("http://request3"), &info3, &callback3, NULL, NULL); |
| 886 EXPECT_EQ(ERR_IO_PENDING, rv); | 895 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 887 ASSERT_EQ(3u, resolver->pending_requests().size()); | 896 ASSERT_EQ(3u, resolver->pending_requests().size()); |
| 888 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 897 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
| 889 | 898 |
| 890 // Cancel the second request | 899 // Cancel the second request |
| 891 service.CancelPacRequest(request2); | 900 service->CancelPacRequest(request2); |
| 892 | 901 |
| 893 ASSERT_EQ(2u, resolver->pending_requests().size()); | 902 ASSERT_EQ(2u, resolver->pending_requests().size()); |
| 894 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 903 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
| 895 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); | 904 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); |
| 896 | 905 |
| 897 // Complete the two un-cancelled requests. | 906 // Complete the two un-cancelled requests. |
| 898 // We complete the last one first, just to mix it up a bit. | 907 // We complete the last one first, just to mix it up a bit. |
| 899 resolver->pending_requests()[1]->results()->UseNamedProxy("request3:80"); | 908 resolver->pending_requests()[1]->results()->UseNamedProxy("request3:80"); |
| 900 resolver->pending_requests()[1]->CompleteNow(OK); | 909 resolver->pending_requests()[1]->CompleteNow(OK); |
| 901 | 910 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 915 } | 924 } |
| 916 | 925 |
| 917 // Test the initial PAC download for ProxyResolverWithoutFetch. | 926 // Test the initial PAC download for ProxyResolverWithoutFetch. |
| 918 TEST(ProxyServiceTest, InitialPACScriptDownload) { | 927 TEST(ProxyServiceTest, InitialPACScriptDownload) { |
| 919 MockProxyConfigService* config_service = | 928 MockProxyConfigService* config_service = |
| 920 new MockProxyConfigService("http://foopy/proxy.pac"); | 929 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 921 | 930 |
| 922 MockAsyncProxyResolverExpectsBytes* resolver = | 931 MockAsyncProxyResolverExpectsBytes* resolver = |
| 923 new MockAsyncProxyResolverExpectsBytes; | 932 new MockAsyncProxyResolverExpectsBytes; |
| 924 | 933 |
| 925 ProxyService service(config_service, resolver); | 934 scoped_refptr<ProxyService> service( |
| 935 new ProxyService(config_service, resolver)); |
| 926 | 936 |
| 927 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 937 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 928 service.SetProxyScriptFetcher(fetcher); | 938 service->SetProxyScriptFetcher(fetcher); |
| 929 | 939 |
| 930 // Start 3 requests. | 940 // Start 3 requests. |
| 931 | 941 |
| 932 ProxyInfo info1; | 942 ProxyInfo info1; |
| 933 TestCompletionCallback callback1; | 943 TestCompletionCallback callback1; |
| 934 int rv = service.ResolveProxy( | 944 int rv = service->ResolveProxy( |
| 935 GURL("http://request1"), &info1, &callback1, NULL, NULL); | 945 GURL("http://request1"), &info1, &callback1, NULL, NULL); |
| 936 EXPECT_EQ(ERR_IO_PENDING, rv); | 946 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 937 | 947 |
| 938 // The first request should have triggered download of PAC script. | 948 // The first request should have triggered download of PAC script. |
| 939 EXPECT_TRUE(fetcher->has_pending_request()); | 949 EXPECT_TRUE(fetcher->has_pending_request()); |
| 940 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 950 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 941 | 951 |
| 942 ProxyInfo info2; | 952 ProxyInfo info2; |
| 943 TestCompletionCallback callback2; | 953 TestCompletionCallback callback2; |
| 944 rv = service.ResolveProxy( | 954 rv = service->ResolveProxy( |
| 945 GURL("http://request2"), &info2, &callback2, NULL, NULL); | 955 GURL("http://request2"), &info2, &callback2, NULL, NULL); |
| 946 EXPECT_EQ(ERR_IO_PENDING, rv); | 956 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 947 | 957 |
| 948 ProxyInfo info3; | 958 ProxyInfo info3; |
| 949 TestCompletionCallback callback3; | 959 TestCompletionCallback callback3; |
| 950 rv = service.ResolveProxy( | 960 rv = service->ResolveProxy( |
| 951 GURL("http://request3"), &info3, &callback3, NULL, NULL); | 961 GURL("http://request3"), &info3, &callback3, NULL, NULL); |
| 952 EXPECT_EQ(ERR_IO_PENDING, rv); | 962 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 953 | 963 |
| 954 // Nothing has been sent to the resolver yet. | 964 // Nothing has been sent to the resolver yet. |
| 955 EXPECT_TRUE(resolver->pending_requests().empty()); | 965 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 956 | 966 |
| 957 // At this point the ProxyService should be waiting for the | 967 // At this point the ProxyService should be waiting for the |
| 958 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 968 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 959 // PAC script download completion. | 969 // PAC script download completion. |
| 960 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 970 fetcher->NotifyFetchCompletion(OK, "pac-v1"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 } | 1003 } |
| 994 | 1004 |
| 995 // Test cancellation of a request, while the PAC script is being fetched. | 1005 // Test cancellation of a request, while the PAC script is being fetched. |
| 996 TEST(ProxyServiceTest, CancelWhilePACFetching) { | 1006 TEST(ProxyServiceTest, CancelWhilePACFetching) { |
| 997 MockProxyConfigService* config_service = | 1007 MockProxyConfigService* config_service = |
| 998 new MockProxyConfigService("http://foopy/proxy.pac"); | 1008 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 999 | 1009 |
| 1000 MockAsyncProxyResolverExpectsBytes* resolver = | 1010 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1001 new MockAsyncProxyResolverExpectsBytes; | 1011 new MockAsyncProxyResolverExpectsBytes; |
| 1002 | 1012 |
| 1003 ProxyService service(config_service, resolver); | 1013 scoped_refptr<ProxyService> service( |
| 1014 new ProxyService(config_service, resolver)); |
| 1004 | 1015 |
| 1005 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1016 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1006 service.SetProxyScriptFetcher(fetcher); | 1017 service->SetProxyScriptFetcher(fetcher); |
| 1007 | 1018 |
| 1008 // Start 3 requests. | 1019 // Start 3 requests. |
| 1009 ProxyInfo info1; | 1020 ProxyInfo info1; |
| 1010 TestCompletionCallback callback1; | 1021 TestCompletionCallback callback1; |
| 1011 ProxyService::PacRequest* request1; | 1022 ProxyService::PacRequest* request1; |
| 1012 scoped_refptr<LoadLog> log1(new LoadLog); | 1023 scoped_refptr<LoadLog> log1(new LoadLog); |
| 1013 int rv = service.ResolveProxy( | 1024 int rv = service->ResolveProxy( |
| 1014 GURL("http://request1"), &info1, &callback1, &request1, log1); | 1025 GURL("http://request1"), &info1, &callback1, &request1, log1); |
| 1015 EXPECT_EQ(ERR_IO_PENDING, rv); | 1026 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1016 | 1027 |
| 1017 // The first request should have triggered download of PAC script. | 1028 // The first request should have triggered download of PAC script. |
| 1018 EXPECT_TRUE(fetcher->has_pending_request()); | 1029 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1019 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1030 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 1020 | 1031 |
| 1021 ProxyInfo info2; | 1032 ProxyInfo info2; |
| 1022 TestCompletionCallback callback2; | 1033 TestCompletionCallback callback2; |
| 1023 ProxyService::PacRequest* request2; | 1034 ProxyService::PacRequest* request2; |
| 1024 rv = service.ResolveProxy( | 1035 rv = service->ResolveProxy( |
| 1025 GURL("http://request2"), &info2, &callback2, &request2, NULL); | 1036 GURL("http://request2"), &info2, &callback2, &request2, NULL); |
| 1026 EXPECT_EQ(ERR_IO_PENDING, rv); | 1037 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1027 | 1038 |
| 1028 ProxyInfo info3; | 1039 ProxyInfo info3; |
| 1029 TestCompletionCallback callback3; | 1040 TestCompletionCallback callback3; |
| 1030 rv = service.ResolveProxy( | 1041 rv = service->ResolveProxy( |
| 1031 GURL("http://request3"), &info3, &callback3, NULL, NULL); | 1042 GURL("http://request3"), &info3, &callback3, NULL, NULL); |
| 1032 EXPECT_EQ(ERR_IO_PENDING, rv); | 1043 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1033 | 1044 |
| 1034 // Nothing has been sent to the resolver yet. | 1045 // Nothing has been sent to the resolver yet. |
| 1035 EXPECT_TRUE(resolver->pending_requests().empty()); | 1046 EXPECT_TRUE(resolver->pending_requests().empty()); |
| 1036 | 1047 |
| 1037 // Cancel the first 2 requests. | 1048 // Cancel the first 2 requests. |
| 1038 service.CancelPacRequest(request1); | 1049 service->CancelPacRequest(request1); |
| 1039 service.CancelPacRequest(request2); | 1050 service->CancelPacRequest(request2); |
| 1040 | 1051 |
| 1041 // At this point the ProxyService should be waiting for the | 1052 // At this point the ProxyService should be waiting for the |
| 1042 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1053 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1043 // PAC script download completion. | 1054 // PAC script download completion. |
| 1044 fetcher->NotifyFetchCompletion(OK, "pac-v1"); | 1055 fetcher->NotifyFetchCompletion(OK, "pac-v1"); |
| 1045 | 1056 |
| 1046 // Now that the PAC script is downloaded, it will have been sent to the | 1057 // Now that the PAC script is downloaded, it will have been sent to the |
| 1047 // proxy resolver. | 1058 // proxy resolver. |
| 1048 EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes()); | 1059 EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes()); |
| 1049 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1060 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1077 // Test that if auto-detect fails, we fall-back to the custom pac. | 1088 // Test that if auto-detect fails, we fall-back to the custom pac. |
| 1078 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { | 1089 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { |
| 1079 ProxyConfig config; | 1090 ProxyConfig config; |
| 1080 config.auto_detect = true; | 1091 config.auto_detect = true; |
| 1081 config.pac_url = GURL("http://foopy/proxy.pac"); | 1092 config.pac_url = GURL("http://foopy/proxy.pac"); |
| 1082 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used. | 1093 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used. |
| 1083 | 1094 |
| 1084 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1095 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1085 MockAsyncProxyResolverExpectsBytes* resolver = | 1096 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1086 new MockAsyncProxyResolverExpectsBytes; | 1097 new MockAsyncProxyResolverExpectsBytes; |
| 1087 ProxyService service(config_service, resolver); | 1098 scoped_refptr<ProxyService> service( |
| 1099 new ProxyService(config_service, resolver)); |
| 1088 | 1100 |
| 1089 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1101 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1090 service.SetProxyScriptFetcher(fetcher); | 1102 service->SetProxyScriptFetcher(fetcher); |
| 1091 | 1103 |
| 1092 // Start 2 requests. | 1104 // Start 2 requests. |
| 1093 | 1105 |
| 1094 ProxyInfo info1; | 1106 ProxyInfo info1; |
| 1095 TestCompletionCallback callback1; | 1107 TestCompletionCallback callback1; |
| 1096 int rv = service.ResolveProxy( | 1108 int rv = service->ResolveProxy( |
| 1097 GURL("http://request1"), &info1, &callback1, NULL, NULL); | 1109 GURL("http://request1"), &info1, &callback1, NULL, NULL); |
| 1098 EXPECT_EQ(ERR_IO_PENDING, rv); | 1110 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1099 | 1111 |
| 1100 ProxyInfo info2; | 1112 ProxyInfo info2; |
| 1101 TestCompletionCallback callback2; | 1113 TestCompletionCallback callback2; |
| 1102 ProxyService::PacRequest* request2; | 1114 ProxyService::PacRequest* request2; |
| 1103 rv = service.ResolveProxy( | 1115 rv = service->ResolveProxy( |
| 1104 GURL("http://request2"), &info2, &callback2, &request2, NULL); | 1116 GURL("http://request2"), &info2, &callback2, &request2, NULL); |
| 1105 EXPECT_EQ(ERR_IO_PENDING, rv); | 1117 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1106 | 1118 |
| 1107 // Check that nothing has been sent to the proxy resolver yet. | 1119 // Check that nothing has been sent to the proxy resolver yet. |
| 1108 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1120 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1109 | 1121 |
| 1110 // It should be trying to auto-detect first -- FAIL the autodetect during | 1122 // It should be trying to auto-detect first -- FAIL the autodetect during |
| 1111 // the script download. | 1123 // the script download. |
| 1112 EXPECT_TRUE(fetcher->has_pending_request()); | 1124 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1113 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1125 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 // the auto-detect script fails parsing rather than downloading. | 1159 // the auto-detect script fails parsing rather than downloading. |
| 1148 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { | 1160 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { |
| 1149 ProxyConfig config; | 1161 ProxyConfig config; |
| 1150 config.auto_detect = true; | 1162 config.auto_detect = true; |
| 1151 config.pac_url = GURL("http://foopy/proxy.pac"); | 1163 config.pac_url = GURL("http://foopy/proxy.pac"); |
| 1152 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used. | 1164 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used. |
| 1153 | 1165 |
| 1154 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1166 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1155 MockAsyncProxyResolverExpectsBytes* resolver = | 1167 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1156 new MockAsyncProxyResolverExpectsBytes; | 1168 new MockAsyncProxyResolverExpectsBytes; |
| 1157 ProxyService service(config_service, resolver); | 1169 scoped_refptr<ProxyService> service( |
| 1170 new ProxyService(config_service, resolver)); |
| 1158 | 1171 |
| 1159 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1172 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1160 service.SetProxyScriptFetcher(fetcher); | 1173 service->SetProxyScriptFetcher(fetcher); |
| 1161 | 1174 |
| 1162 // Start 2 requests. | 1175 // Start 2 requests. |
| 1163 | 1176 |
| 1164 ProxyInfo info1; | 1177 ProxyInfo info1; |
| 1165 TestCompletionCallback callback1; | 1178 TestCompletionCallback callback1; |
| 1166 int rv = service.ResolveProxy( | 1179 int rv = service->ResolveProxy( |
| 1167 GURL("http://request1"), &info1, &callback1, NULL, NULL); | 1180 GURL("http://request1"), &info1, &callback1, NULL, NULL); |
| 1168 EXPECT_EQ(ERR_IO_PENDING, rv); | 1181 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1169 | 1182 |
| 1170 ProxyInfo info2; | 1183 ProxyInfo info2; |
| 1171 TestCompletionCallback callback2; | 1184 TestCompletionCallback callback2; |
| 1172 ProxyService::PacRequest* request2; | 1185 ProxyService::PacRequest* request2; |
| 1173 rv = service.ResolveProxy( | 1186 rv = service->ResolveProxy( |
| 1174 GURL("http://request2"), &info2, &callback2, &request2, NULL); | 1187 GURL("http://request2"), &info2, &callback2, &request2, NULL); |
| 1175 EXPECT_EQ(ERR_IO_PENDING, rv); | 1188 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1176 | 1189 |
| 1177 // Check that nothing has been sent to the proxy resolver yet. | 1190 // Check that nothing has been sent to the proxy resolver yet. |
| 1178 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1191 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1179 | 1192 |
| 1180 // It should be trying to auto-detect first -- succeed the download. | 1193 // It should be trying to auto-detect first -- succeed the download. |
| 1181 EXPECT_TRUE(fetcher->has_pending_request()); | 1194 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1182 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1195 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1183 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1196 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 // are given, then we will try them in that order. | 1235 // are given, then we will try them in that order. |
| 1223 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { | 1236 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { |
| 1224 ProxyConfig config; | 1237 ProxyConfig config; |
| 1225 config.auto_detect = true; | 1238 config.auto_detect = true; |
| 1226 config.pac_url = GURL("http://foopy/proxy.pac"); | 1239 config.pac_url = GURL("http://foopy/proxy.pac"); |
| 1227 config.proxy_rules.ParseFromString("http=foopy:80"); | 1240 config.proxy_rules.ParseFromString("http=foopy:80"); |
| 1228 | 1241 |
| 1229 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1242 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1230 MockAsyncProxyResolverExpectsBytes* resolver = | 1243 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1231 new MockAsyncProxyResolverExpectsBytes; | 1244 new MockAsyncProxyResolverExpectsBytes; |
| 1232 ProxyService service(config_service, resolver); | 1245 scoped_refptr<ProxyService> service( |
| 1246 new ProxyService(config_service, resolver)); |
| 1233 | 1247 |
| 1234 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1248 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1235 service.SetProxyScriptFetcher(fetcher); | 1249 service->SetProxyScriptFetcher(fetcher); |
| 1236 | 1250 |
| 1237 // Start 2 requests. | 1251 // Start 2 requests. |
| 1238 | 1252 |
| 1239 ProxyInfo info1; | 1253 ProxyInfo info1; |
| 1240 TestCompletionCallback callback1; | 1254 TestCompletionCallback callback1; |
| 1241 int rv = service.ResolveProxy( | 1255 int rv = service->ResolveProxy( |
| 1242 GURL("http://request1"), &info1, &callback1, NULL, NULL); | 1256 GURL("http://request1"), &info1, &callback1, NULL, NULL); |
| 1243 EXPECT_EQ(ERR_IO_PENDING, rv); | 1257 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1244 | 1258 |
| 1245 ProxyInfo info2; | 1259 ProxyInfo info2; |
| 1246 TestCompletionCallback callback2; | 1260 TestCompletionCallback callback2; |
| 1247 ProxyService::PacRequest* request2; | 1261 ProxyService::PacRequest* request2; |
| 1248 rv = service.ResolveProxy( | 1262 rv = service->ResolveProxy( |
| 1249 GURL("http://request2"), &info2, &callback2, &request2, NULL); | 1263 GURL("http://request2"), &info2, &callback2, &request2, NULL); |
| 1250 EXPECT_EQ(ERR_IO_PENDING, rv); | 1264 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1251 | 1265 |
| 1252 // Check that nothing has been sent to the proxy resolver yet. | 1266 // Check that nothing has been sent to the proxy resolver yet. |
| 1253 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1267 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1254 | 1268 |
| 1255 // It should be trying to auto-detect first -- fail the download. | 1269 // It should be trying to auto-detect first -- fail the download. |
| 1256 EXPECT_TRUE(fetcher->has_pending_request()); | 1270 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1257 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1271 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1258 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); | 1272 fetcher->NotifyFetchCompletion(ERR_FAILED, ""); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1279 TEST(ProxyServiceTest, BypassDoesntApplyToPac) { | 1293 TEST(ProxyServiceTest, BypassDoesntApplyToPac) { |
| 1280 ProxyConfig config; | 1294 ProxyConfig config; |
| 1281 config.auto_detect = true; | 1295 config.auto_detect = true; |
| 1282 config.pac_url = GURL("http://foopy/proxy.pac"); | 1296 config.pac_url = GURL("http://foopy/proxy.pac"); |
| 1283 config.proxy_rules.ParseFromString("http=foopy:80"); // Not used. | 1297 config.proxy_rules.ParseFromString("http=foopy:80"); // Not used. |
| 1284 config.proxy_bypass.push_back("www.google.com"); | 1298 config.proxy_bypass.push_back("www.google.com"); |
| 1285 | 1299 |
| 1286 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1300 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1287 MockAsyncProxyResolverExpectsBytes* resolver = | 1301 MockAsyncProxyResolverExpectsBytes* resolver = |
| 1288 new MockAsyncProxyResolverExpectsBytes; | 1302 new MockAsyncProxyResolverExpectsBytes; |
| 1289 ProxyService service(config_service, resolver); | 1303 scoped_refptr<ProxyService> service( |
| 1304 new ProxyService(config_service, resolver)); |
| 1290 | 1305 |
| 1291 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1306 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1292 service.SetProxyScriptFetcher(fetcher); | 1307 service->SetProxyScriptFetcher(fetcher); |
| 1293 | 1308 |
| 1294 // Start 1 requests. | 1309 // Start 1 requests. |
| 1295 | 1310 |
| 1296 ProxyInfo info1; | 1311 ProxyInfo info1; |
| 1297 TestCompletionCallback callback1; | 1312 TestCompletionCallback callback1; |
| 1298 int rv = service.ResolveProxy( | 1313 int rv = service->ResolveProxy( |
| 1299 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); | 1314 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); |
| 1300 EXPECT_EQ(ERR_IO_PENDING, rv); | 1315 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1301 | 1316 |
| 1302 // Check that nothing has been sent to the proxy resolver yet. | 1317 // Check that nothing has been sent to the proxy resolver yet. |
| 1303 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1318 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1304 | 1319 |
| 1305 // It should be trying to auto-detect first -- succeed the download. | 1320 // It should be trying to auto-detect first -- succeed the download. |
| 1306 EXPECT_TRUE(fetcher->has_pending_request()); | 1321 EXPECT_TRUE(fetcher->has_pending_request()); |
| 1307 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1322 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 1308 fetcher->NotifyFetchCompletion(OK, "auto-detect"); | 1323 fetcher->NotifyFetchCompletion(OK, "auto-detect"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1319 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1334 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 1320 resolver->pending_requests()[0]->CompleteNow(OK); | 1335 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1321 | 1336 |
| 1322 // Verify that request ran as expected. | 1337 // Verify that request ran as expected. |
| 1323 EXPECT_EQ(OK, callback1.WaitForResult()); | 1338 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1324 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1339 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 1325 | 1340 |
| 1326 // Start another request, it should pickup the bypass item. | 1341 // Start another request, it should pickup the bypass item. |
| 1327 ProxyInfo info2; | 1342 ProxyInfo info2; |
| 1328 TestCompletionCallback callback2; | 1343 TestCompletionCallback callback2; |
| 1329 rv = service.ResolveProxy( | 1344 rv = service->ResolveProxy( |
| 1330 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); | 1345 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); |
| 1331 EXPECT_EQ(ERR_IO_PENDING, rv); | 1346 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1332 | 1347 |
| 1333 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1348 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1334 EXPECT_EQ(GURL("http://www.google.com"), | 1349 EXPECT_EQ(GURL("http://www.google.com"), |
| 1335 resolver->pending_requests()[0]->url()); | 1350 resolver->pending_requests()[0]->url()); |
| 1336 | 1351 |
| 1337 // Complete the pending request. | 1352 // Complete the pending request. |
| 1338 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 1353 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 1339 resolver->pending_requests()[0]->CompleteNow(OK); | 1354 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1340 | 1355 |
| 1341 EXPECT_EQ(OK, callback2.WaitForResult()); | 1356 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 1342 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 1357 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
| 1343 } | 1358 } |
| 1344 | 1359 |
| 1345 TEST(ProxyServiceTest, ResetProxyConfigService) { | 1360 TEST(ProxyServiceTest, ResetProxyConfigService) { |
| 1346 ProxyConfig config1; | 1361 ProxyConfig config1; |
| 1347 config1.proxy_rules.ParseFromString("foopy1:8080"); | 1362 config1.proxy_rules.ParseFromString("foopy1:8080"); |
| 1348 config1.auto_detect = false; | 1363 config1.auto_detect = false; |
| 1349 ProxyService service(new MockProxyConfigService(config1), | 1364 scoped_refptr<ProxyService> service(new ProxyService( |
| 1350 new MockAsyncProxyResolverExpectsBytes); | 1365 new MockProxyConfigService(config1), new MockAsyncProxyResolverExpectsByte
s)); |
| 1351 | 1366 |
| 1352 ProxyInfo info; | 1367 ProxyInfo info; |
| 1353 TestCompletionCallback callback1; | 1368 TestCompletionCallback callback1; |
| 1354 int rv = service.ResolveProxy( | 1369 int rv = service->ResolveProxy( |
| 1355 GURL("http://request1"), &info, &callback1, NULL, NULL); | 1370 GURL("http://request1"), &info, &callback1, NULL, NULL); |
| 1356 EXPECT_EQ(OK, rv); | 1371 EXPECT_EQ(OK, rv); |
| 1357 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1372 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1358 | 1373 |
| 1359 ProxyConfig config2; | 1374 ProxyConfig config2; |
| 1360 config2.proxy_rules.ParseFromString("foopy2:8080"); | 1375 config2.proxy_rules.ParseFromString("foopy2:8080"); |
| 1361 config2.auto_detect = false; | 1376 config2.auto_detect = false; |
| 1362 service.ResetConfigService(new MockProxyConfigService(config2)); | 1377 service->ResetConfigService(new MockProxyConfigService(config2)); |
| 1363 TestCompletionCallback callback2; | 1378 TestCompletionCallback callback2; |
| 1364 rv = service.ResolveProxy( | 1379 rv = service->ResolveProxy( |
| 1365 GURL("http://request2"), &info, &callback2, NULL, NULL); | 1380 GURL("http://request2"), &info, &callback2, NULL, NULL); |
| 1366 EXPECT_EQ(OK, rv); | 1381 EXPECT_EQ(OK, rv); |
| 1367 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1382 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
| 1368 } | 1383 } |
| 1369 | 1384 |
| 1370 TEST(ProxyServiceTest, IsLocalName) { | 1385 TEST(ProxyServiceTest, IsLocalName) { |
| 1371 const struct { | 1386 const struct { |
| 1372 const char* url; | 1387 const char* url; |
| 1373 bool expected_is_local; | 1388 bool expected_is_local; |
| 1374 } tests[] = { | 1389 } tests[] = { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 // is updated (with no change), we don't re-try the autodetect test. | 1427 // is updated (with no change), we don't re-try the autodetect test. |
| 1413 // Regression test for http://crbug.com/18526 -- the configuration was being | 1428 // Regression test for http://crbug.com/18526 -- the configuration was being |
| 1414 // mutated to cancel out the automatic settings, which meant UpdateConfig() | 1429 // mutated to cancel out the automatic settings, which meant UpdateConfig() |
| 1415 // thought it had received a new configuration. | 1430 // thought it had received a new configuration. |
| 1416 TEST(ProxyServiceTest, UpdateConfigAfterFailedAutodetect) { | 1431 TEST(ProxyServiceTest, UpdateConfigAfterFailedAutodetect) { |
| 1417 ProxyConfig config; | 1432 ProxyConfig config; |
| 1418 config.auto_detect = true; | 1433 config.auto_detect = true; |
| 1419 | 1434 |
| 1420 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1435 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1421 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1436 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 1422 ProxyService service(config_service, resolver); | 1437 scoped_refptr<ProxyService> service( |
| 1438 new ProxyService(config_service, resolver)); |
| 1423 | 1439 |
| 1424 // Start 1 requests. | 1440 // Start 1 requests. |
| 1425 | 1441 |
| 1426 ProxyInfo info1; | 1442 ProxyInfo info1; |
| 1427 TestCompletionCallback callback1; | 1443 TestCompletionCallback callback1; |
| 1428 int rv = service.ResolveProxy( | 1444 int rv = service->ResolveProxy( |
| 1429 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); | 1445 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); |
| 1430 EXPECT_EQ(ERR_IO_PENDING, rv); | 1446 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1431 | 1447 |
| 1432 // Check that nothing has been sent to the proxy resolver yet. | 1448 // Check that nothing has been sent to the proxy resolver yet. |
| 1433 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1449 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1434 | 1450 |
| 1435 // Fail the setting of autodetect script. | 1451 // Fail the setting of autodetect script. |
| 1436 EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); | 1452 EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); |
| 1437 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); | 1453 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); |
| 1438 | 1454 |
| 1439 // Verify that request ran as expected -- should have fallen back to direct. | 1455 // Verify that request ran as expected -- should have fallen back to direct. |
| 1440 EXPECT_EQ(OK, callback1.WaitForResult()); | 1456 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1441 EXPECT_TRUE(info1.is_direct()); | 1457 EXPECT_TRUE(info1.is_direct()); |
| 1442 | 1458 |
| 1443 // Force the ProxyService to pull down a new proxy configuration. | 1459 // Force the ProxyService to pull down a new proxy configuration. |
| 1444 // (Even though the configuration isn't old/bad). | 1460 // (Even though the configuration isn't old/bad). |
| 1445 service.UpdateConfig(); | 1461 service->UpdateConfig(); |
| 1446 | 1462 |
| 1447 // Start another request -- the effective configuration has not | 1463 // Start another request -- the effective configuration has not |
| 1448 // changed, so we shouldn't re-run the autodetect step. | 1464 // changed, so we shouldn't re-run the autodetect step. |
| 1449 // Rather, it should complete synchronously as direct-connect. | 1465 // Rather, it should complete synchronously as direct-connect. |
| 1450 ProxyInfo info2; | 1466 ProxyInfo info2; |
| 1451 TestCompletionCallback callback2; | 1467 TestCompletionCallback callback2; |
| 1452 rv = service.ResolveProxy( | 1468 rv = service->ResolveProxy( |
| 1453 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); | 1469 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); |
| 1454 EXPECT_EQ(OK, rv); | 1470 EXPECT_EQ(OK, rv); |
| 1455 | 1471 |
| 1456 EXPECT_TRUE(info2.is_direct()); | 1472 EXPECT_TRUE(info2.is_direct()); |
| 1457 } | 1473 } |
| 1458 | 1474 |
| 1459 // Test that when going from a configuration that required PAC to one | 1475 // Test that when going from a configuration that required PAC to one |
| 1460 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 1476 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
| 1461 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 1477 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
| 1462 ProxyConfig config; | 1478 ProxyConfig config; |
| 1463 config.auto_detect = true; | 1479 config.auto_detect = true; |
| 1464 | 1480 |
| 1465 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1481 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1466 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1482 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
| 1467 ProxyService service(config_service, resolver); | 1483 scoped_refptr<ProxyService> service( |
| 1484 new ProxyService(config_service, resolver)); |
| 1468 | 1485 |
| 1469 // Start 1 request. | 1486 // Start 1 request. |
| 1470 | 1487 |
| 1471 ProxyInfo info1; | 1488 ProxyInfo info1; |
| 1472 TestCompletionCallback callback1; | 1489 TestCompletionCallback callback1; |
| 1473 int rv = service.ResolveProxy( | 1490 int rv = service->ResolveProxy( |
| 1474 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); | 1491 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); |
| 1475 EXPECT_EQ(ERR_IO_PENDING, rv); | 1492 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1476 | 1493 |
| 1477 // Check that nothing has been sent to the proxy resolver yet. | 1494 // Check that nothing has been sent to the proxy resolver yet. |
| 1478 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1495 ASSERT_EQ(0u, resolver->pending_requests().size()); |
| 1479 | 1496 |
| 1480 // Successfully set the autodetect script. | 1497 // Successfully set the autodetect script. |
| 1481 EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); | 1498 EXPECT_EQ(GURL(), resolver->pending_set_pac_script_request()->pac_url()); |
| 1482 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1499 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
| 1483 | 1500 |
| 1484 // Complete the pending request. | 1501 // Complete the pending request. |
| 1485 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1502 ASSERT_EQ(1u, resolver->pending_requests().size()); |
| 1486 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 1503 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 1487 resolver->pending_requests()[0]->CompleteNow(OK); | 1504 resolver->pending_requests()[0]->CompleteNow(OK); |
| 1488 | 1505 |
| 1489 // Verify that request ran as expected. | 1506 // Verify that request ran as expected. |
| 1490 EXPECT_EQ(OK, callback1.WaitForResult()); | 1507 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1491 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1508 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 1492 | 1509 |
| 1493 // Force the ProxyService to pull down a new proxy configuration. | 1510 // Force the ProxyService to pull down a new proxy configuration. |
| 1494 // (Even though the configuration isn't old/bad). | 1511 // (Even though the configuration isn't old/bad). |
| 1495 // | 1512 // |
| 1496 // This new configuration no longer has auto_detect set, so | 1513 // This new configuration no longer has auto_detect set, so |
| 1497 // requests should complete synchronously now as direct-connect. | 1514 // requests should complete synchronously now as direct-connect. |
| 1498 config.auto_detect = false; | 1515 config.auto_detect = false; |
| 1499 config_service->config = config; | 1516 config_service->config = config; |
| 1500 service.UpdateConfig(); | 1517 service->UpdateConfig(); |
| 1501 | 1518 |
| 1502 // Start another request -- the effective configuration has changed. | 1519 // Start another request -- the effective configuration has changed. |
| 1503 ProxyInfo info2; | 1520 ProxyInfo info2; |
| 1504 TestCompletionCallback callback2; | 1521 TestCompletionCallback callback2; |
| 1505 rv = service.ResolveProxy( | 1522 rv = service->ResolveProxy( |
| 1506 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); | 1523 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); |
| 1507 EXPECT_EQ(OK, rv); | 1524 EXPECT_EQ(OK, rv); |
| 1508 | 1525 |
| 1509 EXPECT_TRUE(info2.is_direct()); | 1526 EXPECT_TRUE(info2.is_direct()); |
| 1510 } | 1527 } |
| 1511 | 1528 |
| 1512 } // namespace net | 1529 } // namespace net |
| OLD | NEW |