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

Commit 3a846b1

Browse files
authored
Merge pull request #3706 from darkdh/3458
Add clearAutocompleteData & clearAutofillData to clearBrowsingDataPanel and clear on shutdown
2 parents 0a404dd + a04e037 commit 3a846b1

File tree

10 files changed

+243
-2
lines changed

10 files changed

+243
-2
lines changed

app/extensions/brave/locales/en-US/app.properties

+2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ downloadHistory=Download history
174174
cachedImagesAndFiles=Cached images and files
175175
savedPasswords=Saved passwords
176176
allSiteCookies=All site cookies
177+
autofillData=Autofill data
178+
autocompleteData=Autocomplete data
177179
clear=Clear
178180
clearDataWarning=Warning: Selected data, back to the day you installed Brave will be cleared and cannot be undone.
179181
clearBrowsingData=Clear browsing data

app/extensions/brave/locales/en-US/preferences.properties

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ browsingHistory=Browsing history
186186
downloadHistory=Download history
187187
cachedImagesAndFiles=Cached images and files
188188
allSiteCookies=All site cookies
189+
autofillData=Autofill data
190+
autocompleteData=Autocomplete data
189191
passwordsAndForms=Passwords and Forms
190192
tabSettings=Tab Settings
191193
clearBrowsingDataNow=Clear Browsing Data Now...

app/filtering.js

+14
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,17 @@ module.exports.removeAutofillCreditCard = (guid) => {
647647
}
648648
}
649649
}
650+
651+
module.exports.clearAutocompleteData = () => {
652+
for (let partition in registeredSessions) {
653+
let ses = registeredSessions[partition]
654+
ses.autofill.clearAutocompleteData()
655+
}
656+
}
657+
658+
module.exports.clearAutofillData = () => {
659+
for (let partition in registeredSessions) {
660+
let ses = registeredSessions[partition]
661+
ses.autofill.clearAutofillData()
662+
}
663+
}

app/sessionStore.js

+8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ module.exports.cleanPerWindowData = (perWindowData, isShutdown) => {
199199
if (clearHistory) {
200200
perWindowData.closedFrames = []
201201
}
202+
const clearAutocompleteData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA) === true
203+
if (clearAutocompleteData) {
204+
filtering.clearAutocompleteData()
205+
}
206+
const clearAutofillData = isShutdown && getSetting(settings.SHUTDOWN_CLEAR_AUTOFILL_DATA) === true
207+
if (clearAutofillData) {
208+
filtering.clearAutofillData()
209+
}
202210

203211
// Clean closed frame data before frames because the keys are re-ordered
204212
// and the new next key is calculated in windowStore.js based on

js/about/preferences.js

+2
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ class SecurityTab extends ImmutableComponent {
978978
<SettingCheckbox dataL10nId='downloadHistory' prefKey={settings.SHUTDOWN_CLEAR_DOWNLOADS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
979979
<SettingCheckbox dataL10nId='cachedImagesAndFiles' prefKey={settings.SHUTDOWN_CLEAR_CACHE} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
980980
<SettingCheckbox dataL10nId='allSiteCookies' prefKey={settings.SHUTDOWN_CLEAR_ALL_SITE_COOKIES} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
981+
<SettingCheckbox dataL10nId='autocompleteData' prefKey={settings.SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
982+
<SettingCheckbox dataL10nId='autofillData' prefKey={settings.SHUTDOWN_CLEAR_AUTOFILL_DATA} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
981983
<Button l10nId='clearBrowsingDataNow' className='primaryButton clearBrowsingDataButton' onClick={this.clearBrowsingDataNow} />
982984
</SettingsList>
983985
<div className='sectionTitle' data-l10n-id='passwordsAndForms' />

js/components/clearBrowsingDataPanel.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ClearBrowsingDataPanel extends ImmutableComponent {
1818
this.onToggleCachedImagesAndFiles = this.onToggleSetting.bind(this, 'cachedImagesAndFiles')
1919
this.onToggleSavedPasswords = this.onToggleSetting.bind(this, 'savedPasswords')
2020
this.onToggleAllSiteCookies = this.onToggleSetting.bind(this, 'allSiteCookies')
21+
this.onToggleAutocompleteData = this.onToggleSetting.bind(this, 'autocompleteData')
22+
this.onToggleAutofillData = this.onToggleSetting.bind(this, 'autofillData')
2123
this.onClear = this.onClear.bind(this)
2224
}
2325
onToggleSetting (setting, e) {
@@ -37,6 +39,8 @@ class ClearBrowsingDataPanel extends ImmutableComponent {
3739
<SwitchControl rightl10nId='cachedImagesAndFiles' checkedOn={this.props.clearBrowsingDataDetail.get('cachedImagesAndFiles')} onClick={this.onToggleCachedImagesAndFiles} />
3840
<SwitchControl rightl10nId='savedPasswords' checkedOn={this.props.clearBrowsingDataDetail.get('savedPasswords')} onClick={this.onToggleSavedPasswords} />
3941
<SwitchControl rightl10nId='allSiteCookies' checkedOn={this.props.clearBrowsingDataDetail.get('allSiteCookies')} onClick={this.onToggleAllSiteCookies} />
42+
<SwitchControl className='autocompleteDataSwitch' rightl10nId='autocompleteData' checkedOn={this.props.clearBrowsingDataDetail.get('autocompleteData')} onClick={this.onToggleAutocompleteData} />
43+
<SwitchControl className='autofillDataSwitch' rightl10nId='autofillData' checkedOn={this.props.clearBrowsingDataDetail.get('autofillData')} onClick={this.onToggleAutofillData} />
4044
</div>
4145
<div className='formSection clearBrowsingDataButtons'>
4246
<Button l10nId='cancel' className='secondaryAltButton' onClick={this.props.onHide} />

js/constants/appConfig.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ module.exports = {
119119
'shutdown.clear-history': false,
120120
'shutdown.clear-downloads': false,
121121
'shutdown.clear-cache': false,
122-
'shutdown.clear-all-site-cookies': false
122+
'shutdown.clear-all-site-cookies': false,
123+
'shutdown.clear-autocomplete-data': false,
124+
'shutdown.clear-autofill-data': false
123125
},
124126
defaultFavicon: 'img/empty_favicon.png',
125127
uaExceptionHosts: [

js/constants/settings.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const settings = {
3232
SHUTDOWN_CLEAR_DOWNLOADS: 'shutdown.clear-downloads',
3333
SHUTDOWN_CLEAR_CACHE: 'shutdown.clear-cache',
3434
SHUTDOWN_CLEAR_ALL_SITE_COOKIES: 'shutdown.clear-all-site-cookies',
35+
SHUTDOWN_CLEAR_AUTOCOMPLETE_DATA: 'shutdown.clear-autocomplete-data',
36+
SHUTDOWN_CLEAR_AUTOFILL_DATA: 'shutdown.clear-autofill-data',
3537
// Autofill
3638
AUTOFILL_ENABLED: 'privacy.autofill-enabled',
3739
// Security Tab: DEPRECATED but still required (for now)

js/stores/appStore.js

+8
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,14 @@ const handleAppAction = (action) => {
552552
const Filtering = require('../../app/filtering')
553553
Filtering.clearStorageData()
554554
}
555+
if (action.clearDataDetail.get('autocompleteData')) {
556+
const Filtering = require('../../app/filtering')
557+
Filtering.clearAutocompleteData()
558+
}
559+
if (action.clearDataDetail.get('autofillData')) {
560+
const Filtering = require('../../app/filtering')
561+
Filtering.clearAutofillData()
562+
}
555563
break
556564
case AppConstants.APP_ADD_AUTOFILL_ADDRESS:
557565
{

test/components/autofillTest.js

+198-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const Brave = require('../lib/brave')
44
const messages = require('../../js/constants/messages')
5-
const {urlInput, autofillAddressPanel, autofillCreditCardPanel} = require('../lib/selectors')
5+
const {urlInput, autofillAddressPanel, autofillCreditCardPanel, clearBrowsingDataButton, securityTab} = require('../lib/selectors')
66
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')
77

88
const addAddressButton = '.addAddressButton'
@@ -302,6 +302,151 @@ describe('Autofill', function () {
302302
})
303303
})
304304

305+
describe('clear autofill data', function () {
306+
Brave.beforeAll(this)
307+
before(function * () {
308+
yield setup(this.app.client)
309+
this.autofillPreferences = 'about:autofill'
310+
this.formfill = Brave.server.url('formfill.html')
311+
312+
yield this.app.client
313+
.tabByIndex(0)
314+
.loadUrl(this.autofillPreferences)
315+
.waitForVisible(addAddressButton)
316+
.click(addAddressButton)
317+
.windowByUrl(Brave.browserWindowUrl)
318+
.waitForVisible(autofillAddressPanel)
319+
.click('#nameOnAddress')
320+
.keys(name)
321+
.click('#organization')
322+
.keys(organization)
323+
.click('#streetAddress')
324+
.keys(streetAddress)
325+
.click('#city')
326+
.keys(city)
327+
.click('#state')
328+
.keys(state)
329+
.click('#postalCode')
330+
.keys(postalCode)
331+
.click('#country')
332+
.keys(country)
333+
.click('#phone')
334+
.keys(phone)
335+
.click('#email')
336+
.keys(email)
337+
.click(saveAddressButton)
338+
.waitUntil(function () {
339+
return this.getAppState().then((val) => {
340+
return val.value.autofill.addresses.guid.length === 1
341+
})
342+
})
343+
.tabByIndex(0)
344+
.loadUrl(this.autofillPreferences)
345+
.waitForVisible(addCreditCardButton)
346+
.click(addCreditCardButton)
347+
.windowByUrl(Brave.browserWindowUrl)
348+
.waitForVisible(autofillCreditCardPanel)
349+
.click('#nameOnCard')
350+
.keys(cardName)
351+
.click('#creditCardNumber')
352+
.keys(cardNumber)
353+
.selectByValue('.expMonthSelect', expMonth < 10 ? '0' + expMonth.toString() : expMonth.toString())
354+
.selectByValue('.expYearSelect', expYear.toString())
355+
.click(saveCreditCardButton)
356+
.waitUntil(function () {
357+
return this.getAppState().then((val) => {
358+
return val.value.autofill.creditCards.guid.length === 1
359+
})
360+
})
361+
.tabByIndex(0)
362+
.loadUrl(this.autofillPreferences)
363+
})
364+
it('adds an autofill address', function * () {
365+
yield this.app.client
366+
.waitForVisible('.autofillPage')
367+
.getText('.addressName').should.eventually.be.equal(name)
368+
.getText('.organization').should.eventually.be.equal(organization)
369+
.getText('.streetAddress').should.eventually.be.equal(streetAddress)
370+
.getText('.city').should.eventually.be.equal(city)
371+
.getText('.state').should.eventually.be.equal(state)
372+
.getText('.postalCode').should.eventually.be.equal(postalCode)
373+
.getText('.country').should.eventually.be.equal(country)
374+
.getText('.phone').should.eventually.be.equal(phone)
375+
.getText('.email').should.eventually.be.equal(email)
376+
})
377+
it('adds an autofill credit card', function * () {
378+
yield this.app.client
379+
.waitForVisible('.autofillPage')
380+
.getText('.creditCardName').should.eventually.be.equal(cardName)
381+
.getText('.creditCardNumber').should.eventually.be.equal('***' + cardNumber.slice(-4))
382+
.getText('.creditCardPExpirationDate').should.eventually.be.equal(
383+
(expMonth < 10 ? '0' + expMonth.toString() : expMonth.toString()) + '/' + expYear.toString())
384+
})
385+
it('autofills the address', function * () {
386+
yield this.app.client
387+
.tabByIndex(0)
388+
.loadUrl(this.formfill)
389+
.waitForVisible('<form>')
390+
.click('[name="04fullname"]')
391+
.click('[name="04fullname"]')
392+
.windowByUrl(Brave.browserWindowUrl)
393+
.waitForVisible('.contextMenuItemText')
394+
.click('.contextMenuItemText')
395+
.tabByUrl(this.formfill)
396+
.getValue('[name="04fullname"]').should.eventually.be.equal(name)
397+
.getValue('[name="23cellphon"]').should.eventually.be.equal(phone)
398+
.getValue('[name="24emailadr"]').should.eventually.be.equal(email)
399+
// TODO(bridiver) - this needs to check all fields
400+
})
401+
it('autofills the credit card', function * () {
402+
yield this.app.client
403+
.tabByIndex(0)
404+
.loadUrl(this.formfill)
405+
.waitForVisible('<form>')
406+
.click('[name="41ccnumber"]')
407+
.click('[name="41ccnumber"]')
408+
.windowByUrl(Brave.browserWindowUrl)
409+
.waitForVisible('.contextMenuItemText')
410+
.click('.contextMenuItemText')
411+
.tabByUrl(this.formfill)
412+
.getValue('[name="41ccnumber"]').should.eventually.be.equal(cardNumber)
413+
.getValue('[name="42ccexp_mm"]').should.eventually.be.equal(expMonth.toString())
414+
.getValue('[name="43ccexp_yy"]').should.eventually.be.equal(expYear.toString())
415+
})
416+
it('clear data now', function * () {
417+
yield this.app.client
418+
.tabByIndex(0)
419+
.loadUrl(getTargetAboutUrl('about:preferences'))
420+
.waitForVisible(securityTab)
421+
.click(securityTab)
422+
.waitForVisible(clearBrowsingDataButton)
423+
.click(clearBrowsingDataButton)
424+
.waitForBrowserWindow()
425+
.waitForVisible('.autofillDataSwitch')
426+
.click('.autofillDataSwitch .switchMiddle')
427+
.waitForVisible('.clearDataButton')
428+
.click('.clearDataButton')
429+
})
430+
it('does not autofill in regular tab', function * () {
431+
yield this.app.client
432+
.windowByUrl(Brave.browserWindowUrl)
433+
.ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill)
434+
.waitForUrl(this.formfill)
435+
.waitForVisible('<form>')
436+
.click('[name="04fullname"]')
437+
.click('[name="04fullname"]')
438+
.windowByUrl(Brave.browserWindowUrl)
439+
.waitForExist('contextMenuItemText', 500, true)
440+
.tabByIndex(0)
441+
.getValue('[name="04fullname"]').should.eventually.be.equal('')
442+
.click('[name="41ccnumber"]')
443+
.click('[name="41ccnumber"]')
444+
.waitForExist('contextMenuItemText', 500, true)
445+
.tabByIndex(0)
446+
.getValue('[name="41ccnumber"]').should.eventually.be.equal('')
447+
})
448+
})
449+
305450
describe('ad-hoc autofill', function () {
306451
describe('regular tab', function () {
307452
Brave.beforeAll(this)
@@ -419,5 +564,57 @@ describe('Autofill', function () {
419564
.getValue('[name="04fullname"]').should.eventually.be.equal('')
420565
})
421566
})
567+
describe('clear autocomplete data', function () {
568+
Brave.beforeAll(this)
569+
before(function * () {
570+
yield setup(this.app.client)
571+
this.formfill = Brave.server.url('formfill.html')
572+
yield this.app.client
573+
.tabByIndex(0)
574+
.loadUrl(this.formfill)
575+
.waitForVisible('<form>')
576+
.setValue('[name="04fullname"]', 'test')
577+
.click('#submit')
578+
})
579+
it('autofills in regular tab', function * () {
580+
yield this.app.client
581+
.tabByIndex(0)
582+
.waitForVisible('<form>')
583+
.click('[name="04fullname"]')
584+
.click('[name="04fullname"]')
585+
.windowByUrl(Brave.browserWindowUrl)
586+
.waitForVisible('.contextMenuItemText')
587+
.click('.contextMenuItemText')
588+
.tabByIndex(0)
589+
.getValue('[name="04fullname"]').should.eventually.be.equal('test')
590+
})
591+
it('clear data now', function * () {
592+
yield this.app.client
593+
.tabByIndex(0)
594+
.loadUrl(getTargetAboutUrl('about:preferences'))
595+
.waitForVisible(securityTab)
596+
.click(securityTab)
597+
.waitForVisible(clearBrowsingDataButton)
598+
.click(clearBrowsingDataButton)
599+
.waitForBrowserWindow()
600+
.waitForVisible('.autocompleteDataSwitch')
601+
.click('.autocompleteDataSwitch .switchMiddle')
602+
.waitForVisible('.clearDataButton')
603+
.click('.clearDataButton')
604+
})
605+
it('does not autofill in regular tab', function * () {
606+
yield this.app.client
607+
.windowByUrl(Brave.browserWindowUrl)
608+
.ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill)
609+
.waitForUrl(this.formfill)
610+
.waitForVisible('<form>')
611+
.click('[name="04fullname"]')
612+
.click('[name="04fullname"]')
613+
.windowByUrl(Brave.browserWindowUrl)
614+
.waitForExist('contextMenuItemText', 500, true)
615+
.tabByIndex(0)
616+
.getValue('[name="04fullname"]').should.eventually.be.equal('')
617+
})
618+
})
422619
})
423620
})

0 commit comments

Comments
 (0)