3da598015b
* chore: bump chromium in DEPS to 100.0.4880.0 * resolve conflicts * chore: update patches * fix patch * PIP20: add a new DocumentOverlayWindowViews subtype https://chromium-review.googlesource.com/c/chromium/src/+/3252789 * Clean up PictureInPictureWindowManager::EnterPictureInPicture() https://chromium-review.googlesource.com/c/chromium/src/+/3424145 * Remove StoragePartitionId. https://chromium-review.googlesource.com/c/chromium/src/+/2811120 * Remove FLoC code https://chromium-review.googlesource.com/c/chromium/src/+/3424359 * media: Make AddSupportedKeySystems() Async https://chromium-review.googlesource.com/c/chromium/src/+/3430502 * [Extensions] Move some l10n file util methods to //extensions/browser https://chromium-review.googlesource.com/c/chromium/src/+/3408192 * chore: IWYU * Reland "webhid: Grant permissions for policy-allowed devices" https://chromium-review.googlesource.com/c/chromium/src/+/3444147 * Migrate base::Value::GetList() to base::Value::GetListDeprecated(): 2/N. https://chromium-review.googlesource.com/c/chromium/src/+/3435727 https://chromium-review.googlesource.com/c/chromium/src/+/3440910 https://chromium-review.googlesource.com/c/chromium/src/+/3440088 * [text blink period] Cache blink period instead of fetching from defaults https://chromium-review.googlesource.com/c/chromium/src/+/3419059 * chore: update picture-in-picture.patch https://chromium-review.googlesource.com/c/chromium/src/+/3252789 * ci: update to Xcode 13.2.1 https://chromium-review.googlesource.com/c/chromium/src/+/3437552 * chore: bump chromium in DEPS to 100.0.4882.1 * chore: update patches * chore: bump chromium in DEPS to 100.0.4884.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4886.0 * chore: update patches * Refactor DownloadManager to use StoragePartitionConfig https://chromium-review.googlesource.com/c/chromium/src/+/3222011 * Remove ToWebInputElement() in favor of new WebNode::DynamicTo<> helpers. https://chromium-review.googlesource.com/c/chromium/src/+/3433852 * refactor: autofill to use the color pipeline https://bugs.chromium.org/p/chromium/issues/detail?id=1249558 https://bugs.chromium.org/p/chromium/issues/detail?id=1003612 * [ProcessSingleton] Add many more trace events to cover all scenarios https://chromium-review.googlesource.com/c/chromium/src/+/3429325 * fixup! PIP20: add a new DocumentOverlayWindowViews subtype * chore: bump chromium in DEPS to 100.0.4888.0 * chore: update patches * chore: update picture-in-picture.patch * fixup! refactor: autofill to use the color pipeline * ci: fixup fix sync (cherry picked from commit c1e3e395465739bce5ca8e1c5ec1f5bd72b99ebd) * chore: bump chromium in DEPS to 100.0.4889.0 * chore: update patches * chore: fix feat_add_data_transfer_to_requestsingleinstancelock.patch * fixup! PIP20: add a new DocumentOverlayWindowViews subtype * Remove remaining NativeTheme::GetSystemColor() machinery. https://chromium-review.googlesource.com/c/chromium/src/+/3421719 * ci: fetch proper esbuild for macos * ci: fixup fetch proper esbuild for macos * fix: failing Node.js test on outdated CurrentValueSerializerFormatVersion * chore: bump chromium in DEPS to 100.0.4892.0 * 3460365: Set V8 fatal error callbacks during Isolate initialization https://chromium-review.googlesource.com/c/chromium/src/+/3460365 * 3454343: PIP20: use permanent top controls https://chromium-review.googlesource.com/c/chromium/src/+/3454343 * 3465574: Move most of GTK color mixers to ui/color/. https://chromium-review.googlesource.com/c/chromium/src/+/3465574 * chore: fixup patch indices * 3445327: [locales] Remove locales reference https://chromium-review.googlesource.com/c/chromium/src/+/3445327 * 3456548: [DBB][#7] Blue border falls back to all tab if cropped-to zero pixels https://chromium-review.googlesource.com/c/chromium/src/+/3456548 * 3441196: Convert GuestView's remaining legacy IPC messages to Mojo https://chromium-review.googlesource.com/c/chromium/src/+/3441196 * 3455491: Don't include run_loop.h in thread_task_runner_handle.h https://chromium-review.googlesource.com/c/chromium/src/+/3455491 * fixup! 3454343: PIP20: use permanent top controls * 3442501: Add missing includes of //base/observer_list.h https://chromium-review.googlesource.com/c/chromium/src/+/3442501 * 3437552: mac: Deploy a new hermetic build of Xcode 13.2.1 13C100 https://chromium-review.googlesource.com/c/chromium/src/+/3437552 * chore: bump chromium in DEPS to 100.0.4894.0 * fixup! 3460365: Set V8 fatal error callbacks during Isolate initialization * chore: update patches * 3425231: Use DnsOverHttpsConfig where appropriate https://chromium-review.googlesource.com/c/chromium/src/+/3425231 * test: disable test-heapsnapshot-near-heap-limit-worker.js As a result of CLs linked in https://bugs.chromium.org/p/v8/issues/detail?id=12503, heap snapshotting near the heap limit DCHECKS in Node.js specs. This will likely require a larger refactor in Node.js so i've disabled the test for now and opened an upstream issue on node-v8 issue at https://github.com/nodejs/node-v8/issues/218. * Port all usage of NativeTheme color IDs to color pipeline https://bugs.chromium.org/p/chromium/issues/detail?id=1249558 * chore: update patches after rebase * ci: use gen2 machine for more disk space * ci: don't try to make root volume writeable * ci: use older xcode/macos for tests * fix: html fullscreen transitions stacking (cherry picked from commit 5e10965cdd7b2a024def5fc568912cefd0f05b44) * ci: speed up woa testing (cherry picked from commit 75c33c48b032137794f5734348a9ee3daa60d9de) (cherry picked from commit e81996234029669663bf0daaababd34684dcbb17) * ci: disable flaky tests on WOA * ci: run remote tests separately to isolate issue there * tests: disable node test parallel/test-worker-debug for now * revert: fix: html fullscreen transitions stacking * tests: disable flaky test on macOS arm64 * fixup circleci config so build tools can find xcode version * make sure the workspace is clean before job runs (cherry picked from commit 75f713c9748ac1a356846c39f268886130554fd6) * tests: disable flaky test on Linux * ci: debug why windows i32 is crashing * Revert "ci: debug why windows i32 is crashing" This reverts commit 4c4bba87ea76f16ef3b304dadff59ad4d366f60f. Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
833 lines
29 KiB
TypeScript
833 lines
29 KiB
TypeScript
import * as path from 'path';
|
|
import * as url from 'url';
|
|
import { BrowserWindow, session, ipcMain, app, WebContents } from 'electron/main';
|
|
import { closeAllWindows } from './window-helpers';
|
|
import { emittedOnce, emittedUntil } from './events-helpers';
|
|
import { ifit, delay } from './spec-helpers';
|
|
import { expect } from 'chai';
|
|
|
|
async function loadWebView (w: WebContents, attributes: Record<string, string>, openDevTools: boolean = false): Promise<void> {
|
|
await w.executeJavaScript(`
|
|
new Promise((resolve, reject) => {
|
|
const webview = new WebView()
|
|
for (const [k, v] of Object.entries(${JSON.stringify(attributes)})) {
|
|
webview.setAttribute(k, v)
|
|
}
|
|
document.body.appendChild(webview)
|
|
webview.addEventListener('dom-ready', () => {
|
|
if (${openDevTools}) {
|
|
webview.openDevTools()
|
|
}
|
|
})
|
|
webview.addEventListener('did-finish-load', () => {
|
|
resolve()
|
|
})
|
|
})
|
|
`);
|
|
}
|
|
|
|
describe('<webview> tag', function () {
|
|
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures');
|
|
|
|
afterEach(closeAllWindows);
|
|
|
|
function hideChildWindows (e: any, wc: WebContents) {
|
|
wc.on('new-window', (event, url, frameName, disposition, options) => {
|
|
options.show = false;
|
|
});
|
|
}
|
|
|
|
before(() => {
|
|
app.on('web-contents-created', hideChildWindows);
|
|
});
|
|
|
|
after(() => {
|
|
app.off('web-contents-created', hideChildWindows);
|
|
});
|
|
|
|
it('works without script tag in page', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html'));
|
|
await emittedOnce(ipcMain, 'pong');
|
|
});
|
|
|
|
it('works with sandbox', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
sandbox: true
|
|
}
|
|
});
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'));
|
|
await emittedOnce(ipcMain, 'pong');
|
|
});
|
|
|
|
it('works with contextIsolation', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
contextIsolation: true
|
|
}
|
|
});
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'));
|
|
await emittedOnce(ipcMain, 'pong');
|
|
});
|
|
|
|
it('works with contextIsolation + sandbox', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
contextIsolation: true,
|
|
sandbox: true
|
|
}
|
|
});
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-isolated.html'));
|
|
await emittedOnce(ipcMain, 'pong');
|
|
});
|
|
|
|
it('works with Trusted Types', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true
|
|
}
|
|
});
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-trusted-types.html'));
|
|
await emittedOnce(ipcMain, 'pong');
|
|
});
|
|
|
|
it('is disabled by default', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
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;
|
|
|
|
expect(type).to.equal('undefined', 'WebView still exists');
|
|
});
|
|
|
|
// FIXME(deepak1556): Ch69 follow up.
|
|
xdescribe('document.visibilityState/hidden', () => {
|
|
afterEach(() => {
|
|
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 [, 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();
|
|
|
|
// 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');
|
|
|
|
return getResponse.then(([, visibilityState, hidden]) => {
|
|
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 () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
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);
|
|
});
|
|
});
|
|
|
|
describe('did-attach event', () => {
|
|
it('is emitted when a webview has been attached', async () => {
|
|
const w = new BrowserWindow({
|
|
webPreferences: {
|
|
webviewTag: true
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
const message = await w.webContents.executeJavaScript(`new Promise((resolve, reject) => {
|
|
const webview = new WebView()
|
|
webview.setAttribute('src', 'about:blank')
|
|
webview.addEventListener('did-attach', (e) => {
|
|
resolve('ok')
|
|
})
|
|
document.body.appendChild(webview)
|
|
})`);
|
|
expect(message).to.equal('ok');
|
|
});
|
|
});
|
|
|
|
describe('did-change-theme-color event', () => {
|
|
it('emits when theme color changes', async () => {
|
|
const w = new BrowserWindow({
|
|
webPreferences: {
|
|
webviewTag: true
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
const src = url.format({
|
|
pathname: `${fixtures.replace(/\\/g, '/')}/pages/theme-color.html`,
|
|
protocol: 'file',
|
|
slashes: true
|
|
});
|
|
const message = await w.webContents.executeJavaScript(`new Promise((resolve, reject) => {
|
|
const webview = new WebView()
|
|
webview.setAttribute('src', '${src}')
|
|
webview.addEventListener('did-change-theme-color', (e) => {
|
|
resolve('ok')
|
|
})
|
|
document.body.appendChild(webview)
|
|
})`);
|
|
expect(message).to.equal('ok');
|
|
});
|
|
});
|
|
|
|
// This test is flaky on WOA, so skip it there.
|
|
ifit(process.platform !== 'win32' || process.arch !== 'arm64')('loads devtools extensions registered on the parent window', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
w.webContents.session.removeExtension('foo');
|
|
|
|
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo');
|
|
await w.webContents.session.loadExtension(extensionPath);
|
|
|
|
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'webview-devtools.html'));
|
|
loadWebView(w.webContents, {
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no',
|
|
src: `file://${path.join(__dirname, 'fixtures', 'blank.html')}`
|
|
}, true);
|
|
let childWebContentsId = 0;
|
|
app.once('web-contents-created', (e, webContents) => {
|
|
childWebContentsId = webContents.id;
|
|
webContents.on('devtools-opened', function () {
|
|
const showPanelIntervalId = setInterval(function () {
|
|
if (!webContents.isDestroyed() && webContents.devToolsWebContents) {
|
|
webContents.devToolsWebContents.executeJavaScript('(' + function () {
|
|
const { UI } = (window as any);
|
|
const tabs = UI.inspectorView.tabbedPane.tabs;
|
|
const lastPanelId: any = tabs[tabs.length - 1].id;
|
|
UI.inspectorView.showPanel(lastPanelId);
|
|
}.toString() + ')()');
|
|
} else {
|
|
clearInterval(showPanelIntervalId);
|
|
}
|
|
}, 100);
|
|
});
|
|
});
|
|
|
|
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');
|
|
|
|
before(() => {
|
|
const protocol = webviewSession.protocol;
|
|
protocol.registerStringProtocol(zoomScheme, (request, callback) => {
|
|
callback('hello');
|
|
});
|
|
});
|
|
|
|
after(() => {
|
|
const protocol = webviewSession.protocol;
|
|
protocol.unregisterProtocol(zoomScheme);
|
|
});
|
|
|
|
it('inherits the zoomFactor of the parent window', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
zoomFactor: 1.2,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
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);
|
|
});
|
|
|
|
it('maintains zoom level on navigation', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
zoomFactor: 1.2,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
const promise = new Promise<void>((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);
|
|
} else {
|
|
expect(zoomFactor).to.equal(1.2);
|
|
expect(zoomLevel).to.equal(1);
|
|
}
|
|
|
|
if (final) {
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-custom-zoom-level.html'));
|
|
|
|
await promise;
|
|
});
|
|
|
|
it('maintains zoom level when navigating within same page', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
zoomFactor: 1.2,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
const promise = new Promise<void>((resolve) => {
|
|
ipcMain.on('webview-zoom-in-page', (event, zoomLevel, zoomFactor, final) => {
|
|
expect(zoomFactor).to.equal(1.44);
|
|
expect(zoomLevel).to.equal(2.0);
|
|
|
|
if (final) {
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-in-page-navigate.html'));
|
|
|
|
await promise;
|
|
});
|
|
|
|
it('inherits zoom level for the origin when available', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
zoomFactor: 1.2,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
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);
|
|
});
|
|
|
|
it('does not crash when navigating with zoom level inherited from parent', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
zoomFactor: 1.2,
|
|
session: webviewSession,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
const attachPromise = emittedOnce(w.webContents, 'did-attach-webview');
|
|
const readyPromise = emittedOnce(ipcMain, 'dom-ready');
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-inherited.html'));
|
|
const [, webview] = await attachPromise;
|
|
await readyPromise;
|
|
expect(webview.getZoomFactor()).to.equal(1.2);
|
|
await w.loadURL(`${zoomScheme}://host1`);
|
|
});
|
|
|
|
it('does not crash when changing zoom level after webview is destroyed', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
session: webviewSession,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
const attachPromise = emittedOnce(w.webContents, 'did-attach-webview');
|
|
await w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-inherited.html'));
|
|
await attachPromise;
|
|
await w.webContents.executeJavaScript('view.remove()');
|
|
w.webContents.setZoomLevel(0.5);
|
|
});
|
|
});
|
|
|
|
describe('requestFullscreen from webview', () => {
|
|
const loadWebViewWindow = async () => {
|
|
const w = new BrowserWindow({
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
const attachPromise = emittedOnce(w.webContents, 'did-attach-webview');
|
|
const readyPromise = emittedOnce(ipcMain, 'webview-ready');
|
|
w.loadFile(path.join(__dirname, 'fixtures', 'webview', 'fullscreen', 'main.html'));
|
|
const [, webview] = await attachPromise;
|
|
await readyPromise;
|
|
return [w, webview];
|
|
};
|
|
|
|
afterEach(closeAllWindows);
|
|
|
|
// TODO(jkleinsc) fix this test on arm64 macOS. It causes the tests following it to fail/be flaky
|
|
ifit(process.platform !== 'darwin' || process.arch !== 'arm64')('should make parent frame element fullscreen too', async () => {
|
|
const [w, webview] = await loadWebViewWindow();
|
|
expect(await w.webContents.executeJavaScript('isIframeFullscreen()')).to.be.false();
|
|
|
|
const parentFullscreen = emittedOnce(ipcMain, 'fullscreenchange');
|
|
await webview.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
|
|
await parentFullscreen;
|
|
expect(await w.webContents.executeJavaScript('isIframeFullscreen()')).to.be.true();
|
|
});
|
|
|
|
// FIXME(zcbenz): Fullscreen events do not work on Linux.
|
|
// This test is flaky on arm64 macOS.
|
|
ifit(process.platform !== 'linux' && process.arch !== 'arm64')('exiting fullscreen should unfullscreen window', async () => {
|
|
const [w, webview] = await loadWebViewWindow();
|
|
const enterFullScreen = emittedOnce(w, 'enter-full-screen');
|
|
await webview.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
|
|
await enterFullScreen;
|
|
|
|
const leaveFullScreen = emittedOnce(w, 'leave-full-screen');
|
|
await webview.executeJavaScript('document.exitFullscreen()', true);
|
|
await leaveFullScreen;
|
|
await delay(0);
|
|
expect(w.isFullScreen()).to.be.false();
|
|
});
|
|
|
|
// Sending ESC via sendInputEvent only works on Windows.
|
|
ifit(process.platform === 'win32')('pressing ESC should unfullscreen window', async () => {
|
|
const [w, webview] = await loadWebViewWindow();
|
|
const enterFullScreen = emittedOnce(w, 'enter-full-screen');
|
|
await webview.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
|
|
await enterFullScreen;
|
|
|
|
const leaveFullScreen = emittedOnce(w, 'leave-full-screen');
|
|
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
|
|
await leaveFullScreen;
|
|
await delay(0);
|
|
expect(w.isFullScreen()).to.be.false();
|
|
});
|
|
|
|
it('pressing ESC should emit the leave-html-full-screen event', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
nodeIntegration: true,
|
|
contextIsolation: false
|
|
}
|
|
});
|
|
|
|
const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview');
|
|
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'));
|
|
|
|
const [, webContents] = await didAttachWebview;
|
|
|
|
const enterFSWindow = emittedOnce(w, 'enter-html-full-screen');
|
|
const enterFSWebview = emittedOnce(webContents, 'enter-html-full-screen');
|
|
await webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
|
|
await enterFSWindow;
|
|
await enterFSWebview;
|
|
|
|
const leaveFSWindow = emittedOnce(w, 'leave-html-full-screen');
|
|
const leaveFSWebview = emittedOnce(webContents, 'leave-html-full-screen');
|
|
webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
|
|
await leaveFSWindow;
|
|
await leaveFSWebview;
|
|
});
|
|
});
|
|
|
|
describe('child windows', () => {
|
|
let w: BrowserWindow;
|
|
beforeEach(async () => {
|
|
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true, contextIsolation: false } });
|
|
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.
|
|
loadWebView(w.webContents, {
|
|
allowpopups: 'on',
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no',
|
|
src: `file://${path.join(fixtures, 'api', 'native-window-open-blank.html')}`
|
|
});
|
|
|
|
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.
|
|
loadWebView(w.webContents, {
|
|
allowpopups: 'on',
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no',
|
|
src: `file://${path.join(fixtures, 'api', 'native-window-open-file.html')}`
|
|
});
|
|
|
|
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.
|
|
loadWebView(w.webContents, {
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no',
|
|
src: `file://${path.join(fixtures, 'api', 'native-window-open-no-allowpopups.html')}`
|
|
});
|
|
|
|
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.
|
|
loadWebView(w.webContents, {
|
|
allowpopups: 'on',
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no',
|
|
src: `file://${path.join(fixtures, 'api', 'native-window-open-cross-origin.html')}`
|
|
});
|
|
|
|
const [, content] = await emittedOnce(ipcMain, 'answer');
|
|
const expectedContent =
|
|
'Blocked a frame with origin "file://" from accessing a cross-origin frame.';
|
|
|
|
expect(content).to.equal(expectedContent);
|
|
});
|
|
|
|
it('emits a new-window event', async () => {
|
|
// Don't wait for loading to finish.
|
|
const attributes = {
|
|
allowpopups: 'on',
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no',
|
|
src: `file://${fixtures}/pages/window-open.html`
|
|
};
|
|
const { url, frameName } = await w.webContents.executeJavaScript(`
|
|
new Promise((resolve, reject) => {
|
|
const webview = document.createElement('webview')
|
|
for (const [k, v] of Object.entries(${JSON.stringify(attributes)})) {
|
|
webview.setAttribute(k, v)
|
|
}
|
|
document.body.appendChild(webview)
|
|
webview.addEventListener('new-window', (e) => {
|
|
resolve({url: e.url, frameName: e.frameName})
|
|
})
|
|
})
|
|
`);
|
|
|
|
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.
|
|
loadWebView(w.webContents, {
|
|
allowpopups: 'on',
|
|
webpreferences: 'contextIsolation=no',
|
|
src: `file://${fixtures}/pages/window-open.html`
|
|
});
|
|
|
|
await emittedOnce(app, 'browser-window-created');
|
|
});
|
|
|
|
it('emits a web-contents-created event', async () => {
|
|
const webContentsCreated = emittedUntil(app, 'web-contents-created',
|
|
(event: Electron.Event, contents: Electron.WebContents) => contents.getType() === 'window');
|
|
|
|
loadWebView(w.webContents, {
|
|
allowpopups: 'on',
|
|
webpreferences: 'contextIsolation=no',
|
|
src: `file://${fixtures}/pages/window-open.html`
|
|
});
|
|
|
|
await webContentsCreated;
|
|
});
|
|
|
|
it('does not crash when creating window with noopener', async () => {
|
|
loadWebView(w.webContents, {
|
|
allowpopups: 'on',
|
|
src: `file://${path.join(fixtures, 'api', 'native-window-open-noopener.html')}`
|
|
});
|
|
await emittedOnce(app, 'browser-window-created');
|
|
});
|
|
});
|
|
|
|
describe('webpreferences attribute', () => {
|
|
let w: BrowserWindow;
|
|
beforeEach(async () => {
|
|
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, {
|
|
allowpopups: 'yes',
|
|
preload: `file://${fixtures}/api/isolated-preload.js`,
|
|
src: `file://${fixtures}/api/isolated.html`,
|
|
webpreferences: 'contextIsolation=yes'
|
|
});
|
|
|
|
const [, data] = await emittedOnce(ipcMain, 'isolated-world');
|
|
expect(data).to.deep.equal({
|
|
preloadContext: {
|
|
preloadProperty: 'number',
|
|
pageProperty: 'undefined',
|
|
typeofRequire: 'function',
|
|
typeofProcess: 'object',
|
|
typeofArrayPush: 'function',
|
|
typeofFunctionApply: 'function',
|
|
typeofPreloadExecuteJavaScriptProperty: 'undefined'
|
|
},
|
|
pageContext: {
|
|
preloadProperty: 'undefined',
|
|
pageProperty: 'string',
|
|
typeofRequire: 'undefined',
|
|
typeofProcess: 'undefined',
|
|
typeofArrayPush: 'number',
|
|
typeofFunctionApply: 'boolean',
|
|
typeofPreloadExecuteJavaScriptProperty: 'number',
|
|
typeofOpenedWindow: 'object'
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('permission request handlers', () => {
|
|
let w: BrowserWindow;
|
|
beforeEach(async () => {
|
|
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true, contextIsolation: false } });
|
|
await w.loadURL('about:blank');
|
|
});
|
|
afterEach(closeAllWindows);
|
|
|
|
const partition = 'permissionTest';
|
|
|
|
function setUpRequestHandler (webContentsId: number, requestedPermission: string) {
|
|
return new Promise<void>((resolve, reject) => {
|
|
session.fromPartition(partition).setPermissionRequestHandler(function (webContents, permission, callback) {
|
|
if (webContents.id === webContentsId) {
|
|
// 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);
|
|
}
|
|
|
|
try {
|
|
expect(permission).to.equal(requestedPermission);
|
|
} catch (e) {
|
|
return reject(e);
|
|
}
|
|
callback(false);
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
afterEach(() => {
|
|
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');
|
|
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');
|
|
});
|
|
|
|
it('emits when using navigator.geolocation api', async () => {
|
|
const errorFromRenderer = emittedOnce(ipcMain, 'message');
|
|
loadWebView(w.webContents, {
|
|
src: `file://${fixtures}/pages/permissions/geolocation.html`,
|
|
partition,
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no'
|
|
});
|
|
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');
|
|
loadWebView(w.webContents, {
|
|
src: `file://${fixtures}/pages/permissions/midi.html`,
|
|
partition,
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no'
|
|
});
|
|
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');
|
|
loadWebView(w.webContents, {
|
|
src: `file://${fixtures}/pages/permissions/midi-sysex.html`,
|
|
partition,
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no'
|
|
});
|
|
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');
|
|
});
|
|
|
|
it('emits when using Notification.requestPermission', async () => {
|
|
const errorFromRenderer = emittedOnce(ipcMain, 'message');
|
|
loadWebView(w.webContents, {
|
|
src: `file://${fixtures}/pages/permissions/notification.html`,
|
|
partition,
|
|
nodeintegration: 'on',
|
|
webpreferences: 'contextIsolation=no'
|
|
});
|
|
const [, webViewContents] = await emittedOnce(app, 'web-contents-created');
|
|
|
|
await setUpRequestHandler(webViewContents.id, 'notifications');
|
|
|
|
const [, error] = await errorFromRenderer;
|
|
expect(error).to.equal('denied');
|
|
});
|
|
});
|
|
|
|
describe('DOM events', () => {
|
|
afterEach(closeAllWindows);
|
|
it('receives extra properties on DOM events when contextIsolation is enabled', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
contextIsolation: true
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
const message = await w.webContents.executeJavaScript(`new Promise((resolve, reject) => {
|
|
const webview = new WebView()
|
|
webview.setAttribute('src', 'data:text/html,<script>console.log("hi")</script>')
|
|
webview.addEventListener('console-message', (e) => {
|
|
resolve(e.message)
|
|
})
|
|
document.body.appendChild(webview)
|
|
})`);
|
|
expect(message).to.equal('hi');
|
|
});
|
|
|
|
it('emits focus event when contextIsolation is enabled', async () => {
|
|
const w = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
webviewTag: true,
|
|
contextIsolation: true
|
|
}
|
|
});
|
|
await w.loadURL('about:blank');
|
|
await w.webContents.executeJavaScript(`new Promise((resolve, reject) => {
|
|
const webview = new WebView()
|
|
webview.setAttribute('src', 'about:blank')
|
|
webview.addEventListener('dom-ready', () => {
|
|
webview.focus()
|
|
})
|
|
webview.addEventListener('focus', () => {
|
|
resolve();
|
|
})
|
|
document.body.appendChild(webview)
|
|
})`);
|
|
});
|
|
});
|
|
});
|