| OLD | NEW |
| 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_wrapper.h" | 5 #include "net/proxy/proxy_resolver_v8_tracing_wrapper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 BoundTestNetLog request_log; | 121 BoundTestNetLog request_log; |
| 122 MockCachingHostResolver host_resolver; | 122 MockCachingHostResolver host_resolver; |
| 123 MockErrorObserver* error_observer = new MockErrorObserver; | 123 MockErrorObserver* error_observer = new MockErrorObserver; |
| 124 | 124 |
| 125 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 125 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 126 &log, &host_resolver, make_scoped_ptr(error_observer), "simple.js"); | 126 &log, &host_resolver, make_scoped_ptr(error_observer), "simple.js"); |
| 127 | 127 |
| 128 TestCompletionCallback callback; | 128 TestCompletionCallback callback; |
| 129 ProxyInfo proxy_info; | 129 ProxyInfo proxy_info; |
| 130 | 130 |
| 131 scoped_ptr<ProxyResolver::Request> req; |
| 131 int rv = | 132 int rv = |
| 132 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 133 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 133 callback.callback(), NULL, request_log.bound()); | 134 callback.callback(), &req, request_log.bound()); |
| 134 | 135 |
| 135 EXPECT_EQ(ERR_IO_PENDING, rv); | 136 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 136 EXPECT_EQ(OK, callback.WaitForResult()); | 137 EXPECT_EQ(OK, callback.WaitForResult()); |
| 137 | 138 |
| 138 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); | 139 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); |
| 139 | 140 |
| 140 EXPECT_EQ(0u, host_resolver.num_resolve()); | 141 EXPECT_EQ(0u, host_resolver.num_resolve()); |
| 141 | 142 |
| 142 // There were no errors. | 143 // There were no errors. |
| 143 EXPECT_EQ("", error_observer->GetOutput()); | 144 EXPECT_EQ("", error_observer->GetOutput()); |
| 144 | 145 |
| 145 // Check the NetLogs -- nothing was logged. | 146 // Check the NetLogs -- nothing was logged. |
| 146 EXPECT_EQ(0u, log.GetSize()); | 147 EXPECT_EQ(0u, log.GetSize()); |
| 147 EXPECT_EQ(0u, request_log.GetSize()); | 148 EXPECT_EQ(0u, request_log.GetSize()); |
| 148 } | 149 } |
| 149 | 150 |
| 150 TEST_F(ProxyResolverV8TracingWrapperTest, JavascriptError) { | 151 TEST_F(ProxyResolverV8TracingWrapperTest, JavascriptError) { |
| 151 TestNetLog log; | 152 TestNetLog log; |
| 152 BoundTestNetLog request_log; | 153 BoundTestNetLog request_log; |
| 153 MockCachingHostResolver host_resolver; | 154 MockCachingHostResolver host_resolver; |
| 154 MockErrorObserver* error_observer = new MockErrorObserver; | 155 MockErrorObserver* error_observer = new MockErrorObserver; |
| 155 | 156 |
| 156 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 157 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 157 &log, &host_resolver, make_scoped_ptr(error_observer), "error.js"); | 158 &log, &host_resolver, make_scoped_ptr(error_observer), "error.js"); |
| 158 | 159 |
| 159 TestCompletionCallback callback; | 160 TestCompletionCallback callback; |
| 160 ProxyInfo proxy_info; | 161 ProxyInfo proxy_info; |
| 161 | 162 |
| 163 scoped_ptr<ProxyResolver::Request> req; |
| 162 int rv = | 164 int rv = |
| 163 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, | 165 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, |
| 164 callback.callback(), NULL, request_log.bound()); | 166 callback.callback(), &req, request_log.bound()); |
| 165 | 167 |
| 166 EXPECT_EQ(ERR_IO_PENDING, rv); | 168 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 167 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 169 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
| 168 | 170 |
| 169 EXPECT_EQ(0u, host_resolver.num_resolve()); | 171 EXPECT_EQ(0u, host_resolver.num_resolve()); |
| 170 | 172 |
| 171 EXPECT_EQ( | 173 EXPECT_EQ( |
| 172 "Error: line 5: Uncaught TypeError: Cannot read property 'split' " | 174 "Error: line 5: Uncaught TypeError: Cannot read property 'split' " |
| 173 "of null\n", | 175 "of null\n", |
| 174 error_observer->GetOutput()); | 176 error_observer->GetOutput()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 201 MockCachingHostResolver host_resolver; | 203 MockCachingHostResolver host_resolver; |
| 202 MockErrorObserver* error_observer = new MockErrorObserver; | 204 MockErrorObserver* error_observer = new MockErrorObserver; |
| 203 | 205 |
| 204 scoped_ptr<ProxyResolver> resolver = | 206 scoped_ptr<ProxyResolver> resolver = |
| 205 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 207 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 206 "too_many_alerts.js"); | 208 "too_many_alerts.js"); |
| 207 | 209 |
| 208 TestCompletionCallback callback; | 210 TestCompletionCallback callback; |
| 209 ProxyInfo proxy_info; | 211 ProxyInfo proxy_info; |
| 210 | 212 |
| 213 scoped_ptr<ProxyResolver::Request> req; |
| 211 int rv = | 214 int rv = |
| 212 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 215 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 213 callback.callback(), NULL, request_log.bound()); | 216 callback.callback(), &req, request_log.bound()); |
| 214 | 217 |
| 215 EXPECT_EQ(ERR_IO_PENDING, rv); | 218 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 216 EXPECT_EQ(OK, callback.WaitForResult()); | 219 EXPECT_EQ(OK, callback.WaitForResult()); |
| 217 | 220 |
| 218 // Iteration1 does a DNS resolve | 221 // Iteration1 does a DNS resolve |
| 219 // Iteration2 exceeds the alert buffer | 222 // Iteration2 exceeds the alert buffer |
| 220 // Iteration3 runs in blocking mode and completes | 223 // Iteration3 runs in blocking mode and completes |
| 221 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 224 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
| 222 | 225 |
| 223 EXPECT_EQ(1u, host_resolver.num_resolve()); | 226 EXPECT_EQ(1u, host_resolver.num_resolve()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 249 MockCachingHostResolver host_resolver; | 252 MockCachingHostResolver host_resolver; |
| 250 MockErrorObserver* error_observer = new MockErrorObserver; | 253 MockErrorObserver* error_observer = new MockErrorObserver; |
| 251 | 254 |
| 252 scoped_ptr<ProxyResolver> resolver = | 255 scoped_ptr<ProxyResolver> resolver = |
| 253 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 256 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 254 "too_many_empty_alerts.js"); | 257 "too_many_empty_alerts.js"); |
| 255 | 258 |
| 256 TestCompletionCallback callback; | 259 TestCompletionCallback callback; |
| 257 ProxyInfo proxy_info; | 260 ProxyInfo proxy_info; |
| 258 | 261 |
| 262 scoped_ptr<ProxyResolver::Request> req; |
| 259 int rv = | 263 int rv = |
| 260 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 264 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 261 callback.callback(), NULL, request_log.bound()); | 265 callback.callback(), &req, request_log.bound()); |
| 262 | 266 |
| 263 EXPECT_EQ(ERR_IO_PENDING, rv); | 267 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 264 EXPECT_EQ(OK, callback.WaitForResult()); | 268 EXPECT_EQ(OK, callback.WaitForResult()); |
| 265 | 269 |
| 266 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 270 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
| 267 | 271 |
| 268 EXPECT_EQ(1u, host_resolver.num_resolve()); | 272 EXPECT_EQ(1u, host_resolver.num_resolve()); |
| 269 | 273 |
| 270 // No errors. | 274 // No errors. |
| 271 EXPECT_EQ("", error_observer->GetOutput()); | 275 EXPECT_EQ("", error_observer->GetOutput()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 host_resolver.rules()->AddRuleForAddressFamily("*", ADDRESS_FAMILY_IPV4, | 310 host_resolver.rules()->AddRuleForAddressFamily("*", ADDRESS_FAMILY_IPV4, |
| 307 "122.133.144.155"); | 311 "122.133.144.155"); |
| 308 host_resolver.rules()->AddRule("*", "133.122.100.200"); | 312 host_resolver.rules()->AddRule("*", "133.122.100.200"); |
| 309 | 313 |
| 310 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 314 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 311 &log, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 315 &log, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 312 | 316 |
| 313 TestCompletionCallback callback; | 317 TestCompletionCallback callback; |
| 314 ProxyInfo proxy_info; | 318 ProxyInfo proxy_info; |
| 315 | 319 |
| 320 scoped_ptr<ProxyResolver::Request> req; |
| 316 int rv = | 321 int rv = |
| 317 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 322 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 318 callback.callback(), NULL, request_log.bound()); | 323 callback.callback(), &req, request_log.bound()); |
| 319 | 324 |
| 320 EXPECT_EQ(ERR_IO_PENDING, rv); | 325 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 321 EXPECT_EQ(OK, callback.WaitForResult()); | 326 EXPECT_EQ(OK, callback.WaitForResult()); |
| 322 | 327 |
| 323 // The test does 13 DNS resolution, however only 7 of them are unique. | 328 // The test does 13 DNS resolution, however only 7 of them are unique. |
| 324 EXPECT_EQ(7u, host_resolver.num_resolve()); | 329 EXPECT_EQ(7u, host_resolver.num_resolve()); |
| 325 | 330 |
| 326 const char* kExpectedResult = | 331 const char* kExpectedResult = |
| 327 "122.133.144.155-" // myIpAddress() | 332 "122.133.144.155-" // myIpAddress() |
| 328 "null-" // dnsResolve('') | 333 "null-" // dnsResolve('') |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); | 376 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); |
| 372 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 377 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 373 | 378 |
| 374 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 379 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 375 &log, &host_resolver, make_scoped_ptr(error_observer), "simple_dns.js"); | 380 &log, &host_resolver, make_scoped_ptr(error_observer), "simple_dns.js"); |
| 376 | 381 |
| 377 TestCompletionCallback callback1; | 382 TestCompletionCallback callback1; |
| 378 TestCompletionCallback callback2; | 383 TestCompletionCallback callback2; |
| 379 ProxyInfo proxy_info; | 384 ProxyInfo proxy_info; |
| 380 | 385 |
| 386 scoped_ptr<ProxyResolver::Request> req; |
| 381 int rv = | 387 int rv = |
| 382 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, | 388 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, |
| 383 callback1.callback(), NULL, request_log.bound()); | 389 callback1.callback(), &req, request_log.bound()); |
| 384 | 390 |
| 385 EXPECT_EQ(ERR_IO_PENDING, rv); | 391 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 386 EXPECT_EQ(OK, callback1.WaitForResult()); | 392 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 387 | 393 |
| 388 // The test does 2 DNS resolutions. | 394 // The test does 2 DNS resolutions. |
| 389 EXPECT_EQ(2u, host_resolver.num_resolve()); | 395 EXPECT_EQ(2u, host_resolver.num_resolve()); |
| 390 | 396 |
| 391 // The first request took 2 restarts, hence on g_iteration=3. | 397 // The first request took 2 restarts, hence on g_iteration=3. |
| 392 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); | 398 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); |
| 393 | 399 |
| 394 rv = | 400 scoped_ptr<ProxyResolver::Request> req2; |
| 395 resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info, | 401 rv = resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info, |
| 396 callback2.callback(), NULL, request_log.bound()); | 402 callback2.callback(), &req2, |
| 403 request_log.bound()); |
| 397 | 404 |
| 398 EXPECT_EQ(ERR_IO_PENDING, rv); | 405 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 399 EXPECT_EQ(OK, callback2.WaitForResult()); | 406 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 400 | 407 |
| 401 EXPECT_EQ(4u, host_resolver.num_resolve()); | 408 EXPECT_EQ(4u, host_resolver.num_resolve()); |
| 402 | 409 |
| 403 // This time no restarts were required, so g_iteration incremented by 1. | 410 // This time no restarts were required, so g_iteration incremented by 1. |
| 404 EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI()); | 411 EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI()); |
| 405 | 412 |
| 406 // No errors. | 413 // No errors. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 423 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); | 430 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); |
| 424 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 431 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 425 | 432 |
| 426 scoped_ptr<ProxyResolver> resolver = | 433 scoped_ptr<ProxyResolver> resolver = |
| 427 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 434 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 428 "global_sideffects1.js"); | 435 "global_sideffects1.js"); |
| 429 | 436 |
| 430 TestCompletionCallback callback; | 437 TestCompletionCallback callback; |
| 431 ProxyInfo proxy_info; | 438 ProxyInfo proxy_info; |
| 432 | 439 |
| 440 scoped_ptr<ProxyResolver::Request> req; |
| 433 int rv = | 441 int rv = |
| 434 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 442 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 435 callback.callback(), NULL, request_log.bound()); | 443 callback.callback(), &req, request_log.bound()); |
| 436 EXPECT_EQ(ERR_IO_PENDING, rv); | 444 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 437 EXPECT_EQ(OK, callback.WaitForResult()); | 445 EXPECT_EQ(OK, callback.WaitForResult()); |
| 438 | 446 |
| 439 // The script itself only does 2 DNS resolves per execution, however it | 447 // The script itself only does 2 DNS resolves per execution, however it |
| 440 // constructs the hostname using a global counter which changes on each | 448 // constructs the hostname using a global counter which changes on each |
| 441 // invocation. | 449 // invocation. |
| 442 EXPECT_EQ(3u, host_resolver.num_resolve()); | 450 EXPECT_EQ(3u, host_resolver.num_resolve()); |
| 443 | 451 |
| 444 EXPECT_EQ("166.155.144.11-133.199.111.4:100", | 452 EXPECT_EQ("166.155.144.11-133.199.111.4:100", |
| 445 proxy_info.proxy_server().ToURI()); | 453 proxy_info.proxy_server().ToURI()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 host_resolver.rules()->AddRule("host4", "166.155.144.44"); | 485 host_resolver.rules()->AddRule("host4", "166.155.144.44"); |
| 478 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 486 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 479 | 487 |
| 480 scoped_ptr<ProxyResolver> resolver = | 488 scoped_ptr<ProxyResolver> resolver = |
| 481 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 489 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 482 "global_sideffects2.js"); | 490 "global_sideffects2.js"); |
| 483 | 491 |
| 484 TestCompletionCallback callback; | 492 TestCompletionCallback callback; |
| 485 ProxyInfo proxy_info; | 493 ProxyInfo proxy_info; |
| 486 | 494 |
| 495 scoped_ptr<ProxyResolver::Request> req; |
| 487 int rv = | 496 int rv = |
| 488 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 497 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 489 callback.callback(), NULL, request_log.bound()); | 498 callback.callback(), &req, request_log.bound()); |
| 490 EXPECT_EQ(ERR_IO_PENDING, rv); | 499 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 491 EXPECT_EQ(OK, callback.WaitForResult()); | 500 EXPECT_EQ(OK, callback.WaitForResult()); |
| 492 | 501 |
| 493 EXPECT_EQ(3u, host_resolver.num_resolve()); | 502 EXPECT_EQ(3u, host_resolver.num_resolve()); |
| 494 | 503 |
| 495 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); | 504 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); |
| 496 | 505 |
| 497 // No errors. | 506 // No errors. |
| 498 EXPECT_EQ("", error_observer->GetOutput()); | 507 EXPECT_EQ("", error_observer->GetOutput()); |
| 499 | 508 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 515 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 524 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
| 516 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 525 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 517 | 526 |
| 518 scoped_ptr<ProxyResolver> resolver = | 527 scoped_ptr<ProxyResolver> resolver = |
| 519 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 528 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 520 "global_sideffects3.js"); | 529 "global_sideffects3.js"); |
| 521 | 530 |
| 522 TestCompletionCallback callback; | 531 TestCompletionCallback callback; |
| 523 ProxyInfo proxy_info; | 532 ProxyInfo proxy_info; |
| 524 | 533 |
| 534 scoped_ptr<ProxyResolver::Request> req; |
| 525 int rv = | 535 int rv = |
| 526 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 536 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 527 callback.callback(), NULL, request_log.bound()); | 537 callback.callback(), &req, request_log.bound()); |
| 528 EXPECT_EQ(ERR_IO_PENDING, rv); | 538 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 529 EXPECT_EQ(OK, callback.WaitForResult()); | 539 EXPECT_EQ(OK, callback.WaitForResult()); |
| 530 | 540 |
| 531 EXPECT_EQ(20u, host_resolver.num_resolve()); | 541 EXPECT_EQ(20u, host_resolver.num_resolve()); |
| 532 | 542 |
| 533 EXPECT_EQ( | 543 EXPECT_EQ( |
| 534 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 544 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
| 535 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 545 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
| 536 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 546 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
| 537 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 547 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 560 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 570 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
| 561 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 571 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
| 562 | 572 |
| 563 scoped_ptr<ProxyResolver> resolver = | 573 scoped_ptr<ProxyResolver> resolver = |
| 564 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 574 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
| 565 "global_sideffects4.js"); | 575 "global_sideffects4.js"); |
| 566 | 576 |
| 567 TestCompletionCallback callback; | 577 TestCompletionCallback callback; |
| 568 ProxyInfo proxy_info; | 578 ProxyInfo proxy_info; |
| 569 | 579 |
| 580 scoped_ptr<ProxyResolver::Request> req; |
| 570 int rv = | 581 int rv = |
| 571 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 582 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 572 callback.callback(), NULL, request_log.bound()); | 583 callback.callback(), &req, request_log.bound()); |
| 573 EXPECT_EQ(ERR_IO_PENDING, rv); | 584 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 574 EXPECT_EQ(OK, callback.WaitForResult()); | 585 EXPECT_EQ(OK, callback.WaitForResult()); |
| 575 | 586 |
| 576 EXPECT_EQ(20u, host_resolver.num_resolve()); | 587 EXPECT_EQ(20u, host_resolver.num_resolve()); |
| 577 | 588 |
| 578 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); | 589 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); |
| 579 | 590 |
| 580 // No errors. | 591 // No errors. |
| 581 EXPECT_EQ("", error_observer->GetOutput()); | 592 EXPECT_EQ("", error_observer->GetOutput()); |
| 582 | 593 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 604 | 615 |
| 605 host_resolver.rules()->ClearRules(); | 616 host_resolver.rules()->ClearRules(); |
| 606 host_resolver.GetHostCache()->clear(); | 617 host_resolver.GetHostCache()->clear(); |
| 607 | 618 |
| 608 host_resolver.rules()->AddRule("host1", "145.88.13.3"); | 619 host_resolver.rules()->AddRule("host1", "145.88.13.3"); |
| 609 host_resolver.rules()->AddRule("host2", "137.89.8.45"); | 620 host_resolver.rules()->AddRule("host2", "137.89.8.45"); |
| 610 | 621 |
| 611 TestCompletionCallback callback; | 622 TestCompletionCallback callback; |
| 612 ProxyInfo proxy_info; | 623 ProxyInfo proxy_info; |
| 613 | 624 |
| 625 scoped_ptr<ProxyResolver::Request> req; |
| 614 int rv = | 626 int rv = |
| 615 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 627 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 616 callback.callback(), NULL, request_log.bound()); | 628 callback.callback(), &req, request_log.bound()); |
| 617 EXPECT_EQ(ERR_IO_PENDING, rv); | 629 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 618 EXPECT_EQ(OK, callback.WaitForResult()); | 630 EXPECT_EQ(OK, callback.WaitForResult()); |
| 619 | 631 |
| 620 // Fetched host1 and host2 again, since the ones done during initialization | 632 // Fetched host1 and host2 again, since the ones done during initialization |
| 621 // should not have been cached. | 633 // should not have been cached. |
| 622 EXPECT_EQ(4u, host_resolver.num_resolve()); | 634 EXPECT_EQ(4u, host_resolver.num_resolve()); |
| 623 | 635 |
| 624 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", | 636 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", |
| 625 proxy_info.proxy_server().ToURI()); | 637 proxy_info.proxy_server().ToURI()); |
| 626 | 638 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 MockCachingHostResolver host_resolver; | 672 MockCachingHostResolver host_resolver; |
| 661 MockErrorObserver* error_observer = new MockErrorObserver; | 673 MockErrorObserver* error_observer = new MockErrorObserver; |
| 662 | 674 |
| 663 host_resolver.rules()->AddSimulatedFailure("*"); | 675 host_resolver.rules()->AddSimulatedFailure("*"); |
| 664 | 676 |
| 665 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 677 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 666 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 678 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 667 | 679 |
| 668 const size_t kNumRequests = 5; | 680 const size_t kNumRequests = 5; |
| 669 ProxyInfo proxy_info[kNumRequests]; | 681 ProxyInfo proxy_info[kNumRequests]; |
| 670 ProxyResolver::RequestHandle request[kNumRequests]; | 682 scoped_ptr<ProxyResolver::Request> request[kNumRequests]; |
| 671 | 683 |
| 672 for (size_t i = 0; i < kNumRequests; ++i) { | 684 for (size_t i = 0; i < kNumRequests; ++i) { |
| 673 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], | 685 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], |
| 674 base::Bind(&CrashCallback), &request[i], | 686 base::Bind(&CrashCallback), &request[i], |
| 675 BoundNetLog()); | 687 BoundNetLog()); |
| 676 EXPECT_EQ(ERR_IO_PENDING, rv); | 688 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 677 } | 689 } |
| 678 | 690 |
| 679 for (size_t i = 0; i < kNumRequests; ++i) { | 691 for (size_t i = 0; i < kNumRequests; ++i) { |
| 680 resolver->CancelRequest(request[i]); | 692 request[i].reset(); |
| 681 } | 693 } |
| 682 } | 694 } |
| 683 | 695 |
| 684 // Note the execution order for this test can vary. Since multiple | 696 // Note the execution order for this test can vary. Since multiple |
| 685 // threads are involved, the cancellation may be received a different | 697 // threads are involved, the cancellation may be received a different |
| 686 // times. | 698 // times. |
| 687 TEST_F(ProxyResolverV8TracingWrapperTest, CancelSome) { | 699 TEST_F(ProxyResolverV8TracingWrapperTest, CancelSome) { |
| 688 MockCachingHostResolver host_resolver; | 700 MockCachingHostResolver host_resolver; |
| 689 MockErrorObserver* error_observer = new MockErrorObserver; | 701 MockErrorObserver* error_observer = new MockErrorObserver; |
| 690 | 702 |
| 691 host_resolver.rules()->AddSimulatedFailure("*"); | 703 host_resolver.rules()->AddSimulatedFailure("*"); |
| 692 | 704 |
| 693 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 705 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 694 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 706 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 695 | 707 |
| 696 ProxyInfo proxy_info1; | 708 ProxyInfo proxy_info1; |
| 697 ProxyInfo proxy_info2; | 709 ProxyInfo proxy_info2; |
| 698 ProxyResolver::RequestHandle request1; | 710 scoped_ptr<ProxyResolver::Request> request1; |
| 699 ProxyResolver::RequestHandle request2; | 711 scoped_ptr<ProxyResolver::Request> request2; |
| 700 TestCompletionCallback callback; | 712 TestCompletionCallback callback; |
| 701 | 713 |
| 702 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1, | 714 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1, |
| 703 base::Bind(&CrashCallback), &request1, | 715 base::Bind(&CrashCallback), &request1, |
| 704 BoundNetLog()); | 716 BoundNetLog()); |
| 705 EXPECT_EQ(ERR_IO_PENDING, rv); | 717 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 706 | 718 |
| 707 rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2, | 719 rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2, |
| 708 callback.callback(), &request2, BoundNetLog()); | 720 callback.callback(), &request2, BoundNetLog()); |
| 709 EXPECT_EQ(ERR_IO_PENDING, rv); | 721 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 710 | 722 |
| 711 resolver->CancelRequest(request1); | 723 request1.reset(); |
| 712 | 724 |
| 713 EXPECT_EQ(OK, callback.WaitForResult()); | 725 EXPECT_EQ(OK, callback.WaitForResult()); |
| 714 } | 726 } |
| 715 | 727 |
| 716 // Cancel a request after it has finished running on the worker thread, and has | 728 // Cancel a request after it has finished running on the worker thread, and has |
| 717 // posted a task the completion task back to origin thread. | 729 // posted a task the completion task back to origin thread. |
| 718 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhilePendingCompletionTask) { | 730 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhilePendingCompletionTask) { |
| 719 MockCachingHostResolver host_resolver; | 731 MockCachingHostResolver host_resolver; |
| 720 MockErrorObserver* error_observer = new MockErrorObserver; | 732 MockErrorObserver* error_observer = new MockErrorObserver; |
| 721 | 733 |
| 722 host_resolver.rules()->AddSimulatedFailure("*"); | 734 host_resolver.rules()->AddSimulatedFailure("*"); |
| 723 | 735 |
| 724 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 736 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 725 nullptr, &host_resolver, make_scoped_ptr(error_observer), "error.js"); | 737 nullptr, &host_resolver, make_scoped_ptr(error_observer), "error.js"); |
| 726 | 738 |
| 727 ProxyInfo proxy_info1; | 739 ProxyInfo proxy_info1; |
| 728 ProxyInfo proxy_info2; | 740 ProxyInfo proxy_info2; |
| 729 ProxyResolver::RequestHandle request1; | 741 scoped_ptr<ProxyResolver::Request> request1; |
| 730 ProxyResolver::RequestHandle request2; | 742 scoped_ptr<ProxyResolver::Request> request2; |
| 731 TestCompletionCallback callback; | 743 TestCompletionCallback callback; |
| 732 | 744 |
| 733 int rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), | 745 int rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), |
| 734 &proxy_info1, base::Bind(&CrashCallback), | 746 &proxy_info1, base::Bind(&CrashCallback), |
| 735 &request1, BoundNetLog()); | 747 &request1, BoundNetLog()); |
| 736 EXPECT_EQ(ERR_IO_PENDING, rv); | 748 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 737 | 749 |
| 738 // Wait until the first request has finished running on the worker thread. | 750 // Wait until the first request has finished running on the worker thread. |
| 739 // Cancel the first request, while it has a pending completion task on | 751 // Cancel the first request, while it has a pending completion task on |
| 740 // the origin thread. | 752 // the origin thread. Reset deletes Request object which cancels the request. |
| 741 error_observer->RunOnError(base::Bind(&ProxyResolver::CancelRequest, | 753 error_observer->RunOnError( |
| 742 base::Unretained(resolver.get()), | 754 base::Bind(&scoped_ptr<ProxyResolver::Request>::reset, |
| 743 request1)); | 755 base::Unretained(&request1), nullptr)); |
| 744 | 756 |
| 745 // Start another request, to make sure it is able to complete. | 757 // Start another request, to make sure it is able to complete. |
| 746 rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), | 758 rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), |
| 747 &proxy_info2, callback.callback(), &request2, | 759 &proxy_info2, callback.callback(), &request2, |
| 748 BoundNetLog()); | 760 BoundNetLog()); |
| 749 EXPECT_EQ(ERR_IO_PENDING, rv); | 761 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 750 | 762 |
| 751 EXPECT_EQ(OK, callback.WaitForResult()); | 763 EXPECT_EQ(OK, callback.WaitForResult()); |
| 752 | 764 |
| 753 EXPECT_EQ("i-approve-this-message:42", proxy_info2.proxy_server().ToURI()); | 765 EXPECT_EQ("i-approve-this-message:42", proxy_info2.proxy_server().ToURI()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 TEST_F(ProxyResolverV8TracingWrapperTest, | 833 TEST_F(ProxyResolverV8TracingWrapperTest, |
| 822 CancelWhileOutstandingNonBlockingDns) { | 834 CancelWhileOutstandingNonBlockingDns) { |
| 823 BlockableHostResolver host_resolver; | 835 BlockableHostResolver host_resolver; |
| 824 MockErrorObserver* error_observer = new MockErrorObserver; | 836 MockErrorObserver* error_observer = new MockErrorObserver; |
| 825 | 837 |
| 826 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 838 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 827 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 839 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 828 | 840 |
| 829 ProxyInfo proxy_info1; | 841 ProxyInfo proxy_info1; |
| 830 ProxyInfo proxy_info2; | 842 ProxyInfo proxy_info2; |
| 831 ProxyResolver::RequestHandle request1; | 843 scoped_ptr<ProxyResolver::Request> request1; |
| 832 ProxyResolver::RequestHandle request2; | 844 scoped_ptr<ProxyResolver::Request> request2; |
| 833 | 845 |
| 834 int rv = resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1, | 846 int rv = resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1, |
| 835 base::Bind(&CrashCallback), &request1, | 847 base::Bind(&CrashCallback), &request1, |
| 836 BoundNetLog()); | 848 BoundNetLog()); |
| 837 | 849 |
| 838 EXPECT_EQ(ERR_IO_PENDING, rv); | 850 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 839 | 851 |
| 840 host_resolver.WaitUntilRequestIsReceived(); | 852 host_resolver.WaitUntilRequestIsReceived(); |
| 841 | 853 |
| 842 rv = resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2, | 854 rv = resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2, |
| 843 base::Bind(&CrashCallback), &request2, | 855 base::Bind(&CrashCallback), &request2, |
| 844 BoundNetLog()); | 856 BoundNetLog()); |
| 845 | 857 |
| 846 EXPECT_EQ(ERR_IO_PENDING, rv); | 858 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 847 | 859 |
| 848 host_resolver.WaitUntilRequestIsReceived(); | 860 host_resolver.WaitUntilRequestIsReceived(); |
| 849 | 861 |
| 850 resolver->CancelRequest(request1); | 862 request1.reset(); |
| 851 resolver->CancelRequest(request2); | 863 request2.reset(); |
| 852 | 864 |
| 853 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); | 865 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); |
| 854 | 866 |
| 855 // After leaving this scope, the ProxyResolver is destroyed. | 867 // After leaving this scope, the ProxyResolver is destroyed. |
| 856 // This should not cause any problems, as the outstanding work | 868 // This should not cause any problems, as the outstanding work |
| 857 // should have been cancelled. | 869 // should have been cancelled. |
| 858 } | 870 } |
| 859 | 871 |
| 860 void CancelRequestAndPause(ProxyResolver* resolver, | 872 void CancelRequestAndPause(scoped_ptr<ProxyResolver::Request>* request) { |
| 861 ProxyResolver::RequestHandle request) { | 873 request->reset(); |
| 862 resolver->CancelRequest(request); | |
| 863 | 874 |
| 864 // Sleep for a little bit. This makes it more likely for the worker | 875 // Sleep for a little bit. This makes it more likely for the worker |
| 865 // thread to have returned from its call, and serves as a regression | 876 // thread to have returned from its call, and serves as a regression |
| 866 // test for http://crbug.com/173373. | 877 // test for http://crbug.com/173373. |
| 867 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); | 878 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); |
| 868 } | 879 } |
| 869 | 880 |
| 870 // In non-blocking mode, the worker thread actually does block for | 881 // In non-blocking mode, the worker thread actually does block for |
| 871 // a short time to see if the result is in the DNS cache. Test | 882 // a short time to see if the result is in the DNS cache. Test |
| 872 // cancellation while the worker thread is waiting on this event. | 883 // cancellation while the worker thread is waiting on this event. |
| 873 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns) { | 884 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns) { |
| 874 BlockableHostResolver host_resolver; | 885 BlockableHostResolver host_resolver; |
| 875 MockErrorObserver* error_observer = new MockErrorObserver; | 886 MockErrorObserver* error_observer = new MockErrorObserver; |
| 876 | 887 |
| 877 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 888 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 878 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 889 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 879 | 890 |
| 880 ProxyInfo proxy_info; | 891 ProxyInfo proxy_info; |
| 881 ProxyResolver::RequestHandle request; | 892 scoped_ptr<ProxyResolver::Request> request; |
| 882 | 893 |
| 883 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 894 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 884 base::Bind(&CrashCallback), &request, | 895 base::Bind(&CrashCallback), &request, |
| 885 BoundNetLog()); | 896 BoundNetLog()); |
| 886 | 897 |
| 887 EXPECT_EQ(ERR_IO_PENDING, rv); | 898 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 888 | 899 |
| 889 host_resolver.SetAction( | 900 host_resolver.SetAction(base::Bind(CancelRequestAndPause, &request)); |
| 890 base::Bind(CancelRequestAndPause, resolver.get(), request)); | |
| 891 | 901 |
| 892 host_resolver.WaitUntilRequestIsReceived(); | 902 host_resolver.WaitUntilRequestIsReceived(); |
| 893 } | 903 } |
| 894 | 904 |
| 895 // Cancel the request while there is a pending DNS request, however before | 905 // Cancel the request while there is a pending DNS request, however before |
| 896 // the request is sent to the host resolver. | 906 // the request is sent to the host resolver. |
| 897 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns2) { | 907 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns2) { |
| 898 MockCachingHostResolver host_resolver; | 908 MockCachingHostResolver host_resolver; |
| 899 MockErrorObserver* error_observer = new MockErrorObserver; | 909 MockErrorObserver* error_observer = new MockErrorObserver; |
| 900 | 910 |
| 901 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 911 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 902 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 912 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
| 903 | 913 |
| 904 ProxyInfo proxy_info; | 914 ProxyInfo proxy_info; |
| 905 ProxyResolver::RequestHandle request; | 915 scoped_ptr<ProxyResolver::Request> request; |
| 906 | 916 |
| 907 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 917 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
| 908 base::Bind(&CrashCallback), &request, | 918 base::Bind(&CrashCallback), &request, |
| 909 BoundNetLog()); | 919 BoundNetLog()); |
| 910 | 920 |
| 911 EXPECT_EQ(ERR_IO_PENDING, rv); | 921 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 912 | 922 |
| 913 // Wait a bit, so the DNS task has hopefully been posted. The test will | 923 // Wait a bit, so the DNS task has hopefully been posted. The test will |
| 914 // work whatever the delay is here, but it is most useful if the delay | 924 // work whatever the delay is here, but it is most useful if the delay |
| 915 // is large enough to allow a task to be posted back. | 925 // is large enough to allow a task to be posted back. |
| 916 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); | 926 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
| 917 resolver->CancelRequest(request); | 927 request.reset(); |
| 918 | 928 |
| 919 EXPECT_EQ(0u, host_resolver.num_resolve()); | 929 EXPECT_EQ(0u, host_resolver.num_resolve()); |
| 920 } | 930 } |
| 921 | 931 |
| 922 TEST_F(ProxyResolverV8TracingWrapperTest, | 932 TEST_F(ProxyResolverV8TracingWrapperTest, |
| 923 CancelCreateResolverWhileOutstandingBlockingDns) { | 933 CancelCreateResolverWhileOutstandingBlockingDns) { |
| 924 BlockableHostResolver host_resolver; | 934 BlockableHostResolver host_resolver; |
| 925 MockErrorObserver* error_observer = new MockErrorObserver; | 935 MockErrorObserver* error_observer = new MockErrorObserver; |
| 926 | 936 |
| 927 ProxyResolverFactoryV8TracingWrapper factory( | 937 ProxyResolverFactoryV8TracingWrapper factory( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 | 1004 |
| 995 host_resolver.rules()->AddRule("host1", "182.111.0.222"); | 1005 host_resolver.rules()->AddRule("host1", "182.111.0.222"); |
| 996 host_resolver.rules()->AddRule("host2", "111.33.44.55"); | 1006 host_resolver.rules()->AddRule("host2", "111.33.44.55"); |
| 997 | 1007 |
| 998 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 1008 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
| 999 &log, &host_resolver, make_scoped_ptr(error_observer), "terminate.js"); | 1009 &log, &host_resolver, make_scoped_ptr(error_observer), "terminate.js"); |
| 1000 | 1010 |
| 1001 TestCompletionCallback callback; | 1011 TestCompletionCallback callback; |
| 1002 ProxyInfo proxy_info; | 1012 ProxyInfo proxy_info; |
| 1003 | 1013 |
| 1014 scoped_ptr<ProxyResolver::Request> req; |
| 1004 int rv = | 1015 int rv = |
| 1005 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, | 1016 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, |
| 1006 callback.callback(), NULL, request_log.bound()); | 1017 callback.callback(), &req, request_log.bound()); |
| 1007 | 1018 |
| 1008 EXPECT_EQ(ERR_IO_PENDING, rv); | 1019 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1009 EXPECT_EQ(OK, callback.WaitForResult()); | 1020 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1010 | 1021 |
| 1011 // The test does 2 DNS resolutions. | 1022 // The test does 2 DNS resolutions. |
| 1012 EXPECT_EQ(2u, host_resolver.num_resolve()); | 1023 EXPECT_EQ(2u, host_resolver.num_resolve()); |
| 1013 | 1024 |
| 1014 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); | 1025 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); |
| 1015 | 1026 |
| 1016 // No errors. | 1027 // No errors. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 | 1085 |
| 1075 ProxyResolver* resolver[] = { | 1086 ProxyResolver* resolver[] = { |
| 1076 resolver0.get(), resolver1.get(), resolver2.get(), resolver3.get(), | 1087 resolver0.get(), resolver1.get(), resolver2.get(), resolver3.get(), |
| 1077 }; | 1088 }; |
| 1078 | 1089 |
| 1079 const size_t kNumResolvers = arraysize(resolver); | 1090 const size_t kNumResolvers = arraysize(resolver); |
| 1080 const size_t kNumIterations = 20; | 1091 const size_t kNumIterations = 20; |
| 1081 const size_t kNumResults = kNumResolvers * kNumIterations; | 1092 const size_t kNumResults = kNumResolvers * kNumIterations; |
| 1082 TestCompletionCallback callback[kNumResults]; | 1093 TestCompletionCallback callback[kNumResults]; |
| 1083 ProxyInfo proxy_info[kNumResults]; | 1094 ProxyInfo proxy_info[kNumResults]; |
| 1095 scoped_ptr<ProxyResolver::Request> request[kNumResults]; |
| 1084 | 1096 |
| 1085 for (size_t i = 0; i < kNumResults; ++i) { | 1097 for (size_t i = 0; i < kNumResults; ++i) { |
| 1086 size_t resolver_i = i % kNumResolvers; | 1098 size_t resolver_i = i % kNumResolvers; |
| 1087 int rv = resolver[resolver_i]->GetProxyForURL( | 1099 int rv = resolver[resolver_i]->GetProxyForURL( |
| 1088 GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL, | 1100 GURL("http://foo/"), &proxy_info[i], callback[i].callback(), |
| 1089 BoundNetLog()); | 1101 &request[i], BoundNetLog()); |
| 1090 EXPECT_EQ(ERR_IO_PENDING, rv); | 1102 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1091 } | 1103 } |
| 1092 | 1104 |
| 1093 // ------------------------ | 1105 // ------------------------ |
| 1094 // Verify all of the results. | 1106 // Verify all of the results. |
| 1095 // ------------------------ | 1107 // ------------------------ |
| 1096 | 1108 |
| 1097 const char* kExpectedForDnsJs = | 1109 const char* kExpectedForDnsJs = |
| 1098 "122.133.144.155-" // myIpAddress() | 1110 "122.133.144.155-" // myIpAddress() |
| 1099 "null-" // dnsResolve('') | 1111 "null-" // dnsResolve('') |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1125 proxy_uri.substr(0, proxy_uri.find(':') + 1)); | 1137 proxy_uri.substr(0, proxy_uri.find(':') + 1)); |
| 1126 } else { | 1138 } else { |
| 1127 NOTREACHED(); | 1139 NOTREACHED(); |
| 1128 } | 1140 } |
| 1129 } | 1141 } |
| 1130 } | 1142 } |
| 1131 | 1143 |
| 1132 } // namespace | 1144 } // namespace |
| 1133 | 1145 |
| 1134 } // namespace net | 1146 } // namespace net |
| OLD | NEW |