Merge remote-tracking branch 'origin/master' into renaesop_master
This commit is contained in:
commit
84a9b6a42d
336 changed files with 16704 additions and 2418 deletions
|
@ -1178,7 +1178,6 @@ describe('BrowserWindow module', function () {
|
|||
}
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?allocate-memory'))
|
||||
w.webContents.openDevTools({mode: 'detach'})
|
||||
ipcMain.once('answer', function (event, {bytesBeforeOpen, bytesAfterOpen, bytesAfterClose}) {
|
||||
const memoryIncreaseByOpen = bytesAfterOpen - bytesBeforeOpen
|
||||
const memoryDecreaseByClose = bytesAfterOpen - bytesAfterClose
|
||||
|
@ -1190,6 +1189,137 @@ describe('BrowserWindow module', function () {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
// see #9387
|
||||
it('properly manages remote object references after page reload', (done) => {
|
||||
w.destroy()
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
preload: preload,
|
||||
sandbox: true
|
||||
}
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?reload-remote'))
|
||||
|
||||
ipcMain.on('get-remote-module-path', (event) => {
|
||||
event.returnValue = path.join(fixtures, 'module', 'hello.js')
|
||||
})
|
||||
|
||||
let reload = false
|
||||
ipcMain.on('reloaded', (event) => {
|
||||
event.returnValue = reload
|
||||
reload = !reload
|
||||
})
|
||||
|
||||
ipcMain.once('reload', (event) => {
|
||||
event.sender.reload()
|
||||
})
|
||||
|
||||
ipcMain.once('answer', (event, arg) => {
|
||||
ipcMain.removeAllListeners('reloaded')
|
||||
ipcMain.removeAllListeners('get-remote-module-path')
|
||||
assert.equal(arg, 'hi')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('properly manages remote object references after page reload in child window', (done) => {
|
||||
w.destroy()
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
preload: preload,
|
||||
sandbox: true
|
||||
}
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?reload-remote-child'))
|
||||
|
||||
ipcMain.on('get-remote-module-path', (event) => {
|
||||
event.returnValue = path.join(fixtures, 'module', 'hello-child.js')
|
||||
})
|
||||
|
||||
let reload = false
|
||||
ipcMain.on('reloaded', (event) => {
|
||||
event.returnValue = reload
|
||||
reload = !reload
|
||||
})
|
||||
|
||||
ipcMain.once('reload', (event) => {
|
||||
event.sender.reload()
|
||||
})
|
||||
|
||||
ipcMain.once('answer', (event, arg) => {
|
||||
ipcMain.removeAllListeners('reloaded')
|
||||
ipcMain.removeAllListeners('get-remote-module-path')
|
||||
assert.equal(arg, 'hi child window')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('nativeWindowOpen option', () => {
|
||||
beforeEach(() => {
|
||||
w.destroy()
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nativeWindowOpen: true
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('opens window of about:blank with cross-scripting enabled', (done) => {
|
||||
ipcMain.once('answer', (event, content) => {
|
||||
assert.equal(content, 'Hello')
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-blank.html'))
|
||||
})
|
||||
|
||||
it('opens window of same domain with cross-scripting enabled', (done) => {
|
||||
ipcMain.once('answer', (event, content) => {
|
||||
assert.equal(content, 'Hello')
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-file.html'))
|
||||
})
|
||||
|
||||
if (process.platform !== 'win32' || process.execPath.toLowerCase().indexOf('\\out\\d\\') === -1) {
|
||||
it('loads native addons correctly after reload', (done) => {
|
||||
ipcMain.once('answer', (event, content) => {
|
||||
assert.equal(content, 'function')
|
||||
ipcMain.once('answer', (event, content) => {
|
||||
assert.equal(content, 'function')
|
||||
done()
|
||||
})
|
||||
w.reload()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-native-addon.html'))
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('nativeWindowOpen + contextIsolation options', () => {
|
||||
beforeEach(() => {
|
||||
w.destroy()
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nativeWindowOpen: true,
|
||||
contextIsolation: true,
|
||||
preload: path.join(fixtures, 'api', 'native-window-open-isolated-preload.js')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('opens window with cross-scripting enabled from isolated context', (done) => {
|
||||
ipcMain.once('answer', (event, content) => {
|
||||
assert.equal(content, 'Hello')
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-isolated.html'))
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -1214,6 +1344,60 @@ describe('BrowserWindow module', function () {
|
|||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-empty-string.html'))
|
||||
})
|
||||
|
||||
it('emits for each close attempt', function (done) {
|
||||
var beforeUnloadCount = 0
|
||||
w.on('onbeforeunload', function () {
|
||||
beforeUnloadCount++
|
||||
if (beforeUnloadCount < 3) {
|
||||
w.close()
|
||||
} else if (beforeUnloadCount === 3) {
|
||||
done()
|
||||
}
|
||||
})
|
||||
w.webContents.once('did-finish-load', function () {
|
||||
w.close()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html'))
|
||||
})
|
||||
|
||||
it('emits for each reload attempt', function (done) {
|
||||
var beforeUnloadCount = 0
|
||||
w.on('onbeforeunload', function () {
|
||||
beforeUnloadCount++
|
||||
if (beforeUnloadCount < 3) {
|
||||
w.reload()
|
||||
} else if (beforeUnloadCount === 3) {
|
||||
done()
|
||||
}
|
||||
})
|
||||
w.webContents.once('did-finish-load', function () {
|
||||
w.webContents.once('did-finish-load', function () {
|
||||
assert.fail('Reload was not prevented')
|
||||
})
|
||||
w.reload()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html'))
|
||||
})
|
||||
|
||||
it('emits for each navigation attempt', function (done) {
|
||||
var beforeUnloadCount = 0
|
||||
w.on('onbeforeunload', function () {
|
||||
beforeUnloadCount++
|
||||
if (beforeUnloadCount < 3) {
|
||||
w.loadURL('about:blank')
|
||||
} else if (beforeUnloadCount === 3) {
|
||||
done()
|
||||
}
|
||||
})
|
||||
w.webContents.once('did-finish-load', function () {
|
||||
w.webContents.once('did-finish-load', function () {
|
||||
assert.fail('Navigation was not prevented')
|
||||
})
|
||||
w.loadURL('about:blank')
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('new-window event', function () {
|
||||
|
@ -2171,6 +2355,8 @@ describe('BrowserWindow module', function () {
|
|||
beforeEach(function () {
|
||||
if (w != null) w.destroy()
|
||||
w = new BrowserWindow({
|
||||
width: 100,
|
||||
height: 100,
|
||||
show: false,
|
||||
webPreferences: {
|
||||
backgroundThrottling: false,
|
||||
|
@ -2179,9 +2365,12 @@ describe('BrowserWindow module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
it('creates offscreen window', function (done) {
|
||||
w.webContents.once('paint', function (event, rect, data, size) {
|
||||
it('creates offscreen window with correct size', function (done) {
|
||||
w.webContents.once('paint', function (event, rect, data) {
|
||||
assert.notEqual(data.length, 0)
|
||||
let size = data.getSize()
|
||||
assertWithinDelta(size.width, 100, 2, 'width')
|
||||
assertWithinDelta(size.height, 100, 2, 'height')
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
||||
|
@ -2202,7 +2391,7 @@ describe('BrowserWindow module', function () {
|
|||
|
||||
describe('window.webContents.isPainting()', function () {
|
||||
it('returns whether is currently painting', function (done) {
|
||||
w.webContents.once('paint', function (event, rect, data, size) {
|
||||
w.webContents.once('paint', function (event, rect, data) {
|
||||
assert.equal(w.webContents.isPainting(), true)
|
||||
done()
|
||||
})
|
||||
|
@ -2226,7 +2415,7 @@ describe('BrowserWindow module', function () {
|
|||
w.webContents.on('dom-ready', function () {
|
||||
w.webContents.stopPainting()
|
||||
w.webContents.startPainting()
|
||||
w.webContents.once('paint', function (event, rect, data, size) {
|
||||
w.webContents.once('paint', function (event, rect, data) {
|
||||
assert.equal(w.webContents.isPainting(), true)
|
||||
done()
|
||||
})
|
||||
|
@ -2237,7 +2426,7 @@ describe('BrowserWindow module', function () {
|
|||
|
||||
describe('window.webContents.getFrameRate()', function () {
|
||||
it('has default frame rate', function (done) {
|
||||
w.webContents.once('paint', function (event, rect, data, size) {
|
||||
w.webContents.once('paint', function (event, rect, data) {
|
||||
assert.equal(w.webContents.getFrameRate(), 60)
|
||||
done()
|
||||
})
|
||||
|
@ -2249,7 +2438,7 @@ describe('BrowserWindow module', function () {
|
|||
it('sets custom frame rate', function (done) {
|
||||
w.webContents.on('dom-ready', function () {
|
||||
w.webContents.setFrameRate(30)
|
||||
w.webContents.once('paint', function (event, rect, data, size) {
|
||||
w.webContents.once('paint', function (event, rect, data) {
|
||||
assert.equal(w.webContents.getFrameRate(), 30)
|
||||
done()
|
||||
})
|
||||
|
|
|
@ -9,6 +9,7 @@ const url = require('url')
|
|||
const {closeWindow} = require('./window-helpers')
|
||||
|
||||
const {remote} = require('electron')
|
||||
const isCI = remote.getGlobal('isCi')
|
||||
const {app, BrowserWindow, crashReporter} = remote.require('electron')
|
||||
|
||||
describe('crashReporter module', function () {
|
||||
|
@ -16,6 +17,12 @@ describe('crashReporter module', function () {
|
|||
return
|
||||
}
|
||||
|
||||
// FIXME internal Linux CI is failing when it detects a process crashes
|
||||
// which is a false positive here since crashes are explicitly triggered
|
||||
if (isCI && process.platform === 'linux') {
|
||||
return
|
||||
}
|
||||
|
||||
var originalTempDirectory = null
|
||||
var tempDirectory = null
|
||||
|
||||
|
|
|
@ -324,6 +324,20 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('getOSProcessId()', function () {
|
||||
it('returns a valid procress id', function (done) {
|
||||
assert.strictEqual(w.webContents.getOSProcessId(), 0)
|
||||
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
const pid = w.webContents.getOSProcessId()
|
||||
assert.equal(typeof pid, 'number')
|
||||
assert(pid > 0, `pid ${pid} is not greater than 0`)
|
||||
done()
|
||||
})
|
||||
w.loadURL('about:blank')
|
||||
})
|
||||
})
|
||||
|
||||
describe('zoom api', () => {
|
||||
const zoomScheme = remote.getGlobal('zoomScheme')
|
||||
const hostZoomMap = {
|
||||
|
@ -543,6 +557,31 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('will-prevent-unload event', function () {
|
||||
it('does not emit if beforeunload returns undefined', function (done) {
|
||||
w.once('closed', function () {
|
||||
done()
|
||||
})
|
||||
w.webContents.on('will-prevent-unload', function (e) {
|
||||
assert.fail('should not have fired')
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-undefined.html'))
|
||||
})
|
||||
|
||||
it('emits if beforeunload returns false', (done) => {
|
||||
w.webContents.on('will-prevent-unload', () => {
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
||||
})
|
||||
|
||||
it('supports calling preventDefault on will-prevent-unload events', function (done) {
|
||||
ipcRenderer.send('prevent-next-will-prevent-unload', w.webContents.id)
|
||||
w.once('closed', () => done())
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('destroy()', () => {
|
||||
let server
|
||||
|
||||
|
|
|
@ -149,8 +149,6 @@ describe('chromium feature', function () {
|
|||
})
|
||||
|
||||
describe('navigator.serviceWorker', function () {
|
||||
var url = 'file://' + fixtures + '/pages/service-worker/index.html'
|
||||
|
||||
it('should register for file scheme', function (done) {
|
||||
w = new BrowserWindow({
|
||||
show: false
|
||||
|
@ -169,7 +167,49 @@ describe('chromium feature', function () {
|
|||
})
|
||||
}
|
||||
})
|
||||
w.loadURL(url)
|
||||
w.loadURL(`file://${fixtures}/pages/service-worker/index.html`)
|
||||
})
|
||||
|
||||
it('should register for intercepted file scheme', function (done) {
|
||||
const customSession = session.fromPartition('intercept-file')
|
||||
customSession.protocol.interceptBufferProtocol('file', function (request, callback) {
|
||||
let file = url.parse(request.url).pathname
|
||||
// Remove leading slash before drive letter on Windows
|
||||
if (file[0] === '/' && process.platform === 'win32') {
|
||||
file = file.slice(1)
|
||||
}
|
||||
const content = fs.readFileSync(path.normalize(file))
|
||||
const ext = path.extname(file)
|
||||
let type = 'text/html'
|
||||
if (ext === '.js') {
|
||||
type = 'application/javascript'
|
||||
}
|
||||
callback({data: content, mimeType: type})
|
||||
}, function (error) {
|
||||
if (error) done(error)
|
||||
})
|
||||
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
session: customSession
|
||||
}
|
||||
})
|
||||
w.webContents.on('ipc-message', function (event, args) {
|
||||
if (args[0] === 'reload') {
|
||||
w.webContents.reload()
|
||||
} else if (args[0] === 'error') {
|
||||
done('unexpected error : ' + args[1])
|
||||
} else if (args[0] === 'response') {
|
||||
assert.equal(args[1], 'Hello from serviceWorker!')
|
||||
customSession.clearStorageData({
|
||||
storages: ['serviceworkers']
|
||||
}, function () {
|
||||
customSession.protocol.uninterceptProtocol('file', (error) => done(error))
|
||||
})
|
||||
}
|
||||
})
|
||||
w.loadURL(`file://${fixtures}/pages/service-worker/index.html`)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
17
spec/fixtures/api/beforeunload-false-prevent3.html
vendored
Normal file
17
spec/fixtures/api/beforeunload-false-prevent3.html
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Only prevent unload on the first three window closes
|
||||
var unloadPreventedCount = 0;
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').remote.getCurrentWindow().emit('onbeforeunload');
|
||||
}, 0);
|
||||
if (unloadPreventedCount < 3) {
|
||||
unloadPreventedCount++;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
11
spec/fixtures/api/native-window-open-blank.html
vendored
Normal file
11
spec/fixtures/api/native-window-open-blank.html
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
const {ipcRenderer} = require('electron')
|
||||
const popup = window.open()
|
||||
popup.document.write('<h1>Hello</h1>')
|
||||
const content = popup.document.querySelector('h1').innerText
|
||||
ipcRenderer.send('answer', content)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
1
spec/fixtures/api/native-window-open-child.html
vendored
Normal file
1
spec/fixtures/api/native-window-open-child.html
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Hello</h1>
|
12
spec/fixtures/api/native-window-open-file.html
vendored
Normal file
12
spec/fixtures/api/native-window-open-file.html
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
const {ipcRenderer} = require('electron')
|
||||
const popup = window.open('native-window-open-child.html')
|
||||
popup.onload = () => {
|
||||
const content = popup.document.querySelector('h1').innerText
|
||||
ipcRenderer.send('answer', content)
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
5
spec/fixtures/api/native-window-open-isolated-preload.js
vendored
Normal file
5
spec/fixtures/api/native-window-open-isolated-preload.js
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
const {ipcRenderer} = require('electron')
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
ipcRenderer.send('answer', event.data)
|
||||
})
|
10
spec/fixtures/api/native-window-open-isolated.html
vendored
Normal file
10
spec/fixtures/api/native-window-open-isolated.html
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
const popup = window.open()
|
||||
popup.document.write('<h1>Hello</h1>')
|
||||
const content = popup.document.querySelector('h1').innerText
|
||||
window.postMessage(content, '*')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
9
spec/fixtures/api/native-window-open-native-addon.html
vendored
Normal file
9
spec/fixtures/api/native-window-open-native-addon.html
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
const {ipcRenderer} = require('electron')
|
||||
const runas = require('runas')
|
||||
ipcRenderer.send('answer', typeof runas)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
20
spec/fixtures/api/sandbox.html
vendored
20
spec/fixtures/api/sandbox.html
vendored
|
@ -13,13 +13,28 @@
|
|||
await timeout(100)
|
||||
}
|
||||
}
|
||||
if (window.opener) {
|
||||
|
||||
const [,test] = window.location.href.split('?')
|
||||
if (window.opener && test !== 'reload-remote') {
|
||||
window.callback = () => {
|
||||
opener.require('electron').ipcRenderer.send('answer', document.body.innerHTML)
|
||||
}
|
||||
} else {
|
||||
const {ipcRenderer} = require('electron')
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
const tests = {
|
||||
'reload-remote-child': () => {
|
||||
open(`${location.protocol}//${location.pathname}?reload-remote`)
|
||||
},
|
||||
'reload-remote': async () => {
|
||||
const p = ipcRenderer.sendSync('get-remote-module-path')
|
||||
const Hello = remote.require(p)
|
||||
if (!ipcRenderer.sendSync('reloaded')) {
|
||||
ipcRenderer.send('reload')
|
||||
return
|
||||
}
|
||||
await invokeGc()
|
||||
ipcRenderer.send('answer', new Hello().say())
|
||||
},
|
||||
'allocate-memory': async () => {
|
||||
await invokeGc()
|
||||
const {privateBytes: bytesBeforeOpen} = process.getProcessMemoryInfo()
|
||||
|
@ -95,7 +110,6 @@
|
|||
popup.close()
|
||||
}, false)
|
||||
|
||||
let [,test] = window.location.href.split('?')
|
||||
if (tests.hasOwnProperty(test))
|
||||
tests[test]()
|
||||
}
|
||||
|
|
6
spec/fixtures/module/hello-child.js
vendored
Normal file
6
spec/fixtures/module/hello-child.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
class Hello {
|
||||
say () {
|
||||
return 'hi child window'
|
||||
}
|
||||
}
|
||||
module.exports = Hello
|
6
spec/fixtures/module/hello.js
vendored
Normal file
6
spec/fixtures/module/hello.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
class Hello {
|
||||
say () {
|
||||
return 'hi'
|
||||
}
|
||||
}
|
||||
module.exports = Hello
|
2
spec/fixtures/module/preload-sandbox.js
vendored
2
spec/fixtures/module/preload-sandbox.js
vendored
|
@ -3,9 +3,9 @@
|
|||
const {ipcRenderer} = require('electron')
|
||||
window.ipcRenderer = ipcRenderer
|
||||
window.setImmediate = setImmediate
|
||||
window.require = require
|
||||
if (location.protocol === 'file:') {
|
||||
window.test = 'preload'
|
||||
window.require = require
|
||||
window.process = process
|
||||
} else if (location.href !== 'about:blank') {
|
||||
addEventListener('DOMContentLoaded', () => {
|
||||
|
|
|
@ -266,6 +266,10 @@ ipcMain.on('prevent-next-will-attach-webview', (event) => {
|
|||
event.sender.once('will-attach-webview', event => event.preventDefault())
|
||||
})
|
||||
|
||||
ipcMain.on('prevent-next-will-prevent-unload', (event, id) => {
|
||||
webContents.fromId(id).once('will-prevent-unload', event => event.preventDefault())
|
||||
})
|
||||
|
||||
ipcMain.on('disable-node-on-next-will-attach-webview', (event, id) => {
|
||||
event.sender.once('will-attach-webview', (event, webPreferences, params) => {
|
||||
params.src = `file://${path.join(__dirname, '..', 'fixtures', 'pages', 'c.html')}`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue