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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
23 #include "net/dns/host_cache.h" | 23 #include "net/dns/host_cache.h" |
24 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
25 #include "net/log/net_log.h" | 25 #include "net/log/net_log.h" |
26 #include "net/log/test_net_log.h" | 26 #include "net/log/test_net_log.h" |
27 #include "net/log/test_net_log_entry.h" | 27 #include "net/log/test_net_log_entry.h" |
28 #include "net/log/test_net_log_util.h" | 28 #include "net/log/test_net_log_util.h" |
29 #include "net/proxy/proxy_info.h" | 29 #include "net/proxy/proxy_info.h" |
30 #include "net/proxy/proxy_resolver_error_observer.h" | 30 #include "net/proxy/proxy_resolver_error_observer.h" |
31 #include "net/test/event_waiter.h" | 31 #include "net/test/event_waiter.h" |
| 32 #include "net/test/gtest_util.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
34 | 36 |
| 37 using net::test::IsError; |
| 38 using net::test::IsOk; |
| 39 |
35 namespace net { | 40 namespace net { |
36 | 41 |
37 namespace { | 42 namespace { |
38 | 43 |
39 class ProxyResolverV8TracingWrapperTest : public testing::Test { | 44 class ProxyResolverV8TracingWrapperTest : public testing::Test { |
40 public: | 45 public: |
41 void TearDown() override { | 46 void TearDown() override { |
42 // Drain any pending messages, which may be left over from cancellation. | 47 // Drain any pending messages, which may be left over from cancellation. |
43 // This way they get reliably run as part of the current test, rather than | 48 // This way they get reliably run as part of the current test, rather than |
44 // spilling into the next test's execution. | 49 // spilling into the next test's execution. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 std::unique_ptr<ProxyResolverErrorObserver> error_observer, | 81 std::unique_ptr<ProxyResolverErrorObserver> error_observer, |
77 const char* filename) { | 82 const char* filename) { |
78 std::unique_ptr<ProxyResolver> resolver; | 83 std::unique_ptr<ProxyResolver> resolver; |
79 ProxyResolverFactoryV8TracingWrapper factory( | 84 ProxyResolverFactoryV8TracingWrapper factory( |
80 host_resolver, net_log, | 85 host_resolver, net_log, |
81 base::Bind(&ReturnErrorObserver, base::Passed(&error_observer))); | 86 base::Bind(&ReturnErrorObserver, base::Passed(&error_observer))); |
82 TestCompletionCallback callback; | 87 TestCompletionCallback callback; |
83 std::unique_ptr<ProxyResolverFactory::Request> request; | 88 std::unique_ptr<ProxyResolverFactory::Request> request; |
84 int rv = factory.CreateProxyResolver(LoadScriptData(filename), &resolver, | 89 int rv = factory.CreateProxyResolver(LoadScriptData(filename), &resolver, |
85 callback.callback(), &request); | 90 callback.callback(), &request); |
86 EXPECT_EQ(ERR_IO_PENDING, rv); | 91 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
87 EXPECT_EQ(OK, callback.WaitForResult()); | 92 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
88 EXPECT_TRUE(resolver); | 93 EXPECT_TRUE(resolver); |
89 return resolver; | 94 return resolver; |
90 } | 95 } |
91 | 96 |
92 class MockErrorObserver : public ProxyResolverErrorObserver { | 97 class MockErrorObserver : public ProxyResolverErrorObserver { |
93 public: | 98 public: |
94 void OnPACScriptError(int line_number, const base::string16& error) override { | 99 void OnPACScriptError(int line_number, const base::string16& error) override { |
95 output += base::StringPrintf("Error: line %d: %s\n", line_number, | 100 output += base::StringPrintf("Error: line %d: %s\n", line_number, |
96 base::UTF16ToASCII(error).c_str()); | 101 base::UTF16ToASCII(error).c_str()); |
97 waiter_.NotifyEvent(EVENT_ERROR); | 102 waiter_.NotifyEvent(EVENT_ERROR); |
(...skipping 29 matching lines...) Expand all Loading... |
127 std::unique_ptr<ProxyResolver> resolver = CreateResolver( | 132 std::unique_ptr<ProxyResolver> resolver = CreateResolver( |
128 &log, &host_resolver, base::WrapUnique(error_observer), "simple.js"); | 133 &log, &host_resolver, base::WrapUnique(error_observer), "simple.js"); |
129 | 134 |
130 TestCompletionCallback callback; | 135 TestCompletionCallback callback; |
131 ProxyInfo proxy_info; | 136 ProxyInfo proxy_info; |
132 | 137 |
133 int rv = | 138 int rv = |
134 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 139 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
135 callback.callback(), NULL, request_log.bound()); | 140 callback.callback(), NULL, request_log.bound()); |
136 | 141 |
137 EXPECT_EQ(ERR_IO_PENDING, rv); | 142 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
138 EXPECT_EQ(OK, callback.WaitForResult()); | 143 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
139 | 144 |
140 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); | 145 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); |
141 | 146 |
142 EXPECT_EQ(0u, host_resolver.num_resolve()); | 147 EXPECT_EQ(0u, host_resolver.num_resolve()); |
143 | 148 |
144 // There were no errors. | 149 // There were no errors. |
145 EXPECT_EQ("", error_observer->GetOutput()); | 150 EXPECT_EQ("", error_observer->GetOutput()); |
146 | 151 |
147 // Check the NetLogs -- nothing was logged. | 152 // Check the NetLogs -- nothing was logged. |
148 EXPECT_EQ(0u, log.GetSize()); | 153 EXPECT_EQ(0u, log.GetSize()); |
149 EXPECT_EQ(0u, request_log.GetSize()); | 154 EXPECT_EQ(0u, request_log.GetSize()); |
150 } | 155 } |
151 | 156 |
152 TEST_F(ProxyResolverV8TracingWrapperTest, JavascriptError) { | 157 TEST_F(ProxyResolverV8TracingWrapperTest, JavascriptError) { |
153 TestNetLog log; | 158 TestNetLog log; |
154 BoundTestNetLog request_log; | 159 BoundTestNetLog request_log; |
155 MockCachingHostResolver host_resolver; | 160 MockCachingHostResolver host_resolver; |
156 MockErrorObserver* error_observer = new MockErrorObserver; | 161 MockErrorObserver* error_observer = new MockErrorObserver; |
157 | 162 |
158 std::unique_ptr<ProxyResolver> resolver = CreateResolver( | 163 std::unique_ptr<ProxyResolver> resolver = CreateResolver( |
159 &log, &host_resolver, base::WrapUnique(error_observer), "error.js"); | 164 &log, &host_resolver, base::WrapUnique(error_observer), "error.js"); |
160 | 165 |
161 TestCompletionCallback callback; | 166 TestCompletionCallback callback; |
162 ProxyInfo proxy_info; | 167 ProxyInfo proxy_info; |
163 | 168 |
164 int rv = | 169 int rv = |
165 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, | 170 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, |
166 callback.callback(), NULL, request_log.bound()); | 171 callback.callback(), NULL, request_log.bound()); |
167 | 172 |
168 EXPECT_EQ(ERR_IO_PENDING, rv); | 173 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
169 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 174 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_PAC_SCRIPT_FAILED)); |
170 | 175 |
171 EXPECT_EQ(0u, host_resolver.num_resolve()); | 176 EXPECT_EQ(0u, host_resolver.num_resolve()); |
172 | 177 |
173 EXPECT_EQ( | 178 EXPECT_EQ( |
174 "Error: line 5: Uncaught TypeError: Cannot read property 'split' " | 179 "Error: line 5: Uncaught TypeError: Cannot read property 'split' " |
175 "of null\n", | 180 "of null\n", |
176 error_observer->GetOutput()); | 181 error_observer->GetOutput()); |
177 | 182 |
178 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they | 183 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they |
179 // were output to both the global log, and per-request log. | 184 // were output to both the global log, and per-request log. |
(...skipping 27 matching lines...) Expand all Loading... |
207 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), | 212 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), |
208 "too_many_alerts.js"); | 213 "too_many_alerts.js"); |
209 | 214 |
210 TestCompletionCallback callback; | 215 TestCompletionCallback callback; |
211 ProxyInfo proxy_info; | 216 ProxyInfo proxy_info; |
212 | 217 |
213 int rv = | 218 int rv = |
214 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 219 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
215 callback.callback(), NULL, request_log.bound()); | 220 callback.callback(), NULL, request_log.bound()); |
216 | 221 |
217 EXPECT_EQ(ERR_IO_PENDING, rv); | 222 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
218 EXPECT_EQ(OK, callback.WaitForResult()); | 223 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
219 | 224 |
220 // Iteration1 does a DNS resolve | 225 // Iteration1 does a DNS resolve |
221 // Iteration2 exceeds the alert buffer | 226 // Iteration2 exceeds the alert buffer |
222 // Iteration3 runs in blocking mode and completes | 227 // Iteration3 runs in blocking mode and completes |
223 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 228 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
224 | 229 |
225 EXPECT_EQ(1u, host_resolver.num_resolve()); | 230 EXPECT_EQ(1u, host_resolver.num_resolve()); |
226 | 231 |
227 // No errors. | 232 // No errors. |
228 EXPECT_EQ("", error_observer->GetOutput()); | 233 EXPECT_EQ("", error_observer->GetOutput()); |
(...skipping 26 matching lines...) Expand all Loading... |
255 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), | 260 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), |
256 "too_many_empty_alerts.js"); | 261 "too_many_empty_alerts.js"); |
257 | 262 |
258 TestCompletionCallback callback; | 263 TestCompletionCallback callback; |
259 ProxyInfo proxy_info; | 264 ProxyInfo proxy_info; |
260 | 265 |
261 int rv = | 266 int rv = |
262 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 267 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
263 callback.callback(), NULL, request_log.bound()); | 268 callback.callback(), NULL, request_log.bound()); |
264 | 269 |
265 EXPECT_EQ(ERR_IO_PENDING, rv); | 270 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
266 EXPECT_EQ(OK, callback.WaitForResult()); | 271 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
267 | 272 |
268 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 273 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
269 | 274 |
270 EXPECT_EQ(1u, host_resolver.num_resolve()); | 275 EXPECT_EQ(1u, host_resolver.num_resolve()); |
271 | 276 |
272 // No errors. | 277 // No errors. |
273 EXPECT_EQ("", error_observer->GetOutput()); | 278 EXPECT_EQ("", error_observer->GetOutput()); |
274 | 279 |
275 // Check the NetLogs -- the script generated 50 alerts, which were mirrored | 280 // Check the NetLogs -- the script generated 50 alerts, which were mirrored |
276 // to both the global and per-request logs. | 281 // to both the global and per-request logs. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 std::unique_ptr<ProxyResolver> resolver = CreateResolver( | 317 std::unique_ptr<ProxyResolver> resolver = CreateResolver( |
313 &log, &host_resolver, base::WrapUnique(error_observer), "dns.js"); | 318 &log, &host_resolver, base::WrapUnique(error_observer), "dns.js"); |
314 | 319 |
315 TestCompletionCallback callback; | 320 TestCompletionCallback callback; |
316 ProxyInfo proxy_info; | 321 ProxyInfo proxy_info; |
317 | 322 |
318 int rv = | 323 int rv = |
319 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 324 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
320 callback.callback(), NULL, request_log.bound()); | 325 callback.callback(), NULL, request_log.bound()); |
321 | 326 |
322 EXPECT_EQ(ERR_IO_PENDING, rv); | 327 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
323 EXPECT_EQ(OK, callback.WaitForResult()); | 328 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
324 | 329 |
325 // The test does 13 DNS resolution, however only 7 of them are unique. | 330 // The test does 13 DNS resolution, however only 7 of them are unique. |
326 EXPECT_EQ(7u, host_resolver.num_resolve()); | 331 EXPECT_EQ(7u, host_resolver.num_resolve()); |
327 | 332 |
328 const char* kExpectedResult = | 333 const char* kExpectedResult = |
329 "122.133.144.155-" // myIpAddress() | 334 "122.133.144.155-" // myIpAddress() |
330 "null-" // dnsResolve('') | 335 "null-" // dnsResolve('') |
331 "__1_192.168.1.1-" // dnsResolveEx('host1') | 336 "__1_192.168.1.1-" // dnsResolveEx('host1') |
332 "null-" // dnsResolve('host2') | 337 "null-" // dnsResolve('host2') |
333 "166.155.144.33-" // dnsResolve('host3') | 338 "166.155.144.33-" // dnsResolve('host3') |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 &log, &host_resolver, base::WrapUnique(error_observer), "simple_dns.js"); | 382 &log, &host_resolver, base::WrapUnique(error_observer), "simple_dns.js"); |
378 | 383 |
379 TestCompletionCallback callback1; | 384 TestCompletionCallback callback1; |
380 TestCompletionCallback callback2; | 385 TestCompletionCallback callback2; |
381 ProxyInfo proxy_info; | 386 ProxyInfo proxy_info; |
382 | 387 |
383 int rv = | 388 int rv = |
384 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, | 389 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, |
385 callback1.callback(), NULL, request_log.bound()); | 390 callback1.callback(), NULL, request_log.bound()); |
386 | 391 |
387 EXPECT_EQ(ERR_IO_PENDING, rv); | 392 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
388 EXPECT_EQ(OK, callback1.WaitForResult()); | 393 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
389 | 394 |
390 // The test does 2 DNS resolutions. | 395 // The test does 2 DNS resolutions. |
391 EXPECT_EQ(2u, host_resolver.num_resolve()); | 396 EXPECT_EQ(2u, host_resolver.num_resolve()); |
392 | 397 |
393 // The first request took 2 restarts, hence on g_iteration=3. | 398 // The first request took 2 restarts, hence on g_iteration=3. |
394 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); | 399 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); |
395 | 400 |
396 rv = | 401 rv = |
397 resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info, | 402 resolver->GetProxyForURL(GURL("http://foopy/req2"), &proxy_info, |
398 callback2.callback(), NULL, request_log.bound()); | 403 callback2.callback(), NULL, request_log.bound()); |
399 | 404 |
400 EXPECT_EQ(ERR_IO_PENDING, rv); | 405 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
401 EXPECT_EQ(OK, callback2.WaitForResult()); | 406 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
402 | 407 |
403 EXPECT_EQ(4u, host_resolver.num_resolve()); | 408 EXPECT_EQ(4u, host_resolver.num_resolve()); |
404 | 409 |
405 // 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. |
406 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()); |
407 | 412 |
408 // No errors. | 413 // No errors. |
409 EXPECT_EQ("", error_observer->GetOutput()); | 414 EXPECT_EQ("", error_observer->GetOutput()); |
410 | 415 |
411 EXPECT_EQ(0u, log.GetSize()); | 416 EXPECT_EQ(0u, log.GetSize()); |
(...skipping 16 matching lines...) Expand all Loading... |
428 std::unique_ptr<ProxyResolver> resolver = | 433 std::unique_ptr<ProxyResolver> resolver = |
429 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), | 434 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), |
430 "global_sideffects1.js"); | 435 "global_sideffects1.js"); |
431 | 436 |
432 TestCompletionCallback callback; | 437 TestCompletionCallback callback; |
433 ProxyInfo proxy_info; | 438 ProxyInfo proxy_info; |
434 | 439 |
435 int rv = | 440 int rv = |
436 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 441 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
437 callback.callback(), NULL, request_log.bound()); | 442 callback.callback(), NULL, request_log.bound()); |
438 EXPECT_EQ(ERR_IO_PENDING, rv); | 443 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
439 EXPECT_EQ(OK, callback.WaitForResult()); | 444 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
440 | 445 |
441 // The script itself only does 2 DNS resolves per execution, however it | 446 // The script itself only does 2 DNS resolves per execution, however it |
442 // constructs the hostname using a global counter which changes on each | 447 // constructs the hostname using a global counter which changes on each |
443 // invocation. | 448 // invocation. |
444 EXPECT_EQ(3u, host_resolver.num_resolve()); | 449 EXPECT_EQ(3u, host_resolver.num_resolve()); |
445 | 450 |
446 EXPECT_EQ("166.155.144.11-133.199.111.4:100", | 451 EXPECT_EQ("166.155.144.11-133.199.111.4:100", |
447 proxy_info.proxy_server().ToURI()); | 452 proxy_info.proxy_server().ToURI()); |
448 | 453 |
449 // No errors. | 454 // No errors. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 std::unique_ptr<ProxyResolver> resolver = | 487 std::unique_ptr<ProxyResolver> resolver = |
483 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), | 488 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), |
484 "global_sideffects2.js"); | 489 "global_sideffects2.js"); |
485 | 490 |
486 TestCompletionCallback callback; | 491 TestCompletionCallback callback; |
487 ProxyInfo proxy_info; | 492 ProxyInfo proxy_info; |
488 | 493 |
489 int rv = | 494 int rv = |
490 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 495 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
491 callback.callback(), NULL, request_log.bound()); | 496 callback.callback(), NULL, request_log.bound()); |
492 EXPECT_EQ(ERR_IO_PENDING, rv); | 497 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
493 EXPECT_EQ(OK, callback.WaitForResult()); | 498 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
494 | 499 |
495 EXPECT_EQ(3u, host_resolver.num_resolve()); | 500 EXPECT_EQ(3u, host_resolver.num_resolve()); |
496 | 501 |
497 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); | 502 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); |
498 | 503 |
499 // No errors. | 504 // No errors. |
500 EXPECT_EQ("", error_observer->GetOutput()); | 505 EXPECT_EQ("", error_observer->GetOutput()); |
501 | 506 |
502 // Check the NetLogs -- nothing was logged. | 507 // Check the NetLogs -- nothing was logged. |
503 EXPECT_EQ(0u, log.GetSize()); | 508 EXPECT_EQ(0u, log.GetSize()); |
(...skipping 16 matching lines...) Expand all Loading... |
520 std::unique_ptr<ProxyResolver> resolver = | 525 std::unique_ptr<ProxyResolver> resolver = |
521 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), | 526 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), |
522 "global_sideffects3.js"); | 527 "global_sideffects3.js"); |
523 | 528 |
524 TestCompletionCallback callback; | 529 TestCompletionCallback callback; |
525 ProxyInfo proxy_info; | 530 ProxyInfo proxy_info; |
526 | 531 |
527 int rv = | 532 int rv = |
528 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 533 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
529 callback.callback(), NULL, request_log.bound()); | 534 callback.callback(), NULL, request_log.bound()); |
530 EXPECT_EQ(ERR_IO_PENDING, rv); | 535 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
531 EXPECT_EQ(OK, callback.WaitForResult()); | 536 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
532 | 537 |
533 EXPECT_EQ(20u, host_resolver.num_resolve()); | 538 EXPECT_EQ(20u, host_resolver.num_resolve()); |
534 | 539 |
535 EXPECT_EQ( | 540 EXPECT_EQ( |
536 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 541 "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-" | 542 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
538 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 543 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
539 "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-" |
540 "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-" |
541 "null:21", | 546 "null:21", |
(...skipping 23 matching lines...) Expand all Loading... |
565 std::unique_ptr<ProxyResolver> resolver = | 570 std::unique_ptr<ProxyResolver> resolver = |
566 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), | 571 CreateResolver(&log, &host_resolver, base::WrapUnique(error_observer), |
567 "global_sideffects4.js"); | 572 "global_sideffects4.js"); |
568 | 573 |
569 TestCompletionCallback callback; | 574 TestCompletionCallback callback; |
570 ProxyInfo proxy_info; | 575 ProxyInfo proxy_info; |
571 | 576 |
572 int rv = | 577 int rv = |
573 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 578 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
574 callback.callback(), NULL, request_log.bound()); | 579 callback.callback(), NULL, request_log.bound()); |
575 EXPECT_EQ(ERR_IO_PENDING, rv); | 580 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
576 EXPECT_EQ(OK, callback.WaitForResult()); | 581 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
577 | 582 |
578 EXPECT_EQ(20u, host_resolver.num_resolve()); | 583 EXPECT_EQ(20u, host_resolver.num_resolve()); |
579 | 584 |
580 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); | 585 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); |
581 | 586 |
582 // No errors. | 587 // No errors. |
583 EXPECT_EQ("", error_observer->GetOutput()); | 588 EXPECT_EQ("", error_observer->GetOutput()); |
584 | 589 |
585 // Check the NetLogs -- 1 alert was logged. | 590 // Check the NetLogs -- 1 alert was logged. |
586 EXPECT_EQ(1u, log.GetSize()); | 591 EXPECT_EQ(1u, log.GetSize()); |
(...skipping 22 matching lines...) Expand all Loading... |
609 | 614 |
610 host_resolver.rules()->AddRule("host1", "145.88.13.3"); | 615 host_resolver.rules()->AddRule("host1", "145.88.13.3"); |
611 host_resolver.rules()->AddRule("host2", "137.89.8.45"); | 616 host_resolver.rules()->AddRule("host2", "137.89.8.45"); |
612 | 617 |
613 TestCompletionCallback callback; | 618 TestCompletionCallback callback; |
614 ProxyInfo proxy_info; | 619 ProxyInfo proxy_info; |
615 | 620 |
616 int rv = | 621 int rv = |
617 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 622 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
618 callback.callback(), NULL, request_log.bound()); | 623 callback.callback(), NULL, request_log.bound()); |
619 EXPECT_EQ(ERR_IO_PENDING, rv); | 624 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
620 EXPECT_EQ(OK, callback.WaitForResult()); | 625 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
621 | 626 |
622 // Fetched host1 and host2 again, since the ones done during initialization | 627 // Fetched host1 and host2 again, since the ones done during initialization |
623 // should not have been cached. | 628 // should not have been cached. |
624 EXPECT_EQ(4u, host_resolver.num_resolve()); | 629 EXPECT_EQ(4u, host_resolver.num_resolve()); |
625 | 630 |
626 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", | 631 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", |
627 proxy_info.proxy_server().ToURI()); | 632 proxy_info.proxy_server().ToURI()); |
628 | 633 |
629 // Check the NetLogs -- the script generated 2 alerts during initialization. | 634 // Check the NetLogs -- the script generated 2 alerts during initialization. |
630 EXPECT_EQ(0u, request_log.GetSize()); | 635 EXPECT_EQ(0u, request_log.GetSize()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); | 673 nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); |
669 | 674 |
670 const size_t kNumRequests = 5; | 675 const size_t kNumRequests = 5; |
671 ProxyInfo proxy_info[kNumRequests]; | 676 ProxyInfo proxy_info[kNumRequests]; |
672 ProxyResolver::RequestHandle request[kNumRequests]; | 677 ProxyResolver::RequestHandle request[kNumRequests]; |
673 | 678 |
674 for (size_t i = 0; i < kNumRequests; ++i) { | 679 for (size_t i = 0; i < kNumRequests; ++i) { |
675 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], | 680 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], |
676 base::Bind(&CrashCallback), &request[i], | 681 base::Bind(&CrashCallback), &request[i], |
677 BoundNetLog()); | 682 BoundNetLog()); |
678 EXPECT_EQ(ERR_IO_PENDING, rv); | 683 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
679 } | 684 } |
680 | 685 |
681 for (size_t i = 0; i < kNumRequests; ++i) { | 686 for (size_t i = 0; i < kNumRequests; ++i) { |
682 resolver->CancelRequest(request[i]); | 687 resolver->CancelRequest(request[i]); |
683 } | 688 } |
684 } | 689 } |
685 | 690 |
686 // Note the execution order for this test can vary. Since multiple | 691 // Note the execution order for this test can vary. Since multiple |
687 // threads are involved, the cancellation may be received a different | 692 // threads are involved, the cancellation may be received a different |
688 // times. | 693 // times. |
689 TEST_F(ProxyResolverV8TracingWrapperTest, CancelSome) { | 694 TEST_F(ProxyResolverV8TracingWrapperTest, CancelSome) { |
690 MockCachingHostResolver host_resolver; | 695 MockCachingHostResolver host_resolver; |
691 MockErrorObserver* error_observer = new MockErrorObserver; | 696 MockErrorObserver* error_observer = new MockErrorObserver; |
692 | 697 |
693 host_resolver.rules()->AddSimulatedFailure("*"); | 698 host_resolver.rules()->AddSimulatedFailure("*"); |
694 | 699 |
695 std::unique_ptr<ProxyResolver> resolver = CreateResolver( | 700 std::unique_ptr<ProxyResolver> resolver = CreateResolver( |
696 nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); | 701 nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); |
697 | 702 |
698 ProxyInfo proxy_info1; | 703 ProxyInfo proxy_info1; |
699 ProxyInfo proxy_info2; | 704 ProxyInfo proxy_info2; |
700 ProxyResolver::RequestHandle request1; | 705 ProxyResolver::RequestHandle request1; |
701 ProxyResolver::RequestHandle request2; | 706 ProxyResolver::RequestHandle request2; |
702 TestCompletionCallback callback; | 707 TestCompletionCallback callback; |
703 | 708 |
704 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1, | 709 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info1, |
705 base::Bind(&CrashCallback), &request1, | 710 base::Bind(&CrashCallback), &request1, |
706 BoundNetLog()); | 711 BoundNetLog()); |
707 EXPECT_EQ(ERR_IO_PENDING, rv); | 712 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
708 | 713 |
709 rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2, | 714 rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info2, |
710 callback.callback(), &request2, BoundNetLog()); | 715 callback.callback(), &request2, BoundNetLog()); |
711 EXPECT_EQ(ERR_IO_PENDING, rv); | 716 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
712 | 717 |
713 resolver->CancelRequest(request1); | 718 resolver->CancelRequest(request1); |
714 | 719 |
715 EXPECT_EQ(OK, callback.WaitForResult()); | 720 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
716 } | 721 } |
717 | 722 |
718 // Cancel a request after it has finished running on the worker thread, and has | 723 // Cancel a request after it has finished running on the worker thread, and has |
719 // posted a task the completion task back to origin thread. | 724 // posted a task the completion task back to origin thread. |
720 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhilePendingCompletionTask) { | 725 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhilePendingCompletionTask) { |
721 MockCachingHostResolver host_resolver; | 726 MockCachingHostResolver host_resolver; |
722 MockErrorObserver* error_observer = new MockErrorObserver; | 727 MockErrorObserver* error_observer = new MockErrorObserver; |
723 | 728 |
724 host_resolver.rules()->AddSimulatedFailure("*"); | 729 host_resolver.rules()->AddSimulatedFailure("*"); |
725 | 730 |
726 std::unique_ptr<ProxyResolver> resolver = CreateResolver( | 731 std::unique_ptr<ProxyResolver> resolver = CreateResolver( |
727 nullptr, &host_resolver, base::WrapUnique(error_observer), "error.js"); | 732 nullptr, &host_resolver, base::WrapUnique(error_observer), "error.js"); |
728 | 733 |
729 ProxyInfo proxy_info1; | 734 ProxyInfo proxy_info1; |
730 ProxyInfo proxy_info2; | 735 ProxyInfo proxy_info2; |
731 ProxyResolver::RequestHandle request1; | 736 ProxyResolver::RequestHandle request1; |
732 ProxyResolver::RequestHandle request2; | 737 ProxyResolver::RequestHandle request2; |
733 TestCompletionCallback callback; | 738 TestCompletionCallback callback; |
734 | 739 |
735 int rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), | 740 int rv = resolver->GetProxyForURL(GURL("http://throw-an-error/"), |
736 &proxy_info1, base::Bind(&CrashCallback), | 741 &proxy_info1, base::Bind(&CrashCallback), |
737 &request1, BoundNetLog()); | 742 &request1, BoundNetLog()); |
738 EXPECT_EQ(ERR_IO_PENDING, rv); | 743 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
739 | 744 |
740 // Wait until the first request has finished running on the worker thread. | 745 // Wait until the first request has finished running on the worker thread. |
741 // Cancel the first request, while it has a pending completion task on | 746 // Cancel the first request, while it has a pending completion task on |
742 // the origin thread. | 747 // the origin thread. |
743 error_observer->RunOnError(base::Bind(&ProxyResolver::CancelRequest, | 748 error_observer->RunOnError(base::Bind(&ProxyResolver::CancelRequest, |
744 base::Unretained(resolver.get()), | 749 base::Unretained(resolver.get()), |
745 request1)); | 750 request1)); |
746 | 751 |
747 // Start another request, to make sure it is able to complete. | 752 // Start another request, to make sure it is able to complete. |
748 rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), | 753 rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), |
749 &proxy_info2, callback.callback(), &request2, | 754 &proxy_info2, callback.callback(), &request2, |
750 BoundNetLog()); | 755 BoundNetLog()); |
751 EXPECT_EQ(ERR_IO_PENDING, rv); | 756 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
752 | 757 |
753 EXPECT_EQ(OK, callback.WaitForResult()); | 758 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
754 | 759 |
755 EXPECT_EQ("i-approve-this-message:42", proxy_info2.proxy_server().ToURI()); | 760 EXPECT_EQ("i-approve-this-message:42", proxy_info2.proxy_server().ToURI()); |
756 } | 761 } |
757 | 762 |
758 // This implementation of HostResolver allows blocking until a resolve request | 763 // This implementation of HostResolver allows blocking until a resolve request |
759 // has been received. The resolve requests it receives will never be completed. | 764 // has been received. The resolve requests it receives will never be completed. |
760 class BlockableHostResolver : public HostResolver { | 765 class BlockableHostResolver : public HostResolver { |
761 public: | 766 public: |
762 BlockableHostResolver() | 767 BlockableHostResolver() |
763 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} | 768 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 | 835 |
831 ProxyInfo proxy_info1; | 836 ProxyInfo proxy_info1; |
832 ProxyInfo proxy_info2; | 837 ProxyInfo proxy_info2; |
833 ProxyResolver::RequestHandle request1; | 838 ProxyResolver::RequestHandle request1; |
834 ProxyResolver::RequestHandle request2; | 839 ProxyResolver::RequestHandle request2; |
835 | 840 |
836 int rv = resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1, | 841 int rv = resolver->GetProxyForURL(GURL("http://foo/req1"), &proxy_info1, |
837 base::Bind(&CrashCallback), &request1, | 842 base::Bind(&CrashCallback), &request1, |
838 BoundNetLog()); | 843 BoundNetLog()); |
839 | 844 |
840 EXPECT_EQ(ERR_IO_PENDING, rv); | 845 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
841 | 846 |
842 host_resolver.WaitUntilRequestIsReceived(); | 847 host_resolver.WaitUntilRequestIsReceived(); |
843 | 848 |
844 rv = resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2, | 849 rv = resolver->GetProxyForURL(GURL("http://foo/req2"), &proxy_info2, |
845 base::Bind(&CrashCallback), &request2, | 850 base::Bind(&CrashCallback), &request2, |
846 BoundNetLog()); | 851 BoundNetLog()); |
847 | 852 |
848 EXPECT_EQ(ERR_IO_PENDING, rv); | 853 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
849 | 854 |
850 host_resolver.WaitUntilRequestIsReceived(); | 855 host_resolver.WaitUntilRequestIsReceived(); |
851 | 856 |
852 resolver->CancelRequest(request1); | 857 resolver->CancelRequest(request1); |
853 resolver->CancelRequest(request2); | 858 resolver->CancelRequest(request2); |
854 | 859 |
855 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); | 860 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); |
856 | 861 |
857 // After leaving this scope, the ProxyResolver is destroyed. | 862 // After leaving this scope, the ProxyResolver is destroyed. |
858 // This should not cause any problems, as the outstanding work | 863 // This should not cause any problems, as the outstanding work |
(...skipping 20 matching lines...) Expand all Loading... |
879 std::unique_ptr<ProxyResolver> resolver = CreateResolver( | 884 std::unique_ptr<ProxyResolver> resolver = CreateResolver( |
880 nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); | 885 nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); |
881 | 886 |
882 ProxyInfo proxy_info; | 887 ProxyInfo proxy_info; |
883 ProxyResolver::RequestHandle request; | 888 ProxyResolver::RequestHandle request; |
884 | 889 |
885 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 890 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
886 base::Bind(&CrashCallback), &request, | 891 base::Bind(&CrashCallback), &request, |
887 BoundNetLog()); | 892 BoundNetLog()); |
888 | 893 |
889 EXPECT_EQ(ERR_IO_PENDING, rv); | 894 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
890 | 895 |
891 host_resolver.SetAction( | 896 host_resolver.SetAction( |
892 base::Bind(CancelRequestAndPause, resolver.get(), request)); | 897 base::Bind(CancelRequestAndPause, resolver.get(), request)); |
893 | 898 |
894 host_resolver.WaitUntilRequestIsReceived(); | 899 host_resolver.WaitUntilRequestIsReceived(); |
895 } | 900 } |
896 | 901 |
897 // Cancel the request while there is a pending DNS request, however before | 902 // Cancel the request while there is a pending DNS request, however before |
898 // the request is sent to the host resolver. | 903 // the request is sent to the host resolver. |
899 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns2) { | 904 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns2) { |
900 MockCachingHostResolver host_resolver; | 905 MockCachingHostResolver host_resolver; |
901 MockErrorObserver* error_observer = new MockErrorObserver; | 906 MockErrorObserver* error_observer = new MockErrorObserver; |
902 | 907 |
903 std::unique_ptr<ProxyResolver> resolver = CreateResolver( | 908 std::unique_ptr<ProxyResolver> resolver = CreateResolver( |
904 nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); | 909 nullptr, &host_resolver, base::WrapUnique(error_observer), "dns.js"); |
905 | 910 |
906 ProxyInfo proxy_info; | 911 ProxyInfo proxy_info; |
907 ProxyResolver::RequestHandle request; | 912 ProxyResolver::RequestHandle request; |
908 | 913 |
909 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 914 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
910 base::Bind(&CrashCallback), &request, | 915 base::Bind(&CrashCallback), &request, |
911 BoundNetLog()); | 916 BoundNetLog()); |
912 | 917 |
913 EXPECT_EQ(ERR_IO_PENDING, rv); | 918 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
914 | 919 |
915 // Wait a bit, so the DNS task has hopefully been posted. The test will | 920 // Wait a bit, so the DNS task has hopefully been posted. The test will |
916 // work whatever the delay is here, but it is most useful if the delay | 921 // work whatever the delay is here, but it is most useful if the delay |
917 // is large enough to allow a task to be posted back. | 922 // is large enough to allow a task to be posted back. |
918 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); | 923 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
919 resolver->CancelRequest(request); | 924 resolver->CancelRequest(request); |
920 | 925 |
921 EXPECT_EQ(0u, host_resolver.num_resolve()); | 926 EXPECT_EQ(0u, host_resolver.num_resolve()); |
922 } | 927 } |
923 | 928 |
924 TEST_F(ProxyResolverV8TracingWrapperTest, | 929 TEST_F(ProxyResolverV8TracingWrapperTest, |
925 CancelCreateResolverWhileOutstandingBlockingDns) { | 930 CancelCreateResolverWhileOutstandingBlockingDns) { |
926 BlockableHostResolver host_resolver; | 931 BlockableHostResolver host_resolver; |
927 MockErrorObserver* error_observer = new MockErrorObserver; | 932 MockErrorObserver* error_observer = new MockErrorObserver; |
928 | 933 |
929 ProxyResolverFactoryV8TracingWrapper factory( | 934 ProxyResolverFactoryV8TracingWrapper factory( |
930 &host_resolver, nullptr, | 935 &host_resolver, nullptr, |
931 base::Bind(&ReturnErrorObserver, | 936 base::Bind(&ReturnErrorObserver, |
932 base::Passed(base::WrapUnique(error_observer)))); | 937 base::Passed(base::WrapUnique(error_observer)))); |
933 | 938 |
934 std::unique_ptr<ProxyResolver> resolver; | 939 std::unique_ptr<ProxyResolver> resolver; |
935 std::unique_ptr<ProxyResolverFactory::Request> request; | 940 std::unique_ptr<ProxyResolverFactory::Request> request; |
936 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), | 941 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), |
937 &resolver, base::Bind(&CrashCallback), | 942 &resolver, base::Bind(&CrashCallback), |
938 &request); | 943 &request); |
939 EXPECT_EQ(ERR_IO_PENDING, rv); | 944 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
940 | 945 |
941 host_resolver.WaitUntilRequestIsReceived(); | 946 host_resolver.WaitUntilRequestIsReceived(); |
942 | 947 |
943 request.reset(); | 948 request.reset(); |
944 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 949 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
945 } | 950 } |
946 | 951 |
947 TEST_F(ProxyResolverV8TracingWrapperTest, | 952 TEST_F(ProxyResolverV8TracingWrapperTest, |
948 DeleteFactoryWhileOutstandingBlockingDns) { | 953 DeleteFactoryWhileOutstandingBlockingDns) { |
949 BlockableHostResolver host_resolver; | 954 BlockableHostResolver host_resolver; |
950 MockErrorObserver* error_observer = new MockErrorObserver; | 955 MockErrorObserver* error_observer = new MockErrorObserver; |
951 | 956 |
952 std::unique_ptr<ProxyResolver> resolver; | 957 std::unique_ptr<ProxyResolver> resolver; |
953 std::unique_ptr<ProxyResolverFactory::Request> request; | 958 std::unique_ptr<ProxyResolverFactory::Request> request; |
954 { | 959 { |
955 ProxyResolverFactoryV8TracingWrapper factory( | 960 ProxyResolverFactoryV8TracingWrapper factory( |
956 &host_resolver, nullptr, | 961 &host_resolver, nullptr, |
957 base::Bind(&ReturnErrorObserver, | 962 base::Bind(&ReturnErrorObserver, |
958 base::Passed(base::WrapUnique(error_observer)))); | 963 base::Passed(base::WrapUnique(error_observer)))); |
959 | 964 |
960 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), | 965 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), |
961 &resolver, base::Bind(&CrashCallback), | 966 &resolver, base::Bind(&CrashCallback), |
962 &request); | 967 &request); |
963 EXPECT_EQ(ERR_IO_PENDING, rv); | 968 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
964 host_resolver.WaitUntilRequestIsReceived(); | 969 host_resolver.WaitUntilRequestIsReceived(); |
965 } | 970 } |
966 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 971 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
967 } | 972 } |
968 | 973 |
969 TEST_F(ProxyResolverV8TracingWrapperTest, ErrorLoadingScript) { | 974 TEST_F(ProxyResolverV8TracingWrapperTest, ErrorLoadingScript) { |
970 BlockableHostResolver host_resolver; | 975 BlockableHostResolver host_resolver; |
971 MockErrorObserver* error_observer = new MockErrorObserver; | 976 MockErrorObserver* error_observer = new MockErrorObserver; |
972 | 977 |
973 ProxyResolverFactoryV8TracingWrapper factory( | 978 ProxyResolverFactoryV8TracingWrapper factory( |
974 &host_resolver, nullptr, | 979 &host_resolver, nullptr, |
975 base::Bind(&ReturnErrorObserver, | 980 base::Bind(&ReturnErrorObserver, |
976 base::Passed(base::WrapUnique(error_observer)))); | 981 base::Passed(base::WrapUnique(error_observer)))); |
977 | 982 |
978 std::unique_ptr<ProxyResolver> resolver; | 983 std::unique_ptr<ProxyResolver> resolver; |
979 std::unique_ptr<ProxyResolverFactory::Request> request; | 984 std::unique_ptr<ProxyResolverFactory::Request> request; |
980 TestCompletionCallback callback; | 985 TestCompletionCallback callback; |
981 int rv = | 986 int rv = |
982 factory.CreateProxyResolver(LoadScriptData("error_on_load.js"), &resolver, | 987 factory.CreateProxyResolver(LoadScriptData("error_on_load.js"), &resolver, |
983 callback.callback(), &request); | 988 callback.callback(), &request); |
984 EXPECT_EQ(ERR_IO_PENDING, rv); | 989 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
985 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 990 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_PAC_SCRIPT_FAILED)); |
986 EXPECT_FALSE(resolver); | 991 EXPECT_FALSE(resolver); |
987 } | 992 } |
988 | 993 |
989 // This tests that the execution of a PAC script is terminated when the DNS | 994 // This tests that the execution of a PAC script is terminated when the DNS |
990 // dependencies are missing. If the test fails, then it will hang. | 995 // dependencies are missing. If the test fails, then it will hang. |
991 TEST_F(ProxyResolverV8TracingWrapperTest, Terminate) { | 996 TEST_F(ProxyResolverV8TracingWrapperTest, Terminate) { |
992 TestNetLog log; | 997 TestNetLog log; |
993 BoundTestNetLog request_log; | 998 BoundTestNetLog request_log; |
994 MockCachingHostResolver host_resolver; | 999 MockCachingHostResolver host_resolver; |
995 MockErrorObserver* error_observer = new MockErrorObserver; | 1000 MockErrorObserver* error_observer = new MockErrorObserver; |
996 | 1001 |
997 host_resolver.rules()->AddRule("host1", "182.111.0.222"); | 1002 host_resolver.rules()->AddRule("host1", "182.111.0.222"); |
998 host_resolver.rules()->AddRule("host2", "111.33.44.55"); | 1003 host_resolver.rules()->AddRule("host2", "111.33.44.55"); |
999 | 1004 |
1000 std::unique_ptr<ProxyResolver> resolver = CreateResolver( | 1005 std::unique_ptr<ProxyResolver> resolver = CreateResolver( |
1001 &log, &host_resolver, base::WrapUnique(error_observer), "terminate.js"); | 1006 &log, &host_resolver, base::WrapUnique(error_observer), "terminate.js"); |
1002 | 1007 |
1003 TestCompletionCallback callback; | 1008 TestCompletionCallback callback; |
1004 ProxyInfo proxy_info; | 1009 ProxyInfo proxy_info; |
1005 | 1010 |
1006 int rv = | 1011 int rv = |
1007 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, | 1012 resolver->GetProxyForURL(GURL("http://foopy/req1"), &proxy_info, |
1008 callback.callback(), NULL, request_log.bound()); | 1013 callback.callback(), NULL, request_log.bound()); |
1009 | 1014 |
1010 EXPECT_EQ(ERR_IO_PENDING, rv); | 1015 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1011 EXPECT_EQ(OK, callback.WaitForResult()); | 1016 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
1012 | 1017 |
1013 // The test does 2 DNS resolutions. | 1018 // The test does 2 DNS resolutions. |
1014 EXPECT_EQ(2u, host_resolver.num_resolve()); | 1019 EXPECT_EQ(2u, host_resolver.num_resolve()); |
1015 | 1020 |
1016 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); | 1021 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); |
1017 | 1022 |
1018 // No errors. | 1023 // No errors. |
1019 EXPECT_EQ("", error_observer->GetOutput()); | 1024 EXPECT_EQ("", error_observer->GetOutput()); |
1020 | 1025 |
1021 EXPECT_EQ(0u, log.GetSize()); | 1026 EXPECT_EQ(0u, log.GetSize()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 const size_t kNumIterations = 20; | 1087 const size_t kNumIterations = 20; |
1083 const size_t kNumResults = kNumResolvers * kNumIterations; | 1088 const size_t kNumResults = kNumResolvers * kNumIterations; |
1084 TestCompletionCallback callback[kNumResults]; | 1089 TestCompletionCallback callback[kNumResults]; |
1085 ProxyInfo proxy_info[kNumResults]; | 1090 ProxyInfo proxy_info[kNumResults]; |
1086 | 1091 |
1087 for (size_t i = 0; i < kNumResults; ++i) { | 1092 for (size_t i = 0; i < kNumResults; ++i) { |
1088 size_t resolver_i = i % kNumResolvers; | 1093 size_t resolver_i = i % kNumResolvers; |
1089 int rv = resolver[resolver_i]->GetProxyForURL( | 1094 int rv = resolver[resolver_i]->GetProxyForURL( |
1090 GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL, | 1095 GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL, |
1091 BoundNetLog()); | 1096 BoundNetLog()); |
1092 EXPECT_EQ(ERR_IO_PENDING, rv); | 1097 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1093 } | 1098 } |
1094 | 1099 |
1095 // ------------------------ | 1100 // ------------------------ |
1096 // Verify all of the results. | 1101 // Verify all of the results. |
1097 // ------------------------ | 1102 // ------------------------ |
1098 | 1103 |
1099 const char* kExpectedForDnsJs = | 1104 const char* kExpectedForDnsJs = |
1100 "122.133.144.155-" // myIpAddress() | 1105 "122.133.144.155-" // myIpAddress() |
1101 "null-" // dnsResolve('') | 1106 "null-" // dnsResolve('') |
1102 "__1_192.168.1.1-" // dnsResolveEx('host1') | 1107 "__1_192.168.1.1-" // dnsResolveEx('host1') |
1103 "null-" // dnsResolve('host2') | 1108 "null-" // dnsResolve('host2') |
1104 "166.155.144.33-" // dnsResolve('host3') | 1109 "166.155.144.33-" // dnsResolve('host3') |
1105 "122.133.144.155-" // myIpAddress() | 1110 "122.133.144.155-" // myIpAddress() |
1106 "166.155.144.33-" // dnsResolve('host3') | 1111 "166.155.144.33-" // dnsResolve('host3') |
1107 "__1_192.168.1.1-" // dnsResolveEx('host1') | 1112 "__1_192.168.1.1-" // dnsResolveEx('host1') |
1108 "122.133.144.155-" // myIpAddress() | 1113 "122.133.144.155-" // myIpAddress() |
1109 "null-" // dnsResolve('host2') | 1114 "null-" // dnsResolve('host2') |
1110 "-" // dnsResolveEx('host6') | 1115 "-" // dnsResolveEx('host6') |
1111 "133.122.100.200-" // myIpAddressEx() | 1116 "133.122.100.200-" // myIpAddressEx() |
1112 "166.155.144.44" // dnsResolve('host1') | 1117 "166.155.144.44" // dnsResolve('host1') |
1113 ":99"; | 1118 ":99"; |
1114 | 1119 |
1115 for (size_t i = 0; i < kNumResults; ++i) { | 1120 for (size_t i = 0; i < kNumResults; ++i) { |
1116 size_t resolver_i = i % kNumResolvers; | 1121 size_t resolver_i = i % kNumResolvers; |
1117 EXPECT_EQ(OK, callback[i].WaitForResult()); | 1122 EXPECT_THAT(callback[i].WaitForResult(), IsOk()); |
1118 | 1123 |
1119 std::string proxy_uri = proxy_info[i].proxy_server().ToURI(); | 1124 std::string proxy_uri = proxy_info[i].proxy_server().ToURI(); |
1120 | 1125 |
1121 if (resolver_i == 0 || resolver_i == 1) { | 1126 if (resolver_i == 0 || resolver_i == 1) { |
1122 EXPECT_EQ(kExpectedForDnsJs, proxy_uri); | 1127 EXPECT_EQ(kExpectedForDnsJs, proxy_uri); |
1123 } else if (resolver_i == 2) { | 1128 } else if (resolver_i == 2) { |
1124 EXPECT_EQ("foo:99", proxy_uri); | 1129 EXPECT_EQ("foo:99", proxy_uri); |
1125 } else if (resolver_i == 3) { | 1130 } else if (resolver_i == 3) { |
1126 EXPECT_EQ("166.155.144.33:", | 1131 EXPECT_EQ("166.155.144.33:", |
1127 proxy_uri.substr(0, proxy_uri.find(':') + 1)); | 1132 proxy_uri.substr(0, proxy_uri.find(':') + 1)); |
1128 } else { | 1133 } else { |
1129 NOTREACHED(); | 1134 NOTREACHED(); |
1130 } | 1135 } |
1131 } | 1136 } |
1132 } | 1137 } |
1133 | 1138 |
1134 } // namespace | 1139 } // namespace |
1135 | 1140 |
1136 } // namespace net | 1141 } // namespace net |
OLD | NEW |