chromium/chrome/browser/ip_protection/ip_protection_config_provider_unittest.cc

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

#include "chrome/browser/ip_protection/ip_protection_config_provider.h"

#include <memory>
#include <optional>

#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/ip_protection/common/ip_protection_config_http.h"
#include "components/ip_protection/common/ip_protection_config_provider_helper.h"
#include "components/ip_protection/common/ip_protection_data_types.h"
#include "components/ip_protection/common/ip_protection_proxy_config_fetcher.h"
#include "components/ip_protection/common/mock_blind_sign_auth.h"
#include "components/prefs/testing_pref_service.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/privacy_sandbox/tracking_protection_settings.h"
#include "components/signin/public/identity_manager/account_capabilities_test_mutator.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/signin/public/identity_manager/primary_account_change_event.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_task_environment.h"
#include "net/third_party/quiche/src/quiche/blind_sign_auth/blind_sign_auth_interface.h"
#include "net/third_party/quiche/src/quiche/blind_sign_auth/proto/spend_token_data.pb.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/status/status.h"

BlindSignedAuthToken;
GeoHint;

namespace {

constexpr char kTryGetAuthTokensResultHistogram[] =;
constexpr char kOAuthTokenFetchHistogram[] =;
constexpr char kTokenBatchHistogram[] =;

constexpr char kTestEmail[] =;

class MockIpProtectionProxyConfigRetriever
    : public ip_protection::IpProtectionProxyConfigRetriever {};

enum class PrimaryAccountBehavior {};

}  // namespace

class IpProtectionConfigProviderTest : public testing::Test {};

// The success case: a primary account is available, and BSA gets a token for
// it.
TEST_F(IpProtectionConfigProviderTest, Success) {}

// BSA returns no tokens.
TEST_F(IpProtectionConfigProviderTest, NoTokens) {}

// BSA returns malformed tokens.
TEST_F(IpProtectionConfigProviderTest, MalformedTokens) {}

TEST_F(IpProtectionConfigProviderTest, TokenGeoHintContainsOnlyCountry) {}

TEST_F(IpProtectionConfigProviderTest, TokenHasMissingGeoHint) {}

// BSA returns a 400 error.
TEST_F(IpProtectionConfigProviderTest, BlindSignedTokenError400) {}

// BSA returns a 401 error.
TEST_F(IpProtectionConfigProviderTest, BlindSignedTokenError401) {}

// BSA returns a 403 error.
TEST_F(IpProtectionConfigProviderTest, BlindSignedTokenError403) {}

// BSA returns some other error.
TEST_F(IpProtectionConfigProviderTest, BlindSignedTokenErrorOther) {}

// The CanUseChromeIpProtection capability is not present (`kUnknown`).
TEST_F(IpProtectionConfigProviderTest, AccountCapabilityUnknown) {}

// Fetching OAuth token returns a transient error.
TEST_F(IpProtectionConfigProviderTest, AuthTokenTransientError) {}

// Fetching OAuth token returns a persistent error.
TEST_F(IpProtectionConfigProviderTest, AuthTokenPersistentError) {}

// No primary account.
TEST_F(IpProtectionConfigProviderTest, NoPrimary) {}

// TryGetAuthTokens() fails because IP Protection is disabled by user settings.
TEST_F(IpProtectionConfigProviderTest, TryGetAuthTokens_IpProtectionDisabled) {}

// No primary account initially but this changes when the account status
// changes.
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(IpProtectionConfigProviderTest, AccountLoginTriggersBackoffReset) {}
#endif

// If the account session token expires and is renewed, the persistent backoff
// should be cleared.
TEST_F(IpProtectionConfigProviderTest, SessionRefreshTriggersBackoffReset) {}

// Backoff calculations.
TEST_F(IpProtectionConfigProviderTest, CalculateBackoff) {}

TEST_F(IpProtectionConfigProviderTest, ProxyOverrideFlagsAll) {}

TEST_F(IpProtectionConfigProviderTest, GetProxyListFailure) {}

TEST_F(IpProtectionConfigProviderTest, GetProxyList_IpProtectionDisabled) {}

// Do a basic check of the token formats.
TEST_F(IpProtectionConfigProviderTest, TokenFormat) {}