From c5e249b85c4735d1229805b021783197820c5ebf Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Tue, 16 Jul 2019 13:43:23 -0700 Subject: [PATCH] test: actually test sandbox events in the test that says 'test sandbox events' (#19284) --- spec-main/api-browser-window-spec.ts | 9 +++++---- spec/fixtures/api/sandbox.html | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 3988288caed9..9c5a958cd3db 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -1846,13 +1846,13 @@ describe('BrowserWindow module', () => { describe('event handling', () => { let w: BrowserWindow = null as unknown as BrowserWindow beforeEach(() => { - w = new BrowserWindow({show: false, webPreferences: {nodeIntegration: true}}) + w = new BrowserWindow({show: false, webPreferences: {sandbox: true}}) }) it('works for window events', (done) => { waitForEvents(w, [ 'page-title-updated' ], done) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'window-events' }) + w.loadURL(`data:text/html,`) }) it('works for stop events', (done) => { @@ -1861,7 +1861,7 @@ describe('BrowserWindow module', () => { 'did-fail-load', 'did-stop-loading' ], done) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'webcontents-stop' }) + w.loadURL(`data:text/html,`) }) it('works for web contents events', (done) => { @@ -1869,7 +1869,8 @@ describe('BrowserWindow module', () => { 'did-finish-load', 'did-frame-finish-load', 'did-navigate-in-page', - 'will-navigate', + // TODO(nornagon): sandboxed pages should also emit will-navigate + // 'will-navigate', 'did-start-loading', 'did-stop-loading', 'did-frame-finish-load', diff --git a/spec/fixtures/api/sandbox.html b/spec/fixtures/api/sandbox.html index 7dae2f4c2e5c..c0ae7c279fb0 100644 --- a/spec/fixtures/api/sandbox.html +++ b/spec/fixtures/api/sandbox.html @@ -20,12 +20,12 @@ opener.require('electron').ipcRenderer.send('answer', document.body.innerHTML) } } else { - const {ipcRenderer, remote} = require('electron') 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')) { @@ -35,9 +35,6 @@ await invokeGc() ipcRenderer.send('answer', new Hello().say()) }, - 'window-events': () => { - document.title = 'changed' - }, 'webcontents-stop': () => { stop() }, @@ -50,6 +47,7 @@ }) }, 'exit-event': () => { + const {ipcRenderer} = require('electron') process.on('exit', () => { ipcRenderer.send('answer', location.href) }) @@ -65,6 +63,7 @@ }) }, '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') @@ -82,6 +81,7 @@ }) }, 'verify-ipc-sender': () => { + const {ipcRenderer} = require('electron') popup = open() ipcRenderer.once('verified', () => { ipcRenderer.send('parent-answer')