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

Commit

Permalink
fix and speed up tests
Browse files Browse the repository at this point in the history
auditors: @bbondy
  • Loading branch information
bridiver committed Oct 12, 2016
1 parent 44a0e98 commit f78430c
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 111 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"nsp": "^2.2.0",
"pre-commit": "brave/pre-commit",
"react-addons-perf": "^15.2.1",
"spectron": "^1.37.0",
"spectron": "brave/spectron",
"sqlite3": "^3.1.1",
"standard": "8.1.0",
"style-loader": "^0.13.0",
Expand Down
1 change: 0 additions & 1 deletion test/about/adblockTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('about:adblock', function () {
before(function * () {
const url = getTargetAboutUrl('about:adblock')
yield this.app.client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
1 change: 0 additions & 1 deletion test/about/extensionsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const aboutExtensionsUrl = getTargetAboutUrl('about:extensions')
describe('about:extensions', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
1 change: 0 additions & 1 deletion test/about/historyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe('about:history', function () {

before(function * () {
yield this.app.client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
28 changes: 15 additions & 13 deletions test/app/sessionStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,29 @@ const siteTags = require('../../js/constants/siteTags')
describe('sessionStore', function () {
function * setup (client) {
Brave.addCommands()
yield client
.waitUntilWindowLoaded()
.waitForBrowserWindow()
.waitForVisible(urlInput)
}

describe('state is preserved', function () {
Brave.beforeAllServerSetup(this)
before(function * () {
const page1Url = Brave.server.url('page1.html')
this.timeout(30000)
yield Brave.startApp()
yield setup(Brave.app.client)
yield Brave.app.client
.tabByUrl(Brave.newTabUrl)
.url(page1Url)
.waitForUrl(page1Url)
.waitForUrl(Brave.newTabUrl)
.loadUrl(page1Url)
.windowParentByUrl(page1Url)
.moveToObject(navigator)
.waitForExist(navigatorNotBookmarked)
yield Brave.app.client.addSite({
location: page1Url,
title: 'some page'
}, siteTags.BOOKMARK)
yield Brave.app.client
.moveToObject(navigator)
.waitForExist(navigatorBookmarked)
.waitUntil(function () {
return this.getValue(urlInput).then((val) => val === page1Url)
return this.getAppState().then((val) => {
let state = val.value
return state.sites.length === 1 && state.sites[0].location === page1Url
})
})
yield Brave.stopApp(false)
yield Brave.startApp()
Expand All @@ -49,14 +43,18 @@ describe('sessionStore', function () {
it('windowState by preserving open page', function * () {
const page1Url = Brave.server.url('page1.html')
yield Brave.app.client
.waitForUrl(page1Url)
.waitForBrowserWindow()
.moveToObject(urlInput)
.waitUntil(function () {
return this.getValue(urlInput).then((val) => val === page1Url)
})
})

it('appstate by preserving a bookmark', function * () {
yield Brave.app.client.waitForExist(navigatorBookmarked)
yield Brave.app.client
.waitForBrowserWindow()
.waitForExist(navigatorBookmarked)
})
})

Expand All @@ -75,6 +73,8 @@ describe('sessionStore', function () {
const timestamp = new Date().getTime()
let firstRunTimestamp
yield Brave.app.client
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitUntil(function () {
return this.getAppState().then((val) => {
firstRunTimestamp = val.value.firstRunTimestamp
Expand All @@ -89,6 +89,8 @@ describe('sessionStore', function () {
yield Brave.startApp()
yield setup(Brave.app.client)
yield Brave.app.client
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitUntil(function () {
return this.getAppState().then((val) => {
return (val.value.firstRunTimestamp === firstRunTimestamp)
Expand Down
1 change: 0 additions & 1 deletion test/components/autofillTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const expYear = new Date().getFullYear() + 2
describe('Autofill', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
1 change: 0 additions & 1 deletion test/components/bookmarksTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const siteTags = require('../../js/constants/siteTags')
describe('bookmark tests', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForEnabled(urlInput)
Expand Down
2 changes: 0 additions & 2 deletions test/components/bookmarksToolbarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ const assert = require('assert')

function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible('#window')
.waitForEnabled(urlInput)
}

Expand Down
7 changes: 4 additions & 3 deletions test/components/braveryPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')
describe('Bravery Panel', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down Expand Up @@ -213,6 +212,8 @@ describe('Bravery Panel', function () {
.then((blocked) => blocked === '2')
})
})
// TODO(bridiver) using slashdot won't provide reliable results so we should
// create our own iframe page with urls we expect to be blocked
it('detects blocked elements in iframe in private tab', function * () {
const url = Brave.server.url('slashdot.html')
yield this.app.client
Expand All @@ -223,7 +224,7 @@ describe('Bravery Panel', function () {
yield this.app.client
.waitUntil(function () {
return this.getText(adsBlockedStat)
.then((blocked) => Number(blocked) > 10)
.then((blocked) => Number(blocked) > 1)
})
})
it('detects blocked elements in iframe', function * () {
Expand All @@ -235,7 +236,7 @@ describe('Bravery Panel', function () {
yield this.app.client
.waitUntil(function () {
return this.getText(adsBlockedStat)
.then((blocked) => Number(blocked) > 10)
.then((blocked) => Number(blocked) > 1)
})
})
it('detects https upgrades in private tab', function * () {
Expand Down
1 change: 0 additions & 1 deletion test/components/clearBrowsingDataPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const messages = require('../../js/constants/messages')
describe('Clear Browsing Panel', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
1 change: 0 additions & 1 deletion test/components/errorPageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('errorPage', function () {

before(function * () {
yield this.app.client
.waitUntilWindowLoaded()
.waitForBrowserWindow()
.waitForVisible(urlInput)
})
Expand Down
21 changes: 17 additions & 4 deletions test/components/frameTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,18 @@ describe('clone tab', function () {
})

it('opens a new foreground tab', function * () {
let url1 = this.url1
yield this.app.client
.waitUntil(function () {
return this.getTabCount().then((count) => {
return count === 2
})
})
.waitUntil(function () {
return this.tabByIndex(1).getUrl().then((url) => {
return url === url1
})
})
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(this.webview1)
.waitForExist(this.webview2)
Expand All @@ -194,7 +200,6 @@ describe('clone tab', function () {

yield setup(this.app.client)
yield this.app.client
.waitUntilWindowLoaded()
.windowByUrl(Brave.browserWindowUrl)
.waitForUrl(Brave.newTabUrl)
.url(this.clickWithTargetPage)
Expand Down Expand Up @@ -301,8 +306,7 @@ describe('view source', function () {
yield setup(this.app.client)
yield this.app.client
.tabByIndex(0)
.url(this.url)
.waitForUrl(this.url)
.loadUrl(this.url)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('.tab[data-frame-key="1"]')
.waitForExist(this.webview1)
Expand All @@ -311,6 +315,11 @@ describe('view source', function () {
it('should open in new tab', function * () {
yield this.app.client
.ipcSend(messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE)
.waitUntil(function () {
return this.getTabCount().then((count) => {
return count === 2
})
})
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(this.webview2)
})
Expand All @@ -319,6 +328,11 @@ describe('view source', function () {
yield this.app.client
.setPinned(this.url, true)
.ipcSend(messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE)
.waitUntil(function () {
return this.getTabCount().then((count) => {
return count === 2
})
})
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(this.webview2)
})
Expand Down Expand Up @@ -359,7 +373,6 @@ describe('resource loading', function () {

function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
9 changes: 8 additions & 1 deletion test/components/ledgerPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const prefsUrl = 'about:preferences'

function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down Expand Up @@ -39,6 +38,7 @@ describe('Payments Panel', function () {
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.waitForVisible(walletSwitch)
.click(walletSwitch)
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
Expand All @@ -56,6 +56,7 @@ describe('Payments Panel', function () {
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.waitForVisible(walletSwitch)
.click(walletSwitch)
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
Expand All @@ -65,6 +66,7 @@ describe('Payments Panel', function () {
})
})
.tabByUrl(prefsUrl)
.waitForVisible(walletSwitch)
.click(walletSwitch)
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
Expand All @@ -82,6 +84,7 @@ describe('Payments Panel', function () {
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.waitForVisible(walletSwitch)
.click(walletSwitch)
.waitUntil(function () {
return this.getText(paymentsStatus).then((val) => val.includes('Creating'))
Expand All @@ -106,6 +109,7 @@ describe('synopsis', function () {
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.waitForVisible(walletSwitch)
.click(walletSwitch)
.waitUntil(function () {
return this.getText(paymentsStatus).then((val) => val.includes('Creating'))
Expand Down Expand Up @@ -153,6 +157,7 @@ describe('synopsis', function () {
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible('[data-l10n-id="publisher"]')
.click('[data-l10n-id="publisher"]')
.waitUntil(function () {
return this.getText(ledgerTable + ' a').then((text) => {
Expand All @@ -176,7 +181,9 @@ describe('synopsis', function () {
.loadUrl(prefsUrl)
.waitForVisible(paymentsTab)
.click(paymentsTab)
.waitForVisible('[data-l10n-id="publisher"]')
.click('[data-l10n-id="publisher"]')
.waitForVisible(ledgerTable + ' .switchBackground')
.click(ledgerTable + ' .switchBackground')
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
Expand Down
7 changes: 6 additions & 1 deletion test/components/navigationBarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const messages = require('../../js/constants/messages')
describe('navigationBar', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForEnabled(urlInput)
Expand Down Expand Up @@ -883,13 +882,19 @@ describe('navigationBar', function () {
// tab with typing
yield newFrame(this.app.client, 2)
yield this.app.client
.waitUntil(function () {
return this.getTabCount().then((count) => count === 2)
})
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
return this.keys('a').getValue(urlInput).then((val) => val === 'a')
})
// tab with loaded url
yield newFrame(this.app.client, 3)
yield this.app.client
.waitUntil(function () {
return this.getTabCount().then((count) => count === 3)
})
.tabByIndex(2)
.url(Brave.server.url('page1.html'))
.waitForUrl(Brave.server.url('page1.html'))
Expand Down
2 changes: 0 additions & 2 deletions test/components/notificationBarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {activeWebview, notificationBar, titleBar, urlInput} = require('../lib/sel
describe('notificationBar', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForBrowserWindow()
.waitForVisible(urlInput)
}
Expand Down Expand Up @@ -165,7 +164,6 @@ describe('notificationBar', function () {
describe('permissions state', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForBrowserWindow()
.waitForVisible(urlInput)
}
Expand Down
1 change: 0 additions & 1 deletion test/components/pinnedTabTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {urlInput, tabsTabs, pinnedTabsTabs} = require('../lib/selectors')
describe('pinnedTabs', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
1 change: 0 additions & 1 deletion test/components/tabPagesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const assert = require('assert')
describe('tab pages', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
1 change: 0 additions & 1 deletion test/components/tabTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {urlInput, backButton, forwardButton, activeTabTitle} = require('../lib/se
describe('tabs', function () {
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForVisible(urlInput)
Expand Down
Loading

1 comment on commit f78430c

@bbondy
Copy link
Member

@bbondy bbondy commented on f78430c Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.