From 3a9bbe30ac3a45748dbc4796ab4f2f51558be2f2 Mon Sep 17 00:00:00 2001 From: Rob Brackett Date: Mon, 18 Apr 2016 10:33:56 -0700 Subject: [PATCH] Test for #5183 - webContents.executeJavaScript hangs on subframe load. --- spec/api-browser-window-spec.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 2a8d129..26d4ff4 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -4,6 +4,7 @@ const assert = require('assert') const fs = require('fs') const path = require('path') const os = require('os') +const http = require('http') const remote = require('electron').remote const screen = require('electron').screen @@ -785,6 +786,14 @@ describe('browser-window module', function () { describe('window.webContents.executeJavaScript', function () { var expected = 'hello, world!' var code = '(() => "' + expected + '")()' + var server + + afterEach(function () { + if (server) { + server.close() + server = null + } + }) it('doesnt throw when no calback is provided', function () { const result = ipcRenderer.sendSync('executeJavaScript', code, false) @@ -798,6 +807,31 @@ describe('browser-window module', function () { done() }) }) + + it('works after page load and during subframe load', function (done) { + var url + // a slow server, guaranteeing time to execute code during loading + server = http.createServer(function (req, res) { + setTimeout(function() { res.end('') }, 200) + }); + server.listen(0, '127.0.0.1', function () { + url = 'http://127.0.0.1:' + server.address().port + w.loadURL('file://' + path.join(fixtures, 'pages', 'base-page.html')) + }) + + w.webContents.once('did-finish-load', function() { + // initiate a sub-frame load, then try and execute script during it + w.webContents.executeJavaScript(` + var iframe = document.createElement('iframe') + iframe.src = '${url}' + document.body.appendChild(iframe) + `, function() { + w.webContents.executeJavaScript(`console.log('hello')`, function() { + done() + }) + }) + }) + }) }) describe('deprecated options', function () { -- 2.7.4