// Copyright 2013 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_tracing.h" #include <string> #include <utility> #include <vector> #include "base/files/file_util.h" #include "base/functional/bind.h" #include "base/memory/raw_ptr.h" #include "base/path_service.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/synchronization/waitable_event.h" #include "base/test/task_environment.h" #include "base/threading/platform_thread.h" #include "base/threading/thread_checker.h" #include "base/values.h" #include "net/base/net_errors.h" #include "net/base/network_anonymization_key.h" #include "net/base/network_interfaces.h" #include "net/base/proxy_string_util.h" #include "net/base/test_completion_callback.h" #include "net/log/net_log_with_source.h" #include "net/proxy_resolution/proxy_info.h" #include "net/proxy_resolution/proxy_resolve_dns_operation.h" #include "net/test/event_waiter.h" #include "net/test/gtest_util.h" #include "services/proxy_resolver/mock_proxy_host_resolver.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" #include "url/origin.h" IsError; IsOk; namespace proxy_resolver { namespace { class ProxyResolverV8TracingTest : public testing::Test { … }; scoped_refptr<net::PacFileData> LoadScriptData(const char* filename) { … } class MockBindings { … }; std::unique_ptr<ProxyResolverV8Tracing> CreateResolver( std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings, const char* filename) { … } TEST_F(ProxyResolverV8TracingTest, Simple) { … } TEST_F(ProxyResolverV8TracingTest, JavascriptError) { … } TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { … } // Verify that buffered alerts cannot grow unboundedly, even when the message is // empty string. TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { … } // This test runs a PAC script that issues a sequence of DNS resolves. The test // verifies the final result, and that the underlying DNS resolver received // the correct set of queries. TEST_F(ProxyResolverV8TracingTest, Dns) { … } // This test runs a weird PAC script that was designed to defeat the DNS tracing // optimization. The proxy resolver should detect the inconsistency and // fall-back to synchronous mode execution. TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) { … } // This test runs a weird PAC script that was designed to defeat the DNS tracing // optimization. The proxy resolver should detect the inconsistency and // fall-back to synchronous mode execution. TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) { … } // This test runs a weird PAC script that yields a never ending sequence // of DNS resolves when restarting. Running it will hit the maximum // DNS resolves per request limit (20) after which every DNS resolve will // fail. TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) { … } // This test runs a weird PAC script that yields a never ending sequence // of DNS resolves when restarting. Running it will hit the maximum // DNS resolves per request limit (20) after which every DNS resolve will // fail. TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) { … } void DnsDuringInitHelper(bool synchronous_host_resolver) { … } // Tests a PAC script which does DNS resolves during initialization. TEST_F(ProxyResolverV8TracingTest, DnsDuringInit) { … } void CrashCallback(int) { … } // Start some requests, cancel them all, and then destroy the resolver. // Note the execution order for this test can vary. Since multiple // threads are involved, the cancellation may be received a different // times. TEST_F(ProxyResolverV8TracingTest, CancelAll) { … } // Note the execution order for this test can vary. Since multiple // threads are involved, the cancellation may be received a different // times. TEST_F(ProxyResolverV8TracingTest, CancelSome) { … } // Cancel a request after it has finished running on the worker thread, and has // posted a task the completion task back to origin thread. TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) { … } // This cancellation test exercises a more predictable cancellation codepath -- // when the request has an outstanding DNS request in flight. TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { … } void CancelRequestAndPause( std::unique_ptr<net::ProxyResolver::Request>* request, base::RunLoop* run_loop) { … } // In non-blocking mode, the worker thread actually does block for // a short time to see if the result is in the DNS cache. Test // cancellation while the worker thread is waiting on this event. TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) { … } // Cancel the request while there is a pending DNS request, however before // the request is sent to the host resolver. TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) { … } TEST_F(ProxyResolverV8TracingTest, CancelCreateResolverWhileOutstandingBlockingDns) { … } TEST_F(ProxyResolverV8TracingTest, DeleteFactoryWhileOutstandingBlockingDns) { … } TEST_F(ProxyResolverV8TracingTest, ErrorLoadingScript) { … } // This tests that the execution of a PAC script is terminated when the DNS // dependencies are missing. If the test fails, then it will hang. TEST_F(ProxyResolverV8TracingTest, Terminate) { … } // Tests that multiple instances of ProxyResolverV8Tracing can coexist and run // correctly at the same time. This is relevant because at the moment (time // this test was written) each ProxyResolverV8Tracing creates its own thread to // run V8 on, however each thread is operating on the same v8::Isolate. TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) { … } // Make sure that NetworkAnonymizationKeys passed to the ProxyResolverV8Tracing // are passed to the ProxyHostResolver. Does this by making a // MockProxyHostResolver return different results for the same host based on // what net::NetworkAnonymizationKey is used, and then using a PAC script that // returns the IP address a hostname resolves to as a proxy using the two // different NetworkAnonymizationKeys, checking the results. TEST_F(ProxyResolverV8TracingTest, NetworkAnonymizationKey) { … } // Make sure that net::NetworkAnonymizationKey is not passed to the // ProxyHostResolver when looking up either myIpAddress() or myIpAddressEx(). // This allows their values to be cached across NetworkAnonymizationKeys. This // test works by having the ProxyHostResolver return different results based on // the net::NetworkAnonymizationKey used, and then running a PAC script that // returns a result containing the IP address contained by both values, checking // the resulting value. TEST_F(ProxyResolverV8TracingTest, MyIPAddressWithNetworkAnonymizationKey) { … } } // namespace } // namespace proxy_resolver