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

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

Issue 1439053002: Change ProxyResolver::GetProxyForURL() to take a scoped_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore scoped_ptr to mock and nits Created 4 years, 9 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
« no previous file with comments | « net/proxy/proxy_resolver_v8_tracing.cc ('k') | net/proxy/proxy_resolver_v8_tracing_wrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_resolver_v8_tracing.h" 5 #include "net/proxy/proxy_resolver_v8_tracing.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 TEST_F(ProxyResolverV8TracingTest, Simple) { 153 TEST_F(ProxyResolverV8TracingTest, Simple) {
154 MockCachingHostResolver host_resolver; 154 MockCachingHostResolver host_resolver;
155 MockBindings mock_bindings(&host_resolver); 155 MockBindings mock_bindings(&host_resolver);
156 156
157 scoped_ptr<ProxyResolverV8Tracing> resolver = 157 scoped_ptr<ProxyResolverV8Tracing> resolver =
158 CreateResolver(mock_bindings.CreateBindings(), "simple.js"); 158 CreateResolver(mock_bindings.CreateBindings(), "simple.js");
159 159
160 TestCompletionCallback callback; 160 TestCompletionCallback callback;
161 ProxyInfo proxy_info; 161 ProxyInfo proxy_info;
162 scoped_ptr<ProxyResolver::Request> req;
162 163
163 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 164 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
164 callback.callback(), NULL, 165 callback.callback(), &req,
165 mock_bindings.CreateBindings()); 166 mock_bindings.CreateBindings());
166 167
167 EXPECT_EQ(OK, callback.WaitForResult()); 168 EXPECT_EQ(OK, callback.WaitForResult());
168 169
169 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); 170 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI());
170 171
171 EXPECT_EQ(0u, host_resolver.num_resolve()); 172 EXPECT_EQ(0u, host_resolver.num_resolve());
172 173
173 // There were no alerts or errors. 174 // There were no alerts or errors.
174 EXPECT_TRUE(mock_bindings.GetAlerts().empty()); 175 EXPECT_TRUE(mock_bindings.GetAlerts().empty());
175 EXPECT_TRUE(mock_bindings.GetErrors().empty()); 176 EXPECT_TRUE(mock_bindings.GetErrors().empty());
176 } 177 }
177 178
178 TEST_F(ProxyResolverV8TracingTest, JavascriptError) { 179 TEST_F(ProxyResolverV8TracingTest, JavascriptError) {
179 MockCachingHostResolver host_resolver; 180 MockCachingHostResolver host_resolver;
180 MockBindings mock_bindings(&host_resolver); 181 MockBindings mock_bindings(&host_resolver);
181 182
182 scoped_ptr<ProxyResolverV8Tracing> resolver = 183 scoped_ptr<ProxyResolverV8Tracing> resolver =
183 CreateResolver(mock_bindings.CreateBindings(), "error.js"); 184 CreateResolver(mock_bindings.CreateBindings(), "error.js");
184 185
185 TestCompletionCallback callback; 186 TestCompletionCallback callback;
186 ProxyInfo proxy_info; 187 ProxyInfo proxy_info;
187 188
189 scoped_ptr<ProxyResolver::Request> req;
188 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, 190 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info,
189 callback.callback(), NULL, 191 callback.callback(), &req,
190 mock_bindings.CreateBindings()); 192 mock_bindings.CreateBindings());
191 193
192 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); 194 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult());
193 195
194 EXPECT_EQ(0u, host_resolver.num_resolve()); 196 EXPECT_EQ(0u, host_resolver.num_resolve());
195 197
196 // Check the output -- there was 1 alert and 1 javascript error. 198 // Check the output -- there was 1 alert and 1 javascript error.
197 ASSERT_EQ(1u, mock_bindings.GetAlerts().size()); 199 ASSERT_EQ(1u, mock_bindings.GetAlerts().size());
198 EXPECT_EQ("Prepare to DIE!", mock_bindings.GetAlerts()[0]); 200 EXPECT_EQ("Prepare to DIE!", mock_bindings.GetAlerts()[0]);
199 ASSERT_EQ(1u, mock_bindings.GetErrors().size()); 201 ASSERT_EQ(1u, mock_bindings.GetErrors().size());
200 EXPECT_EQ(5, mock_bindings.GetErrors()[0].first); 202 EXPECT_EQ(5, mock_bindings.GetErrors()[0].first);
201 EXPECT_EQ("Uncaught TypeError: Cannot read property 'split' of null", 203 EXPECT_EQ("Uncaught TypeError: Cannot read property 'split' of null",
202 mock_bindings.GetErrors()[0].second); 204 mock_bindings.GetErrors()[0].second);
203 } 205 }
204 206
205 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { 207 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) {
206 MockCachingHostResolver host_resolver; 208 MockCachingHostResolver host_resolver;
207 MockBindings mock_bindings(&host_resolver); 209 MockBindings mock_bindings(&host_resolver);
208 210
209 scoped_ptr<ProxyResolverV8Tracing> resolver = 211 scoped_ptr<ProxyResolverV8Tracing> resolver =
210 CreateResolver(mock_bindings.CreateBindings(), "too_many_alerts.js"); 212 CreateResolver(mock_bindings.CreateBindings(), "too_many_alerts.js");
211 213
212 TestCompletionCallback callback; 214 TestCompletionCallback callback;
213 ProxyInfo proxy_info; 215 ProxyInfo proxy_info;
214 216
217 scoped_ptr<ProxyResolver::Request> req;
215 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 218 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
216 callback.callback(), NULL, 219 callback.callback(), &req,
217 mock_bindings.CreateBindings()); 220 mock_bindings.CreateBindings());
218 221
219 EXPECT_EQ(OK, callback.WaitForResult()); 222 EXPECT_EQ(OK, callback.WaitForResult());
220 223
221 // Iteration1 does a DNS resolve 224 // Iteration1 does a DNS resolve
222 // Iteration2 exceeds the alert buffer 225 // Iteration2 exceeds the alert buffer
223 // Iteration3 runs in blocking mode and completes 226 // Iteration3 runs in blocking mode and completes
224 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); 227 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI());
225 228
226 EXPECT_EQ(1u, host_resolver.num_resolve()); 229 EXPECT_EQ(1u, host_resolver.num_resolve());
(...skipping 14 matching lines...) Expand all
241 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { 244 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) {
242 MockCachingHostResolver host_resolver; 245 MockCachingHostResolver host_resolver;
243 MockBindings mock_bindings(&host_resolver); 246 MockBindings mock_bindings(&host_resolver);
244 247
245 scoped_ptr<ProxyResolverV8Tracing> resolver = CreateResolver( 248 scoped_ptr<ProxyResolverV8Tracing> resolver = CreateResolver(
246 mock_bindings.CreateBindings(), "too_many_empty_alerts.js"); 249 mock_bindings.CreateBindings(), "too_many_empty_alerts.js");
247 250
248 TestCompletionCallback callback; 251 TestCompletionCallback callback;
249 ProxyInfo proxy_info; 252 ProxyInfo proxy_info;
250 253
254 scoped_ptr<ProxyResolver::Request> req;
251 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 255 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
252 callback.callback(), NULL, 256 callback.callback(), &req,
253 mock_bindings.CreateBindings()); 257 mock_bindings.CreateBindings());
254 258
255 EXPECT_EQ(OK, callback.WaitForResult()); 259 EXPECT_EQ(OK, callback.WaitForResult());
256 260
257 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); 261 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI());
258 262
259 EXPECT_EQ(1u, host_resolver.num_resolve()); 263 EXPECT_EQ(1u, host_resolver.num_resolve());
260 264
261 // No errors. 265 // No errors.
262 EXPECT_TRUE(mock_bindings.GetErrors().empty()); 266 EXPECT_TRUE(mock_bindings.GetErrors().empty());
(...skipping 24 matching lines...) Expand all
287 host_resolver.rules()->AddRuleForAddressFamily( 291 host_resolver.rules()->AddRuleForAddressFamily(
288 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); 292 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155");
289 host_resolver.rules()->AddRule("*", "133.122.100.200"); 293 host_resolver.rules()->AddRule("*", "133.122.100.200");
290 294
291 scoped_ptr<ProxyResolverV8Tracing> resolver = 295 scoped_ptr<ProxyResolverV8Tracing> resolver =
292 CreateResolver(mock_bindings.CreateBindings(), "dns.js"); 296 CreateResolver(mock_bindings.CreateBindings(), "dns.js");
293 297
294 TestCompletionCallback callback; 298 TestCompletionCallback callback;
295 ProxyInfo proxy_info; 299 ProxyInfo proxy_info;
296 300
301 scoped_ptr<ProxyResolver::Request> req;
297 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 302 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
298 callback.callback(), NULL, 303 callback.callback(), &req,
299 mock_bindings.CreateBindings()); 304 mock_bindings.CreateBindings());
300 305
301 EXPECT_EQ(OK, callback.WaitForResult()); 306 EXPECT_EQ(OK, callback.WaitForResult());
302 307
303 // The test does 13 DNS resolution, however only 7 of them are unique. 308 // The test does 13 DNS resolution, however only 7 of them are unique.
304 EXPECT_EQ(7u, host_resolver.num_resolve()); 309 EXPECT_EQ(7u, host_resolver.num_resolve());
305 310
306 const char* kExpectedResult = 311 const char* kExpectedResult =
307 "122.133.144.155-" // myIpAddress() 312 "122.133.144.155-" // myIpAddress()
308 "null-" // dnsResolve('') 313 "null-" // dnsResolve('')
(...skipping 30 matching lines...) Expand all
339 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); 344 host_resolver.rules()->AddRule("foopy", "166.155.144.11");
340 host_resolver.rules()->AddRule("*", "122.133.144.155"); 345 host_resolver.rules()->AddRule("*", "122.133.144.155");
341 346
342 scoped_ptr<ProxyResolverV8Tracing> resolver = 347 scoped_ptr<ProxyResolverV8Tracing> resolver =
343 CreateResolver(mock_bindings.CreateBindings(), "simple_dns.js"); 348 CreateResolver(mock_bindings.CreateBindings(), "simple_dns.js");
344 349
345 TestCompletionCallback callback1; 350 TestCompletionCallback callback1;
346 TestCompletionCallback callback2; 351 TestCompletionCallback callback2;
347 ProxyInfo proxy_info; 352 ProxyInfo proxy_info;
348 353
354 scoped_ptr<ProxyResolver::Request> req;
349 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, 355 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
350 callback1.callback(), NULL, 356 callback1.callback(), &req,
351 mock_bindings.CreateBindings()); 357 mock_bindings.CreateBindings());
352 358
353 EXPECT_EQ(OK, callback1.WaitForResult()); 359 EXPECT_EQ(OK, callback1.WaitForResult());
354 360
355 // The test does 2 DNS resolutions. 361 // The test does 2 DNS resolutions.
356 EXPECT_EQ(2u, host_resolver.num_resolve()); 362 EXPECT_EQ(2u, host_resolver.num_resolve());
357 363
358 // The first request took 2 restarts, hence on g_iteration=3. 364 // The first request took 2 restarts, hence on g_iteration=3.
359 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); 365 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI());
360 366
367 scoped_ptr<ProxyResolver::Request> req2;
361 resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info, 368 resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info,
362 callback2.callback(), NULL, 369 callback2.callback(), &req2,
363 mock_bindings.CreateBindings()); 370 mock_bindings.CreateBindings());
364 371
365 EXPECT_EQ(OK, callback2.WaitForResult()); 372 EXPECT_EQ(OK, callback2.WaitForResult());
366 373
367 EXPECT_EQ(4u, host_resolver.num_resolve()); 374 EXPECT_EQ(4u, host_resolver.num_resolve());
368 375
369 // This time no restarts were required, so g_iteration incremented by 1. 376 // This time no restarts were required, so g_iteration incremented by 1.
370 EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI()); 377 EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI());
371 378
372 // There were no alerts or errors. 379 // There were no alerts or errors.
(...skipping 11 matching lines...) Expand all
384 host_resolver.rules()->AddRule("host1", "166.155.144.11"); 391 host_resolver.rules()->AddRule("host1", "166.155.144.11");
385 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); 392 host_resolver.rules()->AddRule("crazy4", "133.199.111.4");
386 host_resolver.rules()->AddRule("*", "122.133.144.155"); 393 host_resolver.rules()->AddRule("*", "122.133.144.155");
387 394
388 scoped_ptr<ProxyResolverV8Tracing> resolver = 395 scoped_ptr<ProxyResolverV8Tracing> resolver =
389 CreateResolver(mock_bindings.CreateBindings(), "global_sideffects1.js"); 396 CreateResolver(mock_bindings.CreateBindings(), "global_sideffects1.js");
390 397
391 TestCompletionCallback callback; 398 TestCompletionCallback callback;
392 ProxyInfo proxy_info; 399 ProxyInfo proxy_info;
393 400
401 scoped_ptr<ProxyResolver::Request> req;
394 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 402 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
395 callback.callback(), NULL, 403 callback.callback(), &req,
396 mock_bindings.CreateBindings()); 404 mock_bindings.CreateBindings());
397 EXPECT_EQ(OK, callback.WaitForResult()); 405 EXPECT_EQ(OK, callback.WaitForResult());
398 406
399 // The script itself only does 2 DNS resolves per execution, however it 407 // The script itself only does 2 DNS resolves per execution, however it
400 // constructs the hostname using a global counter which changes on each 408 // constructs the hostname using a global counter which changes on each
401 // invocation. 409 // invocation.
402 EXPECT_EQ(3u, host_resolver.num_resolve()); 410 EXPECT_EQ(3u, host_resolver.num_resolve());
403 411
404 EXPECT_EQ("166.155.144.11-133.199.111.4:100", 412 EXPECT_EQ("166.155.144.11-133.199.111.4:100",
405 proxy_info.proxy_server().ToURI()); 413 proxy_info.proxy_server().ToURI());
(...skipping 17 matching lines...) Expand all
423 host_resolver.rules()->AddRule("host3", "166.155.144.33"); 431 host_resolver.rules()->AddRule("host3", "166.155.144.33");
424 host_resolver.rules()->AddRule("host4", "166.155.144.44"); 432 host_resolver.rules()->AddRule("host4", "166.155.144.44");
425 host_resolver.rules()->AddRule("*", "122.133.144.155"); 433 host_resolver.rules()->AddRule("*", "122.133.144.155");
426 434
427 scoped_ptr<ProxyResolverV8Tracing> resolver = 435 scoped_ptr<ProxyResolverV8Tracing> resolver =
428 CreateResolver(mock_bindings.CreateBindings(), "global_sideffects2.js"); 436 CreateResolver(mock_bindings.CreateBindings(), "global_sideffects2.js");
429 437
430 TestCompletionCallback callback; 438 TestCompletionCallback callback;
431 ProxyInfo proxy_info; 439 ProxyInfo proxy_info;
432 440
441 scoped_ptr<ProxyResolver::Request> req;
433 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 442 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
434 callback.callback(), NULL, 443 callback.callback(), &req,
435 mock_bindings.CreateBindings()); 444 mock_bindings.CreateBindings());
436 EXPECT_EQ(OK, callback.WaitForResult()); 445 EXPECT_EQ(OK, callback.WaitForResult());
437 446
438 EXPECT_EQ(3u, host_resolver.num_resolve()); 447 EXPECT_EQ(3u, host_resolver.num_resolve());
439 448
440 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); 449 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI());
441 450
442 // There were no alerts or errors. 451 // There were no alerts or errors.
443 EXPECT_TRUE(mock_bindings.GetAlerts().empty()); 452 EXPECT_TRUE(mock_bindings.GetAlerts().empty());
444 EXPECT_TRUE(mock_bindings.GetErrors().empty()); 453 EXPECT_TRUE(mock_bindings.GetErrors().empty());
445 } 454 }
446 455
447 // This test runs a weird PAC script that yields a never ending sequence 456 // This test runs a weird PAC script that yields a never ending sequence
448 // of DNS resolves when restarting. Running it will hit the maximum 457 // of DNS resolves when restarting. Running it will hit the maximum
449 // DNS resolves per request limit (20) after which every DNS resolve will 458 // DNS resolves per request limit (20) after which every DNS resolve will
450 // fail. 459 // fail.
451 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) { 460 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) {
452 MockCachingHostResolver host_resolver; 461 MockCachingHostResolver host_resolver;
453 MockBindings mock_bindings(&host_resolver); 462 MockBindings mock_bindings(&host_resolver);
454 463
455 host_resolver.rules()->AddRule("host*", "166.155.144.11"); 464 host_resolver.rules()->AddRule("host*", "166.155.144.11");
456 host_resolver.rules()->AddRule("*", "122.133.144.155"); 465 host_resolver.rules()->AddRule("*", "122.133.144.155");
457 466
458 scoped_ptr<ProxyResolverV8Tracing> resolver = 467 scoped_ptr<ProxyResolverV8Tracing> resolver =
459 CreateResolver(mock_bindings.CreateBindings(), "global_sideffects3.js"); 468 CreateResolver(mock_bindings.CreateBindings(), "global_sideffects3.js");
460 469
461 TestCompletionCallback callback; 470 TestCompletionCallback callback;
462 ProxyInfo proxy_info; 471 ProxyInfo proxy_info;
463 472
473 scoped_ptr<ProxyResolver::Request> req;
464 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 474 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
465 callback.callback(), NULL, 475 callback.callback(), &req,
466 mock_bindings.CreateBindings()); 476 mock_bindings.CreateBindings());
467 EXPECT_EQ(OK, callback.WaitForResult()); 477 EXPECT_EQ(OK, callback.WaitForResult());
468 478
469 EXPECT_EQ(20u, host_resolver.num_resolve()); 479 EXPECT_EQ(20u, host_resolver.num_resolve());
470 480
471 EXPECT_EQ( 481 EXPECT_EQ(
472 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" 482 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-"
473 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" 483 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-"
474 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" 484 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-"
475 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" 485 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-"
(...skipping 18 matching lines...) Expand all
494 504
495 host_resolver.rules()->AddRule("host*", "166.155.144.11"); 505 host_resolver.rules()->AddRule("host*", "166.155.144.11");
496 host_resolver.rules()->AddRule("*", "122.133.144.155"); 506 host_resolver.rules()->AddRule("*", "122.133.144.155");
497 507
498 scoped_ptr<ProxyResolverV8Tracing> resolver = 508 scoped_ptr<ProxyResolverV8Tracing> resolver =
499 CreateResolver(mock_bindings.CreateBindings(), "global_sideffects4.js"); 509 CreateResolver(mock_bindings.CreateBindings(), "global_sideffects4.js");
500 510
501 TestCompletionCallback callback; 511 TestCompletionCallback callback;
502 ProxyInfo proxy_info; 512 ProxyInfo proxy_info;
503 513
514 scoped_ptr<ProxyResolver::Request> req;
504 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 515 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
505 callback.callback(), NULL, 516 callback.callback(), &req,
506 mock_bindings.CreateBindings()); 517 mock_bindings.CreateBindings());
507 EXPECT_EQ(OK, callback.WaitForResult()); 518 EXPECT_EQ(OK, callback.WaitForResult());
508 519
509 EXPECT_EQ(20u, host_resolver.num_resolve()); 520 EXPECT_EQ(20u, host_resolver.num_resolve());
510 521
511 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); 522 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI());
512 523
513 // No errors. 524 // No errors.
514 EXPECT_TRUE(mock_bindings.GetErrors().empty()); 525 EXPECT_TRUE(mock_bindings.GetErrors().empty());
515 526
(...skipping 18 matching lines...) Expand all
534 545
535 host_resolver.rules()->ClearRules(); 546 host_resolver.rules()->ClearRules();
536 host_resolver.GetHostCache()->clear(); 547 host_resolver.GetHostCache()->clear();
537 548
538 host_resolver.rules()->AddRule("host1", "145.88.13.3"); 549 host_resolver.rules()->AddRule("host1", "145.88.13.3");
539 host_resolver.rules()->AddRule("host2", "137.89.8.45"); 550 host_resolver.rules()->AddRule("host2", "137.89.8.45");
540 551
541 TestCompletionCallback callback; 552 TestCompletionCallback callback;
542 ProxyInfo proxy_info; 553 ProxyInfo proxy_info;
543 554
555 scoped_ptr<ProxyResolver::Request> req;
544 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 556 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
545 callback.callback(), NULL, 557 callback.callback(), &req,
546 mock_bindings.CreateBindings()); 558 mock_bindings.CreateBindings());
547 EXPECT_EQ(OK, callback.WaitForResult()); 559 EXPECT_EQ(OK, callback.WaitForResult());
548 560
549 // Fetched host1 and host2 again, since the ones done during initialization 561 // Fetched host1 and host2 again, since the ones done during initialization
550 // should not have been cached. 562 // should not have been cached.
551 EXPECT_EQ(4u, host_resolver.num_resolve()); 563 EXPECT_EQ(4u, host_resolver.num_resolve());
552 564
553 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", 565 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99",
554 proxy_info.proxy_server().ToURI()); 566 proxy_info.proxy_server().ToURI());
555 567
(...skipping 24 matching lines...) Expand all
580 MockCachingHostResolver host_resolver; 592 MockCachingHostResolver host_resolver;
581 MockBindings mock_bindings(&host_resolver); 593 MockBindings mock_bindings(&host_resolver);
582 594
583 host_resolver.rules()->AddSimulatedFailure("*"); 595 host_resolver.rules()->AddSimulatedFailure("*");
584 596
585 scoped_ptr<ProxyResolverV8Tracing> resolver = 597 scoped_ptr<ProxyResolverV8Tracing> resolver =
586 CreateResolver(mock_bindings.CreateBindings(), "dns.js"); 598 CreateResolver(mock_bindings.CreateBindings(), "dns.js");
587 599
588 const size_t kNumRequests = 5; 600 const size_t kNumRequests = 5;
589 ProxyInfo proxy_info[kNumRequests]; 601 ProxyInfo proxy_info[kNumRequests];
590 ProxyResolver::RequestHandle request[kNumRequests]; 602 scoped_ptr<ProxyResolver::Request> request[kNumRequests];
591 603
592 for (size_t i = 0; i < kNumRequests; ++i) { 604 for (size_t i = 0; i < kNumRequests; ++i) {
593 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], 605 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i],
594 base::Bind(&CrashCallback), &request[i], 606 base::Bind(&CrashCallback), &request[i],
595 mock_bindings.CreateBindings()); 607 mock_bindings.CreateBindings());
596 } 608 }
597 609
598 for (size_t i = 0; i < kNumRequests; ++i) { 610 for (size_t i = 0; i < kNumRequests; ++i) {
599 resolver->CancelRequest(request[i]); 611 request[i].reset();
600 } 612 }
601 } 613 }
602 614
603 // Note the execution order for this test can vary. Since multiple 615 // Note the execution order for this test can vary. Since multiple
604 // threads are involved, the cancellation may be received a different 616 // threads are involved, the cancellation may be received a different
605 // times. 617 // times.
606 TEST_F(ProxyResolverV8TracingTest, CancelSome) { 618 TEST_F(ProxyResolverV8TracingTest, CancelSome) {
607 MockCachingHostResolver host_resolver; 619 MockCachingHostResolver host_resolver;
608 MockBindings mock_bindings(&host_resolver); 620 MockBindings mock_bindings(&host_resolver);
609 621
610 host_resolver.rules()->AddSimulatedFailure("*"); 622 host_resolver.rules()->AddSimulatedFailure("*");
611 623
612 scoped_ptr<ProxyResolverV8Tracing> resolver = 624 scoped_ptr<ProxyResolverV8Tracing> resolver =
613 CreateResolver(mock_bindings.CreateBindings(), "dns.js"); 625 CreateResolver(mock_bindings.CreateBindings(), "dns.js");
614 626
615 ProxyInfo proxy_info1; 627 ProxyInfo proxy_info1;
616 ProxyInfo proxy_info2; 628 ProxyInfo proxy_info2;
617 ProxyResolver::RequestHandle request1; 629 scoped_ptr<ProxyResolver::Request> request1;
618 ProxyResolver::RequestHandle request2; 630 scoped_ptr<ProxyResolver::Request> request2;
619 TestCompletionCallback callback; 631 TestCompletionCallback callback;
620 632
621 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1, 633 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1,
622 base::Bind(&CrashCallback), &request1, 634 base::Bind(&CrashCallback), &request1,
623 mock_bindings.CreateBindings()); 635 mock_bindings.CreateBindings());
624 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2, 636 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2,
625 callback.callback(), &request2, 637 callback.callback(), &request2,
626 mock_bindings.CreateBindings()); 638 mock_bindings.CreateBindings());
627 639
628 resolver->CancelRequest(request1); 640 request1.reset();
629 641
630 EXPECT_EQ(OK, callback.WaitForResult()); 642 EXPECT_EQ(OK, callback.WaitForResult());
631 } 643 }
632 644
633 // Cancel a request after it has finished running on the worker thread, and has 645 // Cancel a request after it has finished running on the worker thread, and has
634 // posted a task the completion task back to origin thread. 646 // posted a task the completion task back to origin thread.
635 TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) { 647 TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) {
636 MockCachingHostResolver host_resolver; 648 MockCachingHostResolver host_resolver;
637 MockBindings mock_bindings(&host_resolver); 649 MockBindings mock_bindings(&host_resolver);
638 650
639 host_resolver.rules()->AddSimulatedFailure("*"); 651 host_resolver.rules()->AddSimulatedFailure("*");
640 652
641 scoped_ptr<ProxyResolverV8Tracing> resolver = 653 scoped_ptr<ProxyResolverV8Tracing> resolver =
642 CreateResolver(mock_bindings.CreateBindings(), "error.js"); 654 CreateResolver(mock_bindings.CreateBindings(), "error.js");
643 655
644 ProxyInfo proxy_info1; 656 ProxyInfo proxy_info1;
645 ProxyInfo proxy_info2; 657 ProxyInfo proxy_info2;
646 ProxyResolver::RequestHandle request1; 658 scoped_ptr<ProxyResolver::Request> request1;
647 ProxyResolver::RequestHandle request2; 659 scoped_ptr<ProxyResolver::Request> request2;
648 TestCompletionCallback callback; 660 TestCompletionCallback callback;
649 661
650 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info1, 662 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info1,
651 base::Bind(&CrashCallback), &request1, 663 base::Bind(&CrashCallback), &request1,
652 mock_bindings.CreateBindings()); 664 mock_bindings.CreateBindings());
653 665
654 // Wait until the first request has finished running on the worker thread. 666 // Wait until the first request has finished running on the worker thread.
655 // Cancel the first request, while it is running its completion task on 667 // Cancel the first request, while it is running its completion task on
656 // the origin thread. 668 // the origin thread. Reset deletes Request opject which cancels the request.
657 mock_bindings.RunOnError(base::Bind(&ProxyResolverV8Tracing::CancelRequest, 669 mock_bindings.RunOnError(
658 base::Unretained(resolver.get()), 670 base::Bind(&scoped_ptr<ProxyResolver::Request>::reset,
659 request1)); 671 base::Unretained(&request1), nullptr));
660 672
661 // Start another request, to make sure it is able to complete. 673 // Start another request, to make sure it is able to complete.
662 resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), 674 resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"),
663 &proxy_info2, callback.callback(), &request2, 675 &proxy_info2, callback.callback(), &request2,
664 mock_bindings.CreateBindings()); 676 mock_bindings.CreateBindings());
665 677
666 EXPECT_EQ(OK, callback.WaitForResult()); 678 EXPECT_EQ(OK, callback.WaitForResult());
667 679
668 EXPECT_EQ("i-approve-this-message:42", proxy_info2.proxy_server().ToURI()); 680 EXPECT_EQ("i-approve-this-message:42", proxy_info2.proxy_server().ToURI());
669 } 681 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 // when the request has an outstanding DNS request in flight. 751 // when the request has an outstanding DNS request in flight.
740 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { 752 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) {
741 BlockableHostResolver host_resolver; 753 BlockableHostResolver host_resolver;
742 MockBindings mock_bindings(&host_resolver); 754 MockBindings mock_bindings(&host_resolver);
743 755
744 scoped_ptr<ProxyResolverV8Tracing> resolver = 756 scoped_ptr<ProxyResolverV8Tracing> resolver =
745 CreateResolver(mock_bindings.CreateBindings(), "dns.js"); 757 CreateResolver(mock_bindings.CreateBindings(), "dns.js");
746 758
747 ProxyInfo proxy_info1; 759 ProxyInfo proxy_info1;
748 ProxyInfo proxy_info2; 760 ProxyInfo proxy_info2;
749 ProxyResolver::RequestHandle request1; 761 scoped_ptr<ProxyResolver::Request> request1;
750 ProxyResolver::RequestHandle request2; 762 scoped_ptr<ProxyResolver::Request> request2;
751 763
752 resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1, 764 resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1,
753 base::Bind(&CrashCallback), &request1, 765 base::Bind(&CrashCallback), &request1,
754 mock_bindings.CreateBindings()); 766 mock_bindings.CreateBindings());
755 767
756 host_resolver.WaitUntilRequestIsReceived(); 768 host_resolver.WaitUntilRequestIsReceived();
757 769
758 resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2, 770 resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2,
759 base::Bind(&CrashCallback), &request2, 771 base::Bind(&CrashCallback), &request2,
760 mock_bindings.CreateBindings()); 772 mock_bindings.CreateBindings());
761 773
762 host_resolver.WaitUntilRequestIsReceived(); 774 host_resolver.WaitUntilRequestIsReceived();
763 775
764 resolver->CancelRequest(request1); 776 request1.reset();
765 resolver->CancelRequest(request2); 777 request2.reset();
766 778
767 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); 779 EXPECT_EQ(2, host_resolver.num_cancelled_requests());
768 780
769 // After leaving this scope, the ProxyResolver is destroyed. 781 // After leaving this scope, the ProxyResolver is destroyed.
770 // This should not cause any problems, as the outstanding work 782 // This should not cause any problems, as the outstanding work
771 // should have been cancelled. 783 // should have been cancelled.
772 } 784 }
773 785
774 void CancelRequestAndPause(ProxyResolverV8Tracing* resolver, 786 void CancelRequestAndPause(scoped_ptr<ProxyResolver::Request>* request) {
775 ProxyResolver::RequestHandle request) { 787 request->reset();
776 resolver->CancelRequest(request);
777 788
778 // Sleep for a little bit. This makes it more likely for the worker 789 // Sleep for a little bit. This makes it more likely for the worker
779 // thread to have returned from its call, and serves as a regression 790 // thread to have returned from its call, and serves as a regression
780 // test for http://crbug.com/173373. 791 // test for http://crbug.com/173373.
781 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); 792 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30));
782 } 793 }
783 794
784 // In non-blocking mode, the worker thread actually does block for 795 // In non-blocking mode, the worker thread actually does block for
785 // a short time to see if the result is in the DNS cache. Test 796 // a short time to see if the result is in the DNS cache. Test
786 // cancellation while the worker thread is waiting on this event. 797 // cancellation while the worker thread is waiting on this event.
787 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) { 798 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) {
788 BlockableHostResolver host_resolver; 799 BlockableHostResolver host_resolver;
789 MockBindings mock_bindings(&host_resolver); 800 MockBindings mock_bindings(&host_resolver);
790 801
791 scoped_ptr<ProxyResolverV8Tracing> resolver = 802 scoped_ptr<ProxyResolverV8Tracing> resolver =
792 CreateResolver(mock_bindings.CreateBindings(), "dns.js"); 803 CreateResolver(mock_bindings.CreateBindings(), "dns.js");
793 804
794 ProxyInfo proxy_info; 805 ProxyInfo proxy_info;
795 ProxyResolver::RequestHandle request; 806 scoped_ptr<ProxyResolver::Request> request;
796 807
797 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 808 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
798 base::Bind(&CrashCallback), &request, 809 base::Bind(&CrashCallback), &request,
799 mock_bindings.CreateBindings()); 810 mock_bindings.CreateBindings());
800 811
801 host_resolver.SetAction( 812 host_resolver.SetAction(base::Bind(CancelRequestAndPause, &request));
802 base::Bind(CancelRequestAndPause, resolver.get(), request));
803 813
804 host_resolver.WaitUntilRequestIsReceived(); 814 host_resolver.WaitUntilRequestIsReceived();
805 } 815 }
806 816
807 // Cancel the request while there is a pending DNS request, however before 817 // Cancel the request while there is a pending DNS request, however before
808 // the request is sent to the host resolver. 818 // the request is sent to the host resolver.
809 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) { 819 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) {
810 MockCachingHostResolver host_resolver; 820 MockCachingHostResolver host_resolver;
811 MockBindings mock_bindings(&host_resolver); 821 MockBindings mock_bindings(&host_resolver);
812 822
813 scoped_ptr<ProxyResolverV8Tracing> resolver = 823 scoped_ptr<ProxyResolverV8Tracing> resolver =
814 CreateResolver(mock_bindings.CreateBindings(), "dns.js"); 824 CreateResolver(mock_bindings.CreateBindings(), "dns.js");
815 825
816 ProxyInfo proxy_info; 826 ProxyInfo proxy_info;
817 ProxyResolver::RequestHandle request; 827 scoped_ptr<ProxyResolver::Request> request;
818 828
819 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, 829 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info,
820 base::Bind(&CrashCallback), &request, 830 base::Bind(&CrashCallback), &request,
821 mock_bindings.CreateBindings()); 831 mock_bindings.CreateBindings());
822 832
823 // Wait a bit, so the DNS task has hopefully been posted. The test will 833 // Wait a bit, so the DNS task has hopefully been posted. The test will
824 // work whatever the delay is here, but it is most useful if the delay 834 // work whatever the delay is here, but it is most useful if the delay
825 // is large enough to allow a task to be posted back. 835 // is large enough to allow a task to be posted back.
826 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); 836 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
827 resolver->CancelRequest(request); 837 request.reset();
828 838
829 EXPECT_EQ(0u, host_resolver.num_resolve()); 839 EXPECT_EQ(0u, host_resolver.num_resolve());
830 } 840 }
831 841
832 TEST_F(ProxyResolverV8TracingTest, 842 TEST_F(ProxyResolverV8TracingTest,
833 CancelCreateResolverWhileOutstandingBlockingDns) { 843 CancelCreateResolverWhileOutstandingBlockingDns) {
834 BlockableHostResolver host_resolver; 844 BlockableHostResolver host_resolver;
835 MockBindings mock_bindings(&host_resolver); 845 MockBindings mock_bindings(&host_resolver);
836 846
837 scoped_ptr<ProxyResolverV8TracingFactory> factory( 847 scoped_ptr<ProxyResolverV8TracingFactory> factory(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 901
892 host_resolver.rules()->AddRule("host1", "182.111.0.222"); 902 host_resolver.rules()->AddRule("host1", "182.111.0.222");
893 host_resolver.rules()->AddRule("host2", "111.33.44.55"); 903 host_resolver.rules()->AddRule("host2", "111.33.44.55");
894 904
895 scoped_ptr<ProxyResolverV8Tracing> resolver = 905 scoped_ptr<ProxyResolverV8Tracing> resolver =
896 CreateResolver(mock_bindings.CreateBindings(), "terminate.js"); 906 CreateResolver(mock_bindings.CreateBindings(), "terminate.js");
897 907
898 TestCompletionCallback callback; 908 TestCompletionCallback callback;
899 ProxyInfo proxy_info; 909 ProxyInfo proxy_info;
900 910
911 scoped_ptr<ProxyResolver::Request> req;
901 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, 912 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info,
902 callback.callback(), NULL, 913 callback.callback(), &req,
903 mock_bindings.CreateBindings()); 914 mock_bindings.CreateBindings());
904 EXPECT_EQ(OK, callback.WaitForResult()); 915 EXPECT_EQ(OK, callback.WaitForResult());
905 916
906 // The test does 2 DNS resolutions. 917 // The test does 2 DNS resolutions.
907 EXPECT_EQ(2u, host_resolver.num_resolve()); 918 EXPECT_EQ(2u, host_resolver.num_resolve());
908 919
909 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); 920 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI());
910 921
911 // No errors or alerts. 922 // No errors or alerts.
912 EXPECT_TRUE(mock_bindings.GetErrors().empty()); 923 EXPECT_TRUE(mock_bindings.GetErrors().empty());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 975
965 ProxyResolverV8Tracing* resolver[] = { 976 ProxyResolverV8Tracing* resolver[] = {
966 resolver0.get(), resolver1.get(), resolver2.get(), resolver3.get(), 977 resolver0.get(), resolver1.get(), resolver2.get(), resolver3.get(),
967 }; 978 };
968 979
969 const size_t kNumResolvers = arraysize(resolver); 980 const size_t kNumResolvers = arraysize(resolver);
970 const size_t kNumIterations = 20; 981 const size_t kNumIterations = 20;
971 const size_t kNumResults = kNumResolvers * kNumIterations; 982 const size_t kNumResults = kNumResolvers * kNumIterations;
972 TestCompletionCallback callback[kNumResults]; 983 TestCompletionCallback callback[kNumResults];
973 ProxyInfo proxy_info[kNumResults]; 984 ProxyInfo proxy_info[kNumResults];
985 scoped_ptr<ProxyResolver::Request> request[kNumResults];
974 986
975 for (size_t i = 0; i < kNumResults; ++i) { 987 for (size_t i = 0; i < kNumResults; ++i) {
976 size_t resolver_i = i % kNumResolvers; 988 size_t resolver_i = i % kNumResolvers;
977 resolver[resolver_i]->GetProxyForURL( 989 resolver[resolver_i]->GetProxyForURL(
978 GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL, 990 GURL("http://foo/"), &proxy_info[i], callback[i].callback(),
979 resolver_i == 3 ? mock_bindings3.CreateBindings() 991 &request[i], resolver_i == 3 ? mock_bindings3.CreateBindings()
980 : mock_bindings0.CreateBindings()); 992 : mock_bindings0.CreateBindings());
981 } 993 }
982 994
983 // ------------------------ 995 // ------------------------
984 // Verify all of the results. 996 // Verify all of the results.
985 // ------------------------ 997 // ------------------------
986 998
987 const char* kExpectedForDnsJs = 999 const char* kExpectedForDnsJs =
988 "122.133.144.155-" // myIpAddress() 1000 "122.133.144.155-" // myIpAddress()
989 "null-" // dnsResolve('') 1001 "null-" // dnsResolve('')
990 "__1_192.168.1.1-" // dnsResolveEx('host1') 1002 "__1_192.168.1.1-" // dnsResolveEx('host1')
(...skipping 24 matching lines...) Expand all
1015 proxy_uri.substr(0, proxy_uri.find(':') + 1)); 1027 proxy_uri.substr(0, proxy_uri.find(':') + 1));
1016 } else { 1028 } else {
1017 NOTREACHED(); 1029 NOTREACHED();
1018 } 1030 }
1019 } 1031 }
1020 } 1032 }
1021 1033
1022 } // namespace 1034 } // namespace
1023 1035
1024 } // namespace net 1036 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_v8_tracing.cc ('k') | net/proxy/proxy_resolver_v8_tracing_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698