diff --git a/components/brave_ads/test/BUILD.gn b/components/brave_ads/test/BUILD.gn index 1d93fce0b835..c7287e940352 100644 --- a/components/brave_ads/test/BUILD.gn +++ b/components/brave_ads/test/BUILD.gn @@ -87,6 +87,16 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_handler_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad_test.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad_test.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_for_mobile_test.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_test.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_unittest_util.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_unittest_util.h", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util_serve_at_regular_intervals_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/promoted_content_ad_test.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/search_result_ad_test.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/eligible_ads_predictor_util_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/sample_ads_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/eligible_ads_features_unittest.cc", @@ -110,7 +120,7 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/exclusion_rules/subdivision_targeting_exclusion_rule_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/exclusion_rules/transferred_exclusion_rule_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_test.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1_unittest.cc", @@ -118,10 +128,10 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_issue_17199_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_test.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving_test.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving_test.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving_test.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/allow_notifications_permission_rule_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/browser_is_active_permission_rule_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/catalog_permission_rule_test.cc", @@ -157,6 +167,8 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.h", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest_util.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest_util.h", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/targeting/models/behavioral/bandits/epsilon_greedy_bandit_model_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/targeting/models/behavioral/bandits/epsilon_greedy_bandit_model_unittest_util.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/targeting/models/behavioral/bandits/epsilon_greedy_bandit_model_unittest_util.h", @@ -249,6 +261,8 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ad_unittest_util.h", "//brave/vendor/bat-native-ads/src/bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table_test.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.h", "//brave/vendor/bat-native-ads/src/bat/ads/internal/creatives/segments_database_table_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/deprecated/client/preferences/ad_preferences_info_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/diagnostics/diagnostic_manager_unittest.cc", @@ -264,6 +278,8 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/history/filters/date_range_history_filter_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/history/history_item_util_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/history/history_manager_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/history/history_unittest_util.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/history/history_unittest_util.h", "//brave/vendor/bat-native-ads/src/bat/ads/internal/history/history_util_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/history/sorts/history_sort_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/legacy_migration/client/legacy_client_migration_issue_23794_unittest.cc", @@ -348,14 +364,14 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/settings/settings_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/tabs/tab_manager_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/transfer/transfer_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util_unittest.cc", - "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_manager_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/new_tab_page_ad_info_unittest.cc", ] diff --git a/vendor/bat-native-ads/BUILD.gn b/vendor/bat-native-ads/BUILD.gn index 4dd755a94cec..b3fdcf39356a 100644 --- a/vendor/bat-native-ads/BUILD.gn +++ b/vendor/bat-native-ads/BUILD.gn @@ -317,6 +317,8 @@ source_set("ads") { "src/bat/ads/internal/ads/new_tab_page_ad.h", "src/bat/ads/internal/ads/notification_ad.cc", "src/bat/ads/internal/ads/notification_ad.h", + "src/bat/ads/internal/ads/notification_ad_util.cc", + "src/bat/ads/internal/ads/notification_ad_util.h", "src/bat/ads/internal/ads/promoted_content_ad.cc", "src/bat/ads/internal/ads/promoted_content_ad.h", "src/bat/ads/internal/ads/search_result_ad.cc", @@ -327,8 +329,6 @@ source_set("ads") { "src/bat/ads/internal/ads/serving/choose/eligible_ads_predictor_util.h", "src/bat/ads/internal/ads/serving/choose/predict_ad.h", "src/bat/ads/internal/ads/serving/choose/sample_ads.h", - "src/bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.cc", - "src/bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.h", "src/bat/ads/internal/ads/serving/eligible_ads/allocation/round_robin_ads.h", "src/bat/ads/internal/ads/serving/eligible_ads/allocation/round_robin_advertisers.h", "src/bat/ads/internal/ads/serving/eligible_ads/allocation/seen_ads.h", @@ -1065,31 +1065,31 @@ source_set("ads") { "src/bat/ads/internal/tabs/tab_manager.h", "src/bat/ads/internal/transfer/transfer.cc", "src/bat/ads/internal/transfer/transfer.h", - "src/bat/ads/internal/user_interaction/browsing/page_transition_util.cc", - "src/bat/ads/internal/user_interaction/browsing/page_transition_util.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_constants.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_event_info.cc", - "src/bat/ads/internal/user_interaction/browsing/user_activity_event_info.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_event_info_aliases.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_event_types.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_features.cc", - "src/bat/ads/internal/user_interaction/browsing/user_activity_features.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_manager.cc", - "src/bat/ads/internal/user_interaction/browsing/user_activity_manager.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_scoring.cc", - "src/bat/ads/internal/user_interaction/browsing/user_activity_scoring.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.cc", - "src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.cc", - "src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h", - "src/bat/ads/internal/user_interaction/browsing/user_activity_util.cc", - "src/bat/ads/internal/user_interaction/browsing/user_activity_util.h", "src/bat/ads/internal/user_interaction/idle_detection/idle_detection_manager.cc", "src/bat/ads/internal/user_interaction/idle_detection/idle_detection_manager.h", "src/bat/ads/internal/user_interaction/idle_detection/idle_detection_manager_observer.h", "src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util.cc", "src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util.h", + "src/bat/ads/internal/user_interaction/user_activity/page_transition_util.cc", + "src/bat/ads/internal/user_interaction/user_activity/page_transition_util.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_constants.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info.cc", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info_aliases.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_features.cc", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_features.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_manager.cc", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_manager.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring.cc", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.cc", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.cc", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_util.cc", + "src/bat/ads/internal/user_interaction/user_activity/user_activity_util.h", "src/bat/ads/new_tab_page_ad_info.cc", "src/bat/ads/new_tab_page_ad_wallpaper_focal_point_info.cc", "src/bat/ads/new_tab_page_ad_wallpaper_info.cc", diff --git a/vendor/bat-native-ads/data/test/catalog_with_inline_content_ad.json b/vendor/bat-native-ads/data/test/catalog_with_inline_content_ad.json new file mode 100644 index 000000000000..14c98cd7fb06 --- /dev/null +++ b/vendor/bat-native-ads/data/test/catalog_with_inline_content_ad.json @@ -0,0 +1,70 @@ +{ + "version": 9, + "ping": 7200000, + "campaigns": [ + { + "creativeSets": [ + { + "creatives": [ + { + "creativeInstanceId": "30db5f7b-dba3-48a3-b299-c9bd9c67da65", + "type": { + "code": "inline_content_all_v1", + "name": "inline_content", + "platform": "all", + "version": 1 + }, + "payload": { + "title": "Test Title", + "description": "Test Description", + "imageUrl": "https://www.brave.com", + "dimensions": "200x100", + "ctaText": "Test Call to Action Text", + "targetUrl": "https://brave.com" + } + } + ], + "segments": [ + { + "code": "Svp7l-zGN", + "name": "untargeted" + } + ], + "oses": [ + ], + "conversions": [ + { + "observationWindow": 30, + "urlPattern": "https://www.brave.com/*", + "type": "postview" + } + ], + "channels": [ + ], + "creativeSetId": "340c927f-696e-4060-9933-3eafc56c3f31", + "perDay": 1, + "perWeek": 1, + "perMonth": 1, + "totalMax": 1, + "value": "1.0" + } + ], + "dayParts": [ + ], + "geoTargets": [ + { + "code": "US", + "name": "United States" + } + ], + "campaignId": "27a624a1-9c80-494a-bf1b-af327b563f85", + "startAt": "", + "endAt": "", + "dailyCap": 1, + "advertiserId": "a437c7f3-9a48-4fe8-b37b-99321bea93fe", + "priority": 1, + "ptr": 1.0 + } + ], + "catalogId": "29e5c8bc0ba319069980bb390d8e8f9b58c05a20" +} diff --git a/vendor/bat-native-ads/data/test/catalog_with_new_tab_page_ad.json b/vendor/bat-native-ads/data/test/catalog_with_new_tab_page_ad.json new file mode 100644 index 000000000000..f5eb35c67712 --- /dev/null +++ b/vendor/bat-native-ads/data/test/catalog_with_new_tab_page_ad.json @@ -0,0 +1,86 @@ +{ + "version": 9, + "ping": 7200000, + "campaigns": [ + { + "creativeSets": [ + { + "creatives": [ + { + "creativeInstanceId": "7ff400b9-7f8a-46a8-89f1-cb386612edcf", + "type": { + "code": "new_tab_page_all_v1", + "platform": "all", + "name": "new_tab_page", + "version": 1 + }, + "payload": { + "logo": { + "alt": "Test Alt", + "imageUrl": "https://brave.com/image.jpg", + "companyName": "Test Company Name", + "destinationUrl": "https://brave.com" + }, + "wallpapers": [ + { + "focalPoint": { + "x": 1200, + "y": 1400 + }, + "imageUrl": "https://brave.com/wallpaper_1.jpg" + }, + { + "focalPoint": { + "x": 1200, + "y": 1400 + }, + "imageUrl": "https://brave.com/wallpaper_2.jpg" + } + ] + } + } + ], + "segments": [ + { + "code": "Svp7l-zGN", + "name": "untargeted" + } + ], + "oses": [ + ], + "conversions": [ + { + "observationWindow": 30, + "urlPattern": "https://www.brave.com/*", + "type": "postview" + } + ], + "channels": [ + ], + "creativeSetId": "340c927f-696e-4060-9933-3eafc56c3f31", + "perDay": 1, + "perWeek": 1, + "perMonth": 1, + "totalMax": 1, + "value": "1.0" + } + ], + "dayParts": [ + ], + "geoTargets": [ + { + "code": "US", + "name": "United States" + } + ], + "campaignId": "27a624a1-9c80-494a-bf1b-af327b563f85", + "startAt": "", + "endAt": "", + "dailyCap": 1, + "advertiserId": "a437c7f3-9a48-4fe8-b37b-99321bea93fe", + "priority": 1, + "ptr": 1.0 + } + ], + "catalogId": "29e5c8bc0ba319069980bb390d8e8f9b58c05a20" +} diff --git a/vendor/bat-native-ads/data/test/catalog_with_notification_ad.json b/vendor/bat-native-ads/data/test/catalog_with_notification_ad.json new file mode 100644 index 000000000000..a498ad8fb7bf --- /dev/null +++ b/vendor/bat-native-ads/data/test/catalog_with_notification_ad.json @@ -0,0 +1,67 @@ +{ + "version": 9, + "ping": 7200000, + "campaigns": [ + { + "creativeSets": [ + { + "creatives": [ + { + "creativeInstanceId": "18d8df02-68b1-4a6d-81a1-67357b157e2a", + "type": { + "code": "notification_all_v1", + "name": "notification", + "platform": "all", + "version": 1 + }, + "payload": { + "body": "Test Body", + "title": "Test Title", + "targetUrl": "https://brave.com" + } + } + ], + "segments": [ + { + "code": "Svp7l-zGN", + "name": "untargeted" + } + ], + "oses": [ + ], + "conversions": [ + { + "observationWindow": 30, + "urlPattern": "https://www.brave.com/*", + "type": "postview" + } + ], + "channels": [ + ], + "creativeSetId": "340c927f-696e-4060-9933-3eafc56c3f31", + "perDay": 1, + "perWeek": 1, + "perMonth": 1, + "totalMax": 1, + "value": "1.0" + } + ], + "dayParts": [ + ], + "geoTargets": [ + { + "code": "US", + "name": "United States" + } + ], + "campaignId": "27a624a1-9c80-494a-bf1b-af327b563f85", + "startAt": "", + "endAt": "", + "dailyCap": 1, + "advertiserId": "a437c7f3-9a48-4fe8-b37b-99321bea93fe", + "priority": 1, + "ptr": 1.0 + } + ], + "catalogId": "29e5c8bc0ba319069980bb390d8e8f9b58c05a20" +} diff --git a/vendor/bat-native-ads/data/test/catalog_with_promoted_content_ad.json b/vendor/bat-native-ads/data/test/catalog_with_promoted_content_ad.json new file mode 100644 index 000000000000..a6e962bc1afb --- /dev/null +++ b/vendor/bat-native-ads/data/test/catalog_with_promoted_content_ad.json @@ -0,0 +1,71 @@ +{ + "version": 9, + "ping": 7200000, + "campaigns": [ + { + "creativeSets": [ + { + "creatives": [ + { + "creativeInstanceId": "75d4cbac-b661-4126-9ccb-7bbb6ee56ef3", + "type": { + "code": "promoted_content_all_v1", + "name": "promoted_content", + "platform": "all", + "version": 1 + }, + "payload": { + "feed": "https://brave.com", + "title": "Test Title", + "domain": "Test Domain", + "category": "Test Category", + "ogImages": false, + "contentType": "Test Content Type", + "description": "Test Description" + } + } + ], + "segments": [ + { + "code": "Svp7l-zGN", + "name": "untargeted" + } + ], + "oses": [ + ], + "conversions": [ + { + "observationWindow": 30, + "urlPattern": "https://www.brave.com/*", + "type": "postview" + } + ], + "channels": [ + ], + "creativeSetId": "340c927f-696e-4060-9933-3eafc56c3f31", + "perDay": 1, + "perWeek": 1, + "perMonth": 1, + "totalMax": 1, + "value": "1.0" + } + ], + "dayParts": [ + ], + "geoTargets": [ + { + "code": "US", + "name": "United States" + } + ], + "campaignId": "27a624a1-9c80-494a-bf1b-af327b563f85", + "startAt": "", + "endAt": "", + "dailyCap": 1, + "advertiserId": "a437c7f3-9a48-4fe8-b37b-99321bea93fe", + "priority": 1, + "ptr": 1.0 + } + ], + "catalogId": "29e5c8bc0ba319069980bb390d8e8f9b58c05a20" +} diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/account_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/account/account_unittest.cc index 2f1d00800fb3..5bb75ae42655 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/account_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/account_unittest.cc @@ -21,7 +21,7 @@ #include "bat/ads/internal/base/unittest/unittest_mock_util.h" #include "bat/ads/internal/base/unittest/unittest_time_util.h" #include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_info_aliases.h" -#include "bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" #include "bat/ads/internal/privacy/tokens/token_generator_mock.h" #include "bat/ads/internal/privacy/tokens/unblinded_tokens/unblinded_tokens_unittest_util.h" #include "bat/ads/pref_names.h" @@ -68,12 +68,6 @@ class BatAdsAccountTest : public AccountObserver, public UnitTestBase { UnitTestBase::TearDown(); } - void Save(const CreativeNotificationAdList& creative_ads) { - database::table::CreativeNotificationAds database_table; - database_table.Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); - } - void OnWalletDidUpdate(const WalletInfo& wallet) override { wallet_did_update_ = true; } @@ -488,7 +482,7 @@ TEST_F(BatAdsAccountTest, DepositForCash) { info.ptr = 1.0; creative_ads.push_back(info); - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act account_->Deposit(info.creative_instance_id, AdType::kNotificationAd, @@ -598,7 +592,7 @@ TEST_F(BatAdsAccountTest, DoNotDepositCashIfCreativeInstanceIdDoesNotExist) { info.ptr = 1.0; creative_ads.push_back(info); - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act account_->Deposit("eaa6224a-876d-4ef8-a384-9ac34f238631", diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/deposits/deposits_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/account/deposits/deposits_database_table.cc index 26c4894c79c5..46cf33f4494d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/deposits/deposits_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/deposits/deposits_database_table.cc @@ -5,7 +5,6 @@ #include "bat/ads/internal/account/deposits/deposits_database_table.h" -#include #include #include "base/check.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/transactions/transactions_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/account/transactions/transactions_unittest_util.cc index a6f5462ec0d4..d892b5312bd5 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/transactions/transactions_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/transactions/transactions_unittest_util.cc @@ -9,6 +9,7 @@ #include "base/time/time.h" #include "bat/ads/ad_type.h" #include "bat/ads/confirmation_type.h" +#include "bat/ads/internal/account/transactions/transactions.h" #include "bat/ads/internal/account/transactions/transactions_database_table.h" #include "bat/ads/internal/base/unittest/unittest_time_util.h" #include "bat/ads/transaction_info.h" @@ -44,4 +45,18 @@ TransactionInfo BuildTransaction(const double value, return BuildTransaction(value, confirmation_type, base::Time()); } +int GetTransactionCount() { + int count = 0; + + transactions::GetForDateRange( + DistantPast(), DistantFuture(), + [&count](const bool success, + const TransactionList& transactions) mutable { + ASSERT_TRUE(success); + count = transactions.size(); + }); + + return count; +} + } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/transactions/transactions_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/account/transactions/transactions_unittest_util.h index b73c19ff22c4..cb2ded0b4b99 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/transactions/transactions_unittest_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/transactions/transactions_unittest_util.h @@ -26,6 +26,8 @@ TransactionInfo BuildTransaction(const double value, TransactionInfo BuildTransaction(const double value, const ConfirmationType& confirmation_type); +int GetTransactionCount(); + } // namespace ads #endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ACCOUNT_TRANSACTIONS_TRANSACTIONS_UNITTEST_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data.cc b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data.cc index 7c542915d795..6444aed08e53 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data.cc @@ -6,6 +6,7 @@ #include "bat/ads/internal/account/user_data/conversion_user_data.h" #include "base/check_op.h" +#include "base/values.h" #include "bat/ads/confirmation_type.h" #include "bat/ads/internal/account/user_data/conversion_user_data_builder.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data.h b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data.h index b70b5adea94b..2a1ff08eac93 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data.h @@ -9,7 +9,9 @@ #include #include -#include "base/values.h" +namespace base { +class Value; +} // namespace base namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data_builder.cc b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data_builder.cc index 853f35726774..7be0a9c4cfc9 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data_builder.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data_builder.cc @@ -8,6 +8,7 @@ #include #include "base/check.h" +#include "base/values.h" #include "bat/ads/internal/account/user_data/conversion_user_data_util.h" #include "bat/ads/internal/conversions/conversion_queue_database_table.h" #include "bat/ads/internal/conversions/conversion_queue_item_info.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data_builder.h b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data_builder.h index 37a25d1f1f9e..dbeff995e3b9 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data_builder.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/account/user_data/conversion_user_data_builder.h @@ -9,7 +9,9 @@ #include #include -#include "base/values.h" +namespace base { +class Value; +} // namespace base namespace ads { namespace user_data { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_unittest_util.cc index c14c4f438906..e06052a58bed 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_unittest_util.cc @@ -5,7 +5,7 @@ #include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" -#include +#include #include "base/check_op.h" #include "base/guid.h" @@ -128,14 +128,10 @@ void FireAdEvents(const AdEventInfo& ad_event, const int count) { } int GetAdEventCount(const AdType& ad_type, - const ConfirmationType& confirmation_type, - const AdEventList& ad_events) { - return std::count_if( - ad_events.cbegin(), ad_events.cend(), - [&ad_type, &confirmation_type](const AdEventInfo& ad_event) { - return ad_event.type == ad_type && - ad_event.confirmation_type == confirmation_type; - }); + const ConfirmationType& confirmation_type) { + const std::vector ad_events = + GetAdEvents(ad_type, confirmation_type); + return ad_events.size(); } } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_unittest_util.h index ded090c076a9..e5ee8bcb2a1d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_unittest_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_unittest_util.h @@ -48,8 +48,7 @@ void FireAdEvent(const AdEventInfo& ad_event); void FireAdEvents(const AdEventInfo& ad_event, const int count); int GetAdEventCount(const AdType& ad_type, - const ConfirmationType& confirmation_type, - const AdEventList& ad_events); + const ConfirmationType& confirmation_type); } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_util.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_util.h index 467aba44e63a..50b64f067dd3 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_event_util.h @@ -25,7 +25,6 @@ bool HasFiredAdEvent(const AdInfo& ad, absl::optional GetLastSeenAdTime(const AdEventList& ad_events, const CreativeAdInfo& creative_ad); - absl::optional GetLastSeenAdvertiserTime( const AdEventList& ad_events, const CreativeAdInfo& creative_ad); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_events_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_events_database_table.cc index 87abb87e492e..5ef2ac989939 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_events_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_events_database_table.cc @@ -5,7 +5,6 @@ #include "bat/ads/internal/ads/ad_events/ad_events_database_table.h" -#include #include #include "base/check.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_events_database_table_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_events_database_table_unittest_util.cc index 79d3a63b4777..f570a15d6cec 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_events_database_table_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/ad_events_database_table_unittest_util.cc @@ -5,12 +5,12 @@ #include "bat/ads/internal/ads/ad_events/ad_events_database_table_unittest_util.h" -#include #include +#include "base/check.h" +#include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/ads_client_helper.h" #include "bat/ads/internal/base/database/database_table_util.h" -#include "bat/ads/internal/base/database/database_transaction_util.h" #include "bat/ads/public/interfaces/ads.mojom.h" namespace ads { @@ -25,7 +25,19 @@ void Reset(ResultCallback callback) { AdsClientHelper::GetInstance()->RunDBTransaction( std::move(transaction), - std::bind(&OnResultCallback, std::placeholders::_1, callback)); + [callback](mojom::DBCommandResponsePtr command_response) { + if (!command_response || + command_response->status != + mojom::DBCommandResponse::Status::RESPONSE_OK) { + DCHECK(false); + callback(/* success */ false); + return; + } + + RebuildAdEventsFromDatabase(); + + callback(/* success */ true); + }); } } // namespace ad_events diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_clicked.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_clicked.cc index f68a7fc0396d..2484366b42f2 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_clicked.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_clicked.cc @@ -6,11 +6,9 @@ #include "bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_clicked.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/inline_content_ad_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/history/history_manager.h" namespace ads { namespace inline_content_ads { @@ -32,8 +30,6 @@ void AdEventClicked::FireEvent(const InlineContentAdInfo& ad) { BLOG(6, "Successfully logged inline content ad clicked event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); } } // namespace inline_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_handler_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_handler_unittest.cc index b4763d21ebb1..671899e70be2 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_handler_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_handler_unittest.cc @@ -11,7 +11,6 @@ #include "bat/ads/confirmation_type.h" #include "bat/ads/inline_content_ad_info.h" #include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" -#include "bat/ads/internal/ads/ad_events/ad_events_database_table.h" #include "bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_handler_observer.h" #include "bat/ads/internal/ads/serving/serving_features.h" #include "bat/ads/internal/base/unittest/unittest_base.h" @@ -88,19 +87,6 @@ class BatAdsInlineContentAdEventHandlerTest : public EventHandlerObserver, return creative_ad; } - void ExpectAdEventCountEquals(const ConfirmationType& confirmation_type, - const int expected_count) { - database::table::AdEvents database_table; - database_table.GetAll( - [=](const bool success, const AdEventList& ad_events) { - ASSERT_TRUE(success); - - const int count = GetAdEventCount(AdType::kInlineContentAd, - confirmation_type, ad_events); - EXPECT_EQ(expected_count, count); - }); - } - std::unique_ptr event_handler_; InlineContentAdInfo ad_; @@ -127,7 +113,8 @@ TEST_F(BatAdsInlineContentAdEventHandlerTest, FireViewedEvent) { BuildInlineContentAd(creative_ad, kPlacementId); EXPECT_EQ(expected_ad, ad_); - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kViewed)); } TEST_F(BatAdsInlineContentAdEventHandlerTest, @@ -143,7 +130,8 @@ TEST_F(BatAdsInlineContentAdEventHandlerTest, mojom::InlineContentAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kViewed)); } TEST_F(BatAdsInlineContentAdEventHandlerTest, FireClickedEvent) { @@ -162,8 +150,8 @@ TEST_F(BatAdsInlineContentAdEventHandlerTest, FireClickedEvent) { const InlineContentAdInfo& expected_ad = BuildInlineContentAd(creative_ad, kPlacementId); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kClicked)); } TEST_F(BatAdsInlineContentAdEventHandlerTest, @@ -179,7 +167,8 @@ TEST_F(BatAdsInlineContentAdEventHandlerTest, mojom::InlineContentAdEventType::kClicked); // Assert - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kClicked)); } TEST_F(BatAdsInlineContentAdEventHandlerTest, DoNotFireEventWithInvalidUuid) { @@ -194,8 +183,8 @@ TEST_F(BatAdsInlineContentAdEventHandlerTest, DoNotFireEventWithInvalidUuid) { EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ( + 0, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kViewed)); } TEST_F(BatAdsInlineContentAdEventHandlerTest, @@ -211,8 +200,8 @@ TEST_F(BatAdsInlineContentAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ( + 0, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kViewed)); } TEST_F(BatAdsInlineContentAdEventHandlerTest, @@ -228,8 +217,8 @@ TEST_F(BatAdsInlineContentAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ( + 0, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kViewed)); } } // namespace inline_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_served.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_served.cc index 3ada3bcc9046..fe2284db5bff 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_served.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_served.cc @@ -9,7 +9,6 @@ #include "bat/ads/inline_content_ad_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/deprecated/client/client_state_manager.h" namespace ads { namespace inline_content_ads { @@ -31,8 +30,6 @@ void AdEventServed::FireEvent(const InlineContentAdInfo& ad) { BLOG(1, "Successfully logged inline content ad served event"); }); - - ClientStateManager::GetInstance()->UpdateSeenAd(ad); } } // namespace inline_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_viewed.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_viewed.cc index b79846006f3f..e7cde28de86e 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_viewed.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_viewed.cc @@ -6,7 +6,6 @@ #include "bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_viewed.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/inline_content_ad_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" @@ -32,8 +31,6 @@ void AdEventViewed::FireEvent(const InlineContentAdInfo& ad) { BLOG(6, "Successfully logged inline content ad viewed event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); } } // namespace inline_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_clicked.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_clicked.cc index 878ddc43a7cc..1d72ef6ca2c9 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_clicked.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_clicked.cc @@ -6,10 +6,8 @@ #include "bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_clicked.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/new_tab_page_ad_info.h" namespace ads { @@ -32,8 +30,6 @@ void AdEventClicked::FireEvent(const NewTabPageAdInfo& ad) { BLOG(6, "Successfully logged new tab page ad clicked event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); } } // namespace new_tab_page_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_if_ads_disabled_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_if_ads_disabled_unittest.cc index b02111b33e79..0209dd010cf6 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_if_ads_disabled_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_if_ads_disabled_unittest.cc @@ -11,7 +11,6 @@ #include "bat/ads/ad_type.h" #include "bat/ads/confirmation_type.h" #include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" -#include "bat/ads/internal/ads/ad_events/ad_events_database_table.h" #include "bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_observer.h" #include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" #include "bat/ads/internal/ads/serving/serving_features.h" @@ -95,19 +94,6 @@ class BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest return creative_ad; } - void ExpectAdEventCountEquals(const ConfirmationType& confirmation_type, - const int expected_count) { - database::table::AdEvents database_table; - database_table.GetAll([=](const bool success, - const AdEventList& ad_events) { - ASSERT_TRUE(success); - - const int count = - GetAdEventCount(AdType::kNewTabPageAd, confirmation_type, ad_events); - EXPECT_EQ(expected_count, count); - }); - } - std::unique_ptr event_handler_; NewTabPageAdInfo ad_; @@ -135,8 +121,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, FireViewedEvent) { const NewTabPageAdInfo& expected_ad = BuildNewTabPageAd(creative_ad, kPlacementId); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, FireClickedEvent) { @@ -157,8 +143,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, FireClickedEvent) { const NewTabPageAdInfo& expected_ad = BuildNewTabPageAd(creative_ad, kPlacementId); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kClicked)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -176,7 +162,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, mojom::NewTabPageAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -192,8 +179,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -209,8 +196,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -227,8 +214,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -245,8 +232,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -264,7 +251,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, const int ads_per_hour = features::GetMaximumNewTabPageAdsPerHour(); FireAdEvents(ad_event, ads_per_hour - 1); - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_hour - 1); + EXPECT_EQ(ads_per_hour - 1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); AdvanceClockBy(features::GetNewTabPageAdsMinimumWaitTime()); @@ -273,7 +261,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, mojom::NewTabPageAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_hour); + EXPECT_EQ(ads_per_hour, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -297,7 +286,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, mojom::NewTabPageAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_hour); + EXPECT_EQ(ads_per_hour, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -323,7 +313,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, mojom::NewTabPageAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_day); + EXPECT_EQ(ads_per_day, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, @@ -349,7 +340,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerIfAdsDisabledTest, mojom::NewTabPageAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_day); + EXPECT_EQ(ads_per_day, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } } // namespace new_tab_page_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_unittest.cc index 6aede36ec681..6878e25b3466 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_unittest.cc @@ -11,7 +11,6 @@ #include "bat/ads/ad_type.h" #include "bat/ads/confirmation_type.h" #include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" -#include "bat/ads/internal/ads/ad_events/ad_events_database_table.h" #include "bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_observer.h" #include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" #include "bat/ads/internal/ads/serving/serving_features.h" @@ -90,19 +89,6 @@ class BatAdsNewTabPageAdEventHandlerTest : public EventHandlerObserver, return creative_ad; } - void ExpectAdEventCountEquals(const ConfirmationType& confirmation_type, - const int expected_count) { - database::table::AdEvents database_table; - database_table.GetAll([=](const bool success, - const AdEventList& ad_events) { - ASSERT_TRUE(success); - - const int count = - GetAdEventCount(AdType::kNewTabPageAd, confirmation_type, ad_events); - EXPECT_EQ(expected_count, count); - }); - } - std::unique_ptr event_handler_; NewTabPageAdInfo ad_; @@ -128,8 +114,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerTest, FireViewedEvent) { const NewTabPageAdInfo& expected_ad = BuildNewTabPageAd(creative_ad, kPlacementId); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerTest, DoNotFireViewedEventIfAlreadyFired) { @@ -146,7 +132,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerTest, DoNotFireViewedEventIfAlreadyFired) { mojom::NewTabPageAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerTest, FireClickedEvent) { @@ -165,8 +152,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerTest, FireClickedEvent) { const NewTabPageAdInfo& expected_ad = BuildNewTabPageAd(creative_ad, kPlacementId); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kClicked)); } TEST_F(BatAdsNewTabPageAdEventHandlerTest, @@ -182,7 +169,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerTest, mojom::NewTabPageAdEventType::kClicked); // Assert - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kClicked)); } TEST_F(BatAdsNewTabPageAdEventHandlerTest, DoNotFireEventWithInvalidUuid) { @@ -197,8 +185,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerTest, DoNotFireEventWithInvalidUuid) { EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerTest, @@ -214,8 +202,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerTest, @@ -231,8 +219,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNewTabPageAdEventHandlerTest, @@ -258,7 +246,8 @@ TEST_F(BatAdsNewTabPageAdEventHandlerTest, mojom::NewTabPageAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_hour); + EXPECT_EQ(ads_per_hour, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); } } // namespace new_tab_page_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_served.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_served.cc index 09de63031314..8533193dd4b7 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_served.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_served.cc @@ -8,7 +8,6 @@ #include "bat/ads/confirmation_type.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/deprecated/client/client_state_manager.h" #include "bat/ads/new_tab_page_ad_info.h" namespace ads { @@ -31,8 +30,6 @@ void AdEventServed::FireEvent(const NewTabPageAdInfo& ad) { BLOG(6, "Successfully logged new tab page ad served event"); }); - - ClientStateManager::GetInstance()->UpdateSeenAd(ad); } } // namespace new_tab_page_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_viewed.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_viewed.cc index 41be1c7a839b..96adefa223cc 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_viewed.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_viewed.cc @@ -6,10 +6,8 @@ #include "bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_viewed.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/new_tab_page_ad_info.h" namespace ads { @@ -32,8 +30,6 @@ void AdEventViewed::FireEvent(const NewTabPageAdInfo& ad) { BLOG(6, "Successfully logged new tab page ad viewed event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); } } // namespace new_tab_page_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_clicked.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_clicked.cc index 295b860ec4a4..4ed6a541aad2 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_clicked.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_clicked.cc @@ -6,12 +6,8 @@ #include "bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_clicked.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" -#include "bat/ads/internal/ads_client_helper.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/creatives/notification_ads/notification_ad_manager.h" -#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/notification_ad_info.h" namespace ads { @@ -25,11 +21,6 @@ void AdEventClicked::FireEvent(const NotificationAdInfo& ad) { BLOG(3, "Clicked notification ad with placement id " << ad.placement_id << " and creative instance id " << ad.creative_instance_id); - - NotificationAdManager::GetInstance()->Remove(ad.placement_id); - - AdsClientHelper::GetInstance()->CloseNotification(ad.placement_id); - LogAdEvent(ad, ConfirmationType::kClicked, [](const bool success) { if (!success) { BLOG(1, "Failed to log notification ad clicked event"); @@ -38,8 +29,6 @@ void AdEventClicked::FireEvent(const NotificationAdInfo& ad) { BLOG(1, "Successfully logged notification ad clicked event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); } } // namespace notification_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_dismissed.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_dismissed.cc index 207d7e561a36..011dd8164559 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_dismissed.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_dismissed.cc @@ -6,11 +6,8 @@ #include "bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_dismissed.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/creatives/notification_ads/notification_ad_manager.h" -#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/notification_ad_info.h" namespace ads { @@ -25,8 +22,6 @@ void AdEventDismissed::FireEvent(const NotificationAdInfo& ad) { << ad.placement_id << " and creative instance id " << ad.creative_instance_id); - NotificationAdManager::GetInstance()->Remove(ad.placement_id); - LogAdEvent(ad, ConfirmationType::kDismissed, [](const bool success) { if (!success) { BLOG(1, "Failed to log notification ad dismissed event"); @@ -35,8 +30,6 @@ void AdEventDismissed::FireEvent(const NotificationAdInfo& ad) { BLOG(6, "Successfully logged notification ad dismissed event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kDismissed); } } // namespace notification_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_handler_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_handler_unittest.cc index 3cb27a24d280..b5418f21b9c3 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_handler_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_handler_unittest.cc @@ -10,14 +10,12 @@ #include "bat/ads/ad_type.h" #include "bat/ads/confirmation_type.h" #include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" -#include "bat/ads/internal/ads/ad_events/ad_events_database_table.h" #include "bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_handler_observer.h" #include "bat/ads/internal/ads/serving/serving_features.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_info.h" #include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" #include "bat/ads/internal/creatives/notification_ads/notification_ad_builder.h" -#include "bat/ads/internal/creatives/notification_ads/notification_ad_manager.h" #include "bat/ads/notification_ad_info.h" #include "bat/ads/public/interfaces/ads.mojom.h" @@ -84,25 +82,11 @@ class BatAdsNotificationAdEventHandlerTest : public EventHandlerObserver, NotificationAdInfo BuildAndSaveNotificationAd() { const CreativeNotificationAdInfo& creative_ad = BuildCreativeNotificationAd(); - const NotificationAdInfo& ad = BuildNotificationAd(creative_ad); NotificationAdManager::GetInstance()->PushBack(ad); return ad; } - void ExpectAdEventCountEquals(const ConfirmationType& confirmation_type, - const int expected_count) { - database::table::AdEvents database_table; - database_table.GetAll( - [=](const bool success, const AdEventList& ad_events) { - ASSERT_TRUE(success); - - const int count = GetAdEventCount(AdType::kNotificationAd, - confirmation_type, ad_events); - EXPECT_EQ(expected_count, count); - }); - } - std::unique_ptr event_handler_; NotificationAdInfo ad_; @@ -130,9 +114,8 @@ TEST_F(BatAdsNotificationAdEventHandlerTest, FireServedEvent) { EXPECT_FALSE(did_time_out_ad_); EXPECT_FALSE(did_fail_to_fire_event_); EXPECT_EQ(ad, ad_); - EXPECT_TRUE(NotificationAdManager::GetInstance()->Exists(ad.placement_id)); - - ExpectAdEventCountEquals(ConfirmationType::kServed, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kNotificationAd, ConfirmationType::kServed)); } TEST_F(BatAdsNotificationAdEventHandlerTest, FireViewedEvent) { @@ -151,9 +134,8 @@ TEST_F(BatAdsNotificationAdEventHandlerTest, FireViewedEvent) { EXPECT_FALSE(did_time_out_ad_); EXPECT_FALSE(did_fail_to_fire_event_); EXPECT_EQ(ad, ad_); - EXPECT_TRUE(NotificationAdManager::GetInstance()->Exists(ad.placement_id)); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kNotificationAd, ConfirmationType::kViewed)); } TEST_F(BatAdsNotificationAdEventHandlerTest, FireClickedEvent) { @@ -172,9 +154,8 @@ TEST_F(BatAdsNotificationAdEventHandlerTest, FireClickedEvent) { EXPECT_FALSE(did_time_out_ad_); EXPECT_FALSE(did_fail_to_fire_event_); EXPECT_EQ(ad, ad_); - EXPECT_FALSE(NotificationAdManager::GetInstance()->Exists(ad.placement_id)); - - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kNotificationAd, ConfirmationType::kClicked)); } TEST_F(BatAdsNotificationAdEventHandlerTest, FireDismissedEvent) { @@ -193,9 +174,8 @@ TEST_F(BatAdsNotificationAdEventHandlerTest, FireDismissedEvent) { EXPECT_FALSE(did_time_out_ad_); EXPECT_FALSE(did_fail_to_fire_event_); EXPECT_EQ(ad, ad_); - EXPECT_FALSE(NotificationAdManager::GetInstance()->Exists(ad.placement_id)); - - ExpectAdEventCountEquals(ConfirmationType::kDismissed, 1); + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kDismissed)); } TEST_F(BatAdsNotificationAdEventHandlerTest, FireTimedOutEvent) { @@ -214,7 +194,6 @@ TEST_F(BatAdsNotificationAdEventHandlerTest, FireTimedOutEvent) { EXPECT_TRUE(did_time_out_ad_); EXPECT_FALSE(did_fail_to_fire_event_); EXPECT_EQ(ad, ad_); - EXPECT_FALSE(NotificationAdManager::GetInstance()->Exists(ad.placement_id)); } TEST_F(BatAdsNotificationAdEventHandlerTest, DoNotFireEventIfUuidWasNotFound) { @@ -231,8 +210,8 @@ TEST_F(BatAdsNotificationAdEventHandlerTest, DoNotFireEventIfUuidWasNotFound) { EXPECT_FALSE(did_dismiss_ad_); EXPECT_FALSE(did_time_out_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ( + 0, GetAdEventCount(AdType::kNotificationAd, ConfirmationType::kViewed)); } } // namespace notification_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_served.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_served.cc index ae314f42ff05..6ff2ede2d50b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_served.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_served.cc @@ -8,7 +8,6 @@ #include "bat/ads/confirmation_type.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/deprecated/client/client_state_manager.h" #include "bat/ads/notification_ad_info.h" namespace ads { @@ -31,8 +30,6 @@ void AdEventServed::FireEvent(const NotificationAdInfo& ad) { BLOG(1, "Successfully logged notification ad served event"); }); - - ClientStateManager::GetInstance()->UpdateSeenAd(ad); } } // namespace notification_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_timed_out.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_timed_out.cc index b2e8e3f09bf3..acc0cc2a164d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_timed_out.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_timed_out.cc @@ -6,7 +6,6 @@ #include "bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_timed_out.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/creatives/notification_ads/notification_ad_manager.h" #include "bat/ads/notification_ad_info.h" namespace ads { @@ -20,8 +19,6 @@ void AdEventTimedOut::FireEvent(const NotificationAdInfo& ad) { BLOG(3, "Timed out notification ad with placement id " << ad.placement_id << " and creative instance id " << ad.creative_instance_id); - - NotificationAdManager::GetInstance()->Remove(ad.placement_id); } } // namespace notification_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_viewed.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_viewed.cc index 6a04b30241b7..a4e712c11bf1 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_viewed.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_viewed.cc @@ -6,10 +6,8 @@ #include "bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_viewed.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/notification_ad_info.h" namespace ads { @@ -32,8 +30,6 @@ void AdEventViewed::FireEvent(const NotificationAdInfo& ad) { BLOG(6, "Successfully logged notification ad viewed event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); } } // namespace notification_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_clicked.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_clicked.cc index 4897d00a9663..1e53e8202fba 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_clicked.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_clicked.cc @@ -6,10 +6,8 @@ #include "bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_clicked.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/promoted_content_ad_info.h" namespace ads { @@ -32,8 +30,6 @@ void AdEventClicked::FireEvent(const PromotedContentAdInfo& ad) { BLOG(6, "Successfully logged promoted content ad clicked event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); } } // namespace promoted_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc index 1a824cc1cdf0..bf387d1b3510 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc @@ -11,7 +11,6 @@ #include "bat/ads/ad_type.h" #include "bat/ads/confirmation_type.h" #include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" -#include "bat/ads/internal/ads/ad_events/ad_events_database_table.h" #include "bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_handler_observer.h" #include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" #include "bat/ads/internal/ads/serving/serving_features.h" @@ -90,19 +89,6 @@ class BatAdsPromotedContentAdEventHandlerTest : public EventHandlerObserver, return creative_ad; } - void ExpectAdEventCountEquals(const ConfirmationType& confirmation_type, - const int expected_count) { - database::table::AdEvents database_table; - database_table.GetAll( - [=](const bool success, const AdEventList& ad_events) { - ASSERT_TRUE(success); - - const int count = GetAdEventCount(AdType::kPromotedContentAd, - confirmation_type, ad_events); - EXPECT_EQ(expected_count, count); - }); - } - std::unique_ptr event_handler_; PromotedContentAdInfo ad_; @@ -130,8 +116,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, FireViewedEvent) { const PromotedContentAdInfo& expected_ad = BuildPromotedContentAd(creative_ad, kPlacementId); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ(1, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -149,7 +135,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, mojom::PromotedContentAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ(1, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, FireClickedEvent) { @@ -170,8 +157,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, FireClickedEvent) { const PromotedContentAdInfo& expected_ad = BuildPromotedContentAd(creative_ad, kPlacementId); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ(1, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kClicked)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -189,7 +176,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, mojom::PromotedContentAdEventType::kClicked); // Assert - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ(1, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kClicked)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, DoNotFireEventWithInvalidUuid) { @@ -204,8 +192,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, DoNotFireEventWithInvalidUuid) { EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -221,8 +209,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -239,8 +227,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -257,8 +245,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ(0, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -283,7 +271,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, mojom::PromotedContentAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_hour); + EXPECT_EQ(ads_per_hour, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -307,7 +296,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, mojom::PromotedContentAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_hour); + EXPECT_EQ(ads_per_hour, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -334,7 +324,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, mojom::PromotedContentAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_day); + EXPECT_EQ(ads_per_day, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsPromotedContentAdEventHandlerTest, @@ -361,7 +352,8 @@ TEST_F(BatAdsPromotedContentAdEventHandlerTest, mojom::PromotedContentAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_day); + EXPECT_EQ(ads_per_day, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); } } // namespace promoted_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_viewed.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_viewed.cc index e3dd6d1b9a1b..eca018a1a557 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_viewed.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_viewed.cc @@ -6,10 +6,8 @@ #include "bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_viewed.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" -#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/promoted_content_ad_info.h" namespace ads { @@ -32,8 +30,6 @@ void AdEventViewed::FireEvent(const PromotedContentAdInfo& ad) { BLOG(6, "Successfully logged promoted content ad viewed event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); } } // namespace promoted_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_clicked.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_clicked.cc index 065a39fbd66f..74c9f0450b38 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_clicked.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_clicked.cc @@ -6,11 +6,9 @@ #include "bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_clicked.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" #include "bat/ads/internal/creatives/search_result_ads/search_result_ad_info.h" -#include "bat/ads/internal/history/history_manager.h" namespace ads { namespace search_result_ads { @@ -32,8 +30,6 @@ void AdEventClicked::FireEvent(const SearchResultAdInfo& ad) { BLOG(6, "Successfully logged search result ad clicked event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); } } // namespace search_result_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler.cc index 0956b083ec5d..8d36d053c40a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler.cc @@ -168,7 +168,7 @@ void EventHandler::FireViewedEvent( } // We must fire an ad served event due to search result ads not - // being delivered by the library + // being delivered by the library. FireEvent(ad, mojom::SearchResultAdEventType::kServed, callback); FireEvent(ad, event_type, callback); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler_unittest.cc index e971912f4cf0..e717d79dc5d8 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler_unittest.cc @@ -11,7 +11,6 @@ #include "bat/ads/internal/account/deposits/deposit_info.h" #include "bat/ads/internal/account/deposits/deposits_database_table.h" #include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" -#include "bat/ads/internal/ads/ad_events/ad_events_database_table.h" #include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" #include "bat/ads/internal/ads/serving/serving_features.h" #include "bat/ads/internal/base/unittest/unittest_base.h" @@ -69,18 +68,6 @@ mojom::SearchResultAdPtr BuildAdWithConversion( return ad_mojom; } -void ExpectAdEventCountEquals(const ConfirmationType& confirmation_type, - const int expected_count) { - database::table::AdEvents database_table; - database_table.GetAll([=](const bool success, const AdEventList& ad_events) { - ASSERT_TRUE(success); - - const int count = - GetAdEventCount(AdType::kSearchResultAd, confirmation_type, ad_events); - EXPECT_EQ(expected_count, count); - }); -} - void ExpectDepositExistsForCreativeInstanceId( const std::string& creative_instance_id) { database::table::Deposits database_table; @@ -181,8 +168,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireViewedEvent) { EXPECT_FALSE(did_fail_to_fire_event_); const SearchResultAdInfo expected_ad = BuildSearchResultAd(ad_mojom); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kSearchResultAd, ConfirmationType::kViewed)); ExpectDepositExistsForCreativeInstanceId(kCreativeInstanceId); ExpectConversionCountEquals(0); } @@ -204,8 +191,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireViewedEventWithConversion) { EXPECT_FALSE(did_fail_to_fire_event_); const SearchResultAdInfo expected_ad = BuildSearchResultAd(ad_mojom); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kSearchResultAd, ConfirmationType::kViewed)); ExpectDepositExistsForCreativeInstanceId(kCreativeInstanceId); ExpectConversionCountEquals(1); } @@ -224,7 +211,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireEvent(ad_mojom, mojom::SearchResultAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kSearchResultAd, ConfirmationType::kViewed)); ExpectDepositExistsForCreativeInstanceId(kCreativeInstanceId); ExpectConversionCountEquals(0); } @@ -246,8 +234,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireClickedEvent) { EXPECT_FALSE(did_fail_to_fire_event_); const SearchResultAdInfo expected_ad = BuildSearchResultAd(ad_mojom); EXPECT_EQ(expected_ad, ad_); - - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kSearchResultAd, ConfirmationType::kClicked)); } TEST_F(BatAdsSearchResultAdEventHandlerTest, @@ -264,7 +252,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireEvent(ad_mojom, mojom::SearchResultAdEventType::kClicked); // Assert - ExpectAdEventCountEquals(ConfirmationType::kClicked, 1); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kSearchResultAd, ConfirmationType::kClicked)); } TEST_F(BatAdsSearchResultAdEventHandlerTest, @@ -281,8 +270,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ( + 0, GetAdEventCount(AdType::kSearchResultAd, ConfirmationType::kViewed)); } TEST_F(BatAdsSearchResultAdEventHandlerTest, @@ -299,8 +288,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ( + 0, GetAdEventCount(AdType::kSearchResultAd, ConfirmationType::kViewed)); } TEST_F(BatAdsSearchResultAdEventHandlerTest, DoNotFireEventWhenNotPermitted) { @@ -316,8 +305,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, DoNotFireEventWhenNotPermitted) { EXPECT_FALSE(did_view_ad_); EXPECT_FALSE(did_click_ad_); EXPECT_TRUE(did_fail_to_fire_event_); - - ExpectAdEventCountEquals(ConfirmationType::kViewed, 0); + EXPECT_EQ( + 0, GetAdEventCount(AdType::kSearchResultAd, ConfirmationType::kViewed)); } TEST_F(BatAdsSearchResultAdEventHandlerTest, @@ -339,7 +328,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireEvent(ad_mojom, mojom::SearchResultAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_hour); + EXPECT_EQ(ads_per_hour, GetAdEventCount(AdType::kSearchResultAd, + ConfirmationType::kViewed)); ExpectDepositExistsForCreativeInstanceId(kCreativeInstanceId); ExpectConversionCountEquals(0); } @@ -363,7 +353,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireEvent(ad_mojom, mojom::SearchResultAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_hour); + EXPECT_EQ(ads_per_hour, GetAdEventCount(AdType::kSearchResultAd, + ConfirmationType::kViewed)); } TEST_F(BatAdsSearchResultAdEventHandlerTest, @@ -388,7 +379,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireEvent(ad_mojom, mojom::SearchResultAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_day); + EXPECT_EQ(ads_per_day, GetAdEventCount(AdType::kSearchResultAd, + ConfirmationType::kViewed)); ExpectDepositExistsForCreativeInstanceId(kCreativeInstanceId); ExpectConversionCountEquals(0); } @@ -415,7 +407,8 @@ TEST_F(BatAdsSearchResultAdEventHandlerTest, FireEvent(ad_mojom, mojom::SearchResultAdEventType::kViewed); // Assert - ExpectAdEventCountEquals(ConfirmationType::kViewed, ads_per_day); + EXPECT_EQ(ads_per_day, GetAdEventCount(AdType::kSearchResultAd, + ConfirmationType::kViewed)); } } // namespace search_result_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_viewed.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_viewed.cc index f4b34699b929..52e654cce43e 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_viewed.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_viewed.cc @@ -6,11 +6,9 @@ #include "bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_viewed.h" #include "bat/ads/confirmation_type.h" -#include "bat/ads/history_item_info.h" #include "bat/ads/internal/ads/ad_events/ad_events.h" #include "bat/ads/internal/base/logging_util.h" #include "bat/ads/internal/creatives/search_result_ads/search_result_ad_info.h" -#include "bat/ads/internal/history/history_manager.h" namespace ads { namespace search_result_ads { @@ -32,8 +30,6 @@ void AdEventViewed::FireEvent(const SearchResultAdInfo& ad) { BLOG(6, "Successfully logged search result ad viewed event"); }); - - HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); } } // namespace search_result_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad.cc index d27dee137e51..e6101f917890 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad.cc @@ -6,11 +6,16 @@ #include "bat/ads/internal/ads/inline_content_ad.h" #include "bat/ads/confirmation_type.h" +#include "bat/ads/history_item_info.h" #include "bat/ads/inline_content_ad_info.h" #include "bat/ads/internal/account/account.h" #include "bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_handler.h" #include "bat/ads/internal/ads/serving/inline_content_ad_serving.h" +#include "bat/ads/internal/deprecated/client/client_state_manager.h" +#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" +#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/internal/privacy/p2a/impressions/p2a_impression.h" +#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" #include "bat/ads/internal/transfer/transfer.h" namespace ads { @@ -25,11 +30,10 @@ InlineContentAd::InlineContentAd( DCHECK(transfer_); event_handler_ = std::make_unique(); + event_handler_->AddObserver(this); serving_ = std::make_unique( subdivision_targeting, anti_targeting_resource); - - event_handler_->AddObserver(this); serving_->AddObserver(this); } @@ -57,11 +61,17 @@ void InlineContentAd::TriggerEvent( /////////////////////////////////////////////////////////////////////////////// void InlineContentAd::OnDidServeInlineContentAd(const InlineContentAdInfo& ad) { - event_handler_->FireEvent(ad.placement_id, ad.creative_instance_id, - mojom::InlineContentAdEventType::kServed); + TriggerEvent(ad.placement_id, ad.creative_instance_id, + mojom::InlineContentAdEventType::kServed); +} + +void InlineContentAd::OnInlineContentAdServed(const InlineContentAdInfo& ad) { + ClientStateManager::GetInstance()->UpdateSeenAd(ad); } void InlineContentAd::OnInlineContentAdViewed(const InlineContentAdInfo& ad) { + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kViewed); @@ -71,6 +81,8 @@ void InlineContentAd::OnInlineContentAdViewed(const InlineContentAdInfo& ad) { void InlineContentAd::OnInlineContentAdClicked(const InlineContentAdInfo& ad) { transfer_->SetLastClickedAd(ad); + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kClicked); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad.h index 0bc0dfc7dbce..c59a2ecaa954 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad.h @@ -13,8 +13,6 @@ #include "bat/ads/ads_callback.h" #include "bat/ads/internal/ads/ad_events/inline_content_ads/inline_content_ad_event_handler_observer.h" #include "bat/ads/internal/ads/serving/inline_content_ad_serving_observer.h" -#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" -#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" #include "bat/ads/public/interfaces/ads.mojom.h" namespace ads { @@ -59,6 +57,7 @@ class InlineContentAd final : public inline_content_ads::EventHandlerObserver, void OnDidServeInlineContentAd(const InlineContentAdInfo& ad) override; // inline_content_ads::EventHandlerObserver: + void OnInlineContentAdServed(const InlineContentAdInfo& ad) override; void OnInlineContentAdViewed(const InlineContentAdInfo& ad) override; void OnInlineContentAdClicked(const InlineContentAdInfo& ad) override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad_test.cc new file mode 100644 index 000000000000..a16bd0f3d284 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/inline_content_ad_test.cc @@ -0,0 +1,114 @@ +/* Copyright (c) 2022 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/inline_content_ad.h" + +#include "bat/ads/ad_type.h" +#include "bat/ads/confirmation_type.h" +#include "bat/ads/inline_content_ad_info.h" +#include "bat/ads/internal/account/transactions/transactions_unittest_util.h" +#include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/base/net/http/http_status_code.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/base/unittest/unittest_mock_util.h" +#include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.h" +#include "bat/ads/internal/history/history_unittest_util.h" +#include "bat/ads/public/interfaces/ads.mojom.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +namespace { + +constexpr char kDimensions[] = "200x100"; +constexpr char kPlacementId[] = "f0948316-df6f-4e31-814d-d0b5f2a1f28c"; +constexpr char kCreativeInstanceIdId[] = "30db5f7b-dba3-48a3-b299-c9bd9c67da65"; + +} // namespace + +class BatAdsInlineContentAdIntegrationTest : public UnitTestBase { + protected: + BatAdsInlineContentAdIntegrationTest() = default; + + ~BatAdsInlineContentAdIntegrationTest() override = default; + + void SetUp() override { + UnitTestBase::SetUpForTesting(/* is_integration_test */ true); + + ForcePermissionRules(); + } + + void SetUpMocks() override { + const URLEndpointMap endpoints = { + {"/v9/catalog", + {{net::HTTP_OK, "/catalog_with_inline_content_ad.json"}}}}; + MockUrlRequest(ads_client_mock_, endpoints); + } +}; + +TEST_F(BatAdsInlineContentAdIntegrationTest, Serve) { + // Arrange + + // Act + GetAds()->MaybeServeInlineContentAd( + kDimensions, [](const bool success, const std::string& dimensions, + const InlineContentAdInfo& ad) { + // Assert + EXPECT_TRUE(success); + EXPECT_EQ(kDimensions, dimensions); + EXPECT_TRUE(ad.IsValid()); + EXPECT_EQ(1, GetAdEventCount(AdType::kInlineContentAd, + ConfirmationType::kServed)); + }); +} + +TEST_F(BatAdsInlineContentAdIntegrationTest, TriggerServedEvent) { + // Arrange + + // Act + GetAds()->TriggerInlineContentAdEvent( + kPlacementId, kCreativeInstanceIdId, + mojom::InlineContentAdEventType::kServed); + + // Assert + EXPECT_EQ( + 1, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kServed)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); +} + +TEST_F(BatAdsInlineContentAdIntegrationTest, TriggerViewedEvent) { + // Arrange + + // Act + GetAds()->TriggerInlineContentAdEvent( + kPlacementId, kCreativeInstanceIdId, + mojom::InlineContentAdEventType::kViewed); + + // Assert + EXPECT_EQ( + 1, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kViewed)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); +} + +TEST_F(BatAdsInlineContentAdIntegrationTest, TriggerClickedEvent) { + // Arrange + + // Act + GetAds()->TriggerInlineContentAdEvent( + kPlacementId, kCreativeInstanceIdId, + mojom::InlineContentAdEventType::kClicked); + + // Assert + EXPECT_EQ( + 1, GetAdEventCount(AdType::kInlineContentAd, ConfirmationType::kClicked)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad.cc index e0dd32147cb9..b0175a4ab91c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad.cc @@ -6,9 +6,14 @@ #include "bat/ads/internal/ads/new_tab_page_ad.h" #include "bat/ads/confirmation_type.h" +#include "bat/ads/history_item_info.h" #include "bat/ads/internal/account/account.h" #include "bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler.h" #include "bat/ads/internal/ads/serving/new_tab_page_ad_serving.h" +#include "bat/ads/internal/deprecated/client/client_state_manager.h" +#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" +#include "bat/ads/internal/history/history_manager.h" +#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" #include "bat/ads/internal/transfer/transfer.h" #include "bat/ads/new_tab_page_ad_info.h" @@ -24,11 +29,10 @@ NewTabPageAd::NewTabPageAd( DCHECK(transfer_); event_handler_ = std::make_unique(); + event_handler_->AddObserver(this); serving_ = std::make_unique( subdivision_targeting, anti_targeting_resource); - - event_handler_->AddObserver(this); serving_->AddObserver(this); } @@ -52,11 +56,17 @@ void NewTabPageAd::TriggerEvent(const std::string& placement_id, /////////////////////////////////////////////////////////////////////////////// void NewTabPageAd::OnDidServeNewTabPageAd(const NewTabPageAdInfo& ad) { - event_handler_->FireEvent(ad.placement_id, ad.creative_instance_id, - mojom::NewTabPageAdEventType::kServed); + TriggerEvent(ad.placement_id, ad.creative_instance_id, + mojom::NewTabPageAdEventType::kServed); +} + +void NewTabPageAd::OnNewTabPageAdServed(const NewTabPageAdInfo& ad) { + ClientStateManager::GetInstance()->UpdateSeenAd(ad); } void NewTabPageAd::OnNewTabPageAdViewed(const NewTabPageAdInfo& ad) { + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kViewed); } @@ -64,6 +74,8 @@ void NewTabPageAd::OnNewTabPageAdViewed(const NewTabPageAdInfo& ad) { void NewTabPageAd::OnNewTabPageAdClicked(const NewTabPageAdInfo& ad) { transfer_->SetLastClickedAd(ad); + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kClicked); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad.h index e89bf756e70d..87152ba85062 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad.h @@ -13,8 +13,6 @@ #include "bat/ads/ads_callback.h" #include "bat/ads/internal/ads/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_observer.h" #include "bat/ads/internal/ads/serving/new_tab_page_ad_serving_observer.h" -#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" -#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" #include "bat/ads/public/interfaces/ads.mojom.h" namespace ads { @@ -58,6 +56,7 @@ class NewTabPageAd final : public new_tab_page_ads::EventHandlerObserver, void OnDidServeNewTabPageAd(const NewTabPageAdInfo& ad) override; // new_tab_page_ads::EventHandlerObserver: + void OnNewTabPageAdServed(const NewTabPageAdInfo& ad) override; void OnNewTabPageAdViewed(const NewTabPageAdInfo& ad) override; void OnNewTabPageAdClicked(const NewTabPageAdInfo& ad) override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad_test.cc new file mode 100644 index 000000000000..dd968ac4daa1 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/new_tab_page_ad_test.cc @@ -0,0 +1,108 @@ +/* Copyright (c) 2022 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/new_tab_page_ad.h" + +#include "bat/ads/ad_type.h" +#include "bat/ads/confirmation_type.h" +#include "bat/ads/internal/account/transactions/transactions_unittest_util.h" +#include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/base/net/http/http_status_code.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/base/unittest/unittest_mock_util.h" +#include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.h" +#include "bat/ads/internal/history/history_unittest_util.h" +#include "bat/ads/new_tab_page_ad_info.h" +#include "bat/ads/public/interfaces/ads.mojom.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +namespace { + +constexpr char kPlacementId[] = "f0948316-df6f-4e31-814d-d0b5f2a1f28c"; +constexpr char kCreativeInstanceIdId[] = "7ff400b9-7f8a-46a8-89f1-cb386612edcf"; + +} // namespace + +class BatAdsNewTabPageAdIntegrationTest : public UnitTestBase { + protected: + BatAdsNewTabPageAdIntegrationTest() = default; + + ~BatAdsNewTabPageAdIntegrationTest() override = default; + + void SetUp() override { + UnitTestBase::SetUpForTesting(/* is_integration_test */ true); + + ForcePermissionRules(); + } + + void SetUpMocks() override { + const URLEndpointMap endpoints = { + {"/v9/catalog", + {{net::HTTP_OK, "/catalog_with_new_tab_page_ad.json"}}}}; + MockUrlRequest(ads_client_mock_, endpoints); + } +}; + +TEST_F(BatAdsNewTabPageAdIntegrationTest, Serve) { + // Arrange + + // Act + GetAds()->MaybeServeNewTabPageAd([](const bool success, + const NewTabPageAdInfo& ad) { + // Assert + EXPECT_TRUE(success); + EXPECT_TRUE(ad.IsValid()); + EXPECT_EQ( + 1, GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kServed)); + }); +} + +TEST_F(BatAdsNewTabPageAdIntegrationTest, TriggerServedEvent) { + // Arrange + + // Act + GetAds()->TriggerNewTabPageAdEvent(kPlacementId, kCreativeInstanceIdId, + mojom::NewTabPageAdEventType::kServed); + + // Assert + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kServed)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); +} + +TEST_F(BatAdsNewTabPageAdIntegrationTest, TriggerViewedEvent) { + // Arrange + + // Act + GetAds()->TriggerNewTabPageAdEvent(kPlacementId, kCreativeInstanceIdId, + mojom::NewTabPageAdEventType::kViewed); + + // Assert + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kViewed)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); +} + +TEST_F(BatAdsNewTabPageAdIntegrationTest, TriggerClickedEvent) { + // Arrange + + // Act + GetAds()->TriggerNewTabPageAdEvent(kPlacementId, kCreativeInstanceIdId, + mojom::NewTabPageAdEventType::kClicked); + + // Assert + EXPECT_EQ(1, + GetAdEventCount(AdType::kNewTabPageAd, ConfirmationType::kClicked)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad.cc index 8b0cca6b99aa..232d25294ed3 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad.cc @@ -8,22 +8,25 @@ #include "base/time/time.h" #include "bat/ads/ad_type.h" #include "bat/ads/confirmation_type.h" +#include "bat/ads/history_item_info.h" #include "bat/ads/internal/account/account.h" -#include "bat/ads/internal/account/account_util.h" #include "bat/ads/internal/account/wallet/wallet_info.h" #include "bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_handler.h" +#include "bat/ads/internal/ads/notification_ad_util.h" #include "bat/ads/internal/ads/serving/notification_ad_serving.h" -#include "bat/ads/internal/ads_client_helper.h" #include "bat/ads/internal/base/logging_util.h" #include "bat/ads/internal/base/platform/platform_helper.h" #include "bat/ads/internal/browser/browser_manager.h" #include "bat/ads/internal/covariates/covariate_manager.h" +#include "bat/ads/internal/deprecated/client/client_state_manager.h" +#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" +#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/internal/prefs/pref_manager.h" #include "bat/ads/internal/privacy/p2a/impressions/p2a_impression.h" #include "bat/ads/internal/privacy/p2a/opportunities/p2a_opportunity.h" #include "bat/ads/internal/processors/behavioral/bandits/bandit_feedback_info.h" #include "bat/ads/internal/processors/behavioral/bandits/epsilon_greedy_bandit_processor.h" -#include "bat/ads/internal/settings/settings.h" +#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" #include "bat/ads/internal/transfer/transfer.h" #include "bat/ads/internal/user_interaction/idle_detection/idle_detection_manager.h" #include "bat/ads/internal/user_interaction/idle_detection/idle_detection_util.h" @@ -32,17 +35,6 @@ namespace ads { -namespace { - -bool ShouldServeAtRegularIntervals() { - return ShouldRewardUser() && - (BrowserManager::GetInstance()->IsBrowserActive() || - AdsClientHelper::GetInstance()->CanShowBackgroundNotifications()) && - settings::GetAdsPerHour() > 0; -} - -} // namespace - NotificationAd::NotificationAd( Account* account, Transfer* transfer, @@ -56,14 +48,15 @@ NotificationAd::NotificationAd( DCHECK(transfer_); DCHECK(epsilon_greedy_bandit_processor_); + account_->AddObserver(this); + event_handler_ = std::make_unique(); + event_handler_->AddObserver(this); serving_ = std::make_unique( subdivision_targeting, anti_targeting_resource); - - account_->AddObserver(this); - event_handler_->AddObserver(this); serving_->AddObserver(this); + BrowserManager::GetInstance()->AddObserver(this); PrefManager::GetInstance()->AddObserver(this); IdleDetectionManager::GetInstance()->AddObserver(this); @@ -80,6 +73,7 @@ NotificationAd::~NotificationAd() { void NotificationAd::MaybeServeAtRegularIntervals() { if (!PlatformHelper::GetInstance()->IsMobile()) { + // Ads should not be shown on desktop at regular intervals. return; } @@ -119,10 +113,11 @@ void NotificationAd::OnPrefChanged(const std::string& path) { void NotificationAd::OnUserDidBecomeActive(const base::TimeDelta idle_time, const bool was_locked) { if (PlatformHelper::GetInstance()->IsMobile()) { + // Ads should not be shown on mobile when a user becomes active. return; } - if (!ShouldRewardUser()) { + if (!ShouldServe()) { return; } @@ -146,11 +141,18 @@ void NotificationAd::OnOpportunityAroseToServeNotificationAd( } void NotificationAd::OnDidServeNotificationAd(const NotificationAdInfo& ad) { - event_handler_->FireEvent(ad.placement_id, - mojom::NotificationAdEventType::kServed); + ShowNotification(ad); + + TriggerEvent(ad.placement_id, mojom::NotificationAdEventType::kServed); +} + +void NotificationAd::OnNotificationAdServed(const NotificationAdInfo& ad) { + ClientStateManager::GetInstance()->UpdateSeenAd(ad); } void NotificationAd::OnNotificationAdViewed(const NotificationAdInfo& ad) { + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kViewed); @@ -160,8 +162,12 @@ void NotificationAd::OnNotificationAdViewed(const NotificationAdInfo& ad) { } void NotificationAd::OnNotificationAdClicked(const NotificationAdInfo& ad) { + CloseNotification(ad.placement_id); + transfer_->SetLastClickedAd(ad); + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kClicked); @@ -174,6 +180,10 @@ void NotificationAd::OnNotificationAdClicked(const NotificationAdInfo& ad) { } void NotificationAd::OnNotificationAdDismissed(const NotificationAdInfo& ad) { + DismissNotification(ad.placement_id); + + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kDismissed); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kDismissed); @@ -186,6 +196,8 @@ void NotificationAd::OnNotificationAdDismissed(const NotificationAdInfo& ad) { } void NotificationAd::OnNotificationAdTimedOut(const NotificationAdInfo& ad) { + NotificationTimedOut(ad.placement_id); + epsilon_greedy_bandit_processor_->Process( {ad.segment, mojom::NotificationAdEventType::kTimedOut}); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad.h index c7df4c40fdcd..f4281909d055 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad.h @@ -14,9 +14,7 @@ #include "bat/ads/internal/ads/ad_events/notification_ads/notification_ad_event_handler_observer.h" #include "bat/ads/internal/ads/serving/notification_ad_serving_observer.h" #include "bat/ads/internal/browser/browser_manager_observer.h" -#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/internal/prefs/pref_manager_observer.h" -#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" #include "bat/ads/internal/segments/segments_aliases.h" #include "bat/ads/internal/user_interaction/idle_detection/idle_detection_manager_observer.h" #include "bat/ads/public/interfaces/ads.mojom.h" @@ -92,6 +90,7 @@ class NotificationAd final : public AccountObserver, void OnDidServeNotificationAd(const NotificationAdInfo& ad) override; // notification_ads::EventHandlerObserver: + void OnNotificationAdServed(const NotificationAdInfo& ad) override; void OnNotificationAdViewed(const NotificationAdInfo& ad) override; void OnNotificationAdClicked(const NotificationAdInfo& ad) override; void OnNotificationAdDismissed(const NotificationAdInfo& ad) override; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_for_mobile_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_for_mobile_test.cc new file mode 100644 index 000000000000..c9853afa4ecb --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_for_mobile_test.cc @@ -0,0 +1,206 @@ +/* Copyright (c) 2022 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/notification_ad.h" + +#include "base/time/time.h" +#include "bat/ads/ad_type.h" +#include "bat/ads/confirmation_type.h" +#include "bat/ads/internal/account/transactions/transactions_unittest_util.h" +#include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" +#include "bat/ads/internal/ads/notification_ad_unittest_util.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/base/net/http/http_status_code.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/base/unittest/unittest_mock_util.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" +#include "bat/ads/internal/history/history_unittest_util.h" +#include "bat/ads/notification_ad_info.h" +#include "bat/ads/public/interfaces/ads.mojom.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +using ::testing::_; + +namespace ads { + +class BatAdsNotificationAdForMobileIntegrationTest : public UnitTestBase { + protected: + BatAdsNotificationAdForMobileIntegrationTest() = default; + + ~BatAdsNotificationAdForMobileIntegrationTest() override = default; + + void SetUp() override { + UnitTestBase::SetUpForTesting(/* is_integration_test */ true); + + ForcePermissionRules(); + } + + void SetUpMocks() override { + MockPlatformHelper(platform_helper_mock_, PlatformType::kAndroid); + + const URLEndpointMap endpoints = { + {"/v9/catalog", + {{net::HTTP_OK, "/catalog_with_notification_ad.json"}}}}; + MockUrlRequest(ads_client_mock_, endpoints); + } + + void ServeNextAd() { + ASSERT_TRUE(IsServingAdAtRegularIntervals()); + const base::Time serve_ad_at = + ClientStateManager::GetInstance()->GetServeAdAt(); + FastForwardClockTo(serve_ad_at); + } + + void ServeAd() { + GetAds()->OnUnIdle(base::TimeDelta::Min(), /* was_locked */ false); + } +}; + +TEST_F(BatAdsNotificationAdForMobileIntegrationTest, ServeAtRegularIntervals) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + })); + + // Act + ServeNextAd(); + + // Assert + EXPECT_EQ( + 1, GetAdEventCount(AdType::kNotificationAd, ConfirmationType::kServed)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); +} + +TEST_F(BatAdsNotificationAdForMobileIntegrationTest, + DoNotServeWhenUserBecomesActive) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification(_)).Times(0); + + // Act + ServeAd(); + + // Assert + EXPECT_EQ( + 0, GetAdEventCount(AdType::kNotificationAd, ConfirmationType::kServed)); +} + +TEST_F(BatAdsNotificationAdForMobileIntegrationTest, TriggerServedEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kServed); + + // Assert + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kServed)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); + })); + + ServeNextAd(); +} + +TEST_F(BatAdsNotificationAdForMobileIntegrationTest, TriggerViewedEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kViewed); + + // Assert + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kViewed)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); + })); + + ServeNextAd(); +} + +TEST_F(BatAdsNotificationAdForMobileIntegrationTest, TriggerClickedEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_CALL(*ads_client_mock_, CloseNotification(ad.placement_id)) + .Times(1); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kClicked); + + // Assert + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kClicked)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); + })); + + ServeNextAd(); +} + +TEST_F(BatAdsNotificationAdForMobileIntegrationTest, TriggerDismissedEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kDismissed); + + // Assert + EXPECT_FALSE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kDismissed)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); + })); + + ServeNextAd(); +} + +TEST_F(BatAdsNotificationAdForMobileIntegrationTest, TriggerTimedOutEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kTimedOut); + + // Assert + EXPECT_FALSE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); + })); + + ServeNextAd(); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_test.cc new file mode 100644 index 000000000000..a7f674658f9e --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_test.cc @@ -0,0 +1,191 @@ +/* Copyright (c) 2022 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/notification_ad.h" + +#include "base/time/time.h" +#include "bat/ads/ad_type.h" +#include "bat/ads/confirmation_type.h" +#include "bat/ads/internal/account/transactions/transactions_unittest_util.h" +#include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" +#include "bat/ads/internal/ads/notification_ad_unittest_util.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/base/net/http/http_status_code.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/base/unittest/unittest_mock_util.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" +#include "bat/ads/internal/history/history_unittest_util.h" +#include "bat/ads/notification_ad_info.h" +#include "bat/ads/public/interfaces/ads.mojom.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +class BatAdsNotificationAdIntegrationTest : public UnitTestBase { + protected: + BatAdsNotificationAdIntegrationTest() = default; + + ~BatAdsNotificationAdIntegrationTest() override = default; + + void SetUp() override { + UnitTestBase::SetUpForTesting(/* is_integration_test */ true); + + ForcePermissionRules(); + } + + void SetUpMocks() override { + const URLEndpointMap endpoints = { + {"/v9/catalog", + {{net::HTTP_OK, "/catalog_with_notification_ad.json"}}}}; + MockUrlRequest(ads_client_mock_, endpoints); + } + + void ServeAd() { + GetAds()->OnUnIdle(base::TimeDelta::Min(), /* was_locked */ false); + } +}; + +TEST_F(BatAdsNotificationAdIntegrationTest, Serve) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + })); + + // Act + ServeAd(); + + // Assert + EXPECT_EQ( + 1, GetAdEventCount(AdType::kNotificationAd, ConfirmationType::kServed)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); +} + +TEST_F(BatAdsNotificationAdIntegrationTest, DoNotServeAtRegularIntervals) { + // Arrange + + // Act + + // Assert + EXPECT_FALSE(IsServingAdAtRegularIntervals()); +} + +TEST_F(BatAdsNotificationAdIntegrationTest, TriggerServedEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kServed); + + // Assert + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kServed)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); + })); + + ServeAd(); +} + +TEST_F(BatAdsNotificationAdIntegrationTest, TriggerViewedEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kViewed); + + // Assert + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kViewed)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); + })); + + ServeAd(); +} + +TEST_F(BatAdsNotificationAdIntegrationTest, TriggerClickedEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_CALL(*ads_client_mock_, CloseNotification(ad.placement_id)) + .Times(1); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kClicked); + + // Assert + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kClicked)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); + })); + + ServeAd(); +} + +TEST_F(BatAdsNotificationAdIntegrationTest, TriggerDismissedEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kDismissed); + + // Assert + EXPECT_FALSE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_EQ(1, GetAdEventCount(AdType::kNotificationAd, + ConfirmationType::kDismissed)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); + })); + + ServeAd(); +} + +TEST_F(BatAdsNotificationAdIntegrationTest, TriggerTimedOutEvent) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + GetAds()->TriggerNotificationAdEvent( + ad.placement_id, mojom::NotificationAdEventType::kTimedOut); + + // Assert + EXPECT_FALSE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); + })); + + ServeAd(); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_unittest_util.cc new file mode 100644 index 000000000000..35941277293d --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_unittest_util.cc @@ -0,0 +1,19 @@ +/* Copyright (c) 2022 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/notification_ad_unittest_util.h" + +#include "base/time/time.h" +#include "bat/ads/internal/deprecated/client/client_state_manager.h" + +namespace ads { + +bool IsServingAdAtRegularIntervals() { + const base::Time serve_ad_at = + ClientStateManager::GetInstance()->GetServeAdAt(); + return !serve_ad_at.is_null(); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_unittest_util.h new file mode 100644 index 000000000000..d53c84ee34d6 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_unittest_util.h @@ -0,0 +1,15 @@ +/* Copyright (c) 2022 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_NOTIFICATION_AD_UNITTEST_UTIL_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_NOTIFICATION_AD_UNITTEST_UTIL_H_ + +namespace ads { + +bool IsServingAdAtRegularIntervals(); + +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_NOTIFICATION_AD_UNITTEST_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util.cc new file mode 100644 index 000000000000..6f45d1932adb --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util.cc @@ -0,0 +1,46 @@ +/* Copyright (c) 2022 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/notification_ad_util.h" + +#include "bat/ads/internal/account/account_util.h" +#include "bat/ads/internal/ads_client_helper.h" +#include "bat/ads/internal/browser/browser_manager.h" +#include "bat/ads/internal/creatives/notification_ads/notification_ad_manager.h" +#include "bat/ads/internal/settings/settings.h" +#include "bat/ads/notification_ad_info.h" + +namespace ads { + +bool ShouldServe() { + return ShouldRewardUser(); +} + +bool ShouldServeAtRegularIntervals() { + return ShouldServe() && + (BrowserManager::GetInstance()->IsBrowserActive() || + AdsClientHelper::GetInstance()->CanShowBackgroundNotifications()) && + settings::GetAdsPerHour() > 0; +} + +void ShowNotification(const NotificationAdInfo& ad) { + NotificationAdManager::GetInstance()->PushBack(ad); + AdsClientHelper::GetInstance()->ShowNotification(ad); +} + +void DismissNotification(const std::string& placement_id) { + NotificationAdManager::GetInstance()->Remove(placement_id); +} + +void CloseNotification(const std::string& placement_id) { + NotificationAdManager::GetInstance()->Remove(placement_id); + AdsClientHelper::GetInstance()->CloseNotification(placement_id); +} + +void NotificationTimedOut(const std::string& placement_id) { + NotificationAdManager::GetInstance()->Remove(placement_id); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util.h new file mode 100644 index 000000000000..4e1de6a441e8 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2022 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_NOTIFICATION_AD_UTIL_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_NOTIFICATION_AD_UTIL_H_ + +#include + +namespace ads { + +struct NotificationAdInfo; + +bool ShouldServe(); +bool ShouldServeAtRegularIntervals(); + +void ShowNotification(const NotificationAdInfo& ad); +void CloseNotification(const std::string& placement_id); +void DismissNotification(const std::string& placement_id); +void NotificationTimedOut(const std::string& placement_id); + +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_NOTIFICATION_AD_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util_serve_at_regular_intervals_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util_serve_at_regular_intervals_unittest.cc new file mode 100644 index 000000000000..ba65facb71f7 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util_serve_at_regular_intervals_unittest.cc @@ -0,0 +1,146 @@ +/* Copyright (c) 2022 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/notification_ad_util.h" + +#include "base/strings/stringprintf.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/base/unittest/unittest_mock_util.h" +#include "bat/ads/pref_names.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +namespace { + +struct ParamInfo final { + bool should_serve; + bool is_browser_active; + bool can_show_background_notifications; + int ads_per_hour; + bool should_serve_at_regular_intervals; +}; + +const ParamInfo kTests[] = { + {/* should_serve */ false, /* is_browser_active */ false, + /* can_show_background_notifications */ false, /* ads_per_hour */ 0, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ false, /* is_browser_active */ false, + /* can_show_background_notifications */ false, /* ads_per_hour */ 1, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ false, /* is_browser_active */ false, + /* can_show_background_notifications */ true, /* ads_per_hour */ 0, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ false, /* is_browser_active */ false, + /* can_show_background_notifications */ true, /* ads_per_hour */ 1, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ false, /* is_browser_active */ true, + /* can_show_background_notifications */ false, /* ads_per_hour */ 0, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ false, /* is_browser_active */ true, + /* can_show_background_notifications */ false, /* ads_per_hour */ 1, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ false, /* is_browser_active */ true, + /* can_show_background_notifications */ true, /* ads_per_hour */ 0, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ false, /* is_browser_active */ true, + /* can_show_background_notifications */ true, /* ads_per_hour */ 1, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ true, /* is_browser_active */ false, + /* can_show_background_notifications */ false, /* ads_per_hour */ 0, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ true, /* is_browser_active */ false, + /* can_show_background_notifications */ false, /* ads_per_hour */ 1, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ true, /* is_browser_active */ false, + /* can_show_background_notifications */ true, /* ads_per_hour */ 0, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ true, /* is_browser_active */ false, + /* can_show_background_notifications */ true, /* ads_per_hour */ 1, + /* should_serve_at_regular_intervals */ true}, + {/* should_serve */ true, /* is_browser_active */ true, + /* can_show_background_notifications */ false, /* ads_per_hour */ 0, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ true, /* is_browser_active */ true, + /* can_show_background_notifications */ false, /* ads_per_hour */ 1, + /* should_serve_at_regular_intervals */ true}, + {/* should_serve */ true, /* is_browser_active */ true, + /* can_show_background_notifications */ true, /* ads_per_hour */ 0, + /* should_serve_at_regular_intervals */ false}, + {/* should_serve */ true, /* is_browser_active */ true, + /* can_show_background_notifications */ true, /* ads_per_hour */ 1, + /* should_serve_at_regular_intervals */ true}}; + +} // namespace + +class BatAdsNotificationAdUtilServeAtRegularIntervalsTest + : public UnitTestBase, + public ::testing::WithParamInterface { + protected: + BatAdsNotificationAdUtilServeAtRegularIntervalsTest() {} + + ~BatAdsNotificationAdUtilServeAtRegularIntervalsTest() override {} + + void SetUpMocks() override { + const ParamInfo param = GetParam(); + + AdsClientHelper::GetInstance()->SetBooleanPref(prefs::kEnabled, + param.should_serve); + + MockIsBrowserActive(ads_client_mock_, param.is_browser_active); + + MockCanShowBackgroundNotifications(ads_client_mock_, + param.can_show_background_notifications); + + AdsClientHelper::GetInstance()->SetInt64Pref(prefs::kAdsPerHour, + param.ads_per_hour); + } +}; + +TEST_P(BatAdsNotificationAdUtilServeAtRegularIntervalsTest, NotificationAd) { + // Arrange + const ParamInfo param = GetParam(); + + // Act + + // Assert + EXPECT_EQ(param.should_serve_at_regular_intervals, + ShouldServeAtRegularIntervals()); +} + +std::string TestParamToString(::testing::TestParamInfo test_param) { + const std::string should_serve_at_regular_intervals = + test_param.param.should_serve_at_regular_intervals + ? "ShouldServeAtRegularIntervals" + : "ShouldNotServeAtRegularIntervals"; + + const std::string should_serve = + test_param.param.should_serve ? "ShouldServe" : "ShouldNotServe"; + + const std::string is_browser_active = test_param.param.is_browser_active + ? "BrowserIsActive" + : "BrowserIsInactive"; + + const std::string can_show_background_notifications = + test_param.param.can_show_background_notifications + ? "BackgroundNotificationsAreEnabled" + : "BackgroundNotificationsAreDisabled"; + + const std::string ads_per_hour = + base::StringPrintf("%dAdsPerHour", test_param.param.ads_per_hour); + + return base::StringPrintf( + "%sIf%sAnd%sAnd%sAnd%s", should_serve_at_regular_intervals.c_str(), + should_serve.c_str(), is_browser_active.c_str(), + can_show_background_notifications.c_str(), ads_per_hour.c_str()); +} + +INSTANTIATE_TEST_SUITE_P(, + BatAdsNotificationAdUtilServeAtRegularIntervalsTest, + testing::ValuesIn(kTests), + TestParamToString); + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util_unittest.cc new file mode 100644 index 000000000000..bcfb6fc65741 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/notification_ad_util_unittest.cc @@ -0,0 +1,129 @@ +/* Copyright (c) 2022 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/notification_ad_util.h" + +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" +#include "bat/ads/internal/creatives/notification_ads/notification_ad_builder.h" +#include "bat/ads/notification_ad_info.h" +#include "bat/ads/pref_names.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +class BatAdsNotificationAdUtilTest : public UnitTestBase { + protected: + BatAdsNotificationAdUtilTest() {} + + ~BatAdsNotificationAdUtilTest() override {} + + void ShowAdNotification() { + const CreativeNotificationAdInfo creative_ad = + BuildCreativeNotificationAd(); + const NotificationAdInfo ad = BuildNotificationAd(creative_ad); + ShowNotification(ad); + } +}; + +TEST_F(BatAdsNotificationAdUtilTest, ShouldServe) { + // Arrange + AdsClientHelper::GetInstance()->SetBooleanPref(prefs::kEnabled, true); + + // Act + + // Assert + EXPECT_TRUE(ShouldServe()); +} + +TEST_F(BatAdsNotificationAdUtilTest, ShouldNotServe) { + // Arrange + AdsClientHelper::GetInstance()->SetBooleanPref(prefs::kEnabled, false); + + // Act + + // Assert + EXPECT_FALSE(ShouldServe()); +} + +TEST_F(BatAdsNotificationAdUtilTest, ShowNotification) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + // Act + + // Assert + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + })); + + ShowAdNotification(); +} + +TEST_F(BatAdsNotificationAdUtilTest, DismissNotification) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + DismissNotification(ad.placement_id); + + // Assert + ASSERT_FALSE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + })); + + ShowAdNotification(); +} + +TEST_F(BatAdsNotificationAdUtilTest, CloseNotification) { + // Arrange + EXPECT_CALL(*ads_client_mock_, CloseNotification) + .WillOnce(testing::Invoke([=](const std::string& placement_id) { + // Act + + // Assert + ASSERT_FALSE( + NotificationAdManager::GetInstance()->Exists(placement_id)); + })); + + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + CloseNotification(ad.placement_id); + + // Assert + ASSERT_FALSE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + })); + + ShowAdNotification(); +} + +TEST_F(BatAdsNotificationAdUtilTest, NotificationTimedOut) { + // Arrange + EXPECT_CALL(*ads_client_mock_, ShowNotification) + .WillOnce(testing::Invoke([=](const NotificationAdInfo& ad) { + ASSERT_TRUE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + + // Act + NotificationTimedOut(ad.placement_id); + + // Assert + ASSERT_FALSE( + NotificationAdManager::GetInstance()->Exists(ad.placement_id)); + })); + + ShowAdNotification(); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/promoted_content_ad.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/promoted_content_ad.cc index e9fbd0c96428..6b8311433e7f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/promoted_content_ad.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/promoted_content_ad.cc @@ -6,8 +6,10 @@ #include "bat/ads/internal/ads/promoted_content_ad.h" #include "bat/ads/confirmation_type.h" +#include "bat/ads/history_item_info.h" #include "bat/ads/internal/account/account.h" #include "bat/ads/internal/ads/ad_events/promoted_content_ads/promoted_content_ad_event_handler.h" +#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/internal/transfer/transfer.h" #include "bat/ads/promoted_content_ad_info.h" @@ -37,6 +39,8 @@ void PromotedContentAd::TriggerEvent( void PromotedContentAd::OnPromotedContentAdViewed( const PromotedContentAdInfo& ad) { + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kViewed); } @@ -45,6 +49,8 @@ void PromotedContentAd::OnPromotedContentAdClicked( const PromotedContentAdInfo& ad) { transfer_->SetLastClickedAd(ad); + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kClicked); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/promoted_content_ad_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/promoted_content_ad_test.cc new file mode 100644 index 000000000000..d88da8c840f8 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/promoted_content_ad_test.cc @@ -0,0 +1,82 @@ +/* Copyright (c) 2022 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/promoted_content_ad.h" + +#include "bat/ads/ad_type.h" +#include "bat/ads/confirmation_type.h" +#include "bat/ads/internal/account/transactions/transactions_unittest_util.h" +#include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/base/net/http/http_status_code.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/base/unittest/unittest_mock_util.h" +#include "bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ad_unittest_util.h" +#include "bat/ads/internal/history/history_unittest_util.h" +#include "bat/ads/public/interfaces/ads.mojom.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +namespace { + +constexpr char kPlacementId[] = "f0948316-df6f-4e31-814d-d0b5f2a1f28c"; +constexpr char kCreativeInstanceIdId[] = "75d4cbac-b661-4126-9ccb-7bbb6ee56ef3"; + +} // namespace + +class BatAdsPromotedContentAdIntegrationTest : public UnitTestBase { + protected: + BatAdsPromotedContentAdIntegrationTest() = default; + + ~BatAdsPromotedContentAdIntegrationTest() override = default; + + void SetUp() override { + UnitTestBase::SetUpForTesting(/* is_integration_test */ true); + + ForcePermissionRules(); + } + + void SetUpMocks() override { + const URLEndpointMap endpoints = { + {"/v9/catalog", {{net::HTTP_OK, "/catalog.json"}}}}; + MockUrlRequest(ads_client_mock_, endpoints); + } +}; + +TEST_F(BatAdsPromotedContentAdIntegrationTest, TriggerViewedEvent) { + // Arrange + + // Act + GetAds()->TriggerPromotedContentAdEvent( + kPlacementId, kCreativeInstanceIdId, + mojom::PromotedContentAdEventType::kViewed); + + // Assert + EXPECT_EQ(1, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kServed)); + EXPECT_EQ(1, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kViewed)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); +} + +TEST_F(BatAdsPromotedContentAdIntegrationTest, TriggerClickedEvent) { + // Arrange + + // Act + GetAds()->TriggerPromotedContentAdEvent( + kPlacementId, kCreativeInstanceIdId, + mojom::PromotedContentAdEventType::kClicked); + + // Assert + EXPECT_EQ(1, GetAdEventCount(AdType::kPromotedContentAd, + ConfirmationType::kClicked)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/search_result_ad.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/search_result_ad.cc index 05561394f01b..39ad6d0723c6 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/search_result_ad.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/search_result_ad.cc @@ -6,9 +6,11 @@ #include "bat/ads/internal/ads/search_result_ad.h" #include "bat/ads/confirmation_type.h" +#include "bat/ads/history_item_info.h" #include "bat/ads/internal/account/account.h" #include "bat/ads/internal/ads/ad_events/search_result_ads/search_result_ad_event_handler.h" #include "bat/ads/internal/creatives/search_result_ads/search_result_ad_info.h" +#include "bat/ads/internal/history/history_manager.h" #include "bat/ads/internal/transfer/transfer.h" namespace ads { @@ -41,6 +43,8 @@ void SearchResultAd::TriggerEvent( /////////////////////////////////////////////////////////////////////////////// void SearchResultAd::OnSearchResultAdViewed(const SearchResultAdInfo& ad) { + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kViewed); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kViewed); } @@ -48,6 +52,8 @@ void SearchResultAd::OnSearchResultAdViewed(const SearchResultAdInfo& ad) { void SearchResultAd::OnSearchResultAdClicked(const SearchResultAdInfo& ad) { transfer_->SetLastClickedAd(ad); + HistoryManager::GetInstance()->Add(ad, ConfirmationType::kClicked); + account_->Deposit(ad.creative_instance_id, ad.type, ConfirmationType::kClicked); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/search_result_ad_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/search_result_ad_test.cc new file mode 100644 index 000000000000..a15f2e06ed5e --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/search_result_ad_test.cc @@ -0,0 +1,91 @@ +/* Copyright (c) 2022 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/search_result_ad.h" + +#include "base/notreached.h" +#include "bat/ads/ad_type.h" +#include "bat/ads/confirmation_type.h" +#include "bat/ads/internal/account/transactions/transactions_unittest_util.h" +#include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.h" +#include "bat/ads/internal/history/history_unittest_util.h" +#include "bat/ads/public/interfaces/ads.mojom.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +class BatAdsSearchResultAdIntegrationTest : public UnitTestBase { + protected: + BatAdsSearchResultAdIntegrationTest() = default; + + ~BatAdsSearchResultAdIntegrationTest() override = default; + + void SetUp() override { + UnitTestBase::SetUpForTesting(/* is_integration_test */ true); + + ForcePermissionRules(); + } +}; + +TEST_F(BatAdsSearchResultAdIntegrationTest, TriggerViewedEvent) { + // Arrange + + // Act + GetAds()->TriggerSearchResultAdEvent( + BuildSearchResultAd(), mojom::SearchResultAdEventType::kViewed, + [=](const bool success, const std::string& placement_id, + const mojom::SearchResultAdEventType event_type) { + // Assert + ASSERT_TRUE(success); + + switch (event_type) { + case mojom::SearchResultAdEventType::kServed: { + EXPECT_EQ(1, GetAdEventCount(AdType::kSearchResultAd, + ConfirmationType::kServed)); + EXPECT_EQ(0, GetHistoryItemCount()); + EXPECT_EQ(0, GetTransactionCount()); + break; + } + + case mojom::SearchResultAdEventType::kViewed: { + EXPECT_EQ(1, GetAdEventCount(AdType::kSearchResultAd, + ConfirmationType::kViewed)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); + break; + } + + default: { + NOTREACHED(); + break; + } + } + }); +} + +TEST_F(BatAdsSearchResultAdIntegrationTest, TriggerClickedEvent) { + // Arrange + + // Act + GetAds()->TriggerSearchResultAdEvent( + BuildSearchResultAd(), mojom::SearchResultAdEventType::kClicked, + [=](const bool success, const std::string& placement_id, + const mojom::SearchResultAdEventType event_type) { + // Assert + ASSERT_TRUE(success); + + EXPECT_EQ(mojom::SearchResultAdEventType::kClicked, event_type); + EXPECT_EQ(1, GetAdEventCount(AdType::kSearchResultAd, + ConfirmationType::kClicked)); + EXPECT_EQ(1, GetHistoryItemCount()); + EXPECT_EQ(1, GetTransactionCount()); + }); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/eligible_ads_predictor_util.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/eligible_ads_predictor_util.h index e3f356056517..0fd419a6192b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/eligible_ads_predictor_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/eligible_ads_predictor_util.h @@ -10,11 +10,9 @@ #include "bat/ads/internal/ads/ad_events/ad_event_util.h" #include "bat/ads/internal/ads/serving/choose/ad_predictor_aliases.h" -#include "bat/ads/internal/ads/serving/choose/ad_predictor_info.h" #include "bat/ads/internal/ads/serving/eligible_ads/eligible_ads_aliases.h" #include "bat/ads/internal/ads/serving/eligible_ads/eligible_ads_features.h" #include "bat/ads/internal/ads/serving/targeting/top_segments.h" -#include "bat/ads/internal/ads/serving/targeting/user_model_info.h" #include "bat/ads/internal/base/containers/container_util.h" #include "bat/ads/internal/segments/segments_aliases.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/predict_ad.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/predict_ad.h index 32e5272eae0e..f5907b3c87ff 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/predict_ad.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/predict_ad.h @@ -22,7 +22,7 @@ absl::optional PredictAd(const targeting::UserModelInfo& user_model, const std::vector& creative_ads) { DCHECK(!creative_ads.empty()); - const std::vector& paced_creative_ads = PaceAds(creative_ads); + const std::vector& paced_creative_ads = PaceCreativeAds(creative_ads); CreativeAdPredictorMap creative_ad_predictors; creative_ad_predictors = diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/sample_ads.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/sample_ads.h index a6fa302afbac..a023b9a1c82c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/sample_ads.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/choose/sample_ads.h @@ -11,7 +11,6 @@ #include "base/notreached.h" #include "base/rand_util.h" #include "bat/ads/internal/ads/serving/choose/ad_predictor_aliases.h" -#include "bat/ads/internal/ads/serving/choose/ad_predictor_info.h" #include "bat/ads/internal/base/numbers/number_util.h" #include "third_party/abseil-cpp/absl/types/optional.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.cc deleted file mode 100644 index 56b55f2f35d8..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (c) 2020 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/serving/delivery/notification_ads/notification_ad_delivery.h" - -#include "bat/ads/internal/ads_client_helper.h" -#include "bat/ads/internal/creatives/notification_ads/notification_ad_manager.h" -#include "bat/ads/notification_ad_info.h" - -namespace ads { -namespace notification_ads { - -namespace { - -void DeliverAd(const NotificationAdInfo& ad) { - NotificationAdManager::GetInstance()->PushBack(ad); - - AdsClientHelper::GetInstance()->ShowNotification(ad); -} - -} // namespace - -Delivery::Delivery() = default; - -Delivery::~Delivery() = default; - -bool Delivery::MaybeDeliverAd(const NotificationAdInfo& ad) { - if (!ad.IsValid()) { - return false; - } - - DeliverAd(ad); - - return true; -} - -} // namespace notification_ads -} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.h deleted file mode 100644 index 20bfd0c208a1..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (c) 2020 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_SERVING_DELIVERY_NOTIFICATION_ADS_NOTIFICATION_AD_DELIVERY_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_SERVING_DELIVERY_NOTIFICATION_ADS_NOTIFICATION_AD_DELIVERY_H_ - -namespace ads { - -struct NotificationAdInfo; - -namespace notification_ads { - -class Delivery final { - public: - Delivery(); - ~Delivery(); - - bool MaybeDeliverAd(const NotificationAdInfo& ad); -}; - -} // namespace notification_ads -} // namespace ads - -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_SERVING_DELIVERY_NOTIFICATION_ADS_NOTIFICATION_AD_DELIVERY_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing.h index 5be61f427b69..92da37c6da28 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing.h @@ -16,19 +16,20 @@ namespace ads { struct CreativeAdInfo; template -T PaceAds(const T& ads) { - if (ads.empty()) { +T PaceCreativeAds(const T& creative_ads) { + if (creative_ads.empty()) { return {}; } - T paced_ads; + T paced_creative_ads; - std::copy_if(ads.cbegin(), ads.cend(), std::back_inserter(paced_ads), + std::copy_if(creative_ads.cbegin(), creative_ads.cend(), + std::back_inserter(paced_creative_ads), [](const CreativeAdInfo& creative_ad) { return !ShouldPaceAd(creative_ad); }); - return paced_ads; + return paced_creative_ads; } } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_test.cc deleted file mode 100644 index 30c61d6d03fc..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_test.cc +++ /dev/null @@ -1,341 +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/ads/serving/eligible_ads/eligible_ads_unittest_util.h" -#include "bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_random_util.h" -#include "bat/ads/internal/ads/serving/notification_ad_serving.h" -#include "bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.h" -#include "bat/ads/internal/base/net/http/http_status_code.h" -#include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/base/unittest/unittest_mock_util.h" -#include "bat/ads/internal/base/unittest/unittest_time_util.h" -#include "bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.h" -#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" -#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" -#include "bat/ads/notification_ad_info.h" -#include "url/gurl.h" - -// npm run test -- brave_unit_tests --filter=BatAds* - -using ::testing::_; -using ::testing::AllOf; -using ::testing::Field; -using ::testing::Matcher; - -namespace ads { - -namespace { - -Matcher DoesMatchCreativeInstanceId( - const std::string& creative_instance_id) { - return AllOf(Field("creative_instance_id", - &NotificationAdInfo::creative_instance_id, - creative_instance_id)); -} - -std::vector GetPacingRandomNumberList() { - return std::vector{0.0, 0.5, 0.99}; -} - -} // namespace - -class BatAdsPacingIntegrationTest : public UnitTestBase { - protected: - BatAdsPacingIntegrationTest() - : database_table_( - std::make_unique()) {} - - ~BatAdsPacingIntegrationTest() override = default; - - void SetUp() override { - UnitTestBase::SetUpForTesting(/* is_integration_test */ true); - - ForceUserActivityPermissionRule(); - } - - void SetUpMocks() override { - CopyFileFromTestPathToTempPath("confirmations_with_unblinded_tokens.json", - kConfirmationsFilename); - - const URLEndpointMap endpoints = { - {"/v9/catalog", {{net::HTTP_OK, "/empty_catalog.json"}}}, - {// Get issuers request - R"(/v1/issuers/)", - {{net::HTTP_OK, R"( - { - "ping": 7200000, - "issuers": [ - { - "name": "confirmations", - "publicKeys": [ - { - "publicKey": "JsvJluEN35bJBgJWTdW/8dAgPrrTM1I1pXga+o7cllo=", - "associatedValue": "" - }, - { - "publicKey": "crDVI1R6xHQZ4D9cQu4muVM5MaaM1QcOT4It8Y/CYlw=", - "associatedValue": "" - } - ] - }, - { - "name": "payments", - "publicKeys": [ - { - "publicKey": "JiwFR2EU/Adf1lgox+xqOVPuc6a/rxdy/LguFG5eaXg=", - "associatedValue": "0.0" - }, - { - "publicKey": "bPE1QE65mkIgytffeu7STOfly+x10BXCGuk5pVlOHQU=", - "associatedValue": "0.1" - } - ] - } - ] - } - )"}}}}; - MockUrlRequest(ads_client_mock_, endpoints); - } - - CreativeNotificationAdInfo BuildCreativeNotificationAd1() { - CreativeNotificationAdInfo 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 = GURL("https://brave.com/1"); - CreativeDaypartInfo daypart; - creative_ad.dayparts = {daypart}; - creative_ad.title = "Test Ad 1 Title"; - creative_ad.body = "Test Ad 1 Body"; - - return creative_ad; - } - - CreativeNotificationAdInfo BuildCreativeNotificationAd2() { - CreativeNotificationAdInfo 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 = GURL("https://brave.com/2"); - CreativeDaypartInfo daypart; - creative_ad.dayparts = {daypart}; - creative_ad.title = "Test Ad 2 Title"; - creative_ad.body = "Test Ad 2 Body"; - - return creative_ad; - } - - void ServeAd() { - ResetEligibleAds(AdType::kNotificationAd); - - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - notification_ads::Serving serving(&subdivision_targeting, - &anti_targeting_resource); - - serving.MaybeServeAd(); - } - - void Save(const CreativeNotificationAdList& creative_ads) { - database_table_->Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); - } - - std::unique_ptr database_table_; -}; - -TEST_F(BatAdsPacingIntegrationTest, PacingDisableDelivery) { - // Arrange - CreativeNotificationAdList creative_ads; - - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd1(); - creative_ad.ptr = 0.0; - creative_ads.push_back(creative_ad); - - Save(creative_ads); - - // Act - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)).Times(0); - - for (const double number : GetPacingRandomNumberList()) { - ScopedPacingRandomNumberSetter scoped_setter(number); - ServeAd(); - } - - // Assert -} - -TEST_F(BatAdsPacingIntegrationTest, NoPacing) { - // Arrange - CreativeNotificationAdList creative_ads; - - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd1(); - creative_ad.ptr = 1.0; - creative_ads.push_back(creative_ad); - - Save(creative_ads); - - // Act - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)) - .Times(GetPacingRandomNumberList().size()); - - for (const double number : GetPacingRandomNumberList()) { - ScopedPacingRandomNumberSetter scoped_setter(number); - ServeAd(); - } - - // Assert -} - -TEST_F(BatAdsPacingIntegrationTest, SimplePacing) { - // Arrange - CreativeNotificationAdList creative_ads; - - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd1(); - creative_ad.ptr = 0.5; - creative_ads.push_back(creative_ad); - - Save(creative_ads); - - // Act - { - ScopedPacingRandomNumberSetter scoped_setter(0.7); - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)).Times(0); - ServeAd(); - ::testing::Mock::VerifyAndClearExpectations(ads_client_mock_.get()); - } - - { - ScopedPacingRandomNumberSetter scoped_setter(0.3); - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)); - ServeAd(); - ::testing::Mock::VerifyAndClearExpectations(ads_client_mock_.get()); - } - - // Assert -} - -TEST_F(BatAdsPacingIntegrationTest, NoPacingPrioritized) { - // Arrange - CreativeNotificationAdList creative_ads; - - const CreativeNotificationAdInfo creative_ad_1 = - BuildCreativeNotificationAd1(); - creative_ads.push_back(creative_ad_1); - - const CreativeNotificationAdInfo creative_ad_2 = - BuildCreativeNotificationAd2(); - creative_ads.push_back(creative_ad_2); - - Save(creative_ads); - - // Act - for (const double number : GetPacingRandomNumberList()) { - ScopedPacingRandomNumberSetter scoped_setter(number); - EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_1.creative_instance_id))); - ServeAd(); - ::testing::Mock::VerifyAndClearExpectations(ads_client_mock_.get()); - } - - // Assert -} - -TEST_F(BatAdsPacingIntegrationTest, PacingDisableDeliveryPrioritized) { - // Arrange - CreativeNotificationAdList creative_ads; - - CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd1(); - creative_ad_1.ptr = 0.0; - creative_ads.push_back(creative_ad_1); - - const CreativeNotificationAdInfo creative_ad_2 = - BuildCreativeNotificationAd2(); - creative_ads.push_back(creative_ad_2); - - Save(creative_ads); - - // Act - for (const double number : GetPacingRandomNumberList()) { - ScopedPacingRandomNumberSetter scoped_setter(number); - EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_2.creative_instance_id))); - ServeAd(); - ::testing::Mock::VerifyAndClearExpectations(ads_client_mock_.get()); - } - - // Assert -} - -TEST_F(BatAdsPacingIntegrationTest, PacingAndPrioritization) { - // Arrange - CreativeNotificationAdList creative_ads; - - CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd1(); - creative_ad_1.ptr = 0.4; - creative_ads.push_back(creative_ad_1); - - CreativeNotificationAdInfo creative_ad_2 = BuildCreativeNotificationAd2(); - creative_ad_2.ptr = 0.6; - creative_ads.push_back(creative_ad_2); - - Save(creative_ads); - - // Act - { - ScopedPacingRandomNumberSetter scoped_setter(0.1); - EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_1.creative_instance_id))); - ServeAd(); - ::testing::Mock::VerifyAndClearExpectations(ads_client_mock_.get()); - } - - { - ScopedPacingRandomNumberSetter scoped_setter(0.5); - EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_2.creative_instance_id))); - ServeAd(); - ::testing::Mock::VerifyAndClearExpectations(ads_client_mock_.get()); - } - - { - ScopedPacingRandomNumberSetter scoped_setter(0.8); - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)).Times(0); - ServeAd(); - ::testing::Mock::VerifyAndClearExpectations(ads_client_mock_.get()); - } - - // Assert -} - -} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_unittest.cc new file mode 100644 index 000000000000..8d1282453704 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_unittest.cc @@ -0,0 +1,106 @@ +/* Copyright (c) 2022 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/serving/eligible_ads/pacing/pacing.h" + +#include + +#include "bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_random_util.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_info.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_info_aliases.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" +#include "testing/gtest/include/gtest/gtest.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +namespace { + +std::vector GetPacingRandomNumbers() { + return std::vector{0.0, 0.5, 0.99}; +} + +} // namespace + +TEST(BatAdsPacingTest, PaceCreativeAdsWithMinPassThroughRate) { + // Arrange + CreativeNotificationAdList creative_ads; + CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); + creative_ad.ptr = 0.0; + creative_ads.push_back(creative_ad); + + // Act + for (const double number : GetPacingRandomNumbers()) { + ScopedPacingRandomNumberSetter scoped_setter(number); + const CreativeNotificationAdList paced_creative_ads = + PaceCreativeAds(creative_ads); + + // Assert + EXPECT_TRUE(paced_creative_ads.empty()); + } +} + +TEST(BatAdsPacingTest, DoNotPaceCreativeAdsWithMaxPassThroughRate) { + // Arrange + CreativeNotificationAdList creative_ads; + CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); + creative_ad.ptr = 1.0; + creative_ads.push_back(creative_ad); + + // Act + for (const double number : GetPacingRandomNumbers()) { + ScopedPacingRandomNumberSetter scoped_setter(number); + const CreativeNotificationAdList paced_creative_ads = + PaceCreativeAds(creative_ads); + + // Assert + const CreativeNotificationAdList expected_paced_creative_ads = { + creative_ad}; + EXPECT_EQ(expected_paced_creative_ads, paced_creative_ads); + } +} + +TEST(BatAdsPacingTest, + PaceCreativeAdIfPacingIsGreaterThanOrEqualToPassThroughRate) { + // Arrange + CreativeNotificationAdList creative_ads; + CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); + creative_ad.ptr = 0.5; + creative_ads.push_back(creative_ad); + + // Act + ScopedPacingRandomNumberSetter scoped_setter(0.7); + const CreativeNotificationAdList paced_creative_ads = + PaceCreativeAds(creative_ads); + + // Assert + EXPECT_TRUE(paced_creative_ads.empty()); +} + +TEST(BatAdsPacingTest, DoNotPaceCreativeAdWhenPacingIsLessThanPassThroughRate) { + // Arrange + CreativeNotificationAdList creative_ads; + + CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd(); + creative_ad_1.ptr = 0.1; + creative_ads.push_back(creative_ad_1); + + CreativeNotificationAdInfo creative_ad_2 = BuildCreativeNotificationAd(); + creative_ad_2.ptr = 0.5; + creative_ads.push_back(creative_ad_2); + + // Act + ScopedPacingRandomNumberSetter scoped_setter(0.3); + const CreativeNotificationAdList paced_creative_ads = + PaceCreativeAds(creative_ads); + + // Assert + const CreativeNotificationAdList expected_paced_creative_ads = { + creative_ad_2}; + EXPECT_EQ(expected_paced_creative_ads, paced_creative_ads); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1.cc index 70c3d5d57499..694798e18ba9 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1.cc @@ -100,7 +100,7 @@ void EligibleAdsV1::GetForChildSegments( return; } - const CreativeInlineContentAdList& eligible_creative_ads = + const CreativeInlineContentAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() @@ -146,7 +146,7 @@ void EligibleAdsV1::GetForParentSegments( return; } - const CreativeInlineContentAdList& eligible_creative_ads = + const CreativeInlineContentAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() @@ -181,17 +181,19 @@ void EligibleAdsV1::GetForUntargeted( return; } - const CreativeInlineContentAdList& eligible_creative_ads = + const CreativeInlineContentAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads for untargeted segment"); - } else { - BLOG(1, eligible_creative_ads.size() - << " eligible ads out of " << creative_ads.size() - << " ads for untargeted segment"); + callback(/* had_opportunity */ false, {}); + return; } + BLOG(1, eligible_creative_ads.size() + << " eligible ads out of " << creative_ads.size() + << " ads for untargeted segment"); + callback(/* had_opportunity */ true, eligible_creative_ads); }); } @@ -217,9 +219,9 @@ CreativeInlineContentAdList EligibleAdsV1::FilterCreativeAds( eligible_creative_ads = FilterSeenAdsAndRoundRobinIfNeeded( eligible_creative_ads, AdType::kInlineContentAd); - eligible_creative_ads = PaceAds(eligible_creative_ads); + eligible_creative_ads = PaceCreativeAds(eligible_creative_ads); - eligible_creative_ads = PrioritizeAds(eligible_creative_ads); + eligible_creative_ads = PrioritizeCreativeAds(eligible_creative_ads); return eligible_creative_ads; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc index 7db8feec63bb..3ed8d8a19e6a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1_unittest.cc @@ -7,12 +7,14 @@ #include +#include "bat/ads/inline_content_ad_info.h" +#include "bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_random_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_builder_unittest_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_info.h" #include "bat/ads/internal/base/containers/container_util.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.h" -#include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h" +#include "bat/ads/internal/creatives/inline_content_ads/inline_content_ad_builder.h" #include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" @@ -23,18 +25,23 @@ namespace inline_content_ads { class BatAdsEligibleInlineContentAdsV1Test : public UnitTestBase { protected: - BatAdsEligibleInlineContentAdsV1Test() - : database_table_( - std::make_unique()) {} + BatAdsEligibleInlineContentAdsV1Test() = default; ~BatAdsEligibleInlineContentAdsV1Test() override = default; - void Save(const CreativeInlineContentAdList& creative_ads) { - database_table_->Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); + void SetUp() override { + UnitTestBase::SetUp(); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + eligible_ads_ = std::make_unique( + subdivision_targeting_.get(), anti_targeting_resource_.get()); } - std::unique_ptr database_table_; + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr eligible_ads_; }; TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForChildSegment) { @@ -49,79 +56,66 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForChildSegment) { creative_ad_2.segment = "technology & computing-software"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeInlineContentAdList expected_creative_ads = {creative_ad_2}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing-software"}, {}, {}), "200x100", [&expected_creative_ads]( - const bool success, const CreativeInlineContentAdList& creative_ads) { + const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForParentSegment) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeInlineContentAdList expected_creative_ads = {creative_ad}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing-software"}, {}, {}), "200x100", [&expected_creative_ads]( - const bool success, const CreativeInlineContentAdList& creative_ads) { + const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForUntargetedSegment) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeInlineContentAdList expected_creative_ads = {creative_ad}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"finance-banking"}, {}, {}), "200x100", [&expected_creative_ads]( - const bool success, const CreativeInlineContentAdList& creative_ads) { + const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForMultipleSegments) { @@ -140,107 +134,188 @@ TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForMultipleSegments) { creative_ad_3.segment = "food & drink"; creative_ads.push_back(creative_ad_3); - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeInlineContentAdList expected_creative_ads = {creative_ad_1, creative_ad_3}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, {}), "200x100", [&expected_creative_ads]( - const bool success, const CreativeInlineContentAdList& creative_ads) { + const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); - - // Assert } TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForNoSegments) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeInlineContentAdList expected_creative_ads = {creative_ad}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( {}, "200x100", [&expected_creative_ads]( - const bool success, const CreativeInlineContentAdList& creative_ads) { + const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } -TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForUnmatchedSegments) { +TEST_F(BatAdsEligibleInlineContentAdsV1Test, DoNotGetAdsForUnmatchedSegments) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); - Save(creative_ads); + // Act + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"UNMATCHED"}, {}, {}), "200x100", + [](const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); + }); +} + +TEST_F(BatAdsEligibleInlineContentAdsV1Test, + DoNotGetAdsForNonExistentDimensions) { + // Arrange + CreativeInlineContentAdList creative_ads; + CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); + creative_ad.segment = "technology & computing"; + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing"}, {}, {}), "?x?", + [](const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); + }); +} - const CreativeInlineContentAdList expected_creative_ads = {}; +TEST_F(BatAdsEligibleInlineContentAdsV1Test, DoNotGetAdsIfAlreadySeen) { + // Arrange + CreativeInlineContentAdList creative_ads; - eligible_ads.GetForUserModel( - targeting::BuildUserModel({"UNMATCHED"}, {}, {}), "200x100", + CreativeInlineContentAdInfo creative_ad_1 = BuildCreativeInlineContentAd(); + creative_ad_1.segment = "technology & computing"; + creative_ads.push_back(creative_ad_1); + + CreativeInlineContentAdInfo creative_ad_2 = BuildCreativeInlineContentAd(); + creative_ad_2.segment = "food & drink"; + creative_ads.push_back(creative_ad_2); + + SaveCreativeAds(creative_ads); + + const InlineContentAdInfo ad = BuildInlineContentAd(creative_ad_1); + ClientStateManager::GetInstance()->UpdateSeenAd(ad); + + // Act + const CreativeInlineContentAdList expected_creative_ads = {creative_ad_2}; + + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + "200x100", [&expected_creative_ads]( - const bool success, const CreativeInlineContentAdList& creative_ads) { + const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } -TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetAdsForUnmatchedDimensions) { +TEST_F(BatAdsEligibleInlineContentAdsV1Test, DoNotGetPacedAds) { // Arrange CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); - creative_ad.segment = "technology & computing"; - creative_ads.push_back(creative_ad); + CreativeInlineContentAdInfo creative_ad_1 = BuildCreativeInlineContentAd(); + creative_ad_1.segment = "technology & computing"; + creative_ad_1.ptr = 0.1; + creative_ads.push_back(creative_ad_1); - Save(creative_ads); + CreativeInlineContentAdInfo creative_ad_2 = BuildCreativeInlineContentAd(); + creative_ad_2.segment = "food & drink"; + creative_ad_2.ptr = 0.5; + creative_ads.push_back(creative_ad_2); + + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); + ScopedPacingRandomNumberSetter scoped_setter(0.3); - const CreativeInlineContentAdList expected_creative_ads = {}; + const CreativeInlineContentAdList expected_creative_ads = {creative_ad_2}; - eligible_ads.GetForUserModel( - targeting::BuildUserModel({"technology & computing"}, {}, {}), "?x?", + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + "200x100", [&expected_creative_ads]( - const bool success, const CreativeInlineContentAdList& creative_ads) { + const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); +} + +TEST_F(BatAdsEligibleInlineContentAdsV1Test, GetPrioritizedAds) { + // Arrange + CreativeInlineContentAdList creative_ads; + + CreativeInlineContentAdInfo creative_ad_1 = BuildCreativeInlineContentAd(); + creative_ad_1.segment = "technology & computing"; + creative_ad_1.priority = 1; + creative_ads.push_back(creative_ad_1); + + CreativeInlineContentAdInfo creative_ad_2 = BuildCreativeInlineContentAd(); + creative_ad_2.segment = "finance-banking"; + creative_ad_2.priority = 1; + creative_ads.push_back(creative_ad_2); + + CreativeInlineContentAdInfo creative_ad_3 = BuildCreativeInlineContentAd(); + creative_ad_3.segment = "food & drink"; + creative_ad_3.priority = 2; + creative_ads.push_back(creative_ad_3); + + SaveCreativeAds(creative_ads); - // Assert + // Act + const CreativeInlineContentAdList expected_creative_ads = {creative_ad_1}; + + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + "200x100", + [&expected_creative_ads]( + const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); + EXPECT_EQ(expected_creative_ads, creative_ads); + }); } } // namespace inline_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2.cc index 32f13d676fc1..d2ccbc9335a0 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2.cc @@ -76,26 +76,33 @@ void EligibleAdsV2::GetEligibleAds( return; } - const CreativeInlineContentAdList& eligible_creative_ads = + if (creative_ads.empty()) { + BLOG(1, "No eligible ads"); + callback(/* had_opportunity */ false, {}); + return; + } + + const CreativeInlineContentAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { - BLOG(1, "No eligible ads"); + BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads"); callback(/* had_opportunity */ true, {}); return; } - const absl::optional& - creative_ad_optional = - PredictAd(user_model, ad_events, eligible_creative_ads); + const absl::optional creative_ad_optional = + PredictAd(user_model, ad_events, eligible_creative_ads); if (!creative_ad_optional) { - BLOG(1, "No eligible ads"); + BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads"); callback(/* had_opportunity */ true, {}); return; } - const CreativeInlineContentAdInfo& creative_ad = creative_ad_optional.value(); + BLOG(1, eligible_creative_ads.size() << " eligible ads out of " + << creative_ads.size() << " ads"); + callback(/* had_opportunity */ true, {creative_ad}); }); } @@ -110,7 +117,7 @@ CreativeInlineContentAdList EligibleAdsV2::FilterCreativeAds( ExclusionRules exclusion_rules(ad_events, subdivision_targeting_, anti_targeting_resource_, browsing_history); - const CreativeInlineContentAdList& eligible_creative_ads = + const CreativeInlineContentAdList eligible_creative_ads = ApplyExclusionRules(creative_ads, last_served_ad_, &exclusion_rules); return eligible_creative_ads; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc index 4e0e5c0aa30b..1b13eaeb2de6 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v2_unittest.cc @@ -7,11 +7,13 @@ #include +#include "bat/ads/inline_content_ad_info.h" +#include "bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_random_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_builder_unittest_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_info.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.h" -#include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h" +#include "bat/ads/internal/creatives/inline_content_ads/inline_content_ad_builder.h" #include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" @@ -22,18 +24,23 @@ namespace inline_content_ads { class BatAdsEligibleInlineContentAdsV2Test : public UnitTestBase { protected: - BatAdsEligibleInlineContentAdsV2Test() - : database_table_( - std::make_unique()) {} + BatAdsEligibleInlineContentAdsV2Test() = default; ~BatAdsEligibleInlineContentAdsV2Test() override = default; - void Save(const CreativeInlineContentAdList& creative_ads) { - database_table_->Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); + void SetUp() override { + UnitTestBase::SetUp(); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + eligible_ads_ = std::make_unique( + subdivision_targeting_.get(), anti_targeting_resource_.get()); } - std::unique_ptr database_table_; + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr eligible_ads_; }; TEST_F(BatAdsEligibleInlineContentAdsV2Test, GetAds) { @@ -48,27 +55,18 @@ TEST_F(BatAdsEligibleInlineContentAdsV2Test, GetAds) { creative_ad_2.segment = "foo-bar3"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); - - const SegmentList interest_segments = {"foo-bar3"}; - const SegmentList latent_interest_segments = {}; - const SegmentList purchase_intent_segments = {"foo-bar1", "foo-bar2"}; + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"foo-bar3"}, {}, {"foo-bar1", "foo-bar2"}), "200x100", [](const bool had_opportunity, const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(!creative_ads.empty()); }); - - // Assert } TEST_F(BatAdsEligibleInlineContentAdsV2Test, GetAdsForNoSegments) { @@ -83,53 +81,50 @@ TEST_F(BatAdsEligibleInlineContentAdsV2Test, GetAdsForNoSegments) { creative_ad_2.segment = "foo-bar"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); - - const SegmentList interest_segments = {}; - const SegmentList latent_interest_segments = {}; - const SegmentList purchase_intent_segments = {}; + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), - "200x100", + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({}, {}, {}), "200x100", [](const bool had_opportunity, const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(!creative_ads.empty()); }); - - // Assert } -TEST_F(BatAdsEligibleInlineContentAdsV2Test, GetIfNoEligibleAds) { +TEST_F(BatAdsEligibleInlineContentAdsV2Test, + DoNotGetAdsForNonExistentDimensions) { // Arrange - const SegmentList interest_segments = {"interest-foo", "interest-bar"}; - const SegmentList latent_interest_segments = {}; - const SegmentList purchase_intent_segments = {"intent-foo", "intent-bar"}; // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"interest-foo", "interest-bar"}, {}, + {"intent-foo", "intent-bar"}), + "?x?", + [](const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); + }); +} - const CreativeInlineContentAdList expected_creative_ads = {}; +TEST_F(BatAdsEligibleInlineContentAdsV2Test, DoNotGetAdsIfNoEligibleAds) { + // Arrange - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), + // Act + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"interest-foo", "interest-bar"}, {}, + {"intent-foo", "intent-bar"}), "200x100", - [&expected_creative_ads]( - const bool had_opportunity, - const CreativeInlineContentAdList& creative_ads) { - EXPECT_EQ(expected_creative_ads, creative_ads); + [](const bool had_opportunity, + const CreativeInlineContentAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); }); - - // Assert } } // namespace inline_content_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1.cc index 0fa5bdf5c9e2..7f0ad2bf6a05 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1.cc @@ -93,7 +93,7 @@ void EligibleAdsV1::GetForChildSegments( return; } - const CreativeNewTabPageAdList& eligible_creative_ads = + const CreativeNewTabPageAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() @@ -137,7 +137,7 @@ void EligibleAdsV1::GetForParentSegments( return; } - const CreativeNewTabPageAdList& eligible_creative_ads = + const CreativeNewTabPageAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() @@ -170,15 +170,13 @@ void EligibleAdsV1::GetForUntargeted( return; } - const CreativeNewTabPageAdList& eligible_creative_ads = + const CreativeNewTabPageAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads for untargeted segment"); - } else { - BLOG(1, eligible_creative_ads.size() - << " eligible ads out of " << creative_ads.size() - << " ads for untargeted segment"); + callback(/* had_opportunity */ false, {}); + return; } callback(/* had_opportunity */ true, eligible_creative_ads); @@ -206,9 +204,9 @@ CreativeNewTabPageAdList EligibleAdsV1::FilterCreativeAds( eligible_creative_ads = FilterSeenAdsAndRoundRobinIfNeeded( eligible_creative_ads, AdType::kNewTabPageAd); - eligible_creative_ads = PaceAds(eligible_creative_ads); + eligible_creative_ads = PaceCreativeAds(eligible_creative_ads); - eligible_creative_ads = PrioritizeAds(eligible_creative_ads); + eligible_creative_ads = PrioritizeCreativeAds(eligible_creative_ads); return eligible_creative_ads; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1_unittest.cc index be20ef980213..615dd15b7a51 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1_unittest.cc @@ -7,14 +7,16 @@ #include +#include "bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_random_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_builder_unittest_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_info.h" #include "bat/ads/internal/base/containers/container_util.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.h" -#include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.h" +#include "bat/ads/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" #include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" +#include "bat/ads/new_tab_page_ad_info.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -23,18 +25,23 @@ namespace new_tab_page_ads { class BatAdsEligibleNewTabPageAdsV1Test : public UnitTestBase { protected: - BatAdsEligibleNewTabPageAdsV1Test() - : database_table_( - std::make_unique()) {} + BatAdsEligibleNewTabPageAdsV1Test() = default; ~BatAdsEligibleNewTabPageAdsV1Test() override = default; - void Save(const CreativeNewTabPageAdList& creative_ads) { - database_table_->Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); + void SetUp() override { + UnitTestBase::SetUp(); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + eligible_ads_ = std::make_unique( + subdivision_targeting_.get(), anti_targeting_resource_.get()); } - std::unique_ptr database_table_; + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr eligible_ads_; }; TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetAdsForChildSegment) { @@ -49,77 +56,61 @@ TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetAdsForChildSegment) { creative_ad_2.segment = "technology & computing-software"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - const CreativeNewTabPageAdList& expected_creative_ads = {creative_ad_2}; + const CreativeNewTabPageAdList expected_creative_ads = {creative_ad_2}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing-software"}, {}, {}), - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetAdsForParentSegment) { // Arrange CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - const CreativeNewTabPageAdList& expected_creative_ads = {creative_ad}; + const CreativeNewTabPageAdList expected_creative_ads = {creative_ad}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing-software"}, {}, {}), - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetAdsForUntargetedSegment) { // Arrange CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); + const CreativeNewTabPageAdList expected_creative_ads = {creative_ad}; - const CreativeNewTabPageAdList& expected_creative_ads = {creative_ad}; - - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"finance-banking"}, {}, {}), - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetAdsForMultipleSegments) { @@ -138,79 +129,174 @@ TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetAdsForMultipleSegments) { creative_ad_3.segment = "food & drink"; creative_ads.push_back(creative_ad_3); - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - const CreativeNewTabPageAdList& expected_creative_ads = {creative_ad_1, - creative_ad_3}; + const CreativeNewTabPageAdList expected_creative_ads = {creative_ad_1, + creative_ad_3}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, {}), - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); - - // Assert } TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetAdsForNoSegments) { // Arrange CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); + const CreativeNewTabPageAdList expected_creative_ads = {creative_ad}; - const CreativeNewTabPageAdList& expected_creative_ads = {creative_ad}; - - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( {}, - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } -TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetAdsForUnmatchedSegments) { +TEST_F(BatAdsEligibleNewTabPageAdsV1Test, DoNotGetAdsForUnmatchedSegments) { // Arrange CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); - Save(creative_ads); + // Act + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"UNMATCHED"}, {}, {}), + [](const bool had_opportunity, + const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); + }); +} + +TEST_F(BatAdsEligibleNewTabPageAdsV1Test, DoNotGetAdsIfNoEligibleAds) { + // Arrange // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + [](const bool had_opportunity, + const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); + }); +} - const CreativeNewTabPageAdList expected_creative_ads; +TEST_F(BatAdsEligibleNewTabPageAdsV1Test, DoNotGetAdsIfAlreadySeen) { + // Arrange + CreativeNewTabPageAdList creative_ads; - eligible_ads.GetForUserModel( - targeting::BuildUserModel({"UNMATCHED"}, {}, {}), - [&expected_creative_ads](const bool success, + CreativeNewTabPageAdInfo creative_ad_1 = BuildCreativeNewTabPageAd(); + creative_ad_1.segment = "technology & computing"; + creative_ads.push_back(creative_ad_1); + + CreativeNewTabPageAdInfo creative_ad_2 = BuildCreativeNewTabPageAd(); + creative_ad_2.segment = "food & drink"; + creative_ads.push_back(creative_ad_2); + + SaveCreativeAds(creative_ads); + + const NewTabPageAdInfo ad = BuildNewTabPageAd(creative_ad_1); + ClientStateManager::GetInstance()->UpdateSeenAd(ad); + + // Act + const CreativeNewTabPageAdList expected_creative_ads = {creative_ad_2}; + + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + [&expected_creative_ads](const bool had_opportunity, const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); +} - // Assert +TEST_F(BatAdsEligibleNewTabPageAdsV1Test, DoNotGetPacedAds) { + // Arrange + CreativeNewTabPageAdList creative_ads; + + CreativeNewTabPageAdInfo creative_ad_1 = BuildCreativeNewTabPageAd(); + creative_ad_1.segment = "technology & computing"; + creative_ad_1.ptr = 0.1; + creative_ads.push_back(creative_ad_1); + + CreativeNewTabPageAdInfo creative_ad_2 = BuildCreativeNewTabPageAd(); + creative_ad_2.segment = "food & drink"; + creative_ad_2.ptr = 0.5; + creative_ads.push_back(creative_ad_2); + + SaveCreativeAds(creative_ads); + + // Act + ScopedPacingRandomNumberSetter scoped_setter(0.3); + + const CreativeNewTabPageAdList expected_creative_ads = {creative_ad_2}; + + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + [&expected_creative_ads](const bool had_opportunity, + const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); + EXPECT_EQ(expected_creative_ads, creative_ads); + }); +} + +TEST_F(BatAdsEligibleNewTabPageAdsV1Test, GetPrioritizedAds) { + // Arrange + CreativeNewTabPageAdList creative_ads; + + CreativeNewTabPageAdInfo creative_ad_1 = BuildCreativeNewTabPageAd(); + creative_ad_1.segment = "technology & computing"; + creative_ad_1.priority = 1; + creative_ads.push_back(creative_ad_1); + + CreativeNewTabPageAdInfo creative_ad_2 = BuildCreativeNewTabPageAd(); + creative_ad_2.segment = "finance-banking"; + creative_ad_2.priority = 1; + creative_ads.push_back(creative_ad_2); + + CreativeNewTabPageAdInfo creative_ad_3 = BuildCreativeNewTabPageAd(); + creative_ad_3.segment = "food & drink"; + creative_ad_3.priority = 2; + creative_ads.push_back(creative_ad_3); + + SaveCreativeAds(creative_ads); + + // Act + const CreativeNewTabPageAdList expected_creative_ads = {creative_ad_1}; + + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + [&expected_creative_ads](const bool had_opportunity, + const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); + EXPECT_EQ(expected_creative_ads, creative_ads); + }); } } // namespace new_tab_page_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2.cc index a4a6782cf1a1..63c21513413b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2.cc @@ -72,24 +72,32 @@ void EligibleAdsV2::GetEligibleAds( return; } - const CreativeNewTabPageAdList& eligible_creative_ads = + if (creative_ads.empty()) { + BLOG(1, "No eligible ads"); + callback(/* had_opportunity */ false, {}); + return; + } + + const CreativeNewTabPageAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { - BLOG(1, "No eligible ads"); + BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads"); callback(/* had_opportunity */ true, {}); return; } - const absl::optional& creative_ad_optional = + const absl::optional creative_ad_optional = PredictAd(user_model, ad_events, eligible_creative_ads); if (!creative_ad_optional) { - BLOG(1, "No eligible ads"); + BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads"); callback(/* had_opportunity */ true, {}); return; } - const CreativeNewTabPageAdInfo& creative_ad = creative_ad_optional.value(); + BLOG(1, eligible_creative_ads.size() + << " eligible ads out of " << creative_ads.size() << " ads"); + callback(/* had_opportunity */ true, {creative_ad}); }); } @@ -104,7 +112,7 @@ CreativeNewTabPageAdList EligibleAdsV2::FilterCreativeAds( ExclusionRules exclusion_rules(ad_events, subdivision_targeting_, anti_targeting_resource_, browsing_history); - const CreativeNewTabPageAdList& eligible_creative_ads = + const CreativeNewTabPageAdList eligible_creative_ads = ApplyExclusionRules(creative_ads, last_served_ad_, &exclusion_rules); return eligible_creative_ads; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2_unittest.cc index efcb8acca72f..d9991ef0cd7c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2_unittest.cc @@ -7,13 +7,15 @@ #include +#include "bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_random_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_builder_unittest_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_info.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.h" -#include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.h" +#include "bat/ads/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" #include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" +#include "bat/ads/new_tab_page_ad_info.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -22,18 +24,23 @@ namespace new_tab_page_ads { class BatAdsEligibleNewTabPageAdsV2Test : public UnitTestBase { protected: - BatAdsEligibleNewTabPageAdsV2Test() - : database_table_( - std::make_unique()) {} + BatAdsEligibleNewTabPageAdsV2Test() = default; ~BatAdsEligibleNewTabPageAdsV2Test() override = default; - void Save(const CreativeNewTabPageAdList& creative_ads) { - database_table_->Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); + void SetUp() override { + UnitTestBase::SetUp(); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + eligible_ads_ = std::make_unique( + subdivision_targeting_.get(), anti_targeting_resource_.get()); } - std::unique_ptr database_table_; + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr eligible_ads_; }; TEST_F(BatAdsEligibleNewTabPageAdsV2Test, GetAds) { @@ -48,26 +55,17 @@ TEST_F(BatAdsEligibleNewTabPageAdsV2Test, GetAds) { creative_ad_2.segment = "foo-bar3"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); - - const SegmentList& interest_segments = {"foo-bar3"}; - const SegmentList latent_interest_segments; - const SegmentList& purchase_intent_segments = {"foo-bar1", "foo-bar2"}; + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"foo-bar3"}, {}, {"foo-bar1", "foo-bar2"}), [](const bool had_opportunity, const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(!creative_ads.empty()); }); - - // Assert } TEST_F(BatAdsEligibleNewTabPageAdsV2Test, GetAdsForNoSegments) { @@ -82,50 +80,32 @@ TEST_F(BatAdsEligibleNewTabPageAdsV2Test, GetAdsForNoSegments) { creative_ad_2.segment = "foo-bar"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); - - const SegmentList interest_segments; - const SegmentList latent_interest_segments; - const SegmentList purchase_intent_segments; + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({}, {}, {}), [](const bool had_opportunity, const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(!creative_ads.empty()); }); - - // Assert } -TEST_F(BatAdsEligibleNewTabPageAdsV2Test, GetIfNoEligibleAds) { +TEST_F(BatAdsEligibleNewTabPageAdsV2Test, DoNotGetAdsIfNoEligibleAds) { // Arrange - const SegmentList& interest_segments = {"interest-foo", "interest-bar"}; - const SegmentList latent_interest_segments; - const SegmentList& purchase_intent_segments = {"intent-foo", "intent-bar"}; // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - const CreativeNewTabPageAdList expected_creative_ads; - - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), - [&expected_creative_ads](const bool had_opportunity, - const CreativeNewTabPageAdList& creative_ads) { - EXPECT_EQ(expected_creative_ads, creative_ads); + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"interest-foo", "interest-bar"}, {}, + {"intent-foo", "intent-bar"}), + [](const bool had_opportunity, + const CreativeNewTabPageAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); }); - - // Assert } } // namespace new_tab_page_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1.cc index 2ba971a225c9..6592d0e7ab71 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1.cc @@ -93,7 +93,7 @@ void EligibleAdsV1::GetForChildSegments( return; } - const CreativeNotificationAdList& eligible_creative_ads = + const CreativeNotificationAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() @@ -137,7 +137,7 @@ void EligibleAdsV1::GetForParentSegments( return; } - const CreativeNotificationAdList& eligible_creative_ads = + const CreativeNotificationAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() @@ -170,17 +170,19 @@ void EligibleAdsV1::GetForUntargeted( return; } - const CreativeNotificationAdList& eligible_creative_ads = + const CreativeNotificationAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads for untargeted segment"); - } else { - BLOG(1, eligible_creative_ads.size() - << " eligible ads out of " << creative_ads.size() - << " ads for untargeted segment"); + callback(/* had_opportunity */ false, {}); + return; } + BLOG(1, eligible_creative_ads.size() + << " eligible ads out of " << creative_ads.size() + << " ads for untargeted segment"); + callback(/* had_opportunity */ true, eligible_creative_ads); }); } @@ -206,9 +208,9 @@ CreativeNotificationAdList EligibleAdsV1::FilterCreativeAds( eligible_creative_ads = FilterSeenAdsAndRoundRobinIfNeeded( eligible_creative_ads, AdType::kNotificationAd); - eligible_creative_ads = PaceAds(eligible_creative_ads); + eligible_creative_ads = PaceCreativeAds(eligible_creative_ads); - eligible_creative_ads = PrioritizeAds(eligible_creative_ads); + eligible_creative_ads = PrioritizeCreativeAds(eligible_creative_ads); return eligible_creative_ads; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_issue_17199_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_issue_17199_unittest.cc index bf1f93afa33f..ef85d99ed10e 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_issue_17199_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_issue_17199_unittest.cc @@ -43,8 +43,9 @@ TEST_F(BatAdsEligibleNotificationAdsV1Issue17199Test, GetEligibleAds) { eligible_ads.GetForUserModel( targeting::BuildUserModel({"technology & computing-computing"}, {}, {}), - [](const bool success, const CreativeNotificationAdList& creative_ads) { - EXPECT_TRUE(success); + [](const bool had_opportunity, + const CreativeNotificationAdList& creative_ads) { + EXPECT_TRUE(had_opportunity); EXPECT_FALSE(creative_ads.empty()); }); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_unittest.cc index 403b03ee8b44..04e7bb0fb917 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1_unittest.cc @@ -7,14 +7,16 @@ #include +#include "bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_random_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_builder_unittest_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_info.h" #include "bat/ads/internal/base/containers/container_util.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" -#include "bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.h" +#include "bat/ads/internal/creatives/notification_ads/notification_ad_builder.h" #include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" +#include "bat/ads/notification_ad_info.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -23,18 +25,23 @@ namespace notification_ads { class BatAdsEligibleNotificationAdsV1Test : public UnitTestBase { protected: - BatAdsEligibleNotificationAdsV1Test() - : database_table_( - std::make_unique()) {} + BatAdsEligibleNotificationAdsV1Test() = default; ~BatAdsEligibleNotificationAdsV1Test() override = default; - void Save(const CreativeNotificationAdList& creative_ads) { - database_table_->Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); + void SetUp() override { + UnitTestBase::SetUp(); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + eligible_ads_ = std::make_unique( + subdivision_targeting_.get(), anti_targeting_resource_.get()); } - std::unique_ptr database_table_; + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr eligible_ads_; }; TEST_F(BatAdsEligibleNotificationAdsV1Test, GetAdsForChildSegment) { @@ -49,77 +56,61 @@ TEST_F(BatAdsEligibleNotificationAdsV1Test, GetAdsForChildSegment) { creative_ad_2.segment = "technology & computing-software"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeNotificationAdList expected_creative_ads = {creative_ad_2}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing-software"}, {}, {}), - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleNotificationAdsV1Test, GetAdsForParentSegment) { // Arrange CreativeNotificationAdList creative_ads; - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeNotificationAdList expected_creative_ads = {creative_ad}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing-software"}, {}, {}), - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleNotificationAdsV1Test, GetAdsForUntargetedSegment) { // Arrange CreativeNotificationAdList creative_ads; - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeNotificationAdList expected_creative_ads = {creative_ad}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"finance-banking"}, {}, {}), - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } TEST_F(BatAdsEligibleNotificationAdsV1Test, GetAdsForMultipleSegments) { @@ -138,79 +129,174 @@ TEST_F(BatAdsEligibleNotificationAdsV1Test, GetAdsForMultipleSegments) { creative_ad_3.segment = "food & drink"; creative_ads.push_back(creative_ad_3); - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeNotificationAdList expected_creative_ads = {creative_ad_1, creative_ad_3}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, {}), - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(CompareAsSets(expected_creative_ads, creative_ads)); }); - - // Assert } TEST_F(BatAdsEligibleNotificationAdsV1Test, GetAdsForNoSegments) { // Arrange CreativeNotificationAdList creative_ads; - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); creative_ad.segment = "untargeted"; creative_ads.push_back(creative_ad); - - Save(creative_ads); + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - const CreativeNotificationAdList expected_creative_ads = {creative_ad}; - eligible_ads.GetForUserModel( + eligible_ads_->GetForUserModel( {}, - [&expected_creative_ads](const bool success, + [&expected_creative_ads](const bool had_opportunity, const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); - - // Assert } -TEST_F(BatAdsEligibleNotificationAdsV1Test, GetAdsForUnmatchedSegments) { +TEST_F(BatAdsEligibleNotificationAdsV1Test, DoNotGetAdsForUnmatchedSegments) { // Arrange CreativeNotificationAdList creative_ads; - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); creative_ad.segment = "technology & computing"; creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"UNMATCHED"}, {}, {}), + [](const bool had_opportunity, + const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); + }); +} - Save(creative_ads); +TEST_F(BatAdsEligibleNotificationAdsV1Test, DoNotGetAdsIfNoEligibleAds) { + // Arrange // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV1 eligible_ads(&subdivision_targeting, &anti_targeting_resource); + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + [](const bool had_opportunity, + const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); + }); +} + +TEST_F(BatAdsEligibleNotificationAdsV1Test, DoNotGetAdsIfAlreadySeen) { + // Arrange + CreativeNotificationAdList creative_ads; - const CreativeNotificationAdList expected_creative_ads = {}; + CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd(); + creative_ad_1.segment = "technology & computing"; + creative_ads.push_back(creative_ad_1); - eligible_ads.GetForUserModel( - targeting::BuildUserModel({"UNMATCHED"}, {}, {}), - [&expected_creative_ads](const bool success, + CreativeNotificationAdInfo creative_ad_2 = BuildCreativeNotificationAd(); + creative_ad_2.segment = "food & drink"; + creative_ads.push_back(creative_ad_2); + + SaveCreativeAds(creative_ads); + + const NotificationAdInfo ad = BuildNotificationAd(creative_ad_1); + ClientStateManager::GetInstance()->UpdateSeenAd(ad); + + // Act + const CreativeNotificationAdList expected_creative_ads = {creative_ad_2}; + + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + [&expected_creative_ads](const bool had_opportunity, const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_EQ(expected_creative_ads, creative_ads); }); +} - // Assert +TEST_F(BatAdsEligibleNotificationAdsV1Test, DoNotGetPacedAds) { + // Arrange + CreativeNotificationAdList creative_ads; + + CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd(); + creative_ad_1.segment = "technology & computing"; + creative_ad_1.ptr = 0.1; + creative_ads.push_back(creative_ad_1); + + CreativeNotificationAdInfo creative_ad_2 = BuildCreativeNotificationAd(); + creative_ad_2.segment = "food & drink"; + creative_ad_2.ptr = 0.5; + creative_ads.push_back(creative_ad_2); + + SaveCreativeAds(creative_ads); + + // Act + ScopedPacingRandomNumberSetter scoped_setter(0.3); + + const CreativeNotificationAdList expected_creative_ads = {creative_ad_2}; + + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + [&expected_creative_ads](const bool had_opportunity, + const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); + EXPECT_EQ(expected_creative_ads, creative_ads); + }); +} + +TEST_F(BatAdsEligibleNotificationAdsV1Test, GetPrioritizedAds) { + // Arrange + CreativeNotificationAdList creative_ads; + + CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd(); + creative_ad_1.segment = "technology & computing"; + creative_ad_1.priority = 1; + creative_ads.push_back(creative_ad_1); + + CreativeNotificationAdInfo creative_ad_2 = BuildCreativeNotificationAd(); + creative_ad_2.segment = "finance-banking"; + creative_ad_2.priority = 1; + creative_ads.push_back(creative_ad_2); + + CreativeNotificationAdInfo creative_ad_3 = BuildCreativeNotificationAd(); + creative_ad_3.segment = "food & drink"; + creative_ad_3.priority = 2; + creative_ads.push_back(creative_ad_3); + + SaveCreativeAds(creative_ads); + + // Act + const CreativeNotificationAdList expected_creative_ads = {creative_ad_1}; + + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"technology & computing", "food & drink"}, {}, + {}), + [&expected_creative_ads](const bool had_opportunity, + const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); + EXPECT_EQ(expected_creative_ads, creative_ads); + }); } } // namespace notification_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2.cc index b603afa5deea..3383ea23720d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2.cc @@ -72,25 +72,33 @@ void EligibleAdsV2::GetEligibleAds( return; } - const CreativeNotificationAdList& eligible_creative_ads = + if (creative_ads.empty()) { + BLOG(1, "No eligible ads"); + callback(/* had_opportunity */ false, {}); + return; + } + + const CreativeNotificationAdList eligible_creative_ads = FilterCreativeAds(creative_ads, ad_events, browsing_history); if (eligible_creative_ads.empty()) { - BLOG(1, "No eligible ads"); + BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads"); callback(/* had_opportunity */ true, {}); return; } - const absl::optional& creative_ad_optional = + const absl::optional creative_ad_optional = PredictAd(user_model, ad_events, eligible_creative_ads); if (!creative_ad_optional) { - BLOG(1, "No eligible ads"); + BLOG(1, "No eligible ads out of " << creative_ads.size() << " ads"); callback(/* had_opportunity */ true, {}); return; } - const CreativeNotificationAdInfo& creative_ad = creative_ad_optional.value(); + BLOG(1, eligible_creative_ads.size() + << " eligible ads out of " << creative_ads.size() << " ads"); + callback(/* had_opportunity */ true, {creative_ad}); }); } @@ -105,7 +113,7 @@ CreativeNotificationAdList EligibleAdsV2::FilterCreativeAds( ExclusionRules exclusion_rules(ad_events, subdivision_targeting_, anti_targeting_resource_, browsing_history); - const CreativeNotificationAdList& eligible_creative_ads = + const CreativeNotificationAdList eligible_creative_ads = ApplyExclusionRules(creative_ads, last_served_ad_, &exclusion_rules); return eligible_creative_ads; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2_unittest.cc index dd5edf5e1961..c39d49458dea 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2_unittest.cc @@ -7,13 +7,15 @@ #include +#include "bat/ads/internal/ads/serving/eligible_ads/pacing/pacing_random_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_builder_unittest_util.h" #include "bat/ads/internal/ads/serving/targeting/user_model_info.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" -#include "bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.h" +#include "bat/ads/internal/creatives/notification_ads/notification_ad_builder.h" #include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" #include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" +#include "bat/ads/notification_ad_info.h" // npm run test -- brave_unit_tests --filter=BatAds* @@ -22,18 +24,23 @@ namespace notification_ads { class BatAdsEligibleNotificationAdsV2Test : public UnitTestBase { protected: - BatAdsEligibleNotificationAdsV2Test() - : database_table_( - std::make_unique()) {} + BatAdsEligibleNotificationAdsV2Test() = default; ~BatAdsEligibleNotificationAdsV2Test() override = default; - void Save(const CreativeNotificationAdList& creative_ads) { - database_table_->Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); + void SetUp() override { + UnitTestBase::SetUp(); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + eligible_ads_ = std::make_unique( + subdivision_targeting_.get(), anti_targeting_resource_.get()); } - std::unique_ptr database_table_; + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr eligible_ads_; }; TEST_F(BatAdsEligibleNotificationAdsV2Test, GetAds) { @@ -48,26 +55,17 @@ TEST_F(BatAdsEligibleNotificationAdsV2Test, GetAds) { creative_ad_2.segment = "foo-bar3"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); - - const SegmentList interest_segments = {"foo-bar3"}; - const SegmentList latent_interest_segments = {}; - const SegmentList purchase_intent_segments = {"foo-bar1", "foo-bar2"}; + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"foo-bar3"}, {}, {"foo-bar1", "foo-bar2"}), [](const bool had_opportunity, const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(!creative_ads.empty()); }); - - // Assert } TEST_F(BatAdsEligibleNotificationAdsV2Test, GetAdsForNoSegments) { @@ -82,50 +80,32 @@ TEST_F(BatAdsEligibleNotificationAdsV2Test, GetAdsForNoSegments) { creative_ad_2.segment = "foo-bar"; creative_ads.push_back(creative_ad_2); - Save(creative_ads); - - const SegmentList interest_segments = {}; - const SegmentList latent_interest_segments = {}; - const SegmentList purchase_intent_segments = {}; + SaveCreativeAds(creative_ads); // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({}, {}, {}), [](const bool had_opportunity, const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_TRUE(had_opportunity); EXPECT_TRUE(!creative_ads.empty()); }); - - // Assert } -TEST_F(BatAdsEligibleNotificationAdsV2Test, GetIfNoEligibleAds) { +TEST_F(BatAdsEligibleNotificationAdsV2Test, DoNotGetAdsIfNoEligibleAds) { // Arrange - const SegmentList interest_segments = {"interest-foo", "interest-bar"}; - const SegmentList latent_interest_segments = {}; - const SegmentList purchase_intent_segments = {"intent-foo", "intent-bar"}; // Act - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - EligibleAdsV2 eligible_ads(&subdivision_targeting, &anti_targeting_resource); - - const CreativeNotificationAdList expected_creative_ads = {}; - - eligible_ads.GetForUserModel( - targeting::BuildUserModel(interest_segments, latent_interest_segments, - purchase_intent_segments), - [&expected_creative_ads](const bool had_opportunity, - const CreativeNotificationAdList& creative_ads) { - EXPECT_EQ(expected_creative_ads, creative_ads); + eligible_ads_->GetForUserModel( + targeting::BuildUserModel({"interest-foo", "interest-bar"}, {}, + {"intent-foo", "intent-bar"}), + [](const bool had_opportunity, + const CreativeNotificationAdList& creative_ads) { + // Assert + EXPECT_FALSE(had_opportunity); + EXPECT_TRUE(creative_ads.empty()); }); - - // Assert } } // namespace notification_ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority.h index 5e495f5e4820..86464b25637b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority.h @@ -10,26 +10,27 @@ #include "base/containers/flat_map.h" #include "bat/ads/internal/ads/serving/eligible_ads/priority/priority_util.h" +#include "bat/ads/internal/base/logging_util.h" namespace ads { template -T PrioritizeAds(const T& ads) { - if (ads.empty()) { +T PrioritizeCreativeAds(const T& creative_ads) { + if (creative_ads.empty()) { return {}; } const base::flat_map buckets = - SortAdsIntoPrioritizedBuckets(ads); + SortCreativeAdsIntoPrioritizedBuckets(creative_ads); if (buckets.empty()) { return {}; } const std::pair bucket = GetHighestPriorityBucket(buckets); const unsigned int priority = bucket.first; - const T creative_ads = bucket.second; + const T prioritized_creative_ads = bucket.second; - BLOG(2, creative_ads.size() + BLOG(2, prioritized_creative_ads.size() << " ads with a priority of " << priority << " in bucket 1"); int index = 2; @@ -43,7 +44,7 @@ T PrioritizeAds(const T& ads) { index++; } - return creative_ads; + return prioritized_creative_ads; } } // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_test.cc deleted file mode 100644 index b3621e28966c..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_test.cc +++ /dev/null @@ -1,220 +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 "base/guid.h" -#include "bat/ads/internal/ads/serving/eligible_ads/eligible_ads_unittest_util.h" -#include "bat/ads/internal/ads/serving/notification_ad_serving.h" -#include "bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.h" -#include "bat/ads/internal/base/net/http/http_status_code.h" -#include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/base/unittest/unittest_mock_util.h" -#include "bat/ads/internal/base/unittest/unittest_time_util.h" -#include "bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.h" -#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" -#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" -#include "bat/ads/notification_ad_info.h" -#include "url/gurl.h" - -// npm run test -- brave_unit_tests --filter=BatAds* - -using ::testing::_; -using ::testing::AllOf; -using ::testing::Between; -using ::testing::Field; -using ::testing::Matcher; - -namespace ads { - -namespace { - -Matcher DoesMatchCreativeInstanceId( - const std::string& creative_instance_id) { - return AllOf(Field("creative_instance_id", - &NotificationAdInfo::creative_instance_id, - creative_instance_id)); -} - -void ServeAd() { - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - notification_ads::Serving serving(&subdivision_targeting, - &anti_targeting_resource); - - serving.MaybeServeAd(); -} - -} // namespace - -class BatAdsPriorityIntegrationTest : public UnitTestBase { - protected: - BatAdsPriorityIntegrationTest() - : database_table_( - std::make_unique()) {} - - ~BatAdsPriorityIntegrationTest() override = default; - - void SetUp() override { - UnitTestBase::SetUpForTesting(/* is_integration_test */ true); - - ForceUserActivityPermissionRule(); - } - - void SetUpMocks() override { - CopyFileFromTestPathToTempPath("confirmations_with_unblinded_tokens.json", - kConfirmationsFilename); - - const URLEndpointMap endpoints = { - {"/v9/catalog", {{net::HTTP_OK, "/empty_catalog.json"}}}, - {// Get issuers request - R"(/v1/issuers/)", - {{net::HTTP_OK, R"( - { - "ping": 7200000, - "issuers": [ - { - "name": "confirmations", - "publicKeys": [ - { - "publicKey": "JsvJluEN35bJBgJWTdW/8dAgPrrTM1I1pXga+o7cllo=", - "associatedValue": "" - }, - { - "publicKey": "crDVI1R6xHQZ4D9cQu4muVM5MaaM1QcOT4It8Y/CYlw=", - "associatedValue": "" - } - ] - }, - { - "name": "payments", - "publicKeys": [ - { - "publicKey": "JiwFR2EU/Adf1lgox+xqOVPuc6a/rxdy/LguFG5eaXg=", - "associatedValue": "0.0" - }, - { - "publicKey": "bPE1QE65mkIgytffeu7STOfly+x10BXCGuk5pVlOHQU=", - "associatedValue": "0.1" - } - ] - } - ] - } - )"}}}}; - MockUrlRequest(ads_client_mock_, endpoints); - } - - CreativeNotificationAdInfo BuildCreativeNotificationAd() { - CreativeNotificationAdInfo creative_ad; - - creative_ad.creative_instance_id = - base::GUID::GenerateRandomV4().AsLowercaseString(); - creative_ad.creative_set_id = - base::GUID::GenerateRandomV4().AsLowercaseString(); - creative_ad.campaign_id = - base::GUID::GenerateRandomV4().AsLowercaseString(); - creative_ad.start_at = DistantPast(); - creative_ad.end_at = DistantFuture(); - creative_ad.daily_cap = 1; - creative_ad.advertiser_id = - base::GUID::GenerateRandomV4().AsLowercaseString(); - 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 = GURL("https://brave.com"); - CreativeDaypartInfo daypart; - creative_ad.dayparts = {daypart}; - creative_ad.title = "Test Ad Title"; - creative_ad.body = "Test Ad Body"; - - return creative_ad; - } - - void ServeAdForIterations(const int iterations) { - for (int i = 0; i < iterations; i++) { - ResetEligibleAds(AdType::kNotificationAd); - - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - notification_ads::Serving serving(&subdivision_targeting, - &anti_targeting_resource); - - serving.MaybeServeAd(); - } - } - - void Save(const CreativeNotificationAdList& creative_ads) { - database_table_->Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); - } - - std::unique_ptr database_table_; -}; - -TEST_F(BatAdsPriorityIntegrationTest, PrioritizeDeliveryForSingleAd) { - // Arrange - CreativeNotificationAdList creative_ads; - - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); - creative_ad.priority = 3; - creative_ads.push_back(creative_ad); - - Save(creative_ads); - - // Act - EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( - creative_ad.creative_instance_id))) - .Times(1); - - ServeAd(); - - // Assert -} - -TEST_F(BatAdsPriorityIntegrationTest, PrioritizeDeliveryForNoAds) { - // Arrange - - // Act - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)).Times(0); - - ServeAd(); - - // Assert -} - -TEST_F(BatAdsPriorityIntegrationTest, PrioritizeDeliveryForMultipleAds) { - // Arrange - CreativeNotificationAdList creative_ads; - - CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd(); - creative_ad_1.priority = 3; - creative_ads.push_back(creative_ad_1); - - CreativeNotificationAdInfo creative_ad_2 = BuildCreativeNotificationAd(); - creative_ad_2.priority = 2; - creative_ads.push_back(creative_ad_2); - - CreativeNotificationAdInfo creative_ad_3 = BuildCreativeNotificationAd(); - creative_ad_3.priority = 4; - creative_ads.push_back(creative_ad_3); - - Save(creative_ads); - - // Act - EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( - creative_ad_2.creative_instance_id))) - .Times(1); - - ServeAd(); - - // Assert -} - -} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_unittest.cc new file mode 100644 index 000000000000..46304d31f213 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_unittest.cc @@ -0,0 +1,96 @@ +/* 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/serving/eligible_ads/priority/priority.h" + +#include "bat/ads/internal/base/containers/container_util.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_info.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_info_aliases.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" +#include "testing/gtest/include/gtest/gtest.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +TEST(BatAdsPriorityTest, PrioritizeNoCreativeAds) { + // Arrange + const CreativeNotificationAdList creative_ads = {}; + + // Act + const CreativeNotificationAdList prioritized_creative_ads = + PrioritizeCreativeAds(creative_ads); + + // Assert + EXPECT_TRUE(prioritized_creative_ads.empty()); +} + +TEST(BatAdsPriorityTest, PrioritizeSingleCreativeAd) { + // Arrange + CreativeNotificationAdList creative_ads; + CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); + creative_ad.priority = 1; + creative_ads.push_back(creative_ad); + + // Act + const CreativeNotificationAdList prioritized_creative_ads = + PrioritizeCreativeAds(creative_ads); + + // Assert + const CreativeNotificationAdList expected_prioritized_creative_ads = { + creative_ad}; + EXPECT_EQ(expected_prioritized_creative_ads, prioritized_creative_ads); +} + +TEST(BatAdsPriorityTest, PrioritizeMultipleCreativeAds) { + // Arrange + CreativeNotificationAdList creative_ads; + + CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd(); + creative_ad_1.priority = 1; + creative_ads.push_back(creative_ad_1); + + CreativeNotificationAdInfo creative_ad_2 = BuildCreativeNotificationAd(); + creative_ad_2.priority = 2; + creative_ads.push_back(creative_ad_2); + + CreativeNotificationAdInfo creative_ad_3 = BuildCreativeNotificationAd(); + creative_ad_3.priority = 1; + creative_ads.push_back(creative_ad_3); + + // Act + const CreativeNotificationAdList prioritized_creative_ads = + PrioritizeCreativeAds(creative_ads); + + // Assert + const CreativeNotificationAdList expected_prioritized_creative_ads = { + creative_ad_1, creative_ad_3}; + EXPECT_TRUE(IsEqualContainers(expected_prioritized_creative_ads, + prioritized_creative_ads)); +} + +TEST(BatAdsPriorityTest, DoNotPrioritizeZeroPriorityCreativeAds) { + // Arrange + CreativeNotificationAdList creative_ads; + + CreativeNotificationAdInfo creative_ad_1 = BuildCreativeNotificationAd(); + creative_ad_1.priority = 1; + creative_ads.push_back(creative_ad_1); + + CreativeNotificationAdInfo creative_ad_2 = BuildCreativeNotificationAd(); + creative_ad_2.priority = 0; + creative_ads.push_back(creative_ad_2); + + // Act + const CreativeNotificationAdList prioritized_creative_ads = + PrioritizeCreativeAds(creative_ads); + + // Assert + const CreativeNotificationAdList expected_prioritized_creative_ads = { + creative_ad_1}; + EXPECT_EQ(expected_prioritized_creative_ads, prioritized_creative_ads); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_util.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_util.h index bde2773ae30a..336f94729589 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/eligible_ads/priority/priority_util.h @@ -14,21 +14,22 @@ namespace ads { template -base::flat_map SortAdsIntoPrioritizedBuckets(const T& ads) { +base::flat_map SortCreativeAdsIntoPrioritizedBuckets( + const T& creative_ads) { base::flat_map buckets; - for (const auto& ad : ads) { - if (ad.priority == 0) { + for (const auto& creative_ad : creative_ads) { + if (creative_ad.priority == 0) { continue; } - const auto iter = buckets.find(ad.priority); + const auto iter = buckets.find(creative_ad.priority); if (iter == buckets.end()) { - buckets.insert({ad.priority, {ad}}); + buckets.insert({creative_ad.priority, {creative_ad}}); continue; } - iter->second.push_back(ad); + iter->second.push_back(creative_ad); } return buckets; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving.cc index 60a3d9666a16..2169516da7f3 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving.cc @@ -95,14 +95,7 @@ void Serving::MaybeServeAd(const std::string& dimensions, const CreativeInlineContentAdInfo& creative_ad = creative_ads.at(rand); const InlineContentAdInfo& ad = BuildInlineContentAd(creative_ad); - if (!ServeAd(ad, callback)) { - BLOG(1, "Failed to serve inline content ad"); - FailedToServeAd(dimensions, callback); - return; - } - - BLOG(1, "Served inline content ad"); - ServedAd(ad); + ServeAd(ad, callback); }); } @@ -116,11 +109,15 @@ bool Serving::IsSupported() const { return true; } -bool Serving::ServeAd(const InlineContentAdInfo& ad, - MaybeServeInlineContentAdCallback callback) const { - DCHECK(ad.IsValid()); +void Serving::ServeAd(const InlineContentAdInfo& ad, + MaybeServeInlineContentAdCallback callback) { + if (!ad.IsValid()) { + BLOG(1, "Failed to serve inline content ad"); + FailedToServeAd(ad.dimensions, callback); + return; + } - BLOG(1, "Serving inline content ad:\n" + BLOG(1, "Served inline content ad:\n" << " placementId: " << ad.placement_id << "\n" << " creativeInstanceId: " << ad.creative_instance_id << "\n" << " creativeSetId: " << ad.creative_set_id << "\n" @@ -134,23 +131,19 @@ bool Serving::ServeAd(const InlineContentAdInfo& ad, << " ctaText: " << ad.cta_text << "\n" << " targetUrl: " << ad.target_url); - callback(/* success */ true, ad.dimensions, ad); + DCHECK(eligible_ads_); + eligible_ads_->SetLastServedAd(ad); NotifyDidServeInlineContentAd(ad); - return true; + callback(/* success */ true, ad.dimensions, ad); } void Serving::FailedToServeAd(const std::string& dimensions, MaybeServeInlineContentAdCallback callback) { - callback(/* success */ false, dimensions, {}); - NotifyFailedToServeInlineContentAd(); -} -void Serving::ServedAd(const InlineContentAdInfo& ad) { - DCHECK(eligible_ads_); - eligible_ads_->SetLastServedAd(ad); + callback(/* success */ false, dimensions, {}); } void Serving::NotifyOpportunityAroseToServeInlineContentAd( diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving.h index 3d3f26b748ab..33ecf31d6efb 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving.h @@ -47,11 +47,10 @@ class Serving final { private: bool IsSupported() const; - bool ServeAd(const InlineContentAdInfo& ad, - MaybeServeInlineContentAdCallback callback) const; + void ServeAd(const InlineContentAdInfo& ad, + MaybeServeInlineContentAdCallback callback); void FailedToServeAd(const std::string& dimensions, MaybeServeInlineContentAdCallback callback); - void ServedAd(const InlineContentAdInfo& ad); void NotifyOpportunityAroseToServeInlineContentAd( const SegmentList& segments) const; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving_test.cc deleted file mode 100644 index 500eb8a86b6f..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving_test.cc +++ /dev/null @@ -1,143 +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/ads/serving/inline_content_ad_serving.h" - -#include "bat/ads/inline_content_ad_info.h" -#include "bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.h" -#include "bat/ads/internal/base/net/http/http_status_code.h" -#include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/base/unittest/unittest_mock_util.h" -#include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.h" -#include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h" -#include "bat/ads/internal/creatives/inline_content_ads/inline_content_ad_builder.h" - -// npm run test -- brave_unit_tests --filter=BatAds* - -namespace ads { -namespace inline_content_ads { - -class BatAdsInlineContentAdServingIntegrationTest : public UnitTestBase { - protected: - BatAdsInlineContentAdServingIntegrationTest() = default; - - ~BatAdsInlineContentAdServingIntegrationTest() override = default; - - void SetUp() override { - UnitTestBase::SetUpForTesting(/* is_integration_test */ true); - } - - void SetUpMocks() override { - CopyFileFromTestPathToTempPath("confirmations_with_unblinded_tokens.json", - kConfirmationsFilename); - - const URLEndpointMap endpoints = { - {"/v9/catalog", {{net::HTTP_OK, "/empty_catalog.json"}}}, - {// Get issuers request - R"(/v1/issuers/)", - {{net::HTTP_OK, R"( - { - "ping": 7200000, - "issuers": [ - { - "name": "confirmations", - "publicKeys": [ - { - "publicKey": "JsvJluEN35bJBgJWTdW/8dAgPrrTM1I1pXga+o7cllo=", - "associatedValue": "" - }, - { - "publicKey": "crDVI1R6xHQZ4D9cQu4muVM5MaaM1QcOT4It8Y/CYlw=", - "associatedValue": "" - } - ] - }, - { - "name": "payments", - "publicKeys": [ - { - "publicKey": "JiwFR2EU/Adf1lgox+xqOVPuc6a/rxdy/LguFG5eaXg=", - "associatedValue": "0.0" - }, - { - "publicKey": "bPE1QE65mkIgytffeu7STOfly+x10BXCGuk5pVlOHQU=", - "associatedValue": "0.1" - } - ] - } - ] - } - )"}}}}; - MockUrlRequest(ads_client_mock_, endpoints); - } - - void Save(const CreativeInlineContentAdList& creative_ads) { - database::table::CreativeInlineContentAds database_table; - database_table.Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); - } -}; - -TEST_F(BatAdsInlineContentAdServingIntegrationTest, ServeAd) { - // Arrange - ForceUserActivityPermissionRule(); - - CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - // Act - GetAds()->MaybeServeInlineContentAd( - "200x100", - [&creative_ad](const bool success, const std::string& dimensions, - const InlineContentAdInfo& ad) { - ASSERT_TRUE(success); - - InlineContentAdInfo expected_ad = BuildInlineContentAd(creative_ad); - expected_ad.placement_id = ad.placement_id; - - EXPECT_EQ(expected_ad, ad); - }); - - // Assert -} - -TEST_F(BatAdsInlineContentAdServingIntegrationTest, - DoNotServeAdForUnavailableDimensions) { - // Arrange - ForceUserActivityPermissionRule(); - - CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - // Act - GetAds()->MaybeServeInlineContentAd( - "?x?", [](const bool success, const std::string& dimensions, - const InlineContentAdInfo& ad) { EXPECT_FALSE(success); }); - - // Assert -} - -TEST_F(BatAdsInlineContentAdServingIntegrationTest, - DoNotServeAdIfNotAllowedDueToPermissionRules) { - // Arrange - CreativeInlineContentAdList creative_ads; - CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - // Act - GetAds()->MaybeServeInlineContentAd( - "200x100", [](const bool success, const std::string& dimensions, - const InlineContentAdInfo& ad) { EXPECT_FALSE(success); }); - - // Assert -} - -} // namespace inline_content_ads -} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving_unittest.cc new file mode 100644 index 000000000000..7777c1e4ea99 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/inline_content_ad_serving_unittest.cc @@ -0,0 +1,162 @@ +/* Copyright (c) 2022 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/serving/inline_content_ad_serving.h" + +#include + +#include "bat/ads/inline_content_ad_info.h" +#include "bat/ads/internal/ads/serving/eligible_ads/eligible_ads_unittest_util.h" +#include "bat/ads/internal/ads/serving/inline_content_ad_serving_observer.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/ads/serving/serving_features_unittest_util.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.h" +#include "bat/ads/internal/creatives/inline_content_ads/inline_content_ad_builder.h" +#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" +#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" +#include "bat/ads/internal/segments/segments_aliases.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { +namespace inline_content_ads { + +class BatAdsInlineContentAdServingTest : public ServingObserver, + public UnitTestBase { + protected: + BatAdsInlineContentAdServingTest() = default; + + ~BatAdsInlineContentAdServingTest() override = default; + + void SetUp() override { + UnitTestBase::SetUp(); + + features::ForceServingVersion(1); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + serving_ = std::make_unique(subdivision_targeting_.get(), + anti_targeting_resource_.get()); + serving_->AddObserver(this); + } + + void TearDown() override { + serving_->RemoveObserver(this); + + UnitTestBase::TearDown(); + } + + void OnOpportunityAroseToServeInlineContentAd( + const SegmentList& segments) override { + had_opportunuity_ = true; + } + + void OnDidServeInlineContentAd(const InlineContentAdInfo& ad) override { + ad_ = ad; + did_serve_ad_ = true; + } + + void OnFailedToServeInlineContentAd() override { failed_to_serve_ad_ = true; } + + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr serving_; + + InlineContentAdInfo ad_; + bool had_opportunuity_ = false; + bool did_serve_ad_ = false; + bool failed_to_serve_ad_ = false; +}; + +TEST_F(BatAdsInlineContentAdServingTest, DoNotServeAdForUnsupportedVersion) { + // Arrange + features::ForceServingVersion(0); + + // Act + serving_->MaybeServeAd("200x100", + [=](const bool success, const std::string& dimensions, + const InlineContentAdInfo& ad) { + // Assert + EXPECT_FALSE(success); + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); + }); +} + +TEST_F(BatAdsInlineContentAdServingTest, ServeAd) { + // Arrange + ForcePermissionRules(); + + CreativeInlineContentAdList creative_ads; + const CreativeInlineContentAdInfo creative_ad = + BuildCreativeInlineContentAd(); + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + serving_->MaybeServeAd("200x100", + [=](const bool success, const std::string& dimensions, + const InlineContentAdInfo& ad) { + // Assert + EXPECT_TRUE(success); + EXPECT_TRUE(had_opportunuity_); + EXPECT_TRUE(did_serve_ad_); + EXPECT_FALSE(failed_to_serve_ad_); + EXPECT_EQ(ad, ad_); + }); +} + +TEST_F(BatAdsInlineContentAdServingTest, DoNotServeAdForNonExistentDimensions) { + // Arrange + ForcePermissionRules(); + + CreativeInlineContentAdList creative_ads; + const CreativeInlineContentAdInfo creative_ad = + BuildCreativeInlineContentAd(); + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + serving_->MaybeServeAd("?x?", + [=](const bool success, const std::string& dimensions, + const InlineContentAdInfo& ad) { + // Assert + EXPECT_FALSE(success); + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); + }); + + // Assert +} + +TEST_F(BatAdsInlineContentAdServingTest, + DoNotServeAdIfNotAllowedDueToPermissionRules) { + // Arrange + CreativeInlineContentAdList creative_ads; + const CreativeInlineContentAdInfo creative_ad = + BuildCreativeInlineContentAd(); + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + serving_->MaybeServeAd("200x100", + [=](const bool success, const std::string& dimensions, + const InlineContentAdInfo& ad) { + // Assert + EXPECT_FALSE(success); + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); + }); + + // Assert +} + +} // namespace inline_content_ads +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving.cc index 3c3b41287840..838a6777942b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving.cc @@ -92,14 +92,7 @@ void Serving::MaybeServeAd(MaybeServeNewTabPageAdCallback callback) { const CreativeNewTabPageAdInfo& creative_ad = creative_ads.at(rand); const NewTabPageAdInfo& ad = BuildNewTabPageAd(creative_ad); - if (!ServeAd(ad, callback)) { - BLOG(1, "Failed to serve new tab page ad"); - FailedToServeAd(callback); - return; - } - - BLOG(1, "Served new tab page ad"); - ServedAd(ad); + ServeAd(ad, callback); }); } @@ -113,16 +106,21 @@ bool Serving::IsSupported() const { return true; } -bool Serving::ServeAd(const NewTabPageAdInfo& ad, - MaybeServeNewTabPageAdCallback callback) const { - DCHECK(ad.IsValid()); +void Serving::ServeAd(const NewTabPageAdInfo& ad, + MaybeServeNewTabPageAdCallback callback) { + if (!ad.IsValid()) { + BLOG(1, "Failed to serve new tab page ad"); + FailedToServeAd(callback); + return; + } if (ad.wallpapers.empty()) { + BLOG(1, "Failed to serve new tab page ad due to missing wallpapers"); callback(/* success */ false, ad); - return false; + return; } - BLOG(1, "Serving new tab page ad:\n" + BLOG(1, "Served new tab page ad:\n" << " placementId: " << ad.placement_id << "\n" << " creativeInstanceId: " << ad.creative_instance_id << "\n" << " creativeSetId: " << ad.creative_set_id << "\n" @@ -133,27 +131,24 @@ bool Serving::ServeAd(const NewTabPageAdInfo& ad, << " imageUrl: " << ad.image_url << "\n" << " alt: " << ad.alt << "\n" << " targetUrl: " << ad.target_url << "\n" - << " wallpaperImageUrl: " << ad.wallpapers[0].image_url << "\n" - << " wallpaperFocalPointX: " << ad.wallpapers[0].focal_point.x - << "\n" - << " wallpaperFocalPointY: " << ad.wallpapers[0].focal_point.y); + << " wallpaper:\n" + << " imageUrl: " << ad.wallpapers[0].image_url << "\n" + << " focalPoint:\n" + << " x: " << ad.wallpapers[0].focal_point.x << "\n" + << " y: " << ad.wallpapers[0].focal_point.y); - callback(/* success */ true, ad); + DCHECK(eligible_ads_); + eligible_ads_->SetLastServedAd(ad); NotifyDidServeNewTabPageAd(ad); - return true; + callback(/* success */ true, ad); } void Serving::FailedToServeAd(MaybeServeNewTabPageAdCallback callback) { - callback(/* success */ false, {}); - NotifyFailedToServeNewTabPageAd(); -} -void Serving::ServedAd(const NewTabPageAdInfo& ad) { - DCHECK(eligible_ads_); - eligible_ads_->SetLastServedAd(ad); + callback(/* success */ false, {}); } void Serving::NotifyOpportunityAroseToServeNewTabPageAd( diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving.h index 30104091f6a3..2aa9caf2af0f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving.h @@ -45,10 +45,9 @@ class Serving final { private: bool IsSupported() const; - bool ServeAd(const NewTabPageAdInfo& ad, - MaybeServeNewTabPageAdCallback callback) const; + void ServeAd(const NewTabPageAdInfo& ad, + MaybeServeNewTabPageAdCallback callback); void FailedToServeAd(MaybeServeNewTabPageAdCallback callback); - void ServedAd(const NewTabPageAdInfo& ad); void NotifyOpportunityAroseToServeNewTabPageAd( const SegmentList& segments) const; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving_test.cc deleted file mode 100644 index ac565f1bbf3d..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving_test.cc +++ /dev/null @@ -1,325 +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/ads/serving/new_tab_page_ad_serving.h" - -#include - -#include "bat/ads/internal/ads/ad_events/ad_event_unittest_util.h" -#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" -#include "bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.h" -#include "bat/ads/internal/ads/serving/serving_features.h" -#include "bat/ads/internal/base/net/http/http_status_code.h" -#include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/base/unittest/unittest_mock_util.h" -#include "bat/ads/internal/base/unittest/unittest_time_util.h" -#include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.h" -#include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.h" -#include "bat/ads/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" -#include "bat/ads/new_tab_page_ad_info.h" - -// npm run test -- brave_unit_tests --filter=BatAds* - -namespace ads { -namespace new_tab_page_ads { - -class BatAdsNewTabPageAdServingIntegrationTest : public UnitTestBase { - protected: - BatAdsNewTabPageAdServingIntegrationTest() = default; - - ~BatAdsNewTabPageAdServingIntegrationTest() override = default; - - void SetUp() override { - UnitTestBase::SetUpForTesting(/* is_integration_test */ true); - } - - void SetUpMocks() override { - CopyFileFromTestPathToTempPath("confirmations_with_unblinded_tokens.json", - kConfirmationsFilename); - - const URLEndpointMap endpoints = { - {"/v9/catalog", {{net::HTTP_OK, "/empty_catalog.json"}}}, - {// Get issuers request - R"(/v1/issuers/)", - {{net::HTTP_OK, R"( - { - "ping": 7200000, - "issuers": [ - { - "name": "confirmations", - "publicKeys": [ - { - "publicKey": "JsvJluEN35bJBgJWTdW/8dAgPrrTM1I1pXga+o7cllo=", - "associatedValue": "" - }, - { - "publicKey": "crDVI1R6xHQZ4D9cQu4muVM5MaaM1QcOT4It8Y/CYlw=", - "associatedValue": "" - } - ] - }, - { - "name": "payments", - "publicKeys": [ - { - "publicKey": "JiwFR2EU/Adf1lgox+xqOVPuc6a/rxdy/LguFG5eaXg=", - "associatedValue": "0.1" - }, - { - "publicKey": "bPE1QE65mkIgytffeu7STOfly+x10BXCGuk5pVlOHQU=", - "associatedValue": "0.2" - } - ] - } - ] - } - )"}}}}; - MockUrlRequest(ads_client_mock_, endpoints); - } - - void Save(const CreativeNewTabPageAdList& creative_ads) { - database::table::CreativeNewTabPageAds database_table; - database_table.Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); - } -}; - -TEST_F(BatAdsNewTabPageAdServingIntegrationTest, ServeAd) { - // Arrange - ForcePermissionRules(); - - CreativeNewTabPageAdList creative_ads; - const CreativeNewTabPageAdInfo& creative_ad = BuildCreativeNewTabPageAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - // Act - GetAds()->MaybeServeNewTabPageAd( - [&creative_ad](const bool success, const NewTabPageAdInfo& ad) { - ASSERT_TRUE(success); - - NewTabPageAdInfo expected_ad = BuildNewTabPageAd(creative_ad); - expected_ad.placement_id = ad.placement_id; - - EXPECT_EQ(expected_ad, ad); - }); - - // Assert -} - -TEST_F(BatAdsNewTabPageAdServingIntegrationTest, - ServeAdIfNotExceededPerDayExclusionRuleFrequencyCap) { - // Arrange - ForcePermissionRules(); - - CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - const int allowed_ad_count_per_day = - std::min(creative_ad.per_day, creative_ad.daily_cap); - - AdEventInfo ad_event = BuildAdEvent(creative_ad, AdType::kNewTabPageAd, - ConfirmationType::kServed, Now()); - for (int i = 0; i < allowed_ad_count_per_day - 1; ++i) { - FireAdEvent(ad_event); - } - - AdvanceClockBy(base::Hours(1)); - - // Act - GetAds()->MaybeServeNewTabPageAd( - [&creative_ad](const bool success, const NewTabPageAdInfo& ad) { - ASSERT_TRUE(success); - - NewTabPageAdInfo expected_ad = BuildNewTabPageAd(creative_ad); - expected_ad.placement_id = ad.placement_id; - - EXPECT_EQ(expected_ad, ad); - }); - - // Assert -} - -TEST_F(BatAdsNewTabPageAdServingIntegrationTest, - DoNotServeAdIfExceededPerDayExclusionRuleFrequencyCap) { - // Arrange - ForcePermissionRules(); - - CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - const int allowed_ad_count_per_day = - std::min(creative_ad.per_day, creative_ad.daily_cap); - - AdEventInfo ad_event = BuildAdEvent(creative_ad, AdType::kNewTabPageAd, - ConfirmationType::kServed, Now()); - for (int i = 0; i < allowed_ad_count_per_day; ++i) { - FireAdEvent(ad_event); - } - - // Act - GetAds()->MaybeServeNewTabPageAd( - [](const bool success, const NewTabPageAdInfo& ad) { - EXPECT_FALSE(success); - }); - - // Assert -} - -TEST_F(BatAdsNewTabPageAdServingIntegrationTest, - DoNotServeAdIfNotAllowedDueToPermissionRules) { - // Arrange - CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - // Act - GetAds()->MaybeServeNewTabPageAd( - [](const bool success, const NewTabPageAdInfo& ad) { - EXPECT_FALSE(success); - }); - - // Assert -} - -TEST_F(BatAdsNewTabPageAdServingIntegrationTest, - ServeAdIfNotExceededAdsPerHourPermissionRuleFrequencyCap) { - // Arrange - ForcePermissionRules(); - - CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad1 = BuildCreativeNewTabPageAd(); - CreativeNewTabPageAdInfo creative_ad2 = BuildCreativeNewTabPageAd(); - creative_ads.push_back(creative_ad1); - creative_ads.push_back(creative_ad2); - Save(creative_ads); - - AdEventInfo ad_event1 = BuildAdEvent(creative_ad1, AdType::kNewTabPageAd, - ConfirmationType::kServed, Now()); - - const int ads_per_hour = features::GetMaximumNewTabPageAdsPerHour(); - for (int i = 0; i < ads_per_hour - 1; ++i) { - FireAdEvent(ad_event1); - } - - AdvanceClockBy(features::GetNewTabPageAdsMinimumWaitTime()); - - // Act - GetAds()->MaybeServeNewTabPageAd( - [&creative_ad2](const bool success, const NewTabPageAdInfo& ad) { - ASSERT_TRUE(success); - - NewTabPageAdInfo expected_ad = BuildNewTabPageAd(creative_ad2); - expected_ad.placement_id = ad.placement_id; - - EXPECT_EQ(expected_ad, ad); - }); - - // Assert -} - -TEST_F(BatAdsNewTabPageAdServingIntegrationTest, - DoNotServeAdIfExceededAdsPerHourPermissionRuleFrequencyCap) { - // Arrange - ForcePermissionRules(); - - CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad1 = BuildCreativeNewTabPageAd(); - CreativeNewTabPageAdInfo creative_ad2 = BuildCreativeNewTabPageAd(); - creative_ads.push_back(creative_ad1); - creative_ads.push_back(creative_ad2); - Save(creative_ads); - - AdEventInfo ad_event1 = BuildAdEvent(creative_ad1, AdType::kNewTabPageAd, - ConfirmationType::kServed, Now()); - - const int ads_per_hour = features::GetMaximumNewTabPageAdsPerHour(); - for (int i = 0; i < ads_per_hour; ++i) { - FireAdEvent(ad_event1); - } - - // Act - GetAds()->MaybeServeNewTabPageAd( - [](const bool success, const NewTabPageAdInfo& ad) { - EXPECT_FALSE(success); - }); - - // Assert -} - -TEST_F(BatAdsNewTabPageAdServingIntegrationTest, - ServeAdIfNotExceededAdsPerDayPermissionRuleFrequencyCap) { - // Arrange - ForcePermissionRules(); - - CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad1 = BuildCreativeNewTabPageAd(); - CreativeNewTabPageAdInfo creative_ad2 = BuildCreativeNewTabPageAd(); - creative_ads.push_back(creative_ad1); - creative_ads.push_back(creative_ad2); - Save(creative_ads); - - AdEventInfo ad_event1 = BuildAdEvent(creative_ad1, AdType::kNewTabPageAd, - ConfirmationType::kServed, Now()); - - const int ads_per_day = features::GetMaximumNewTabPageAdsPerDay(); - for (int i = 0; i < ads_per_day - 1; ++i) { - FireAdEvent(ad_event1); - } - - AdvanceClockBy(base::Hours(1)); - - // Act - GetAds()->MaybeServeNewTabPageAd( - [&creative_ad2](const bool success, const NewTabPageAdInfo& ad) { - ASSERT_TRUE(success); - - NewTabPageAdInfo expected_ad = BuildNewTabPageAd(creative_ad2); - expected_ad.placement_id = ad.placement_id; - - EXPECT_EQ(expected_ad, ad); - }); - - // Assert -} - -TEST_F(BatAdsNewTabPageAdServingIntegrationTest, - DoNotServeAdIfExceededAdsPerDayPermissionRuleFrequencyCap) { - // Arrange - ForcePermissionRules(); - - CreativeNewTabPageAdList creative_ads; - CreativeNewTabPageAdInfo creative_ad1 = BuildCreativeNewTabPageAd(); - CreativeNewTabPageAdInfo creative_ad2 = BuildCreativeNewTabPageAd(); - creative_ads.push_back(creative_ad1); - creative_ads.push_back(creative_ad2); - Save(creative_ads); - - AdEventInfo ad_event1 = BuildAdEvent(creative_ad1, AdType::kNewTabPageAd, - ConfirmationType::kServed, Now()); - - const int ads_per_day = features::GetMaximumNewTabPageAdsPerDay(); - for (int i = 0; i < ads_per_day; ++i) { - FireAdEvent(ad_event1); - } - - AdvanceClockBy(base::Hours(1)); - - // Act - GetAds()->MaybeServeNewTabPageAd( - [](const bool success, const NewTabPageAdInfo& ad) { - EXPECT_FALSE(success); - }); - - // Assert -} - -} // namespace new_tab_page_ads -} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving_unittest.cc new file mode 100644 index 000000000000..bff54e7ec8b2 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/new_tab_page_ad_serving_unittest.cc @@ -0,0 +1,162 @@ +/* Copyright (c) 2022 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/serving/new_tab_page_ad_serving.h" + +#include + +#include "bat/ads/internal/ads/serving/eligible_ads/eligible_ads_unittest_util.h" +#include "bat/ads/internal/ads/serving/new_tab_page_ad_serving_observer.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/ads/serving/serving_features_unittest_util.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.h" +#include "bat/ads/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" +#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" +#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" +#include "bat/ads/internal/segments/segments_aliases.h" +#include "bat/ads/new_tab_page_ad_info.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { +namespace new_tab_page_ads { + +class BatAdsNewTabPageAdServingTest : public ServingObserver, + public UnitTestBase { + protected: + BatAdsNewTabPageAdServingTest() = default; + + ~BatAdsNewTabPageAdServingTest() override = default; + + void SetUp() override { + UnitTestBase::SetUp(); + + features::ForceServingVersion(1); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + serving_ = std::make_unique(subdivision_targeting_.get(), + anti_targeting_resource_.get()); + serving_->AddObserver(this); + } + + void TearDown() override { + serving_->RemoveObserver(this); + + UnitTestBase::TearDown(); + } + + void OnOpportunityAroseToServeNewTabPageAd( + const SegmentList& segments) override { + had_opportunuity_ = true; + } + + void OnDidServeNewTabPageAd(const NewTabPageAdInfo& ad) override { + ad_ = ad; + did_serve_ad_ = true; + } + + void OnFailedToServeNewTabPageAd() override { failed_to_serve_ad_ = true; } + + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr serving_; + + NewTabPageAdInfo ad_; + bool had_opportunuity_ = false; + bool did_serve_ad_ = false; + bool failed_to_serve_ad_ = false; +}; + +TEST_F(BatAdsNewTabPageAdServingTest, DoNotServeAdForUnsupportedVersion) { + // Arrange + features::ForceServingVersion(0); + + // Act + serving_->MaybeServeAd([=](const bool success, const NewTabPageAdInfo& ad) { + // Assert + EXPECT_FALSE(success); + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); + }); +} + +TEST_F(BatAdsNewTabPageAdServingTest, ServeAd) { + // Arrange + ForcePermissionRules(); + + CreativeNewTabPageAdList creative_ads; + const CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + serving_->MaybeServeAd([=](const bool success, const NewTabPageAdInfo& ad) { + // Assert + EXPECT_TRUE(success); + EXPECT_TRUE(had_opportunuity_); + EXPECT_TRUE(did_serve_ad_); + EXPECT_FALSE(failed_to_serve_ad_); + EXPECT_EQ(ad, ad_); + }); +} + +TEST_F(BatAdsNewTabPageAdServingTest, DoNotServeAdIfMissingWallpapers) { + // Arrange + ForcePermissionRules(); + + CreativeNewTabPageAdList creative_ads; + CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); + creative_ad.wallpapers = {}; + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + serving_->MaybeServeAd([=](const bool success, const NewTabPageAdInfo& ad) { + // Assert + EXPECT_FALSE(success); + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); + }); +} + +TEST_F(BatAdsNewTabPageAdServingTest, DoNotServeAdIfNoEligibleAdsFound) { + // Arrange + ForcePermissionRules(); + + // Act + serving_->MaybeServeAd([=](const bool success, const NewTabPageAdInfo& ad) { + // Assert + EXPECT_FALSE(success); + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); + }); +} + +TEST_F(BatAdsNewTabPageAdServingTest, + DoNotServeAdIfNotAllowedDueToPermissionRules) { + // Arrange + CreativeNewTabPageAdList creative_ads; + const CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(); + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + serving_->MaybeServeAd([=](const bool success, const NewTabPageAdInfo& ad) { + // Assert + EXPECT_FALSE(success); + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); + }); +} + +} // namespace new_tab_page_ads +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving.cc index c3ac827e53fb..8277ba371c64 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving.cc @@ -11,7 +11,6 @@ #include "base/rand_util.h" #include "base/time/time.h" #include "bat/ads/ad_type.h" -#include "bat/ads/internal/ads/serving/delivery/notification_ads/notification_ad_delivery.h" #include "bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_base.h" #include "bat/ads/internal/ads/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_factory.h" #include "bat/ads/internal/ads/serving/permission_rules/notification_ads/notification_ad_permission_rules.h" @@ -145,14 +144,7 @@ void Serving::MaybeServeAd() { const CreativeNotificationAdInfo& creative_ad = creative_ads.at(rand); const NotificationAdInfo& ad = BuildNotificationAd(creative_ad); - if (!ServeAd(ad)) { - BLOG(1, "Failed to serve notification ad"); - FailedToServeAd(); - return; - } - - BLOG(1, "Served notification ad"); - ServedAd(ad); + ServeAd(ad); }); } @@ -236,10 +228,14 @@ base::Time Serving::MaybeServeAdAfter(const base::TimeDelta delay) { base::BindOnce(&Serving::MaybeServeAd, base::Unretained(this))); } -bool Serving::ServeAd(const NotificationAdInfo& ad) const { - DCHECK(ad.IsValid()); +void Serving::ServeAd(const NotificationAdInfo& ad) { + if (!ad.IsValid()) { + BLOG(1, "Failed to serve notification ad"); + FailedToServeAd(); + return; + } - BLOG(1, "Serving notification ad:\n" + BLOG(1, "Served notification ad:\n" << " placementId: " << ad.placement_id << "\n" << " creativeInstanceId: " << ad.creative_instance_id << "\n" << " creativeSetId: " << ad.creative_set_id << "\n" @@ -250,14 +246,14 @@ bool Serving::ServeAd(const NotificationAdInfo& ad) const { << " body: " << ad.body << "\n" << " targetUrl: " << ad.target_url); - Delivery delivery; - if (!delivery.MaybeDeliverAd(ad)) { - return false; - } + DCHECK(eligible_ads_); + eligible_ads_->SetLastServedAd(ad); NotifyDidServeNotificationAd(ad); - return true; + is_serving_ = false; + + MaybeServeAdAtNextRegularInterval(); } void Serving::FailedToServeAd() { @@ -268,15 +264,6 @@ void Serving::FailedToServeAd() { RetryServingAdAtNextInterval(); } -void Serving::ServedAd(const NotificationAdInfo& ad) { - DCHECK(eligible_ads_); - eligible_ads_->SetLastServedAd(ad); - - is_serving_ = false; - - MaybeServeAdAtNextRegularInterval(); -} - void Serving::NotifyOpportunityAroseToServeNotificationAd( const SegmentList& segments) const { for (ServingObserver& observer : observers_) { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving.h index 252ab666cfdb..350d2577e101 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving.h @@ -65,9 +65,8 @@ class Serving final : public PrefManagerObserver { void RetryServingAdAtNextInterval(); base::Time MaybeServeAdAfter(const base::TimeDelta delay); - bool ServeAd(const NotificationAdInfo& ad) const; + void ServeAd(const NotificationAdInfo& ad); void FailedToServeAd(); - void ServedAd(const NotificationAdInfo& ad); void NotifyOpportunityAroseToServeNotificationAd( const SegmentList& segments) const; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving_test.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving_test.cc deleted file mode 100644 index c33b07505628..000000000000 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving_test.cc +++ /dev/null @@ -1,208 +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/ads/serving/notification_ad_serving.h" - -#include - -#include "base/guid.h" -#include "base/test/scoped_feature_list.h" -#include "bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.h" -#include "bat/ads/internal/ads/serving/serving_features.h" -#include "bat/ads/internal/base/net/http/http_status_code.h" -#include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/base/unittest/unittest_mock_util.h" -#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" -#include "bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.h" -#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" -#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" -#include "bat/ads/notification_ad_info.h" - -// npm run test -- brave_unit_tests --filter=BatAds* - -using ::testing::_; -using ::testing::AllOf; -using ::testing::Between; -using ::testing::Field; -using ::testing::Matcher; - -namespace ads { -namespace notification_ads { - -namespace { - -Matcher DoesMatchCreativeInstanceId( - const std::string& creative_instance_id) { - return AllOf(Field("creative_instance_id", - &NotificationAdInfo::creative_instance_id, - creative_instance_id)); -} - -} // namespace - -class BatAdsNotificationAdServingIntegrationTest : public UnitTestBase { - protected: - BatAdsNotificationAdServingIntegrationTest() = default; - - ~BatAdsNotificationAdServingIntegrationTest() override = default; - - void SetUp() override { - UnitTestBase::SetUpForTesting(/* is_integration_test */ true); - } - - void SetUpMocks() override { - CopyFileFromTestPathToTempPath("confirmations_with_unblinded_tokens.json", - kConfirmationsFilename); - - const URLEndpointMap endpoints = { - {"/v9/catalog", {{net::HTTP_OK, "/empty_catalog.json"}}}, - {// Get issuers request - R"(/v1/issuers/)", - {{net::HTTP_OK, R"( - { - "ping": 7200000, - "issuers": [ - { - "name": "confirmations", - "publicKeys": [ - { - "publicKey": "JsvJluEN35bJBgJWTdW/8dAgPrrTM1I1pXga+o7cllo=", - "associatedValue": "" - }, - { - "publicKey": "crDVI1R6xHQZ4D9cQu4muVM5MaaM1QcOT4It8Y/CYlw=", - "associatedValue": "" - } - ] - }, - { - "name": "payments", - "publicKeys": [ - { - "publicKey": "JiwFR2EU/Adf1lgox+xqOVPuc6a/rxdy/LguFG5eaXg=", - "associatedValue": "0.0" - }, - { - "publicKey": "bPE1QE65mkIgytffeu7STOfly+x10BXCGuk5pVlOHQU=", - "associatedValue": "0.1" - } - ] - } - ] - } - )"}}}}; - MockUrlRequest(ads_client_mock_, endpoints); - } - - void ServeAd() { - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - Serving serving(&subdivision_targeting, &anti_targeting_resource); - - serving.MaybeServeAd(); - } - - void Save(const CreativeNotificationAdList& creative_ads) { - database::table::CreativeNotificationAds database_table; - database_table.Save(creative_ads, - [](const bool success) { ASSERT_TRUE(success); }); - } -}; - -TEST_F(BatAdsNotificationAdServingIntegrationTest, ServeAd) { - // Arrange - ForceUserActivityPermissionRule(); - - CreativeNotificationAdList creative_ads; - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( - creative_ad.creative_instance_id))) - .Times(1); - - // Act - ServeAd(); - - // Assert -} - -TEST_F(BatAdsNotificationAdServingIntegrationTest, - DoNotServeAdIfNoEligibleAdsFound) { - // Arrange - ForceUserActivityPermissionRule(); - - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)).Times(0); - - // Act - ServeAd(); - - // Assert -} - -TEST_F(BatAdsNotificationAdServingIntegrationTest, DoNotServeInvalidAd) { - // Arrange - ForceUserActivityPermissionRule(); - - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)).Times(0); - - // Act - ServeAd(); - - // Assert -} - -TEST_F(BatAdsNotificationAdServingIntegrationTest, - DoNotServeAdIfNotAllowedDueToPermissionRules) { - // Arrange - CreativeNotificationAdList creative_ads; - CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - EXPECT_CALL(*ads_client_mock_, ShowNotification(_)).Times(0); - - // Act - ServeAd(); - - // Assert -} - -TEST_F(BatAdsNotificationAdServingIntegrationTest, ServeAdWithServingVersion2) { - // Arrange - ForceUserActivityPermissionRule(); - - CreativeNotificationAdList creative_ads; - const CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); - creative_ads.push_back(creative_ad); - Save(creative_ads); - - geographic::SubdivisionTargeting subdivision_targeting; - resource::AntiTargeting anti_targeting_resource; - Serving serving(&subdivision_targeting, &anti_targeting_resource); - - std::map serving_parameters; - serving_parameters["ad_serving_version"] = "2"; - - base::test::ScopedFeatureList scoped_feature_list; - scoped_feature_list.InitWithFeaturesAndParameters( - {{features::kServing, serving_parameters}}, {}); - - ASSERT_TRUE(features::IsServingEnabled()); - ASSERT_EQ(2, features::GetServingVersion()); - - // Act - EXPECT_CALL(*ads_client_mock_, ShowNotification(DoesMatchCreativeInstanceId( - creative_ad.creative_instance_id))) - .Times(1); - - ServeAd(); - - // Assert -} - -} // namespace notification_ads -} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving_unittest.cc new file mode 100644 index 000000000000..2d7ad629c6e5 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/notification_ad_serving_unittest.cc @@ -0,0 +1,141 @@ +/* Copyright (c) 2022 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/serving/notification_ad_serving.h" + +#include + +#include "bat/ads/internal/ads/serving/eligible_ads/eligible_ads_unittest_util.h" +#include "bat/ads/internal/ads/serving/notification_ad_serving_observer.h" +#include "bat/ads/internal/ads/serving/permission_rules/permission_rules_unittest_util.h" +#include "bat/ads/internal/ads/serving/serving_features_unittest_util.h" +#include "bat/ads/internal/base/unittest/unittest_base.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h" +#include "bat/ads/internal/creatives/notification_ads/notification_ad_builder.h" +#include "bat/ads/internal/geographic/subdivision/subdivision_targeting.h" +#include "bat/ads/internal/resources/behavioral/anti_targeting/anti_targeting_resource.h" +#include "bat/ads/internal/segments/segments_aliases.h" +#include "bat/ads/notification_ad_info.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { +namespace notification_ads { + +class BatAdsNotificationAdServingTest : public ServingObserver, + public UnitTestBase { + protected: + BatAdsNotificationAdServingTest() = default; + + ~BatAdsNotificationAdServingTest() override = default; + + void SetUp() override { + UnitTestBase::SetUp(); + + features::ForceServingVersion(1); + + subdivision_targeting_ = + std::make_unique(); + anti_targeting_resource_ = std::make_unique(); + serving_ = std::make_unique(subdivision_targeting_.get(), + anti_targeting_resource_.get()); + serving_->AddObserver(this); + } + + void TearDown() override { + serving_->RemoveObserver(this); + + UnitTestBase::TearDown(); + } + + void OnOpportunityAroseToServeNotificationAd( + const SegmentList& segments) override { + had_opportunuity_ = true; + } + + void OnDidServeNotificationAd(const NotificationAdInfo& ad) override { + ad_ = ad; + did_serve_ad_ = true; + } + + void OnFailedToServeNotificationAd() override { failed_to_serve_ad_ = true; } + + std::unique_ptr subdivision_targeting_; + std::unique_ptr anti_targeting_resource_; + std::unique_ptr serving_; + + NotificationAdInfo ad_; + bool had_opportunuity_ = false; + bool did_serve_ad_ = false; + bool failed_to_serve_ad_ = false; +}; + +TEST_F(BatAdsNotificationAdServingTest, DoNotServeAdForUnsupportedVersion) { + // Arrange + features::ForceServingVersion(0); + + // Act + serving_->MaybeServeAd(); + + // Assert + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); +} + +TEST_F(BatAdsNotificationAdServingTest, ServeAd) { + // Arrange + ForcePermissionRules(); + + CreativeNotificationAdList creative_ads; + const CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + serving_->MaybeServeAd(); + + // Assert + EXPECT_TRUE(had_opportunuity_); + EXPECT_TRUE(did_serve_ad_); + EXPECT_FALSE(failed_to_serve_ad_); + + const NotificationAdInfo expected_ad = + BuildNotificationAd(creative_ad, ad_.placement_id); + EXPECT_EQ(expected_ad, ad_); +} + +TEST_F(BatAdsNotificationAdServingTest, DoNotServeAdIfNoEligibleAdsFound) { + // Arrange + ForcePermissionRules(); + + // Act + serving_->MaybeServeAd(); + + // Assert + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); +} + +TEST_F(BatAdsNotificationAdServingTest, + DoNotServeAdIfNotAllowedDueToPermissionRules) { + // Arrange + CreativeNotificationAdList creative_ads; + const CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd(); + creative_ads.push_back(creative_ad); + SaveCreativeAds(creative_ads); + + // Act + serving_->MaybeServeAd(); + + // Assert + EXPECT_FALSE(had_opportunuity_); + EXPECT_FALSE(did_serve_ad_); + EXPECT_TRUE(failed_to_serve_ad_); +} + +} // namespace notification_ads +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule.cc index 7e6eedfee4c4..db64bfe26388 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule.cc @@ -7,7 +7,7 @@ #include "bat/ads/internal/account/account_util.h" #include "bat/ads/internal/base/platform/platform_helper.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest.cc index f99e77d9609e..061a4010383f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest.cc @@ -9,7 +9,7 @@ #include "base/test/scoped_feature_list.h" #include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" // npm run test -- brave_unit_tests --filter=BatAds* diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.cc index 963ff926f23b..0472d584e8fd 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.cc @@ -5,7 +5,7 @@ #include "bat/ads/internal/ads/serving/permission_rules/user_activity_permission_rule_unittest_util.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest_util.cc new file mode 100644 index 000000000000..3f9babfe8210 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest_util.cc @@ -0,0 +1,33 @@ +/* Copyright (c) 2022 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/serving/serving_features_unittest_util.h" + +#include +#include + +#include "base/strings/string_number_conversions.h" +#include "base/test/scoped_feature_list.h" +#include "bat/ads/internal/ads/serving/serving_features.h" +#include "testing/gtest/include/gtest/gtest.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { +namespace features { + +void ForceServingVersion(const int version) { + std::map serving_parameters; + serving_parameters["ad_serving_version"] = base::NumberToString(version); + + base::test::ScopedFeatureList scoped_feature_list; + scoped_feature_list.InitWithFeaturesAndParameters( + {{kServing, serving_parameters}}, {}); + + ASSERT_EQ(version, GetServingVersion()); +} + +} // namespace features +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest_util.h new file mode 100644 index 000000000000..8665e7af99c8 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/serving/serving_features_unittest_util.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2022 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_SERVING_SERVING_FEATURES_UNITTEST_UTIL_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_SERVING_SERVING_FEATURES_UNITTEST_UTIL_H_ + +namespace ads { +namespace features { + +void ForceServingVersion(const int version); + +} // namespace features +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_SERVING_SERVING_FEATURES_UNITTEST_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h b/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h index 52afec76ef3c..e214529e6b7c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h @@ -6,12 +6,10 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_CLIENT_MOCK_H_ #define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_ADS_CLIENT_MOCK_H_ -#include "bat/ads/ads_client.h" - #include #include -#include "bat/ads/public/interfaces/ads.mojom.h" +#include "bat/ads/ads_client.h" #include "testing/gmock/include/gmock/gmock.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc index 6fd03a600bfa..4ddc77e42db2 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc @@ -54,8 +54,8 @@ #include "bat/ads/internal/studies/studies_util.h" #include "bat/ads/internal/tabs/tab_manager.h" #include "bat/ads/internal/transfer/transfer.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" #include "bat/ads/internal/user_interaction/idle_detection/idle_detection_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" #include "bat/ads/new_tab_page_ad_info.h" #include "bat/ads/notification_ad_info.h" #include "bat/ads/promoted_content_ad_info.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.cc b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.cc index 7991dc5fd0a3..57e568d41add 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.cc @@ -12,7 +12,6 @@ #include "bat/ads/internal/base/unittest/unittest_file_util.h" #include "bat/ads/internal/base/unittest/unittest_mock_util.h" #include "bat/ads/internal/base/unittest/unittest_time_util.h" -#include "bat/ads/internal/creatives/notification_ads/notification_ad_manager.h" #include "bat/ads/pref_names.h" #include "bat/ads/public/interfaces/ads.mojom.h" @@ -154,7 +153,7 @@ void UnitTestBase::AdvanceClockToMidnight(const bool is_local) { /////////////////////////////////////////////////////////////////////////////// void UnitTestBase::Initialize() { - InitializeMocks(); + SetDefaultMocks(); SetDefaultPrefs(); @@ -169,6 +168,11 @@ void UnitTestBase::Initialize() { SetUpMocks(); + if (is_integration_test_) { + SetUpIntegrationTest(); + return; + } + browser_manager_ = std::make_unique(); client_state_manager_ = std::make_unique(); @@ -210,7 +214,7 @@ void UnitTestBase::Initialize() { task_environment_.FastForwardUntilNoTasksRemain(); } -void UnitTestBase::InitializeMocks() { +void UnitTestBase::SetDefaultMocks() { MockBuildChannel(BuildChannelType::kRelease); MockEnvironment(mojom::Environment::kStaging); @@ -225,6 +229,7 @@ void UnitTestBase::InitializeMocks() { MockIsBrowserInFullScreenMode(ads_client_mock_, false); MockShouldShowNotifications(ads_client_mock_, true); + MockCanShowBackgroundNotifications(ads_client_mock_, false); MockShowNotification(ads_client_mock_); MockCloseNotification(ads_client_mock_); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.h b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.h index bd6d18e077fb..13d613a611ab 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_base.h @@ -17,6 +17,7 @@ #include "bat/ads/internal/base/platform/platform_helper_mock.h" #include "bat/ads/internal/browser/browser_manager.h" #include "bat/ads/internal/covariates/covariate_manager.h" +#include "bat/ads/internal/creatives/notification_ads/notification_ad_manager.h" #include "bat/ads/internal/database/database_manager.h" #include "bat/ads/internal/deprecated/client/client_state_manager.h" #include "bat/ads/internal/deprecated/confirmations/confirmation_state_manager.h" @@ -26,8 +27,8 @@ #include "bat/ads/internal/prefs/pref_manager.h" #include "bat/ads/internal/resources/resource_manager.h" #include "bat/ads/internal/tabs/tab_manager.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" #include "bat/ads/internal/user_interaction/idle_detection/idle_detection_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" #include "brave/components/l10n/browser/locale_helper_mock.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -44,7 +45,6 @@ constexpr char kDatabaseFilename[] = "database.sqlite"; constexpr char kDefaultLocale[] = "en-US"; class Database; -class NotificationAdManager; class UnitTestBase : public testing::Test { public: @@ -136,7 +136,7 @@ class UnitTestBase : public testing::Test { private: void Initialize(); - void InitializeMocks(); + void SetDefaultMocks(); void SetDefaultPrefs(); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_mock_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_mock_util.cc index ca32006d1e0c..7541dc22a791 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_mock_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_mock_util.cc @@ -164,6 +164,13 @@ void MockShouldShowNotifications(const std::unique_ptr& mock, ON_CALL(*mock, ShouldShowNotifications()).WillByDefault(Return(should_show)); } +void MockCanShowBackgroundNotifications( + const std::unique_ptr& mock, + const bool can_show) { + ON_CALL(*mock, CanShowBackgroundNotifications()) + .WillByDefault(Return(can_show)); +} + void MockShowNotification(const std::unique_ptr& mock) { ON_CALL(*mock, ShowNotification(_)) .WillByDefault(Invoke([](const NotificationAdInfo& notification_ad) { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_mock_util.h b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_mock_util.h index b00d020cd27a..f89143c81f7e 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_mock_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_mock_util.h @@ -42,7 +42,9 @@ void MockIsBrowserInFullScreenMode(const std::unique_ptr& mock, void MockShouldShowNotifications(const std::unique_ptr& mock, const bool should_show); - +void MockCanShowBackgroundNotifications( + const std::unique_ptr& mock, + const bool can_show); void MockShowNotification(const std::unique_ptr& mock); void MockCloseNotification(const std::unique_ptr& mock); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_url_response_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_url_response_util.cc index eb01175e47bf..1e57757fc582 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_url_response_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/base/unittest/unittest_url_response_util.cc @@ -111,14 +111,12 @@ absl::optional GetNextUrlEndpointResponse( // uuid does not exist so insert a new index set to 0 for the endpoint GetUrlEndpointIndexes()[uuid] = url_endpoint_response_index; } else { + url_endpoint_response_indexes_iter->second++; if (url_endpoint_response_indexes_iter->second == - url_endpoint_responses.size() - 1) { - NOTREACHED() << "Missing MockUrlRequest endpoint response for " << url; - return absl::nullopt; + url_endpoint_responses.size()) { + url_endpoint_response_indexes_iter->second = 0; } - url_endpoint_response_indexes_iter->second++; - url_endpoint_response_index = url_endpoint_response_indexes_iter->second; } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversion_queue_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversion_queue_database_table.cc index 2e74b3ad260f..6368aa91a07a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversion_queue_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversion_queue_database_table.cc @@ -5,7 +5,6 @@ #include "bat/ads/internal/conversions/conversion_queue_database_table.h" -#include #include #include diff --git a/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversions_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversions_database_table.cc index 0eccb2c38a0e..19cd8604e47c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversions_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/conversions/conversions_database_table.cc @@ -5,7 +5,6 @@ #include "bat/ads/internal/conversions/conversions_database_table.h" -#include #include #include "base/check.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/covariate_manager.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/covariate_manager.cc index c8b62a6ffed3..e4688681bffa 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/covariate_manager.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/covariate_manager.cc @@ -6,7 +6,6 @@ #include "bat/ads/internal/covariates/covariate_manager.h" #include -#include #include "base/check.h" #include "base/no_destructor.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/covariate_manager_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/covariate_manager_unittest.cc index 8eb68013936b..c86e19574803 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/covariate_manager_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/covariate_manager_unittest.cc @@ -9,7 +9,7 @@ #include "bat/ads/internal/base/unittest/unittest_time_util.h" #include "bat/ads/internal/covariates/log_entries/notification_ad_event.h" -// npm run test -- brave_unit_tests --filter=BatAdsCovariateManagerTest* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/average_clickthrough_rate_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/average_clickthrough_rate_unittest.cc index 799f0c4cb5ca..6cc9388136ce 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/average_clickthrough_rate_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/average_clickthrough_rate_unittest.cc @@ -12,7 +12,7 @@ #include "bat/ads/internal/history/history_manager.h" #include "bat/ads/notification_ad_info.h" -// npm run test -- brave_unit_tests --filter=BatAdsFederatedLogEntries* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/last_notification_ad_was_clicked_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/last_notification_ad_was_clicked_unittest.cc index 20a629dbd44f..ed50fff8159f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/last_notification_ad_was_clicked_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/last_notification_ad_was_clicked_unittest.cc @@ -12,7 +12,7 @@ #include "bat/ads/internal/history/history_manager.h" #include "bat/ads/notification_ad_info.h" -// npm run test -- brave_unit_tests --filter=BatAdsFederatedLogEntries* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/notification_ad_event_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/notification_ad_event_unittest.cc index 6d49fd907871..7e78c85f6e83 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/notification_ad_event_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/notification_ad_event_unittest.cc @@ -9,7 +9,7 @@ #include "bat/ads/internal/base/unittest/unittest_base.h" -// npm run test -- brave_unit_tests --filter=BatAdsFederatedLogEntries* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/notification_ad_served_at_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/notification_ad_served_at_unittest.cc index da8875ec602a..0d2a25aa909c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/notification_ad_served_at_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/notification_ad_served_at_unittest.cc @@ -8,7 +8,7 @@ #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/base/unittest/unittest_time_util.h" -// npm run test -- brave_unit_tests --filter=BatAdsFederatedLogEntries* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events.cc index e9e8de5989b1..77ff98ad498d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events.cc @@ -6,8 +6,8 @@ #include "bat/ads/internal/covariates/log_entries/number_of_user_activity_events.h" #include "base/strings/string_number_conversions.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_util.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events.h b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events.h index af05491b76dc..7840fa5b8993 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events.h @@ -9,7 +9,7 @@ #include #include "bat/ads/internal/covariates/covariate_log_entry_interface.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_types.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events_unittest.cc index 5b75feb8f0ce..9b5e1cd608ad 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/number_of_user_activity_events_unittest.cc @@ -8,9 +8,9 @@ #include #include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" -// npm run test -- brave_unit_tests --filter=BatAdsFederatedLogEntries* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event.cc index 70c4a2ded303..1c96ff6e81ce 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event.cc @@ -7,8 +7,8 @@ #include "base/strings/string_number_conversions.h" #include "base/time/time.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_util.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event.h b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event.h index 0e3df0ccf377..eb1983facb50 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event.h @@ -9,7 +9,7 @@ #include #include "bat/ads/internal/covariates/covariate_log_entry_interface.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_types.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event_unittest.cc index cc3b2b9c3e36..1b5d54bd486f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/covariates/log_entries/time_since_last_user_activity_event_unittest.cc @@ -8,9 +8,9 @@ #include #include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" -// npm run test -- brave_unit_tests --filter=BatAdsFederatedLogEntries* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/creative_ads_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/creative_ads_database_table.cc index cb1084b770fa..d0bb77c898a9 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/creative_ads_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/creative_ads_database_table.cc @@ -6,9 +6,7 @@ #include "bat/ads/internal/creatives/creative_ads_database_table.h" #include -#include #include -#include #include #include "base/check.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.cc index 3a089030933e..3e89f7a33b13 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.cc @@ -5,6 +5,7 @@ #include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_unittest_util.h" +#include "bat/ads/internal/creatives/creative_ad_info.h" #include "bat/ads/internal/creatives/creative_ad_unittest_util.h" #include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ad_info.h" #include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.cc index d88c4f39c5d4..1a8ea910b1ca 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.cc @@ -6,9 +6,7 @@ #include "bat/ads/internal/creatives/inline_content_ads/creative_inline_content_ads_database_table.h" #include -#include #include -#include #include #include diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.cc index 64205f859639..8e8cd90875f6 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.cc @@ -5,6 +5,7 @@ #include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_unittest_util.h" +#include "bat/ads/internal/creatives/creative_ad_info.h" #include "bat/ads/internal/creatives/creative_ad_unittest_util.h" #include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_info.h" #include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpaper_focal_point_info.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.cc index d71a7a122a8d..1a56d90cc159 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.cc @@ -5,7 +5,9 @@ #include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_wallpapers_database_table.h" +#include #include +#include #include #include "base/check.h" @@ -15,6 +17,7 @@ #include "bat/ads/internal/base/database/database_column_util.h" #include "bat/ads/internal/base/database/database_table_util.h" #include "bat/ads/internal/base/database/database_transaction_util.h" +#include "bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_info.h" namespace ads { namespace database { @@ -56,13 +59,21 @@ void CreativeNewTabPageAdWallpapers::InsertOrUpdate( const CreativeNewTabPageAdList& creative_ads) { DCHECK(transaction); - if (creative_ads.empty()) { + CreativeNewTabPageAdList filtered_creative_ads; + std::copy_if(creative_ads.cbegin(), creative_ads.cend(), + std::back_inserter(filtered_creative_ads), + [](const CreativeNewTabPageAdInfo& creative_ad) { + return !creative_ad.wallpapers.empty(); + }); + + if (filtered_creative_ads.empty()) { return; } mojom::DBCommandPtr command = mojom::DBCommand::New(); command->type = mojom::DBCommand::Type::RUN; - command->command = BuildInsertOrUpdateQuery(command.get(), creative_ads); + command->command = + BuildInsertOrUpdateQuery(command.get(), filtered_creative_ads); transaction->commands.push_back(std::move(command)); } diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.cc index 2492315a50d4..b6f7384c768e 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_table.cc @@ -7,9 +7,7 @@ #include #include -#include #include -#include #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.cc index 4f5d738cf966..424476820fad 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.cc @@ -8,9 +8,17 @@ #include "bat/ads/internal/creatives/creative_ad_info.h" #include "bat/ads/internal/creatives/creative_ad_unittest_util.h" #include "bat/ads/internal/creatives/notification_ads/creative_notification_ad_info.h" +#include "bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.h" +#include "third_party/googletest/src/googletest/include/gtest/gtest.h" namespace ads { +void SaveCreativeAds(const CreativeNotificationAdList& creative_ads) { + database::table::CreativeNotificationAds database_table; + database_table.Save(creative_ads, + [](const bool success) { ASSERT_TRUE(success); }); +} + CreativeNotificationAdList BuildCreativeNotificationAds(const int count) { CreativeNotificationAdList creative_ads; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h index 43c73a4ec188..3e1dc57e49e1 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ad_unittest_util.h @@ -12,6 +12,8 @@ namespace ads { struct CreativeNotificationAdInfo; +void SaveCreativeAds(const CreativeNotificationAdList& creative_ads); + CreativeNotificationAdList BuildCreativeNotificationAds(const int count); CreativeNotificationAdInfo BuildCreativeNotificationAd(); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.cc index 8f01e33ac49d..7da23ac6e80b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.cc @@ -6,11 +6,8 @@ #include "bat/ads/internal/creatives/notification_ads/creative_notification_ads_database_table.h" #include -#include #include -#include #include -#include #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.cc index de2c673a7fc7..42bc965cd161 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.cc @@ -6,11 +6,8 @@ #include "bat/ads/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_table.h" #include -#include #include -#include #include -#include #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.cc new file mode 100644 index 000000000000..c2a23c213504 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.cc @@ -0,0 +1,37 @@ +/* Copyright (c) 2022 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/creatives/search_result_ads/search_result_ad_unittest_util.h" + +#include "base/guid.h" +#include "bat/ads/internal/base/unittest/unittest_time_util.h" +#include "url/gurl.h" + +namespace ads { + +mojom::SearchResultAdPtr BuildSearchResultAd() { + mojom::SearchResultAdPtr ad = mojom::SearchResultAd::New(); + + ad->creative_instance_id = base::GUID::GenerateRandomV4().AsLowercaseString(); + ad->placement_id = base::GUID::GenerateRandomV4().AsLowercaseString(); + ad->creative_set_id = base::GUID::GenerateRandomV4().AsLowercaseString(); + ad->campaign_id = base::GUID::GenerateRandomV4().AsLowercaseString(); + ad->advertiser_id = base::GUID::GenerateRandomV4().AsLowercaseString(); + ad->target_url = GURL("https://brave.com"); + ad->headline_text = "headline"; + ad->description = "description"; + ad->value = 1.0; + ad->conversion = mojom::Conversion::New(); + ad->conversion->type = "postview"; + ad->conversion->url_pattern = "https://brave.com/*"; + ad->conversion->advertiser_public_key = + "ofIveUY/bM7qlL9eIkAv/xbjDItFs1xRTTYKRZZsPHI="; + ad->conversion->observation_window = 3; + ad->conversion->expire_at = DistantFuture(); + + return ad; +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.h new file mode 100644 index 000000000000..dfb69182a6fc --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/creatives/search_result_ads/search_result_ad_unittest_util.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2022 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_CREATIVES_SEARCH_RESULT_ADS_SEARCH_RESULT_AD_UNITTEST_UTIL_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_CREATIVES_SEARCH_RESULT_ADS_SEARCH_RESULT_AD_UNITTEST_UTIL_H_ + +#include "bat/ads/public/interfaces/ads.mojom.h" + +namespace ads { + +mojom::SearchResultAdPtr BuildSearchResultAd(); + +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_CREATIVES_SEARCH_RESULT_ADS_SEARCH_RESULT_AD_UNITTEST_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/deprecated/client/preferences/ad_preferences_info_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/deprecated/client/preferences/ad_preferences_info_unittest.cc index 7d90c88f930e..c21e37f05869 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/deprecated/client/preferences/ad_preferences_info_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/deprecated/client/preferences/ad_preferences_info_unittest.cc @@ -6,7 +6,7 @@ #include "bat/ads/internal/deprecated/client/preferences/ad_preferences_info.h" #include "bat/ads/internal/base/unittest/unittest_base.h" -// npm run test -- brave_unit_tests --filter=BatAdsAdPreferencesInfoTest.* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/features/features_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/features/features_util.cc index 7a83d895b227..e2d25ec796ac 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/features/features_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/features/features_util.cc @@ -15,7 +15,7 @@ #include "bat/ads/internal/features/epsilon_greedy_bandit_features.h" #include "bat/ads/internal/features/purchase_intent_features.h" #include "bat/ads/internal/features/text_classification_features.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/history/history_unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/history/history_unittest_util.cc new file mode 100644 index 000000000000..fe5ff47a720e --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/history/history_unittest_util.cc @@ -0,0 +1,25 @@ +/* Copyright (c) 2022 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/history/history_unittest_util.h" + +#include "bat/ads/history_filter_types.h" +#include "bat/ads/history_info.h" +#include "bat/ads/history_item_info.h" +#include "bat/ads/history_sort_types.h" +#include "bat/ads/internal/base/unittest/unittest_time_util.h" +#include "bat/ads/internal/history/history_manager.h" + +namespace ads { + +int GetHistoryItemCount() { + const HistoryInfo history = HistoryManager::GetInstance()->Get( + HistoryFilterType::kNone, HistorySortType::kNone, DistantPast(), + DistantFuture()); + + return history.items.size(); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/history/history_unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/history/history_unittest_util.h new file mode 100644 index 000000000000..7b88eec48bc8 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/history/history_unittest_util.h @@ -0,0 +1,15 @@ +/* Copyright (c) 2022 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_HISTORY_HISTORY_UNITTEST_UTIL_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_HISTORY_HISTORY_UNITTEST_UTIL_H_ + +namespace ads { + +int GetHistoryItemCount(); + +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_HISTORY_HISTORY_UNITTEST_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/segments/segments_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/segments/segments_util.cc index 30d61d1a436c..d320211bfc62 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/segments/segments_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/segments/segments_util.cc @@ -5,7 +5,6 @@ #include "bat/ads/internal/segments/segments_util.h" -#include #include #include diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util.cc index e16b26597e73..39384692856d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util.cc @@ -7,7 +7,7 @@ #include "base/time/time.h" #include "bat/ads/internal/ads_client_helper.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" #include "bat/ads/pref_names.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util_unittest.cc index de062bb5ee1d..4055e4af5427 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/idle_detection/idle_detection_util_unittest.cc @@ -11,7 +11,7 @@ #include "base/test/scoped_feature_list.h" #include "bat/ads/internal/ads_client_helper.h" #include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" #include "bat/ads/pref_names.h" // npm run test -- brave_unit_tests --filter=BatAds* diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util.cc similarity index 96% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util.cc index 0c9d5366ed13..581cc86ac3ae 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/page_transition_util.h" +#include "bat/ads/internal/user_interaction/user_activity/page_transition_util.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util.h similarity index 81% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util.h index ce6469a7a86e..6c7d4d26958c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util.h @@ -3,10 +3,10 @@ * 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_USER_INTERACTION_BROWSING_PAGE_TRANSITION_UTIL_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_PAGE_TRANSITION_UTIL_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_PAGE_TRANSITION_UTIL_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_PAGE_TRANSITION_UTIL_H_ -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_types.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h" #include "bat/ads/page_transition_types.h" #include "third_party/abseil-cpp/absl/types/optional.h" @@ -27,4 +27,4 @@ absl::optional ToUserActivityEventType( } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_PAGE_TRANSITION_UTIL_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_PAGE_TRANSITION_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util_unittest.cc similarity index 97% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util_unittest.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util_unittest.cc index 594dc00cdf4f..46cf684920a1 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/page_transition_util_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/page_transition_util_unittest.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/page_transition_util.h" +#include "bat/ads/internal/user_interaction/user_activity/page_transition_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_constants.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_constants.h similarity index 77% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_constants.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_constants.h index 09752378ae6b..77c06459bbb4 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_constants.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_constants.h @@ -3,8 +3,8 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_CONSTANTS_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_CONSTANTS_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_CONSTANTS_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_CONSTANTS_H_ namespace ads { @@ -12,4 +12,4 @@ constexpr int kMaximumHistoryItems = 3600; } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_CONSTANTS_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_CONSTANTS_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info.cc similarity index 91% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info.cc index 67f4d929517a..99921ad9e278 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/user_activity_event_info.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_info.h" #include "bat/ads/internal/base/numbers/number_util.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info.h similarity index 79% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info.h index 071ddf97d388..5dfa9a3adbe3 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info.h @@ -3,11 +3,11 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_INFO_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_INFO_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_INFO_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_INFO_H_ #include "base/time/time.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_types.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h" namespace ads { @@ -28,4 +28,4 @@ struct UserActivityEventInfo final { } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_INFO_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_INFO_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info_aliases.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info_aliases.h similarity index 69% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info_aliases.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info_aliases.h index 9fdfd2824c1a..1925574a3f36 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_info_aliases.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_info_aliases.h @@ -3,11 +3,11 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_INFO_ALIASES_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_INFO_ALIASES_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_INFO_ALIASES_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_INFO_ALIASES_H_ #include "base/containers/circular_deque.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_info.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_info.h" namespace ads { @@ -15,4 +15,4 @@ using UserActivityEventList = base::circular_deque; } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_INFO_ALIASES_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_INFO_ALIASES_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_types.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h similarity index 90% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_types.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h index 380a0ef14fd4..6c876469eeab 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_event_types.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h @@ -3,8 +3,8 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_TYPES_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_TYPES_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_TYPES_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_TYPES_H_ #include @@ -42,4 +42,4 @@ enum class UserActivityEventType : int8_t { } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_EVENT_TYPES_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_EVENT_TYPES_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features.cc similarity index 96% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features.cc index d77266fcac55..7ba3c6a799cb 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" #include "base/metrics/field_trial_params.h" #include "base/time/time.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features.h similarity index 86% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features.h index 4038a447f643..c94fb100369f 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features.h @@ -3,8 +3,8 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_FEATURES_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_FEATURES_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_FEATURES_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_FEATURES_H_ #include @@ -35,4 +35,4 @@ bool ShouldDetectWasLocked(); } // namespace user_activity } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_FEATURES_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_FEATURES_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features_unittest.cc similarity index 99% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features_unittest.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features_unittest.cc index d8d675802591..453688832d32 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_features_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_features_unittest.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" #include diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager.cc similarity index 90% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager.cc index 4d75faf9755b..989b1e098f79 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" #include #include @@ -15,12 +15,12 @@ #include "bat/ads/internal/browser/browser_manager.h" #include "bat/ads/internal/tabs/tab_info.h" #include "bat/ads/internal/tabs/tab_manager.h" -#include "bat/ads/internal/user_interaction/browsing/page_transition_util.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_constants.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_features.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_scoring.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_util.h" +#include "bat/ads/internal/user_interaction/user_activity/page_transition_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_constants.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_util.h" #include "third_party/abseil-cpp/absl/types/optional.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager.h similarity index 86% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager.h index 60c3a3b1be8f..b3580dc45240 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager.h @@ -3,15 +3,15 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_MANAGER_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_MANAGER_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_MANAGER_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_MANAGER_H_ #include #include "bat/ads/internal/browser/browser_manager_observer.h" #include "bat/ads/internal/tabs/tab_manager_observer.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_info_aliases.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_types.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h" #include "bat/ads/page_transition_types.h" namespace base { @@ -63,4 +63,4 @@ class UserActivityManager final : public BrowserManagerObserver, } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_MANAGER_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_MANAGER_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager_unittest.cc similarity index 99% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager_unittest.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager_unittest.cc index 85bf8b09b1a7..96b36032af81 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_manager_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_manager_unittest.cc @@ -3,12 +3,12 @@ * 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/user_interaction/browsing/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" #include "bat/ads/internal/base/containers/container_util.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/base/unittest/unittest_time_util.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_constants.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_constants.h" // npm run test -- brave_unit_tests --filter=BatAds* diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring.cc similarity index 85% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring.cc index c0d910fe0e17..30e9e7d2afad 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/user_activity_scoring.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h" #include #include @@ -11,10 +11,10 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_features.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_util.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h similarity index 65% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h index 16c01807433a..4c23ed3dab99 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h @@ -3,11 +3,11 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_SCORING_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_SCORING_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_SCORING_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_SCORING_H_ -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_info_aliases.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h" namespace ads { @@ -16,4 +16,4 @@ double GetUserActivityScore(const UserActivityTriggerList& triggers, } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_SCORING_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_SCORING_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_unittest.cc similarity index 96% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_unittest.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_unittest.cc index 4a11156aec3e..27d21ed9932b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_unittest.cc @@ -3,11 +3,11 @@ * 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/user_interaction/browsing/user_activity_scoring.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h" #include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_util.h" // npm run test -- brave_unit_tests --filter=BatAds* diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.cc similarity index 58% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.cc index 4431ea34e835..95de9824ecc0 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.cc @@ -3,14 +3,14 @@ * 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/user_interaction/browsing/user_activity_scoring_util.h" - -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_info.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_features.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_scoring.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.h" + +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_info.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_util.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.h similarity index 75% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.h index 5ba0794cb68e..56844e4e5d95 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.h @@ -3,8 +3,8 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_SCORING_UTIL_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_SCORING_UTIL_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_SCORING_UTIL_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_SCORING_UTIL_H_ namespace ads { @@ -12,4 +12,4 @@ bool WasUserActive(); } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_SCORING_UTIL_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_SCORING_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util_unittest.cc similarity index 91% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util_unittest.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util_unittest.cc index 2f36574dfaa7..a06ba67fb969 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_scoring_util_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util_unittest.cc @@ -3,14 +3,14 @@ * 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/user_interaction/browsing/user_activity_scoring_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_scoring_util.h" #include #include "base/test/scoped_feature_list.h" #include "bat/ads/internal/base/unittest/unittest_base.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_features.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_features.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" // npm run test -- brave_unit_tests --filter=BatAds* diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.cc similarity index 91% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.cc index 48c9e8c304fa..04841ac14852 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/user_activity_trigger_info.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h" #include "bat/ads/internal/base/numbers/number_util.h" diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h similarity index 85% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h index bacca640a2f5..5ab40c0271fa 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h @@ -3,8 +3,8 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_TRIGGER_INFO_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_TRIGGER_INFO_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_TRIGGER_INFO_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_TRIGGER_INFO_H_ #include @@ -25,4 +25,4 @@ struct UserActivityTriggerInfo final { } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_TRIGGER_INFO_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_TRIGGER_INFO_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h similarity index 68% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h index f0fa0ea6d9c9..d7018eb40d2b 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h @@ -3,12 +3,12 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_TRIGGER_INFO_ALIASES_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_TRIGGER_INFO_ALIASES_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_TRIGGER_INFO_ALIASES_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_TRIGGER_INFO_ALIASES_H_ #include -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h" namespace ads { @@ -16,4 +16,4 @@ using UserActivityTriggerList = std::vector; } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_TRIGGER_INFO_ALIASES_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_TRIGGER_INFO_ALIASES_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util.cc similarity index 93% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util.cc index 3390f6b88815..84f73f74ce31 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util.cc @@ -3,7 +3,7 @@ * 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/user_interaction/browsing/user_activity_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_util.h" #include #include @@ -12,7 +12,7 @@ #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/time/time.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h" namespace ads { diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util.h b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util.h similarity index 71% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util.h rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util.h index 125315c3a268..a290c8659530 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util.h @@ -3,15 +3,15 @@ * 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_USER_INTERACTION_BROWSING_USER_ACTIVITY_UTIL_H_ -#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_UTIL_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_UTIL_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_UTIL_H_ #include #include -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_info_aliases.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_event_types.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_event_types.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h" namespace ads { @@ -28,4 +28,4 @@ UserActivityTriggerList ToUserActivityTriggers(const std::string& param_value); } // namespace ads -#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_BROWSING_USER_ACTIVITY_UTIL_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_USER_INTERACTION_USER_ACTIVITY_USER_ACTIVITY_UTIL_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util_unittest.cc similarity index 94% rename from vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util_unittest.cc rename to vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util_unittest.cc index 89331b10adb5..75329c792817 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/browsing/user_activity_util_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/user_interaction/user_activity/user_activity_util_unittest.cc @@ -3,15 +3,15 @@ * 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/user_interaction/browsing/user_activity_scoring.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_scoring.h" #include "base/time/time.h" #include "bat/ads/internal/base/unittest/unittest_base.h" #include "bat/ads/internal/covariates/covariate_constants.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_manager.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_trigger_info_aliases.h" -#include "bat/ads/internal/user_interaction/browsing/user_activity_util.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_manager.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_trigger_info_aliases.h" +#include "bat/ads/internal/user_interaction/user_activity/user_activity_util.h" // npm run test -- brave_unit_tests --filter=BatAds* diff --git a/vendor/bat-native-ads/src/bat/ads/new_tab_page_ad_info_unittest.cc b/vendor/bat-native-ads/src/bat/ads/new_tab_page_ad_info_unittest.cc index 0ff701f4c369..c7fbea3073d8 100644 --- a/vendor/bat-native-ads/src/bat/ads/new_tab_page_ad_info_unittest.cc +++ b/vendor/bat-native-ads/src/bat/ads/new_tab_page_ad_info_unittest.cc @@ -9,7 +9,7 @@ #include "bat/ads/internal/deprecated/json/json_helper.h" #include "url/gurl.h" -// npm run test -- brave_unit_tests --filter=BatAdsNewTabPageAdInfoTest* +// npm run test -- brave_unit_tests --filter=BatAds* namespace ads {