#include "components/browsing_topics/browsing_topics_state.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/values_util.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/browsing_topics/util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
namespace browsing_topics {
namespace {
constexpr base::Time kTime1 = …;
constexpr base::Time kTime2 = …;
constexpr base::Time kTime3 = …;
constexpr base::Time kTime4 = …;
constexpr base::Time kTime5 = …;
constexpr browsing_topics::HmacKey kZeroKey = …;
constexpr browsing_topics::HmacKey kTestKey = …;
constexpr browsing_topics::HmacKey kTestKey2 = …;
constexpr int kConfigVersion = …;
constexpr int kTaxonomyVersion = …;
constexpr int64_t kModelVersion = …;
constexpr size_t kPaddedTopTopicsStartIndex = …;
constexpr base::TimeDelta kNextScheduledCalculationDelay = …;
EpochTopics CreateTestEpochTopics(base::Time calculation_time,
bool from_manually_triggered_calculation,
int config_version = kConfigVersion) { … }
}
class BrowsingTopicsStateTest : public testing::Test { … };
TEST_F(BrowsingTopicsStateTest, InitFromNoFile_SaveToDiskAfterDelay) { … }
TEST_F(BrowsingTopicsStateTest,
UpdateNextScheduledCalculationTime_SaveToDiskAfterDelay) { … }
TEST_F(BrowsingTopicsStateTest, AddEpoch) { … }
TEST_F(BrowsingTopicsStateTest, EpochsForSite_Empty) { … }
TEST_F(BrowsingTopicsStateTest, EpochsForSite_OneEpoch_SwitchTimeNotArrived) { … }
TEST_F(BrowsingTopicsStateTest, EpochsForSite_OneEpoch_SwitchTimeArrived) { … }
TEST_F(BrowsingTopicsStateTest, EpochsForSite_OneEpoch_ManuallyTriggered) { … }
TEST_F(BrowsingTopicsStateTest,
EpochsForSite_ThreeEpochs_SwitchTimeNotArrived) { … }
TEST_F(BrowsingTopicsStateTest, EpochsForSite_ThreeEpochs_SwitchTimeArrived) { … }
TEST_F(BrowsingTopicsStateTest,
EpochsForSite_ThreeEpochs_LatestManuallyTriggered) { … }
TEST_F(BrowsingTopicsStateTest,
EpochsForSite_ThreeEpochs_EarlierEpochManuallyTriggered) { … }
TEST_F(BrowsingTopicsStateTest, EpochsForSite_FourEpochs_SwitchTimeNotArrived) { … }
TEST_F(BrowsingTopicsStateTest, EpochsForSite_FourEpochs_SwitchTimeArrived) { … }
TEST_F(BrowsingTopicsStateTest,
EpochsForSite_FourEpochs_LatestManuallyTriggered) { … }
TEST_F(BrowsingTopicsStateTest,
EpochsForSite_FourEpochs_EarlierEpochManuallyTriggered) { … }
TEST_F(BrowsingTopicsStateTest, InitFromPreexistingFile_CorruptedHmacKey) { … }
TEST_F(BrowsingTopicsStateTest, InitFromPreexistingFile_SameConfigVersion) { … }
TEST_F(BrowsingTopicsStateTest,
InitFromPreexistingFile_ForwardCompatibleConfigVersion) { … }
TEST_F(BrowsingTopicsStateTest,
InitFromPreexistingFile_BackwardCompatibleConfigVersion) { … }
TEST_F(BrowsingTopicsStateTest,
InitFromPreexistingFile_IncompatibleConfigVersion) { … }
TEST_F(BrowsingTopicsStateTest, ClearOneEpoch) { … }
TEST_F(BrowsingTopicsStateTest, ClearAllTopics) { … }
TEST_F(BrowsingTopicsStateTest, ClearTopic) { … }
TEST_F(BrowsingTopicsStateTest, ClearContextDomain) { … }
TEST_F(BrowsingTopicsStateTest, ShouldSaveFileDespiteShutdownWhileScheduled) { … }
}