Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ads] Add SmartNTT epoch condition matcher defaults #26612

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ bool MatchConditions(const PrefProviderInterface* const pref_provider,
return !value;
}

if (IsEpochOperator(condition)) {
// Default to now if the pref path does not exist.
return MatchCondition(value.value_or(base::NumberToString(
base::Time::Now()
.ToDeltaSinceWindowsEpoch()
.InMicroseconds())),
condition);
}

if (IsNumericalOperator(condition)) {
// Default to "0" if the pref path does not exist.
return MatchCondition(value.value_or("0"), condition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,20 @@ TEST_F(BraveAdsConditionMatcherUtilTest, MatchEpochEqualOperatorCondition) {
}

TEST_F(BraveAdsConditionMatcherUtilTest,
DoNotMatchEpochEqualOperatorConditionForUnknownPrefPath) {
MatchEpochEqualOperatorConditionForUnknownPrefPath) {
// Arrange
const ConditionMatcherMap condition_matchers = {
{"unknown_pref_path", "[T=]:7"}};
{"unknown_pref_path", "[T=]:0"}};

AdvanceClockBy(base::Days(7) - base::Milliseconds(1));
// Act & Assert
EXPECT_TRUE(MatchConditions(&pref_provider_, condition_matchers));
}

TEST_F(BraveAdsConditionMatcherUtilTest,
DoNotMatchEpochEqualOperatorConditionForUnknownPrefPath) {
// Arrange
const ConditionMatcherMap condition_matchers = {
{"unknown_pref_path", "[T=]:1"}};

// Act & Assert
EXPECT_FALSE(MatchConditions(&pref_provider_, condition_matchers));
Expand Down Expand Up @@ -89,7 +97,7 @@ TEST_F(BraveAdsConditionMatcherUtilTest, MatchNumericalEqualOperatorCondition) {
}

TEST_F(BraveAdsConditionMatcherUtilTest,
MatchNumericalhEqualOperatorConditionForUnknownPrefPath) {
MatchNumericalEqualOperatorConditionForUnknownPrefPath) {
// Arrange
const ConditionMatcherMap condition_matchers = {
{"unknown_pref_path", "[R=]:0"}};
Expand All @@ -99,7 +107,7 @@ TEST_F(BraveAdsConditionMatcherUtilTest,
}

TEST_F(BraveAdsConditionMatcherUtilTest,
DoNotMatchNumericalhEqualOperatorConditionForUnknownPrefPath) {
DoNotMatchNumericalEqualOperatorConditionForUnknownPrefPath) {
// Arrange
const ConditionMatcherMap condition_matchers = {
{"unknown_pref_path", "[R=]:1"}};
Expand Down
Loading