#include "components/affiliations/core/browser/affiliation_backend.h"
#include <stddef.h>
#include <memory>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/test/test_simple_task_runner.h"
#include "base/time/clock.h"
#include "base/time/tick_clock.h"
#include "components/affiliations/core/browser/affiliation_database.h"
#include "components/affiliations/core/browser/affiliation_fetch_throttler.h"
#include "components/affiliations/core/browser/affiliation_fetch_throttler_delegate.h"
#include "components/affiliations/core/browser/affiliation_utils.h"
#include "components/affiliations/core/browser/facet_manager.h"
#include "components/affiliations/core/browser/fake_affiliation_api.h"
#include "components/affiliations/core/browser/mock_affiliation_consumer.h"
#include "components/variations/scoped_variations_ids_provider.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_network_connection_tracker.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace affiliations {
namespace {
StrategyOnCacheMiss;
class MockAffiliationFetchThrottler : public AffiliationFetchThrottler { … };
const char kTestFacetURIAlpha1[] = …;
const char kTestFacetURIAlpha2[] = …;
const char kTestFacetURIAlpha3[] = …;
const char kTestFacetURIAlpha4[] = …;
const char kTestFacetNameAlpha4[] = …;
const char kTestFacetIconURLAlpha4[] = …;
const char kTestFacetURIBeta1[] = …;
const char kTestFacetURIBeta2[] = …;
const char kTestFacetURIGamma1[] = …;
AffiliatedFacets GetTestEquivalenceClassAlpha() { … }
AffiliatedFacets GetTestEquivalenceClassBeta() { … }
AffiliatedFacets GetTestEquivalenceClassGamma() { … }
GroupedFacets GetTestGropingAlpha() { … }
GroupedFacets GetTestGropingBeta() { … }
base::TimeDelta GetCacheHardExpiryPeriod() { … }
base::TimeDelta GetCacheSoftExpiryPeriod() { … }
base::TimeDelta GetShortTestPeriod() { … }
base::TimeDelta Epsilon() { … }
}
class AffiliationBackendTest : public testing::Test { … };
TEST_F(AffiliationBackendTest, OnDemandRequestSucceedsWithFetch) { … }
TEST_F(AffiliationBackendTest, CachedOnlyRequestFailsDueToCacheMiss) { … }
TEST_F(AffiliationBackendTest, PrefetchTriggersInitialFetch) { … }
TEST_F(AffiliationBackendTest, ExpiredPrefetchTriggersNoInitialFetch) { … }
TEST_F(AffiliationBackendTest, ConcurrentUnrelatedRequests) { … }
TEST_F(AffiliationBackendTest, ConcurrentUnrelatedRequests2) { … }
TEST_F(AffiliationBackendTest, RetryIsMadeOnFailedFetch) { … }
TEST_F(AffiliationBackendTest, FetchIsNoLongerNeededOnceAllowed) { … }
TEST_F(AffiliationBackendTest, CacheServesSubsequentRequestForSameFacet) { … }
TEST_F(AffiliationBackendTest, CacheServesSubsequentRequestForAffiliatedFacet) { … }
TEST_F(AffiliationBackendTest, CacheServesRequestsForPrefetchedFacets) { … }
TEST_F(AffiliationBackendTest,
CacheServesRequestsForFacetsAffiliatedWithPrefetchedFacets) { … }
TEST_F(AffiliationBackendTest,
CacheServesConcurrentRequestsForAffiliatedFacets) { … }
TEST_F(AffiliationBackendTest,
CacheServesConcurrentPrefetchesForAffiliatedFacets) { … }
TEST_F(AffiliationBackendTest, SimpleCacheExpiryWithoutPrefetches) { … }
TEST_F(AffiliationBackendTest,
PrefetchTriggersOneInitialFetchAndOneRefetchBeforeExpiring) { … }
TEST_F(AffiliationBackendTest, PrefetchTriggersPeriodicRefetch) { … }
TEST_F(AffiliationBackendTest,
PrefetchTriggersNoInitialFetchIfDataIsAlreadyFresh) { … }
TEST_F(AffiliationBackendTest, CancelPrefetch) { … }
TEST_F(AffiliationBackendTest, CancelDuplicatePrefetch) { … }
TEST_F(AffiliationBackendTest, CancelingNonExistingPrefetchIsSilentlyIgnored) { … }
TEST_F(AffiliationBackendTest,
TrimCacheForFacetURIOnlyRemovesDataForTheGivenFacet) { … }
TEST_F(AffiliationBackendTest, NothingExplodesWhenShutDownDuringFetch) { … }
TEST_F(AffiliationBackendTest,
FailureCallbacksAreCalledIfBackendIsDestroyedWithPendingRequest) { … }
TEST_F(AffiliationBackendTest, DeleteCache) { … }
TEST_F(AffiliationBackendTest, KeepPrefetchForFacets) { … }
TEST_F(AffiliationBackendTest, GetGroupingWith) { … }
TEST_F(AffiliationBackendTest, SingleGroupForAffiliatedFacets) { … }
TEST_F(AffiliationBackendTest, UpdateAffiliationsAndBrandingClearsOldCache) { … }
TEST_F(AffiliationBackendTest, UpdateAffiliationsAndBrandingSuccess) { … }
TEST_F(AffiliationBackendTest, UpdateAffiliationsAndBrandingFailure) { … }
TEST_F(AffiliationBackendTest, UpdateAffiliationsAndBrandingFailsIfNoInternet) { … }
TEST_F(AffiliationBackendTest, GetGroupingInfoInjectsGroupsForMissingFacets) { … }
TEST_F(AffiliationBackendTest, GetGroupingInfoWithDuplicates) { … }
TEST_F(AffiliationBackendTest, GetGroupingInfoForInvalidFacet) { … }
TEST_F(AffiliationBackendTest,
UpdateAffiliationsAndBrandingSkipsInvalidFacets) { … }
TEST_F(AffiliationBackendTest, GroupsUpdatedByMainDomain) { … }
}