Add sync executeJavaScript test

This commit is contained in:
Samuel Attard 2016-10-11 10:40:05 +11:00 committed by Kevin Sawicki
parent 124fbdbd74
commit 75b010ce63
2 changed files with 10 additions and 1 deletions

View file

@ -48,7 +48,7 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev
}) })
} }
args.push(responseCallback) args.push(responseCallback)
electron.webFrame[method].apply(electron.webFrame, args) electron.webFrame[method](...args)
}) })
// Process command line arguments. // Process command line arguments.

View file

@ -1463,6 +1463,7 @@ describe('browser-window module', function () {
describe('window.webContents.executeJavaScript', function () { describe('window.webContents.executeJavaScript', function () {
var expected = 'hello, world!' var expected = 'hello, world!'
var code = '(() => "' + expected + '")()' var code = '(() => "' + expected + '")()'
var asyncCode = '(() => new Promise(r => setTimeout(() => r("' + expected + '"), 500)))()'
it('doesnt throw when no calback is provided', function () { it('doesnt throw when no calback is provided', function () {
const result = ipcRenderer.sendSync('executeJavaScript', code, false) const result = ipcRenderer.sendSync('executeJavaScript', code, false)
@ -1477,6 +1478,14 @@ describe('browser-window module', function () {
}) })
}) })
it('returns result if the code returns an asyncronous promise', function (done) {
ipcRenderer.send('executeJavaScript', asyncCode, true)
ipcRenderer.once('executeJavaScript-response', function (event, result) {
assert.equal(result, expected)
done()
})
})
it('works after page load and during subframe load', function (done) { it('works after page load and during subframe load', function (done) {
w.webContents.once('did-finish-load', function () { w.webContents.once('did-finish-load', function () {
// initiate a sub-frame load, then try and execute script during it // initiate a sub-frame load, then try and execute script during it