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 #6006 from bsclifton/chromium54-clifton
Browse files Browse the repository at this point in the history
First steps at getting the spectron/webdriver tests working
  • Loading branch information
bsclifton authored Dec 5, 2016
2 parents 45f0d8d + 90bc8f4 commit b050724
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 49 deletions.
1 change: 1 addition & 0 deletions app/extensions/brave/index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; form-action http://localhost:*; referrer no-referrer; script-src 'self' http://localhost:*; connect-src 'self' https://s3.amazonaws.com/adblock-data/ https://s3.amazonaws.com/safe-browsing-data/ https://s3.amazonaws.com/tracking-protection-data/ https://s3.amazonaws.com/https-everywhere-data/ http://localhost:* ws://localhost:* https://suggestqueries.google.com https://ac.duckduckgo.com https://completion.amazon.com https://search.yahoo.com https://api.bing.com https://www.startpage.com https://brave-download.global.ssl.fastly.net https://brave-laptop-updates.global.ssl.fastly.net https://brave-download.global.ssl.fastly.net https://laptop-updates-pre.brave.com https://brave-laptop-updates-pre.brave.com; style-src 'unsafe-inline'; font-src 'self' http://localhost:*; img-src 'self' * data: file:; object-src 'self'; plugin-types application/browser-plugin">
<title>Brave</title>
<script src="index-load-script.js" defer></script>
<script src="gen/lib.devTools.js" async></script>
<script src="ext/l20n.min.js" async></script>
<link rel="localization" href="locales/{locale}/app.properties">
<link rel="localization" href="locales/{locale}/common.properties">
Expand Down
2 changes: 2 additions & 0 deletions app/extensions/brave/index-load-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ document.querySelector('#webpackLoading').style.display = 'block'
createScript(appEntry).catch(function () {
document.querySelector('#webpackLoading').style.display = 'none'
document.querySelector('#setupError').style.display = 'block'
}).then(() => {
createScript(baseHref + '/gen/lib.devTools.js')
})
1 change: 1 addition & 0 deletions app/extensions/brave/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; form-action 'none'; referrer no-referrer; script-src 'self'; img-src * data: file:; style-src 'self' 'unsafe-inline'; font-src 'self'; connect-src 'self' https://s3.amazonaws.com/adblock-data/ https://s3.amazonaws.com/safe-browsing-data/ https://s3.amazonaws.com/tracking-protection-data/ https://s3.amazonaws.com/https-everywhere-data/ https://suggestqueries.google.com https://ac.duckduckgo.com https://completion.amazon.com https://search.yahoo.com https://api.bing.com https://www.startpage.com https://infogalactic.com https://brave-download.global.ssl.fastly.net https://brave-laptop-updates.global.ssl.fastly.net https://laptop-updates-pre.brave.com https://brave-laptop-updates-pre.brave.com; object-src 'self'; plugin-types application/browser-plugin"/>
<title>Brave</title>
<script src="gen/app.entry.js" async></script>
<script src="gen/lib.devTools.js" async></script>
<script src="ext/l20n.min.js" async></script>
<link rel="localization" href="locales/{locale}/app.properties"/>
<link rel="localization" href="locales/{locale}/common.properties"/>
Expand Down
10 changes: 10 additions & 0 deletions js/devTools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const electron = require('electron')
const appActions = require('./actions/appActions')

module.exports = function (name) {
if (name === 'electron') {
return electron
} else if (name === 'appActions') {
return appActions
}
}
22 changes: 4 additions & 18 deletions js/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const messages = require('./constants/messages')
const siteUtil = require('./state/siteUtil')
const urlParse = require('url').parse
const settings = require('./constants/settings')
const { siteHacks } = require('./data/siteHacks')
const {siteHacks} = require('./data/siteHacks')
const urlutil = require('./lib/urlutil')

let flashInstalled = false
const notificationCallbacks = {}
Expand All @@ -43,16 +44,6 @@ const getPepperFlashPath = () => {
return pluginPath
}

/**
* Checks whether a link is an Flash installer URL.
* @param {string} url
* @return {boolean}
*/
const isFlashInstallUrl = (url) => {
const adobeRegex = new RegExp('//(get\\.adobe\\.com/([a-z_-]+/)*flashplayer|www\\.macromedia\\.com/go/getflash|www\\.adobe\\.com/go/getflash)', 'i')
return adobeRegex.test(url)
}

/**
* Shows a Flash CtP notification if Flash is installed and enabled.
* If not enabled, alert user that Flash is installed.
Expand Down Expand Up @@ -169,12 +160,7 @@ const shouldInterceptFlash = (url, isPrivate) => {
return false
}

const parsed = urlParse(url)
const exemptHostPattern = new RegExp('(\\.adobe\\.com|www\\.google(\\.\\w+){1,2}|^duckduckgo\\.com|^search\\.yahoo\\.com)$')
return parsed.hostname &&
['http:', 'https:'].includes(parsed.protocol) &&
!exemptHostPattern.test(parsed.hostname) &&
!['/search', '/search/'].includes(parsed.pathname)
return urlutil.shouldInterceptFlash(url)
}

function handleFlashCTP (details, isPrivate) {
Expand Down Expand Up @@ -221,7 +207,7 @@ function handleFlashInstallUrl (details, isPrivate) {
}

const origin = siteUtil.getOrigin(mainFrameUrl)
if (origin && isFlashInstallUrl(details.url) &&
if (origin && urlutil.isFlashInstallUrl(details.url) &&
shouldInterceptFlash(mainFrameUrl, isPrivate)) {
result.cancel = true
showFlashNotification(origin, details.tabId, details.url)
Expand Down
42 changes: 22 additions & 20 deletions test/lib/brave.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals devTools */
var Application = require('spectron').Application
var chai = require('chai')
require('./coMocha')
Expand Down Expand Up @@ -153,13 +154,13 @@ var exports = {
addCommands: function () {
this.app.client.addCommand('ipcSend', function (message, ...param) {
return this.execute(function (message, ...param) {
return require('electron').remote.getCurrentWindow().webContents.send(message, ...param)
return devTools('electron').remote.getCurrentWindow().webContents.send(message, ...param)
}, message, ...param).then((response) => response.value)
})

this.app.client.addCommand('ipcSendRenderer', function (message, ...param) {
return this.execute(function (message, ...param) {
return require('electron').ipcRenderer.send(message, ...param)
return devTools('electron').ipcRenderer.send(message, ...param)
}, message, ...param).then((response) => response.value)
})

Expand Down Expand Up @@ -310,7 +311,7 @@ var exports = {
this.app.client.addCommand('showFindbar', function (show, key = 1) {
return this.execute(function (show, key) {
window.windowActions.setFindbarShown(Object.assign({
windowId: require('electron').remote.getCurrentWindow().id,
windowId: devTools('electron').remote.getCurrentWindow().id,
key
}), show !== false)
}, show, key)
Expand All @@ -328,21 +329,21 @@ var exports = {
return this.execute(function (location, isPinned, options) {
var Immutable = require('immutable')
window.windowActions.setPinned(Immutable.fromJS(Object.assign({
windowId: require('electron').remote.getCurrentWindow().id,
windowId: devTools('electron').remote.getCurrentWindow().id,
location
}, options)), isPinned)
}, location, isPinned, options)
})

this.app.client.addCommand('ipcOn', function (message, fn) {
return this.execute(function (message, fn) {
return require('electron').remote.getCurrentWindow().webContents.on(message, fn)
return devTools('electron').remote.getCurrentWindow().webContents.on(message, fn)
}, message, fn).then((response) => response.value)
})

this.app.client.addCommand('newWindowAction', function (frameOpts, browserOpts) {
return this.execute(function () {
return require('../../../js/actions/appActions').newWindow()
return devTools('appActions').newWindow()
}, frameOpts, browserOpts).then((response) => response.value)
})

Expand All @@ -354,7 +355,7 @@ var exports = {
*/
this.app.client.addCommand('addSite', function (siteDetail, tag) {
return this.execute(function (siteDetail, tag) {
return require('../../../js/actions/appActions').addSite(siteDetail, tag)
return devTools('appActions').addSite(siteDetail, tag)
}, siteDetail, tag).then((response) => response.value)
})

Expand All @@ -365,7 +366,7 @@ var exports = {
*/
this.app.client.addCommand('addSiteList', function (siteDetail) {
return this.execute(function (siteDetail) {
return require('../../../js/actions/appActions').addSite(siteDetail)
return devTools('appActions').addSite(siteDetail)
}, siteDetail).then((response) => response.value)
})

Expand All @@ -377,7 +378,7 @@ var exports = {
*/
this.app.client.addCommand('setResourceEnabled', function (resourceName, enabled) {
return this.execute(function (resourceName, enabled) {
return require('../../../js/actions/appActions').setResourceEnabled(resourceName, enabled)
return devTools('appActions').setResourceEnabled(resourceName, enabled)
}, resourceName, enabled).then((response) => response.value)
})

Expand All @@ -389,7 +390,7 @@ var exports = {
*/
this.app.client.addCommand('removeSite', function (siteDetail, tag) {
return this.execute(function (siteDetail, tag) {
return require('../../../js/actions/appActions').removeSite(siteDetail, tag)
return devTools('appActions').removeSite(siteDetail, tag)
}, siteDetail, tag).then((response) => response.value)
})

Expand All @@ -401,7 +402,7 @@ var exports = {
*/
this.app.client.addCommand('changeSetting', function (key, value) {
return this.execute(function (key, value) {
return require('../../../js/actions/appActions').changeSetting(key, value)
return devTools('appActions').changeSetting(key, value)
}, key, value).then((response) => response.value)
})

Expand All @@ -413,7 +414,7 @@ var exports = {
*/
this.app.client.addCommand('changeSiteSetting', function (hostPattern, key, value) {
return this.execute(function (hostPattern, key, value) {
return require('../../../js/actions/appActions').changeSiteSetting(hostPattern, key, value)
return devTools('appActions').changeSiteSetting(hostPattern, key, value)
}, hostPattern, key, value).then((response) => response.value)
})

Expand All @@ -424,29 +425,29 @@ var exports = {
*/
this.app.client.addCommand('clearAppData', function (clearDataDetail) {
return this.execute(function (clearDataDetail) {
return require('../../../js/actions/appActions').clearAppData(clearDataDetail)
return devTools('appActions').clearAppData(clearDataDetail)
}, clearDataDetail).then((response) => response.value)
})

this.app.client.addCommand('getDefaultWindowHeight', function () {
return this.execute(function () {
let screen = require('electron').screen
let screen = devTools('electron').screen
let primaryDisplay = screen.getPrimaryDisplay()
return primaryDisplay.workAreaSize.height
}).then((response) => response.value)
})

this.app.client.addCommand('getDefaultWindowWidth', function () {
return this.execute(function () {
let screen = require('electron').screen
let screen = devTools('electron').screen
let primaryDisplay = screen.getPrimaryDisplay()
return primaryDisplay.workAreaSize.width
}).then((response) => response.value)
})

this.app.client.addCommand('getPrimaryDisplayHeight', function () {
return this.execute(function () {
let screen = require('electron').screen
let screen = devTools('electron').screen
return screen.getPrimaryDisplay().bounds.height
}).then((response) => response.value)
})
Expand All @@ -459,14 +460,14 @@ var exports = {

this.app.client.addCommand('getPrimaryDisplayWidth', function () {
return this.execute(function () {
let screen = require('electron').screen
let screen = devTools('electron').screen
return screen.getPrimaryDisplay().bounds.width
}).then((response) => response.value)
})

this.app.client.addCommand('resizeWindow', function (width, height) {
return this.execute(function (width, height) {
return require('electron').remote.getCurrentWindow().setSize(width, height)
return devTools('electron').remote.getCurrentWindow().setSize(width, height)
}, width, height).then((response) => response.value)
})

Expand Down Expand Up @@ -527,7 +528,7 @@ var exports = {
internal.viewInstanceId
// This allows you to send more args than just the event itself like would only
// be possible with dispatchEvent.
require('electron').ipcRenderer.emit('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + internal.viewInstanceId, ...params)
devTools('electron').ipcRenderer.emit('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + internal.viewInstanceId, ...params)
}, frameKey, eventName, ...params).then((response) => response.value)
})

Expand Down Expand Up @@ -570,7 +571,8 @@ var exports = {
quitTimeout: 0,
path: './node_modules/.bin/electron',
env,
args: ['./', '--debug=5858', '--enable-logging', '--v=1']
args: ['./', '--debug=5858', '--enable-logging', '--v=1'],
requireName: 'devTools'
})
return this.app.start()
},
Expand Down
27 changes: 16 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function config () {
exclude: [
/node_modules/,
/\.min.js$/,
path.resolve(__dirname, 'app', 'browser', '*'),
path.resolve(__dirname, 'app', 'extensions', '*')
],
loader: 'babel'
Expand Down Expand Up @@ -106,24 +107,28 @@ function merge (config, env) {
}

var app = {
name: 'app',
target: 'web',
entry: ['./js/entry.js'],
entry: {
app: [ path.resolve(__dirname, 'js', 'entry.js') ],
aboutPages: [ path.resolve(__dirname, 'js', 'about', 'entry.js') ]
},
output: {
path: path.resolve(__dirname, 'app', 'extensions', 'brave', 'gen'),
filename: 'app.entry.js',
filename: '[name].entry.js',
publicPath: './gen/'
}
}

var aboutPages = {
name: 'about',
var devTools = {
target: 'web',
entry: ['./js/about/entry.js'],
entry: {
devTools: [ path.resolve(__dirname, 'js', 'devTools.js') ]
},
output: {
path: path.resolve(__dirname, 'app', 'extensions', 'brave', 'gen'),
filename: 'aboutPages.entry.js',
publicPath: './gen/'
filename: 'lib.[name].js',
publicPath: './gen/',
library: '[name]'
}
}

Expand All @@ -141,17 +146,17 @@ var webtorrentPage = {
module.exports = {
development: [
merge(app, development()),
merge(aboutPages, development()),
merge(devTools, development()),
merge(webtorrentPage, development())
],
production: [
merge(app, production()),
merge(aboutPages, production()),
merge(devTools, development()),
merge(webtorrentPage, production())
],
test: [
merge(app, production()),
merge(aboutPages, production()),
merge(devTools, development()),
merge(webtorrentPage, production())
]
}[env]

0 comments on commit b050724

Please sign in to comment.