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