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

Commit

Permalink
Merge pull request #7951 from NejcZdovc/hotfix/#7950-tests
Browse files Browse the repository at this point in the history
Automated tests fixes and refactoring
  • Loading branch information
NejcZdovc authored Apr 5, 2017
2 parents 387738a + 79e5f72 commit 952790b
Show file tree
Hide file tree
Showing 32 changed files with 556 additions and 720 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ before_install:
before_script:
- npm run download-sync-client
script:
- npm run testsuite
- BRAVE_TEST_COMMAND_LOGS=1 npm run testsuite
branches:
only:
- master
Expand Down
29 changes: 19 additions & 10 deletions app/browser/ads/adBlockUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,26 @@ const mapFilterType = {
*/
const shouldDoAdBlockCheck = (resourceType, firstPartyUrl, url, shouldCheckMainFrame) =>
firstPartyUrl.protocol &&
// By default first party hosts are allowed, but enable the check if a flag is specified in siteHacks
// By default first party hosts are allowed, but enable the check if a flag is specified in siteHacks
(
shouldCheckMainFrame ||
(resourceType !== 'mainFrame' &&
isThirdPartyHost(firstPartyUrl.hostname || '', url.hostname) ||
siteHacks[firstPartyUrl.hostname] && siteHacks[firstPartyUrl.hostname].allowFirstPartyAdblockChecks) &&
// Only check http and https for now
firstPartyUrl.protocol.startsWith('http') &&
// Only do adblock if the host isn't in the whitelist
!whitelistHosts.find((whitelistHost) => whitelistHost === url.hostname || url.hostname.endsWith('.' + whitelistHost)) &&
// Make sure there's a valid resource type before trying to use adblock
mapFilterType[resourceType] !== undefined
(
(
resourceType !== 'mainFrame' &&
isThirdPartyHost(firstPartyUrl.hostname || '', url.hostname)
) ||
(
siteHacks[firstPartyUrl.hostname] &&
siteHacks[firstPartyUrl.hostname].allowFirstPartyAdblockChecks
)
)
) &&
// Only check http and https for now
firstPartyUrl.protocol.startsWith('http') &&
// Only do adblock if the host isn't in the whitelist
!whitelistHosts.find((whitelistHost) => whitelistHost === url.hostname || url.hostname.endsWith('.' + whitelistHost)) &&
// Make sure there's a valid resource type before trying to use adblock
mapFilterType[resourceType] !== undefined

module.exports = {
mapFilterType,
Expand Down
1 change: 0 additions & 1 deletion app/renderer/components/preferences/payment/ledgerTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const aboutActions = require('../../../../../js/about/aboutActions')
const {SettingCheckbox, SiteSettingCheckbox} = require('../../settings')

class LedgerTable extends ImmutableComponent {

get synopsis () {
return this.props.ledgerData.get('synopsis')
}
Expand Down
2 changes: 1 addition & 1 deletion js/stores/eventStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const addPageView = (url, tabId) => {
tab.isDestroyed() ||
!tab.session.partition.startsWith('persist:')

if (url && isSourceAboutUrl(url) || isPrivate) {
if ((url && isSourceAboutUrl(url)) || isPrivate) {
url = null
}

Expand Down
2 changes: 1 addition & 1 deletion test/about/adblockTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ describe('about:adblock', function () {

it('lists adblock count', function * () {
yield this.app.client
.getText('[data-test-id="blockedCountTotal"]').should.eventually.be.equal('0')
.waitForTextValue('[data-test-id="blockedCountTotal"]', '0')
})
})
99 changes: 85 additions & 14 deletions test/about/bookmarksManagerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {urlInput} = require('../lib/selectors')
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')
const siteTags = require('../../js/constants/siteTags')
const aboutBookmarksUrl = getTargetAboutUrl('about:bookmarks')
const Immutable = require('immutable')

describe('about:bookmarks', function () {
const folderId = Math.random()
Expand All @@ -24,29 +25,99 @@ describe('about:bookmarks', function () {
const siteWithFavicon = Brave.server.url('favicon.html')
const favicon = Brave.server.url('img/test.ico')
const siteWithoutFavicon = Brave.server.url('page_favicon_not_found.html')
const sites = Immutable.fromJS([
{
location: siteWithFavicon,
title: 'Page with Favicon',
favicon: favicon,
tags: bookmarkTag,
parentFolderId: 0,
lastAccessedTime: lastVisit
},
{
location: siteWithoutFavicon,
title: 'Page without Favicon',
tags: bookmarkTag,
parentFolderId: 0,
lastAccessedTime: lastVisit
}
])
yield client
.addSite({ location: siteWithFavicon, title: 'Page with Favicon', favicon: favicon, tags: bookmarkTag, parentFolderId: 0, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
.addSite({ location: siteWithoutFavicon, title: 'Page without Favicon', tags: bookmarkTag, parentFolderId: 0, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
.addSiteList(sites)
.tabByIndex(0)
.loadUrl(aboutBookmarksUrl)
}

function * addDemoSites (client) {
yield client
.waitForBrowserWindow()
.addSite({
const sites = Immutable.fromJS([
{
customTitle: 'demo1',
folderId: folderId,
parentFolderId: 0,
tags: [siteTags.BOOKMARK_FOLDER]
}, siteTags.BOOKMARK_FOLDER)
.addSite({ location: 'https://brave.com', title: 'Brave', tags: bookmarkTag, parentFolderId: 0, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
.addSite({ location: 'https://brave.com/test', title: 'Test', customTitle: 'customTest', tags: bookmarkTag, parentFolderId: 0, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
.addSite({ location: 'https://www.youtube.com', tags: bookmarkTag, parentFolderId: 0, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
.addSite({ location: 'https://www.facebook.com', title: 'facebook', tags: bookmarkTag, parentFolderId: 0, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
.addSite({ location: 'https://duckduckgo.com', title: 'duckduckgo', tags: bookmarkTag, parentFolderId: folderId, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
.addSite({ location: 'https://google.com', title: 'Google', tags: bookmarkTag, parentFolderId: folderId, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
.addSite({ location: 'https://bing.com', title: 'Bing', tags: bookmarkTag, parentFolderId: folderId, lastAccessedTime: lastVisit }, siteTags.BOOKMARK)
},
{
location: 'https://brave.com',
title: 'Brave',
tags: bookmarkTag,
parentFolderId: 0,
lastAccessedTime: lastVisit
},
{
location: 'https://brave.com/test',
title: 'Test',
customTitle: 'customTest',
tags: bookmarkTag,
parentFolderId: 0,
lastAccessedTime: lastVisit
},
{
location: 'https://brave.com/test',
title: 'Test',
customTitle: 'customTest',
tags: bookmarkTag,
parentFolderId: 0,
lastAccessedTime: lastVisit
},
{
location: 'https://www.youtube.com',
tags: bookmarkTag,
parentFolderId: 0,
lastAccessedTime: lastVisit
},
{
location: 'https://www.facebook.com',
title: 'facebook',
tags: bookmarkTag,
parentFolderId: 0,
lastAccessedTime: lastVisit
},
{
location: 'https://duckduckgo.com',
title: 'duckduckgo',
tags: bookmarkTag,
parentFolderId: folderId,
lastAccessedTime: lastVisit
},
{
location: 'https://google.com',
title: 'Google',
tags: bookmarkTag,
parentFolderId: folderId,
lastAccessedTime: lastVisit
},
{
location: 'https://bing.com',
title: 'Bing',
tags: bookmarkTag,
parentFolderId: folderId,
lastAccessedTime: lastVisit
}
])

yield client
.waitForBrowserWindow()
.addSiteList(sites)
.tabByIndex(0)
.loadUrl(aboutBookmarksUrl)
}
Expand Down Expand Up @@ -202,7 +273,7 @@ describe('about:bookmarks', function () {
.waitForVisible('table.sortableTable tr.selected td.title[data-sort="Brave"]')
// Click the header; this should dismiss and release selection
.click('table.sortableTable th')
.waitForVisible('table.sortableTable tr.selected td.title[data-sort="Brave"]', 5000, true)
.waitForElementCount('table.sortableTable tr.selected td.title[data-sort="Brave"]', 0)
})
})

Expand Down
4 changes: 2 additions & 2 deletions test/about/historyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('about:history', function () {

it('does NOT use customTitle when displaying entries', function * () {
yield this.app.client
.waitForVisible('table.sortableTable td.title[data-sort="customTest"]', 1000, true)
.waitForElementCount('table.sortableTable td.title[data-sort="customTest"]', 0)
})

it('defaults to sorting table by time DESC', function * () {
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('about:history', function () {
.waitForVisible('table.sortableTable tr.selected td.title[data-sort="Brave"]')
// Click the search box; this should dismiss and release selection
.click('input#historySearch')
.waitForVisible('table.sortableTable tr.selected td.title[data-sort="Brave"]', 5000, true)
.waitForElementCount('table.sortableTable tr.selected td.title[data-sort="Brave"]', 0)
})
it('does not lose selection if table is sorted', function * () {
yield this.app.client
Expand Down
18 changes: 8 additions & 10 deletions test/about/ledgerPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('Regular payment panel tests', function () {
.click(paymentsTab)
.waitForVisible(paymentsWelcomePage)
.waitForVisible(walletSwitch)
.waitForVisible(advancedSettingsButton, 100, true)
.waitForElementCount(advancedSettingsButton, 0)
})

it('advanced settings is visible when payments are enabled', function * () {
Expand Down Expand Up @@ -246,16 +246,14 @@ describe('synopsis', function () {

it('no table if empty synopsis', function * () {
yield this.app.client
.isExisting(ledgerTable).then((isExisting) => isExisting === false)
.waitForElementCount(ledgerTable, 0)
})

it('creates synopsis table after visiting a site', function * () {
var site1 = 'http://web.mit.edu/zyan/Public/wait.html'
const site1 = 'http://web.mit.edu/zyan/Public/wait.html'
yield this.app.client
.url(site1)
.waitUntil(function () {
return this.getText('div').then((val) => val === 'done')
})
.waitForTextValue('div', 'done')
.windowByUrl(Brave.browserWindowUrl)
.tabByUrl(site1)
.loadUrl(prefsUrl)
Expand All @@ -265,9 +263,9 @@ describe('synopsis', function () {
})

it('can sort synopsis table', function * () {
var site1 = 'http://web.mit.edu/zyan/Public/wait.html'
var site2 = 'http://example.com/'
var site3 = 'https://www.eff.org/'
const site1 = 'http://web.mit.edu/zyan/Public/wait.html'
const site2 = 'http://example.com/'
const site3 = 'https://www.eff.org/'
yield this.app.client
.loadUrl(site1)
.windowByUrl(Brave.browserWindowUrl)
Expand Down Expand Up @@ -300,7 +298,7 @@ describe('synopsis', function () {
})

it('can disable site', function * () {
var site1 = 'https://www.eff.org/'
const site1 = 'https://www.eff.org/'
yield this.app.client
.loadUrl(site1)
.loadUrl(prefsUrl)
Expand Down
28 changes: 5 additions & 23 deletions test/about/preferencesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ describe('General Panel', function () {
.loadUrl(prefsUrl)
.waitForVisible(homepageInput)
.click(homepageInput)
.keys(Brave.keys.END)
.keys('а')
.waitUntil(function () {
return this.getValue(homepageInput).then((val) => {
return val === 'https://www.brave.xn--com-8cd/'
})
})
.keys([Brave.keys.END, 'а'])
.waitForInputText(homepageInput, 'https://www.brave.xn--com-8cd/')
})

it('homepage can be backspaced', function * () {
Expand All @@ -47,16 +42,8 @@ describe('General Panel', function () {
.waitForVisible(homepageInput)
.click(homepageInput)
.keys(Brave.keys.END)
.keys('/')
.keys('1')
.keys(Brave.keys.BACKSPACE)
.keys(Brave.keys.BACKSPACE)
.keys(Brave.keys.BACKSPACE)
.waitUntil(function () {
return this.getValue(homepageInput).then((val) => {
return val === 'https://www.brave.co'
})
})
.typeText(homepageInput, ['/', '1', Brave.keys.BACKSPACE, Brave.keys.BACKSPACE, Brave.keys.BACKSPACE], 'https://www.brave.com')
.waitForInputText(homepageInput, 'https://www.brave.co')
})

it('multiple homepages direct input', function * () {
Expand All @@ -66,12 +53,7 @@ describe('General Panel', function () {
.waitForVisible(homepageInput)
.click(homepageInput)
.keys(Brave.keys.END)
.keys('|https://duckduckgo.com')
.waitUntil(function () {
return this.getValue(homepageInput).then((val) => {
return val === 'https://www.brave.com/|https://duckduckgo.com'
})
})
.typeText(homepageInput, '|https://duckduckgo.com', 'https://www.brave.com/')
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/about/stylesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ describe('about:styles', function () {

it('displays the title', function * () {
yield this.app.client
.getText('.typography').should.eventually.be.equal('Typography')
.waitForTextValue('.typography', 'Typography')
})
})
28 changes: 5 additions & 23 deletions test/app/renderer/components/messageBoxTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ describe('MessageBox component tests', function () {

function * showsExpectedMessage (client) {
yield client
.getText(msgBoxMessage).then((val) => {
// console.log('expected: ' + alertText + '; actual: ' + val)
assert(val === alertText)
})
.waitForTextValue(msgBoxMessage, alertText)
}

function * storesDetailsInTabState (client) {
Expand Down Expand Up @@ -205,12 +202,7 @@ describe('MessageBox component tests', function () {
// verify link was followed
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.waitUntil(function () {
return this.getText('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]')
.then((title) => {
return title === 'Page 2'
})
})
.waitForTextValue('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]', 'Page 2')
})

it('lets you use the back button', function * () {
Expand All @@ -221,33 +213,23 @@ describe('MessageBox component tests', function () {

// verify page is previous
yield this.app.client
.waitUntil(function () {
return this.getText('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]')
.then((title) => {
return title === 'Page 2'
})
})
.waitForTextValue('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]', 'Page 2')
})

it('lets you use the forward button', function * () {
// click back button
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.leftClick(backButton)
.waitForVisible(forwardButton + '[disabled]', 1000, true)
.waitForElementCount(forwardButton + '[disabled]', 0)

// click forward button
yield this.app.client
.leftClick(forwardButton)

// verify page is previous
yield this.app.client
.waitUntil(function () {
return this.getText('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]')
.then((title) => {
return title === 'Page 1'
})
})
.waitForTextValue('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]', 'Page 1')
})

it('original tab does not respond to escape or enter being pressed', function * () {
Expand Down
Loading

0 comments on commit 952790b

Please sign in to comment.