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

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

Powered by Google App Engine
This is Rietveld 408576698