OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "net/base/load_flags.h" |
13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
14 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
15 #include "net/base/net_log_unittest.h" | 16 #include "net/base/net_log_unittest.h" |
| 17 #include "net/base/network_delegate.h" |
16 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
17 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 19 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
18 #include "net/proxy/mock_proxy_resolver.h" | 20 #include "net/proxy/mock_proxy_resolver.h" |
19 #include "net/proxy/mock_proxy_script_fetcher.h" | 21 #include "net/proxy/mock_proxy_script_fetcher.h" |
20 #include "net/proxy/proxy_config_service.h" | 22 #include "net/proxy/proxy_config_service.h" |
21 #include "net/proxy/proxy_resolver.h" | 23 #include "net/proxy/proxy_resolver.h" |
22 #include "net/proxy/proxy_script_fetcher.h" | 24 #include "net/proxy/proxy_script_fetcher.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "url/gurl.h" | 26 #include "url/gurl.h" |
25 | 27 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 FOR_EACH_OBSERVER(Observer, observers_, | 148 FOR_EACH_OBSERVER(Observer, observers_, |
147 OnProxyConfigChanged(config_, availability_)); | 149 OnProxyConfigChanged(config_, availability_)); |
148 } | 150 } |
149 | 151 |
150 private: | 152 private: |
151 ConfigAvailability availability_; | 153 ConfigAvailability availability_; |
152 ProxyConfig config_; | 154 ProxyConfig config_; |
153 ObserverList<Observer, true> observers_; | 155 ObserverList<Observer, true> observers_; |
154 }; | 156 }; |
155 | 157 |
| 158 // A test network delegate that exercises the OnResolveProxy callback. |
| 159 class TestResolveProxyNetworkDelegate : public NetworkDelegate { |
| 160 public: |
| 161 TestResolveProxyNetworkDelegate() |
| 162 : on_resolve_proxy_called_(false), |
| 163 add_proxy_(false), |
| 164 remove_proxy_(false) { |
| 165 } |
| 166 |
| 167 virtual void OnResolveProxy( |
| 168 const GURL& url, int load_flags, ProxyInfo* result) OVERRIDE { |
| 169 on_resolve_proxy_called_ = true; |
| 170 DCHECK(!add_proxy_ || !remove_proxy_); |
| 171 if (add_proxy_) { |
| 172 result->UseNamedProxy("delegate_proxy.com"); |
| 173 } else if (remove_proxy_) { |
| 174 result->UseDirect(); |
| 175 } |
| 176 } |
| 177 |
| 178 bool on_resolve_proxy_called() const { |
| 179 return on_resolve_proxy_called_; |
| 180 } |
| 181 |
| 182 void set_add_proxy(bool add_proxy) { |
| 183 add_proxy_ = add_proxy; |
| 184 } |
| 185 |
| 186 void set_remove_proxy(bool remove_proxy) { |
| 187 remove_proxy_ = remove_proxy; |
| 188 } |
| 189 |
| 190 private: |
| 191 bool on_resolve_proxy_called_; |
| 192 bool add_proxy_; |
| 193 bool remove_proxy_; |
| 194 }; |
| 195 |
156 } // namespace | 196 } // namespace |
157 | 197 |
158 TEST_F(ProxyServiceTest, Direct) { | 198 TEST_F(ProxyServiceTest, Direct) { |
159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 199 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
160 ProxyService service(new MockProxyConfigService( | 200 ProxyService service(new MockProxyConfigService( |
161 ProxyConfig::CreateDirect()), resolver, NULL); | 201 ProxyConfig::CreateDirect()), resolver, NULL); |
162 | 202 |
163 GURL url("http://www.google.com/"); | 203 GURL url("http://www.google.com/"); |
164 | 204 |
165 ProxyInfo info; | 205 ProxyInfo info; |
166 TestCompletionCallback callback; | 206 TestCompletionCallback callback; |
167 CapturingBoundNetLog log; | 207 CapturingBoundNetLog log; |
168 int rv = service.ResolveProxy( | 208 int rv = service.ResolveProxy( |
169 url, &info, callback.callback(), NULL, log.bound()); | 209 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, |
| 210 log.bound()); |
170 EXPECT_EQ(OK, rv); | 211 EXPECT_EQ(OK, rv); |
171 EXPECT_TRUE(resolver->pending_requests().empty()); | 212 EXPECT_TRUE(resolver->pending_requests().empty()); |
172 | 213 |
173 EXPECT_TRUE(info.is_direct()); | 214 EXPECT_TRUE(info.is_direct()); |
174 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 215 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
175 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 216 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
176 | 217 |
177 // Check the NetLog was filled correctly. | 218 // Check the NetLog was filled correctly. |
178 CapturingNetLog::CapturedEntryList entries; | 219 CapturingNetLog::CapturedEntryList entries; |
179 log.GetEntries(&entries); | 220 log.GetEntries(&entries); |
180 | 221 |
181 EXPECT_EQ(3u, entries.size()); | 222 EXPECT_EQ(3u, entries.size()); |
182 EXPECT_TRUE(LogContainsBeginEvent( | 223 EXPECT_TRUE(LogContainsBeginEvent( |
183 entries, 0, NetLog::TYPE_PROXY_SERVICE)); | 224 entries, 0, NetLog::TYPE_PROXY_SERVICE)); |
184 EXPECT_TRUE(LogContainsEvent( | 225 EXPECT_TRUE(LogContainsEvent( |
185 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 226 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
186 NetLog::PHASE_NONE)); | 227 NetLog::PHASE_NONE)); |
187 EXPECT_TRUE(LogContainsEndEvent( | 228 EXPECT_TRUE(LogContainsEndEvent( |
188 entries, 2, NetLog::TYPE_PROXY_SERVICE)); | 229 entries, 2, NetLog::TYPE_PROXY_SERVICE)); |
189 } | 230 } |
190 | 231 |
| 232 TEST_F(ProxyServiceTest, OnResolveProxyCallbackAddProxy) { |
| 233 ProxyConfig config; |
| 234 config.proxy_rules().ParseFromString("foopy1:8080"); |
| 235 config.set_auto_detect(false); |
| 236 config.proxy_rules().bypass_rules.ParseFromString("*.org"); |
| 237 |
| 238 ProxyService service( |
| 239 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
| 240 |
| 241 GURL url("http://www.google.com/"); |
| 242 GURL bypass_url("http://internet.org"); |
| 243 |
| 244 ProxyInfo info; |
| 245 TestCompletionCallback callback; |
| 246 CapturingBoundNetLog log; |
| 247 |
| 248 // First, warm up the ProxyService. |
| 249 int rv = service.ResolveProxy( |
| 250 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, |
| 251 log.bound()); |
| 252 EXPECT_EQ(OK, rv); |
| 253 |
| 254 // Verify that network delegate is invoked. |
| 255 TestResolveProxyNetworkDelegate delegate; |
| 256 rv = service.ResolveProxy( |
| 257 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, |
| 258 log.bound()); |
| 259 EXPECT_TRUE(delegate.on_resolve_proxy_called()); |
| 260 |
| 261 // Verify that the NetworkDelegate's behavior is stateless across |
| 262 // invocations of ResolveProxy. Start by having the callback add a proxy |
| 263 // and checking that subsequent requests are not affected. |
| 264 delegate.set_add_proxy(true); |
| 265 |
| 266 // Callback should interpose: |
| 267 rv = service.ResolveProxy( |
| 268 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, |
| 269 log.bound()); |
| 270 EXPECT_FALSE(info.is_direct()); |
| 271 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); |
| 272 delegate.set_add_proxy(false); |
| 273 |
| 274 // Check non-bypassed URL: |
| 275 rv = service.ResolveProxy( |
| 276 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, |
| 277 log.bound()); |
| 278 EXPECT_FALSE(info.is_direct()); |
| 279 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "foopy1"); |
| 280 |
| 281 // Check bypassed URL: |
| 282 rv = service.ResolveProxy( |
| 283 bypass_url, net::LOAD_NORMAL, &info, callback.callback(), NULL, |
| 284 &delegate, log.bound()); |
| 285 EXPECT_TRUE(info.is_direct()); |
| 286 } |
| 287 |
| 288 TEST_F(ProxyServiceTest, OnResolveProxyCallbackRemoveProxy) { |
| 289 // Same as OnResolveProxyCallbackAddProxy, but verify that the |
| 290 // NetworkDelegate's behavior is stateless across invocations after it |
| 291 // *removes* a proxy. |
| 292 ProxyConfig config; |
| 293 config.proxy_rules().ParseFromString("foopy1:8080"); |
| 294 config.set_auto_detect(false); |
| 295 config.proxy_rules().bypass_rules.ParseFromString("*.org"); |
| 296 |
| 297 ProxyService service( |
| 298 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
| 299 |
| 300 GURL url("http://www.google.com/"); |
| 301 GURL bypass_url("http://internet.org"); |
| 302 |
| 303 ProxyInfo info; |
| 304 TestCompletionCallback callback; |
| 305 CapturingBoundNetLog log; |
| 306 |
| 307 // First, warm up the ProxyService. |
| 308 int rv = service.ResolveProxy( |
| 309 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, |
| 310 log.bound()); |
| 311 EXPECT_EQ(OK, rv); |
| 312 |
| 313 TestResolveProxyNetworkDelegate delegate; |
| 314 delegate.set_remove_proxy(true); |
| 315 |
| 316 // Callback should interpose: |
| 317 rv = service.ResolveProxy( |
| 318 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, |
| 319 log.bound()); |
| 320 EXPECT_TRUE(info.is_direct()); |
| 321 delegate.set_remove_proxy(false); |
| 322 |
| 323 // Check non-bypassed URL: |
| 324 rv = service.ResolveProxy( |
| 325 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, &delegate, |
| 326 log.bound()); |
| 327 EXPECT_FALSE(info.is_direct()); |
| 328 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "foopy1"); |
| 329 |
| 330 // Check bypassed URL: |
| 331 rv = service.ResolveProxy( |
| 332 bypass_url, net::LOAD_NORMAL, &info, callback.callback(), NULL, |
| 333 &delegate, log.bound()); |
| 334 EXPECT_TRUE(info.is_direct()); |
| 335 } |
| 336 |
191 TEST_F(ProxyServiceTest, PAC) { | 337 TEST_F(ProxyServiceTest, PAC) { |
192 MockProxyConfigService* config_service = | 338 MockProxyConfigService* config_service = |
193 new MockProxyConfigService("http://foopy/proxy.pac"); | 339 new MockProxyConfigService("http://foopy/proxy.pac"); |
194 | 340 |
195 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 341 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
196 | 342 |
197 ProxyService service(config_service, resolver, NULL); | 343 ProxyService service(config_service, resolver, NULL); |
198 | 344 |
199 GURL url("http://www.google.com/"); | 345 GURL url("http://www.google.com/"); |
200 | 346 |
201 ProxyInfo info; | 347 ProxyInfo info; |
202 TestCompletionCallback callback; | 348 TestCompletionCallback callback; |
203 ProxyService::PacRequest* request; | 349 ProxyService::PacRequest* request; |
204 CapturingBoundNetLog log; | 350 CapturingBoundNetLog log; |
205 | 351 |
206 int rv = service.ResolveProxy( | 352 int rv = service.ResolveProxy( |
207 url, &info, callback.callback(), &request, log.bound()); | 353 url, net::LOAD_NORMAL, &info, callback.callback(), &request, NULL, |
| 354 log.bound()); |
208 EXPECT_EQ(ERR_IO_PENDING, rv); | 355 EXPECT_EQ(ERR_IO_PENDING, rv); |
209 | 356 |
210 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 357 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
211 | 358 |
212 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 359 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
213 resolver->pending_set_pac_script_request()->script_data()->url()); | 360 resolver->pending_set_pac_script_request()->script_data()->url()); |
214 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 361 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
215 | 362 |
216 ASSERT_EQ(1u, resolver->pending_requests().size()); | 363 ASSERT_EQ(1u, resolver->pending_requests().size()); |
217 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 364 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 399 |
253 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 400 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
254 | 401 |
255 ProxyService service(config_service, resolver, NULL); | 402 ProxyService service(config_service, resolver, NULL); |
256 | 403 |
257 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 404 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
258 | 405 |
259 ProxyInfo info; | 406 ProxyInfo info; |
260 TestCompletionCallback callback; | 407 TestCompletionCallback callback; |
261 int rv = service.ResolveProxy( | 408 int rv = service.ResolveProxy( |
262 url, &info, callback.callback(), NULL, BoundNetLog()); | 409 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, |
| 410 BoundNetLog()); |
263 EXPECT_EQ(ERR_IO_PENDING, rv); | 411 EXPECT_EQ(ERR_IO_PENDING, rv); |
264 | 412 |
265 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 413 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
266 resolver->pending_set_pac_script_request()->script_data()->url()); | 414 resolver->pending_set_pac_script_request()->script_data()->url()); |
267 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 415 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
268 | 416 |
269 ASSERT_EQ(1u, resolver->pending_requests().size()); | 417 ASSERT_EQ(1u, resolver->pending_requests().size()); |
270 // The URL should have been simplified, stripping the username/password/hash. | 418 // The URL should have been simplified, stripping the username/password/hash. |
271 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 419 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
272 resolver->pending_requests()[0]->url()); | 420 resolver->pending_requests()[0]->url()); |
273 | 421 |
274 // We end here without ever completing the request -- destruction of | 422 // We end here without ever completing the request -- destruction of |
275 // ProxyService will cancel the outstanding request. | 423 // ProxyService will cancel the outstanding request. |
276 } | 424 } |
277 | 425 |
278 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 426 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
279 MockProxyConfigService* config_service = | 427 MockProxyConfigService* config_service = |
280 new MockProxyConfigService("http://foopy/proxy.pac"); | 428 new MockProxyConfigService("http://foopy/proxy.pac"); |
281 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 429 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
282 | 430 |
283 ProxyService service(config_service, resolver, NULL); | 431 ProxyService service(config_service, resolver, NULL); |
284 | 432 |
285 GURL url("http://www.google.com/"); | 433 GURL url("http://www.google.com/"); |
286 | 434 |
287 ProxyInfo info; | 435 ProxyInfo info; |
288 TestCompletionCallback callback1; | 436 TestCompletionCallback callback1; |
289 int rv = service.ResolveProxy( | 437 int rv = service.ResolveProxy( |
290 url, &info, callback1.callback(), NULL, BoundNetLog()); | 438 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 439 BoundNetLog()); |
291 EXPECT_EQ(ERR_IO_PENDING, rv); | 440 EXPECT_EQ(ERR_IO_PENDING, rv); |
292 | 441 |
293 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 442 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
294 resolver->pending_set_pac_script_request()->script_data()->url()); | 443 resolver->pending_set_pac_script_request()->script_data()->url()); |
295 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 444 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
296 | 445 |
297 ASSERT_EQ(1u, resolver->pending_requests().size()); | 446 ASSERT_EQ(1u, resolver->pending_requests().size()); |
298 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 447 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
299 | 448 |
300 // Set the result in proxy resolver. | 449 // Set the result in proxy resolver. |
301 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 450 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
302 resolver->pending_requests()[0]->CompleteNow(OK); | 451 resolver->pending_requests()[0]->CompleteNow(OK); |
303 | 452 |
304 EXPECT_EQ(OK, callback1.WaitForResult()); | 453 EXPECT_EQ(OK, callback1.WaitForResult()); |
305 EXPECT_FALSE(info.is_direct()); | 454 EXPECT_FALSE(info.is_direct()); |
306 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 455 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
307 EXPECT_TRUE(info.did_use_pac_script()); | 456 EXPECT_TRUE(info.did_use_pac_script()); |
308 | 457 |
309 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 458 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
310 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 459 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
311 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 460 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
312 | 461 |
313 // Now, imagine that connecting to foopy:8080 fails: there is nothing | 462 // Now, imagine that connecting to foopy:8080 fails: there is nothing |
314 // left to fallback to, since our proxy list was NOT terminated by | 463 // left to fallback to, since our proxy list was NOT terminated by |
315 // DIRECT. | 464 // DIRECT. |
316 TestCompletionCallback callback2; | 465 TestCompletionCallback callback2; |
317 rv = service.ReconsiderProxyAfterError( | 466 rv = service.ReconsiderProxyAfterError( |
318 url, net::ERR_PROXY_CONNECTION_FAILED, | 467 url, net::LOAD_NORMAL, net::ERR_PROXY_CONNECTION_FAILED, |
319 &info, callback2.callback(), NULL, BoundNetLog()); | 468 &info, callback2.callback(), NULL, NULL, BoundNetLog()); |
320 // ReconsiderProxyAfterError returns error indicating nothing left. | 469 // ReconsiderProxyAfterError returns error indicating nothing left. |
321 EXPECT_EQ(ERR_FAILED, rv); | 470 EXPECT_EQ(ERR_FAILED, rv); |
322 EXPECT_TRUE(info.is_empty()); | 471 EXPECT_TRUE(info.is_empty()); |
323 } | 472 } |
324 | 473 |
325 // Test that if the execution of the PAC script fails (i.e. javascript runtime | 474 // Test that if the execution of the PAC script fails (i.e. javascript runtime |
326 // error), and the PAC settings are non-mandatory, that we fall-back to direct. | 475 // error), and the PAC settings are non-mandatory, that we fall-back to direct. |
327 TEST_F(ProxyServiceTest, PAC_RuntimeError) { | 476 TEST_F(ProxyServiceTest, PAC_RuntimeError) { |
328 MockProxyConfigService* config_service = | 477 MockProxyConfigService* config_service = |
329 new MockProxyConfigService("http://foopy/proxy.pac"); | 478 new MockProxyConfigService("http://foopy/proxy.pac"); |
330 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 479 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
331 | 480 |
332 ProxyService service(config_service, resolver, NULL); | 481 ProxyService service(config_service, resolver, NULL); |
333 | 482 |
334 GURL url("http://this-causes-js-error/"); | 483 GURL url("http://this-causes-js-error/"); |
335 | 484 |
336 ProxyInfo info; | 485 ProxyInfo info; |
337 TestCompletionCallback callback1; | 486 TestCompletionCallback callback1; |
338 int rv = service.ResolveProxy( | 487 int rv = service.ResolveProxy( |
339 url, &info, callback1.callback(), NULL, BoundNetLog()); | 488 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 489 BoundNetLog()); |
340 EXPECT_EQ(ERR_IO_PENDING, rv); | 490 EXPECT_EQ(ERR_IO_PENDING, rv); |
341 | 491 |
342 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 492 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
343 resolver->pending_set_pac_script_request()->script_data()->url()); | 493 resolver->pending_set_pac_script_request()->script_data()->url()); |
344 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 494 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
345 | 495 |
346 ASSERT_EQ(1u, resolver->pending_requests().size()); | 496 ASSERT_EQ(1u, resolver->pending_requests().size()); |
347 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 497 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
348 | 498 |
349 // Simulate a failure in the PAC executor. | 499 // Simulate a failure in the PAC executor. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 new MockProxyConfigService("http://foopy/proxy.pac"); | 534 new MockProxyConfigService("http://foopy/proxy.pac"); |
385 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 535 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
386 | 536 |
387 ProxyService service(config_service, resolver, NULL); | 537 ProxyService service(config_service, resolver, NULL); |
388 | 538 |
389 GURL url("http://www.google.com/"); | 539 GURL url("http://www.google.com/"); |
390 | 540 |
391 ProxyInfo info; | 541 ProxyInfo info; |
392 TestCompletionCallback callback1; | 542 TestCompletionCallback callback1; |
393 int rv = service.ResolveProxy( | 543 int rv = service.ResolveProxy( |
394 url, &info, callback1.callback(), NULL, BoundNetLog()); | 544 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 545 BoundNetLog()); |
395 EXPECT_EQ(ERR_IO_PENDING, rv); | 546 EXPECT_EQ(ERR_IO_PENDING, rv); |
396 | 547 |
397 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 548 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
398 resolver->pending_set_pac_script_request()->script_data()->url()); | 549 resolver->pending_set_pac_script_request()->script_data()->url()); |
399 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 550 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
400 | 551 |
401 ASSERT_EQ(1u, resolver->pending_requests().size()); | 552 ASSERT_EQ(1u, resolver->pending_requests().size()); |
402 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 553 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
403 | 554 |
404 // Set the result in proxy resolver. | 555 // Set the result in proxy resolver. |
405 resolver->pending_requests()[0]->results()->UsePacString( | 556 resolver->pending_requests()[0]->results()->UsePacString( |
406 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 557 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
407 resolver->pending_requests()[0]->CompleteNow(OK); | 558 resolver->pending_requests()[0]->CompleteNow(OK); |
408 | 559 |
409 EXPECT_EQ(OK, callback1.WaitForResult()); | 560 EXPECT_EQ(OK, callback1.WaitForResult()); |
410 EXPECT_TRUE(info.is_direct()); | 561 EXPECT_TRUE(info.is_direct()); |
411 | 562 |
412 // Fallback 1. | 563 // Fallback 1. |
413 TestCompletionCallback callback2; | 564 TestCompletionCallback callback2; |
414 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 565 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 566 net::ERR_PROXY_CONNECTION_FAILED, |
415 &info, callback2.callback(), NULL, | 567 &info, callback2.callback(), NULL, |
416 BoundNetLog()); | 568 NULL, BoundNetLog()); |
417 EXPECT_EQ(OK, rv); | 569 EXPECT_EQ(OK, rv); |
418 EXPECT_FALSE(info.is_direct()); | 570 EXPECT_FALSE(info.is_direct()); |
419 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); | 571 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); |
420 | 572 |
421 // Fallback 2. | 573 // Fallback 2. |
422 TestCompletionCallback callback3; | 574 TestCompletionCallback callback3; |
423 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 575 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 576 net::ERR_PROXY_CONNECTION_FAILED, |
424 &info, callback3.callback(), NULL, | 577 &info, callback3.callback(), NULL, |
425 BoundNetLog()); | 578 NULL, BoundNetLog()); |
426 EXPECT_EQ(OK, rv); | 579 EXPECT_EQ(OK, rv); |
427 EXPECT_TRUE(info.is_direct()); | 580 EXPECT_TRUE(info.is_direct()); |
428 | 581 |
429 // Fallback 3. | 582 // Fallback 3. |
430 TestCompletionCallback callback4; | 583 TestCompletionCallback callback4; |
431 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 584 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 585 net::ERR_PROXY_CONNECTION_FAILED, |
432 &info, callback4.callback(), NULL, | 586 &info, callback4.callback(), NULL, |
433 BoundNetLog()); | 587 NULL, BoundNetLog()); |
434 EXPECT_EQ(OK, rv); | 588 EXPECT_EQ(OK, rv); |
435 EXPECT_FALSE(info.is_direct()); | 589 EXPECT_FALSE(info.is_direct()); |
436 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); | 590 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); |
437 | 591 |
438 // Fallback 4 -- Nothing to fall back to! | 592 // Fallback 4 -- Nothing to fall back to! |
439 TestCompletionCallback callback5; | 593 TestCompletionCallback callback5; |
440 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 594 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 595 net::ERR_PROXY_CONNECTION_FAILED, |
441 &info, callback5.callback(), NULL, | 596 &info, callback5.callback(), NULL, |
442 BoundNetLog()); | 597 NULL, BoundNetLog()); |
443 EXPECT_EQ(ERR_FAILED, rv); | 598 EXPECT_EQ(ERR_FAILED, rv); |
444 EXPECT_TRUE(info.is_empty()); | 599 EXPECT_TRUE(info.is_empty()); |
445 } | 600 } |
446 | 601 |
447 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { | 602 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { |
448 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied | 603 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied |
449 // to ProxyInfo after the proxy is resolved via a PAC script. | 604 // to ProxyInfo after the proxy is resolved via a PAC script. |
450 ProxyConfig config = | 605 ProxyConfig config = |
451 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 606 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
452 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 607 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
453 | 608 |
454 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 609 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
455 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 610 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
456 ProxyService service(config_service, resolver, NULL); | 611 ProxyService service(config_service, resolver, NULL); |
457 | 612 |
458 // Resolve something. | 613 // Resolve something. |
459 GURL url("http://www.google.com/"); | 614 GURL url("http://www.google.com/"); |
460 ProxyInfo info; | 615 ProxyInfo info; |
461 TestCompletionCallback callback; | 616 TestCompletionCallback callback; |
462 int rv = service.ResolveProxy( | 617 int rv = service.ResolveProxy( |
463 url, &info, callback.callback(), NULL, BoundNetLog()); | 618 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, |
| 619 BoundNetLog()); |
464 ASSERT_EQ(ERR_IO_PENDING, rv); | 620 ASSERT_EQ(ERR_IO_PENDING, rv); |
465 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 621 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
466 ASSERT_EQ(1u, resolver->pending_requests().size()); | 622 ASSERT_EQ(1u, resolver->pending_requests().size()); |
467 | 623 |
468 // Set the result in proxy resolver. | 624 // Set the result in proxy resolver. |
469 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); | 625 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); |
470 resolver->pending_requests()[0]->CompleteNow(OK); | 626 resolver->pending_requests()[0]->CompleteNow(OK); |
471 | 627 |
472 EXPECT_EQ(OK, callback.WaitForResult()); | 628 EXPECT_EQ(OK, callback.WaitForResult()); |
473 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 629 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
(...skipping 14 matching lines...) Expand all Loading... |
488 | 644 |
489 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 645 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
490 | 646 |
491 ProxyService service(config_service, resolver, NULL); | 647 ProxyService service(config_service, resolver, NULL); |
492 | 648 |
493 // Start first resolve request. | 649 // Start first resolve request. |
494 GURL url("http://www.google.com/"); | 650 GURL url("http://www.google.com/"); |
495 ProxyInfo info; | 651 ProxyInfo info; |
496 TestCompletionCallback callback1; | 652 TestCompletionCallback callback1; |
497 int rv = service.ResolveProxy( | 653 int rv = service.ResolveProxy( |
498 url, &info, callback1.callback(), NULL, BoundNetLog()); | 654 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 655 BoundNetLog()); |
499 EXPECT_EQ(ERR_IO_PENDING, rv); | 656 EXPECT_EQ(ERR_IO_PENDING, rv); |
500 | 657 |
501 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 658 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
502 resolver->pending_set_pac_script_request()->script_data()->url()); | 659 resolver->pending_set_pac_script_request()->script_data()->url()); |
503 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 660 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
504 | 661 |
505 ASSERT_EQ(1u, resolver->pending_requests().size()); | 662 ASSERT_EQ(1u, resolver->pending_requests().size()); |
506 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 663 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
507 | 664 |
508 // Fail the first resolve request in MockAsyncProxyResolver. | 665 // Fail the first resolve request in MockAsyncProxyResolver. |
509 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 666 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
510 | 667 |
511 // Although the proxy resolver failed the request, ProxyService implicitly | 668 // Although the proxy resolver failed the request, ProxyService implicitly |
512 // falls-back to DIRECT. | 669 // falls-back to DIRECT. |
513 EXPECT_EQ(OK, callback1.WaitForResult()); | 670 EXPECT_EQ(OK, callback1.WaitForResult()); |
514 EXPECT_TRUE(info.is_direct()); | 671 EXPECT_TRUE(info.is_direct()); |
515 | 672 |
516 // Failed PAC executions still have proxy resolution times. | 673 // Failed PAC executions still have proxy resolution times. |
517 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 674 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
518 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 675 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
519 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 676 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
520 | 677 |
521 // The second resolve request will try to run through the proxy resolver, | 678 // The second resolve request will try to run through the proxy resolver, |
522 // regardless of whether the first request failed in it. | 679 // regardless of whether the first request failed in it. |
523 TestCompletionCallback callback2; | 680 TestCompletionCallback callback2; |
524 rv = service.ResolveProxy( | 681 rv = service.ResolveProxy( |
525 url, &info, callback2.callback(), NULL, BoundNetLog()); | 682 url, net::LOAD_NORMAL, &info, callback2.callback(), NULL, NULL, |
| 683 BoundNetLog()); |
526 EXPECT_EQ(ERR_IO_PENDING, rv); | 684 EXPECT_EQ(ERR_IO_PENDING, rv); |
527 | 685 |
528 ASSERT_EQ(1u, resolver->pending_requests().size()); | 686 ASSERT_EQ(1u, resolver->pending_requests().size()); |
529 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 687 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
530 | 688 |
531 // This time we will have the resolver succeed (perhaps the PAC script has | 689 // This time we will have the resolver succeed (perhaps the PAC script has |
532 // a dependency on the current time). | 690 // a dependency on the current time). |
533 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 691 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
534 resolver->pending_requests()[0]->CompleteNow(OK); | 692 resolver->pending_requests()[0]->CompleteNow(OK); |
535 | 693 |
(...skipping 14 matching lines...) Expand all Loading... |
550 | 708 |
551 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 709 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
552 | 710 |
553 ProxyService service(config_service, resolver, NULL); | 711 ProxyService service(config_service, resolver, NULL); |
554 | 712 |
555 // Start first resolve request. | 713 // Start first resolve request. |
556 GURL url("http://www.google.com/"); | 714 GURL url("http://www.google.com/"); |
557 ProxyInfo info; | 715 ProxyInfo info; |
558 TestCompletionCallback callback1; | 716 TestCompletionCallback callback1; |
559 int rv = service.ResolveProxy( | 717 int rv = service.ResolveProxy( |
560 url, &info, callback1.callback(), NULL, BoundNetLog()); | 718 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 719 BoundNetLog()); |
561 EXPECT_EQ(ERR_IO_PENDING, rv); | 720 EXPECT_EQ(ERR_IO_PENDING, rv); |
562 | 721 |
563 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 722 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
564 resolver->pending_set_pac_script_request()->script_data()->url()); | 723 resolver->pending_set_pac_script_request()->script_data()->url()); |
565 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); | 724 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); |
566 | 725 |
567 ASSERT_EQ(0u, resolver->pending_requests().size()); | 726 ASSERT_EQ(0u, resolver->pending_requests().size()); |
568 | 727 |
569 // As the proxy resolver failed the request and is configured for a mandatory | 728 // As the proxy resolver failed the request and is configured for a mandatory |
570 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 729 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
571 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 730 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
572 callback1.WaitForResult()); | 731 callback1.WaitForResult()); |
573 EXPECT_FALSE(info.is_direct()); | 732 EXPECT_FALSE(info.is_direct()); |
574 | 733 |
575 // As the proxy resolver failed the request and is configured for a mandatory | 734 // As the proxy resolver failed the request and is configured for a mandatory |
576 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 735 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
577 TestCompletionCallback callback2; | 736 TestCompletionCallback callback2; |
578 rv = service.ResolveProxy( | 737 rv = service.ResolveProxy( |
579 url, &info, callback2.callback(), NULL, BoundNetLog()); | 738 url, net::LOAD_NORMAL, &info, callback2.callback(), NULL, NULL, |
| 739 BoundNetLog()); |
580 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); | 740 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); |
581 EXPECT_FALSE(info.is_direct()); | 741 EXPECT_FALSE(info.is_direct()); |
582 } | 742 } |
583 | 743 |
584 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 744 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
585 // Test what happens when the ProxyResolver fails that is configured to use a | 745 // Test what happens when the ProxyResolver fails that is configured to use a |
586 // mandatory PAC script. The download of the PAC script has already | 746 // mandatory PAC script. The download of the PAC script has already |
587 // succeeded but the PAC script contains no valid javascript. | 747 // succeeded but the PAC script contains no valid javascript. |
588 | 748 |
589 ProxyConfig config( | 749 ProxyConfig config( |
590 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 750 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
591 config.set_pac_mandatory(true); | 751 config.set_pac_mandatory(true); |
592 | 752 |
593 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 753 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
594 | 754 |
595 MockAsyncProxyResolverExpectsBytes* resolver = | 755 MockAsyncProxyResolverExpectsBytes* resolver = |
596 new MockAsyncProxyResolverExpectsBytes; | 756 new MockAsyncProxyResolverExpectsBytes; |
597 | 757 |
598 ProxyService service(config_service, resolver, NULL); | 758 ProxyService service(config_service, resolver, NULL); |
599 | 759 |
600 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 760 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
601 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); | 761 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); |
602 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); | 762 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); |
603 | 763 |
604 // Start resolve request. | 764 // Start resolve request. |
605 GURL url("http://www.google.com/"); | 765 GURL url("http://www.google.com/"); |
606 ProxyInfo info; | 766 ProxyInfo info; |
607 TestCompletionCallback callback; | 767 TestCompletionCallback callback; |
608 int rv = service.ResolveProxy( | 768 int rv = service.ResolveProxy( |
609 url, &info, callback.callback(), NULL, BoundNetLog()); | 769 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, |
| 770 BoundNetLog()); |
610 EXPECT_EQ(ERR_IO_PENDING, rv); | 771 EXPECT_EQ(ERR_IO_PENDING, rv); |
611 | 772 |
612 // Check that nothing has been sent to the proxy resolver yet. | 773 // Check that nothing has been sent to the proxy resolver yet. |
613 ASSERT_EQ(0u, resolver->pending_requests().size()); | 774 ASSERT_EQ(0u, resolver->pending_requests().size()); |
614 | 775 |
615 // Downloading the PAC script succeeds. | 776 // Downloading the PAC script succeeds. |
616 EXPECT_TRUE(fetcher->has_pending_request()); | 777 EXPECT_TRUE(fetcher->has_pending_request()); |
617 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 778 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
618 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 779 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
619 | 780 |
(...skipping 22 matching lines...) Expand all Loading... |
642 | 803 |
643 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 804 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
644 | 805 |
645 ProxyService service(config_service, resolver, NULL); | 806 ProxyService service(config_service, resolver, NULL); |
646 | 807 |
647 // Start first resolve request. | 808 // Start first resolve request. |
648 GURL url("http://www.google.com/"); | 809 GURL url("http://www.google.com/"); |
649 ProxyInfo info; | 810 ProxyInfo info; |
650 TestCompletionCallback callback1; | 811 TestCompletionCallback callback1; |
651 int rv = service.ResolveProxy( | 812 int rv = service.ResolveProxy( |
652 url, &info, callback1.callback(), NULL, BoundNetLog()); | 813 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 814 BoundNetLog()); |
653 EXPECT_EQ(ERR_IO_PENDING, rv); | 815 EXPECT_EQ(ERR_IO_PENDING, rv); |
654 | 816 |
655 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 817 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
656 resolver->pending_set_pac_script_request()->script_data()->url()); | 818 resolver->pending_set_pac_script_request()->script_data()->url()); |
657 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 819 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
658 | 820 |
659 ASSERT_EQ(1u, resolver->pending_requests().size()); | 821 ASSERT_EQ(1u, resolver->pending_requests().size()); |
660 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 822 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
661 | 823 |
662 // Fail the first resolve request in MockAsyncProxyResolver. | 824 // Fail the first resolve request in MockAsyncProxyResolver. |
663 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 825 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
664 | 826 |
665 // As the proxy resolver failed the request and is configured for a mandatory | 827 // As the proxy resolver failed the request and is configured for a mandatory |
666 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 828 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
667 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 829 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
668 callback1.WaitForResult()); | 830 callback1.WaitForResult()); |
669 EXPECT_FALSE(info.is_direct()); | 831 EXPECT_FALSE(info.is_direct()); |
670 | 832 |
671 // The second resolve request will try to run through the proxy resolver, | 833 // The second resolve request will try to run through the proxy resolver, |
672 // regardless of whether the first request failed in it. | 834 // regardless of whether the first request failed in it. |
673 TestCompletionCallback callback2; | 835 TestCompletionCallback callback2; |
674 rv = service.ResolveProxy( | 836 rv = service.ResolveProxy( |
675 url, &info, callback2.callback(), NULL, BoundNetLog()); | 837 url, net::LOAD_NORMAL, &info, callback2.callback(), NULL, NULL, |
| 838 BoundNetLog()); |
676 EXPECT_EQ(ERR_IO_PENDING, rv); | 839 EXPECT_EQ(ERR_IO_PENDING, rv); |
677 | 840 |
678 ASSERT_EQ(1u, resolver->pending_requests().size()); | 841 ASSERT_EQ(1u, resolver->pending_requests().size()); |
679 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 842 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
680 | 843 |
681 // This time we will have the resolver succeed (perhaps the PAC script has | 844 // This time we will have the resolver succeed (perhaps the PAC script has |
682 // a dependency on the current time). | 845 // a dependency on the current time). |
683 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 846 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
684 resolver->pending_requests()[0]->CompleteNow(OK); | 847 resolver->pending_requests()[0]->CompleteNow(OK); |
685 | 848 |
(...skipping 12 matching lines...) Expand all Loading... |
698 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 861 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
699 | 862 |
700 ProxyService service(config_service, resolver, NULL); | 863 ProxyService service(config_service, resolver, NULL); |
701 | 864 |
702 GURL url("http://www.google.com/"); | 865 GURL url("http://www.google.com/"); |
703 | 866 |
704 // Get the proxy information. | 867 // Get the proxy information. |
705 ProxyInfo info; | 868 ProxyInfo info; |
706 TestCompletionCallback callback1; | 869 TestCompletionCallback callback1; |
707 int rv = service.ResolveProxy( | 870 int rv = service.ResolveProxy( |
708 url, &info, callback1.callback(), NULL, BoundNetLog()); | 871 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 872 BoundNetLog()); |
709 EXPECT_EQ(ERR_IO_PENDING, rv); | 873 EXPECT_EQ(ERR_IO_PENDING, rv); |
710 | 874 |
711 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 875 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
712 resolver->pending_set_pac_script_request()->script_data()->url()); | 876 resolver->pending_set_pac_script_request()->script_data()->url()); |
713 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 877 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
714 | 878 |
715 ASSERT_EQ(1u, resolver->pending_requests().size()); | 879 ASSERT_EQ(1u, resolver->pending_requests().size()); |
716 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 880 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
717 | 881 |
718 // Set the result in proxy resolver. | 882 // Set the result in proxy resolver. |
719 resolver->pending_requests()[0]->results()->UseNamedProxy( | 883 resolver->pending_requests()[0]->results()->UseNamedProxy( |
720 "foopy1:8080;foopy2:9090"); | 884 "foopy1:8080;foopy2:9090"); |
721 resolver->pending_requests()[0]->CompleteNow(OK); | 885 resolver->pending_requests()[0]->CompleteNow(OK); |
722 | 886 |
723 // The first item is valid. | 887 // The first item is valid. |
724 EXPECT_EQ(OK, callback1.WaitForResult()); | 888 EXPECT_EQ(OK, callback1.WaitForResult()); |
725 EXPECT_FALSE(info.is_direct()); | 889 EXPECT_FALSE(info.is_direct()); |
726 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 890 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
727 | 891 |
728 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 892 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
729 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 893 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
730 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 894 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
731 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); | 895 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); |
732 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); | 896 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); |
733 | 897 |
734 // Fake an error on the proxy. | 898 // Fake an error on the proxy. |
735 TestCompletionCallback callback2; | 899 TestCompletionCallback callback2; |
736 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 900 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 901 net::ERR_PROXY_CONNECTION_FAILED, |
737 &info, callback2.callback(), NULL, | 902 &info, callback2.callback(), NULL, |
738 BoundNetLog()); | 903 NULL, BoundNetLog()); |
739 EXPECT_EQ(OK, rv); | 904 EXPECT_EQ(OK, rv); |
740 | 905 |
741 // Proxy times should not have been modified by fallback. | 906 // Proxy times should not have been modified by fallback. |
742 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 907 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
743 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 908 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
744 | 909 |
745 // The second proxy should be specified. | 910 // The second proxy should be specified. |
746 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 911 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
747 // Report back that the second proxy worked. This will globally mark the | 912 // Report back that the second proxy worked. This will globally mark the |
748 // first proxy as bad. | 913 // first proxy as bad. |
749 service.ReportSuccess(info); | 914 service.ReportSuccess(info); |
750 | 915 |
751 TestCompletionCallback callback3; | 916 TestCompletionCallback callback3; |
752 rv = service.ResolveProxy( | 917 rv = service.ResolveProxy( |
753 url, &info, callback3.callback(), NULL, BoundNetLog()); | 918 url, net::LOAD_NORMAL, &info, callback3.callback(), NULL, NULL, |
| 919 BoundNetLog()); |
754 EXPECT_EQ(ERR_IO_PENDING, rv); | 920 EXPECT_EQ(ERR_IO_PENDING, rv); |
755 | 921 |
756 ASSERT_EQ(1u, resolver->pending_requests().size()); | 922 ASSERT_EQ(1u, resolver->pending_requests().size()); |
757 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 923 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
758 | 924 |
759 // Set the result in proxy resolver -- the second result is already known | 925 // Set the result in proxy resolver -- the second result is already known |
760 // to be bad, so we will not try to use it initially. | 926 // to be bad, so we will not try to use it initially. |
761 resolver->pending_requests()[0]->results()->UseNamedProxy( | 927 resolver->pending_requests()[0]->results()->UseNamedProxy( |
762 "foopy3:7070;foopy1:8080;foopy2:9090"); | 928 "foopy3:7070;foopy1:8080;foopy2:9090"); |
763 resolver->pending_requests()[0]->CompleteNow(OK); | 929 resolver->pending_requests()[0]->CompleteNow(OK); |
764 | 930 |
765 EXPECT_EQ(OK, callback3.WaitForResult()); | 931 EXPECT_EQ(OK, callback3.WaitForResult()); |
766 EXPECT_FALSE(info.is_direct()); | 932 EXPECT_FALSE(info.is_direct()); |
767 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 933 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
768 | 934 |
769 // Proxy times should have been updated, so get them again. | 935 // Proxy times should have been updated, so get them again. |
770 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 936 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
771 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 937 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
772 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 938 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
773 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 939 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
774 proxy_resolve_start_time = info.proxy_resolve_start_time(); | 940 proxy_resolve_start_time = info.proxy_resolve_start_time(); |
775 proxy_resolve_end_time = info.proxy_resolve_end_time(); | 941 proxy_resolve_end_time = info.proxy_resolve_end_time(); |
776 | 942 |
777 // We fake another error. It should now try the third one. | 943 // We fake another error. It should now try the third one. |
778 TestCompletionCallback callback4; | 944 TestCompletionCallback callback4; |
779 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 945 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 946 net::ERR_PROXY_CONNECTION_FAILED, |
780 &info, callback4.callback(), NULL, | 947 &info, callback4.callback(), NULL, |
781 BoundNetLog()); | 948 NULL, BoundNetLog()); |
782 EXPECT_EQ(OK, rv); | 949 EXPECT_EQ(OK, rv); |
783 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 950 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
784 | 951 |
785 // We fake another error. At this point we have tried all of the | 952 // We fake another error. At this point we have tried all of the |
786 // proxy servers we thought were valid; next we try the proxy server | 953 // proxy servers we thought were valid; next we try the proxy server |
787 // that was in our bad proxies map (foopy1:8080). | 954 // that was in our bad proxies map (foopy1:8080). |
788 TestCompletionCallback callback5; | 955 TestCompletionCallback callback5; |
789 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 956 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 957 net::ERR_PROXY_CONNECTION_FAILED, |
790 &info, callback5.callback(), NULL, | 958 &info, callback5.callback(), NULL, |
791 BoundNetLog()); | 959 NULL, BoundNetLog()); |
792 EXPECT_EQ(OK, rv); | 960 EXPECT_EQ(OK, rv); |
793 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 961 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
794 | 962 |
795 // Fake another error, the last proxy is gone, the list should now be empty, | 963 // Fake another error, the last proxy is gone, the list should now be empty, |
796 // so there is nothing left to try. | 964 // so there is nothing left to try. |
797 TestCompletionCallback callback6; | 965 TestCompletionCallback callback6; |
798 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 966 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 967 net::ERR_PROXY_CONNECTION_FAILED, |
799 &info, callback6.callback(), NULL, | 968 &info, callback6.callback(), NULL, |
800 BoundNetLog()); | 969 NULL, BoundNetLog()); |
801 EXPECT_EQ(ERR_FAILED, rv); | 970 EXPECT_EQ(ERR_FAILED, rv); |
802 EXPECT_FALSE(info.is_direct()); | 971 EXPECT_FALSE(info.is_direct()); |
803 EXPECT_TRUE(info.is_empty()); | 972 EXPECT_TRUE(info.is_empty()); |
804 | 973 |
805 // Proxy times should not have been modified by fallback. | 974 // Proxy times should not have been modified by fallback. |
806 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 975 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
807 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 976 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
808 | 977 |
809 // Look up proxies again | 978 // Look up proxies again |
810 TestCompletionCallback callback7; | 979 TestCompletionCallback callback7; |
811 rv = service.ResolveProxy(url, &info, callback7.callback(), NULL, | 980 rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback7.callback(), |
812 BoundNetLog()); | 981 NULL, NULL, BoundNetLog()); |
813 EXPECT_EQ(ERR_IO_PENDING, rv); | 982 EXPECT_EQ(ERR_IO_PENDING, rv); |
814 | 983 |
815 ASSERT_EQ(1u, resolver->pending_requests().size()); | 984 ASSERT_EQ(1u, resolver->pending_requests().size()); |
816 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 985 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
817 | 986 |
818 // This time, the first 3 results have been found to be bad, but only the | 987 // This time, the first 3 results have been found to be bad, but only the |
819 // first proxy has been confirmed ... | 988 // first proxy has been confirmed ... |
820 resolver->pending_requests()[0]->results()->UseNamedProxy( | 989 resolver->pending_requests()[0]->results()->UseNamedProxy( |
821 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 990 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
822 resolver->pending_requests()[0]->CompleteNow(OK); | 991 resolver->pending_requests()[0]->CompleteNow(OK); |
(...skipping 18 matching lines...) Expand all Loading... |
841 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1010 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
842 | 1011 |
843 ProxyService service(config_service, resolver, NULL); | 1012 ProxyService service(config_service, resolver, NULL); |
844 | 1013 |
845 GURL url("http://www.google.com/"); | 1014 GURL url("http://www.google.com/"); |
846 | 1015 |
847 // Get the proxy information. | 1016 // Get the proxy information. |
848 ProxyInfo info; | 1017 ProxyInfo info; |
849 TestCompletionCallback callback1; | 1018 TestCompletionCallback callback1; |
850 int rv = service.ResolveProxy( | 1019 int rv = service.ResolveProxy( |
851 url, &info, callback1.callback(), NULL, BoundNetLog()); | 1020 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 1021 BoundNetLog()); |
852 EXPECT_EQ(ERR_IO_PENDING, rv); | 1022 EXPECT_EQ(ERR_IO_PENDING, rv); |
853 | 1023 |
854 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1024 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
855 resolver->pending_set_pac_script_request()->script_data()->url()); | 1025 resolver->pending_set_pac_script_request()->script_data()->url()); |
856 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1026 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
857 | 1027 |
858 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1028 ASSERT_EQ(1u, resolver->pending_requests().size()); |
859 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1029 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
860 | 1030 |
861 // Set the result in proxy resolver. | 1031 // Set the result in proxy resolver. |
862 resolver->pending_requests()[0]->results()->UsePacString( | 1032 resolver->pending_requests()[0]->results()->UsePacString( |
863 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 1033 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
864 resolver->pending_requests()[0]->CompleteNow(OK); | 1034 resolver->pending_requests()[0]->CompleteNow(OK); |
865 | 1035 |
866 // Get the first result. | 1036 // Get the first result. |
867 EXPECT_EQ(OK, callback1.WaitForResult()); | 1037 EXPECT_EQ(OK, callback1.WaitForResult()); |
868 EXPECT_FALSE(info.is_direct()); | 1038 EXPECT_FALSE(info.is_direct()); |
869 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1039 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
870 | 1040 |
871 // Fake an error on the proxy. | 1041 // Fake an error on the proxy. |
872 TestCompletionCallback callback2; | 1042 TestCompletionCallback callback2; |
873 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1043 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1044 net::ERR_PROXY_CONNECTION_FAILED, |
874 &info, callback2.callback(), NULL, | 1045 &info, callback2.callback(), NULL, |
875 BoundNetLog()); | 1046 NULL, BoundNetLog()); |
876 EXPECT_EQ(OK, rv); | 1047 EXPECT_EQ(OK, rv); |
877 | 1048 |
878 // Now we get back the second proxy. | 1049 // Now we get back the second proxy. |
879 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1050 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
880 | 1051 |
881 // Fake an error on this proxy as well. | 1052 // Fake an error on this proxy as well. |
882 TestCompletionCallback callback3; | 1053 TestCompletionCallback callback3; |
883 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1054 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1055 net::ERR_PROXY_CONNECTION_FAILED, |
884 &info, callback3.callback(), NULL, | 1056 &info, callback3.callback(), NULL, |
885 BoundNetLog()); | 1057 NULL, BoundNetLog()); |
886 EXPECT_EQ(OK, rv); | 1058 EXPECT_EQ(OK, rv); |
887 | 1059 |
888 // Finally, we get back DIRECT. | 1060 // Finally, we get back DIRECT. |
889 EXPECT_TRUE(info.is_direct()); | 1061 EXPECT_TRUE(info.is_direct()); |
890 | 1062 |
891 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1063 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
892 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1064 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
893 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1065 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
894 | 1066 |
895 // Now we tell the proxy service that even DIRECT failed. | 1067 // Now we tell the proxy service that even DIRECT failed. |
896 TestCompletionCallback callback4; | 1068 TestCompletionCallback callback4; |
897 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1069 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1070 net::ERR_PROXY_CONNECTION_FAILED, |
898 &info, callback4.callback(), NULL, | 1071 &info, callback4.callback(), NULL, |
899 BoundNetLog()); | 1072 NULL, BoundNetLog()); |
900 // There was nothing left to try after DIRECT, so we are out of | 1073 // There was nothing left to try after DIRECT, so we are out of |
901 // choices. | 1074 // choices. |
902 EXPECT_EQ(ERR_FAILED, rv); | 1075 EXPECT_EQ(ERR_FAILED, rv); |
903 } | 1076 } |
904 | 1077 |
905 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { | 1078 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { |
906 // Test proxy failover when new settings are available. | 1079 // Test proxy failover when new settings are available. |
907 | 1080 |
908 MockProxyConfigService* config_service = | 1081 MockProxyConfigService* config_service = |
909 new MockProxyConfigService("http://foopy/proxy.pac"); | 1082 new MockProxyConfigService("http://foopy/proxy.pac"); |
910 | 1083 |
911 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1084 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
912 | 1085 |
913 ProxyService service(config_service, resolver, NULL); | 1086 ProxyService service(config_service, resolver, NULL); |
914 | 1087 |
915 GURL url("http://www.google.com/"); | 1088 GURL url("http://www.google.com/"); |
916 | 1089 |
917 // Get the proxy information. | 1090 // Get the proxy information. |
918 ProxyInfo info; | 1091 ProxyInfo info; |
919 TestCompletionCallback callback1; | 1092 TestCompletionCallback callback1; |
920 int rv = service.ResolveProxy( | 1093 int rv = service.ResolveProxy( |
921 url, &info, callback1.callback(), NULL, BoundNetLog()); | 1094 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 1095 BoundNetLog()); |
922 EXPECT_EQ(ERR_IO_PENDING, rv); | 1096 EXPECT_EQ(ERR_IO_PENDING, rv); |
923 | 1097 |
924 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1098 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
925 resolver->pending_set_pac_script_request()->script_data()->url()); | 1099 resolver->pending_set_pac_script_request()->script_data()->url()); |
926 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1100 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
927 | 1101 |
928 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1102 ASSERT_EQ(1u, resolver->pending_requests().size()); |
929 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1103 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
930 | 1104 |
931 // Set the result in proxy resolver. | 1105 // Set the result in proxy resolver. |
932 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1106 resolver->pending_requests()[0]->results()->UseNamedProxy( |
933 "foopy1:8080;foopy2:9090"); | 1107 "foopy1:8080;foopy2:9090"); |
934 resolver->pending_requests()[0]->CompleteNow(OK); | 1108 resolver->pending_requests()[0]->CompleteNow(OK); |
935 | 1109 |
936 // The first item is valid. | 1110 // The first item is valid. |
937 EXPECT_EQ(OK, callback1.WaitForResult()); | 1111 EXPECT_EQ(OK, callback1.WaitForResult()); |
938 EXPECT_FALSE(info.is_direct()); | 1112 EXPECT_FALSE(info.is_direct()); |
939 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1113 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
940 | 1114 |
941 // Fake an error on the proxy, and also a new configuration on the proxy. | 1115 // Fake an error on the proxy, and also a new configuration on the proxy. |
942 config_service->SetConfig( | 1116 config_service->SetConfig( |
943 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 1117 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
944 | 1118 |
945 TestCompletionCallback callback2; | 1119 TestCompletionCallback callback2; |
946 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1120 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1121 net::ERR_PROXY_CONNECTION_FAILED, |
947 &info, callback2.callback(), NULL, | 1122 &info, callback2.callback(), NULL, |
948 BoundNetLog()); | 1123 NULL, BoundNetLog()); |
949 EXPECT_EQ(ERR_IO_PENDING, rv); | 1124 EXPECT_EQ(ERR_IO_PENDING, rv); |
950 | 1125 |
951 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 1126 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
952 resolver->pending_set_pac_script_request()->script_data()->url()); | 1127 resolver->pending_set_pac_script_request()->script_data()->url()); |
953 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1128 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
954 | 1129 |
955 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1130 ASSERT_EQ(1u, resolver->pending_requests().size()); |
956 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1131 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
957 | 1132 |
958 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1133 resolver->pending_requests()[0]->results()->UseNamedProxy( |
959 "foopy1:8080;foopy2:9090"); | 1134 "foopy1:8080;foopy2:9090"); |
960 resolver->pending_requests()[0]->CompleteNow(OK); | 1135 resolver->pending_requests()[0]->CompleteNow(OK); |
961 | 1136 |
962 // The first proxy is still there since the configuration changed. | 1137 // The first proxy is still there since the configuration changed. |
963 EXPECT_EQ(OK, callback2.WaitForResult()); | 1138 EXPECT_EQ(OK, callback2.WaitForResult()); |
964 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1139 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
965 | 1140 |
966 // We fake another error. It should now ignore the first one. | 1141 // We fake another error. It should now ignore the first one. |
967 TestCompletionCallback callback3; | 1142 TestCompletionCallback callback3; |
968 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1143 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1144 net::ERR_PROXY_CONNECTION_FAILED, |
969 &info, callback3.callback(), NULL, | 1145 &info, callback3.callback(), NULL, |
970 BoundNetLog()); | 1146 NULL, BoundNetLog()); |
971 EXPECT_EQ(OK, rv); | 1147 EXPECT_EQ(OK, rv); |
972 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1148 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
973 | 1149 |
974 // We simulate a new configuration. | 1150 // We simulate a new configuration. |
975 config_service->SetConfig( | 1151 config_service->SetConfig( |
976 ProxyConfig::CreateFromCustomPacURL( | 1152 ProxyConfig::CreateFromCustomPacURL( |
977 GURL("http://foopy-new2/proxy.pac"))); | 1153 GURL("http://foopy-new2/proxy.pac"))); |
978 | 1154 |
979 // We fake another error. It should go back to the first proxy. | 1155 // We fake another error. It should go back to the first proxy. |
980 TestCompletionCallback callback4; | 1156 TestCompletionCallback callback4; |
981 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1157 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1158 net::ERR_PROXY_CONNECTION_FAILED, |
982 &info, callback4.callback(), NULL, | 1159 &info, callback4.callback(), NULL, |
983 BoundNetLog()); | 1160 NULL, BoundNetLog()); |
984 EXPECT_EQ(ERR_IO_PENDING, rv); | 1161 EXPECT_EQ(ERR_IO_PENDING, rv); |
985 | 1162 |
986 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 1163 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
987 resolver->pending_set_pac_script_request()->script_data()->url()); | 1164 resolver->pending_set_pac_script_request()->script_data()->url()); |
988 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1165 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
989 | 1166 |
990 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1167 ASSERT_EQ(1u, resolver->pending_requests().size()); |
991 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1168 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
992 | 1169 |
993 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1170 resolver->pending_requests()[0]->results()->UseNamedProxy( |
(...skipping 17 matching lines...) Expand all Loading... |
1011 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1188 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1012 | 1189 |
1013 ProxyService service(config_service, resolver, NULL); | 1190 ProxyService service(config_service, resolver, NULL); |
1014 | 1191 |
1015 GURL url("http://www.google.com/"); | 1192 GURL url("http://www.google.com/"); |
1016 | 1193 |
1017 // Get the proxy information. | 1194 // Get the proxy information. |
1018 ProxyInfo info; | 1195 ProxyInfo info; |
1019 TestCompletionCallback callback1; | 1196 TestCompletionCallback callback1; |
1020 int rv = service.ResolveProxy( | 1197 int rv = service.ResolveProxy( |
1021 url, &info, callback1.callback(), NULL, BoundNetLog()); | 1198 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 1199 BoundNetLog()); |
1022 EXPECT_EQ(ERR_IO_PENDING, rv); | 1200 EXPECT_EQ(ERR_IO_PENDING, rv); |
1023 | 1201 |
1024 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1202 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1025 resolver->pending_set_pac_script_request()->script_data()->url()); | 1203 resolver->pending_set_pac_script_request()->script_data()->url()); |
1026 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1204 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1027 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1205 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1028 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1206 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1029 | 1207 |
1030 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1208 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1031 "foopy1:8080;foopy2:9090"); | 1209 "foopy1:8080;foopy2:9090"); |
1032 resolver->pending_requests()[0]->CompleteNow(OK); | 1210 resolver->pending_requests()[0]->CompleteNow(OK); |
1033 | 1211 |
1034 // The first item is valid. | 1212 // The first item is valid. |
1035 EXPECT_EQ(OK, callback1.WaitForResult()); | 1213 EXPECT_EQ(OK, callback1.WaitForResult()); |
1036 EXPECT_FALSE(info.is_direct()); | 1214 EXPECT_FALSE(info.is_direct()); |
1037 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1215 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1038 | 1216 |
1039 // Fake a proxy error. | 1217 // Fake a proxy error. |
1040 TestCompletionCallback callback2; | 1218 TestCompletionCallback callback2; |
1041 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1219 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1220 net::ERR_PROXY_CONNECTION_FAILED, |
1042 &info, callback2.callback(), NULL, | 1221 &info, callback2.callback(), NULL, |
1043 BoundNetLog()); | 1222 NULL, BoundNetLog()); |
1044 EXPECT_EQ(OK, rv); | 1223 EXPECT_EQ(OK, rv); |
1045 | 1224 |
1046 // The first proxy is ignored, and the second one is selected. | 1225 // The first proxy is ignored, and the second one is selected. |
1047 EXPECT_FALSE(info.is_direct()); | 1226 EXPECT_FALSE(info.is_direct()); |
1048 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1227 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1049 | 1228 |
1050 // Fake a PAC failure. | 1229 // Fake a PAC failure. |
1051 ProxyInfo info2; | 1230 ProxyInfo info2; |
1052 TestCompletionCallback callback3; | 1231 TestCompletionCallback callback3; |
1053 rv = service.ResolveProxy( | 1232 rv = service.ResolveProxy( |
1054 url, &info2, callback3.callback(), NULL, BoundNetLog()); | 1233 url, net::LOAD_NORMAL, &info2, callback3.callback(), NULL, NULL, |
| 1234 BoundNetLog()); |
1055 EXPECT_EQ(ERR_IO_PENDING, rv); | 1235 EXPECT_EQ(ERR_IO_PENDING, rv); |
1056 | 1236 |
1057 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1237 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1058 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1238 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1059 | 1239 |
1060 // This simulates a javascript runtime error in the PAC script. | 1240 // This simulates a javascript runtime error in the PAC script. |
1061 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 1241 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
1062 | 1242 |
1063 // Although the resolver failed, the ProxyService will implicitly fall-back | 1243 // Although the resolver failed, the ProxyService will implicitly fall-back |
1064 // to a DIRECT connection. | 1244 // to a DIRECT connection. |
1065 EXPECT_EQ(OK, callback3.WaitForResult()); | 1245 EXPECT_EQ(OK, callback3.WaitForResult()); |
1066 EXPECT_TRUE(info2.is_direct()); | 1246 EXPECT_TRUE(info2.is_direct()); |
1067 EXPECT_FALSE(info2.is_empty()); | 1247 EXPECT_FALSE(info2.is_empty()); |
1068 | 1248 |
1069 // The PAC script will work properly next time and successfully return a | 1249 // The PAC script will work properly next time and successfully return a |
1070 // proxy list. Since we have not marked the configuration as bad, it should | 1250 // proxy list. Since we have not marked the configuration as bad, it should |
1071 // "just work" the next time we call it. | 1251 // "just work" the next time we call it. |
1072 ProxyInfo info3; | 1252 ProxyInfo info3; |
1073 TestCompletionCallback callback4; | 1253 TestCompletionCallback callback4; |
1074 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1254 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1255 net::ERR_PROXY_CONNECTION_FAILED, |
1075 &info3, callback4.callback(), | 1256 &info3, callback4.callback(), |
1076 NULL, BoundNetLog()); | 1257 NULL, NULL, BoundNetLog()); |
1077 EXPECT_EQ(ERR_IO_PENDING, rv); | 1258 EXPECT_EQ(ERR_IO_PENDING, rv); |
1078 | 1259 |
1079 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1260 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1080 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1261 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1081 | 1262 |
1082 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1263 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1083 "foopy1:8080;foopy2:9090"); | 1264 "foopy1:8080;foopy2:9090"); |
1084 resolver->pending_requests()[0]->CompleteNow(OK); | 1265 resolver->pending_requests()[0]->CompleteNow(OK); |
1085 | 1266 |
1086 // The first proxy is not there since the it was added to the bad proxies | 1267 // The first proxy is not there since the it was added to the bad proxies |
(...skipping 19 matching lines...) Expand all Loading... |
1106 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1287 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1107 | 1288 |
1108 ProxyService service(config_service, resolver, NULL); | 1289 ProxyService service(config_service, resolver, NULL); |
1109 | 1290 |
1110 GURL url("http://www.google.com/"); | 1291 GURL url("http://www.google.com/"); |
1111 | 1292 |
1112 // Get the proxy information. | 1293 // Get the proxy information. |
1113 ProxyInfo info; | 1294 ProxyInfo info; |
1114 TestCompletionCallback callback1; | 1295 TestCompletionCallback callback1; |
1115 int rv = service.ResolveProxy( | 1296 int rv = service.ResolveProxy( |
1116 url, &info, callback1.callback(), NULL, BoundNetLog()); | 1297 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, |
| 1298 BoundNetLog()); |
1117 EXPECT_EQ(ERR_IO_PENDING, rv); | 1299 EXPECT_EQ(ERR_IO_PENDING, rv); |
1118 | 1300 |
1119 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1301 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1120 resolver->pending_set_pac_script_request()->script_data()->url()); | 1302 resolver->pending_set_pac_script_request()->script_data()->url()); |
1121 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1303 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1122 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1304 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1123 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1305 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1124 | 1306 |
1125 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1307 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1126 "foopy1:8080;foopy2:9090"); | 1308 "foopy1:8080;foopy2:9090"); |
1127 resolver->pending_requests()[0]->CompleteNow(OK); | 1309 resolver->pending_requests()[0]->CompleteNow(OK); |
1128 | 1310 |
1129 // The first item is valid. | 1311 // The first item is valid. |
1130 EXPECT_EQ(OK, callback1.WaitForResult()); | 1312 EXPECT_EQ(OK, callback1.WaitForResult()); |
1131 EXPECT_FALSE(info.is_direct()); | 1313 EXPECT_FALSE(info.is_direct()); |
1132 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1314 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1133 | 1315 |
1134 // Fake a proxy error. | 1316 // Fake a proxy error. |
1135 TestCompletionCallback callback2; | 1317 TestCompletionCallback callback2; |
1136 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1318 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1319 net::ERR_PROXY_CONNECTION_FAILED, |
1137 &info, callback2.callback(), NULL, | 1320 &info, callback2.callback(), NULL, |
1138 BoundNetLog()); | 1321 NULL, BoundNetLog()); |
1139 EXPECT_EQ(OK, rv); | 1322 EXPECT_EQ(OK, rv); |
1140 | 1323 |
1141 // The first proxy is ignored, and the second one is selected. | 1324 // The first proxy is ignored, and the second one is selected. |
1142 EXPECT_FALSE(info.is_direct()); | 1325 EXPECT_FALSE(info.is_direct()); |
1143 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1326 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1144 | 1327 |
1145 // Fake a PAC failure. | 1328 // Fake a PAC failure. |
1146 ProxyInfo info2; | 1329 ProxyInfo info2; |
1147 TestCompletionCallback callback3; | 1330 TestCompletionCallback callback3; |
1148 rv = service.ResolveProxy( | 1331 rv = service.ResolveProxy( |
1149 url, &info2, callback3.callback(), NULL, BoundNetLog()); | 1332 url, net::LOAD_NORMAL, &info2, callback3.callback(), NULL, NULL, |
| 1333 BoundNetLog()); |
1150 EXPECT_EQ(ERR_IO_PENDING, rv); | 1334 EXPECT_EQ(ERR_IO_PENDING, rv); |
1151 | 1335 |
1152 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1336 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1153 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1337 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1154 | 1338 |
1155 // This simulates a javascript runtime error in the PAC script. | 1339 // This simulates a javascript runtime error in the PAC script. |
1156 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); | 1340 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); |
1157 | 1341 |
1158 // Although the resolver failed, the ProxyService will NOT fall-back | 1342 // Although the resolver failed, the ProxyService will NOT fall-back |
1159 // to a DIRECT connection as it is configured as mandatory. | 1343 // to a DIRECT connection as it is configured as mandatory. |
1160 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1344 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1161 callback3.WaitForResult()); | 1345 callback3.WaitForResult()); |
1162 EXPECT_FALSE(info2.is_direct()); | 1346 EXPECT_FALSE(info2.is_direct()); |
1163 EXPECT_TRUE(info2.is_empty()); | 1347 EXPECT_TRUE(info2.is_empty()); |
1164 | 1348 |
1165 // The PAC script will work properly next time and successfully return a | 1349 // The PAC script will work properly next time and successfully return a |
1166 // proxy list. Since we have not marked the configuration as bad, it should | 1350 // proxy list. Since we have not marked the configuration as bad, it should |
1167 // "just work" the next time we call it. | 1351 // "just work" the next time we call it. |
1168 ProxyInfo info3; | 1352 ProxyInfo info3; |
1169 TestCompletionCallback callback4; | 1353 TestCompletionCallback callback4; |
1170 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, | 1354 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, |
| 1355 net::ERR_PROXY_CONNECTION_FAILED, |
1171 &info3, callback4.callback(), | 1356 &info3, callback4.callback(), |
1172 NULL, BoundNetLog()); | 1357 NULL, NULL, BoundNetLog()); |
1173 EXPECT_EQ(ERR_IO_PENDING, rv); | 1358 EXPECT_EQ(ERR_IO_PENDING, rv); |
1174 | 1359 |
1175 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1360 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1176 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); | 1361 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); |
1177 | 1362 |
1178 resolver->pending_requests()[0]->results()->UseNamedProxy( | 1363 resolver->pending_requests()[0]->results()->UseNamedProxy( |
1179 "foopy1:8080;foopy2:9090"); | 1364 "foopy1:8080;foopy2:9090"); |
1180 resolver->pending_requests()[0]->CompleteNow(OK); | 1365 resolver->pending_requests()[0]->CompleteNow(OK); |
1181 | 1366 |
1182 // The first proxy is not there since the it was added to the bad proxies | 1367 // The first proxy is not there since the it was added to the bad proxies |
(...skipping 15 matching lines...) Expand all Loading... |
1198 | 1383 |
1199 ProxyService service( | 1384 ProxyService service( |
1200 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1385 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1201 | 1386 |
1202 int rv; | 1387 int rv; |
1203 GURL url1("http://www.webkit.org"); | 1388 GURL url1("http://www.webkit.org"); |
1204 GURL url2("http://www.webkit.com"); | 1389 GURL url2("http://www.webkit.com"); |
1205 | 1390 |
1206 // Request for a .org domain should bypass proxy. | 1391 // Request for a .org domain should bypass proxy. |
1207 rv = service.ResolveProxy( | 1392 rv = service.ResolveProxy( |
1208 url1, &info[0], callback[0].callback(), NULL, BoundNetLog()); | 1393 url1, net::LOAD_NORMAL, &info[0], callback[0].callback(), NULL, NULL, |
| 1394 BoundNetLog()); |
1209 EXPECT_EQ(OK, rv); | 1395 EXPECT_EQ(OK, rv); |
1210 EXPECT_TRUE(info[0].is_direct()); | 1396 EXPECT_TRUE(info[0].is_direct()); |
1211 | 1397 |
1212 // Request for a .com domain hits the proxy. | 1398 // Request for a .com domain hits the proxy. |
1213 rv = service.ResolveProxy( | 1399 rv = service.ResolveProxy( |
1214 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); | 1400 url2, net::LOAD_NORMAL, &info[1], callback[1].callback(), NULL, NULL, |
| 1401 BoundNetLog()); |
1215 EXPECT_EQ(OK, rv); | 1402 EXPECT_EQ(OK, rv); |
1216 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1403 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
1217 } | 1404 } |
1218 | 1405 |
1219 | 1406 |
1220 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { | 1407 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { |
1221 ProxyConfig config; | 1408 ProxyConfig config; |
1222 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 1409 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
1223 config.set_auto_detect(false); | 1410 config.set_auto_detect(false); |
1224 { | 1411 { |
1225 ProxyService service( | 1412 ProxyService service( |
1226 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1413 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1227 GURL test_url("http://www.msn.com"); | 1414 GURL test_url("http://www.msn.com"); |
1228 ProxyInfo info; | 1415 ProxyInfo info; |
1229 TestCompletionCallback callback; | 1416 TestCompletionCallback callback; |
1230 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1417 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
| 1418 callback.callback(), NULL, NULL, |
1231 BoundNetLog()); | 1419 BoundNetLog()); |
1232 EXPECT_EQ(OK, rv); | 1420 EXPECT_EQ(OK, rv); |
1233 EXPECT_FALSE(info.is_direct()); | 1421 EXPECT_FALSE(info.is_direct()); |
1234 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1422 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1235 } | 1423 } |
1236 { | 1424 { |
1237 ProxyService service( | 1425 ProxyService service( |
1238 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1426 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1239 GURL test_url("ftp://ftp.google.com"); | 1427 GURL test_url("ftp://ftp.google.com"); |
1240 ProxyInfo info; | 1428 ProxyInfo info; |
1241 TestCompletionCallback callback; | 1429 TestCompletionCallback callback; |
1242 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1430 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1243 BoundNetLog()); | 1431 callback.callback(), NULL, |
| 1432 NULL, BoundNetLog()); |
1244 EXPECT_EQ(OK, rv); | 1433 EXPECT_EQ(OK, rv); |
1245 EXPECT_TRUE(info.is_direct()); | 1434 EXPECT_TRUE(info.is_direct()); |
1246 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 1435 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
1247 } | 1436 } |
1248 { | 1437 { |
1249 ProxyService service( | 1438 ProxyService service( |
1250 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1439 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1251 GURL test_url("https://webbranch.techcu.com"); | 1440 GURL test_url("https://webbranch.techcu.com"); |
1252 ProxyInfo info; | 1441 ProxyInfo info; |
1253 TestCompletionCallback callback; | 1442 TestCompletionCallback callback; |
1254 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1443 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1255 BoundNetLog()); | 1444 callback.callback(), NULL, |
| 1445 NULL, BoundNetLog()); |
1256 EXPECT_EQ(OK, rv); | 1446 EXPECT_EQ(OK, rv); |
1257 EXPECT_FALSE(info.is_direct()); | 1447 EXPECT_FALSE(info.is_direct()); |
1258 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1448 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1259 } | 1449 } |
1260 { | 1450 { |
1261 config.proxy_rules().ParseFromString("foopy1:8080"); | 1451 config.proxy_rules().ParseFromString("foopy1:8080"); |
1262 ProxyService service( | 1452 ProxyService service( |
1263 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1453 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1264 GURL test_url("http://www.microsoft.com"); | 1454 GURL test_url("http://www.microsoft.com"); |
1265 ProxyInfo info; | 1455 ProxyInfo info; |
1266 TestCompletionCallback callback; | 1456 TestCompletionCallback callback; |
1267 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1457 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1268 BoundNetLog()); | 1458 callback.callback(), NULL, |
| 1459 NULL, BoundNetLog()); |
1269 EXPECT_EQ(OK, rv); | 1460 EXPECT_EQ(OK, rv); |
1270 EXPECT_FALSE(info.is_direct()); | 1461 EXPECT_FALSE(info.is_direct()); |
1271 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1462 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1272 } | 1463 } |
1273 } | 1464 } |
1274 | 1465 |
1275 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { | 1466 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { |
1276 // Test that the proxy config source is set correctly when resolving proxies | 1467 // Test that the proxy config source is set correctly when resolving proxies |
1277 // using manual proxy rules. Namely, the config source should only be set if | 1468 // using manual proxy rules. Namely, the config source should only be set if |
1278 // any of the rules were applied. | 1469 // any of the rules were applied. |
1279 { | 1470 { |
1280 ProxyConfig config; | 1471 ProxyConfig config; |
1281 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1472 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1282 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1473 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1283 ProxyService service( | 1474 ProxyService service( |
1284 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1475 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1285 GURL test_url("http://www.google.com"); | 1476 GURL test_url("http://www.google.com"); |
1286 ProxyInfo info; | 1477 ProxyInfo info; |
1287 TestCompletionCallback callback; | 1478 TestCompletionCallback callback; |
1288 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1479 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1289 BoundNetLog()); | 1480 callback.callback(), NULL, |
| 1481 NULL, BoundNetLog()); |
1290 ASSERT_EQ(OK, rv); | 1482 ASSERT_EQ(OK, rv); |
1291 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. | 1483 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. |
1292 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1484 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1293 } | 1485 } |
1294 { | 1486 { |
1295 ProxyConfig config; | 1487 ProxyConfig config; |
1296 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1488 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1297 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1489 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1298 ProxyService service( | 1490 ProxyService service( |
1299 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1491 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1300 GURL test_url("https://www.google.com"); | 1492 GURL test_url("https://www.google.com"); |
1301 ProxyInfo info; | 1493 ProxyInfo info; |
1302 TestCompletionCallback callback; | 1494 TestCompletionCallback callback; |
1303 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1495 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1304 BoundNetLog()); | 1496 callback.callback(), NULL, |
| 1497 NULL, BoundNetLog()); |
1305 ASSERT_EQ(OK, rv); | 1498 ASSERT_EQ(OK, rv); |
1306 // Used the HTTPS proxy. So source should be TEST. | 1499 // Used the HTTPS proxy. So source should be TEST. |
1307 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1500 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1308 } | 1501 } |
1309 { | 1502 { |
1310 ProxyConfig config; | 1503 ProxyConfig config; |
1311 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1504 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1312 ProxyService service( | 1505 ProxyService service( |
1313 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1506 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1314 GURL test_url("http://www.google.com"); | 1507 GURL test_url("http://www.google.com"); |
1315 ProxyInfo info; | 1508 ProxyInfo info; |
1316 TestCompletionCallback callback; | 1509 TestCompletionCallback callback; |
1317 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1510 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1318 BoundNetLog()); | 1511 callback.callback(), NULL, |
| 1512 NULL, BoundNetLog()); |
1319 ASSERT_EQ(OK, rv); | 1513 ASSERT_EQ(OK, rv); |
1320 // ProxyConfig is empty. Source should still be TEST. | 1514 // ProxyConfig is empty. Source should still be TEST. |
1321 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1515 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1322 } | 1516 } |
1323 } | 1517 } |
1324 | 1518 |
1325 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1519 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
1326 // fall back to the SOCKS proxy. | 1520 // fall back to the SOCKS proxy. |
1327 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1521 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
1328 ProxyConfig config; | 1522 ProxyConfig config; |
1329 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1523 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
1330 config.set_auto_detect(false); | 1524 config.set_auto_detect(false); |
1331 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1525 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
1332 config.proxy_rules().type); | 1526 config.proxy_rules().type); |
1333 | 1527 |
1334 { | 1528 { |
1335 ProxyService service( | 1529 ProxyService service( |
1336 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1530 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1337 GURL test_url("http://www.msn.com"); | 1531 GURL test_url("http://www.msn.com"); |
1338 ProxyInfo info; | 1532 ProxyInfo info; |
1339 TestCompletionCallback callback; | 1533 TestCompletionCallback callback; |
1340 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1534 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1341 BoundNetLog()); | 1535 callback.callback(), NULL, |
| 1536 NULL, BoundNetLog()); |
1342 EXPECT_EQ(OK, rv); | 1537 EXPECT_EQ(OK, rv); |
1343 EXPECT_FALSE(info.is_direct()); | 1538 EXPECT_FALSE(info.is_direct()); |
1344 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1539 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1345 } | 1540 } |
1346 { | 1541 { |
1347 ProxyService service( | 1542 ProxyService service( |
1348 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1543 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1349 GURL test_url("ftp://ftp.google.com"); | 1544 GURL test_url("ftp://ftp.google.com"); |
1350 ProxyInfo info; | 1545 ProxyInfo info; |
1351 TestCompletionCallback callback; | 1546 TestCompletionCallback callback; |
1352 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1547 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1353 BoundNetLog()); | 1548 callback.callback(), NULL, |
| 1549 NULL, BoundNetLog()); |
1354 EXPECT_EQ(OK, rv); | 1550 EXPECT_EQ(OK, rv); |
1355 EXPECT_FALSE(info.is_direct()); | 1551 EXPECT_FALSE(info.is_direct()); |
1356 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1552 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1357 } | 1553 } |
1358 { | 1554 { |
1359 ProxyService service( | 1555 ProxyService service( |
1360 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1556 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1361 GURL test_url("https://webbranch.techcu.com"); | 1557 GURL test_url("https://webbranch.techcu.com"); |
1362 ProxyInfo info; | 1558 ProxyInfo info; |
1363 TestCompletionCallback callback; | 1559 TestCompletionCallback callback; |
1364 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1560 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1365 BoundNetLog()); | 1561 callback.callback(), NULL, |
| 1562 NULL, BoundNetLog()); |
1366 EXPECT_EQ(OK, rv); | 1563 EXPECT_EQ(OK, rv); |
1367 EXPECT_FALSE(info.is_direct()); | 1564 EXPECT_FALSE(info.is_direct()); |
1368 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1565 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1369 } | 1566 } |
1370 { | 1567 { |
1371 ProxyService service( | 1568 ProxyService service( |
1372 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); | 1569 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); |
1373 GURL test_url("unknown://www.microsoft.com"); | 1570 GURL test_url("unknown://www.microsoft.com"); |
1374 ProxyInfo info; | 1571 ProxyInfo info; |
1375 TestCompletionCallback callback; | 1572 TestCompletionCallback callback; |
1376 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, | 1573 int rv = service.ResolveProxy(test_url, net::LOAD_NORMAL, &info, |
1377 BoundNetLog()); | 1574 callback.callback(), NULL, |
| 1575 NULL, BoundNetLog()); |
1378 EXPECT_EQ(OK, rv); | 1576 EXPECT_EQ(OK, rv); |
1379 EXPECT_FALSE(info.is_direct()); | 1577 EXPECT_FALSE(info.is_direct()); |
1380 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1578 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1381 } | 1579 } |
1382 } | 1580 } |
1383 | 1581 |
1384 // Test cancellation of an in-progress request. | 1582 // Test cancellation of an in-progress request. |
1385 TEST_F(ProxyServiceTest, CancelInProgressRequest) { | 1583 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
1386 MockProxyConfigService* config_service = | 1584 MockProxyConfigService* config_service = |
1387 new MockProxyConfigService("http://foopy/proxy.pac"); | 1585 new MockProxyConfigService("http://foopy/proxy.pac"); |
1388 | 1586 |
1389 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 1587 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
1390 | 1588 |
1391 ProxyService service(config_service, resolver, NULL); | 1589 ProxyService service(config_service, resolver, NULL); |
1392 | 1590 |
1393 // Start 3 requests. | 1591 // Start 3 requests. |
1394 | 1592 |
1395 ProxyInfo info1; | 1593 ProxyInfo info1; |
1396 TestCompletionCallback callback1; | 1594 TestCompletionCallback callback1; |
1397 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1595 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
1398 callback1.callback(), NULL, BoundNetLog()); | 1596 &info1, callback1.callback(), NULL, NULL, |
| 1597 BoundNetLog()); |
1399 EXPECT_EQ(ERR_IO_PENDING, rv); | 1598 EXPECT_EQ(ERR_IO_PENDING, rv); |
1400 | 1599 |
1401 // Nothing has been sent to the proxy resolver yet, since the proxy | 1600 // Nothing has been sent to the proxy resolver yet, since the proxy |
1402 // resolver has not been configured yet. | 1601 // resolver has not been configured yet. |
1403 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1602 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1404 | 1603 |
1405 // Successfully initialize the PAC script. | 1604 // Successfully initialize the PAC script. |
1406 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1605 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1407 resolver->pending_set_pac_script_request()->script_data()->url()); | 1606 resolver->pending_set_pac_script_request()->script_data()->url()); |
1408 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 1607 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1409 | 1608 |
1410 ASSERT_EQ(1u, resolver->pending_requests().size()); | 1609 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1411 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1610 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1412 | 1611 |
1413 ProxyInfo info2; | 1612 ProxyInfo info2; |
1414 TestCompletionCallback callback2; | 1613 TestCompletionCallback callback2; |
1415 ProxyService::PacRequest* request2; | 1614 ProxyService::PacRequest* request2; |
1416 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1615 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, |
1417 callback2.callback(), &request2, BoundNetLog()); | 1616 callback2.callback(), &request2, NULL, |
| 1617 BoundNetLog()); |
1418 EXPECT_EQ(ERR_IO_PENDING, rv); | 1618 EXPECT_EQ(ERR_IO_PENDING, rv); |
1419 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1619 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1420 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); | 1620 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); |
1421 | 1621 |
1422 ProxyInfo info3; | 1622 ProxyInfo info3; |
1423 TestCompletionCallback callback3; | 1623 TestCompletionCallback callback3; |
1424 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1624 rv = service.ResolveProxy(GURL("http://request3"), net::LOAD_NORMAL, &info3, |
1425 callback3.callback(), NULL, BoundNetLog()); | 1625 callback3.callback(), NULL, NULL, BoundNetLog()); |
1426 EXPECT_EQ(ERR_IO_PENDING, rv); | 1626 EXPECT_EQ(ERR_IO_PENDING, rv); |
1427 ASSERT_EQ(3u, resolver->pending_requests().size()); | 1627 ASSERT_EQ(3u, resolver->pending_requests().size()); |
1428 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); | 1628 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); |
1429 | 1629 |
1430 // Cancel the second request | 1630 // Cancel the second request |
1431 service.CancelPacRequest(request2); | 1631 service.CancelPacRequest(request2); |
1432 | 1632 |
1433 ASSERT_EQ(2u, resolver->pending_requests().size()); | 1633 ASSERT_EQ(2u, resolver->pending_requests().size()); |
1434 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); | 1634 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); |
1435 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); | 1635 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); |
(...skipping 30 matching lines...) Expand all Loading... |
1466 | 1666 |
1467 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1667 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1468 service.SetProxyScriptFetchers(fetcher, | 1668 service.SetProxyScriptFetchers(fetcher, |
1469 new DoNothingDhcpProxyScriptFetcher()); | 1669 new DoNothingDhcpProxyScriptFetcher()); |
1470 | 1670 |
1471 // Start 3 requests. | 1671 // Start 3 requests. |
1472 | 1672 |
1473 ProxyInfo info1; | 1673 ProxyInfo info1; |
1474 TestCompletionCallback callback1; | 1674 TestCompletionCallback callback1; |
1475 ProxyService::PacRequest* request1; | 1675 ProxyService::PacRequest* request1; |
1476 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1676 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
1477 callback1.callback(), &request1, BoundNetLog()); | 1677 &info1, callback1.callback(), &request1, NULL, |
| 1678 BoundNetLog()); |
1478 EXPECT_EQ(ERR_IO_PENDING, rv); | 1679 EXPECT_EQ(ERR_IO_PENDING, rv); |
1479 | 1680 |
1480 // The first request should have triggered download of PAC script. | 1681 // The first request should have triggered download of PAC script. |
1481 EXPECT_TRUE(fetcher->has_pending_request()); | 1682 EXPECT_TRUE(fetcher->has_pending_request()); |
1482 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1683 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1483 | 1684 |
1484 ProxyInfo info2; | 1685 ProxyInfo info2; |
1485 TestCompletionCallback callback2; | 1686 TestCompletionCallback callback2; |
1486 ProxyService::PacRequest* request2; | 1687 ProxyService::PacRequest* request2; |
1487 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1688 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, |
1488 callback2.callback(), &request2, BoundNetLog()); | 1689 callback2.callback(), &request2, NULL, |
| 1690 BoundNetLog()); |
1489 EXPECT_EQ(ERR_IO_PENDING, rv); | 1691 EXPECT_EQ(ERR_IO_PENDING, rv); |
1490 | 1692 |
1491 ProxyInfo info3; | 1693 ProxyInfo info3; |
1492 TestCompletionCallback callback3; | 1694 TestCompletionCallback callback3; |
1493 ProxyService::PacRequest* request3; | 1695 ProxyService::PacRequest* request3; |
1494 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1696 rv = service.ResolveProxy(GURL("http://request3"), net::LOAD_NORMAL, &info3, |
1495 callback3.callback(), &request3, BoundNetLog()); | 1697 callback3.callback(), &request3, NULL, |
| 1698 BoundNetLog()); |
1496 EXPECT_EQ(ERR_IO_PENDING, rv); | 1699 EXPECT_EQ(ERR_IO_PENDING, rv); |
1497 | 1700 |
1498 // Nothing has been sent to the resolver yet. | 1701 // Nothing has been sent to the resolver yet. |
1499 EXPECT_TRUE(resolver->pending_requests().empty()); | 1702 EXPECT_TRUE(resolver->pending_requests().empty()); |
1500 | 1703 |
1501 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1704 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
1502 service.GetLoadState(request1)); | 1705 service.GetLoadState(request1)); |
1503 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1706 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
1504 service.GetLoadState(request2)); | 1707 service.GetLoadState(request2)); |
1505 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1708 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 ProxyService service(config_service, resolver, NULL); | 1771 ProxyService service(config_service, resolver, NULL); |
1569 | 1772 |
1570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1773 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1571 service.SetProxyScriptFetchers(fetcher, | 1774 service.SetProxyScriptFetchers(fetcher, |
1572 new DoNothingDhcpProxyScriptFetcher()); | 1775 new DoNothingDhcpProxyScriptFetcher()); |
1573 | 1776 |
1574 // Start 2 requests. | 1777 // Start 2 requests. |
1575 | 1778 |
1576 ProxyInfo info1; | 1779 ProxyInfo info1; |
1577 TestCompletionCallback callback1; | 1780 TestCompletionCallback callback1; |
1578 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1781 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
1579 callback1.callback(), NULL, BoundNetLog()); | 1782 &info1, callback1.callback(), NULL, NULL, |
| 1783 BoundNetLog()); |
1580 EXPECT_EQ(ERR_IO_PENDING, rv); | 1784 EXPECT_EQ(ERR_IO_PENDING, rv); |
1581 | 1785 |
1582 // The first request should have triggered download of PAC script. | 1786 // The first request should have triggered download of PAC script. |
1583 EXPECT_TRUE(fetcher->has_pending_request()); | 1787 EXPECT_TRUE(fetcher->has_pending_request()); |
1584 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1788 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1585 | 1789 |
1586 ProxyInfo info2; | 1790 ProxyInfo info2; |
1587 TestCompletionCallback callback2; | 1791 TestCompletionCallback callback2; |
1588 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1792 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, |
1589 callback2.callback(), NULL, BoundNetLog()); | 1793 callback2.callback(), NULL, NULL, BoundNetLog()); |
1590 EXPECT_EQ(ERR_IO_PENDING, rv); | 1794 EXPECT_EQ(ERR_IO_PENDING, rv); |
1591 | 1795 |
1592 // At this point the ProxyService should be waiting for the | 1796 // At this point the ProxyService should be waiting for the |
1593 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1797 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
1594 // PAC script download completion. | 1798 // PAC script download completion. |
1595 | 1799 |
1596 // We now change out the ProxyService's script fetcher. We should restart | 1800 // We now change out the ProxyService's script fetcher. We should restart |
1597 // the initialization with the new fetcher. | 1801 // the initialization with the new fetcher. |
1598 | 1802 |
1599 fetcher = new MockProxyScriptFetcher; | 1803 fetcher = new MockProxyScriptFetcher; |
(...skipping 28 matching lines...) Expand all Loading... |
1628 | 1832 |
1629 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1833 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1630 service.SetProxyScriptFetchers(fetcher, | 1834 service.SetProxyScriptFetchers(fetcher, |
1631 new DoNothingDhcpProxyScriptFetcher()); | 1835 new DoNothingDhcpProxyScriptFetcher()); |
1632 | 1836 |
1633 // Start 3 requests. | 1837 // Start 3 requests. |
1634 ProxyInfo info1; | 1838 ProxyInfo info1; |
1635 TestCompletionCallback callback1; | 1839 TestCompletionCallback callback1; |
1636 ProxyService::PacRequest* request1; | 1840 ProxyService::PacRequest* request1; |
1637 CapturingBoundNetLog log1; | 1841 CapturingBoundNetLog log1; |
1638 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1842 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
1639 callback1.callback(), &request1, log1.bound()); | 1843 &info1, callback1.callback(), &request1, NULL, |
| 1844 log1.bound()); |
1640 EXPECT_EQ(ERR_IO_PENDING, rv); | 1845 EXPECT_EQ(ERR_IO_PENDING, rv); |
1641 | 1846 |
1642 // The first request should have triggered download of PAC script. | 1847 // The first request should have triggered download of PAC script. |
1643 EXPECT_TRUE(fetcher->has_pending_request()); | 1848 EXPECT_TRUE(fetcher->has_pending_request()); |
1644 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1849 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1645 | 1850 |
1646 ProxyInfo info2; | 1851 ProxyInfo info2; |
1647 TestCompletionCallback callback2; | 1852 TestCompletionCallback callback2; |
1648 ProxyService::PacRequest* request2; | 1853 ProxyService::PacRequest* request2; |
1649 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1854 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, |
1650 callback2.callback(), &request2, BoundNetLog()); | 1855 callback2.callback(), &request2, NULL, |
| 1856 BoundNetLog()); |
1651 EXPECT_EQ(ERR_IO_PENDING, rv); | 1857 EXPECT_EQ(ERR_IO_PENDING, rv); |
1652 | 1858 |
1653 ProxyInfo info3; | 1859 ProxyInfo info3; |
1654 TestCompletionCallback callback3; | 1860 TestCompletionCallback callback3; |
1655 rv = service.ResolveProxy(GURL("http://request3"), &info3, | 1861 rv = service.ResolveProxy(GURL("http://request3"), net::LOAD_NORMAL, &info3, |
1656 callback3.callback(), NULL, BoundNetLog()); | 1862 callback3.callback(), NULL, NULL, BoundNetLog()); |
1657 EXPECT_EQ(ERR_IO_PENDING, rv); | 1863 EXPECT_EQ(ERR_IO_PENDING, rv); |
1658 | 1864 |
1659 // Nothing has been sent to the resolver yet. | 1865 // Nothing has been sent to the resolver yet. |
1660 EXPECT_TRUE(resolver->pending_requests().empty()); | 1866 EXPECT_TRUE(resolver->pending_requests().empty()); |
1661 | 1867 |
1662 // Cancel the first 2 requests. | 1868 // Cancel the first 2 requests. |
1663 service.CancelPacRequest(request1); | 1869 service.CancelPacRequest(request1); |
1664 service.CancelPacRequest(request2); | 1870 service.CancelPacRequest(request2); |
1665 | 1871 |
1666 // At this point the ProxyService should be waiting for the | 1872 // At this point the ProxyService should be waiting for the |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1719 ProxyService service(config_service, resolver, NULL); | 1925 ProxyService service(config_service, resolver, NULL); |
1720 | 1926 |
1721 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1927 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1722 service.SetProxyScriptFetchers(fetcher, | 1928 service.SetProxyScriptFetchers(fetcher, |
1723 new DoNothingDhcpProxyScriptFetcher()); | 1929 new DoNothingDhcpProxyScriptFetcher()); |
1724 | 1930 |
1725 // Start 2 requests. | 1931 // Start 2 requests. |
1726 | 1932 |
1727 ProxyInfo info1; | 1933 ProxyInfo info1; |
1728 TestCompletionCallback callback1; | 1934 TestCompletionCallback callback1; |
1729 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 1935 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
1730 callback1.callback(), NULL, BoundNetLog()); | 1936 &info1, callback1.callback(), NULL, NULL, |
| 1937 BoundNetLog()); |
1731 EXPECT_EQ(ERR_IO_PENDING, rv); | 1938 EXPECT_EQ(ERR_IO_PENDING, rv); |
1732 | 1939 |
1733 ProxyInfo info2; | 1940 ProxyInfo info2; |
1734 TestCompletionCallback callback2; | 1941 TestCompletionCallback callback2; |
1735 ProxyService::PacRequest* request2; | 1942 ProxyService::PacRequest* request2; |
1736 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 1943 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, |
1737 callback2.callback(), &request2, BoundNetLog()); | 1944 callback2.callback(), &request2, NULL, |
| 1945 BoundNetLog()); |
1738 EXPECT_EQ(ERR_IO_PENDING, rv); | 1946 EXPECT_EQ(ERR_IO_PENDING, rv); |
1739 | 1947 |
1740 // Check that nothing has been sent to the proxy resolver yet. | 1948 // Check that nothing has been sent to the proxy resolver yet. |
1741 ASSERT_EQ(0u, resolver->pending_requests().size()); | 1949 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1742 | 1950 |
1743 // It should be trying to auto-detect first -- FAIL the autodetect during | 1951 // It should be trying to auto-detect first -- FAIL the autodetect during |
1744 // the script download. | 1952 // the script download. |
1745 EXPECT_TRUE(fetcher->has_pending_request()); | 1953 EXPECT_TRUE(fetcher->has_pending_request()); |
1746 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 1954 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1747 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 1955 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 ProxyService service(config_service, resolver, NULL); | 2004 ProxyService service(config_service, resolver, NULL); |
1797 | 2005 |
1798 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2006 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1799 service.SetProxyScriptFetchers(fetcher, | 2007 service.SetProxyScriptFetchers(fetcher, |
1800 new DoNothingDhcpProxyScriptFetcher()); | 2008 new DoNothingDhcpProxyScriptFetcher()); |
1801 | 2009 |
1802 // Start 2 requests. | 2010 // Start 2 requests. |
1803 | 2011 |
1804 ProxyInfo info1; | 2012 ProxyInfo info1; |
1805 TestCompletionCallback callback1; | 2013 TestCompletionCallback callback1; |
1806 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 2014 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
1807 callback1.callback(), NULL, BoundNetLog()); | 2015 &info1, callback1.callback(), NULL, NULL, |
| 2016 BoundNetLog()); |
1808 EXPECT_EQ(ERR_IO_PENDING, rv); | 2017 EXPECT_EQ(ERR_IO_PENDING, rv); |
1809 | 2018 |
1810 ProxyInfo info2; | 2019 ProxyInfo info2; |
1811 TestCompletionCallback callback2; | 2020 TestCompletionCallback callback2; |
1812 ProxyService::PacRequest* request2; | 2021 ProxyService::PacRequest* request2; |
1813 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 2022 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, |
1814 callback2.callback(), &request2, BoundNetLog()); | 2023 callback2.callback(), &request2, NULL, |
| 2024 BoundNetLog()); |
1815 EXPECT_EQ(ERR_IO_PENDING, rv); | 2025 EXPECT_EQ(ERR_IO_PENDING, rv); |
1816 | 2026 |
1817 // Check that nothing has been sent to the proxy resolver yet. | 2027 // Check that nothing has been sent to the proxy resolver yet. |
1818 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2028 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1819 | 2029 |
1820 // It should be trying to auto-detect first -- succeed the download. | 2030 // It should be trying to auto-detect first -- succeed the download. |
1821 EXPECT_TRUE(fetcher->has_pending_request()); | 2031 EXPECT_TRUE(fetcher->has_pending_request()); |
1822 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2032 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1823 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 2033 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
1824 | 2034 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 ProxyService service(config_service, resolver, NULL); | 2079 ProxyService service(config_service, resolver, NULL); |
1870 | 2080 |
1871 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2081 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1872 service.SetProxyScriptFetchers(fetcher, | 2082 service.SetProxyScriptFetchers(fetcher, |
1873 new DoNothingDhcpProxyScriptFetcher()); | 2083 new DoNothingDhcpProxyScriptFetcher()); |
1874 | 2084 |
1875 // Start 2 requests. | 2085 // Start 2 requests. |
1876 | 2086 |
1877 ProxyInfo info1; | 2087 ProxyInfo info1; |
1878 TestCompletionCallback callback1; | 2088 TestCompletionCallback callback1; |
1879 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 2089 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
1880 callback1.callback(), NULL, BoundNetLog()); | 2090 &info1, callback1.callback(), NULL, NULL, |
| 2091 BoundNetLog()); |
1881 EXPECT_EQ(ERR_IO_PENDING, rv); | 2092 EXPECT_EQ(ERR_IO_PENDING, rv); |
1882 | 2093 |
1883 ProxyInfo info2; | 2094 ProxyInfo info2; |
1884 TestCompletionCallback callback2; | 2095 TestCompletionCallback callback2; |
1885 ProxyService::PacRequest* request2; | 2096 ProxyService::PacRequest* request2; |
1886 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 2097 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, |
1887 callback2.callback(), &request2, BoundNetLog()); | 2098 callback2.callback(), &request2, NULL, |
| 2099 BoundNetLog()); |
1888 EXPECT_EQ(ERR_IO_PENDING, rv); | 2100 EXPECT_EQ(ERR_IO_PENDING, rv); |
1889 | 2101 |
1890 // Check that nothing has been sent to the proxy resolver yet. | 2102 // Check that nothing has been sent to the proxy resolver yet. |
1891 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2103 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1892 | 2104 |
1893 // It should be trying to auto-detect first -- fail the download. | 2105 // It should be trying to auto-detect first -- fail the download. |
1894 EXPECT_TRUE(fetcher->has_pending_request()); | 2106 EXPECT_TRUE(fetcher->has_pending_request()); |
1895 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2107 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1896 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2108 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
1897 | 2109 |
(...skipping 30 matching lines...) Expand all Loading... |
1928 | 2140 |
1929 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2141 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1930 service.SetProxyScriptFetchers(fetcher, | 2142 service.SetProxyScriptFetchers(fetcher, |
1931 new DoNothingDhcpProxyScriptFetcher()); | 2143 new DoNothingDhcpProxyScriptFetcher()); |
1932 | 2144 |
1933 // Start 1 requests. | 2145 // Start 1 requests. |
1934 | 2146 |
1935 ProxyInfo info1; | 2147 ProxyInfo info1; |
1936 TestCompletionCallback callback1; | 2148 TestCompletionCallback callback1; |
1937 int rv = service.ResolveProxy( | 2149 int rv = service.ResolveProxy( |
1938 GURL("http://www.google.com"), &info1, callback1.callback(), NULL, | 2150 GURL("http://www.google.com"), net::LOAD_NORMAL, &info1, |
1939 BoundNetLog()); | 2151 callback1.callback(), NULL, NULL, BoundNetLog()); |
1940 EXPECT_EQ(ERR_IO_PENDING, rv); | 2152 EXPECT_EQ(ERR_IO_PENDING, rv); |
1941 | 2153 |
1942 // Check that nothing has been sent to the proxy resolver yet. | 2154 // Check that nothing has been sent to the proxy resolver yet. |
1943 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2155 ASSERT_EQ(0u, resolver->pending_requests().size()); |
1944 | 2156 |
1945 // It should be trying to auto-detect first -- succeed the download. | 2157 // It should be trying to auto-detect first -- succeed the download. |
1946 EXPECT_TRUE(fetcher->has_pending_request()); | 2158 EXPECT_TRUE(fetcher->has_pending_request()); |
1947 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2159 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
1948 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2160 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
1949 | 2161 |
1950 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2162 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
1951 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 2163 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
1952 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2164 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
1953 | 2165 |
1954 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2166 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1955 EXPECT_EQ(GURL("http://www.google.com"), | 2167 EXPECT_EQ(GURL("http://www.google.com"), |
1956 resolver->pending_requests()[0]->url()); | 2168 resolver->pending_requests()[0]->url()); |
1957 | 2169 |
1958 // Complete the pending request. | 2170 // Complete the pending request. |
1959 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2171 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
1960 resolver->pending_requests()[0]->CompleteNow(OK); | 2172 resolver->pending_requests()[0]->CompleteNow(OK); |
1961 | 2173 |
1962 // Verify that request ran as expected. | 2174 // Verify that request ran as expected. |
1963 EXPECT_EQ(OK, callback1.WaitForResult()); | 2175 EXPECT_EQ(OK, callback1.WaitForResult()); |
1964 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2176 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1965 | 2177 |
1966 // Start another request, it should pickup the bypass item. | 2178 // Start another request, it should pickup the bypass item. |
1967 ProxyInfo info2; | 2179 ProxyInfo info2; |
1968 TestCompletionCallback callback2; | 2180 TestCompletionCallback callback2; |
1969 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 2181 rv = service.ResolveProxy(GURL("http://www.google.com"), net::LOAD_NORMAL, |
1970 callback2.callback(), NULL, BoundNetLog()); | 2182 &info2, callback2.callback(), NULL, NULL, |
| 2183 BoundNetLog()); |
1971 EXPECT_EQ(ERR_IO_PENDING, rv); | 2184 EXPECT_EQ(ERR_IO_PENDING, rv); |
1972 | 2185 |
1973 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2186 ASSERT_EQ(1u, resolver->pending_requests().size()); |
1974 EXPECT_EQ(GURL("http://www.google.com"), | 2187 EXPECT_EQ(GURL("http://www.google.com"), |
1975 resolver->pending_requests()[0]->url()); | 2188 resolver->pending_requests()[0]->url()); |
1976 | 2189 |
1977 // Complete the pending request. | 2190 // Complete the pending request. |
1978 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2191 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
1979 resolver->pending_requests()[0]->CompleteNow(OK); | 2192 resolver->pending_requests()[0]->CompleteNow(OK); |
1980 | 2193 |
(...skipping 15 matching lines...) Expand all Loading... |
1996 ProxyService service(config_service, resolver, NULL); | 2209 ProxyService service(config_service, resolver, NULL); |
1997 | 2210 |
1998 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2211 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1999 service.SetProxyScriptFetchers(fetcher, | 2212 service.SetProxyScriptFetchers(fetcher, |
2000 new DoNothingDhcpProxyScriptFetcher()); | 2213 new DoNothingDhcpProxyScriptFetcher()); |
2001 | 2214 |
2002 // Start 1 request. | 2215 // Start 1 request. |
2003 | 2216 |
2004 ProxyInfo info1; | 2217 ProxyInfo info1; |
2005 TestCompletionCallback callback1; | 2218 TestCompletionCallback callback1; |
2006 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, | 2219 int rv = service.ResolveProxy(GURL("http://www.google.com"), net::LOAD_NORMAL, |
2007 callback1.callback(), NULL, BoundNetLog()); | 2220 &info1, callback1.callback(), NULL, NULL, |
| 2221 BoundNetLog()); |
2008 EXPECT_EQ(ERR_IO_PENDING, rv); | 2222 EXPECT_EQ(ERR_IO_PENDING, rv); |
2009 | 2223 |
2010 // Check that nothing has been sent to the proxy resolver yet. | 2224 // Check that nothing has been sent to the proxy resolver yet. |
2011 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2225 ASSERT_EQ(0u, resolver->pending_requests().size()); |
2012 | 2226 |
2013 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 2227 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
2014 // and be waiting on that to complete. | 2228 // and be waiting on that to complete. |
2015 EXPECT_TRUE(fetcher->has_pending_request()); | 2229 EXPECT_TRUE(fetcher->has_pending_request()); |
2016 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2230 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2017 } | 2231 } |
2018 | 2232 |
2019 // Delete the ProxyService while InitProxyResolver has an outstanding | 2233 // Delete the ProxyService while InitProxyResolver has an outstanding |
2020 // request to the proxy resolver. When run under valgrind, should not | 2234 // request to the proxy resolver. When run under valgrind, should not |
2021 // have any memory errors (used to be that the ProxyResolver was | 2235 // have any memory errors (used to be that the ProxyResolver was |
2022 // being deleted prior to the InitProxyResolver). | 2236 // being deleted prior to the InitProxyResolver). |
2023 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { | 2237 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { |
2024 MockProxyConfigService* config_service = | 2238 MockProxyConfigService* config_service = |
2025 new MockProxyConfigService("http://foopy/proxy.pac"); | 2239 new MockProxyConfigService("http://foopy/proxy.pac"); |
2026 | 2240 |
2027 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 2241 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
2028 | 2242 |
2029 ProxyService service(config_service, resolver, NULL); | 2243 ProxyService service(config_service, resolver, NULL); |
2030 | 2244 |
2031 GURL url("http://www.google.com/"); | 2245 GURL url("http://www.google.com/"); |
2032 | 2246 |
2033 ProxyInfo info; | 2247 ProxyInfo info; |
2034 TestCompletionCallback callback; | 2248 TestCompletionCallback callback; |
2035 int rv = service.ResolveProxy( | 2249 int rv = service.ResolveProxy( |
2036 url, &info, callback.callback(), NULL, BoundNetLog()); | 2250 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, |
| 2251 BoundNetLog()); |
2037 EXPECT_EQ(ERR_IO_PENDING, rv); | 2252 EXPECT_EQ(ERR_IO_PENDING, rv); |
2038 | 2253 |
2039 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 2254 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
2040 resolver->pending_set_pac_script_request()->script_data()->url()); | 2255 resolver->pending_set_pac_script_request()->script_data()->url()); |
2041 } | 2256 } |
2042 | 2257 |
2043 TEST_F(ProxyServiceTest, ResetProxyConfigService) { | 2258 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
2044 ProxyConfig config1; | 2259 ProxyConfig config1; |
2045 config1.proxy_rules().ParseFromString("foopy1:8080"); | 2260 config1.proxy_rules().ParseFromString("foopy1:8080"); |
2046 config1.set_auto_detect(false); | 2261 config1.set_auto_detect(false); |
2047 ProxyService service( | 2262 ProxyService service( |
2048 new MockProxyConfigService(config1), | 2263 new MockProxyConfigService(config1), |
2049 new MockAsyncProxyResolverExpectsBytes, NULL); | 2264 new MockAsyncProxyResolverExpectsBytes, NULL); |
2050 | 2265 |
2051 ProxyInfo info; | 2266 ProxyInfo info; |
2052 TestCompletionCallback callback1; | 2267 TestCompletionCallback callback1; |
2053 int rv = service.ResolveProxy(GURL("http://request1"), &info, | 2268 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
2054 callback1.callback(), NULL, BoundNetLog()); | 2269 &info, callback1.callback(), NULL, NULL, |
| 2270 BoundNetLog()); |
2055 EXPECT_EQ(OK, rv); | 2271 EXPECT_EQ(OK, rv); |
2056 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 2272 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
2057 | 2273 |
2058 ProxyConfig config2; | 2274 ProxyConfig config2; |
2059 config2.proxy_rules().ParseFromString("foopy2:8080"); | 2275 config2.proxy_rules().ParseFromString("foopy2:8080"); |
2060 config2.set_auto_detect(false); | 2276 config2.set_auto_detect(false); |
2061 service.ResetConfigService(new MockProxyConfigService(config2)); | 2277 service.ResetConfigService(new MockProxyConfigService(config2)); |
2062 TestCompletionCallback callback2; | 2278 TestCompletionCallback callback2; |
2063 rv = service.ResolveProxy(GURL("http://request2"), &info, | 2279 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info, |
2064 callback2.callback(), NULL, BoundNetLog()); | 2280 callback2.callback(), NULL, NULL, BoundNetLog()); |
2065 EXPECT_EQ(OK, rv); | 2281 EXPECT_EQ(OK, rv); |
2066 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 2282 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
2067 } | 2283 } |
2068 | 2284 |
2069 // Test that when going from a configuration that required PAC to one | 2285 // Test that when going from a configuration that required PAC to one |
2070 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 2286 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
2071 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 2287 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
2072 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 2288 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
2073 | 2289 |
2074 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2290 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2075 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; | 2291 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; |
2076 ProxyService service(config_service, resolver, NULL); | 2292 ProxyService service(config_service, resolver, NULL); |
2077 | 2293 |
2078 // Start 1 request. | 2294 // Start 1 request. |
2079 | 2295 |
2080 ProxyInfo info1; | 2296 ProxyInfo info1; |
2081 TestCompletionCallback callback1; | 2297 TestCompletionCallback callback1; |
2082 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, | 2298 int rv = service.ResolveProxy(GURL("http://www.google.com"), net::LOAD_NORMAL, |
2083 callback1.callback(), NULL, BoundNetLog()); | 2299 &info1, callback1.callback(), NULL, NULL, |
| 2300 BoundNetLog()); |
2084 EXPECT_EQ(ERR_IO_PENDING, rv); | 2301 EXPECT_EQ(ERR_IO_PENDING, rv); |
2085 | 2302 |
2086 // Check that nothing has been sent to the proxy resolver yet. | 2303 // Check that nothing has been sent to the proxy resolver yet. |
2087 ASSERT_EQ(0u, resolver->pending_requests().size()); | 2304 ASSERT_EQ(0u, resolver->pending_requests().size()); |
2088 | 2305 |
2089 // Successfully set the autodetect script. | 2306 // Successfully set the autodetect script. |
2090 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2307 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2091 resolver->pending_set_pac_script_request()->script_data()->type()); | 2308 resolver->pending_set_pac_script_request()->script_data()->type()); |
2092 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2309 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
2093 | 2310 |
2094 // Complete the pending request. | 2311 // Complete the pending request. |
2095 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2312 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2096 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2313 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2097 resolver->pending_requests()[0]->CompleteNow(OK); | 2314 resolver->pending_requests()[0]->CompleteNow(OK); |
2098 | 2315 |
2099 // Verify that request ran as expected. | 2316 // Verify that request ran as expected. |
2100 EXPECT_EQ(OK, callback1.WaitForResult()); | 2317 EXPECT_EQ(OK, callback1.WaitForResult()); |
2101 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2318 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2102 | 2319 |
2103 // Force the ProxyService to pull down a new proxy configuration. | 2320 // Force the ProxyService to pull down a new proxy configuration. |
2104 // (Even though the configuration isn't old/bad). | 2321 // (Even though the configuration isn't old/bad). |
2105 // | 2322 // |
2106 // This new configuration no longer has auto_detect set, so | 2323 // This new configuration no longer has auto_detect set, so |
2107 // requests should complete synchronously now as direct-connect. | 2324 // requests should complete synchronously now as direct-connect. |
2108 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2325 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2109 | 2326 |
2110 // Start another request -- the effective configuration has changed. | 2327 // Start another request -- the effective configuration has changed. |
2111 ProxyInfo info2; | 2328 ProxyInfo info2; |
2112 TestCompletionCallback callback2; | 2329 TestCompletionCallback callback2; |
2113 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, | 2330 rv = service.ResolveProxy(GURL("http://www.google.com"), net::LOAD_NORMAL, |
2114 callback2.callback(), NULL, BoundNetLog()); | 2331 &info2, callback2.callback(), NULL, NULL, |
| 2332 BoundNetLog()); |
2115 EXPECT_EQ(OK, rv); | 2333 EXPECT_EQ(OK, rv); |
2116 | 2334 |
2117 EXPECT_TRUE(info2.is_direct()); | 2335 EXPECT_TRUE(info2.is_direct()); |
2118 } | 2336 } |
2119 | 2337 |
2120 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 2338 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
2121 MockProxyConfigService* config_service = | 2339 MockProxyConfigService* config_service = |
2122 new MockProxyConfigService("http://foopy/proxy.pac"); | 2340 new MockProxyConfigService("http://foopy/proxy.pac"); |
2123 | 2341 |
2124 MockAsyncProxyResolverExpectsBytes* resolver = | 2342 MockAsyncProxyResolverExpectsBytes* resolver = |
2125 new MockAsyncProxyResolverExpectsBytes; | 2343 new MockAsyncProxyResolverExpectsBytes; |
2126 | 2344 |
2127 CapturingNetLog log; | 2345 CapturingNetLog log; |
2128 | 2346 |
2129 ProxyService service(config_service, resolver, &log); | 2347 ProxyService service(config_service, resolver, &log); |
2130 | 2348 |
2131 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2349 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2132 service.SetProxyScriptFetchers(fetcher, | 2350 service.SetProxyScriptFetchers(fetcher, |
2133 new DoNothingDhcpProxyScriptFetcher()); | 2351 new DoNothingDhcpProxyScriptFetcher()); |
2134 | 2352 |
2135 // Disable the "wait after IP address changes" hack, so this unit-test can | 2353 // Disable the "wait after IP address changes" hack, so this unit-test can |
2136 // complete quickly. | 2354 // complete quickly. |
2137 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 2355 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
2138 | 2356 |
2139 // Start 1 request. | 2357 // Start 1 request. |
2140 | 2358 |
2141 ProxyInfo info1; | 2359 ProxyInfo info1; |
2142 TestCompletionCallback callback1; | 2360 TestCompletionCallback callback1; |
2143 int rv = service.ResolveProxy(GURL("http://request1"), &info1, | 2361 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, |
2144 callback1.callback(), NULL, BoundNetLog()); | 2362 &info1, callback1.callback(), NULL, NULL, |
| 2363 BoundNetLog()); |
2145 EXPECT_EQ(ERR_IO_PENDING, rv); | 2364 EXPECT_EQ(ERR_IO_PENDING, rv); |
2146 | 2365 |
2147 // The first request should have triggered initial download of PAC script. | 2366 // The first request should have triggered initial download of PAC script. |
2148 EXPECT_TRUE(fetcher->has_pending_request()); | 2367 EXPECT_TRUE(fetcher->has_pending_request()); |
2149 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2368 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2150 | 2369 |
2151 // Nothing has been sent to the resolver yet. | 2370 // Nothing has been sent to the resolver yet. |
2152 EXPECT_TRUE(resolver->pending_requests().empty()); | 2371 EXPECT_TRUE(resolver->pending_requests().empty()); |
2153 | 2372 |
2154 // At this point the ProxyService should be waiting for the | 2373 // At this point the ProxyService should be waiting for the |
(...skipping 20 matching lines...) Expand all Loading... |
2175 | 2394 |
2176 // Now simluate a change in the network. The ProxyConfigService is still | 2395 // Now simluate a change in the network. The ProxyConfigService is still |
2177 // going to return the same PAC URL as before, but this URL needs to be | 2396 // going to return the same PAC URL as before, but this URL needs to be |
2178 // refetched on the new network. | 2397 // refetched on the new network. |
2179 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2398 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2180 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 2399 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
2181 | 2400 |
2182 // Start a second request. | 2401 // Start a second request. |
2183 ProxyInfo info2; | 2402 ProxyInfo info2; |
2184 TestCompletionCallback callback2; | 2403 TestCompletionCallback callback2; |
2185 rv = service.ResolveProxy(GURL("http://request2"), &info2, | 2404 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, |
2186 callback2.callback(), NULL, BoundNetLog()); | 2405 callback2.callback(), NULL, NULL, BoundNetLog()); |
2187 EXPECT_EQ(ERR_IO_PENDING, rv); | 2406 EXPECT_EQ(ERR_IO_PENDING, rv); |
2188 | 2407 |
2189 // This second request should have triggered the re-download of the PAC | 2408 // This second request should have triggered the re-download of the PAC |
2190 // script (since we marked the network as having changed). | 2409 // script (since we marked the network as having changed). |
2191 EXPECT_TRUE(fetcher->has_pending_request()); | 2410 EXPECT_TRUE(fetcher->has_pending_request()); |
2192 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2411 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2193 | 2412 |
2194 // Nothing has been sent to the resolver yet. | 2413 // Nothing has been sent to the resolver yet. |
2195 EXPECT_TRUE(resolver->pending_requests().empty()); | 2414 EXPECT_TRUE(resolver->pending_requests().empty()); |
2196 | 2415 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 | 2467 |
2249 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2468 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2250 service.SetProxyScriptFetchers(fetcher, | 2469 service.SetProxyScriptFetchers(fetcher, |
2251 new DoNothingDhcpProxyScriptFetcher()); | 2470 new DoNothingDhcpProxyScriptFetcher()); |
2252 | 2471 |
2253 // Start 1 request. | 2472 // Start 1 request. |
2254 | 2473 |
2255 ProxyInfo info1; | 2474 ProxyInfo info1; |
2256 TestCompletionCallback callback1; | 2475 TestCompletionCallback callback1; |
2257 int rv = service.ResolveProxy( | 2476 int rv = service.ResolveProxy( |
2258 GURL("http://request1"), &info1, callback1.callback(), | 2477 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), |
2259 NULL, BoundNetLog()); | 2478 NULL, NULL, BoundNetLog()); |
2260 EXPECT_EQ(ERR_IO_PENDING, rv); | 2479 EXPECT_EQ(ERR_IO_PENDING, rv); |
2261 | 2480 |
2262 // The first request should have triggered initial download of PAC script. | 2481 // The first request should have triggered initial download of PAC script. |
2263 EXPECT_TRUE(fetcher->has_pending_request()); | 2482 EXPECT_TRUE(fetcher->has_pending_request()); |
2264 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2483 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2265 | 2484 |
2266 // Nothing has been sent to the resolver yet. | 2485 // Nothing has been sent to the resolver yet. |
2267 EXPECT_TRUE(resolver->pending_requests().empty()); | 2486 EXPECT_TRUE(resolver->pending_requests().empty()); |
2268 | 2487 |
2269 // At this point the ProxyService should be waiting for the | 2488 // At this point the ProxyService should be waiting for the |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 | 2528 |
2310 // At this point the ProxyService should have re-configured itself to use the | 2529 // At this point the ProxyService should have re-configured itself to use the |
2311 // PAC script (thereby recovering from the initial fetch failure). We will | 2530 // PAC script (thereby recovering from the initial fetch failure). We will |
2312 // verify that the next Resolve request uses the resolver rather than | 2531 // verify that the next Resolve request uses the resolver rather than |
2313 // DIRECT. | 2532 // DIRECT. |
2314 | 2533 |
2315 // Start a second request. | 2534 // Start a second request. |
2316 ProxyInfo info2; | 2535 ProxyInfo info2; |
2317 TestCompletionCallback callback2; | 2536 TestCompletionCallback callback2; |
2318 rv = service.ResolveProxy( | 2537 rv = service.ResolveProxy( |
2319 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2538 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(), |
2320 BoundNetLog()); | 2539 NULL, NULL, BoundNetLog()); |
2321 EXPECT_EQ(ERR_IO_PENDING, rv); | 2540 EXPECT_EQ(ERR_IO_PENDING, rv); |
2322 | 2541 |
2323 // Check that it was sent to the resolver. | 2542 // Check that it was sent to the resolver. |
2324 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2543 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2325 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2544 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2326 | 2545 |
2327 // Complete the pending second request. | 2546 // Complete the pending second request. |
2328 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2547 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2329 resolver->pending_requests()[0]->CompleteNow(OK); | 2548 resolver->pending_requests()[0]->CompleteNow(OK); |
2330 | 2549 |
(...skipping 22 matching lines...) Expand all Loading... |
2353 | 2572 |
2354 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2573 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2355 service.SetProxyScriptFetchers(fetcher, | 2574 service.SetProxyScriptFetchers(fetcher, |
2356 new DoNothingDhcpProxyScriptFetcher()); | 2575 new DoNothingDhcpProxyScriptFetcher()); |
2357 | 2576 |
2358 // Start 1 request. | 2577 // Start 1 request. |
2359 | 2578 |
2360 ProxyInfo info1; | 2579 ProxyInfo info1; |
2361 TestCompletionCallback callback1; | 2580 TestCompletionCallback callback1; |
2362 int rv = service.ResolveProxy( | 2581 int rv = service.ResolveProxy( |
2363 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2582 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), |
2364 BoundNetLog()); | 2583 NULL, NULL, BoundNetLog()); |
2365 EXPECT_EQ(ERR_IO_PENDING, rv); | 2584 EXPECT_EQ(ERR_IO_PENDING, rv); |
2366 | 2585 |
2367 // The first request should have triggered initial download of PAC script. | 2586 // The first request should have triggered initial download of PAC script. |
2368 EXPECT_TRUE(fetcher->has_pending_request()); | 2587 EXPECT_TRUE(fetcher->has_pending_request()); |
2369 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2588 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2370 | 2589 |
2371 // Nothing has been sent to the resolver yet. | 2590 // Nothing has been sent to the resolver yet. |
2372 EXPECT_TRUE(resolver->pending_requests().empty()); | 2591 EXPECT_TRUE(resolver->pending_requests().empty()); |
2373 | 2592 |
2374 // At this point the ProxyService should be waiting for the | 2593 // At this point the ProxyService should be waiting for the |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 resolver->pending_set_pac_script_request()->script_data()->utf16()); | 2638 resolver->pending_set_pac_script_request()->script_data()->utf16()); |
2420 resolver->pending_set_pac_script_request()->CompleteNow(OK); | 2639 resolver->pending_set_pac_script_request()->CompleteNow(OK); |
2421 | 2640 |
2422 // At this point the ProxyService should have re-configured itself to use the | 2641 // At this point the ProxyService should have re-configured itself to use the |
2423 // new PAC script. | 2642 // new PAC script. |
2424 | 2643 |
2425 // Start a second request. | 2644 // Start a second request. |
2426 ProxyInfo info2; | 2645 ProxyInfo info2; |
2427 TestCompletionCallback callback2; | 2646 TestCompletionCallback callback2; |
2428 rv = service.ResolveProxy( | 2647 rv = service.ResolveProxy( |
2429 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2648 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(), |
2430 BoundNetLog()); | 2649 NULL, NULL, BoundNetLog()); |
2431 EXPECT_EQ(ERR_IO_PENDING, rv); | 2650 EXPECT_EQ(ERR_IO_PENDING, rv); |
2432 | 2651 |
2433 // Check that it was sent to the resolver. | 2652 // Check that it was sent to the resolver. |
2434 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2653 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2435 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2654 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2436 | 2655 |
2437 // Complete the pending second request. | 2656 // Complete the pending second request. |
2438 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2657 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2439 resolver->pending_requests()[0]->CompleteNow(OK); | 2658 resolver->pending_requests()[0]->CompleteNow(OK); |
2440 | 2659 |
(...skipping 22 matching lines...) Expand all Loading... |
2463 | 2682 |
2464 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2683 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2465 service.SetProxyScriptFetchers(fetcher, | 2684 service.SetProxyScriptFetchers(fetcher, |
2466 new DoNothingDhcpProxyScriptFetcher()); | 2685 new DoNothingDhcpProxyScriptFetcher()); |
2467 | 2686 |
2468 // Start 1 request. | 2687 // Start 1 request. |
2469 | 2688 |
2470 ProxyInfo info1; | 2689 ProxyInfo info1; |
2471 TestCompletionCallback callback1; | 2690 TestCompletionCallback callback1; |
2472 int rv = service.ResolveProxy( | 2691 int rv = service.ResolveProxy( |
2473 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2692 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), |
2474 BoundNetLog()); | 2693 NULL, NULL, BoundNetLog()); |
2475 EXPECT_EQ(ERR_IO_PENDING, rv); | 2694 EXPECT_EQ(ERR_IO_PENDING, rv); |
2476 | 2695 |
2477 // The first request should have triggered initial download of PAC script. | 2696 // The first request should have triggered initial download of PAC script. |
2478 EXPECT_TRUE(fetcher->has_pending_request()); | 2697 EXPECT_TRUE(fetcher->has_pending_request()); |
2479 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2698 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2480 | 2699 |
2481 // Nothing has been sent to the resolver yet. | 2700 // Nothing has been sent to the resolver yet. |
2482 EXPECT_TRUE(resolver->pending_requests().empty()); | 2701 EXPECT_TRUE(resolver->pending_requests().empty()); |
2483 | 2702 |
2484 // At this point the ProxyService should be waiting for the | 2703 // At this point the ProxyService should be waiting for the |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2525 | 2744 |
2526 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); | 2745 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); |
2527 | 2746 |
2528 // At this point the ProxyService is still running the same PAC script as | 2747 // At this point the ProxyService is still running the same PAC script as |
2529 // before. | 2748 // before. |
2530 | 2749 |
2531 // Start a second request. | 2750 // Start a second request. |
2532 ProxyInfo info2; | 2751 ProxyInfo info2; |
2533 TestCompletionCallback callback2; | 2752 TestCompletionCallback callback2; |
2534 rv = service.ResolveProxy( | 2753 rv = service.ResolveProxy( |
2535 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2754 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(), |
2536 BoundNetLog()); | 2755 NULL, NULL, BoundNetLog()); |
2537 EXPECT_EQ(ERR_IO_PENDING, rv); | 2756 EXPECT_EQ(ERR_IO_PENDING, rv); |
2538 | 2757 |
2539 // Check that it was sent to the resolver. | 2758 // Check that it was sent to the resolver. |
2540 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2759 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2541 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 2760 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2542 | 2761 |
2543 // Complete the pending second request. | 2762 // Complete the pending second request. |
2544 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2763 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2545 resolver->pending_requests()[0]->CompleteNow(OK); | 2764 resolver->pending_requests()[0]->CompleteNow(OK); |
2546 | 2765 |
(...skipping 22 matching lines...) Expand all Loading... |
2569 | 2788 |
2570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2789 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2571 service.SetProxyScriptFetchers(fetcher, | 2790 service.SetProxyScriptFetchers(fetcher, |
2572 new DoNothingDhcpProxyScriptFetcher()); | 2791 new DoNothingDhcpProxyScriptFetcher()); |
2573 | 2792 |
2574 // Start 1 request. | 2793 // Start 1 request. |
2575 | 2794 |
2576 ProxyInfo info1; | 2795 ProxyInfo info1; |
2577 TestCompletionCallback callback1; | 2796 TestCompletionCallback callback1; |
2578 int rv = service.ResolveProxy( | 2797 int rv = service.ResolveProxy( |
2579 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2798 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), |
2580 BoundNetLog()); | 2799 NULL, NULL, BoundNetLog()); |
2581 EXPECT_EQ(ERR_IO_PENDING, rv); | 2800 EXPECT_EQ(ERR_IO_PENDING, rv); |
2582 | 2801 |
2583 // The first request should have triggered initial download of PAC script. | 2802 // The first request should have triggered initial download of PAC script. |
2584 EXPECT_TRUE(fetcher->has_pending_request()); | 2803 EXPECT_TRUE(fetcher->has_pending_request()); |
2585 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2804 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2586 | 2805 |
2587 // Nothing has been sent to the resolver yet. | 2806 // Nothing has been sent to the resolver yet. |
2588 EXPECT_TRUE(resolver->pending_requests().empty()); | 2807 EXPECT_TRUE(resolver->pending_requests().empty()); |
2589 | 2808 |
2590 // At this point the ProxyService should be waiting for the | 2809 // At this point the ProxyService should be waiting for the |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 | 2848 |
2630 base::MessageLoop::current()->RunUntilIdle(); | 2849 base::MessageLoop::current()->RunUntilIdle(); |
2631 | 2850 |
2632 // At this point the ProxyService should have re-configured itself to use | 2851 // At this point the ProxyService should have re-configured itself to use |
2633 // DIRECT connections rather than the given proxy resolver. | 2852 // DIRECT connections rather than the given proxy resolver. |
2634 | 2853 |
2635 // Start a second request. | 2854 // Start a second request. |
2636 ProxyInfo info2; | 2855 ProxyInfo info2; |
2637 TestCompletionCallback callback2; | 2856 TestCompletionCallback callback2; |
2638 rv = service.ResolveProxy( | 2857 rv = service.ResolveProxy( |
2639 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2858 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(), |
2640 BoundNetLog()); | 2859 NULL, NULL, BoundNetLog()); |
2641 EXPECT_EQ(OK, rv); | 2860 EXPECT_EQ(OK, rv); |
2642 EXPECT_TRUE(info2.is_direct()); | 2861 EXPECT_TRUE(info2.is_direct()); |
2643 } | 2862 } |
2644 | 2863 |
2645 // Tests that the code which decides at what times to poll the PAC | 2864 // Tests that the code which decides at what times to poll the PAC |
2646 // script follows the expected policy. | 2865 // script follows the expected policy. |
2647 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { | 2866 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { |
2648 // Retrieve the internal polling policy implementation used by ProxyService. | 2867 // Retrieve the internal polling policy implementation used by ProxyService. |
2649 scoped_ptr<ProxyService::PacPollPolicy> policy = | 2868 scoped_ptr<ProxyService::PacPollPolicy> policy = |
2650 ProxyService::CreateDefaultPacPollPolicy(); | 2869 ProxyService::CreateDefaultPacPollPolicy(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2721 | 2940 |
2722 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2941 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2723 service.SetProxyScriptFetchers(fetcher, | 2942 service.SetProxyScriptFetchers(fetcher, |
2724 new DoNothingDhcpProxyScriptFetcher()); | 2943 new DoNothingDhcpProxyScriptFetcher()); |
2725 | 2944 |
2726 // Start 1 request. | 2945 // Start 1 request. |
2727 | 2946 |
2728 ProxyInfo info1; | 2947 ProxyInfo info1; |
2729 TestCompletionCallback callback1; | 2948 TestCompletionCallback callback1; |
2730 int rv = service.ResolveProxy( | 2949 int rv = service.ResolveProxy( |
2731 GURL("http://request1"), &info1, callback1.callback(), NULL, | 2950 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), |
2732 BoundNetLog()); | 2951 NULL, NULL, BoundNetLog()); |
2733 EXPECT_EQ(ERR_IO_PENDING, rv); | 2952 EXPECT_EQ(ERR_IO_PENDING, rv); |
2734 | 2953 |
2735 // The first request should have triggered initial download of PAC script. | 2954 // The first request should have triggered initial download of PAC script. |
2736 EXPECT_TRUE(fetcher->has_pending_request()); | 2955 EXPECT_TRUE(fetcher->has_pending_request()); |
2737 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2956 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2738 | 2957 |
2739 // Nothing has been sent to the resolver yet. | 2958 // Nothing has been sent to the resolver yet. |
2740 EXPECT_TRUE(resolver->pending_requests().empty()); | 2959 EXPECT_TRUE(resolver->pending_requests().empty()); |
2741 | 2960 |
2742 // At this point the ProxyService should be waiting for the | 2961 // At this point the ProxyService should be waiting for the |
(...skipping 22 matching lines...) Expand all Loading... |
2765 // Our PAC poller is set to update ONLY in response to network activity, | 2984 // Our PAC poller is set to update ONLY in response to network activity, |
2766 // (i.e. another call to ResolveProxy()). | 2985 // (i.e. another call to ResolveProxy()). |
2767 | 2986 |
2768 ASSERT_FALSE(fetcher->has_pending_request()); | 2987 ASSERT_FALSE(fetcher->has_pending_request()); |
2769 ASSERT_TRUE(resolver->pending_requests().empty()); | 2988 ASSERT_TRUE(resolver->pending_requests().empty()); |
2770 | 2989 |
2771 // Start a second request. | 2990 // Start a second request. |
2772 ProxyInfo info2; | 2991 ProxyInfo info2; |
2773 TestCompletionCallback callback2; | 2992 TestCompletionCallback callback2; |
2774 rv = service.ResolveProxy( | 2993 rv = service.ResolveProxy( |
2775 GURL("http://request2"), &info2, callback2.callback(), NULL, | 2994 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(), |
2776 BoundNetLog()); | 2995 NULL, NULL, BoundNetLog()); |
2777 EXPECT_EQ(ERR_IO_PENDING, rv); | 2996 EXPECT_EQ(ERR_IO_PENDING, rv); |
2778 | 2997 |
2779 // This request should have sent work to the resolver; complete it. | 2998 // This request should have sent work to the resolver; complete it. |
2780 ASSERT_EQ(1u, resolver->pending_requests().size()); | 2999 ASSERT_EQ(1u, resolver->pending_requests().size()); |
2781 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); | 3000 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); |
2782 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3001 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2783 resolver->pending_requests()[0]->CompleteNow(OK); | 3002 resolver->pending_requests()[0]->CompleteNow(OK); |
2784 | 3003 |
2785 EXPECT_EQ(OK, callback2.WaitForResult()); | 3004 EXPECT_EQ(OK, callback2.WaitForResult()); |
2786 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3005 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2787 | 3006 |
2788 // In response to getting that resolve request, the poller should have | 3007 // In response to getting that resolve request, the poller should have |
2789 // started the next poll, and made it as far as to request the download. | 3008 // started the next poll, and made it as far as to request the download. |
2790 | 3009 |
2791 EXPECT_TRUE(fetcher->has_pending_request()); | 3010 EXPECT_TRUE(fetcher->has_pending_request()); |
2792 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3011 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2793 | 3012 |
2794 // This time we will fail the download, to simulate a PAC script change. | 3013 // This time we will fail the download, to simulate a PAC script change. |
2795 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 3014 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2796 | 3015 |
2797 // Drain the message loop, so ProxyService is notified of the change | 3016 // Drain the message loop, so ProxyService is notified of the change |
2798 // and has a chance to re-configure itself. | 3017 // and has a chance to re-configure itself. |
2799 base::MessageLoop::current()->RunUntilIdle(); | 3018 base::MessageLoop::current()->RunUntilIdle(); |
2800 | 3019 |
2801 // Start a third request -- this time we expect to get a direct connection | 3020 // Start a third request -- this time we expect to get a direct connection |
2802 // since the PAC script poller experienced a failure. | 3021 // since the PAC script poller experienced a failure. |
2803 ProxyInfo info3; | 3022 ProxyInfo info3; |
2804 TestCompletionCallback callback3; | 3023 TestCompletionCallback callback3; |
2805 rv = service.ResolveProxy( | 3024 rv = service.ResolveProxy( |
2806 GURL("http://request3"), &info3, callback3.callback(), NULL, | 3025 GURL("http://request3"), net::LOAD_NORMAL, &info3, callback3.callback(), |
2807 BoundNetLog()); | 3026 NULL, NULL, BoundNetLog()); |
2808 EXPECT_EQ(OK, rv); | 3027 EXPECT_EQ(OK, rv); |
2809 EXPECT_TRUE(info3.is_direct()); | 3028 EXPECT_TRUE(info3.is_direct()); |
2810 } | 3029 } |
2811 | 3030 |
2812 } // namespace net | 3031 } // namespace net |
OLD | NEW |