From 9f2983560122087a1b7dddc8ca1390fc5ecc85c9 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Fri, 24 Nov 2023 12:00:37 -0500 Subject: [PATCH 1/6] [ads] Cleanup unused params --- .../account/deposits/deposits_database_table.cc | 2 +- .../internal/account/deposits/non_cash_deposit.cc | 2 +- .../account/user_data/fixed/conversion_user_data.cc | 2 +- .../brave_ads/core/internal/catalog/catalog.cc | 4 ++-- .../internal/common/unittest/unittest_base_util.cc | 6 +++--- .../internal/common/unittest/unittest_mock_util.cc | 2 +- .../core/internal/conversions/conversions.cc | 2 +- .../conversions/resource/conversion_resource.cc | 4 ++-- .../resource/conversion_resource_unittest.cc | 6 +++--- .../brave_ads/core/internal/database/database.cc | 2 +- .../database/database_migration_unittest.cc | 8 ++++---- .../database/invalid_database_migration_unittest.cc | 8 ++++---- .../eligible_inline_content_ads_v1.cc | 6 +++--- .../new_tab_page_ads/eligible_new_tab_page_ads_v1.cc | 6 +++--- .../new_tab_page_ads/eligible_new_tab_page_ads_v2.cc | 2 +- .../notification_ads/eligible_notification_ads_v1.cc | 6 +++--- .../notification_ads/eligible_notification_ads_v2.cc | 2 +- .../notification_ads/eligible_notification_ads_v3.cc | 2 +- .../resource/anti_targeting_resource.cc | 2 +- .../resource/anti_targeting_resource_unittest.cc | 6 +++--- .../purchase_intent/purchase_intent_processor.cc | 4 ++-- .../resource/purchase_intent_resource.cc | 2 +- .../resource/purchase_intent_resource_unittest.cc | 6 +++--- .../resource/text_classification_resource.cc | 2 +- .../text_classification_resource_unittest.cc | 6 +++--- .../text_classification_processor.cc | 2 +- .../resource/text_embedding_resource.cc | 2 +- .../resource/text_embedding_resource_unittest.cc | 6 +++--- .../text_embedding/text_embedding_processor.cc | 2 +- .../inline_content_ad/inline_content_ad_handler.cc | 8 ++++---- .../units/new_tab_page_ad/new_tab_page_ad_handler.cc | 10 +++++----- .../units/notification_ad/notification_ad_handler.cc | 6 +++--- .../promoted_content_ad_handler.cc | 11 +++++------ .../search_result_ad/search_result_ad_handler.cc | 10 +++++----- .../user_activity/user_activity_manager.cc | 12 ++++++------ .../notification_ad_event_timed_out.cc | 2 +- 36 files changed, 85 insertions(+), 86 deletions(-) diff --git a/components/brave_ads/core/internal/account/deposits/deposits_database_table.cc b/components/brave_ads/core/internal/account/deposits/deposits_database_table.cc index 6e82355d65c5..690891bcd0e7 100644 --- a/components/brave_ads/core/internal/account/deposits/deposits_database_table.cc +++ b/components/brave_ads/core/internal/account/deposits/deposits_database_table.cc @@ -78,7 +78,7 @@ DepositInfo GetFromRecord(mojom::DBRecordInfo* record) { } void GetForCreativeInstanceIdCallback( - const std::string& /*creative_instance_id=*/, + const std::string& /*creative_instance_id*/, GetDepositsCallback callback, mojom::DBCommandResponseInfoPtr command_response) { if (!command_response || diff --git a/components/brave_ads/core/internal/account/deposits/non_cash_deposit.cc b/components/brave_ads/core/internal/account/deposits/non_cash_deposit.cc index 68ec9121064c..728519857459 100644 --- a/components/brave_ads/core/internal/account/deposits/non_cash_deposit.cc +++ b/components/brave_ads/core/internal/account/deposits/non_cash_deposit.cc @@ -11,7 +11,7 @@ namespace brave_ads { -void NonCashDeposit::GetValue(const std::string& /*creative_instance_id=*/, +void NonCashDeposit::GetValue(const std::string& /*creative_instance_id*/, GetDepositCallback callback) { std::move(callback).Run(/*success=*/true, /* value=*/0.0); } diff --git a/components/brave_ads/core/internal/account/user_data/fixed/conversion_user_data.cc b/components/brave_ads/core/internal/account/user_data/fixed/conversion_user_data.cc index 68d0232a2edf..1d0c4ea1cc03 100644 --- a/components/brave_ads/core/internal/account/user_data/fixed/conversion_user_data.cc +++ b/components/brave_ads/core/internal/account/user_data/fixed/conversion_user_data.cc @@ -27,7 +27,7 @@ void BuildConversionUserData(const std::string& creative_instance_id, creative_instance_id, base::BindOnce( [](BuildUserDataCallback callback, const bool success, - const std::string& /*creative_instance_id=*/, + const std::string& /*creative_instance_id*/, const ConversionQueueItemList& conversion_queue_items) { if (!success) { return std::move(callback).Run(/*user_data=*/{}); diff --git a/components/brave_ads/core/internal/catalog/catalog.cc b/components/brave_ads/core/internal/catalog/catalog.cc index dc33d82af55e..517061de1059 100644 --- a/components/brave_ads/core/internal/catalog/catalog.cc +++ b/components/brave_ads/core/internal/catalog/catalog.cc @@ -138,8 +138,8 @@ void Catalog::OnFailedToFetchCatalog() { NotifyFailedToUpdateCatalog(); } -void Catalog::OnDidMigrateDatabase(const int /*from_version=*/, - const int /*to_version=*/) { +void Catalog::OnDidMigrateDatabase(const int /*from_version*/, + const int /*to_version*/) { ResetCatalog(); } diff --git a/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc index 715984ba9604..5b85e032347c 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc @@ -138,8 +138,8 @@ void MockResetAdEventCacheForInstanceId(const AdsClientMock& mock) { void MockSave(AdsClientMock& mock) { ON_CALL(mock, Save) - .WillByDefault(::testing::Invoke([](const std::string& /*name=*/, - const std::string& /*value=*/, + .WillByDefault(::testing::Invoke([](const std::string& /*name*/, + const std::string& /*value*/, SaveCallback callback) { std::move(callback).Run(/*success=*/true); })); @@ -168,7 +168,7 @@ void MockLoadFileResource(AdsClientMock& mock, const base::ScopedTempDir& temp_dir) { ON_CALL(mock, LoadFileResource) .WillByDefault(::testing::Invoke( - [&temp_dir](const std::string& id, const int /*version=*/, + [&temp_dir](const std::string& id, const int /*version*/, LoadFileCallback callback) { base::FilePath path = temp_dir.GetPath().AppendASCII(id); diff --git a/components/brave_ads/core/internal/common/unittest/unittest_mock_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_mock_util.cc index ba91840de3ee..bb407c8ed092 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_mock_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_mock_util.cc @@ -131,7 +131,7 @@ void MockGetBrowsingHistory(AdsClientMock& mock, const std::vector& history) { ON_CALL(mock, GetBrowsingHistory) .WillByDefault(::testing::Invoke( - [history](const size_t max_count, const size_t /*recent_day_range=*/, + [history](const size_t max_count, const size_t /*recent_day_range*/, GetBrowsingHistoryCallback callback) { CHECK_LE(history.size(), max_count); diff --git a/components/brave_ads/core/internal/conversions/conversions.cc b/components/brave_ads/core/internal/conversions/conversions.cc index 6258a9d21603..441d2447b432 100644 --- a/components/brave_ads/core/internal/conversions/conversions.cc +++ b/components/brave_ads/core/internal/conversions/conversions.cc @@ -292,7 +292,7 @@ void Conversions::OnDidExhaustConversionQueue() { } void Conversions::OnHtmlContentDidChange( - const int32_t /*tab_id=*/, + const int32_t /*tab_id*/, const std::vector& redirect_chain, const std::string& html) { MaybeConvert(redirect_chain, html); diff --git a/components/brave_ads/core/internal/conversions/resource/conversion_resource.cc b/components/brave_ads/core/internal/conversions/resource/conversion_resource.cc index 8cb0ff33e381..2b0ac55ff354 100644 --- a/components/brave_ads/core/internal/conversions/resource/conversion_resource.cc +++ b/components/brave_ads/core/internal/conversions/resource/conversion_resource.cc @@ -63,12 +63,12 @@ void ConversionResource::LoadCallback( } void ConversionResource::OnNotifyLocaleDidChange( - const std::string& /*locale=*/) { + const std::string& /*locale*/) { Load(); } void ConversionResource::OnNotifyDidUpdateResourceComponent( - const std::string& /*manifest_version=*/, + const std::string& /*manifest_version*/, const std::string& id) { if (IsValidCountryComponentId(id)) { Load(); diff --git a/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc b/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc index 3ffdfe6c0048..682fff8372de 100644 --- a/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc +++ b/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc @@ -56,9 +56,9 @@ TEST_F(BraveAdsConversionResourceTest, DoNotLoadMissingResource) { // Arrange ON_CALL(ads_client_mock_, LoadFileResource(kConversionResourceId, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( - [](const std::string& /*id=*/, const int /*version=*/, - LoadFileCallback callback) { + .WillByDefault( + ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, + LoadFileCallback callback) { const base::FilePath path = GetFileResourcePath().AppendASCII(kMissingResourceId); diff --git a/components/brave_ads/core/internal/database/database.cc b/components/brave_ads/core/internal/database/database.cc index 95587d745889..19551e1e73c1 100644 --- a/components/brave_ads/core/internal/database/database.cc +++ b/components/brave_ads/core/internal/database/database.cc @@ -264,7 +264,7 @@ void Database::ErrorCallback(const int error, sql::Statement* statement) { void Database::MemoryPressureListenerCallback( base::MemoryPressureListener:: - MemoryPressureLevel /*memory_pressure_level=*/) { + MemoryPressureLevel /*memory_pressure_level*/) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); db_.TrimMemory(); } diff --git a/components/brave_ads/core/internal/legacy_migration/database/database_migration_unittest.cc b/components/brave_ads/core/internal/legacy_migration/database/database_migration_unittest.cc index 73c1f5d399d5..e9cc912ba156 100644 --- a/components/brave_ads/core/internal/legacy_migration/database/database_migration_unittest.cc +++ b/components/brave_ads/core/internal/legacy_migration/database/database_migration_unittest.cc @@ -64,13 +64,13 @@ class BraveAdsDatabaseMigrationTest : public UnitTestBase, // DatabaseManagerObserver: void OnDidCreateDatabase() override { did_create_database_ = true; } - void OnDidMigrateDatabase(const int /*from_version=*/, - const int /*to_version=*/) override { + void OnDidMigrateDatabase(const int /*from_version*/, + const int /*to_version*/) override { did_migrate_database_ = true; } - void OnFailedToMigrateDatabase(const int /*from_version=*/, - const int /*to_version=*/) override { + void OnFailedToMigrateDatabase(const int /*from_version*/, + const int /*to_version*/) override { failed_to_migrate_database_ = true; } diff --git a/components/brave_ads/core/internal/legacy_migration/database/invalid_database_migration_unittest.cc b/components/brave_ads/core/internal/legacy_migration/database/invalid_database_migration_unittest.cc index ccf0526d30c5..7a31d59413dc 100644 --- a/components/brave_ads/core/internal/legacy_migration/database/invalid_database_migration_unittest.cc +++ b/components/brave_ads/core/internal/legacy_migration/database/invalid_database_migration_unittest.cc @@ -51,13 +51,13 @@ class BraveAdsInvalidDatabaseMigrationTest // DatabaseManagerObserver: void OnDidCreateDatabase() override { did_create_database_ = true; } - void OnDidMigrateDatabase(const int /*from_version=*/, - const int /*to_version=*/) override { + void OnDidMigrateDatabase(const int /*from_version*/, + const int /*to_version*/) override { did_migrate_database_ = true; } - void OnFailedToMigrateDatabase(const int /*from_version=*/, - const int /*to_version=*/) override { + void OnFailedToMigrateDatabase(const int /*from_version*/, + const int /*to_version*/) override { failed_to_migrate_database_ = true; } diff --git a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1.cc b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1.cc index 940f7af2632d..fee734af8430 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/inline_content_ads/eligible_inline_content_ads_v1.cc @@ -114,7 +114,7 @@ void EligibleInlineContentAdsV1::GetForChildSegmentsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeInlineContentAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for child segments"); @@ -168,7 +168,7 @@ void EligibleInlineContentAdsV1::GetForParentSegmentsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeInlineContentAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for parent segments"); @@ -211,7 +211,7 @@ void EligibleInlineContentAdsV1::GetForUntargetedCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeInlineContentAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for untargeted segment"); diff --git a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1.cc b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1.cc index 00c30d640e7c..b120ccadd5f8 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v1.cc @@ -107,7 +107,7 @@ void EligibleNewTabPageAdsV1::GetForChildSegmentsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNewTabPageAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for child segments"); @@ -158,7 +158,7 @@ void EligibleNewTabPageAdsV1::GetForParentSegmentsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNewTabPageAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for parent segments"); @@ -199,7 +199,7 @@ void EligibleNewTabPageAdsV1::GetForUntargetedCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNewTabPageAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for untargeted segment"); diff --git a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2.cc b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2.cc index df404806b268..87beddb8b5a1 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/new_tab_page_ads/eligible_new_tab_page_ads_v2.cc @@ -83,7 +83,7 @@ void EligibleNewTabPageAdsV2::GetEligibleAdsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNewTabPageAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads"); diff --git a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1.cc b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1.cc index 38e5977312a4..8749513599dc 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v1.cc @@ -107,7 +107,7 @@ void EligibleNotificationAdsV1::GetForChildSegmentsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNotificationAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for child segments"); @@ -158,7 +158,7 @@ void EligibleNotificationAdsV1::GetForParentSegmentsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNotificationAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for parent segments"); @@ -199,7 +199,7 @@ void EligibleNotificationAdsV1::GetForUntargetedCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNotificationAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads for untargeted segment"); diff --git a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2.cc b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2.cc index 7e7c4bfc80e9..ad67f8c2da53 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v2.cc @@ -84,7 +84,7 @@ void EligibleNotificationAdsV2::GetEligibleAdsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNotificationAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads"); diff --git a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v3.cc b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v3.cc index f61651c9ef28..47c1a732ed22 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v3.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/pipelines/notification_ads/eligible_notification_ads_v3.cc @@ -84,7 +84,7 @@ void EligibleNotificationAdsV3::GetEligibleAdsCallback( const BrowsingHistoryList& browsing_history, EligibleAdsCallback callback, const bool success, - const SegmentList& /*segments=*/, + const SegmentList& /*segments*/, const CreativeNotificationAdList& creative_ads) { if (!success) { BLOG(1, "Failed to get ads"); diff --git a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc index 5dcada25ffda..f0fc58eed761 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource.cc @@ -110,7 +110,7 @@ void AntiTargetingResource::Reset() { } void AntiTargetingResource::OnNotifyLocaleDidChange( - const std::string& /*locale=*/) { + const std::string& /*locale*/) { MaybeLoad(); } diff --git a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc index 498d19bc1717..15f0e4aa4de6 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc @@ -57,9 +57,9 @@ TEST_F(BraveAdsAntiTargetingResourceTest, DoNotLoadMissingResource) { // Arrange ON_CALL(ads_client_mock_, LoadFileResource(kAntiTargetingResourceId, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( - [](const std::string& /*id=*/, const int /*version=*/, - LoadFileCallback callback) { + .WillByDefault( + ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, + LoadFileCallback callback) { const base::FilePath path = GetFileResourcePath().AppendASCII(kMissingResourceId); diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.cc b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.cc index 7b8ef495a2d1..d168e0fd76ff 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.cc @@ -181,9 +181,9 @@ uint16_t PurchaseIntentProcessor::GetFunnelWeightForSearchQuery( } void PurchaseIntentProcessor::OnTextContentDidChange( - const int32_t /*tab_id=*/, + const int32_t /*tab_id*/, const std::vector& redirect_chain, - const std::string& /*text=*/) { + const std::string& /*text*/) { if (redirect_chain.empty()) { return; } diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.cc b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.cc index 8577bcc7a39b..6d945bd8e734 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource.cc @@ -94,7 +94,7 @@ void PurchaseIntentResource::Reset() { } void PurchaseIntentResource::OnNotifyLocaleDidChange( - const std::string& /*locale=*/) { + const std::string& /*locale*/) { MaybeLoad(); } diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc index b1b6e8193ca2..878a210e0acf 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc @@ -57,9 +57,9 @@ TEST_F(BraveAdsPurchaseIntentResourceTest, DoNotLoadMissingResource) { // Arrange ON_CALL(ads_client_mock_, LoadFileResource(kPurchaseIntentResourceId, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( - [](const std::string& /*id=*/, const int /*version=*/, - LoadFileCallback callback) { + .WillByDefault( + ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, + LoadFileCallback callback) { const base::FilePath path = GetFileResourcePath().AppendASCII(kMissingResourceId); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc index 477a74fbf3d2..94345a05fcc2 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc @@ -128,7 +128,7 @@ void TextClassificationResource::Reset() { } void TextClassificationResource::OnNotifyLocaleDidChange( - const std::string& /*locale=*/) { + const std::string& /*locale*/) { MaybeLoad(); } diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc index da0911709c84..2b6b6ed520ed 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc @@ -58,9 +58,9 @@ TEST_F(BraveAdsTextClassificationResourceTest, DoNotLoadMissingResource) { ON_CALL(ads_client_mock_, LoadFileResource(kFlatBuffersTextClassificationResourceId, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( - [](const std::string& /*id=*/, const int /*version=*/, - LoadFileCallback callback) { + .WillByDefault( + ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, + LoadFileCallback callback) { const base::FilePath path = GetFileResourcePath().AppendASCII(kMissingResourceId); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/text_classification_processor.cc b/components/brave_ads/core/internal/targeting/contextual/text_classification/text_classification_processor.cc index 1133e9cb859f..20f85d6aca2a 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/text_classification_processor.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/text_classification_processor.cc @@ -76,7 +76,7 @@ void TextClassificationProcessor::ClassifyPageCallback( /////////////////////////////////////////////////////////////////////////////// void TextClassificationProcessor::OnTextContentDidChange( - const int32_t /*tab_id=*/, + const int32_t /*tab_id*/, const std::vector& redirect_chain, const std::string& text) { if (redirect_chain.empty()) { diff --git a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource.cc b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource.cc index cdbe755fa0f7..ac3fb120041e 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource.cc @@ -93,7 +93,7 @@ void TextEmbeddingResource::Reset() { } void TextEmbeddingResource::OnNotifyLocaleDidChange( - const std::string& /*locale=*/) { + const std::string& /*locale*/) { MaybeLoad(); } diff --git a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc index 07e89d55c085..1537e35a254c 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc @@ -57,9 +57,9 @@ TEST_F(BraveAdsTextEmbeddingResourceTest, DoNotLoadMissingResource) { // Arrange ON_CALL(ads_client_mock_, LoadFileResource(kTextEmbeddingResourceId, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( - [](const std::string& /*id=*/, const int /*version=*/, - LoadFileCallback callback) { + .WillByDefault( + ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, + LoadFileCallback callback) { const base::FilePath path = GetFileResourcePath().AppendASCII(kMissingResourceId); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_embedding/text_embedding_processor.cc b/components/brave_ads/core/internal/targeting/contextual/text_embedding/text_embedding_processor.cc index e9edaaf56169..d8d73f4ab890 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_embedding/text_embedding_processor.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_embedding/text_embedding_processor.cc @@ -86,7 +86,7 @@ void TextEmbeddingProcessor::Process(const std::string& html) { /////////////////////////////////////////////////////////////////////////////// void TextEmbeddingProcessor::OnHtmlContentDidChange( - const int32_t /*tab_id=*/, + const int32_t /*tab_id*/, const std::vector& redirect_chain, const std::string& html) { if (redirect_chain.empty()) { diff --git a/components/brave_ads/core/internal/units/inline_content_ad/inline_content_ad_handler.cc b/components/brave_ads/core/internal/units/inline_content_ad/inline_content_ad_handler.cc index 291a031e45e4..8d73b8a6e98b 100644 --- a/components/brave_ads/core/internal/units/inline_content_ad/inline_content_ad_handler.cc +++ b/components/brave_ads/core/internal/units/inline_content_ad/inline_content_ad_handler.cc @@ -33,8 +33,8 @@ void FireServedEventCallback( const InlineContentAdInfo& ad, MaybeServeInlineContentAdCallback callback, const bool success, - const std::string& /*placement_id=*/, - const mojom::InlineContentAdEventType /*event_type=*/) { + const std::string& /*placement_id*/, + const mojom::InlineContentAdEventType /*event_type*/) { if (!success) { return std::move(callback).Run(dimensions, /*ad=*/absl::nullopt); } @@ -44,8 +44,8 @@ void FireServedEventCallback( void FireEventCallback(TriggerAdEventCallback callback, const bool success, - const std::string& /*placement_id=*/, - const mojom::InlineContentAdEventType /*event_type=*/) { + const std::string& /*placement_id*/, + const mojom::InlineContentAdEventType /*event_type*/) { std::move(callback).Run(success); } diff --git a/components/brave_ads/core/internal/units/new_tab_page_ad/new_tab_page_ad_handler.cc b/components/brave_ads/core/internal/units/new_tab_page_ad/new_tab_page_ad_handler.cc index 473834d75374..69c44fbf34e9 100644 --- a/components/brave_ads/core/internal/units/new_tab_page_ad/new_tab_page_ad_handler.cc +++ b/components/brave_ads/core/internal/units/new_tab_page_ad/new_tab_page_ad_handler.cc @@ -32,8 +32,8 @@ void FireServedEventCallback( const NewTabPageAdInfo& ad, MaybeServeNewTabPageAdCallback callback, const bool success, - const std::string& /*placement_id=*/, - const mojom::NewTabPageAdEventType /*event_type=*/) { + const std::string& /*placement_id*/, + const mojom::NewTabPageAdEventType /*event_type*/) { if (!success) { return std::move(callback).Run(/*ad=*/absl::nullopt); } @@ -43,8 +43,8 @@ void FireServedEventCallback( void FireEventCallback(TriggerAdEventCallback callback, const bool success, - const std::string& /*placement_id=*/, - const mojom::NewTabPageAdEventType /*event_type=*/) { + const std::string& /*placement_id*/, + const mojom::NewTabPageAdEventType /*event_type*/) { std::move(callback).Run(success); } @@ -137,7 +137,7 @@ void NewTabPageAdHandler::TriggerServedEventCallback( TriggerAdEventCallback callback, const bool success, const std::string& placement_id, - const mojom::NewTabPageAdEventType /*event_type=*/) { + const mojom::NewTabPageAdEventType /*event_type*/) { if (!success) { return std::move(callback).Run(/*success=*/false); } diff --git a/components/brave_ads/core/internal/units/notification_ad/notification_ad_handler.cc b/components/brave_ads/core/internal/units/notification_ad/notification_ad_handler.cc index f54d2c2164c9..55af4cc3ad3b 100644 --- a/components/brave_ads/core/internal/units/notification_ad/notification_ad_handler.cc +++ b/components/brave_ads/core/internal/units/notification_ad/notification_ad_handler.cc @@ -39,8 +39,8 @@ namespace { void FireEventCallback(TriggerAdEventCallback callback, const bool success, - const std::string& /*placement_id=*/, - const mojom::NotificationAdEventType /*event_type=*/) { + const std::string& /*placement_id*/, + const mojom::NotificationAdEventType /*event_type*/) { std::move(callback).Run(success); } @@ -116,7 +116,7 @@ void NotificationAdHandler::FireServedEventCallback( TriggerAdEventCallback callback, const bool success, const std::string& placement_id, - const mojom::NotificationAdEventType /*event_type=*/) { + const mojom::NotificationAdEventType /*event_type*/) { if (!success) { return std::move(callback).Run(/*success=*/false); } diff --git a/components/brave_ads/core/internal/units/promoted_content_ad/promoted_content_ad_handler.cc b/components/brave_ads/core/internal/units/promoted_content_ad/promoted_content_ad_handler.cc index 771fa5415c4d..18c8ab687dc5 100644 --- a/components/brave_ads/core/internal/units/promoted_content_ad/promoted_content_ad_handler.cc +++ b/components/brave_ads/core/internal/units/promoted_content_ad/promoted_content_ad_handler.cc @@ -20,11 +20,10 @@ namespace brave_ads { namespace { -void FireEventCallback( - TriggerAdEventCallback callback, - const bool success, - const std::string& /*placement_id=*/, - const mojom::PromotedContentAdEventType /*event_type=*/) { +void FireEventCallback(TriggerAdEventCallback callback, + const bool success, + const std::string& /*placement_id*/, + const mojom::PromotedContentAdEventType /*event_type*/) { std::move(callback).Run(success); } @@ -77,7 +76,7 @@ void PromotedContentAdHandler::TriggerServedEventCallback( TriggerAdEventCallback callback, const bool success, const std::string& placement_id, - const mojom::PromotedContentAdEventType /*event_type=*/) { + const mojom::PromotedContentAdEventType /*event_type*/) { if (!success) { return std::move(callback).Run(/*success=*/false); } diff --git a/components/brave_ads/core/internal/units/search_result_ad/search_result_ad_handler.cc b/components/brave_ads/core/internal/units/search_result_ad/search_result_ad_handler.cc index d8aac444b423..41415f503c49 100644 --- a/components/brave_ads/core/internal/units/search_result_ad/search_result_ad_handler.cc +++ b/components/brave_ads/core/internal/units/search_result_ad/search_result_ad_handler.cc @@ -32,8 +32,8 @@ bool g_defer_triggering_of_ad_viewed_event_for_testing = false; void FireEventCallback(TriggerAdEventCallback callback, const bool success, - const std::string& /*placement_id=*/, - const mojom::SearchResultAdEventType /*event_type=*/) { + const std::string& /*placement_id*/, + const mojom::SearchResultAdEventType /*event_type*/) { std::move(callback).Run(success); } @@ -98,8 +98,8 @@ void SearchResultAd::FireServedEventCallback( mojom::SearchResultAdInfoPtr ad_mojom, TriggerAdEventCallback callback, const bool success, - const std::string& /*placement_id=*/, - const mojom::SearchResultAdEventType /*event_type=*/) { + const std::string& /*placement_id*/, + const mojom::SearchResultAdEventType /*event_type*/) { if (!success) { return std::move(callback).Run(/*success=*/false); } @@ -131,7 +131,7 @@ void SearchResultAd::MaybeTriggerAdViewedEventFromQueue( void SearchResultAd::FireAdViewedEventCallback( TriggerAdEventCallback callback, const bool success, - const std::string& /*placement_id=*/, + const std::string& /*placement_id*/, const mojom::SearchResultAdEventType event_type) { CHECK(mojom::IsKnownEnumValue(event_type)); CHECK_EQ(event_type, mojom::SearchResultAdEventType::kViewed); diff --git a/components/brave_ads/core/internal/user/user_attention/user_activity/user_activity_manager.cc b/components/brave_ads/core/internal/user/user_attention/user_activity/user_activity_manager.cc index 3e1b8273f5ad..4a1e374fd261 100644 --- a/components/brave_ads/core/internal/user/user_attention/user_activity/user_activity_manager.cc +++ b/components/brave_ads/core/internal/user/user_attention/user_activity/user_activity_manager.cc @@ -154,27 +154,27 @@ void UserActivityManager::OnBrowserDidEnterBackground() { RecordEvent(UserActivityEventType::kBrowserDidEnterBackground); } -void UserActivityManager::OnTabDidChangeFocus(const int32_t /*tab_id=*/) { +void UserActivityManager::OnTabDidChangeFocus(const int32_t /*tab_id*/) { RecordEvent(UserActivityEventType::kTabChangedFocus); } -void UserActivityManager::OnTabDidChange(const TabInfo& /*tab=*/) { +void UserActivityManager::OnTabDidChange(const TabInfo& /*tab*/) { RecordEvent(UserActivityEventType::kTabUpdated); } -void UserActivityManager::OnDidOpenNewTab(const TabInfo& /*tab=*/) { +void UserActivityManager::OnDidOpenNewTab(const TabInfo& /*tab*/) { RecordEvent(UserActivityEventType::kOpenedNewTab); } -void UserActivityManager::OnDidCloseTab(const int32_t /*tab_id=*/) { +void UserActivityManager::OnDidCloseTab(const int32_t /*tab_id*/) { RecordEvent(UserActivityEventType::kClosedTab); } -void UserActivityManager::OnTabDidStartPlayingMedia(const int32_t /*tab_id=*/) { +void UserActivityManager::OnTabDidStartPlayingMedia(const int32_t /*tab_id*/) { RecordEvent(UserActivityEventType::kTabStartedPlayingMedia); } -void UserActivityManager::OnTabDidStopPlayingMedia(const int32_t /*tab_id=*/) { +void UserActivityManager::OnTabDidStopPlayingMedia(const int32_t /*tab_id*/) { RecordEvent(UserActivityEventType::kTabStoppedPlayingMedia); } diff --git a/components/brave_ads/core/internal/user/user_interaction/ad_events/notification_ads/notification_ad_event_timed_out.cc b/components/brave_ads/core/internal/user/user_interaction/ad_events/notification_ads/notification_ad_event_timed_out.cc index 8a9925d936e6..a49a6bbb2dba 100644 --- a/components/brave_ads/core/internal/user/user_interaction/ad_events/notification_ads/notification_ad_event_timed_out.cc +++ b/components/brave_ads/core/internal/user/user_interaction/ad_events/notification_ads/notification_ad_event_timed_out.cc @@ -11,7 +11,7 @@ namespace brave_ads { -void NotificationAdEventTimedOut::FireEvent(const NotificationAdInfo& /*ad=*/, +void NotificationAdEventTimedOut::FireEvent(const NotificationAdInfo& /*ad*/, ResultCallback callback) { std::move(callback).Run(/*success=*/true); } From 1bb2b90ada622cca497ed7170af19cfbe18bb249 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Fri, 24 Nov 2023 11:54:05 -0500 Subject: [PATCH 2/6] [ads] Cleanup test data --- ...atalog_url_request_json_reader_unittest.cc | 26 ++++---- .../internal/common/unittest/unittest_base.cc | 6 +- .../common/unittest/unittest_base_util.cc | 9 ++- .../unittest/unittest_file_path_util.cc | 59 +++---------------- .../common/unittest/unittest_file_path_util.h | 15 +---- .../common/unittest/unittest_file_util.cc | 51 ++++++++++++++++ .../common/unittest/unittest_file_util.h | 25 ++++++++ .../unittest/unittest_url_response_util.cc | 8 +-- .../resource/conversion_resource_unittest.cc | 5 +- .../pipeline/linear_pipeline_util_unittest.cc | 10 ++-- .../pipeline/neural_pipeline_util_unittest.cc | 10 ++-- .../text_processing_unittest.cc | 51 ++++++++-------- .../hash_vectorizer_unittest.cc | 4 +- .../segments/segment_util_unittest.cc | 11 ++-- .../anti_targeting_resource_unittest.cc | 5 +- .../purchase_intent_resource_unittest.cc | 5 +- .../text_classification_resource_unittest.cc | 5 +- .../text_embedding_resource_unittest.cc | 5 +- components/brave_ads/core/test/BUILD.gn | 2 + 19 files changed, 176 insertions(+), 136 deletions(-) create mode 100644 components/brave_ads/core/internal/common/unittest/unittest_file_util.cc create mode 100644 components/brave_ads/core/internal/common/unittest/unittest_file_util.h diff --git a/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc b/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc index 2e11bfc95473..dc64939469dd 100644 --- a/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc +++ b/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc @@ -23,7 +23,7 @@ #include "brave/components/brave_ads/core/internal/catalog/catalog_info.h" #include "brave/components/brave_ads/core/internal/catalog/catalog_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" -#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_time_util.h" #include "url/gurl.h" @@ -431,10 +431,10 @@ class BraveAdsCatalogUrlRequestJsonReaderTest : public UnitTestBase {}; TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, ParseCatalogWithSingleCampaign) { // Arrange - const absl::optional json = - ReadFileFromTestPathAndParseTagsToString( + const absl::optional contents = + MaybeReadAndReplaceTagsForFileResourceToString( kCatalogWithSingleCampaignFilename); - ASSERT_TRUE(json); + ASSERT_TRUE(contents); // Act & Assert CatalogInfo expected_catalog; @@ -442,16 +442,16 @@ TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, expected_catalog.version = 9; expected_catalog.ping = base::Milliseconds(7'200'000); expected_catalog.campaigns.push_back(BuildCatalogCampaign1()); - EXPECT_EQ(expected_catalog, json::reader::ReadCatalog(*json)); + EXPECT_EQ(expected_catalog, json::reader::ReadCatalog(*contents)); } TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, ParseCatalogWithMultipleCampaigns) { // Arrange - const absl::optional json = - ReadFileFromTestPathAndParseTagsToString( + const absl::optional contents = + MaybeReadAndReplaceTagsForFileResourceToString( kCatalogWithMultipleCampaignsFilename); - ASSERT_TRUE(json); + ASSERT_TRUE(contents); // Act & Assert CatalogInfo expected_catalog; @@ -460,21 +460,21 @@ TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, expected_catalog.ping = base::Milliseconds(7'200'000); expected_catalog.campaigns.push_back(BuildCatalogCampaign1()); expected_catalog.campaigns.push_back(BuildCatalogCampaign2()); - EXPECT_EQ(expected_catalog, json::reader::ReadCatalog(*json)); + EXPECT_EQ(expected_catalog, json::reader::ReadCatalog(*contents)); } TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, ParseEmptyCatalog) { // Arrange - const absl::optional json = - ReadFileFromTestPathAndParseTagsToString(kEmptyCatalogFilename); - ASSERT_TRUE(json); + const absl::optional contents = + MaybeReadAndReplaceTagsForFileResourceToString(kEmptyCatalogFilename); + ASSERT_TRUE(contents); // Act & Assert CatalogInfo expected_catalog; expected_catalog.id = kCatalogId; expected_catalog.version = 9; expected_catalog.ping = base::Milliseconds(7'200'000); - EXPECT_EQ(expected_catalog, json::reader::ReadCatalog(*json)); + EXPECT_EQ(expected_catalog, json::reader::ReadCatalog(*contents)); } TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, InvalidCatalog) { diff --git a/components/brave_ads/core/internal/common/unittest/unittest_base.cc b/components/brave_ads/core/internal/common/unittest/unittest_base.cc index 1f8f37a60905..15d03a654231 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_base.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_base.cc @@ -88,7 +88,8 @@ bool UnitTestBase::CopyFileFromTestPathToTempPath( CHECK(setup_called_) << "CopyFileFromTestPathToTempPath should be called after SetUp"; - const base::FilePath from_test_path = GetTestPath().AppendASCII(from_path); + const base::FilePath from_test_path = + TestDataFileResourcesPath().AppendASCII(from_path); const base::FilePath to_temp_path = temp_dir_.GetPath().AppendASCII(to_path); return base::CopyFile(from_test_path, to_temp_path); @@ -105,7 +106,8 @@ bool UnitTestBase::CopyDirectoryFromTestPathToTempPath( CHECK(setup_called_) << "CopyDirectoryFromTestPathToTempPath should be called after SetUp"; - const base::FilePath from_test_path = GetTestPath().AppendASCII(from_path); + const base::FilePath from_test_path = + TestDataFileResourcesPath().AppendASCII(from_path); const base::FilePath to_temp_path = temp_dir_.GetPath().AppendASCII(to_path); return base::CopyDirectory(from_test_path, to_temp_path, diff --git a/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc index 5b85e032347c..dc46c59ad1f8 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc @@ -22,6 +22,7 @@ #include "brave/components/brave_ads/core/internal/common/unittest/unittest_command_line_switch_util.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_current_test_util.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_local_state_pref_value_util.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_profile_pref_value_util.h" #include "brave/components/brave_ads/core/internal/global_state/global_state.h" @@ -152,7 +153,7 @@ void MockLoad(AdsClientMock& mock, const base::ScopedTempDir& temp_dir) { base::FilePath path = temp_dir.GetPath().AppendASCII(name); if (!base::PathExists(path)) { // If path does not exist load the file from the test path. - path = GetTestPath().AppendASCII(name); + path = TestDataFileResourcesPath().AppendASCII(name); } std::string value; @@ -174,7 +175,9 @@ void MockLoadFileResource(AdsClientMock& mock, if (!base::PathExists(path)) { // If path does not exist load the file from the test path. - path = GetFileResourcePath().AppendASCII(id); + path = TestDataFileResourcesPath() + .AppendASCII("resources") + .AppendASCII(id); } base::File file(path, base::File::Flags::FLAG_OPEN | @@ -187,7 +190,7 @@ void MockLoadDataResource(AdsClientMock& mock) { ON_CALL(mock, LoadDataResource) .WillByDefault( ::testing::Invoke([](const std::string& name) -> std::string { - return ReadFileFromDataResourcePathToString(name).value_or(""); + return MaybeReadDataResourceToString(name).value_or(""); })); } diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc index 7f1d92c6b821..6c54d4ddc0a6 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc @@ -5,70 +5,29 @@ #include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" -#include "base/base_paths.h" -#include "base/files/file_util.h" +#include "base/base_paths.h"xx #include "base/path_service.h" -#include "brave/components/brave_ads/core/internal/common/unittest/unittest_tag_parser_util.h" namespace brave_ads { namespace { -absl::optional ReadFileToString(const base::FilePath& path) { - std::string content; - if (!base::ReadFileToString(path, &content)) { - return absl::nullopt; - } - - return content; -} - -} // namespace - -base::FilePath GetTestPath() { +base::FilePath TestDataRootPath() { return base::PathService::CheckedGet(base::DIR_SRC_TEST_DATA_ROOT) .AppendASCII("brave") .AppendASCII("components") - .AppendASCII("brave_ads") - .AppendASCII("core") - .AppendASCII("test") - .AppendASCII("data"); -} - -absl::optional ReadFileFromTestPathToString( - const std::string& name) { - const base::FilePath path = GetTestPath().AppendASCII(name); - return ReadFileToString(path); -} - -absl::optional ReadFileFromTestPathAndParseTagsToString( - const std::string& name) { - absl::optional content = ReadFileFromTestPathToString(name); - if (!content) { - return absl::nullopt; - } - - ParseAndReplaceTags(*content); - - return *content; + .AppendASCII("brave_ads"); } -base::FilePath GetFileResourcePath() { - return GetTestPath().AppendASCII("resources"); -} +} // namespace -base::FilePath GetDataResourcePath() { - return base::PathService::CheckedGet(base::DIR_SRC_TEST_DATA_ROOT) - .AppendASCII("brave") - .AppendASCII("components") - .AppendASCII("brave_ads") - .AppendASCII("resources"); +base::FilePath TestDataFileResourcesPath() { + return TestDataRootPath().AppendASCII("core").AppendASCII("test").AppendASCII( + "data"); } -absl::optional ReadFileFromDataResourcePathToString( - const std::string& name) { - const base::FilePath path = GetDataResourcePath().AppendASCII(name); - return ReadFileToString(path); +base::FilePath DataResourcesPath() { + return TestDataRootPath().AppendASCII("resources"); } } // namespace brave_ads diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h index 640e174f8549..e79a7d7656c4 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h @@ -6,24 +6,13 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_UNITTEST_UNITTEST_FILE_PATH_UTIL_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_UNITTEST_UNITTEST_FILE_PATH_UTIL_H_ -#include - #include "base/files/file_path.h" -#include "third_party/abseil-cpp/absl/types/optional.h" namespace brave_ads { -base::FilePath GetTestPath(); -absl::optional ReadFileFromTestPathToString( - const std::string& name); -absl::optional ReadFileFromTestPathAndParseTagsToString( - const std::string& name); - -base::FilePath GetFileResourcePath(); +base::FilePath TestDataFileResourcesPath(); -base::FilePath GetDataResourcePath(); -absl::optional ReadFileFromDataResourcePathToString( - const std::string& name); +base::FilePath DataResourcesPath(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_file_util.cc new file mode 100644 index 000000000000..33f88b8fcdfb --- /dev/null +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_util.cc @@ -0,0 +1,51 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" + +#include "base/files/file_util.h" +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_tag_parser_util.h" + +namespace brave_ads { + +namespace { + +absl::optional MaybeReadFileToString(const base::FilePath& path) { + std::string content; + if (!base::ReadFileToString(path, &content)) { + return absl::nullopt; + } + + return content; +} + +} // namespace + +absl::optional MaybeReadFileResourceToString( + const std::string& name) { + const base::FilePath path = TestDataFileResourcesPath().AppendASCII(name); + return MaybeReadFileToString(path); +} + +absl::optional MaybeReadAndReplaceTagsForFileResourceToString( + const std::string& name) { + absl::optional contents = MaybeReadFileResourceToString(name); + if (!contents) { + return absl::nullopt; + } + + ParseAndReplaceTags(*contents); + + return *contents; +} + +absl::optional MaybeReadDataResourceToString( + const std::string& name) { + const base::FilePath path = DataResourcesPath().AppendASCII(name); + return MaybeReadFileToString(path); +} + +} // namespace brave_ads diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_util.h b/components/brave_ads/core/internal/common/unittest/unittest_file_util.h new file mode 100644 index 000000000000..b7684ebd74f6 --- /dev/null +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_util.h @@ -0,0 +1,25 @@ +/* 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_UNITTEST_UNITTEST_FILE_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_UNITTEST_UNITTEST_FILE_UTIL_H_ + +#include + +#include "third_party/abseil-cpp/absl/types/optional.h" + +namespace brave_ads { + +absl::optional MaybeReadFileResourceToString( + const std::string& name); +absl::optional MaybeReadAndReplaceTagsForFileResourceToString( + const std::string& name); + +absl::optional MaybeReadDataResourceToString( + const std::string& name); + +} // namespace brave_ads + +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_UNITTEST_UNITTEST_FILE_UTIL_H_ diff --git a/components/brave_ads/core/internal/common/unittest/unittest_url_response_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_url_response_util.cc index 6a4ba4b5fcb4..7fc8e370b475 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_url_response_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_url_response_util.cc @@ -98,10 +98,10 @@ absl::optional GetNextUrlResponseForRequest( std::string response_body = url_response->second; if (ShouldReadResponseBodyFromFile(response_body)) { - const base::FilePath file_path = - GetTestPath().AppendASCII(ParseFilenameFromResponseBody(response_body)); - if (!base::ReadFileToString(file_path, &response_body)) { - NOTREACHED_NORETURN() << file_path << " not found"; + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + ParseFilenameFromResponseBody(response_body)); + if (!base::ReadFileToString(path, &response_body)) { + NOTREACHED_NORETURN() << path << " not found"; } ParseAndReplaceTags(response_body); diff --git a/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc b/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc index 682fff8372de..5fff8f05ca64 100644 --- a/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc +++ b/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc @@ -59,8 +59,9 @@ TEST_F(BraveAdsConversionResourceTest, DoNotLoadMissingResource) { .WillByDefault( ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, LoadFileCallback callback) { - const base::FilePath path = - GetFileResourcePath().AppendASCII(kMissingResourceId); + const base::FilePath path = TestDataFileResourcesPath() + .AppendASCII("resources") + .AppendASCII(kMissingResourceId); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/internal/ml/pipeline/linear_pipeline_util_unittest.cc b/components/brave_ads/core/internal/ml/pipeline/linear_pipeline_util_unittest.cc index c7c7ba8d69ac..946f0cd5343d 100644 --- a/components/brave_ads/core/internal/ml/pipeline/linear_pipeline_util_unittest.cc +++ b/components/brave_ads/core/internal/ml/pipeline/linear_pipeline_util_unittest.cc @@ -9,7 +9,7 @@ #include #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" -#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" #include "brave/components/brave_ads/core/internal/ml/pipeline/pipeline_info.h" // npm run test -- brave_unit_tests --filter=BraveAds* @@ -25,13 +25,13 @@ class BraveAdsLinearPipelineUtilTest : public UnitTestBase {}; TEST_F(BraveAdsLinearPipelineUtilTest, LoadLinearPipelineTest) { // Arrange - absl::optional buffer = - ReadFileFromTestPathToString(kValidSpamClassificationPipeline); - ASSERT_TRUE(buffer); + const absl::optional contents = + MaybeReadFileResourceToString(kValidSpamClassificationPipeline); + ASSERT_TRUE(contents); // Act & Assert EXPECT_TRUE(pipeline::LoadLinearPipeline( - reinterpret_cast(buffer->data()), buffer->size())); + reinterpret_cast(contents->data()), contents->size())); } } // namespace brave_ads::ml diff --git a/components/brave_ads/core/internal/ml/pipeline/neural_pipeline_util_unittest.cc b/components/brave_ads/core/internal/ml/pipeline/neural_pipeline_util_unittest.cc index fe5ce07e9560..3209cc95346c 100644 --- a/components/brave_ads/core/internal/ml/pipeline/neural_pipeline_util_unittest.cc +++ b/components/brave_ads/core/internal/ml/pipeline/neural_pipeline_util_unittest.cc @@ -9,7 +9,7 @@ #include #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" -#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" #include "brave/components/brave_ads/core/internal/ml/pipeline/pipeline_info.h" // npm run test -- brave_unit_tests --filter=BraveAds* @@ -25,13 +25,13 @@ class BraveAdsNeuralPipelineUtilTest : public UnitTestBase {}; TEST_F(BraveAdsNeuralPipelineUtilTest, LoadNeuralPipelineTest) { // Arrange - absl::optional buffer = - ReadFileFromTestPathToString(kOnlyRequiredFieldsNeuralModelPipeline); - ASSERT_TRUE(buffer); + const absl::optional contents = + MaybeReadFileResourceToString(kOnlyRequiredFieldsNeuralModelPipeline); + ASSERT_TRUE(contents); // Act & Assert EXPECT_TRUE(pipeline::LoadNeuralPipeline( - reinterpret_cast(buffer->data()), buffer->size())); + reinterpret_cast(contents->data()), contents->size())); } } // namespace brave_ads::ml diff --git a/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing_unittest.cc b/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing_unittest.cc index e62b66046f8b..2ac213c4373c 100644 --- a/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing_unittest.cc +++ b/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing_unittest.cc @@ -13,6 +13,7 @@ #include "base/files/file.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" #include "brave/components/brave_ads/core/internal/ml/data/data.h" #include "brave/components/brave_ads/core/internal/ml/data/text_data.h" #include "brave/components/brave_ads/core/internal/ml/data/vector_data.h" @@ -132,7 +133,7 @@ TEST_F(BraveAdsTextProcessingTest, TestLoadFromValue) { "junk"}; const base::FilePath path = - GetTestPath().AppendASCII(kValidSpamClassificationPipeline); + TestDataFileResourcesPath().AppendASCII(kValidSpamClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -162,8 +163,8 @@ TEST_F(BraveAdsTextProcessingTest, TestLoadFromValue) { TEST_F(BraveAdsTextProcessingTest, InitValidLinearModelTest) { // Arrange - const base::FilePath path = - GetTestPath().AppendASCII(kValidSegmentClassificationPipeline); + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + kValidSegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -175,8 +176,8 @@ TEST_F(BraveAdsTextProcessingTest, InitValidLinearModelTest) { TEST_F(BraveAdsTextProcessingTest, InitValidNeuralModelTest) { // Arrange - const base::FilePath path = - GetTestPath().AppendASCII(kOnlyRequiredFieldsNeuralModelPipeline); + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + kOnlyRequiredFieldsNeuralModelPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -190,8 +191,8 @@ TEST_F(BraveAdsTextProcessingTest, EmptySegmentModelTest) { // Arrange const std::string input_text = "This is a spam email."; - const base::FilePath path = - GetTestPath().AppendASCII(kEmptySegmentClassificationPipeline); + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + kEmptySegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -212,7 +213,7 @@ TEST_F(BraveAdsTextProcessingTest, EmptyTransformationsModelTest) { const std::string input_text = "This is a spam email."; const base::FilePath path = - GetTestPath().AppendASCII(kEmptyTransformationsPipeline); + TestDataFileResourcesPath().AppendASCII(kEmptyTransformationsPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -235,8 +236,8 @@ TEST_F(BraveAdsTextProcessingTest, WrongTransformationsOrderModelTest) { "Message from mom with no real subject", "Another messase from mom with no real subject", "Yadayada"}; - const base::FilePath path = - GetTestPath().AppendASCII(kWrongTransformationOrderPipeline); + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + kWrongTransformationOrderPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -254,8 +255,8 @@ TEST_F(BraveAdsTextProcessingTest, WrongTransformationsOrderModelTest) { TEST_F(BraveAdsTextProcessingTest, MissingRequiredFieldModelTest) { // Arrange - const base::FilePath path = - GetTestPath().AppendASCII(kMissingRequiredFieldClassificationPipeline); + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + kMissingRequiredFieldClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -267,7 +268,8 @@ TEST_F(BraveAdsTextProcessingTest, MissingRequiredFieldModelTest) { TEST_F(BraveAdsTextProcessingTest, InvalidModelTest) { // Arrange - const base::FilePath path = GetTestPath().AppendASCII(kInvalidModel); + const base::FilePath path = + TestDataFileResourcesPath().AppendASCII(kInvalidModel); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -279,7 +281,8 @@ TEST_F(BraveAdsTextProcessingTest, InvalidModelTest) { TEST_F(BraveAdsTextProcessingTest, kNotExistingFile) { // Arrange - const base::FilePath path = GetTestPath().AppendASCII(kNotExistingFile); + const base::FilePath path = + TestDataFileResourcesPath().AppendASCII(kNotExistingFile); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -301,8 +304,8 @@ TEST_F(BraveAdsTextProcessingTest, WrongLanguageModelTest) { // Arrange brave_l10n::test::ScopedDefaultLocale default_locale("es"); - const base::FilePath path = - GetTestPath().AppendASCII(kValidSegmentClassificationPipeline); + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + kValidSegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -317,8 +320,8 @@ TEST_F(BraveAdsTextProcessingTest, TopPredUnitTest) { constexpr size_t kMaxPredictionsSize = 100; constexpr char kTestPage[] = "ethereum bitcoin bat zcash crypto tokens!"; - const base::FilePath path = - GetTestPath().AppendASCII(kValidSegmentClassificationPipeline); + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + kValidSegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -344,21 +347,21 @@ TEST_F(BraveAdsTextProcessingTest, TextCMCCrashTest) { constexpr size_t kMinPredictionsSize = 2; constexpr size_t kMaxPredictionsSize = 100; - const base::FilePath path = - GetTestPath().AppendASCII(kValidSegmentClassificationPipeline); + const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + kValidSegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); pipeline::TextProcessing text_processing_pipeline; ASSERT_TRUE(text_processing_pipeline.SetPipeline(std::move(file))); - const absl::optional text = - ReadFileFromTestPathToString(kTextCMCCrash); - ASSERT_TRUE(text); + const absl::optional contents = + MaybeReadFileResourceToString(kTextCMCCrash); + ASSERT_TRUE(contents); // Act const absl::optional predictions = - text_processing_pipeline.ClassifyPage(*text); + text_processing_pipeline.ClassifyPage(*contents); ASSERT_TRUE(predictions); // Assert diff --git a/components/brave_ads/core/internal/ml/transformation/hash_vectorizer_unittest.cc b/components/brave_ads/core/internal/ml/transformation/hash_vectorizer_unittest.cc index 5573d810f425..da4c096a7f6c 100644 --- a/components/brave_ads/core/internal/ml/transformation/hash_vectorizer_unittest.cc +++ b/components/brave_ads/core/internal/ml/transformation/hash_vectorizer_unittest.cc @@ -23,8 +23,8 @@ void RunHashingExtractorTestCase(const std::string& test_case_name) { constexpr double kTolerance = 1e-7; // Act - const base::Value::Dict root = - base::test::ParseJsonDictFromFile(GetTestPath().AppendASCII(kHashCheck)); + const base::Value::Dict root = base::test::ParseJsonDictFromFile( + TestDataFileResourcesPath().AppendASCII(kHashCheck)); const base::Value::Dict* const test_case_name_dict = root.FindDict(test_case_name); diff --git a/components/brave_ads/core/internal/segments/segment_util_unittest.cc b/components/brave_ads/core/internal/segments/segment_util_unittest.cc index ef536b41a52b..451942996582 100644 --- a/components/brave_ads/core/internal/segments/segment_util_unittest.cc +++ b/components/brave_ads/core/internal/segments/segment_util_unittest.cc @@ -9,7 +9,7 @@ #include "brave/components/brave_ads/core/internal/catalog/catalog_unittest_constants.h" #include "brave/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" -#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" +#include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" #include "brave/components/brave_ads/core/internal/deprecated/client/client_state_manager.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-shared.h" #include "brave/components/brave_ads/core/public/history/category_content_info.h" @@ -23,11 +23,12 @@ class BraveAdsSegmentUtilTest : public UnitTestBase {}; TEST_F(BraveAdsSegmentUtilTest, GetSegmentsFromCatalog) { // Arrange - const absl::optional json = - ReadFileFromTestPathToString(kCatalogWithMultipleCampaignsFilename); - ASSERT_TRUE(json); + const absl::optional contents = + MaybeReadFileResourceToString(kCatalogWithMultipleCampaignsFilename); + ASSERT_TRUE(contents); - const absl::optional catalog = json::reader::ReadCatalog(*json); + const absl::optional catalog = + json::reader::ReadCatalog(*contents); ASSERT_TRUE(catalog); // Act & Assert diff --git a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc index 15f0e4aa4de6..5d42424643f9 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc @@ -60,8 +60,9 @@ TEST_F(BraveAdsAntiTargetingResourceTest, DoNotLoadMissingResource) { .WillByDefault( ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, LoadFileCallback callback) { - const base::FilePath path = - GetFileResourcePath().AppendASCII(kMissingResourceId); + const base::FilePath path = TestDataFileResourcesPath() + .AppendASCII("resources") + .AppendASCII(kMissingResourceId); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc index 878a210e0acf..a982f9245bc9 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc @@ -60,8 +60,9 @@ TEST_F(BraveAdsPurchaseIntentResourceTest, DoNotLoadMissingResource) { .WillByDefault( ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, LoadFileCallback callback) { - const base::FilePath path = - GetFileResourcePath().AppendASCII(kMissingResourceId); + const base::FilePath path = TestDataFileResourcesPath() + .AppendASCII("resources") + .AppendASCII(kMissingResourceId); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc index 2b6b6ed520ed..43887d7f0681 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc @@ -61,8 +61,9 @@ TEST_F(BraveAdsTextClassificationResourceTest, DoNotLoadMissingResource) { .WillByDefault( ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, LoadFileCallback callback) { - const base::FilePath path = - GetFileResourcePath().AppendASCII(kMissingResourceId); + const base::FilePath path = TestDataFileResourcesPath() + .AppendASCII("resources") + .AppendASCII(kMissingResourceId); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc index 1537e35a254c..ee1263f3b4c2 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc @@ -60,8 +60,9 @@ TEST_F(BraveAdsTextEmbeddingResourceTest, DoNotLoadMissingResource) { .WillByDefault( ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, LoadFileCallback callback) { - const base::FilePath path = - GetFileResourcePath().AppendASCII(kMissingResourceId); + const base::FilePath path = TestDataFileResourcesPath() + .AppendASCII("resources") + .AppendASCII(kMissingResourceId); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/test/BUILD.gn b/components/brave_ads/core/test/BUILD.gn index 9693a950756e..f1ccc1eabe3b 100644 --- a/components/brave_ads/core/test/BUILD.gn +++ b/components/brave_ads/core/test/BUILD.gn @@ -248,6 +248,8 @@ source_set("brave_ads_unit_tests") { "//brave/components/brave_ads/core/internal/common/unittest/unittest_current_test_util.h", "//brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc", "//brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h", + "//brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.cc", + "//brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h", "//brave/components/brave_ads/core/internal/common/unittest/unittest_local_state_pref_registry.cc", "//brave/components/brave_ads/core/internal/common/unittest/unittest_local_state_pref_registry.h", "//brave/components/brave_ads/core/internal/common/unittest/unittest_local_state_pref_registry_util.cc", From ca956fbe468858df6e00dadd13363164f4239900 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Fri, 24 Nov 2023 14:11:42 -0500 Subject: [PATCH 3/6] [ads] Refactor LoadFileResource to LoadComponentResource --- .../brave_ads/browser/ads_service_impl.cc | 9 ++-- .../brave_ads/browser/ads_service_impl.h | 6 +-- ...atalog_url_request_json_reader_unittest.cc | 7 ++- .../core/internal/client/ads_client_mock.h | 2 +- .../core/internal/client/ads_client_util.cc | 8 ++-- .../core/internal/client/ads_client_util.h | 8 ++-- .../common/resources/resources_util_impl.h | 8 ++-- .../core/internal/common/unittest/README.md | 20 +++++---- .../internal/common/unittest/unittest_base.cc | 10 ++--- .../common/unittest/unittest_base_util.cc | 12 +++-- .../common/unittest/unittest_base_util.h | 6 ++- .../unittest/unittest_file_path_util.cc | 8 +++- .../common/unittest/unittest_file_path_util.h | 8 +++- .../common/unittest/unittest_file_util.cc | 37 +++++++-------- .../common/unittest/unittest_file_util.h | 6 +-- .../unittest/unittest_url_response_util.cc | 3 +- .../resource/conversion_resource_unittest.cc | 26 +++++------ .../pipeline/linear_pipeline_util_unittest.cc | 2 +- .../pipeline/neural_pipeline_util_unittest.cc | 2 +- .../text_processing_unittest.cc | 45 +++++++++---------- .../hash_vectorizer_unittest.cc | 5 ++- .../segments/segment_util_unittest.cc | 2 +- .../anti_targeting_resource_unittest.cc | 26 +++++------ .../purchase_intent_resource_unittest.cc | 26 +++++------ .../resource/text_classification_resource.cc | 7 +-- .../resource/text_classification_resource.h | 2 +- .../text_classification_resource_unittest.cc | 26 +++++------ .../text_embedding_resource_unittest.cc | 26 +++++------ .../brave_ads/core/public/client/ads_client.h | 12 ++--- .../bat_ads/bat_ads_client_mojo_bridge.cc | 6 +-- .../bat_ads/bat_ads_client_mojo_bridge.h | 8 ++-- .../bat_ads/public/interfaces/bat_ads.mojom | 5 ++- ios/browser/api/ads/ads_client_bridge.h | 6 +-- ios/browser/api/ads/ads_client_ios.h | 6 +-- ios/browser/api/ads/ads_client_ios.mm | 10 +++-- ios/browser/api/ads/brave_ads.mm | 6 +-- 36 files changed, 218 insertions(+), 194 deletions(-) diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index 4066811ebfee..6f805261c310 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -1625,9 +1625,10 @@ void AdsServiceImpl::Load(const std::string& name, LoadCallback callback) { std::move(callback))); } -void AdsServiceImpl::LoadFileResource(const std::string& id, - const int version, - LoadFileResourceCallback callback) { +void AdsServiceImpl::LoadComponentResource( + const std::string& id, + const int version, + LoadComponentResourceCallback callback) { absl::optional file_path = g_brave_browser_process->resource_component()->GetPath(id, version); if (!file_path) { @@ -1647,7 +1648,7 @@ void AdsServiceImpl::LoadFileResource(const std::string& id, }, std::move(*file_path), file_task_runner_), base::BindOnce( - [](LoadFileResourceCallback callback, + [](LoadComponentResourceCallback callback, std::unique_ptr file) { CHECK(file); std::move(callback).Run(std::move(*file)); diff --git a/components/brave_ads/browser/ads_service_impl.h b/components/brave_ads/browser/ads_service_impl.h index ecb0f61ff4ec..46c7300e6ac7 100644 --- a/components/brave_ads/browser/ads_service_impl.h +++ b/components/brave_ads/browser/ads_service_impl.h @@ -330,9 +330,9 @@ class AdsServiceImpl : public AdsService, // TODO(https://github.com/brave/brave-browser/issues/26195) Decouple load // resources business logic. - void LoadFileResource(const std::string& id, - int version, - LoadFileResourceCallback callback) override; + void LoadComponentResource(const std::string& id, + int version, + LoadComponentResourceCallback callback) override; void LoadDataResource(const std::string& name, LoadDataResourceCallback callback) override; diff --git a/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc b/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc index dc64939469dd..00e9d3bc29b5 100644 --- a/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc +++ b/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc @@ -432,8 +432,7 @@ TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, ParseCatalogWithSingleCampaign) { // Arrange const absl::optional contents = - MaybeReadAndReplaceTagsForFileResourceToString( - kCatalogWithSingleCampaignFilename); + MaybeReadFileToStringAndReplaceTags(kCatalogWithSingleCampaignFilename); ASSERT_TRUE(contents); // Act & Assert @@ -449,7 +448,7 @@ TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, ParseCatalogWithMultipleCampaigns) { // Arrange const absl::optional contents = - MaybeReadAndReplaceTagsForFileResourceToString( + MaybeReadFileToStringAndReplaceTags( kCatalogWithMultipleCampaignsFilename); ASSERT_TRUE(contents); @@ -466,7 +465,7 @@ TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, TEST_F(BraveAdsCatalogUrlRequestJsonReaderTest, ParseEmptyCatalog) { // Arrange const absl::optional contents = - MaybeReadAndReplaceTagsForFileResourceToString(kEmptyCatalogFilename); + MaybeReadFileToStringAndReplaceTags(kEmptyCatalogFilename); ASSERT_TRUE(contents); // Act & Assert diff --git a/components/brave_ads/core/internal/client/ads_client_mock.h b/components/brave_ads/core/internal/client/ads_client_mock.h index ba6ca6b64e0d..224371ff4c46 100644 --- a/components/brave_ads/core/internal/client/ads_client_mock.h +++ b/components/brave_ads/core/internal/client/ads_client_mock.h @@ -80,7 +80,7 @@ class AdsClientMock : public AdsClient { SaveCallback callback)); MOCK_METHOD(void, Load, (const std::string& name, LoadCallback callback)); MOCK_METHOD(void, - LoadFileResource, + LoadComponentResource, (const std::string& id, const int version, LoadFileCallback callback)); diff --git a/components/brave_ads/core/internal/client/ads_client_util.cc b/components/brave_ads/core/internal/client/ads_client_util.cc index 4636ae9dd05a..e8707cf69786 100644 --- a/components/brave_ads/core/internal/client/ads_client_util.cc +++ b/components/brave_ads/core/internal/client/ads_client_util.cc @@ -115,10 +115,10 @@ void Load(const std::string& name, LoadCallback callback) { GetInstance()->Load(name, std::move(callback)); } -void LoadFileResource(const std::string& id, - int version, - LoadFileCallback callback) { - GetInstance()->LoadFileResource(id, version, std::move(callback)); +void LoadComponentResource(const std::string& id, + int version, + LoadFileCallback callback) { + GetInstance()->LoadComponentResource(id, version, std::move(callback)); } std::string LoadDataResource(const std::string& name) { diff --git a/components/brave_ads/core/internal/client/ads_client_util.h b/components/brave_ads/core/internal/client/ads_client_util.h index c5381a4dde41..37173fb78748 100644 --- a/components/brave_ads/core/internal/client/ads_client_util.h +++ b/components/brave_ads/core/internal/client/ads_client_util.h @@ -58,9 +58,11 @@ void Save(const std::string& name, const std::string& value, SaveCallback callback); void Load(const std::string& name, LoadCallback callback); -void LoadFileResource(const std::string& id, - int version, - LoadFileCallback callback); + +void LoadComponentResource(const std::string& id, + int version, + LoadFileCallback callback); + std::string LoadDataResource(const std::string& name); void GetScheduledCaptcha(const std::string& payment_id, diff --git a/components/brave_ads/core/internal/common/resources/resources_util_impl.h b/components/brave_ads/core/internal/common/resources/resources_util_impl.h index 1a978e81354d..5fc3d8940129 100644 --- a/components/brave_ads/core/internal/common/resources/resources_util_impl.h +++ b/components/brave_ads/core/internal/common/resources/resources_util_impl.h @@ -53,8 +53,8 @@ base::expected ReadFileAndParseResourceOnBackgroundThread( } template -void LoadFileResourceCallback(LoadAndParseResourceCallback callback, - base::File file) { +void LoadComponentResourceCallback(LoadAndParseResourceCallback callback, + base::File file) { base::ThreadPool::PostTaskAndReplyWithResult( FROM_HERE, {base::MayBlock()}, base::BindOnce(&ReadFileAndParseResourceOnBackgroundThread, @@ -66,9 +66,9 @@ template void LoadAndParseResource(const std::string& id, const int version, LoadAndParseResourceCallback callback) { - LoadFileResource( + LoadComponentResource( id, version, - base::BindOnce(&LoadFileResourceCallback, std::move(callback))); + base::BindOnce(&LoadComponentResourceCallback, std::move(callback))); } } // namespace brave_ads diff --git a/components/brave_ads/core/internal/common/unittest/README.md b/components/brave_ads/core/internal/common/unittest/README.md index d8ebd77045d6..a1d05a54f715 100644 --- a/components/brave_ads/core/internal/common/unittest/README.md +++ b/components/brave_ads/core/internal/common/unittest/README.md @@ -34,26 +34,30 @@ See [unittest_command_line_switch_util.h](unittest_command_line_switch_util.h). See [unittest_time_util.h](unittest_time_util.h). -## Mocking File Resources +## Mocking Files -You can mock file resources loaded with `LoadFileResource` by placing your mocked files in the following directory: +You can mock files loaded with `Load` by placing your mocked files in the following directory: . └── brave/components/brave_ads/core/ └── test/ - └── data/ - └── resources + └── data -## Mocking Files +You can copy files to the simulated user profile (temp path) using `CopyFileFromTestPathToTempPath` or `CopyDirectoryFromTestPathToTempPath` in `SetUpMocks`. -You can mock files loaded with `LoadFile` by placing your mocked files in the following directory: +See [unittest_file_path_util.h](unittest_file_path_util.h) and [unittest_file_util.h](unittest_file_util.h). + +## Mocking Component Resources + +You can mock component resources loaded with `LoadComponentResource` by placing your mocked files in the following directory: . └── brave/components/brave_ads/core/ └── test/ - └── data + └── data/ + └── resources -You can copy files to the simulated user profile (temp path) using `CopyFileFromTestPathToTempPath` or `CopyDirectoryFromTestPathToTempPath` in `SetUpMocks`. +See [unittest_file_path_util.h](unittest_file_path_util.h). ## Mocking Prefs diff --git a/components/brave_ads/core/internal/common/unittest/unittest_base.cc b/components/brave_ads/core/internal/common/unittest/unittest_base.cc index 15d03a654231..9bb8c48270cf 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_base.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_base.cc @@ -88,8 +88,7 @@ bool UnitTestBase::CopyFileFromTestPathToTempPath( CHECK(setup_called_) << "CopyFileFromTestPathToTempPath should be called after SetUp"; - const base::FilePath from_test_path = - TestDataFileResourcesPath().AppendASCII(from_path); + const base::FilePath from_test_path = TestDataPath().AppendASCII(from_path); const base::FilePath to_temp_path = temp_dir_.GetPath().AppendASCII(to_path); return base::CopyFile(from_test_path, to_temp_path); @@ -106,8 +105,7 @@ bool UnitTestBase::CopyDirectoryFromTestPathToTempPath( CHECK(setup_called_) << "CopyDirectoryFromTestPathToTempPath should be called after SetUp"; - const base::FilePath from_test_path = - TestDataFileResourcesPath().AppendASCII(from_path); + const base::FilePath from_test_path = TestDataPath().AppendASCII(from_path); const base::FilePath to_temp_path = temp_dir_.GetPath().AppendASCII(to_path); return base::CopyDirectory(from_test_path, to_temp_path, @@ -195,7 +193,9 @@ void UnitTestBase::MockAdsClient() { MockSave(ads_client_mock_); MockLoad(ads_client_mock_, temp_dir_); - MockLoadFileResource(ads_client_mock_, temp_dir_); + + MockLoadComponentResource(ads_client_mock_, temp_dir_); + MockLoadDataResource(ads_client_mock_); database_ = std::make_unique( diff --git a/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc index dc46c59ad1f8..1ec79c921d32 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc @@ -153,7 +153,7 @@ void MockLoad(AdsClientMock& mock, const base::ScopedTempDir& temp_dir) { base::FilePath path = temp_dir.GetPath().AppendASCII(name); if (!base::PathExists(path)) { // If path does not exist load the file from the test path. - path = TestDataFileResourcesPath().AppendASCII(name); + path = TestDataPath().AppendASCII(name); } std::string value; @@ -165,9 +165,9 @@ void MockLoad(AdsClientMock& mock, const base::ScopedTempDir& temp_dir) { })); } -void MockLoadFileResource(AdsClientMock& mock, - const base::ScopedTempDir& temp_dir) { - ON_CALL(mock, LoadFileResource) +void MockLoadComponentResource(AdsClientMock& mock, + const base::ScopedTempDir& temp_dir) { + ON_CALL(mock, LoadComponentResource) .WillByDefault(::testing::Invoke( [&temp_dir](const std::string& id, const int /*version*/, LoadFileCallback callback) { @@ -175,9 +175,7 @@ void MockLoadFileResource(AdsClientMock& mock, if (!base::PathExists(path)) { // If path does not exist load the file from the test path. - path = TestDataFileResourcesPath() - .AppendASCII("resources") - .AppendASCII(id); + path = TestDataComponentResourcesPath().AppendASCII(id); } base::File file(path, base::File::Flags::FLAG_OPEN | diff --git a/components/brave_ads/core/internal/common/unittest/unittest_base_util.h b/components/brave_ads/core/internal/common/unittest/unittest_base_util.h index 06a95b6825f6..b6f4814283d2 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_base_util.h +++ b/components/brave_ads/core/internal/common/unittest/unittest_base_util.h @@ -23,8 +23,10 @@ void MockResetAdEventCacheForInstanceId(const AdsClientMock& mock); void MockSave(AdsClientMock& mock); void MockLoad(AdsClientMock& mock, const base::ScopedTempDir& temp_dir); -void MockLoadFileResource(AdsClientMock& mock, - const base::ScopedTempDir& temp_dir); + +void MockLoadComponentResource(AdsClientMock& mock, + const base::ScopedTempDir& temp_dir); + void MockLoadDataResource(AdsClientMock& mock); void MockRunDBTransaction(AdsClientMock& mock, Database& database); diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc index 6c54d4ddc0a6..11472cfbcc39 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc @@ -5,7 +5,7 @@ #include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" -#include "base/base_paths.h"xx +#include "base/files/file_path.h" #include "base/path_service.h" namespace brave_ads { @@ -21,11 +21,15 @@ base::FilePath TestDataRootPath() { } // namespace -base::FilePath TestDataFileResourcesPath() { +base::FilePath TestDataPath() { return TestDataRootPath().AppendASCII("core").AppendASCII("test").AppendASCII( "data"); } +base::FilePath TestDataComponentResourcesPath() { + return TestDataPath().AppendASCII("resources"); +} + base::FilePath DataResourcesPath() { return TestDataRootPath().AppendASCII("resources"); } diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h index e79a7d7656c4..87c5006ce34b 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h @@ -6,11 +6,15 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_UNITTEST_UNITTEST_FILE_PATH_UTIL_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_UNITTEST_UNITTEST_FILE_PATH_UTIL_H_ -#include "base/files/file_path.h" +namespace base { +class FilePath; +} // namespace base namespace brave_ads { -base::FilePath TestDataFileResourcesPath(); +base::FilePath TestDataPath(); + +base::FilePath TestDataComponentResourcesPath(); base::FilePath DataResourcesPath(); diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_file_util.cc index 33f88b8fcdfb..8b0977ed304a 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_file_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_util.cc @@ -5,47 +5,48 @@ #include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" +#include "base/files/file_path.h" #include "base/files/file_util.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_tag_parser_util.h" namespace brave_ads { -namespace { +absl::optional MaybeReadFileToString(const std::string& name) { + const base::FilePath path = TestDataPath().AppendASCII(name); -absl::optional MaybeReadFileToString(const base::FilePath& path) { - std::string content; - if (!base::ReadFileToString(path, &content)) { + std::string contents; + if (!base::ReadFileToString(path, &contents)) { return absl::nullopt; } - return content; + return contents; } -} // namespace - -absl::optional MaybeReadFileResourceToString( +absl::optional MaybeReadFileToStringAndReplaceTags( const std::string& name) { - const base::FilePath path = TestDataFileResourcesPath().AppendASCII(name); - return MaybeReadFileToString(path); -} + const base::FilePath path = TestDataPath().AppendASCII(name); -absl::optional MaybeReadAndReplaceTagsForFileResourceToString( - const std::string& name) { - absl::optional contents = MaybeReadFileResourceToString(name); - if (!contents) { + std::string contents; + if (!base::ReadFileToString(path, &contents)) { return absl::nullopt; } - ParseAndReplaceTags(*contents); + ParseAndReplaceTags(contents); - return *contents; + return contents; } absl::optional MaybeReadDataResourceToString( const std::string& name) { const base::FilePath path = DataResourcesPath().AppendASCII(name); - return MaybeReadFileToString(path); + + std::string contents; + if (!base::ReadFileToString(path, &contents)) { + return absl::nullopt; + } + + return contents; } } // namespace brave_ads diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_util.h b/components/brave_ads/core/internal/common/unittest/unittest_file_util.h index b7684ebd74f6..bb0fd715fb60 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_file_util.h +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_util.h @@ -12,9 +12,9 @@ namespace brave_ads { -absl::optional MaybeReadFileResourceToString( - const std::string& name); -absl::optional MaybeReadAndReplaceTagsForFileResourceToString( +absl::optional MaybeReadFileToString(const std::string& name); + +absl::optional MaybeReadFileToStringAndReplaceTags( const std::string& name); absl::optional MaybeReadDataResourceToString( diff --git a/components/brave_ads/core/internal/common/unittest/unittest_url_response_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_url_response_util.cc index 7fc8e370b475..79765f3978e8 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_url_response_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_url_response_util.cc @@ -9,6 +9,7 @@ #include "base/check_op.h" #include "base/containers/flat_map.h" +#include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/no_destructor.h" #include "base/notreached.h" @@ -98,7 +99,7 @@ absl::optional GetNextUrlResponseForRequest( std::string response_body = url_response->second; if (ShouldReadResponseBodyFromFile(response_body)) { - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( + const base::FilePath path = TestDataPath().AppendASCII( ParseFilenameFromResponseBody(response_body)); if (!base::ReadFileToString(path, &response_body)) { NOTREACHED_NORETURN() << path << " not found"; diff --git a/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc b/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc index 5fff8f05ca64..9b396344a2b6 100644 --- a/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc +++ b/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc @@ -9,6 +9,7 @@ #include #include "base/files/file.h" +#include "base/files/file_path.h" #include "brave/components/brave_ads/core/internal/common/resources/country_components_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/resources/resources_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" @@ -54,19 +55,18 @@ TEST_F(BraveAdsConversionResourceTest, DoNotLoadInvalidResource) { TEST_F(BraveAdsConversionResourceTest, DoNotLoadMissingResource) { // Arrange - ON_CALL(ads_client_mock_, - LoadFileResource(kConversionResourceId, ::testing::_, ::testing::_)) - .WillByDefault( - ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, - LoadFileCallback callback) { - const base::FilePath path = TestDataFileResourcesPath() - .AppendASCII("resources") - .AppendASCII(kMissingResourceId); - - base::File file(path, base::File::Flags::FLAG_OPEN | - base::File::Flags::FLAG_READ); - std::move(callback).Run(std::move(file)); - })); + ON_CALL(ads_client_mock_, LoadComponentResource(kConversionResourceId, + ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke([](const std::string& /*id*/, + const int /*version*/, + LoadFileCallback callback) { + const base::FilePath path = + TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + + base::File file( + path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); + std::move(callback).Run(std::move(file)); + })); // Act & Assert EXPECT_FALSE(LoadResource(kCountryComponentId)); diff --git a/components/brave_ads/core/internal/ml/pipeline/linear_pipeline_util_unittest.cc b/components/brave_ads/core/internal/ml/pipeline/linear_pipeline_util_unittest.cc index 946f0cd5343d..d6f7d3578331 100644 --- a/components/brave_ads/core/internal/ml/pipeline/linear_pipeline_util_unittest.cc +++ b/components/brave_ads/core/internal/ml/pipeline/linear_pipeline_util_unittest.cc @@ -26,7 +26,7 @@ class BraveAdsLinearPipelineUtilTest : public UnitTestBase {}; TEST_F(BraveAdsLinearPipelineUtilTest, LoadLinearPipelineTest) { // Arrange const absl::optional contents = - MaybeReadFileResourceToString(kValidSpamClassificationPipeline); + MaybeReadFileToString(kValidSpamClassificationPipeline); ASSERT_TRUE(contents); // Act & Assert diff --git a/components/brave_ads/core/internal/ml/pipeline/neural_pipeline_util_unittest.cc b/components/brave_ads/core/internal/ml/pipeline/neural_pipeline_util_unittest.cc index 3209cc95346c..54a6363c1717 100644 --- a/components/brave_ads/core/internal/ml/pipeline/neural_pipeline_util_unittest.cc +++ b/components/brave_ads/core/internal/ml/pipeline/neural_pipeline_util_unittest.cc @@ -26,7 +26,7 @@ class BraveAdsNeuralPipelineUtilTest : public UnitTestBase {}; TEST_F(BraveAdsNeuralPipelineUtilTest, LoadNeuralPipelineTest) { // Arrange const absl::optional contents = - MaybeReadFileResourceToString(kOnlyRequiredFieldsNeuralModelPipeline); + MaybeReadFileToString(kOnlyRequiredFieldsNeuralModelPipeline); ASSERT_TRUE(contents); // Act & Assert diff --git a/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing_unittest.cc b/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing_unittest.cc index 2ac213c4373c..2ff6dd84f111 100644 --- a/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing_unittest.cc +++ b/components/brave_ads/core/internal/ml/pipeline/text_processing/text_processing_unittest.cc @@ -11,6 +11,7 @@ #include #include "base/files/file.h" +#include "base/files/file_path.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_file_util.h" @@ -133,7 +134,7 @@ TEST_F(BraveAdsTextProcessingTest, TestLoadFromValue) { "junk"}; const base::FilePath path = - TestDataFileResourcesPath().AppendASCII(kValidSpamClassificationPipeline); + TestDataPath().AppendASCII(kValidSpamClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -163,8 +164,8 @@ TEST_F(BraveAdsTextProcessingTest, TestLoadFromValue) { TEST_F(BraveAdsTextProcessingTest, InitValidLinearModelTest) { // Arrange - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( - kValidSegmentClassificationPipeline); + const base::FilePath path = + TestDataPath().AppendASCII(kValidSegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -176,8 +177,8 @@ TEST_F(BraveAdsTextProcessingTest, InitValidLinearModelTest) { TEST_F(BraveAdsTextProcessingTest, InitValidNeuralModelTest) { // Arrange - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( - kOnlyRequiredFieldsNeuralModelPipeline); + const base::FilePath path = + TestDataPath().AppendASCII(kOnlyRequiredFieldsNeuralModelPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -191,8 +192,8 @@ TEST_F(BraveAdsTextProcessingTest, EmptySegmentModelTest) { // Arrange const std::string input_text = "This is a spam email."; - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( - kEmptySegmentClassificationPipeline); + const base::FilePath path = + TestDataPath().AppendASCII(kEmptySegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -213,7 +214,7 @@ TEST_F(BraveAdsTextProcessingTest, EmptyTransformationsModelTest) { const std::string input_text = "This is a spam email."; const base::FilePath path = - TestDataFileResourcesPath().AppendASCII(kEmptyTransformationsPipeline); + TestDataPath().AppendASCII(kEmptyTransformationsPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -236,8 +237,8 @@ TEST_F(BraveAdsTextProcessingTest, WrongTransformationsOrderModelTest) { "Message from mom with no real subject", "Another messase from mom with no real subject", "Yadayada"}; - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( - kWrongTransformationOrderPipeline); + const base::FilePath path = + TestDataPath().AppendASCII(kWrongTransformationOrderPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -255,8 +256,8 @@ TEST_F(BraveAdsTextProcessingTest, WrongTransformationsOrderModelTest) { TEST_F(BraveAdsTextProcessingTest, MissingRequiredFieldModelTest) { // Arrange - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( - kMissingRequiredFieldClassificationPipeline); + const base::FilePath path = + TestDataPath().AppendASCII(kMissingRequiredFieldClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -268,8 +269,7 @@ TEST_F(BraveAdsTextProcessingTest, MissingRequiredFieldModelTest) { TEST_F(BraveAdsTextProcessingTest, InvalidModelTest) { // Arrange - const base::FilePath path = - TestDataFileResourcesPath().AppendASCII(kInvalidModel); + const base::FilePath path = TestDataPath().AppendASCII(kInvalidModel); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -281,8 +281,7 @@ TEST_F(BraveAdsTextProcessingTest, InvalidModelTest) { TEST_F(BraveAdsTextProcessingTest, kNotExistingFile) { // Arrange - const base::FilePath path = - TestDataFileResourcesPath().AppendASCII(kNotExistingFile); + const base::FilePath path = TestDataPath().AppendASCII(kNotExistingFile); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -304,8 +303,8 @@ TEST_F(BraveAdsTextProcessingTest, WrongLanguageModelTest) { // Arrange brave_l10n::test::ScopedDefaultLocale default_locale("es"); - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( - kValidSegmentClassificationPipeline); + const base::FilePath path = + TestDataPath().AppendASCII(kValidSegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -320,8 +319,8 @@ TEST_F(BraveAdsTextProcessingTest, TopPredUnitTest) { constexpr size_t kMaxPredictionsSize = 100; constexpr char kTestPage[] = "ethereum bitcoin bat zcash crypto tokens!"; - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( - kValidSegmentClassificationPipeline); + const base::FilePath path = + TestDataPath().AppendASCII(kValidSegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -347,8 +346,8 @@ TEST_F(BraveAdsTextProcessingTest, TextCMCCrashTest) { constexpr size_t kMinPredictionsSize = 2; constexpr size_t kMaxPredictionsSize = 100; - const base::FilePath path = TestDataFileResourcesPath().AppendASCII( - kValidSegmentClassificationPipeline); + const base::FilePath path = + TestDataPath().AppendASCII(kValidSegmentClassificationPipeline); base::File file(path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); @@ -356,7 +355,7 @@ TEST_F(BraveAdsTextProcessingTest, TextCMCCrashTest) { ASSERT_TRUE(text_processing_pipeline.SetPipeline(std::move(file))); const absl::optional contents = - MaybeReadFileResourceToString(kTextCMCCrash); + MaybeReadFileToString(kTextCMCCrash); ASSERT_TRUE(contents); // Act diff --git a/components/brave_ads/core/internal/ml/transformation/hash_vectorizer_unittest.cc b/components/brave_ads/core/internal/ml/transformation/hash_vectorizer_unittest.cc index da4c096a7f6c..5f0d04e52eac 100644 --- a/components/brave_ads/core/internal/ml/transformation/hash_vectorizer_unittest.cc +++ b/components/brave_ads/core/internal/ml/transformation/hash_vectorizer_unittest.cc @@ -5,6 +5,7 @@ #include "brave/components/brave_ads/core/internal/ml/transformation/hash_vectorizer.h" +#include "base/files/file_path.h" #include "base/test/values_test_util.h" #include "base/values.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" @@ -23,8 +24,8 @@ void RunHashingExtractorTestCase(const std::string& test_case_name) { constexpr double kTolerance = 1e-7; // Act - const base::Value::Dict root = base::test::ParseJsonDictFromFile( - TestDataFileResourcesPath().AppendASCII(kHashCheck)); + const base::Value::Dict root = + base::test::ParseJsonDictFromFile(TestDataPath().AppendASCII(kHashCheck)); const base::Value::Dict* const test_case_name_dict = root.FindDict(test_case_name); diff --git a/components/brave_ads/core/internal/segments/segment_util_unittest.cc b/components/brave_ads/core/internal/segments/segment_util_unittest.cc index 451942996582..601a87a8b14f 100644 --- a/components/brave_ads/core/internal/segments/segment_util_unittest.cc +++ b/components/brave_ads/core/internal/segments/segment_util_unittest.cc @@ -24,7 +24,7 @@ class BraveAdsSegmentUtilTest : public UnitTestBase {}; TEST_F(BraveAdsSegmentUtilTest, GetSegmentsFromCatalog) { // Arrange const absl::optional contents = - MaybeReadFileResourceToString(kCatalogWithMultipleCampaignsFilename); + MaybeReadFileToString(kCatalogWithMultipleCampaignsFilename); ASSERT_TRUE(contents); const absl::optional catalog = diff --git a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc index 5d42424643f9..6c11c8941255 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc @@ -10,6 +10,7 @@ #include #include "base/files/file.h" +#include "base/files/file_path.h" #include "brave/components/brave_ads/core/internal/common/resources/country_components_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/resources/resources_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" @@ -55,19 +56,18 @@ TEST_F(BraveAdsAntiTargetingResourceTest, DoNotLoadInvalidResource) { TEST_F(BraveAdsAntiTargetingResourceTest, DoNotLoadMissingResource) { // Arrange - ON_CALL(ads_client_mock_, LoadFileResource(kAntiTargetingResourceId, - ::testing::_, ::testing::_)) - .WillByDefault( - ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, - LoadFileCallback callback) { - const base::FilePath path = TestDataFileResourcesPath() - .AppendASCII("resources") - .AppendASCII(kMissingResourceId); - - base::File file(path, base::File::Flags::FLAG_OPEN | - base::File::Flags::FLAG_READ); - std::move(callback).Run(std::move(file)); - })); + ON_CALL(ads_client_mock_, LoadComponentResource(kAntiTargetingResourceId, + ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke([](const std::string& /*id*/, + const int /*version*/, + LoadFileCallback callback) { + const base::FilePath path = + TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + + base::File file( + path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); + std::move(callback).Run(std::move(file)); + })); // Act & Assert EXPECT_FALSE(LoadResource(kCountryComponentId)); diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc index a982f9245bc9..4b4ee0e827ae 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc @@ -10,6 +10,7 @@ #include #include "base/files/file.h" +#include "base/files/file_path.h" #include "brave/components/brave_ads/core/internal/common/resources/country_components_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/resources/resources_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" @@ -55,19 +56,18 @@ TEST_F(BraveAdsPurchaseIntentResourceTest, DoNotLoadInvalidResource) { TEST_F(BraveAdsPurchaseIntentResourceTest, DoNotLoadMissingResource) { // Arrange - ON_CALL(ads_client_mock_, LoadFileResource(kPurchaseIntentResourceId, - ::testing::_, ::testing::_)) - .WillByDefault( - ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, - LoadFileCallback callback) { - const base::FilePath path = TestDataFileResourcesPath() - .AppendASCII("resources") - .AppendASCII(kMissingResourceId); - - base::File file(path, base::File::Flags::FLAG_OPEN | - base::File::Flags::FLAG_READ); - std::move(callback).Run(std::move(file)); - })); + ON_CALL(ads_client_mock_, LoadComponentResource(kPurchaseIntentResourceId, + ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke([](const std::string& /*id*/, + const int /*version*/, + LoadFileCallback callback) { + const base::FilePath path = + TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + + base::File file( + path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); + std::move(callback).Run(std::move(file)); + })); // Act & Assert EXPECT_FALSE(LoadResource(kCountryComponentId)); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc index 94345a05fcc2..26ad863c58ba 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.cc @@ -74,13 +74,14 @@ void TextClassificationResource::MaybeLoadOrReset() { void TextClassificationResource::Load() { did_load_ = true; - LoadFileResource( + LoadComponentResource( GetResourceId(), GetResourceVersion(), - base::BindOnce(&TextClassificationResource::LoadFileResourceCallback, + base::BindOnce(&TextClassificationResource::LoadComponentResourceCallback, weak_factory_.GetWeakPtr())); } -void TextClassificationResource::LoadFileResourceCallback(base::File file) { +void TextClassificationResource::LoadComponentResourceCallback( + base::File file) { if (!file.IsValid()) { BLOG(0, "Failed to load invalid resource file"); return; diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.h b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.h index 1ee673abe64e..2ea67d253134 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.h +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource.h @@ -46,7 +46,7 @@ class TextClassificationResource final : public AdsClientNotifierObserver { bool DidLoad() const { return did_load_; } void Load(); - void LoadFileResourceCallback(base::File file); + void LoadComponentResourceCallback(base::File file); void LoadPipelineCallback(base::expected result); void MaybeReset(); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc index 43887d7f0681..66cd2d530e7e 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc @@ -10,6 +10,7 @@ #include #include "base/files/file.h" +#include "base/files/file_path.h" #include "brave/components/brave_ads/core/internal/common/resources/language_components_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/resources/resources_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" @@ -56,19 +57,18 @@ TEST_F(BraveAdsTextClassificationResourceTest, DoNotLoadInvalidResource) { TEST_F(BraveAdsTextClassificationResourceTest, DoNotLoadMissingResource) { // Arrange ON_CALL(ads_client_mock_, - LoadFileResource(kFlatBuffersTextClassificationResourceId, - ::testing::_, ::testing::_)) - .WillByDefault( - ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, - LoadFileCallback callback) { - const base::FilePath path = TestDataFileResourcesPath() - .AppendASCII("resources") - .AppendASCII(kMissingResourceId); - - base::File file(path, base::File::Flags::FLAG_OPEN | - base::File::Flags::FLAG_READ); - std::move(callback).Run(std::move(file)); - })); + LoadComponentResource(kFlatBuffersTextClassificationResourceId, + ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke([](const std::string& /*id*/, + const int /*version*/, + LoadFileCallback callback) { + const base::FilePath path = + TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + + base::File file( + path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); + std::move(callback).Run(std::move(file)); + })); // Act & Assert EXPECT_FALSE(LoadResource(kLanguageComponentId)); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc index ee1263f3b4c2..ddbfe055711a 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc @@ -10,6 +10,7 @@ #include #include "base/files/file.h" +#include "base/files/file_path.h" #include "brave/components/brave_ads/core/internal/common/resources/language_components_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/resources/resources_unittest_constants.h" #include "brave/components/brave_ads/core/internal/common/unittest/unittest_base.h" @@ -55,19 +56,18 @@ TEST_F(BraveAdsTextEmbeddingResourceTest, DoNotLoadInvalidResource) { TEST_F(BraveAdsTextEmbeddingResourceTest, DoNotLoadMissingResource) { // Arrange - ON_CALL(ads_client_mock_, LoadFileResource(kTextEmbeddingResourceId, - ::testing::_, ::testing::_)) - .WillByDefault( - ::testing::Invoke([](const std::string& /*id*/, const int /*version*/, - LoadFileCallback callback) { - const base::FilePath path = TestDataFileResourcesPath() - .AppendASCII("resources") - .AppendASCII(kMissingResourceId); - - base::File file(path, base::File::Flags::FLAG_OPEN | - base::File::Flags::FLAG_READ); - std::move(callback).Run(std::move(file)); - })); + ON_CALL(ads_client_mock_, LoadComponentResource(kTextEmbeddingResourceId, + ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke([](const std::string& /*id*/, + const int /*version*/, + LoadFileCallback callback) { + const base::FilePath path = + TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + + base::File file( + path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); + std::move(callback).Run(std::move(file)); + })); // Act & Assert EXPECT_FALSE(LoadResource(kLanguageComponentId)); diff --git a/components/brave_ads/core/public/client/ads_client.h b/components/brave_ads/core/public/client/ads_client.h index f275ed0b2897..d8c3629a3ee7 100644 --- a/components/brave_ads/core/public/client/ads_client.h +++ b/components/brave_ads/core/public/client/ads_client.h @@ -98,12 +98,12 @@ class ADS_EXPORT AdsClient { // takes one argument - optional containing the loaded `value`. virtual void Load(const std::string& name, LoadCallback callback) = 0; - // Load a file resource for the specified `id` and `version` from persistent - // storage. The callback takes one argument - `base::File` will be valid if - // successful otherwise invalid. - virtual void LoadFileResource(const std::string& id, - int version, - LoadFileCallback callback) = 0; + // Load a component resource for the specified `id` and `version` from + // persistent storage. The callback takes one argument - `base::File` will be + // valid if successful otherwise invalid. + virtual void LoadComponentResource(const std::string& id, + int version, + LoadFileCallback callback) = 0; // Load a data resource for the specified `name`. Returns the resource if // successful otherwise an empty string. diff --git a/components/services/bat_ads/bat_ads_client_mojo_bridge.cc b/components/services/bat_ads/bat_ads_client_mojo_bridge.cc index ca6276cadd7c..d21fb98ae81c 100644 --- a/components/services/bat_ads/bat_ads_client_mojo_bridge.cc +++ b/components/services/bat_ads/bat_ads_client_mojo_bridge.cc @@ -185,7 +185,7 @@ void BatAdsClientMojoBridge::Save(const std::string& name, bat_ads_client_associated_receiver_->Save(name, value, std::move(callback)); } -void BatAdsClientMojoBridge::LoadFileResource( +void BatAdsClientMojoBridge::LoadComponentResource( const std::string& id, const int version, brave_ads::LoadFileCallback callback) { @@ -194,8 +194,8 @@ void BatAdsClientMojoBridge::LoadFileResource( return; } - bat_ads_client_associated_receiver_->LoadFileResource(id, version, - std::move(callback)); + bat_ads_client_associated_receiver_->LoadComponentResource( + id, version, std::move(callback)); } void BatAdsClientMojoBridge::GetBrowsingHistory( diff --git a/components/services/bat_ads/bat_ads_client_mojo_bridge.h b/components/services/bat_ads/bat_ads_client_mojo_bridge.h index 44234b167c20..106df4d583f1 100644 --- a/components/services/bat_ads/bat_ads_client_mojo_bridge.h +++ b/components/services/bat_ads/bat_ads_client_mojo_bridge.h @@ -82,9 +82,11 @@ class BatAdsClientMojoBridge : public brave_ads::AdsClient { const std::string& value, brave_ads::SaveCallback callback) override; void Load(const std::string& name, brave_ads::LoadCallback callback) override; - void LoadFileResource(const std::string& id, - int version, - brave_ads::LoadFileCallback callback) override; + + void LoadComponentResource(const std::string& id, + int version, + brave_ads::LoadFileCallback callback) override; + std::string LoadDataResource(const std::string& name) override; void GetScheduledCaptcha( diff --git a/components/services/bat_ads/public/interfaces/bat_ads.mojom b/components/services/bat_ads/public/interfaces/bat_ads.mojom index 7293b0ce52e6..7b6b2e2d7469 100644 --- a/components/services/bat_ads/public/interfaces/bat_ads.mojom +++ b/components/services/bat_ads/public/interfaces/bat_ads.mojom @@ -96,7 +96,10 @@ interface BatAdsClient { Save(string name, string value) => (bool success); Load(string name) => (string? value); - LoadFileResource(string id, int32 version) => (mojo_base.mojom.File? file); + + LoadComponentResource(string id, int32 version) => + (mojo_base.mojom.File? file); + [Sync] LoadDataResource(string name) => (mojo_base.mojom.BigString value); diff --git a/ios/browser/api/ads/ads_client_bridge.h b/ios/browser/api/ads/ads_client_bridge.h index a502ef802279..bb23ca6fa524 100644 --- a/ios/browser/api/ads/ads_client_bridge.h +++ b/ios/browser/api/ads/ads_client_bridge.h @@ -23,9 +23,9 @@ - (void)notifyPendingObservers; - (bool)isNetworkConnectionAvailable; - (bool)canShowNotificationAds; -- (void)loadFileResource:(const std::string&)id - version:(const int)version - callback:(brave_ads::LoadFileCallback)callback; +- (void)loadComponentResource:(const std::string&)id + version:(const int)version + callback:(brave_ads::LoadFileCallback)callback; - (void)getScheduledCaptcha:(const std::string&)payment_id callback:(brave_ads::GetScheduledCaptchaCallback)callback; - (void)showScheduledCaptchaNotification:(const std::string&)payment_id diff --git a/ios/browser/api/ads/ads_client_ios.h b/ios/browser/api/ads/ads_client_ios.h index 663a98f028cb..2fbaca49d0c6 100644 --- a/ios/browser/api/ads/ads_client_ios.h +++ b/ios/browser/api/ads/ads_client_ios.h @@ -45,9 +45,9 @@ class AdsClientIOS : public brave_ads::AdsClient { const std::string& value, brave_ads::SaveCallback callback) override; void Load(const std::string& name, brave_ads::LoadCallback callback) override; - void LoadFileResource(const std::string& id, - const int version, - brave_ads::LoadFileCallback callback) override; + void LoadComponentResource(const std::string& id, + const int version, + brave_ads::LoadFileCallback callback) override; void GetBrowsingHistory( const int max_count, const int days_ago, diff --git a/ios/browser/api/ads/ads_client_ios.mm b/ios/browser/api/ads/ads_client_ios.mm index 1fb6f19d2c93..0036bf911770 100644 --- a/ios/browser/api/ads/ads_client_ios.mm +++ b/ios/browser/api/ads/ads_client_ios.mm @@ -92,10 +92,12 @@ [bridge_ save:name value:value callback:std::move(callback)]; } -void AdsClientIOS::LoadFileResource(const std::string& id, - const int version, - brave_ads::LoadFileCallback callback) { - [bridge_ loadFileResource:id version:version callback:std::move(callback)]; +void AdsClientIOS::LoadComponentResource(const std::string& id, + const int version, + brave_ads::LoadFileCallback callback) { + [bridge_ loadComponentResource:id + version:version + callback:std::move(callback)]; } void AdsClientIOS::GetBrowsingHistory( diff --git a/ios/browser/api/ads/brave_ads.mm b/ios/browser/api/ads/brave_ads.mm index f6fcd990f125..442d4ad6f47c 100644 --- a/ios/browser/api/ads/brave_ads.mm +++ b/ios/browser/api/ads/brave_ads.mm @@ -1490,9 +1490,9 @@ - (void)load:(const std::string&)name std::move(callback).Run(contents); } -- (void)loadFileResource:(const std::string&)id - version:(const int)version - callback:(brave_ads::LoadFileCallback)callback { +- (void)loadComponentResource:(const std::string&)id + version:(const int)version + callback:(brave_ads::LoadFileCallback)callback { NSString* bridgedId = base::SysUTF8ToNSString(id); NSString* nsFilePath = [self.commonOps dataPathForFilename:bridgedId]; From b3872bcef80131db41362b0ad692406d2ce340ee Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Fri, 24 Nov 2023 13:16:27 -0500 Subject: [PATCH 4/6] [ads] Update GLOSSARY.md --- components/brave_ads/GLOSSARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/components/brave_ads/GLOSSARY.md b/components/brave_ads/GLOSSARY.md index 9c335d4aa66a..f867b8b5c01d 100644 --- a/components/brave_ads/GLOSSARY.md +++ b/components/brave_ads/GLOSSARY.md @@ -4,6 +4,7 @@ A place to define all specific terms and vocabulary for the Brave Ads component, | term | description | |---|---| +| Ad unit | An ad unit is displayed to the user. Also known as an ad placement. | | Advertiser | An advertiser is someone or a company that promotes products, services, or ideas through various mediums to reach and persuade potential customers or target audiences. | | Advertisement | An advertisement is a promotional message or content created to promote a product, service, or idea to a target audience, also known as an Ad. | | Analytics | Examine data to uncover meaningful insights, trends, and patterns that can inform decision-making and improve understanding of a given subject or domain. See P2A and P3A. | From e485c3587f58c2093b0da7228f10932bd9736e9b Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Fri, 24 Nov 2023 14:46:05 -0500 Subject: [PATCH 5/6] [ads] Cleanup ISO 8601 usage --- .../user_data/dynamic/system_timestamp_user_data.cc | 2 +- .../user_data/fixed/created_at_timestamp_user_data.cc | 2 +- .../catalog/catalog_url_request_json_reader_unittest.cc | 8 ++++---- .../brave_ads/core/internal/common/time/time_util.cc | 2 +- .../brave_ads/core/internal/common/time/time_util.h | 2 +- .../core/internal/common/time/time_util_unittest.cc | 4 ++-- .../core/internal/common/unittest/unittest_base_util.cc | 2 +- .../internal/common/unittest/unittest_file_path_util.cc | 2 +- .../internal/common/unittest/unittest_file_path_util.h | 2 +- .../internal/common/unittest/unittest_tag_parser_util.cc | 6 +++--- .../core/internal/common/unittest/unittest_time_util.cc | 6 +++--- .../core/internal/common/unittest/unittest_time_util.h | 9 ++++++--- .../conversions/resource/conversion_resource_unittest.cc | 2 +- .../resource/anti_targeting_resource_unittest.cc | 2 +- .../resource/purchase_intent_resource_unittest.cc | 2 +- .../resource/text_classification_resource_unittest.cc | 2 +- .../resource/text_embedding_resource_unittest.cc | 2 +- 17 files changed, 30 insertions(+), 27 deletions(-) diff --git a/components/brave_ads/core/internal/account/user_data/dynamic/system_timestamp_user_data.cc b/components/brave_ads/core/internal/account/user_data/dynamic/system_timestamp_user_data.cc index 55b5ff2e3275..9738bc1acc8e 100644 --- a/components/brave_ads/core/internal/account/user_data/dynamic/system_timestamp_user_data.cc +++ b/components/brave_ads/core/internal/account/user_data/dynamic/system_timestamp_user_data.cc @@ -23,7 +23,7 @@ base::Value::Dict BuildSystemTimestampUserData() { } user_data.Set(kSystemTimestampKey, - TimeToPrivacyPreservingISO8601(base::Time::Now())); + TimeToPrivacyPreservingIso8601(base::Time::Now())); return user_data; } diff --git a/components/brave_ads/core/internal/account/user_data/fixed/created_at_timestamp_user_data.cc b/components/brave_ads/core/internal/account/user_data/fixed/created_at_timestamp_user_data.cc index 7203ccc14d1b..820cccc57f33 100644 --- a/components/brave_ads/core/internal/account/user_data/fixed/created_at_timestamp_user_data.cc +++ b/components/brave_ads/core/internal/account/user_data/fixed/created_at_timestamp_user_data.cc @@ -24,7 +24,7 @@ base::Value::Dict BuildCreatedAtTimestampUserData( } user_data.Set(kCreatedAtTimestampKey, - TimeToPrivacyPreservingISO8601(transaction.created_at)); + TimeToPrivacyPreservingIso8601(transaction.created_at)); return user_data; } diff --git a/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc b/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc index 00e9d3bc29b5..e3ddcf3d7e0a 100644 --- a/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc +++ b/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader_unittest.cc @@ -225,8 +225,8 @@ CatalogCampaignInfo BuildCatalogCampaign1() { catalog_campaign.id = "27a624a1-9c80-494a-bf1b-af327b563f85"; catalog_campaign.priority = 1; catalog_campaign.pass_through_rate = 1.0; - catalog_campaign.start_at = DistantPastAsISO8601(); - catalog_campaign.end_at = DistantFutureAsISO8601(); + catalog_campaign.start_at = DistantPastAsIso8601(); + catalog_campaign.end_at = DistantFutureAsIso8601(); catalog_campaign.daily_cap = 10; catalog_campaign.advertiser_id = "a437c7f3-9a48-4fe8-b37b-99321bea93fe"; catalog_campaign.creative_sets = catalog_creative_sets; @@ -413,8 +413,8 @@ CatalogCampaignInfo BuildCatalogCampaign2() { catalog_campaign.id = "856fc4bc-a21b-4582-bab7-a20d412359aa"; catalog_campaign.priority = 2; catalog_campaign.pass_through_rate = 0.5; - catalog_campaign.start_at = DistantPastAsISO8601(); - catalog_campaign.end_at = DistantFutureAsISO8601(); + catalog_campaign.start_at = DistantPastAsIso8601(); + catalog_campaign.end_at = DistantFutureAsIso8601(); catalog_campaign.daily_cap = 25; catalog_campaign.advertiser_id = "7523854c-5f28-4153-9da8-d9da6804ed58"; catalog_campaign.creative_sets = catalog_creative_sets; diff --git a/components/brave_ads/core/internal/common/time/time_util.cc b/components/brave_ads/core/internal/common/time/time_util.cc index 80bf03e18c3b..095426904c1b 100644 --- a/components/brave_ads/core/internal/common/time/time_util.cc +++ b/components/brave_ads/core/internal/common/time/time_util.cc @@ -236,7 +236,7 @@ base::Time GetLocalTimeAtEndOfThisMonth() { return AdjustLocalTimeToEndOfMonth(now); } -std::string TimeToPrivacyPreservingISO8601(const base::Time time) { +std::string TimeToPrivacyPreservingIso8601(const base::Time time) { base::Time::Exploded exploded; time.UTCExplode(&exploded); diff --git a/components/brave_ads/core/internal/common/time/time_util.h b/components/brave_ads/core/internal/common/time/time_util.h index 3aa65f170e5b..4caed70dff51 100644 --- a/components/brave_ads/core/internal/common/time/time_util.h +++ b/components/brave_ads/core/internal/common/time/time_util.h @@ -28,7 +28,7 @@ base::Time GetLocalTimeAtEndOfLastMonth(); base::Time GetLocalTimeAtBeginningOfThisMonth(); base::Time GetLocalTimeAtEndOfThisMonth(); -std::string TimeToPrivacyPreservingISO8601(base::Time time); +std::string TimeToPrivacyPreservingIso8601(base::Time time); // TODO(https://github.com/brave/brave-browser/issues/20169): Remove this // function when base::Time::FromLocalExploded for linux sandbox will be fixed. diff --git a/components/brave_ads/core/internal/common/time/time_util_unittest.cc b/components/brave_ads/core/internal/common/time/time_util_unittest.cc index 5fb0ecba4d50..de57eb59ff72 100644 --- a/components/brave_ads/core/internal/common/time/time_util_unittest.cc +++ b/components/brave_ads/core/internal/common/time/time_util_unittest.cc @@ -235,14 +235,14 @@ TEST_P(BraveAdsTimeUtilTest, GetLocalTimeAtEndOfThisMonth) { EXPECT_EQ(expected_adjusted_time, GetLocalTimeAtEndOfThisMonth()); } -TEST_P(BraveAdsTimeUtilTest, TimeToPrivacyPreservingISO8601) { +TEST_P(BraveAdsTimeUtilTest, TimeToPrivacyPreservingIso8601) { // Arrange const base::Time time = TimeFromString("November 18 2020 23:45:12.345", /*is_local=*/false); AdvanceClockTo(time); // Act & Assert - EXPECT_EQ("2020-11-18T23:00:00.000Z", TimeToPrivacyPreservingISO8601(Now())); + EXPECT_EQ("2020-11-18T23:00:00.000Z", TimeToPrivacyPreservingIso8601(Now())); } #if BUILDFLAG(IS_LINUX) diff --git a/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc index 1ec79c921d32..59e50fc260da 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_base_util.cc @@ -175,7 +175,7 @@ void MockLoadComponentResource(AdsClientMock& mock, if (!base::PathExists(path)) { // If path does not exist load the file from the test path. - path = TestDataComponentResourcesPath().AppendASCII(id); + path = ComponentResourcesTestDataPath().AppendASCII(id); } base::File file(path, base::File::Flags::FLAG_OPEN | diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc index 11472cfbcc39..607d431e2b21 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.cc @@ -26,7 +26,7 @@ base::FilePath TestDataPath() { "data"); } -base::FilePath TestDataComponentResourcesPath() { +base::FilePath ComponentResourcesTestDataPath() { return TestDataPath().AppendASCII("resources"); } diff --git a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h index 87c5006ce34b..b17b82efa062 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h +++ b/components/brave_ads/core/internal/common/unittest/unittest_file_path_util.h @@ -14,7 +14,7 @@ namespace brave_ads { base::FilePath TestDataPath(); -base::FilePath TestDataComponentResourcesPath(); +base::FilePath ComponentResourcesTestDataPath(); base::FilePath DataResourcesPath(); diff --git a/components/brave_ads/core/internal/common/unittest/unittest_tag_parser_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_tag_parser_util.cc index 103a51c90e93..1d2548f9ac4b 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_tag_parser_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_tag_parser_util.cc @@ -64,15 +64,15 @@ absl::optional ParseTimeDelta(const std::string& value) { absl::optional ParseTimeTagValue(const std::string& value) { if (value == kNowTimeTagValue) { - return NowAsISO8601(); + return NowAsIso8601(); } if (value == kDistantPastTimeTagValue) { - return DistantPastAsISO8601(); + return DistantPastAsIso8601(); } if (value == kDistantFutureTimeTagValue) { - return DistantFutureAsISO8601(); + return DistantFutureAsIso8601(); } if (re2::RE2::FullMatch(value, "[-+]?[0-9]*.*(seconds|minutes|hours|days)")) { diff --git a/components/brave_ads/core/internal/common/unittest/unittest_time_util.cc b/components/brave_ads/core/internal/common/unittest/unittest_time_util.cc index e4526a2ee8cb..2798af53766a 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_time_util.cc +++ b/components/brave_ads/core/internal/common/unittest/unittest_time_util.cc @@ -28,7 +28,7 @@ base::Time DistantPast() { return base::Time() + base::Microseconds(1); } -std::string DistantPastAsISO8601() { +std::string DistantPastAsIso8601() { return base::TimeFormatAsIso8601(DistantPast()); } @@ -37,7 +37,7 @@ base::Time Now() { return base::Time::Now(); } -std::string NowAsISO8601() { +std::string NowAsIso8601() { return base::TimeFormatAsIso8601(Now()); } @@ -49,7 +49,7 @@ base::Time DistantFuture() { /*Tuesday, 19 January 2038 03:14:07=*/2147483647); } -std::string DistantFutureAsISO8601() { +std::string DistantFutureAsIso8601() { return base::TimeFormatAsIso8601(DistantFuture()); } diff --git a/components/brave_ads/core/internal/common/unittest/unittest_time_util.h b/components/brave_ads/core/internal/common/unittest/unittest_time_util.h index 7d4d34d73c9e..906b9b948bc1 100644 --- a/components/brave_ads/core/internal/common/unittest/unittest_time_util.h +++ b/components/brave_ads/core/internal/common/unittest/unittest_time_util.h @@ -18,12 +18,15 @@ base::Time TimeFromString(const std::string& time_string, bool is_local); // The distance between the past, present and future is only a persistent // illusion. Albert Einstein. + base::Time DistantPast(); -std::string DistantPastAsISO8601(); +std::string DistantPastAsIso8601(); + base::Time Now(); -std::string NowAsISO8601(); +std::string NowAsIso8601(); + base::Time DistantFuture(); -std::string DistantFutureAsISO8601(); +std::string DistantFutureAsIso8601(); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc b/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc index 9b396344a2b6..e7a9abc68664 100644 --- a/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc +++ b/components/brave_ads/core/internal/conversions/resource/conversion_resource_unittest.cc @@ -61,7 +61,7 @@ TEST_F(BraveAdsConversionResourceTest, DoNotLoadMissingResource) { const int /*version*/, LoadFileCallback callback) { const base::FilePath path = - TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + ComponentResourcesTestDataPath().AppendASCII(kMissingResourceId); base::File file( path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc index 6c11c8941255..c127ddce4478 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/anti_targeting/resource/anti_targeting_resource_unittest.cc @@ -62,7 +62,7 @@ TEST_F(BraveAdsAntiTargetingResourceTest, DoNotLoadMissingResource) { const int /*version*/, LoadFileCallback callback) { const base::FilePath path = - TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + ComponentResourcesTestDataPath().AppendASCII(kMissingResourceId); base::File file( path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc index 4b4ee0e827ae..6a070a345632 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/resource/purchase_intent_resource_unittest.cc @@ -62,7 +62,7 @@ TEST_F(BraveAdsPurchaseIntentResourceTest, DoNotLoadMissingResource) { const int /*version*/, LoadFileCallback callback) { const base::FilePath path = - TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + ComponentResourcesTestDataPath().AppendASCII(kMissingResourceId); base::File file( path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc index 66cd2d530e7e..0e78dbeba2dc 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_classification/resource/text_classification_resource_unittest.cc @@ -63,7 +63,7 @@ TEST_F(BraveAdsTextClassificationResourceTest, DoNotLoadMissingResource) { const int /*version*/, LoadFileCallback callback) { const base::FilePath path = - TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + ComponentResourcesTestDataPath().AppendASCII(kMissingResourceId); base::File file( path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); diff --git a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc index ddbfe055711a..d01a9ce30dac 100644 --- a/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc +++ b/components/brave_ads/core/internal/targeting/contextual/text_embedding/resource/text_embedding_resource_unittest.cc @@ -62,7 +62,7 @@ TEST_F(BraveAdsTextEmbeddingResourceTest, DoNotLoadMissingResource) { const int /*version*/, LoadFileCallback callback) { const base::FilePath path = - TestDataComponentResourcesPath().AppendASCII(kMissingResourceId); + ComponentResourcesTestDataPath().AppendASCII(kMissingResourceId); base::File file( path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); From c2637bd7e41584237cfd942f50c0de3e11b33f48 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Fri, 24 Nov 2023 17:38:34 -0500 Subject: [PATCH 6/6] [ads] Update README.md --- components/brave_ads/README.md | 2 +- components/brave_ads/core/README.md | 2 + .../core/internal/common/unittest/README.md | 39 ++++++++++--------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/components/brave_ads/README.md b/components/brave_ads/README.md index 4f342c158e2c..7423ace50674 100644 --- a/components/brave_ads/README.md +++ b/components/brave_ads/README.md @@ -2,7 +2,7 @@ Users earn tokens by viewing privacy-first Brave Ads. Ads presented are based on the user's interests, as inferred from the user's browsing behavior. No personal data or browsing history should ever leave the browser. -For more details, refer to [glossary of terms](../../../brave/components/brave_ads/GLOSSARY.md). +For more details, refer to [glossary of terms](GLOSSARY.md). Brave Ads is a [layered component](https://sites.google.com/a/chromium.org/dev/developers/design-documents/layered-components-design). It has the following structure: diff --git a/components/brave_ads/core/README.md b/components/brave_ads/core/README.md index 01c39c98d04e..c6231c032e6f 100644 --- a/components/brave_ads/core/README.md +++ b/components/brave_ads/core/README.md @@ -2,4 +2,6 @@ Platform independent implementation of the world's first global ad platform built on privacy, see [Brave Ads](https://brave.com/brave-ads-launch/). +For more details, refer to [glossary of terms](../GLOSSARY.md). + Please add to it! diff --git a/components/brave_ads/core/internal/common/unittest/README.md b/components/brave_ads/core/internal/common/unittest/README.md index a1d05a54f715..62de3039848d 100644 --- a/components/brave_ads/core/internal/common/unittest/README.md +++ b/components/brave_ads/core/internal/common/unittest/README.md @@ -23,8 +23,9 @@ Override `SetUp` and call `SetUp` with `is_integration_test` set to `true` to te Use the `GetAds` convenience function to access `AdsImpl`. i.e. - GetAds().TriggerNotificationAdEvent(/*placement_id* - "7ee858e8-6306-4317-88c3-9e7d58afad26", ConfirmationType::kClicked); + GetAds().TriggerNotificationAdEvent( + /*placement_id=*/"7ee858e8-6306-4317-88c3-9e7d58afad26", + ConfirmationType::kClicked); ## Mocking Command-Line Switches @@ -76,7 +77,7 @@ Mocked responses for URL requests can be defined inline or read from a text file net::HTTP_OK, "/response.json" } } - } + }; MockUrlResponses(ads_client_mock_, url_responses); @@ -88,7 +89,7 @@ Inline or text file responses can contain `` tags for mocking times net::HTTP_OK, "An example response with a timestamp in the not too distant future" } } - } + }; MockUrlResponses(ads_client_mock_, url_responses); @@ -96,23 +97,25 @@ Inline or text file responses can contain `` tags for mocking times You can add one or more responses per request, which will be returned in the given order, then will wrap back to the first response after mocking the last, i.e. - const URLResponseMap url_responses = { - "/foo/bar", { - { - net::HTTP_INTERNAL_SERVER_ERROR, "Program say to kill, to disassemble, to make dead" - }, - { - net::HTTP_CREATED, "To me there's no creativity without boundaries" + const URLResponseMap url_responses2 = { + { + "/foo/bar", { + { + net::HTTP_INTERNAL_SERVER_ERROR, "Program say to kill, to disassemble, to make dead" + }, + { + net::HTTP_CREATED, "To me there's no creativity without boundaries" + } } - } - }, - { - "/baz", { - { - net::HTTP_IM_A_TEAPOT, "Keep Calm & Drink Tea! L. Masinter, 1 April 1998" + }, + { + "/baz", { + { + net::HTTP_IM_A_TEAPOT, "Keep Calm & Drink Tea! L. Masinter, 1 April 1998" + } } } - } + }; MockUrlResponses(ads_client_mock_, url_responses);