#include "components/safe_browsing/core/browser/hashprefix_realtime/ohttp_key_service.h"
#include <memory>
#include "base/functional/bind.h"
#include "base/strings/escape.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/hashprefix_realtime/hash_realtime_utils.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/variations/pref_names.h"
#include "google_apis/google_api_keys.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
Eq;
Optional;
namespace safe_browsing {
namespace {
constexpr char kTestOhttpKey[] = …;
constexpr char kEncodedTestOhttpKey[] = …;
constexpr char kTestOldOhttpKey[] = …;
constexpr char kTestNewOhttpKey[] = …;
constexpr char kExpectedKeyFetchServerUrl[] = …;
scoped_refptr<net::HttpResponseHeaders> CreateSuccessHeaders() { … }
scoped_refptr<net::HttpResponseHeaders> CreateKeyRotatedHeaders() { … }
}
class OhttpKeyServiceTest : public ::testing::Test { … };
class OhttpKeyServiceFeatureOffTest : public OhttpKeyServiceTest { … };
class OhttpKeyServiceLocationDisabledTest : public OhttpKeyServiceTest { … };
class OhttpKeyServiceFastKeyRotationDisabledTest : public OhttpKeyServiceTest { … };
TEST_F(OhttpKeyServiceTest, GetOhttpKey_Success) { … }
TEST_F(OhttpKeyServiceTest, GetOhttpKey_Failure) { … }
TEST_F(OhttpKeyServiceTest, GetOhttpKey_Backoff) { … }
TEST_F(OhttpKeyServiceTest, GetOhttpKey_MultipleRequests) { … }
TEST_F(OhttpKeyServiceTest, GetOhttpKey_WithValidCache) { … }
TEST_F(OhttpKeyServiceTest, GetOhttpKey_WithExpiredCache) { … }
TEST_F(OhttpKeyServiceTest, GetOhttpKey_SafeBrowsingDisabled) { … }
TEST_F(OhttpKeyServiceLocationDisabledTest, GetOhttpKey_LocationDisabled) { … }
TEST_F(OhttpKeyServiceFeatureOffTest, GetOhttpKey_FeatureDisabled) { … }
TEST_F(OhttpKeyServiceLocationDisabledTest, GetOhttpKey_FreshnessHistogram) { … }
TEST_F(OhttpKeyServiceTest, PopulateKeyFromPref_ValidKey) { … }
TEST_F(OhttpKeyServiceTest, PopulateKeyFromPref_EmptyKey) { … }
TEST_F(OhttpKeyServiceTest, AsyncFetch) { … }
TEST_F(OhttpKeyServiceTest, AsyncFetch_PrefChanges) { … }
TEST_F(OhttpKeyServiceTest, AsyncFetch_Backoff) { … }
TEST_F(OhttpKeyServiceTest, AsyncFetch_RescheduledBasedOnBackoffRemainingTime) { … }
TEST_F(OhttpKeyServiceTest, NotifyLookupResponse_SuccessFetch) { … }
TEST_F(OhttpKeyServiceTest, NotifyLookupResponse_HeaderHint) { … }
TEST_F(OhttpKeyServiceTest, NotifyLookupResponse_HeaderHintOnDifferentKey) { … }
TEST_F(OhttpKeyServiceTest, NotifyLookupResponse_HeaderHintWithError) { … }
TEST_F(OhttpKeyServiceTest, NotifyLookupResponse_KeyRelatedHttpFailure) { … }
TEST_F(OhttpKeyServiceTest, NotifyLookupResponse_Backoff) { … }
TEST_F(OhttpKeyServiceTest,
NotifyLookupResponse_LogFirstLookupResponseHistogram) { … }
TEST_F(OhttpKeyServiceTest, Shutdown) { … }
TEST_F(OhttpKeyServiceFastKeyRotationDisabledTest, NoFastRotationHeader) { … }
TEST_F(OhttpKeyServiceFastKeyRotationDisabledTest, AsyncFetch) { … }
}