chromium/services/network/proxy_auto_config_library_unittest.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/proxy_auto_config_library.h"

#include <algorithm>
#include <deque>
#include <memory>
#include <string_view>

#include "base/barrier_closure.h"
#include "base/containers/circular_deque.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "net/base/address_list.h"
#include "net/base/completion_once_callback.h"
#include "net/base/ip_address.h"
#include "net/base/net_errors.h"
#include "net/base/network_interfaces.h"
#include "net/dns/host_resolver_system_task.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/datagram_client_socket.h"
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace network {
namespace {

class MockClient : public proxy_resolver::mojom::HostResolverRequestClient {};

// Helper for verifying whether the address list returned by myIpAddress() /
// myIpAddressEx() looks correct.
void VerifyActualMyIpAddresses(const net::IPAddressList& test_list) {}

net::IPAddress CreateIPAddress(std::string_view literal) {}

class MockHostResolverProc : public net::HostResolverProc {};

class MockUDPSocket : public net::DatagramClientSocket {};

class MockSocketFactory : public net::ClientSocketFactory {};

class PacLibraryTest : public testing::Test {};

// Tests for actual PacMyIpAddress() and PacMyIpAddressEx() (real socket
// connections and DNS results rather than mocks)
TEST_F(PacLibraryTest, ActualPacMyIpAddress) {}

TEST_F(PacLibraryTest, ActualPacMyIpAddressEx) {}

// Tests myIpAddress() when there is a route to 8.8.8.8.
TEST_F(PacLibraryTest, PacMyIpAddress8888) {}

TEST_F(PacLibraryTest, PacMyIpAddress8888AsyncConnect) {}

// Tests successful async-completion of the connections.
TEST_F(PacLibraryTest, PacMyIpAddress8888AsyncConnect2) {}

TEST_F(PacLibraryTest, PacMyIpAddress8888AsyncConnect2OutOfOrder) {}

TEST_F(PacLibraryTest, PacMyIpAddress8888AsyncConnect2OutOfOrder2) {}

// Tests myIpAddress() when there is no route to 8.8.8.8, but there is one to
// 2001:4860:4860::8888.
TEST_F(PacLibraryTest, PacMyIpAddress2001) {}

// Tests myIpAddress() when there is no route to 8.8.8.8, no route to
// 2001:4860:4860::8888, however getaddrinfo(gethostname()) finds results. Most
// of those results are skipped over, and the IPv4 one is favored.
TEST_F(PacLibraryTest, PacMyIpAddressHostname) {}

// Tests myIpAddress() when there is no route to 8.8.8.8, no route to
// 2001:4860:4860::8888, however getaddrinfo(gethostname()) finds multiple IPv6
// results.
TEST_F(PacLibraryTest, PacMyIpAddressHostnameAllIPv6) {}

// Tests myIpAddress() when there is no route to 8.8.8.8, no route to
// 2001:4860:4860::8888, no acceptable result in getaddrinfo(gethostname()),
// however there is a route for private address.
TEST_F(PacLibraryTest, PacMyIpAddressPrivateIPv4) {}

// Tests myIpAddress() when there is no route to 8.8.8.8, no route to
// 2001:4860:4860::8888, no acceptable result in getaddrinfo(gethostname()),
// however there is a route for private address.
TEST_F(PacLibraryTest, PacMyIpAddressPrivateIPv6) {}

// Tests myIpAddress() when there are no routes, and getaddrinfo(gethostname())
// fails.
TEST_F(PacLibraryTest, PacMyIpAddressAllFail) {}

// Tests myIpAddress() when there are no routes, and
// getaddrinfo(gethostname()) only returns loopback.
TEST_F(PacLibraryTest, PacMyIpAddressAllFailOrLoopback) {}

// Tests myIpAddress() when there is only an IPv6 link-local address.
TEST_F(PacLibraryTest, PacMyIpAddressAllFailHasLinkLocal) {}

// Tests myIpAddress() when there are only link-local addresses. The IPv4
// link-local address is favored.
TEST_F(PacLibraryTest, PacMyIpAddressAllFailHasLinkLocalFavorIPv4) {}

// Tests myIpAddressEx() when there is a route to 8.8.8.8 but not one to
// 2001:4860:4860::8888
TEST_F(PacLibraryTest, PacMyIpAddressEx8888) {}

// Tests myIpAddressEx() when there is a route to 2001:4860:4860::8888 but
// not 8.8.8.8.
TEST_F(PacLibraryTest, PacMyIpAddressEx2001) {}

// Tests myIpAddressEx() when there is a route to both 8.8.8.8 and
// 2001:4860:4860::8888.
TEST_F(PacLibraryTest, PacMyIpAddressEx8888And2001) {}

// Tests myIpAddressEx() when there is no route to 8.8.8.8, no route to
// 2001:4860:4860::8888, however getaddrinfo(gethostname()) finds results. Some
// of those results are skipped due to being link-local and loopback.
TEST_F(PacLibraryTest, PacMyIpAddressExHostname) {}

// Tests myIpAddressEx() when routes are found for private IP space.
TEST_F(PacLibraryTest, PacMyIpAddressExPrivateDuplicates) {}

// Tests the same as above, but some of the connections complete asynchronously.
TEST_F(PacLibraryTest, PacMyIpAddressExPrivateDuplicatesAsyncConnect) {}

// Tests myIpAddressEx() when there are no routes, and
// getaddrinfo(gethostname()) fails.
TEST_F(PacLibraryTest, PacMyIpAddressExAllFail) {}

// Tests myIpAddressEx() when there are only IPv6 link-local address.
TEST_F(PacLibraryTest, PacMyIpAddressExAllFailHasLinkLocal) {}

// Tests myIpAddressEx() when there are only link-local addresses. The IPv4
// link-local address is favored.
TEST_F(PacLibraryTest, PacMyIpAddressExAllFailHasLinkLocalFavorIPv4) {}

// Tests myIpAddressEx() when there are no routes, and
// getaddrinfo(gethostname()) only returns loopback.
TEST_F(PacLibraryTest, PacMyIpAddressExAllFailOrLoopback) {}

TEST_F(PacLibraryTest, PacMyIpAddressExRunMultipleTimes) {}

TEST_F(PacLibraryTest, PacMyIpAddressExRunMultipleTimesAsync) {}

// Same as above but the connections complete asynchronously.
TEST_F(PacLibraryTest, PacMyIpAddressExAllFailOrLoopbackAsyncConnect) {}

// Tests that during async connect, MyIpAddressImpl can be deleted successfully.
TEST_F(PacLibraryTest, DeleteMyIpAddressImpl) {}

TEST_F(PacLibraryTest, ConnectMultipleRemotes) {}

// A clone of the above test that connects the second client after
// MyIpAddressImpl has lready started running.
TEST_F(PacLibraryTest, ConnectMultipleRemotesAsync) {}

// Connect multiple remotes, but one disconnects.
TEST_F(PacLibraryTest, ConnectMultipleRemotesOneDisconnects) {}

// Connect multiple remotes, but one disconnects.
TEST_F(PacLibraryTest, ConnectMultipleRemotesButAllDisconnect) {}

// Connect one remote, and during search, disconnect one remote but connect
// another.
TEST_F(PacLibraryTest, ConnectOneRemoteAndThenAnother) {}

}  // namespace
}  // namespace network