diff --git a/components/brave_ads/test/BUILD.gn b/components/brave_ads/test/BUILD.gn index c80c876daf6d..ff49e52380a4 100644 --- a/components/brave_ads/test/BUILD.gn +++ b/components/brave_ads/test/BUILD.gn @@ -90,7 +90,6 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_features_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_features_util_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads_unittest.cc", diff --git a/vendor/bat-native-ads/BUILD.gn b/vendor/bat-native-ads/BUILD.gn index 023454ed945c..91172274e341 100644 --- a/vendor/bat-native-ads/BUILD.gn +++ b/vendor/bat-native-ads/BUILD.gn @@ -281,6 +281,8 @@ source_set("ads") { "src/bat/ads/internal/ads/ad_notifications/ad_notification_permission_rules.h", "src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc", "src/bat/ads/internal/ads/ad_notifications/ad_notifications.h", + "src/bat/ads/internal/ads/exclusion_rules_base.cc", + "src/bat/ads/internal/ads/exclusion_rules_base.h", "src/bat/ads/internal/ads/inline_content_ads/inline_content_ad.cc", "src/bat/ads/internal/ads/inline_content_ads/inline_content_ad.h", "src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_builder.cc", @@ -492,7 +494,6 @@ source_set("ads") { "src/bat/ads/internal/database/tables/geo_targets_database_table.h", "src/bat/ads/internal/database/tables/segments_database_table.cc", "src/bat/ads/internal/database/tables/segments_database_table.h", - "src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h", "src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.cc", "src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.h", "src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_factory.cc", @@ -503,6 +504,8 @@ source_set("ads") { "src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.h", "src/bat/ads/internal/eligible_ads/ad_predictor_info.cc", "src/bat/ads/internal/eligible_ads/ad_predictor_info.h", + "src/bat/ads/internal/eligible_ads/choose_ad.h", + "src/bat/ads/internal/eligible_ads/eligible_ads_aliases.h", "src/bat/ads/internal/eligible_ads/eligible_ads_aliases.h", "src/bat/ads/internal/eligible_ads/eligible_ads_constants.h", "src/bat/ads/internal/eligible_ads/eligible_ads_features.cc", @@ -510,9 +513,7 @@ source_set("ads") { "src/bat/ads/internal/eligible_ads/eligible_ads_features_util.cc", "src/bat/ads/internal/eligible_ads/eligible_ads_features_util.h", "src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h", - "src/bat/ads/internal/eligible_ads/eligible_ads_util.h", - "src/bat/ads/internal/eligible_ads/eligible_ads_util_aliases.h", - "src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h", + "src/bat/ads/internal/eligible_ads/frequency_capping.h", "src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.cc", "src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.h", "src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_factory.cc", diff --git a/vendor/bat-native-ads/data/test/database_schema_17.sqlite b/vendor/bat-native-ads/data/test/database_schema_17.sqlite new file mode 100644 index 000000000000..5b847fa1810c Binary files /dev/null and b/vendor/bat-native-ads/data/test/database_schema_17.sqlite differ diff --git a/vendor/bat-native-ads/src/bat/ads/ad_event_history_unittest.cc b/vendor/bat-native-ads/src/bat/ads/ad_event_history_unittest.cc index a121cb2678c8..c1acbb2217ab 100644 --- a/vendor/bat-native-ads/src/bat/ads/ad_event_history_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/ad_event_history_unittest.cc @@ -31,8 +31,8 @@ class BatAdsAdEventHistoryTest : public UnitTestBase { timestamp); } - std::vector GetAdEvent(const AdType& ad_type, - const ConfirmationType& confirmation_type) { + std::vector GetAdEvents(const AdType& ad_type, + const ConfirmationType& confirmation_type) { const std::string ad_type_as_string = std::string(ad_type); const std::string confirmation_type_as_string = @@ -51,7 +51,7 @@ TEST_F(BatAdsAdEventHistoryTest, RecordAdEventForNewType) { // Act const std::vector history = - GetAdEvent(AdType::kAdNotification, ConfirmationType::kViewed); + GetAdEvents(AdType::kAdNotification, ConfirmationType::kViewed); // Assert const double timestamp = NowAsTimestamp(); @@ -66,7 +66,7 @@ TEST_F(BatAdsAdEventHistoryTest, RecordAdEventForExistingType) { // Act const std::vector history = - GetAdEvent(AdType::kAdNotification, ConfirmationType::kViewed); + GetAdEvents(AdType::kAdNotification, ConfirmationType::kViewed); // Assert const double timestamp = NowAsTimestamp(); @@ -81,7 +81,7 @@ TEST_F(BatAdsAdEventHistoryTest, RecordAdEventForMultipleTypes) { // Act const std::vector history = - GetAdEvent(AdType::kAdNotification, ConfirmationType::kViewed); + GetAdEvents(AdType::kAdNotification, ConfirmationType::kViewed); // Assert const double timestamp = NowAsTimestamp(); @@ -100,7 +100,7 @@ TEST_F(BatAdsAdEventHistoryTest, PurgeHistoryOlderThan) { // Act const std::vector history = - GetAdEvent(AdType::kAdNotification, ConfirmationType::kViewed); + GetAdEvents(AdType::kAdNotification, ConfirmationType::kViewed); // Assert const double timestamp = NowAsTimestamp(); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_unittest_util.cc index 0538fa2200dc..934c5a416352 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_unittest_util.cc @@ -9,13 +9,16 @@ #include "base/time/time.h" #include "bat/ads/confirmation_type.h" #include "bat/ads/internal/ad_events/ad_event_info.h" +#include "bat/ads/internal/ad_events/ad_events.h" #include "bat/ads/internal/bundle/creative_ad_info.h" +#include "bat/ads/internal/unittest_time_util.h" +#include "bat/ads/internal/unittest_util.h" namespace ads { -AdEventInfo GetAdEvent(const CreativeAdInfo& creative_ad, - const ConfirmationType confirmation_type, - const base::Time& created_at) { +AdEventInfo BuildAdEvent(const CreativeAdInfo& creative_ad, + const ConfirmationType confirmation_type, + const base::Time& created_at) { AdEventInfo ad_event; ad_event.uuid = base::GenerateGUID(); ad_event.confirmation_type = confirmation_type; @@ -26,4 +29,46 @@ AdEventInfo GetAdEvent(const CreativeAdInfo& creative_ad, return ad_event; } +AdEventInfo BuildAdEvent(const ConfirmationType confirmation_type) { + AdEventInfo ad_event; + + ad_event.type = AdType::kAdNotification; + ad_event.uuid = base::GenerateGUID(); + ad_event.confirmation_type = confirmation_type; + ad_event.campaign_id = base::GenerateGUID(); + ad_event.creative_set_id = base::GenerateGUID(); + ad_event.creative_instance_id = base::GenerateGUID(); + ad_event.advertiser_id = base::GenerateGUID(); + ad_event.created_at = Now(); + + return ad_event; +} + +AdEventInfo BuildAdEvent(const std::string& uuid, + const std::string& creative_set_id, + const ConfirmationType confirmation_type) { + AdEventInfo ad_event; + + ad_event.type = AdType::kAdNotification; + ad_event.uuid = uuid; + ad_event.confirmation_type = confirmation_type; + ad_event.campaign_id = "604df73f-bc6e-4583-a56d-ce4e243c8537"; + ad_event.creative_set_id = creative_set_id; + ad_event.creative_instance_id = "7a3b6d9f-d0b7-4da6-8988-8d5b8938c94f"; + ad_event.advertiser_id = "f646c5f5-027a-4a35-b081-fce85e830b19"; + ad_event.created_at = Now(); + + return ad_event; +} + +AdEventInfo BuildAdEvent(const std::string& creative_set_id, + const ConfirmationType confirmation_type) { + const std::string uuid = base::GenerateGUID(); + return BuildAdEvent(uuid, creative_set_id, confirmation_type); +} + +void FireAdEvent(const AdEventInfo& ad_event) { + LogAdEvent(ad_event, [](const bool success) { ASSERT_TRUE(success); }); +} + } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_unittest_util.h index 116269c76ea7..0ce4b136249a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_unittest_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_unittest_util.h @@ -6,6 +6,8 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_EVENTS_AD_EVENT_UNITTEST_UTIL_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_EVENTS_AD_EVENT_UNITTEST_UTIL_H_ +#include + namespace base { class Time; } // namespace base @@ -16,9 +18,20 @@ class ConfirmationType; struct AdEventInfo; struct CreativeAdInfo; -AdEventInfo GetAdEvent(const CreativeAdInfo& creative_ad, - const ConfirmationType confirmation_type, - const base::Time& created_at); +AdEventInfo BuildAdEvent(const CreativeAdInfo& creative_ad, + const ConfirmationType confirmation_type, + const base::Time& created_at); + +AdEventInfo BuildAdEvent(const ConfirmationType confirmation_type); + +AdEventInfo BuildAdEvent(const std::string& uuid, + const std::string& creative_set_id, + const ConfirmationType confirmation_type); + +AdEventInfo BuildAdEvent(const std::string& creative_set_id, + const ConfirmationType confirmation_type); + +void FireAdEvent(const AdEventInfo& ad_event); } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_util_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_util_unittest.cc index af67891ef6ae..482cccacecc8 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_util_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_events/ad_event_util_unittest.cc @@ -11,6 +11,7 @@ #include "bat/ads/internal/ad_events/ad_event_unittest_util.h" #include "bat/ads/internal/bundle/creative_ad_notification_info.h" #include "bat/ads/internal/bundle/creative_ad_notification_unittest_util.h" +#include "bat/ads/internal/unittest_time_util.h" #include "testing/gtest/include/gtest/gtest.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -21,38 +22,37 @@ TEST(BatAdsAdEventUtilTest, GetLastSeenAdTimeForEmptyAdEvents) { // Arrange AdEventList ad_events; - const CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification(); + const CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); // Act - const absl::optional ad_last_seen = - GetLastSeenAdTime(ad_events, creative_ad_notification); + const absl::optional last_seen_ad_time = + GetLastSeenAdTime(ad_events, creative_ad); // Assert - EXPECT_EQ(absl::nullopt, ad_last_seen); + EXPECT_EQ(absl::nullopt, last_seen_ad_time); } TEST(BatAdsAdEventUtilTest, GetLastSeenAdTimeForUnseenAd) { // Arrange AdEventList ad_events; - const CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification(); + const CreativeAdNotificationInfo creative_ad_1 = + BuildCreativeAdNotification(); const base::Time event_time = base::Time::Now() - base::TimeDelta::FromHours(12); - const AdEventInfo ad_event = GetAdEvent( - creative_ad_notification_1, ConfirmationType::kViewed, event_time); + const AdEventInfo ad_event = + BuildAdEvent(creative_ad_1, ConfirmationType::kViewed, event_time); ad_events.push_back(ad_event); // Act - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification(); - const absl::optional ad_last_seen = - GetLastSeenAdTime(ad_events, creative_ad_notification_2); + const CreativeAdNotificationInfo creative_ad_2 = + BuildCreativeAdNotification(); + const absl::optional last_seen_ad_time = + GetLastSeenAdTime(ad_events, creative_ad_2); // Assert - EXPECT_EQ(absl::nullopt, ad_last_seen); + EXPECT_EQ(absl::nullopt, last_seen_ad_time); } TEST(BatAdsAdEventUtilTest, GetLastSeenAdTime) { @@ -61,125 +61,126 @@ TEST(BatAdsAdEventUtilTest, GetLastSeenAdTime) { const base::Time now = base::Time::Now(); - const CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification(); + const CreativeAdNotificationInfo creative_ad_1 = + BuildCreativeAdNotification(); - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification(); + const CreativeAdNotificationInfo creative_ad_2 = + BuildCreativeAdNotification(); const AdEventInfo ad_event_4 = - GetAdEvent(creative_ad_notification_1, ConfirmationType::kConversion, - now - base::TimeDelta::FromHours(3)); + BuildAdEvent(creative_ad_1, ConfirmationType::kConversion, + now - base::TimeDelta::FromHours(3)); ad_events.push_back(ad_event_4); const AdEventInfo ad_event_3 = - GetAdEvent(creative_ad_notification_1, ConfirmationType::kViewed, - now - base::TimeDelta::FromHours(6)); + BuildAdEvent(creative_ad_1, ConfirmationType::kViewed, + now - base::TimeDelta::FromHours(6)); ad_events.push_back(ad_event_3); const AdEventInfo ad_event_2 = - GetAdEvent(creative_ad_notification_2, ConfirmationType::kViewed, - now - base::TimeDelta::FromHours(11)); + BuildAdEvent(creative_ad_2, ConfirmationType::kViewed, + now - base::TimeDelta::FromHours(11)); ad_events.push_back(ad_event_2); const AdEventInfo ad_event_1 = - GetAdEvent(creative_ad_notification_1, ConfirmationType::kViewed, - now - base::TimeDelta::FromHours(12)); + BuildAdEvent(creative_ad_1, ConfirmationType::kViewed, + now - base::TimeDelta::FromHours(12)); ad_events.push_back(ad_event_1); // Act - const absl::optional ad_last_seen = - GetLastSeenAdTime(ad_events, creative_ad_notification_1); + const absl::optional last_seen_ad_time = + GetLastSeenAdTime(ad_events, creative_ad_1); // Assert - const base::Time expected_ad_last_seen = now - base::TimeDelta::FromHours(6); - EXPECT_EQ(expected_ad_last_seen, ad_last_seen.value()); + const base::Time expected_last_seen_ad_time = + now - base::TimeDelta::FromHours(6); + EXPECT_EQ(expected_last_seen_ad_time, last_seen_ad_time.value()); } TEST(BatAdsAdEventUtilTest, GetLastSeenAdvertiserTimeForEmptyAdEvents) { // Arrange AdEventList ad_events; - const CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification(); + const CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); // Act - const absl::optional advertiser_last_seen = - GetLastSeenAdvertiserTime(ad_events, creative_ad_notification); + const absl::optional last_seen_advertiser_time = + GetLastSeenAdvertiserTime(ad_events, creative_ad); // Assert - EXPECT_EQ(absl::nullopt, advertiser_last_seen); + EXPECT_EQ(absl::nullopt, last_seen_advertiser_time); } TEST(BatAdsAdEventUtilTest, GetLastSeenAdvertiserTimeForUnseenAdvertiser) { // Arrange AdEventList ad_events; - const CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification(); + const CreativeAdNotificationInfo creative_ad_1 = + BuildCreativeAdNotification(); const base::Time event_time = base::Time::Now() - base::TimeDelta::FromHours(12); - const AdEventInfo ad_event = GetAdEvent( - creative_ad_notification_1, ConfirmationType::kViewed, event_time); + const AdEventInfo ad_event = + BuildAdEvent(creative_ad_1, ConfirmationType::kViewed, event_time); ad_events.push_back(ad_event); // Act - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification(); - const absl::optional advertiser_last_seen = - GetLastSeenAdvertiserTime(ad_events, creative_ad_notification_2); + const CreativeAdNotificationInfo creative_ad_2 = + BuildCreativeAdNotification(); + const absl::optional last_seen_advertiser_time = + GetLastSeenAdvertiserTime(ad_events, creative_ad_2); // Assert - EXPECT_EQ(absl::nullopt, advertiser_last_seen); + EXPECT_EQ(absl::nullopt, last_seen_advertiser_time); } TEST(BatAdsAdEventUtilTest, GetLastSeenAdvertiserTime) { // Arrange - AdEventList ad_events; + const std::string advertiser_1 = base::GenerateGUID(); + const std::string advertiser_2 = base::GenerateGUID(); - const base::Time now = base::Time::Now(); + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.advertiser_id = advertiser_1; - const std::string advertiser_id_1 = base::GenerateGUID(); - const CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotificationForAdvertiser(advertiser_id_1); + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.advertiser_id = advertiser_2; - const std::string advertiser_id_2 = base::GenerateGUID(); - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotificationForAdvertiser(advertiser_id_2); + CreativeAdNotificationInfo creative_ad_3 = BuildCreativeAdNotification(); + creative_ad_3.advertiser_id = advertiser_1; - const CreativeAdNotificationInfo creative_ad_notification_3 = - GetCreativeAdNotificationForAdvertiser(advertiser_id_1); + AdEventList ad_events; + + const base::Time now = base::Time::Now(); - // Ad events are ordered by date DESC in |AdEvents::GetAll()| const AdEventInfo ad_event_4 = - GetAdEvent(creative_ad_notification_1, ConfirmationType::kViewed, - now - base::TimeDelta::FromHours(3)); + BuildAdEvent(creative_ad_1, ConfirmationType::kViewed, + now - base::TimeDelta::FromHours(3)); ad_events.push_back(ad_event_4); const AdEventInfo ad_event_3 = - GetAdEvent(creative_ad_notification_3, ConfirmationType::kViewed, - now - base::TimeDelta::FromHours(6)); + BuildAdEvent(creative_ad_3, ConfirmationType::kViewed, + now - base::TimeDelta::FromHours(6)); ad_events.push_back(ad_event_3); const AdEventInfo ad_event_2 = - GetAdEvent(creative_ad_notification_2, ConfirmationType::kViewed, - now - base::TimeDelta::FromHours(11)); + BuildAdEvent(creative_ad_2, ConfirmationType::kViewed, + now - base::TimeDelta::FromHours(11)); ad_events.push_back(ad_event_2); const AdEventInfo ad_event_1 = - GetAdEvent(creative_ad_notification_1, ConfirmationType::kViewed, - now - base::TimeDelta::FromHours(12)); + BuildAdEvent(creative_ad_1, ConfirmationType::kViewed, + now - base::TimeDelta::FromHours(12)); ad_events.push_back(ad_event_1); // Act - const absl::optional advertiser_last_seen = - GetLastSeenAdvertiserTime(ad_events, creative_ad_notification_3); + const absl::optional last_seen_advertiser_time = + GetLastSeenAdvertiserTime(ad_events, creative_ad_3); // Assert - const base::Time expected_advertiser_last_seen = + const base::Time expected_last_seen_advertiser_time = now - base::TimeDelta::FromHours(3); - EXPECT_EQ(expected_advertiser_last_seen, advertiser_last_seen.value()); + EXPECT_EQ(expected_last_seen_advertiser_time, + last_seen_advertiser_time.value()); } } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_pacing/ad_pacing_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ad_pacing/ad_pacing_test.cc index 8d0819c49447..984b0384a456 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_pacing/ad_pacing_test.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_pacing/ad_pacing_test.cc @@ -63,68 +63,60 @@ class BatAdsAdPacingTest : public UnitTestBase { UserActivity::Get()->RecordEvent(UserActivityEventType::kClosedTab); } - CreativeAdNotificationInfo GetCreativeAdNotification1() { - CreativeAdNotificationInfo creative_ad_notification; - - creative_ad_notification.creative_instance_id = - "3519f52c-46a4-4c48-9c2b-c264c0067f04"; - creative_ad_notification.creative_set_id = - "c2ba3e7d-f688-4bc4-a053-cbe7ac1e6123"; - creative_ad_notification.campaign_id = - "84197fc8-830a-4a8e-8339-7a70c2bfa104"; - creative_ad_notification.start_at = DistantPast(); - creative_ad_notification.end_at = DistantFuture(); - creative_ad_notification.daily_cap = 1; - creative_ad_notification.advertiser_id = - "5484a63f-eb99-4ba5-a3b0-8c25d3c0e4b2"; - creative_ad_notification.priority = 1; - creative_ad_notification.ptr = 1.0; - creative_ad_notification.per_day = 3; - creative_ad_notification.per_week = 4; - creative_ad_notification.per_month = 5; - creative_ad_notification.total_max = 6; - creative_ad_notification.value = 1.0; - creative_ad_notification.segment = "untargeted"; - creative_ad_notification.geo_targets = {"US"}; - creative_ad_notification.target_url = "https://brave.com/1"; + CreativeAdNotificationInfo BuildCreativeAdNotification1() { + CreativeAdNotificationInfo creative_ad; + + creative_ad.creative_instance_id = "3519f52c-46a4-4c48-9c2b-c264c0067f04"; + creative_ad.creative_set_id = "c2ba3e7d-f688-4bc4-a053-cbe7ac1e6123"; + creative_ad.campaign_id = "84197fc8-830a-4a8e-8339-7a70c2bfa104"; + creative_ad.start_at = DistantPast(); + creative_ad.end_at = DistantFuture(); + creative_ad.daily_cap = 1; + creative_ad.advertiser_id = "5484a63f-eb99-4ba5-a3b0-8c25d3c0e4b2"; + creative_ad.priority = 1; + creative_ad.ptr = 1.0; + creative_ad.per_day = 3; + creative_ad.per_week = 4; + creative_ad.per_month = 5; + creative_ad.total_max = 6; + creative_ad.value = 1.0; + creative_ad.segment = "untargeted"; + creative_ad.geo_targets = {"US"}; + creative_ad.target_url = "https://brave.com/1"; CreativeDaypartInfo daypart; - creative_ad_notification.dayparts = {daypart}; - creative_ad_notification.title = "Test Ad 1 Title"; - creative_ad_notification.body = "Test Ad 1 Body"; + creative_ad.dayparts = {daypart}; + creative_ad.title = "Test Ad 1 Title"; + creative_ad.body = "Test Ad 1 Body"; - return creative_ad_notification; + return creative_ad; } - CreativeAdNotificationInfo GetCreativeAdNotification2() { - CreativeAdNotificationInfo creative_ad_notification; - - creative_ad_notification.creative_instance_id = - "a1ac44c2-675f-43e6-ab6d-500614cafe63"; - creative_ad_notification.creative_set_id = - "5800049f-cee5-4bcb-90c7-85246d5f5e7c"; - creative_ad_notification.campaign_id = - "3d62eca2-324a-4161-a0c5-7d9f29d10ab0"; - creative_ad_notification.start_at = DistantPast(); - creative_ad_notification.end_at = DistantFuture(); - creative_ad_notification.daily_cap = 1; - creative_ad_notification.advertiser_id = - "9a11b60f-e29d-4446-8d1f-318311e36e0a"; - creative_ad_notification.priority = 2; - creative_ad_notification.ptr = 1.0; - creative_ad_notification.per_day = 3; - creative_ad_notification.per_week = 4; - creative_ad_notification.per_month = 5; - creative_ad_notification.total_max = 6; - creative_ad_notification.value = 1.0; - creative_ad_notification.segment = "untargeted"; - creative_ad_notification.geo_targets = {"US"}; - creative_ad_notification.target_url = "https://brave.com/2"; + CreativeAdNotificationInfo BuildCreativeAdNotification2() { + CreativeAdNotificationInfo creative_ad; + + creative_ad.creative_instance_id = "a1ac44c2-675f-43e6-ab6d-500614cafe63"; + creative_ad.creative_set_id = "5800049f-cee5-4bcb-90c7-85246d5f5e7c"; + creative_ad.campaign_id = "3d62eca2-324a-4161-a0c5-7d9f29d10ab0"; + creative_ad.start_at = DistantPast(); + creative_ad.end_at = DistantFuture(); + creative_ad.daily_cap = 1; + creative_ad.advertiser_id = "9a11b60f-e29d-4446-8d1f-318311e36e0a"; + creative_ad.priority = 2; + creative_ad.ptr = 1.0; + creative_ad.per_day = 3; + creative_ad.per_week = 4; + creative_ad.per_month = 5; + creative_ad.total_max = 6; + creative_ad.value = 1.0; + creative_ad.segment = "untargeted"; + creative_ad.geo_targets = {"US"}; + creative_ad.target_url = "https://brave.com/2"; CreativeDaypartInfo daypart; - creative_ad_notification.dayparts = {daypart}; - creative_ad_notification.title = "Test Ad 2 Title"; - creative_ad_notification.body = "Test Ad 2 Body"; + creative_ad.dayparts = {daypart}; + creative_ad.title = "Test Ad 2 Title"; + creative_ad.body = "Test Ad 2 Body"; - return creative_ad_notification; + return creative_ad; } void ServeAdForIterations(const int iterations) { @@ -140,8 +132,8 @@ class BatAdsAdPacingTest : public UnitTestBase { } } - void Save(const CreativeAdNotificationList& creative_ad_notifications) { - database_table_->Save(creative_ad_notifications, + void Save(const CreativeAdNotificationList& creative_ads) { + database_table_->Save(creative_ads, [](const bool success) { ASSERT_TRUE(success); }); } @@ -150,14 +142,13 @@ class BatAdsAdPacingTest : public UnitTestBase { TEST_F(BatAdsAdPacingTest, PacingDisableDelivery) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification1(); - creative_ad_notification.ptr = 0.0; - creative_ad_notifications.push_back(creative_ad_notification); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification1(); + creative_ad.ptr = 0.0; + creative_ads.push_back(creative_ad); - Save(creative_ad_notifications); + Save(creative_ads); // Act int iterations = 1000; @@ -170,14 +161,13 @@ TEST_F(BatAdsAdPacingTest, PacingDisableDelivery) { TEST_F(BatAdsAdPacingTest, NoPacing) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification1(); - creative_ad_notification.ptr = 1.0; - creative_ad_notifications.push_back(creative_ad_notification); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification1(); + creative_ad.ptr = 1.0; + creative_ads.push_back(creative_ad); - Save(creative_ad_notifications); + Save(creative_ads); // Act int iterations = 1000; @@ -190,20 +180,19 @@ TEST_F(BatAdsAdPacingTest, NoPacing) { TEST_F(BatAdsAdPacingTest, SimplePacing) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification1(); - creative_ad_notification.ptr = 0.2; - creative_ad_notifications.push_back(creative_ad_notification); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification1(); + creative_ad.ptr = 0.2; + creative_ads.push_back(creative_ad); - Save(creative_ad_notifications); + Save(creative_ads); // Act int iterations = 1000; EXPECT_CALL(*ads_client_mock_, ShowNotification(_)) - .Times(Between(iterations * creative_ad_notification.ptr * 0.8, - iterations * creative_ad_notification.ptr * 1.2)); + .Times(Between(iterations * creative_ad.ptr * 0.8, + iterations * creative_ad.ptr * 1.2)); ServeAdForIterations(iterations); @@ -212,22 +201,21 @@ TEST_F(BatAdsAdPacingTest, SimplePacing) { TEST_F(BatAdsAdPacingTest, NoPacingPrioritized) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; - const CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification1(); - creative_ad_notifications.push_back(creative_ad_notification_1); + const CreativeAdNotificationInfo creative_ad_1 = + BuildCreativeAdNotification1(); + creative_ads.push_back(creative_ad_1); - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification2(); - creative_ad_notifications.push_back(creative_ad_notification_2); + const CreativeAdNotificationInfo creative_ad_2 = + BuildCreativeAdNotification2(); + creative_ads.push_back(creative_ad_2); - Save(creative_ad_notifications); + Save(creative_ads); // Act - EXPECT_CALL(*ads_client_mock_, - ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_notification_1.creative_instance_id))) + EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( + creative_ad_1.creative_instance_id))) .Times(1); ServeAdForIterations(1); @@ -237,23 +225,21 @@ TEST_F(BatAdsAdPacingTest, NoPacingPrioritized) { TEST_F(BatAdsAdPacingTest, PacingDisableDeliveryPrioritized) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification1(); - creative_ad_notification_1.ptr = 0.0; - creative_ad_notifications.push_back(creative_ad_notification_1); + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification1(); + creative_ad_1.ptr = 0.0; + creative_ads.push_back(creative_ad_1); - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification2(); - creative_ad_notifications.push_back(creative_ad_notification_2); + const CreativeAdNotificationInfo creative_ad_2 = + BuildCreativeAdNotification2(); + creative_ads.push_back(creative_ad_2); - Save(creative_ad_notifications); + Save(creative_ads); // Act - EXPECT_CALL(*ads_client_mock_, - ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_notification_2.creative_instance_id))) + EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( + creative_ad_2.creative_instance_id))) .Times(1); ServeAdForIterations(1); @@ -263,37 +249,31 @@ TEST_F(BatAdsAdPacingTest, PacingDisableDeliveryPrioritized) { TEST_F(BatAdsAdPacingTest, PacingAndPrioritization) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification1(); - creative_ad_notification_1.ptr = 0.5; - creative_ad_notifications.push_back(creative_ad_notification_1); + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification1(); + creative_ad_1.ptr = 0.5; + creative_ads.push_back(creative_ad_1); - CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification2(); - creative_ad_notification_2.ptr = 0.5; - creative_ad_notifications.push_back(creative_ad_notification_2); + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification2(); + creative_ad_2.ptr = 0.5; + creative_ads.push_back(creative_ad_2); - Save(creative_ad_notifications); + Save(creative_ads); // Act int iterations = 1000; - EXPECT_CALL(*ads_client_mock_, - ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_notification_1.creative_instance_id))) - .Times(Between(iterations * creative_ad_notification_1.ptr * 0.8, - iterations * creative_ad_notification_1.ptr * 1.2)); - - // creative_ad_notification_2 ad would be shown probabilistically when - // creative_ad_notification_1 gets dropped due to pacing - EXPECT_CALL(*ads_client_mock_, - ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_notification_2.creative_instance_id))) - .Times(Between(iterations * creative_ad_notification_1.ptr * 0.8 * - creative_ad_notification_2.ptr, - iterations * creative_ad_notification_1.ptr * 1.2 * - creative_ad_notification_2.ptr)); + EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( + creative_ad_1.creative_instance_id))) + .Times(Between(iterations * creative_ad_1.ptr * 0.8, + iterations * creative_ad_1.ptr * 1.2)); + + // creative_ad_2 ad would be shown probabilistically when + // creative_ad_1 gets dropped due to pacing + EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( + creative_ad_2.creative_instance_id))) + .Times(Between(iterations * creative_ad_1.ptr * 0.8 * creative_ad_2.ptr, + iterations * creative_ad_1.ptr * 1.2 * creative_ad_2.ptr)); ServeAdForIterations(iterations); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_priority/ad_priority_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ad_priority/ad_priority_test.cc index f4cfa272fc5b..97253d522ec8 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_priority/ad_priority_test.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_priority/ad_priority_test.cc @@ -73,32 +73,32 @@ class BatAdsAdPriorityTest : public UnitTestBase { UserActivity::Get()->RecordEvent(UserActivityEventType::kClosedTab); } - CreativeAdNotificationInfo GetCreativeAdNotification() { - CreativeAdNotificationInfo creative_ad_notification; - - creative_ad_notification.creative_instance_id = base::GenerateGUID(); - creative_ad_notification.creative_set_id = base::GenerateGUID(); - creative_ad_notification.campaign_id = base::GenerateGUID(); - creative_ad_notification.start_at = DistantPast(); - creative_ad_notification.end_at = DistantFuture(); - creative_ad_notification.daily_cap = 1; - creative_ad_notification.advertiser_id = base::GenerateGUID(); - creative_ad_notification.priority = 1; - creative_ad_notification.ptr = 1.0; - creative_ad_notification.per_day = 1; - creative_ad_notification.per_week = 1; - creative_ad_notification.per_month = 1; - creative_ad_notification.total_max = 1; - creative_ad_notification.value = 1.0; - creative_ad_notification.segment = "untargeted"; - creative_ad_notification.geo_targets = {"US"}; - creative_ad_notification.target_url = "https://brave.com"; + CreativeAdNotificationInfo BuildCreativeAdNotification() { + CreativeAdNotificationInfo creative_ad; + + creative_ad.creative_instance_id = base::GenerateGUID(); + creative_ad.creative_set_id = base::GenerateGUID(); + creative_ad.campaign_id = base::GenerateGUID(); + creative_ad.start_at = DistantPast(); + creative_ad.end_at = DistantFuture(); + creative_ad.daily_cap = 1; + creative_ad.advertiser_id = base::GenerateGUID(); + creative_ad.priority = 1; + creative_ad.ptr = 1.0; + creative_ad.per_day = 1; + creative_ad.per_week = 1; + creative_ad.per_month = 1; + creative_ad.total_max = 1; + creative_ad.value = 1.0; + creative_ad.segment = "untargeted"; + creative_ad.geo_targets = {"US"}; + creative_ad.target_url = "https://brave.com"; CreativeDaypartInfo daypart; - creative_ad_notification.dayparts = {daypart}; - creative_ad_notification.title = "Test Ad Title"; - creative_ad_notification.body = "Test Ad Body"; + creative_ad.dayparts = {daypart}; + creative_ad.title = "Test Ad Title"; + creative_ad.body = "Test Ad Body"; - return creative_ad_notification; + return creative_ad; } void ServeAdForIterations(const int iterations) { @@ -114,8 +114,8 @@ class BatAdsAdPriorityTest : public UnitTestBase { } } - void Save(const CreativeAdNotificationList& creative_ad_notifications) { - database_table_->Save(creative_ad_notifications, + void Save(const CreativeAdNotificationList& creative_ads) { + database_table_->Save(creative_ads, [](const bool success) { ASSERT_TRUE(success); }); } @@ -124,19 +124,17 @@ class BatAdsAdPriorityTest : public UnitTestBase { TEST_F(BatAdsAdPriorityTest, PrioritizeDeliveryForSingleAd) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification(); - creative_ad_notification.priority = 3; - creative_ad_notifications.push_back(creative_ad_notification); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); + creative_ad.priority = 3; + creative_ads.push_back(creative_ad); - Save(creative_ad_notifications); + Save(creative_ads); // Act - EXPECT_CALL(*ads_client_mock_, - ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_notification.creative_instance_id))) + EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( + creative_ad.creative_instance_id))) .Times(1); ServeAd(); @@ -157,29 +155,25 @@ TEST_F(BatAdsAdPriorityTest, PrioritizeDeliveryForNoAds) { TEST_F(BatAdsAdPriorityTest, PrioritizeDeliveryForMultipleAds) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification(); - creative_ad_notification_1.priority = 3; - creative_ad_notifications.push_back(creative_ad_notification_1); + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.priority = 3; + creative_ads.push_back(creative_ad_1); - CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification(); - creative_ad_notification_2.priority = 2; - creative_ad_notifications.push_back(creative_ad_notification_2); + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.priority = 2; + creative_ads.push_back(creative_ad_2); - CreativeAdNotificationInfo creative_ad_notification_3 = - GetCreativeAdNotification(); - creative_ad_notification_3.priority = 4; - creative_ad_notifications.push_back(creative_ad_notification_3); + CreativeAdNotificationInfo creative_ad_3 = BuildCreativeAdNotification(); + creative_ad_3.priority = 4; + creative_ads.push_back(creative_ad_3); - Save(creative_ad_notifications); + Save(creative_ads); // Act - EXPECT_CALL(*ads_client_mock_, - ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_notification_2.creative_instance_id))) + EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( + creative_ad_2.creative_instance_id))) .Times(1); ServeAd(); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_serving/ad_notifications/ad_notification_serving_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ad_serving/ad_notifications/ad_notification_serving_test.cc index 6aa0b8677cb1..103ef53b27fa 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_serving/ad_notifications/ad_notification_serving_test.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_serving/ad_notifications/ad_notification_serving_test.cc @@ -76,8 +76,8 @@ class BatAdsAdNotificationServingTest : public UnitTestBase { ad_serving.MaybeServeAd(); } - void Save(const CreativeAdNotificationList& creative_ad_notifications) { - database_table_->Save(creative_ad_notifications, + void Save(const CreativeAdNotificationList& creative_ads) { + database_table_->Save(creative_ads, [](const bool success) { ASSERT_TRUE(success); }); } @@ -89,7 +89,7 @@ TEST_F(BatAdsAdNotificationServingTest, ServeAd) { RecordUserActivityEvents(); CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad = GetCreativeAdNotification(); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); creative_ads.push_back(creative_ad); Save(creative_ads); @@ -131,7 +131,7 @@ TEST_F(BatAdsAdNotificationServingTest, DoNotServeAdIfNotAllowedDueToPermissionRules) { // Arrange CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad = GetCreativeAdNotification(); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); creative_ads.push_back(creative_ad); Save(creative_ads); @@ -148,7 +148,7 @@ TEST_F(BatAdsAdNotificationServingTest, ServeAdWithAdServingVersion2) { RecordUserActivityEvents(); CreativeAdNotificationList creative_ads; - const CreativeAdNotificationInfo creative_ad = GetCreativeAdNotification(); + const CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); creative_ads.push_back(creative_ad); Save(creative_ads); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_serving/inline_content_ads/inline_content_ad_serving_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ad_serving/inline_content_ads/inline_content_ad_serving_test.cc index dc2d48c7b072..9d7de47a35b1 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_serving/inline_content_ads/inline_content_ad_serving_test.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_serving/inline_content_ads/inline_content_ad_serving_test.cc @@ -51,8 +51,8 @@ class BatAdsInlineContentAdServingTest : public UnitTestBase { UserActivity::Get()->RecordEvent(UserActivityEventType::kClosedTab); } - void Save(const CreativeInlineContentAdList& creative_inline_content_ads) { - database_table_->Save(creative_inline_content_ads, + void Save(const CreativeInlineContentAdList& creative_ads) { + database_table_->Save(creative_ads, [](const bool success) { ASSERT_TRUE(success); }); } @@ -69,7 +69,7 @@ TEST_F(BatAdsInlineContentAdServingTest, ServeAd) { RecordUserActivityEvents(); CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = GetCreativeInlineContentAd(); + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); creative_ads.push_back(creative_ad); Save(creative_ads); @@ -91,7 +91,7 @@ TEST_F(BatAdsInlineContentAdServingTest, DoNotServeAdForUnavailableDimensions) { RecordUserActivityEvents(); CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = GetCreativeInlineContentAd(); + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); creative_ads.push_back(creative_ad); Save(creative_ads); @@ -107,7 +107,7 @@ TEST_F(BatAdsInlineContentAdServingTest, DoNotServeAdIfNotAllowedDueToPermissionRules) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = GetCreativeInlineContentAd(); + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); creative_ads.push_back(creative_ad); Save(creative_ads); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ad_transfer/ad_transfer_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ad_transfer/ad_transfer_unittest.cc index d4e849a7d72d..ee8a99032106 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ad_transfer/ad_transfer_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ad_transfer/ad_transfer_unittest.cc @@ -28,7 +28,7 @@ class BatAdsAdTransferTest : public AdTransferObserver, public UnitTestBase { int GetAdTransferCount() { return ad_transfer_count_; } - AdInfo GetAdForType(const AdType type) { + AdInfo BuildAdForType(const AdType type) { AdInfo ad; ad.type = type; @@ -50,7 +50,7 @@ class BatAdsAdTransferTest : public AdTransferObserver, public UnitTestBase { TEST_F(BatAdsAdTransferTest, DoNotTransferAdIfUrlIsMissingHTTPOrHTTPSScheme) { // Arrange - const AdInfo ad = GetAdForType(AdType::kPromotedContentAd); + const AdInfo ad = BuildAdForType(AdType::kPromotedContentAd); ad_transfer_->set_last_clicked_ad(ad); TabManager::Get()->OnUpdated(1, "https://brave.com", /* is_visible */ true, @@ -67,7 +67,7 @@ TEST_F(BatAdsAdTransferTest, DoNotTransferAdIfUrlIsMissingHTTPOrHTTPSScheme) { TEST_F(BatAdsAdTransferTest, DoNotTransferAdIfTheUrlDoesNotMatchTheLastClickedAd) { // Arrange - const AdInfo ad = GetAdForType(AdType::kNewTabPageAd); + const AdInfo ad = BuildAdForType(AdType::kNewTabPageAd); ad_transfer_->set_last_clicked_ad(ad); TabManager::Get()->OnUpdated(1, "https://foobar.com", /* is_visible */ true, @@ -83,7 +83,7 @@ TEST_F(BatAdsAdTransferTest, TEST_F(BatAdsAdTransferTest, DoNotTransferAdIfTheSameAdIsAlreadyTransferring) { // Arrange - const AdInfo ad = GetAdForType(AdType::kAdNotification); + const AdInfo ad = BuildAdForType(AdType::kAdNotification); ad_transfer_->set_last_clicked_ad(ad); TabManager::Get()->OnUpdated(1, "https://brave.com", /* is_visible */ true, @@ -101,7 +101,7 @@ TEST_F(BatAdsAdTransferTest, DoNotTransferAdIfTheSameAdIsAlreadyTransferring) { TEST_F(BatAdsAdTransferTest, TransferAdIfAnotherAdIsAlreadyTransferring) { // Arrange - const AdInfo ad = GetAdForType(AdType::kPromotedContentAd); + const AdInfo ad = BuildAdForType(AdType::kPromotedContentAd); ad_transfer_->set_last_clicked_ad(ad); TabManager::Get()->OnUpdated(1, "https://foobar.com", /* is_visible */ true, @@ -126,7 +126,7 @@ TEST_F(BatAdsAdTransferTest, TransferAdIfAnotherAdIsAlreadyTransferring) { TEST_F(BatAdsAdTransferTest, TransferAdIfTheTabIsVisibleAndTheUrlIsTheSameAsTheDomainOrHost) { // Arrange - const AdInfo ad = GetAdForType(AdType::kNewTabPageAd); + const AdInfo ad = BuildAdForType(AdType::kNewTabPageAd); ad_transfer_->set_last_clicked_ad(ad); TabManager::Get()->OnUpdated(1, "https://brave.com", /* is_visible */ true, @@ -142,7 +142,7 @@ TEST_F(BatAdsAdTransferTest, TEST_F(BatAdsAdTransferTest, FailToTransferAdIfNotVisible) { // Arrange - const AdInfo ad = GetAdForType(AdType::kAdNotification); + const AdInfo ad = BuildAdForType(AdType::kAdNotification); ad_transfer_->set_last_clicked_ad(ad); TabManager::Get()->OnUpdated(1, "https://brave.com", /* is_visible */ false, @@ -159,7 +159,7 @@ TEST_F(BatAdsAdTransferTest, FailToTransferAdIfNotVisible) { TEST_F(BatAdsAdTransferTest, FailToTransferAdIfTheTabUrlIsNotTheSameAsTheDomainOrHost) { // Arrange - const AdInfo ad = GetAdForType(AdType::kInlineContentAd); + const AdInfo ad = BuildAdForType(AdType::kInlineContentAd); ad_transfer_->set_last_clicked_ad(ad); TabManager::Get()->OnUpdated(1, "https://brave.com", /* is_visible */ true, diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.cc index e85ec143a094..8cafd35734c5 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.cc @@ -5,26 +5,9 @@ #include "bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.h" -#include "base/check.h" #include "bat/ads/internal/ad_serving/ad_targeting/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/internal/bundle/creative_ad_info.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h" #include "bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule_util.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.h" #include "bat/ads/internal/resources/frequency_capping/anti_targeting_resource.h" namespace ads { @@ -36,103 +19,25 @@ ExclusionRules::ExclusionRules( resource::AntiTargeting* anti_targeting_resource, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history) - : subdivision_targeting_(subdivision_targeting), - anti_targeting_resource_(anti_targeting_resource), - ad_events_(ad_events), - browsing_history_(browsing_history) { - DCHECK(subdivision_targeting_); - DCHECK(anti_targeting_resource_); -} + : ExclusionRulesBase(subdivision_targeting, + anti_targeting_resource, + ad_events, + browsing_history) {} ExclusionRules::~ExclusionRules() = default; bool ExclusionRules::ShouldExcludeCreativeAd( - const CreativeAdInfo& creative_ad) const { - bool should_exclude = false; - - DailyCapFrequencyCap daily_cap_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &daily_cap_frequency_cap)) { - should_exclude = true; - } - - PerDayFrequencyCap per_day_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &per_day_frequency_cap)) { - should_exclude = true; - } - - PerHourFrequencyCap per_hour_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &per_hour_frequency_cap)) { - should_exclude = true; - } - - PerWeekFrequencyCap per_week_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &per_week_frequency_cap)) { - should_exclude = true; - } - - PerMonthFrequencyCap per_month_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &per_month_frequency_cap)) { - should_exclude = true; - } - - TotalMaxFrequencyCap total_max_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &total_max_frequency_cap)) { - should_exclude = true; - } - - ConversionFrequencyCap conversion_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &conversion_frequency_cap)) { - should_exclude = true; - } - - SubdivisionTargetingFrequencyCap subdivision_frequency_cap( - subdivision_targeting_); - if (ShouldExclude(creative_ad, &subdivision_frequency_cap)) { - should_exclude = true; - } - - DaypartFrequencyCap daypart_frequency_cap; - if (ShouldExclude(creative_ad, &daypart_frequency_cap)) { - should_exclude = true; + const CreativeAdInfo& creative_ad) { + if (ExclusionRulesBase::ShouldExcludeCreativeAd(creative_ad)) { + return true; } DismissedFrequencyCap dismissed_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &dismissed_frequency_cap)) { - should_exclude = true; - } - - TransferredFrequencyCap transferred_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &transferred_frequency_cap)) { - should_exclude = true; - } - - DislikeFrequencyCap dislike_frequency_cap; - if (ShouldExclude(creative_ad, &dislike_frequency_cap)) { - should_exclude = true; - } - - MarkedToNoLongerReceiveFrequencyCap marked_to_no_longer_receive_frequency_cap; - if (ShouldExclude(creative_ad, &marked_to_no_longer_receive_frequency_cap)) { - should_exclude = true; - } - - MarkedAsInappropriateFrequencyCap marked_as_inappropriate_frequency_cap; - if (ShouldExclude(creative_ad, &marked_as_inappropriate_frequency_cap)) { - should_exclude = true; - } - - SplitTestFrequencyCap split_test_frequency_cap; - if (ShouldExclude(creative_ad, &split_test_frequency_cap)) { - should_exclude = true; - } - - AntiTargetingFrequencyCap anti_targeting_frequency_cap( - anti_targeting_resource_, browsing_history_); - if (ShouldExclude(creative_ad, &anti_targeting_frequency_cap)) { - should_exclude = true; + if (AddToCacheIfNeeded(creative_ad, &dismissed_frequency_cap)) { + return true; } - return should_exclude; + return false; } } // namespace frequency_capping diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.h index 8b9d1fe21be9..a717ca170f84 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.h @@ -6,13 +6,10 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_AD_NOTIFICATIONS_AD_NOTIFICATION_EXCLUSION_RULES_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_AD_NOTIFICATIONS_AD_NOTIFICATION_EXCLUSION_RULES_H_ -#include "bat/ads/internal/ad_events/ad_event_info_aliases.h" -#include "bat/ads/internal/frequency_capping/frequency_capping_aliases.h" +#include "bat/ads/internal/ads/exclusion_rules_base.h" namespace ads { -struct CreativeAdInfo; - namespace ad_targeting { namespace geographic { class SubdivisionTargeting; @@ -23,26 +20,23 @@ namespace resource { class AntiTargeting; } // namespace resource +struct CreativeAdInfo; + namespace ad_notifications { namespace frequency_capping { -class ExclusionRules final { +class ExclusionRules final : public ExclusionRulesBase { public: ExclusionRules( ad_targeting::geographic::SubdivisionTargeting* subdivision_targeting, resource::AntiTargeting* anti_targeting_resource, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history); - ~ExclusionRules(); + ~ExclusionRules() override; - bool ShouldExcludeCreativeAd(const CreativeAdInfo& creative_ad) const; + bool ShouldExcludeCreativeAd(const CreativeAdInfo& creative_ad) override; private: - ad_targeting::geographic::SubdivisionTargeting* subdivision_targeting_; - resource::AntiTargeting* anti_targeting_resource_; - AdEventList ad_events_; - BrowsingHistoryList browsing_history_; - ExclusionRules(const ExclusionRules&) = delete; ExclusionRules& operator=(const ExclusionRules&) = delete; }; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/exclusion_rules_base.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/exclusion_rules_base.cc new file mode 100644 index 000000000000..081bdb8e7d9a --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/exclusion_rules_base.cc @@ -0,0 +1,179 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/ads/internal/ads/exclusion_rules_base.h" + +#include "bat/ads/internal/ad_serving/ad_targeting/geographic/subdivision/subdivision_targeting.h" +#include "bat/ads/internal/bundle/creative_ad_info.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule_util.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.h" +#include "bat/ads/internal/logging.h" +#include "bat/ads/internal/resources/frequency_capping/anti_targeting_resource.h" + +namespace ads { + +ExclusionRulesBase::ExclusionRulesBase( + ad_targeting::geographic::SubdivisionTargeting* subdivision_targeting, + resource::AntiTargeting* anti_targeting_resource, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history) + : subdivision_targeting_(subdivision_targeting), + anti_targeting_resource_(anti_targeting_resource), + ad_events_(ad_events), + browsing_history_(browsing_history) { + DCHECK(subdivision_targeting_); + DCHECK(anti_targeting_resource_); +} + +ExclusionRulesBase::~ExclusionRulesBase() = default; + +bool ExclusionRulesBase::ShouldExcludeCreativeAd( + const CreativeAdInfo& creative_ad) { + if (IsCached(creative_ad)) { + return true; + } + + SplitTestFrequencyCap split_test_frequency_cap; + if (AddToCacheIfNeeded(creative_ad, &split_test_frequency_cap)) { + return true; + } + + SubdivisionTargetingFrequencyCap subdivision_frequency_cap( + subdivision_targeting_); + if (AddToCacheIfNeeded(creative_ad, &subdivision_frequency_cap)) { + return true; + } + + AntiTargetingFrequencyCap anti_targeting_frequency_cap( + anti_targeting_resource_, browsing_history_); + if (AddToCacheIfNeeded(creative_ad, &anti_targeting_frequency_cap)) { + return true; + } + + DislikeFrequencyCap dislike_frequency_cap; + if (AddToCacheIfNeeded(creative_ad, &dislike_frequency_cap)) { + return true; + } + + MarkedToNoLongerReceiveFrequencyCap marked_to_no_longer_receive_frequency_cap; + if (AddToCacheIfNeeded(creative_ad, + &marked_to_no_longer_receive_frequency_cap)) { + return true; + } + + MarkedAsInappropriateFrequencyCap marked_as_inappropriate_frequency_cap; + if (AddToCacheIfNeeded(creative_ad, &marked_as_inappropriate_frequency_cap)) { + return true; + } + + ConversionFrequencyCap conversion_frequency_cap(ad_events_); + if (AddToCacheIfNeeded(creative_ad, &conversion_frequency_cap)) { + return true; + } + + TransferredFrequencyCap transferred_frequency_cap(ad_events_); + if (AddToCacheIfNeeded(creative_ad, &transferred_frequency_cap)) { + return true; + } + + TotalMaxFrequencyCap total_max_frequency_cap(ad_events_); + if (AddToCacheIfNeeded(creative_ad, &total_max_frequency_cap)) { + return true; + } + + PerMonthFrequencyCap per_month_frequency_cap(ad_events_); + if (AddToCacheIfNeeded(creative_ad, &per_month_frequency_cap)) { + return true; + } + + PerWeekFrequencyCap per_week_frequency_cap(ad_events_); + if (AddToCacheIfNeeded(creative_ad, &per_week_frequency_cap)) { + return true; + } + + DailyCapFrequencyCap daily_cap_frequency_cap(ad_events_); + if (AddToCacheIfNeeded(creative_ad, &daily_cap_frequency_cap)) { + return true; + } + + PerDayFrequencyCap per_day_frequency_cap(ad_events_); + if (AddToCacheIfNeeded(creative_ad, &per_day_frequency_cap)) { + return true; + } + + DaypartFrequencyCap daypart_frequency_cap; + if (AddToCacheIfNeeded(creative_ad, &daypart_frequency_cap)) { + return true; + } + + PerHourFrequencyCap per_hour_frequency_cap(ad_events_); + if (AddToCacheIfNeeded(creative_ad, &per_hour_frequency_cap)) { + return true; + } + + return false; +} + +/////////////////////////////////////////////////////////////////////////////// + +bool ExclusionRulesBase::IsCached(const CreativeAdInfo& creative_ad) const { + if (uuids_.find(creative_ad.creative_instance_id) != uuids_.end()) { + return true; + } + + if (uuids_.find(creative_ad.creative_set_id) != uuids_.end()) { + return true; + } + + if (uuids_.find(creative_ad.campaign_id) != uuids_.end()) { + return true; + } + + if (uuids_.find(creative_ad.advertiser_id) != uuids_.end()) { + return true; + } + + return false; +} + +bool ExclusionRulesBase::AddToCacheIfNeeded( + const CreativeAdInfo& creative_ad, + ExclusionRule* exclusion_rule) { + DCHECK(exclusion_rule); + + if (!exclusion_rule->ShouldExclude(creative_ad)) { + return false; + } + + const std::string last_message = exclusion_rule->GetLastMessage(); + if (!last_message.empty()) { + BLOG(2, last_message); + } + + const std::string uuid = exclusion_rule->GetUuid(creative_ad); + AddToCache(uuid); + + return true; +} + +void ExclusionRulesBase::AddToCache(const std::string& uuid) { + uuids_.insert(uuid); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/exclusion_rules_base.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/exclusion_rules_base.h new file mode 100644 index 000000000000..a3dc748358ef --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/exclusion_rules_base.h @@ -0,0 +1,62 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_EXCLUSION_RULES_BASE_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_EXCLUSION_RULES_BASE_H_ + +#include +#include + +#include "bat/ads/internal/ad_events/ad_event_info_aliases.h" +#include "bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule.h" +#include "bat/ads/internal/frequency_capping/frequency_capping_aliases.h" + +namespace ads { + +namespace ad_targeting { +namespace geographic { +class SubdivisionTargeting; +} // namespace geographic +} // namespace ad_targeting + +namespace resource { +class AntiTargeting; +} // namespace resource + +struct CreativeAdInfo; + +class ExclusionRulesBase { + public: + ExclusionRulesBase( + ad_targeting::geographic::SubdivisionTargeting* subdivision_targeting, + resource::AntiTargeting* anti_targeting_resource, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history); + virtual ~ExclusionRulesBase(); + + virtual bool ShouldExcludeCreativeAd(const CreativeAdInfo& creative_ad); + + protected: + ad_targeting::geographic::SubdivisionTargeting* + subdivision_targeting_; // NOT OWNED + resource::AntiTargeting* anti_targeting_resource_; // NOT OWNED + AdEventList ad_events_; + BrowsingHistoryList browsing_history_; + + std::set uuids_; + bool AddToCacheIfNeeded(const CreativeAdInfo& creative_ad, + ExclusionRule* exclusion_rule); + + private: + bool IsCached(const CreativeAdInfo& creative_ad) const; + void AddToCache(const std::string& uuid); + + ExclusionRulesBase(const ExclusionRulesBase&) = delete; + ExclusionRulesBase& operator=(const ExclusionRulesBase&) = delete; +}; + +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_EXCLUSION_RULES_BASE_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.cc index 99ed31f10e2e..c4e8850a5b9e 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.cc @@ -5,26 +5,7 @@ #include "bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.h" -#include "base/check.h" #include "bat/ads/internal/ad_serving/ad_targeting/geographic/subdivision/subdivision_targeting.h" -#include "bat/ads/internal/bundle/creative_ad_info.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule_util.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.h" -#include "bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.h" #include "bat/ads/internal/resources/frequency_capping/anti_targeting_resource.h" namespace ads { @@ -36,100 +17,13 @@ ExclusionRules::ExclusionRules( resource::AntiTargeting* anti_targeting_resource, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history) - : subdivision_targeting_(subdivision_targeting), - anti_targeting_resource_(anti_targeting_resource), - ad_events_(ad_events), - browsing_history_(browsing_history) { - DCHECK(subdivision_targeting_); - DCHECK(anti_targeting_resource_); -} + : ExclusionRulesBase(subdivision_targeting, + anti_targeting_resource, + ad_events, + browsing_history) {} ExclusionRules::~ExclusionRules() = default; -bool ExclusionRules::ShouldExcludeCreativeAd( - const CreativeAdInfo& creative_ad) const { - bool should_exclude = false; - - DailyCapFrequencyCap daily_cap_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &daily_cap_frequency_cap)) { - should_exclude = true; - } - - PerDayFrequencyCap per_day_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &per_day_frequency_cap)) { - should_exclude = true; - } - - PerHourFrequencyCap per_hour_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &per_hour_frequency_cap)) { - should_exclude = true; - } - - PerWeekFrequencyCap per_week_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &per_week_frequency_cap)) { - should_exclude = true; - } - - PerMonthFrequencyCap per_month_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &per_month_frequency_cap)) { - should_exclude = true; - } - - TotalMaxFrequencyCap total_max_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &total_max_frequency_cap)) { - should_exclude = true; - } - - ConversionFrequencyCap conversion_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &conversion_frequency_cap)) { - should_exclude = true; - } - - SubdivisionTargetingFrequencyCap subdivision_frequency_cap( - subdivision_targeting_); - if (ShouldExclude(creative_ad, &subdivision_frequency_cap)) { - should_exclude = true; - } - - DaypartFrequencyCap daypart_frequency_cap; - if (ShouldExclude(creative_ad, &daypart_frequency_cap)) { - should_exclude = true; - } - - TransferredFrequencyCap transferred_frequency_cap(ad_events_); - if (ShouldExclude(creative_ad, &transferred_frequency_cap)) { - should_exclude = true; - } - - DislikeFrequencyCap dislike_frequency_cap; - if (ShouldExclude(creative_ad, &dislike_frequency_cap)) { - should_exclude = true; - } - - MarkedToNoLongerReceiveFrequencyCap marked_to_no_longer_receive_frequency_cap; - if (ShouldExclude(creative_ad, &marked_to_no_longer_receive_frequency_cap)) { - should_exclude = true; - } - - MarkedAsInappropriateFrequencyCap marked_as_inappropriate_frequency_cap; - if (ShouldExclude(creative_ad, &marked_as_inappropriate_frequency_cap)) { - should_exclude = true; - } - - SplitTestFrequencyCap split_test_frequency_cap; - if (ShouldExclude(creative_ad, &split_test_frequency_cap)) { - should_exclude = true; - } - - AntiTargetingFrequencyCap anti_targeting_frequency_cap( - anti_targeting_resource_, browsing_history_); - if (ShouldExclude(creative_ad, &anti_targeting_frequency_cap)) { - should_exclude = true; - } - - return should_exclude; -} - } // namespace frequency_capping } // namespace inline_content_ads } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.h index 5b7cc84be78f..429c509f8407 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.h @@ -6,13 +6,10 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_INLINE_CONTENT_ADS_INLINE_CONTENT_AD_EXCLUSION_RULES_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_INLINE_CONTENT_ADS_INLINE_CONTENT_AD_EXCLUSION_RULES_H_ -#include "bat/ads/internal/ad_events/ad_event_info_aliases.h" -#include "bat/ads/internal/frequency_capping/frequency_capping_aliases.h" +#include "bat/ads/internal/ads/exclusion_rules_base.h" namespace ads { -struct CreativeAdInfo; - namespace ad_targeting { namespace geographic { class SubdivisionTargeting; @@ -26,23 +23,16 @@ class AntiTargeting; namespace inline_content_ads { namespace frequency_capping { -class ExclusionRules final { +class ExclusionRules final : public ExclusionRulesBase { public: ExclusionRules( ad_targeting::geographic::SubdivisionTargeting* subdivision_targeting, resource::AntiTargeting* anti_targeting_resource, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history); - ~ExclusionRules(); - - bool ShouldExcludeCreativeAd(const CreativeAdInfo& creative_ad) const; + ~ExclusionRules() override; private: - ad_targeting::geographic::SubdivisionTargeting* subdivision_targeting_; - resource::AntiTargeting* anti_targeting_resource_; - AdEventList ad_events_; - BrowsingHistoryList browsing_history_; - ExclusionRules(const ExclusionRules&) = delete; ExclusionRules& operator=(const ExclusionRules&) = delete; }; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/bundle/bundle.cc b/vendor/bat-native-ads/src/bat/ads/internal/bundle/bundle.cc index b4adbb5f5dda..0e21bd1721cc 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/bundle/bundle.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/bundle/bundle.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -88,7 +89,7 @@ BundleInfo Bundle::FromCatalog(const Catalog& catalog) const { // Campaigns for (const auto& campaign : catalog.GetCampaigns()) { // Geo Targets - std::vector geo_targets; + std::set geo_targets; for (const auto& geo_target : campaign.geo_targets) { std::string code = geo_target.code; @@ -97,7 +98,7 @@ BundleInfo Bundle::FromCatalog(const Catalog& catalog) const { continue; } - geo_targets.push_back(code); + geo_targets.insert(code); } std::vector creative_dayparts; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_info.h b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_info.h index 74a0fb7f42a3..4937e2aa04ca 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_info.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_info.h @@ -6,6 +6,7 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_BUNDLE_CREATIVE_AD_INFO_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_BUNDLE_CREATIVE_AD_INFO_H_ +#include #include #include @@ -40,7 +41,7 @@ struct CreativeAdInfo { std::string segment; std::string split_test_group; std::vector dayparts; - std::vector geo_targets; + std::set geo_targets; std::string target_url; }; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_notification_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_notification_unittest_util.cc index 6e2cc310eaaa..b6d6d16a0c10 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_notification_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_notification_unittest_util.cc @@ -11,8 +11,8 @@ namespace ads { -CreativeAdNotificationInfo GetCreativeAdNotification() { - const CreativeAdInfo creative_ad = GetCreativeAd(); +CreativeAdNotificationInfo BuildCreativeAdNotification() { + const CreativeAdInfo creative_ad = BuildCreativeAd(); CreativeAdNotificationInfo creative_ad_notification(creative_ad); creative_ad_notification.title = "Test Ad Title"; @@ -21,48 +21,4 @@ CreativeAdNotificationInfo GetCreativeAdNotification() { return creative_ad_notification; } -CreativeAdNotificationInfo GetCreativeAdNotification(const std::string& segment, - const double ptr, - const int priority) { - CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification(); - creative_ad_notification.priority = priority; - creative_ad_notification.ptr = ptr; - creative_ad_notification.segment = segment; - - return creative_ad_notification; -} - -CreativeAdNotificationInfo GetCreativeAdNotification( - const std::string& creative_instance_id, - const std::string& segment) { - CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification(); - - creative_ad_notification.creative_instance_id = creative_instance_id; - creative_ad_notification.segment = segment; - - return creative_ad_notification; -} - -CreativeAdNotificationInfo GetCreativeAdNotificationForAdvertiser( - const std::string& advertiser_id) { - CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification(); - - creative_ad_notification.advertiser_id = advertiser_id; - - return creative_ad_notification; -} - -CreativeAdNotificationInfo GetCreativeAdNotificationForSegment( - const std::string& segment) { - CreativeAdNotificationInfo creative_ad_notification = - GetCreativeAdNotification(); - - creative_ad_notification.segment = segment; - - return creative_ad_notification; -} - } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_notification_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_notification_unittest_util.h index 8938dee55457..c71539e90fb6 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_notification_unittest_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_notification_unittest_util.h @@ -6,27 +6,11 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_BUNDLE_CREATIVE_AD_NOTIFICATION_UNITTEST_UTIL_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_BUNDLE_CREATIVE_AD_NOTIFICATION_UNITTEST_UTIL_H_ -#include - namespace ads { struct CreativeAdNotificationInfo; -CreativeAdNotificationInfo GetCreativeAdNotification(); - -CreativeAdNotificationInfo GetCreativeAdNotification(const std::string& segment, - const double ptr, - const int priority); - -CreativeAdNotificationInfo GetCreativeAdNotification( - const std::string& creative_instance_id, - const std::string& segment); - -CreativeAdNotificationInfo GetCreativeAdNotificationForAdvertiser( - const std::string& advertiser_id); - -CreativeAdNotificationInfo GetCreativeAdNotificationForSegment( - const std::string& segment); +CreativeAdNotificationInfo BuildCreativeAdNotification(); } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_unittest_util.cc index 82dda5607c0a..ecbc78074bfc 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_unittest_util.cc @@ -11,7 +11,7 @@ namespace ads { -CreativeAdInfo GetCreativeAd() { +CreativeAdInfo BuildCreativeAd() { CreativeAdInfo creative_ad; creative_ad.creative_instance_id = base::GenerateGUID(); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_unittest_util.h index b477b760dad3..0c6113c36200 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_unittest_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_ad_unittest_util.h @@ -12,7 +12,7 @@ namespace ads { struct CreativeAdInfo; -CreativeAdInfo GetCreativeAd(); +CreativeAdInfo BuildCreativeAd(); } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_inline_content_ad_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_inline_content_ad_unittest_util.cc index 24d2fa01f25c..e5398bca09f4 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_inline_content_ad_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_inline_content_ad_unittest_util.cc @@ -10,8 +10,8 @@ namespace ads { -CreativeInlineContentAdInfo GetCreativeInlineContentAd() { - const CreativeAdInfo creative_ad = GetCreativeAd(); +CreativeInlineContentAdInfo BuildCreativeInlineContentAd() { + const CreativeAdInfo creative_ad = BuildCreativeAd(); CreativeInlineContentAdInfo creative_inline_content_ad(creative_ad); creative_inline_content_ad.title = "Test Ad Title"; @@ -23,11 +23,4 @@ CreativeInlineContentAdInfo GetCreativeInlineContentAd() { return creative_inline_content_ad; } -CreativeInlineContentAdInfo GetCreativeInlineContentAdForSegment( - const std::string& segment) { - CreativeInlineContentAdInfo creative_ad = GetCreativeInlineContentAd(); - creative_ad.segment = segment; - return creative_ad; -} - } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_inline_content_ad_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_inline_content_ad_unittest_util.h index 3bf43c461c04..be31458d3834 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_inline_content_ad_unittest_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/bundle/creative_inline_content_ad_unittest_util.h @@ -6,16 +6,11 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_BUNDLE_CREATIVE_INLINE_CONTENT_AD_UNITTEST_UTIL_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_BUNDLE_CREATIVE_INLINE_CONTENT_AD_UNITTEST_UTIL_H_ -#include - namespace ads { struct CreativeInlineContentAdInfo; -CreativeInlineContentAdInfo GetCreativeInlineContentAd(); - -CreativeInlineContentAdInfo GetCreativeInlineContentAdForSegment( - const std::string& segment); +CreativeInlineContentAdInfo BuildCreativeInlineContentAd(); } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversions_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversions_unittest.cc index 50ab951c5137..4d373ec7b52a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversions_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversions_unittest.cc @@ -8,7 +8,7 @@ #include #include "base/strings/stringprintf.h" -#include "bat/ads/internal/ad_events/ad_events.h" +#include "bat/ads/internal/ad_events/ad_event_unittest_util.h" #include "bat/ads/internal/database/tables/ad_events_database_table.h" #include "bat/ads/internal/database/tables/conversion_queue_database_table.h" #include "bat/ads/internal/database/tables/conversions_database_table.h" @@ -44,18 +44,6 @@ class BatAdsConversionsTest : public UnitTestBase { return Now() + base::TimeDelta::FromDays(observation_window); } - void FireAdEvent(const std::string& creative_set_id, - const ConfirmationType confirmation_type) { - AdEventInfo ad_event; - ad_event.type = AdType::kAdNotification; - ad_event.creative_instance_id = "7a3b6d9f-d0b7-4da6-8988-8d5b8938c94f"; - ad_event.creative_set_id = creative_set_id; - ad_event.confirmation_type = confirmation_type; - ad_event.created_at = Now(); - - LogAdEvent(ad_event, [](const bool success) { ASSERT_TRUE(success); }); - } - std::unique_ptr conversions_; std::unique_ptr ad_events_database_table_; std::unique_ptr @@ -110,7 +98,9 @@ TEST_F(BatAdsConversionsTest, ConvertViewedAd) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act conversions_->MaybeConvert({"https://www.foo.com/bar"}, "", {}); @@ -146,8 +136,12 @@ TEST_F(BatAdsConversionsTest, ConvertClickedAd) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kClicked); + const AdEventInfo ad_event_1 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event_1); + const AdEventInfo ad_event_2 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kClicked); + FireAdEvent(ad_event_2); // Act conversions_->MaybeConvert({"https://www.foo.com/bar/baz"}, "", {}); @@ -193,10 +187,21 @@ TEST_F(BatAdsConversionsTest, ConvertMultipleAds) { SaveConversions(conversions); - FireAdEvent(conversion_1.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event_1 = + BuildAdEvent("7ee858e8-6306-4317-88c3-9e7d58afad26", + conversion_1.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event_1); + + AdvanceClock(base::TimeDelta::FromMinutes(1)); - FireAdEvent(conversion_2.creative_set_id, ConfirmationType::kViewed); - FireAdEvent(conversion_2.creative_set_id, ConfirmationType::kClicked); + const AdEventInfo ad_event_2 = + BuildAdEvent("da2d3397-bc97-46d1-a323-d8723c0a6b33", + conversion_2.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event_2); + const AdEventInfo ad_event_3 = + BuildAdEvent("da2d3397-bc97-46d1-a323-d8723c0a6b33", + conversion_2.creative_set_id, ConfirmationType::kClicked); + FireAdEvent(ad_event_3); // Act conversions_->MaybeConvert({"https://www.foo.com/qux"}, "", {}); @@ -218,11 +223,11 @@ TEST_F(BatAdsConversionsTest, ConvertMultipleAds) { EXPECT_EQ(2UL, ad_events.size()); const ConversionInfo conversion_1 = conversions.at(0); - const AdEventInfo ad_event_1 = ad_events.at(0); + const AdEventInfo ad_event_1 = ad_events.at(1); EXPECT_EQ(conversion_1.creative_set_id, ad_event_1.creative_set_id); const ConversionInfo conversion_2 = conversions.at(1); - const AdEventInfo ad_event_2 = ad_events.at(1); + const AdEventInfo ad_event_2 = ad_events.at(0); EXPECT_EQ(conversion_2.creative_set_id, ad_event_2.creative_set_id); }); } @@ -241,8 +246,12 @@ TEST_F(BatAdsConversionsTest, ConvertViewedAdWhenAdWasDismissed) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kDismissed); + const AdEventInfo ad_event_1 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event_1); + const AdEventInfo ad_event_2 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kClicked); + FireAdEvent(ad_event_2); // Act conversions_->MaybeConvert({"https://www.foo.com/quxbarbaz"}, "", {}); @@ -278,11 +287,21 @@ TEST_F(BatAdsConversionsTest, DoNotConvertNonViewedOrClickedAds) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kDismissed); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kTransferred); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kFlagged); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kUpvoted); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kDownvoted); + const AdEventInfo ad_event_1 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kDismissed); + FireAdEvent(ad_event_1); + const AdEventInfo ad_event_2 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kTransferred); + FireAdEvent(ad_event_2); + const AdEventInfo ad_event_3 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kFlagged); + FireAdEvent(ad_event_3); + const AdEventInfo ad_event_4 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kUpvoted); + FireAdEvent(ad_event_4); + const AdEventInfo ad_event_5 = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kDownvoted); + FireAdEvent(ad_event_5); // Act conversions_->MaybeConvert({"https://www.foo.com/bar"}, "", {}); @@ -314,7 +333,9 @@ TEST_F(BatAdsConversionsTest, DoNotConvertViewedAdForPostClick) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act conversions_->MaybeConvert({"https://www.foo.com/bar"}, "", {}); @@ -336,7 +357,9 @@ TEST_F(BatAdsConversionsTest, DoNotConvertAdIfConversionDoesNotExist) { // Arrange const std::string creative_set_id = "3519f52c-46a4-4c48-9c2b-c264c0067f04"; - FireAdEvent(creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act conversions_->MaybeConvert({"https://www.foo.com/bar"}, "", {}); @@ -369,7 +392,9 @@ TEST_F(BatAdsConversionsTest, SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); conversions_->MaybeConvert({"https://www.foo.com/bar"}, "", {}); @@ -408,7 +433,9 @@ TEST_F(BatAdsConversionsTest, SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act conversions_->MaybeConvert({"https://www.foo.com/qux"}, "", {}); @@ -440,7 +467,9 @@ TEST_F(BatAdsConversionsTest, ConvertAdWhenTheConversionIsOnTheCuspOfExpiring) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); task_environment_.FastForwardBy(base::TimeDelta::FromDays(3) - base::TimeDelta::FromMinutes(1)); @@ -479,7 +508,9 @@ TEST_F(BatAdsConversionsTest, DoNotConvertAdWhenTheConversionHasExpired) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); task_environment_.FastForwardBy(base::TimeDelta::FromDays(3)); @@ -513,7 +544,9 @@ TEST_F(BatAdsConversionsTest, ConvertAdForRedirectChainIntermediateUrl) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act conversions_->MaybeConvert( @@ -551,7 +584,9 @@ TEST_F(BatAdsConversionsTest, ConvertAdForRedirectChainOriginalUrl) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act conversions_->MaybeConvert( @@ -589,7 +624,9 @@ TEST_F(BatAdsConversionsTest, ConvertAdForRedirectChainUrl) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act conversions_->MaybeConvert( @@ -632,7 +669,9 @@ TEST_F(BatAdsConversionsTest, ExtractConversionId) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act conversions_->MaybeConvert( @@ -676,7 +715,9 @@ TEST_F(BatAdsConversionsTest, ExtractConversionIdWithResourcePatternFromHtml) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act // See associated patterns in the verifiable conversion resource @@ -721,7 +762,9 @@ TEST_F(BatAdsConversionsTest, ExtractConversionIdWithResourcePatternFromUrl) { SaveConversions(conversions); - FireAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + const AdEventInfo ad_event = + BuildAdEvent(conversion.creative_set_id, ConfirmationType::kViewed); + FireAdEvent(ad_event); // Act // See associated patterns in the verifiable conversion resource diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/database_migration_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/database_migration_unittest.cc index 68733856ceba..481c591c3e97 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/database_migration_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/database_migration_unittest.cc @@ -5,6 +5,7 @@ #include "base/strings/stringprintf.h" #include "bat/ads/internal/ad_events/ad_event_info.h" +#include "bat/ads/internal/ad_events/ad_event_unittest_util.h" #include "bat/ads/internal/ad_events/ad_events.h" #include "bat/ads/internal/database/database_version.h" #include "bat/ads/internal/unittest_base.h" @@ -34,26 +35,11 @@ class BatAdsDatabaseMigrationTest : public UnitTestBase, } int GetSchemaVersion() { return GetParam() + 1; } - - AdEventInfo GetAdEvent() { - AdEventInfo ad_event; - - ad_event.type = AdType::kAdNotification; - ad_event.confirmation_type = ConfirmationType::kViewed; - ad_event.uuid = "90ca9157-9c1a-484a-b52b-86e3dfea7d9c"; - ad_event.campaign_id = "b6c52182-dcbc-4932-aafa-34e6d2420383"; - ad_event.creative_set_id = "93af82a4-f929-4eb2-8af9-f5f2cafc3ed0"; - ad_event.creative_instance_id = "59b43768-40ad-4d3e-8a04-61431a75cd24"; - ad_event.advertiser_id = "46afa495-cf5b-405b-94de-25cff55f05e7"; - ad_event.created_at = Now(); - - return ad_event; - } }; TEST_P(BatAdsDatabaseMigrationTest, MigrateFromSchema) { // Arrange - const AdEventInfo ad_event = GetAdEvent(); + const AdEventInfo ad_event = BuildAdEvent(ConfirmationType::kViewed); // Act LogAdEvent(ad_event, [=](const bool success) { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/database_version.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/database_version.cc index cbddce7098b8..e77a0ecc4570 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/database_version.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/database_version.cc @@ -9,11 +9,11 @@ namespace ads { namespace database { int32_t version() { - return 16; + return 17; } int32_t compatible_version() { - return 16; + return 17; } } // namespace database diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/ad_events_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/ad_events_database_table.cc index b72748c5b186..b473491de173 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/ad_events_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/ad_events_database_table.cc @@ -142,6 +142,11 @@ void AdEvents::Migrate(mojom::DBTransaction* transaction, break; } + case 17: { + MigrateToV17(transaction); + break; + } + default: { break; } @@ -355,6 +360,12 @@ void AdEvents::MigrateToV13(mojom::DBTransaction* transaction) { util::Drop(transaction, "ad_events_temp"); } +void AdEvents::MigrateToV17(mojom::DBTransaction* transaction) { + DCHECK(transaction); + + util::CreateIndex(transaction, "ad_events", "timestamp"); +} + } // namespace table } // namespace database } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/ad_events_database_table.h b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/ad_events_database_table.h index 68b60b28654a..d79586a6471c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/ad_events_database_table.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/ad_events_database_table.h @@ -59,6 +59,8 @@ class AdEvents final : public Table { void CreateTableV13(mojom::DBTransaction* transaction); void MigrateToV13(mojom::DBTransaction* transaction); + + void MigrateToV17(mojom::DBTransaction* transaction); }; } // namespace table diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/conversion_queue_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/conversion_queue_database_table.cc index 7849ce2485fe..e99e96e60540 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/conversion_queue_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/conversion_queue_database_table.cc @@ -183,6 +183,11 @@ void ConversionQueue::Migrate(mojom::DBTransaction* transaction, break; } + case 17: { + MigrateToV17(transaction); + break; + } + default: { break; } @@ -375,6 +380,12 @@ void ConversionQueue::MigrateToV11(mojom::DBTransaction* transaction) { util::Rename(transaction, temp_table_name, GetTableName()); } +void ConversionQueue::MigrateToV17(mojom::DBTransaction* transaction) { + DCHECK(transaction); + + util::CreateIndex(transaction, "conversion_queue", "creative_instance_id"); +} + } // namespace table } // namespace database } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/conversion_queue_database_table.h b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/conversion_queue_database_table.h index c80f2945e48a..dc70e48544ab 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/conversion_queue_database_table.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/conversion_queue_database_table.h @@ -76,6 +76,8 @@ class ConversionQueue final : public Table { void MigrateToV11(mojom::DBTransaction* transaction); + void MigrateToV17(mojom::DBTransaction* transaction); + int batch_size_; }; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table.cc index 1a38bff53deb..8b1e938935df 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table.cc @@ -420,7 +420,7 @@ CreativeAdNotificationInfo CreativeAdNotifications::GetFromRecord( creative_ad_notification.value = ColumnDouble(record, 13); creative_ad_notification.split_test_group = ColumnString(record, 14); creative_ad_notification.segment = ColumnString(record, 15); - creative_ad_notification.geo_targets.push_back(ColumnString(record, 16)); + creative_ad_notification.geo_targets.insert(ColumnString(record, 16)); creative_ad_notification.target_url = ColumnString(record, 17); creative_ad_notification.title = ColumnString(record, 18); creative_ad_notification.body = ColumnString(record, 19); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table_test.cc index 89fd92d3e657..0c6dc3fa7c56 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table_test.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table_test.cc @@ -5,6 +5,8 @@ #include "bat/ads/internal/database/tables/creative_ad_notifications_database_table.h" +#include + #include "bat/ads/internal/unittest_base.h" #include "bat/ads/internal/unittest_util.h" #include "net/http/http_status_code.h" @@ -41,13 +43,12 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableIntegrationTest, // Assert const std::vector segments = {"technology & computing"}; - database::table::CreativeAdNotifications creative_ad_notifications; - creative_ad_notifications.GetForSegments( - segments, - [](const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + database::table::CreativeAdNotifications creative_ads; + creative_ads.GetForSegments( + segments, [](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_EQ(2UL, creative_ad_notifications.size()); + EXPECT_EQ(2UL, creative_ads.size()); }); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table_unittest.cc index aff0a654d7ae..bd33b7bd498b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_ad_notifications_database_table_unittest.cc @@ -24,8 +24,8 @@ class BatAdsCreativeAdNotificationsDatabaseTableTest : public UnitTestBase { ~BatAdsCreativeAdNotificationsDatabaseTableTest() override = default; - void Save(const CreativeAdNotificationList& creative_ad_notifications) { - database_table_->Save(creative_ad_notifications, + void Save(const CreativeAdNotificationList& creative_ads) { + database_table_->Save(creative_ads, [](const bool success) { ASSERT_TRUE(success); }); } @@ -35,10 +35,10 @@ class BatAdsCreativeAdNotificationsDatabaseTableTest : public UnitTestBase { TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, SaveEmptyCreativeAdNotifications) { // Arrange - CreativeAdNotificationList creative_ad_notifications = {}; + CreativeAdNotificationList creative_ads = {}; // Act - Save(creative_ad_notifications); + Save(creative_ads); // Assert } @@ -46,7 +46,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, SaveCreativeAdNotifications) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info_1; @@ -70,7 +70,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_1.title = "Test Ad 1 Title"; info_1.body = "Test Ad 1 Body"; info_1.ptr = 1.0; - creative_ad_notifications.push_back(info_1); + creative_ads.push_back(info_1); CreativeAdNotificationInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -93,25 +93,22 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_2.title = "Test Ad 2 Title"; info_2.body = "Test Ad 2 Body"; info_2.ptr = 0.8; - creative_ad_notifications.push_back(info_2); + creative_ads.push_back(info_2); // Act - Save(creative_ad_notifications); + Save(creative_ads); // Assert - const CreativeAdNotificationList expected_creative_ad_notifications = - creative_ad_notifications; + const CreativeAdNotificationList expected_creative_ads = creative_ads; const SegmentList segments = {"technology & computing-software"}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } @@ -120,7 +117,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, // Arrange database_table_->set_batch_size(2); - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info_1; @@ -144,7 +141,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_1.title = "Test Ad 1 Title"; info_1.body = "Test Ad 1 Body"; info_1.ptr = 1.0; - creative_ad_notifications.push_back(info_1); + creative_ads.push_back(info_1); CreativeAdNotificationInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -167,7 +164,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_2.title = "Test Ad 2 Title"; info_2.body = "Test Ad 2 Body"; info_2.ptr = 1.0; - creative_ad_notifications.push_back(info_2); + creative_ads.push_back(info_2); CreativeAdNotificationInfo info_3; info_3.creative_instance_id = "a1ac44c2-675f-43e6-ab6d-500614cafe63"; @@ -190,32 +187,29 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_3.title = "Test Ad 3 Title"; info_3.body = "Test Ad 3 Body"; info_3.ptr = 1.0; - creative_ad_notifications.push_back(info_3); + creative_ads.push_back(info_3); // Act - Save(creative_ad_notifications); + Save(creative_ads); // Assert - const CreativeAdNotificationList expected_creative_ad_notifications = - creative_ad_notifications; + const CreativeAdNotificationList expected_creative_ads = creative_ads; const SegmentList segments = {"technology & computing-software"}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, DoNotSaveDuplicateCreativeAdNotifications) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info; @@ -239,34 +233,31 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info.title = "Test Ad 1 Title"; info.body = "Test Ad 1 Body"; info.ptr = 1.0; - creative_ad_notifications.push_back(info); + creative_ads.push_back(info); - Save(creative_ad_notifications); + Save(creative_ads); // Act - Save(creative_ad_notifications); + Save(creative_ads); // Assert - const CreativeAdNotificationList expected_creative_ad_notifications = - creative_ad_notifications; + const CreativeAdNotificationList expected_creative_ads = creative_ads; const SegmentList segments = {"technology & computing-software"}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, GetCreativeAdNotifications) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info_1; @@ -290,7 +281,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_1.title = "Test Ad 1 Title"; info_1.body = "Test Ad 1 Body"; info_1.ptr = 1.0; - creative_ad_notifications.push_back(info_1); + creative_ads.push_back(info_1); CreativeAdNotificationInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -313,33 +304,30 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_2.title = "Test Ad 2 Title"; info_2.body = "Test Ad 2 Body"; info_2.ptr = 1.0; - creative_ad_notifications.push_back(info_2); + creative_ads.push_back(info_2); - Save(creative_ad_notifications); + Save(creative_ads); // Act // Assert - const CreativeAdNotificationList expected_creative_ad_notifications = - creative_ad_notifications; + const CreativeAdNotificationList expected_creative_ads = creative_ads; const SegmentList segments = {"technology & computing-software"}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, GetCreativeAdNotificationsForEmptySegments) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info; @@ -363,32 +351,30 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info.title = "Test Ad 1 Title"; info.body = "Test Ad 1 Body"; info.ptr = 1.0; - creative_ad_notifications.push_back(info); + creative_ads.push_back(info); - Save(creative_ad_notifications); + Save(creative_ads); // Act // Assert - const CreativeAdNotificationList expected_creative_ad_notifications = {}; + const CreativeAdNotificationList expected_creative_ads = {}; const SegmentList segments = {}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, GetCreativeAdNotificationsForNonExistentCategory) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info; @@ -412,32 +398,30 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info.title = "Test Ad 1 Title"; info.body = "Test Ad 1 Body"; info.ptr = 1.0; - creative_ad_notifications.push_back(info); + creative_ads.push_back(info); - Save(creative_ad_notifications); + Save(creative_ads); // Act // Assert - const CreativeAdNotificationList expected_creative_ad_notifications = {}; + const CreativeAdNotificationList expected_creative_ads = {}; const SegmentList segments = {"food & drink"}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, GetCreativeAdNotificationsFromMultipleSegments) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info_1; @@ -461,7 +445,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_1.title = "Test Ad 1 Title"; info_1.body = "Test Ad 1 Body"; info_1.ptr = 1.0; - creative_ad_notifications.push_back(info_1); + creative_ads.push_back(info_1); CreativeAdNotificationInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -484,7 +468,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_2.title = "Test Ad 2 Title"; info_2.body = "Test Ad 2 Body"; info_2.ptr = 1.0; - creative_ad_notifications.push_back(info_2); + creative_ads.push_back(info_2); CreativeAdNotificationInfo info_3; info_3.creative_instance_id = "a1ac44c2-675f-43e6-ab6d-500614cafe63"; @@ -507,35 +491,33 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_3.title = "Test Ad 3 Title"; info_3.body = "Test Ad 3 Body"; info_3.ptr = 1.0; - creative_ad_notifications.push_back(info_3); + creative_ads.push_back(info_3); - Save(creative_ad_notifications); + Save(creative_ads); // Act // Assert - CreativeAdNotificationList expected_creative_ad_notifications; - expected_creative_ad_notifications.push_back(info_1); - expected_creative_ad_notifications.push_back(info_2); + CreativeAdNotificationList expected_creative_ads; + expected_creative_ads.push_back(info_1); + expected_creative_ads.push_back(info_2); const std::vector segments = {"technology & computing-software", "food & drink"}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, GetNonExpiredCreativeAdNotifications) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info_1; @@ -559,7 +541,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_1.title = "Test Ad 1 Title"; info_1.body = "Test Ad 1 Body"; info_1.ptr = 1.0; - creative_ad_notifications.push_back(info_1); + creative_ads.push_back(info_1); CreativeAdNotificationInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -582,34 +564,32 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_2.title = "Test Ad 2 Title"; info_2.body = "Test Ad 2 Body"; info_2.ptr = 1.0; - creative_ad_notifications.push_back(info_2); + creative_ads.push_back(info_2); - Save(creative_ad_notifications); + Save(creative_ads); // Act FastForwardClockBy(base::TimeDelta::FromHours(1)); // Assert - CreativeAdNotificationList expected_creative_ad_notifications; - expected_creative_ad_notifications.push_back(info_2); + CreativeAdNotificationList expected_creative_ads; + expected_creative_ads.push_back(info_2); const SegmentList segments = {"technology & computing-software"}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, GetCreativeAdNotificationsMatchingCaseInsensitiveSegments) { // Arrange - CreativeAdNotificationList creative_ad_notifications; + CreativeAdNotificationList creative_ads; CreativeDaypartInfo daypart_info; CreativeAdNotificationInfo info_1; @@ -633,7 +613,7 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_1.title = "Test Ad 1 Title"; info_1.body = "Test Ad 1 Body"; info_1.ptr = 1.0; - creative_ad_notifications.push_back(info_1); + creative_ads.push_back(info_1); CreativeAdNotificationInfo info_2; info_2.creative_instance_id = "a1ac44c2-675f-43e6-ab6d-500614cafe63"; @@ -656,26 +636,24 @@ TEST_F(BatAdsCreativeAdNotificationsDatabaseTableTest, info_2.title = "Test Ad 2 Title"; info_2.body = "Test Ad 2 Body"; info_2.ptr = 1.0; - creative_ad_notifications.push_back(info_2); + creative_ads.push_back(info_2); - Save(creative_ad_notifications); + Save(creative_ads); // Act // Assert - CreativeAdNotificationList expected_creative_ad_notifications; - expected_creative_ad_notifications.push_back(info_2); + CreativeAdNotificationList expected_creative_ads; + expected_creative_ads.push_back(info_2); const SegmentList segments = {"FoOd & DrInK"}; database_table_->GetForSegments( segments, - [&expected_creative_ad_notifications]( - const bool success, const SegmentList& segments, - const CreativeAdNotificationList& creative_ad_notifications) { + [&expected_creative_ads](const bool success, const SegmentList& segments, + const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_ad_notifications, - creative_ad_notifications)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table.cc index 2fad6c4565b6..e535d6e9d358 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table.cc @@ -682,7 +682,7 @@ CreativeInlineContentAdInfo CreativeInlineContentAds::GetFromRecord( creative_inline_content_ad.value = ColumnDouble(record, 13); creative_inline_content_ad.split_test_group = ColumnString(record, 14); creative_inline_content_ad.segment = ColumnString(record, 15); - creative_inline_content_ad.geo_targets.push_back(ColumnString(record, 16)); + creative_inline_content_ad.geo_targets.insert(ColumnString(record, 16)); creative_inline_content_ad.target_url = ColumnString(record, 17); creative_inline_content_ad.title = ColumnString(record, 18); creative_inline_content_ad.description = ColumnString(record, 19); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table_test.cc index b65bc466967b..0fab23d28713 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table_test.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table_test.cc @@ -43,13 +43,13 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableIntegrationTest, // Assert const std::vector segments = {"technology & computing"}; - database::table::CreativeInlineContentAds creative_inline_content_ads; - creative_inline_content_ads.GetForSegmentsAndDimensions( + database::table::CreativeInlineContentAds creative_ads; + creative_ads.GetForSegmentsAndDimensions( segments, "200x100", [](const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { + const CreativeInlineContentAdList& creative_ads) { EXPECT_TRUE(success); - EXPECT_EQ(1UL, creative_inline_content_ads.size()); + EXPECT_EQ(1UL, creative_ads.size()); }); } @@ -66,13 +66,12 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableIntegrationTest, // Act // Assert - database::table::CreativeInlineContentAds creative_inline_content_ads; - creative_inline_content_ads.GetForDimensions( + database::table::CreativeInlineContentAds creative_ads; + creative_ads.GetForDimensions( "200x100", - [](const bool success, - const CreativeInlineContentAdList& creative_inline_content_ads) { + [](const bool success, const CreativeInlineContentAdList& creative_ads) { EXPECT_TRUE(success); - EXPECT_EQ(1UL, creative_inline_content_ads.size()); + EXPECT_EQ(1UL, creative_ads.size()); }); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table_unittest.cc index 5cce92a8be7d..1b7808fc770b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_inline_content_ads_database_table_unittest.cc @@ -22,8 +22,8 @@ class BatAdsCreativeInlineContentAdsDatabaseTableTest : public UnitTestBase { ~BatAdsCreativeInlineContentAdsDatabaseTableTest() override = default; - void Save(const CreativeInlineContentAdList& creative_inline_content_ads) { - database_table_->Save(creative_inline_content_ads, + void Save(const CreativeInlineContentAdList& creative_ads) { + database_table_->Save(creative_ads, [](const bool success) { ASSERT_TRUE(success); }); } @@ -33,10 +33,10 @@ class BatAdsCreativeInlineContentAdsDatabaseTableTest : public UnitTestBase { TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, SaveEmptyCreativeInlineContentAds) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads = {}; + CreativeInlineContentAdList creative_ads = {}; // Act - Save(creative_inline_content_ads); + Save(creative_ads); // Assert } @@ -44,7 +44,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, SaveCreativeInlineContentAds) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info_1; @@ -69,7 +69,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_1.dimensions = "200x100"; info_1.cta_text = "Call to Action Text 1"; info_1.ptr = 1.0; - creative_inline_content_ads.push_back(info_1); + creative_ads.push_back(info_1); CreativeInlineContentAdInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -93,23 +93,20 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_2.dimensions = "200x100"; info_2.cta_text = "Call to Action Text 2"; info_2.ptr = 0.9; - creative_inline_content_ads.push_back(info_2); + creative_ads.push_back(info_2); // Act - Save(creative_inline_content_ads); + Save(creative_ads); // Assert - const CreativeInlineContentAdList expected_creative_inline_content_ads = - creative_inline_content_ads; - - database_table_->GetAll( - [&expected_creative_inline_content_ads]( - const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { - EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); - }); + const CreativeInlineContentAdList expected_creative_ads = creative_ads; + + database_table_->GetAll([&expected_creative_ads]( + const bool success, const SegmentList& segments, + const CreativeInlineContentAdList& creative_ads) { + EXPECT_TRUE(success); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); + }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, @@ -117,7 +114,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, // Arrange database_table_->set_batch_size(2); - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info_1; @@ -142,7 +139,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_1.dimensions = "200x100"; info_1.cta_text = "Call to Action Text 1"; info_1.ptr = 1.0; - creative_inline_content_ads.push_back(info_1); + creative_ads.push_back(info_1); CreativeInlineContentAdInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -166,7 +163,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_2.dimensions = "200x100"; info_2.cta_text = "Call to Action Text 2"; info_2.ptr = 0.9; - creative_inline_content_ads.push_back(info_2); + creative_ads.push_back(info_2); CreativeInlineContentAdInfo info_3; info_3.creative_instance_id = "a1ac44c2-675f-43e6-ab6d-500614cafe63"; @@ -190,29 +187,26 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_3.dimensions = "200x100"; info_3.cta_text = "Call to Action Text 3"; info_3.ptr = 1.0; - creative_inline_content_ads.push_back(info_3); + creative_ads.push_back(info_3); // Act - Save(creative_inline_content_ads); + Save(creative_ads); // Assert - const CreativeInlineContentAdList expected_creative_inline_content_ads = - creative_inline_content_ads; - - database_table_->GetAll( - [&expected_creative_inline_content_ads]( - const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { - EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); - }); + const CreativeInlineContentAdList expected_creative_ads = creative_ads; + + database_table_->GetAll([&expected_creative_ads]( + const bool success, const SegmentList& segments, + const CreativeInlineContentAdList& creative_ads) { + EXPECT_TRUE(success); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); + }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, DoNotSaveDuplicateCreativeInlineContentAds) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info; @@ -237,32 +231,29 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info.dimensions = "200x100"; info.cta_text = "Call to Action Text"; info.ptr = 1.0; - creative_inline_content_ads.push_back(info); + creative_ads.push_back(info); - Save(creative_inline_content_ads); + Save(creative_ads); // Act - Save(creative_inline_content_ads); + Save(creative_ads); // Assert - const CreativeInlineContentAdList expected_creative_inline_content_ads = - creative_inline_content_ads; - - database_table_->GetAll( - [&expected_creative_inline_content_ads]( - const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { - EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); - }); + const CreativeInlineContentAdList expected_creative_ads = creative_ads; + + database_table_->GetAll([&expected_creative_ads]( + const bool success, const SegmentList& segments, + const CreativeInlineContentAdList& creative_ads) { + EXPECT_TRUE(success); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); + }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, GetForSegmentsAndDimensions) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info_1; @@ -287,7 +278,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_1.dimensions = "200x100"; info_1.cta_text = "Call to Action Text 1"; info_1.ptr = 1.0; - creative_inline_content_ads.push_back(info_1); + creative_ads.push_back(info_1); CreativeInlineContentAdInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -311,30 +302,27 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_2.dimensions = "200x100"; info_2.cta_text = "Call to Action Text 2"; info_2.ptr = 0.9; - creative_inline_content_ads.push_back(info_2); + creative_ads.push_back(info_2); - Save(creative_inline_content_ads); + Save(creative_ads); // Act // Assert - const CreativeInlineContentAdList expected_creative_inline_content_ads = - creative_inline_content_ads; - - database_table_->GetAll( - [&expected_creative_inline_content_ads]( - const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { - EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); - }); + const CreativeInlineContentAdList expected_creative_ads = creative_ads; + + database_table_->GetAll([&expected_creative_ads]( + const bool success, const SegmentList& segments, + const CreativeInlineContentAdList& creative_ads) { + EXPECT_TRUE(success); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); + }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, GetCreativeInlineContentAdsForCreativeInstanceId) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info; @@ -359,33 +347,32 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info.dimensions = "200x100"; info.cta_text = "Call to Action Text"; info.ptr = 1.0; - creative_inline_content_ads.push_back(info); + creative_ads.push_back(info); - Save(creative_inline_content_ads); + Save(creative_ads); // Act // Assert - const CreativeInlineContentAdInfo expected_creative_inline_content_ad = info; + const CreativeInlineContentAdInfo expected_creative_ad = info; const std::string creative_instance_id = "3519f52c-46a4-4c48-9c2b-c264c0067f04"; database_table_->GetForCreativeInstanceId( creative_instance_id, - [&expected_creative_inline_content_ad]( - const bool success, const std::string& creative_instance_id, - const CreativeInlineContentAdInfo& creative_inline_content_ad) { + [&expected_creative_ad](const bool success, + const std::string& creative_instance_id, + const CreativeInlineContentAdInfo& creative_ad) { ASSERT_TRUE(success); - EXPECT_EQ(expected_creative_inline_content_ad, - creative_inline_content_ad); + EXPECT_EQ(expected_creative_ad, creative_ad); }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, GetCreativeInlineContentAdsForNonExistentCreativeInstanceId) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info; @@ -410,9 +397,9 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info.dimensions = "200x100"; info.cta_text = "Call to Action Text"; info.ptr = 1.0; - creative_inline_content_ads.push_back(info); + creative_ads.push_back(info); - Save(creative_inline_content_ads); + Save(creative_ads); // Act @@ -423,7 +410,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, database_table_->GetForCreativeInstanceId( creative_instance_id, [](const bool success, const std::string& creative_instance_id, - const CreativeInlineContentAdInfo& creative_inline_content_ad) { + const CreativeInlineContentAdInfo& creative_ad) { EXPECT_FALSE(success); }); } @@ -431,7 +418,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, GetCreativeInlineContentAdsForEmptySegments) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info; @@ -456,32 +443,31 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info.dimensions = "200x100"; info.cta_text = "Call to Action Text"; info.ptr = 1.0; - creative_inline_content_ads.push_back(info); + creative_ads.push_back(info); - Save(creative_inline_content_ads); + Save(creative_ads); // Act // Assert - const CreativeInlineContentAdList expected_creative_inline_content_ads = {}; + const CreativeInlineContentAdList expected_creative_ads = {}; const SegmentList segments = {}; database_table_->GetForSegmentsAndDimensions( segments, "200x100", - [&expected_creative_inline_content_ads]( + [&expected_creative_ads]( const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { + const CreativeInlineContentAdList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, GetCreativeInlineContentAdsForNonExistentCategory) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info; @@ -506,32 +492,31 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info.dimensions = "200x100"; info.cta_text = "Call to Action Text"; info.ptr = 1.0; - creative_inline_content_ads.push_back(info); + creative_ads.push_back(info); - Save(creative_inline_content_ads); + Save(creative_ads); // Act // Assert - const CreativeInlineContentAdList expected_creative_inline_content_ads = {}; + const CreativeInlineContentAdList expected_creative_ads = {}; const SegmentList segments = {"technology & computing"}; database_table_->GetForSegmentsAndDimensions( segments, "200x100", - [&expected_creative_inline_content_ads]( + [&expected_creative_ads]( const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { + const CreativeInlineContentAdList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, GetCreativeInlineContentAdsFromMultipleSegments) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info_1; @@ -556,7 +541,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_1.dimensions = "200x100"; info_1.cta_text = "Call to Action Text 1"; info_1.ptr = 1.0; - creative_inline_content_ads.push_back(info_1); + creative_ads.push_back(info_1); CreativeInlineContentAdInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -580,7 +565,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_2.dimensions = "200x100"; info_2.cta_text = "Call to Action Text 2"; info_2.ptr = 0.9; - creative_inline_content_ads.push_back(info_2); + creative_ads.push_back(info_2); CreativeInlineContentAdInfo info_3; info_3.creative_instance_id = "a1ac44c2-675f-43e6-ab6d-500614cafe63"; @@ -604,35 +589,34 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_3.dimensions = "200x100"; info_3.cta_text = "Call to Action Text 3"; info_3.ptr = 1.0; - creative_inline_content_ads.push_back(info_3); + creative_ads.push_back(info_3); - Save(creative_inline_content_ads); + Save(creative_ads); // Act // Assert - CreativeInlineContentAdList expected_creative_inline_content_ads; - expected_creative_inline_content_ads.push_back(info_1); - expected_creative_inline_content_ads.push_back(info_2); + CreativeInlineContentAdList expected_creative_ads; + expected_creative_ads.push_back(info_1); + expected_creative_ads.push_back(info_2); const SegmentList segments = {"technology & computing-software", "food & drink"}; database_table_->GetForSegmentsAndDimensions( segments, "200x100", - [&expected_creative_inline_content_ads]( + [&expected_creative_ads]( const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { + const CreativeInlineContentAdList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, GetNonExpiredCreativeInlineContentAds) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info_1; @@ -657,7 +641,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_1.dimensions = "200x100"; info_1.cta_text = "Call to Action Text 1"; info_1.ptr = 1.0; - creative_inline_content_ads.push_back(info_1); + creative_ads.push_back(info_1); CreativeInlineContentAdInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -681,34 +665,33 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_2.dimensions = "200x100"; info_2.cta_text = "Call to Action Text 2"; info_2.ptr = 0.9; - creative_inline_content_ads.push_back(info_2); + creative_ads.push_back(info_2); - Save(creative_inline_content_ads); + Save(creative_ads); // Act FastForwardClockBy(base::TimeDelta::FromHours(1)); // Assert - CreativeInlineContentAdList expected_creative_inline_content_ads; - expected_creative_inline_content_ads.push_back(info_2); + CreativeInlineContentAdList expected_creative_ads; + expected_creative_ads.push_back(info_2); const SegmentList segments = {"food & drink"}; database_table_->GetForSegmentsAndDimensions( segments, "200x100", - [&expected_creative_inline_content_ads]( + [&expected_creative_ads]( const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { + const CreativeInlineContentAdList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, GetCreativeInlineContentAdsMatchingCaseInsensitiveSegments) { // Arrange - CreativeInlineContentAdList creative_inline_content_ads; + CreativeInlineContentAdList creative_ads; CreativeDaypartInfo daypart_info; CreativeInlineContentAdInfo info_1; @@ -733,7 +716,7 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_1.dimensions = "200x100"; info_1.cta_text = "Call to Action Text 1"; info_1.ptr = 1.0; - creative_inline_content_ads.push_back(info_1); + creative_ads.push_back(info_1); CreativeInlineContentAdInfo info_2; info_2.creative_instance_id = "eaa6224a-876d-4ef8-a384-9ac34f238631"; @@ -757,26 +740,25 @@ TEST_F(BatAdsCreativeInlineContentAdsDatabaseTableTest, info_2.dimensions = "200x100"; info_2.cta_text = "Call to Action Text 2"; info_2.ptr = 0.9; - creative_inline_content_ads.push_back(info_2); + creative_ads.push_back(info_2); - Save(creative_inline_content_ads); + Save(creative_ads); // Act // Assert - CreativeInlineContentAdList expected_creative_inline_content_ads; - expected_creative_inline_content_ads.push_back(info_1); + CreativeInlineContentAdList expected_creative_ads; + expected_creative_ads.push_back(info_1); const SegmentList segments = {"FoOd & DrInK"}; database_table_->GetForSegmentsAndDimensions( segments, "200x100", - [&expected_creative_inline_content_ads]( + [&expected_creative_ads]( const bool success, const SegmentList& segments, - const CreativeInlineContentAdList& creative_inline_content_ads) { + const CreativeInlineContentAdList& creative_ads) { EXPECT_TRUE(success); - EXPECT_TRUE(CompareAsSets(expected_creative_inline_content_ads, - creative_inline_content_ads)); + EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_new_tab_page_ads_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_new_tab_page_ads_database_table.cc index bc84c6f3acb7..d40ab96c7ec8 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_new_tab_page_ads_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_new_tab_page_ads_database_table.cc @@ -527,7 +527,7 @@ CreativeNewTabPageAdInfo CreativeNewTabPageAds::GetFromRecord( creative_new_tab_page_ad.total_max = ColumnInt(record, 12); creative_new_tab_page_ad.value = ColumnDouble(record, 13); creative_new_tab_page_ad.segment = ColumnString(record, 14); - creative_new_tab_page_ad.geo_targets.push_back(ColumnString(record, 15)); + creative_new_tab_page_ad.geo_targets.insert(ColumnString(record, 15)); creative_new_tab_page_ad.target_url = ColumnString(record, 16); creative_new_tab_page_ad.company_name = ColumnString(record, 17); creative_new_tab_page_ad.alt = ColumnString(record, 18); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_promoted_content_ads_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_promoted_content_ads_database_table.cc index 862b5c5add1c..5ae41f246dbc 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_promoted_content_ads_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/database/tables/creative_promoted_content_ads_database_table.cc @@ -532,7 +532,7 @@ CreativePromotedContentAdInfo CreativePromotedContentAds::GetFromRecord( creative_promoted_content_ad.total_max = ColumnInt(record, 12); creative_promoted_content_ad.value = ColumnDouble(record, 13); creative_promoted_content_ad.segment = ColumnString(record, 14); - creative_promoted_content_ad.geo_targets.push_back(ColumnString(record, 15)); + creative_promoted_content_ad.geo_targets.insert(ColumnString(record, 15)); creative_promoted_content_ad.target_url = ColumnString(record, 16); creative_promoted_content_ad.title = ColumnString(record, 17); creative_promoted_content_ad.description = ColumnString(record, 18); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h deleted file mode 100644 index 8334df9d54d0..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_AD_NOTIFICATIONS_ELIGIBLE_AD_NOTIFICATIONS_ALIASES_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_AD_NOTIFICATIONS_ELIGIBLE_AD_NOTIFICATIONS_ALIASES_H_ - -#include - -#include "bat/ads/internal/bundle/creative_ad_notification_info_aliases.h" - -namespace ads { -namespace ad_notifications { - -using GetEligibleAdsCallback = - std::function; - -} // namespace ad_notifications -} // namespace ads - -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_AD_NOTIFICATIONS_ELIGIBLE_AD_NOTIFICATIONS_ALIASES_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.h index b54aec2f29b7..f73088cc44f6 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.h @@ -6,9 +6,9 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_AD_NOTIFICATIONS_ELIGIBLE_AD_NOTIFICATIONS_BASE_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_AD_NOTIFICATIONS_ELIGIBLE_AD_NOTIFICATIONS_BASE_H_ -#include "bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h" - #include "bat/ads/ad_info.h" +#include "bat/ads/internal/bundle/creative_ad_notification_info_aliases.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" namespace ads { @@ -32,8 +32,9 @@ class EligibleAdsBase { resource::AntiTargeting* anti_targeting_resource); virtual ~EligibleAdsBase(); - virtual void GetForUserModel(const ad_targeting::UserModelInfo& user_model, - GetEligibleAdsCallback callback) = 0; + virtual void GetForUserModel( + const ad_targeting::UserModelInfo& user_model, + GetEligibleAdsCallback callback) = 0; void set_last_served_ad(const AdInfo& ad) { last_served_ad_ = ad; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_factory.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_factory.h index bc08f0ee8b5f..c3721fb04d62 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_factory.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_factory.h @@ -8,8 +8,6 @@ #include -#include "bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h" - namespace ads { namespace ad_targeting { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1.cc index 3205c8435a6a..c78e3f6c241a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1.cc @@ -13,11 +13,10 @@ #include "bat/ads/internal/ad_targeting/ad_targeting_user_model_info.h" #include "bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.h" #include "bat/ads/internal/ads_client_helper.h" -#include "bat/ads/internal/bundle/creative_ad_info.h" #include "bat/ads/internal/database/tables/ad_events_database_table.h" #include "bat/ads/internal/database/tables/creative_ad_notifications_database_table.h" #include "bat/ads/internal/eligible_ads/eligible_ads_constants.h" -#include "bat/ads/internal/eligible_ads/eligible_ads_util.h" +#include "bat/ads/internal/eligible_ads/frequency_capping.h" #include "bat/ads/internal/eligible_ads/seen_ads.h" #include "bat/ads/internal/eligible_ads/seen_advertisers.h" #include "bat/ads/internal/features/ad_serving/ad_serving_features.h" @@ -36,7 +35,7 @@ EligibleAdsV1::~EligibleAdsV1() = default; void EligibleAdsV1::GetForUserModel( const ad_targeting::UserModelInfo& user_model, - GetEligibleAdsCallback callback) { + GetEligibleAdsCallback callback) { BLOG(1, "Get eligible ad notifications:"); database::table::AdEvents database_table; @@ -62,7 +61,7 @@ void EligibleAdsV1::GetEligibleAds( const ad_targeting::UserModelInfo& user_model, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { GetForParentChildSegments(user_model, ad_events, browsing_history, callback); } @@ -70,7 +69,7 @@ void EligibleAdsV1::GetForParentChildSegments( const ad_targeting::UserModelInfo& user_model, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { const SegmentList segments = ad_targeting::GetTopParentChildSegments(user_model); if (segments.empty()) { @@ -105,7 +104,7 @@ void EligibleAdsV1::GetForParentSegments( const ad_targeting::UserModelInfo& user_model, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { const SegmentList segments = ad_targeting::GetTopParentSegments(user_model); if (segments.empty()) { GetForUntargeted(ad_events, browsing_history, callback); @@ -137,7 +136,7 @@ void EligibleAdsV1::GetForParentSegments( void EligibleAdsV1::GetForUntargeted( const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { BLOG(1, "Get eligible ads for untargeted segment"); database::table::CreativeAdNotifications database_table; @@ -158,17 +157,18 @@ void EligibleAdsV1::GetForUntargeted( CreativeAdNotificationList EligibleAdsV1::FilterCreativeAds( const CreativeAdNotificationList& creative_ads, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const { + const BrowsingHistoryList& browsing_history) { if (creative_ads.empty()) { return {}; } CreativeAdNotificationList eligible_creative_ads = creative_ads; + frequency_capping::ExclusionRules exclusion_rules( + subdivision_targeting_, anti_targeting_resource_, ad_events, + browsing_history); eligible_creative_ads = ApplyFrequencyCapping( - eligible_creative_ads, - ShouldCapLastServedAd(creative_ads) ? last_served_ad_ : AdInfo(), - ad_events, browsing_history); + eligible_creative_ads, last_served_ad_, &exclusion_rules); eligible_creative_ads = FilterSeenAdvertisersAndRoundRobinIfNeeded( eligible_creative_ads, AdType::kAdNotification); @@ -183,29 +183,5 @@ CreativeAdNotificationList EligibleAdsV1::FilterCreativeAds( return eligible_creative_ads; } -CreativeAdNotificationList EligibleAdsV1::ApplyFrequencyCapping( - const CreativeAdNotificationList& creative_ads, - const AdInfo& last_served_ad, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const { - CreativeAdNotificationList eligible_creative_ads = creative_ads; - - const frequency_capping::ExclusionRules exclusion_rules( - subdivision_targeting_, anti_targeting_resource_, ad_events, - browsing_history); - - const auto iter = std::remove_if( - eligible_creative_ads.begin(), eligible_creative_ads.end(), - [&exclusion_rules, &last_served_ad](const CreativeAdInfo& creative_ad) { - return exclusion_rules.ShouldExcludeCreativeAd(creative_ad) || - creative_ad.creative_instance_id == - last_served_ad.creative_instance_id; - }); - - eligible_creative_ads.erase(iter, eligible_creative_ads.end()); - - return eligible_creative_ads; -} - } // namespace ad_notifications } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1.h index ac4c77a01eae..7a0a3112c906 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1.h @@ -8,8 +8,8 @@ #include "bat/ads/internal/ad_events/ad_event_info_aliases.h" #include "bat/ads/internal/bundle/creative_ad_notification_info_aliases.h" -#include "bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h" #include "bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" #include "bat/ads/internal/frequency_capping/frequency_capping_aliases.h" namespace ads { @@ -25,8 +25,6 @@ namespace resource { class AntiTargeting; } // namespace resource -struct AdInfo; - namespace ad_notifications { class EligibleAdsV1 final : public EligibleAdsBase { @@ -36,39 +34,38 @@ class EligibleAdsV1 final : public EligibleAdsBase { resource::AntiTargeting* anti_targeting); ~EligibleAdsV1() override; - void GetForUserModel(const ad_targeting::UserModelInfo& user_model, - GetEligibleAdsCallback callback) override; + void GetForUserModel( + const ad_targeting::UserModelInfo& user_model, + GetEligibleAdsCallback callback) override; private: - void GetEligibleAds(const ad_targeting::UserModelInfo& user_model, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; - - void GetForParentChildSegments(const ad_targeting::UserModelInfo& user_model, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; + void GetEligibleAds( + const ad_targeting::UserModelInfo& user_model, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); - void GetForParentSegments(const ad_targeting::UserModelInfo& user_model, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; + void GetForParentChildSegments( + const ad_targeting::UserModelInfo& user_model, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); - void GetForUntargeted(const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; + void GetForParentSegments( + const ad_targeting::UserModelInfo& user_model, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); - CreativeAdNotificationList FilterCreativeAds( - const CreativeAdNotificationList& creative_ads, + void GetForUntargeted( const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const; + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); - CreativeAdNotificationList ApplyFrequencyCapping( + CreativeAdNotificationList FilterCreativeAds( const CreativeAdNotificationList& creative_ads, - const AdInfo& last_served_ad, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const; + const BrowsingHistoryList& browsing_history); }; } // namespace ad_notifications diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1_issue_17199_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1_issue_17199_unittest.cc index 93e0c77915ce..4fe3cf1d8de8 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1_issue_17199_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1_issue_17199_unittest.cc @@ -47,10 +47,9 @@ TEST_F(BatAdsEligibleAdNotificationsV1Issue17199Test, GetEligibleAds) { eligible_ads.GetForUserModel( ad_targeting::BuildUserModel({"technology & computing-computing"}, {}, {}), - [](const bool success, - const CreativeAdNotificationList& creative_ad_notifications) { + [](const bool success, const CreativeAdNotificationList& creative_ads) { EXPECT_TRUE(success); - EXPECT_FALSE(creative_ad_notifications.empty()); + EXPECT_FALSE(creative_ads.empty()); }); // Assert diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1_unittest.cc index f053536845e1..becefe165b3b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v1_unittest.cc @@ -45,12 +45,12 @@ TEST_F(BatAdsEligibleAdNotificationsV1Test, GetAdsForParentChildSegment) { // Arrange CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_1 = - GetCreativeAdNotificationForSegment("technology & computing"); + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.segment = "technology & computing"; creative_ads.push_back(creative_ad_1); - CreativeAdNotificationInfo creative_ad_2 = - GetCreativeAdNotificationForSegment("technology & computing-software"); + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.segment = "technology & computing-software"; creative_ads.push_back(creative_ad_2); Save(creative_ads); @@ -77,8 +77,8 @@ TEST_F(BatAdsEligibleAdNotificationsV1Test, GetAdsForParentSegment) { // Arrange CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad = - GetCreativeAdNotificationForSegment("technology & computing"); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); + creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); Save(creative_ads); @@ -105,8 +105,8 @@ TEST_F(BatAdsEligibleAdNotificationsV1Test, GetAdsForUntargetedSegment) { // Arrange CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad = - GetCreativeAdNotificationForSegment("untargeted"); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); + creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); Save(creative_ads); @@ -133,16 +133,16 @@ TEST_F(BatAdsEligibleAdNotificationsV1Test, GetAdsForMultipleSegments) { // Arrange CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad_1 = - GetCreativeAdNotificationForSegment("technology & computing"); + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.segment = "technology & computing"; creative_ads.push_back(creative_ad_1); - CreativeAdNotificationInfo creative_ad_2 = - GetCreativeAdNotificationForSegment("finance-banking"); + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.segment = "finance-banking"; creative_ads.push_back(creative_ad_2); - CreativeAdNotificationInfo creative_ad_3 = - GetCreativeAdNotificationForSegment("food & drink"); + CreativeAdNotificationInfo creative_ad_3 = BuildCreativeAdNotification(); + creative_ad_3.segment = "food & drink"; creative_ads.push_back(creative_ad_3); Save(creative_ads); @@ -171,8 +171,8 @@ TEST_F(BatAdsEligibleAdNotificationsV1Test, GetAdsForNoSegments) { // Arrange CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad = - GetCreativeAdNotificationForSegment("untargeted"); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); + creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); Save(creative_ads); @@ -199,8 +199,8 @@ TEST_F(BatAdsEligibleAdNotificationsV1Test, GetAdsForUnmatchedSegments) { // Arrange CreativeAdNotificationList creative_ads; - CreativeAdNotificationInfo creative_ad = - GetCreativeAdNotificationForSegment("technology & computing"); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); + creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); Save(creative_ads); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.cc index c6c6abc4ff88..9fa1dfe1b207 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.cc @@ -12,45 +12,19 @@ #include "bat/ads/internal/ad_targeting/ad_targeting_user_model_info.h" #include "bat/ads/internal/ads/ad_notifications/ad_notification_exclusion_rules.h" #include "bat/ads/internal/ads_client_helper.h" -#include "bat/ads/internal/bundle/creative_ad_info.h" +#include "bat/ads/internal/bundle/creative_ad_notification_info.h" #include "bat/ads/internal/database/tables/ad_events_database_table.h" #include "bat/ads/internal/database/tables/creative_ad_notifications_database_table.h" -#include "bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h" -#include "bat/ads/internal/eligible_ads/eligible_ads_util.h" -#include "bat/ads/internal/eligible_ads/sample_ads.h" +#include "bat/ads/internal/eligible_ads/choose_ad.h" +#include "bat/ads/internal/eligible_ads/frequency_capping.h" #include "bat/ads/internal/features/ad_serving/ad_serving_features.h" #include "bat/ads/internal/logging.h" #include "bat/ads/internal/resources/frequency_capping/anti_targeting_resource.h" #include "bat/ads/internal/segments/segments_aliases.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace ads { namespace ad_notifications { -namespace { - -CreativeAdNotificationInfo ChooseAd( - const ad_targeting::UserModelInfo& user_model, - const AdEventList& ad_events, - const CreativeAdNotificationList& creative_ads) { - DCHECK(!creative_ads.empty()); - - CreativeAdNotificationPredictorMap predictors; - predictors = GroupCreativeAdsByCreativeInstanceId(creative_ads); - predictors = - ComputePredictorFeaturesAndScores(predictors, user_model, ad_events); - - const absl::optional ad_optional = - SampleAdFromPredictors(predictors); - if (!ad_optional) { - return {}; - } - - return ad_optional.value(); -} - -} // namespace - EligibleAdsV2::EligibleAdsV2( ad_targeting::geographic::SubdivisionTargeting* subdivision_targeting, resource::AntiTargeting* anti_targeting_resource) @@ -60,7 +34,7 @@ EligibleAdsV2::~EligibleAdsV2() = default; void EligibleAdsV2::GetForUserModel( const ad_targeting::UserModelInfo& user_model, - GetEligibleAdsCallback callback) { + GetEligibleAdsCallback callback) { BLOG(1, "Get eligible ad notifications:"); database::table::AdEvents database_table; @@ -86,7 +60,7 @@ void EligibleAdsV2::GetEligibleAds( const ad_targeting::UserModelInfo& user_model, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { database::table::CreativeAdNotifications database_table; database_table.GetAll([=](const bool success, const SegmentList& segments, const CreativeAdNotificationList& creative_ads) { @@ -97,10 +71,7 @@ void EligibleAdsV2::GetEligibleAds( } const CreativeAdNotificationList eligible_creative_ads = - ApplyFrequencyCapping( - creative_ads, - ShouldCapLastServedAd(creative_ads) ? last_served_ad_ : AdInfo(), - ad_events, browsing_history); + FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads"); @@ -115,26 +86,19 @@ void EligibleAdsV2::GetEligibleAds( }); } -CreativeAdNotificationList EligibleAdsV2::ApplyFrequencyCapping( +CreativeAdNotificationList EligibleAdsV2::FilterCreativeAds( const CreativeAdNotificationList& creative_ads, - const AdInfo& last_served_ad, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const { - CreativeAdNotificationList eligible_creative_ads = creative_ads; + const BrowsingHistoryList& browsing_history) { + if (creative_ads.empty()) { + return {}; + } - const frequency_capping::ExclusionRules exclusion_rules( + frequency_capping::ExclusionRules exclusion_rules( subdivision_targeting_, anti_targeting_resource_, ad_events, browsing_history); - - const auto iter = std::remove_if( - eligible_creative_ads.begin(), eligible_creative_ads.end(), - [&exclusion_rules, &last_served_ad](const CreativeAdInfo& creative_ad) { - return exclusion_rules.ShouldExcludeCreativeAd(creative_ad) || - creative_ad.creative_instance_id == - last_served_ad.creative_instance_id; - }); - - eligible_creative_ads.erase(iter, eligible_creative_ads.end()); + const CreativeAdNotificationList& eligible_creative_ads = + ApplyFrequencyCapping(creative_ads, last_served_ad_, &exclusion_rules); return eligible_creative_ads; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.h index 30129f9e56f2..84df6c82e17b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2.h @@ -8,7 +8,6 @@ #include "bat/ads/internal/ad_events/ad_event_info_aliases.h" #include "bat/ads/internal/bundle/creative_ad_notification_info_aliases.h" -#include "bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_aliases.h" #include "bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_base.h" #include "bat/ads/internal/frequency_capping/frequency_capping_aliases.h" @@ -25,8 +24,6 @@ namespace resource { class AntiTargeting; } // namespace resource -struct AdInfo; - namespace ad_notifications { class EligibleAdsV2 final : public EligibleAdsBase { @@ -36,20 +33,21 @@ class EligibleAdsV2 final : public EligibleAdsBase { resource::AntiTargeting* anti_targeting); ~EligibleAdsV2() override; - void GetForUserModel(const ad_targeting::UserModelInfo& user_model, - GetEligibleAdsCallback callback) override; + void GetForUserModel( + const ad_targeting::UserModelInfo& user_model, + GetEligibleAdsCallback callback) override; private: - void GetEligibleAds(const ad_targeting::UserModelInfo& user_model, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; + void GetEligibleAds( + const ad_targeting::UserModelInfo& user_model, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); - CreativeAdNotificationList ApplyFrequencyCapping( + CreativeAdNotificationList FilterCreativeAds( const CreativeAdNotificationList& creative_ads, - const AdInfo& last_served_ad, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const; + const BrowsingHistoryList& browsing_history); }; } // namespace ad_notifications diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2_unittest.cc index 60bf113e47d6..e4f96ba2d429 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/ad_notifications/eligible_ad_notifications_v2_unittest.cc @@ -45,12 +45,12 @@ TEST_F(BatAdsEligibleAdNotificationsV2Test, GetAds) { // Arrange CreativeAdNotificationList creative_ads; - const CreativeAdNotificationInfo creative_ad_1 = - GetCreativeAdNotificationForSegment("foo-bar1"); + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.segment = "foo-bar1"; creative_ads.push_back(creative_ad_1); - const CreativeAdNotificationInfo creative_ad_2 = - GetCreativeAdNotificationForSegment("foo-bar3"); + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.segment = "foo-bar3"; creative_ads.push_back(creative_ad_2); Save(creative_ads); @@ -82,12 +82,12 @@ TEST_F(BatAdsEligibleAdNotificationsV2Test, GetAdsForNoSegments) { // Arrange CreativeAdNotificationList creative_ads; - const CreativeAdNotificationInfo creative_ad_1 = - GetCreativeAdNotificationForSegment("foo"); + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.segment = "foo"; creative_ads.push_back(creative_ad_1); - const CreativeAdNotificationInfo creative_ad_2 = - GetCreativeAdNotificationForSegment("foo-bar"); + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.segment = "foo-bar"; creative_ads.push_back(creative_ad_2); Save(creative_ads); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/choose_ad.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/choose_ad.h new file mode 100644 index 000000000000..97b8f7655b5c --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/choose_ad.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_CHOOSE_AD_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_CHOOSE_AD_H_ + +#include + +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h" +#include "bat/ads/internal/eligible_ads/sample_ads.h" + +namespace absl { +template +class optional; +} // namespace absl + +namespace ads { + +template +T ChooseAd(const ad_targeting::UserModelInfo& user_model, + const AdEventList& ad_events, + const std::vector& creative_ads) { + DCHECK(!creative_ads.empty()); + + CreativeAdPredictorMap creative_ad_predictors; + creative_ad_predictors = GroupCreativeAdsByCreativeInstanceId(creative_ads); + creative_ad_predictors = ComputePredictorFeaturesAndScores( + creative_ad_predictors, user_model, ad_events); + + const absl::optional creative_ad_optional = + SampleAdFromPredictors(creative_ad_predictors); + if (!creative_ad_optional) { + return {}; + } + + return creative_ad_optional.value(); +} + +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_CHOOSE_AD_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_aliases.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_aliases.h index a9fbc032c77c..75ce1942c450 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_aliases.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_aliases.h @@ -6,10 +6,21 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_ELIGIBLE_ADS_ALIASES_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_ELIGIBLE_ADS_ALIASES_H_ +#include +#include +#include #include +#include "bat/ads/internal/eligible_ads/ad_predictor_info.h" + namespace ads { +template +using GetEligibleAdsCallback = std::function; + +template +using CreativeAdPredictorMap = std::map>; + using AdPredictorWeights = std::vector; } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h index a04ee682f2c9..2a6354c7d95d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h @@ -8,12 +8,14 @@ #include #include +#include #include "bat/ads/internal/ad_events/ad_event_util.h" #include "bat/ads/internal/ad_targeting/ad_targeting.h" #include "bat/ads/internal/ad_targeting/ad_targeting_user_model_info.h" #include "bat/ads/internal/container_util.h" #include "bat/ads/internal/eligible_ads/ad_predictor_info.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" #include "bat/ads/internal/eligible_ads/eligible_ads_features.h" #include "bat/ads/internal/segments/segments_aliases.h" @@ -27,6 +29,30 @@ constexpr size_t AdLastSeenHoursAgoIndex = 4; constexpr size_t kAdvertiserLastSeenHoursAgoIndex = 5; constexpr size_t kPriorityIndex = 6; +template +CreativeAdPredictorMap GroupCreativeAdsByCreativeInstanceId( + const std::vector& creative_ads) { + CreativeAdPredictorMap creative_ad_predictors; + + for (const auto& creative_ad : creative_ads) { + const auto iter = + creative_ad_predictors.find(creative_ad.creative_instance_id); + if (iter != creative_ad_predictors.end()) { + iter->second.segments.push_back(creative_ad.segment); + continue; + } + + AdPredictorInfo ad_predictor; + ad_predictor.segments = {creative_ad.segment}; + ad_predictor.creative_ad = creative_ad; + + creative_ad_predictors.insert( + {creative_ad.creative_instance_id, ad_predictor}); + } + + return creative_ad_predictors; +} + template AdPredictorInfo ComputePredictorFeatures( const AdPredictorInfo& ad_predictor, @@ -60,15 +86,22 @@ AdPredictorInfo ComputePredictorFeatures( const base::Time now = base::Time::Now(); - const absl::optional last_seen_ad = + const absl::optional last_seen_ad_at_optional = GetLastSeenAdTime(ad_events, ad_predictor.creative_ad); - mutable_ad_predictor.ad_last_seen_hours_ago = - last_seen_ad ? (now - last_seen_ad.value()).InHours() : 0; + if (last_seen_ad_at_optional) { + const base::Time last_seen_ad_at = last_seen_ad_at_optional.value(); + const base::TimeDelta time_delta = now - last_seen_ad_at; + mutable_ad_predictor.ad_last_seen_hours_ago = time_delta.InHours(); + } - const absl::optional last_seen_advertiser = + const absl::optional last_seen_advertiser_at_optional = GetLastSeenAdvertiserTime(ad_events, ad_predictor.creative_ad); - mutable_ad_predictor.advertiser_last_seen_hours_ago = - last_seen_advertiser ? (now - last_seen_advertiser.value()).InHours() : 0; + if (last_seen_advertiser_at_optional) { + const base::Time last_seen_advertiser_at = + last_seen_advertiser_at_optional.value(); + const base::TimeDelta time_delta = now - last_seen_advertiser_at; + mutable_ad_predictor.advertiser_last_seen_hours_ago = time_delta.InHours(); + } return mutable_ad_predictor; } @@ -112,23 +145,24 @@ double ComputePredictorScore(const AdPredictorInfo& ad_predictor) { } template -std::map> ComputePredictorFeaturesAndScores( - const std::map>& ads, +CreativeAdPredictorMap ComputePredictorFeaturesAndScores( + const CreativeAdPredictorMap& creative_ad_predictors, const ad_targeting::UserModelInfo& user_model, const AdEventList& ad_events) { - std::map> ads_with_features; + CreativeAdPredictorMap creative_ad_predictors_with_features; - for (auto& ad : ads) { - const AdPredictorInfo ad_predictor = ad.second; - AdPredictorInfo mutable_ad_predictor = + for (const auto& creative_ad_predictor : creative_ad_predictors) { + AdPredictorInfo ad_predictor = creative_ad_predictor.second; + + ad_predictor = ComputePredictorFeatures(ad_predictor, user_model, ad_events); - mutable_ad_predictor.score = ComputePredictorScore(mutable_ad_predictor); - ads_with_features.insert( - {mutable_ad_predictor.creative_ad.creative_instance_id, - mutable_ad_predictor}); + ad_predictor.score = ComputePredictorScore(ad_predictor); + + creative_ad_predictors_with_features.insert( + {ad_predictor.creative_ad.creative_instance_id, ad_predictor}); } - return ads_with_features; + return creative_ad_predictors_with_features; } } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util_unittest.cc index 3c3ff7565c12..99b4a155fa65 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_predictor_util_unittest.cc @@ -8,6 +8,7 @@ #include "base/guid.h" #include "base/test/scoped_feature_list.h" #include "bat/ads/internal/bundle/creative_ad_notification_info.h" +#include "bat/ads/internal/bundle/creative_ad_notification_info_aliases.h" #include "bat/ads/internal/bundle/creative_ad_notification_unittest_util.h" #include "bat/ads/internal/eligible_ads/eligible_ads_features.h" #include "bat/ads/internal/unittest_util.h" @@ -16,7 +17,56 @@ namespace ads { -TEST(BatAdsEligibleAdsUtilTest, +TEST(BatAdsEligibleAdsPredictorUtilTest, GroupCreativeAdsByCreativeInstanceId) { + // Arrange + CreativeAdNotificationList creative_ads; + + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.segment = "foo-bar1"; + creative_ads.push_back(creative_ad_1); + + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.segment = "foo-bar2"; + creative_ads.push_back(creative_ad_2); + + CreativeAdNotificationInfo creative_ad_3 = BuildCreativeAdNotification(); + creative_ad_3.segment = "foo-bar3"; + creative_ads.push_back(creative_ad_3); + + CreativeAdNotificationInfo creative_ad_4 = BuildCreativeAdNotification(); + creative_ad_4.creative_instance_id = creative_ad_2.creative_instance_id; + creative_ad_4.segment = "foo-bar4"; + creative_ads.push_back(creative_ad_4); + + // Act + const CreativeAdPredictorMap + creative_ad_predictors = + GroupCreativeAdsByCreativeInstanceId(creative_ads); + + // Assert + ASSERT_EQ(3U, creative_ad_predictors.size()); + + const AdPredictorInfo ad_predictor = + creative_ad_predictors.at(creative_ad_2.creative_instance_id); + const SegmentList& expected_segments = {"foo-bar2", "foo-bar4"}; + EXPECT_EQ(expected_segments, ad_predictor.segments); +} + +TEST(BatAdsEligibleAdsPredictorUtilTest, + GroupCreativeAdsByCreativeInstanceIdForEmptyAds) { + // Arrange + CreativeAdNotificationList creative_ads; + + // Act + const CreativeAdPredictorMap + creative_ad_predictors = + GroupCreativeAdsByCreativeInstanceId(creative_ads); + + // Assert + EXPECT_TRUE(creative_ad_predictors.empty()); +} + +TEST(BatAdsEligibleAdsPredictorUtilTest, ComputePredictorScoreWithZeroWeightsNotAllowedByGriffin) { // Arrange const char kAdFeatureWeights[] = "ad_predictor_weights"; @@ -28,15 +78,12 @@ TEST(BatAdsEligibleAdsUtilTest, scoped_feature_list.InitWithFeaturesAndParameters( {{features::kEligibleAds, kEligibleAdsParameters}}, {}); - const std::string segment = "foo-bar"; - const double ptr = 1.0; - const double priority = 1; - const CreativeAdNotificationInfo creative_ad = - GetCreativeAdNotification(segment, ptr, priority); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); + creative_ad.segment = "foo-bar"; AdPredictorInfo ad_predictor; ad_predictor.creative_ad = creative_ad; - ad_predictor.segments = {segment}; + ad_predictor.segments = {creative_ad.segment}; ad_predictor.does_match_intent_child_segments = 1; ad_predictor.does_match_intent_parent_segments = 0; ad_predictor.does_match_interest_child_segments = 0; @@ -51,17 +98,15 @@ TEST(BatAdsEligibleAdsUtilTest, EXPECT_LT(0, ad_predictor.score); } -TEST(BatAdsEligibleAdsUtilTest, ComputePredictorScoreWithDefaultWeights) { +TEST(BatAdsEligibleAdsPredictorUtilTest, + ComputePredictorScoreWithDefaultWeights) { // Arrange - const std::string segment = "foo-bar"; - const double ptr = 1.0; - const double priority = 1; - const CreativeAdNotificationInfo creative_ad = - GetCreativeAdNotification(segment, ptr, priority); + CreativeAdNotificationInfo creative_ad = BuildCreativeAdNotification(); + creative_ad.segment = "foo-bar"; AdPredictorInfo ad_predictor; ad_predictor.creative_ad = creative_ad; - ad_predictor.segments = {segment}; + ad_predictor.segments = {creative_ad.segment}; ad_predictor.does_match_intent_child_segments = 1; ad_predictor.does_match_intent_parent_segments = 0; ad_predictor.does_match_interest_child_segments = 0; @@ -77,7 +122,8 @@ TEST(BatAdsEligibleAdsUtilTest, ComputePredictorScoreWithDefaultWeights) { EXPECT_EQ(expected_score, ad_predictor.score); } -TEST(BatAdsEligibleAdsUtilTest, ComputePredictorScoreWithEmptyAdFeatures) { +TEST(BatAdsEligibleAdsPredictorUtilTest, + ComputePredictorScoreWithEmptyAdFeatures) { // Arrange AdPredictorInfo ad_predictor; @@ -85,7 +131,7 @@ TEST(BatAdsEligibleAdsUtilTest, ComputePredictorScoreWithEmptyAdFeatures) { ad_predictor.score = ComputePredictorScore(ad_predictor); // Assert - const double expected_score = 0; + const double expected_score = 0.0; EXPECT_EQ(expected_score, ad_predictor.score); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util.h deleted file mode 100644 index 1ad0766a3e81..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_ELIGIBLE_ADS_UTIL_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_ELIGIBLE_ADS_UTIL_H_ - -#include -#include -#include -#include - -#include "bat/ads/internal/bundle/creative_ad_info_aliases.h" -#include "bat/ads/internal/eligible_ads/ad_predictor_info.h" -#include "bat/ads/internal/eligible_ads/eligible_ads_util_aliases.h" - -namespace ads { - -template -bool ShouldCapLastServedAd(const T& ads) { - return ads.size() != 1; -} - -template -std::map> GroupCreativeAdsByCreativeInstanceId( - const std::vector& creative_ads) { - std::map> grouped_creative_ads; - - for (const auto& creative_ad : creative_ads) { - const auto iter = - grouped_creative_ads.find(creative_ad.creative_instance_id); - if (iter != grouped_creative_ads.end()) { - iter->second.segments.push_back(creative_ad.segment); - continue; - } - - AdPredictorInfo ad_predictor; - ad_predictor.segments = {creative_ad.segment}; - ad_predictor.creative_ad = creative_ad; - - grouped_creative_ads.insert( - {creative_ad.creative_instance_id, ad_predictor}); - } - - return grouped_creative_ads; -} - -} // namespace ads - -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_ELIGIBLE_ADS_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util_aliases.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util_aliases.h deleted file mode 100644 index 93a4ef8cdfe2..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util_aliases.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_ELIGIBLE_ADS_UTIL_ALIASES_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_ELIGIBLE_ADS_UTIL_ALIASES_H_ - -#include -#include - -#include "bat/ads/internal/bundle/creative_ad_notification_info.h" -#include "bat/ads/internal/bundle/creative_inline_content_ad_info.h" -#include "bat/ads/internal/eligible_ads/ad_predictor_info.h" - -namespace ads { - -using CreativeAdNotificationPredictorMap = - std::map>; - -using CreativeInlineContentAdPredictorMap = - std::map>; - -} // namespace ads - -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_ELIGIBLE_ADS_UTIL_ALIASES_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util_unittest.cc deleted file mode 100644 index cf6f4e304ed9..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/eligible_ads_util_unittest.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "bat/ads/internal/eligible_ads/eligible_ads_util.h" - -#include - -#include "base/guid.h" -#include "bat/ads/internal/bundle/creative_ad_notification_info.h" -#include "bat/ads/internal/bundle/creative_ad_notification_unittest_util.h" -#include "bat/ads/internal/unittest_util.h" - -// npm run test -- brave_unit_tests --filter=BatAds* - -namespace ads { - -TEST(BatAdsEligibleAdsUtilTest, - GroupCreativeAdsByCreativeInstanceIdForEmptyAds) { - // Arrange - std::vector eligible_ads; - - // Act - const CreativeAdNotificationPredictorMap ads = - GroupCreativeAdsByCreativeInstanceId(eligible_ads); - - // Assert - EXPECT_TRUE(ads.empty()); -} - -TEST(BatAdsEligibleAdsUtilTest, GroupCreativeAdsByCreativeInstanceId) { - // Arrange - std::vector eligible_ads; - - const CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification(base::GenerateGUID(), "foo-bar1"); - eligible_ads.push_back(creative_ad_notification_1); - - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification(base::GenerateGUID(), "foo-bar2"); - eligible_ads.push_back(creative_ad_notification_2); - - const CreativeAdNotificationInfo creative_ad_notification_3 = - GetCreativeAdNotification(base::GenerateGUID(), "foo-bar3"); - eligible_ads.push_back(creative_ad_notification_3); - - const CreativeAdNotificationInfo creative_ad_notification_4 = - GetCreativeAdNotification(creative_ad_notification_2.creative_instance_id, - "foo-bar4"); - eligible_ads.push_back(creative_ad_notification_4); - - // Act - const CreativeAdNotificationPredictorMap ads = - GroupCreativeAdsByCreativeInstanceId(eligible_ads); - - // Assert - ASSERT_EQ(3u, ads.size()); - - AdPredictorInfo ad = - ads.at(creative_ad_notification_2.creative_instance_id); - const SegmentList& expected_segments = {"foo-bar2", "foo-bar4"}; - EXPECT_EQ(expected_segments, ad.segments); -} - -} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/frequency_capping.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/frequency_capping.h new file mode 100644 index 000000000000..3420a11f1635 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/frequency_capping.h @@ -0,0 +1,49 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_FREQUENCY_CAPPING_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_FREQUENCY_CAPPING_H_ + +#include "base/check.h" +#include "bat/ads/ad_info.h" +#include "bat/ads/internal/ads/exclusion_rules_base.h" +#include "bat/ads/internal/bundle/creative_ad_info.h" + +namespace ads { + +template +bool ShouldCapLastServedCreativeAd(const T& creative_ads) { + return creative_ads.size() != 1; +} + +template +T ApplyFrequencyCapping(const T& creative_ads, + const AdInfo& last_served_ad, + ExclusionRulesBase* exclusion_rules) { + DCHECK(exclusion_rules); + + const bool should_cap_last_served_ad = + ShouldCapLastServedCreativeAd(creative_ads); + + T filtered_creative_ads = creative_ads; + + const auto iter = std::remove_if( + filtered_creative_ads.begin(), filtered_creative_ads.end(), + [exclusion_rules, &last_served_ad, + &should_cap_last_served_ad](const CreativeAdInfo& creative_ad) { + return exclusion_rules->ShouldExcludeCreativeAd(creative_ad) || + (should_cap_last_served_ad && + creative_ad.creative_instance_id == + last_served_ad.creative_instance_id); + }); + + filtered_creative_ads.erase(iter, filtered_creative_ads.end()); + + return filtered_creative_ads; +} + +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_FREQUENCY_CAPPING_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h deleted file mode 100644 index f99213859658..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_INLINE_CONTENT_ADS_ELIGIBLE_INLINE_CONTENT_ADS_ALIASES_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_INLINE_CONTENT_ADS_ELIGIBLE_INLINE_CONTENT_ADS_ALIASES_H_ - -#include - -#include "bat/ads/internal/bundle/creative_inline_content_ad_info_aliases.h" - -namespace ads { -namespace inline_content_ads { - -using GetEligibleAdsCallback = - std::function; - -} // namespace inline_content_ads -} // namespace ads - -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_INLINE_CONTENT_ADS_ELIGIBLE_INLINE_CONTENT_ADS_ALIASES_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.h index 50cf85d5ce33..4a4aa7c414fc 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.h @@ -6,11 +6,11 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_INLINE_CONTENT_ADS_ELIGIBLE_INLINE_CONTENT_ADS_BASE_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ELIGIBLE_ADS_INLINE_CONTENT_ADS_ELIGIBLE_INLINE_CONTENT_ADS_BASE_H_ -#include "bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h" - #include #include "bat/ads/ad_info.h" +#include "bat/ads/internal/bundle/creative_inline_content_ad_info_aliases.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" namespace ads { @@ -34,9 +34,10 @@ class EligibleAdsBase { resource::AntiTargeting* anti_targeting_resource); virtual ~EligibleAdsBase(); - virtual void GetForUserModel(const ad_targeting::UserModelInfo& user_model, - const std::string& dimensions, - GetEligibleAdsCallback callback) = 0; + virtual void GetForUserModel( + const ad_targeting::UserModelInfo& user_model, + const std::string& dimensions, + GetEligibleAdsCallback callback) = 0; void set_last_served_ad(const AdInfo& ad) { last_served_ad_ = ad; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_factory.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_factory.h index bd916b25af37..d8ec62227ebe 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_factory.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_factory.h @@ -8,8 +8,6 @@ #include -#include "bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h" - namespace ads { namespace ad_targeting { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1.cc index 812760fa736c..25588efa57b7 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1.cc @@ -13,11 +13,10 @@ #include "bat/ads/internal/ad_targeting/ad_targeting_user_model_info.h" #include "bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.h" #include "bat/ads/internal/ads_client_helper.h" -#include "bat/ads/internal/bundle/creative_ad_info.h" #include "bat/ads/internal/database/tables/ad_events_database_table.h" #include "bat/ads/internal/database/tables/creative_inline_content_ads_database_table.h" #include "bat/ads/internal/eligible_ads/eligible_ads_constants.h" -#include "bat/ads/internal/eligible_ads/eligible_ads_util.h" +#include "bat/ads/internal/eligible_ads/frequency_capping.h" #include "bat/ads/internal/eligible_ads/seen_ads.h" #include "bat/ads/internal/eligible_ads/seen_advertisers.h" #include "bat/ads/internal/features/ad_serving/ad_serving_features.h" @@ -37,7 +36,7 @@ EligibleAdsV1::~EligibleAdsV1() = default; void EligibleAdsV1::GetForUserModel( const ad_targeting::UserModelInfo& user_model, const std::string& dimensions, - GetEligibleAdsCallback callback) { + GetEligibleAdsCallback callback) { BLOG(1, "Get eligible inline content ads:"); database::table::AdEvents database_table; @@ -65,7 +64,7 @@ void EligibleAdsV1::GetEligibleAds( const std::string& dimensions, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { GetForParentChildSegments(user_model, dimensions, ad_events, browsing_history, callback); } @@ -75,7 +74,7 @@ void EligibleAdsV1::GetForParentChildSegments( const std::string& dimensions, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { const SegmentList segments = ad_targeting::GetTopParentChildSegments(user_model); if (segments.empty()) { @@ -113,7 +112,7 @@ void EligibleAdsV1::GetForParentSegments( const std::string& dimensions, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { const SegmentList segments = ad_targeting::GetTopParentSegments(user_model); if (segments.empty()) { GetForUntargeted(dimensions, ad_events, browsing_history, callback); @@ -130,7 +129,7 @@ void EligibleAdsV1::GetForParentSegments( segments, dimensions, [=](const bool success, const SegmentList& segments, const CreativeInlineContentAdList& creative_ads) { - CreativeInlineContentAdList eligible_creative_ads = + const CreativeInlineContentAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { @@ -147,7 +146,7 @@ void EligibleAdsV1::GetForUntargeted( const std::string& dimensions, const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { BLOG(1, "Get eligible ads for untargeted segment"); database::table::CreativeInlineContentAds database_table; @@ -155,7 +154,7 @@ void EligibleAdsV1::GetForUntargeted( {kUntargeted}, dimensions, [=](const bool success, const SegmentList& segments, const CreativeInlineContentAdList& creative_ads) { - CreativeInlineContentAdList eligible_creative_ads = + const CreativeInlineContentAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { @@ -169,17 +168,18 @@ void EligibleAdsV1::GetForUntargeted( CreativeInlineContentAdList EligibleAdsV1::FilterCreativeAds( const CreativeInlineContentAdList& creative_ads, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const { + const BrowsingHistoryList& browsing_history) { if (creative_ads.empty()) { return {}; } CreativeInlineContentAdList eligible_creative_ads = creative_ads; + frequency_capping::ExclusionRules exclusion_rules( + subdivision_targeting_, anti_targeting_resource_, ad_events, + browsing_history); eligible_creative_ads = ApplyFrequencyCapping( - eligible_creative_ads, - ShouldCapLastServedAd(creative_ads) ? last_served_ad_ : AdInfo(), - ad_events, browsing_history); + eligible_creative_ads, last_served_ad_, &exclusion_rules); eligible_creative_ads = FilterSeenAdvertisersAndRoundRobinIfNeeded( eligible_creative_ads, AdType::kInlineContentAd); @@ -194,29 +194,5 @@ CreativeInlineContentAdList EligibleAdsV1::FilterCreativeAds( return eligible_creative_ads; } -CreativeInlineContentAdList EligibleAdsV1::ApplyFrequencyCapping( - const CreativeInlineContentAdList& creative_ads, - const AdInfo& last_served_ad, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const { - CreativeInlineContentAdList eligible_creative_ads = creative_ads; - - const frequency_capping::ExclusionRules exclusion_rules( - subdivision_targeting_, anti_targeting_resource_, ad_events, - browsing_history); - - const auto iter = std::remove_if( - eligible_creative_ads.begin(), eligible_creative_ads.end(), - [&exclusion_rules, &last_served_ad](const CreativeAdInfo& creative_ad) { - return exclusion_rules.ShouldExcludeCreativeAd(creative_ad) || - creative_ad.creative_instance_id == - last_served_ad.creative_instance_id; - }); - - eligible_creative_ads.erase(iter, eligible_creative_ads.end()); - - return eligible_creative_ads; -} - } // namespace inline_content_ads } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1.h index 4abcdcc46d51..bf6c2839d3f5 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1.h @@ -10,7 +10,7 @@ #include "bat/ads/internal/ad_events/ad_event_info_aliases.h" #include "bat/ads/internal/bundle/creative_inline_content_ad_info_aliases.h" -#include "bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" #include "bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.h" #include "bat/ads/internal/frequency_capping/frequency_capping_aliases.h" @@ -27,8 +27,6 @@ namespace resource { class AntiTargeting; } // namespace resource -struct AdInfo; - namespace inline_content_ads { class EligibleAdsV1 final : public EligibleAdsBase { @@ -38,44 +36,43 @@ class EligibleAdsV1 final : public EligibleAdsBase { resource::AntiTargeting* anti_targeting); ~EligibleAdsV1() override; - void GetForUserModel(const ad_targeting::UserModelInfo& user_model, - const std::string& dimensions, - GetEligibleAdsCallback callback) override; + void GetForUserModel( + const ad_targeting::UserModelInfo& user_model, + const std::string& dimensions, + GetEligibleAdsCallback callback) override; private: - void GetEligibleAds(const ad_targeting::UserModelInfo& user_model, - const std::string& dimensions, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; - - void GetForParentChildSegments(const ad_targeting::UserModelInfo& user_model, - const std::string& dimensions, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; - - void GetForParentSegments(const ad_targeting::UserModelInfo& user_model, - const std::string& dimensions, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; - - void GetForUntargeted(const std::string& dimensions, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - GetEligibleAdsCallback callback) const; + void GetEligibleAds( + const ad_targeting::UserModelInfo& user_model, + const std::string& dimensions, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); - CreativeInlineContentAdList FilterCreativeAds( - const CreativeInlineContentAdList& creative_ads, + void GetForParentChildSegments( + const ad_targeting::UserModelInfo& user_model, + const std::string& dimensions, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const; + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); - CreativeInlineContentAdList ApplyFrequencyCapping( + void GetForParentSegments( + const ad_targeting::UserModelInfo& user_model, + const std::string& dimensions, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); + + void GetForUntargeted( + const std::string& dimensions, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history, + GetEligibleAdsCallback callback); + + CreativeInlineContentAdList FilterCreativeAds( const CreativeInlineContentAdList& creative_ads, - const AdInfo& last_served_ad, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const; + const BrowsingHistoryList& browsing_history); }; } // namespace inline_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc index a53f70af2085..33cc9d95484f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc @@ -45,12 +45,12 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForParentChildSegment) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad_1 = - GetCreativeInlineContentAdForSegment("technology & computing"); + CreativeInlineContentAdInfo creative_ad_1 = BuildCreativeInlineContentAd(); + creative_ad_1.segment = "technology & computing"; creative_ads.push_back(creative_ad_1); - CreativeInlineContentAdInfo creative_ad_2 = - GetCreativeInlineContentAdForSegment("technology & computing-software"); + CreativeInlineContentAdInfo creative_ad_2 = BuildCreativeInlineContentAd(); + creative_ad_2.segment = "technology & computing-software"; creative_ads.push_back(creative_ad_2); Save(creative_ads); @@ -78,8 +78,8 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForParentSegment) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = - GetCreativeInlineContentAdForSegment("technology & computing"); + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); + creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); Save(creative_ads); @@ -107,8 +107,8 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForUntargetedSegment) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = - GetCreativeInlineContentAdForSegment("untargeted"); + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); + creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); Save(creative_ads); @@ -135,16 +135,16 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForMultipleSegments) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad_1 = - GetCreativeInlineContentAdForSegment("technology & computing"); + CreativeInlineContentAdInfo creative_ad_1 = BuildCreativeInlineContentAd(); + creative_ad_1.segment = "technology & computing"; creative_ads.push_back(creative_ad_1); - CreativeInlineContentAdInfo creative_ad_2 = - GetCreativeInlineContentAdForSegment("finance-banking"); + CreativeInlineContentAdInfo creative_ad_2 = BuildCreativeInlineContentAd(); + creative_ad_2.segment = "finance-banking"; creative_ads.push_back(creative_ad_2); - CreativeInlineContentAdInfo creative_ad_3 = - GetCreativeInlineContentAdForSegment("food & drink"); + CreativeInlineContentAdInfo creative_ad_3 = BuildCreativeInlineContentAd(); + creative_ad_3.segment = "food & drink"; creative_ads.push_back(creative_ad_3); Save(creative_ads); @@ -174,8 +174,8 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForNoSegments) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = - GetCreativeInlineContentAdForSegment("untargeted"); + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); + creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); Save(creative_ads); @@ -202,8 +202,8 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForUnmatchedSegments) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = - GetCreativeInlineContentAdForSegment("technology & computing"); + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); + creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); Save(creative_ads); @@ -230,8 +230,8 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForUnmatchedDimensions) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = - GetCreativeInlineContentAdForSegment("technology & computing"); + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); + creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); Save(creative_ads); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2.cc index 2a6afa0217a3..92b2ff8a27a7 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2.cc @@ -12,45 +12,19 @@ #include "bat/ads/internal/ad_targeting/ad_targeting_user_model_info.h" #include "bat/ads/internal/ads/inline_content_ads/inline_content_ad_exclusion_rules.h" #include "bat/ads/internal/ads_client_helper.h" -#include "bat/ads/internal/bundle/creative_ad_info.h" +#include "bat/ads/internal/bundle/creative_ad_notification_info.h" #include "bat/ads/internal/database/tables/ad_events_database_table.h" #include "bat/ads/internal/database/tables/creative_inline_content_ads_database_table.h" -#include "bat/ads/internal/eligible_ads/eligible_ads_predictor_util.h" -#include "bat/ads/internal/eligible_ads/eligible_ads_util.h" -#include "bat/ads/internal/eligible_ads/sample_ads.h" +#include "bat/ads/internal/eligible_ads/choose_ad.h" +#include "bat/ads/internal/eligible_ads/frequency_capping.h" #include "bat/ads/internal/features/ad_serving/ad_serving_features.h" #include "bat/ads/internal/logging.h" #include "bat/ads/internal/resources/frequency_capping/anti_targeting_resource.h" #include "bat/ads/internal/segments/segments_aliases.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace ads { namespace inline_content_ads { -namespace { - -CreativeInlineContentAdInfo ChooseAd( - const ad_targeting::UserModelInfo& user_model, - const AdEventList& ad_events, - const CreativeInlineContentAdList& creative_ads) { - DCHECK(!creative_ads.empty()); - - CreativeInlineContentAdPredictorMap predictors; - predictors = GroupCreativeAdsByCreativeInstanceId(creative_ads); - predictors = - ComputePredictorFeaturesAndScores(predictors, user_model, ad_events); - - const absl::optional ad_optional = - SampleAdFromPredictors(predictors); - if (!ad_optional) { - return {}; - } - - return ad_optional.value(); -} - -} // namespace - EligibleAdsV2::EligibleAdsV2( ad_targeting::geographic::SubdivisionTargeting* subdivision_targeting, resource::AntiTargeting* anti_targeting_resource) @@ -61,7 +35,7 @@ EligibleAdsV2::~EligibleAdsV2() = default; void EligibleAdsV2::GetForUserModel( const ad_targeting::UserModelInfo& user_model, const std::string& dimensions, - GetEligibleAdsCallback callback) { + GetEligibleAdsCallback callback) { BLOG(1, "Get eligible inline content ads:"); database::table::AdEvents database_table; @@ -89,7 +63,7 @@ void EligibleAdsV2::GetEligibleAds( const AdEventList& ad_events, const BrowsingHistoryList& browsing_history, const std::string& dimensions, - GetEligibleAdsCallback callback) const { + GetEligibleAdsCallback callback) { database::table::CreativeInlineContentAds database_table; database_table.GetForDimensions( dimensions, @@ -101,11 +75,7 @@ void EligibleAdsV2::GetEligibleAds( } const CreativeInlineContentAdList eligible_creative_ads = - ApplyFrequencyCapping(creative_ads, - ShouldCapLastServedAd(creative_ads) - ? last_served_ad_ - : AdInfo(), - ad_events, browsing_history); + FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads"); @@ -120,27 +90,19 @@ void EligibleAdsV2::GetEligibleAds( }); } -CreativeInlineContentAdList EligibleAdsV2::ApplyFrequencyCapping( +CreativeInlineContentAdList EligibleAdsV2::FilterCreativeAds( const CreativeInlineContentAdList& creative_ads, - const AdInfo& last_served_ad, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const { - CreativeInlineContentAdList eligible_creative_ads = creative_ads; + const BrowsingHistoryList& browsing_history) { + if (creative_ads.empty()) { + return {}; + } - const frequency_capping::ExclusionRules exclusion_rules( + frequency_capping::ExclusionRules exclusion_rules( subdivision_targeting_, anti_targeting_resource_, ad_events, browsing_history); - - const auto iter = std::remove_if( - eligible_creative_ads.begin(), eligible_creative_ads.end(), - [&exclusion_rules, &last_served_ad](const CreativeAdInfo& creative_ad) { - return exclusion_rules.ShouldExcludeCreativeAd(creative_ad) || - creative_ad.creative_instance_id == - last_served_ad.creative_instance_id; - }); - - eligible_creative_ads.erase(iter, eligible_creative_ads.end()); - + const CreativeInlineContentAdList& eligible_creative_ads = + ApplyFrequencyCapping(creative_ads, last_served_ad_, &exclusion_rules); return eligible_creative_ads; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2.h index c6b2d2140660..67cb0aef151b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2.h @@ -10,7 +10,7 @@ #include "bat/ads/internal/ad_events/ad_event_info_aliases.h" #include "bat/ads/internal/bundle/creative_inline_content_ad_info_aliases.h" -#include "bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_aliases.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" #include "bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_base.h" #include "bat/ads/internal/frequency_capping/frequency_capping_aliases.h" @@ -27,8 +27,6 @@ namespace resource { class AntiTargeting; } // namespace resource -struct AdInfo; - namespace inline_content_ads { class EligibleAdsV2 final : public EligibleAdsBase { @@ -38,22 +36,23 @@ class EligibleAdsV2 final : public EligibleAdsBase { resource::AntiTargeting* anti_targeting); ~EligibleAdsV2() override; - void GetForUserModel(const ad_targeting::UserModelInfo& user_model, - const std::string& dimensions, - GetEligibleAdsCallback callback) override; + void GetForUserModel( + const ad_targeting::UserModelInfo& user_model, + const std::string& dimensions, + GetEligibleAdsCallback callback) override; private: - void GetEligibleAds(const ad_targeting::UserModelInfo& user_model, - const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history, - const std::string& dimensions, - GetEligibleAdsCallback callback) const; + void GetEligibleAds( + const ad_targeting::UserModelInfo& user_model, + const AdEventList& ad_events, + const BrowsingHistoryList& browsing_history, + const std::string& dimensions, + GetEligibleAdsCallback callback); - CreativeInlineContentAdList ApplyFrequencyCapping( + CreativeInlineContentAdList FilterCreativeAds( const CreativeInlineContentAdList& creative_ads, - const AdInfo& last_served_ad, const AdEventList& ad_events, - const BrowsingHistoryList& browsing_history) const; + const BrowsingHistoryList& browsing_history); }; } // namespace inline_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc index 2f6cd9fe1f59..dc8d27524245 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc @@ -45,12 +45,12 @@ TEST_F(BatAdsEligibleInlineContentAdsV2Test, GetAds) { // Arrange CreativeInlineContentAdList creative_ads; - const CreativeInlineContentAdInfo creative_ad_1 = - GetCreativeInlineContentAdForSegment("foo-bar1"); + CreativeInlineContentAdInfo creative_ad_1 = BuildCreativeInlineContentAd(); + creative_ad_1.segment = "foo-bar1"; creative_ads.push_back(creative_ad_1); - const CreativeInlineContentAdInfo creative_ad_2 = - GetCreativeInlineContentAdForSegment("foo-bar3"); + CreativeInlineContentAdInfo creative_ad_2 = BuildCreativeInlineContentAd(); + creative_ad_2.segment = "foo-bar3"; creative_ads.push_back(creative_ad_2); Save(creative_ads); @@ -84,12 +84,12 @@ TEST_F(BatAdsEligibleInlineContentAdsV2Test, GetAdsForNoSegments) { // Arrange CreativeInlineContentAdList creative_ads; - const CreativeInlineContentAdInfo creative_ad_1 = - GetCreativeInlineContentAdForSegment("foo"); + CreativeInlineContentAdInfo creative_ad_1 = BuildCreativeInlineContentAd(); + creative_ad_1.segment = "foo"; creative_ads.push_back(creative_ad_1); - const CreativeInlineContentAdInfo creative_ad_2 = - GetCreativeInlineContentAdForSegment("foo-bar"); + CreativeInlineContentAdInfo creative_ad_2 = BuildCreativeInlineContentAd(); + creative_ad_2.segment = "foo-bar"; creative_ads.push_back(creative_ad_2); Save(creative_ads); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads.h index a611bb004595..bf863e32b52b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads.h @@ -13,6 +13,7 @@ #include "base/notreached.h" #include "base/rand_util.h" #include "bat/ads/internal/eligible_ads/ad_predictor_info.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" #include "bat/ads/internal/number_util.h" #include "third_party/abseil-cpp/absl/types/optional.h" @@ -20,10 +21,12 @@ namespace ads { template double CalculateNormalisingConstant( - const std::map>& predictors) { + const CreativeAdPredictorMap& creative_ad_predictors) { double normalising_constant = 0.0; - for (const auto& ad : predictors) { - normalising_constant += ad.second.score; + + for (const auto& creative_ad_predictor : creative_ad_predictors) { + const AdPredictorInfo ad_predictor = creative_ad_predictor.second; + normalising_constant += ad_predictor.score; } return normalising_constant; @@ -31,8 +34,9 @@ double CalculateNormalisingConstant( template absl::optional SampleAdFromPredictors( - const std::map>& predictors) { - const double normalising_constant = CalculateNormalisingConstant(predictors); + const CreativeAdPredictorMap& creative_ad_predictors) { + const double normalising_constant = + CalculateNormalisingConstant(creative_ad_predictors); if (DoubleIsLessEqual(normalising_constant, 0.0)) { return absl::nullopt; } @@ -40,15 +44,18 @@ absl::optional SampleAdFromPredictors( const double rand = base::RandDouble(); double sum = 0; - for (const auto& ad : predictors) { - const double probability = ad.second.score / normalising_constant; + for (const auto& creative_ad_predictor : creative_ad_predictors) { + const AdPredictorInfo ad_predictor = creative_ad_predictor.second; + + const double probability = ad_predictor.score / normalising_constant; sum += probability; + if (DoubleIsLess(rand, sum)) { - return ad.second.creative_ad; + return ad_predictor.creative_ad; } } - NOTREACHED() << "Sum should always be strictly less than probability"; + NOTREACHED() << "Sum should always be less than probability"; return absl::nullopt; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads_unittest.cc index bd120c8a2c8b..da8e6ebc66f8 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/sample_ads_unittest.cc @@ -8,7 +8,7 @@ #include "base/guid.h" #include "bat/ads/internal/bundle/creative_ad_notification_info.h" #include "bat/ads/internal/bundle/creative_ad_notification_unittest_util.h" -#include "bat/ads/internal/eligible_ads/eligible_ads_util.h" +#include "bat/ads/internal/eligible_ads/eligible_ads_aliases.h" #include "bat/ads/internal/unittest_util.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -17,10 +17,12 @@ namespace ads { TEST(BatAdsSampleAdsTest, CalculateNormalisingConstantWithEmptyAds) { // Arrange - CreativeAdNotificationPredictorMap predictors; + const CreativeAdPredictorMap + creative_ad_predictors; // Act - const double normalising_constant = CalculateNormalisingConstant(predictors); + const double normalising_constant = + CalculateNormalisingConstant(creative_ad_predictors); // Assert const double expected_normalising_constant = 0.0; @@ -30,21 +32,23 @@ TEST(BatAdsSampleAdsTest, CalculateNormalisingConstantWithEmptyAds) { TEST(BatAdsSampleAdsTest, CalculateNormalisingConstant) { // Arrange - CreativeAdNotificationPredictorMap predictors; + CreativeAdPredictorMap creative_ad_predictors; + AdPredictorInfo ad_predictor_1; ad_predictor_1.score = 1.1; - predictors[base::GenerateGUID()] = ad_predictor_1; + creative_ad_predictors[base::GenerateGUID()] = ad_predictor_1; AdPredictorInfo ad_predictor_2; ad_predictor_2.score = 2.2; - predictors[base::GenerateGUID()] = ad_predictor_2; + creative_ad_predictors[base::GenerateGUID()] = ad_predictor_2; AdPredictorInfo ad_predictor_3; ad_predictor_3.score = 3.3; - predictors[base::GenerateGUID()] = ad_predictor_3; + creative_ad_predictors[base::GenerateGUID()] = ad_predictor_3; // Act - const double normalising_constant = CalculateNormalisingConstant(predictors); + const double normalising_constant = + CalculateNormalisingConstant(creative_ad_predictors); // Assert const double expected_normalising_constant = 6.6; @@ -54,60 +58,69 @@ TEST(BatAdsSampleAdsTest, CalculateNormalisingConstant) { TEST(BatAdsSampleAdsTest, SampleAdFromPredictorsWithZeroScores) { // Arrange - CreativeAdNotificationPredictorMap predictors; + CreativeAdPredictorMap creative_ad_predictors; + AdPredictorInfo ad_predictor_1; ad_predictor_1.score = 0; - predictors[base::GenerateGUID()] = ad_predictor_1; + creative_ad_predictors[base::GenerateGUID()] = ad_predictor_1; AdPredictorInfo ad_predictor_2; ad_predictor_2.score = 0; - predictors[base::GenerateGUID()] = ad_predictor_2; + creative_ad_predictors[base::GenerateGUID()] = ad_predictor_2; AdPredictorInfo ad_predictor_3; ad_predictor_3.score = 0; - predictors[base::GenerateGUID()] = ad_predictor_3; + creative_ad_predictors[base::GenerateGUID()] = ad_predictor_3; // Act - const absl::optional ad = - SampleAdFromPredictors(predictors); + const absl::optional creative_ad_optional = + SampleAdFromPredictors(creative_ad_predictors); // Assert - const absl::optional expected_ad = absl::nullopt; - EXPECT_EQ(expected_ad, ad); + const absl::optional + expected_creative_ad_optional = absl::nullopt; + EXPECT_EQ(expected_creative_ad_optional, creative_ad_optional); } TEST(BatAdsSampleAdsTest, DeterministicallySampleAdFromPredictorsWithOneNonZeroScore) { // Arrange - CreativeAdNotificationPredictorMap predictors; + CreativeAdPredictorMap creative_ad_predictors; + + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.segment = "foo-bar"; - const CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification("foo-bar", 1.0, 1); AdPredictorInfo ad_predictor_1; ad_predictor_1.score = 0; - ad_predictor_1.creative_ad = creative_ad_notification_1; - predictors[creative_ad_notification_1.creative_instance_id] = ad_predictor_1; + ad_predictor_1.creative_ad = creative_ad_1; + creative_ad_predictors[creative_ad_1.creative_instance_id] = ad_predictor_1; + + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.segment = "foo-bar"; - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification("foo-bar", 1.0, 1); AdPredictorInfo ad_predictor_2; ad_predictor_2.score = 0.1; - ad_predictor_2.creative_ad = creative_ad_notification_2; - predictors[creative_ad_notification_2.creative_instance_id] = ad_predictor_2; + ad_predictor_2.creative_ad = creative_ad_2; + creative_ad_predictors[creative_ad_2.creative_instance_id] = ad_predictor_2; + + CreativeAdNotificationInfo creative_ad_3 = BuildCreativeAdNotification(); + creative_ad_3.segment = "foo-bar"; - const CreativeAdNotificationInfo creative_ad_notification_3 = - GetCreativeAdNotification("foo-bar", 1.0, 1); AdPredictorInfo ad_predictor_3; ad_predictor_3.score = 0; - ad_predictor_3.creative_ad = creative_ad_notification_3; - predictors[creative_ad_notification_3.creative_instance_id] = ad_predictor_3; + ad_predictor_3.creative_ad = creative_ad_3; + creative_ad_predictors[creative_ad_3.creative_instance_id] = ad_predictor_3; // Act for (int i = 0; i < 10; i++) { - CreativeAdNotificationInfo expected_ad = creative_ad_notification_2; - const absl::optional ad = - SampleAdFromPredictors(predictors); - EXPECT_EQ(expected_ad, ad.value()); + const CreativeAdNotificationInfo expected_creative_ad = creative_ad_2; + const absl::optional creative_ad_optional = + SampleAdFromPredictors(creative_ad_predictors); + ASSERT_NE(absl::nullopt, creative_ad_optional); + + const CreativeAdNotificationInfo creative_ad = creative_ad_optional.value(); + + EXPECT_EQ(expected_creative_ad, creative_ad); } // Assert @@ -115,43 +128,49 @@ TEST(BatAdsSampleAdsTest, TEST(BatAdsSampleAdsTest, ProbabilisticallySampleAdFromPredictors) { // Arrange - CreativeAdNotificationPredictorMap predictors; + CreativeAdPredictorMap creative_ad_predictors; + + CreativeAdNotificationInfo creative_ad_1 = BuildCreativeAdNotification(); + creative_ad_1.segment = "foo-bar"; - const CreativeAdNotificationInfo creative_ad_notification_1 = - GetCreativeAdNotification("foo-bar", 1.0, 1); AdPredictorInfo ad_predictor_1; - ad_predictor_1.creative_ad = creative_ad_notification_1; + ad_predictor_1.creative_ad = creative_ad_1; ad_predictor_1.score = 3; - predictors[creative_ad_notification_1.creative_instance_id] = ad_predictor_1; + creative_ad_predictors[creative_ad_1.creative_instance_id] = ad_predictor_1; + + CreativeAdNotificationInfo creative_ad_2 = BuildCreativeAdNotification(); + creative_ad_2.segment = "foo-bar"; - const CreativeAdNotificationInfo creative_ad_notification_2 = - GetCreativeAdNotification("foo-bar", 1.0, 1); AdPredictorInfo ad_predictor_2; - ad_predictor_2.creative_ad = creative_ad_notification_2; + ad_predictor_2.creative_ad = creative_ad_2; ad_predictor_2.score = 3; - predictors[creative_ad_notification_2.creative_instance_id] = ad_predictor_2; + creative_ad_predictors[creative_ad_2.creative_instance_id] = ad_predictor_2; // Act - int ads_1_count = 0; - int ads_2_count = 0; + int creative_ad_notification_1_count = 0; + int creative_ad_notification_2_count = 0; // P(X>1) > 0.99999999 with X~Bin(n=25, p=0.5), i.e. less than 1 in 100M tests // are expected to fail for (int i = 0; i < 25; i++) { - const absl::optional ad = - SampleAdFromPredictors(predictors); - - if (ad.value().creative_instance_id == - creative_ad_notification_1.creative_instance_id) { - ads_1_count++; - } else if (ad.value().creative_instance_id == - creative_ad_notification_2.creative_instance_id) { - ads_2_count++; + const absl::optional creative_ad_optional = + SampleAdFromPredictors(creative_ad_predictors); + ASSERT_NE(absl::nullopt, creative_ad_optional); + + const CreativeAdNotificationInfo creative_ad = creative_ad_optional.value(); + + if (creative_ad.creative_instance_id == + creative_ad_1.creative_instance_id) { + creative_ad_notification_1_count++; + } else if (creative_ad.creative_instance_id == + creative_ad_2.creative_instance_id) { + creative_ad_notification_2_count++; } } // Assert - EXPECT_FALSE(ads_1_count == 0 || ads_2_count == 0); + EXPECT_FALSE(creative_ad_notification_1_count == 0 || + creative_ad_notification_2_count == 0); } } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/seen_ads.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/seen_ads.h index d3d78e1a7648..6387e4b31e63 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/seen_ads.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/seen_ads.h @@ -26,7 +26,8 @@ T FilterSeenAdsAndRoundRobinIfNeeded(const T& ads, const AdType& type) { return filtered_ads; } - BLOG(1, "All " << std::string(type) << "s have been shown, so round robin"); + BLOG(1, + "All " << std::string(type) << " ads have been shown, so round robin"); CreativeAdList cast_creative_ads; for (const auto& ad : ads) { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/seen_advertisers.h b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/seen_advertisers.h index 19c19f31e476..85b1e28ffd2d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/seen_advertisers.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/eligible_ads/seen_advertisers.h @@ -26,7 +26,8 @@ T FilterSeenAdvertisersAndRoundRobinIfNeeded(const T& ads, const AdType& type) { return filtered_ads; } - BLOG(1, "All " << std::string(type) << "s have been shown, so round robin"); + BLOG(1, "All " << std::string(type) + << " advertisers have been shown, so round robin"); CreativeAdList cast_creative_ads; for (const auto& ad : ads) { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.cc index 5ff205574582..587851748d4d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.cc @@ -40,12 +40,17 @@ AntiTargetingFrequencyCap::AntiTargetingFrequencyCap( AntiTargetingFrequencyCap::~AntiTargetingFrequencyCap() = default; +std::string AntiTargetingFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool AntiTargetingFrequencyCap::ShouldExclude( const CreativeAdInfo& creative_ad) { if (!DoesRespectCap(creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s excluded as previously visited an anti-targeted site", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.h index 784f2158935b..ed99d714fb72 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/anti_targeting_frequency_cap.h @@ -28,6 +28,8 @@ class AntiTargetingFrequencyCap final : public ExclusionRule { AntiTargetingFrequencyCap& operator=(const AntiTargetingFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.cc index db4eee4c715c..e1c05d6cf408 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.cc @@ -11,6 +11,7 @@ #include "bat/ads/ads_client.h" #include "bat/ads/internal/ads_client_helper.h" #include "bat/ads/internal/frequency_capping/frequency_capping_features.h" +#include "bat/ads/internal/frequency_capping/frequency_capping_util.h" #include "bat/ads/pref_names.h" namespace ads { @@ -24,16 +25,20 @@ ConversionFrequencyCap::ConversionFrequencyCap(const AdEventList& ad_events) ConversionFrequencyCap::~ConversionFrequencyCap() = default; +std::string ConversionFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool ConversionFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { if (!features::frequency_capping::ShouldExcludeAdIfConverted()) { return false; } if (!ShouldAllow(creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s excluded due to ad conversion tracking being " - "disabled", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } @@ -42,9 +47,9 @@ bool ConversionFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events)) { - last_message_ = base::StringPrintf( - "creativeSetId %s has exceeded the frequency capping for conversions", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } @@ -81,8 +86,7 @@ AdEventList ConversionFrequencyCap::FilterAdEvents( const auto iter = std::remove_if( filtered_ad_events.begin(), filtered_ad_events.end(), [&creative_ad](const AdEventInfo& ad_event) { - return (ad_event.type != AdType::kAdNotification && - ad_event.type != AdType::kInlineContentAd) || + return !DoesAdTypeSupportFrequencyCapping(ad_event.type) || ad_event.creative_set_id != creative_ad.creative_set_id || ad_event.confirmation_type != ConfirmationType::kConversion; }); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.h index 6c1b7e50b532..e4a7a0d9fae7 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/conversion_frequency_cap.h @@ -22,6 +22,8 @@ class ConversionFrequencyCap final : public ExclusionRule { ConversionFrequencyCap(const ConversionFrequencyCap&) = delete; ConversionFrequencyCap& operator=(const ConversionFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.cc index 1defce409681..ba010f26c4ac 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.cc @@ -18,14 +18,19 @@ DailyCapFrequencyCap::DailyCapFrequencyCap(const AdEventList& ad_events) DailyCapFrequencyCap::~DailyCapFrequencyCap() = default; +std::string DailyCapFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.campaign_id; +} + bool DailyCapFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events, creative_ad)) { - last_message_ = base::StringPrintf( - "campaignId %s has exceeded the frequency capping for dailyCap", - creative_ad.campaign_id.c_str()); + last_message_ = + base::StringPrintf("campaignId %s has exceeded the frequency cap", + creative_ad.campaign_id.c_str()); return true; } @@ -39,13 +44,11 @@ std::string DailyCapFrequencyCap::GetLastMessage() const { bool DailyCapFrequencyCap::DoesRespectCap(const AdEventList& ad_events, const CreativeAdInfo& creative_ad) { - const std::deque history = GetHistoryForAdEvents(ad_events); - const base::TimeDelta time_constraint = base::TimeDelta::FromSeconds( base::Time::kSecondsPerHour * base::Time::kHoursPerDay); - return DoesHistoryRespectCapForRollingTimeConstraint(history, time_constraint, - creative_ad.daily_cap); + return DoesAdEventsRespectCapForRollingTimeConstraint( + ad_events, time_constraint, creative_ad.daily_cap); } AdEventList DailyCapFrequencyCap::FilterAdEvents( @@ -56,8 +59,7 @@ AdEventList DailyCapFrequencyCap::FilterAdEvents( const auto iter = std::remove_if( filtered_ad_events.begin(), filtered_ad_events.end(), [&creative_ad](const AdEventInfo& ad_event) { - return (ad_event.type != AdType::kAdNotification && - ad_event.type != AdType::kInlineContentAd) || + return !DoesAdTypeSupportFrequencyCapping(ad_event.type) || ad_event.campaign_id != creative_ad.campaign_id || ad_event.confirmation_type != ConfirmationType::kServed; }); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.h index c1f90b99d4f0..40348bfcfebc 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daily_cap_frequency_cap.h @@ -22,6 +22,8 @@ class DailyCapFrequencyCap final : public ExclusionRule { DailyCapFrequencyCap(const DailyCapFrequencyCap&) = delete; DailyCapFrequencyCap& operator=(const DailyCapFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.cc index 2895f7d06fee..ea05ad75b2d1 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.cc @@ -33,11 +33,16 @@ DaypartFrequencyCap::DaypartFrequencyCap() = default; DaypartFrequencyCap::~DaypartFrequencyCap() = default; +std::string DaypartFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool DaypartFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { if (!DoesRespectCap(creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s excluded as not within a scheduled time slot", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.h index b9467691d099..97251724215f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/daypart_frequency_cap.h @@ -21,6 +21,8 @@ class DaypartFrequencyCap final : public ExclusionRule { DaypartFrequencyCap(const DaypartFrequencyCap&) = delete; DaypartFrequencyCap& operator=(const DaypartFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.cc index 51982ecf53ec..026b29af0ebb 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.cc @@ -15,6 +15,11 @@ DislikeFrequencyCap::DislikeFrequencyCap() = default; DislikeFrequencyCap::~DislikeFrequencyCap() = default; +std::string DislikeFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool DislikeFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { if (!DoesRespectCap(creative_ad)) { last_message_ = diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h index cfac0786fc79..a5cd904a3ae6 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h @@ -21,6 +21,8 @@ class DislikeFrequencyCap final : public ExclusionRule { DislikeFrequencyCap(const DislikeFrequencyCap&) = delete; DislikeFrequencyCap& operator=(const DislikeFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.cc index 55b521d59ba0..ade979e8c527 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.cc @@ -16,15 +16,20 @@ DismissedFrequencyCap::DismissedFrequencyCap(const AdEventList& ad_events) DismissedFrequencyCap::~DismissedFrequencyCap() = default; +std::string DismissedFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.campaign_id; +} + bool DismissedFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events)) { - last_message_ = base::StringPrintf( - "campaignId %s has exceeded the " - "frequency capping for dismissed", - creative_ad.campaign_id.c_str()); + last_message_ = + base::StringPrintf("campaignId %s has exceeded the frequency cap", + creative_ad.campaign_id.c_str()); + return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.h index 3d8e5e5dabfe..3ec3b14c6b1e 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dismissed_frequency_cap.h @@ -22,6 +22,8 @@ class DismissedFrequencyCap final : public ExclusionRule { DismissedFrequencyCap(const DismissedFrequencyCap&) = delete; DismissedFrequencyCap& operator=(const DismissedFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule.h index 34ea335e730c..6f2834bc6723 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule.h @@ -15,6 +15,8 @@ class ExclusionRule { public: virtual ~ExclusionRule() = default; + virtual std::string GetUuid(const T&) const = 0; + virtual bool ShouldExclude(const T&) = 0; virtual std::string GetLastMessage() const = 0; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.cc index 41e719e86d98..e252b7d0ba1a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.cc @@ -17,12 +17,17 @@ MarkedAsInappropriateFrequencyCap::MarkedAsInappropriateFrequencyCap() = MarkedAsInappropriateFrequencyCap::~MarkedAsInappropriateFrequencyCap() = default; +std::string MarkedAsInappropriateFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool MarkedAsInappropriateFrequencyCap::ShouldExclude( const CreativeAdInfo& creative_ad) { if (!DoesRespectCap(creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s excluded due to being marked as inappropriate", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.h index 1884d6108008..e041a9b795ec 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_as_inappropriate_frequency_cap.h @@ -24,6 +24,8 @@ class MarkedAsInappropriateFrequencyCap final MarkedAsInappropriateFrequencyCap& operator=( const MarkedAsInappropriateFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.cc index 64c9d9776034..4d1b60d191f3 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.cc @@ -16,13 +16,17 @@ MarkedToNoLongerReceiveFrequencyCap::MarkedToNoLongerReceiveFrequencyCap() = MarkedToNoLongerReceiveFrequencyCap::~MarkedToNoLongerReceiveFrequencyCap() = default; +std::string MarkedToNoLongerReceiveFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool MarkedToNoLongerReceiveFrequencyCap::ShouldExclude( const CreativeAdInfo& creative_ad) { if (!DoesRespectCap(creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s excluded due to being marked to no longer receive " - "ads", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.h index d23fb59d357e..2b348e808d06 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/marked_to_no_longer_receive_frequency_cap.h @@ -24,6 +24,8 @@ class MarkedToNoLongerReceiveFrequencyCap final MarkedToNoLongerReceiveFrequencyCap& operator=( const MarkedToNoLongerReceiveFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/new_tab_page_ad_uuid_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/new_tab_page_ad_uuid_frequency_cap.cc index f036b00ec9aa..c0396e942456 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/new_tab_page_ad_uuid_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/new_tab_page_ad_uuid_frequency_cap.cc @@ -21,14 +21,18 @@ NewTabPageAdUuidFrequencyCap::NewTabPageAdUuidFrequencyCap( NewTabPageAdUuidFrequencyCap::~NewTabPageAdUuidFrequencyCap() = default; +std::string NewTabPageAdUuidFrequencyCap::GetUuid(const AdInfo& ad) const { + return ad.uuid; +} + bool NewTabPageAdUuidFrequencyCap::ShouldExclude(const AdInfo& ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, ad); if (!DoesRespectCap(filtered_ad_events)) { last_message_ = base::StringPrintf( - "uuid %s has exceeded the " - "frequency capping for new tab page ad", + "uuid %s has exceeded the frequency capping for new tab page ad", ad.uuid.c_str()); + return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/new_tab_page_ad_uuid_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/new_tab_page_ad_uuid_frequency_cap.h index 920bc6ad32ff..8737c570ec6a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/new_tab_page_ad_uuid_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/new_tab_page_ad_uuid_frequency_cap.h @@ -23,6 +23,8 @@ class NewTabPageAdUuidFrequencyCap final : public ExclusionRule { NewTabPageAdUuidFrequencyCap& operator=(const NewTabPageAdUuidFrequencyCap&) = delete; + std::string GetUuid(const AdInfo& ad) const override; + bool ShouldExclude(const AdInfo& ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.cc index 45dcaa3bcc70..b49a4e23686b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.cc @@ -18,14 +18,19 @@ PerDayFrequencyCap::PerDayFrequencyCap(const AdEventList& ad_events) PerDayFrequencyCap::~PerDayFrequencyCap() = default; +std::string PerDayFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool PerDayFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events, creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s has exceeded the frequency capping for perDay", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } @@ -43,13 +48,11 @@ bool PerDayFrequencyCap::DoesRespectCap(const AdEventList& ad_events, return true; } - const std::deque history = GetHistoryForAdEvents(ad_events); - const base::TimeDelta time_constraint = base::TimeDelta::FromSeconds( base::Time::kSecondsPerHour * base::Time::kHoursPerDay); - return DoesHistoryRespectCapForRollingTimeConstraint(history, time_constraint, - creative_ad.per_day); + return DoesAdEventsRespectCapForRollingTimeConstraint( + ad_events, time_constraint, creative_ad.per_day); } AdEventList PerDayFrequencyCap::FilterAdEvents( @@ -60,8 +63,7 @@ AdEventList PerDayFrequencyCap::FilterAdEvents( const auto iter = std::remove_if( filtered_ad_events.begin(), filtered_ad_events.end(), [&creative_ad](const AdEventInfo& ad_event) { - return (ad_event.type != AdType::kAdNotification && - ad_event.type != AdType::kInlineContentAd) || + return !DoesAdTypeSupportFrequencyCapping(ad_event.type) || ad_event.creative_set_id != creative_ad.creative_set_id || ad_event.confirmation_type != ConfirmationType::kServed; }); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.h index eb308652b330..8905219295de 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_day_frequency_cap.h @@ -22,6 +22,8 @@ class PerDayFrequencyCap final : public ExclusionRule { PerDayFrequencyCap(const PerDayFrequencyCap&) = delete; PerDayFrequencyCap& operator=(const PerDayFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.cc index 9e254123364c..441116babe58 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.cc @@ -24,13 +24,18 @@ PerHourFrequencyCap::PerHourFrequencyCap(const AdEventList& ad_events) PerHourFrequencyCap::~PerHourFrequencyCap() = default; +std::string PerHourFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_instance_id; +} + bool PerHourFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events)) { last_message_ = base::StringPrintf( - "creativeInstanceId %s has exceeded the frequency capping for perHour", + "creativeInstanceId %s has exceeded the frequency cap", creative_ad.creative_instance_id.c_str()); return true; @@ -44,13 +49,11 @@ std::string PerHourFrequencyCap::GetLastMessage() const { } bool PerHourFrequencyCap::DoesRespectCap(const AdEventList& ad_events) { - const std::deque history = GetHistoryForAdEvents(ad_events); - const base::TimeDelta time_constraint = base::TimeDelta::FromSeconds(base::Time::kSecondsPerHour); - return DoesHistoryRespectCapForRollingTimeConstraint(history, time_constraint, - kPerHourFrequencyCap); + return DoesAdEventsRespectCapForRollingTimeConstraint( + ad_events, time_constraint, kPerHourFrequencyCap); } AdEventList PerHourFrequencyCap::FilterAdEvents( @@ -61,8 +64,7 @@ AdEventList PerHourFrequencyCap::FilterAdEvents( const auto iter = std::remove_if( filtered_ad_events.begin(), filtered_ad_events.end(), [&creative_ad](const AdEventInfo& ad_event) { - return (ad_event.type != AdType::kAdNotification && - ad_event.type != AdType::kInlineContentAd) || + return !DoesAdTypeSupportFrequencyCapping(ad_event.type) || ad_event.creative_instance_id != creative_ad.creative_instance_id || ad_event.confirmation_type != ConfirmationType::kServed; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.h index 6e8cfb5c329f..fca99d3d89f4 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_hour_frequency_cap.h @@ -22,6 +22,8 @@ class PerHourFrequencyCap final : public ExclusionRule { PerHourFrequencyCap(const PerHourFrequencyCap&) = delete; PerHourFrequencyCap& operator=(const PerHourFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.cc index 23bbc08bbfb7..a73d2a5e8b3d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.cc @@ -19,15 +19,19 @@ PerMonthFrequencyCap::PerMonthFrequencyCap(const AdEventList& ad_events) PerMonthFrequencyCap::~PerMonthFrequencyCap() = default; +std::string PerMonthFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool PerMonthFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events, creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s has exceeded the " - "frequency capping for perMonth", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } @@ -45,13 +49,11 @@ bool PerMonthFrequencyCap::DoesRespectCap(const AdEventList& ad_events, return true; } - const std::deque history = GetHistoryForAdEvents(ad_events); - const base::TimeDelta time_constraint = base::TimeDelta::FromSeconds( 28 * (base::Time::kSecondsPerHour * base::Time::kHoursPerDay)); - return DoesHistoryRespectCapForRollingTimeConstraint(history, time_constraint, - creative_ad.per_month); + return DoesAdEventsRespectCapForRollingTimeConstraint( + ad_events, time_constraint, creative_ad.per_month); } AdEventList PerMonthFrequencyCap::FilterAdEvents( @@ -62,8 +64,7 @@ AdEventList PerMonthFrequencyCap::FilterAdEvents( const auto iter = std::remove_if( filtered_ad_events.begin(), filtered_ad_events.end(), [&creative_ad](const AdEventInfo& ad_event) { - return (ad_event.type != AdType::kAdNotification && - ad_event.type != AdType::kInlineContentAd) || + return !DoesAdTypeSupportFrequencyCapping(ad_event.type) || ad_event.creative_set_id != creative_ad.creative_set_id || ad_event.confirmation_type != ConfirmationType::kServed; }); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.h index 7f50fb5fe46c..51a456a2361c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_month_frequency_cap.h @@ -22,6 +22,8 @@ class PerMonthFrequencyCap final : public ExclusionRule { PerMonthFrequencyCap(const PerMonthFrequencyCap&) = delete; PerMonthFrequencyCap& operator=(const PerMonthFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.cc index b662cb095ec1..a858ba216fe9 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.cc @@ -19,14 +19,19 @@ PerWeekFrequencyCap::PerWeekFrequencyCap(const AdEventList& ad_events) PerWeekFrequencyCap::~PerWeekFrequencyCap() = default; +std::string PerWeekFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool PerWeekFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events, creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s has exceeded the frequency capping for perWeek", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } @@ -44,13 +49,11 @@ bool PerWeekFrequencyCap::DoesRespectCap(const AdEventList& ad_events, return true; } - const std::deque history = GetHistoryForAdEvents(ad_events); - const base::TimeDelta time_constraint = base::TimeDelta::FromSeconds( 7 * (base::Time::kSecondsPerHour * base::Time::kHoursPerDay)); - return DoesHistoryRespectCapForRollingTimeConstraint(history, time_constraint, - creative_ad.per_week); + return DoesAdEventsRespectCapForRollingTimeConstraint( + ad_events, time_constraint, creative_ad.per_week); } AdEventList PerWeekFrequencyCap::FilterAdEvents( @@ -61,8 +64,7 @@ AdEventList PerWeekFrequencyCap::FilterAdEvents( const auto iter = std::remove_if( filtered_ad_events.begin(), filtered_ad_events.end(), [&creative_ad](const AdEventInfo& ad_event) { - return (ad_event.type != AdType::kAdNotification && - ad_event.type != AdType::kInlineContentAd) || + return !DoesAdTypeSupportFrequencyCapping(ad_event.type) || ad_event.creative_set_id != creative_ad.creative_set_id || ad_event.confirmation_type != ConfirmationType::kServed; }); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.h index 4ae2272675bb..84ab227e9278 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/per_week_frequency_cap.h @@ -22,6 +22,8 @@ class PerWeekFrequencyCap final : public ExclusionRule { PerWeekFrequencyCap(const PerWeekFrequencyCap&) = delete; PerWeekFrequencyCap& operator=(const PerWeekFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/promoted_content_ad_uuid_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/promoted_content_ad_uuid_frequency_cap.cc index d798729fb007..1605ba29c9cc 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/promoted_content_ad_uuid_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/promoted_content_ad_uuid_frequency_cap.cc @@ -22,14 +22,18 @@ PromotedContentAdUuidFrequencyCap::PromotedContentAdUuidFrequencyCap( PromotedContentAdUuidFrequencyCap::~PromotedContentAdUuidFrequencyCap() = default; +std::string PromotedContentAdUuidFrequencyCap::GetUuid(const AdInfo& ad) const { + return ad.uuid; +} + bool PromotedContentAdUuidFrequencyCap::ShouldExclude(const AdInfo& ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, ad); if (!DoesRespectCap(filtered_ad_events)) { last_message_ = base::StringPrintf( - "uuid %s has exceeded the " - "frequency capping for new tab page ad", + "uuid %s has exceeded the frequency capping for new tab page ad", ad.uuid.c_str()); + return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/promoted_content_ad_uuid_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/promoted_content_ad_uuid_frequency_cap.h index 75ab67cbfc7a..752485e86dd8 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/promoted_content_ad_uuid_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/promoted_content_ad_uuid_frequency_cap.h @@ -24,6 +24,8 @@ class PromotedContentAdUuidFrequencyCap final : public ExclusionRule { PromotedContentAdUuidFrequencyCap& operator=( const PromotedContentAdUuidFrequencyCap&) = delete; + std::string GetUuid(const AdInfo& ad) const override; + bool ShouldExclude(const AdInfo& ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.cc index 1e76196ce0cd..185c06fedd5f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.cc @@ -30,6 +30,11 @@ SplitTestFrequencyCap::SplitTestFrequencyCap() = default; SplitTestFrequencyCap::~SplitTestFrequencyCap() = default; +std::string SplitTestFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool SplitTestFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { if (!DoesRespectCap(creative_ad)) { last_message_ = base::StringPrintf( diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.h index 57aaccab0582..d4111f24ebee 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/split_test_frequency_cap.h @@ -21,6 +21,8 @@ class SplitTestFrequencyCap : public ExclusionRule { SplitTestFrequencyCap(const SplitTestFrequencyCap&) = delete; SplitTestFrequencyCap& operator=(const SplitTestFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.cc index fb3ccbf0d55a..5b024c9d888b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.cc @@ -24,20 +24,10 @@ bool DoesAdSupportSubdivisionTargetingCode( const std::string country_code = locale::GetCountryCode(subdivision_targeting_code); - const auto iter = - std::find_if(creative_ad.geo_targets.begin(), - creative_ad.geo_targets.end(), - [&subdivision_targeting_code, - &country_code](const std::string& geo_target) { - return geo_target == subdivision_targeting_code || - geo_target == country_code; - }); - - if (iter == creative_ad.geo_targets.end()) { - return false; - } - - return true; + return creative_ad.geo_targets.find(subdivision_targeting_code) != + creative_ad.geo_targets.end() || + creative_ad.geo_targets.find(country_code) != + creative_ad.geo_targets.end(); } bool DoesAdTargetSubdivision(const CreativeAdInfo& creative_ad) { @@ -67,12 +57,17 @@ SubdivisionTargetingFrequencyCap::SubdivisionTargetingFrequencyCap( SubdivisionTargetingFrequencyCap::~SubdivisionTargetingFrequencyCap() = default; +std::string SubdivisionTargetingFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool SubdivisionTargetingFrequencyCap::ShouldExclude( const CreativeAdInfo& creative_ad) { if (!DoesRespectCap(creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s excluded as not within the targeted subdivision", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.h index 5e6a47100144..e13191ef7202 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/subdivision_targeting_frequency_cap.h @@ -31,6 +31,8 @@ class SubdivisionTargetingFrequencyCap final SubdivisionTargetingFrequencyCap& operator=( const SubdivisionTargetingFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.cc index 6200a2ded451..df6888447f2c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.cc @@ -6,6 +6,7 @@ #include "bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.h" #include "base/strings/stringprintf.h" +#include "bat/ads/internal/frequency_capping/frequency_capping_util.h" namespace ads { @@ -14,14 +15,19 @@ TotalMaxFrequencyCap::TotalMaxFrequencyCap(const AdEventList& ad_events) TotalMaxFrequencyCap::~TotalMaxFrequencyCap() = default; +std::string TotalMaxFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.creative_set_id; +} + bool TotalMaxFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events, creative_ad)) { - last_message_ = base::StringPrintf( - "creativeSetId %s has exceeded the frequency capping for totalMax", - creative_ad.creative_set_id.c_str()); + last_message_ = + base::StringPrintf("creativeSetId %s has exceeded the frequency cap", + creative_ad.creative_set_id.c_str()); return true; } @@ -50,8 +56,7 @@ AdEventList TotalMaxFrequencyCap::FilterAdEvents( const auto iter = std::remove_if( filtered_ad_events.begin(), filtered_ad_events.end(), [&creative_ad](const AdEventInfo& ad_event) { - return (ad_event.type != AdType::kAdNotification && - ad_event.type != AdType::kInlineContentAd) || + return !DoesAdTypeSupportFrequencyCapping(ad_event.type) || ad_event.creative_set_id != creative_ad.creative_set_id || ad_event.confirmation_type != ConfirmationType::kServed; }); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.h index d6e5ded810ab..664ff8a33ef2 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/total_max_frequency_cap.h @@ -22,6 +22,8 @@ class TotalMaxFrequencyCap final : public ExclusionRule { TotalMaxFrequencyCap(const TotalMaxFrequencyCap&) = delete; TotalMaxFrequencyCap& operator=(const TotalMaxFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.cc index 6e5e1263b558..6de6d0c7c3e3 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.cc @@ -23,14 +23,20 @@ TransferredFrequencyCap::TransferredFrequencyCap(const AdEventList& ad_events) TransferredFrequencyCap::~TransferredFrequencyCap() = default; +std::string TransferredFrequencyCap::GetUuid( + const CreativeAdInfo& creative_ad) const { + return creative_ad.campaign_id; +} + bool TransferredFrequencyCap::ShouldExclude(const CreativeAdInfo& creative_ad) { const AdEventList filtered_ad_events = FilterAdEvents(ad_events_, creative_ad); if (!DoesRespectCap(filtered_ad_events)) { - last_message_ = base::StringPrintf( - "campaignId %s has exceeded the frequency capping for transferred", - creative_ad.campaign_id.c_str()); + last_message_ = + base::StringPrintf("campaignId %s has exceeded the frequency cap", + creative_ad.campaign_id.c_str()); + return true; } @@ -42,13 +48,11 @@ std::string TransferredFrequencyCap::GetLastMessage() const { } bool TransferredFrequencyCap::DoesRespectCap(const AdEventList& ad_events) { - const std::deque history = GetHistoryForAdEvents(ad_events); - const base::TimeDelta time_constraint = features::frequency_capping::ExcludeAdIfTransferredWithinTimeWindow(); - return DoesHistoryRespectCapForRollingTimeConstraint( - history, time_constraint, kTransferredFrequencyCap); + return DoesAdEventsRespectCapForRollingTimeConstraint( + ad_events, time_constraint, kTransferredFrequencyCap); } AdEventList TransferredFrequencyCap::FilterAdEvents( @@ -59,8 +63,7 @@ AdEventList TransferredFrequencyCap::FilterAdEvents( const auto iter = std::remove_if( filtered_ad_events.begin(), filtered_ad_events.end(), [&creative_ad](const AdEventInfo& ad_event) { - return (ad_event.type != AdType::kAdNotification && - ad_event.type != AdType::kInlineContentAd) || + return !DoesAdTypeSupportFrequencyCapping(ad_event.type) || ad_event.campaign_id != creative_ad.campaign_id || ad_event.confirmation_type != ConfirmationType::kTransferred; }); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.h index 3b1b8eab4f01..70a0cda77bb4 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/transferred_frequency_cap.h @@ -22,6 +22,8 @@ class TransferredFrequencyCap final : public ExclusionRule { TransferredFrequencyCap(const TransferredFrequencyCap&) = delete; TransferredFrequencyCap& operator=(const TransferredFrequencyCap&) = delete; + std::string GetUuid(const CreativeAdInfo& creative_ad) const override; + bool ShouldExclude(const CreativeAdInfo& creative_ad) override; std::string GetLastMessage() const override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/frequency_capping_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/frequency_capping_util.cc index fae86f8d6b74..2871dc394c6c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/frequency_capping_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/frequency_capping_util.cc @@ -5,18 +5,50 @@ #include "bat/ads/internal/frequency_capping/frequency_capping_util.h" +#include "base/notreached.h" #include "base/time/time.h" +#include "bat/ads/ad_type.h" namespace ads { -std::deque GetHistoryForAdEvents(const AdEventList& ad_events) { - std::deque history; +bool DoesAdTypeSupportFrequencyCapping(const AdType& type) { + switch (type.value()) { + case AdType::kAdNotification: + case AdType::kInlineContentAd: { + return true; + } + + case AdType::kNewTabPageAd: + case AdType::kPromotedContentAd: { + return false; + } + + case AdType::kUndefined: { + NOTREACHED(); + return false; + } + } +} + +bool DoesAdEventsRespectCapForRollingTimeConstraint( + const AdEventList& ad_events, + const base::TimeDelta& time_constraint, + const uint64_t cap) { + uint64_t count = 0; + + const base::Time now = base::Time::Now(); for (const auto& ad_event : ad_events) { - history.push_back(ad_event.created_at); + if (now - ad_event.created_at < time_constraint) { + count++; + } } - return history; + if (count >= cap) { + return false; + } + + return true; } bool DoesHistoryRespectCapForRollingTimeConstraint( diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/frequency_capping_util.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/frequency_capping_util.h index 1c40d9849022..bb300b309d31 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/frequency_capping_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/frequency_capping_util.h @@ -17,7 +17,14 @@ class TimeDelta; namespace ads { -std::deque GetHistoryForAdEvents(const AdEventList& ad_events); +class AdType; + +bool DoesAdTypeSupportFrequencyCapping(const AdType& type); + +bool DoesAdEventsRespectCapForRollingTimeConstraint( + const AdEventList& ad_events, + const base::TimeDelta& time_constraint, + const uint64_t cap); bool DoesHistoryRespectCapForRollingTimeConstraint( const std::deque& history, diff --git a/vendor/bat-native-ads/src/bat/ads/internal/tokens/redeem_unblinded_token/create_confirmation_url_request_builder_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/tokens/redeem_unblinded_token/create_confirmation_url_request_builder_unittest.cc index 776c000533f6..cd47ba58ad7d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/tokens/redeem_unblinded_token/create_confirmation_url_request_builder_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/tokens/redeem_unblinded_token/create_confirmation_url_request_builder_unittest.cc @@ -21,7 +21,7 @@ class BatAdsCreateConfirmationUrlRequestBuilderTest : public UnitTestBase { ~BatAdsCreateConfirmationUrlRequestBuilderTest() override = default; - ConfirmationInfo GetConfirmationForType(const ConfirmationType type) { + ConfirmationInfo BuildConfirmationForType(const ConfirmationType type) { ConfirmationInfo confirmation = BuildConfirmation("d990ed8d-d739-49fb-811b-c2e02158fb60", "546fe7b0-5047-4f28-a11c-81f14edcf0f6", type); @@ -53,7 +53,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(true, "release"); @@ -87,7 +87,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(true, "release"); @@ -121,7 +121,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(true, "release"); @@ -155,7 +155,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(false, "beta"); @@ -189,7 +189,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(false, "beta"); @@ -223,7 +223,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(false, "beta"); @@ -257,7 +257,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(true, "release"); @@ -291,7 +291,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(true, "release"); @@ -325,7 +325,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(true, "release"); @@ -359,7 +359,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(false, "beta"); @@ -393,7 +393,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(false, "beta"); @@ -427,7 +427,7 @@ TEST_F(BatAdsCreateConfirmationUrlRequestBuilderTest, SetSysInfo(sys_info); const ConfirmationInfo confirmation = - GetConfirmationForType(ConfirmationType::kViewed); + BuildConfirmationForType(ConfirmationType::kViewed); SetBuildChannel(false, "beta"); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/tokens/redeem_unblinded_token/redeem_unblinded_token_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/tokens/redeem_unblinded_token/redeem_unblinded_token_unittest.cc index 87b699ae601a..a8959e1aa361 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/tokens/redeem_unblinded_token/redeem_unblinded_token_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/tokens/redeem_unblinded_token/redeem_unblinded_token_unittest.cc @@ -57,7 +57,7 @@ class BatAdsRedeemUnblindedTokenTest : public UnitTestBase { get_unblinded_tokens()->SetTokens({unblinded_token}); } - ConfirmationInfo GetConfirmationInfo() { + ConfirmationInfo BuildConfirmationWithPayloadIfNeeded() { ConfirmationInfo confirmation = BuildConfirmation( "9fd71bc4-1b8e-4c1e-8ddc-443193a09f91", "70829d71-ce2e-4483-a4c0-e1e2bee96520", ConfirmationType::kViewed); @@ -131,7 +131,7 @@ TEST_F(BatAdsRedeemUnblindedTokenTest, RedeemUnblindedToken) { SetUnblindedTokens(); - const ConfirmationInfo confirmation = GetConfirmationInfo(); + const ConfirmationInfo confirmation = BuildConfirmationWithPayloadIfNeeded(); // Act ConfirmationInfo expected_confirmation = confirmation; @@ -176,7 +176,7 @@ TEST_F(BatAdsRedeemUnblindedTokenTest, RetryRedeemingUnblindedToken) { SetUnblindedTokens(); - ConfirmationInfo confirmation = GetConfirmationInfo(); + ConfirmationInfo confirmation = BuildConfirmationWithPayloadIfNeeded(); confirmation.was_created = true; // Act @@ -211,7 +211,7 @@ TEST_F( SetUnblindedTokens(); - const ConfirmationInfo confirmation = GetConfirmationInfo(); + const ConfirmationInfo confirmation = BuildConfirmationWithPayloadIfNeeded(); // Act ConfirmationInfo expected_confirmation = confirmation; @@ -246,7 +246,7 @@ TEST_F( SetUnblindedTokens(); - const ConfirmationInfo confirmation = GetConfirmationInfo(); + const ConfirmationInfo confirmation = BuildConfirmationWithPayloadIfNeeded(); // Act ConfirmationInfo expected_confirmation = confirmation; @@ -283,7 +283,7 @@ TEST_F(BatAdsRedeemUnblindedTokenTest, RedeemUnblindedTokenIfAdsIsDisabled) { MockUrlRequest(ads_client_mock_, endpoints); - const ConfirmationInfo confirmation = GetConfirmationInfo(); + const ConfirmationInfo confirmation = BuildConfirmationWithPayloadIfNeeded(); // Act ConfirmationInfo expected_confirmation = confirmation; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/tokens/refill_unblinded_tokens/refill_unblinded_tokens_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/tokens/refill_unblinded_tokens/refill_unblinded_tokens_unittest.cc index 18da30ef146e..fdb685f2804c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/tokens/refill_unblinded_tokens/refill_unblinded_tokens_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/tokens/refill_unblinded_tokens/refill_unblinded_tokens_unittest.cc @@ -56,7 +56,7 @@ class BatAdsRefillUnblindedTokensTest : public UnitTestBase { return wallet.Get(); } - CatalogIssuersInfo GetValidCatalogIssuers() { + CatalogIssuersInfo BuildValidCatalogIssuers() { CatalogIssuersInfo catalog_issuers; catalog_issuers.public_key = "crDVI1R6xHQZ4D9cQu4muVM5MaaM1QcOT4It8Y/CYlw="; @@ -179,7 +179,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, RefillUnblindedTokens) { const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -217,7 +217,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, RefillUnblindedTokensCaptchaRequired) { const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -428,7 +428,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -474,7 +474,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, RequestSignedTokensMissingNonce) { const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -585,7 +585,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -637,7 +637,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, GetSignedTokensInvalidResponse) { const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -741,7 +741,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, GetSignedTokensMissingPublicKey) { const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -845,7 +845,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, GetSignedTokensMissingBatchProofDleq) { const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -898,7 +898,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, GetSignedTokensMissingSignedTokens) { const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -1003,7 +1003,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, GetInvalidSignedTokens) { const std::vector tokens = GetTokens(); ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -1044,7 +1044,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, VerifyAndUnblindInvalidTokens) { ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act @@ -1202,7 +1202,7 @@ TEST_F(BatAdsRefillUnblindedTokensTest, RefillIfBelowTheMinimumThreshold) { ON_CALL(*token_generator_mock_, Generate(_)).WillByDefault(Return(tokens)); - CatalogIssuersInfo catalog_issuers = GetValidCatalogIssuers(); + const CatalogIssuersInfo catalog_issuers = BuildValidCatalogIssuers(); ConfirmationsState::Get()->SetCatalogIssuers(catalog_issuers); // Act