Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: net/proxy/proxy_service_unittest.cc

Issue 332313003: Add Finch experiment for selectively bypassing proxies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address mmenke's feedback Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 : NetworkDelegate(),
163 on_resolve_proxy_called(false),
164 add_proxy(false),
165 remove_proxy(false) {
166 }
167
168 virtual void OnResolveProxy(
169 const GURL& url, int load_flags, ProxyInfo* result) {
170 on_resolve_proxy_called = true;
171 DCHECK(!(add_proxy && remove_proxy));
172 if (add_proxy) {
173 result->UseNamedProxy("delegate_proxy.com");
174 } else if (remove_proxy) {
175 result->UseDirect();
176 }
177 }
178
179 bool on_resolve_proxy_called;
180 bool add_proxy;
181 bool remove_proxy;
182 };
183
156 } // namespace 184 } // namespace
157 185
158 TEST_F(ProxyServiceTest, Direct) { 186 TEST_F(ProxyServiceTest, Direct) {
159 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 187 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
160 ProxyService service(new MockProxyConfigService( 188 ProxyService service(new MockProxyConfigService(
161 ProxyConfig::CreateDirect()), resolver, NULL); 189 ProxyConfig::CreateDirect()), resolver, NULL);
162 190
163 GURL url("http://www.google.com/"); 191 GURL url("http://www.google.com/");
164 192
165 ProxyInfo info; 193 ProxyInfo info;
166 TestCompletionCallback callback; 194 TestCompletionCallback callback;
167 CapturingBoundNetLog log; 195 CapturingBoundNetLog log;
168 int rv = service.ResolveProxy( 196 int rv = service.ResolveProxy(
169 url, &info, callback.callback(), NULL, log.bound()); 197 url, LOAD_NORMAL, &info, callback.callback(), NULL, NULL, log.bound());
170 EXPECT_EQ(OK, rv); 198 EXPECT_EQ(OK, rv);
171 EXPECT_TRUE(resolver->pending_requests().empty()); 199 EXPECT_TRUE(resolver->pending_requests().empty());
172 200
173 EXPECT_TRUE(info.is_direct()); 201 EXPECT_TRUE(info.is_direct());
174 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); 202 EXPECT_TRUE(info.proxy_resolve_start_time().is_null());
175 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); 203 EXPECT_TRUE(info.proxy_resolve_end_time().is_null());
176 204
177 // Check the NetLog was filled correctly. 205 // Check the NetLog was filled correctly.
178 CapturingNetLog::CapturedEntryList entries; 206 CapturingNetLog::CapturedEntryList entries;
179 log.GetEntries(&entries); 207 log.GetEntries(&entries);
180 208
181 EXPECT_EQ(3u, entries.size()); 209 EXPECT_EQ(3u, entries.size());
182 EXPECT_TRUE(LogContainsBeginEvent( 210 EXPECT_TRUE(LogContainsBeginEvent(
183 entries, 0, NetLog::TYPE_PROXY_SERVICE)); 211 entries, 0, NetLog::TYPE_PROXY_SERVICE));
184 EXPECT_TRUE(LogContainsEvent( 212 EXPECT_TRUE(LogContainsEvent(
185 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, 213 entries, 1, NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
186 NetLog::PHASE_NONE)); 214 NetLog::PHASE_NONE));
187 EXPECT_TRUE(LogContainsEndEvent( 215 EXPECT_TRUE(LogContainsEndEvent(
188 entries, 2, NetLog::TYPE_PROXY_SERVICE)); 216 entries, 2, NetLog::TYPE_PROXY_SERVICE));
189 } 217 }
190 218
219 TEST_F(ProxyServiceTest, OnResolveProxyCallbackAddProxy) {
220 ProxyConfig config;
221 config.proxy_rules().ParseFromString("foopy1:8080");
222 config.set_auto_detect(false);
223 config.proxy_rules().bypass_rules.ParseFromString("*.org");
224
225 ProxyService service(
226 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
227
228 GURL url("http://www.google.com/");
229 GURL bypass_url("http://internet.org");
230
231 ProxyInfo info;
232 TestCompletionCallback callback;
233 CapturingBoundNetLog log;
234
235 // First, warm up the ProxyService.
236 int rv = service.ResolveProxy(
237 url, LOAD_NORMAL, &info, callback.callback(), NULL, NULL, log.bound());
238 EXPECT_EQ(OK, rv);
239
240 // Verify that network delegate is invoked.
241 TestResolveProxyNetworkDelegate delegate;
242 rv = service.ResolveProxy(
243 url, LOAD_NORMAL, &info, callback.callback(), NULL, &delegate,
244 log.bound());
245 EXPECT_TRUE(delegate.on_resolve_proxy_called);
246
247 // Verify that the NetworkDelegate's behavior is stateless across
248 // invocations of ResolveProxy. Start by having the callback add a proxy
249 // and checking that subsequent requests are not effected.
250 delegate.add_proxy = true;
251 // Callback should interpose:
252 rv = service.ResolveProxy(
253 url, LOAD_NORMAL, &info, callback.callback(), NULL, &delegate,
254 log.bound());
255 EXPECT_FALSE(info.is_direct());
256 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com");
257 delegate.add_proxy = false;
258 // Check non-bypassed URL:
259 rv = service.ResolveProxy(
260 url, LOAD_NORMAL, &info, callback.callback(), NULL, &delegate,
261 log.bound());
262 EXPECT_FALSE(info.is_direct());
263 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "foopy1");
264 // Check bypassed URL:
265 rv = service.ResolveProxy(
266 bypass_url, LOAD_NORMAL, &info, callback.callback(), NULL, &delegate,
267 log.bound());
268 EXPECT_TRUE(info.is_direct());
269 }
270
271 TEST_F(ProxyServiceTest, OnResolveProxyCallbackRemoveProxy) {
272 // Same as OnResolveProxyCallbackAddProxy, but verify that the
273 // NetworkDelegate's behavior is stateless across invocations after it
274 // *removes* a proxy.
275 ProxyConfig config;
276 config.proxy_rules().ParseFromString("foopy1:8080");
277 config.set_auto_detect(false);
278 config.proxy_rules().bypass_rules.ParseFromString("*.org");
279
280 ProxyService service(
281 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
282
283 GURL url("http://www.google.com/");
284 GURL bypass_url("http://internet.org");
285
286 ProxyInfo info;
287 TestCompletionCallback callback;
288 CapturingBoundNetLog log;
289
290 // First, warm up the ProxyService.
291 int rv = service.ResolveProxy(
292 url, LOAD_NORMAL, &info, callback.callback(), NULL, NULL, log.bound());
293 EXPECT_EQ(OK, rv);
294
295 // Verify that network delegate is invoked.
rcs 2014/07/02 06:08:55 Oops, will remove
rcs 2014/07/02 17:15:03 Done.
296 TestResolveProxyNetworkDelegate delegate;
297 delegate.remove_proxy = true;
298 // Callback should interpose:
299 rv = service.ResolveProxy(
300 url, LOAD_NORMAL, &info, callback.callback(), NULL, &delegate,
301 log.bound());
302 EXPECT_TRUE(info.is_direct());
303 delegate.remove_proxy = false;
304 // Check non-bypassed URL:
305 rv = service.ResolveProxy(
306 url, LOAD_NORMAL, &info, callback.callback(), NULL, &delegate,
307 log.bound());
308 EXPECT_FALSE(info.is_direct());
309 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "foopy1");
310 // Check bypassed URL:
311 rv = service.ResolveProxy(
312 bypass_url, LOAD_NORMAL, &info, callback.callback(), NULL, &delegate,
313 log.bound());
314 EXPECT_TRUE(info.is_direct());
315 }
316
191 TEST_F(ProxyServiceTest, PAC) { 317 TEST_F(ProxyServiceTest, PAC) {
192 MockProxyConfigService* config_service = 318 MockProxyConfigService* config_service =
193 new MockProxyConfigService("http://foopy/proxy.pac"); 319 new MockProxyConfigService("http://foopy/proxy.pac");
194 320
195 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 321 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
196 322
197 ProxyService service(config_service, resolver, NULL); 323 ProxyService service(config_service, resolver, NULL);
198 324
199 GURL url("http://www.google.com/"); 325 GURL url("http://www.google.com/");
200 326
201 ProxyInfo info; 327 ProxyInfo info;
202 TestCompletionCallback callback; 328 TestCompletionCallback callback;
203 ProxyService::PacRequest* request; 329 ProxyService::PacRequest* request;
204 CapturingBoundNetLog log; 330 CapturingBoundNetLog log;
205 331
206 int rv = service.ResolveProxy( 332 int rv = service.ResolveProxy(
207 url, &info, callback.callback(), &request, log.bound()); 333 url, LOAD_NORMAL, &info, callback.callback(), &request, NULL,
334 log.bound());
208 EXPECT_EQ(ERR_IO_PENDING, rv); 335 EXPECT_EQ(ERR_IO_PENDING, rv);
209 336
210 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); 337 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request));
211 338
212 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 339 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
213 resolver->pending_set_pac_script_request()->script_data()->url()); 340 resolver->pending_set_pac_script_request()->script_data()->url());
214 resolver->pending_set_pac_script_request()->CompleteNow(OK); 341 resolver->pending_set_pac_script_request()->CompleteNow(OK);
215 342
216 ASSERT_EQ(1u, resolver->pending_requests().size()); 343 ASSERT_EQ(1u, resolver->pending_requests().size());
217 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 344 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 379
253 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 380 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
254 381
255 ProxyService service(config_service, resolver, NULL); 382 ProxyService service(config_service, resolver, NULL);
256 383
257 GURL url("http://username:password@www.google.com/?ref#hash#hash"); 384 GURL url("http://username:password@www.google.com/?ref#hash#hash");
258 385
259 ProxyInfo info; 386 ProxyInfo info;
260 TestCompletionCallback callback; 387 TestCompletionCallback callback;
261 int rv = service.ResolveProxy( 388 int rv = service.ResolveProxy(
262 url, &info, callback.callback(), NULL, BoundNetLog()); 389 url, LOAD_NORMAL, &info, callback.callback(), NULL, NULL, BoundNetLog());
263 EXPECT_EQ(ERR_IO_PENDING, rv); 390 EXPECT_EQ(ERR_IO_PENDING, rv);
264 391
265 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 392 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
266 resolver->pending_set_pac_script_request()->script_data()->url()); 393 resolver->pending_set_pac_script_request()->script_data()->url());
267 resolver->pending_set_pac_script_request()->CompleteNow(OK); 394 resolver->pending_set_pac_script_request()->CompleteNow(OK);
268 395
269 ASSERT_EQ(1u, resolver->pending_requests().size()); 396 ASSERT_EQ(1u, resolver->pending_requests().size());
270 // The URL should have been simplified, stripping the username/password/hash. 397 // The URL should have been simplified, stripping the username/password/hash.
271 EXPECT_EQ(GURL("http://www.google.com/?ref"), 398 EXPECT_EQ(GURL("http://www.google.com/?ref"),
272 resolver->pending_requests()[0]->url()); 399 resolver->pending_requests()[0]->url());
273 400
274 // We end here without ever completing the request -- destruction of 401 // We end here without ever completing the request -- destruction of
275 // ProxyService will cancel the outstanding request. 402 // ProxyService will cancel the outstanding request.
276 } 403 }
277 404
278 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { 405 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) {
279 MockProxyConfigService* config_service = 406 MockProxyConfigService* config_service =
280 new MockProxyConfigService("http://foopy/proxy.pac"); 407 new MockProxyConfigService("http://foopy/proxy.pac");
281 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 408 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
282 409
283 ProxyService service(config_service, resolver, NULL); 410 ProxyService service(config_service, resolver, NULL);
284 411
285 GURL url("http://www.google.com/"); 412 GURL url("http://www.google.com/");
286 413
287 ProxyInfo info; 414 ProxyInfo info;
288 TestCompletionCallback callback1; 415 TestCompletionCallback callback1;
289 int rv = service.ResolveProxy( 416 int rv = service.ResolveProxy(
290 url, &info, callback1.callback(), NULL, BoundNetLog()); 417 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
291 EXPECT_EQ(ERR_IO_PENDING, rv); 418 EXPECT_EQ(ERR_IO_PENDING, rv);
292 419
293 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 420 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
294 resolver->pending_set_pac_script_request()->script_data()->url()); 421 resolver->pending_set_pac_script_request()->script_data()->url());
295 resolver->pending_set_pac_script_request()->CompleteNow(OK); 422 resolver->pending_set_pac_script_request()->CompleteNow(OK);
296 423
297 ASSERT_EQ(1u, resolver->pending_requests().size()); 424 ASSERT_EQ(1u, resolver->pending_requests().size());
298 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 425 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
299 426
300 // Set the result in proxy resolver. 427 // Set the result in proxy resolver.
301 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); 428 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080");
302 resolver->pending_requests()[0]->CompleteNow(OK); 429 resolver->pending_requests()[0]->CompleteNow(OK);
303 430
304 EXPECT_EQ(OK, callback1.WaitForResult()); 431 EXPECT_EQ(OK, callback1.WaitForResult());
305 EXPECT_FALSE(info.is_direct()); 432 EXPECT_FALSE(info.is_direct());
306 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); 433 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI());
307 EXPECT_TRUE(info.did_use_pac_script()); 434 EXPECT_TRUE(info.did_use_pac_script());
308 435
309 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 436 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
310 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 437 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
311 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 438 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
312 439
313 // Now, imagine that connecting to foopy:8080 fails: there is nothing 440 // Now, imagine that connecting to foopy:8080 fails: there is nothing
314 // left to fallback to, since our proxy list was NOT terminated by 441 // left to fallback to, since our proxy list was NOT terminated by
315 // DIRECT. 442 // DIRECT.
316 TestCompletionCallback callback2; 443 TestCompletionCallback callback2;
317 rv = service.ReconsiderProxyAfterError( 444 rv = service.ReconsiderProxyAfterError(
318 url, net::ERR_PROXY_CONNECTION_FAILED, 445 url, net::LOAD_NORMAL, net::ERR_PROXY_CONNECTION_FAILED,
319 &info, callback2.callback(), NULL, BoundNetLog()); 446 &info, callback2.callback(), NULL, NULL, BoundNetLog());
320 // ReconsiderProxyAfterError returns error indicating nothing left. 447 // ReconsiderProxyAfterError returns error indicating nothing left.
321 EXPECT_EQ(ERR_FAILED, rv); 448 EXPECT_EQ(ERR_FAILED, rv);
322 EXPECT_TRUE(info.is_empty()); 449 EXPECT_TRUE(info.is_empty());
323 } 450 }
324 451
325 // Test that if the execution of the PAC script fails (i.e. javascript runtime 452 // 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. 453 // error), and the PAC settings are non-mandatory, that we fall-back to direct.
327 TEST_F(ProxyServiceTest, PAC_RuntimeError) { 454 TEST_F(ProxyServiceTest, PAC_RuntimeError) {
328 MockProxyConfigService* config_service = 455 MockProxyConfigService* config_service =
329 new MockProxyConfigService("http://foopy/proxy.pac"); 456 new MockProxyConfigService("http://foopy/proxy.pac");
330 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 457 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
331 458
332 ProxyService service(config_service, resolver, NULL); 459 ProxyService service(config_service, resolver, NULL);
333 460
334 GURL url("http://this-causes-js-error/"); 461 GURL url("http://this-causes-js-error/");
335 462
336 ProxyInfo info; 463 ProxyInfo info;
337 TestCompletionCallback callback1; 464 TestCompletionCallback callback1;
338 int rv = service.ResolveProxy( 465 int rv = service.ResolveProxy(
339 url, &info, callback1.callback(), NULL, BoundNetLog()); 466 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
340 EXPECT_EQ(ERR_IO_PENDING, rv); 467 EXPECT_EQ(ERR_IO_PENDING, rv);
341 468
342 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 469 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
343 resolver->pending_set_pac_script_request()->script_data()->url()); 470 resolver->pending_set_pac_script_request()->script_data()->url());
344 resolver->pending_set_pac_script_request()->CompleteNow(OK); 471 resolver->pending_set_pac_script_request()->CompleteNow(OK);
345 472
346 ASSERT_EQ(1u, resolver->pending_requests().size()); 473 ASSERT_EQ(1u, resolver->pending_requests().size());
347 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 474 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
348 475
349 // Simulate a failure in the PAC executor. 476 // Simulate a failure in the PAC executor.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 new MockProxyConfigService("http://foopy/proxy.pac"); 511 new MockProxyConfigService("http://foopy/proxy.pac");
385 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 512 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
386 513
387 ProxyService service(config_service, resolver, NULL); 514 ProxyService service(config_service, resolver, NULL);
388 515
389 GURL url("http://www.google.com/"); 516 GURL url("http://www.google.com/");
390 517
391 ProxyInfo info; 518 ProxyInfo info;
392 TestCompletionCallback callback1; 519 TestCompletionCallback callback1;
393 int rv = service.ResolveProxy( 520 int rv = service.ResolveProxy(
394 url, &info, callback1.callback(), NULL, BoundNetLog()); 521 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
395 EXPECT_EQ(ERR_IO_PENDING, rv); 522 EXPECT_EQ(ERR_IO_PENDING, rv);
396 523
397 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 524 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
398 resolver->pending_set_pac_script_request()->script_data()->url()); 525 resolver->pending_set_pac_script_request()->script_data()->url());
399 resolver->pending_set_pac_script_request()->CompleteNow(OK); 526 resolver->pending_set_pac_script_request()->CompleteNow(OK);
400 527
401 ASSERT_EQ(1u, resolver->pending_requests().size()); 528 ASSERT_EQ(1u, resolver->pending_requests().size());
402 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 529 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
403 530
404 // Set the result in proxy resolver. 531 // Set the result in proxy resolver.
405 resolver->pending_requests()[0]->results()->UsePacString( 532 resolver->pending_requests()[0]->results()->UsePacString(
406 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); 533 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20");
407 resolver->pending_requests()[0]->CompleteNow(OK); 534 resolver->pending_requests()[0]->CompleteNow(OK);
408 535
409 EXPECT_EQ(OK, callback1.WaitForResult()); 536 EXPECT_EQ(OK, callback1.WaitForResult());
410 EXPECT_TRUE(info.is_direct()); 537 EXPECT_TRUE(info.is_direct());
411 538
412 // Fallback 1. 539 // Fallback 1.
413 TestCompletionCallback callback2; 540 TestCompletionCallback callback2;
414 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 541 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
542 net::ERR_PROXY_CONNECTION_FAILED,
415 &info, callback2.callback(), NULL, 543 &info, callback2.callback(), NULL,
416 BoundNetLog()); 544 NULL, BoundNetLog());
417 EXPECT_EQ(OK, rv); 545 EXPECT_EQ(OK, rv);
418 EXPECT_FALSE(info.is_direct()); 546 EXPECT_FALSE(info.is_direct());
419 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); 547 EXPECT_EQ("foobar:10", info.proxy_server().ToURI());
420 548
421 // Fallback 2. 549 // Fallback 2.
422 TestCompletionCallback callback3; 550 TestCompletionCallback callback3;
423 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 551 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
552 net::ERR_PROXY_CONNECTION_FAILED,
424 &info, callback3.callback(), NULL, 553 &info, callback3.callback(), NULL,
425 BoundNetLog()); 554 NULL, BoundNetLog());
426 EXPECT_EQ(OK, rv); 555 EXPECT_EQ(OK, rv);
427 EXPECT_TRUE(info.is_direct()); 556 EXPECT_TRUE(info.is_direct());
428 557
429 // Fallback 3. 558 // Fallback 3.
430 TestCompletionCallback callback4; 559 TestCompletionCallback callback4;
431 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 560 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
561 net::ERR_PROXY_CONNECTION_FAILED,
432 &info, callback4.callback(), NULL, 562 &info, callback4.callback(), NULL,
433 BoundNetLog()); 563 NULL, BoundNetLog());
434 EXPECT_EQ(OK, rv); 564 EXPECT_EQ(OK, rv);
435 EXPECT_FALSE(info.is_direct()); 565 EXPECT_FALSE(info.is_direct());
436 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); 566 EXPECT_EQ("foobar:20", info.proxy_server().ToURI());
437 567
438 // Fallback 4 -- Nothing to fall back to! 568 // Fallback 4 -- Nothing to fall back to!
439 TestCompletionCallback callback5; 569 TestCompletionCallback callback5;
440 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 570 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
571 net::ERR_PROXY_CONNECTION_FAILED,
441 &info, callback5.callback(), NULL, 572 &info, callback5.callback(), NULL,
442 BoundNetLog()); 573 NULL, BoundNetLog());
443 EXPECT_EQ(ERR_FAILED, rv); 574 EXPECT_EQ(ERR_FAILED, rv);
444 EXPECT_TRUE(info.is_empty()); 575 EXPECT_TRUE(info.is_empty());
445 } 576 }
446 577
447 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { 578 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) {
448 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied 579 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied
449 // to ProxyInfo after the proxy is resolved via a PAC script. 580 // to ProxyInfo after the proxy is resolved via a PAC script.
450 ProxyConfig config = 581 ProxyConfig config =
451 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); 582 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"));
452 config.set_source(PROXY_CONFIG_SOURCE_TEST); 583 config.set_source(PROXY_CONFIG_SOURCE_TEST);
453 584
454 MockProxyConfigService* config_service = new MockProxyConfigService(config); 585 MockProxyConfigService* config_service = new MockProxyConfigService(config);
455 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 586 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
456 ProxyService service(config_service, resolver, NULL); 587 ProxyService service(config_service, resolver, NULL);
457 588
458 // Resolve something. 589 // Resolve something.
459 GURL url("http://www.google.com/"); 590 GURL url("http://www.google.com/");
460 ProxyInfo info; 591 ProxyInfo info;
461 TestCompletionCallback callback; 592 TestCompletionCallback callback;
462 int rv = service.ResolveProxy( 593 int rv = service.ResolveProxy(
463 url, &info, callback.callback(), NULL, BoundNetLog()); 594 url, LOAD_NORMAL, &info, callback.callback(), NULL, NULL, BoundNetLog());
464 ASSERT_EQ(ERR_IO_PENDING, rv); 595 ASSERT_EQ(ERR_IO_PENDING, rv);
465 resolver->pending_set_pac_script_request()->CompleteNow(OK); 596 resolver->pending_set_pac_script_request()->CompleteNow(OK);
466 ASSERT_EQ(1u, resolver->pending_requests().size()); 597 ASSERT_EQ(1u, resolver->pending_requests().size());
467 598
468 // Set the result in proxy resolver. 599 // Set the result in proxy resolver.
469 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy"); 600 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy");
470 resolver->pending_requests()[0]->CompleteNow(OK); 601 resolver->pending_requests()[0]->CompleteNow(OK);
471 602
472 EXPECT_EQ(OK, callback.WaitForResult()); 603 EXPECT_EQ(OK, callback.WaitForResult());
473 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); 604 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
(...skipping 14 matching lines...) Expand all
488 619
489 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 620 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
490 621
491 ProxyService service(config_service, resolver, NULL); 622 ProxyService service(config_service, resolver, NULL);
492 623
493 // Start first resolve request. 624 // Start first resolve request.
494 GURL url("http://www.google.com/"); 625 GURL url("http://www.google.com/");
495 ProxyInfo info; 626 ProxyInfo info;
496 TestCompletionCallback callback1; 627 TestCompletionCallback callback1;
497 int rv = service.ResolveProxy( 628 int rv = service.ResolveProxy(
498 url, &info, callback1.callback(), NULL, BoundNetLog()); 629 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
499 EXPECT_EQ(ERR_IO_PENDING, rv); 630 EXPECT_EQ(ERR_IO_PENDING, rv);
500 631
501 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 632 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
502 resolver->pending_set_pac_script_request()->script_data()->url()); 633 resolver->pending_set_pac_script_request()->script_data()->url());
503 resolver->pending_set_pac_script_request()->CompleteNow(OK); 634 resolver->pending_set_pac_script_request()->CompleteNow(OK);
504 635
505 ASSERT_EQ(1u, resolver->pending_requests().size()); 636 ASSERT_EQ(1u, resolver->pending_requests().size());
506 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 637 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
507 638
508 // Fail the first resolve request in MockAsyncProxyResolver. 639 // Fail the first resolve request in MockAsyncProxyResolver.
509 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); 640 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED);
510 641
511 // Although the proxy resolver failed the request, ProxyService implicitly 642 // Although the proxy resolver failed the request, ProxyService implicitly
512 // falls-back to DIRECT. 643 // falls-back to DIRECT.
513 EXPECT_EQ(OK, callback1.WaitForResult()); 644 EXPECT_EQ(OK, callback1.WaitForResult());
514 EXPECT_TRUE(info.is_direct()); 645 EXPECT_TRUE(info.is_direct());
515 646
516 // Failed PAC executions still have proxy resolution times. 647 // Failed PAC executions still have proxy resolution times.
517 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 648 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
518 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 649 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
519 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 650 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
520 651
521 // The second resolve request will try to run through the proxy resolver, 652 // The second resolve request will try to run through the proxy resolver,
522 // regardless of whether the first request failed in it. 653 // regardless of whether the first request failed in it.
523 TestCompletionCallback callback2; 654 TestCompletionCallback callback2;
524 rv = service.ResolveProxy( 655 rv = service.ResolveProxy(
525 url, &info, callback2.callback(), NULL, BoundNetLog()); 656 url, LOAD_NORMAL, &info, callback2.callback(), NULL, NULL, BoundNetLog());
526 EXPECT_EQ(ERR_IO_PENDING, rv); 657 EXPECT_EQ(ERR_IO_PENDING, rv);
527 658
528 ASSERT_EQ(1u, resolver->pending_requests().size()); 659 ASSERT_EQ(1u, resolver->pending_requests().size());
529 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 660 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
530 661
531 // This time we will have the resolver succeed (perhaps the PAC script has 662 // This time we will have the resolver succeed (perhaps the PAC script has
532 // a dependency on the current time). 663 // a dependency on the current time).
533 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); 664 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080");
534 resolver->pending_requests()[0]->CompleteNow(OK); 665 resolver->pending_requests()[0]->CompleteNow(OK);
535 666
(...skipping 14 matching lines...) Expand all
550 681
551 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 682 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
552 683
553 ProxyService service(config_service, resolver, NULL); 684 ProxyService service(config_service, resolver, NULL);
554 685
555 // Start first resolve request. 686 // Start first resolve request.
556 GURL url("http://www.google.com/"); 687 GURL url("http://www.google.com/");
557 ProxyInfo info; 688 ProxyInfo info;
558 TestCompletionCallback callback1; 689 TestCompletionCallback callback1;
559 int rv = service.ResolveProxy( 690 int rv = service.ResolveProxy(
560 url, &info, callback1.callback(), NULL, BoundNetLog()); 691 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
561 EXPECT_EQ(ERR_IO_PENDING, rv); 692 EXPECT_EQ(ERR_IO_PENDING, rv);
562 693
563 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 694 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
564 resolver->pending_set_pac_script_request()->script_data()->url()); 695 resolver->pending_set_pac_script_request()->script_data()->url());
565 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED); 696 resolver->pending_set_pac_script_request()->CompleteNow(ERR_FAILED);
566 697
567 ASSERT_EQ(0u, resolver->pending_requests().size()); 698 ASSERT_EQ(0u, resolver->pending_requests().size());
568 699
569 // As the proxy resolver failed the request and is configured for a mandatory 700 // As the proxy resolver failed the request and is configured for a mandatory
570 // PAC script, ProxyService must not implicitly fall-back to DIRECT. 701 // PAC script, ProxyService must not implicitly fall-back to DIRECT.
571 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, 702 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED,
572 callback1.WaitForResult()); 703 callback1.WaitForResult());
573 EXPECT_FALSE(info.is_direct()); 704 EXPECT_FALSE(info.is_direct());
574 705
575 // As the proxy resolver failed the request and is configured for a mandatory 706 // As the proxy resolver failed the request and is configured for a mandatory
576 // PAC script, ProxyService must not implicitly fall-back to DIRECT. 707 // PAC script, ProxyService must not implicitly fall-back to DIRECT.
577 TestCompletionCallback callback2; 708 TestCompletionCallback callback2;
578 rv = service.ResolveProxy( 709 rv = service.ResolveProxy(
579 url, &info, callback2.callback(), NULL, BoundNetLog()); 710 url, LOAD_NORMAL, &info, callback2.callback(), NULL, NULL, BoundNetLog());
580 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); 711 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv);
581 EXPECT_FALSE(info.is_direct()); 712 EXPECT_FALSE(info.is_direct());
582 } 713 }
583 714
584 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { 715 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) {
585 // Test what happens when the ProxyResolver fails that is configured to use a 716 // 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 717 // mandatory PAC script. The download of the PAC script has already
587 // succeeded but the PAC script contains no valid javascript. 718 // succeeded but the PAC script contains no valid javascript.
588 719
589 ProxyConfig config( 720 ProxyConfig config(
590 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); 721 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")));
591 config.set_pac_mandatory(true); 722 config.set_pac_mandatory(true);
592 723
593 MockProxyConfigService* config_service = new MockProxyConfigService(config); 724 MockProxyConfigService* config_service = new MockProxyConfigService(config);
594 725
595 MockAsyncProxyResolverExpectsBytes* resolver = 726 MockAsyncProxyResolverExpectsBytes* resolver =
596 new MockAsyncProxyResolverExpectsBytes; 727 new MockAsyncProxyResolverExpectsBytes;
597 728
598 ProxyService service(config_service, resolver, NULL); 729 ProxyService service(config_service, resolver, NULL);
599 730
600 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 731 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
601 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); 732 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher();
602 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); 733 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher);
603 734
604 // Start resolve request. 735 // Start resolve request.
605 GURL url("http://www.google.com/"); 736 GURL url("http://www.google.com/");
606 ProxyInfo info; 737 ProxyInfo info;
607 TestCompletionCallback callback; 738 TestCompletionCallback callback;
608 int rv = service.ResolveProxy( 739 int rv = service.ResolveProxy(
609 url, &info, callback.callback(), NULL, BoundNetLog()); 740 url, LOAD_NORMAL, &info, callback.callback(), NULL, NULL, BoundNetLog());
610 EXPECT_EQ(ERR_IO_PENDING, rv); 741 EXPECT_EQ(ERR_IO_PENDING, rv);
611 742
612 // Check that nothing has been sent to the proxy resolver yet. 743 // Check that nothing has been sent to the proxy resolver yet.
613 ASSERT_EQ(0u, resolver->pending_requests().size()); 744 ASSERT_EQ(0u, resolver->pending_requests().size());
614 745
615 // Downloading the PAC script succeeds. 746 // Downloading the PAC script succeeds.
616 EXPECT_TRUE(fetcher->has_pending_request()); 747 EXPECT_TRUE(fetcher->has_pending_request());
617 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 748 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
618 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); 749 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents");
619 750
(...skipping 22 matching lines...) Expand all
642 773
643 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 774 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
644 775
645 ProxyService service(config_service, resolver, NULL); 776 ProxyService service(config_service, resolver, NULL);
646 777
647 // Start first resolve request. 778 // Start first resolve request.
648 GURL url("http://www.google.com/"); 779 GURL url("http://www.google.com/");
649 ProxyInfo info; 780 ProxyInfo info;
650 TestCompletionCallback callback1; 781 TestCompletionCallback callback1;
651 int rv = service.ResolveProxy( 782 int rv = service.ResolveProxy(
652 url, &info, callback1.callback(), NULL, BoundNetLog()); 783 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
653 EXPECT_EQ(ERR_IO_PENDING, rv); 784 EXPECT_EQ(ERR_IO_PENDING, rv);
654 785
655 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 786 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
656 resolver->pending_set_pac_script_request()->script_data()->url()); 787 resolver->pending_set_pac_script_request()->script_data()->url());
657 resolver->pending_set_pac_script_request()->CompleteNow(OK); 788 resolver->pending_set_pac_script_request()->CompleteNow(OK);
658 789
659 ASSERT_EQ(1u, resolver->pending_requests().size()); 790 ASSERT_EQ(1u, resolver->pending_requests().size());
660 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 791 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
661 792
662 // Fail the first resolve request in MockAsyncProxyResolver. 793 // Fail the first resolve request in MockAsyncProxyResolver.
663 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); 794 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED);
664 795
665 // As the proxy resolver failed the request and is configured for a mandatory 796 // As the proxy resolver failed the request and is configured for a mandatory
666 // PAC script, ProxyService must not implicitly fall-back to DIRECT. 797 // PAC script, ProxyService must not implicitly fall-back to DIRECT.
667 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, 798 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED,
668 callback1.WaitForResult()); 799 callback1.WaitForResult());
669 EXPECT_FALSE(info.is_direct()); 800 EXPECT_FALSE(info.is_direct());
670 801
671 // The second resolve request will try to run through the proxy resolver, 802 // The second resolve request will try to run through the proxy resolver,
672 // regardless of whether the first request failed in it. 803 // regardless of whether the first request failed in it.
673 TestCompletionCallback callback2; 804 TestCompletionCallback callback2;
674 rv = service.ResolveProxy( 805 rv = service.ResolveProxy(
675 url, &info, callback2.callback(), NULL, BoundNetLog()); 806 url, LOAD_NORMAL, &info, callback2.callback(), NULL, NULL, BoundNetLog());
676 EXPECT_EQ(ERR_IO_PENDING, rv); 807 EXPECT_EQ(ERR_IO_PENDING, rv);
677 808
678 ASSERT_EQ(1u, resolver->pending_requests().size()); 809 ASSERT_EQ(1u, resolver->pending_requests().size());
679 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 810 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
680 811
681 // This time we will have the resolver succeed (perhaps the PAC script has 812 // This time we will have the resolver succeed (perhaps the PAC script has
682 // a dependency on the current time). 813 // a dependency on the current time).
683 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); 814 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080");
684 resolver->pending_requests()[0]->CompleteNow(OK); 815 resolver->pending_requests()[0]->CompleteNow(OK);
685 816
(...skipping 12 matching lines...) Expand all
698 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 829 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
699 830
700 ProxyService service(config_service, resolver, NULL); 831 ProxyService service(config_service, resolver, NULL);
701 832
702 GURL url("http://www.google.com/"); 833 GURL url("http://www.google.com/");
703 834
704 // Get the proxy information. 835 // Get the proxy information.
705 ProxyInfo info; 836 ProxyInfo info;
706 TestCompletionCallback callback1; 837 TestCompletionCallback callback1;
707 int rv = service.ResolveProxy( 838 int rv = service.ResolveProxy(
708 url, &info, callback1.callback(), NULL, BoundNetLog()); 839 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
709 EXPECT_EQ(ERR_IO_PENDING, rv); 840 EXPECT_EQ(ERR_IO_PENDING, rv);
710 841
711 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 842 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
712 resolver->pending_set_pac_script_request()->script_data()->url()); 843 resolver->pending_set_pac_script_request()->script_data()->url());
713 resolver->pending_set_pac_script_request()->CompleteNow(OK); 844 resolver->pending_set_pac_script_request()->CompleteNow(OK);
714 845
715 ASSERT_EQ(1u, resolver->pending_requests().size()); 846 ASSERT_EQ(1u, resolver->pending_requests().size());
716 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 847 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
717 848
718 // Set the result in proxy resolver. 849 // Set the result in proxy resolver.
719 resolver->pending_requests()[0]->results()->UseNamedProxy( 850 resolver->pending_requests()[0]->results()->UseNamedProxy(
720 "foopy1:8080;foopy2:9090"); 851 "foopy1:8080;foopy2:9090");
721 resolver->pending_requests()[0]->CompleteNow(OK); 852 resolver->pending_requests()[0]->CompleteNow(OK);
722 853
723 // The first item is valid. 854 // The first item is valid.
724 EXPECT_EQ(OK, callback1.WaitForResult()); 855 EXPECT_EQ(OK, callback1.WaitForResult());
725 EXPECT_FALSE(info.is_direct()); 856 EXPECT_FALSE(info.is_direct());
726 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 857 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
727 858
728 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 859 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
729 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 860 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
730 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 861 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
731 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); 862 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time();
732 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); 863 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time();
733 864
734 // Fake an error on the proxy. 865 // Fake an error on the proxy.
735 TestCompletionCallback callback2; 866 TestCompletionCallback callback2;
736 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 867 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
868 net::ERR_PROXY_CONNECTION_FAILED,
737 &info, callback2.callback(), NULL, 869 &info, callback2.callback(), NULL,
738 BoundNetLog()); 870 NULL, BoundNetLog());
739 EXPECT_EQ(OK, rv); 871 EXPECT_EQ(OK, rv);
740 872
741 // Proxy times should not have been modified by fallback. 873 // Proxy times should not have been modified by fallback.
742 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); 874 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time());
743 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); 875 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time());
744 876
745 // The second proxy should be specified. 877 // The second proxy should be specified.
746 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 878 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
747 // Report back that the second proxy worked. This will globally mark the 879 // Report back that the second proxy worked. This will globally mark the
748 // first proxy as bad. 880 // first proxy as bad.
749 service.ReportSuccess(info); 881 service.ReportSuccess(info);
750 882
751 TestCompletionCallback callback3; 883 TestCompletionCallback callback3;
752 rv = service.ResolveProxy( 884 rv = service.ResolveProxy(
753 url, &info, callback3.callback(), NULL, BoundNetLog()); 885 url, LOAD_NORMAL, &info, callback3.callback(), NULL, NULL, BoundNetLog());
754 EXPECT_EQ(ERR_IO_PENDING, rv); 886 EXPECT_EQ(ERR_IO_PENDING, rv);
755 887
756 ASSERT_EQ(1u, resolver->pending_requests().size()); 888 ASSERT_EQ(1u, resolver->pending_requests().size());
757 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 889 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
758 890
759 // Set the result in proxy resolver -- the second result is already known 891 // 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. 892 // to be bad, so we will not try to use it initially.
761 resolver->pending_requests()[0]->results()->UseNamedProxy( 893 resolver->pending_requests()[0]->results()->UseNamedProxy(
762 "foopy3:7070;foopy1:8080;foopy2:9090"); 894 "foopy3:7070;foopy1:8080;foopy2:9090");
763 resolver->pending_requests()[0]->CompleteNow(OK); 895 resolver->pending_requests()[0]->CompleteNow(OK);
764 896
765 EXPECT_EQ(OK, callback3.WaitForResult()); 897 EXPECT_EQ(OK, callback3.WaitForResult());
766 EXPECT_FALSE(info.is_direct()); 898 EXPECT_FALSE(info.is_direct());
767 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); 899 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI());
768 900
769 // Proxy times should have been updated, so get them again. 901 // Proxy times should have been updated, so get them again.
770 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); 902 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time());
771 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 903 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
772 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 904 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
773 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 905 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
774 proxy_resolve_start_time = info.proxy_resolve_start_time(); 906 proxy_resolve_start_time = info.proxy_resolve_start_time();
775 proxy_resolve_end_time = info.proxy_resolve_end_time(); 907 proxy_resolve_end_time = info.proxy_resolve_end_time();
776 908
777 // We fake another error. It should now try the third one. 909 // We fake another error. It should now try the third one.
778 TestCompletionCallback callback4; 910 TestCompletionCallback callback4;
779 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 911 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
912 net::ERR_PROXY_CONNECTION_FAILED,
780 &info, callback4.callback(), NULL, 913 &info, callback4.callback(), NULL,
781 BoundNetLog()); 914 NULL, BoundNetLog());
782 EXPECT_EQ(OK, rv); 915 EXPECT_EQ(OK, rv);
783 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 916 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
784 917
785 // We fake another error. At this point we have tried all of the 918 // 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 919 // proxy servers we thought were valid; next we try the proxy server
787 // that was in our bad proxies map (foopy1:8080). 920 // that was in our bad proxies map (foopy1:8080).
788 TestCompletionCallback callback5; 921 TestCompletionCallback callback5;
789 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 922 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
923 net::ERR_PROXY_CONNECTION_FAILED,
790 &info, callback5.callback(), NULL, 924 &info, callback5.callback(), NULL,
791 BoundNetLog()); 925 NULL, BoundNetLog());
792 EXPECT_EQ(OK, rv); 926 EXPECT_EQ(OK, rv);
793 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 927 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
794 928
795 // Fake another error, the last proxy is gone, the list should now be empty, 929 // Fake another error, the last proxy is gone, the list should now be empty,
796 // so there is nothing left to try. 930 // so there is nothing left to try.
797 TestCompletionCallback callback6; 931 TestCompletionCallback callback6;
798 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 932 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
933 net::ERR_PROXY_CONNECTION_FAILED,
799 &info, callback6.callback(), NULL, 934 &info, callback6.callback(), NULL,
800 BoundNetLog()); 935 NULL, BoundNetLog());
801 EXPECT_EQ(ERR_FAILED, rv); 936 EXPECT_EQ(ERR_FAILED, rv);
802 EXPECT_FALSE(info.is_direct()); 937 EXPECT_FALSE(info.is_direct());
803 EXPECT_TRUE(info.is_empty()); 938 EXPECT_TRUE(info.is_empty());
804 939
805 // Proxy times should not have been modified by fallback. 940 // Proxy times should not have been modified by fallback.
806 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); 941 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time());
807 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); 942 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time());
808 943
809 // Look up proxies again 944 // Look up proxies again
810 TestCompletionCallback callback7; 945 TestCompletionCallback callback7;
811 rv = service.ResolveProxy(url, &info, callback7.callback(), NULL, 946 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback7.callback(), NULL,
812 BoundNetLog()); 947 NULL, BoundNetLog());
813 EXPECT_EQ(ERR_IO_PENDING, rv); 948 EXPECT_EQ(ERR_IO_PENDING, rv);
814 949
815 ASSERT_EQ(1u, resolver->pending_requests().size()); 950 ASSERT_EQ(1u, resolver->pending_requests().size());
816 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 951 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
817 952
818 // This time, the first 3 results have been found to be bad, but only the 953 // This time, the first 3 results have been found to be bad, but only the
819 // first proxy has been confirmed ... 954 // first proxy has been confirmed ...
820 resolver->pending_requests()[0]->results()->UseNamedProxy( 955 resolver->pending_requests()[0]->results()->UseNamedProxy(
821 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); 956 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091");
822 resolver->pending_requests()[0]->CompleteNow(OK); 957 resolver->pending_requests()[0]->CompleteNow(OK);
(...skipping 18 matching lines...) Expand all
841 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 976 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
842 977
843 ProxyService service(config_service, resolver, NULL); 978 ProxyService service(config_service, resolver, NULL);
844 979
845 GURL url("http://www.google.com/"); 980 GURL url("http://www.google.com/");
846 981
847 // Get the proxy information. 982 // Get the proxy information.
848 ProxyInfo info; 983 ProxyInfo info;
849 TestCompletionCallback callback1; 984 TestCompletionCallback callback1;
850 int rv = service.ResolveProxy( 985 int rv = service.ResolveProxy(
851 url, &info, callback1.callback(), NULL, BoundNetLog()); 986 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
852 EXPECT_EQ(ERR_IO_PENDING, rv); 987 EXPECT_EQ(ERR_IO_PENDING, rv);
853 988
854 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 989 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
855 resolver->pending_set_pac_script_request()->script_data()->url()); 990 resolver->pending_set_pac_script_request()->script_data()->url());
856 resolver->pending_set_pac_script_request()->CompleteNow(OK); 991 resolver->pending_set_pac_script_request()->CompleteNow(OK);
857 992
858 ASSERT_EQ(1u, resolver->pending_requests().size()); 993 ASSERT_EQ(1u, resolver->pending_requests().size());
859 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 994 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
860 995
861 // Set the result in proxy resolver. 996 // Set the result in proxy resolver.
862 resolver->pending_requests()[0]->results()->UsePacString( 997 resolver->pending_requests()[0]->results()->UsePacString(
863 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); 998 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT");
864 resolver->pending_requests()[0]->CompleteNow(OK); 999 resolver->pending_requests()[0]->CompleteNow(OK);
865 1000
866 // Get the first result. 1001 // Get the first result.
867 EXPECT_EQ(OK, callback1.WaitForResult()); 1002 EXPECT_EQ(OK, callback1.WaitForResult());
868 EXPECT_FALSE(info.is_direct()); 1003 EXPECT_FALSE(info.is_direct());
869 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1004 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
870 1005
871 // Fake an error on the proxy. 1006 // Fake an error on the proxy.
872 TestCompletionCallback callback2; 1007 TestCompletionCallback callback2;
873 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1008 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1009 net::ERR_PROXY_CONNECTION_FAILED,
874 &info, callback2.callback(), NULL, 1010 &info, callback2.callback(), NULL,
875 BoundNetLog()); 1011 NULL, BoundNetLog());
876 EXPECT_EQ(OK, rv); 1012 EXPECT_EQ(OK, rv);
877 1013
878 // Now we get back the second proxy. 1014 // Now we get back the second proxy.
879 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 1015 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
880 1016
881 // Fake an error on this proxy as well. 1017 // Fake an error on this proxy as well.
882 TestCompletionCallback callback3; 1018 TestCompletionCallback callback3;
883 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1019 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1020 net::ERR_PROXY_CONNECTION_FAILED,
884 &info, callback3.callback(), NULL, 1021 &info, callback3.callback(), NULL,
885 BoundNetLog()); 1022 NULL, BoundNetLog());
886 EXPECT_EQ(OK, rv); 1023 EXPECT_EQ(OK, rv);
887 1024
888 // Finally, we get back DIRECT. 1025 // Finally, we get back DIRECT.
889 EXPECT_TRUE(info.is_direct()); 1026 EXPECT_TRUE(info.is_direct());
890 1027
891 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 1028 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
892 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 1029 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
893 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 1030 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
894 1031
895 // Now we tell the proxy service that even DIRECT failed. 1032 // Now we tell the proxy service that even DIRECT failed.
896 TestCompletionCallback callback4; 1033 TestCompletionCallback callback4;
897 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1034 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1035 net::ERR_PROXY_CONNECTION_FAILED,
898 &info, callback4.callback(), NULL, 1036 &info, callback4.callback(), NULL,
899 BoundNetLog()); 1037 NULL, BoundNetLog());
900 // There was nothing left to try after DIRECT, so we are out of 1038 // There was nothing left to try after DIRECT, so we are out of
901 // choices. 1039 // choices.
902 EXPECT_EQ(ERR_FAILED, rv); 1040 EXPECT_EQ(ERR_FAILED, rv);
903 } 1041 }
904 1042
905 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { 1043 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) {
906 // Test proxy failover when new settings are available. 1044 // Test proxy failover when new settings are available.
907 1045
908 MockProxyConfigService* config_service = 1046 MockProxyConfigService* config_service =
909 new MockProxyConfigService("http://foopy/proxy.pac"); 1047 new MockProxyConfigService("http://foopy/proxy.pac");
910 1048
911 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 1049 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
912 1050
913 ProxyService service(config_service, resolver, NULL); 1051 ProxyService service(config_service, resolver, NULL);
914 1052
915 GURL url("http://www.google.com/"); 1053 GURL url("http://www.google.com/");
916 1054
917 // Get the proxy information. 1055 // Get the proxy information.
918 ProxyInfo info; 1056 ProxyInfo info;
919 TestCompletionCallback callback1; 1057 TestCompletionCallback callback1;
920 int rv = service.ResolveProxy( 1058 int rv = service.ResolveProxy(
921 url, &info, callback1.callback(), NULL, BoundNetLog()); 1059 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
922 EXPECT_EQ(ERR_IO_PENDING, rv); 1060 EXPECT_EQ(ERR_IO_PENDING, rv);
923 1061
924 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1062 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
925 resolver->pending_set_pac_script_request()->script_data()->url()); 1063 resolver->pending_set_pac_script_request()->script_data()->url());
926 resolver->pending_set_pac_script_request()->CompleteNow(OK); 1064 resolver->pending_set_pac_script_request()->CompleteNow(OK);
927 1065
928 ASSERT_EQ(1u, resolver->pending_requests().size()); 1066 ASSERT_EQ(1u, resolver->pending_requests().size());
929 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1067 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
930 1068
931 // Set the result in proxy resolver. 1069 // Set the result in proxy resolver.
932 resolver->pending_requests()[0]->results()->UseNamedProxy( 1070 resolver->pending_requests()[0]->results()->UseNamedProxy(
933 "foopy1:8080;foopy2:9090"); 1071 "foopy1:8080;foopy2:9090");
934 resolver->pending_requests()[0]->CompleteNow(OK); 1072 resolver->pending_requests()[0]->CompleteNow(OK);
935 1073
936 // The first item is valid. 1074 // The first item is valid.
937 EXPECT_EQ(OK, callback1.WaitForResult()); 1075 EXPECT_EQ(OK, callback1.WaitForResult());
938 EXPECT_FALSE(info.is_direct()); 1076 EXPECT_FALSE(info.is_direct());
939 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1077 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
940 1078
941 // Fake an error on the proxy, and also a new configuration on the proxy. 1079 // Fake an error on the proxy, and also a new configuration on the proxy.
942 config_service->SetConfig( 1080 config_service->SetConfig(
943 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); 1081 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac")));
944 1082
945 TestCompletionCallback callback2; 1083 TestCompletionCallback callback2;
946 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1084 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1085 net::ERR_PROXY_CONNECTION_FAILED,
947 &info, callback2.callback(), NULL, 1086 &info, callback2.callback(), NULL,
948 BoundNetLog()); 1087 NULL, BoundNetLog());
949 EXPECT_EQ(ERR_IO_PENDING, rv); 1088 EXPECT_EQ(ERR_IO_PENDING, rv);
950 1089
951 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), 1090 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"),
952 resolver->pending_set_pac_script_request()->script_data()->url()); 1091 resolver->pending_set_pac_script_request()->script_data()->url());
953 resolver->pending_set_pac_script_request()->CompleteNow(OK); 1092 resolver->pending_set_pac_script_request()->CompleteNow(OK);
954 1093
955 ASSERT_EQ(1u, resolver->pending_requests().size()); 1094 ASSERT_EQ(1u, resolver->pending_requests().size());
956 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1095 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
957 1096
958 resolver->pending_requests()[0]->results()->UseNamedProxy( 1097 resolver->pending_requests()[0]->results()->UseNamedProxy(
959 "foopy1:8080;foopy2:9090"); 1098 "foopy1:8080;foopy2:9090");
960 resolver->pending_requests()[0]->CompleteNow(OK); 1099 resolver->pending_requests()[0]->CompleteNow(OK);
961 1100
962 // The first proxy is still there since the configuration changed. 1101 // The first proxy is still there since the configuration changed.
963 EXPECT_EQ(OK, callback2.WaitForResult()); 1102 EXPECT_EQ(OK, callback2.WaitForResult());
964 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1103 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
965 1104
966 // We fake another error. It should now ignore the first one. 1105 // We fake another error. It should now ignore the first one.
967 TestCompletionCallback callback3; 1106 TestCompletionCallback callback3;
968 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1107 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1108 net::ERR_PROXY_CONNECTION_FAILED,
969 &info, callback3.callback(), NULL, 1109 &info, callback3.callback(), NULL,
970 BoundNetLog()); 1110 NULL, BoundNetLog());
971 EXPECT_EQ(OK, rv); 1111 EXPECT_EQ(OK, rv);
972 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 1112 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
973 1113
974 // We simulate a new configuration. 1114 // We simulate a new configuration.
975 config_service->SetConfig( 1115 config_service->SetConfig(
976 ProxyConfig::CreateFromCustomPacURL( 1116 ProxyConfig::CreateFromCustomPacURL(
977 GURL("http://foopy-new2/proxy.pac"))); 1117 GURL("http://foopy-new2/proxy.pac")));
978 1118
979 // We fake another error. It should go back to the first proxy. 1119 // We fake another error. It should go back to the first proxy.
980 TestCompletionCallback callback4; 1120 TestCompletionCallback callback4;
981 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1121 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1122 net::ERR_PROXY_CONNECTION_FAILED,
982 &info, callback4.callback(), NULL, 1123 &info, callback4.callback(), NULL,
983 BoundNetLog()); 1124 NULL, BoundNetLog());
984 EXPECT_EQ(ERR_IO_PENDING, rv); 1125 EXPECT_EQ(ERR_IO_PENDING, rv);
985 1126
986 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), 1127 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"),
987 resolver->pending_set_pac_script_request()->script_data()->url()); 1128 resolver->pending_set_pac_script_request()->script_data()->url());
988 resolver->pending_set_pac_script_request()->CompleteNow(OK); 1129 resolver->pending_set_pac_script_request()->CompleteNow(OK);
989 1130
990 ASSERT_EQ(1u, resolver->pending_requests().size()); 1131 ASSERT_EQ(1u, resolver->pending_requests().size());
991 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1132 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
992 1133
993 resolver->pending_requests()[0]->results()->UseNamedProxy( 1134 resolver->pending_requests()[0]->results()->UseNamedProxy(
(...skipping 17 matching lines...) Expand all
1011 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 1152 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
1012 1153
1013 ProxyService service(config_service, resolver, NULL); 1154 ProxyService service(config_service, resolver, NULL);
1014 1155
1015 GURL url("http://www.google.com/"); 1156 GURL url("http://www.google.com/");
1016 1157
1017 // Get the proxy information. 1158 // Get the proxy information.
1018 ProxyInfo info; 1159 ProxyInfo info;
1019 TestCompletionCallback callback1; 1160 TestCompletionCallback callback1;
1020 int rv = service.ResolveProxy( 1161 int rv = service.ResolveProxy(
1021 url, &info, callback1.callback(), NULL, BoundNetLog()); 1162 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
1022 EXPECT_EQ(ERR_IO_PENDING, rv); 1163 EXPECT_EQ(ERR_IO_PENDING, rv);
1023 1164
1024 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1165 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1025 resolver->pending_set_pac_script_request()->script_data()->url()); 1166 resolver->pending_set_pac_script_request()->script_data()->url());
1026 resolver->pending_set_pac_script_request()->CompleteNow(OK); 1167 resolver->pending_set_pac_script_request()->CompleteNow(OK);
1027 ASSERT_EQ(1u, resolver->pending_requests().size()); 1168 ASSERT_EQ(1u, resolver->pending_requests().size());
1028 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1169 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
1029 1170
1030 resolver->pending_requests()[0]->results()->UseNamedProxy( 1171 resolver->pending_requests()[0]->results()->UseNamedProxy(
1031 "foopy1:8080;foopy2:9090"); 1172 "foopy1:8080;foopy2:9090");
1032 resolver->pending_requests()[0]->CompleteNow(OK); 1173 resolver->pending_requests()[0]->CompleteNow(OK);
1033 1174
1034 // The first item is valid. 1175 // The first item is valid.
1035 EXPECT_EQ(OK, callback1.WaitForResult()); 1176 EXPECT_EQ(OK, callback1.WaitForResult());
1036 EXPECT_FALSE(info.is_direct()); 1177 EXPECT_FALSE(info.is_direct());
1037 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1178 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1038 1179
1039 // Fake a proxy error. 1180 // Fake a proxy error.
1040 TestCompletionCallback callback2; 1181 TestCompletionCallback callback2;
1041 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1182 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1183 net::ERR_PROXY_CONNECTION_FAILED,
1042 &info, callback2.callback(), NULL, 1184 &info, callback2.callback(), NULL,
1043 BoundNetLog()); 1185 NULL, BoundNetLog());
1044 EXPECT_EQ(OK, rv); 1186 EXPECT_EQ(OK, rv);
1045 1187
1046 // The first proxy is ignored, and the second one is selected. 1188 // The first proxy is ignored, and the second one is selected.
1047 EXPECT_FALSE(info.is_direct()); 1189 EXPECT_FALSE(info.is_direct());
1048 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 1190 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
1049 1191
1050 // Fake a PAC failure. 1192 // Fake a PAC failure.
1051 ProxyInfo info2; 1193 ProxyInfo info2;
1052 TestCompletionCallback callback3; 1194 TestCompletionCallback callback3;
1053 rv = service.ResolveProxy( 1195 rv = service.ResolveProxy(
1054 url, &info2, callback3.callback(), NULL, BoundNetLog()); 1196 url, LOAD_NORMAL, &info2, callback3.callback(), NULL, NULL,
1197 BoundNetLog());
1055 EXPECT_EQ(ERR_IO_PENDING, rv); 1198 EXPECT_EQ(ERR_IO_PENDING, rv);
1056 1199
1057 ASSERT_EQ(1u, resolver->pending_requests().size()); 1200 ASSERT_EQ(1u, resolver->pending_requests().size());
1058 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1201 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
1059 1202
1060 // This simulates a javascript runtime error in the PAC script. 1203 // This simulates a javascript runtime error in the PAC script.
1061 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); 1204 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED);
1062 1205
1063 // Although the resolver failed, the ProxyService will implicitly fall-back 1206 // Although the resolver failed, the ProxyService will implicitly fall-back
1064 // to a DIRECT connection. 1207 // to a DIRECT connection.
1065 EXPECT_EQ(OK, callback3.WaitForResult()); 1208 EXPECT_EQ(OK, callback3.WaitForResult());
1066 EXPECT_TRUE(info2.is_direct()); 1209 EXPECT_TRUE(info2.is_direct());
1067 EXPECT_FALSE(info2.is_empty()); 1210 EXPECT_FALSE(info2.is_empty());
1068 1211
1069 // The PAC script will work properly next time and successfully return a 1212 // 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 1213 // proxy list. Since we have not marked the configuration as bad, it should
1071 // "just work" the next time we call it. 1214 // "just work" the next time we call it.
1072 ProxyInfo info3; 1215 ProxyInfo info3;
1073 TestCompletionCallback callback4; 1216 TestCompletionCallback callback4;
1074 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1217 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1218 net::ERR_PROXY_CONNECTION_FAILED,
1075 &info3, callback4.callback(), 1219 &info3, callback4.callback(),
1076 NULL, BoundNetLog()); 1220 NULL, NULL, BoundNetLog());
1077 EXPECT_EQ(ERR_IO_PENDING, rv); 1221 EXPECT_EQ(ERR_IO_PENDING, rv);
1078 1222
1079 ASSERT_EQ(1u, resolver->pending_requests().size()); 1223 ASSERT_EQ(1u, resolver->pending_requests().size());
1080 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1224 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
1081 1225
1082 resolver->pending_requests()[0]->results()->UseNamedProxy( 1226 resolver->pending_requests()[0]->results()->UseNamedProxy(
1083 "foopy1:8080;foopy2:9090"); 1227 "foopy1:8080;foopy2:9090");
1084 resolver->pending_requests()[0]->CompleteNow(OK); 1228 resolver->pending_requests()[0]->CompleteNow(OK);
1085 1229
1086 // The first proxy is not there since the it was added to the bad proxies 1230 // The first proxy is not there since the it was added to the bad proxies
(...skipping 19 matching lines...) Expand all
1106 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 1250 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
1107 1251
1108 ProxyService service(config_service, resolver, NULL); 1252 ProxyService service(config_service, resolver, NULL);
1109 1253
1110 GURL url("http://www.google.com/"); 1254 GURL url("http://www.google.com/");
1111 1255
1112 // Get the proxy information. 1256 // Get the proxy information.
1113 ProxyInfo info; 1257 ProxyInfo info;
1114 TestCompletionCallback callback1; 1258 TestCompletionCallback callback1;
1115 int rv = service.ResolveProxy( 1259 int rv = service.ResolveProxy(
1116 url, &info, callback1.callback(), NULL, BoundNetLog()); 1260 url, LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, BoundNetLog());
1117 EXPECT_EQ(ERR_IO_PENDING, rv); 1261 EXPECT_EQ(ERR_IO_PENDING, rv);
1118 1262
1119 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1263 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1120 resolver->pending_set_pac_script_request()->script_data()->url()); 1264 resolver->pending_set_pac_script_request()->script_data()->url());
1121 resolver->pending_set_pac_script_request()->CompleteNow(OK); 1265 resolver->pending_set_pac_script_request()->CompleteNow(OK);
1122 ASSERT_EQ(1u, resolver->pending_requests().size()); 1266 ASSERT_EQ(1u, resolver->pending_requests().size());
1123 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1267 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
1124 1268
1125 resolver->pending_requests()[0]->results()->UseNamedProxy( 1269 resolver->pending_requests()[0]->results()->UseNamedProxy(
1126 "foopy1:8080;foopy2:9090"); 1270 "foopy1:8080;foopy2:9090");
1127 resolver->pending_requests()[0]->CompleteNow(OK); 1271 resolver->pending_requests()[0]->CompleteNow(OK);
1128 1272
1129 // The first item is valid. 1273 // The first item is valid.
1130 EXPECT_EQ(OK, callback1.WaitForResult()); 1274 EXPECT_EQ(OK, callback1.WaitForResult());
1131 EXPECT_FALSE(info.is_direct()); 1275 EXPECT_FALSE(info.is_direct());
1132 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1276 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1133 1277
1134 // Fake a proxy error. 1278 // Fake a proxy error.
1135 TestCompletionCallback callback2; 1279 TestCompletionCallback callback2;
1136 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1280 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1281 net::ERR_PROXY_CONNECTION_FAILED,
1137 &info, callback2.callback(), NULL, 1282 &info, callback2.callback(), NULL,
1138 BoundNetLog()); 1283 NULL, BoundNetLog());
1139 EXPECT_EQ(OK, rv); 1284 EXPECT_EQ(OK, rv);
1140 1285
1141 // The first proxy is ignored, and the second one is selected. 1286 // The first proxy is ignored, and the second one is selected.
1142 EXPECT_FALSE(info.is_direct()); 1287 EXPECT_FALSE(info.is_direct());
1143 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 1288 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
1144 1289
1145 // Fake a PAC failure. 1290 // Fake a PAC failure.
1146 ProxyInfo info2; 1291 ProxyInfo info2;
1147 TestCompletionCallback callback3; 1292 TestCompletionCallback callback3;
1148 rv = service.ResolveProxy( 1293 rv = service.ResolveProxy(
1149 url, &info2, callback3.callback(), NULL, BoundNetLog()); 1294 url, LOAD_NORMAL, &info2, callback3.callback(), NULL, NULL,
1295 BoundNetLog());
1150 EXPECT_EQ(ERR_IO_PENDING, rv); 1296 EXPECT_EQ(ERR_IO_PENDING, rv);
1151 1297
1152 ASSERT_EQ(1u, resolver->pending_requests().size()); 1298 ASSERT_EQ(1u, resolver->pending_requests().size());
1153 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1299 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
1154 1300
1155 // This simulates a javascript runtime error in the PAC script. 1301 // This simulates a javascript runtime error in the PAC script.
1156 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); 1302 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED);
1157 1303
1158 // Although the resolver failed, the ProxyService will NOT fall-back 1304 // Although the resolver failed, the ProxyService will NOT fall-back
1159 // to a DIRECT connection as it is configured as mandatory. 1305 // to a DIRECT connection as it is configured as mandatory.
1160 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, 1306 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED,
1161 callback3.WaitForResult()); 1307 callback3.WaitForResult());
1162 EXPECT_FALSE(info2.is_direct()); 1308 EXPECT_FALSE(info2.is_direct());
1163 EXPECT_TRUE(info2.is_empty()); 1309 EXPECT_TRUE(info2.is_empty());
1164 1310
1165 // The PAC script will work properly next time and successfully return a 1311 // 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 1312 // proxy list. Since we have not marked the configuration as bad, it should
1167 // "just work" the next time we call it. 1313 // "just work" the next time we call it.
1168 ProxyInfo info3; 1314 ProxyInfo info3;
1169 TestCompletionCallback callback4; 1315 TestCompletionCallback callback4;
1170 rv = service.ReconsiderProxyAfterError(url, net::ERR_PROXY_CONNECTION_FAILED, 1316 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1317 net::ERR_PROXY_CONNECTION_FAILED,
1171 &info3, callback4.callback(), 1318 &info3, callback4.callback(),
1172 NULL, BoundNetLog()); 1319 NULL, NULL, BoundNetLog());
1173 EXPECT_EQ(ERR_IO_PENDING, rv); 1320 EXPECT_EQ(ERR_IO_PENDING, rv);
1174 1321
1175 ASSERT_EQ(1u, resolver->pending_requests().size()); 1322 ASSERT_EQ(1u, resolver->pending_requests().size());
1176 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 1323 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
1177 1324
1178 resolver->pending_requests()[0]->results()->UseNamedProxy( 1325 resolver->pending_requests()[0]->results()->UseNamedProxy(
1179 "foopy1:8080;foopy2:9090"); 1326 "foopy1:8080;foopy2:9090");
1180 resolver->pending_requests()[0]->CompleteNow(OK); 1327 resolver->pending_requests()[0]->CompleteNow(OK);
1181 1328
1182 // The first proxy is not there since the it was added to the bad proxies 1329 // The first proxy is not there since the it was added to the bad proxies
(...skipping 15 matching lines...) Expand all
1198 1345
1199 ProxyService service( 1346 ProxyService service(
1200 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1347 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1201 1348
1202 int rv; 1349 int rv;
1203 GURL url1("http://www.webkit.org"); 1350 GURL url1("http://www.webkit.org");
1204 GURL url2("http://www.webkit.com"); 1351 GURL url2("http://www.webkit.com");
1205 1352
1206 // Request for a .org domain should bypass proxy. 1353 // Request for a .org domain should bypass proxy.
1207 rv = service.ResolveProxy( 1354 rv = service.ResolveProxy(
1208 url1, &info[0], callback[0].callback(), NULL, BoundNetLog()); 1355 url1, LOAD_NORMAL, &info[0], callback[0].callback(), NULL, NULL,
1356 BoundNetLog());
1209 EXPECT_EQ(OK, rv); 1357 EXPECT_EQ(OK, rv);
1210 EXPECT_TRUE(info[0].is_direct()); 1358 EXPECT_TRUE(info[0].is_direct());
1211 1359
1212 // Request for a .com domain hits the proxy. 1360 // Request for a .com domain hits the proxy.
1213 rv = service.ResolveProxy( 1361 rv = service.ResolveProxy(
1214 url2, &info[1], callback[1].callback(), NULL, BoundNetLog()); 1362 url2, LOAD_NORMAL, &info[1], callback[1].callback(), NULL, NULL,
1363 BoundNetLog());
1215 EXPECT_EQ(OK, rv); 1364 EXPECT_EQ(OK, rv);
1216 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); 1365 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI());
1217 } 1366 }
1218 1367
1219 1368
1220 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { 1369 TEST_F(ProxyServiceTest, PerProtocolProxyTests) {
1221 ProxyConfig config; 1370 ProxyConfig config;
1222 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); 1371 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080");
1223 config.set_auto_detect(false); 1372 config.set_auto_detect(false);
1224 { 1373 {
1225 ProxyService service( 1374 ProxyService service(
1226 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1375 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1227 GURL test_url("http://www.msn.com"); 1376 GURL test_url("http://www.msn.com");
1228 ProxyInfo info; 1377 ProxyInfo info;
1229 TestCompletionCallback callback; 1378 TestCompletionCallback callback;
1230 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1379 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1380 callback.callback(), NULL, NULL,
1231 BoundNetLog()); 1381 BoundNetLog());
1232 EXPECT_EQ(OK, rv); 1382 EXPECT_EQ(OK, rv);
1233 EXPECT_FALSE(info.is_direct()); 1383 EXPECT_FALSE(info.is_direct());
1234 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1384 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1235 } 1385 }
1236 { 1386 {
1237 ProxyService service( 1387 ProxyService service(
1238 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1388 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1239 GURL test_url("ftp://ftp.google.com"); 1389 GURL test_url("ftp://ftp.google.com");
1240 ProxyInfo info; 1390 ProxyInfo info;
1241 TestCompletionCallback callback; 1391 TestCompletionCallback callback;
1242 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1392 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1243 BoundNetLog()); 1393 callback.callback(), NULL,
1394 NULL, BoundNetLog());
1244 EXPECT_EQ(OK, rv); 1395 EXPECT_EQ(OK, rv);
1245 EXPECT_TRUE(info.is_direct()); 1396 EXPECT_TRUE(info.is_direct());
1246 EXPECT_EQ("direct://", info.proxy_server().ToURI()); 1397 EXPECT_EQ("direct://", info.proxy_server().ToURI());
1247 } 1398 }
1248 { 1399 {
1249 ProxyService service( 1400 ProxyService service(
1250 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1401 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1251 GURL test_url("https://webbranch.techcu.com"); 1402 GURL test_url("https://webbranch.techcu.com");
1252 ProxyInfo info; 1403 ProxyInfo info;
1253 TestCompletionCallback callback; 1404 TestCompletionCallback callback;
1254 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1405 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1255 BoundNetLog()); 1406 callback.callback(), NULL,
1407 NULL, BoundNetLog());
1256 EXPECT_EQ(OK, rv); 1408 EXPECT_EQ(OK, rv);
1257 EXPECT_FALSE(info.is_direct()); 1409 EXPECT_FALSE(info.is_direct());
1258 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); 1410 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI());
1259 } 1411 }
1260 { 1412 {
1261 config.proxy_rules().ParseFromString("foopy1:8080"); 1413 config.proxy_rules().ParseFromString("foopy1:8080");
1262 ProxyService service( 1414 ProxyService service(
1263 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1415 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1264 GURL test_url("http://www.microsoft.com"); 1416 GURL test_url("http://www.microsoft.com");
1265 ProxyInfo info; 1417 ProxyInfo info;
1266 TestCompletionCallback callback; 1418 TestCompletionCallback callback;
1267 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1419 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1268 BoundNetLog()); 1420 callback.callback(), NULL,
1421 NULL, BoundNetLog());
1269 EXPECT_EQ(OK, rv); 1422 EXPECT_EQ(OK, rv);
1270 EXPECT_FALSE(info.is_direct()); 1423 EXPECT_FALSE(info.is_direct());
1271 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1424 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1272 } 1425 }
1273 } 1426 }
1274 1427
1275 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { 1428 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) {
1276 // Test that the proxy config source is set correctly when resolving proxies 1429 // 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 1430 // using manual proxy rules. Namely, the config source should only be set if
1278 // any of the rules were applied. 1431 // any of the rules were applied.
1279 { 1432 {
1280 ProxyConfig config; 1433 ProxyConfig config;
1281 config.set_source(PROXY_CONFIG_SOURCE_TEST); 1434 config.set_source(PROXY_CONFIG_SOURCE_TEST);
1282 config.proxy_rules().ParseFromString("https=foopy2:8080"); 1435 config.proxy_rules().ParseFromString("https=foopy2:8080");
1283 ProxyService service( 1436 ProxyService service(
1284 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1437 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1285 GURL test_url("http://www.google.com"); 1438 GURL test_url("http://www.google.com");
1286 ProxyInfo info; 1439 ProxyInfo info;
1287 TestCompletionCallback callback; 1440 TestCompletionCallback callback;
1288 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1441 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1289 BoundNetLog()); 1442 callback.callback(), NULL,
1443 NULL, BoundNetLog());
1290 ASSERT_EQ(OK, rv); 1444 ASSERT_EQ(OK, rv);
1291 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. 1445 // Should be SOURCE_TEST, even if there are no HTTP proxies configured.
1292 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); 1446 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
1293 } 1447 }
1294 { 1448 {
1295 ProxyConfig config; 1449 ProxyConfig config;
1296 config.set_source(PROXY_CONFIG_SOURCE_TEST); 1450 config.set_source(PROXY_CONFIG_SOURCE_TEST);
1297 config.proxy_rules().ParseFromString("https=foopy2:8080"); 1451 config.proxy_rules().ParseFromString("https=foopy2:8080");
1298 ProxyService service( 1452 ProxyService service(
1299 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1453 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1300 GURL test_url("https://www.google.com"); 1454 GURL test_url("https://www.google.com");
1301 ProxyInfo info; 1455 ProxyInfo info;
1302 TestCompletionCallback callback; 1456 TestCompletionCallback callback;
1303 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1457 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1304 BoundNetLog()); 1458 callback.callback(), NULL,
1459 NULL, BoundNetLog());
1305 ASSERT_EQ(OK, rv); 1460 ASSERT_EQ(OK, rv);
1306 // Used the HTTPS proxy. So source should be TEST. 1461 // Used the HTTPS proxy. So source should be TEST.
1307 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); 1462 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
1308 } 1463 }
1309 { 1464 {
1310 ProxyConfig config; 1465 ProxyConfig config;
1311 config.set_source(PROXY_CONFIG_SOURCE_TEST); 1466 config.set_source(PROXY_CONFIG_SOURCE_TEST);
1312 ProxyService service( 1467 ProxyService service(
1313 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1468 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1314 GURL test_url("http://www.google.com"); 1469 GURL test_url("http://www.google.com");
1315 ProxyInfo info; 1470 ProxyInfo info;
1316 TestCompletionCallback callback; 1471 TestCompletionCallback callback;
1317 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1472 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1318 BoundNetLog()); 1473 callback.callback(), NULL,
1474 NULL, BoundNetLog());
1319 ASSERT_EQ(OK, rv); 1475 ASSERT_EQ(OK, rv);
1320 // ProxyConfig is empty. Source should still be TEST. 1476 // ProxyConfig is empty. Source should still be TEST.
1321 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); 1477 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
1322 } 1478 }
1323 } 1479 }
1324 1480
1325 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries 1481 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries
1326 // fall back to the SOCKS proxy. 1482 // fall back to the SOCKS proxy.
1327 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { 1483 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) {
1328 ProxyConfig config; 1484 ProxyConfig config;
1329 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); 1485 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080");
1330 config.set_auto_detect(false); 1486 config.set_auto_detect(false);
1331 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 1487 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
1332 config.proxy_rules().type); 1488 config.proxy_rules().type);
1333 1489
1334 { 1490 {
1335 ProxyService service( 1491 ProxyService service(
1336 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1492 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1337 GURL test_url("http://www.msn.com"); 1493 GURL test_url("http://www.msn.com");
1338 ProxyInfo info; 1494 ProxyInfo info;
1339 TestCompletionCallback callback; 1495 TestCompletionCallback callback;
1340 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1496 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1341 BoundNetLog()); 1497 callback.callback(), NULL,
1498 NULL, BoundNetLog());
1342 EXPECT_EQ(OK, rv); 1499 EXPECT_EQ(OK, rv);
1343 EXPECT_FALSE(info.is_direct()); 1500 EXPECT_FALSE(info.is_direct());
1344 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1501 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1345 } 1502 }
1346 { 1503 {
1347 ProxyService service( 1504 ProxyService service(
1348 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1505 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1349 GURL test_url("ftp://ftp.google.com"); 1506 GURL test_url("ftp://ftp.google.com");
1350 ProxyInfo info; 1507 ProxyInfo info;
1351 TestCompletionCallback callback; 1508 TestCompletionCallback callback;
1352 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1509 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1353 BoundNetLog()); 1510 callback.callback(), NULL,
1511 NULL, BoundNetLog());
1354 EXPECT_EQ(OK, rv); 1512 EXPECT_EQ(OK, rv);
1355 EXPECT_FALSE(info.is_direct()); 1513 EXPECT_FALSE(info.is_direct());
1356 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); 1514 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI());
1357 } 1515 }
1358 { 1516 {
1359 ProxyService service( 1517 ProxyService service(
1360 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1518 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1361 GURL test_url("https://webbranch.techcu.com"); 1519 GURL test_url("https://webbranch.techcu.com");
1362 ProxyInfo info; 1520 ProxyInfo info;
1363 TestCompletionCallback callback; 1521 TestCompletionCallback callback;
1364 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1522 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1365 BoundNetLog()); 1523 callback.callback(), NULL,
1524 NULL, BoundNetLog());
1366 EXPECT_EQ(OK, rv); 1525 EXPECT_EQ(OK, rv);
1367 EXPECT_FALSE(info.is_direct()); 1526 EXPECT_FALSE(info.is_direct());
1368 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); 1527 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI());
1369 } 1528 }
1370 { 1529 {
1371 ProxyService service( 1530 ProxyService service(
1372 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL); 1531 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
1373 GURL test_url("unknown://www.microsoft.com"); 1532 GURL test_url("unknown://www.microsoft.com");
1374 ProxyInfo info; 1533 ProxyInfo info;
1375 TestCompletionCallback callback; 1534 TestCompletionCallback callback;
1376 int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL, 1535 int rv = service.ResolveProxy(test_url, LOAD_NORMAL, &info,
1377 BoundNetLog()); 1536 callback.callback(), NULL,
1537 NULL, BoundNetLog());
1378 EXPECT_EQ(OK, rv); 1538 EXPECT_EQ(OK, rv);
1379 EXPECT_FALSE(info.is_direct()); 1539 EXPECT_FALSE(info.is_direct());
1380 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); 1540 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI());
1381 } 1541 }
1382 } 1542 }
1383 1543
1384 // Test cancellation of an in-progress request. 1544 // Test cancellation of an in-progress request.
1385 TEST_F(ProxyServiceTest, CancelInProgressRequest) { 1545 TEST_F(ProxyServiceTest, CancelInProgressRequest) {
1386 MockProxyConfigService* config_service = 1546 MockProxyConfigService* config_service =
1387 new MockProxyConfigService("http://foopy/proxy.pac"); 1547 new MockProxyConfigService("http://foopy/proxy.pac");
1388 1548
1389 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 1549 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
1390 1550
1391 ProxyService service(config_service, resolver, NULL); 1551 ProxyService service(config_service, resolver, NULL);
1392 1552
1393 // Start 3 requests. 1553 // Start 3 requests.
1394 1554
1395 ProxyInfo info1; 1555 ProxyInfo info1;
1396 TestCompletionCallback callback1; 1556 TestCompletionCallback callback1;
1397 int rv = service.ResolveProxy(GURL("http://request1"), &info1, 1557 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1,
1398 callback1.callback(), NULL, BoundNetLog()); 1558 callback1.callback(), NULL, NULL,
1559 BoundNetLog());
1399 EXPECT_EQ(ERR_IO_PENDING, rv); 1560 EXPECT_EQ(ERR_IO_PENDING, rv);
1400 1561
1401 // Nothing has been sent to the proxy resolver yet, since the proxy 1562 // Nothing has been sent to the proxy resolver yet, since the proxy
1402 // resolver has not been configured yet. 1563 // resolver has not been configured yet.
1403 ASSERT_EQ(0u, resolver->pending_requests().size()); 1564 ASSERT_EQ(0u, resolver->pending_requests().size());
1404 1565
1405 // Successfully initialize the PAC script. 1566 // Successfully initialize the PAC script.
1406 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1567 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1407 resolver->pending_set_pac_script_request()->script_data()->url()); 1568 resolver->pending_set_pac_script_request()->script_data()->url());
1408 resolver->pending_set_pac_script_request()->CompleteNow(OK); 1569 resolver->pending_set_pac_script_request()->CompleteNow(OK);
1409 1570
1410 ASSERT_EQ(1u, resolver->pending_requests().size()); 1571 ASSERT_EQ(1u, resolver->pending_requests().size());
1411 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); 1572 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url());
1412 1573
1413 ProxyInfo info2; 1574 ProxyInfo info2;
1414 TestCompletionCallback callback2; 1575 TestCompletionCallback callback2;
1415 ProxyService::PacRequest* request2; 1576 ProxyService::PacRequest* request2;
1416 rv = service.ResolveProxy(GURL("http://request2"), &info2, 1577 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2,
1417 callback2.callback(), &request2, BoundNetLog()); 1578 callback2.callback(), &request2, NULL,
1579 BoundNetLog());
1418 EXPECT_EQ(ERR_IO_PENDING, rv); 1580 EXPECT_EQ(ERR_IO_PENDING, rv);
1419 ASSERT_EQ(2u, resolver->pending_requests().size()); 1581 ASSERT_EQ(2u, resolver->pending_requests().size());
1420 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url()); 1582 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[1]->url());
1421 1583
1422 ProxyInfo info3; 1584 ProxyInfo info3;
1423 TestCompletionCallback callback3; 1585 TestCompletionCallback callback3;
1424 rv = service.ResolveProxy(GURL("http://request3"), &info3, 1586 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3,
1425 callback3.callback(), NULL, BoundNetLog()); 1587 callback3.callback(), NULL, NULL, BoundNetLog());
1426 EXPECT_EQ(ERR_IO_PENDING, rv); 1588 EXPECT_EQ(ERR_IO_PENDING, rv);
1427 ASSERT_EQ(3u, resolver->pending_requests().size()); 1589 ASSERT_EQ(3u, resolver->pending_requests().size());
1428 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url()); 1590 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[2]->url());
1429 1591
1430 // Cancel the second request 1592 // Cancel the second request
1431 service.CancelPacRequest(request2); 1593 service.CancelPacRequest(request2);
1432 1594
1433 ASSERT_EQ(2u, resolver->pending_requests().size()); 1595 ASSERT_EQ(2u, resolver->pending_requests().size());
1434 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url()); 1596 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url());
1435 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url()); 1597 EXPECT_EQ(GURL("http://request3"), resolver->pending_requests()[1]->url());
(...skipping 30 matching lines...) Expand all
1466 1628
1467 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1629 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1468 service.SetProxyScriptFetchers(fetcher, 1630 service.SetProxyScriptFetchers(fetcher,
1469 new DoNothingDhcpProxyScriptFetcher()); 1631 new DoNothingDhcpProxyScriptFetcher());
1470 1632
1471 // Start 3 requests. 1633 // Start 3 requests.
1472 1634
1473 ProxyInfo info1; 1635 ProxyInfo info1;
1474 TestCompletionCallback callback1; 1636 TestCompletionCallback callback1;
1475 ProxyService::PacRequest* request1; 1637 ProxyService::PacRequest* request1;
1476 int rv = service.ResolveProxy(GURL("http://request1"), &info1, 1638 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1,
1477 callback1.callback(), &request1, BoundNetLog()); 1639 callback1.callback(), &request1, NULL,
1640 BoundNetLog());
1478 EXPECT_EQ(ERR_IO_PENDING, rv); 1641 EXPECT_EQ(ERR_IO_PENDING, rv);
1479 1642
1480 // The first request should have triggered download of PAC script. 1643 // The first request should have triggered download of PAC script.
1481 EXPECT_TRUE(fetcher->has_pending_request()); 1644 EXPECT_TRUE(fetcher->has_pending_request());
1482 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 1645 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
1483 1646
1484 ProxyInfo info2; 1647 ProxyInfo info2;
1485 TestCompletionCallback callback2; 1648 TestCompletionCallback callback2;
1486 ProxyService::PacRequest* request2; 1649 ProxyService::PacRequest* request2;
1487 rv = service.ResolveProxy(GURL("http://request2"), &info2, 1650 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2,
1488 callback2.callback(), &request2, BoundNetLog()); 1651 callback2.callback(), &request2, NULL,
1652 BoundNetLog());
1489 EXPECT_EQ(ERR_IO_PENDING, rv); 1653 EXPECT_EQ(ERR_IO_PENDING, rv);
1490 1654
1491 ProxyInfo info3; 1655 ProxyInfo info3;
1492 TestCompletionCallback callback3; 1656 TestCompletionCallback callback3;
1493 ProxyService::PacRequest* request3; 1657 ProxyService::PacRequest* request3;
1494 rv = service.ResolveProxy(GURL("http://request3"), &info3, 1658 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3,
1495 callback3.callback(), &request3, BoundNetLog()); 1659 callback3.callback(), &request3, NULL,
1660 BoundNetLog());
1496 EXPECT_EQ(ERR_IO_PENDING, rv); 1661 EXPECT_EQ(ERR_IO_PENDING, rv);
1497 1662
1498 // Nothing has been sent to the resolver yet. 1663 // Nothing has been sent to the resolver yet.
1499 EXPECT_TRUE(resolver->pending_requests().empty()); 1664 EXPECT_TRUE(resolver->pending_requests().empty());
1500 1665
1501 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, 1666 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT,
1502 service.GetLoadState(request1)); 1667 service.GetLoadState(request1));
1503 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, 1668 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT,
1504 service.GetLoadState(request2)); 1669 service.GetLoadState(request2));
1505 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, 1670 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 ProxyService service(config_service, resolver, NULL); 1733 ProxyService service(config_service, resolver, NULL);
1569 1734
1570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1735 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1571 service.SetProxyScriptFetchers(fetcher, 1736 service.SetProxyScriptFetchers(fetcher,
1572 new DoNothingDhcpProxyScriptFetcher()); 1737 new DoNothingDhcpProxyScriptFetcher());
1573 1738
1574 // Start 2 requests. 1739 // Start 2 requests.
1575 1740
1576 ProxyInfo info1; 1741 ProxyInfo info1;
1577 TestCompletionCallback callback1; 1742 TestCompletionCallback callback1;
1578 int rv = service.ResolveProxy(GURL("http://request1"), &info1, 1743 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1,
1579 callback1.callback(), NULL, BoundNetLog()); 1744 callback1.callback(), NULL, NULL,
1745 BoundNetLog());
1580 EXPECT_EQ(ERR_IO_PENDING, rv); 1746 EXPECT_EQ(ERR_IO_PENDING, rv);
1581 1747
1582 // The first request should have triggered download of PAC script. 1748 // The first request should have triggered download of PAC script.
1583 EXPECT_TRUE(fetcher->has_pending_request()); 1749 EXPECT_TRUE(fetcher->has_pending_request());
1584 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 1750 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
1585 1751
1586 ProxyInfo info2; 1752 ProxyInfo info2;
1587 TestCompletionCallback callback2; 1753 TestCompletionCallback callback2;
1588 rv = service.ResolveProxy(GURL("http://request2"), &info2, 1754 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2,
1589 callback2.callback(), NULL, BoundNetLog()); 1755 callback2.callback(), NULL, NULL, BoundNetLog());
1590 EXPECT_EQ(ERR_IO_PENDING, rv); 1756 EXPECT_EQ(ERR_IO_PENDING, rv);
1591 1757
1592 // At this point the ProxyService should be waiting for the 1758 // At this point the ProxyService should be waiting for the
1593 // ProxyScriptFetcher to invoke its completion callback, notifying it of 1759 // ProxyScriptFetcher to invoke its completion callback, notifying it of
1594 // PAC script download completion. 1760 // PAC script download completion.
1595 1761
1596 // We now change out the ProxyService's script fetcher. We should restart 1762 // We now change out the ProxyService's script fetcher. We should restart
1597 // the initialization with the new fetcher. 1763 // the initialization with the new fetcher.
1598 1764
1599 fetcher = new MockProxyScriptFetcher; 1765 fetcher = new MockProxyScriptFetcher;
(...skipping 28 matching lines...) Expand all
1628 1794
1629 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1795 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1630 service.SetProxyScriptFetchers(fetcher, 1796 service.SetProxyScriptFetchers(fetcher,
1631 new DoNothingDhcpProxyScriptFetcher()); 1797 new DoNothingDhcpProxyScriptFetcher());
1632 1798
1633 // Start 3 requests. 1799 // Start 3 requests.
1634 ProxyInfo info1; 1800 ProxyInfo info1;
1635 TestCompletionCallback callback1; 1801 TestCompletionCallback callback1;
1636 ProxyService::PacRequest* request1; 1802 ProxyService::PacRequest* request1;
1637 CapturingBoundNetLog log1; 1803 CapturingBoundNetLog log1;
1638 int rv = service.ResolveProxy(GURL("http://request1"), &info1, 1804 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1,
1639 callback1.callback(), &request1, log1.bound()); 1805 callback1.callback(), &request1, NULL,
1806 log1.bound());
1640 EXPECT_EQ(ERR_IO_PENDING, rv); 1807 EXPECT_EQ(ERR_IO_PENDING, rv);
1641 1808
1642 // The first request should have triggered download of PAC script. 1809 // The first request should have triggered download of PAC script.
1643 EXPECT_TRUE(fetcher->has_pending_request()); 1810 EXPECT_TRUE(fetcher->has_pending_request());
1644 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 1811 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
1645 1812
1646 ProxyInfo info2; 1813 ProxyInfo info2;
1647 TestCompletionCallback callback2; 1814 TestCompletionCallback callback2;
1648 ProxyService::PacRequest* request2; 1815 ProxyService::PacRequest* request2;
1649 rv = service.ResolveProxy(GURL("http://request2"), &info2, 1816 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2,
1650 callback2.callback(), &request2, BoundNetLog()); 1817 callback2.callback(), &request2, NULL,
1818 BoundNetLog());
1651 EXPECT_EQ(ERR_IO_PENDING, rv); 1819 EXPECT_EQ(ERR_IO_PENDING, rv);
1652 1820
1653 ProxyInfo info3; 1821 ProxyInfo info3;
1654 TestCompletionCallback callback3; 1822 TestCompletionCallback callback3;
1655 rv = service.ResolveProxy(GURL("http://request3"), &info3, 1823 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3,
1656 callback3.callback(), NULL, BoundNetLog()); 1824 callback3.callback(), NULL, NULL, BoundNetLog());
1657 EXPECT_EQ(ERR_IO_PENDING, rv); 1825 EXPECT_EQ(ERR_IO_PENDING, rv);
1658 1826
1659 // Nothing has been sent to the resolver yet. 1827 // Nothing has been sent to the resolver yet.
1660 EXPECT_TRUE(resolver->pending_requests().empty()); 1828 EXPECT_TRUE(resolver->pending_requests().empty());
1661 1829
1662 // Cancel the first 2 requests. 1830 // Cancel the first 2 requests.
1663 service.CancelPacRequest(request1); 1831 service.CancelPacRequest(request1);
1664 service.CancelPacRequest(request2); 1832 service.CancelPacRequest(request2);
1665 1833
1666 // At this point the ProxyService should be waiting for the 1834 // At this point the ProxyService should be waiting for the
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 ProxyService service(config_service, resolver, NULL); 1887 ProxyService service(config_service, resolver, NULL);
1720 1888
1721 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1889 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1722 service.SetProxyScriptFetchers(fetcher, 1890 service.SetProxyScriptFetchers(fetcher,
1723 new DoNothingDhcpProxyScriptFetcher()); 1891 new DoNothingDhcpProxyScriptFetcher());
1724 1892
1725 // Start 2 requests. 1893 // Start 2 requests.
1726 1894
1727 ProxyInfo info1; 1895 ProxyInfo info1;
1728 TestCompletionCallback callback1; 1896 TestCompletionCallback callback1;
1729 int rv = service.ResolveProxy(GURL("http://request1"), &info1, 1897 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1,
1730 callback1.callback(), NULL, BoundNetLog()); 1898 callback1.callback(), NULL, NULL,
1899 BoundNetLog());
1731 EXPECT_EQ(ERR_IO_PENDING, rv); 1900 EXPECT_EQ(ERR_IO_PENDING, rv);
1732 1901
1733 ProxyInfo info2; 1902 ProxyInfo info2;
1734 TestCompletionCallback callback2; 1903 TestCompletionCallback callback2;
1735 ProxyService::PacRequest* request2; 1904 ProxyService::PacRequest* request2;
1736 rv = service.ResolveProxy(GURL("http://request2"), &info2, 1905 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2,
1737 callback2.callback(), &request2, BoundNetLog()); 1906 callback2.callback(), &request2, NULL,
1907 BoundNetLog());
1738 EXPECT_EQ(ERR_IO_PENDING, rv); 1908 EXPECT_EQ(ERR_IO_PENDING, rv);
1739 1909
1740 // Check that nothing has been sent to the proxy resolver yet. 1910 // Check that nothing has been sent to the proxy resolver yet.
1741 ASSERT_EQ(0u, resolver->pending_requests().size()); 1911 ASSERT_EQ(0u, resolver->pending_requests().size());
1742 1912
1743 // It should be trying to auto-detect first -- FAIL the autodetect during 1913 // It should be trying to auto-detect first -- FAIL the autodetect during
1744 // the script download. 1914 // the script download.
1745 EXPECT_TRUE(fetcher->has_pending_request()); 1915 EXPECT_TRUE(fetcher->has_pending_request());
1746 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); 1916 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
1747 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 1917 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 ProxyService service(config_service, resolver, NULL); 1966 ProxyService service(config_service, resolver, NULL);
1797 1967
1798 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1968 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1799 service.SetProxyScriptFetchers(fetcher, 1969 service.SetProxyScriptFetchers(fetcher,
1800 new DoNothingDhcpProxyScriptFetcher()); 1970 new DoNothingDhcpProxyScriptFetcher());
1801 1971
1802 // Start 2 requests. 1972 // Start 2 requests.
1803 1973
1804 ProxyInfo info1; 1974 ProxyInfo info1;
1805 TestCompletionCallback callback1; 1975 TestCompletionCallback callback1;
1806 int rv = service.ResolveProxy(GURL("http://request1"), &info1, 1976 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1,
1807 callback1.callback(), NULL, BoundNetLog()); 1977 callback1.callback(), NULL, NULL,
1978 BoundNetLog());
1808 EXPECT_EQ(ERR_IO_PENDING, rv); 1979 EXPECT_EQ(ERR_IO_PENDING, rv);
1809 1980
1810 ProxyInfo info2; 1981 ProxyInfo info2;
1811 TestCompletionCallback callback2; 1982 TestCompletionCallback callback2;
1812 ProxyService::PacRequest* request2; 1983 ProxyService::PacRequest* request2;
1813 rv = service.ResolveProxy(GURL("http://request2"), &info2, 1984 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2,
1814 callback2.callback(), &request2, BoundNetLog()); 1985 callback2.callback(), &request2, NULL,
1986 BoundNetLog());
1815 EXPECT_EQ(ERR_IO_PENDING, rv); 1987 EXPECT_EQ(ERR_IO_PENDING, rv);
1816 1988
1817 // Check that nothing has been sent to the proxy resolver yet. 1989 // Check that nothing has been sent to the proxy resolver yet.
1818 ASSERT_EQ(0u, resolver->pending_requests().size()); 1990 ASSERT_EQ(0u, resolver->pending_requests().size());
1819 1991
1820 // It should be trying to auto-detect first -- succeed the download. 1992 // It should be trying to auto-detect first -- succeed the download.
1821 EXPECT_TRUE(fetcher->has_pending_request()); 1993 EXPECT_TRUE(fetcher->has_pending_request());
1822 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); 1994 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
1823 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); 1995 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents");
1824 1996
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 ProxyService service(config_service, resolver, NULL); 2041 ProxyService service(config_service, resolver, NULL);
1870 2042
1871 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2043 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1872 service.SetProxyScriptFetchers(fetcher, 2044 service.SetProxyScriptFetchers(fetcher,
1873 new DoNothingDhcpProxyScriptFetcher()); 2045 new DoNothingDhcpProxyScriptFetcher());
1874 2046
1875 // Start 2 requests. 2047 // Start 2 requests.
1876 2048
1877 ProxyInfo info1; 2049 ProxyInfo info1;
1878 TestCompletionCallback callback1; 2050 TestCompletionCallback callback1;
1879 int rv = service.ResolveProxy(GURL("http://request1"), &info1, 2051 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1,
1880 callback1.callback(), NULL, BoundNetLog()); 2052 callback1.callback(), NULL, NULL,
2053 BoundNetLog());
1881 EXPECT_EQ(ERR_IO_PENDING, rv); 2054 EXPECT_EQ(ERR_IO_PENDING, rv);
1882 2055
1883 ProxyInfo info2; 2056 ProxyInfo info2;
1884 TestCompletionCallback callback2; 2057 TestCompletionCallback callback2;
1885 ProxyService::PacRequest* request2; 2058 ProxyService::PacRequest* request2;
1886 rv = service.ResolveProxy(GURL("http://request2"), &info2, 2059 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2,
1887 callback2.callback(), &request2, BoundNetLog()); 2060 callback2.callback(), &request2, NULL,
2061 BoundNetLog());
1888 EXPECT_EQ(ERR_IO_PENDING, rv); 2062 EXPECT_EQ(ERR_IO_PENDING, rv);
1889 2063
1890 // Check that nothing has been sent to the proxy resolver yet. 2064 // Check that nothing has been sent to the proxy resolver yet.
1891 ASSERT_EQ(0u, resolver->pending_requests().size()); 2065 ASSERT_EQ(0u, resolver->pending_requests().size());
1892 2066
1893 // It should be trying to auto-detect first -- fail the download. 2067 // It should be trying to auto-detect first -- fail the download.
1894 EXPECT_TRUE(fetcher->has_pending_request()); 2068 EXPECT_TRUE(fetcher->has_pending_request());
1895 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); 2069 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
1896 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 2070 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
1897 2071
(...skipping 30 matching lines...) Expand all
1928 2102
1929 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2103 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1930 service.SetProxyScriptFetchers(fetcher, 2104 service.SetProxyScriptFetchers(fetcher,
1931 new DoNothingDhcpProxyScriptFetcher()); 2105 new DoNothingDhcpProxyScriptFetcher());
1932 2106
1933 // Start 1 requests. 2107 // Start 1 requests.
1934 2108
1935 ProxyInfo info1; 2109 ProxyInfo info1;
1936 TestCompletionCallback callback1; 2110 TestCompletionCallback callback1;
1937 int rv = service.ResolveProxy( 2111 int rv = service.ResolveProxy(
1938 GURL("http://www.google.com"), &info1, callback1.callback(), NULL, 2112 GURL("http://www.google.com"), LOAD_NORMAL, &info1,
1939 BoundNetLog()); 2113 callback1.callback(), NULL, NULL, BoundNetLog());
1940 EXPECT_EQ(ERR_IO_PENDING, rv); 2114 EXPECT_EQ(ERR_IO_PENDING, rv);
1941 2115
1942 // Check that nothing has been sent to the proxy resolver yet. 2116 // Check that nothing has been sent to the proxy resolver yet.
1943 ASSERT_EQ(0u, resolver->pending_requests().size()); 2117 ASSERT_EQ(0u, resolver->pending_requests().size());
1944 2118
1945 // It should be trying to auto-detect first -- succeed the download. 2119 // It should be trying to auto-detect first -- succeed the download.
1946 EXPECT_TRUE(fetcher->has_pending_request()); 2120 EXPECT_TRUE(fetcher->has_pending_request());
1947 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); 2121 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
1948 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2122 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
1949 2123
1950 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2124 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
1951 resolver->pending_set_pac_script_request()->script_data()->utf16()); 2125 resolver->pending_set_pac_script_request()->script_data()->utf16());
1952 resolver->pending_set_pac_script_request()->CompleteNow(OK); 2126 resolver->pending_set_pac_script_request()->CompleteNow(OK);
1953 2127
1954 ASSERT_EQ(1u, resolver->pending_requests().size()); 2128 ASSERT_EQ(1u, resolver->pending_requests().size());
1955 EXPECT_EQ(GURL("http://www.google.com"), 2129 EXPECT_EQ(GURL("http://www.google.com"),
1956 resolver->pending_requests()[0]->url()); 2130 resolver->pending_requests()[0]->url());
1957 2131
1958 // Complete the pending request. 2132 // Complete the pending request.
1959 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); 2133 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80");
1960 resolver->pending_requests()[0]->CompleteNow(OK); 2134 resolver->pending_requests()[0]->CompleteNow(OK);
1961 2135
1962 // Verify that request ran as expected. 2136 // Verify that request ran as expected.
1963 EXPECT_EQ(OK, callback1.WaitForResult()); 2137 EXPECT_EQ(OK, callback1.WaitForResult());
1964 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); 2138 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
1965 2139
1966 // Start another request, it should pickup the bypass item. 2140 // Start another request, it should pickup the bypass item.
1967 ProxyInfo info2; 2141 ProxyInfo info2;
1968 TestCompletionCallback callback2; 2142 TestCompletionCallback callback2;
1969 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, 2143 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2,
1970 callback2.callback(), NULL, BoundNetLog()); 2144 callback2.callback(), NULL, NULL, BoundNetLog());
1971 EXPECT_EQ(ERR_IO_PENDING, rv); 2145 EXPECT_EQ(ERR_IO_PENDING, rv);
1972 2146
1973 ASSERT_EQ(1u, resolver->pending_requests().size()); 2147 ASSERT_EQ(1u, resolver->pending_requests().size());
1974 EXPECT_EQ(GURL("http://www.google.com"), 2148 EXPECT_EQ(GURL("http://www.google.com"),
1975 resolver->pending_requests()[0]->url()); 2149 resolver->pending_requests()[0]->url());
1976 2150
1977 // Complete the pending request. 2151 // Complete the pending request.
1978 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); 2152 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80");
1979 resolver->pending_requests()[0]->CompleteNow(OK); 2153 resolver->pending_requests()[0]->CompleteNow(OK);
1980 2154
(...skipping 15 matching lines...) Expand all
1996 ProxyService service(config_service, resolver, NULL); 2170 ProxyService service(config_service, resolver, NULL);
1997 2171
1998 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2172 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1999 service.SetProxyScriptFetchers(fetcher, 2173 service.SetProxyScriptFetchers(fetcher,
2000 new DoNothingDhcpProxyScriptFetcher()); 2174 new DoNothingDhcpProxyScriptFetcher());
2001 2175
2002 // Start 1 request. 2176 // Start 1 request.
2003 2177
2004 ProxyInfo info1; 2178 ProxyInfo info1;
2005 TestCompletionCallback callback1; 2179 TestCompletionCallback callback1;
2006 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, 2180 int rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL,
2007 callback1.callback(), NULL, BoundNetLog()); 2181 &info1, callback1.callback(), NULL, NULL,
2182 BoundNetLog());
2008 EXPECT_EQ(ERR_IO_PENDING, rv); 2183 EXPECT_EQ(ERR_IO_PENDING, rv);
2009 2184
2010 // Check that nothing has been sent to the proxy resolver yet. 2185 // Check that nothing has been sent to the proxy resolver yet.
2011 ASSERT_EQ(0u, resolver->pending_requests().size()); 2186 ASSERT_EQ(0u, resolver->pending_requests().size());
2012 2187
2013 // InitProxyResolver should have issued a request to the ProxyScriptFetcher 2188 // InitProxyResolver should have issued a request to the ProxyScriptFetcher
2014 // and be waiting on that to complete. 2189 // and be waiting on that to complete.
2015 EXPECT_TRUE(fetcher->has_pending_request()); 2190 EXPECT_TRUE(fetcher->has_pending_request());
2016 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2191 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2017 } 2192 }
2018 2193
2019 // Delete the ProxyService while InitProxyResolver has an outstanding 2194 // Delete the ProxyService while InitProxyResolver has an outstanding
2020 // request to the proxy resolver. When run under valgrind, should not 2195 // request to the proxy resolver. When run under valgrind, should not
2021 // have any memory errors (used to be that the ProxyResolver was 2196 // have any memory errors (used to be that the ProxyResolver was
2022 // being deleted prior to the InitProxyResolver). 2197 // being deleted prior to the InitProxyResolver).
2023 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { 2198 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) {
2024 MockProxyConfigService* config_service = 2199 MockProxyConfigService* config_service =
2025 new MockProxyConfigService("http://foopy/proxy.pac"); 2200 new MockProxyConfigService("http://foopy/proxy.pac");
2026 2201
2027 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 2202 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
2028 2203
2029 ProxyService service(config_service, resolver, NULL); 2204 ProxyService service(config_service, resolver, NULL);
2030 2205
2031 GURL url("http://www.google.com/"); 2206 GURL url("http://www.google.com/");
2032 2207
2033 ProxyInfo info; 2208 ProxyInfo info;
2034 TestCompletionCallback callback; 2209 TestCompletionCallback callback;
2035 int rv = service.ResolveProxy( 2210 int rv = service.ResolveProxy(
2036 url, &info, callback.callback(), NULL, BoundNetLog()); 2211 url, LOAD_NORMAL, &info, callback.callback(), NULL, NULL, BoundNetLog());
2037 EXPECT_EQ(ERR_IO_PENDING, rv); 2212 EXPECT_EQ(ERR_IO_PENDING, rv);
2038 2213
2039 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 2214 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
2040 resolver->pending_set_pac_script_request()->script_data()->url()); 2215 resolver->pending_set_pac_script_request()->script_data()->url());
2041 } 2216 }
2042 2217
2043 TEST_F(ProxyServiceTest, ResetProxyConfigService) { 2218 TEST_F(ProxyServiceTest, ResetProxyConfigService) {
2044 ProxyConfig config1; 2219 ProxyConfig config1;
2045 config1.proxy_rules().ParseFromString("foopy1:8080"); 2220 config1.proxy_rules().ParseFromString("foopy1:8080");
2046 config1.set_auto_detect(false); 2221 config1.set_auto_detect(false);
2047 ProxyService service( 2222 ProxyService service(
2048 new MockProxyConfigService(config1), 2223 new MockProxyConfigService(config1),
2049 new MockAsyncProxyResolverExpectsBytes, NULL); 2224 new MockAsyncProxyResolverExpectsBytes, NULL);
2050 2225
2051 ProxyInfo info; 2226 ProxyInfo info;
2052 TestCompletionCallback callback1; 2227 TestCompletionCallback callback1;
2053 int rv = service.ResolveProxy(GURL("http://request1"), &info, 2228 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info,
2054 callback1.callback(), NULL, BoundNetLog()); 2229 callback1.callback(), NULL, NULL,
2230 BoundNetLog());
2055 EXPECT_EQ(OK, rv); 2231 EXPECT_EQ(OK, rv);
2056 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 2232 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
2057 2233
2058 ProxyConfig config2; 2234 ProxyConfig config2;
2059 config2.proxy_rules().ParseFromString("foopy2:8080"); 2235 config2.proxy_rules().ParseFromString("foopy2:8080");
2060 config2.set_auto_detect(false); 2236 config2.set_auto_detect(false);
2061 service.ResetConfigService(new MockProxyConfigService(config2)); 2237 service.ResetConfigService(new MockProxyConfigService(config2));
2062 TestCompletionCallback callback2; 2238 TestCompletionCallback callback2;
2063 rv = service.ResolveProxy(GURL("http://request2"), &info, 2239 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info,
2064 callback2.callback(), NULL, BoundNetLog()); 2240 callback2.callback(), NULL, NULL, BoundNetLog());
2065 EXPECT_EQ(OK, rv); 2241 EXPECT_EQ(OK, rv);
2066 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); 2242 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI());
2067 } 2243 }
2068 2244
2069 // Test that when going from a configuration that required PAC to one 2245 // Test that when going from a configuration that required PAC to one
2070 // that does NOT, we unset the variable |should_use_proxy_resolver_|. 2246 // that does NOT, we unset the variable |should_use_proxy_resolver_|.
2071 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { 2247 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) {
2072 ProxyConfig config = ProxyConfig::CreateAutoDetect(); 2248 ProxyConfig config = ProxyConfig::CreateAutoDetect();
2073 2249
2074 MockProxyConfigService* config_service = new MockProxyConfigService(config); 2250 MockProxyConfigService* config_service = new MockProxyConfigService(config);
2075 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 2251 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
2076 ProxyService service(config_service, resolver, NULL); 2252 ProxyService service(config_service, resolver, NULL);
2077 2253
2078 // Start 1 request. 2254 // Start 1 request.
2079 2255
2080 ProxyInfo info1; 2256 ProxyInfo info1;
2081 TestCompletionCallback callback1; 2257 TestCompletionCallback callback1;
2082 int rv = service.ResolveProxy(GURL("http://www.google.com"), &info1, 2258 int rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL,
2083 callback1.callback(), NULL, BoundNetLog()); 2259 &info1, callback1.callback(), NULL, NULL,
2260 BoundNetLog());
2084 EXPECT_EQ(ERR_IO_PENDING, rv); 2261 EXPECT_EQ(ERR_IO_PENDING, rv);
2085 2262
2086 // Check that nothing has been sent to the proxy resolver yet. 2263 // Check that nothing has been sent to the proxy resolver yet.
2087 ASSERT_EQ(0u, resolver->pending_requests().size()); 2264 ASSERT_EQ(0u, resolver->pending_requests().size());
2088 2265
2089 // Successfully set the autodetect script. 2266 // Successfully set the autodetect script.
2090 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, 2267 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT,
2091 resolver->pending_set_pac_script_request()->script_data()->type()); 2268 resolver->pending_set_pac_script_request()->script_data()->type());
2092 resolver->pending_set_pac_script_request()->CompleteNow(OK); 2269 resolver->pending_set_pac_script_request()->CompleteNow(OK);
2093 2270
2094 // Complete the pending request. 2271 // Complete the pending request.
2095 ASSERT_EQ(1u, resolver->pending_requests().size()); 2272 ASSERT_EQ(1u, resolver->pending_requests().size());
2096 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80"); 2273 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80");
2097 resolver->pending_requests()[0]->CompleteNow(OK); 2274 resolver->pending_requests()[0]->CompleteNow(OK);
2098 2275
2099 // Verify that request ran as expected. 2276 // Verify that request ran as expected.
2100 EXPECT_EQ(OK, callback1.WaitForResult()); 2277 EXPECT_EQ(OK, callback1.WaitForResult());
2101 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); 2278 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
2102 2279
2103 // Force the ProxyService to pull down a new proxy configuration. 2280 // Force the ProxyService to pull down a new proxy configuration.
2104 // (Even though the configuration isn't old/bad). 2281 // (Even though the configuration isn't old/bad).
2105 // 2282 //
2106 // This new configuration no longer has auto_detect set, so 2283 // This new configuration no longer has auto_detect set, so
2107 // requests should complete synchronously now as direct-connect. 2284 // requests should complete synchronously now as direct-connect.
2108 config_service->SetConfig(ProxyConfig::CreateDirect()); 2285 config_service->SetConfig(ProxyConfig::CreateDirect());
2109 2286
2110 // Start another request -- the effective configuration has changed. 2287 // Start another request -- the effective configuration has changed.
2111 ProxyInfo info2; 2288 ProxyInfo info2;
2112 TestCompletionCallback callback2; 2289 TestCompletionCallback callback2;
2113 rv = service.ResolveProxy(GURL("http://www.google.com"), &info2, 2290 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2,
2114 callback2.callback(), NULL, BoundNetLog()); 2291 callback2.callback(), NULL, NULL, BoundNetLog());
2115 EXPECT_EQ(OK, rv); 2292 EXPECT_EQ(OK, rv);
2116 2293
2117 EXPECT_TRUE(info2.is_direct()); 2294 EXPECT_TRUE(info2.is_direct());
2118 } 2295 }
2119 2296
2120 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { 2297 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) {
2121 MockProxyConfigService* config_service = 2298 MockProxyConfigService* config_service =
2122 new MockProxyConfigService("http://foopy/proxy.pac"); 2299 new MockProxyConfigService("http://foopy/proxy.pac");
2123 2300
2124 MockAsyncProxyResolverExpectsBytes* resolver = 2301 MockAsyncProxyResolverExpectsBytes* resolver =
2125 new MockAsyncProxyResolverExpectsBytes; 2302 new MockAsyncProxyResolverExpectsBytes;
2126 2303
2127 CapturingNetLog log; 2304 CapturingNetLog log;
2128 2305
2129 ProxyService service(config_service, resolver, &log); 2306 ProxyService service(config_service, resolver, &log);
2130 2307
2131 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2308 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2132 service.SetProxyScriptFetchers(fetcher, 2309 service.SetProxyScriptFetchers(fetcher,
2133 new DoNothingDhcpProxyScriptFetcher()); 2310 new DoNothingDhcpProxyScriptFetcher());
2134 2311
2135 // Disable the "wait after IP address changes" hack, so this unit-test can 2312 // Disable the "wait after IP address changes" hack, so this unit-test can
2136 // complete quickly. 2313 // complete quickly.
2137 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); 2314 service.set_stall_proxy_auto_config_delay(base::TimeDelta());
2138 2315
2139 // Start 1 request. 2316 // Start 1 request.
2140 2317
2141 ProxyInfo info1; 2318 ProxyInfo info1;
2142 TestCompletionCallback callback1; 2319 TestCompletionCallback callback1;
2143 int rv = service.ResolveProxy(GURL("http://request1"), &info1, 2320 int rv = service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1,
2144 callback1.callback(), NULL, BoundNetLog()); 2321 callback1.callback(), NULL, NULL,
2322 BoundNetLog());
2145 EXPECT_EQ(ERR_IO_PENDING, rv); 2323 EXPECT_EQ(ERR_IO_PENDING, rv);
2146 2324
2147 // The first request should have triggered initial download of PAC script. 2325 // The first request should have triggered initial download of PAC script.
2148 EXPECT_TRUE(fetcher->has_pending_request()); 2326 EXPECT_TRUE(fetcher->has_pending_request());
2149 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2327 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2150 2328
2151 // Nothing has been sent to the resolver yet. 2329 // Nothing has been sent to the resolver yet.
2152 EXPECT_TRUE(resolver->pending_requests().empty()); 2330 EXPECT_TRUE(resolver->pending_requests().empty());
2153 2331
2154 // At this point the ProxyService should be waiting for the 2332 // At this point the ProxyService should be waiting for the
(...skipping 20 matching lines...) Expand all
2175 2353
2176 // Now simluate a change in the network. The ProxyConfigService is still 2354 // 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 2355 // going to return the same PAC URL as before, but this URL needs to be
2178 // refetched on the new network. 2356 // refetched on the new network.
2179 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 2357 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
2180 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. 2358 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async.
2181 2359
2182 // Start a second request. 2360 // Start a second request.
2183 ProxyInfo info2; 2361 ProxyInfo info2;
2184 TestCompletionCallback callback2; 2362 TestCompletionCallback callback2;
2185 rv = service.ResolveProxy(GURL("http://request2"), &info2, 2363 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2,
2186 callback2.callback(), NULL, BoundNetLog()); 2364 callback2.callback(), NULL, NULL, BoundNetLog());
2187 EXPECT_EQ(ERR_IO_PENDING, rv); 2365 EXPECT_EQ(ERR_IO_PENDING, rv);
2188 2366
2189 // This second request should have triggered the re-download of the PAC 2367 // This second request should have triggered the re-download of the PAC
2190 // script (since we marked the network as having changed). 2368 // script (since we marked the network as having changed).
2191 EXPECT_TRUE(fetcher->has_pending_request()); 2369 EXPECT_TRUE(fetcher->has_pending_request());
2192 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2370 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2193 2371
2194 // Nothing has been sent to the resolver yet. 2372 // Nothing has been sent to the resolver yet.
2195 EXPECT_TRUE(resolver->pending_requests().empty()); 2373 EXPECT_TRUE(resolver->pending_requests().empty());
2196 2374
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 2426
2249 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2427 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2250 service.SetProxyScriptFetchers(fetcher, 2428 service.SetProxyScriptFetchers(fetcher,
2251 new DoNothingDhcpProxyScriptFetcher()); 2429 new DoNothingDhcpProxyScriptFetcher());
2252 2430
2253 // Start 1 request. 2431 // Start 1 request.
2254 2432
2255 ProxyInfo info1; 2433 ProxyInfo info1;
2256 TestCompletionCallback callback1; 2434 TestCompletionCallback callback1;
2257 int rv = service.ResolveProxy( 2435 int rv = service.ResolveProxy(
2258 GURL("http://request1"), &info1, callback1.callback(), 2436 GURL("http://request1"), LOAD_NORMAL, &info1, callback1.callback(),
2259 NULL, BoundNetLog()); 2437 NULL, NULL, BoundNetLog());
2260 EXPECT_EQ(ERR_IO_PENDING, rv); 2438 EXPECT_EQ(ERR_IO_PENDING, rv);
2261 2439
2262 // The first request should have triggered initial download of PAC script. 2440 // The first request should have triggered initial download of PAC script.
2263 EXPECT_TRUE(fetcher->has_pending_request()); 2441 EXPECT_TRUE(fetcher->has_pending_request());
2264 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2442 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2265 2443
2266 // Nothing has been sent to the resolver yet. 2444 // Nothing has been sent to the resolver yet.
2267 EXPECT_TRUE(resolver->pending_requests().empty()); 2445 EXPECT_TRUE(resolver->pending_requests().empty());
2268 2446
2269 // At this point the ProxyService should be waiting for the 2447 // At this point the ProxyService should be waiting for the
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 2487
2310 // At this point the ProxyService should have re-configured itself to use the 2488 // 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 2489 // PAC script (thereby recovering from the initial fetch failure). We will
2312 // verify that the next Resolve request uses the resolver rather than 2490 // verify that the next Resolve request uses the resolver rather than
2313 // DIRECT. 2491 // DIRECT.
2314 2492
2315 // Start a second request. 2493 // Start a second request.
2316 ProxyInfo info2; 2494 ProxyInfo info2;
2317 TestCompletionCallback callback2; 2495 TestCompletionCallback callback2;
2318 rv = service.ResolveProxy( 2496 rv = service.ResolveProxy(
2319 GURL("http://request2"), &info2, callback2.callback(), NULL, 2497 GURL("http://request2"), LOAD_NORMAL, &info2, callback2.callback(), NULL,
2320 BoundNetLog()); 2498 NULL, BoundNetLog());
2321 EXPECT_EQ(ERR_IO_PENDING, rv); 2499 EXPECT_EQ(ERR_IO_PENDING, rv);
2322 2500
2323 // Check that it was sent to the resolver. 2501 // Check that it was sent to the resolver.
2324 ASSERT_EQ(1u, resolver->pending_requests().size()); 2502 ASSERT_EQ(1u, resolver->pending_requests().size());
2325 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); 2503 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url());
2326 2504
2327 // Complete the pending second request. 2505 // Complete the pending second request.
2328 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); 2506 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80");
2329 resolver->pending_requests()[0]->CompleteNow(OK); 2507 resolver->pending_requests()[0]->CompleteNow(OK);
2330 2508
(...skipping 22 matching lines...) Expand all
2353 2531
2354 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2532 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2355 service.SetProxyScriptFetchers(fetcher, 2533 service.SetProxyScriptFetchers(fetcher,
2356 new DoNothingDhcpProxyScriptFetcher()); 2534 new DoNothingDhcpProxyScriptFetcher());
2357 2535
2358 // Start 1 request. 2536 // Start 1 request.
2359 2537
2360 ProxyInfo info1; 2538 ProxyInfo info1;
2361 TestCompletionCallback callback1; 2539 TestCompletionCallback callback1;
2362 int rv = service.ResolveProxy( 2540 int rv = service.ResolveProxy(
2363 GURL("http://request1"), &info1, callback1.callback(), NULL, 2541 GURL("http://request1"), LOAD_NORMAL, &info1, callback1.callback(), NULL,
2364 BoundNetLog()); 2542 NULL, BoundNetLog());
2365 EXPECT_EQ(ERR_IO_PENDING, rv); 2543 EXPECT_EQ(ERR_IO_PENDING, rv);
2366 2544
2367 // The first request should have triggered initial download of PAC script. 2545 // The first request should have triggered initial download of PAC script.
2368 EXPECT_TRUE(fetcher->has_pending_request()); 2546 EXPECT_TRUE(fetcher->has_pending_request());
2369 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2547 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2370 2548
2371 // Nothing has been sent to the resolver yet. 2549 // Nothing has been sent to the resolver yet.
2372 EXPECT_TRUE(resolver->pending_requests().empty()); 2550 EXPECT_TRUE(resolver->pending_requests().empty());
2373 2551
2374 // At this point the ProxyService should be waiting for the 2552 // At this point the ProxyService should be waiting for the
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2419 resolver->pending_set_pac_script_request()->script_data()->utf16()); 2597 resolver->pending_set_pac_script_request()->script_data()->utf16());
2420 resolver->pending_set_pac_script_request()->CompleteNow(OK); 2598 resolver->pending_set_pac_script_request()->CompleteNow(OK);
2421 2599
2422 // At this point the ProxyService should have re-configured itself to use the 2600 // At this point the ProxyService should have re-configured itself to use the
2423 // new PAC script. 2601 // new PAC script.
2424 2602
2425 // Start a second request. 2603 // Start a second request.
2426 ProxyInfo info2; 2604 ProxyInfo info2;
2427 TestCompletionCallback callback2; 2605 TestCompletionCallback callback2;
2428 rv = service.ResolveProxy( 2606 rv = service.ResolveProxy(
2429 GURL("http://request2"), &info2, callback2.callback(), NULL, 2607 GURL("http://request2"), LOAD_NORMAL, &info2, callback2.callback(), NULL,
2430 BoundNetLog()); 2608 NULL, BoundNetLog());
2431 EXPECT_EQ(ERR_IO_PENDING, rv); 2609 EXPECT_EQ(ERR_IO_PENDING, rv);
2432 2610
2433 // Check that it was sent to the resolver. 2611 // Check that it was sent to the resolver.
2434 ASSERT_EQ(1u, resolver->pending_requests().size()); 2612 ASSERT_EQ(1u, resolver->pending_requests().size());
2435 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); 2613 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url());
2436 2614
2437 // Complete the pending second request. 2615 // Complete the pending second request.
2438 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); 2616 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80");
2439 resolver->pending_requests()[0]->CompleteNow(OK); 2617 resolver->pending_requests()[0]->CompleteNow(OK);
2440 2618
(...skipping 22 matching lines...) Expand all
2463 2641
2464 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2642 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2465 service.SetProxyScriptFetchers(fetcher, 2643 service.SetProxyScriptFetchers(fetcher,
2466 new DoNothingDhcpProxyScriptFetcher()); 2644 new DoNothingDhcpProxyScriptFetcher());
2467 2645
2468 // Start 1 request. 2646 // Start 1 request.
2469 2647
2470 ProxyInfo info1; 2648 ProxyInfo info1;
2471 TestCompletionCallback callback1; 2649 TestCompletionCallback callback1;
2472 int rv = service.ResolveProxy( 2650 int rv = service.ResolveProxy(
2473 GURL("http://request1"), &info1, callback1.callback(), NULL, 2651 GURL("http://request1"), LOAD_NORMAL, &info1, callback1.callback(), NULL,
2474 BoundNetLog()); 2652 NULL, BoundNetLog());
2475 EXPECT_EQ(ERR_IO_PENDING, rv); 2653 EXPECT_EQ(ERR_IO_PENDING, rv);
2476 2654
2477 // The first request should have triggered initial download of PAC script. 2655 // The first request should have triggered initial download of PAC script.
2478 EXPECT_TRUE(fetcher->has_pending_request()); 2656 EXPECT_TRUE(fetcher->has_pending_request());
2479 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2657 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2480 2658
2481 // Nothing has been sent to the resolver yet. 2659 // Nothing has been sent to the resolver yet.
2482 EXPECT_TRUE(resolver->pending_requests().empty()); 2660 EXPECT_TRUE(resolver->pending_requests().empty());
2483 2661
2484 // At this point the ProxyService should be waiting for the 2662 // At this point the ProxyService should be waiting for the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 2703
2526 ASSERT_FALSE(resolver->has_pending_set_pac_script_request()); 2704 ASSERT_FALSE(resolver->has_pending_set_pac_script_request());
2527 2705
2528 // At this point the ProxyService is still running the same PAC script as 2706 // At this point the ProxyService is still running the same PAC script as
2529 // before. 2707 // before.
2530 2708
2531 // Start a second request. 2709 // Start a second request.
2532 ProxyInfo info2; 2710 ProxyInfo info2;
2533 TestCompletionCallback callback2; 2711 TestCompletionCallback callback2;
2534 rv = service.ResolveProxy( 2712 rv = service.ResolveProxy(
2535 GURL("http://request2"), &info2, callback2.callback(), NULL, 2713 GURL("http://request2"), LOAD_NORMAL, &info2, callback2.callback(), NULL,
2536 BoundNetLog()); 2714 NULL, BoundNetLog());
2537 EXPECT_EQ(ERR_IO_PENDING, rv); 2715 EXPECT_EQ(ERR_IO_PENDING, rv);
2538 2716
2539 // Check that it was sent to the resolver. 2717 // Check that it was sent to the resolver.
2540 ASSERT_EQ(1u, resolver->pending_requests().size()); 2718 ASSERT_EQ(1u, resolver->pending_requests().size());
2541 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); 2719 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url());
2542 2720
2543 // Complete the pending second request. 2721 // Complete the pending second request.
2544 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); 2722 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80");
2545 resolver->pending_requests()[0]->CompleteNow(OK); 2723 resolver->pending_requests()[0]->CompleteNow(OK);
2546 2724
(...skipping 22 matching lines...) Expand all
2569 2747
2570 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2748 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2571 service.SetProxyScriptFetchers(fetcher, 2749 service.SetProxyScriptFetchers(fetcher,
2572 new DoNothingDhcpProxyScriptFetcher()); 2750 new DoNothingDhcpProxyScriptFetcher());
2573 2751
2574 // Start 1 request. 2752 // Start 1 request.
2575 2753
2576 ProxyInfo info1; 2754 ProxyInfo info1;
2577 TestCompletionCallback callback1; 2755 TestCompletionCallback callback1;
2578 int rv = service.ResolveProxy( 2756 int rv = service.ResolveProxy(
2579 GURL("http://request1"), &info1, callback1.callback(), NULL, 2757 GURL("http://request1"), LOAD_NORMAL, &info1, callback1.callback(), NULL,
2580 BoundNetLog()); 2758 NULL, BoundNetLog());
2581 EXPECT_EQ(ERR_IO_PENDING, rv); 2759 EXPECT_EQ(ERR_IO_PENDING, rv);
2582 2760
2583 // The first request should have triggered initial download of PAC script. 2761 // The first request should have triggered initial download of PAC script.
2584 EXPECT_TRUE(fetcher->has_pending_request()); 2762 EXPECT_TRUE(fetcher->has_pending_request());
2585 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2763 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2586 2764
2587 // Nothing has been sent to the resolver yet. 2765 // Nothing has been sent to the resolver yet.
2588 EXPECT_TRUE(resolver->pending_requests().empty()); 2766 EXPECT_TRUE(resolver->pending_requests().empty());
2589 2767
2590 // At this point the ProxyService should be waiting for the 2768 // At this point the ProxyService should be waiting for the
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2629 2807
2630 base::MessageLoop::current()->RunUntilIdle(); 2808 base::MessageLoop::current()->RunUntilIdle();
2631 2809
2632 // At this point the ProxyService should have re-configured itself to use 2810 // At this point the ProxyService should have re-configured itself to use
2633 // DIRECT connections rather than the given proxy resolver. 2811 // DIRECT connections rather than the given proxy resolver.
2634 2812
2635 // Start a second request. 2813 // Start a second request.
2636 ProxyInfo info2; 2814 ProxyInfo info2;
2637 TestCompletionCallback callback2; 2815 TestCompletionCallback callback2;
2638 rv = service.ResolveProxy( 2816 rv = service.ResolveProxy(
2639 GURL("http://request2"), &info2, callback2.callback(), NULL, 2817 GURL("http://request2"), LOAD_NORMAL, &info2, callback2.callback(), NULL,
2640 BoundNetLog()); 2818 NULL, BoundNetLog());
2641 EXPECT_EQ(OK, rv); 2819 EXPECT_EQ(OK, rv);
2642 EXPECT_TRUE(info2.is_direct()); 2820 EXPECT_TRUE(info2.is_direct());
2643 } 2821 }
2644 2822
2645 // Tests that the code which decides at what times to poll the PAC 2823 // Tests that the code which decides at what times to poll the PAC
2646 // script follows the expected policy. 2824 // script follows the expected policy.
2647 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { 2825 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) {
2648 // Retrieve the internal polling policy implementation used by ProxyService. 2826 // Retrieve the internal polling policy implementation used by ProxyService.
2649 scoped_ptr<ProxyService::PacPollPolicy> policy = 2827 scoped_ptr<ProxyService::PacPollPolicy> policy =
2650 ProxyService::CreateDefaultPacPollPolicy(); 2828 ProxyService::CreateDefaultPacPollPolicy();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2721 2899
2722 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2900 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2723 service.SetProxyScriptFetchers(fetcher, 2901 service.SetProxyScriptFetchers(fetcher,
2724 new DoNothingDhcpProxyScriptFetcher()); 2902 new DoNothingDhcpProxyScriptFetcher());
2725 2903
2726 // Start 1 request. 2904 // Start 1 request.
2727 2905
2728 ProxyInfo info1; 2906 ProxyInfo info1;
2729 TestCompletionCallback callback1; 2907 TestCompletionCallback callback1;
2730 int rv = service.ResolveProxy( 2908 int rv = service.ResolveProxy(
2731 GURL("http://request1"), &info1, callback1.callback(), NULL, 2909 GURL("http://request1"), LOAD_NORMAL, &info1, callback1.callback(), NULL,
2732 BoundNetLog()); 2910 NULL, BoundNetLog());
2733 EXPECT_EQ(ERR_IO_PENDING, rv); 2911 EXPECT_EQ(ERR_IO_PENDING, rv);
2734 2912
2735 // The first request should have triggered initial download of PAC script. 2913 // The first request should have triggered initial download of PAC script.
2736 EXPECT_TRUE(fetcher->has_pending_request()); 2914 EXPECT_TRUE(fetcher->has_pending_request());
2737 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2915 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2738 2916
2739 // Nothing has been sent to the resolver yet. 2917 // Nothing has been sent to the resolver yet.
2740 EXPECT_TRUE(resolver->pending_requests().empty()); 2918 EXPECT_TRUE(resolver->pending_requests().empty());
2741 2919
2742 // At this point the ProxyService should be waiting for the 2920 // At this point the ProxyService should be waiting for the
(...skipping 22 matching lines...) Expand all
2765 // Our PAC poller is set to update ONLY in response to network activity, 2943 // Our PAC poller is set to update ONLY in response to network activity,
2766 // (i.e. another call to ResolveProxy()). 2944 // (i.e. another call to ResolveProxy()).
2767 2945
2768 ASSERT_FALSE(fetcher->has_pending_request()); 2946 ASSERT_FALSE(fetcher->has_pending_request());
2769 ASSERT_TRUE(resolver->pending_requests().empty()); 2947 ASSERT_TRUE(resolver->pending_requests().empty());
2770 2948
2771 // Start a second request. 2949 // Start a second request.
2772 ProxyInfo info2; 2950 ProxyInfo info2;
2773 TestCompletionCallback callback2; 2951 TestCompletionCallback callback2;
2774 rv = service.ResolveProxy( 2952 rv = service.ResolveProxy(
2775 GURL("http://request2"), &info2, callback2.callback(), NULL, 2953 GURL("http://request2"), LOAD_NORMAL, &info2, callback2.callback(), NULL,
2776 BoundNetLog()); 2954 NULL, BoundNetLog());
2777 EXPECT_EQ(ERR_IO_PENDING, rv); 2955 EXPECT_EQ(ERR_IO_PENDING, rv);
2778 2956
2779 // This request should have sent work to the resolver; complete it. 2957 // This request should have sent work to the resolver; complete it.
2780 ASSERT_EQ(1u, resolver->pending_requests().size()); 2958 ASSERT_EQ(1u, resolver->pending_requests().size());
2781 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url()); 2959 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url());
2782 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80"); 2960 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80");
2783 resolver->pending_requests()[0]->CompleteNow(OK); 2961 resolver->pending_requests()[0]->CompleteNow(OK);
2784 2962
2785 EXPECT_EQ(OK, callback2.WaitForResult()); 2963 EXPECT_EQ(OK, callback2.WaitForResult());
2786 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); 2964 EXPECT_EQ("request2:80", info2.proxy_server().ToURI());
2787 2965
2788 // In response to getting that resolve request, the poller should have 2966 // 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. 2967 // started the next poll, and made it as far as to request the download.
2790 2968
2791 EXPECT_TRUE(fetcher->has_pending_request()); 2969 EXPECT_TRUE(fetcher->has_pending_request());
2792 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2970 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2793 2971
2794 // This time we will fail the download, to simulate a PAC script change. 2972 // This time we will fail the download, to simulate a PAC script change.
2795 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 2973 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
2796 2974
2797 // Drain the message loop, so ProxyService is notified of the change 2975 // Drain the message loop, so ProxyService is notified of the change
2798 // and has a chance to re-configure itself. 2976 // and has a chance to re-configure itself.
2799 base::MessageLoop::current()->RunUntilIdle(); 2977 base::MessageLoop::current()->RunUntilIdle();
2800 2978
2801 // Start a third request -- this time we expect to get a direct connection 2979 // Start a third request -- this time we expect to get a direct connection
2802 // since the PAC script poller experienced a failure. 2980 // since the PAC script poller experienced a failure.
2803 ProxyInfo info3; 2981 ProxyInfo info3;
2804 TestCompletionCallback callback3; 2982 TestCompletionCallback callback3;
2805 rv = service.ResolveProxy( 2983 rv = service.ResolveProxy(
2806 GURL("http://request3"), &info3, callback3.callback(), NULL, 2984 GURL("http://request3"), LOAD_NORMAL, &info3, callback3.callback(), NULL,
2807 BoundNetLog()); 2985 NULL, BoundNetLog());
2808 EXPECT_EQ(OK, rv); 2986 EXPECT_EQ(OK, rv);
2809 EXPECT_TRUE(info3.is_direct()); 2987 EXPECT_TRUE(info3.is_direct());
2810 } 2988 }
2811 2989
2812 } // namespace net 2990 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698