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

Commit

Permalink
Merge pull request #7680 from NejcZdovc/hotfix/#7451-autoinclude
Browse files Browse the repository at this point in the history
Auto-include propagates correctly
  • Loading branch information
bsclifton authored Mar 20, 2017
2 parents d717669 + c8b88bb commit bee2993
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 8 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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"testsuite": "cross-env NODE_ENV=test mocha \"test/$TEST_DIR/**/*Test.js\"",
"unittest": "cross-env NODE_ENV=test mocha \"test/unit/**/*Test.js\"",
"unittest-cov": "node --harmony node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report html --report text -x \"test/unit/**/*Test.js\" -- \"test/unit/**/*Test.js\"",
"uitest": "cross-env NODE_ENV=test mocha \"test/about/**/*Test.js\" \"test/app/**/*Test.js\" \"test/components/**/*Test.js\" \"test/lib/**/*Test.js\"",
"update-pdfjs": "rm -r app/extensions/pdfjs/; cp -r ../pdf.js/build/chromium/ app/extensions/pdfjs/",
"update-psl": "./tools/updatepsl.sh",
"vagrant-destroy-linux": "VAGRANT_CWD=./test/vms/vagrant/ubuntu-14.04 vagrant destroy",
Expand Down
113 changes: 113 additions & 0 deletions test/about/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,118 @@ describe('Regular payment panel tests', function () {
.waitForEnabled(addFundsButton)
})
})

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

beforeEach(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, ledgerAPIWaitTimeout)
})

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"]')
.windowByUrl(Brave.browserWindowUrl)
.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
.windowByUrl(Brave.browserWindowUrl)
.changeSetting(settings.AUTO_SUGGEST_SITES, false)
.tabByIndex(0)
.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"]')
.windowByUrl(Brave.browserWindowUrl)
.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
.tabByIndex(0)
.loadUrl(site1)
.windowByUrl(Brave.browserWindowUrl)
.waitForSiteEntry(site1)
.tabByUrl(site1)
.windowByUrl(Brave.browserWindowUrl)
.changeSetting(settings.AUTO_SUGGEST_SITES, false)
.tabByIndex(0)
.loadUrl(site2)
.windowByUrl(Brave.browserWindowUrl)
.waitForSiteEntry(site2)
.tabByUrl(site2)
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible('[data-l10n-id="publisher"]')
.windowByUrl(Brave.browserWindowUrl)
.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 bee2993

Please sign in to comment.