build: enable JS semicolons (#22783)
This commit is contained in:
parent
24e21467b9
commit
5d657dece4
354 changed files with 21512 additions and 21510 deletions
|
@ -1,8 +1,8 @@
|
|||
import * as path from 'path'
|
||||
import { BrowserWindow, session, ipcMain, app, WebContents } from 'electron'
|
||||
import { closeAllWindows } from './window-helpers'
|
||||
import { emittedOnce } from './events-helpers'
|
||||
import { expect } from 'chai'
|
||||
import * as path from 'path';
|
||||
import { BrowserWindow, session, ipcMain, app, WebContents } from 'electron';
|
||||
import { closeAllWindows } from './window-helpers';
|
||||
import { emittedOnce } from './events-helpers';
|
||||
import { expect } from 'chai';
|
||||
|
||||
async function loadWebView (w: WebContents, attributes: Record<string, string>): Promise<void> {
|
||||
await w.executeJavaScript(`
|
||||
|
@ -16,13 +16,13 @@ async function loadWebView (w: WebContents, attributes: Record<string, string>):
|
|||
resolve()
|
||||
})
|
||||
})
|
||||
`)
|
||||
`);
|
||||
}
|
||||
|
||||
describe('<webview> tag', function () {
|
||||
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures')
|
||||
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures');
|
||||
|
||||
afterEach(closeAllWindows)
|
||||
afterEach(closeAllWindows);
|
||||
|
||||
it('works without script tag in page', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -31,10 +31,10 @@ describe('<webview> tag', function () {
|
|||
webviewTag: true,
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html'))
|
||||
await emittedOnce(ipcMain, 'pong')
|
||||
})
|
||||
});
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html'));
|
||||
await emittedOnce(ipcMain, 'pong');
|
||||
});
|
||||
|
||||
it('works with sandbox', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -44,10 +44,10 @@ describe('<webview> tag', function () {
|
|||
nodeIntegration: true,
|
||||
sandbox: true
|
||||
}
|
||||
})
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'))
|
||||
await emittedOnce(ipcMain, 'pong')
|
||||
})
|
||||
});
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'));
|
||||
await emittedOnce(ipcMain, 'pong');
|
||||
});
|
||||
|
||||
it('works with contextIsolation', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -57,10 +57,10 @@ describe('<webview> tag', function () {
|
|||
nodeIntegration: true,
|
||||
contextIsolation: true
|
||||
}
|
||||
})
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'))
|
||||
await emittedOnce(ipcMain, 'pong')
|
||||
})
|
||||
});
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'));
|
||||
await emittedOnce(ipcMain, 'pong');
|
||||
});
|
||||
|
||||
it('works with contextIsolation + sandbox', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -71,10 +71,10 @@ describe('<webview> tag', function () {
|
|||
contextIsolation: true,
|
||||
sandbox: true
|
||||
}
|
||||
})
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'))
|
||||
await emittedOnce(ipcMain, 'pong')
|
||||
})
|
||||
});
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'));
|
||||
await emittedOnce(ipcMain, 'pong');
|
||||
});
|
||||
|
||||
it('is disabled by default', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -83,54 +83,54 @@ describe('<webview> tag', function () {
|
|||
preload: path.join(fixtures, 'module', 'preload-webview.js'),
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const webview = emittedOnce(ipcMain, 'webview')
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html'))
|
||||
const [, type] = await webview
|
||||
const webview = emittedOnce(ipcMain, 'webview');
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html'));
|
||||
const [, type] = await webview;
|
||||
|
||||
expect(type).to.equal('undefined', 'WebView still exists')
|
||||
})
|
||||
expect(type).to.equal('undefined', 'WebView still exists');
|
||||
});
|
||||
|
||||
// FIXME(deepak1556): Ch69 follow up.
|
||||
xdescribe('document.visibilityState/hidden', () => {
|
||||
afterEach(() => {
|
||||
ipcMain.removeAllListeners('pong')
|
||||
})
|
||||
ipcMain.removeAllListeners('pong');
|
||||
});
|
||||
|
||||
it('updates when the window is shown after the ready-to-show event', async () => {
|
||||
const w = new BrowserWindow({ show: false })
|
||||
const readyToShowSignal = emittedOnce(w, 'ready-to-show')
|
||||
const pongSignal1 = emittedOnce(ipcMain, 'pong')
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-visibilitychange.html'))
|
||||
await pongSignal1
|
||||
const pongSignal2 = emittedOnce(ipcMain, 'pong')
|
||||
await readyToShowSignal
|
||||
w.show()
|
||||
const w = new BrowserWindow({ show: false });
|
||||
const readyToShowSignal = emittedOnce(w, 'ready-to-show');
|
||||
const pongSignal1 = emittedOnce(ipcMain, 'pong');
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-visibilitychange.html'));
|
||||
await pongSignal1;
|
||||
const pongSignal2 = emittedOnce(ipcMain, 'pong');
|
||||
await readyToShowSignal;
|
||||
w.show();
|
||||
|
||||
const [, visibilityState, hidden] = await pongSignal2
|
||||
expect(visibilityState).to.equal('visible')
|
||||
expect(hidden).to.be.false()
|
||||
})
|
||||
const [, visibilityState, hidden] = await pongSignal2;
|
||||
expect(visibilityState).to.equal('visible');
|
||||
expect(hidden).to.be.false();
|
||||
});
|
||||
|
||||
it('inherits the parent window visibility state and receives visibilitychange events', async () => {
|
||||
const w = new BrowserWindow({ show: false })
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-visibilitychange.html'))
|
||||
const [, visibilityState, hidden] = await emittedOnce(ipcMain, 'pong')
|
||||
expect(visibilityState).to.equal('hidden')
|
||||
expect(hidden).to.be.true()
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-visibilitychange.html'));
|
||||
const [, visibilityState, hidden] = await emittedOnce(ipcMain, 'pong');
|
||||
expect(visibilityState).to.equal('hidden');
|
||||
expect(hidden).to.be.true();
|
||||
|
||||
// We have to start waiting for the event
|
||||
// before we ask the webContents to resize.
|
||||
const getResponse = emittedOnce(ipcMain, 'pong')
|
||||
w.webContents.emit('-window-visibility-change', 'visible')
|
||||
const getResponse = emittedOnce(ipcMain, 'pong');
|
||||
w.webContents.emit('-window-visibility-change', 'visible');
|
||||
|
||||
return getResponse.then(([, visibilityState, hidden]) => {
|
||||
expect(visibilityState).to.equal('visible')
|
||||
expect(hidden).to.be.false()
|
||||
})
|
||||
})
|
||||
})
|
||||
expect(visibilityState).to.equal('visible');
|
||||
expect(hidden).to.be.false();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('did-attach-webview event', () => {
|
||||
it('is emitted when a webview has been attached', async () => {
|
||||
|
@ -140,16 +140,16 @@ describe('<webview> tag', function () {
|
|||
webviewTag: true,
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview')
|
||||
const webviewDomReady = emittedOnce(ipcMain, 'webview-dom-ready')
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'))
|
||||
});
|
||||
const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview');
|
||||
const webviewDomReady = emittedOnce(ipcMain, 'webview-dom-ready');
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'));
|
||||
|
||||
const [, webContents] = await didAttachWebview
|
||||
const [, id] = await webviewDomReady
|
||||
expect(webContents.id).to.equal(id)
|
||||
})
|
||||
})
|
||||
const [, webContents] = await didAttachWebview;
|
||||
const [, id] = await webviewDomReady;
|
||||
expect(webContents.id).to.equal(id);
|
||||
});
|
||||
});
|
||||
|
||||
it('loads devtools extensions registered on the parent window', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -158,50 +158,50 @@ describe('<webview> tag', function () {
|
|||
webviewTag: true,
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
BrowserWindow.removeDevToolsExtension('foo')
|
||||
});
|
||||
BrowserWindow.removeDevToolsExtension('foo');
|
||||
|
||||
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
|
||||
await BrowserWindow.addDevToolsExtension(extensionPath)
|
||||
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo');
|
||||
await BrowserWindow.addDevToolsExtension(extensionPath);
|
||||
|
||||
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'webview-devtools.html'))
|
||||
let childWebContentsId = 0
|
||||
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'webview-devtools.html'));
|
||||
let childWebContentsId = 0;
|
||||
app.once('web-contents-created', (e, webContents) => {
|
||||
childWebContentsId = webContents.id
|
||||
childWebContentsId = webContents.id;
|
||||
webContents.on('devtools-opened', function () {
|
||||
const showPanelIntervalId = setInterval(function () {
|
||||
if (!webContents.isDestroyed() && webContents.devToolsWebContents) {
|
||||
webContents.devToolsWebContents.executeJavaScript('(' + function () {
|
||||
const lastPanelId: any = (window as any).UI.inspectorView._tabbedPane._tabs.peekLast().id;
|
||||
(window as any).UI.inspectorView.showPanel(lastPanelId)
|
||||
}.toString() + ')()')
|
||||
(window as any).UI.inspectorView.showPanel(lastPanelId);
|
||||
}.toString() + ')()');
|
||||
} else {
|
||||
clearInterval(showPanelIntervalId)
|
||||
clearInterval(showPanelIntervalId);
|
||||
}
|
||||
}, 100)
|
||||
})
|
||||
})
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
const [, { runtimeId, tabId }] = await emittedOnce(ipcMain, 'answer')
|
||||
expect(runtimeId).to.match(/^[a-z]{32}$/)
|
||||
expect(tabId).to.equal(childWebContentsId)
|
||||
})
|
||||
const [, { runtimeId, tabId }] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(runtimeId).to.match(/^[a-z]{32}$/);
|
||||
expect(tabId).to.equal(childWebContentsId);
|
||||
});
|
||||
|
||||
describe('zoom behavior', () => {
|
||||
const zoomScheme = standardScheme
|
||||
const webviewSession = session.fromPartition('webview-temp')
|
||||
const zoomScheme = standardScheme;
|
||||
const webviewSession = session.fromPartition('webview-temp');
|
||||
|
||||
before((done) => {
|
||||
const protocol = webviewSession.protocol
|
||||
const protocol = webviewSession.protocol;
|
||||
protocol.registerStringProtocol(zoomScheme, (request, callback) => {
|
||||
callback('hello')
|
||||
}, (error) => done(error))
|
||||
})
|
||||
callback('hello');
|
||||
}, (error) => done(error));
|
||||
});
|
||||
|
||||
after((done) => {
|
||||
const protocol = webviewSession.protocol
|
||||
protocol.unregisterProtocol(zoomScheme, (error) => done(error))
|
||||
})
|
||||
const protocol = webviewSession.protocol;
|
||||
protocol.unregisterProtocol(zoomScheme, (error) => done(error));
|
||||
});
|
||||
|
||||
it('inherits the zoomFactor of the parent window', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -211,14 +211,14 @@ describe('<webview> tag', function () {
|
|||
nodeIntegration: true,
|
||||
zoomFactor: 1.2
|
||||
}
|
||||
})
|
||||
const zoomEventPromise = emittedOnce(ipcMain, 'webview-parent-zoom-level')
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-factor.html'))
|
||||
});
|
||||
const zoomEventPromise = emittedOnce(ipcMain, 'webview-parent-zoom-level');
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-factor.html'));
|
||||
|
||||
const [, zoomFactor, zoomLevel] = await zoomEventPromise
|
||||
expect(zoomFactor).to.equal(1.2)
|
||||
expect(zoomLevel).to.equal(1)
|
||||
})
|
||||
const [, zoomFactor, zoomLevel] = await zoomEventPromise;
|
||||
expect(zoomFactor).to.equal(1.2);
|
||||
expect(zoomLevel).to.equal(1);
|
||||
});
|
||||
|
||||
it('maintains zoom level on navigation', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -228,27 +228,27 @@ describe('<webview> tag', function () {
|
|||
nodeIntegration: true,
|
||||
zoomFactor: 1.2
|
||||
}
|
||||
})
|
||||
});
|
||||
const promise = new Promise((resolve) => {
|
||||
ipcMain.on('webview-zoom-level', (event, zoomLevel, zoomFactor, newHost, final) => {
|
||||
if (!newHost) {
|
||||
expect(zoomFactor).to.equal(1.44)
|
||||
expect(zoomLevel).to.equal(2.0)
|
||||
expect(zoomFactor).to.equal(1.44);
|
||||
expect(zoomLevel).to.equal(2.0);
|
||||
} else {
|
||||
expect(zoomFactor).to.equal(1.2)
|
||||
expect(zoomLevel).to.equal(1)
|
||||
expect(zoomFactor).to.equal(1.2);
|
||||
expect(zoomLevel).to.equal(1);
|
||||
}
|
||||
|
||||
if (final) {
|
||||
resolve()
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-custom-zoom-level.html'))
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-custom-zoom-level.html'));
|
||||
|
||||
await promise
|
||||
})
|
||||
await promise;
|
||||
});
|
||||
|
||||
it('maintains zoom level when navigating within same page', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -258,22 +258,22 @@ describe('<webview> tag', function () {
|
|||
nodeIntegration: true,
|
||||
zoomFactor: 1.2
|
||||
}
|
||||
})
|
||||
});
|
||||
const promise = new Promise((resolve) => {
|
||||
ipcMain.on('webview-zoom-in-page', (event, zoomLevel, zoomFactor, final) => {
|
||||
expect(zoomFactor).to.equal(1.44)
|
||||
expect(zoomLevel).to.equal(2.0)
|
||||
expect(zoomFactor).to.equal(1.44);
|
||||
expect(zoomLevel).to.equal(2.0);
|
||||
|
||||
if (final) {
|
||||
resolve()
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-in-page-navigate.html'))
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-in-page-navigate.html'));
|
||||
|
||||
await promise
|
||||
})
|
||||
await promise;
|
||||
});
|
||||
|
||||
it('inherits zoom level for the origin when available', async () => {
|
||||
const w = new BrowserWindow({
|
||||
|
@ -283,21 +283,21 @@ describe('<webview> tag', function () {
|
|||
nodeIntegration: true,
|
||||
zoomFactor: 1.2
|
||||
}
|
||||
})
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-origin-zoom-level.html'))
|
||||
});
|
||||
w.loadFile(path.join(fixtures, 'pages', 'webview-origin-zoom-level.html'));
|
||||
|
||||
const [, zoomLevel] = await emittedOnce(ipcMain, 'webview-origin-zoom-level')
|
||||
expect(zoomLevel).to.equal(2.0)
|
||||
})
|
||||
})
|
||||
const [, zoomLevel] = await emittedOnce(ipcMain, 'webview-origin-zoom-level');
|
||||
expect(zoomLevel).to.equal(2.0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('nativeWindowOpen option', () => {
|
||||
let w: BrowserWindow
|
||||
let w: BrowserWindow;
|
||||
beforeEach(async () => {
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } })
|
||||
await w.loadURL('about:blank')
|
||||
})
|
||||
afterEach(closeAllWindows)
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } });
|
||||
await w.loadURL('about:blank');
|
||||
});
|
||||
afterEach(closeAllWindows);
|
||||
|
||||
it('opens window of about:blank with cross-scripting enabled', async () => {
|
||||
// Don't wait for loading to finish.
|
||||
|
@ -306,11 +306,11 @@ describe('<webview> tag', function () {
|
|||
nodeintegration: 'on',
|
||||
webpreferences: 'nativeWindowOpen=1',
|
||||
src: `file://${path.join(fixtures, 'api', 'native-window-open-blank.html')}`
|
||||
})
|
||||
});
|
||||
|
||||
const [, content] = await emittedOnce(ipcMain, 'answer')
|
||||
expect(content).to.equal('Hello')
|
||||
})
|
||||
const [, content] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(content).to.equal('Hello');
|
||||
});
|
||||
|
||||
it('opens window of same domain with cross-scripting enabled', async () => {
|
||||
// Don't wait for loading to finish.
|
||||
|
@ -319,11 +319,11 @@ describe('<webview> tag', function () {
|
|||
nodeintegration: 'on',
|
||||
webpreferences: 'nativeWindowOpen=1',
|
||||
src: `file://${path.join(fixtures, 'api', 'native-window-open-file.html')}`
|
||||
})
|
||||
});
|
||||
|
||||
const [, content] = await emittedOnce(ipcMain, 'answer')
|
||||
expect(content).to.equal('Hello')
|
||||
})
|
||||
const [, content] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(content).to.equal('Hello');
|
||||
});
|
||||
|
||||
it('returns null from window.open when allowpopups is not set', async () => {
|
||||
// Don't wait for loading to finish.
|
||||
|
@ -331,11 +331,11 @@ describe('<webview> tag', function () {
|
|||
nodeintegration: 'on',
|
||||
webpreferences: 'nativeWindowOpen=1',
|
||||
src: `file://${path.join(fixtures, 'api', 'native-window-open-no-allowpopups.html')}`
|
||||
})
|
||||
});
|
||||
|
||||
const [, { windowOpenReturnedNull }] = await emittedOnce(ipcMain, 'answer')
|
||||
expect(windowOpenReturnedNull).to.be.true()
|
||||
})
|
||||
const [, { windowOpenReturnedNull }] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(windowOpenReturnedNull).to.be.true();
|
||||
});
|
||||
|
||||
it('blocks accessing cross-origin frames', async () => {
|
||||
// Don't wait for loading to finish.
|
||||
|
@ -344,14 +344,14 @@ describe('<webview> tag', function () {
|
|||
nodeintegration: 'on',
|
||||
webpreferences: 'nativeWindowOpen=1',
|
||||
src: `file://${path.join(fixtures, 'api', 'native-window-open-cross-origin.html')}`
|
||||
})
|
||||
});
|
||||
|
||||
const [, content] = await emittedOnce(ipcMain, 'answer')
|
||||
const [, content] = await emittedOnce(ipcMain, 'answer');
|
||||
const expectedContent =
|
||||
'Blocked a frame with origin "file://" from accessing a cross-origin frame.'
|
||||
'Blocked a frame with origin "file://" from accessing a cross-origin frame.';
|
||||
|
||||
expect(content).to.equal(expectedContent)
|
||||
})
|
||||
expect(content).to.equal(expectedContent);
|
||||
});
|
||||
|
||||
it('emits a new-window event', async () => {
|
||||
// Don't wait for loading to finish.
|
||||
|
@ -360,7 +360,7 @@ describe('<webview> tag', function () {
|
|||
nodeintegration: 'on',
|
||||
webpreferences: 'nativeWindowOpen=1',
|
||||
src: `file://${fixtures}/pages/window-open.html`
|
||||
}
|
||||
};
|
||||
const { url, frameName } = await w.webContents.executeJavaScript(`
|
||||
new Promise((resolve, reject) => {
|
||||
const webview = document.createElement('webview')
|
||||
|
@ -372,11 +372,11 @@ describe('<webview> tag', function () {
|
|||
resolve({url: e.url, frameName: e.frameName})
|
||||
})
|
||||
})
|
||||
`)
|
||||
`);
|
||||
|
||||
expect(url).to.equal('http://host/')
|
||||
expect(frameName).to.equal('host')
|
||||
})
|
||||
expect(url).to.equal('http://host/');
|
||||
expect(frameName).to.equal('host');
|
||||
});
|
||||
|
||||
it('emits a browser-window-created event', async () => {
|
||||
// Don't wait for loading to finish.
|
||||
|
@ -384,33 +384,33 @@ describe('<webview> tag', function () {
|
|||
allowpopups: 'on',
|
||||
webpreferences: 'nativeWindowOpen=1',
|
||||
src: `file://${fixtures}/pages/window-open.html`
|
||||
})
|
||||
});
|
||||
|
||||
await emittedOnce(app, 'browser-window-created')
|
||||
})
|
||||
await emittedOnce(app, 'browser-window-created');
|
||||
});
|
||||
|
||||
it('emits a web-contents-created event', (done) => {
|
||||
app.on('web-contents-created', function listener (event, contents) {
|
||||
if (contents.getType() === 'window') {
|
||||
app.removeListener('web-contents-created', listener)
|
||||
done()
|
||||
app.removeListener('web-contents-created', listener);
|
||||
done();
|
||||
}
|
||||
})
|
||||
});
|
||||
loadWebView(w.webContents, {
|
||||
allowpopups: 'on',
|
||||
webpreferences: 'nativeWindowOpen=1',
|
||||
src: `file://${fixtures}/pages/window-open.html`
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('webpreferences attribute', () => {
|
||||
let w: BrowserWindow
|
||||
let w: BrowserWindow;
|
||||
beforeEach(async () => {
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } })
|
||||
await w.loadURL('about:blank')
|
||||
})
|
||||
afterEach(closeAllWindows)
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } });
|
||||
await w.loadURL('about:blank');
|
||||
});
|
||||
afterEach(closeAllWindows);
|
||||
|
||||
it('can enable context isolation', async () => {
|
||||
loadWebView(w.webContents, {
|
||||
|
@ -418,9 +418,9 @@ describe('<webview> tag', function () {
|
|||
preload: `file://${fixtures}/api/isolated-preload.js`,
|
||||
src: `file://${fixtures}/api/isolated.html`,
|
||||
webpreferences: 'contextIsolation=yes'
|
||||
})
|
||||
});
|
||||
|
||||
const [, data] = await emittedOnce(ipcMain, 'isolated-world')
|
||||
const [, data] = await emittedOnce(ipcMain, 'isolated-world');
|
||||
expect(data).to.deep.equal({
|
||||
preloadContext: {
|
||||
preloadProperty: 'number',
|
||||
|
@ -441,19 +441,19 @@ describe('<webview> tag', function () {
|
|||
typeofPreloadExecuteJavaScriptProperty: 'number',
|
||||
typeofOpenedWindow: 'object'
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('permission request handlers', () => {
|
||||
let w: BrowserWindow
|
||||
let w: BrowserWindow;
|
||||
beforeEach(async () => {
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } })
|
||||
await w.loadURL('about:blank')
|
||||
})
|
||||
afterEach(closeAllWindows)
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } });
|
||||
await w.loadURL('about:blank');
|
||||
});
|
||||
afterEach(closeAllWindows);
|
||||
|
||||
const partition = 'permissionTest'
|
||||
const partition = 'permissionTest';
|
||||
|
||||
function setUpRequestHandler (webContentsId: number, requestedPermission: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -462,130 +462,130 @@ describe('<webview> tag', function () {
|
|||
// requestMIDIAccess with sysex requests both midi and midiSysex so
|
||||
// grant the first midi one and then reject the midiSysex one
|
||||
if (requestedPermission === 'midiSysex' && permission === 'midi') {
|
||||
return callback(true)
|
||||
return callback(true);
|
||||
}
|
||||
|
||||
try {
|
||||
expect(permission).to.equal(requestedPermission)
|
||||
expect(permission).to.equal(requestedPermission);
|
||||
} catch (e) {
|
||||
return reject(e)
|
||||
return reject(e);
|
||||
}
|
||||
callback(false)
|
||||
resolve()
|
||||
callback(false);
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
afterEach(() => {
|
||||
session.fromPartition(partition).setPermissionRequestHandler(null)
|
||||
})
|
||||
session.fromPartition(partition).setPermissionRequestHandler(null);
|
||||
});
|
||||
|
||||
// This is disabled because CI machines don't have cameras or microphones,
|
||||
// so Chrome responds with "NotFoundError" instead of
|
||||
// "PermissionDeniedError". It should be re-enabled if we find a way to mock
|
||||
// the presence of a microphone & camera.
|
||||
xit('emits when using navigator.getUserMedia api', async () => {
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message')
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message');
|
||||
loadWebView(w.webContents, {
|
||||
src: `file://${fixtures}/pages/permissions/media.html`,
|
||||
partition,
|
||||
nodeintegration: 'on'
|
||||
})
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created')
|
||||
setUpRequestHandler(webViewContents.id, 'media')
|
||||
const [, errorName] = await errorFromRenderer
|
||||
expect(errorName).to.equal('PermissionDeniedError')
|
||||
})
|
||||
});
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
||||
setUpRequestHandler(webViewContents.id, 'media');
|
||||
const [, errorName] = await errorFromRenderer;
|
||||
expect(errorName).to.equal('PermissionDeniedError');
|
||||
});
|
||||
|
||||
it('emits when using navigator.geolocation api', async () => {
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message')
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message');
|
||||
loadWebView(w.webContents, {
|
||||
src: `file://${fixtures}/pages/permissions/geolocation.html`,
|
||||
partition,
|
||||
nodeintegration: 'on'
|
||||
})
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created')
|
||||
setUpRequestHandler(webViewContents.id, 'geolocation')
|
||||
const [, error] = await errorFromRenderer
|
||||
expect(error).to.equal('User denied Geolocation')
|
||||
})
|
||||
});
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
||||
setUpRequestHandler(webViewContents.id, 'geolocation');
|
||||
const [, error] = await errorFromRenderer;
|
||||
expect(error).to.equal('User denied Geolocation');
|
||||
});
|
||||
|
||||
it('emits when using navigator.requestMIDIAccess without sysex api', async () => {
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message')
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message');
|
||||
loadWebView(w.webContents, {
|
||||
src: `file://${fixtures}/pages/permissions/midi.html`,
|
||||
partition,
|
||||
nodeintegration: 'on'
|
||||
})
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created')
|
||||
setUpRequestHandler(webViewContents.id, 'midi')
|
||||
const [, error] = await errorFromRenderer
|
||||
expect(error).to.equal('SecurityError')
|
||||
})
|
||||
});
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
||||
setUpRequestHandler(webViewContents.id, 'midi');
|
||||
const [, error] = await errorFromRenderer;
|
||||
expect(error).to.equal('SecurityError');
|
||||
});
|
||||
|
||||
it('emits when using navigator.requestMIDIAccess with sysex api', async () => {
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message')
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message');
|
||||
loadWebView(w.webContents, {
|
||||
src: `file://${fixtures}/pages/permissions/midi-sysex.html`,
|
||||
partition,
|
||||
nodeintegration: 'on'
|
||||
})
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created')
|
||||
setUpRequestHandler(webViewContents.id, 'midiSysex')
|
||||
const [, error] = await errorFromRenderer
|
||||
expect(error).to.equal('SecurityError')
|
||||
})
|
||||
});
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
||||
setUpRequestHandler(webViewContents.id, 'midiSysex');
|
||||
const [, error] = await errorFromRenderer;
|
||||
expect(error).to.equal('SecurityError');
|
||||
});
|
||||
|
||||
it('emits when accessing external protocol', async () => {
|
||||
loadWebView(w.webContents, {
|
||||
src: 'magnet:test',
|
||||
partition
|
||||
})
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created')
|
||||
await setUpRequestHandler(webViewContents.id, 'openExternal')
|
||||
})
|
||||
});
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
||||
await setUpRequestHandler(webViewContents.id, 'openExternal');
|
||||
});
|
||||
|
||||
it('emits when using Notification.requestPermission', async () => {
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message')
|
||||
const errorFromRenderer = emittedOnce(ipcMain, 'message');
|
||||
loadWebView(w.webContents, {
|
||||
src: `file://${fixtures}/pages/permissions/notification.html`,
|
||||
partition,
|
||||
nodeintegration: 'on'
|
||||
})
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created')
|
||||
});
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
||||
|
||||
await setUpRequestHandler(webViewContents.id, 'notifications')
|
||||
await setUpRequestHandler(webViewContents.id, 'notifications');
|
||||
|
||||
const [, error] = await errorFromRenderer
|
||||
expect(error).to.equal('denied')
|
||||
})
|
||||
})
|
||||
const [, error] = await errorFromRenderer;
|
||||
expect(error).to.equal('denied');
|
||||
});
|
||||
});
|
||||
|
||||
describe('enableremotemodule attribute', () => {
|
||||
let w: BrowserWindow
|
||||
let w: BrowserWindow;
|
||||
beforeEach(async () => {
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } })
|
||||
await w.loadURL('about:blank')
|
||||
})
|
||||
afterEach(closeAllWindows)
|
||||
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true } });
|
||||
await w.loadURL('about:blank');
|
||||
});
|
||||
afterEach(closeAllWindows);
|
||||
|
||||
const generateSpecs = (description: string, sandbox: boolean) => {
|
||||
describe(description, () => {
|
||||
const preload = `file://${fixtures}/module/preload-disable-remote.js`
|
||||
const src = `file://${fixtures}/api/blank.html`
|
||||
const preload = `file://${fixtures}/module/preload-disable-remote.js`;
|
||||
const src = `file://${fixtures}/api/blank.html`;
|
||||
|
||||
it('enables the remote module by default', async () => {
|
||||
loadWebView(w.webContents, {
|
||||
preload,
|
||||
src,
|
||||
sandbox: sandbox.toString()
|
||||
})
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created')
|
||||
const [, , message] = await emittedOnce(webViewContents, 'console-message')
|
||||
});
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
||||
const [, , message] = await emittedOnce(webViewContents, 'console-message');
|
||||
|
||||
const typeOfRemote = JSON.parse(message)
|
||||
expect(typeOfRemote).to.equal('object')
|
||||
})
|
||||
const typeOfRemote = JSON.parse(message);
|
||||
expect(typeOfRemote).to.equal('object');
|
||||
});
|
||||
|
||||
it('disables the remote module when false', async () => {
|
||||
loadWebView(w.webContents, {
|
||||
|
@ -593,17 +593,17 @@ describe('<webview> tag', function () {
|
|||
src,
|
||||
sandbox: sandbox.toString(),
|
||||
enableremotemodule: 'false'
|
||||
})
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created')
|
||||
const [, , message] = await emittedOnce(webViewContents, 'console-message')
|
||||
});
|
||||
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
||||
const [, , message] = await emittedOnce(webViewContents, 'console-message');
|
||||
|
||||
const typeOfRemote = JSON.parse(message)
|
||||
expect(typeOfRemote).to.equal('undefined')
|
||||
})
|
||||
})
|
||||
}
|
||||
const typeOfRemote = JSON.parse(message);
|
||||
expect(typeOfRemote).to.equal('undefined');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
generateSpecs('without sandbox', false)
|
||||
generateSpecs('with sandbox', true)
|
||||
})
|
||||
})
|
||||
generateSpecs('without sandbox', false);
|
||||
generateSpecs('with sandbox', true);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue