Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ac being processed when ac is off (uplift to 0.71.x) #3929

Merged
merged 1 commit into from Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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,
Expand All @@ -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,
Expand Down