From 448904159a99cad3b64306ebb536f9aeea400fcd Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Mon, 18 Nov 2024 13:03:53 -0500 Subject: [PATCH] [ads] Add SmartNTT epoch condition matcher defaults --- .../condition_matcher_util.cc | 9 +++++++++ .../condition_matcher_util_unittest.cc | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util.cc b/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util.cc index 9270c2bddef6..2b5228ff4555 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util.cc +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util.cc @@ -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); diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util_unittest.cc b/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util_unittest.cc index 0eb8bfd03c5b..18463be3e196 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util_unittest.cc +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util_unittest.cc @@ -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)); @@ -89,7 +97,7 @@ TEST_F(BraveAdsConditionMatcherUtilTest, MatchNumericalEqualOperatorCondition) { } TEST_F(BraveAdsConditionMatcherUtilTest, - MatchNumericalhEqualOperatorConditionForUnknownPrefPath) { + MatchNumericalEqualOperatorConditionForUnknownPrefPath) { // Arrange const ConditionMatcherMap condition_matchers = { {"unknown_pref_path", "[R=]:0"}}; @@ -99,7 +107,7 @@ TEST_F(BraveAdsConditionMatcherUtilTest, } TEST_F(BraveAdsConditionMatcherUtilTest, - DoNotMatchNumericalhEqualOperatorConditionForUnknownPrefPath) { + DoNotMatchNumericalEqualOperatorConditionForUnknownPrefPath) { // Arrange const ConditionMatcherMap condition_matchers = { {"unknown_pref_path", "[R=]:1"}};