Skip to content

Commit

Permalink
Merge pull request #3927 from brave/pr3915_ac-check_0.73.x
Browse files Browse the repository at this point in the history
Fixes ac being processed when ac is off (uplift to 0.73.x)
  • Loading branch information
kjozwiak committed Nov 10, 2019
2 parents 47252a6 + dab97d0 commit 58a217c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
53 changes: 53 additions & 0 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 58a217c

Please sign in to comment.