test: remove a bunch of usage of the remote module (#21119)
This commit is contained in:
parent
4f1536479e
commit
26ecf63ab4
22 changed files with 124 additions and 125 deletions
|
@ -233,7 +233,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
|
|||
})
|
||||
|
||||
describe('remote value in browser', () => {
|
||||
const print = path.join(fixtures, 'module', 'print_name.js')
|
||||
const print = path.join(__dirname, '..', 'spec-main', 'fixtures', 'module', 'print_name.js')
|
||||
const printName = remote.require(print)
|
||||
|
||||
it('preserves NaN', () => {
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
<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>
|
2
spec/fixtures/api/beforeunload-false.html
vendored
2
spec/fixtures/api/beforeunload-false.html
vendored
|
@ -5,7 +5,7 @@
|
|||
var unloadPrevented = false;
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').remote.getCurrentWindow().emit('onbeforeunload');
|
||||
require('electron').ipcRenderer.sendSync('onbeforeunload');
|
||||
}, 0);
|
||||
if (!unloadPrevented) {
|
||||
unloadPrevented = true;
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Only prevent unload on the first window close
|
||||
var unloadPrevented = false;
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').remote.getCurrentWindow().emit('onbeforeunload');
|
||||
}, 0);
|
||||
|
||||
if (!unloadPrevented) {
|
||||
unloadPrevented = true;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
window.onload = () => window.close();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
19
spec/fixtures/api/close-beforeunload-false.html
vendored
19
spec/fixtures/api/close-beforeunload-false.html
vendored
|
@ -1,19 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Only prevent unload on the first window close
|
||||
var unloadPrevented = false;
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').remote.getCurrentWindow().emit('onbeforeunload');
|
||||
}, 0);
|
||||
if (!unloadPrevented) {
|
||||
unloadPrevented = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// unload events don't get run unless load events have run.
|
||||
window.onload = () => window.close()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
window.onbeforeunload = function() {
|
||||
setTimeout(function() {
|
||||
require('electron').remote.getCurrentWindow().emit('onbeforeunload');
|
||||
}, 0);
|
||||
}
|
||||
window.onload = () => window.close();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
4
spec/fixtures/api/new-window-preload.js
vendored
4
spec/fixtures/api/new-window-preload.js
vendored
|
@ -1,4 +1,4 @@
|
|||
const { ipcRenderer, remote } = require('electron')
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
ipcRenderer.send('answer', process.argv, remote.getCurrentWindow().webContents.getWebPreferences())
|
||||
ipcRenderer.send('answer', process.argv)
|
||||
window.close()
|
||||
|
|
18
spec/fixtures/api/remote-event-handler.html
vendored
18
spec/fixtures/api/remote-event-handler.html
vendored
|
@ -1,18 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script>
|
||||
const {remote} = require('electron')
|
||||
const browserWindow = remote.getCurrentWindow()
|
||||
|
||||
const handler = () => {}
|
||||
browserWindow.webContents.on('remote-handler', handler)
|
||||
browserWindow.webContents.on('other-remote-handler', handler)
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
32
spec/fixtures/api/render-view-deleted.html
vendored
32
spec/fixtures/api/render-view-deleted.html
vendored
|
@ -1,32 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script>
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
|
||||
const contents = remote.getCurrentWebContents()
|
||||
|
||||
// This should not trigger a dereference and a remote getURL call should not fail
|
||||
contents.emit('render-view-deleted', {}, 'not-a-process-id')
|
||||
try {
|
||||
contents.getURL()
|
||||
} catch (error) {
|
||||
ipcRenderer.send('error-message', 'Unexpected error on getURL call')
|
||||
}
|
||||
|
||||
// This should trigger a dereference and a remote getURL call should fail
|
||||
contents.emit('render-view-deleted', {}, contents.getProcessId())
|
||||
try {
|
||||
contents.getURL()
|
||||
ipcRenderer.send('error-message', 'No error thrown')
|
||||
} catch (error) {
|
||||
ipcRenderer.send('error-message', error.message)
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
106
spec/fixtures/api/sandbox.html
vendored
106
spec/fixtures/api/sandbox.html
vendored
|
@ -1,106 +0,0 @@
|
|||
<html>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
function timeout(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
async function invokeGc () {
|
||||
// it seems calling window.gc once does not guarantee garbage will be
|
||||
// collected, so we repeat 10 times with interval of 100 ms
|
||||
for (let i = 0; i < 10; i++) {
|
||||
window.gc()
|
||||
await timeout(100)
|
||||
}
|
||||
}
|
||||
|
||||
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 tests = {
|
||||
'reload-remote-child': () => {
|
||||
open(`${location.protocol}//${location.pathname}?reload-remote`)
|
||||
},
|
||||
'reload-remote': async () => {
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
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())
|
||||
},
|
||||
'webcontents-stop': () => {
|
||||
stop()
|
||||
},
|
||||
'webcontents-events': () => {
|
||||
addEventListener('load', () => {
|
||||
location.hash = 'in-page-navigate'
|
||||
setTimeout(() => {
|
||||
location.reload()
|
||||
}, 50)
|
||||
})
|
||||
},
|
||||
'exit-event': () => {
|
||||
const {ipcRenderer} = require('electron')
|
||||
process.on('exit', () => {
|
||||
ipcRenderer.send('answer', location.href)
|
||||
})
|
||||
location.assign('http://www.google.com')
|
||||
},
|
||||
'window-open': () => {
|
||||
addEventListener('load', () => {
|
||||
popup = open(window.location.href, 'popup!', 'top=60,left=50,width=500,height=600')
|
||||
popup.addEventListener('DOMContentLoaded', () => {
|
||||
popup.document.write('<h1>scripting from opener</h1>')
|
||||
popup.callback()
|
||||
}, false)
|
||||
})
|
||||
},
|
||||
'window-open-external': () => {
|
||||
const {ipcRenderer} = require('electron')
|
||||
addEventListener('load', () => {
|
||||
ipcRenderer.once('open-the-popup', (event, url) => {
|
||||
popup = open(url, '', 'top=65,left=55,width=505,height=605')
|
||||
})
|
||||
ipcRenderer.once('touch-the-popup', () => {
|
||||
let errorMessage = null
|
||||
try {
|
||||
const childDoc = popup.document
|
||||
} catch (error) {
|
||||
errorMessage = error.message
|
||||
}
|
||||
ipcRenderer.send('answer', errorMessage)
|
||||
})
|
||||
ipcRenderer.send('opener-loaded')
|
||||
})
|
||||
},
|
||||
'verify-ipc-sender': () => {
|
||||
const {ipcRenderer} = require('electron')
|
||||
popup = open()
|
||||
ipcRenderer.once('verified', () => {
|
||||
ipcRenderer.send('parent-answer')
|
||||
})
|
||||
popup.ipcRenderer.once('verified', () => {
|
||||
popup.ipcRenderer.send('child-answer')
|
||||
})
|
||||
ipcRenderer.send('parent-ready')
|
||||
popup.ipcRenderer.send('child-ready')
|
||||
}
|
||||
}
|
||||
|
||||
addEventListener('unload', () => {
|
||||
if (window.popup)
|
||||
popup.close()
|
||||
}, false)
|
||||
|
||||
if (tests.hasOwnProperty(test))
|
||||
tests[test]()
|
||||
}
|
||||
</script>
|
||||
</html>
|
11
spec/fixtures/module/delete-buffer.js
vendored
11
spec/fixtures/module/delete-buffer.js
vendored
|
@ -1,11 +0,0 @@
|
|||
const path = require('path')
|
||||
const { remote } = require('electron')
|
||||
const { Buffer } = window
|
||||
|
||||
delete window.Buffer
|
||||
delete global.Buffer
|
||||
|
||||
// Test that remote.js doesn't use Buffer global
|
||||
remote.require(path.join(__dirname, 'print_name.js')).echo(Buffer.from('bar'))
|
||||
|
||||
window.test = Buffer.from('buffer')
|
5
spec/fixtures/module/preload-remote.js
vendored
5
spec/fixtures/module/preload-remote.js
vendored
|
@ -1,5 +0,0 @@
|
|||
const { ipcRenderer, remote } = require('electron')
|
||||
|
||||
window.onload = function () {
|
||||
ipcRenderer.send('remote', typeof remote)
|
||||
}
|
36
spec/fixtures/module/print_name.js
vendored
36
spec/fixtures/module/print_name.js
vendored
|
@ -1,36 +0,0 @@
|
|||
exports.print = function (obj) {
|
||||
return obj.constructor.name
|
||||
}
|
||||
|
||||
exports.echo = function (obj) {
|
||||
return obj
|
||||
}
|
||||
|
||||
const typedArrays = {
|
||||
Int8Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray,
|
||||
Int16Array,
|
||||
Uint16Array,
|
||||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array
|
||||
}
|
||||
|
||||
exports.typedArray = function (type, values) {
|
||||
const constructor = typedArrays[type]
|
||||
const array = new constructor(values.length)
|
||||
for (let i = 0; i < values.length; ++i) {
|
||||
array[i] = values[i]
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
exports.getNaN = function () {
|
||||
return NaN
|
||||
}
|
||||
|
||||
exports.getInfinity = function () {
|
||||
return Infinity
|
||||
}
|
24
spec/fixtures/pages/focus-web-contents.html
vendored
24
spec/fixtures/pages/focus-web-contents.html
vendored
|
@ -1,24 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script>
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
|
||||
remote.getCurrentWindow().focus()
|
||||
|
||||
const child = new remote.BrowserWindow({show: false})
|
||||
child.loadURL('about:blank')
|
||||
child.webContents.focus()
|
||||
|
||||
const currentFocused = remote.getCurrentWindow().isFocused()
|
||||
const childFocused = child.isFocused()
|
||||
child.close()
|
||||
ipcRenderer.send('answer', currentFocused, childFocused)
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
31
spec/fixtures/pages/webview-devtools.html
vendored
31
spec/fixtures/pages/webview-devtools.html
vendored
|
@ -1,31 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<webview nodeintegration src="./a.html"></webview>
|
||||
<script>
|
||||
var wv = document.querySelector('webview')
|
||||
wv.addEventListener('dom-ready', () => {
|
||||
const { remote } = require('electron')
|
||||
const webContents = remote.webContents.fromId(wv.getWebContentsId())
|
||||
webContents.on('devtools-opened', function () {
|
||||
var showPanelIntevalId = setInterval(function () {
|
||||
if (webContents.devToolsWebContents) {
|
||||
webContents.devToolsWebContents.executeJavaScript('(' + (function () {
|
||||
var lastPanelId = UI.inspectorView._tabbedPane._tabs.peekLast().id
|
||||
UI.inspectorView.showPanel(lastPanelId)
|
||||
}).toString() + ')()')
|
||||
} else {
|
||||
clearInterval(showPanelIntevalId)
|
||||
}
|
||||
}, 100)
|
||||
})
|
||||
|
||||
wv.openDevTools()
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
3
spec/fixtures/pages/window-open-size.html
vendored
3
spec/fixtures/pages/window-open-size.html
vendored
|
@ -1,8 +1,7 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
var size = require('electron').remote.getCurrentWindow().getSize();
|
||||
window.opener.postMessage('size: ' + size[0] + ' ' + size[1], '*')
|
||||
window.opener.postMessage('size: ' + outerWidth + ' ' + outerHeight, '*')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue