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

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

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