OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "net/base/load_log_unittest.h" | 9 #include "net/base/net_log_unittest.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/proxy/proxy_info.h" | 11 #include "net/proxy/proxy_info.h" |
12 #include "net/proxy/proxy_resolver_js_bindings.h" | 12 #include "net/proxy/proxy_resolver_js_bindings.h" |
13 #include "net/proxy/proxy_resolver_v8.h" | 13 #include "net/proxy/proxy_resolver_v8.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Javascript bindings for ProxyResolverV8, which returns mock values. | 19 // Javascript bindings for ProxyResolverV8, which returns mock values. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 const GURL kQueryUrl("http://www.google.com"); | 111 const GURL kQueryUrl("http://www.google.com"); |
112 const GURL kPacUrl; | 112 const GURL kPacUrl; |
113 | 113 |
114 | 114 |
115 TEST(ProxyResolverV8Test, Direct) { | 115 TEST(ProxyResolverV8Test, Direct) { |
116 ProxyResolverV8WithMockBindings resolver; | 116 ProxyResolverV8WithMockBindings resolver; |
117 int result = resolver.SetPacScriptFromDisk("direct.js"); | 117 int result = resolver.SetPacScriptFromDisk("direct.js"); |
118 EXPECT_EQ(OK, result); | 118 EXPECT_EQ(OK, result); |
119 | 119 |
120 ProxyInfo proxy_info; | 120 ProxyInfo proxy_info; |
121 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); | 121 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
122 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); | 122 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 123 log.bound()); |
123 | 124 |
124 EXPECT_EQ(OK, result); | 125 EXPECT_EQ(OK, result); |
125 EXPECT_TRUE(proxy_info.is_direct()); | 126 EXPECT_TRUE(proxy_info.is_direct()); |
126 | 127 |
127 EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); | 128 EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); |
128 EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); | 129 EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); |
129 | 130 |
130 // No bindings were called, so no log entries. | 131 // No bindings were called, so no log entries. |
131 EXPECT_EQ(0u, log->entries().size()); | 132 EXPECT_EQ(0u, log.entries().size()); |
132 } | 133 } |
133 | 134 |
134 TEST(ProxyResolverV8Test, ReturnEmptyString) { | 135 TEST(ProxyResolverV8Test, ReturnEmptyString) { |
135 ProxyResolverV8WithMockBindings resolver; | 136 ProxyResolverV8WithMockBindings resolver; |
136 int result = resolver.SetPacScriptFromDisk("return_empty_string.js"); | 137 int result = resolver.SetPacScriptFromDisk("return_empty_string.js"); |
137 EXPECT_EQ(OK, result); | 138 EXPECT_EQ(OK, result); |
138 | 139 |
139 ProxyInfo proxy_info; | 140 ProxyInfo proxy_info; |
140 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, NULL); | 141 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, NULL); |
141 | 142 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 // MyIpAddressEx was called once. | 410 // MyIpAddressEx was called once. |
410 EXPECT_EQ(1, bindings->my_ip_address_ex_count); | 411 EXPECT_EQ(1, bindings->my_ip_address_ex_count); |
411 | 412 |
412 // DnsResolveEx was called 2 times. | 413 // DnsResolveEx was called 2 times. |
413 ASSERT_EQ(2U, bindings->dns_resolves_ex.size()); | 414 ASSERT_EQ(2U, bindings->dns_resolves_ex.size()); |
414 EXPECT_EQ("is_resolvable", bindings->dns_resolves_ex[0]); | 415 EXPECT_EQ("is_resolvable", bindings->dns_resolves_ex[0]); |
415 EXPECT_EQ("foobar", bindings->dns_resolves_ex[1]); | 416 EXPECT_EQ("foobar", bindings->dns_resolves_ex[1]); |
416 } | 417 } |
417 | 418 |
418 // Test that calls to the myIpAddress() and dnsResolve() bindings get | 419 // Test that calls to the myIpAddress() and dnsResolve() bindings get |
419 // logged to the LoadLog parameter. | 420 // logged to the NetLog parameter. |
420 TEST(ProxyResolverV8Test, LoadLog) { | 421 TEST(ProxyResolverV8Test, NetLog) { |
421 ProxyResolverV8WithMockBindings resolver; | 422 ProxyResolverV8WithMockBindings resolver; |
422 int result = resolver.SetPacScriptFromDisk("simple.js"); | 423 int result = resolver.SetPacScriptFromDisk("simple.js"); |
423 EXPECT_EQ(OK, result); | 424 EXPECT_EQ(OK, result); |
424 | 425 |
425 ProxyInfo proxy_info; | 426 ProxyInfo proxy_info; |
426 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); | 427 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
427 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); | 428 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 429 log.bound()); |
428 | 430 |
429 EXPECT_EQ(OK, result); | 431 EXPECT_EQ(OK, result); |
430 EXPECT_FALSE(proxy_info.is_direct()); | 432 EXPECT_FALSE(proxy_info.is_direct()); |
431 EXPECT_EQ("c:100", proxy_info.proxy_server().ToURI()); | 433 EXPECT_EQ("c:100", proxy_info.proxy_server().ToURI()); |
432 | 434 |
433 // Note that dnsResolve() was never called directly, but it appears | 435 // Note that dnsResolve() was never called directly, but it appears |
434 // in the LoadLog. This is because it gets called indirectly by | 436 // in the NetLog. This is because it gets called indirectly by |
435 // isInNet() and isResolvable(). | 437 // isInNet() and isResolvable(). |
436 | 438 |
437 EXPECT_EQ(6u, log->entries().size()); | 439 EXPECT_EQ(6u, log.entries().size()); |
438 EXPECT_TRUE(LogContainsBeginEvent( | 440 EXPECT_TRUE(LogContainsBeginEvent( |
439 *log, 0, LoadLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS)); | 441 log.entries(), 0, NetLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS)); |
440 EXPECT_TRUE(LogContainsEndEvent( | 442 EXPECT_TRUE(LogContainsEndEvent( |
441 *log, 1, LoadLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS)); | 443 log.entries(), 1, NetLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS)); |
442 EXPECT_TRUE(LogContainsBeginEvent( | 444 EXPECT_TRUE(LogContainsBeginEvent( |
443 *log, 2, LoadLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); | 445 log.entries(), 2, NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); |
444 EXPECT_TRUE(LogContainsEndEvent( | 446 EXPECT_TRUE(LogContainsEndEvent( |
445 *log, 3, LoadLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); | 447 log.entries(), 3, NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); |
446 EXPECT_TRUE(LogContainsBeginEvent( | 448 EXPECT_TRUE(LogContainsBeginEvent( |
447 *log, 4, LoadLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); | 449 log.entries(), 4, NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); |
448 EXPECT_TRUE(LogContainsEndEvent( | 450 EXPECT_TRUE(LogContainsEndEvent( |
449 *log, 5, LoadLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); | 451 log.entries(), 5, NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); |
450 } | 452 } |
451 | 453 |
452 // Try loading a PAC script that ends with a comment and has no terminal | 454 // Try loading a PAC script that ends with a comment and has no terminal |
453 // newline. This should not cause problems with the PAC utility functions | 455 // newline. This should not cause problems with the PAC utility functions |
454 // that we add to the script's environment. | 456 // that we add to the script's environment. |
455 // http://crbug.com/22864 | 457 // http://crbug.com/22864 |
456 TEST(ProxyResolverV8Test, EndsWithCommentNoNewline) { | 458 TEST(ProxyResolverV8Test, EndsWithCommentNoNewline) { |
457 ProxyResolverV8WithMockBindings resolver; | 459 ProxyResolverV8WithMockBindings resolver; |
458 int result = resolver.SetPacScriptFromDisk("ends_with_comment.js"); | 460 int result = resolver.SetPacScriptFromDisk("ends_with_comment.js"); |
459 EXPECT_EQ(OK, result); | 461 EXPECT_EQ(OK, result); |
460 | 462 |
461 ProxyInfo proxy_info; | 463 ProxyInfo proxy_info; |
462 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); | 464 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
463 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); | 465 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 466 log.bound()); |
464 | 467 |
465 EXPECT_EQ(OK, result); | 468 EXPECT_EQ(OK, result); |
466 EXPECT_FALSE(proxy_info.is_direct()); | 469 EXPECT_FALSE(proxy_info.is_direct()); |
467 EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); | 470 EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); |
468 } | 471 } |
469 | 472 |
470 // Try loading a PAC script that ends with a statement and has no terminal | 473 // Try loading a PAC script that ends with a statement and has no terminal |
471 // newline. This should not cause problems with the PAC utility functions | 474 // newline. This should not cause problems with the PAC utility functions |
472 // that we add to the script's environment. | 475 // that we add to the script's environment. |
473 // http://crbug.com/22864 | 476 // http://crbug.com/22864 |
474 TEST(ProxyResolverV8Test, EndsWithStatementNoNewline) { | 477 TEST(ProxyResolverV8Test, EndsWithStatementNoNewline) { |
475 ProxyResolverV8WithMockBindings resolver; | 478 ProxyResolverV8WithMockBindings resolver; |
476 int result = resolver.SetPacScriptFromDisk( | 479 int result = resolver.SetPacScriptFromDisk( |
477 "ends_with_statement_no_semicolon.js"); | 480 "ends_with_statement_no_semicolon.js"); |
478 EXPECT_EQ(OK, result); | 481 EXPECT_EQ(OK, result); |
479 | 482 |
480 ProxyInfo proxy_info; | 483 ProxyInfo proxy_info; |
481 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); | 484 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
482 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); | 485 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 486 log.bound()); |
483 | 487 |
484 EXPECT_EQ(OK, result); | 488 EXPECT_EQ(OK, result); |
485 EXPECT_FALSE(proxy_info.is_direct()); | 489 EXPECT_FALSE(proxy_info.is_direct()); |
486 EXPECT_EQ("success:3", proxy_info.proxy_server().ToURI()); | 490 EXPECT_EQ("success:3", proxy_info.proxy_server().ToURI()); |
487 } | 491 } |
488 | 492 |
489 // Test the return values from myIpAddress(), myIpAddressEx(), dnsResolve(), | 493 // Test the return values from myIpAddress(), myIpAddressEx(), dnsResolve(), |
490 // dnsResolveEx(), isResolvable(), isResolvableEx(), when the the binding | 494 // dnsResolveEx(), isResolvable(), isResolvableEx(), when the the binding |
491 // returns empty string (failure). This simulates the return values from | 495 // returns empty string (failure). This simulates the return values from |
492 // those functions when the underlying DNS resolution fails. | 496 // those functions when the underlying DNS resolution fails. |
493 TEST(ProxyResolverV8Test, DNSResolutionFailure) { | 497 TEST(ProxyResolverV8Test, DNSResolutionFailure) { |
494 ProxyResolverV8WithMockBindings resolver; | 498 ProxyResolverV8WithMockBindings resolver; |
495 int result = resolver.SetPacScriptFromDisk("dns_fail.js"); | 499 int result = resolver.SetPacScriptFromDisk("dns_fail.js"); |
496 EXPECT_EQ(OK, result); | 500 EXPECT_EQ(OK, result); |
497 | 501 |
498 ProxyInfo proxy_info; | 502 ProxyInfo proxy_info; |
499 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, NULL); | 503 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, NULL); |
500 | 504 |
501 EXPECT_EQ(OK, result); | 505 EXPECT_EQ(OK, result); |
502 EXPECT_FALSE(proxy_info.is_direct()); | 506 EXPECT_FALSE(proxy_info.is_direct()); |
503 EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); | 507 EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); |
504 } | 508 } |
505 | 509 |
506 } // namespace | 510 } // namespace |
507 } // namespace net | 511 } // namespace net |
OLD | NEW |