Skip to content

Commit

Permalink
Add timestamp in autofill app state
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Aug 26, 2016
1 parent 12391d9 commit 375c64d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 45 deletions.
10 changes: 8 additions & 2 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,14 @@ module.exports.defaultAppState = () => {
ignoredWords: []
},
autofill: {
addresses: [],
creditCards: []
addresses: {
guid: [],
timestamp: 0
},
creditCards: {
guid: [],
timestamp: 0
}
}
}
}
18 changes: 12 additions & 6 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,18 @@ AppStore
addedWords: Array<string> // List of words to add to the dictionary
},
autofill: {
addresses: [{
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}],
creditCards: [{
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}]
addresses: {
guid: [{
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}],
timestamp: number
},
creditCards: {
guid: [{
Object.<string, <string>> // map of (partition, id) used to access the autofill entry in database
}],
timestamp: number
}
}
}
```
Expand Down
8 changes: 4 additions & 4 deletions js/about/autofill.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class AddressItem extends ImmutableComponent {
}

onDelete () {
aboutActions.removeAutofillAddress(this.props.address.toJS())
aboutActions.removeAutofillAddress(this.props.address)
}

onEdit () {
aboutActions.editAutofillAddress(this.props.address.toJS())
aboutActions.editAutofillAddress(this.props.address)
}

render () {
Expand Down Expand Up @@ -63,11 +63,11 @@ class CreditCardItem extends ImmutableComponent {
}

onDelete () {
aboutActions.removeAutofillCreditCard(this.props.creditCard.toJS())
aboutActions.removeAutofillCreditCard(this.props.creditCard)
}

onEdit () {
aboutActions.editAutofillCreditCard(this.props.creditCard.toJS())
aboutActions.editAutofillCreditCard(this.props.creditCard)
}

render () {
Expand Down
22 changes: 12 additions & 10 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ class Frame extends ImmutableComponent {
} else if (location === 'about:autofill') {
const partition = FrameStateUtil.getPartition(this.frame)
if (this.props.autofillAddresses) {
const addresses = this.props.autofillAddresses.toJS()
const addresses = this.props.autofillAddresses.get('guid')
let list = []
for (let index in addresses) {
const address = currentWindow.webContents.session.autofill.getProfile(addresses[index][partition])
addresses.forEach((entry) => {
const guid = entry.get(partition)
const address = currentWindow.webContents.session.autofill.getProfile(guid)
let addressDetail = {
name: address.full_name,
organization: address.company_name,
Expand All @@ -124,26 +125,27 @@ class Frame extends ImmutableComponent {
country: address.country_code,
phone: address.phone,
email: address.email,
guid: addresses[index]
guid: entry.toJS()
}
list.push(addressDetail)
}
})
this.webview.send(messages.AUTOFILL_ADDRESSES_UPDATED, list)
}
if (this.props.autofillCreditCards) {
const creditCards = this.props.autofillCreditCards.toJS()
const creditCards = this.props.autofillCreditCards.get('guid')
let list = []
for (let index in creditCards) {
const creditCard = currentWindow.webContents.session.autofill.getCreditCard(creditCards[index][partition])
creditCards.forEach((entry) => {
const guid = entry.get(partition)
const creditCard = currentWindow.webContents.session.autofill.getCreditCard(guid)
let creditCardDetail = {
name: creditCard.name,
card: creditCard.card_number,
month: creditCard.expiration_month,
year: creditCard.expiration_year,
guid: creditCards[index]
guid: entry.toJS()
}
list.push(creditCardDetail)
}
})
this.webview.send(messages.AUTOFILL_CREDIT_CARDS_UPDATED, list)
}
}
Expand Down
30 changes: 17 additions & 13 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,55 +549,59 @@ const handleAppAction = (action) => {
case AppConstants.APP_ADD_AUTOFILL_ADDRESS:
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'addresses'],
appState.getIn(['autofill', 'addresses']).filterNot((address) => {
appState = appState.setIn(['autofill', 'addresses', 'guid'],
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((address) => {
return Immutable.is(address, action.originalDetail.get('guid'))
}))

let addresses = appState.getIn(['autofill', 'addresses'])
let addresses = appState.getIn(['autofill', 'addresses', 'guid'])
const guid = Filtering.addAutofillAddress(action.detail.toJS())
if (action.originalDetail.get('guid') !== undefined &&
!Immutable.is(Immutable.fromJS(guid), action.originalDetail.get('guid'))) {
Filtering.removeAutofillAddress(action.originalDetail.get('guid').toJS())
}
appState = appState.setIn(['autofill', 'addresses'], addresses.push(Immutable.fromJS(guid)))
appState = appState.setIn(['autofill', 'addresses', 'guid'], addresses.push(Immutable.fromJS(guid)))
appState = appState.setIn(['autofill', 'addresses', 'timestamp'], Immutable.fromJS(new Date().getTime()))
break
}
case AppConstants.APP_REMOVE_AUTOFILL_ADDRESS:
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'addresses'],
appState.getIn(['autofill', 'addresses']).filterNot((address) => {
return Immutable.is(address, Immutable.fromJS(action.detail.get('guid')))
appState = appState.setIn(['autofill', 'addresses', 'guid'],
appState.getIn(['autofill', 'addresses', 'guid']).filterNot((address) => {
return Immutable.is(address, action.detail.get('guid'))
}))
Filtering.removeAutofillAddress(action.detail.get('guid').toJS())
appState = appState.setIn(['autofill', 'addresses', 'timestamp'], Immutable.fromJS(new Date().getTime()))
break
}
case AppConstants.APP_ADD_AUTOFILL_CREDIT_CARD:
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'creditCards'],
appState.getIn(['autofill', 'creditCards']).filterNot((card) => {
appState = appState.setIn(['autofill', 'creditCards', 'guid'],
appState.getIn(['autofill', 'creditCards', 'guid']).filterNot((card) => {
return Immutable.is(card, action.originalDetail.get('guid'))
}))

let creditCards = appState.getIn(['autofill', 'creditCards'])
let creditCards = appState.getIn(['autofill', 'creditCards', 'guid'])
const guid = Filtering.addAutofillCreditCard(action.detail.toJS())
if (action.originalDetail.get('guid') !== undefined &&
!Immutable.is(Immutable.fromJS(guid), action.originalDetail.get('guid'))) {
Filtering.removeAutofillCreditCard(action.originalDetail.get('guid').toJS())
}
appState = appState.setIn(['autofill', 'creditCards'], creditCards.push(Immutable.fromJS(guid)))
appState = appState.setIn(['autofill', 'creditCards', 'guid'], creditCards.push(Immutable.fromJS(guid)))
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], Immutable.fromJS(new Date().getTime()))
break
}
case AppConstants.APP_REMOVE_AUTOFILL_CREDIT_CARD:
{
const Filtering = require('../../app/filtering')
appState = appState.setIn(['autofill', 'creditCards'],
appState.getIn(['autofill', 'creditCards']).filterNot((card) => {
appState = appState.setIn(['autofill', 'creditCards', 'guid'],
appState.getIn(['autofill', 'creditCards', 'guid']).filterNot((card) => {
return Immutable.is(card, action.detail.get('guid'))
}))
Filtering.removeAutofillCreditCard(action.detail.get('guid').toJS())
appState = appState.setIn(['autofill', 'creditCards', 'timestamp'], Immutable.fromJS(new Date().getTime()))
break
}
default:
Expand Down
22 changes: 12 additions & 10 deletions test/components/autofillTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Autofill', function () {
.click(saveAddressButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.addresses.length === 1
return val.value.autofill.addresses.guid.length === 1
})
})
.tabByUrl(this.page1Url)
Expand Down Expand Up @@ -103,13 +103,15 @@ describe('Autofill', function () {
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(autofillAddressPanel)
.click('#phone')
.keys('\uE010') // send END key
.keys('123')
.click('#email')
.keys('\uE010') // send END key
.keys('mm')
.click(saveAddressButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.addresses.length === 1
return val.value.autofill.addresses.guid.length === 1
})
})
.tabByUrl(this.page1Url)
Expand Down Expand Up @@ -174,7 +176,7 @@ describe('Autofill', function () {
.click(saveCreditCardButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.creditCards.length === 1
return val.value.autofill.creditCards.guid.length === 1
})
})
.tabByUrl(this.page1Url)
Expand Down Expand Up @@ -211,15 +213,17 @@ describe('Autofill', function () {
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(autofillCreditCardPanel)
.click('#nameOnCard')
.keys('\uE010') // send END key
.keys('123')
.click('#creditCardNumber')
.keys('\uE010') // send END key
.keys('123')
.selectByValue('.expMonthSelect', (expMonth + 1).toString())
.selectByValue('.expYearSelect', (expYear + 1).toString())
.click(saveCreditCardButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.creditCards.length === 1
return val.value.autofill.creditCards.guid.length === 1
})
})
.tabByUrl(this.page1Url)
Expand Down Expand Up @@ -282,7 +286,7 @@ describe('Autofill', function () {
.click(saveAddressButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.addresses.length === 1
return val.value.autofill.addresses.guid.length === 1
})
})
.tabByUrl(this.page1Url)
Expand All @@ -305,11 +309,10 @@ describe('Autofill', function () {
.click(saveAddressButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.addresses.length === 1
return val.value.autofill.addresses.guid.length === 1
})
})
.tabByUrl(this.page1Url)
.refresh()
.waitForVisible('.autofillPage')
.getText('.addressName').should.eventually.be.equal(name)
.getText('.city').should.eventually.be.equal(city)
Expand Down Expand Up @@ -363,7 +366,7 @@ describe('Autofill', function () {
.click(saveCreditCardButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.creditCards.length === 1
return val.value.autofill.creditCards.guid.length === 1
})
})
.tabByUrl(this.page1Url)
Expand All @@ -386,11 +389,10 @@ describe('Autofill', function () {
.click(saveCreditCardButton)
.waitUntil(function () {
return this.getAppState().then((val) => {
return val.value.autofill.creditCards.length === 1
return val.value.autofill.creditCards.guid.length === 1
})
})
.tabByUrl(this.page1Url)
.refresh()
.waitForVisible('.autofillPage')
.getText('.creditCardName').should.eventually.be.equal(cardName)
.getText('.creditCardNumber').should.eventually.be.equal('***' + cardNumber.slice(-4))
Expand Down

0 comments on commit 375c64d

Please sign in to comment.