#include "chrome/browser/ui/user_education/recent_session_policy.h"
#include <sstream>
#include <vector>
#include "base/containers/map_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/user_education/browser_feature_promo_storage_service.h"
#include "chrome/browser/user_education/user_education_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
constexpr base::Time kNow = …;
RecentSessionData CreateSessionData(
const std::initializer_list<base::TimeDelta>& before_now,
const std::optional<base::TimeDelta>& since_enabled = base::Days(30)) { … }
Constraint;
ConstraintInfo;
ConstraintInfos;
constexpr char kTestHistogramName[] = …;
constexpr char kTestHistogramName2[] = …;
class MockConstraint : public Constraint { … };
StrictMockConstraint;
StrictMockConstraintPtr;
ConstraintInfo CreateMockConstraintInfo(StrictMockConstraintPtr& constraint,
std::string histogram_name,
std::optional<int> histogram_max,
std::optional<int> low_usage) { … }
}
class RecentSessionPolicyTest : public testing::Test { … };
TEST_F(RecentSessionPolicyTest,
ShouldEnableLowUsagePromoMode_SingleConstraint) { … }
TEST_F(RecentSessionPolicyTest,
ShouldEnableLowUsagePromoMode_MultipleConstraints) { … }
TEST_F(RecentSessionPolicyTest,
ShouldEnableLowUsagePromoMode_HistogramOnlyConstraint) { … }
TEST_F(RecentSessionPolicyTest, RecordRecentUsageMetrics_SingleHistogram) { … }
TEST_F(RecentSessionPolicyTest, RecordRecentUsageMetrics_TwoHistograms) { … }
TEST_F(RecentSessionPolicyTest, SessionCountConstraint) { … }
TEST_F(RecentSessionPolicyTest, ActiveDaysConstraint) { … }
TEST_F(RecentSessionPolicyTest, ActiveWeeksConstraint) { … }
TEST_F(RecentSessionPolicyTest, ActiveWeeksConstraintWithThreshold) { … }
TEST_F(RecentSessionPolicyTest,
ShouldEnableLowUsagePromoMode_OffWhenNotEnabledForLongEnough) { … }
TEST_F(RecentSessionPolicyTest,
ShouldEnableLowUsagePromoMode_OffMoreThanTwoActiveDays) { … }
TEST_F(RecentSessionPolicyTest, RecordRecentUsageMetrics_LessThanOneWeek) { … }
TEST_F(RecentSessionPolicyTest, RecordRecentUsageMetrics_MoreThanOneWeek) { … }
TEST_F(RecentSessionPolicyTest, RecordRecentUsageMetrics_FullPeriod) { … }
TEST_F(RecentSessionPolicyTest,
RecordRecentUsageMetrics_SuperActiveCountsDaysNotSessions) { … }
TEST_F(RecentSessionPolicyTest, RecordRecentUsageMetrics_DailyLimit) { … }
class RecentSessionPolicyFinchTest : public RecentSessionPolicyTest { … };
TEST_F(RecentSessionPolicyFinchTest, ChangeExistingThresholds) { … }
TEST_F(RecentSessionPolicyFinchTest, SwitchToNewThresholds) { … }
TEST_F(RecentSessionPolicyFinchTest, EnableSuperActiveThreshold) { … }