From 63874da08778c1e9b65ce4a41f69746178290cf9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 27 Nov 2018 10:39:03 +0900 Subject: [PATCH] test: add test for window.open in BrowserView --- spec/api-browser-view-spec.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/api-browser-view-spec.js b/spec/api-browser-view-spec.js index 5c27132aed90..515d9f926d2c 100644 --- a/spec/api-browser-view-spec.js +++ b/spec/api-browser-view-spec.js @@ -1,5 +1,6 @@ 'use strict' +const assert = require('assert') const chai = require('chai') const ChildProcess = require('child_process') const dirtyChai = require('dirty-chai') @@ -14,6 +15,8 @@ const { expect } = chai chai.use(dirtyChai) describe('BrowserView module', () => { + const fixtures = path.resolve(__dirname, 'fixtures') + let w = null let view = null @@ -178,11 +181,26 @@ describe('BrowserView module', () => { describe('new BrowserView()', () => { it('does not crash on exit', async () => { - const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-browserview.js') + const appPath = path.join(fixtures, 'api', 'leak-exit-browserview.js') const electronPath = remote.getGlobal('process').execPath const appProcess = ChildProcess.spawn(electronPath, [appPath]) const [code] = await emittedOnce(appProcess, 'close') expect(code).to.equal(0) }) }) + + describe('window.open()', () => { + it('works in BrowserView', (done) => { + view = new BrowserView() + w.setBrowserView(view) + view.webContents.once('new-window', (e, url, frameName, disposition, options, additionalFeatures) => { + e.preventDefault() + assert.strictEqual(url, 'http://host/') + assert.strictEqual(frameName, 'host') + assert.strictEqual(additionalFeatures[0], 'this-is-not-a-standard-feature') + done() + }) + view.webContents.loadFile(path.join(fixtures, 'pages', 'window-open.html')) + }) + }) })