// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/351564777): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif #include "services/proxy_resolver/proxy_resolver_v8.h" #include "base/compiler_specific.h" #include "base/files/file_util.h" #include "base/path_service.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/test/task_environment.h" #include "net/base/net_errors.h" #include "net/base/proxy_string_util.h" #include "net/proxy_resolution/pac_file_data.h" #include "net/proxy_resolution/proxy_info.h" #include "net/test/gtest_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" IsError; IsOk; IsEmpty; namespace proxy_resolver { namespace { // Javascript bindings for ProxyResolverV8, which returns mock values. // Each time one of the bindings is called into, we push the input into a // list, for later verification. class MockJSBindings : public ProxyResolverV8::JSBindings { … }; class ProxyResolverV8Test : public testing::Test { … }; TEST_F(ProxyResolverV8Test, Direct) { … } TEST_F(ProxyResolverV8Test, ReturnEmptyString) { … } TEST_F(ProxyResolverV8Test, Basic) { … } TEST_F(ProxyResolverV8Test, BadReturnType) { … } // Try using a PAC script which defines no "FindProxyForURL" function. TEST_F(ProxyResolverV8Test, NoEntryPoint) { … } // Try loading a malformed PAC script. TEST_F(ProxyResolverV8Test, ParseError) { … } // Run a PAC script several times, which has side-effects. TEST_F(ProxyResolverV8Test, SideEffects) { … } // Execute a PAC script which throws an exception in FindProxyForURL. TEST_F(ProxyResolverV8Test, UnhandledException) { … } // Execute a PAC script which throws an exception when first accessing // FindProxyForURL TEST_F(ProxyResolverV8Test, ExceptionAccessingFindProxyForURLDuringInit) { … } // Execute a PAC script which throws an exception during the second access to // FindProxyForURL TEST_F(ProxyResolverV8Test, ExceptionAccessingFindProxyForURLDuringResolve) { … } TEST_F(ProxyResolverV8Test, ReturnUnicode) { … } // Test the PAC library functions that we expose in the JS environment. TEST_F(ProxyResolverV8Test, JavascriptLibrary) { … } // Test marshalling/un-marshalling of values between C++/V8. TEST_F(ProxyResolverV8Test, V8Bindings) { … } // Test calling a binding (myIpAddress()) from the script's global scope. // http://crbug.com/40026 TEST_F(ProxyResolverV8Test, BindingCalledDuringInitialization) { … } // Try loading a PAC script that ends with a comment and has no terminal // newline. This should not cause problems with the PAC utility functions // that we add to the script's environment. // http://crbug.com/22864 TEST_F(ProxyResolverV8Test, EndsWithCommentNoNewline) { … } // Try loading a PAC script that ends with a statement and has no terminal // newline. This should not cause problems with the PAC utility functions // that we add to the script's environment. // http://crbug.com/22864 TEST_F(ProxyResolverV8Test, EndsWithStatementNoNewline) { … } // Test the return values from myIpAddress(), myIpAddressEx(), dnsResolve(), // dnsResolveEx(), isResolvable(), isResolvableEx(), when the the binding // returns empty string (failure). This simulates the return values from // those functions when the underlying DNS resolution fails. TEST_F(ProxyResolverV8Test, DNSResolutionFailure) { … } TEST_F(ProxyResolverV8Test, DNSResolutionOfInternationDomainName) { … } // Test that when resolving a URL which contains an IPv6 string literal, the // brackets are removed from the host before passing it down to the PAC script. // If we don't do this, then subsequent calls to dnsResolveEx(host) will be // doomed to fail since it won't correspond with a valid name. TEST_F(ProxyResolverV8Test, IPv6HostnamesNotBracketed) { … } // Test that terminating a script within DnsResolve() leads to eventual // termination of the script. Also test that repeatedly calling terminate is // safe, and running the script again after termination still works. TEST_F(ProxyResolverV8Test, Terminate) { … } } // namespace } // namespace proxy_resolver