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

Commit ec95567

Browse files
committed
Add test
1 parent 5dc58e6 commit ec95567

File tree

7 files changed

+281
-9
lines changed

7 files changed

+281
-9
lines changed

js/about/autofill.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ class AboutAutofill extends React.Component {
194194
<h2 data-l10n-id='addresses' />
195195
<div className='autofillPageContent'>
196196
{savedAddresssPage}
197-
<Button l10nId='addAddress' className='primaryButton' onClick={this.onAddAddress} />
197+
<Button l10nId='addAddress' className='primaryButton addAddressButton' onClick={this.onAddAddress} />
198198
</div>
199199
<div className='autofillPageFooter'></div>
200200
<h2 data-l10n-id='creditCards' />
201201
<div className='autofillPageContent'>
202202
{savedCreditCardsPage}
203-
<Button l10nId='addCreditCard' className='primaryButton' onClick={this.onAddCreditCard} />
203+
<Button l10nId='addCreditCard' className='primaryButton addCreditCardButton' onClick={this.onAddCreditCard} />
204204
</div>
205205
</div>
206206
</div>

js/components/autofillAddressPanel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AutofillAddressPanel extends ImmutableComponent {
8989
e.stopPropagation()
9090
}
9191
render () {
92-
return <Dialog onHide={this.props.onHide} className='manageAutofillDataPanel' isClickDismiss>
92+
return <Dialog onHide={this.props.onHide} className='manageAutofillDataPanel autofillAddressPanel' isClickDismiss>
9393
<div className='genericForm manageAutofillData' onClick={this.onClick}>
9494
<div className='formRow manageAutofillDataTitle' data-l10n-id='editAddress' />
9595
<div className='genericFormTable'>
@@ -141,7 +141,7 @@ class AutofillAddressPanel extends ImmutableComponent {
141141
</div>
142142
<div className='formRow'>
143143
<Button l10nId='cancel' className='secondaryAltButton' onClick={this.props.onHide} />
144-
<Button l10nId='save' className='primaryButton' onClick={this.onSave} />
144+
<Button l10nId='save' className='primaryButton saveAddressButton' onClick={this.onSave} />
145145
</div>
146146
</div>
147147
</div>

js/components/autofillCreditCardPanel.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class AutofillCreditCardPanel extends ImmutableComponent {
7373
ExpYear.push(<option value={i}>{i}</option>)
7474
}
7575

76-
return <Dialog onHide={this.props.onHide} className='manageAutofillDataPanel' isClickDismiss>
76+
return <Dialog onHide={this.props.onHide} className='manageAutofillDataPanel autofillCreditCardPanel' isClickDismiss>
7777
<div className='genericForm manageAutofillData' onClick={this.onClick}>
7878
<div className='formRow manageAutofillDataTitle' data-l10n-id='editCreditCard' />
7979
<div className='genericFormTable'>
@@ -90,17 +90,17 @@ class AutofillCreditCardPanel extends ImmutableComponent {
9090
<div id='expirationDate' className='formRow'>
9191
<label data-l10n-id='expirationDate' htmlFor='expirationDate' />
9292
<select value={this.displayMonth}
93-
onChange={this.onExpMonthChange} className='formSelect' >
93+
onChange={this.onExpMonthChange} className='formSelect expMonthSelect' >
9494
{ExpMonth}
9595
</select>
9696
<select value={this.props.currentDetail.get('year')}
97-
onChange={this.onExpYearChange} className='formSelect' >
97+
onChange={this.onExpYearChange} className='formSelect expYearSelect' >
9898
{ExpYear}
9999
</select>
100100
</div>
101101
<div className='formRow'>
102102
<Button l10nId='cancel' className='secondaryAltButton' onClick={this.props.onHide} />
103-
<Button l10nId='save' className='primaryButton' onClick={this.onSave} />
103+
<Button l10nId='save' className='primaryButton saveCreditCardButton' onClick={this.onSave} />
104104
</div>
105105
</div>
106106
</div>

js/contextMenus.js

+1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ function autofillTemplateInit (suggestions, frame) {
379379
for (let i = 0; i < suggestions.length; ++i) {
380380
let value
381381
let frontendId = suggestions[i].frontend_id
382+
console.log(frontendId)
382383
if (frontendId >= 0) { // POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY and Autofill Entry
383384
value = suggestions[i].value
384385
} else if (frontendId === -1) { // POPUP_ITEM_ID_WARNING_MESSAGE

test/components/autofillTest.js

+256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
/* global describe, it, before */
2+
3+
const Brave = require('../lib/brave')
4+
const {urlInput, autofillAddressPanel, autofillCreditCardPanel} = require('../lib/selectors')
5+
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')
6+
7+
describe('Autofill', function () {
8+
function * setup (client) {
9+
yield client
10+
.waitUntilWindowLoaded()
11+
.waitForUrl(Brave.newTabUrl)
12+
.waitForBrowserWindow()
13+
.waitForVisible('#window')
14+
.waitForVisible(urlInput)
15+
}
16+
17+
describe('Data Management', function () {
18+
Brave.beforeAll(this)
19+
before(function * () {
20+
yield setup(this.app.client)
21+
})
22+
const page1Url = 'about:autofill'
23+
const addAddressButton = '.addAddressButton'
24+
const saveAddressButton = '.saveAddressButton'
25+
const name = 'Brave Lion'
26+
const organization = 'Brave'
27+
const streetAddress = '1161 Mission Street, #401'
28+
const city = 'San Francisco'
29+
const state = 'CA'
30+
const postalCode = '94103-1550'
31+
const country = 'US'
32+
const phone = '0987654321'
33+
const email = 'press@brave.com'
34+
it('Adding Address', function * () {
35+
yield this.app.client
36+
.tabByIndex(0)
37+
.loadUrl(page1Url)
38+
.url(getTargetAboutUrl(page1Url))
39+
.waitForVisible(addAddressButton)
40+
.click(addAddressButton)
41+
.windowByUrl(Brave.browserWindowUrl)
42+
.waitForVisible(autofillAddressPanel)
43+
.click('#nameOnAddress')
44+
.keys(name)
45+
.click('#organization')
46+
.keys(organization)
47+
.click('#streetAddress')
48+
.keys(streetAddress)
49+
.click('#city')
50+
.keys(city)
51+
.click('#state')
52+
.keys(state)
53+
.click('#postalCode')
54+
.keys(postalCode)
55+
.click('#country')
56+
.keys(country)
57+
.click('#phone')
58+
.keys(phone)
59+
.click('#email')
60+
.keys(email)
61+
.click(saveAddressButton)
62+
.waitUntil(function () {
63+
return this.getAppState().then((val) => {
64+
return val.value.autofill.addresses.length === 1
65+
})
66+
})
67+
.tabByUrl(this.page1Url)
68+
.waitForVisible('.autofillPage')
69+
.getText('.addressName').should.eventually.be.equal(name)
70+
.getText('.organization').should.eventually.be.equal(organization)
71+
.getText('.streetAddress').should.eventually.be.equal(streetAddress)
72+
.getText('.city').should.eventually.be.equal(city)
73+
.getText('.state').should.eventually.be.equal(state)
74+
.getText('.postalCode').should.eventually.be.equal(postalCode)
75+
.getText('.country').should.eventually.be.equal(country)
76+
.getText('.phone').should.eventually.be.equal(phone)
77+
.getText('.email').should.eventually.be.equal(email)
78+
})
79+
it('Address form test', function * () {
80+
const page1Url = 'https://www.roboform.com/filling-test-all-fields'
81+
yield this.app.client
82+
.tabByIndex(0)
83+
.loadUrl(page1Url)
84+
.url(getTargetAboutUrl(page1Url))
85+
.waitForVisible('<form>')
86+
.click('[name="04fullname"]')
87+
.click('[name="04fullname"]')
88+
.windowByUrl(Brave.browserWindowUrl)
89+
.ipcSendRenderer('autofill-selection-clicked', 2, name, 1, 0)
90+
.setContextMenuDetail()
91+
.tabByUrl(this.page1Url)
92+
.getValue('[name="04fullname"]').should.eventually.be.equal(name)
93+
})
94+
it('Editing Address', function * () {
95+
yield this.app.client
96+
.tabByIndex(0)
97+
.loadUrl(page1Url)
98+
.url(getTargetAboutUrl(page1Url))
99+
.waitForVisible('[title="Edit address"]')
100+
.click('[title="Edit address"]')
101+
.windowByUrl(Brave.browserWindowUrl)
102+
.waitForVisible(autofillAddressPanel)
103+
.click('#phone')
104+
.keys('123')
105+
.click('#email')
106+
.keys('mm')
107+
.click(saveAddressButton)
108+
.waitUntil(function () {
109+
return this.getAppState().then((val) => {
110+
return val.value.autofill.addresses.length === 1
111+
})
112+
})
113+
.tabByUrl(this.page1Url)
114+
.waitForVisible('.autofillPage')
115+
.getText('.addressName').should.eventually.be.equal(name)
116+
.getText('.organization').should.eventually.be.equal(organization)
117+
.getText('.streetAddress').should.eventually.be.equal(streetAddress)
118+
.getText('.city').should.eventually.be.equal(city)
119+
.getText('.state').should.eventually.be.equal(state)
120+
.getText('.postalCode').should.eventually.be.equal(postalCode)
121+
.getText('.country').should.eventually.be.equal(country)
122+
.getText('.phone').should.eventually.be.equal(phone + '123')
123+
.getText('.email').should.eventually.be.equal(email + 'mm')
124+
})
125+
it('Edited Address form test', function * () {
126+
const page1Url = 'https://www.roboform.com/filling-test-all-fields'
127+
yield this.app.client
128+
.tabByIndex(0)
129+
.loadUrl(page1Url)
130+
.url(getTargetAboutUrl(page1Url))
131+
.waitForVisible('<form>')
132+
.click('[name="04fullname"]')
133+
.click('[name="04fullname"]')
134+
.windowByUrl(Brave.browserWindowUrl)
135+
.ipcSendRenderer('autofill-selection-clicked', 2, name, 1, 0)
136+
.setContextMenuDetail()
137+
.tabByUrl(this.page1Url)
138+
.getValue('[name="04fullname"]').should.eventually.be.equal(name)
139+
.getValue('[name="23cellphon"]').should.eventually.be.equal(phone + '123')
140+
.getValue('[name="24emailadr"]').should.eventually.be.equal(email + 'mm')
141+
})
142+
it('Deleting Address', function * () {
143+
yield this.app.client
144+
.tabByIndex(0)
145+
.loadUrl(page1Url)
146+
.url(getTargetAboutUrl(page1Url))
147+
.waitForVisible('[title="Delete address"]')
148+
.click('[title="Delete address"]')
149+
.waitForVisible('[data-l10n-id=noAddressesSaved]')
150+
})
151+
const addCreditCardButton = '.addCreditCardButton'
152+
const saveCreditCardButton = '.saveCreditCardButton'
153+
const cardName = 'Test Card'
154+
const cardNumber = '1234567890'
155+
const expMonth = 10
156+
const expYear = new Date().getFullYear() + 2
157+
it('Adding Credit Card', function * () {
158+
yield this.app.client
159+
.tabByIndex(0)
160+
.loadUrl(page1Url)
161+
.url(getTargetAboutUrl(page1Url))
162+
.waitForVisible(addCreditCardButton)
163+
.click(addCreditCardButton)
164+
.windowByUrl(Brave.browserWindowUrl)
165+
.waitForVisible(autofillCreditCardPanel)
166+
.click('#nameOnCard')
167+
.keys(cardName)
168+
.click('#creditCardNumber')
169+
.keys(cardNumber)
170+
.selectByValue('.expMonthSelect', expMonth.toString())
171+
.selectByValue('.expYearSelect', expYear.toString())
172+
.click(saveCreditCardButton)
173+
.waitUntil(function () {
174+
return this.getAppState().then((val) => {
175+
return val.value.autofill.creditCards.length === 1
176+
})
177+
})
178+
.tabByUrl(this.page1Url)
179+
.waitForVisible('.autofillPage')
180+
.getText('.creditCardName').should.eventually.be.equal(cardName)
181+
.getText('.creditCardNumber').should.eventually.be.equal('***' + cardNumber.slice(-4))
182+
.getText('.creditCardPExpirationDate').should.eventually.be.equal(expMonth.toString() + '/' + expYear.toString())
183+
})
184+
it('Credit Card form test', function * () {
185+
const page1Url = 'https://www.roboform.com/filling-test-all-fields'
186+
yield this.app.client
187+
.tabByIndex(0)
188+
.loadUrl(page1Url)
189+
.url(getTargetAboutUrl(page1Url))
190+
.waitForVisible('<form>')
191+
.click('[name="41ccnumber"]')
192+
.click('[name="41ccnumber"]')
193+
.windowByUrl(Brave.browserWindowUrl)
194+
.ipcSendRenderer('autofill-selection-clicked', 2, cardNumber, 65536, 0)
195+
.setContextMenuDetail()
196+
.tabByUrl(this.page1Url)
197+
.getValue('[name="41ccnumber"]').should.eventually.be.equal(cardNumber)
198+
.getValue('[name="42ccexp_mm"]').should.eventually.be.equal(expMonth.toString())
199+
.getValue('[name="43ccexp_yy"]').should.eventually.be.equal(expYear.toString())
200+
})
201+
it('Editing Credit Card', function * () {
202+
yield this.app.client
203+
.tabByIndex(0)
204+
.loadUrl(page1Url)
205+
.url(getTargetAboutUrl(page1Url))
206+
.waitForVisible('[title="Edit creditCard"]')
207+
.click('[title="Edit creditCard"]')
208+
.windowByUrl(Brave.browserWindowUrl)
209+
.waitForVisible(autofillCreditCardPanel)
210+
.click('#nameOnCard')
211+
.keys('123')
212+
.click('#creditCardNumber')
213+
.keys('123')
214+
.selectByValue('.expMonthSelect', (expMonth + 1).toString())
215+
.selectByValue('.expYearSelect', (expYear + 1).toString())
216+
.click(saveCreditCardButton)
217+
.waitUntil(function () {
218+
return this.getAppState().then((val) => {
219+
return val.value.autofill.creditCards.length === 1
220+
})
221+
})
222+
.tabByUrl(this.page1Url)
223+
.waitForVisible('.autofillPage')
224+
.getText('.creditCardName').should.eventually.be.equal(cardName + 123)
225+
.getText('.creditCardNumber').should.eventually.be.equal('***' + (cardNumber + 123).slice(-4))
226+
.getText('.creditCardPExpirationDate').should.eventually.be.equal(
227+
(expMonth + 1).toString() + '/' + (expYear + 1).toString())
228+
})
229+
it('Edited Credit Card form test', function * () {
230+
const page1Url = 'https://www.roboform.com/filling-test-all-fields'
231+
yield this.app.client
232+
.tabByIndex(0)
233+
.loadUrl(page1Url)
234+
.url(getTargetAboutUrl(page1Url))
235+
.waitForVisible('<form>')
236+
.click('[name="41ccnumber"]')
237+
.click('[name="41ccnumber"]')
238+
.windowByUrl(Brave.browserWindowUrl)
239+
.ipcSendRenderer('autofill-selection-clicked', 2, cardNumber, 65536, 0)
240+
.setContextMenuDetail()
241+
.tabByUrl(this.page1Url)
242+
.getValue('[name="41ccnumber"]').should.eventually.be.equal(cardNumber + '123')
243+
.getValue('[name="42ccexp_mm"]').should.eventually.be.equal((expMonth + 1).toString())
244+
.getValue('[name="43ccexp_yy"]').should.eventually.be.equal((expYear + 1).toString())
245+
})
246+
it('Deleting Credit Card', function * () {
247+
yield this.app.client
248+
.tabByIndex(0)
249+
.loadUrl(page1Url)
250+
.url(getTargetAboutUrl(page1Url))
251+
.waitForVisible('[title="Delete creditCard"]')
252+
.click('[title="Delete creditCard"]')
253+
.waitForVisible('[data-l10n-id=noCreditCardsSaved]')
254+
})
255+
})
256+
})

test/lib/brave.js

+12
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ var exports = {
106106
}, message, ...param).then((response) => response.value)
107107
})
108108

109+
this.app.client.addCommand('ipcSendRenderer', function (message, ...param) {
110+
return this.execute(function (message, ...param) {
111+
return require('electron').ipcRenderer.send(message, ...param)
112+
}, message, ...param).then((response) => response.value)
113+
})
114+
109115
var windowHandlesOrig = this.app.client.windowHandles
110116
Object.getPrototypeOf(this.app.client).windowHandles = function () {
111117
return windowHandlesOrig.apply(this)
@@ -196,6 +202,12 @@ var exports = {
196202
})
197203
})
198204

205+
this.app.client.addCommand('setContextMenuDetail', function () {
206+
return this.execute(function () {
207+
return window.windowActions.setContextMenuDetail()
208+
})
209+
})
210+
199211
this.app.client.addCommand('showFindbar', function (show) {
200212
return this.execute(function (show) {
201213
window.windowActions.setFindbarShown(Object.assign({

test/lib/selectors.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,8 @@ module.exports = {
4545
clearBrowsingDataPanel: '.clearBrowsingDataPanel',
4646
clearBrowsingDataButton: '.clearBrowsingDataButton',
4747
saveButton: '[data-l10n-id="save"]',
48-
securityTab: '[data-l10n-id="security"]'
48+
securityTab: '[data-l10n-id="security"]',
49+
saveButton: '[data-l10n-id="save"]',
50+
autofillAddressPanel: '.autofillAddressPanel',
51+
autofillCreditCardPanel: '.autofillCreditCardPanel'
4952
}

0 commit comments

Comments
 (0)