diff --git a/components/brave_ads/core/internal/account/confirmations/reward/reward_confirmation_util.cc b/components/brave_ads/core/internal/account/confirmations/reward/reward_confirmation_util.cc index c0c53304f13e..1c5657317d9c 100644 --- a/components/brave_ads/core/internal/account/confirmations/reward/reward_confirmation_util.cc +++ b/components/brave_ads/core/internal/account/confirmations/reward/reward_confirmation_util.cc @@ -6,7 +6,6 @@ #include "brave/components/brave_ads/core/internal/account/confirmations/reward/reward_confirmation_util.h" #include -#include #include "base/base64url.h" #include "base/check.h" @@ -39,14 +38,12 @@ std::optional BuildReward(const ConfirmationInfo& confirmation) { RewardInfo reward; // Token - const std::vector tokens = - GetTokenGenerator()->Generate(/*count=*/1); + const cbr::TokenList tokens = GetTokenGenerator()->Generate(/*count=*/1); CHECK(!tokens.empty()); reward.token = tokens.front(); // Blinded token - const std::vector blinded_tokens = - cbr::BlindTokens(tokens); + const cbr::BlindedTokenList blinded_tokens = cbr::BlindTokens(tokens); CHECK(!blinded_tokens.empty()); reward.blinded_token = blinded_tokens.front(); diff --git a/components/brave_ads/core/internal/account/tokens/token_generator.cc b/components/brave_ads/core/internal/account/tokens/token_generator.cc index 1570873e93fc..b4aa22010d0b 100644 --- a/components/brave_ads/core/internal/account/tokens/token_generator.cc +++ b/components/brave_ads/core/internal/account/tokens/token_generator.cc @@ -5,12 +5,10 @@ #include "brave/components/brave_ads/core/internal/account/tokens/token_generator.h" -#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h" - namespace brave_ads { -std::vector TokenGenerator::Generate(const size_t count) const { - return std::vector(count); +cbr::TokenList TokenGenerator::Generate(const size_t count) const { + return cbr::TokenList(count); } } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/tokens/token_generator.h b/components/brave_ads/core/internal/account/tokens/token_generator.h index daca3f7576cb..6b4f96b0f0be 100644 --- a/components/brave_ads/core/internal/account/tokens/token_generator.h +++ b/components/brave_ads/core/internal/account/tokens/token_generator.h @@ -7,19 +7,15 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_TOKENS_TOKEN_GENERATOR_H_ #include -#include #include "brave/components/brave_ads/core/internal/account/tokens/token_generator_interface.h" +#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h" namespace brave_ads { -namespace cbr { -class Token; -} // namespace cbr - class TokenGenerator : public TokenGeneratorInterface { public: - std::vector Generate(size_t count) const override; + cbr::TokenList Generate(size_t count) const override; }; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/tokens/token_generator_interface.h b/components/brave_ads/core/internal/account/tokens/token_generator_interface.h index 323e817a35f9..24a9ff15a62b 100644 --- a/components/brave_ads/core/internal/account/tokens/token_generator_interface.h +++ b/components/brave_ads/core/internal/account/tokens/token_generator_interface.h @@ -7,19 +7,16 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_TOKENS_TOKEN_GENERATOR_INTERFACE_H_ #include -#include -namespace brave_ads { +#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h" -namespace cbr { -class Token; -} // namespace cbr +namespace brave_ads { class TokenGeneratorInterface { public: virtual ~TokenGeneratorInterface() = default; - virtual std::vector Generate(size_t count) const = 0; + virtual cbr::TokenList Generate(size_t count) const = 0; }; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/tokens/token_generator_mock.h b/components/brave_ads/core/internal/account/tokens/token_generator_mock.h index 86e685fbb290..0d2a6afdbfb3 100644 --- a/components/brave_ads/core/internal/account/tokens/token_generator_mock.h +++ b/components/brave_ads/core/internal/account/tokens/token_generator_mock.h @@ -7,9 +7,8 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_TOKENS_TOKEN_GENERATOR_MOCK_H_ #include -#include -#include "brave/components/brave_ads/core/internal/account/tokens/token_generator.h" +#include "brave/components/brave_ads/core/internal/account/tokens/token_generator_interface.h" #include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h" #include "testing/gmock/include/gmock/gmock.h" @@ -27,7 +26,7 @@ class TokenGeneratorMock : public TokenGeneratorInterface { ~TokenGeneratorMock() override; - MOCK_METHOD(std::vector, Generate, (const size_t count), (const)); + MOCK_METHOD(cbr::TokenList, Generate, (const size_t count), (const)); }; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/tokens/token_generator_test_util.cc b/components/brave_ads/core/internal/account/tokens/token_generator_test_util.cc index 6b2a08e41d58..b69e9e62b939 100644 --- a/components/brave_ads/core/internal/account/tokens/token_generator_test_util.cc +++ b/components/brave_ads/core/internal/account/tokens/token_generator_test_util.cc @@ -6,13 +6,12 @@ #include "brave/components/brave_ads/core/internal/account/tokens/token_generator_test_util.h" #include +#include #include "base/check_op.h" #include "base/no_destructor.h" -#include "brave/components/brave_ads/core/internal/account/tokens/token_generator_interface.h" #include "brave/components/brave_ads/core/internal/account/tokens/token_generator_mock.h" #include "brave/components/brave_ads/core/internal/ads_core/ads_core_util.h" -#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h" #include "testing/gmock/include/gmock/gmock.h" namespace brave_ads::test { @@ -149,12 +148,12 @@ void MockTokenGenerator(const size_t count) { .WillByDefault(::testing::Return(BuildTokens(count))); } -std::vector BuildTokens(const size_t count) { +cbr::TokenList BuildTokens(const size_t count) { CHECK_GT(count, 0U); const size_t modulo = Tokens().size(); - std::vector tokens; + cbr::TokenList tokens; for (size_t i = 0; i < count; ++i) { const std::string& token_base64 = Tokens().at(i % modulo); diff --git a/components/brave_ads/core/internal/account/tokens/token_generator_test_util.h b/components/brave_ads/core/internal/account/tokens/token_generator_test_util.h index 462efb43a02e..f892423794a8 100644 --- a/components/brave_ads/core/internal/account/tokens/token_generator_test_util.h +++ b/components/brave_ads/core/internal/account/tokens/token_generator_test_util.h @@ -7,25 +7,18 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_TOKENS_TOKEN_GENERATOR_TEST_UTIL_H_ #include -#include -namespace brave_ads { +#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h" -namespace cbr { -class Token; -} // namespace cbr - -namespace test { +namespace brave_ads::test { // Call this function to mock the token generator for testing purposes if code // paths call `RefillConfirmationTokens::MaybeRefill`, `Confirmations::Confirm`, // `BuildRewardConfirmation`, or `BuildReward`. void MockTokenGenerator(size_t count); -std::vector BuildTokens(size_t count); - -} // namespace test +cbr::TokenList BuildTokens(size_t count); -} // namespace brave_ads +} // namespace brave_ads::test #endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_TOKENS_TOKEN_GENERATOR_TEST_UTIL_H_ diff --git a/components/brave_ads/core/internal/account/tokens/token_generator_unittest.cc b/components/brave_ads/core/internal/account/tokens/token_generator_unittest.cc index bf9c6ef5ec1c..89170ced3b93 100644 --- a/components/brave_ads/core/internal/account/tokens/token_generator_unittest.cc +++ b/components/brave_ads/core/internal/account/tokens/token_generator_unittest.cc @@ -18,7 +18,7 @@ TEST(BraveAdsTokenGeneratorTest, Generate) { const TokenGenerator token_generator; // Act - const std::vector tokens = token_generator.Generate(5); + const cbr::TokenList tokens = token_generator.Generate(5); // Assert EXPECT_THAT(tokens, ::testing::SizeIs(5)); @@ -29,7 +29,7 @@ TEST(BraveAdsTokenGeneratorTest, GenerateZero) { const TokenGenerator token_generator; // Act - const std::vector tokens = token_generator.Generate(0); + const cbr::TokenList tokens = token_generator.Generate(0); // Assert EXPECT_THAT(tokens, ::testing::IsEmpty()); diff --git a/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.cc b/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.cc index 9443d664c0c5..9a75b85df75a 100644 --- a/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.cc +++ b/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.cc @@ -248,7 +248,7 @@ RedeemRewardConfirmation::HandleFetchPaymentTokenUrlResponse( /*should_retry=*/true)); } - const std::optional> unblinded_tokens = + const std::optional unblinded_tokens = ParseVerifyAndUnblindTokens( *payment_token_dict, {confirmation.reward->token}, {confirmation.reward->blinded_token}, *public_key); diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.cc b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.cc index 0439df12937e..97cb89b31ce1 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.cc +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.cc @@ -251,7 +251,7 @@ RefillConfirmationTokens::HandleGetSignedTokensUrlResponse( /*should_retry=*/true)); } - const std::optional> unblinded_tokens = + const std::optional unblinded_tokens = ParseVerifyAndUnblindTokens(*dict, *tokens_, *blinded_tokens_, *public_key); if (!unblinded_tokens) { diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h index c9d4b242441f..a5826054eac2 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h @@ -9,7 +9,6 @@ #include #include #include -#include #include "base/check_op.h" #include "base/memory/raw_ptr.h" @@ -89,8 +88,8 @@ class RefillConfirmationTokens final { std::optional nonce_; - std::optional> tokens_; - std::optional> blinded_tokens_; + std::optional tokens_; + std::optional blinded_tokens_; bool is_refilling_ = false; diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/get_signed_tokens/get_signed_tokens_url_request_util.cc b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/get_signed_tokens/get_signed_tokens_url_request_util.cc index 2150b0fb44ba..b37c4921693c 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/get_signed_tokens/get_signed_tokens_url_request_util.cc +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/get_signed_tokens/get_signed_tokens_url_request_util.cc @@ -10,7 +10,6 @@ #include "brave/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens_util.h" #include "brave/components/brave_ads/core/internal/account/wallet/wallet_info.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/common/crypto/crypto_util.h" #include "brave/components/brave_ads/core/internal/common/logging_util.h" @@ -32,7 +31,7 @@ std::optional Sign(const cbr::UnblindedToken& unblinded_token, } ConfirmationTokenList BuildConfirmationTokens( - const std::vector& unblinded_tokens, + const cbr::UnblindedTokenList& unblinded_tokens, const cbr::PublicKey& public_key, const WalletInfo& wallet) { ConfirmationTokenList confirmation_tokens; @@ -60,7 +59,7 @@ std::optional ParseCaptchaId(const base::Value::Dict& dict) { } void BuildAndAddConfirmationTokens( - const std::vector& unblinded_tokens, + const cbr::UnblindedTokenList& unblinded_tokens, const cbr::PublicKey& public_key, const WalletInfo& wallet) { const ConfirmationTokenList confirmation_tokens = diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/get_signed_tokens/get_signed_tokens_url_request_util.h b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/get_signed_tokens/get_signed_tokens_url_request_util.h index 7eb51f48126b..18f09662de8f 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/get_signed_tokens/get_signed_tokens_url_request_util.h +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/get_signed_tokens/get_signed_tokens_url_request_util.h @@ -8,15 +8,14 @@ #include #include -#include #include "base/values.h" +#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h" namespace brave_ads { namespace cbr { class PublicKey; -class UnblindedToken; } // namespace cbr struct WalletInfo; @@ -24,7 +23,7 @@ struct WalletInfo; std::optional ParseCaptchaId(const base::Value::Dict& dict); void BuildAndAddConfirmationTokens( - const std::vector& unblinded_tokens, + const cbr::UnblindedTokenList& unblinded_tokens, const cbr::PublicKey& public_key, const WalletInfo& wallet); diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder.cc b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder.cc index c4b833fb7d52..9caf5c119a80 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder.cc +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder.cc @@ -40,7 +40,7 @@ std::string BuildDigestHeaderValue(const std::string& body) { RequestSignedTokensUrlRequestBuilder::RequestSignedTokensUrlRequestBuilder( WalletInfo wallet, - std::vector blinded_tokens) + cbr::BlindedTokenList blinded_tokens) : wallet_(std::move(wallet)), blinded_tokens_(std::move(blinded_tokens)) { CHECK(wallet_.IsValid()); CHECK(!blinded_tokens_.empty()); diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder.h b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder.h index 546d5e2067b1..50bb90b1b718 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder.h +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder.h @@ -22,7 +22,7 @@ class RequestSignedTokensUrlRequestBuilder final : public UrlRequestBuilderInterface { public: RequestSignedTokensUrlRequestBuilder(WalletInfo wallet, - std::vector tokens); + cbr::BlindedTokenList tokens); RequestSignedTokensUrlRequestBuilder( const RequestSignedTokensUrlRequestBuilder&) = delete; @@ -47,7 +47,7 @@ class RequestSignedTokensUrlRequestBuilder final std::string BuildBody() const; const WalletInfo wallet_; - const std::vector blinded_tokens_; + const cbr::BlindedTokenList blinded_tokens_; }; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder_unittest.cc b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder_unittest.cc index 9aa9be4e57d3..1bbf51637090 100644 --- a/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder_unittest.cc +++ b/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/url_requests/request_signed_tokens/request_signed_tokens_url_request_builder_unittest.cc @@ -21,9 +21,8 @@ class BraveAdsRequestSignedTokensUrlRequestBuilderTest : public test::TestBase { TEST_F(BraveAdsRequestSignedTokensUrlRequestBuilderTest, BuildUrl) { // Arrange - const std::vector tokens = test::BuildTokens(/*count=*/3); - const std::vector blinded_tokens = - cbr::BlindTokens(tokens); + const cbr::TokenList tokens = test::BuildTokens(/*count=*/3); + const cbr::BlindedTokenList blinded_tokens = cbr::BlindTokens(tokens); RequestSignedTokensUrlRequestBuilder url_request_builder(test::Wallet(), blinded_tokens); diff --git a/components/brave_ads/core/internal/account/utility/tokens_util.cc b/components/brave_ads/core/internal/account/utility/tokens_util.cc index e3beb34742de..4e3fe88d87db 100644 --- a/components/brave_ads/core/internal/account/utility/tokens_util.cc +++ b/components/brave_ads/core/internal/account/utility/tokens_util.cc @@ -5,10 +5,10 @@ #include "brave/components/brave_ads/core/internal/account/utility/tokens_util.h" +#include + #include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/batch_dleq_proof.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/signed_token.h" -#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h" #include "brave/components/brave_ads/core/internal/common/logging_util.h" namespace brave_ads { @@ -35,14 +35,14 @@ std::optional ParsePublicKey(const base::Value::Dict& dict) { return public_key; } -std::optional> ParseSignedTokens( +std::optional ParseSignedTokens( const base::Value::Dict& dict) { const base::Value::List* const list = dict.FindList(kSignedTokensKey); if (!list) { return std::nullopt; } - std::vector signed_tokens; + cbr::SignedTokenList signed_tokens; for (const auto& value : *list) { const std::string* const signed_token_base64 = value.GetIfString(); @@ -62,10 +62,10 @@ std::optional> ParseSignedTokens( return signed_tokens; } -std::optional> ParseVerifyAndUnblindTokens( +std::optional ParseVerifyAndUnblindTokens( const base::Value::Dict& dict, - const std::vector& tokens, - const std::vector& blinded_tokens, + const cbr::TokenList& tokens, + const cbr::BlindedTokenList& blinded_tokens, const cbr::PublicKey& public_key) { if (!public_key.has_value()) { BLOG(1, "Invalid public key"); @@ -85,14 +85,14 @@ std::optional> ParseVerifyAndUnblindTokens( return std::nullopt; } - const std::optional> signed_tokens = + const std::optional signed_tokens = ParseSignedTokens(dict); if (!signed_tokens) { BLOG(1, "Failed to parse signed tokens"); return std::nullopt; } - const std::optional> unblinded_tokens = + const std::optional unblinded_tokens = batch_dleq_proof.VerifyAndUnblind(tokens, blinded_tokens, *signed_tokens, public_key); if (!unblinded_tokens || unblinded_tokens->empty()) { diff --git a/components/brave_ads/core/internal/account/utility/tokens_util.h b/components/brave_ads/core/internal/account/utility/tokens_util.h index 016003874ff4..9904b2a0fc8a 100644 --- a/components/brave_ads/core/internal/account/utility/tokens_util.h +++ b/components/brave_ads/core/internal/account/utility/tokens_util.h @@ -7,29 +7,28 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_UTILITY_TOKENS_UTIL_H_ #include -#include #include "base/values.h" +#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h" +#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h" +#include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h" #include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h" namespace brave_ads { namespace cbr { -class BlindedToken; class PublicKey; -class SignedToken; -class Token; } // namespace cbr std::optional ParsePublicKey(const base::Value::Dict& dict); -std::optional> ParseSignedTokens( +std::optional ParseSignedTokens( const base::Value::Dict& dict); -std::optional> ParseVerifyAndUnblindTokens( +std::optional ParseVerifyAndUnblindTokens( const base::Value::Dict& dict, - const std::vector& tokens, - const std::vector& blinded_tokens, + const cbr::TokenList& tokens, + const cbr::BlindedTokenList& blinded_tokens, const cbr::PublicKey& public_key); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/utility/tokens_util_unittest.cc b/components/brave_ads/core/internal/account/utility/tokens_util_unittest.cc index 6395e95a8101..4bda78a0b224 100644 --- a/components/brave_ads/core/internal/account/utility/tokens_util_unittest.cc +++ b/components/brave_ads/core/internal/account/utility/tokens_util_unittest.cc @@ -52,12 +52,12 @@ TEST_F(BraveAdsSignedTokensUtilTest, DoNotParseInvalidPublicKey) { TEST_F(BraveAdsSignedTokensUtilTest, ParseSignedTokens) { // Act - const std::optional> signed_tokens = + const std::optional signed_tokens = ParseSignedTokens(BuildUrlResponseBody()); ASSERT_TRUE(signed_tokens); // Assert - const std::vector expected_signed_tokens = { + const cbr::SignedTokenList expected_signed_tokens = { cbr::SignedToken(cbr::test::kSignedTokenBase64)}; EXPECT_EQ(expected_signed_tokens, signed_tokens); } diff --git a/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.cc b/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.cc index c25f17e1af7c..6e49902dbb84 100644 --- a/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.cc +++ b/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.cc @@ -3,11 +3,13 @@ * 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/ad_units/inline_content_ad/inline_content_ad_test_util.h" + #include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_info.h" #include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.h" +#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_util.h" #include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h" #include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h" namespace brave_ads::test { @@ -18,4 +20,12 @@ InlineContentAdInfo BuildInlineContentAd( return BuildInlineContentAd(creative_ad); } +InlineContentAdInfo BuildAndSaveInlineContentAd( + const bool should_generate_random_uuids) { + const CreativeInlineContentAdInfo creative_ad = + BuildCreativeInlineContentAd(should_generate_random_uuids); + database::SaveCreativeInlineContentAds({creative_ad}); + return BuildInlineContentAd(creative_ad); +} + } // namespace brave_ads::test diff --git a/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h b/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h similarity index 53% rename from components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h rename to components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h index e881726652f1..8ed572d98050 100644 --- a/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h +++ b/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_ namespace brave_ads { @@ -14,8 +14,11 @@ namespace test { InlineContentAdInfo BuildInlineContentAd(bool should_generate_random_uuids); +InlineContentAdInfo BuildAndSaveInlineContentAd( + bool should_generate_random_uuids); + } // namespace test } // namespace brave_ads -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_ diff --git a/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.cc b/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.cc index 05f02069b161..da8687d65dba 100644 --- a/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.cc +++ b/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.cc @@ -3,11 +3,13 @@ * 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/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" + #include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_info.h" #include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_test_util.h" +#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_util.h" #include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" #include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" namespace brave_ads::test { @@ -17,4 +19,12 @@ NewTabPageAdInfo BuildNewTabPageAd(const bool should_generate_random_uuids) { return BuildNewTabPageAd(creative_ad); } +NewTabPageAdInfo BuildAndSaveNewTabPageAd( + const bool should_generate_random_uuids) { + const CreativeNewTabPageAdInfo creative_ad = + BuildCreativeNewTabPageAd(should_generate_random_uuids); + database::SaveCreativeNewTabPageAds({creative_ad}); + return BuildNewTabPageAd(creative_ad); +} + } // namespace brave_ads::test diff --git a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h b/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h similarity index 53% rename from components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h rename to components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h index aa61b96e7340..87078355eea1 100644 --- a/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h +++ b/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_ namespace brave_ads { @@ -14,8 +14,10 @@ namespace test { NewTabPageAdInfo BuildNewTabPageAd(bool should_generate_random_uuids); +NewTabPageAdInfo BuildAndSaveNewTabPageAd(bool should_generate_random_uuids); + } // namespace test } // namespace brave_ads -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_ diff --git a/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.cc b/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.cc index 83652ad0e8a0..731459d55b76 100644 --- a/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.cc +++ b/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.cc @@ -3,11 +3,14 @@ * 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/ad_units/notification_ad/notification_ad_test_util.h" + #include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_info.h" #include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_test_util.h" +#include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_util.h" #include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_builder.h" +#include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h" namespace brave_ads::test { @@ -18,4 +21,14 @@ NotificationAdInfo BuildNotificationAd( return BuildNotificationAd(creative_ad); } +NotificationAdInfo BuildAndSaveNotificationAd( + const bool should_generate_random_uuids) { + const CreativeNotificationAdInfo creative_ad = + BuildCreativeNotificationAd(should_generate_random_uuids); + database::SaveCreativeNotificationAds({creative_ad}); + const NotificationAdInfo ad = BuildNotificationAd(creative_ad); + NotificationAdManager::GetInstance().Add(ad); + return ad; +} + } // namespace brave_ads::test diff --git a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h b/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h similarity index 53% rename from components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h rename to components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h index 77cc15db20b6..a3f1a3a7f2a4 100644 --- a/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h +++ b/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_ namespace brave_ads { @@ -14,8 +14,11 @@ namespace test { NotificationAdInfo BuildNotificationAd(bool should_generate_random_uuids); +NotificationAdInfo BuildAndSaveNotificationAd( + bool should_generate_random_uuids); + } // namespace test } // namespace brave_ads -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_ diff --git a/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.cc b/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.cc new file mode 100644 index 000000000000..a199e454d04f --- /dev/null +++ b/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.cc @@ -0,0 +1,31 @@ +/* Copyright (c) 2024 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/ad_units/promoted_content_ad/promoted_content_ad_test_util.h" + +#include "brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_info.h" +#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_info.h" +#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_test_util.h" +#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_util.h" +#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/promoted_content_ad_builder.h" + +namespace brave_ads::test { + +PromotedContentAdInfo BuildPromotedContentAd( + const bool should_generate_random_uuids) { + const CreativePromotedContentAdInfo creative_ad = + BuildCreativePromotedContentAd(should_generate_random_uuids); + return BuildPromotedContentAd(creative_ad); +} + +PromotedContentAdInfo BuildAndSavePromotedContentAd( + const bool should_generate_random_uuids) { + const CreativePromotedContentAdInfo creative_ad = + BuildCreativePromotedContentAd(should_generate_random_uuids); + database::SaveCreativePromotedContentAds({creative_ad}); + return BuildPromotedContentAd(creative_ad); +} + +} // namespace brave_ads::test diff --git a/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.h b/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.h new file mode 100644 index 000000000000..1caadc116a43 --- /dev/null +++ b/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2024 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_AD_UNITS_PROMOTED_CONTENT_AD_PROMOTED_CONTENT_AD_TEST_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_PROMOTED_CONTENT_AD_PROMOTED_CONTENT_AD_TEST_UTIL_H_ + +namespace brave_ads { + +struct PromotedContentAdInfo; + +namespace test { + +PromotedContentAdInfo BuildPromotedContentAd(bool should_generate_random_uuids); + +PromotedContentAdInfo BuildAndSavePromotedContentAd( + bool should_generate_random_uuids); + +} // namespace test + +} // namespace brave_ads + +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_PROMOTED_CONTENT_AD_PROMOTED_CONTENT_AD_TEST_UTIL_H_ diff --git a/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_handler.cc b/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_handler.cc index 97a8e81abbbc..af3e4d02e6c1 100644 --- a/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_handler.cc +++ b/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_handler.cc @@ -61,7 +61,7 @@ void SearchResultAdHandler::TriggerDeferredAdViewedEventForTesting() { if (g_search_result_ad_handler_for_testing) { g_search_result_ad_handler_for_testing - ->trigger_ad_viewed_event_in_progress_ = false; + ->is_processing_viewed_ad_event_queue_ = false; g_search_result_ad_handler_for_testing->MaybeTriggerDeferredAdViewedEvent( /*intentional*/ base::DoNothing()); @@ -114,24 +114,24 @@ void SearchResultAdHandler::FireServedEventCallback( return std::move(callback).Run(/*success=*/false); } - ad_viewed_event_queue_.push_front(std::move(mojom_creative_ad)); + viewed_ad_event_queue_.push_front(std::move(mojom_creative_ad)); MaybeTriggerDeferredAdViewedEvent(std::move(callback)); } void SearchResultAdHandler::MaybeTriggerDeferredAdViewedEvent( TriggerAdEventCallback callback) { - CHECK((!ad_viewed_event_queue_.empty() || - !trigger_ad_viewed_event_in_progress_)); + CHECK((!viewed_ad_event_queue_.empty() || + !is_processing_viewed_ad_event_queue_)); - if (ad_viewed_event_queue_.empty() || trigger_ad_viewed_event_in_progress_) { + if (viewed_ad_event_queue_.empty() || is_processing_viewed_ad_event_queue_) { return std::move(callback).Run(/*success=*/true); } - trigger_ad_viewed_event_in_progress_ = true; + is_processing_viewed_ad_event_queue_ = true; mojom::CreativeSearchResultAdInfoPtr mojom_creative_ad = - std::move(ad_viewed_event_queue_.back()); - ad_viewed_event_queue_.pop_back(); + std::move(viewed_ad_event_queue_.back()); + viewed_ad_event_queue_.pop_back(); event_handler_.FireEvent( std::move(mojom_creative_ad), @@ -156,7 +156,7 @@ void SearchResultAdHandler::FireAdViewedEventCallback( return std::move(callback).Run(success); } - trigger_ad_viewed_event_in_progress_ = false; + is_processing_viewed_ad_event_queue_ = false; MaybeTriggerDeferredAdViewedEvent(std::move(callback)); } diff --git a/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_handler.h b/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_handler.h index 18277f8cb543..f96cbb43fc74 100644 --- a/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_handler.h +++ b/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_handler.h @@ -69,10 +69,9 @@ class SearchResultAdHandler final : public SearchResultAdEventHandlerDelegate { SearchResultAdEventHandler event_handler_; + bool is_processing_viewed_ad_event_queue_ = false; base::circular_deque - ad_viewed_event_queue_; - - bool trigger_ad_viewed_event_in_progress_ = false; + viewed_ad_event_queue_; base::WeakPtrFactory weak_factory_{this}; }; diff --git a/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.cc b/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.cc index 1f88016c34be..717628600c80 100644 --- a/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.cc +++ b/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.cc @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h" +#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_builder.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_info.h" diff --git a/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h b/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h similarity index 59% rename from components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h rename to components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h index ca0c05e015f4..acf0e3236e12 100644 --- a/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h +++ b/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_ namespace brave_ads { @@ -18,4 +18,4 @@ SearchResultAdInfo BuildSearchResultAd(bool should_generate_random_uuids); } // namespace brave_ads -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_ +#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_ diff --git a/components/brave_ads/core/internal/ads_impl.cc b/components/brave_ads/core/internal/ads_impl.cc index 9456a77a5a5e..6b282683aa2b 100644 --- a/components/brave_ads/core/internal/ads_impl.cc +++ b/components/brave_ads/core/internal/ads_impl.cc @@ -25,8 +25,6 @@ #include "brave/components/brave_ads/core/internal/legacy_migration/client/legacy_client_migration.h" #include "brave/components/brave_ads/core/internal/legacy_migration/confirmations/legacy_confirmation_migration.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_events.h" -#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_value_util.h" #include "brave/components/brave_ads/core/public/ads_client/ads_client.h" namespace brave_ads { diff --git a/components/brave_ads/core/internal/catalog/catalog.cc b/components/brave_ads/core/internal/catalog/catalog.cc index 6e529bed80e5..d7f4da68bbb0 100644 --- a/components/brave_ads/core/internal/catalog/catalog.cc +++ b/components/brave_ads/core/internal/catalog/catalog.cc @@ -102,15 +102,15 @@ void Catalog::MaybeFetchCatalog() const { } } -void Catalog::NotifyDidUpdateCatalog(const CatalogInfo& catalog) const { +void Catalog::NotifyDidFetchCatalog(const CatalogInfo& catalog) const { for (CatalogObserver& observer : observers_) { - observer.OnDidUpdateCatalog(catalog); + observer.OnDidFetchCatalog(catalog); } } -void Catalog::NotifyFailedToUpdateCatalog() const { +void Catalog::NotifyFailedToFetchCatalog() const { for (CatalogObserver& observer : observers_) { - observer.OnFailedToUpdateCatalog(); + observer.OnFailedToFetchCatalog(); } } @@ -138,11 +138,11 @@ void Catalog::OnDidFetchCatalog(const CatalogInfo& catalog) { SaveCatalog(catalog); - NotifyDidUpdateCatalog(catalog); + NotifyDidFetchCatalog(catalog); } void Catalog::OnFailedToFetchCatalog() { - NotifyFailedToUpdateCatalog(); + NotifyFailedToFetchCatalog(); } void Catalog::OnDidMigrateDatabase(const int /*from_version*/, diff --git a/components/brave_ads/core/internal/catalog/catalog.h b/components/brave_ads/core/internal/catalog/catalog.h index be142921297d..cf3d5c6ba7ff 100644 --- a/components/brave_ads/core/internal/catalog/catalog.h +++ b/components/brave_ads/core/internal/catalog/catalog.h @@ -46,8 +46,8 @@ class Catalog final : public AdsClientNotifierObserver, void MaybeFetchCatalog() const; - void NotifyDidUpdateCatalog(const CatalogInfo& catalog) const; - void NotifyFailedToUpdateCatalog() const; + void NotifyDidFetchCatalog(const CatalogInfo& catalog) const; + void NotifyFailedToFetchCatalog() const; // AdsClientNotifierObserver: void OnNotifyDidInitializeAds() override; diff --git a/components/brave_ads/core/internal/catalog/catalog_observer.h b/components/brave_ads/core/internal/catalog/catalog_observer.h index 3f6184e44303..2e114bd97aa8 100644 --- a/components/brave_ads/core/internal/catalog/catalog_observer.h +++ b/components/brave_ads/core/internal/catalog/catalog_observer.h @@ -14,11 +14,11 @@ struct CatalogInfo; class CatalogObserver : public base::CheckedObserver { public: - // Invoked when the catalog has updated. - virtual void OnDidUpdateCatalog(const CatalogInfo& catalog) {} + // Invoked when the catalog is successfully fetched. + virtual void OnDidFetchCatalog(const CatalogInfo& catalog) {} - // Invoked when the catalog failed to update. - virtual void OnFailedToUpdateCatalog() {} + // Invoked when the catalog fetch fails. + virtual void OnFailedToFetchCatalog() {} }; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/catalog/catalog_observer_mock.h b/components/brave_ads/core/internal/catalog/catalog_observer_mock.h index c0aaf0f10457..1168f52c0c54 100644 --- a/components/brave_ads/core/internal/catalog/catalog_observer_mock.h +++ b/components/brave_ads/core/internal/catalog/catalog_observer_mock.h @@ -23,9 +23,9 @@ class CatalogObserverMock : public CatalogObserver { ~CatalogObserverMock() override; - MOCK_METHOD(void, OnDidUpdateCatalog, (const CatalogInfo& catalog)); + MOCK_METHOD(void, OnDidFetchCatalog, (const CatalogInfo& catalog)); - MOCK_METHOD(void, OnFailedToUpdateCatalog, ()); + MOCK_METHOD(void, OnFailedToFetchCatalog, ()); }; } // namespace brave_ads diff --git a/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader.cc b/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader.cc index 35c2f8e5cfee..f6f819ad5100 100644 --- a/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader.cc +++ b/components/brave_ads/core/internal/catalog/catalog_url_request_json_reader.cc @@ -368,6 +368,10 @@ std::optional ReadCatalog(const std::string& json) { .x = wallpaper_node["focalPoint"]["x"].GetInt(), .y = wallpaper_node["focalPoint"]["y"].GetInt()}; + // For Rewards users, these matchers should be placed in the catalog + // under "wallpapers" with the "imageUrl" prefixed with "[SmartNTT]" + // for backwards compatibility, where legacy browsers will discard + // these wallpapers due to an invalid URL. if (wallpaper_node.HasMember("conditionMatchers")) { if (wallpaper_node["conditionMatchers"].IsArray()) { for (const auto& condition_matchers_node : diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h index 345d9dba1166..8c4abacc1436 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "base/check.h" #include "brave/components/challenge_bypass_ristretto/blinded_token.h" @@ -60,6 +61,8 @@ class BlindedToken { std::ostream& operator<<(std::ostream& os, const BlindedToken& blinded_token); +using BlindedTokenList = std::vector; + } // namespace brave_ads::cbr #endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_CHALLENGE_BYPASS_RISTRETTO_BLINDED_TOKEN_H_ diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token_util_unittest.cc b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token_util_unittest.cc index 038a5b92dc11..7b948e1a9bd3 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token_util_unittest.cc +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/blinded_token_util_unittest.cc @@ -18,10 +18,10 @@ namespace brave_ads { TEST(BraveAdsBlindedTokenUtilTest, BlindTokens) { // Arrange - const std::vector tokens = cbr::test::GetTokens(); + const cbr::TokenList tokens = cbr::test::GetTokens(); // Act - const std::vector blinded_tokens = BlindTokens(tokens); + const cbr::BlindedTokenList blinded_tokens = BlindTokens(tokens); // Assert EXPECT_EQ(cbr::test::GetBlindedTokens(), blinded_tokens); @@ -34,8 +34,7 @@ TEST(BraveAdsBlindedTokenUtilTToUnblindedTokensest, BlindEmptyTokens) { TEST(BraveAdsBlindedTokenUtilTest, BlindedTokensToRawBlindedTokens) { // Arrange - const std::vector blinded_tokens = - cbr::test::GetBlindedTokens(); + const cbr::BlindedTokenList blinded_tokens = cbr::test::GetBlindedTokens(); // Act const std::vector diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/challenge_bypass_ristretto_test.cc b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/challenge_bypass_ristretto_test.cc index 9b1b87c393cf..a1c7cf0439b5 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/challenge_bypass_ristretto_test.cc +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/challenge_bypass_ristretto_test.cc @@ -52,8 +52,8 @@ TEST(BraveAdsChallengeBypassRistrettoTest, ProveAndVerifyUnblindedToken) { const std::optional public_key = signing_key.GetPublicKey(); EXPECT_TRUE(public_key); - const std::vector blinded_tokens = {*blinded_token}; - const std::vector signed_tokens = {*signed_token}; + const cbr::BlindedTokenList blinded_tokens = {*blinded_token}; + const cbr::SignedTokenList signed_tokens = {*signed_token}; cbr::BatchDLEQProof batch_dleq_proof(blinded_tokens, signed_tokens, signing_key); EXPECT_TRUE(batch_dleq_proof.has_value()); @@ -61,8 +61,8 @@ TEST(BraveAdsChallengeBypassRistrettoTest, ProveAndVerifyUnblindedToken) { batch_dleq_proof.Verify(blinded_tokens, signed_tokens, *public_key)); // The client unblinds the signed tokens using the blinding scalar. - const std::vector tokens = {token}; - const std::optional> unblinded_tokens = + const cbr::TokenList tokens = {token}; + const std::optional unblinded_tokens = batch_dleq_proof.VerifyAndUnblind(tokens, blinded_tokens, signed_tokens, *public_key); EXPECT_TRUE(unblinded_tokens); diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h index 6dc3feaf5db5..43071c4202ad 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "base/check.h" #include "brave/components/challenge_bypass_ristretto/signed_token.h" @@ -56,6 +57,8 @@ class SignedToken { std::ostream& operator<<(std::ostream& os, const SignedToken& signed_token); +using SignedTokenList = std::vector; + } // namespace brave_ads::cbr #endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_CHALLENGE_BYPASS_RISTRETTO_SIGNED_TOKEN_H_ diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token_util_unittest.cc b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token_util_unittest.cc index 7ccf62aa3cb4..36d3a8dd955e 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token_util_unittest.cc +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/signed_token_util_unittest.cc @@ -16,8 +16,7 @@ namespace brave_ads { TEST(BraveAdsSignedTokenUtilTest, SignedTokensToRawSignedTokens) { // Arrange - const std::vector signed_tokens = - cbr::test::GetSignedTokens(); + const cbr::SignedTokenList signed_tokens = cbr::test::GetSignedTokens(); // Act const std::vector raw_signed_tokens = diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h index 2a6517eaa1d2..5e53434f322d 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "base/check.h" #include "brave/components/challenge_bypass_ristretto/token.h" @@ -60,6 +61,8 @@ class Token { std::ostream& operator<<(std::ostream& os, const Token& token); +using TokenList = std::vector; + } // namespace brave_ads::cbr #endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_CHALLENGE_BYPASS_RISTRETTO_TOKEN_H_ diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token_util_unittest.cc b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token_util_unittest.cc index 7a0a8b428944..fd08a2b47629 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token_util_unittest.cc +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/token_util_unittest.cc @@ -16,7 +16,7 @@ namespace brave_ads { TEST(BraveAdsTokenUtilTest, TokensToRawTokens) { // Arrange - const std::vector tokens = cbr::test::GetTokens(); + const cbr::TokenList tokens = cbr::test::GetTokens(); // Act const std::vector raw_tokens = diff --git a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h index 2ab2c39479b1..cb967b81eee0 100644 --- a/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h +++ b/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "base/check.h" #include "brave/components/challenge_bypass_ristretto/unblinded_token.h" @@ -68,6 +69,8 @@ class UnblindedToken { std::ostream& operator<<(std::ostream& os, const UnblindedToken& unblinded_token); +using UnblindedTokenList = std::vector; + } // namespace brave_ads::cbr #endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_CHALLENGE_BYPASS_RISTRETTO_UNBLINDED_TOKEN_H_ diff --git a/components/brave_ads/core/internal/history/ad_history_manager_unittest.cc b/components/brave_ads/core/internal/history/ad_history_manager_unittest.cc index 6988271e19ed..6a1054a6990b 100644 --- a/components/brave_ads/core/internal/history/ad_history_manager_unittest.cc +++ b/components/brave_ads/core/internal/history/ad_history_manager_unittest.cc @@ -8,6 +8,7 @@ #include "brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_info.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_builder.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_info.h" +#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.h" #include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h" @@ -24,7 +25,6 @@ #include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_info.h" #include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h" #include "brave/components/brave_ads/core/public/history/ad_history_item_info.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/eligible_ads/allocation/seen_ads_util_unittest.cc b/components/brave_ads/core/internal/serving/eligible_ads/allocation/seen_ads_util_unittest.cc index d432211db5d9..1f3e8f5066e4 100644 --- a/components/brave_ads/core/internal/serving/eligible_ads/allocation/seen_ads_util_unittest.cc +++ b/components/brave_ads/core/internal/serving/eligible_ads/allocation/seen_ads_util_unittest.cc @@ -5,11 +5,11 @@ #include "brave/components/brave_ads/core/internal/serving/eligible_ads/allocation/seen_ads_util.h" +#include "brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/time_test_util.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_builder.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h" #include "testing/gtest/include/gtest/gtest.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_day_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_day_permission_rule_unittest.cc index dcabbc9c02af..14cd75e85716 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_day_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_day_permission_rule_unittest.cc @@ -6,11 +6,11 @@ #include "brave/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_day_permission_rule.h" #include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_feature.h" +#include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_hour_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_hour_permission_rule_unittest.cc index e4c4e3053c83..b53d31623d52 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_hour_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_hour_permission_rule_unittest.cc @@ -6,11 +6,11 @@ #include "brave/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_hour_permission_rule.h" #include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_feature.h" +#include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_minimum_wait_time_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_minimum_wait_time_permission_rule_unittest.cc index d2ea0c1fa95e..f95272a54cbf 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_minimum_wait_time_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_minimum_wait_time_permission_rule_unittest.cc @@ -6,11 +6,11 @@ #include "brave/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_minimum_wait_time_permission_rule.h" #include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h" +#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_day_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_day_permission_rule_unittest.cc index efc0dc90be4f..80abce5d4af6 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_day_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_day_permission_rule_unittest.cc @@ -6,11 +6,11 @@ #include "brave/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_day_permission_rule.h" #include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h" +#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_hour_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_hour_permission_rule_unittest.cc index 37f7537caa24..e8d53d08e429 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_hour_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_hour_permission_rule_unittest.cc @@ -6,11 +6,11 @@ #include "brave/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_hour_permission_rule.h" #include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h" +#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_day_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_day_permission_rule_unittest.cc index 8ee4bd350b25..b8386cf62d21 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_day_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_day_permission_rule_unittest.cc @@ -5,12 +5,12 @@ #include "brave/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_day_permission_rule.h" +#include "brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_feature.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_hour_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_hour_permission_rule_unittest.cc index ce1d6f4cfcc0..1003779d793b 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_hour_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_hour_permission_rule_unittest.cc @@ -5,6 +5,7 @@ #include "brave/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_hour_permission_rule.h" +#include "brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/mock_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_builder.h" @@ -12,7 +13,6 @@ #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_feature.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/search_result_ads/search_result_ads_per_day_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/search_result_ads/search_result_ads_per_day_permission_rule_unittest.cc index 4a4cfea9186a..571fcee000bd 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/search_result_ads/search_result_ads_per_day_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/search_result_ads/search_result_ads_per_day_permission_rule_unittest.cc @@ -8,10 +8,10 @@ #include "base/test/scoped_feature_list.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_builder.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_info.h" +#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_feature.h" -#include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/permission_rules/search_result_ads/search_result_ads_per_hour_permission_rule_unittest.cc b/components/brave_ads/core/internal/serving/permission_rules/search_result_ads/search_result_ads_per_hour_permission_rule_unittest.cc index 0608b2b3032d..e7975520cbcf 100644 --- a/components/brave_ads/core/internal/serving/permission_rules/search_result_ads/search_result_ads_per_hour_permission_rule_unittest.cc +++ b/components/brave_ads/core/internal/serving/permission_rules/search_result_ads/search_result_ads_per_hour_permission_rule_unittest.cc @@ -8,11 +8,11 @@ #include "base/test/scoped_feature_list.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_builder.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_info.h" +#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" #include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_feature.h" -#include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util.cc b/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util.cc index 57d7316b9ad2..e71cd7552958 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util.cc +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/condition_matcher_util.cc @@ -21,11 +21,11 @@ namespace brave_ads { namespace { -constexpr char kOperatorPrefixPattern[] = "[?]:*"; -constexpr char kNotOperatorPrefix[] = "[!]:"; +constexpr char kPrefPathOperatorPrefixPattern[] = "[?]:*"; +constexpr char kPrefPathNotOperatorPrefix[] = "[!]:"; std::string MaybeStripOperatorPrefix(const std::string& pref_path) { - if (!base::MatchPattern(pref_path, kOperatorPrefixPattern)) { + if (!base::MatchPattern(pref_path, kPrefPathOperatorPrefixPattern)) { // Not an operator. return pref_path; } @@ -35,7 +35,7 @@ std::string MaybeStripOperatorPrefix(const std::string& pref_path) { } bool HasNotOperator(const std::string_view pref_path) { - return pref_path.starts_with(kNotOperatorPrefix); + return pref_path.starts_with(kPrefPathNotOperatorPrefix); } bool MatchCondition(const std::string_view value, diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc index a2c00bb25a32..c021283e94b9 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc @@ -18,6 +18,7 @@ namespace brave_ads { namespace { constexpr char kEqualOperatorConditionMatcherPrefix[] = "[T=]:"; +constexpr char kNotEqualOperatorConditionMatcherPrefix[] = "[T≠]:"; constexpr char kGreaterThanOperatorConditionMatcherPrefix[] = "[T>]:"; constexpr char kGreaterThanOrEqualOperatorConditionMatcherPrefix[] = "[T≥]:"; constexpr char kLessThanOperatorConditionMatcherPrefix[] = "[T<]:"; @@ -50,6 +51,10 @@ bool MatchEpochOperator(const std::string_view value, return time_delta->InDays() == days; } + if (condition.starts_with(kNotEqualOperatorConditionMatcherPrefix)) { + return time_delta->InDays() != days; + } + if (condition.starts_with(kGreaterThanOperatorConditionMatcherPrefix)) { return time_delta->InDays() > days; } diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util_unittest.cc b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util_unittest.cc index f786cc1afc76..78a8ffbf177b 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util_unittest.cc +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util_unittest.cc @@ -47,6 +47,27 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, DoNotMatchEqualOperator) { "[T=]:3")); // Event occurred 2 days ago. } +TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchNotEqualOperator) { + // Arrange + AdvanceClockTo(test::TimeFromUTCString("3 October 2024")); + + // Act & Assert + EXPECT_TRUE( + MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/, + "[T≠]:3")); // Event occurred 2 days ago. +} + +TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, + DoNotMatchNotEqualOperator) { + // Arrange + AdvanceClockTo(test::TimeFromUTCString("3 October 2024")); + + // Act & Assert + EXPECT_FALSE( + MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/, + "[T≠]:2")); // Event occurred 2 days ago. +} + TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchGreaterThanOperator) { // Arrange diff --git a/components/brave_ads/core/internal/tabs/tab_manager.cc b/components/brave_ads/core/internal/tabs/tab_manager.cc index 6b8a683c7846..39495651a3bf 100644 --- a/components/brave_ads/core/internal/tabs/tab_manager.cc +++ b/components/brave_ads/core/internal/tabs/tab_manager.cc @@ -101,28 +101,28 @@ void TabManager::RemoveForId(const int32_t tab_id) { } } -void TabManager::NotifyTabDidChangeFocus(const int32_t tab_id) const { +void TabManager::NotifyDidOpenNewTab(const TabInfo& tab) const { for (TabManagerObserver& observer : observers_) { - observer.OnTabDidChangeFocus(tab_id); + observer.OnDidOpenNewTab(tab); } } -void TabManager::NotifyTabDidChange(const TabInfo& tab) const { +void TabManager::NotifyTabDidLoad(const TabInfo& tab, + const int http_status_code) const { for (TabManagerObserver& observer : observers_) { - observer.OnTabDidChange(tab); + observer.OnTabDidLoad(tab, http_status_code); } } -void TabManager::NotifyTabDidLoad(const TabInfo& tab, - const int http_status_code) const { +void TabManager::NotifyTabDidChangeFocus(const int32_t tab_id) const { for (TabManagerObserver& observer : observers_) { - observer.OnTabDidLoad(tab, http_status_code); + observer.OnTabDidChangeFocus(tab_id); } } -void TabManager::NotifyDidOpenNewTab(const TabInfo& tab) const { +void TabManager::NotifyTabDidChange(const TabInfo& tab) const { for (TabManagerObserver& observer : observers_) { - observer.OnDidOpenNewTab(tab); + observer.OnTabDidChange(tab); } } diff --git a/components/brave_ads/core/internal/tabs/tab_manager_observer.h b/components/brave_ads/core/internal/tabs/tab_manager_observer.h index c180166b31db..7b66c43b0e90 100644 --- a/components/brave_ads/core/internal/tabs/tab_manager_observer.h +++ b/components/brave_ads/core/internal/tabs/tab_manager_observer.h @@ -19,18 +19,18 @@ struct TabInfo; class TabManagerObserver : public base::CheckedObserver { public: + // Invoked when a new `tab` is opened. + virtual void OnDidOpenNewTab(const TabInfo& tab) {} + + // Invoked when the `tab` has loaded. + virtual void OnTabDidLoad(const TabInfo& tab, const int http_status_code) {} + // Invoked when the tab specfied by `tab_id` changes focus. virtual void OnTabDidChangeFocus(const int32_t tab_id) {} // Invoked when the `tab` is updated. virtual void OnTabDidChange(const TabInfo& tab) {} - // Invoked when the `tab` has loaded. - virtual void OnTabDidLoad(const TabInfo& tab, const int http_status_code) {} - - // Invoked when a new `tab` is opened. - virtual void OnDidOpenNewTab(const TabInfo& tab) {} - // Invoked when the text content for the tab specified by `tab_id` did change. virtual void OnTextContentDidChange(const int32_t tab_id, const std::vector& redirect_chain, diff --git a/components/brave_ads/core/internal/tabs/tab_manager_observer_mock.h b/components/brave_ads/core/internal/tabs/tab_manager_observer_mock.h index d3e1ed49d25f..8b689054cedf 100644 --- a/components/brave_ads/core/internal/tabs/tab_manager_observer_mock.h +++ b/components/brave_ads/core/internal/tabs/tab_manager_observer_mock.h @@ -27,12 +27,16 @@ class TabManagerObserverMock : public TabManagerObserver { ~TabManagerObserverMock() override; + MOCK_METHOD(void, OnDidOpenNewTab, (const TabInfo& tab)); + + MOCK_METHOD(void, + OnTabDidLoad, + (const TabInfo& tab, const int http_status_code)); + MOCK_METHOD(void, OnTabDidChangeFocus, (const int32_t tab_id)); MOCK_METHOD(void, OnTabDidChange, (const TabInfo& tab)); - MOCK_METHOD(void, OnDidOpenNewTab, (const TabInfo& tab)); - MOCK_METHOD(void, OnTextContentDidChange, (const int32_t tab_id, 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 222ee6a16535..8fea8665983d 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 @@ -193,14 +193,14 @@ PurchaseIntentProcessor::MaybeGetFunnelForUrl(const GURL& url) const { return iter->second; } -void PurchaseIntentProcessor::OnTabDidChange(const TabInfo& tab) { +void PurchaseIntentProcessor::OnDidOpenNewTab(const TabInfo& tab) { CHECK(!tab.redirect_chain.empty()); const GURL& url = tab.redirect_chain.back(); MaybeProcess(tab.id, url); } -void PurchaseIntentProcessor::OnDidOpenNewTab(const TabInfo& tab) { +void PurchaseIntentProcessor::OnTabDidChange(const TabInfo& tab) { CHECK(!tab.redirect_chain.empty()); const GURL& url = tab.redirect_chain.back(); diff --git a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.h b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.h index d7bf6cd8b911..599d25ede7fd 100644 --- a/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.h +++ b/components/brave_ads/core/internal/targeting/behavioral/purchase_intent/purchase_intent_processor.h @@ -58,8 +58,8 @@ class PurchaseIntentProcessor final : public TabManagerObserver { const GURL& url) const; // TabManagerObserver: - void OnTabDidChange(const TabInfo& tab) override; void OnDidOpenNewTab(const TabInfo& tab) override; + void OnTabDidChange(const TabInfo& tab) override; void OnDidCloseTab(int32_t tab_id) override; std::map tabs_; diff --git a/components/brave_ads/core/internal/user_attention/user_activity/user_activity_manager.cc b/components/brave_ads/core/internal/user_attention/user_activity/user_activity_manager.cc index 7eb5fffbda91..16a570bee7c6 100644 --- a/components/brave_ads/core/internal/user_attention/user_activity/user_activity_manager.cc +++ b/components/brave_ads/core/internal/user_attention/user_activity/user_activity_manager.cc @@ -155,6 +155,10 @@ void UserActivityManager::OnBrowserDidEnterBackground() { RecordEvent(UserActivityEventType::kBrowserDidEnterBackground); } +void UserActivityManager::OnDidOpenNewTab(const TabInfo& /*tab*/) { + RecordEvent(UserActivityEventType::kOpenedNewTab); +} + void UserActivityManager::OnTabDidChangeFocus(const int32_t /*tab_id*/) { RecordEvent(UserActivityEventType::kTabChangedFocus); } @@ -163,10 +167,6 @@ void UserActivityManager::OnTabDidChange(const TabInfo& /*tab*/) { RecordEvent(UserActivityEventType::kTabDidChange); } -void UserActivityManager::OnDidOpenNewTab(const TabInfo& /*tab*/) { - RecordEvent(UserActivityEventType::kOpenedNewTab); -} - void UserActivityManager::OnDidCloseTab(const int32_t /*tab_id*/) { RecordEvent(UserActivityEventType::kClosedTab); } diff --git a/components/brave_ads/core/internal/user_attention/user_activity/user_activity_manager.h b/components/brave_ads/core/internal/user_attention/user_activity/user_activity_manager.h index 21e924c4533c..c4f0002f1172 100644 --- a/components/brave_ads/core/internal/user_attention/user_activity/user_activity_manager.h +++ b/components/brave_ads/core/internal/user_attention/user_activity/user_activity_manager.h @@ -58,9 +58,9 @@ class UserActivityManager final : public AdsClientNotifierObserver, void OnBrowserDidEnterBackground() override; // TabManagerObserver: + void OnDidOpenNewTab(const TabInfo& tab) override; void OnTabDidChangeFocus(int32_t tab_id) override; void OnTabDidChange(const TabInfo& tab) override; - void OnDidOpenNewTab(const TabInfo& tab) override; void OnDidCloseTab(int32_t tab_id) override; void OnTabDidStartPlayingMedia(int32_t tab_id) override; void OnTabDidStopPlayingMedia(int32_t tab_id) override; diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table_unittest.cc b/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table_unittest.cc index 26be3efafa8e..6aca2d623d15 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table_unittest.cc @@ -6,6 +6,8 @@ #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_events_database_table.h" #include "base/test/mock_callback.h" +#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" +#include "brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.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/conversions/creative_set_conversion_database_table_util.h" @@ -15,9 +17,7 @@ #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_builder.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" #include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" #include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h" -#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h" #include "brave/components/brave_ads/core/public/ads_client/ads_client_callback.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/inline_content_ads/inline_content_ad_event_handler_unittest.cc b/components/brave_ads/core/internal/user_engagement/ad_events/inline_content_ads/inline_content_ad_event_handler_unittest.cc index 8c0f6c548481..c52a2a356589 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/inline_content_ads/inline_content_ad_event_handler_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/ad_events/inline_content_ads/inline_content_ad_event_handler_unittest.cc @@ -7,11 +7,8 @@ #include "base/test/mock_callback.h" #include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" +#include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" -#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_info.h" -#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.h" -#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_util.h" -#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/inline_content_ads/inline_content_ad_event_handler_delegate_mock.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" @@ -21,17 +18,6 @@ namespace brave_ads { -namespace { - -InlineContentAdInfo BuildAndSaveAd() { - const CreativeInlineContentAdInfo creative_ad = - test::BuildCreativeInlineContentAd( - /*should_generate_random_uuids=*/false); - database::SaveCreativeInlineContentAds({creative_ad}); - return BuildInlineContentAd(creative_ad); -} - -} // namespace class BraveAdsInlineContentAdEventHandlerTest : public test::TestBase { protected: void SetUp() override { @@ -58,7 +44,8 @@ class BraveAdsInlineContentAdEventHandlerTest : public test::TestBase { TEST_F(BraveAdsInlineContentAdEventHandlerTest, FireServedEvent) { // Arrange - const InlineContentAdInfo ad = BuildAndSaveAd(); + const InlineContentAdInfo ad = + test::BuildAndSaveInlineContentAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnDidFireInlineContentAdServedEvent(ad)); @@ -70,7 +57,8 @@ TEST_F(BraveAdsInlineContentAdEventHandlerTest, FireServedEvent) { TEST_F(BraveAdsInlineContentAdEventHandlerTest, FireViewedEvent) { // Arrange - const InlineContentAdInfo ad = BuildAndSaveAd(); + const InlineContentAdInfo ad = + test::BuildAndSaveInlineContentAd(/*should_generate_random_uuids=*/false); test::RecordAdEvent(ad, mojom::ConfirmationType::kServedImpression); // Act & Assert @@ -84,7 +72,8 @@ TEST_F(BraveAdsInlineContentAdEventHandlerTest, FireViewedEvent) { TEST_F(BraveAdsInlineContentAdEventHandlerTest, DoNotFireViewedEventIfAdPlacementWasAlreadyViewed) { // Arrange - const InlineContentAdInfo ad = BuildAndSaveAd(); + const InlineContentAdInfo ad = + test::BuildAndSaveInlineContentAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression}); @@ -102,7 +91,8 @@ TEST_F(BraveAdsInlineContentAdEventHandlerTest, TEST_F(BraveAdsInlineContentAdEventHandlerTest, DoNotFireViewedEventIfAdPlacementWasNotServed) { // Arrange - const InlineContentAdInfo ad = BuildAndSaveAd(); + const InlineContentAdInfo ad = + test::BuildAndSaveInlineContentAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, @@ -117,7 +107,8 @@ TEST_F(BraveAdsInlineContentAdEventHandlerTest, TEST_F(BraveAdsInlineContentAdEventHandlerTest, FireClickedEvent) { // Arrange - const InlineContentAdInfo ad = BuildAndSaveAd(); + const InlineContentAdInfo ad = + test::BuildAndSaveInlineContentAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression}); @@ -131,7 +122,8 @@ TEST_F(BraveAdsInlineContentAdEventHandlerTest, FireClickedEvent) { TEST_F(BraveAdsInlineContentAdEventHandlerTest, DoNotFireClickedEventIfAdPlacementWasAlreadyClicked) { // Arrange - const InlineContentAdInfo ad = BuildAndSaveAd(); + const InlineContentAdInfo ad = + test::BuildAndSaveInlineContentAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression, mojom::ConfirmationType::kClicked}); @@ -148,7 +140,8 @@ TEST_F(BraveAdsInlineContentAdEventHandlerTest, TEST_F(BraveAdsInlineContentAdEventHandlerTest, DoNotFireClickedEventIfAdPlacementWasNotServed) { // Arrange - const InlineContentAdInfo ad = BuildAndSaveAd(); + const InlineContentAdInfo ad = + test::BuildAndSaveInlineContentAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnFailedToFireInlineContentAdEvent( @@ -188,7 +181,8 @@ TEST_F(BraveAdsInlineContentAdEventHandlerTest, TEST_F(BraveAdsInlineContentAdEventHandlerTest, DoNotFireEventForMissingCreativeInstanceId) { // Arrange - const InlineContentAdInfo ad = BuildAndSaveAd(); + const InlineContentAdInfo ad = + test::BuildAndSaveInlineContentAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_for_non_rewards_unittest.cc b/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_for_non_rewards_unittest.cc index 6a84cb76e9bf..5b96ef71658f 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_for_non_rewards_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_for_non_rewards_unittest.cc @@ -5,10 +5,8 @@ #include "base/test/mock_callback.h" #include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" +#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" -#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_info.h" -#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_test_util.h" -#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_util.h" #include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" #include "brave/components/brave_ads/core/internal/settings/settings_test_util.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" @@ -21,17 +19,6 @@ namespace brave_ads { -namespace { - -NewTabPageAdInfo BuildAndSaveAd() { - const CreativeNewTabPageAdInfo creative_ad = - test::BuildCreativeNewTabPageAd(/*should_generate_random_uuids=*/true); - database::SaveCreativeNewTabPageAds({creative_ad}); - return BuildNewTabPageAd(creative_ad); -} - -} // namespace - class BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest : public test::TestBase { protected: @@ -62,7 +49,8 @@ class BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, FireServedEvent) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnDidFireNewTabPageAdServedEvent(ad)); @@ -75,7 +63,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, FireViewedEvent) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); test::RecordAdEvent(ad, mojom::ConfirmationType::kServedImpression); // Act & Assert @@ -89,7 +78,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, DoNotFireViewedEventIfAdPlacementWasAlreadyViewed) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression}); @@ -107,7 +97,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, DoNotFireViewedEventIfAdPlacementWasNotServed) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, @@ -123,7 +114,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, FireClickedEvent) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression}); @@ -137,7 +129,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, DoNotFireClickedEventIfAdPlacementWasAlreadyClicked) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression, mojom::ConfirmationType::kClicked}); @@ -154,7 +147,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, DoNotFireClickedEventIfAdPlacementWasNotServed) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnFailedToFireNewTabPageAdEvent( @@ -194,7 +188,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerIfUserHasNotJoinedBraveRewardsTest, DoNotFireEventForMissingCreativeInstanceId) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_for_rewards_unittest.cc b/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_for_rewards_unittest.cc index 6f88c9130468..587ba5c71f75 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_for_rewards_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler_for_rewards_unittest.cc @@ -5,10 +5,8 @@ #include "base/test/mock_callback.h" #include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" +#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" -#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_info.h" -#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_test_util.h" -#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_util.h" #include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/new_tab_page_ads/new_tab_page_ad_event_handler.h" @@ -20,17 +18,6 @@ namespace brave_ads { -namespace { - -NewTabPageAdInfo BuildAndSaveAd() { - const CreativeNewTabPageAdInfo creative_ad = - test::BuildCreativeNewTabPageAd(/*should_generate_random_uuids=*/false); - database::SaveCreativeNewTabPageAds({creative_ad}); - return BuildNewTabPageAd(creative_ad); -} - -} // namespace - class BraveAdsNewTabPageAdEventHandlerForRewardsTest : public test::TestBase { protected: void SetUp() override { @@ -57,7 +44,8 @@ class BraveAdsNewTabPageAdEventHandlerForRewardsTest : public test::TestBase { TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, FireServedEvent) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnDidFireNewTabPageAdServedEvent(ad)); @@ -69,7 +57,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, FireServedEvent) { TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, FireViewedEvent) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); test::RecordAdEvent(ad, mojom::ConfirmationType::kServedImpression); // Act & Assert @@ -83,7 +72,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, FireViewedEvent) { TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, DoNotFireViewedEventIfAdPlacementWasAlreadyViewed) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression}); @@ -101,7 +91,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, DoNotFireViewedEventIfAdPlacementWasNotServed) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, @@ -116,7 +107,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, FireClickedEvent) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression}); @@ -130,7 +122,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, FireClickedEvent) { TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, DoNotFireClickedEventIfAdPlacementWasAlreadyClicked) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression, mojom::ConfirmationType::kClicked}); @@ -147,7 +140,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, DoNotFireClickedEventIfAdPlacementWasNotServed) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnFailedToFireNewTabPageAdEvent( @@ -187,7 +181,8 @@ TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, TEST_F(BraveAdsNewTabPageAdEventHandlerForRewardsTest, DoNotFireEventForMissingCreativeInstanceId) { // Arrange - const NewTabPageAdInfo ad = BuildAndSaveAd(); + const NewTabPageAdInfo ad = + test::BuildAndSaveNewTabPageAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/notification_ads/notification_ad_event_handler_unittest.cc b/components/brave_ads/core/internal/user_engagement/ad_events/notification_ads/notification_ad_event_handler_unittest.cc index ccc7759d7328..9776c9752fcc 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/notification_ads/notification_ad_event_handler_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/ad_events/notification_ads/notification_ad_event_handler_unittest.cc @@ -7,9 +7,8 @@ #include "base/test/mock_callback.h" #include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" +#include "brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" -#include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_info.h" -#include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_test_util.h" #include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_builder.h" #include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/notification_ads/notification_ad_event_handler_delegate_mock.h" @@ -20,18 +19,6 @@ namespace brave_ads { -namespace { - -NotificationAdInfo BuildAndSaveAd() { - const CreativeNotificationAdInfo creative_ad = - test::BuildCreativeNotificationAd(/*should_generate_random_uuids=*/false); - NotificationAdInfo ad = BuildNotificationAd(creative_ad); - NotificationAdManager::GetInstance().Add(ad); - return ad; -} - -} // namespace - class BraveAdsNotificationAdEventHandlerTest : public test::TestBase { protected: void SetUp() override { @@ -56,7 +43,8 @@ class BraveAdsNotificationAdEventHandlerTest : public test::TestBase { TEST_F(BraveAdsNotificationAdEventHandlerTest, FireServedEvent) { // Arrange - const NotificationAdInfo ad = BuildAndSaveAd(); + const NotificationAdInfo ad = + test::BuildAndSaveNotificationAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnDidFireNotificationAdServedEvent(ad)); @@ -67,7 +55,8 @@ TEST_F(BraveAdsNotificationAdEventHandlerTest, FireServedEvent) { TEST_F(BraveAdsNotificationAdEventHandlerTest, FireViewedEvent) { // Arrange - const NotificationAdInfo ad = BuildAndSaveAd(); + const NotificationAdInfo ad = + test::BuildAndSaveNotificationAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnDidFireNotificationAdViewedEvent(ad)); @@ -78,7 +67,8 @@ TEST_F(BraveAdsNotificationAdEventHandlerTest, FireViewedEvent) { TEST_F(BraveAdsNotificationAdEventHandlerTest, FireClickedEvent) { // Arrange - const NotificationAdInfo ad = BuildAndSaveAd(); + const NotificationAdInfo ad = + test::BuildAndSaveNotificationAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnDidFireNotificationAdClickedEvent(ad)); @@ -89,7 +79,8 @@ TEST_F(BraveAdsNotificationAdEventHandlerTest, FireClickedEvent) { TEST_F(BraveAdsNotificationAdEventHandlerTest, FireDismissedEvent) { // Arrange - const NotificationAdInfo ad = BuildAndSaveAd(); + const NotificationAdInfo ad = + test::BuildAndSaveNotificationAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnDidFireNotificationAdDismissedEvent(ad)); @@ -100,7 +91,8 @@ TEST_F(BraveAdsNotificationAdEventHandlerTest, FireDismissedEvent) { TEST_F(BraveAdsNotificationAdEventHandlerTest, FireTimedOutEvent) { // Arrange - const NotificationAdInfo ad = BuildAndSaveAd(); + const NotificationAdInfo ad = + test::BuildAndSaveNotificationAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnDidFireNotificationAdTimedOutEvent(ad)); @@ -112,7 +104,8 @@ TEST_F(BraveAdsNotificationAdEventHandlerTest, FireTimedOutEvent) { TEST_F(BraveAdsNotificationAdEventHandlerTest, DoNotFireEventIfMissingPlacementId) { // Arrange - const NotificationAdInfo ad = BuildAndSaveAd(); + const NotificationAdInfo ad = + test::BuildAndSaveNotificationAd(/*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc b/components/brave_ads/core/internal/user_engagement/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc index a5064f513730..5d65f6f21283 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/ad_events/promoted_content_ads/promoted_content_ad_event_handler_unittest.cc @@ -9,10 +9,8 @@ #include "brave/components/brave_ads/core/internal/ad_units/ad_test_constants.h" #include "brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_feature.h" #include "brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_info.h" +#include "brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" -#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_info.h" -#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_test_util.h" -#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_util.h" #include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/promoted_content_ad_builder.h" #include "brave/components/brave_ads/core/internal/serving/permission_rules/permission_rules_test_util.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h" @@ -23,18 +21,6 @@ namespace brave_ads { -namespace { - -PromotedContentAdInfo BuildAndSaveAd() { - const CreativePromotedContentAdInfo creative_ad = - test::BuildCreativePromotedContentAd( - /*should_generate_random_uuids=*/false); - database::SaveCreativePromotedContentAds({creative_ad}); - return BuildPromotedContentAd(creative_ad); -} - -} // namespace - class BraveAdsPromotedContentAdEventHandlerTest : public test::TestBase { protected: void SetUp() override { @@ -64,7 +50,8 @@ class BraveAdsPromotedContentAdEventHandlerTest : public test::TestBase { TEST_F(BraveAdsPromotedContentAdEventHandlerTest, FireViewedEvent) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); test::RecordAdEvent(ad, mojom::ConfirmationType::kServedImpression); // Act & Assert @@ -78,7 +65,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, FireViewedEvent) { TEST_F(BraveAdsPromotedContentAdEventHandlerTest, DoNotFireViewedEventIfAdPlacementWasAlreadyViewed) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression}); @@ -96,7 +84,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, TEST_F(BraveAdsPromotedContentAdEventHandlerTest, DoNotFireViewedEventIfAdPlacementWasNotServed) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, @@ -111,7 +100,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, TEST_F(BraveAdsPromotedContentAdEventHandlerTest, FireClickedEvent) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression}); @@ -125,7 +115,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, FireClickedEvent) { TEST_F(BraveAdsPromotedContentAdEventHandlerTest, DoNotFireClickedEventIfAdPlacementWasAlreadyClicked) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, {mojom::ConfirmationType::kServedImpression, mojom::ConfirmationType::kViewedImpression, mojom::ConfirmationType::kClicked}); @@ -142,7 +133,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, TEST_F(BraveAdsPromotedContentAdEventHandlerTest, DoNotFireClickedEventIfAdPlacementWasNotServed) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, OnFailedToFirePromotedContentAdEvent( @@ -182,7 +174,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, TEST_F(BraveAdsPromotedContentAdEventHandlerTest, DoNotFireEventForMissingCreativeInstanceId) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); // Act & Assert EXPECT_CALL(delegate_mock_, @@ -198,7 +191,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, TEST_F(BraveAdsPromotedContentAdEventHandlerTest, FireEventIfNotExceededAdsPerHourCap) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, mojom::ConfirmationType::kServedImpression, kMaximumPromotedContentAdsPerHour.Get() - 1); @@ -215,7 +209,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, TEST_F(BraveAdsPromotedContentAdEventHandlerTest, DoNotFireEventIfExceededAdsPerHourCap) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, mojom::ConfirmationType::kServedImpression, kMaximumPromotedContentAdsPerHour.Get()); @@ -235,7 +230,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, TEST_F(BraveAdsPromotedContentAdEventHandlerTest, FireEventIfNotExceededAdsPerDayCap) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, mojom::ConfirmationType::kServedImpression, kMaximumPromotedContentAdsPerDay.Get() - 1); @@ -252,7 +248,8 @@ TEST_F(BraveAdsPromotedContentAdEventHandlerTest, TEST_F(BraveAdsPromotedContentAdEventHandlerTest, DoNotFireEventIfExceededAdsPerDayCap) { // Arrange - const PromotedContentAdInfo ad = BuildAndSaveAd(); + const PromotedContentAdInfo ad = test::BuildAndSavePromotedContentAd( + /*should_generate_random_uuids=*/false); test::RecordAdEvents(ad, mojom::ConfirmationType::kServedImpression, kMaximumPromotedContentAdsPerDay.Get()); diff --git a/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util_for_rewards_unittest.cc b/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util_for_rewards_unittest.cc index 3e1a64273c25..7a5432ac7039 100644 --- a/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util_for_rewards_unittest.cc +++ b/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util_for_rewards_unittest.cc @@ -7,6 +7,7 @@ #include "base/test/scoped_feature_list.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_builder.h" #include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_info.h" +#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.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/conversions/creative_set_conversion_builder.h" @@ -15,7 +16,6 @@ #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/user_engagement/ad_events/ad_event_builder.h" #include "brave/components/brave_ads/core/internal/user_engagement/ad_events/search_result_ads/search_result_ad_event_handler_util.h" -#include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h" #include "brave/components/brave_ads/core/public/ads_feature.h" // npm run test -- brave_unit_tests --filter=BraveAds* diff --git a/components/brave_ads/core/public/BUILD.gn b/components/brave_ads/core/public/BUILD.gn index c7abb1d946d5..72c28166c234 100644 --- a/components/brave_ads/core/public/BUILD.gn +++ b/components/brave_ads/core/public/BUILD.gn @@ -10,21 +10,17 @@ source_set("headers") { "ad_units/ad_type.h", "ad_units/inline_content_ad/inline_content_ad_constants.h", "ad_units/inline_content_ad/inline_content_ad_info.h", - "ad_units/inline_content_ad/inline_content_ad_test_util.h", "ad_units/inline_content_ad/inline_content_ad_value_util.h", "ad_units/new_tab_page_ad/new_tab_page_ad_constants.h", "ad_units/new_tab_page_ad/new_tab_page_ad_info.h", - "ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h", "ad_units/new_tab_page_ad/new_tab_page_ad_value_util.h", "ad_units/new_tab_page_ad/new_tab_page_ad_wallpaper_focal_point_info.h", "ad_units/new_tab_page_ad/new_tab_page_ad_wallpaper_info.h", "ad_units/notification_ad/notification_ad_constants.h", "ad_units/notification_ad/notification_ad_feature.h", "ad_units/notification_ad/notification_ad_info.h", - "ad_units/notification_ad/notification_ad_test_util.h", "ad_units/notification_ad/notification_ad_value_util.h", "ad_units/search_result_ad/search_result_ad_feature.h", - "ad_units/search_result_ad/search_result_ad_test_util.h", "ads.h", "ads_callback.h", "ads_client/ads_client.h", diff --git a/components/brave_ads/core/public/ads.h b/components/brave_ads/core/public/ads.h index daa2d9492645..38ad5fbe184e 100644 --- a/components/brave_ads/core/public/ads.h +++ b/components/brave_ads/core/public/ads.h @@ -7,7 +7,6 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_ADS_H_ #include -#include #include #include "brave/components/brave_ads/browser/ads_service_callback.h" diff --git a/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h b/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h index e62f5d2cece7..2e93752f3e01 100644 --- a/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h +++ b/components/brave_ads/core/public/serving/targeting/condition_matcher/condition_matcher_util.h @@ -16,21 +16,15 @@ using ConditionMatcherMap = class PrefProviderInterface; +// Condition matchers must undergo a privacy review. +// // Matchers are one or more pref paths and conditions, using AND logic, that // must all be met for an ad to be served. Pref path keys should be separated by -// "|", where paths may include list indices (e.g., "list|1") or dictionary keys -// (e.g., "dict|key"). Paths can also be nested. Both Brave local state and -// profile prefs are supported. -// -// For non-Rewards users, condition matchers should be included in the -// "photo.json" file under the NTP (New Tab Page) sponsored images component, -// within "campaigns2", falling back to "campaigns", or the root "campaign" for -// backwards compatibility. -// -// For Rewards users, these matchers should be placed in the catalog under -// "wallpapers" with the "imageUrl" prefixed with "[SmartNTT]" for backwards -// compatibility, where legacy browsers will discard these wallpapers due to an -// invalid URL. +// "|", with the exception that registered pref paths must use a dotted path. +// Paths may include list indices (e.g., "list|1") or dictionary keys (e.g., +// "dict|key"). Paths can be nested. Both local state and profile prefs are +// supported. This process only occurs on the device and never leaves the +// device. // // If no condition matchers are present ads will always be shown, unless // frequency capped for Rewards users. If condition matchers are malformed or @@ -38,17 +32,31 @@ class PrefProviderInterface; // // Supported Condition Matchers: // -// 1. [epoch operator]:days Matcher: -// - Support operators: -// - 'T=': Equal -// - 'T>': Greater than -// - 'T≥': Greater than or equal to -// - 'T<': Less than -// - 'T≤': Less than or equal to -// - This matcher triggers an ad based on when an event occurred or will -// occur, using a timestamp (Unix or Windows epoch) stored at "prefPath". -// For instance, the example below will serve an ad only if the timestamp -// for "foo.bar" occurred more than 3 days ago: +// 1. [pref path operator] Matcher: +// - Supported operators: +// - [!]: Not equal +// - This matcher serves an ad if a "prefPath" does not exist. For example, +// the following condition matcher will serve an ad if the pref path +// "foo.bar" does not exist: +// +// "conditionMatchers": [ +// { +// "prefPath": "[!]:foo.bar" +// } +// ] +// +// 2. [epoch operator]:days Matcher: +// - Supported operators: +// - [T=]: Equal +// - [T≠]: Not equal +// - [T>]: Greater than +// - [T≥]: Greater than or equal to +// - [T<]: Less than +// - [T≤]: Less than or equal to +// - This matcher serves an ad based on when an event occurred or will occur, +// using a timestamp (Unix, Windows, or ISO 8601 format) stored at +// "prefPath". For example, the following condition matcher will serve an +// ad if the timestamp for "foo.bar" occurred more than 3 days ago: // // "conditionMatchers": [ // { @@ -57,17 +65,18 @@ class PrefProviderInterface; // } // ] // -// 2. [numerical operator]:number Matcher: -// - Support operators: -// - 'R=': Equal -// - 'R≠': Not equal -// - 'R>': Greater than -// - 'R≥': Greater than or equal to -// - 'R<': Less than -// - 'R≤': Less than or equal to -// - This matcher triggers an ad based on when a real number (integers or -// fractional) stored at "prefPath". For instance, the example below will -// serve an ad only if the value stored at "foo.bar" is not equal to 3: +// 3. [numerical operator]:number Matcher: +// - Supported operators: +// - [R=]: Equal +// - [R≠]: Not equal +// - [R>]: Greater than +// - [R≥]: Greater than or equal to +// - [R<]: Less than +// - [R≤]: Less than or equal to +// - This matcher serves an ad based on the real number (integers or +// fractional) stored at "prefPath". For example, the following condition +// matcher will serve an ad if the value stored at "foo.bar" is not equal +// to 3: // // "conditionMatchers": [ // { @@ -76,98 +85,115 @@ class PrefProviderInterface; // } // ] // -// 3. Regex Matcher: +// 4. Regex Matcher: // - Uses an RE2 regular expression to partially match values at "prefPath", // see https://github.com/google/re2/wiki/syntax. For example, the -// following will serve an ad if the value at "foo.bar" starts with "abc": +// following condition matcher will serve an ad if the value at "foo.bar" +// is either "fred" or "waldo": // // "conditionMatchers": [ // { -// "condition": "^abc", +// "condition": "^(fred|waldo)$", // "prefPath": "foo.bar" // } // ] // -// 4. Pattern Matcher: +// 5. Pattern Matcher: // - Supports wildcards "*" and "?". "*" matches zero or more characters, // while "?" matches zero or one character. To use these literally, escape -// them with "\". In the example below, an ad will be served only if the -// value at "foo.bar" matches the pattern "*baz?qux*": +// them with "\". For example, the following condition matcher will serve +// an ad if the value at "foo.bar" matches the pattern "*baz?qux*": // // "conditionMatchers": [ // { // "condition": "*baz?qux*", -// "prefPath": "foo.bar" +// "prefPath": "foo.bar" // } // ] // -// For example, the following condition matchers would only serve a new tab -// takeover ad if the default search provider is set to "Startpage", the user -// has less than 10 bookmarks, and the browser was installed between three and -// seven days ago: +// For example, the following condition matcher will serve an ad if the +// `brave.new_tab_page.show_brave_news` pref path does not exist, the browser +// was installed 3 or more days ago, the user has fewer than 7 bookmarks, the +// chosen search provider is Startpage, and both the brave://settings/languages +// preferred website language and the operating system language are Deutsch: // // "conditionMatchers": [ // { -// "condition": "*-538868000510", -// "prefPath": "default_search_provider.guid" +// "prefPath": "!brave.new_tab_page.show_brave_news" +// }, +// { +// "condition": "[T≥]:3", +// "prefPath": "uninstall_metrics.installation_date2" // }, // { -// "condition": "[R<]:10", +// "condition": "[R<]:7", // "prefPath": "p3a.logs_constellation_prep|Brave.Core.BookmarkCount|value" // }, // { -// "condition": "[T≥]:3", -// "prefPath": "uninstall_metrics.installation_date2" +// "condition": "de$", +// "prefPath": "intl.selected_languages" // }, // { -// "condition": "[T≤]:7", -// "prefPath": "uninstall_metrics.installation_date2" +// "condition": "*-538868000510", +// "prefPath": "default_search_provider.guid" +// }, +// { +// "condition": "de", +// "prefPath": "[virtual]:operating_system|locale|language" // } // ] // -// We support virtual prefs for values that are not stored in the profile or -// local state prefs. Virtual pref path keys should be prefixed with -// "[virtual]:". +// For values that are not stored in the local state or profile prefs you can +// use virtual prefs. Prefix virtual pref paths with "[virtual]:". // -// "[virtual]:browser|version" retrieves the browser version, e.g. "72.0.59.3". +// Supported virtual pref paths: // -// "[virtual]:browser|build_channel" retrieves the build channel of the browser, -// returning one of the following values: "stable", "beta", "dev", "nightly", or -// "unknown". +// 1. "[virtual]:browser|version" +// - Returning the browser version, e.g. "72.0.59.3". // -// "[virtual]:operating_system|locale|language" retrieves the operating system's -// language, e.g., "en", and "[virtual]:operating_system|locale|region" -// retrieves the operating system's region, e.g., "US". +// 2. "[virtual]:browser|build_channel" +// - Returning the build channel of the browser, returning one of the +// following values: "stable", "beta", "dev", "nightly", or "unknown". // -// "[virtual]:operating_system|name" retrieves the operating system, returning -// one of the following values: "Windows", "Mac OS X", "Linux", "Android", -// "iOS", or "Unknown". +// 3. "[virtual]:operating_system|locale|language" +// - Returning the operating system's language, e.g., "en". // -// "[virtual]:search_engine|default_name" retrieves the default search engine -// chosen during browser installation, returning one of the following values: -// "Brave", "Google", "Yandex", "Bing", "Daum", "네이버", "DuckDuckGo", "Qwant", -// "Startpage", or "Ecosia". For the most up-to-date list of possible default -// search engines, see `TemplateURLPrepopulateData::GetDefaultSearchEngine`. +// 4. "[virtual]:operating_system|locale|region" +// - Returning the operating system's region, e.g., "US". // -// "[virtual]:skus|environment|location|key" retrieves the value from either the -// production or staging environment, the "talk.brave.com", "vpn.brave.com", or -// "leo.brave.com" location, and the "created_at", "expires_at", "last_paid_at", -// or "status" key. Status returns one of the following values: `trial`, `beta`, -// `paid`, or `canceled`. For example, the following will serve an ad if the -// user has canceled their Brave VPN subscription: +// 5. "[virtual]:operating_system|name" +// - Returning the operating system, returning one of the following values: +// "Windows", "Mac OS X", "Linux", "Android", "iOS", or "Unknown". // -// "conditionMatchers": [ -// { -// "condition": "canceled", -// "prefPath": "[virtual]:skus|production|vpn.brave.com|status" -// } -// ] +// 6. "[virtual]:search_engine|default_name" +// - Returning the default search engine chosen during browser installation, +// returning one of the following values: "Brave", "Google", "Yandex", +// "Bing", "Daum", "네이버", "DuckDuckGo", "Qwant", "Startpage", or +// "Ecosia". For the most up-to-date list of possible default search +// engines, see `TemplateURLPrepopulateData::GetDefaultSearchEngine`. +// +// 7. "[virtual]:skus|environment|location|key" +// - Returning the SKU value from either the production or staging +// environment, for the given location, i.e., "vpn.brave.com", +// "search.brave.com", "leo.brave.com", or "talk.brave.com", and the +// "created_at", "expires_at", "last_paid_at", or "status" key. Status +// returns one of the following values: `trial`, `beta`, `paid`, or +// `canceled`. For example, the following condition matcher will serve an +// ad if the user has canceled their Brave VPN subscription: +// +// "conditionMatchers": [ +// { +// "condition": "canceled", +// "prefPath": "[virtual]:skus|production|vpn.brave.com|status" +// } +// ] // -// NOTE: To identify condition matchers, first create a copy of your pref files. -// Next, change a brave://setting or enable a feature, quit the browser and then -// compare the original and modified versions to determine which key/value pairs -// are required. Invalid or malformed condition matchers will be logged to the -// console, they are not logged to the Rewards log. +// NOTE: To identify condition matchers, first create a copy of your `Local +// State` and `Default/Preferences` files. Next, change a brave://setting or +// enable a feature, quit the browser and then compare the original and modified +// versions to determine which key/value pairs are required. Invalid or +// malformed condition matchers will be logged to the console, they are not +// logged to the Rewards log. bool MatchConditions(const PrefProviderInterface* pref_provider, const ConditionMatcherMap& condition_matchers); diff --git a/components/brave_ads/core/test/BUILD.gn b/components/brave_ads/core/test/BUILD.gn index 271ec942ca1c..18bff47e1691 100644 --- a/components/brave_ads/core/test/BUILD.gn +++ b/components/brave_ads/core/test/BUILD.gn @@ -162,11 +162,13 @@ source_set("brave_ads_unit_tests") { "//brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_info_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test.cc", "//brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.cc", + "//brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h", "//brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_value_util_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_feature_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_info_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test.cc", "//brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.cc", + "//brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h", "//brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_value_util_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_feature_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_for_mobile_test.cc", @@ -175,14 +177,18 @@ source_set("brave_ads_unit_tests") { "//brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_info_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test.cc", "//brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.cc", + "//brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h", "//brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_value_util_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_feature_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_info_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test.cc", + "//brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.cc", + "//brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.h", "//brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_feature_unittest.cc", "//brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_for_non_rewards_test.cc", "//brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_for_rewards_test.cc", "//brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.cc", + "//brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h", "//brave/components/brave_ads/core/internal/ads_client/ads_client_mock.cc", "//brave/components/brave_ads/core/internal/ads_client/ads_client_mock.h", "//brave/components/brave_ads/core/internal/ads_client/ads_client_notifier_for_testing.cc", diff --git a/components/ntp_background_images/browser/view_counter_service.cc b/components/ntp_background_images/browser/view_counter_service.cc index bffbb5b7930e..ec79259776bc 100644 --- a/components/ntp_background_images/browser/view_counter_service.cc +++ b/components/ntp_background_images/browser/view_counter_service.cc @@ -241,6 +241,11 @@ ViewCounterService::GetCurrentBrandedWallpaper() { std::optional ViewCounterService::GetConditionMatchers(const base::Value::Dict& dict) { + // For non-Rewards users, condition matchers should be included in the + // "photo.json" file under the NTP (New Tab Page) sponsored images component, + // within "campaigns2", falling back to "campaigns", or the root "campaign" + // for backwards compatibility. + const auto* const list = dict.FindList(kWallpaperConditionMatchersKey); if (!list || list->empty()) { return std::nullopt;