| 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "net/base/net_errors.h" |
| 10 #include "net/base/net_log_unittest.h" | 11 #include "net/base/net_log_unittest.h" |
| 11 #include "net/base/net_errors.h" | |
| 12 #include "net/proxy/proxy_info.h" | 12 #include "net/proxy/proxy_info.h" |
| 13 #include "net/proxy/proxy_resolver_js_bindings.h" | 13 #include "net/proxy/proxy_resolver_js_bindings.h" |
| 14 #include "net/proxy/proxy_resolver_v8.h" | 14 #include "net/proxy/proxy_resolver_v8.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Javascript bindings for ProxyResolverV8, which returns mock values. | 20 // Javascript bindings for ProxyResolverV8, which returns mock values. |
| 21 // Each time one of the bindings is called into, we push the input into a | 21 // Each time one of the bindings is called into, we push the input into a |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 EXPECT_EQ("127.0.0.1:80", proxy_info.proxy_server().ToURI()); | 451 EXPECT_EQ("127.0.0.1:80", proxy_info.proxy_server().ToURI()); |
| 452 | 452 |
| 453 // Check that no other bindings were called. | 453 // Check that no other bindings were called. |
| 454 EXPECT_EQ(0U, bindings->errors.size()); | 454 EXPECT_EQ(0U, bindings->errors.size()); |
| 455 ASSERT_EQ(0U, bindings->alerts.size()); | 455 ASSERT_EQ(0U, bindings->alerts.size()); |
| 456 ASSERT_EQ(0U, bindings->dns_resolves.size()); | 456 ASSERT_EQ(0U, bindings->dns_resolves.size()); |
| 457 EXPECT_EQ(0, bindings->my_ip_address_ex_count); | 457 EXPECT_EQ(0, bindings->my_ip_address_ex_count); |
| 458 ASSERT_EQ(0U, bindings->dns_resolves_ex.size()); | 458 ASSERT_EQ(0U, bindings->dns_resolves_ex.size()); |
| 459 } | 459 } |
| 460 | 460 |
| 461 // Test that calls to the myIpAddress() and dnsResolve() bindings get | |
| 462 // logged to the NetLog parameter. | |
| 463 TEST(ProxyResolverV8Test, NetLog) { | |
| 464 ProxyResolverV8WithMockBindings resolver; | |
| 465 int result = resolver.SetPacScriptFromDisk("simple.js"); | |
| 466 EXPECT_EQ(OK, result); | |
| 467 | |
| 468 ProxyInfo proxy_info; | |
| 469 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | |
| 470 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, | |
| 471 log.bound()); | |
| 472 | |
| 473 EXPECT_EQ(OK, result); | |
| 474 EXPECT_FALSE(proxy_info.is_direct()); | |
| 475 EXPECT_EQ("c:100", proxy_info.proxy_server().ToURI()); | |
| 476 | |
| 477 // Note that dnsResolve() was never called directly, but it appears | |
| 478 // in the NetLog. This is because it gets called indirectly by | |
| 479 // isInNet() and isResolvable(). | |
| 480 | |
| 481 EXPECT_EQ(6u, log.entries().size()); | |
| 482 EXPECT_TRUE(LogContainsBeginEvent( | |
| 483 log.entries(), 0, NetLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS)); | |
| 484 EXPECT_TRUE(LogContainsEndEvent( | |
| 485 log.entries(), 1, NetLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS)); | |
| 486 EXPECT_TRUE(LogContainsBeginEvent( | |
| 487 log.entries(), 2, NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); | |
| 488 EXPECT_TRUE(LogContainsEndEvent( | |
| 489 log.entries(), 3, NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); | |
| 490 EXPECT_TRUE(LogContainsBeginEvent( | |
| 491 log.entries(), 4, NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); | |
| 492 EXPECT_TRUE(LogContainsEndEvent( | |
| 493 log.entries(), 5, NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE)); | |
| 494 } | |
| 495 | |
| 496 // Try loading a PAC script that ends with a comment and has no terminal | 461 // Try loading a PAC script that ends with a comment and has no terminal |
| 497 // newline. This should not cause problems with the PAC utility functions | 462 // newline. This should not cause problems with the PAC utility functions |
| 498 // that we add to the script's environment. | 463 // that we add to the script's environment. |
| 499 // http://crbug.com/22864 | 464 // http://crbug.com/22864 |
| 500 TEST(ProxyResolverV8Test, EndsWithCommentNoNewline) { | 465 TEST(ProxyResolverV8Test, EndsWithCommentNoNewline) { |
| 501 ProxyResolverV8WithMockBindings resolver; | 466 ProxyResolverV8WithMockBindings resolver; |
| 502 int result = resolver.SetPacScriptFromDisk("ends_with_comment.js"); | 467 int result = resolver.SetPacScriptFromDisk("ends_with_comment.js"); |
| 503 EXPECT_EQ(OK, result); | 468 EXPECT_EQ(OK, result); |
| 504 | 469 |
| 505 ProxyInfo proxy_info; | 470 ProxyInfo proxy_info; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 534 |
| 570 ASSERT_EQ(1u, bindings->dns_resolves.size()); | 535 ASSERT_EQ(1u, bindings->dns_resolves.size()); |
| 571 EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves[0]); | 536 EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves[0]); |
| 572 | 537 |
| 573 ASSERT_EQ(1u, bindings->dns_resolves_ex.size()); | 538 ASSERT_EQ(1u, bindings->dns_resolves_ex.size()); |
| 574 EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves_ex[0]); | 539 EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves_ex[0]); |
| 575 } | 540 } |
| 576 | 541 |
| 577 } // namespace | 542 } // namespace |
| 578 } // namespace net | 543 } // namespace net |
| OLD | NEW |