Skip to content

Commit 375c64d

Browse files
committed
Add timestamp in autofill app state
fix brave#3438
1 parent 12391d9 commit 375c64d

File tree

6 files changed

+65
-45
lines changed

6 files changed

+65
-45
lines changed

app/sessionStore.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,14 @@ module.exports.defaultAppState = () => {
367367
ignoredWords: []
368368
},
369369
autofill: {
370-
addresses: [],
371-
creditCards: []
370+
addresses: {
371+
guid: [],
372+
timestamp: 0
373+
},
374+
creditCards: {
375+
guid: [],
376+
timestamp: 0
377+
}
372378
}
373379
}
374380
}

docs/state.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,18 @@ AppStore
177177
addedWords: Array<string> // List of words to add to the dictionary
178178
},
179179
autofill: {
180-
addresses: [{
181-
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
182-
}],
183-
creditCards: [{
184-
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
185-
}]
180+
addresses: {
181+
guid: [{
182+
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
183+
}],
184+
timestamp: number
185+
},
186+
creditCards: {
187+
guid: [{
188+
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
189+
}],
190+
timestamp: number
191+
}
186192
}
187193
}
188194
```

js/about/autofill.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class AddressItem extends ImmutableComponent {
2222
}
2323

2424
onDelete () {
25-
aboutActions.removeAutofillAddress(this.props.address.toJS())
25+
aboutActions.removeAutofillAddress(this.props.address)
2626
}
2727

2828
onEdit () {
29-
aboutActions.editAutofillAddress(this.props.address.toJS())
29+
aboutActions.editAutofillAddress(this.props.address)
3030
}
3131

3232
render () {
@@ -63,11 +63,11 @@ class CreditCardItem extends ImmutableComponent {
6363
}
6464

6565
onDelete () {
66-
aboutActions.removeAutofillCreditCard(this.props.creditCard.toJS())
66+
aboutActions.removeAutofillCreditCard(this.props.creditCard)
6767
}
6868

6969
onEdit () {
70-
aboutActions.editAutofillCreditCard(this.props.creditCard.toJS())
70+
aboutActions.editAutofillCreditCard(this.props.creditCard)
7171
}
7272

7373
render () {

js/components/frame.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ class Frame extends ImmutableComponent {
110110
} else if (location === 'about:autofill') {
111111
const partition = FrameStateUtil.getPartition(this.frame)
112112
if (this.props.autofillAddresses) {
113-
const addresses = this.props.autofillAddresses.toJS()
113+
const addresses = this.props.autofillAddresses.get('guid')
114114
let list = []
115-
for (let index in addresses) {
116-
const address = currentWindow.webContents.session.autofill.getProfile(addresses[index][partition])
115+
addresses.forEach((entry) => {
116+
const guid = entry.get(partition)
117+
const address = currentWindow.webContents.session.autofill.getProfile(guid)
117118
let addressDetail = {
118119
name: address.full_name,
119120
organization: address.company_name,
@@ -124,26 +125,27 @@ class Frame extends ImmutableComponent {
124125
country: address.country_code,
125126
phone: address.phone,
126127
email: address.email,
127-
guid: addresses[index]
128+
guid: entry.toJS()
128129
}
129130
list.push(addressDetail)
130-
}
131+
})
131132
this.webview.send(messages.AUTOFILL_ADDRESSES_UPDATED, list)
132133
}
133134
if (this.props.autofillCreditCards) {
134-
const creditCards = this.props.autofillCreditCards.toJS()
135+
const creditCards = this.props.autofillCreditCards.get('guid')
135136
let list = []
136-
for (let index in creditCards) {
137-
const creditCard = currentWindow.webContents.session.autofill.getCreditCard(creditCards[index][partition])
137+
creditCards.forEach((entry) => {
138+
const guid = entry.get(partition)
139+
const creditCard = currentWindow.webContents.session.autofill.getCreditCard(guid)
138140
let creditCardDetail = {
139141
name: creditCard.name,
140142
card: creditCard.card_number,
141143
month: creditCard.expiration_month,
142144
year: creditCard.expiration_year,
143-
guid: creditCards[index]
145+
guid: entry.toJS()
144146
}
145147
list.push(creditCardDetail)
146-
}
148+
})
147149
this.webview.send(messages.AUTOFILL_CREDIT_CARDS_UPDATED, list)
148150
}
149151
}

js/stores/appStore.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -549,55 +549,59 @@ const handleAppAction = (action) => {
549549
case AppConstants.APP_ADD_AUTOFILL_ADDRESS:
550550
{
551551
const Filtering = require('../../app/filtering')
552-
appState = appState.setIn(['autofill', 'addresses'],
553-
appState.getIn(['autofill', 'addresses']).filterNot((address) => {
552+
appState = appState.setIn(['autofill', 'addresses', 'guid'],
553+
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((address) => {
554554
return Immutable.is(address, action.originalDetail.get('guid'))
555555
}))
556556

557-
let addresses = appState.getIn(['autofill', 'addresses'])
557+
let addresses = appState.getIn(['autofill', 'addresses', 'guid'])
558558
const guid = Filtering.addAutofillAddress(action.detail.toJS())
559559
if (action.originalDetail.get('guid') !== undefined &&
560560
!Immutable.is(Immutable.fromJS(guid), action.originalDetail.get('guid'))) {
561561
Filtering.removeAutofillAddress(action.originalDetail.get('guid').toJS())
562562
}
563-
appState = appState.setIn(['autofill', 'addresses'], addresses.push(Immutable.fromJS(guid)))
563+
appState = appState.setIn(['autofill', 'addresses', 'guid'], addresses.push(Immutable.fromJS(guid)))
564+
appState = appState.setIn(['autofill', 'addresses', 'timestamp'], Immutable.fromJS(new Date().getTime()))
564565
break
565566
}
566567
case AppConstants.APP_REMOVE_AUTOFILL_ADDRESS:
567568
{
568569
const Filtering = require('../../app/filtering')
569-
appState = appState.setIn(['autofill', 'addresses'],
570-
appState.getIn(['autofill', 'addresses']).filterNot((address) => {
571-
return Immutable.is(address, Immutable.fromJS(action.detail.get('guid')))
570+
appState = appState.setIn(['autofill', 'addresses', 'guid'],
571+
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((address) => {
572+
return Immutable.is(address, action.detail.get('guid'))
572573
}))
573574
Filtering.removeAutofillAddress(action.detail.get('guid').toJS())
575+
appState = appState.setIn(['autofill', 'addresses', 'timestamp'], Immutable.fromJS(new Date().getTime()))
574576
break
575577
}
576578
case AppConstants.APP_ADD_AUTOFILL_CREDIT_CARD:
577579
{
578580
const Filtering = require('../../app/filtering')
579-
appState = appState.setIn(['autofill', 'creditCards'],
580-
appState.getIn(['autofill', 'creditCards']).filterNot((card) => {
581+
appState = appState.setIn(['autofill', 'creditCards', 'guid'],
582+
appState.getIn(['autofill', 'creditCards', 'guid']).filterNot((card) => {
581583
return Immutable.is(card, action.originalDetail.get('guid'))
582584
}))
583585

584-
let creditCards = appState.getIn(['autofill', 'creditCards'])
586+
let creditCards = appState.getIn(['autofill', 'creditCards', 'guid'])
585587
const guid = Filtering.addAutofillCreditCard(action.detail.toJS())
586588
if (action.originalDetail.get('guid') !== undefined &&
587589
!Immutable.is(Immutable.fromJS(guid), action.originalDetail.get('guid'))) {
588590
Filtering.removeAutofillCreditCard(action.originalDetail.get('guid').toJS())
589591
}
590-
appState = appState.setIn(['autofill', 'creditCards'], creditCards.push(Immutable.fromJS(guid)))
592+
appState = appState.setIn(['autofill', 'creditCards', 'guid'], creditCards.push(Immutable.fromJS(guid)))
593+
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], Immutable.fromJS(new Date().getTime()))
591594
break
592595
}
593596
case AppConstants.APP_REMOVE_AUTOFILL_CREDIT_CARD:
594597
{
595598
const Filtering = require('../../app/filtering')
596-
appState = appState.setIn(['autofill', 'creditCards'],
597-
appState.getIn(['autofill', 'creditCards']).filterNot((card) => {
599+
appState = appState.setIn(['autofill', 'creditCards', 'guid'],
600+
appState.getIn(['autofill', 'creditCards', 'guid']).filterNot((card) => {
598601
return Immutable.is(card, action.detail.get('guid'))
599602
}))
600603
Filtering.removeAutofillCreditCard(action.detail.get('guid').toJS())
604+
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], Immutable.fromJS(new Date().getTime()))
601605
break
602606
}
603607
default:

test/components/autofillTest.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('Autofill', function () {
6363
.click(saveAddressButton)
6464
.waitUntil(function () {
6565
return this.getAppState().then((val) => {
66-
return val.value.autofill.addresses.length === 1
66+
return val.value.autofill.addresses.guid.length === 1
6767
})
6868
})
6969
.tabByUrl(this.page1Url)
@@ -103,13 +103,15 @@ describe('Autofill', function () {
103103
.windowByUrl(Brave.browserWindowUrl)
104104
.waitForVisible(autofillAddressPanel)
105105
.click('#phone')
106+
.keys('\uE010') // send END key
106107
.keys('123')
107108
.click('#email')
109+
.keys('\uE010') // send END key
108110
.keys('mm')
109111
.click(saveAddressButton)
110112
.waitUntil(function () {
111113
return this.getAppState().then((val) => {
112-
return val.value.autofill.addresses.length === 1
114+
return val.value.autofill.addresses.guid.length === 1
113115
})
114116
})
115117
.tabByUrl(this.page1Url)
@@ -174,7 +176,7 @@ describe('Autofill', function () {
174176
.click(saveCreditCardButton)
175177
.waitUntil(function () {
176178
return this.getAppState().then((val) => {
177-
return val.value.autofill.creditCards.length === 1
179+
return val.value.autofill.creditCards.guid.length === 1
178180
})
179181
})
180182
.tabByUrl(this.page1Url)
@@ -211,15 +213,17 @@ describe('Autofill', function () {
211213
.windowByUrl(Brave.browserWindowUrl)
212214
.waitForVisible(autofillCreditCardPanel)
213215
.click('#nameOnCard')
216+
.keys('\uE010') // send END key
214217
.keys('123')
215218
.click('#creditCardNumber')
219+
.keys('\uE010') // send END key
216220
.keys('123')
217221
.selectByValue('.expMonthSelect', (expMonth + 1).toString())
218222
.selectByValue('.expYearSelect', (expYear + 1).toString())
219223
.click(saveCreditCardButton)
220224
.waitUntil(function () {
221225
return this.getAppState().then((val) => {
222-
return val.value.autofill.creditCards.length === 1
226+
return val.value.autofill.creditCards.guid.length === 1
223227
})
224228
})
225229
.tabByUrl(this.page1Url)
@@ -282,7 +286,7 @@ describe('Autofill', function () {
282286
.click(saveAddressButton)
283287
.waitUntil(function () {
284288
return this.getAppState().then((val) => {
285-
return val.value.autofill.addresses.length === 1
289+
return val.value.autofill.addresses.guid.length === 1
286290
})
287291
})
288292
.tabByUrl(this.page1Url)
@@ -305,11 +309,10 @@ describe('Autofill', function () {
305309
.click(saveAddressButton)
306310
.waitUntil(function () {
307311
return this.getAppState().then((val) => {
308-
return val.value.autofill.addresses.length === 1
312+
return val.value.autofill.addresses.guid.length === 1
309313
})
310314
})
311315
.tabByUrl(this.page1Url)
312-
.refresh()
313316
.waitForVisible('.autofillPage')
314317
.getText('.addressName').should.eventually.be.equal(name)
315318
.getText('.city').should.eventually.be.equal(city)
@@ -363,7 +366,7 @@ describe('Autofill', function () {
363366
.click(saveCreditCardButton)
364367
.waitUntil(function () {
365368
return this.getAppState().then((val) => {
366-
return val.value.autofill.creditCards.length === 1
369+
return val.value.autofill.creditCards.guid.length === 1
367370
})
368371
})
369372
.tabByUrl(this.page1Url)
@@ -386,11 +389,10 @@ describe('Autofill', function () {
386389
.click(saveCreditCardButton)
387390
.waitUntil(function () {
388391
return this.getAppState().then((val) => {
389-
return val.value.autofill.creditCards.length === 1
392+
return val.value.autofill.creditCards.guid.length === 1
390393
})
391394
})
392395
.tabByUrl(this.page1Url)
393-
.refresh()
394396
.waitForVisible('.autofillPage')
395397
.getText('.creditCardName').should.eventually.be.equal(cardName)
396398
.getText('.creditCardNumber').should.eventually.be.equal('***' + cardNumber.slice(-4))

0 commit comments

Comments
 (0)