From cacf22deab7fec07d1f9f62d7afb8dc7be0fd9a9 Mon Sep 17 00:00:00 2001 From: bridiver Date: Thu, 1 Sep 2016 18:52:51 -0700 Subject: [PATCH] allow setting of user data dir use a different user data dir for each test run refactor autofill tests fixes #3618 --- app/index.js | 9 + app/sessionStore.js | 16 +- test/app/sessionStoreTest.js | 4 +- test/components/autofillTest.js | 527 ++++++++++++++------------------ test/fixtures/formfill.html | 1 + test/lib/brave.js | 65 ++-- 6 files changed, 291 insertions(+), 331 deletions(-) diff --git a/app/index.js b/app/index.js index cdb776870fa..d0f3ce6d253 100644 --- a/app/index.js +++ b/app/index.js @@ -28,6 +28,7 @@ var locale = require('./locale') const Immutable = require('immutable') const electron = require('electron') +const path = require('path') const BrowserWindow = electron.BrowserWindow const dialog = electron.dialog const ipcMain = electron.ipcMain @@ -64,6 +65,14 @@ const contentSettings = require('../js/state/contentSettings') const privacy = require('../js/state/privacy') const basicAuth = require('./browser/basicAuth') +if (!process.env.USER_DATA_DIR && ['development', 'test'].includes(process.env.NODE_ENV)) { + process.env.USER_DATA_DIR = path.join(app.getPath('appData'), app.getName() + '-' + process.env.NODE_ENV) +} + +if (process.env.USER_DATA_DIR) { + app.setPath('userData', process.env.USER_DATA_DIR) +} + // Used to collect the per window state when shutting down the application let perWindowState = [] let sessionStateStoreCompleteOnQuit = false diff --git a/app/sessionStore.js b/app/sessionStore.js index 002163dfc3b..89a6ecf9d2c 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -23,17 +23,13 @@ const sessionStorageVersion = 1 const filtering = require('./filtering') // const tabState = require('./common/state/tabState') -let suffix = '' -if (process.env.NODE_ENV === 'development') { - suffix = '-dev' -} -const sessionStorageName = `session-store-${sessionStorageVersion}${suffix}` -const storagePath = process.env.NODE_ENV !== 'test' - ? path.join(app.getPath('userData'), sessionStorageName) - : path.join(process.env.HOME, '.brave-test-session-store-1') const getSetting = require('../js/settings').getSetting const promisify = require('../js/lib/promisify') +const sessionStorageName = `session-store-${sessionStorageVersion}` +const getStoragePath = () => { + return path.join(app.getPath('userData'), sessionStorageName) +} /** * Saves the specified immutable browser state to storage. * @@ -78,7 +74,7 @@ module.exports.saveAppState = (payload, isShutdown) => { : path.join(process.env.HOME, '.brave-test-session-store-tmp-' + epochTimestamp) let p = promisify(fs.writeFile, tmpStoragePath, JSON.stringify(payload)) - .then(() => promisify(fs.rename, tmpStoragePath, storagePath)) + .then(() => promisify(fs.rename, tmpStoragePath, getStoragePath())) if (isShutdown) { p = p.then(module.exports.cleanSessionDataOnShutdown()) } @@ -314,7 +310,7 @@ module.exports.loadAppState = () => { return new Promise((resolve, reject) => { let data try { - data = fs.readFileSync(storagePath) + data = fs.readFileSync(getStoragePath()) } catch (e) { } diff --git a/test/app/sessionStoreTest.js b/test/app/sessionStoreTest.js index 068fbbe3e53..e61bd5789d7 100644 --- a/test/app/sessionStoreTest.js +++ b/test/app/sessionStoreTest.js @@ -38,8 +38,8 @@ describe('sessionStore', function () { .waitUntil(function () { return this.getValue(urlInput).then((val) => val === page1Url) }) - yield Brave.stopApp() - yield Brave.startApp(false) + yield Brave.stopApp(false) + yield Brave.startApp() yield setup(Brave.app.client) }) diff --git a/test/components/autofillTest.js b/test/components/autofillTest.js index 58e3a87a959..6855ad27c3f 100644 --- a/test/components/autofillTest.js +++ b/test/components/autofillTest.js @@ -1,11 +1,28 @@ /* global describe, it, before */ const Brave = require('../lib/brave') -const assert = require('assert') const messages = require('../../js/constants/messages') const {urlInput, autofillAddressPanel, autofillCreditCardPanel} = require('../lib/selectors') const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil') +const addAddressButton = '.addAddressButton' +const saveAddressButton = '.saveAddressButton' +const addCreditCardButton = '.addCreditCardButton' +const saveCreditCardButton = '.saveCreditCardButton' +const name = 'Brave Lion' +const organization = 'Brave' +const streetAddress = '1161 Mission Street, #401' +const city = 'San Francisco' +const state = 'CA' +const postalCode = '94103-1550' +const country = 'US' +const phone = '0987654321' +const email = 'press@brave.com' +const cardName = 'Test Card' +const cardNumber = '1234567890' +const expMonth = 9 +const expYear = new Date().getFullYear() + 2 + describe('Autofill', function () { function * setup (client) { yield client @@ -16,28 +33,16 @@ describe('Autofill', function () { .waitForVisible(urlInput) } - describe('Data Management', function () { + describe('address', function () { Brave.beforeAll(this) before(function * () { yield setup(this.app.client) - }) - const page1Url = 'about:autofill' - const addAddressButton = '.addAddressButton' - const saveAddressButton = '.saveAddressButton' - const name = 'Brave Lion' - const organization = 'Brave' - const streetAddress = '1161 Mission Street, #401' - const city = 'San Francisco' - const state = 'CA' - const postalCode = '94103-1550' - const country = 'US' - const phone = '0987654321' - const email = 'press@brave.com' - it('Adding Address', function * () { + this.autofillPreferences = 'about:autofill' + this.formfill = Brave.server.url('formfill.html') + yield this.app.client .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.autofillPreferences) .waitForVisible(addAddressButton) .click(addAddressButton) .windowByUrl(Brave.browserWindowUrl) @@ -66,7 +71,11 @@ describe('Autofill', function () { return val.value.autofill.addresses.guid.length === 1 }) }) - .tabByUrl(this.page1Url) + .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) @@ -78,26 +87,44 @@ describe('Autofill', function () { .getText('.phone').should.eventually.be.equal(phone) .getText('.email').should.eventually.be.equal(email) }) - it('Address form test', function * () { - const page1Url = Brave.server.url('formfill.html') + it('autofills the address', function * () { yield this.app.client .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.formfill) .waitForVisible('
') .click('[name="04fullname"]') .click('[name="04fullname"]') .windowByUrl(Brave.browserWindowUrl) - .ipcSendRenderer('autofill-selection-clicked', 2, name, 1, 0) - .setContextMenuDetail() - .tabByUrl(this.page1Url) + .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('Editing Address', function * () { + it('autofills the address in a private tab', function * () { yield this.app.client + .windowByUrl(Brave.browserWindowUrl) + .ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill + '?2', { isPrivate: true }) + .waitForUrl(this.formfill + '?2') + .waitForVisible('') + .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 updated address when edited', function * () { + yield this.app.client + // update the address .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.autofillPreferences) .waitForVisible('[title="Edit address"]') .click('[title="Edit address"]') .windowByUrl(Brave.browserWindowUrl) @@ -114,7 +141,8 @@ describe('Autofill', function () { return val.value.autofill.addresses.guid.length === 1 }) }) - .tabByUrl(this.page1Url) + .tabByIndex(0) + .loadUrl(this.autofillPreferences) .waitForVisible('.autofillPage') .getText('.addressName').should.eventually.be.equal(name) .getText('.organization').should.eventually.be.equal(organization) @@ -125,44 +153,42 @@ describe('Autofill', function () { .getText('.country').should.eventually.be.equal(country) .getText('.phone').should.eventually.be.equal(phone + '123') .getText('.email').should.eventually.be.equal(email + 'mm') - }) - it('Edited Address form test', function * () { - const page1Url = Brave.server.url('formfill.html') - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + // fill out the form + .loadUrl(this.formfill) .waitForVisible('') .click('[name="04fullname"]') .click('[name="04fullname"]') .windowByUrl(Brave.browserWindowUrl) - .ipcSendRenderer('autofill-selection-clicked', 2, name, 1, 0) - .setContextMenuDetail() - .tabByUrl(this.page1Url) + .waitForVisible('.contextMenuItemText') + .click('.contextMenuItemText') + .tabByUrl(this.formfill) .getValue('[name="04fullname"]').should.eventually.be.equal(name) .getValue('[name="23cellphon"]').should.eventually.be.equal(phone + '123') .getValue('[name="24emailadr"]').should.eventually.be.equal(email + 'mm') + // TODO(bridiver) - this needs to check all fields }) - it('Deleting Address', function * () { + it('deletes the address', function * () { yield this.app.client .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.autofillPreferences) + .url(getTargetAboutUrl(this.autofillPreferences)) .waitForVisible('[title="Delete address"]') .click('[title="Delete address"]') + .loadUrl(this.autofillPreferences) .waitForVisible('[data-l10n-id=noAddressesSaved]') }) - const addCreditCardButton = '.addCreditCardButton' - const saveCreditCardButton = '.saveCreditCardButton' - const cardName = 'Test Card' - const cardNumber = '1234567890' - const expMonth = 9 - const expYear = new Date().getFullYear() + 2 - it('Adding Credit Card', function * () { + }) + + describe('credit card', 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(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.autofillPreferences) .waitForVisible(addCreditCardButton) .click(addCreditCardButton) .windowByUrl(Brave.browserWindowUrl) @@ -179,35 +205,53 @@ describe('Autofill', function () { return val.value.autofill.creditCards.guid.length === 1 }) }) - .tabByUrl(this.page1Url) + .tabByIndex(0) + .loadUrl(this.autofillPreferences) + }) + 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('Credit Card form test', function * () { - const page1Url = Brave.server.url('formfill.html') + it('autofills the credit card', function * () { yield this.app.client .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.formfill) .waitForVisible('') .click('[name="41ccnumber"]') .click('[name="41ccnumber"]') .windowByUrl(Brave.browserWindowUrl) - .ipcSendRenderer('autofill-selection-clicked', 2, cardNumber, 65536, 0) - .setContextMenuDetail() - .tabByUrl(this.page1Url) + .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('Editing Credit Card', function * () { + it('autofills the credit card in a private tab', function * () { + yield this.app.client + .windowByUrl(Brave.browserWindowUrl) + .ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill + '?2', { isPrivate: true }) + .waitForUrl(this.formfill + '?2') + .waitForVisible('') + .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('autofills the updated credit card when edited', function * () { yield this.app.client .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.autofillPreferences) + .url(getTargetAboutUrl(this.autofillPreferences)) .waitForVisible('[title="Edit creditCard"]') .click('[title="Edit creditCard"]') .windowByUrl(Brave.browserWindowUrl) @@ -226,263 +270,154 @@ describe('Autofill', function () { return val.value.autofill.creditCards.guid.length === 1 }) }) - .tabByUrl(this.page1Url) + .tabByIndex(0) + .loadUrl(this.autofillPreferences) .waitForVisible('.autofillPage') .getText('.creditCardName').should.eventually.be.equal(cardName + 123) .getText('.creditCardNumber').should.eventually.be.equal('***' + (cardNumber + 123).slice(-4)) .getText('.creditCardPExpirationDate').should.eventually.be.equal( (expMonth + 1).toString() + '/' + (expYear + 1).toString()) - }) - it('Edited Credit Card form test', function * () { - const page1Url = Brave.server.url('formfill.html') - yield this.app.client .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.formfill) .waitForVisible('') .click('[name="41ccnumber"]') .click('[name="41ccnumber"]') .windowByUrl(Brave.browserWindowUrl) - .ipcSendRenderer('autofill-selection-clicked', 2, cardNumber, 65536, 0) - .setContextMenuDetail() - .tabByUrl(this.page1Url) + .waitForVisible('.contextMenuItemText') + .click('.contextMenuItemText') + .tabByUrl(this.formfill) .getValue('[name="41ccnumber"]').should.eventually.be.equal(cardNumber + '123') .getValue('[name="42ccexp_mm"]').should.eventually.be.equal((expMonth + 1).toString()) .getValue('[name="43ccexp_yy"]').should.eventually.be.equal((expYear + 1).toString()) + // TODO(bridiver) this needs to check all fields }) - it('Deleting Credit Card', function * () { + it('deletes the credit card', function * () { yield this.app.client .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) + .loadUrl(this.autofillPreferences) .waitForVisible('[title="Delete creditCard"]') .click('[title="Delete creditCard"]') + .loadUrl(this.autofillPreferences) .waitForVisible('[data-l10n-id=noCreditCardsSaved]') }) }) - describe('Mergeable Data', function () { - Brave.beforeAll(this) - before(function * () { - yield setup(this.app.client) + describe('ad-hoc autofill', function () { + describe('regular tab', 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('') + .setValue('[name="04fullname"]', 'test') + .click('#submit') + }) + it('autofills in regular tab', function * () { + yield this.app.client + .tabByIndex(0) + .waitForVisible('') + .click('[name="04fullname"]') + .click('[name="04fullname"]') + .windowByUrl(Brave.browserWindowUrl) + .waitForVisible('.contextMenuItemText') + .click('.contextMenuItemText') + .tabByIndex(0) + .getValue('[name="04fullname"]').should.eventually.be.equal('test') + }) + it('autofills in private tab', function * () { + yield this.app.client + .windowByUrl(Brave.browserWindowUrl) + .ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill + '?2', { isPrivate: true }) + .waitForUrl(this.formfill + '?2') + .waitForVisible('') + .click('[name="04fullname"]') + .click('[name="04fullname"]') + .windowByUrl(Brave.browserWindowUrl) + .waitForVisible('.contextMenuItemText') + .click('.contextMenuItemText') + .tabByIndex(0) + .getValue('[name="04fullname"]').should.eventually.be.equal('test') + }) }) - const page1Url = 'about:autofill' - const addAddressButton = '.addAddressButton' - const saveAddressButton = '.saveAddressButton' - const name = 'Brave Lion' - const city = 'San Francisco' - const country = 'US' - it('Adding Address', function * () { - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) - .waitForVisible(addAddressButton) - .click(addAddressButton) - .windowByUrl(Brave.browserWindowUrl) - .waitForVisible(autofillAddressPanel) - .click('#nameOnAddress') - .keys(name) - .click(saveAddressButton) - .waitUntil(function () { - return this.getAppState().then((val) => { - return val.value.autofill.addresses.guid.length === 1 - }) - }) - .tabByUrl(this.page1Url) - .waitForVisible('.autofillPage') - .getText('.addressName').should.eventually.be.equal(name) + describe('session tab', 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('') + .setValue('[name="04fullname"]', 'test') + .click('#submit') + }) + it('autofills in regular tab', function * () { + yield this.app.client + .tabByIndex(0) + .waitForVisible('') + .click('[name="04fullname"]') + .click('[name="04fullname"]') + .windowByUrl(Brave.browserWindowUrl) + .waitForVisible('.contextMenuItemText') + .click('.contextMenuItemText') + .tabByIndex(0) + .getValue('[name="04fullname"]').should.eventually.be.equal('test') + }) + // TODO(bridiver) - session tabs should have autofill data + it.skip('autofills in session tab', function * () { + yield this.app.client + .windowByUrl(Brave.browserWindowUrl) + .ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill + '?2', { partitionNumber: 3 }) + .waitForUrl(this.formfill + '?2') + .waitForVisible('') + .click('[name="04fullname"]') + .click('[name="04fullname"]') + .windowByUrl(Brave.browserWindowUrl) + .waitForVisible('.contextMenuItemText') + .click('.contextMenuItemText') + .tabByIndex(0) + .getValue('[name="04fullname"]').should.eventually.be.equal('test') + }) }) - it('Editing Address', function * () { - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) - .waitForVisible('[title="Edit address"]') - .click('[title="Edit address"]') - .windowByUrl(Brave.browserWindowUrl) - .waitForVisible(autofillAddressPanel) - .click('#city') - .keys(city) - .click('#country') - .keys(country) - .click(saveAddressButton) - .waitUntil(function () { - return this.getAppState().then((val) => { - return val.value.autofill.addresses.guid.length === 1 - }) - }) - .tabByUrl(this.page1Url) - .waitForVisible('.autofillPage') - .getText('.addressName').should.eventually.be.equal(name) - .getText('.city').should.eventually.be.equal(city) - .getText('.country').should.eventually.be.equal(country) - }) - it('Address form test', function * () { - const page1Url = Brave.server.url('formfill.html') - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) - .waitForVisible('') - .click('[name="04fullname"]') - .click('[name="04fullname"]') - .windowByUrl(Brave.browserWindowUrl) - .ipcSendRenderer('autofill-selection-clicked', 2, name, 1, 0) - .setContextMenuDetail() - .tabByUrl(this.page1Url) - .getValue('[name="04fullname"]').should.eventually.be.equal(name) - .getValue('[name="13adr_city"]').should.eventually.be.equal(city) - .getValue('[name="15_country"]').should.eventually.be.equal('United States') - }) - it('Deleting Address', function * () { - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) - .waitForVisible('[title="Delete address"]') - .click('[title="Delete address"]') - .waitForVisible('[data-l10n-id=noAddressesSaved]') - }) - const addCreditCardButton = '.addCreditCardButton' - const saveCreditCardButton = '.saveCreditCardButton' - const cardName = 'Test Card' - const cardNumber = '1234567890' - const expMonth = 10 - const expYear = new Date().getFullYear() + 2 - it('Adding Credit Card', function * () { - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) - .waitForVisible(addCreditCardButton) - .click(addCreditCardButton) - .windowByUrl(Brave.browserWindowUrl) - .waitForVisible(autofillCreditCardPanel) - .click('#nameOnCard') - .keys(cardName) - .click('#creditCardNumber') - .keys(cardNumber) - .click(saveCreditCardButton) - .waitUntil(function () { - return this.getAppState().then((val) => { - return val.value.autofill.creditCards.guid.length === 1 - }) - }) - .tabByUrl(this.page1Url) - .waitForVisible('.autofillPage') - .getText('.creditCardName').should.eventually.be.equal(cardName) - .getText('.creditCardNumber').should.eventually.be.equal('***' + cardNumber.slice(-4)) - .getText('.creditCardPExpirationDate').should.eventually.be.equal('01/' + new Date().getFullYear().toString()) - }) - it('Editing Credit Card', function * () { - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) - .waitForVisible('[title="Edit creditCard"]') - .click('[title="Edit creditCard"]') - .windowByUrl(Brave.browserWindowUrl) - .waitForVisible(autofillCreditCardPanel) - .selectByValue('.expMonthSelect', expMonth.toString()) - .selectByValue('.expYearSelect', expYear.toString()) - .click(saveCreditCardButton) - .waitUntil(function () { - return this.getAppState().then((val) => { - return val.value.autofill.creditCards.guid.length === 1 - }) - }) - .tabByUrl(this.page1Url) - .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.toString() + '/' + expYear.toString()) - }) - it('Credit Card form test', function * () { - const page1Url = Brave.server.url('formfill.html') - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) - .waitForVisible('') - .click('[name="41ccnumber"]') - .click('[name="41ccnumber"]') - .windowByUrl(Brave.browserWindowUrl) - .ipcSendRenderer('autofill-selection-clicked', 2, cardNumber, 65536, 0) - .setContextMenuDetail() - .tabByUrl(this.page1Url) - .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('Deleting Credit Card', function * () { - yield this.app.client - .tabByIndex(0) - .loadUrl(page1Url) - .url(getTargetAboutUrl(page1Url)) - .waitForVisible('[title="Delete creditCard"]') - .click('[title="Delete creditCard"]') - .waitForVisible('[data-l10n-id=noCreditCardsSaved]') - }) - }) - - describe('prevent autocomplete data leak from private to regular', function () { - Brave.beforeAll(this) - const url = 'https://yoast.com/research/autocompletetype.php' - before(function * () { - yield setup(this.app.client) - }) - it('submit form on regular', function * () { - yield this.app.client - .ipcSend(messages.SHORTCUT_NEW_FRAME, url) - .waitForUrl(url) - .windowByUrl(Brave.browserWindowUrl) - .waitForExist('.tab[data-frame-key="2"]') - .waitForVisible('webview[partition="persist:default"]') - .tabByUrl(this.url) - .setValue('[x-autocompletetype="name"]', 'bravery') - .click('[value="Submit your name"]') - .loadUrl(url) - .click('[x-autocompletetype="name"]') - .keys('b') - .windowByUrl(Brave.browserWindowUrl) - let item = yield this.app.client.getText('.contextMenuItemText') - assert.equal(item, 'bravery') - yield this.app.client.setContextMenuDetail() - }) - it('submit form on private', function * () { - yield this.app.client - .ipcSend(messages.SHORTCUT_NEW_FRAME, url, { isPrivate: true }) - .waitForUrl(url) - .windowByUrl(Brave.browserWindowUrl) - .waitForExist('.tab.private[data-frame-key="3"]') - .waitForVisible('webview[partition="default"]') - .tabByUrl(this.url) - .setValue('[x-autocompletetype="name"]', 'bravery2') - .click('[value="Submit your name"]') - .loadUrl(url) - .click('[x-autocompletetype="name"]') - .keys('b') - .windowByUrl(Brave.browserWindowUrl) - let item = yield this.app.client.getText('.contextMenuItemText') - assert.equal(item, 'bravery') - yield this.app.client.setContextMenuDetail() - }) - it('check on regular', function * () { - yield this.app.client - .ipcSend(messages.SHORTCUT_NEW_FRAME, url) - .waitForUrl(url) - .windowByUrl(Brave.browserWindowUrl) - .waitForExist('.tab[data-frame-key="4"]') - .waitForVisible('webview[partition="persist:default"]') - .tabByUrl(this.url) - .click('[x-autocompletetype="name"]') - .keys('b') - .windowByUrl(Brave.browserWindowUrl) - let item = yield this.app.client.getText('.contextMenuItemText') - assert.equal(item, 'bravery') - yield this.app.client.setContextMenuDetail() + describe('private tab', function () { + Brave.beforeAll(this) + before(function * () { + yield setup(this.app.client) + this.formfill = Brave.server.url('formfill.html') + yield this.app.client + .windowByUrl(Brave.browserWindowUrl) + .ipcSend(messages.SHORTCUT_NEW_FRAME, this.formfill, { isPrivate: true }) + .waitForUrl(this.formfill) + .waitForVisible('') + .setValue('[name="04fullname"]', 'test') + .click('#submit') + }) + it('does not autofill in private tab', function * () { + yield this.app.client + .tabByIndex(1) + .waitForVisible('') + .click('[name="04fullname"]') + .click('[name="04fullname"]') + .windowByUrl(Brave.browserWindowUrl) + .waitForExist('contextMenuItemText', 500, true) + .tabByIndex(1) + .getValue('[name="04fullname"]').should.eventually.be.equal('') + }) + it('does not autofill in regular tab', function * () { + yield this.app.client + .tabByIndex(0) + .loadUrl(this.formfill + '?2') + .waitForVisible('') + .click('[name="04fullname"]') + .click('[name="04fullname"]') + .windowByUrl(Brave.browserWindowUrl) + .waitForExist('contextMenuItemText', 500, true) + .tabByIndex(0) + .getValue('[name="04fullname"]').should.eventually.be.equal('') + }) }) }) }) diff --git a/test/fixtures/formfill.html b/test/fixtures/formfill.html index b3755cc6775..01614d176e2 100644 --- a/test/fixtures/formfill.html +++ b/test/fixtures/formfill.html @@ -239,6 +239,7 @@

Form Fill

+

diff --git a/test/lib/brave.js b/test/lib/brave.js index 33239aa0a91..09b9e66c2a9 100644 --- a/test/lib/brave.js +++ b/test/lib/brave.js @@ -5,6 +5,7 @@ require('./coMocha') const path = require('path') const fs = require('fs') +const os = require('os') const {getTargetAboutUrl, isSourceAboutUrl} = require('../../js/lib/appUrlUtil') var chaiAsPromised = require('chai-as-promised') @@ -13,6 +14,30 @@ chai.use(chaiAsPromised) const Server = require('./server') +const generateUserDataDir = () => { + return path.join(os.tmpdir(), 'brave-test', (new Date().getTime()) + Math.floor(Math.random() * 1000).toString()) +} + +const rmDir = (dirPath) => { + try { + var files = fs.readdirSync(dirPath) + } catch (e) { + console.error(e) + return + } + if (files.length > 0) { + for (var i = 0; i < files.length; i++) { + var filePath = path.join(dirPath, files[i]) + if (fs.statSync(filePath).isFile()) { + fs.unlinkSync(filePath) + } else { + rmDir(filePath) + } + } + } + fs.rmdirSync(dirPath) +} + var promiseMapSeries = function (array, iterator) { var length = array.length var current = Promise.resolve() @@ -26,6 +51,7 @@ var promiseMapSeries = function (array, iterator) { return Promise.all(results) } +let userDataDir = generateUserDataDir() var exports = { keys: { COMMAND: '\ue03d', @@ -411,36 +437,29 @@ var exports = { this.app.client.waitUntilWindowLoaded().windowByUrl(exports.browserWindowUrl) }, - startApp: function (cleanSessionStore = true) { - if (cleanSessionStore) { - let ledgerDir = path.join(process.env.HOME, '.brave-test-ledger') - try { - fs.unlinkSync(path.join(process.env.HOME, '.brave-test-session-store-1')) - } catch (e) { - } - try { - ['publisher', 'state', 'scores', 'synopsis'].forEach((name) => { - try { - fs.unlinkSync(path.join(ledgerDir, `ledger-${name}-test.json`)) - } catch (e) { - } - }) - } catch (e) { - // probably ledgerDir does not exist yet - fs.mkdirSync(ledgerDir) - } + startApp: function () { + if (process.env.KEEP_USER_DATA_DIR) { + console.log('USER_DATA_DIR=' + userDataDir) + } + let env = { + NODE_ENV: 'test', + USER_DATA_DIR: userDataDir } this.app = new Application({ path: './node_modules/.bin/electron', - env: { - NODE_ENV: 'test' - }, - args: ['./', '--debug=5858', '--enable-logging', '--v=0'] + env, + args: ['./', '--debug=5858', '--enable-logging', '--v=1'] }) return this.app.start() }, - stopApp: function () { + stopApp: function (cleanSessionStore = true) { + if (cleanSessionStore) { + if (!process.env.KEEP_USER_DATA_DIR) { + userDataDir && rmDir(userDataDir) + } + userDataDir = generateUserDataDir() + } // this.app.client.getMainProcessLogs().then(function (logs) { // logs.forEach(function (log) { // console.log(log)