diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index 1335dd4d78ce..71f704461a89 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -306,6 +306,7 @@ class BraveRewardsBrowserTest : *response = brave_test_resp::captcha_; } else if (URLMatches(url, RECONCILE_CONTRIBUTION, PREFIX_V2, SERVER_TYPES::LEDGER)) { + first_url_ac_called_ = true; *response = brave_test_resp::contribution_; } else if (URLMatches(url, REGISTER_VIEWING, PREFIX_V2, SERVER_TYPES::LEDGER)) { @@ -1268,6 +1269,7 @@ class BraveRewardsBrowserTest : double verified_wallet_ = false; const std::string external_wallet_address_ = "abe5f454-fedd-4ea9-9203-470ae7315bb3"; + bool first_url_ac_called_ = false; }; IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, RenderWelcome) { @@ -1750,6 +1752,57 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, AutoContribution) { rewards_service_->RemoveObserver(this); } +IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, AutoContributeWhenACOff) { + // Observe the Rewards service + rewards_service_->AddObserver(this); + + EnableRewards(); + + // Claim grant using panel + const bool use_panel = true; + ClaimGrant(use_panel); + + // Visit verified publisher + const bool verified = true; + VisitPublisher("duckduckgo.com", verified); + + // toggle auto contribute off + content::EvalJsResult toggleOffResult = EvalJs(contents(), + "let toggleClicked = false;" + "new Promise((resolve) => {" + "var count = 10;" + "var interval = setInterval(function() {" + " if (count == 0) {" + " clearInterval(interval);" + " resolve(false);" + " } else {" + " count -= 1;" + " }" + " if (document.querySelector(\"[data-test-id2='autoContribution']\")) {" + " if (!toggleClicked) {" + " toggleClicked = true;" + " document.querySelector(" + " \"[data-test-id2='autoContribution']\").click();" + " } else {" + " clearInterval(interval);" + " resolve(document.querySelector(" + " \"[data-test-id2='autoContribution']\")" + " .getAttribute(\"data-toggled\") === 'false');" + " }" + " }" + "}, 500);});", + content::EXECUTE_SCRIPT_DEFAULT_OPTIONS, + content::ISOLATED_WORLD_ID_CONTENT_END); + ASSERT_TRUE(toggleOffResult.ExtractBool()); + + // Trigger contribution process + rewards_service()->StartMonthlyContributionForTest(); + ASSERT_FALSE(first_url_ac_called_); + + // Stop observing the Rewards service + rewards_service_->RemoveObserver(this); +} + // #6 - Tip verified publisher IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, TipVerifiedPublisher) { // Observe the Rewards service diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc index 4a3311cb468b..5ce4198bfb42 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc @@ -223,11 +223,11 @@ void Contribution::ResetReconcileStamp() { } void Contribution::StartMonthlyContribution() { - BLOG(ledger_, ledger::LogLevel::LOG_INFO) << "Staring monthly contribution"; if (!ledger_->GetRewardsMainEnabled()) { ResetReconcileStamp(); return; } + BLOG(ledger_, ledger::LogLevel::LOG_INFO) << "Staring monthly contribution"; auto callback = std::bind(&Contribution::OnStartRecurringTips, this, @@ -250,6 +250,11 @@ bool Contribution::ShouldStartAutoContribute() { } void Contribution::StartAutoContribute(uint64_t reconcile_stamp) { + if (!ShouldStartAutoContribute()) { + return; + } + + BLOG(ledger_, ledger::LogLevel::LOG_INFO) << "Staring auto contribution"; auto filter = ledger_->CreateActivityFilter( "", ledger::ExcludeFilter::FILTER_ALL_EXCEPT_EXCLUDED,