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

Add clearAutocompleteData & clearAutofillData to clearBrowsingDataPanel and clear on shutdown #3706

Merged
merged 1 commit into from
Sep 8, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ downloadHistory=Download history
cachedImagesAndFiles=Cached images and files
savedPasswords=Saved passwords
allSiteCookies=All site cookies
autofillData=Autofill data
autocompleteData=Autocomplete data
clear=Clear
clearDataWarning=Warning: Selected data, back to the day you installed Brave will be cleared and cannot be undone.
clearBrowsingData=Clear browsing data
Expand Down
2 changes: 2 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ browsingHistory=Browsing history
downloadHistory=Download history
cachedImagesAndFiles=Cached images and files
allSiteCookies=All site cookies
autofillData=Autofill data
autocompleteData=Autocomplete data
passwordsAndForms=Passwords and Forms
tabSettings=Tab Settings
clearBrowsingDataNow=Clear Browsing Data Now...
Expand Down
14 changes: 14 additions & 0 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,17 @@ module.exports.removeAutofillCreditCard = (guid) => {
}
}
}

module.exports.clearAutocompleteData = () => {
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
ses.autofill.clearAutocompleteData()
}
}

module.exports.clearAutofillData = () => {
for (let partition in registeredSessions) {
let ses = registeredSessions[partition]
ses.autofill.clearAutofillData()
}
}
8 changes: 8 additions & 0 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ module.exports.cleanPerWindowData = (perWindowData, isShutdown) => {
if (clearHistory) {
perWindowData.closedFrames = []
}
const clearAutocompleteData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA) === true
if (clearAutocompleteData) {
filtering.clearAutocompleteData()
}
const clearAutofillData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOFILL_DATA) === true
if (clearAutofillData) {
filtering.clearAutofillData()
}

// Clean closed frame data before frames because the keys are re-ordered
// and the new next key is calculated in windowStore.js based on
Expand Down
2 changes: 2 additions & 0 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,8 @@ class SecurityTab extends ImmutableComponent {
<SettingCheckbox dataL10nId='downloadHistory' prefKey={settings.SHUTDOWN_CLEAR_DOWNLOADS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='cachedImagesAndFiles' prefKey={settings.SHUTDOWN_CLEAR_CACHE} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='allSiteCookies' prefKey={settings.SHUTDOWN_CLEAR_ALL_SITE_COOKIES} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='autocompleteData' prefKey={settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='autofillData' prefKey={settings.SHUTDOWN_CLEAR_AUTOFILL_DATA} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<Button l10nId='clearBrowsingDataNow' className='primaryButton clearBrowsingDataButton' onClick={this.clearBrowsingDataNow} />
</SettingsList>
<div className='sectionTitle' data-l10n-id='passwordsAndForms' />
Expand Down
4 changes: 4 additions & 0 deletions js/components/clearBrowsingDataPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ClearBrowsingDataPanel extends ImmutableComponent {
this.onToggleCachedImagesAndFiles = this.onToggleSetting.bind(this, 'cachedImagesAndFiles')
this.onToggleSavedPasswords = this.onToggleSetting.bind(this, 'savedPasswords')
this.onToggleAllSiteCookies = this.onToggleSetting.bind(this, 'allSiteCookies')
this.onToggleAutocompleteData = this.onToggleSetting.bind(this, 'autocompleteData')
this.onToggleAutofillData = this.onToggleSetting.bind(this, 'autofillData')
this.onClear = this.onClear.bind(this)
}
onToggleSetting (setting, e) {
Expand All @@ -37,6 +39,8 @@ class ClearBrowsingDataPanel extends ImmutableComponent {
<SwitchControl rightl10nId='cachedImagesAndFiles' checkedOn={this.props.clearBrowsingDataDetail.get('cachedImagesAndFiles')} onClick={this.onToggleCachedImagesAndFiles} />
<SwitchControl rightl10nId='savedPasswords' checkedOn={this.props.clearBrowsingDataDetail.get('savedPasswords')} onClick={this.onToggleSavedPasswords} />
<SwitchControl rightl10nId='allSiteCookies' checkedOn={this.props.clearBrowsingDataDetail.get('allSiteCookies')} onClick={this.onToggleAllSiteCookies} />
<SwitchControl className='autocompleteDataSwitch' rightl10nId='autocompleteData' checkedOn={this.props.clearBrowsingDataDetail.get('autocompleteData')} onClick={this.onToggleAutocompleteData} />
<SwitchControl className='autofillDataSwitch' rightl10nId='autofillData' checkedOn={this.props.clearBrowsingDataDetail.get('autofillData')} onClick={this.onToggleAutofillData} />
</div>
<div className='formSection clearBrowsingDataButtons'>
<Button l10nId='cancel' className='secondaryAltButton' onClick={this.props.onHide} />
Expand Down
4 changes: 3 additions & 1 deletion js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ module.exports = {
'shutdown.clear-history': false,
'shutdown.clear-downloads': false,
'shutdown.clear-cache': false,
'shutdown.clear-all-site-cookies': false
'shutdown.clear-all-site-cookies': false,
'shutdown.clear-autocomplete-data': false,
'shutdown.clear-autofill-data': false
},
defaultFavicon: 'img/empty_favicon.png',
uaExceptionHosts: [
Expand Down
2 changes: 2 additions & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const settings = {
SHUTDOWN_CLEAR_DOWNLOADS: 'shutdown.clear-downloads',
SHUTDOWN_CLEAR_CACHE: 'shutdown.clear-cache',
SHUTDOWN_CLEAR_ALL_SITE_COOKIES: 'shutdown.clear-all-site-cookies',
SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA: 'shutdown.clear-autocomplete-data',
SHUTDOWN_CLEAR_AUTOFILL_DATA: 'shutdown.clear-autofill-data',
// Autofill
AUTOFILL_ENABLED: 'privacy.autofill-enabled',
// Security Tab: DEPRECATED but still required (for now)
Expand Down
8 changes: 8 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,14 @@ const handleAppAction = (action) => {
const Filtering = require('../../app/filtering')
Filtering.clearStorageData()
}
if (action.clearDataDetail.get('autocompleteData')) {
const Filtering = require('../../app/filtering')
Filtering.clearAutocompleteData()
}
if (action.clearDataDetail.get('autofillData')) {
const Filtering = require('../../app/filtering')
Filtering.clearAutofillData()
}
break
case AppConstants.APP_ADD_AUTOFILL_ADDRESS:
{
Expand Down
199 changes: 198 additions & 1 deletion test/components/autofillTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const Brave = require('../lib/brave')
const messages = require('../../js/constants/messages')
const {urlInput, autofillAddressPanel, autofillCreditCardPanel} = require('../lib/selectors')
const {urlInput, autofillAddressPanel, autofillCreditCardPanel, clearBrowsingDataButton, securityTab} = require('../lib/selectors')
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')

const addAddressButton = '.addAddressButton'
Expand Down Expand Up @@ -302,6 +302,151 @@ describe('Autofill', function () {
})
})

describe('clear autofill data', function () {
Brave.beforeAll(this)
before(function * () {
yield setup(this.app.client)
this.autofillPreferences = 'about:autofill'
this.formfill = Brave.server.url('formfill.html')

yield this.app.client
.tabByIndex(0)
.loadUrl(this.autofillPreferences)
.waitForVisible(addAddressButton)
.click(addAddressButton)
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(autofillAddressPanel)
.click('#nameOnAddress')
.keys(name)
.click('#organization')
.keys(organization)
.click('#streetAddress')
.keys(streetAddress)
.click('#city')
.keys(city)
.click('#state')
.keys(state)
.click('#postalCode')
.keys(postalCode)
.click('#country')
.keys(country)
.click('#phone')
.keys(phone)
.click('#email')
.keys(email)
.click(saveAddressButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.addresses.guid.length === 1
})
})
.tabByIndex(0)
.loadUrl(this.autofillPreferences)
.waitForVisible(addCreditCardButton)
.click(addCreditCardButton)
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(autofillCreditCardPanel)
.click('#nameOnCard')
.keys(cardName)
.click('#creditCardNumber')
.keys(cardNumber)
.selectByValue('.expMonthSelect', expMonth < 10 ? '0' + expMonth.toString() : expMonth.toString())
.selectByValue('.expYearSelect', expYear.toString())
.click(saveCreditCardButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.creditCards.guid.length === 1
})
})
.tabByIndex(0)
.loadUrl(this.autofillPreferences)
})
it('adds an autofill address', function * () {
yield this.app.client
.waitForVisible('.autofillPage')
.getText('.addressName').should.eventually.be.equal(name)
.getText('.organization').should.eventually.be.equal(organization)
.getText('.streetAddress').should.eventually.be.equal(streetAddress)
.getText('.city').should.eventually.be.equal(city)
.getText('.state').should.eventually.be.equal(state)
.getText('.postalCode').should.eventually.be.equal(postalCode)
.getText('.country').should.eventually.be.equal(country)
.getText('.phone').should.eventually.be.equal(phone)
.getText('.email').should.eventually.be.equal(email)
})
it('adds an autofill credit card', function * () {
yield this.app.client
.waitForVisible('.autofillPage')
.getText('.creditCardName').should.eventually.be.equal(cardName)
.getText('.creditCardNumber').should.eventually.be.equal('***' + cardNumber.slice(-4))
.getText('.creditCardPExpirationDate').should.eventually.be.equal(
(expMonth < 10 ? '0' + expMonth.toString() : expMonth.toString()) + '/' + expYear.toString())
})
it('autofills the address', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(this.formfill)
.waitForVisible('<form>')
.click('[name="04fullname"]')
.click('[name="04fullname"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible('.contextMenuItemText')
.click('.contextMenuItemText')
.tabByUrl(this.formfill)
.getValue('[name="04fullname"]').should.eventually.be.equal(name)
.getValue('[name="23cellphon"]').should.eventually.be.equal(phone)
.getValue('[name="24emailadr"]').should.eventually.be.equal(email)
// TODO(bridiver) - this needs to check all fields
})
it('autofills the credit card', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(this.formfill)
.waitForVisible('<form>')
.click('[name="41ccnumber"]')
.click('[name="41ccnumber"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible('.contextMenuItemText')
.click('.contextMenuItemText')
.tabByUrl(this.formfill)
.getValue('[name="41ccnumber"]').should.eventually.be.equal(cardNumber)
.getValue('[name="42ccexp_mm"]').should.eventually.be.equal(expMonth.toString())
.getValue('[name="43ccexp_yy"]').should.eventually.be.equal(expYear.toString())
})
it('clear data now', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(getTargetAboutUrl('about:preferences'))
.waitForVisible(securityTab)
.click(securityTab)
.waitForVisible(clearBrowsingDataButton)
.click(clearBrowsingDataButton)
.waitForBrowserWindow()
.waitForVisible('.autofillDataSwitch')
.click('.autofillDataSwitch .switchMiddle')
.waitForVisible('.clearDataButton')
.click('.clearDataButton')
})
it('does not autofill in regular tab', function * () {
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill)
.waitForUrl(this.formfill)
.waitForVisible('<form>')
.click('[name="04fullname"]')
.click('[name="04fullname"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('contextMenuItemText', 500, true)
.tabByIndex(0)
.getValue('[name="04fullname"]').should.eventually.be.equal('')
.click('[name="41ccnumber"]')
.click('[name="41ccnumber"]')
.waitForExist('contextMenuItemText', 500, true)
.tabByIndex(0)
.getValue('[name="41ccnumber"]').should.eventually.be.equal('')
})
})

describe('ad-hoc autofill', function () {
describe('regular tab', function () {
Brave.beforeAll(this)
Expand Down Expand Up @@ -419,5 +564,57 @@ describe('Autofill', function () {
.getValue('[name="04fullname"]').should.eventually.be.equal('')
})
})
describe('clear autocomplete data', function () {
Brave.beforeAll(this)
before(function * () {
yield setup(this.app.client)
this.formfill = Brave.server.url('formfill.html')
yield this.app.client
.tabByIndex(0)
.loadUrl(this.formfill)
.waitForVisible('<form>')
.setValue('[name="04fullname"]', 'test')
.click('#submit')
})
it('autofills in regular tab', function * () {
yield this.app.client
.tabByIndex(0)
.waitForVisible('<form>')
.click('[name="04fullname"]')
.click('[name="04fullname"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible('.contextMenuItemText')
.click('.contextMenuItemText')
.tabByIndex(0)
.getValue('[name="04fullname"]').should.eventually.be.equal('test')
})
it('clear data now', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(getTargetAboutUrl('about:preferences'))
.waitForVisible(securityTab)
.click(securityTab)
.waitForVisible(clearBrowsingDataButton)
.click(clearBrowsingDataButton)
.waitForBrowserWindow()
.waitForVisible('.autocompleteDataSwitch')
.click('.autocompleteDataSwitch .switchMiddle')
.waitForVisible('.clearDataButton')
.click('.clearDataButton')
})
it('does not autofill in regular tab', function * () {
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill)
.waitForUrl(this.formfill)
.waitForVisible('<form>')
.click('[name="04fullname"]')
.click('[name="04fullname"]')
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('contextMenuItemText', 500, true)
.tabByIndex(0)
.getValue('[name="04fullname"]').should.eventually.be.equal('')
})
})
})
})