chromium/components/browsing_topics/browsing_topics_service_impl_unittest.cc

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

#include "components/browsing_topics/browsing_topics_service_impl.h"

#include "base/files/scoped_temp_dir.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/values_util.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/strcat.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 "components/browsing_topics/test_util.h"
#include "components/browsing_topics/util.h"
#include "components/content_settings/browser/page_specific_content_settings.h"
#include "components/content_settings/browser/test_page_specific_content_settings_delegate.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/history/core/browser/history_database_params.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/test/test_history_database.h"
#include "components/privacy_sandbox/privacy_sandbox_attestations/privacy_sandbox_attestations.h"
#include "components/privacy_sandbox/privacy_sandbox_attestations/scoped_privacy_sandbox_attestations.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/privacy_sandbox/privacy_sandbox_settings_impl.h"
#include "components/privacy_sandbox/privacy_sandbox_test_util.h"
#include "components/privacy_sandbox/tracking_protection_settings.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/browsing_topics_site_data_manager.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/test/browsing_topics_test_util.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/web_contents_tester.h"
#include "content/test/test_render_view_host.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/mojom/browsing_topics/browsing_topics.mojom.h"

namespace browsing_topics {

namespace {

// Tests can be slow if `TaskEnvironment::FastForwardBy()` is called with a long
// period of time. Thus, use `base::Seconds(1)` as the duration of a day in
// tests.
constexpr base::TimeDelta kOneTestDay =;
constexpr base::TimeDelta kEpoch =;
constexpr base::TimeDelta kMaxEpochIntroductionDelay =;

constexpr base::TimeDelta kDatabaseFetchDelay =;
constexpr base::TimeDelta kCalculatorDelay =;
constexpr base::TimeDelta kFirstTimeoutRetryDelay =;

constexpr browsing_topics::HmacKey kTestKey =;

constexpr base::Time kTime1 =;
constexpr base::Time kTime2 =;
constexpr base::Time kTime3 =;

constexpr int kConfigVersion =;
constexpr int kTaxonomyVersion =;
constexpr int64_t kModelVersion =;

EpochTopics CreateTestEpochTopics(
    const std::vector<std::pair<Topic, std::set<HashedDomain>>>& topics,
    base::Time calculation_time,
    size_t padded_top_topics_start_index = 5,
    int64_t model_version = kModelVersion,
    int config_version = kConfigVersion) {}

}  // namespace

// A tester class that allows mocking the topics calculators (i.e. the result
// and the finish delay).
class TesterBrowsingTopicsService : public BrowsingTopicsServiceImpl {};

class BrowsingTopicsServiceImplTest
    : public content::RenderViewHostTestHarness {};

TEST_F(BrowsingTopicsServiceImplTest, EmptyInitialState_CalculationScheduling) {}

TEST_F(BrowsingTopicsServiceImplTest, WallTimeScheduling) {}

TEST_F(BrowsingTopicsServiceImplTest,
       StartFromPreexistingState_CalculateAtScheduledTime) {}

TEST_F(BrowsingTopicsServiceImplTest,
       StartFromPreexistingState_CalculateAtScheduledTime_FailedCalculation) {}

TEST_F(
    BrowsingTopicsServiceImplTest,
    StartFromPreexistingState_ScheduledTimeReachedBeforeStartup_CalculateImmediately) {}

TEST_F(
    BrowsingTopicsServiceImplTest,
    StartFromPreexistingState_TopicsAccessibleSinceUpdated_ResetStateAndStorage_CalculateAtScheduledTime) {}

TEST_F(
    BrowsingTopicsServiceImplTest,
    StartFromPreexistingState_UnexpectedNextCalculationDelay_ResetState_CalculateImmediately) {}

TEST_F(BrowsingTopicsServiceImplTest,
       StartFromPreexistingState_DefaultHandlingBeforeLoadFinish) {}

TEST_F(BrowsingTopicsServiceImplTest,
       StartFromPreexistingState_DataDeletionOnCalculation) {}

TEST_F(
    BrowsingTopicsServiceImplTest,
    OnTopicsDataAccessibleSinceUpdated_ResetState_ClearTopicsSiteDataStorage) {}

TEST_F(BrowsingTopicsServiceImplTest, TimeoutRetry_Success) {}

TEST_F(BrowsingTopicsServiceImplTest, TimeoutRetry_TimeoutAgain) {}

TEST_F(BrowsingTopicsServiceImplTest, TimeoutRetry_SuccessiveTimeout) {}

TEST_F(BrowsingTopicsServiceImplTest,
       TimeoutRetry_InterruptedByHistoryDeletion) {}

TEST_F(BrowsingTopicsServiceImplTest,
       OnURLsDeleted_TimeRangeOverlapWithOneEpoch) {}

TEST_F(BrowsingTopicsServiceImplTest,
       OnURLsDeleted_TimeRangeOverlapWithAllEpochs) {}

TEST_F(BrowsingTopicsServiceImplTest, Recalculate) {}

TEST_F(BrowsingTopicsServiceImplTest,
       HandleTopicsWebApi_PrivacySandboxSettingsDisabled) {}

TEST_F(BrowsingTopicsServiceImplTest, HandleTopicsWebApi_OneEpoch) {}

TEST_F(BrowsingTopicsServiceImplTest,
       HandleTopicsWebApi_EpochConfigVersionDifferentFromCurrent) {}

TEST_F(BrowsingTopicsServiceImplTest,
       HandleTopicsWebApi_TwoEpochsWithDifferentConfigVersions) {}

TEST_F(BrowsingTopicsServiceImplTest, HandleTopicsWebApi_OneEpoch_Filtered) {}

TEST_F(BrowsingTopicsServiceImplTest,
       HandleTopicsWebApi_TopicNotAllowedByPrivacySandboxSettings) {}

TEST_F(BrowsingTopicsServiceImplTest, HandleTopicsWebApi_FourEpochs) {}

TEST_F(BrowsingTopicsServiceImplTest,
       HandleTopicsWebApi_DuplicateTopicsRemoved) {}

TEST_F(BrowsingTopicsServiceImplTest,
       HandleTopicsWebApi_TopicsReturnedInSortedOrder) {}

TEST_F(BrowsingTopicsServiceImplTest,
       HandleTopicsWebApi_TopicsReturnedInSortedOrder_DifferentVersions) {}

TEST_F(BrowsingTopicsServiceImplTest, NumVersionsInEpochs_OneVerison) {}

TEST_F(BrowsingTopicsServiceImplTest,
       NumVersionsInEpochs_ThreeVerisons_ClearedTopics) {}

TEST_F(BrowsingTopicsServiceImplTest, HandleTopicsWebApi_TrackedUsageContext) {}

TEST_F(BrowsingTopicsServiceImplTest, HandleTopicsWebApi_DoesNotObserve) {}

TEST_F(BrowsingTopicsServiceImplTest, HandleTopicsWebApi_DoesNotGetTopics) {}

TEST_F(
    BrowsingTopicsServiceImplTest,
    HandleTopicsWebApi_DoesNotGetTopics_SettingsDisabled_NoApiResultUkmEvent) {}

TEST_F(BrowsingTopicsServiceImplTest, ApiResultUkm_ZeroAndOneTopic) {}

TEST_F(BrowsingTopicsServiceImplTest, ApiResultUkm_3Topics) {}

TEST_F(BrowsingTopicsServiceImplTest, GetTopTopicsForDisplay) {}

TEST_F(BrowsingTopicsServiceImplTest,
       GetBrowsingTopicsStateForWebUi_CalculationInProgress) {}

TEST_F(BrowsingTopicsServiceImplTest,
       GetBrowsingTopicsStateForWebUi_CalculationNow) {}

TEST_F(BrowsingTopicsServiceImplTest, GetBrowsingTopicsStateForWebUi) {}

TEST_F(BrowsingTopicsServiceImplTest, ClearTopic) {}

TEST_F(BrowsingTopicsServiceImplTest, BlockTopicWithFinch) {}

TEST_F(BrowsingTopicsServiceImplTest, ClearTopicBeforeLoadFinish) {}

TEST_F(BrowsingTopicsServiceImplTest, ClearAllTopicsData) {}

TEST_F(BrowsingTopicsServiceImplTest, ClearTopicsDataForOrigin) {}

TEST_F(BrowsingTopicsServiceImplTest, MethodsFailGracefullyAfterShutdown) {}

}  // namespace browsing_topics