From 4558b8a365003766b97523f5a451c0d338a7df04 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Thu, 17 Oct 2024 11:48:03 -0500 Subject: [PATCH] [ads] General code health --- components/brave_ads/core/internal/BUILD.gn | 1 + .../account/issuers/issuers_constants.h | 2 +- .../payment_token_value_util_unittest.cc | 4 +- .../payment_tokens_test_util.cc | 6 +- .../account/utility/tokens_constants.h | 2 +- .../internal/ad_units/ad_test_constants.h | 10 +++ .../internal/ad_units/creative_ad_cache.cc | 32 +++---- .../internal/ad_units/creative_ad_cache.h | 17 ++-- .../ad_units/creative_ad_cache_unittest.cc | 85 ++++++++++--------- .../core/internal/catalog/catalog_constants.h | 2 +- .../common/net/http/http_status_code.h | 2 +- .../subdivision_url_request_constants.h | 2 +- ..._set_conversion_database_table_unittest.cc | 4 +- .../creative_set_conversion_util_unittest.cc | 18 ++-- .../core/internal/flags/flag_constants.h | 4 +- .../conversion_exclusion_rule_unittest.cc | 20 ++--- .../daily_cap_exclusion_rule_unittest.cc | 22 ++--- ...on_ad_dismissed_exclusion_rule_unittest.cc | 37 ++++---- .../page_land_exclusion_rule_unittest.cc | 29 +++---- .../total_max_exclusion_rule_unittest.cc | 21 ++--- .../priority/priority_unittest.cc | 6 +- .../conversions/conversions_unittest.cc | 3 +- .../reactions/reactions_unittest.cc | 9 +- 23 files changed, 163 insertions(+), 175 deletions(-) diff --git a/components/brave_ads/core/internal/BUILD.gn b/components/brave_ads/core/internal/BUILD.gn index 07254e58d988..32a962023cc0 100644 --- a/components/brave_ads/core/internal/BUILD.gn +++ b/components/brave_ads/core/internal/BUILD.gn @@ -1251,6 +1251,7 @@ static_library("internal") { "//crypto", "//net", "//sql", + "//third_party/abseil-cpp:absl", "//third_party/boringssl", "//third_party/re2", "//third_party/zlib", diff --git a/components/brave_ads/core/internal/account/issuers/issuers_constants.h b/components/brave_ads/core/internal/account/issuers/issuers_constants.h index e548881b1a3a..abfee926a318 100644 --- a/components/brave_ads/core/internal/account/issuers/issuers_constants.h +++ b/components/brave_ads/core/internal/account/issuers/issuers_constants.h @@ -8,7 +8,7 @@ namespace brave_ads { -constexpr int kIssuersServerVersion = 3; +inline constexpr int kIssuersServerVersion = 3; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_value_util_unittest.cc b/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_value_util_unittest.cc index 627bb7a62069..404c15be95d3 100644 --- a/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_value_util_unittest.cc +++ b/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_value_util_unittest.cc @@ -23,14 +23,14 @@ constexpr char kPaymentTokensAsJson[] = "ad_type": "ad_notification", "confirmation_type": "view", "public_key": "RJ2i/o/pZkrH+i0aGEMY1G9FXtd7Q7gfRi3YdNRnDDk=", - "transaction_id": "0d9de7ce-b3f9-4158-8726-23d52b9457c6", + "transaction_id": "8b742869-6e4a-490c-ac31-31b49130098a", "unblinded_token": "PLowz2WF2eGD5zfwZjk9p76HXBLDKMq/3EAZHeG/fE2XGQ48jyte+Ve50ZlasOuYL5mwA8CU2aFMlJrt3DDgC3B1+VD/uyHPfa/+bwYRrpVH5YwNSDEydVx8S4r+BYVY" }, { "ad_type": "ad_notification", "confirmation_type": "view", "public_key": "RJ2i/o/pZkrH+i0aGEMY1G9FXtd7Q7gfRi3YdNRnDDk=", - "transaction_id": "0d9de7ce-b3f9-4158-8726-23d52b9457c6", + "transaction_id": "8b742869-6e4a-490c-ac31-31b49130098a", "unblinded_token": "hfrMEltWLuzbKQ02Qixh5C/DWiJbdOoaGaidKZ7Mv+cRq5fyxJqemE/MPlARPhl6NgXPHUeyaxzd6/Lk6YHlfXbBA023DYvGMHoKm15NP/nWnZ1V3iLkgOOHZuk80Z4K" } ])"; diff --git a/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens_test_util.cc b/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens_test_util.cc index 9293b31258b3..777e7485b05c 100644 --- a/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens_test_util.cc +++ b/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens_test_util.cc @@ -3,13 +3,15 @@ * 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/account/tokens/payment_tokens/payment_tokens_test_util.h" + #include #include #include #include "base/check_op.h" #include "brave/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens.h" -#include "brave/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens_test_util.h" +#include "brave/components/brave_ads/core/internal/account/transactions/transaction_test_constants.h" #include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/public_key.h" #include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h" #include "brave/components/brave_ads/core/internal/deprecated/confirmations/confirmation_state_manager.h" @@ -21,7 +23,7 @@ namespace { PaymentTokenInfo BuildPaymentToken(const std::string& payment_token_base64) { PaymentTokenInfo payment_token; - payment_token.transaction_id = "0d9de7ce-b3f9-4158-8726-23d52b9457c6"; + payment_token.transaction_id = test::kTransactionId; payment_token.unblinded_token = cbr::UnblindedToken(payment_token_base64); CHECK(payment_token.unblinded_token.has_value()); diff --git a/components/brave_ads/core/internal/account/utility/tokens_constants.h b/components/brave_ads/core/internal/account/utility/tokens_constants.h index 510be4870bed..13efb10f3878 100644 --- a/components/brave_ads/core/internal/account/utility/tokens_constants.h +++ b/components/brave_ads/core/internal/account/utility/tokens_constants.h @@ -8,7 +8,7 @@ namespace brave_ads { -constexpr int kTokensServerVersion = 3; +inline constexpr int kTokensServerVersion = 3; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/ad_units/ad_test_constants.h b/components/brave_ads/core/internal/ad_units/ad_test_constants.h index 8a9eef2fa9ac..6bd542e98041 100644 --- a/components/brave_ads/core/internal/ad_units/ad_test_constants.h +++ b/components/brave_ads/core/internal/ad_units/ad_test_constants.h @@ -9,27 +9,37 @@ namespace brave_ads::test { inline constexpr char kPlacementId[] = "9bac9ae4-693c-4569-9b3e-300e357780cf"; +inline constexpr char kAnotherPlacementId[] = + "75994a99-65e4-4171-b134-10859dfc6d18"; inline constexpr char kMissingPlacementId[] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; inline constexpr char kInvalidPlacementId[] = ""; inline constexpr char kCreativeInstanceId[] = "546fe7b0-5047-4f28-a11c-81f14edcf0f6"; +inline constexpr char kAnotherCreativeInstanceId[] = + "e1c4c9a3-a05b-4d6a-83f9-72260729ebb0"; inline constexpr char kMissingCreativeInstanceId[] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; inline constexpr char kInvalidCreativeInstanceId[] = ""; inline constexpr char kCreativeSetId[] = "c2ba3e7d-f688-4bc4-a053-cbe7ac1e6123"; +inline constexpr char kAnotherCreativeSetId[] = + "e31e1905-e8a3-4461-9930-82f68e70d8ba"; inline constexpr char kMissingCreativeSetId[] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; inline constexpr char kInvalidCreativeSetId[] = ""; inline constexpr char kCampaignId[] = "84197fc8-830a-4a8e-8339-7a70c2bfa104"; +inline constexpr char kAnotherCampaignId[] = + "b164214f-670d-4eb2-8a71-92fb2dd805ca"; inline constexpr char kMissingCampaignId[] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; inline constexpr char kInvalidCampaignId[] = ""; inline constexpr char kAdvertiserId[] = "5484a63f-eb99-4ba5-a3b0-8c25d3c0e4b2"; +inline constexpr char kAnotherAdvertiserId[] = + "5b010b85-39ed-476a-b8c1-1746db2f86b7"; inline constexpr char kMissingAdvertiserId[] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; inline constexpr char kInvalidAdvertiserId[] = ""; diff --git a/components/brave_ads/core/internal/ad_units/creative_ad_cache.cc b/components/brave_ads/core/internal/ad_units/creative_ad_cache.cc index d03db5e05a69..1a3bf57aab2e 100644 --- a/components/brave_ads/core/internal/ad_units/creative_ad_cache.cc +++ b/components/brave_ads/core/internal/ad_units/creative_ad_cache.cc @@ -5,8 +5,6 @@ #include "brave/components/brave_ads/core/internal/ad_units/creative_ad_cache.h" -#include - #include "base/containers/contains.h" #include "base/functional/overloaded.h" #include "brave/components/brave_ads/core/internal/tabs/tab_info.h" @@ -16,21 +14,21 @@ namespace brave_ads { namespace { -bool IsCreativeAdVariantValid(const CreativeAdVariant& creative_ad_variant) { +bool IsValid(const CreativeAdVariant& creative_ad_variant) { return absl::visit( base::Overloaded{ - [](const mojom::CreativeSearchResultAdInfoPtr& search_result_ad) - -> bool { return !!search_result_ad; }}, + [](const mojom::CreativeSearchResultAdInfoPtr& mojom_creative_ad) + -> bool { return !!mojom_creative_ad; }}, creative_ad_variant); } -std::optional CloneCreativeAdVariant( +std::optional Clone( const CreativeAdVariant& creative_ad_variant) { return absl::visit( base::Overloaded{ - [](const mojom::CreativeSearchResultAdInfoPtr& search_result_ad) + [](const mojom::CreativeSearchResultAdInfoPtr& mojom_creative_ad) -> std::optional { - return search_result_ad.Clone(); + return mojom_creative_ad.Clone(); }}, creative_ad_variant); } @@ -47,7 +45,7 @@ CreativeAdCache::~CreativeAdCache() { void CreativeAdCache::MaybeAdd(const std::string& placement_id, CreativeAdVariant creative_ad_variant) { - if (!IsCreativeAdVariantValid(creative_ad_variant)) { + if (!IsValid(creative_ad_variant)) { return; } @@ -58,19 +56,17 @@ void CreativeAdCache::MaybeAdd(const std::string& placement_id, } } -std::optional CreativeAdCache::MaybeGet( - const std::string& placement_id) { +/////////////////////////////////////////////////////////////////////////////// + +std::optional CreativeAdCache::MaybeGetCreativeAdVariant( + const std::string& placement_id) const { const auto iter = creative_ad_variants_.find(placement_id); if (iter == creative_ad_variants_.cend()) { return std::nullopt; } const auto& creative_ad_variant = iter->second; - return CloneCreativeAdVariant(creative_ad_variant); -} - -void CreativeAdCache::OnDidCloseTab(const int32_t tab_id) { - PurgePlacements(tab_id); + return Clone(creative_ad_variant); } void CreativeAdCache::PurgePlacements(const int32_t tab_id) { @@ -84,4 +80,8 @@ void CreativeAdCache::PurgePlacements(const int32_t tab_id) { placement_ids_.erase(tab_id); } +void CreativeAdCache::OnDidCloseTab(const int32_t tab_id) { + PurgePlacements(tab_id); +} + } // namespace brave_ads diff --git a/components/brave_ads/core/internal/ad_units/creative_ad_cache.h b/components/brave_ads/core/internal/ad_units/creative_ad_cache.h index b8905f6da391..d83b2a073b87 100644 --- a/components/brave_ads/core/internal/ad_units/creative_ad_cache.h +++ b/components/brave_ads/core/internal/ad_units/creative_ad_cache.h @@ -6,7 +6,9 @@ #ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_CREATIVE_AD_CACHE_H_ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_CREATIVE_AD_CACHE_H_ +#include #include +#include #include #include #include @@ -36,13 +38,17 @@ class CreativeAdCache final : public TabManagerObserver { ~CreativeAdCache() override; + // Adds a creative ad to the cache for the given `placement_id` if it is valid + // and there is a visible tab. void MaybeAdd(const std::string& placement_id, CreativeAdVariant creative_ad_variant); + // Gets a creative ad from the cache if it exists for the given + // `placement_id`. template std::optional MaybeGet(const std::string& placement_id) { std::optional creative_ad_variant = - MaybeGet(placement_id); + MaybeGetCreativeAdVariant(placement_id); if (!creative_ad_variant) { return std::nullopt; } @@ -55,13 +61,14 @@ class CreativeAdCache final : public TabManagerObserver { } private: - // TabManagerObserver: - void OnDidCloseTab(int32_t tab_id) override; - - std::optional MaybeGet(const std::string& placement_id); + std::optional MaybeGetCreativeAdVariant( + const std::string& placement_id) const; void PurgePlacements(int32_t tab_id); + // TabManagerObserver: + void OnDidCloseTab(int32_t tab_id) override; + CreativeAdVariantMap creative_ad_variants_; PlacementIdMap placement_ids_; }; diff --git a/components/brave_ads/core/internal/ad_units/creative_ad_cache_unittest.cc b/components/brave_ads/core/internal/ad_units/creative_ad_cache_unittest.cc index e28804ff4e8a..1c741399d966 100644 --- a/components/brave_ads/core/internal/ad_units/creative_ad_cache_unittest.cc +++ b/components/brave_ads/core/internal/ad_units/creative_ad_cache_unittest.cc @@ -10,22 +10,18 @@ #include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/search_result_ads/creative_search_result_ad_test_util.h" -#include "brave/components/brave_ads/core/internal/tabs/tab_manager.h" -#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" // npm run test -- brave_unit_tests --filter=BraveAds* namespace brave_ads { -constexpr char kAnotherPlacementId[] = "b1f50335-5b9f-4139-a8cd-dd3d16337096"; - class BraveAdsCreativeAdCacheTest : public test::TestBase { protected: void SetUp() override { test::TestBase::SetUp(); - cache_ = std::make_unique(); + creative_ad_cache_ = std::make_unique(); } void SimulateOpenTab(const int32_t tab_id) { @@ -36,23 +32,23 @@ class BraveAdsCreativeAdCacheTest : public test::TestBase { void SimulateCloseTab(const int32_t tab_id) { NotifyDidCloseTab(tab_id); } - std::unique_ptr cache_; + std::unique_ptr creative_ad_cache_; }; TEST_F(BraveAdsCreativeAdCacheTest, AddCreativeAd) { // Arrange - const mojom::CreativeSearchResultAdInfoPtr expected_mojom_creative_ad = + const mojom::CreativeSearchResultAdInfoPtr mojom_creative_ad = test::BuildCreativeSearchResultAdWithConversion( /*should_generate_random_uuids=*/true); SimulateOpenTab(/*tab_id=*/1); // Act - cache_->MaybeAdd(test::kPlacementId, expected_mojom_creative_ad->Clone()); + creative_ad_cache_->MaybeAdd(test::kPlacementId, mojom_creative_ad->Clone()); // Assert - EXPECT_EQ(expected_mojom_creative_ad, - cache_->MaybeGet( + EXPECT_EQ(mojom_creative_ad, + creative_ad_cache_->MaybeGet( test::kPlacementId)); } @@ -61,11 +57,13 @@ TEST_F(BraveAdsCreativeAdCacheTest, DoNotAddCreativeAd) { SimulateOpenTab(/*tab_id=*/1); // Act - cache_->MaybeAdd(test::kPlacementId, mojom::CreativeSearchResultAdInfoPtr{}); + creative_ad_cache_->MaybeAdd(test::kPlacementId, + mojom::CreativeSearchResultAdInfoPtr{}); // Assert - EXPECT_FALSE(cache_->MaybeGet( - test::kPlacementId)); + EXPECT_FALSE( + creative_ad_cache_->MaybeGet( + test::kPlacementId)); } TEST_F(BraveAdsCreativeAdCacheTest, DoNotAddInvalidCreativeAd) { @@ -75,11 +73,13 @@ TEST_F(BraveAdsCreativeAdCacheTest, DoNotAddInvalidCreativeAd) { CreativeAdVariant creative_ad_variant; // Act - cache_->MaybeAdd(test::kPlacementId, std::move(creative_ad_variant)); + creative_ad_cache_->MaybeAdd(test::kPlacementId, + std::move(creative_ad_variant)); // Assert - EXPECT_FALSE(cache_->MaybeGet( - test::kPlacementId)); + EXPECT_FALSE( + creative_ad_cache_->MaybeGet( + test::kPlacementId)); } TEST_F(BraveAdsCreativeAdCacheTest, DoNotAddCreativeAdForOccludedTab) { @@ -89,11 +89,13 @@ TEST_F(BraveAdsCreativeAdCacheTest, DoNotAddCreativeAdForOccludedTab) { /*should_generate_random_uuids=*/true)); // Act - cache_->MaybeAdd(test::kPlacementId, std::move(creative_ad_variant)); + creative_ad_cache_->MaybeAdd(test::kPlacementId, + std::move(creative_ad_variant)); // Assert - EXPECT_FALSE(cache_->MaybeGet( - test::kPlacementId)); + EXPECT_FALSE( + creative_ad_cache_->MaybeGet( + test::kPlacementId)); } TEST_F(BraveAdsCreativeAdCacheTest, DoNotGetCreativeAdForMissingPlacementId) { @@ -103,57 +105,60 @@ TEST_F(BraveAdsCreativeAdCacheTest, DoNotGetCreativeAdForMissingPlacementId) { /*should_generate_random_uuids=*/true)); // Act - cache_->MaybeAdd(test::kPlacementId, std::move(creative_ad_variant)); + creative_ad_cache_->MaybeAdd(test::kPlacementId, + std::move(creative_ad_variant)); // Assert - EXPECT_FALSE(cache_->MaybeGet( - test::kMissingPlacementId)); + EXPECT_FALSE( + creative_ad_cache_->MaybeGet( + test::kMissingPlacementId)); } -TEST_F(BraveAdsCreativeAdCacheTest, GetCreativeAdsForMultipleTabs) { +TEST_F(BraveAdsCreativeAdCacheTest, GetCreativeAdsAcrossMultipleTabs) { // Arrange - const mojom::CreativeSearchResultAdInfoPtr expected_mojom_creative_ad = + const mojom::CreativeSearchResultAdInfoPtr mojom_creative_ad = test::BuildCreativeSearchResultAdWithConversion( /*should_generate_random_uuids=*/true); // Act SimulateOpenTab(/*tab_id=*/1); - cache_->MaybeAdd(test::kPlacementId, expected_mojom_creative_ad->Clone()); + creative_ad_cache_->MaybeAdd(test::kPlacementId, mojom_creative_ad->Clone()); SimulateOpenTab(/*tab_id=*/2); - cache_->MaybeAdd(kAnotherPlacementId, expected_mojom_creative_ad->Clone()); + creative_ad_cache_->MaybeAdd(test::kAnotherPlacementId, + mojom_creative_ad->Clone()); // Assert - EXPECT_EQ(expected_mojom_creative_ad, - cache_->MaybeGet( + EXPECT_EQ(mojom_creative_ad, + creative_ad_cache_->MaybeGet( test::kPlacementId)); - - EXPECT_EQ(expected_mojom_creative_ad, - cache_->MaybeGet( - kAnotherPlacementId)); + EXPECT_EQ(mojom_creative_ad, + creative_ad_cache_->MaybeGet( + test::kAnotherPlacementId)); } TEST_F(BraveAdsCreativeAdCacheTest, PurgePlacementsOnTabDidClose) { // Arrange - const mojom::CreativeSearchResultAdInfoPtr expected_mojom_creative_ad = + const mojom::CreativeSearchResultAdInfoPtr mojom_creative_ad = test::BuildCreativeSearchResultAdWithConversion( /*should_generate_random_uuids=*/true); SimulateOpenTab(/*tab_id=*/1); - cache_->MaybeAdd(test::kPlacementId, expected_mojom_creative_ad->Clone()); + creative_ad_cache_->MaybeAdd(test::kPlacementId, mojom_creative_ad->Clone()); SimulateOpenTab(/*tab_id=*/2); - cache_->MaybeAdd(kAnotherPlacementId, expected_mojom_creative_ad->Clone()); + creative_ad_cache_->MaybeAdd(test::kAnotherPlacementId, + mojom_creative_ad->Clone()); // Act SimulateCloseTab(/*tab_id=*/2); // Assert - EXPECT_EQ(expected_mojom_creative_ad, - cache_->MaybeGet( + EXPECT_EQ(mojom_creative_ad, + creative_ad_cache_->MaybeGet( test::kPlacementId)); - - EXPECT_FALSE(cache_->MaybeGet( - kAnotherPlacementId)); + EXPECT_FALSE( + creative_ad_cache_->MaybeGet( + test::kAnotherPlacementId)); } } // namespace brave_ads diff --git a/components/brave_ads/core/internal/catalog/catalog_constants.h b/components/brave_ads/core/internal/catalog/catalog_constants.h index 88de79d60fff..ebee72fb7031 100644 --- a/components/brave_ads/core/internal/catalog/catalog_constants.h +++ b/components/brave_ads/core/internal/catalog/catalog_constants.h @@ -8,7 +8,7 @@ namespace brave_ads { -constexpr int kCatalogVersion = 9; +inline constexpr int kCatalogVersion = 9; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/common/net/http/http_status_code.h b/components/brave_ads/core/internal/common/net/http/http_status_code.h index d065e894b84e..4341bfe05c55 100644 --- a/components/brave_ads/core/internal/common/net/http/http_status_code.h +++ b/components/brave_ads/core/internal/common/net/http/http_status_code.h @@ -10,7 +10,7 @@ namespace net { // HTTP status code 418 "I'm a teapot" is an April Fools' joke from the IETF's // RFC 2324, Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0). -constexpr int kHttpImATeapot = 418; +inline constexpr int kHttpImATeapot = 418; } // namespace net diff --git a/components/brave_ads/core/internal/common/subdivision/url_request/subdivision_url_request_constants.h b/components/brave_ads/core/internal/common/subdivision/url_request/subdivision_url_request_constants.h index eb50445b2671..426231a49e00 100644 --- a/components/brave_ads/core/internal/common/subdivision/url_request/subdivision_url_request_constants.h +++ b/components/brave_ads/core/internal/common/subdivision/url_request/subdivision_url_request_constants.h @@ -8,7 +8,7 @@ namespace brave_ads { -constexpr int kSubdivisionServerVersion = 1; +inline constexpr int kSubdivisionServerVersion = 1; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table_unittest.cc b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table_unittest.cc index 4f9c74a1dd85..919b27e76ccd 100644 --- a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table_unittest.cc +++ b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_database_table_unittest.cc @@ -47,7 +47,7 @@ TEST_F(BraveAdsCreativeSetConversionDatabaseTableTest, const CreativeSetConversionInfo creative_set_conversion_2 = test::BuildCreativeSetConversion( - /*creative_set_id=*/"4e83a23c-1194-40f8-8fdc-2f38d7ed75c8", + test::kAnotherCreativeSetId, /*url_pattern=*/"https://www.brave.com/signup/*", /*observation_window=*/base::Days(30)); creative_set_conversions.push_back(creative_set_conversion_2); @@ -100,7 +100,7 @@ TEST_F(BraveAdsCreativeSetConversionDatabaseTableTest, const CreativeSetConversionInfo creative_set_conversion_2 = test::BuildCreativeSetConversion( - /*creative_set_id=*/"4e83a23c-1194-40f8-8fdc-2f38d7ed75c8", + test::kAnotherCreativeSetId, /*url_pattern=*/"https://www.brave.com/signup/*", /*observation_window=*/base::Days(3)); // Should be purged creative_set_conversions.push_back(creative_set_conversion_2); diff --git a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_util_unittest.cc b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_util_unittest.cc index dd7a304a92a4..1d3154eb7524 100644 --- a/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_util_unittest.cc +++ b/components/brave_ads/core/internal/creatives/conversions/creative_set_conversion_util_unittest.cc @@ -85,7 +85,7 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest, GetCreativeSetConversionCounts) { AdEventInfo ad_event_2 = BuildAdEvent(ad, mojom::ConfirmationType::kConversion, /*created_at=*/test::Now()); - ad_event_2.creative_set_id = "4e83a23c-1194-40f8-8fdc-2f38d7ed75c8"; + ad_event_2.creative_set_id = test::kAnotherCreativeSetId; ad_events.push_back(ad_event_2); const AdEventInfo ad_event_3 = @@ -124,8 +124,7 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest, const CreativeSetConversionInfo creative_set_conversion_2 = test::BuildCreativeSetConversion( - /*creative_set_id=*/"4e83a23c-1194-40f8-8fdc-2f38d7ed75c8", - /*url_pattern=*/"https://www.qux.com/", + test::kAnotherCreativeSetId, /*url_pattern=*/"https://www.qux.com/", /*observation_window=*/base::Days(7)); // Bucket #2 creative_set_conversions.push_back(creative_set_conversion_2); @@ -174,8 +173,7 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest, const CreativeSetConversionInfo creative_set_conversion_2 = test::BuildCreativeSetConversion( - /*creative_set_id=*/"4e83a23c-1194-40f8-8fdc-2f38d7ed75c8", - /*url_pattern=*/"https://baz.com/", + test::kAnotherCreativeSetId, /*url_pattern=*/"https://baz.com/", /*observation_window=*/base::Days(30)); // Bucket #1 creative_set_conversions.push_back(creative_set_conversion_2); creative_set_conversions.push_back(creative_set_conversion_2); @@ -216,8 +214,7 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest, const CreativeSetConversionInfo creative_set_conversion_2 = test::BuildCreativeSetConversion( - /*creative_set_id=*/"4e83a23c-1194-40f8-8fdc-2f38d7ed75c8", - /*url_pattern=*/"https://baz.com/", + test::kAnotherCreativeSetId, /*url_pattern=*/"https://baz.com/", /*observation_window=*/base::Days(30)); // Bucket #2 creative_set_conversions.push_back(creative_set_conversion_2); creative_set_conversions.push_back(creative_set_conversion_2); @@ -268,10 +265,9 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest, creative_set_conversions.push_back(creative_set_conversion_1); const CreativeSetConversionInfo creative_set_conversion_2 = - test::BuildCreativeSetConversion( - /*creative_set_id=*/"4e83a23c-1194-40f8-8fdc-2f38d7ed75c8", - /*url_pattern=*/"https://www.qux.com/", - /*observation_window=*/base::Days(3)); + test::BuildCreativeSetConversion(test::kAnotherCreativeSetId, + /*url_pattern=*/"https://www.qux.com/", + /*observation_window=*/base::Days(3)); creative_set_conversions.push_back(creative_set_conversion_2); // Act diff --git a/components/brave_ads/core/internal/flags/flag_constants.h b/components/brave_ads/core/internal/flags/flag_constants.h index bb7cd7a9e3ba..08c81699bed5 100644 --- a/components/brave_ads/core/internal/flags/flag_constants.h +++ b/components/brave_ads/core/internal/flags/flag_constants.h @@ -12,10 +12,10 @@ namespace brave_ads { #if defined(OFFICIAL_BUILD) -constexpr mojom::EnvironmentType kDefaultEnvironmentType = +inline constexpr mojom::EnvironmentType kDefaultEnvironmentType = mojom::EnvironmentType::kProduction; #else // OFFICIAL_BUILD -constexpr mojom::EnvironmentType kDefaultEnvironmentType = +inline constexpr mojom::EnvironmentType kDefaultEnvironmentType = mojom::EnvironmentType::kStaging; #endif // !OFFICIAL_BUILD diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/conversion_exclusion_rule_unittest.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/conversion_exclusion_rule_unittest.cc index 0917bb5236a7..a0e8496004e5 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/conversion_exclusion_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/conversion_exclusion_rule_unittest.cc @@ -18,14 +18,6 @@ namespace brave_ads { -namespace { - -constexpr const char* kCreativeSetIds[] = { - "654f10df-fbc4-4a92-8d43-2edf73734a60", - "465f10df-fbc4-4a92-8d43-4edf73734a60"}; - -} // namespace - class BraveAdsConversionExclusionRuleTest : public test::TestBase {}; TEST_F(BraveAdsConversionExclusionRuleTest, @@ -44,7 +36,7 @@ TEST_F(BraveAdsConversionExclusionRuleTest, ShouldExcludeIfSameCreativeSetHasAlreadyConverted) { // Arrange CreativeAdInfo creative_ad; - creative_ad.creative_set_id = kCreativeSetIds[0]; + creative_ad.creative_set_id = test::kCreativeSetId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -68,7 +60,7 @@ TEST_F(BraveAdsConversionExclusionRuleTest, {{"should_exclude_ad_if_creative_set_exceeds_conversion_cap", "0"}}); CreativeAdInfo creative_ad; - creative_ad.creative_set_id = kCreativeSetIds[0]; + creative_ad.creative_set_id = test::kCreativeSetId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -94,7 +86,7 @@ TEST_F(BraveAdsConversionExclusionRuleTest, {{"should_exclude_ad_if_creative_set_exceeds_conversion_cap", "7"}}); CreativeAdInfo creative_ad; - creative_ad.creative_set_id = kCreativeSetIds[0]; + creative_ad.creative_set_id = test::kCreativeSetId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -121,7 +113,7 @@ TEST_F(BraveAdsConversionExclusionRuleTest, {{"should_exclude_ad_if_creative_set_exceeds_conversion_cap", "7"}}); CreativeAdInfo creative_ad; - creative_ad.creative_set_id = kCreativeSetIds[0]; + creative_ad.creative_set_id = test::kCreativeSetId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -143,10 +135,10 @@ TEST_F(BraveAdsConversionExclusionRuleTest, ShouldIncludeIfCreativeSetHasNotAlreadyConverted) { // Arrange CreativeAdInfo creative_ad_1; - creative_ad_1.creative_set_id = kCreativeSetIds[0]; + creative_ad_1.creative_set_id = test::kCreativeSetId; CreativeAdInfo creative_ad_2; - creative_ad_2.creative_set_id = kCreativeSetIds[1]; + creative_ad_2.creative_set_id = test::kAnotherCreativeSetId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daily_cap_exclusion_rule_unittest.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daily_cap_exclusion_rule_unittest.cc index 1dd78792c141..d633660eb4ec 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daily_cap_exclusion_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daily_cap_exclusion_rule_unittest.cc @@ -5,6 +5,7 @@ #include "brave/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/daily_cap_exclusion_rule.h" +#include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/common/test/time_test_util.h" #include "brave/components/brave_ads/core/internal/creatives/creative_ad_info.h" @@ -15,19 +16,12 @@ namespace brave_ads { -namespace { - -constexpr const char* kCampaignIds[] = {"60267cee-d5bb-4a0d-baaf-91cd7f18e07e", - "90762cee-d5bb-4a0d-baaf-61cd7f18e07e"}; - -} // namespace - class BraveAdsDailyCapExclusionRuleTest : public test::TestBase {}; TEST_F(BraveAdsDailyCapExclusionRuleTest, ShouldIncludeIfThereAreNoAdEvents) { // Arrange CreativeAdInfo creative_ad; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; creative_ad.daily_cap = 2; const DailyCapExclusionRule exclusion_rule(/*ad_events=*/{}); @@ -39,7 +33,7 @@ TEST_F(BraveAdsDailyCapExclusionRuleTest, ShouldIncludeIfThereAreNoAdEvents) { TEST_F(BraveAdsDailyCapExclusionRuleTest, ShouldIncludeIfDoesNotExceedCap) { // Arrange CreativeAdInfo creative_ad; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; creative_ad.daily_cap = 2; AdEventList ad_events; @@ -59,11 +53,11 @@ TEST_F(BraveAdsDailyCapExclusionRuleTest, ShouldIncludeIfDoesNotExceedCapForNoMatchingCampaigns) { // Arrange CreativeAdInfo creative_ad_1; - creative_ad_1.campaign_id = kCampaignIds[0]; + creative_ad_1.campaign_id = test::kCampaignId; creative_ad_1.daily_cap = 1; CreativeAdInfo creative_ad_2; - creative_ad_2.campaign_id = kCampaignIds[1]; + creative_ad_2.campaign_id = test::kAnotherCampaignId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -82,7 +76,7 @@ TEST_F(BraveAdsDailyCapExclusionRuleTest, ShouldIncludeIfDoesNotExceedCapWithin1Day) { // Arrange CreativeAdInfo creative_ad; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; creative_ad.daily_cap = 2; AdEventList ad_events; @@ -104,7 +98,7 @@ TEST_F(BraveAdsDailyCapExclusionRuleTest, ShouldIncludeIfDoesNotExceedCapAfter1Day) { // Arrange CreativeAdInfo creative_ad; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; creative_ad.daily_cap = 2; AdEventList ad_events; @@ -125,7 +119,7 @@ TEST_F(BraveAdsDailyCapExclusionRuleTest, TEST_F(BraveAdsDailyCapExclusionRuleTest, ShouldExcludeIfExceedsCap) { // Arrange CreativeAdInfo creative_ad; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; creative_ad.daily_cap = 2; AdEventList ad_events; diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/notification_ads/notification_ad_dismissed_exclusion_rule_unittest.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/notification_ads/notification_ad_dismissed_exclusion_rule_unittest.cc index b89278e50b59..206c40ca5134 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/notification_ads/notification_ad_dismissed_exclusion_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/notification_ads/notification_ad_dismissed_exclusion_rule_unittest.cc @@ -24,13 +24,6 @@ namespace brave_ads { -namespace { - -constexpr const char* kCampaignIds[] = {"60267cee-d5bb-4a0d-baaf-91cd7f18e07e", - "90762cee-d5bb-4a0d-baaf-61cd7f18e07e"}; - -} // namespace - class BraveAdsDismissedExclusionRuleTest : public test::TestBase {}; TEST_F(BraveAdsDismissedExclusionRuleTest, ShouldAlwaysInclude) { @@ -42,7 +35,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, ShouldAlwaysInclude) { CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -61,7 +54,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, ShouldIncludeIfThereAreNoAdEvents) { // Arrange CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const NotificationAdDismissedExclusionRule exclusion_rule(/*ad_events=*/{}); @@ -79,7 +72,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -113,7 +106,7 @@ TEST_F( CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; AdEventList ad_events; @@ -157,7 +150,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -191,7 +184,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -228,7 +221,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -262,7 +255,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -299,7 +292,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -337,7 +330,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -373,7 +366,7 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -408,11 +401,11 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, CreativeAdInfo creative_ad_1; creative_ad_1.creative_instance_id = test::kCreativeInstanceId; - creative_ad_1.campaign_id = kCampaignIds[0]; + creative_ad_1.campaign_id = test::kCampaignId; CreativeAdInfo creative_ad_2; creative_ad_2.creative_instance_id = test::kCreativeInstanceId; - creative_ad_2.campaign_id = kCampaignIds[1]; + creative_ad_2.campaign_id = test::kAnotherCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, @@ -441,11 +434,11 @@ TEST_F(BraveAdsDismissedExclusionRuleTest, // Arrange CreativeAdInfo creative_ad_1; creative_ad_1.creative_instance_id = test::kCreativeInstanceId; - creative_ad_1.campaign_id = kCampaignIds[0]; + creative_ad_1.campaign_id = test::kCampaignId; CreativeAdInfo creative_ad_2; creative_ad_2.creative_instance_id = test::kCreativeInstanceId; - creative_ad_2.campaign_id = kCampaignIds[1]; + creative_ad_2.campaign_id = test::kAnotherCampaignId; const std::vector mojom_confirmation_types = { mojom::ConfirmationType::kViewedImpression, diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/page_land_exclusion_rule_unittest.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/page_land_exclusion_rule_unittest.cc index bb2f5c0573df..c32629c24f3c 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/page_land_exclusion_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/page_land_exclusion_rule_unittest.cc @@ -21,13 +21,6 @@ namespace brave_ads { -namespace { - -constexpr const char* kCampaignIds[] = {"60267cee-d5bb-4a0d-baaf-91cd7f18e07e", - "90762cee-d5bb-4a0d-baaf-61cd7f18e07e"}; - -} // namespace - class BraveAdsPageLandExclusionRuleTest : public test::TestBase {}; TEST_F(BraveAdsPageLandExclusionRuleTest, ShouldAlwaysInclude) { @@ -39,7 +32,7 @@ TEST_F(BraveAdsPageLandExclusionRuleTest, ShouldAlwaysInclude) { CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -58,7 +51,7 @@ TEST_F(BraveAdsPageLandExclusionRuleTest, ShouldIncludeIfThereAreNoAdEvents) { // Arrange CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; const PageLandExclusionRule exclusion_rule(/*ad_events=*/{}); @@ -76,11 +69,11 @@ TEST_F(BraveAdsPageLandExclusionRuleTest, CreativeAdInfo creative_ad_1; creative_ad_1.creative_instance_id = test::kCreativeInstanceId; - creative_ad_1.campaign_id = kCampaignIds[0]; + creative_ad_1.campaign_id = test::kCampaignId; CreativeAdInfo creative_ad_2; creative_ad_2.creative_instance_id = test::kCreativeInstanceId; - creative_ad_2.campaign_id = kCampaignIds[1]; + creative_ad_2.campaign_id = test::kAnotherCampaignId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -106,11 +99,11 @@ TEST_F(BraveAdsPageLandExclusionRuleTest, CreativeAdInfo creative_ad_1; creative_ad_1.creative_instance_id = test::kCreativeInstanceId; - creative_ad_1.campaign_id = kCampaignIds[0]; + creative_ad_1.campaign_id = test::kCampaignId; CreativeAdInfo creative_ad_2; creative_ad_2.creative_instance_id = test::kCreativeInstanceId; - creative_ad_2.campaign_id = kCampaignIds[1]; + creative_ad_2.campaign_id = test::kAnotherCampaignId; AdEventList ad_events; @@ -163,7 +156,7 @@ TEST_F(BraveAdsPageLandExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -190,7 +183,7 @@ TEST_F(BraveAdsPageLandExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -217,7 +210,7 @@ TEST_F(BraveAdsPageLandExclusionRuleTest, CreativeAdInfo creative_ad; creative_ad.creative_instance_id = test::kCreativeInstanceId; - creative_ad.campaign_id = kCampaignIds[0]; + creative_ad.campaign_id = test::kCampaignId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -244,11 +237,11 @@ TEST_F(BraveAdsPageLandExclusionRuleTest, CreativeAdInfo creative_ad_1; creative_ad_1.creative_instance_id = test::kCreativeInstanceId; - creative_ad_1.campaign_id = kCampaignIds[0]; + creative_ad_1.campaign_id = test::kCampaignId; CreativeAdInfo creative_ad_2; creative_ad_2.creative_instance_id = test::kCreativeInstanceId; - creative_ad_2.campaign_id = kCampaignIds[1]; + creative_ad_2.campaign_id = test::kAnotherCampaignId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( diff --git a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule_unittest.cc b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule_unittest.cc index 39754b4f2305..48a9b1801d08 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule_unittest.cc @@ -5,6 +5,7 @@ #include "brave/components/brave_ads/core/internal/serving/eligible_ads/exclusion_rules/total_max_exclusion_rule.h" +#include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/common/test/time_test_util.h" #include "brave/components/brave_ads/core/internal/creatives/creative_ad_info.h" @@ -15,20 +16,12 @@ namespace brave_ads { -namespace { - -constexpr const char* kCreativeSetIds[] = { - "654f10df-fbc4-4a92-8d43-2edf73734a60", - "465f10df-fbc4-4a92-8d43-4edf73734a60"}; - -} // namespace - class BraveAdsTotalMaxExclusionRuleTest : public test::TestBase {}; TEST_F(BraveAdsTotalMaxExclusionRuleTest, ShouldIncludeIfThereAreNoAdEvents) { // Arrange CreativeAdInfo creative_ad; - creative_ad.creative_set_id = kCreativeSetIds[0]; + creative_ad.creative_set_id = test::kCreativeSetId; creative_ad.total_max = 2; const TotalMaxExclusionRule exclusion_rule(/*ad_events=*/{}); @@ -40,7 +33,7 @@ TEST_F(BraveAdsTotalMaxExclusionRuleTest, ShouldIncludeIfThereAreNoAdEvents) { TEST_F(BraveAdsTotalMaxExclusionRuleTest, ShouldIncludeIfZero) { // Arrange CreativeAdInfo creative_ad; - creative_ad.creative_set_id = kCreativeSetIds[0]; + creative_ad.creative_set_id = test::kCreativeSetId; creative_ad.total_max = 0; const TotalMaxExclusionRule exclusion_rule(/*ad_events=*/{}); @@ -52,7 +45,7 @@ TEST_F(BraveAdsTotalMaxExclusionRuleTest, ShouldIncludeIfZero) { TEST_F(BraveAdsTotalMaxExclusionRuleTest, ShouldIncludeIfDoesNotExceedCap) { // Arrange CreativeAdInfo creative_ad; - creative_ad.creative_set_id = kCreativeSetIds[0]; + creative_ad.creative_set_id = test::kCreativeSetId; creative_ad.total_max = 2; AdEventList ad_events; @@ -72,11 +65,11 @@ TEST_F(BraveAdsTotalMaxExclusionRuleTest, ShouldIncludeIfDoesNotExceedCapForNoMatchingCreatives) { // Arrange CreativeAdInfo creative_ad_1; - creative_ad_1.creative_set_id = kCreativeSetIds[0]; + creative_ad_1.creative_set_id = test::kCreativeSetId; creative_ad_1.total_max = 2; CreativeAdInfo creative_ad_2; - creative_ad_2.creative_set_id = kCreativeSetIds[1]; + creative_ad_2.creative_set_id = test::kAnotherCreativeSetId; AdEventList ad_events; const AdEventInfo ad_event = test::BuildAdEvent( @@ -95,7 +88,7 @@ TEST_F(BraveAdsTotalMaxExclusionRuleTest, TEST_F(BraveAdsTotalMaxExclusionRuleTest, ShouldExcludeIfExceedsCap) { // Arrange CreativeAdInfo creative_ad; - creative_ad.creative_set_id = kCreativeSetIds[0]; + creative_ad.creative_set_id = test::kCreativeSetId; creative_ad.total_max = 2; AdEventList ad_events; diff --git a/components/brave_ads/core/internal/serving/eligible_ads/priority/priority_unittest.cc b/components/brave_ads/core/internal/serving/eligible_ads/priority/priority_unittest.cc index 33d53b5f5221..98b8dd84bd89 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/priority/priority_unittest.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/priority/priority_unittest.cc @@ -65,9 +65,9 @@ TEST_F(BraveAdsPriorityTest, // Assert const PrioritizedCreativeAdBuckets expected_prioritized_creative_ad_buckets = { - {/*priority*/ 1, {creative_ad_1, creative_ad_3}}, - {/*priority*/ 2, {creative_ad_2}}, - {/*priority*/ 3, {creative_ad_4}}}; + {/*priority=*/1, {creative_ad_1, creative_ad_3}}, + {/*priority=*/2, {creative_ad_2}}, + {/*priority=*/3, {creative_ad_4}}}; EXPECT_THAT(expected_prioritized_creative_ad_buckets, ::testing::ElementsAreArray(prioritized_creative_ad_buckets)); } diff --git a/components/brave_ads/core/internal/user_engagement/conversions/conversions_unittest.cc b/components/brave_ads/core/internal/user_engagement/conversions/conversions_unittest.cc index faa62023403d..4ff17e944657 100644 --- a/components/brave_ads/core/internal/user_engagement/conversions/conversions_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/conversions/conversions_unittest.cc @@ -7,6 +7,7 @@ #include "base/test/scoped_feature_list.h" #include "base/time/time.h" +#include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" #include "brave/components/brave_ads/core/internal/ad_units/ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/resources/country_components_test_constants.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" @@ -200,7 +201,7 @@ TEST_F(BraveAdsConversionsTest, /*html=*/""); AdInfo ad_2 = ad_1; - ad_2.creative_instance_id = "1e945c25-98a2-443c-a7f5-e695110d2b84"; + ad_2.creative_instance_id = test::kAnotherCreativeInstanceId; test::RecordAdEvents(ad_2, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression, mojom::ConfirmationType::kClicked}); diff --git a/components/brave_ads/core/internal/user_engagement/reactions/reactions_unittest.cc b/components/brave_ads/core/internal/user_engagement/reactions/reactions_unittest.cc index 677d1713a208..1f51b975f103 100644 --- a/components/brave_ads/core/internal/user_engagement/reactions/reactions_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/reactions/reactions_unittest.cc @@ -96,7 +96,7 @@ TEST_F(BraveAdsReactionsTest, Ads) { { mojom::ReactionInfoPtr mojom_reaction = test::BuildReaction(mojom::AdType::kNotificationAd); - mojom_reaction->advertiser_id = "57b26e2f-2e77-4b31-a3ce-d3faf82dd574"; + mojom_reaction->advertiser_id = test::kAnotherCampaignId; base::MockCallback callback; EXPECT_CALL(callback, Run(/*success=*/true)); @@ -126,7 +126,7 @@ TEST_F(BraveAdsReactionsTest, Ads) { { mojom::ReactionInfoPtr mojom_reaction = test::BuildReaction(mojom::AdType::kNotificationAd); - mojom_reaction->advertiser_id = "57b26e2f-2e77-4b31-a3ce-d3faf82dd574"; + mojom_reaction->advertiser_id = test::kAnotherCampaignId; base::MockCallback callback; EXPECT_CALL(callback, Run(/*success=*/true)); @@ -136,8 +136,9 @@ TEST_F(BraveAdsReactionsTest, Ads) { // Act & Assert const ReactionMap expected_ad_reactions = { {test::kAdvertiserId, mojom::ReactionType::kLiked}, - {"2c0577b2-097b-41e8-81db-685de60d26e5", mojom::ReactionType::kDisliked}, - {"57b26e2f-2e77-4b31-a3ce-d3faf82dd574", mojom::ReactionType::kDisliked}}; + {/*advertiser_id=*/"2c0577b2-097b-41e8-81db-685de60d26e5", + mojom::ReactionType::kDisliked}, + {test::kAnotherCampaignId, mojom::ReactionType::kDisliked}}; EXPECT_EQ(expected_ad_reactions, GetReactions().Ads()); }