chromium/services/network/ip_protection/ip_protection_proxy_delegate_unittest.cc

// Copyright 2024 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/ip_protection/ip_protection_proxy_delegate.h"

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/ip_protection/common/ip_protection_data_types.h"
#include "components/ip_protection/common/ip_protection_telemetry.h"
#include "components/ip_protection/common/masked_domain_list_manager.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_string_util.h"
#include "net/proxy_resolution/proxy_info.h"
#include "net/test/gtest_util.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_test_util.h"
#include "services/network/ip_protection/ip_protection_config_cache_impl.h"
#include "services/network/ip_protection/ip_protection_proxy_list_manager.h"
#include "services/network/ip_protection/ip_protection_token_cache_manager.h"
#include "services/network/public/cpp/features.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

IsError;
IsOk;

namespace network {
namespace {

MaskedDomainListManager;
ProtectionEligibility;

constexpr char kHttpsUrl[] =;
constexpr char kHttpUrl[] =;
constexpr char kLocalhost[] =;

constexpr char kEligibilityHistogram[] =;
constexpr char kAreAuthTokensAvailableHistogram[] =;
constexpr char kIsProxyListAvailableHistogram[] =;
constexpr char kAvailabilityHistogram[] =;

class MockIpProtectionConfigCache : public IpProtectionConfigCache {};

}  // namespace

MATCHER_P2(Contain,
           expected_name,
           expected_value,
           std::string("headers ") + (negation ? "don't " : "") + "contain '" +
               expected_name + ": " + expected_value + "'") {}

struct HeadersReceived {};

class TestCustomProxyConnectionObserver
    : public mojom::CustomProxyConnectionObserver {};

class IpProtectionProxyDelegateTest : public testing::Test {};

TEST_F(IpProtectionProxyDelegateTest, AddsTokenToTunnelRequest) {}

TEST_F(IpProtectionProxyDelegateTest, ErrorIfConnectionWithNoTokens) {}

TEST_F(IpProtectionProxyDelegateTest, AddsDebugExperimentArm) {}

TEST_F(IpProtectionProxyDelegateTest, OnResolveProxyDeprioritizesBadProxies) {}

TEST_F(IpProtectionProxyDelegateTest, OnResolveProxyAllProxiesBad) {}

TEST_F(IpProtectionProxyDelegateTest,
       OnResolveProxyMaskedDomainListManagerMatch) {}

TEST_F(IpProtectionProxyDelegateTest,
       OnResolveProxyMaskedDomainListManagerMatch_DirectOnly) {}

TEST_F(IpProtectionProxyDelegateTest,
       OnResolveProxyMaskedDomainListManagerDoesNotMatch_FirstPartyException) {}

TEST_F(IpProtectionProxyDelegateTest, OnResolveProxy_NoAuthToken) {}

TEST_F(IpProtectionProxyDelegateTest, OnResolveProxy_NoProxyList) {}

TEST_F(IpProtectionProxyDelegateTest, OnResolveProxy_IpProtectionDisabled) {}

// When URLs do not match the allow list, the result is direct and not flagged
// as for IP protection.
TEST_F(IpProtectionProxyDelegateTest, OnResolveProxyIpProtectionNoMatch) {}

// If the allowlist is empty, this suggests it hasn't yet been populated and
// thus we don't really know whether the request is supposed to be eligible or
// not.
TEST_F(IpProtectionProxyDelegateTest,
       OnResolveProxyIpProtectionNoMatch_UnpopulatedAllowList) {}

// When the URL is HTTP and multi-proxy chains are used, the result is flagged
// as for IP protection and is not direct.
TEST_F(IpProtectionProxyDelegateTest,
       OnResolveProxyIpProtectionMultiProxyHttpSuccess) {}

// When URLs match the allow list, and a token is available, the result is
// flagged as for IP protection and is not direct.
TEST_F(IpProtectionProxyDelegateTest, OnResolveProxyIpProtectionSuccess) {}

TEST_F(IpProtectionProxyDelegateTest, OnSuccessfulRequestAfterFailures) {}

TEST_F(IpProtectionProxyDelegateTest, OnFallback) {}

TEST_F(IpProtectionProxyDelegateTest, MergeProxyRules) {}

TEST_F(IpProtectionProxyDelegateTest, InvalidateTryAgainAfterTime) {}

}  // namespace network