#include "services/network/proxy_resolver_factory_mojo.h"
#include <list>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/containers/queue.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/load_states.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/test_completion_callback.h"
#include "net/dns/mock_host_resolver.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_with_source.h"
#include "net/log/test_net_log.h"
#include "net/log/test_net_log_util.h"
#include "net/proxy_resolution/pac_file_data.h"
#include "net/proxy_resolution/proxy_info.h"
#include "net/proxy_resolution/proxy_resolve_dns_operation.h"
#include "net/proxy_resolution/proxy_resolver.h"
#include "net/proxy_resolution/proxy_resolver_error_observer.h"
#include "net/proxy_resolution/proxy_resolver_factory.h"
#include "net/test/event_waiter.h"
#include "net/test/gtest_util.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"
#include "url/gurl.h"
#include "url/origin.h"
IsError;
IsOk;
namespace network {
namespace {
const char kScriptData[] = …;
const char kExampleUrl[] = …;
struct CreateProxyResolverAction { … };
struct GetProxyForUrlAction { … };
class MockMojoProxyResolver : public proxy_resolver::mojom::ProxyResolver { … };
MockMojoProxyResolver::~MockMojoProxyResolver() { … }
MockMojoProxyResolver::MockMojoProxyResolver() = default;
void MockMojoProxyResolver::AddGetProxyAction(GetProxyForUrlAction action) { … }
void MockMojoProxyResolver::WaitForNextRequest() { … }
void MockMojoProxyResolver::WakeWaiter() { … }
void MockMojoProxyResolver::ClearBlockedClients() { … }
void MockMojoProxyResolver::AddConnection(
mojo::PendingReceiver<proxy_resolver::mojom::ProxyResolver> receiver) { … }
void MockMojoProxyResolver::GetProxyForUrl(
const GURL& url,
const net::NetworkAnonymizationKey& network_anonymization_key,
mojo::PendingRemote<proxy_resolver::mojom::ProxyResolverRequestClient>
pending_client) { … }
class Request { … };
Request::Request(net::ProxyResolver* resolver,
const GURL& url,
const net::NetworkAnonymizationKey& network_anonymization_key)
: … { … }
int Request::Resolve() { … }
void Request::Cancel() { … }
int Request::WaitForResult() { … }
class MockMojoProxyResolverFactory
: public proxy_resolver::mojom::ProxyResolverFactory { … };
MockMojoProxyResolverFactory::MockMojoProxyResolverFactory(
MockMojoProxyResolver* resolver,
mojo::PendingReceiver<proxy_resolver::mojom::ProxyResolverFactory> receiver)
: … { … }
MockMojoProxyResolverFactory::~MockMojoProxyResolverFactory() { … }
void MockMojoProxyResolverFactory::AddCreateProxyResolverAction(
CreateProxyResolverAction action) { … }
void MockMojoProxyResolverFactory::WaitForNextRequest() { … }
void MockMojoProxyResolverFactory::WakeWaiter() { … }
void MockMojoProxyResolverFactory::ClearBlockedClients() { … }
void MockMojoProxyResolverFactory::RespondToBlockedClientsWithResult(
net::Error error) { … }
void MockMojoProxyResolverFactory::CreateResolver(
const std::string& pac_script,
mojo::PendingReceiver<proxy_resolver::mojom::ProxyResolver> receiver,
mojo::PendingRemote<
proxy_resolver::mojom::ProxyResolverFactoryRequestClient>
pending_client) { … }
void DeleteResolverFactoryRequestCallback(
std::unique_ptr<net::ProxyResolverFactory::Request>* request,
net::CompletionOnceCallback callback,
int result) { … }
void CheckCapturedNetLogEntries(const std::string& expected_string,
const std::vector<net::NetLogEntry>& entries) { … }
}
class ProxyResolverFactoryMojoTest : public testing::Test { … };
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver) { … }
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver_Empty) { … }
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver_Url) { … }
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver_Failed) { … }
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver_BothDisconnected) { … }
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver_ClientDisconnected) { … }
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver_ResolverDisconnected) { … }
TEST_F(ProxyResolverFactoryMojoTest,
CreateProxyResolver_ResolverDisconnectedButClientSucceeded) { … }
TEST_F(ProxyResolverFactoryMojoTest,
CreateProxyResolver_ResolverDisconnected_DeleteRequestInCallback) { … }
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver_Cancel) { … }
TEST_F(ProxyResolverFactoryMojoTest, CreateProxyResolver_DnsRequest) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_MultipleResults) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_Error) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_Cancel) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_MultipleRequests) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_Disconnect) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_ClientClosed) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_DeleteInCallback) { … }
TEST_F(ProxyResolverFactoryMojoTest,
GetProxyForURL_DeleteInCallbackFromDisconnect) { … }
TEST_F(ProxyResolverFactoryMojoTest, GetProxyForURL_DnsRequest) { … }
TEST_F(ProxyResolverFactoryMojoTest,
GetProxyForURL_DnsRequestWithNetworkAnonymizationKey) { … }
TEST_F(ProxyResolverFactoryMojoTest, DeleteResolver) { … }
}