Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Auto-include propagates correctly
Browse files Browse the repository at this point in the history
Resolves #7451

Auditors: @mrose17

Test Plan:
- Enable payments in settings
- Disable auto-include switch
- Visit brianbondy.com in a new tab, site is added in the list and is not included
  • Loading branch information
NejcZdovc committed Mar 19, 2017
1 parent 8b8cf36 commit d6c1bce
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 7 deletions.
19 changes: 16 additions & 3 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,14 @@ eventStore.addChangeListener(() => {
pattern = `https?://${publisher}`
initP = !synopsis.publishers[publisher]
synopsis.initPublisher(publisher)
if ((initP) && (getSetting(settings.AUTO_SUGGEST_SITES))) {
if (initP) {
excludeP(publisher, (unused, exclude) => {
appActions.changeSiteSetting(pattern, 'ledgerPayments', !exclude)
if (!getSetting(settings.AUTO_SUGGEST_SITES)) {
exclude = false
} else {
exclude = !exclude
}
appActions.changeSiteSetting(pattern, 'ledgerPayments', exclude)
updatePublisherInfo()
})
}
Expand Down Expand Up @@ -849,6 +854,9 @@ var enable = (paymentsEnabled) => {
})
updatePublisherInfo()

// change undefined include publishers to include publishers
appActions.enableUndefinedPublishers(synopsis.publishers)

fs.readFile(pathName(publisherPath), (err, data) => {
if (err) {
if (err.code !== 'ENOENT') console.log('publisherPath read error: ' + err.toString())
Expand Down Expand Up @@ -985,7 +993,12 @@ var stickyP = (publisher) => {
result = synopsis.publishers[publisher].options.stickyP
appActions.changeSiteSetting(pattern, 'ledgerPayments', result)
}
delete synopsis.publishers[publisher].options.stickyP

if (synopsis.publishers[publisher] &&
synopsis.publishers[publisher].options &&
synopsis.publishers[publisher].options.stickyP) {
delete synopsis.publishers[publisher].options.stickyP
}

return (result || false)
}
Expand Down
6 changes: 3 additions & 3 deletions app/renderer/components/preferences/payment/ledgerTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LedgerTable extends ImmutableComponent {
return result
}
}
return true
return getSetting(settings.AUTO_SUGGEST_SITES, this.props.settings)
}

shouldShow (synopsis) {
Expand Down Expand Up @@ -101,7 +101,7 @@ class LedgerTable extends ImmutableComponent {
const publisherURL = synopsis.get('publisherURL')
const percentage = synopsis.get('percentage')
const site = synopsis.get('site')
const defaultSiteSetting = true
const defaultAutoInclude = this.enabledForSite(synopsis)

return [
{
Expand Down Expand Up @@ -131,7 +131,7 @@ class LedgerTable extends ImmutableComponent {
{
html: <SiteSettingCheckbox small
hostPattern={this.getHostPattern(synopsis)}
defaultValue={defaultSiteSetting}
defaultValue={defaultAutoInclude}
prefKey='ledgerPayments'
siteSettings={this.props.siteSettings}
checked={this.enabledForSite(synopsis)} />,
Expand Down
11 changes: 11 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,17 @@ Open dialog for default download path setting



### enableUndefinedPublishers(publishers)

Change all undefined publishers in site settings to defined sites
also change all undefined ledgerPayments to value true

**Parameters**

**publishers**: `Object`, publishers from the synopsis




* * *

Expand Down
12 changes: 12 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,18 @@ const appActions = {
AppDispatcher.dispatch({
actionType: appConstants.APP_DOWNLOAD_DEFAULT_PATH
})
},

/**
* Change all undefined publishers in site settings to defined sites
* also change all undefined ledgerPayments to value true
* @param publishers {Object} publishers from the synopsis
*/
enableUndefinedPublishers: function (publishers) {
AppDispatcher.dispatch({
actionType: appConstants.APP_ENABLE_UNDEFINED_PUBLISHERS,
publishers
})
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ const appConstants = {
APP_TAB_MESSAGE_BOX_DISMISSED: _,
APP_TAB_MESSAGE_BOX_UPDATED: _,
APP_NAVIGATOR_HANDLER_REGISTERED: _,
APP_NAVIGATOR_HANDLER_UNREGISTERED: _
APP_NAVIGATOR_HANDLER_UNREGISTERED: _,
APP_ENABLE_UNDEFINED_PUBLISHERS: _
}

module.exports = mapValuesByKeys(appConstants)
15 changes: 15 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,21 @@ const handleAppAction = (action) => {
case appConstants.APP_HIDE_DOWNLOAD_DELETE_CONFIRMATION:
appState = appState.set('deleteConfirmationVisible', false)
break
case appConstants.APP_ENABLE_UNDEFINED_PUBLISHERS:
const sitesObject = appState.get('siteSettings')
Object.keys(action.publishers).map((item) => {
const pattern = `https?://${item}`
const siteSetting = sitesObject.get(pattern)
const result = (siteSetting) && (siteSetting.get('ledgerPayments'))

if (result === undefined) {
let newSiteSettings = siteSettings.mergeSiteSetting(appState.get('siteSettings'), pattern, 'ledgerPayments', true)
const syncObject = siteUtil.setObjectId(newSiteSettings.get(pattern))
newSiteSettings = newSiteSettings.set(pattern, syncObject)
appState = appState.set('siteSettings', newSiteSettings)
}
})
break
default:
}

Expand Down
105 changes: 105 additions & 0 deletions test/components/ledgerPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Brave = require('../lib/brave')
const {urlInput, advancedSettingsButton, addFundsButton, paymentsWelcomePage, paymentsTab, walletSwitch, siteSettingItem, ledgerTable} = require('../lib/selectors')
const assert = require('assert')
const settings = require('../../js/constants/settings')

const prefsUrl = 'about:preferences'
const ledgerAPIWaitTimeout = 20000
Expand Down Expand Up @@ -113,6 +114,110 @@ describe('Regular payment panel tests', function () {
.waitForEnabled(addFundsButton)
})
})

describe('auto include', function () {
Brave.beforeAll(this)

before(function * () {
yield setup(this.app.client)
yield this.app.client
.changeSetting(settings.AUTO_SUGGEST_SITES, true)
.tabByIndex(0)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.waitForVisible(walletSwitch)
.click(walletSwitch)
.waitForEnabled(addFundsButton)
})

it('site is added automatically', function * () {
const site1 = 'http://example.com/'
const site2 = 'https://www.eff.org/'
yield this.app.client
.loadUrl(site1)
.windowByUrl(Brave.browserWindowUrl)
.waitForSiteEntry(site1)
.tabByUrl(site1)
.loadUrl(site2)
.windowByUrl(Brave.browserWindowUrl)
.waitForSiteEntry(site2)
.tabByUrl(site2)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible('[data-l10n-id="publisher"]')
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.siteSettings['https?://example.com'].ledgerPayments === true
})
})
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.siteSettings['https?://eff.org'].ledgerPayments === true
})
})
})

it('site is not added automatically', function * () {
const site1 = 'http://example.com/'
const site2 = 'https://www.eff.org/'
yield this.app.client
.changeSetting(settings.AUTO_SUGGEST_SITES, false)
.loadUrl(site1)
.windowByUrl(Brave.browserWindowUrl)
.waitForSiteEntry(site1)
.tabByUrl(site1)
.loadUrl(site2)
.windowByUrl(Brave.browserWindowUrl)
.waitForSiteEntry(site2)
.tabByUrl(site2)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible('[data-l10n-id="publisher"]')
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.siteSettings['https?://example.com'].ledgerPayments === false
})
})
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.siteSettings['https?://eff.org'].ledgerPayments === false
})
})
})

it('first site included, second site excluded', function * () {
const site1 = 'http://example.com/'
const site2 = 'https://www.eff.org/'
yield this.app.client
.loadUrl(site1)
.windowByUrl(Brave.browserWindowUrl)
.waitForSiteEntry(site1)
.tabByUrl(site1)
.changeSetting(settings.AUTO_SUGGEST_SITES, false)
.loadUrl(site2)
.windowByUrl(Brave.browserWindowUrl)
.waitForSiteEntry(site2)
.tabByUrl(site2)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible('[data-l10n-id="publisher"]')
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.siteSettings['https?://example.com'].ledgerPayments === true
})
})
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.siteSettings['https?://eff.org'].ledgerPayments === false
})
})
})
})
})

describe('synopsis', function () {
Expand Down

0 comments on commit d6c1bce

Please sign in to comment.