From dab97d0153315396eaf8dae6175144b442c49530 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Fri, 8 Nov 2019 08:59:35 +0000 Subject: [PATCH] Uplift of #3915 (squashed) to dev --- .../browser/rewards_service_browsertest.cc | 53 +++++++++++++++++++ .../internal/contribution/contribution.cc | 7 ++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index 0c4cc7cb93ee..b425ec8831fb 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -361,6 +361,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)) { @@ -1559,6 +1560,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) { @@ -2061,6 +2063,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 f43963907a57..584a35572910 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 @@ -224,11 +224,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, @@ -251,6 +251,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,