From 237d7592a9729e65eaf61de8265bf83535a18971 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Fri, 25 Oct 2024 11:18:22 -0500 Subject: [PATCH] [ads] Fixes earnings in rewards non-custodian state count towards earnings in rewards custodian state --- .../brave_ads/browser/ads_service_impl.cc | 15 ++++--- .../brave_ads/browser/ads_service_impl.h | 6 ++- components/brave_ads/core/internal/BUILD.gn | 1 - .../core/internal/account/account.cc | 5 --- .../brave_ads/core/internal/account/account.h | 7 +-- .../confirmations/confirmations_util.cc | 13 ------ .../confirmations/confirmations_util.h | 2 - .../confirmations_util_unittest.cc | 42 ------------------ .../internal/account/issuers/issuers_util.cc | 5 --- .../internal/account/issuers/issuers_util.h | 1 - .../account/user_rewards/user_rewards.cc | 34 --------------- .../account/user_rewards/user_rewards.h | 14 ------ .../user_rewards/user_rewards_delegate.h | 23 ---------- .../user_rewards_delegate_mock.cc | 14 ------ .../user_rewards/user_rewards_delegate_mock.h | 32 -------------- .../user_rewards/user_rewards_unittest.cc | 43 ------------------- .../account/user_rewards/user_rewards_util.cc | 8 ---- .../account/user_rewards/user_rewards_util.h | 2 - .../user_rewards_util_unittest.cc | 23 ---------- .../common/test/pref_registry_test_util.cc | 1 - .../core/internal/prefs/obsolete_pref_util.cc | 9 ++++ .../core/internal/prefs/pref_registry.cc | 2 - .../brave_ads/core/public/prefs/pref_names.h | 2 - .../browser/test/rewards_state_browsertest.cc | 13 ------ 24 files changed, 22 insertions(+), 295 deletions(-) delete mode 100644 components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate.h delete mode 100644 components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.cc delete mode 100644 components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.h diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index 22dc0ad93761..6eec71223176 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -515,7 +515,7 @@ void AdsServiceImpl::NotifyAdsServiceInitialized() const { } } -void AdsServiceImpl::ShutdownAndClearData() { +void AdsServiceImpl::ShutdownClearDataAndMaybeRestart() { ShutdownAdsService(); VLOG(6) << "Clearing ads data"; @@ -525,11 +525,12 @@ void AdsServiceImpl::ShutdownAndClearData() { file_task_runner_->PostTaskAndReplyWithResult( FROM_HERE, base::BindOnce(&DeletePathOnFileTaskRunner, ads_service_path_), - base::BindOnce(&AdsServiceImpl::ShutdownAndClearDataCallback, + base::BindOnce(&AdsServiceImpl::ShutdownClearDataAndMaybeRestartCallback, weak_ptr_factory_.GetWeakPtr())); } -void AdsServiceImpl::ShutdownAndClearDataCallback(const bool success) { +void AdsServiceImpl::ShutdownClearDataAndMaybeRestartCallback( + const bool success) { if (!success) { VLOG(0) << "Failed to clear ads data"; } else { @@ -1157,7 +1158,7 @@ void AdsServiceImpl::OnNotificationAdClicked(const std::string& placement_id) { void AdsServiceImpl::ClearData() { UMA_HISTOGRAM_BOOLEAN(kClearDataHistogramName, true); - ShutdownAndClearData(); + ShutdownClearDataAndMaybeRestart(); } void AdsServiceImpl::GetDiagnostics(GetDiagnosticsCallback callback) { @@ -1903,14 +1904,14 @@ void AdsServiceImpl::OnRewardsWalletCreated() { } void AdsServiceImpl::OnExternalWalletConnected() { - SetProfilePref(prefs::kShouldMigrateVerifiedRewardsUser, base::Value(true)); - ShowReminder(mojom::ReminderType::kExternalWalletConnected); + + ShutdownClearDataAndMaybeRestart(); } void AdsServiceImpl::OnCompleteReset(const bool success) { if (success) { - ShutdownAndClearData(); + ShutdownClearDataAndMaybeRestart(); } } diff --git a/components/brave_ads/browser/ads_service_impl.h b/components/brave_ads/browser/ads_service_impl.h index e7861cc1ecbb..c98ea93e41e7 100644 --- a/components/brave_ads/browser/ads_service_impl.h +++ b/components/brave_ads/browser/ads_service_impl.h @@ -140,8 +140,10 @@ class AdsServiceImpl final : public AdsService, void NotifyAdsServiceInitialized() const; - void ShutdownAndClearData(); - void ShutdownAndClearDataCallback(bool success); + void ShutdownClearDataAndMaybeRestart(); + void ShutdownClearDataAndMaybeRestartCallback(bool success); + + void OnExternalWalletConnectedCallback(bool success); void SetSysInfo(); void SetBuildChannel(); diff --git a/components/brave_ads/core/internal/BUILD.gn b/components/brave_ads/core/internal/BUILD.gn index 32a962023cc0..29fd853de9a4 100644 --- a/components/brave_ads/core/internal/BUILD.gn +++ b/components/brave_ads/core/internal/BUILD.gn @@ -189,7 +189,6 @@ static_library("internal") { "account/user_data/user_data_info.h", "account/user_rewards/user_rewards.cc", "account/user_rewards/user_rewards.h", - "account/user_rewards/user_rewards_delegate.h", "account/user_rewards/user_rewards_util.cc", "account/user_rewards/user_rewards_util.h", "account/utility/redeem_confirmation/non_reward/redeem_non_reward_confirmation.cc", diff --git a/components/brave_ads/core/internal/account/account.cc b/components/brave_ads/core/internal/account/account.cc index a5c94a6b8d96..0ef457cc5d26 100644 --- a/components/brave_ads/core/internal/account/account.cc +++ b/components/brave_ads/core/internal/account/account.cc @@ -227,7 +227,6 @@ void Account::MaybeInitializeUserRewards() { // destroyed. user_rewards_ = std::make_unique(*wallet_); - user_rewards_->SetDelegate(this); user_rewards_->FetchIssuers(); @@ -295,8 +294,4 @@ void Account::OnFailedToConfirm(const ConfirmationInfo& /*confirmation*/) { MaybeRefillConfirmationTokens(); } -void Account::OnDidMigrateVerifiedRewardsUser() { - InitializeConfirmations(); -} - } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/account.h b/components/brave_ads/core/internal/account/account.h index 7a1c32ee5b3b..5525d29ebbfa 100644 --- a/components/brave_ads/core/internal/account/account.h +++ b/components/brave_ads/core/internal/account/account.h @@ -16,7 +16,6 @@ #include "brave/components/brave_ads/core/internal/account/account_observer.h" #include "brave/components/brave_ads/core/internal/account/confirmations/confirmations_delegate.h" #include "brave/components/brave_ads/core/internal/account/user_rewards/user_rewards.h" -#include "brave/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate.h" #include "brave/components/brave_ads/core/internal/account/wallet/wallet_info.h" #include "brave/components/brave_ads/core/mojom/brave_ads.mojom-forward.h" #include "brave/components/brave_ads/core/public/ads_callback.h" @@ -28,8 +27,7 @@ class Confirmations; struct TransactionInfo; class Account final : public AdsClientNotifierObserver, - public ConfirmationDelegate, - public UserRewardsDelegate { + public ConfirmationDelegate { public: Account(); @@ -118,9 +116,6 @@ class Account final : public AdsClientNotifierObserver, void OnDidConfirm(const ConfirmationInfo& confirmation) override; void OnFailedToConfirm(const ConfirmationInfo& confirmation) override; - // UserRewardsDelegate: - void OnDidMigrateVerifiedRewardsUser() override; - base::ObserverList observers_; std::unique_ptr confirmations_; diff --git a/components/brave_ads/core/internal/account/confirmations/confirmations_util.cc b/components/brave_ads/core/internal/account/confirmations/confirmations_util.cc index 89dae3f3aca8..47e471b00ce1 100644 --- a/components/brave_ads/core/internal/account/confirmations/confirmations_util.cc +++ b/components/brave_ads/core/internal/account/confirmations/confirmations_util.cc @@ -9,14 +9,10 @@ #include #include "base/base64url.h" -#include "base/functional/callback_helpers.h" #include "base/json/json_reader.h" #include "brave/components/brave_ads/core/internal/account/confirmations/confirmation_info.h" #include "brave/components/brave_ads/core/internal/account/confirmations/payload/confirmation_payload_json_writer.h" -#include "brave/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.h" #include "brave/components/brave_ads/core/internal/account/confirmations/reward/reward_info.h" -#include "brave/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens_util.h" -#include "brave/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_util.h" #include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/unblinded_token.h" #include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/verification_key.h" #include "brave/components/brave_ads/core/internal/common/challenge_bypass_ristretto/verification_signature.h" @@ -87,13 +83,4 @@ bool IsValid(const ConfirmationInfo& confirmation) { return Verify(confirmation); } -void ResetTokens() { - database::table::ConfirmationQueue database_table; - database_table.DeleteAll(/*intentional*/ base::DoNothing()); - - RemoveAllConfirmationTokens(); - - RemoveAllPaymentTokens(); -} - } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/confirmations/confirmations_util.h b/components/brave_ads/core/internal/account/confirmations/confirmations_util.h index 1a9d84a1cb3b..d8e77c829574 100644 --- a/components/brave_ads/core/internal/account/confirmations/confirmations_util.h +++ b/components/brave_ads/core/internal/account/confirmations/confirmations_util.h @@ -12,8 +12,6 @@ struct ConfirmationInfo; [[nodiscard]] bool IsValid(const ConfirmationInfo& confirmation); -void ResetTokens(); - } // namespace brave_ads #endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_CONFIRMATIONS_CONFIRMATIONS_UTIL_H_ diff --git a/components/brave_ads/core/internal/account/confirmations/confirmations_util_unittest.cc b/components/brave_ads/core/internal/account/confirmations/confirmations_util_unittest.cc index a11c92b4c772..f668479d5380 100644 --- a/components/brave_ads/core/internal/account/confirmations/confirmations_util_unittest.cc +++ b/components/brave_ads/core/internal/account/confirmations/confirmations_util_unittest.cc @@ -7,7 +7,6 @@ #include -#include "base/test/mock_callback.h" #include "brave/components/brave_ads/core/internal/account/confirmations/confirmation_info.h" #include "brave/components/brave_ads/core/internal/account/confirmations/non_reward/non_reward_confirmation_test_util.h" #include "brave/components/brave_ads/core/internal/account/confirmations/queue/confirmation_queue_database_table.h" @@ -15,8 +14,6 @@ #include "brave/components/brave_ads/core/internal/account/confirmations/reward/reward_confirmation_test_util.h" #include "brave/components/brave_ads/core/internal/account/confirmations/reward/reward_confirmation_util.h" #include "brave/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens_test_util.h" -#include "brave/components/brave_ads/core/internal/account/tokens/confirmation_tokens/confirmation_tokens_util.h" -#include "brave/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_util.h" #include "brave/components/brave_ads/core/internal/account/tokens/token_generator_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" #include "brave/components/brave_ads/core/internal/settings/settings_test_util.h" @@ -63,43 +60,4 @@ TEST_F(BraveAdsConfirmationsUtilTest, IsConfirmationNotValid) { EXPECT_FALSE(IsValid(confirmation)); } -TEST_F(BraveAdsConfirmationsUtilTest, ResetTokens) { - // Arrange - test::MockTokenGenerator(/*count=*/1); - test::RefillConfirmationTokens(/*count=*/1); - - const std::optional confirmation = - test::BuildRewardConfirmation(/*should_generate_random_uuids=*/false); - ASSERT_TRUE(confirmation); - test::BuildAndSaveConfirmationQueueItems(*confirmation, /*count=*/1); - - // Act - ResetTokens(); - - // Assert - base::MockCallback callback; - EXPECT_CALL(callback, Run(/*success=*/true, - /*confirmation_queue_items=*/::testing::IsEmpty())); - confirmation_queue_database_table_.GetAll(callback.Get()); - - EXPECT_TRUE(ConfirmationTokensIsEmpty()); - - EXPECT_TRUE(PaymentTokensIsEmpty()); -} - -TEST_F(BraveAdsConfirmationsUtilTest, ResetIfNoTokens) { - // Act - ResetTokens(); - - // Assert - base::MockCallback callback; - EXPECT_CALL(callback, Run(/*success=*/true, - /*confirmation_queue_items=*/::testing::IsEmpty())); - confirmation_queue_database_table_.GetAll(callback.Get()); - - EXPECT_TRUE(ConfirmationTokensIsEmpty()); - - EXPECT_TRUE(PaymentTokensIsEmpty()); -} - } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/issuers/issuers_util.cc b/components/brave_ads/core/internal/account/issuers/issuers_util.cc index ffbcf87ccc91..8192ff506d7b 100644 --- a/components/brave_ads/core/internal/account/issuers/issuers_util.cc +++ b/components/brave_ads/core/internal/account/issuers/issuers_util.cc @@ -46,11 +46,6 @@ std::optional GetIssuers() { return issuers; } -void ResetIssuers() { - ClearProfilePref(prefs::kIssuerPing); - ClearProfilePref(prefs::kIssuers); -} - bool IsIssuersValid(const IssuersInfo& issuers) { return IsConfirmationTokenIssuerValid(issuers) && IsPaymentTokenIssuerValid(issuers); diff --git a/components/brave_ads/core/internal/account/issuers/issuers_util.h b/components/brave_ads/core/internal/account/issuers/issuers_util.h index 25649e386fda..078da6ef3160 100644 --- a/components/brave_ads/core/internal/account/issuers/issuers_util.h +++ b/components/brave_ads/core/internal/account/issuers/issuers_util.h @@ -14,7 +14,6 @@ struct IssuersInfo; void SetIssuers(const IssuersInfo& issuers); std::optional GetIssuers(); -void ResetIssuers(); bool IsIssuersValid(const IssuersInfo& issuers); diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards.cc b/components/brave_ads/core/internal/account/user_rewards/user_rewards.cc index 30b11dfe0524..94e3cc99ae12 100644 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards.cc +++ b/components/brave_ads/core/internal/account/user_rewards/user_rewards.cc @@ -9,7 +9,6 @@ #include "base/debug/dump_without_crashing.h" #include "base/functional/bind.h" -#include "brave/components/brave_ads/core/internal/account/confirmations/confirmations_util.h" #include "brave/components/brave_ads/core/internal/account/issuers/issuers_info.h" #include "brave/components/brave_ads/core/internal/account/issuers/issuers_util.h" #include "brave/components/brave_ads/core/internal/account/issuers/url_request/issuers_url_request.h" @@ -19,9 +18,7 @@ #include "brave/components/brave_ads/core/internal/ads_client/ads_client_util.h" #include "brave/components/brave_ads/core/internal/common/logging_util.h" #include "brave/components/brave_ads/core/internal/common/time/time_formatting_util.h" -#include "brave/components/brave_ads/core/internal/prefs/pref_util.h" #include "brave/components/brave_ads/core/public/ads_client/ads_client.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" namespace brave_ads { @@ -37,8 +34,6 @@ UserRewards::UserRewards(WalletInfo wallet) : wallet_(std::move(wallet)) { UserRewards::~UserRewards() { GetAdsClient()->RemoveObserver(this); - - delegate_ = nullptr; } void UserRewards::FetchIssuers() { @@ -55,39 +50,10 @@ void UserRewards::MaybeRedeemPaymentTokens() { /////////////////////////////////////////////////////////////////////////////// -void UserRewards::MaybeMigrateVerifiedRewardsUser() { - if (!ShouldMigrateVerifiedRewardsUser()) { - return; - } - - BLOG(1, "Migrate verified rewards user"); - - ResetTokens(); - - ResetIssuers(); - FetchIssuers(); - - SetProfileBooleanPref(prefs::kShouldMigrateVerifiedRewardsUser, false); - - NotifyDidMigrateVerifiedRewardsUser(); -} - -void UserRewards::NotifyDidMigrateVerifiedRewardsUser() const { - if (delegate_) { - delegate_->OnDidMigrateVerifiedRewardsUser(); - } -} - void UserRewards::OnNotifyDidSolveAdaptiveCaptcha() { MaybeRefillConfirmationTokens(); } -void UserRewards::OnNotifyPrefDidChange(const std::string& path) { - if (path == prefs::kShouldMigrateVerifiedRewardsUser) { - MaybeMigrateVerifiedRewardsUser(); - } -} - void UserRewards::OnDidFetchIssuers(const IssuersInfo& issuers) { if (!IsIssuersValid(issuers)) { return BLOG(0, "Invalid issuers"); diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards.h b/components/brave_ads/core/internal/account/user_rewards/user_rewards.h index 210ff1493ac8..d092a16ba586 100644 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards.h +++ b/components/brave_ads/core/internal/account/user_rewards/user_rewards.h @@ -8,12 +8,10 @@ #include -#include "base/memory/raw_ptr.h" #include "brave/components/brave_ads/core/internal/account/issuers/url_request/issuers_url_request.h" #include "brave/components/brave_ads/core/internal/account/issuers/url_request/issuers_url_request_delegate.h" #include "brave/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_info.h" #include "brave/components/brave_ads/core/internal/account/transactions/transactions_database_table.h" -#include "brave/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate.h" #include "brave/components/brave_ads/core/internal/account/utility/redeem_payment_tokens/redeem_payment_tokens.h" #include "brave/components/brave_ads/core/internal/account/utility/redeem_payment_tokens/redeem_payment_tokens_delegate.h" #include "brave/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens.h" @@ -40,11 +38,6 @@ class UserRewards final : public AdsClientNotifierObserver, ~UserRewards() override; - void SetDelegate(UserRewardsDelegate* delegate) { - CHECK_EQ(delegate_, nullptr); - delegate_ = delegate; - } - void FetchIssuers(); void MaybeRefillConfirmationTokens(); @@ -52,13 +45,8 @@ class UserRewards final : public AdsClientNotifierObserver, void MaybeRedeemPaymentTokens(); private: - void MaybeMigrateVerifiedRewardsUser(); - - void NotifyDidMigrateVerifiedRewardsUser() const; - // AdsClientNotifierObserver: void OnNotifyDidSolveAdaptiveCaptcha() override; - void OnNotifyPrefDidChange(const std::string& path) override; // IssuersUrlRequestDelegate: void OnDidFetchIssuers(const IssuersInfo& issuers) override; @@ -76,8 +64,6 @@ class UserRewards final : public AdsClientNotifierObserver, void OnCaptchaRequiredToRefillConfirmationTokens( const std::string& captcha_id) override; - raw_ptr delegate_ = nullptr; - IssuersUrlRequest issuers_url_request_; RefillConfirmationTokens refill_confirmation_tokens_; RedeemPaymentTokens redeem_payment_tokens_; diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate.h b/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate.h deleted file mode 100644 index 6013f11881ad..000000000000 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (c) 2023 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_USER_REWARDS_USER_REWARDS_DELEGATE_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_USER_REWARDS_USER_REWARDS_DELEGATE_H_ - -namespace brave_ads { - -class UserRewardsDelegate { - public: - // Invoked to tell the delegate that migration of the verified rewards user - // was successful. - virtual void OnDidMigrateVerifiedRewardsUser() {} - - protected: - virtual ~UserRewardsDelegate() = default; -}; - -} // namespace brave_ads - -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_USER_REWARDS_USER_REWARDS_DELEGATE_H_ diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.cc b/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.cc deleted file mode 100644 index 468d3ac2e52d..000000000000 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.cc +++ /dev/null @@ -1,14 +0,0 @@ -/* Copyright (c) 2023 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#include "brave/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.h" - -namespace brave_ads { - -UserRewardsDelegateMock::UserRewardsDelegateMock() = default; - -UserRewardsDelegateMock::~UserRewardsDelegateMock() = default; - -} // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.h b/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.h deleted file mode 100644 index c56573845421..000000000000 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (c) 2023 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_USER_REWARDS_USER_REWARDS_DELEGATE_MOCK_H_ -#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_USER_REWARDS_USER_REWARDS_DELEGATE_MOCK_H_ - -#include "brave/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace brave_ads { - -class UserRewardsDelegateMock : public UserRewardsDelegate { - public: - UserRewardsDelegateMock(); - - UserRewardsDelegateMock(const UserRewardsDelegateMock&) = delete; - UserRewardsDelegateMock& operator=(const UserRewardsDelegateMock&) = delete; - - UserRewardsDelegateMock(UserRewardsDelegateMock&&) noexcept = delete; - UserRewardsDelegateMock& operator=(UserRewardsDelegateMock&&) noexcept = - delete; - - ~UserRewardsDelegateMock() override; - - MOCK_METHOD(void, OnDidMigrateVerifiedRewardsUser, ()); -}; - -} // namespace brave_ads - -#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_ACCOUNT_USER_REWARDS_USER_REWARDS_DELEGATE_MOCK_H_ diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards_unittest.cc b/components/brave_ads/core/internal/account/user_rewards/user_rewards_unittest.cc index 5a117a4d146b..1eedfc438893 100644 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards_unittest.cc +++ b/components/brave_ads/core/internal/account/user_rewards/user_rewards_unittest.cc @@ -15,7 +15,6 @@ #include "brave/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_token_util.h" #include "brave/components/brave_ads/core/internal/account/tokens/payment_tokens/payment_tokens_test_util.h" #include "brave/components/brave_ads/core/internal/account/tokens/token_generator_test_util.h" -#include "brave/components/brave_ads/core/internal/account/user_rewards/user_rewards_delegate_mock.h" #include "brave/components/brave_ads/core/internal/account/utility/redeem_payment_tokens/redeem_payment_tokens_test_util.h" #include "brave/components/brave_ads/core/internal/account/utility/redeem_payment_tokens/url_request_builders/redeem_payment_tokens_url_request_builder_util.h" #include "brave/components/brave_ads/core/internal/account/utility/refill_confirmation_tokens/refill_confirmation_tokens_test_util.h" @@ -29,8 +28,6 @@ #include "brave/components/brave_ads/core/internal/common/test/profile_pref_value_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/prefs/pref_util.h" -#include "brave/components/brave_ads/core/internal/settings/settings_test_util.h" #include "brave/components/brave_ads/core/public/prefs/pref_names.h" #include "net/http/http_status_code.h" @@ -44,11 +41,9 @@ class BraveAdsUserRewardsTest : public AdsClientMock, public test::TestBase { test::TestBase::SetUp(); user_rewards_ = std::make_unique(test::Wallet()); - user_rewards_->SetDelegate(&delegate_mock_); } std::unique_ptr user_rewards_; - UserRewardsDelegateMock delegate_mock_; }; TEST_F(BraveAdsUserRewardsTest, FetchIssuers) { @@ -218,44 +213,6 @@ TEST_F(BraveAdsUserRewardsTest, RedeemPaymentTokens) { EXPECT_TRUE(PaymentTokensIsEmpty()); } -TEST_F(BraveAdsUserRewardsTest, MigrateVerifiedRewardsUser) { - // Arrange - test::BuildAndSetIssuers(); - - test::MockTokenGenerator(/*count=*/50); - - const test::URLResponseMap url_responses = { - {BuildIssuersUrlPath(), - {{net::HTTP_OK, test::BuildIssuersUrlResponseBody()}}}}; - test::MockUrlResponses(ads_client_mock_, url_responses); - - test::SetPaymentTokens(/*count=*/1); - - EXPECT_CALL(delegate_mock_, OnDidMigrateVerifiedRewardsUser); - - // Act - SetProfileBooleanPref(prefs::kShouldMigrateVerifiedRewardsUser, true); - - // Assert - EXPECT_EQ(0U, ConfirmationTokenCount()); - EXPECT_EQ(0U, PaymentTokenCount()); - EXPECT_FALSE(GetProfileBooleanPref(prefs::kShouldMigrateVerifiedRewardsUser)); - EXPECT_TRUE(HasIssuers()); -} - -TEST_F(BraveAdsUserRewardsTest, DoNotMigrateVerifiedRewardsUser) { - // Arrange - test::DisableBraveRewards(); - - EXPECT_CALL(delegate_mock_, OnDidMigrateVerifiedRewardsUser).Times(0); - - // Act - SetProfileBooleanPref(prefs::kShouldMigrateVerifiedRewardsUser, false); - - // Assert - EXPECT_FALSE(GetProfileBooleanPref(prefs::kShouldMigrateVerifiedRewardsUser)); -} - TEST_F(BraveAdsUserRewardsTest, RequireCaptchaToRefillConfirmationTokensIfCaptchaIdExists) { // Arrange diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards_util.cc b/components/brave_ads/core/internal/account/user_rewards/user_rewards_util.cc index 253de64f4d6b..2bb0e4119c54 100644 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards_util.cc +++ b/components/brave_ads/core/internal/account/user_rewards/user_rewards_util.cc @@ -8,17 +8,9 @@ #include "brave/components/brave_ads/core/internal/account/issuers/issuers_info.h" #include "brave/components/brave_ads/core/internal/account/issuers/issuers_util.h" #include "brave/components/brave_ads/core/internal/common/logging_util.h" -#include "brave/components/brave_ads/core/internal/prefs/pref_util.h" -#include "brave/components/brave_ads/core/internal/settings/settings.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" namespace brave_ads { -bool ShouldMigrateVerifiedRewardsUser() { - return UserHasJoinedBraveRewards() && - GetProfileBooleanPref(prefs::kShouldMigrateVerifiedRewardsUser); -} - void UpdateIssuers(const IssuersInfo& issuers) { if (!HasIssuersChanged(issuers)) { return BLOG(1, "Issuers already up to date"); diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards_util.h b/components/brave_ads/core/internal/account/user_rewards/user_rewards_util.h index cd39673b8bad..d4f96267aff6 100644 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards_util.h +++ b/components/brave_ads/core/internal/account/user_rewards/user_rewards_util.h @@ -10,8 +10,6 @@ namespace brave_ads { struct IssuersInfo; -bool ShouldMigrateVerifiedRewardsUser(); - void UpdateIssuers(const IssuersInfo& issuers); } // namespace brave_ads diff --git a/components/brave_ads/core/internal/account/user_rewards/user_rewards_util_unittest.cc b/components/brave_ads/core/internal/account/user_rewards/user_rewards_util_unittest.cc index 752a2865795a..02bb0d3a39ab 100644 --- a/components/brave_ads/core/internal/account/user_rewards/user_rewards_util_unittest.cc +++ b/components/brave_ads/core/internal/account/user_rewards/user_rewards_util_unittest.cc @@ -10,9 +10,7 @@ #include "brave/components/brave_ads/core/internal/account/issuers/issuers_util.h" #include "brave/components/brave_ads/core/internal/ads_client/ads_client_notifier_observer_mock.h" #include "brave/components/brave_ads/core/internal/ads_client/ads_client_util.h" -#include "brave/components/brave_ads/core/internal/common/test/profile_pref_value_test_util.h" #include "brave/components/brave_ads/core/internal/common/test/test_base.h" -#include "brave/components/brave_ads/core/internal/settings/settings_test_util.h" #include "brave/components/brave_ads/core/public/prefs/pref_names.h" // npm run test -- brave_unit_tests --filter=BraveAds @@ -37,27 +35,6 @@ class BraveAdsUserRewardsUtilTest : public AdsClientNotifierObserverMock, AdsClientNotifierObserverMock ads_client_notifier_observer_mock_; }; -TEST_F(BraveAdsUserRewardsUtilTest, ShouldMigrateVerifiedRewardsUser) { - // Arrange - test::SetProfileBooleanPrefValue(prefs::kShouldMigrateVerifiedRewardsUser, - true); - - // Act & Assert - EXPECT_TRUE(ShouldMigrateVerifiedRewardsUser()); -} - -TEST_F(BraveAdsUserRewardsUtilTest, - ShouldNotMigrateVerifiedRewardsUserIfBraveRewardsIsDisabled) { - // Arrange - test::DisableBraveRewards(); - - test::SetProfileBooleanPrefValue(prefs::kShouldMigrateVerifiedRewardsUser, - false); - - // Act & Assert - EXPECT_FALSE(ShouldMigrateVerifiedRewardsUser()); -} - TEST_F(BraveAdsUserRewardsUtilTest, UpdateIssuers) { // Arrange EXPECT_CALL(ads_client_notifier_observer_mock_, diff --git a/components/brave_ads/core/internal/common/test/pref_registry_test_util.cc b/components/brave_ads/core/internal/common/test/pref_registry_test_util.cc index 63b01fba7d7d..658deec1624a 100644 --- a/components/brave_ads/core/internal/common/test/pref_registry_test_util.cc +++ b/components/brave_ads/core/internal/common/test/pref_registry_test_util.cc @@ -59,7 +59,6 @@ void RegisterProfilePrefs() { RegisterProfileBooleanPref(prefs::kHasMigratedClientState, true); RegisterProfileBooleanPref(prefs::kHasMigratedConfirmationState, true); - RegisterProfileBooleanPref(prefs::kShouldMigrateVerifiedRewardsUser, false); RegisterProfileStringPref(prefs::kBrowserVersionNumber, ""); diff --git a/components/brave_ads/core/internal/prefs/obsolete_pref_util.cc b/components/brave_ads/core/internal/prefs/obsolete_pref_util.cc index 27fb5624ff97..8c12a5889a1e 100644 --- a/components/brave_ads/core/internal/prefs/obsolete_pref_util.cc +++ b/components/brave_ads/core/internal/prefs/obsolete_pref_util.cc @@ -29,6 +29,9 @@ constexpr char kHasMigratedNotificationState[] = constexpr char kHasMigratedRewardsState[] = "brave.brave_ads.migrated.rewards_state"; +constexpr char kShouldMigrateVerifiedRewardsUser[] = + "brave.brave_ads.rewards.verified_user.should_migrate"; + } // namespace void RegisterProfilePrefsForMigration(PrefRegistrySimple* const registry) { @@ -46,6 +49,9 @@ void RegisterProfilePrefsForMigration(PrefRegistrySimple* const registry) { registry->RegisterBooleanPref(kHasMigratedConversionState, false); registry->RegisterBooleanPref(kHasMigratedNotificationState, false); registry->RegisterBooleanPref(kHasMigratedRewardsState, false); + + // Added 10/2024. + registry->RegisterBooleanPref(kShouldMigrateVerifiedRewardsUser, false); } void MigrateObsoleteProfilePrefs(PrefService* const prefs) { @@ -61,6 +67,9 @@ void MigrateObsoleteProfilePrefs(PrefService* const prefs) { prefs->ClearPref(kHasMigratedConversionState); prefs->ClearPref(kHasMigratedNotificationState); prefs->ClearPref(kHasMigratedRewardsState); + + // Added 10/2024. + prefs->ClearPref(kShouldMigrateVerifiedRewardsUser); } } // namespace brave_ads diff --git a/components/brave_ads/core/internal/prefs/pref_registry.cc b/components/brave_ads/core/internal/prefs/pref_registry.cc index 1baeaf91a7a6..32d08ed5195f 100644 --- a/components/brave_ads/core/internal/prefs/pref_registry.cc +++ b/components/brave_ads/core/internal/prefs/pref_registry.cc @@ -50,8 +50,6 @@ void RegisterProfilePrefs(PrefRegistrySimple* const registry) { registry->RegisterBooleanPref(prefs::kHasMigratedClientState, false); registry->RegisterBooleanPref(prefs::kHasMigratedConfirmationState, false); - registry->RegisterBooleanPref(prefs::kShouldMigrateVerifiedRewardsUser, - false); registry->RegisterStringPref(prefs::kBrowserVersionNumber, ""); diff --git a/components/brave_ads/core/public/prefs/pref_names.h b/components/brave_ads/core/public/prefs/pref_names.h index e878b5f8a07b..79dbcb530cf0 100644 --- a/components/brave_ads/core/public/prefs/pref_names.h +++ b/components/brave_ads/core/public/prefs/pref_names.h @@ -51,8 +51,6 @@ inline constexpr char kHasMigratedClientState[] = "brave.brave_ads.state.has_migrated.client.v7"; inline constexpr char kHasMigratedConfirmationState[] = "brave.brave_ads.state.has_migrated.confirmations.v8"; -inline constexpr char kShouldMigrateVerifiedRewardsUser[] = - "brave.brave_ads.rewards.verified_user.should_migrate"; inline constexpr char kBrowserVersionNumber[] = "brave.brave_ads.browser_version_number"; diff --git a/components/brave_rewards/browser/test/rewards_state_browsertest.cc b/components/brave_rewards/browser/test/rewards_state_browsertest.cc index 3b74b2a40097..b298edcab149 100644 --- a/components/brave_rewards/browser/test/rewards_state_browsertest.cc +++ b/components/brave_rewards/browser/test/rewards_state_browsertest.cc @@ -20,7 +20,6 @@ #include "base/strings/stringprintf.h" #include "base/test/bind.h" #include "brave/browser/brave_rewards/rewards_service_factory.h" -#include "brave/components/brave_ads/core/public/prefs/pref_names.h" #include "brave/components/brave_rewards/browser/rewards_service_impl.h" #include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_network_util.h" #include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_response.h" @@ -996,18 +995,6 @@ IN_PROC_BROWSER_TEST_P_(V13, Paths) { ASSERT_TRUE(encrypted_wallet); profile_->GetPrefs()->SetString( "brave.rewards.wallets." + std::get<0>(GetParam()), *encrypted_wallet); - - test_util::StartProcess(rewards_service_); - - if (wallet_status == mojom::WalletStatus::kConnected) { - ASSERT_TRUE(profile_->GetPrefs()->HasPrefPath( - brave_ads::prefs::kShouldMigrateVerifiedRewardsUser)); - ASSERT_TRUE(profile_->GetPrefs()->GetBoolean( - brave_ads::prefs::kShouldMigrateVerifiedRewardsUser)); - } else { - ASSERT_FALSE(profile_->GetPrefs()->HasPrefPath( - brave_ads::prefs::kShouldMigrateVerifiedRewardsUser)); - } } IN_PROC_BROWSER_TEST_F(RewardsStateBrowserTest, V14EmptyWalletType) {