chromium/net/reporting/reporting_cache_unittest.cc

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

#include "net/reporting/reporting_cache.h"

#include <string>
#include <utility>

#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/test/values_test_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "net/base/features.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/schemeful_site.h"
#include "net/reporting/mock_persistent_reporting_store.h"
#include "net/reporting/reporting_cache_impl.h"
#include "net/reporting/reporting_cache_observer.h"
#include "net/reporting/reporting_endpoint.h"
#include "net/reporting/reporting_report.h"
#include "net/reporting/reporting_target_type.h"
#include "net/reporting/reporting_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace net {
namespace {

CommandType;

class TestReportingCacheObserver : public ReportingCacheObserver {};

// The tests are parametrized on a boolean value which represents whether or not
// to use a MockPersistentReportingStore.
class ReportingCacheTest : public ReportingTestBase,
                           public ::testing::WithParamInterface<bool> {};

// Note: These tests exercise both sides of the cache (reports and clients),
// aside from header parsing (i.e. OnParsedHeader(), AddOrUpdate*(),
// Remove*OtherThan() methods) which are exercised in the unittests for the
// header parser.

TEST_P(ReportingCacheTest, Reports) {}

TEST_P(ReportingCacheTest, RemoveAllReports) {}

TEST_P(ReportingCacheTest, RemovePendingReports) {}

TEST_P(ReportingCacheTest, RemoveAllPendingReports) {}

TEST_P(ReportingCacheTest, GetReportsAsValue) {}

TEST_P(ReportingCacheTest, GetReportsToDeliverForSource) {}

TEST_P(ReportingCacheTest, Endpoints) {}

TEST_P(ReportingCacheTest, SetEnterpriseReportingEndpointsWithFeatureEnabled) {}

TEST_P(ReportingCacheTest, SetEnterpriseReportingEndpointsWithFeatureDisabled) {}

TEST_P(ReportingCacheTest, ReportingCacheImplConstructionWithFeatureEnabled) {}

TEST_P(ReportingCacheTest, ReportingCacheImplConstructionWithFeatureDisabled) {}

TEST_P(ReportingCacheTest, ClientsKeyedByEndpointGroupKey) {}

TEST_P(ReportingCacheTest, RemoveClientsForOrigin) {}

TEST_P(ReportingCacheTest, RemoveAllClients) {}

TEST_P(ReportingCacheTest, RemoveEndpointGroup) {}

TEST_P(ReportingCacheTest, RemoveEndpointsForUrl) {}

TEST_P(ReportingCacheTest, RemoveSourceAndEndpoints) {}

TEST_P(ReportingCacheTest, GetClientsAsValue) {}

TEST_P(ReportingCacheTest, GetCandidateEndpointsForDelivery) {}

TEST_P(ReportingCacheTest, GetCandidateEnterpriseEndpointsForDelivery) {}

TEST_P(ReportingCacheTest, GetCandidateEndpointsFromDocumentForDelivery) {}

// V1 reporting endpoints must not be returned in response to a request for
// endpoints for network reports (with no reporting source).
TEST_P(ReportingCacheTest, GetCandidateEndpointsFromDocumentForNetworkReports) {}

// V1 reporting endpoints must not be returned in response to a request for
// endpoints for a different source.
TEST_P(ReportingCacheTest, GetCandidateEndpointsFromDifferentDocument) {}

// When both V0 and V1 endpoints are present, V1 endpoints must only be
// returned when the reporting source matches. Only when no reporting source is
// given, or if there is no V1 endpoint with a matching source and name defined
// should a V0 endpoint be used.
TEST_P(ReportingCacheTest, GetMixedCandidateEndpointsForDelivery) {}

TEST_P(ReportingCacheTest, GetCandidateEndpointsDifferentNak) {}

TEST_P(ReportingCacheTest, GetCandidateEndpointsExcludesExpired) {}

TEST_P(ReportingCacheTest, ExcludeSubdomainsDifferentPort) {}

TEST_P(ReportingCacheTest, ExcludeSubdomainsSuperdomain) {}

TEST_P(ReportingCacheTest, IncludeSubdomainsDifferentPort) {}

TEST_P(ReportingCacheTest, IncludeSubdomainsSuperdomain) {}

TEST_P(ReportingCacheTest, IncludeSubdomainsPreferOriginToDifferentPort) {}

TEST_P(ReportingCacheTest, IncludeSubdomainsPreferOriginToSuperdomain) {}

TEST_P(ReportingCacheTest, IncludeSubdomainsPreferMoreSpecificSuperdomain) {}

TEST_P(ReportingCacheTest, IncludeSubdomainsPreserveNak) {}

TEST_P(ReportingCacheTest, EvictOldestReport) {}

TEST_P(ReportingCacheTest, DontEvictPendingReports) {}

TEST_P(ReportingCacheTest, EvictEndpointsOverPerOriginLimit) {}

TEST_P(ReportingCacheTest, EvictExpiredGroups) {}

TEST_P(ReportingCacheTest, EvictStaleGroups) {}

TEST_P(ReportingCacheTest, EvictFromStalestGroup) {}

TEST_P(ReportingCacheTest, EvictFromLargestGroup) {}

TEST_P(ReportingCacheTest, EvictLeastImportantEndpoint) {}

TEST_P(ReportingCacheTest, EvictEndpointsOverGlobalLimitFromStalestClient) {}

TEST_P(ReportingCacheTest, AddClientsLoadedFromStore) {}

TEST_P(ReportingCacheTest,
       AddStoredClientsWithDifferentNetworkAnonymizationKeys) {}

TEST_P(ReportingCacheTest, DoNotStoreMoreThanLimits) {}

TEST_P(ReportingCacheTest, DoNotLoadMismatchedGroupsAndEndpoints) {}

// This test verifies that we preserve the last_used field when storing clients
// loaded from disk. We don't have direct access into individual cache elements,
// so we test this indirectly by triggering a cache eviction and verifying that
// a stale element (i.e., one older than a week, by default) is selected for
// eviction. If last_used weren't populated then presumably that element
// wouldn't be evicted. (Or rather, it would only have a 25% chance of being
// evicted and this test would then be flaky.)
TEST_P(ReportingCacheTest, StoreLastUsedProperly) {}

TEST_P(ReportingCacheTest, DoNotAddDuplicatedEntriesFromStore) {}

TEST_P(ReportingCacheTest, GetIsolationInfoForEndpoint) {}

TEST_P(ReportingCacheTest, GetV1ReportingEndpointsForOrigin) {}

TEST_P(ReportingCacheTest, ReportingTargetType) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace
}  // namespace net