#include "services/network/ip_protection/ip_protection_token_cache_manager_impl.h"
#include <deque>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/strings/stringprintf.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 "net/base/features.h"
#include "services/network/ip_protection/ip_protection_config_cache.h"
#include "services/network/ip_protection/ip_protection_geo_utils.h"
#include "services/network/ip_protection/ip_protection_token_cache_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace network {
namespace {
constexpr char kGeoChangeTokenPresence[] = …;
BlindSignedAuthToken;
constexpr char kGetAuthTokenResultHistogram[] = …;
constexpr char kProxyATokenSpendRateHistogram[] = …;
constexpr char kProxyATokenExpirationRateHistogram[] = …;
constexpr char kProxyBTokenSpendRateHistogram[] = …;
constexpr char kProxyBTokenExpirationRateHistogram[] = …;
constexpr char kTokenBatchGenerationTimeHistogram[] = …;
constexpr char kGetAuthTokenResultForGeoHistogram[] = …;
constexpr base::TimeDelta kTokenLimitExceededDelay = …;
constexpr base::TimeDelta kTokenRateMeasurementInterval = …;
const bool kEnableTokenCacheByGeo = …;
const bool kDisableTokenCacheByGeo = …;
const ip_protection::GeoHint kMountainViewGeo = …;
const std::string kMountainViewGeoId = …;
const ip_protection::GeoHint kSunnyvaleGeo = …;
const std::string kSunnyvaleGeoId = …;
struct ExpectedTryGetAuthTokensCall { … };
class MockIpProtectionConfigGetter : public IpProtectionConfigGetter { … };
class MockIpProtectionConfigCache : public IpProtectionConfigCache { … };
struct HistogramState { … };
class IpProtectionTokenCacheManagerImplTest : public testing::Test { … };
TEST_F(IpProtectionTokenCacheManagerImplTest, IsAuthTokenAvailableFalseEmpty) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
IsAuthTokenAvailableFalseEmptyGeoCachingEnabled) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, IsAuthTokenAvailableTrue) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
IsAuthTokenAvailableTrueGeoCachingEnabled) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
IsAuthTokenAvailableFalseExpired) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
IsAuthTokenAvailableGeoCachingExpiration) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, GetAuthTokenEmpty) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, GetAuthTokenEmptyForGeo) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, GetAuthTokenSuccessful) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, GetAuthTokenForGeoSuccessful) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, GetAuthTokenForUnavailableGeo) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, GetAuthTokenFalseExpired) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, GetAuthTokenForGeoFalseExpired) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
CurrentGeoNoGeoCachingReturnsEarth) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
CurrentGeoTokensNotRequestedGeoCachingEnabledReturnsEmpty) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
CurrentGeoTokensFilledGeoCachingEnabledReturnsGeo) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, SmallBatch) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, ErrorBatch) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, SkipExpiredTokens) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, TokenExpirationFuzzed) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, NullGetter) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, ProxyATokenSpendRate) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, ProxyATokenExpirationRate) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, ProxyBTokenSpendRate) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, ProxyBTokenExpirationRate) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, Prefill) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, RefillLowWaterMark) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, RefillAfterBackoff) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest, RefillAfterExpiration) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
GeoChangeNewGeoAvailableForGetToken) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
GeoChangeOldGeoTokensStillUsable) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
SetCurrentGeoDifferentGeoRetrievesNewTokens) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
SetCurrentGeoNewTokensHaveSameGeo) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
GeoCachingFeatureDisabledSetCurrentGeoShortCircuits) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
GeoChangeFromWithinTokenManagerNewGeoAlreadyHasTokensPresent) { … }
TEST_F(IpProtectionTokenCacheManagerImplTest,
GeoChangeFromOutsideTokenManagerNewGeoAlreadyHasTokensPresent) { … }
}
}