electron/spec/webview-spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

2235 lines
79 KiB
TypeScript
Raw Normal View History

chore: bump chromium to 141.0.7361.0 (main) (#48054) * chore: bump chromium in DEPS to 141.0.7352.0 * chore: update patches * 6830573: Revert 'Migrate WrappableWithNamedPropertyInterceptor to gin::Wrappable' | https://chromium-review.googlesource.com/c/chromium/src/+/6830573 * chore: bump chromium in DEPS to 141.0.7354.0 * chore: bump chromium in DEPS to 141.0.7356.0 * chore: bump chromium in DEPS to 141.0.7357.0 * chore: bump chromium in DEPS to 141.0.7359.0 * chore: bump chromium in DEPS to 141.0.7361.0 * 6838518: [Mac] Correctly deallocate sandbox error buffers and prevent crash resulting from nullptr assignment | https://chromium-review.googlesource.com/c/chromium/src/+/6838518 * 6850973: Reland "Use base::ByteCount in base::SysInfo." | https://chromium-review.googlesource.com/c/chromium/src/+/6850973 * 6506565: [FPF-CI] Create initial NoiseHash in the browser. | https://chromium-review.googlesource.com/c/chromium/src/+/6506565 * chore: update patches * fixup! 6850973: Reland "Use base::ByteCount in base::SysInfo." | https://chromium-review.googlesource.com/c/chromium/src/+/6850973 * fixup! 6506565: [FPF-CI] Create initial NoiseHash in the browser. | https://chromium-review.googlesource.com/c/chromium/src/+/6506565 * fix: unsafe buffer warning in fix_properly_honor_printing_page_ranges.patch * fix: FTBFS in src_remove_dependency_on_wrapper-descriptor-based_cppheap.patch This change should be upstreamed. Fixes this error: ../../third_party/electron_node/src/env.cc:606:3: error: no matching function for call to 'Wrap' 606 | v8::Object::Wrap<v8::CppHeapPointerTag::kDefaultTag>( | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1076:14: note: candidate function template not viable: cannot convert argument of incomplete type 'void *' to 'v8::Object::Wrappable *' for 3rd argument 1076 | void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper, | ^ 1077 | v8::Object::Wrappable* wrappable) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1084:14: note: candidate function template not viable: no known conversion from 'Local<Object>' to 'const PersistentBase<Object>' for 2nd argument 1084 | void Object::Wrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper, | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1093:14: note: candidate function template not viable: no known conversion from 'Local<Object>' to 'const BasicTracedReference<Object>' for 2nd argument 1093 | void Object::Wrap(v8::Isolate* isolate, | ^ 1094 | const BasicTracedReference<Object>& wrapper, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. * [v8-init] Access crash key only from main thread | https://chromium-review.googlesource.com/c/chromium/src/+/6827167 * chore: e patches all * chore: remove chore_restore_some_deprecated_wrapper_utility_in_gin.patch from patches this remove line got re-added when rebasing roller/chromium/main * chore: e patches all * fix: include base/time/time.h when using base::Time * chore: update patches * Make --host-rules an alias for --host-resolver-rules. Refs https://chromium-review.googlesource.com/c/chromium/src/+/4867872 * ci: update BUILD_TOOLS_SHA Refs https://github.com/electron/build-tools/pull/746 * [Fontations] Remove Fontations suffix from font names Refs https://chromium-review.googlesource.com/c/chromium/src/+/6835930 * temp: debug macOS addon build failure * Revert "temp: debug macOS addon build failure" This reverts commit 40bc8abab65dc83e17c4ab97cb6e7522a193fb44. * test: run tests with Xcode 16.4 * ci: fix tccdb update for macOS 15 * spec: disable opening external application for loadURL on macOS opening unknown external application will bring up dialog to choose apps from application store which will break our other test suites that want to capture screen for pixel matching. The loadURL spec that tests bad-scheme://foo is sufficient that we hit the permission handler for openExternal since at that point we already know the runtime gave up on handling the scheme. * chore: rebase patches * chore: disable codesiging tests * ci: update ScreenCaptureApprovals.plist for /bin/bash * ci: try updating tcc permissions * ci: update TCC permissions Refs https://www.rainforestqa.com/blog/macos-tcc-db-deep-dive * chore: test with 1st quadrant of the window * chore: adjust for macOS 15 menubar height --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2025-08-29 12:31:47 +09:00
import { BrowserWindow, session, ipcMain, app, WebContents, screen } from 'electron/main';
import * as auth from 'basic-auth';
import { expect } from 'chai';
import { once } from 'node:events';
import * as http from 'node:http';
import * as path from 'node:path';
import { setTimeout } from 'node:timers/promises';
import * as url from 'node:url';
import { emittedUntil } from './lib/events-helpers';
import { HexColors, ScreenCapture, hasCapturableScreen } from './lib/screen-helpers';
import { ifit, ifdescribe, defer, itremote, useRemoteContext, listen } from './lib/spec-helpers';
import { closeAllWindows } from './lib/window-helpers';
declare let WebView: any;
const features = process._linkedBinding('electron_common_features');
async function loadWebView (w: WebContents, attributes: Record<string, string>, opts?: {openDevTools?: boolean}): Promise<void> {
const { openDevTools } = {
openDevTools: false,
...opts
};
await w.executeJavaScript(`
new Promise((resolve, reject) => {
const webview = new WebView()
webview.id = '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()
})
})
`);
}
async function loadWebViewAndWaitForEvent (w: WebContents, attributes: Record<string, string>, eventName: string): Promise<any> {
return await w.executeJavaScript(`new Promise((resolve, reject) => {
const webview = new WebView()
webview.id = 'webview'
for (const [k, v] of Object.entries(${JSON.stringify(attributes)})) {
webview.setAttribute(k, v)
}
webview.addEventListener(${JSON.stringify(eventName)}, (e) => resolve({...e}), {once: true})
document.body.appendChild(webview)
})`);
};
async function loadWebViewAndWaitForMessage (w: WebContents, attributes: Record<string, string>): Promise<string> {
const { message } = await loadWebViewAndWaitForEvent(w, attributes, 'console-message');
return message;
};
describe('<webview> tag', function () {
const fixtures = path.join(__dirname, 'fixtures');
const blankPageUrl = url.pathToFileURL(path.join(fixtures, 'pages', 'blank.html')).toString();
function hideChildWindows (e: any, wc: WebContents) {
wc.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
show: false
}
}));
}
before(() => {
app.on('web-contents-created', hideChildWindows);
});
after(() => {
app.off('web-contents-created', hideChildWindows);
});
describe('behavior', () => {
afterEach(closeAllWindows);
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 once(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 once(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 once(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 once(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 once(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 = once(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');
});
afterEach(closeAllWindows);
it('updates when the window is shown after the ready-to-show event', async () => {
const w = new BrowserWindow({ show: false });
const readyToShowSignal = once(w, 'ready-to-show');
const pongSignal1 = once(ipcMain, 'pong');
w.loadFile(path.join(fixtures, 'pages', 'webview-visibilitychange.html'));
await pongSignal1;
const pongSignal2 = once(ipcMain, 'pong');
await readyToShowSignal;
w.show();
2020-03-20 13:28:31 -07:00
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 once(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 = once(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', () => {
afterEach(closeAllWindows);
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 = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
const webviewDomReady = once(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', () => {
afterEach(closeAllWindows);
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', () => {
afterEach(closeAllWindows);
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.replaceAll('\\', '/')}/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');
});
});
describe('devtools', () => {
afterEach(closeAllWindows);
// FIXME: 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');
chore: bump chromium to 117.0.5913.0 (main) (#39172) * chore: bump chromium in DEPS to 117.0.5899.0 * 4686653: webui: Filter out non-chrome scheme URLs in WebUIConfigMap https://chromium-review.googlesource.com/c/chromium/src/+/4686653 * 4696355: Remove deprecated version of base::CommandLine::CopySwitchesFrom() https://chromium-review.googlesource.com/c/chromium/src/+/4696355 * chore: fixup patch indices * 4603888: Reland "Enable raw_ref check on linux" https://chromium-review.googlesource.com/c/chromium/src/+/4603888 * chore: bump chromium in DEPS to 117.0.5901.0 * chore: update patches * chore: bump chromium in DEPS to 117.0.5903.0 * chore: bump chromium in DEPS to 117.0.5903.2 * chore: bump chromium in DEPS to 117.0.5905.0 * 4706792: Printing: Add debug code for a DispatchBeforePrintEvent() failure https://chromium-review.googlesource.com/c/chromium/src/+/4706792 * 4704786: Refactor libunwind build rules/flags https://chromium-review.googlesource.com/c/chromium/src/+/4704786 * 4701710: [Linux Ui] Set toolkit dark preference based on FDO dark preference https://chromium-review.googlesource.com/c/chromium/src/+/4701710 * chore: fixup patch indices * chore: bump chromium in DEPS to 117.0.5907.0 * chore: bump chromium in DEPS to 117.0.5909.2 * chore: update patches * chore: bump chromium in DEPS to 117.0.5911.0 * chore: update patches * chore: build-what-we-include * fix: set allowFileAccess on devtools extensions correctly Ref: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4714725 * 4670615: Reland "[iterator-helpers] Shipping iterator helpers" https://chromium-review.googlesource.com/c/v8/v8/+/4670615 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
2023-07-31 10:47:32 -07:00
await w.webContents.session.loadExtension(extensionPath, {
allowFileAccess: true
});
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')}`
}, { openDevTools: 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 { EUI } = (window as any);
const instance = EUI.InspectorView.InspectorView.instance();
const tabs = instance.tabbedPane.tabs;
const lastPanelId: any = tabs[tabs.length - 1].id;
instance.showPanel(lastPanelId);
}.toString() + ')()');
} else {
clearInterval(showPanelIntervalId);
}
}, 100);
});
});
const [, { runtimeId, tabId }] = await once(ipcMain, 'answer');
expect(runtimeId).to.match(/^[a-z]{32}$/);
expect(tabId).to.equal(childWebContentsId);
await w.webContents.executeJavaScript('webview.closeDevTools()');
});
});
describe('zoom behavior', () => {
const zoomScheme = standardScheme;
const webviewSession = session.fromPartition('webview-temp');
afterEach(closeAllWindows);
before(() => {
const protocol = webviewSession.protocol;
protocol.registerStringProtocol(zoomScheme, (request, respond) => {
respond('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 = once(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 the zoom level for a given host in the same session after navigation', () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: false
}
});
const zoomPromise = new Promise<void>((resolve) => {
ipcMain.on('webview-zoom-persist-level', (_event, values) => {
resolve(values);
});
});
w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-change-persist-host.html'));
expect(zoomPromise).to.eventually.deep.equal({
initialZoomLevel: 2,
switchZoomLevel: 3,
finalZoomLevel: 2
});
});
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 once(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 = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
const readyPromise = once(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 = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
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', () => {
afterEach(closeAllWindows);
async function loadWebViewWindow (): Promise<[BrowserWindow, WebContents]> {
const w = new BrowserWindow({
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: false
}
});
const attachPromise = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
const loadPromise = once(w.webContents, 'did-finish-load');
const readyPromise = once(ipcMain, 'webview-ready');
w.loadFile(path.join(__dirname, 'fixtures', 'webview', 'fullscreen', 'main.html'));
const [, webview] = await attachPromise;
await Promise.all([readyPromise, loadPromise]);
return [w, webview];
};
afterEach(async () => {
// The leaving animation is un-observable but can interfere with future tests
// Specifically this is async on macOS but can be on other platforms too
await setTimeout(1000);
closeAllWindows();
});
ifit(process.platform !== 'darwin')('should make parent frame element fullscreen too (non-macOS)', async () => {
const [w, webview] = await loadWebViewWindow();
expect(await w.webContents.executeJavaScript('isIframeFullscreen()')).to.be.false();
const parentFullscreen = once(ipcMain, 'fullscreenchange');
await webview.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await parentFullscreen;
expect(await w.webContents.executeJavaScript('isIframeFullscreen()')).to.be.true();
const close = once(w, 'closed');
w.close();
await close;
});
ifit(process.platform === 'darwin')('should make parent frame element fullscreen too (macOS)', async () => {
const [w, webview] = await loadWebViewWindow();
expect(await w.webContents.executeJavaScript('isIframeFullscreen()')).to.be.false();
const parentFullscreen = once(ipcMain, 'fullscreenchange');
const enterHTMLFS = once(w.webContents, 'enter-html-full-screen');
const leaveHTMLFS = once(w.webContents, 'leave-html-full-screen');
await webview.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
expect(await w.webContents.executeJavaScript('isIframeFullscreen()')).to.be.true();
await webview.executeJavaScript('document.exitFullscreen()');
await Promise.all([enterHTMLFS, leaveHTMLFS, parentFullscreen]);
const close = once(w, 'closed');
w.close();
await close;
});
// FIXME(zcbenz): Fullscreen events do not work on Linux.
ifit(process.platform !== 'linux')('exiting fullscreen should unfullscreen window', async () => {
const [w, webview] = await loadWebViewWindow();
const enterFullScreen = once(w, 'enter-full-screen');
await webview.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;
const leaveFullScreen = once(w, 'leave-full-screen');
await webview.executeJavaScript('document.exitFullscreen()', true);
await leaveFullScreen;
await setTimeout();
expect(w.isFullScreen()).to.be.false();
const close = once(w, 'closed');
w.close();
await close;
});
it('pressing ESC should unfullscreen window', async () => {
const [w, webview] = await loadWebViewWindow();
const enterFullScreen = once(w, 'enter-full-screen');
await webview.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;
const leaveFullScreen = once(w, 'leave-full-screen');
webview.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
await leaveFullScreen;
await setTimeout(1000);
expect(w.isFullScreen()).to.be.false();
const close = once(w, 'closed');
w.close();
await close;
});
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 = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'));
const [, webContents] = await didAttachWebview;
const enterFSWindow = once(w, 'enter-html-full-screen');
const enterFSWebview = once(webContents, 'enter-html-full-screen');
await webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFSWindow;
await enterFSWebview;
const leaveFSWindow = once(w, 'leave-html-full-screen');
const leaveFSWebview = once(webContents, 'leave-html-full-screen');
webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
await leaveFSWebview;
await leaveFSWindow;
const close = once(w, 'closed');
w.close();
await close;
});
it('should support user gesture', async () => {
const [w, webview] = await loadWebViewWindow();
const waitForEnterHtmlFullScreen = once(webview, 'enter-html-full-screen');
const jsScript = "document.querySelector('video').webkitRequestFullscreen()";
webview.executeJavaScript(jsScript, true);
await waitForEnterHtmlFullScreen;
const close = once(w, 'closed');
w.close();
await close;
});
});
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 once(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 once(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 once(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 once(ipcMain, 'answer');
const expectedContent =
chore: bump chromium to 119.0.6006.0 (main) (#39774) * chore: bump chromium in DEPS to 119.0.5994.0 * chore: update patches * Add some more debugging for navigation origin & process lock mismatch https://chromium-review.googlesource.com/c/chromium/src/+/4829483 * chore: bump chromium in DEPS to 119.0.5996.2 * chore: bump chromium in DEPS to 119.0.5997.0 * chore: bump chromium in DEPS to 119.0.6000.0 * chore: bump chromium in DEPS to 119.0.6002.0 * 4781766: Port remaining control color ids to the color pipeline https://chromium-review.googlesource.com/c/chromium/src/+/4781766 * 4846057: Preloading: Move prefetch_prefs to chrome/browser/preloading/ https://chromium-review.googlesource.com/c/chromium/src/+/4846057 * chore: fixup patch indices * 4848108: Pass v8::Isolate into FromV8Value calls on blink API https://chromium-review.googlesource.com/c/chromium/src/+/4848108 * 4834471: Reland "[api] allow v8::Data as internal field" https://chromium-review.googlesource.com/c/v8/v8/+/4834471 * 4808884: Major overhaul of ExceptionState in the v8 bindings https://chromium-review.googlesource.com/c/chromium/src/+/4808884 * 4791643: [sandbox] Add a TRUSTED_SPACE and TRUSTED_LO_SPACE to the V8 heap https://chromium-review.googlesource.com/c/v8/v8/+/4791643 * chore: bump chromium in DEPS to 119.0.6005.0 * 4776268: [v8][etw] Enables filtering of ETW tracing by URL https://chromium-review.googlesource.com/c/chromium/src/+/4776268 * chore: fixup patch indices * 4673258: WebSQL: Disable WebSQL by default https://chromium-review.googlesource.com/c/chromium/src/+/4673258 * chore: bump chromium in DEPS to 119.0.6006.0 * chore: update patches * 4854732: Reland^2 "[iterator-helpers] Unship due to incompat" https://chromium-review.googlesource.com/c/v8/v8/+/4854732 * 4794133: [AWC] Add `display-state` CSS @media feature https://chromium-review.googlesource.com/c/chromium/src/+/4794133 * fixup! Add some more debugging for navigation origin & process lock mismatch * Revert "fixup! Add some more debugging for navigation origin & process lock mismatch" This reverts commit 38fef075fc5690f7db6d4bbcabbe877a1618a964. * 4858437: Revert "[iOS] Delete GN flags for mach absolute time ticks" https://chromium-review.googlesource.com/c/chromium/src/+/4858437 * refactor: fix_crash_loading_non-standard_schemes_in_iframes.patch (#39879) * chore: 4869108: handle absolute and relative gn imports in autoninja https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4869108 * chore: set GOMA_DIR for autoninja * Revert "chore: 4869108: handle absolute and relative gn imports in autoninja" This reverts commit d94c7720bab96d1de25499383948da2cb8862d90. --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Robo <hop2deep@gmail.com>
2023-09-18 16:44:09 -04:00
/Failed to read a named property 'toString' from 'Location': Blocked a frame with origin "(.*?)" from accessing a cross-origin frame./;
chore: bump chromium to 119.0.6006.0 (main) (#39774) * chore: bump chromium in DEPS to 119.0.5994.0 * chore: update patches * Add some more debugging for navigation origin & process lock mismatch https://chromium-review.googlesource.com/c/chromium/src/+/4829483 * chore: bump chromium in DEPS to 119.0.5996.2 * chore: bump chromium in DEPS to 119.0.5997.0 * chore: bump chromium in DEPS to 119.0.6000.0 * chore: bump chromium in DEPS to 119.0.6002.0 * 4781766: Port remaining control color ids to the color pipeline https://chromium-review.googlesource.com/c/chromium/src/+/4781766 * 4846057: Preloading: Move prefetch_prefs to chrome/browser/preloading/ https://chromium-review.googlesource.com/c/chromium/src/+/4846057 * chore: fixup patch indices * 4848108: Pass v8::Isolate into FromV8Value calls on blink API https://chromium-review.googlesource.com/c/chromium/src/+/4848108 * 4834471: Reland "[api] allow v8::Data as internal field" https://chromium-review.googlesource.com/c/v8/v8/+/4834471 * 4808884: Major overhaul of ExceptionState in the v8 bindings https://chromium-review.googlesource.com/c/chromium/src/+/4808884 * 4791643: [sandbox] Add a TRUSTED_SPACE and TRUSTED_LO_SPACE to the V8 heap https://chromium-review.googlesource.com/c/v8/v8/+/4791643 * chore: bump chromium in DEPS to 119.0.6005.0 * 4776268: [v8][etw] Enables filtering of ETW tracing by URL https://chromium-review.googlesource.com/c/chromium/src/+/4776268 * chore: fixup patch indices * 4673258: WebSQL: Disable WebSQL by default https://chromium-review.googlesource.com/c/chromium/src/+/4673258 * chore: bump chromium in DEPS to 119.0.6006.0 * chore: update patches * 4854732: Reland^2 "[iterator-helpers] Unship due to incompat" https://chromium-review.googlesource.com/c/v8/v8/+/4854732 * 4794133: [AWC] Add `display-state` CSS @media feature https://chromium-review.googlesource.com/c/chromium/src/+/4794133 * fixup! Add some more debugging for navigation origin & process lock mismatch * Revert "fixup! Add some more debugging for navigation origin & process lock mismatch" This reverts commit 38fef075fc5690f7db6d4bbcabbe877a1618a964. * 4858437: Revert "[iOS] Delete GN flags for mach absolute time ticks" https://chromium-review.googlesource.com/c/chromium/src/+/4858437 * refactor: fix_crash_loading_non-standard_schemes_in_iframes.patch (#39879) * chore: 4869108: handle absolute and relative gn imports in autoninja https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4869108 * chore: set GOMA_DIR for autoninja * Revert "chore: 4869108: handle absolute and relative gn imports in autoninja" This reverts commit d94c7720bab96d1de25499383948da2cb8862d90. --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Robo <hop2deep@gmail.com>
2023-09-18 16:44:09 -04:00
expect(content).to.match(expectedContent);
});
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 once(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 once(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);
2019-11-01 13:37:02 -07:00
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 once(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('webpreferences attribute', () => {
const WINDOW_BACKGROUND_COLOR = '#55ccbb';
let w: BrowserWindow;
before(async () => {
chore: bump chromium to 141.0.7361.0 (main) (#48054) * chore: bump chromium in DEPS to 141.0.7352.0 * chore: update patches * 6830573: Revert 'Migrate WrappableWithNamedPropertyInterceptor to gin::Wrappable' | https://chromium-review.googlesource.com/c/chromium/src/+/6830573 * chore: bump chromium in DEPS to 141.0.7354.0 * chore: bump chromium in DEPS to 141.0.7356.0 * chore: bump chromium in DEPS to 141.0.7357.0 * chore: bump chromium in DEPS to 141.0.7359.0 * chore: bump chromium in DEPS to 141.0.7361.0 * 6838518: [Mac] Correctly deallocate sandbox error buffers and prevent crash resulting from nullptr assignment | https://chromium-review.googlesource.com/c/chromium/src/+/6838518 * 6850973: Reland "Use base::ByteCount in base::SysInfo." | https://chromium-review.googlesource.com/c/chromium/src/+/6850973 * 6506565: [FPF-CI] Create initial NoiseHash in the browser. | https://chromium-review.googlesource.com/c/chromium/src/+/6506565 * chore: update patches * fixup! 6850973: Reland "Use base::ByteCount in base::SysInfo." | https://chromium-review.googlesource.com/c/chromium/src/+/6850973 * fixup! 6506565: [FPF-CI] Create initial NoiseHash in the browser. | https://chromium-review.googlesource.com/c/chromium/src/+/6506565 * fix: unsafe buffer warning in fix_properly_honor_printing_page_ranges.patch * fix: FTBFS in src_remove_dependency_on_wrapper-descriptor-based_cppheap.patch This change should be upstreamed. Fixes this error: ../../third_party/electron_node/src/env.cc:606:3: error: no matching function for call to 'Wrap' 606 | v8::Object::Wrap<v8::CppHeapPointerTag::kDefaultTag>( | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1076:14: note: candidate function template not viable: cannot convert argument of incomplete type 'void *' to 'v8::Object::Wrappable *' for 3rd argument 1076 | void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper, | ^ 1077 | v8::Object::Wrappable* wrappable) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1084:14: note: candidate function template not viable: no known conversion from 'Local<Object>' to 'const PersistentBase<Object>' for 2nd argument 1084 | void Object::Wrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper, | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1093:14: note: candidate function template not viable: no known conversion from 'Local<Object>' to 'const BasicTracedReference<Object>' for 2nd argument 1093 | void Object::Wrap(v8::Isolate* isolate, | ^ 1094 | const BasicTracedReference<Object>& wrapper, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. * [v8-init] Access crash key only from main thread | https://chromium-review.googlesource.com/c/chromium/src/+/6827167 * chore: e patches all * chore: remove chore_restore_some_deprecated_wrapper_utility_in_gin.patch from patches this remove line got re-added when rebasing roller/chromium/main * chore: e patches all * fix: include base/time/time.h when using base::Time * chore: update patches * Make --host-rules an alias for --host-resolver-rules. Refs https://chromium-review.googlesource.com/c/chromium/src/+/4867872 * ci: update BUILD_TOOLS_SHA Refs https://github.com/electron/build-tools/pull/746 * [Fontations] Remove Fontations suffix from font names Refs https://chromium-review.googlesource.com/c/chromium/src/+/6835930 * temp: debug macOS addon build failure * Revert "temp: debug macOS addon build failure" This reverts commit 40bc8abab65dc83e17c4ab97cb6e7522a193fb44. * test: run tests with Xcode 16.4 * ci: fix tccdb update for macOS 15 * spec: disable opening external application for loadURL on macOS opening unknown external application will bring up dialog to choose apps from application store which will break our other test suites that want to capture screen for pixel matching. The loadURL spec that tests bad-scheme://foo is sufficient that we hit the permission handler for openExternal since at that point we already know the runtime gave up on handling the scheme. * chore: rebase patches * chore: disable codesiging tests * ci: update ScreenCaptureApprovals.plist for /bin/bash * ci: try updating tcc permissions * ci: update TCC permissions Refs https://www.rainforestqa.com/blog/macos-tcc-db-deep-dive * chore: test with 1st quadrant of the window * chore: adjust for macOS 15 menubar height --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2025-08-29 12:31:47 +09:00
const display = screen.getPrimaryDisplay();
w = new BrowserWindow({
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: false
}
});
chore: bump chromium to 141.0.7361.0 (main) (#48054) * chore: bump chromium in DEPS to 141.0.7352.0 * chore: update patches * 6830573: Revert 'Migrate WrappableWithNamedPropertyInterceptor to gin::Wrappable' | https://chromium-review.googlesource.com/c/chromium/src/+/6830573 * chore: bump chromium in DEPS to 141.0.7354.0 * chore: bump chromium in DEPS to 141.0.7356.0 * chore: bump chromium in DEPS to 141.0.7357.0 * chore: bump chromium in DEPS to 141.0.7359.0 * chore: bump chromium in DEPS to 141.0.7361.0 * 6838518: [Mac] Correctly deallocate sandbox error buffers and prevent crash resulting from nullptr assignment | https://chromium-review.googlesource.com/c/chromium/src/+/6838518 * 6850973: Reland "Use base::ByteCount in base::SysInfo." | https://chromium-review.googlesource.com/c/chromium/src/+/6850973 * 6506565: [FPF-CI] Create initial NoiseHash in the browser. | https://chromium-review.googlesource.com/c/chromium/src/+/6506565 * chore: update patches * fixup! 6850973: Reland "Use base::ByteCount in base::SysInfo." | https://chromium-review.googlesource.com/c/chromium/src/+/6850973 * fixup! 6506565: [FPF-CI] Create initial NoiseHash in the browser. | https://chromium-review.googlesource.com/c/chromium/src/+/6506565 * fix: unsafe buffer warning in fix_properly_honor_printing_page_ranges.patch * fix: FTBFS in src_remove_dependency_on_wrapper-descriptor-based_cppheap.patch This change should be upstreamed. Fixes this error: ../../third_party/electron_node/src/env.cc:606:3: error: no matching function for call to 'Wrap' 606 | v8::Object::Wrap<v8::CppHeapPointerTag::kDefaultTag>( | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1076:14: note: candidate function template not viable: cannot convert argument of incomplete type 'void *' to 'v8::Object::Wrappable *' for 3rd argument 1076 | void Object::Wrap(v8::Isolate* isolate, const v8::Local<v8::Object>& wrapper, | ^ 1077 | v8::Object::Wrappable* wrappable) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1084:14: note: candidate function template not viable: no known conversion from 'Local<Object>' to 'const PersistentBase<Object>' for 2nd argument 1084 | void Object::Wrap(v8::Isolate* isolate, const PersistentBase<Object>& wrapper, | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../v8/include/v8-object.h:1093:14: note: candidate function template not viable: no known conversion from 'Local<Object>' to 'const BasicTracedReference<Object>' for 2nd argument 1093 | void Object::Wrap(v8::Isolate* isolate, | ^ 1094 | const BasicTracedReference<Object>& wrapper, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. * [v8-init] Access crash key only from main thread | https://chromium-review.googlesource.com/c/chromium/src/+/6827167 * chore: e patches all * chore: remove chore_restore_some_deprecated_wrapper_utility_in_gin.patch from patches this remove line got re-added when rebasing roller/chromium/main * chore: e patches all * fix: include base/time/time.h when using base::Time * chore: update patches * Make --host-rules an alias for --host-resolver-rules. Refs https://chromium-review.googlesource.com/c/chromium/src/+/4867872 * ci: update BUILD_TOOLS_SHA Refs https://github.com/electron/build-tools/pull/746 * [Fontations] Remove Fontations suffix from font names Refs https://chromium-review.googlesource.com/c/chromium/src/+/6835930 * temp: debug macOS addon build failure * Revert "temp: debug macOS addon build failure" This reverts commit 40bc8abab65dc83e17c4ab97cb6e7522a193fb44. * test: run tests with Xcode 16.4 * ci: fix tccdb update for macOS 15 * spec: disable opening external application for loadURL on macOS opening unknown external application will bring up dialog to choose apps from application store which will break our other test suites that want to capture screen for pixel matching. The loadURL spec that tests bad-scheme://foo is sufficient that we hit the permission handler for openExternal since at that point we already know the runtime gave up on handling the scheme. * chore: rebase patches * chore: disable codesiging tests * ci: update ScreenCaptureApprovals.plist for /bin/bash * ci: try updating tcc permissions * ci: update TCC permissions Refs https://www.rainforestqa.com/blog/macos-tcc-db-deep-dive * chore: test with 1st quadrant of the window * chore: adjust for macOS 15 menubar height --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2025-08-29 12:31:47 +09:00
w.setBounds(display.bounds);
await w.loadURL(`file://${fixtures}/pages/flex-webview.html`);
w.setBackgroundColor(WINDOW_BACKGROUND_COLOR);
});
afterEach(async () => {
await w.webContents.executeJavaScript(`{
for (const el of document.querySelectorAll('webview')) el.remove();
}`);
});
after(() => w.close());
ifit(hasCapturableScreen())('is transparent by default', async () => {
await loadWebView(w.webContents, {
src: 'data:text/html,foo'
});
const screenCapture = new ScreenCapture();
await screenCapture.expectColorAtCenterMatches(WINDOW_BACKGROUND_COLOR);
});
ifit(hasCapturableScreen())('remains transparent when set', async () => {
await loadWebView(w.webContents, {
src: 'data:text/html,foo',
webpreferences: 'transparent=yes'
});
const screenCapture = new ScreenCapture();
await screenCapture.expectColorAtCenterMatches(WINDOW_BACKGROUND_COLOR);
});
ifit(hasCapturableScreen())('can disable transparency', async () => {
await loadWebView(w.webContents, {
src: 'data:text/html,foo',
webpreferences: 'transparent=no'
});
const screenCapture = new ScreenCapture();
await screenCapture.expectColorAtCenterMatches(HexColors.WHITE);
});
});
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';
2019-11-01 13:37:02 -07:00
function setUpRequestHandler (webContentsId: number, requestedPermission: string) {
return new Promise<void>((resolve, reject) => {
session.fromPartition(partition).setPermissionRequestHandler(function (webContents, permission, allow) {
if (webContents.id === webContentsId) {
chore: bump chromium to 127.0.6521.0 (main) (#42118) * chore: bump chromium in DEPS to 126.0.6470.0 * 5492605: Migrate TODOs referencing old crbug IDs to the new issue tracker IDs | https://chromium-review.googlesource.com/c/chromium/src/+/5492605 * 5513277: Move subresource-filter-ruleset to GCS | https://chromium-review.googlesource.com/c/chromium/src/+/5513277 * 5512656: Remove CustomizeChromeSupportsChromeRefresh2023 | https://chromium-review.googlesource.com/c/chromium/src/+/5512656 * 5516009: Accept mouse events in inactive window for Top Chrome WebUIs | https://chromium-review.googlesource.com/c/chromium/src/+/5516009 * 5376861: Change references to RWHVB in RWHIER and RenderWidgetTargeter to RWHVI. | https://chromium-review.googlesource.com/c/chromium/src/+/5376861 * 5490530: Use partition_alloc PA_BUILDFLAG(...) outside PA. #cleanup | https://chromium-review.googlesource.com/c/chromium/src/+/5490530 * 5296870: network: Allow trusted loaders to learn the sent request cookies. | https://chromium-review.googlesource.com/c/chromium/src/+/5296870 * 5453438: Delegate delegated ink trails to RWHI from RWHIER. | https://chromium-review.googlesource.com/c/chromium/src/+/5453438 * chore: update patches * chore: bump chromium in DEPS to 126.0.6472.0 * chore: bump chromium in DEPS to 126.0.6474.0 * chore: update patches * chore: bump chromium in DEPS to 126.0.6476.0 * chore: bump chromium in DEPS to 126.0.6478.0 * chore: bump chromium in DEPS to 126.0.6478.3 * chore: bump chromium in DEPS to 126.0.6478.8 * update patches * only disable enterprise_cloud_content_analysis * 5403888: [api] support v8::Data in v8::TracedReference and v8::EmbedderGraph https://chromium-review.googlesource.com/c/v8/v8/+/5403888 * chore: bump chromium in DEPS to 127.0.6484.0 * chore: bump chromium in DEPS to 127.0.6485.0 * 5539004: Use NOTREACHED_IN_MIGRATION() in remaining chrome/ | https://chromium-review.googlesource.com/c/chromium/src/+/5539004 * src: cast to v8::Value before using v8::EmbedderGraph::V8Node | https://github.com/nodejs/node/pull/52638/files * chore: update patches * chore: update v8 patches * chore: bump chromium in DEPS to 127.0.6486.0 * chore: bump chromium in DEPS to 127.0.6488.0 * chore: bump chromium in DEPS to 127.0.6490.0 * chore: bump chromium in DEPS to 127.0.6492.0 * chore: update patches For some reason, `feat_expose_raw_response_headers_from_urlloader.patch` got messed up in an earlier commit. * chore: update patches printing.patch was updated due to https://chromium-review.googlesource.com/c/chromium/src/+/5535938 * 5527572: Move Connectors prefs files to components/enterprise/connectors/ https://chromium-review.googlesource.com/c/chromium/src/+/5527572 * chore: bump chromium in DEPS to 127.0.6494.0 * chore: bump chromium in DEPS to 127.0.6495.0 * chore: bump chromium in DEPS to 127.0.6496.0 * 5465511: [api] Mark v8::ObjectTemplate::SetAccessor(..) for deprecation https://chromium-review.googlesource.com/c/v8/v8/+/5465511 * chore: revert v8 deprecation See patch message for more details. https://chromium-review.googlesource.com/c/v8/v8/+/5526611 * chore: update patches * 5538771: Remove srcdoc else-if block in CalculateOrigin() https://chromium-review.googlesource.com/c/chromium/src/+/5538771 * 5522321: [devtools] Support saving base64 encoded files via host bindings https://chromium-review.googlesource.com/c/chromium/src/+/5522321 * 5376861: Change references to RWHVB in RWHIER and RenderWidgetTargeter to RWHVI. https://chromium-review.googlesource.com/c/chromium/src/+/5376861 * 5530163: [media] Use VideoFrame::Plane typed enum instead of nameless enum https://chromium-review.googlesource.com/c/chromium/src/+/5530163 * 5463431: iwa: Only create IsolatedWebAppURLLoaderFactory for subresources in IWAs https://chromium-review.googlesource.com/c/chromium/src/+/5463431 * fixup! 5465511: [api] Mark v8::ObjectTemplate::SetAccessor(..) for deprecation https://chromium-review.googlesource.com/c/v8/v8/+/5465511 * 5512176: Remove OnEnvironmentEstimationComplete() https://chromium-review.googlesource.com/c/chromium/src/+/5512176 * 5528282: Move Web Speech API .mojom files to //media/mojo/mojom https://chromium-review.googlesource.com/c/chromium/src/+/5528282 * 5513740: Reland "[Extensions] Restructure extensions::ProcessMap" https://chromium-review.googlesource.com/c/chromium/src/+/5513740 * 5483406: [PEPC] Make PEPC permission subscription take into account device status https://chromium-review.googlesource.com/c/chromium/src/+/5483406 * 5526034: [DoH] Remove kDnsOverHttps feature flag https://chromium-review.googlesource.com/c/chromium/src/+/5526034 The title is a bit misleading. They removed handling for the feature flag and generally intend to remove it but haven't yet. I only changed our code to address the flag that was removed. A quick search on GitHub for `DnsOverHttpsFallback` yielded a few results, but they were all C++ chromium code or patches, 0 app code or discussion results. Since I couldn't find any evidence of this flag being used in developer applications, I've chosen to exclude this change from the breaking changes docs. * chore: revert v8 removal https://chromium-review.googlesource.com/c/v8/v8/+/5497515 See patch message for more details. * chore: cherry-pick Node.js patch for V8 API removal fix Node.js PR: https://github.com/nodejs/node/pull/52996 V8 API Removal CL: https://chromium-review.googlesource.com/c/v8/v8/+/5539888 See the patch description for more details. * 5492183: Extensions: CodeHealth: Give enums some class https://chromium-review.googlesource.com/c/chromium/src/+/5492183 * fixup! 5528282: Move Web Speech API .mojom files to //media/mojo/mojom https://chromium-review.googlesource.com/c/chromium/src/+/5528282 * 5514687: Reland "Add a secret handshake to the base::Feature constructor" https://chromium-review.googlesource.com/c/chromium/src/+/5514687 * fixup! 5530163: [media] Use VideoFrame::Plane typed enum instead of nameless enum https://chromium-review.googlesource.com/c/chromium/src/+/5530163 * 5466238: PDF Viewer: add metrics to record if PDF is opened with a11y https://chromium-review.googlesource.com/c/chromium/src/+/5466238 * 5502081: Migrate OnDisplayRemoved to OnDisplaysRemoved https://chromium-review.googlesource.com/c/chromium/src/+/5502081 * 5539888: [api] Remove several APIs deprecated in version 12.6 https://chromium-review.googlesource.com/c/v8/v8/+/5539888 This commit essentially only removes the `only_terminate_in_safe_scope` isolate creation parameter. This undoes some work that was originally done in #35766. * 5498236: Make browser_tests force full async initialization for OSCrypt Async https://chromium-review.googlesource.com/c/chromium/src/+/5498236 * fixup! 5528282: Move Web Speech API .mojom files to //media/mojo/mojom https://chromium-review.googlesource.com/c/chromium/src/+/5528282 * 5545807: Migrate most remaining NOTREACHED() https://chromium-review.googlesource.com/c/chromium/src/+/5545807 I took a systematic approach to modifying all of our uses of `NOTREACHED` that were causing errors: * If there was a `return` or `break` (etc.) immediately after `NOTREACHED`, I removed the control flow instruction and left the `NOTREACHED` unmodified * All other instances were migrated to `NOTREACHED_IN_MIGRATION` We should revisit pretty much all usage of `NOTREACHED` as an upgrade follow-up item. * fixup! 5526034: [DoH] Remove kDnsOverHttps feature flag https://chromium-review.googlesource.com/c/chromium/src/+/5526034 Turns out the feature flags were removed in the `.cc` file, but not the `.h` feature list file. This means that the feature flags are pretty much officially gone. (The leftover symbols in the header are likely an oversight from what I can gather.) We may potentially decide to put this in the breaking changes doc if we decide this feature flag is important enough to highlight. * chore: bump chromium in DEPS to 127.0.6498.3 * chore: bump chromium in DEPS to 127.0.6500.0 * chore: bump chromium in DEPS to 127.0.6502.0 * chore: bump chromium in DEPS to 127.0.6504.0 * chore: bump chromium in DEPS to 127.0.6505.0 * chore: bump chromium in DEPS to 127.0.6508.0 * build: use Sha256Sum in script/sysroots.json Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5506275 * chore: update chore_add_electron_deps_to_gitignores.patch Xref: no manual changes; patch applied with fuzz 2 * chore: update feat_allow_code_cache_in_custom_schemes.patch Xref: no manual changes; patch applied with fuzz 1 * chore: e patches all * fixup! build: use Sha256Sum in script/sysroots.json `sync` succeeds now * chore: replace absl::optional with std::optional Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5253843 * chore: update CalculatePreferredSize() to new upstream semantics Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5459174 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5541220 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5514708 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5504212 Xref: https://chromium-review.googlesource.com/516542 * chore: replace absl::optional with std::optional Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5296147 * chore: add kPip to enumeration as a no-op https://chromium-review.googlesource.com/c/chromium/src/+/5546257 * [Autofill] Remove RenderFrame::ElementBoundsInWindow() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5553982 * chore: fix feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch need new header to pick up definition of BLINK_PLATFORM_EXPORT macro Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5463143 * chore: bump chromium in DEPS to 127.0.6510.0 * chore: update patches * chore: fix include path for native_web_keyboard_event.h Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5541976 * chore: add currently-unused should_include_device_status arg to GetPermissionStatusForCurrentDocument() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5545382 * chore: bump chromium in DEPS to 127.0.6512.0 * chore: update mas_avoid_private_macos_api_usage.patch.patch No manual changes; patch applied with fuzz 1 * chore: update feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch No manual changes; patch applied with fuzz 1 * chore: update webview_fullscreen.patch No manual changes; patch applied with fuzz 1 * chore=: remove cherry-pick-22db6918bac9.patch already present upstream * chore: remove nonexistent patchfiles from .patches * chore: remove cherry-pick-3e037e195e50.patch no longer needed; merged upstream * Update namespace for files moved to //components/input Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5563251 * Require client for InitParams to always specify an ownership mode. Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5532482 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5578714 * chore: e patches all * fixup! Update namespace for files moved to //components/input * chore: remove profile_keyed_service_factory, profile_selections from chromium_src already being linked in via chrome browser for printing * chore: bump chromium in DEPS to 127.0.6515.0 * chore: bump chromium in DEPS to 127.0.6516.0 * chore: update render_widget_host_view_base.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5547803 patch applied manually due to simple upstream shear * chore: update feat_allow_code_cache_in_custom_schemes.patch No manual changes; patch applied with fuzz 1 * chore: e patches all * Pull RWHIER and RWT to //content/common/input. Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5397681 * chore: bump chromium in DEPS to 127.0.6517.0 * chore: update patches * fixup: Update namespace for files moved to //components/input * Remove 0-arg (default) constructor for views::Widget::InitParams. https://chromium-review.googlesource.com/c/chromium/src/+/5578714 * fixup: only disable enterprise_cloud_content_analysis The original commit https://github.com/electron/electron/pull/42118/commits/a5480accc20f2d63e11d02c09985ba1af9e82de2, was due to this CL 5527572: Move Connectors prefs files to components/enterprise/connectors/ | https://chromium-review.googlesource.com/c/chromium/src/+/5527572 * chore: bump chromium in DEPS to 127.0.6519.0 * chore: update patches * src: do not use deprecated V8 API https://github.com/nodejs/node/pull/53084 * src: remove dependency on wrapper-descriptor-based cpp heap https://github.com/nodejs/node/pull/53086 * 5344413: [DevTools] Add `getHostConfig` UI binding for sending status of `base::Features` to DevTools https://chromium-review.googlesource.com/c/chromium/src/+/5344413 * 5585788: Extensions: ManifestHandler: Separate Registry like ExtensionRegistry https://chromium-review.googlesource.com/c/chromium/src/+/5585788 * chore: update filenames.libcxx.gni * 5506857: Reland "Migrate clang-format to gcs first class deps" https://chromium-review.googlesource.com/c/chromium/src/+/5506857 * fixup: 5539888: [api] Remove several APIs deprecated in version 12.6 * fixup: 5506857: Reland Migrate clang-format to gcs first class deps * chore: bump chromium in DEPS to 127.0.6521.0 * chore: update patches * spec: update navigator.keyboard should lock the keyboard * Block or allow all MIDI using the existing SysEx permission Refs https://chromium-review.googlesource.com/c/chromium/src/+/5154368 Refs https://chromium-review.googlesource.com/c/chromium/src/+/5499157 * spec: update test/parallel/test-v8-stats * views: remove CalculatePreferredSize() Refs https://chromium-review.googlesource.com/c/chromium/src/+/5504212 * chore: update patches after rebase * 5560288: Re-enable ChromeOS XNNPack on Intel only https://chromium-review.googlesource.com/c/chromium/src/+/5560288 * chore: add nan patches for v8 changes Refs 5539888: [api] Remove several APIs deprecated in version 12.6 | https://chromium-review.googlesource.com/c/v8/v8/+/5539888 and 5539852: [heap][api] Remove deprecated v8::Isolate::IdleNotificationDeadline | https://chromium-review.googlesource.com/c/v8/v8/+/5539852 * 5573603: Modularize //chrome/browser/themes https://chromium-review.googlesource.com/c/chromium/src/+/5573603 * 5539888: [api] Remove several APIs deprecated in version 12.6 https://chromium-review.googlesource.com/c/v8/v8/+/5539888 * chore: update patches * test: fixup navigator.keyboard.lock on Windows * chore: remove unneeded profile target --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: deepak1556 <hop2deep@gmail.com>
2024-06-07 17:18:35 -04:00
// All midi permission requests are blocked or allowed as midiSysex permissions
// since https://chromium-review.googlesource.com/c/chromium/src/+/5154368
if (permission === 'midiSysex') {
const allowed = requestedPermission === 'midi' || requestedPermission === 'midiSysex';
return allow(!allowed);
}
try {
expect(permission).to.equal(requestedPermission);
} catch (e) {
return reject(e);
}
allow(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 = once(ipcMain, 'message');
loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/media.html`,
partition,
nodeintegration: 'on'
});
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
setUpRequestHandler(webViewContents.id, 'media');
const [, errorName] = await errorFromRenderer;
expect(errorName).to.equal('PermissionDeniedError');
});
it('emits when using navigator.geolocation api', async () => {
const errorFromRenderer = once(ipcMain, 'message');
loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/geolocation.html`,
partition,
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
});
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
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 = once(ipcMain, 'message');
loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/midi.html`,
partition,
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
});
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
setUpRequestHandler(webViewContents.id, 'midi');
const [, error] = await errorFromRenderer;
chore: bump chromium to 131.0.6734.0 (main) (#43769) * chore: bump chromium in DEPS to 130.0.6723.4 * chore: bump chromium in DEPS to 131.0.6724.0 * chore: update patches * chore: update libc++ filenames * 5844369: controlledframe: Disable Web Bluetooth for <webview> & <controlledframe> https://chromium-review.googlesource.com/c/chromium/src/+/5844369 * (multiple CLs): Use an opaque type for FrameTreeNode IDs 5807683: Use an opaque type for FrameTreeNode IDs, part 1 | https://chromium-review.googlesource.com/c/chromium/src/+/5807683 5829746: Use an opaque type for FrameTreeNode IDs, part 2 | https://chromium-review.googlesource.com/c/chromium/src/+/5829746 5836903: Use an opaque type for FrameTreeNode IDs, part 7 | https://chromium-review.googlesource.com/c/chromium/src/+/5836903 5837249: Use an opaque type for FrameTreeNode IDs, part 8 | https://chromium-review.googlesource.com/c/chromium/src/+/5837249 5836564: Use an opaque type for FrameTreeNode IDs, part 12 | https://chromium-review.googlesource.com/c/chromium/src/+/5836564 5837180: Use an opaque type for FrameTreeNode IDs, part 15 | https://chromium-review.googlesource.com/c/chromium/src/+/5837180 * 5822889: [task] Make GetForegroundTaskRunner non-virtual https://chromium-review.googlesource.com/c/v8/v8/+/5822889 * 5833297: Remove unused inner WebContents attach params https://chromium-review.googlesource.com/c/chromium/src/+/5833297 * 5806403: Shift PowerMonitor to non static https://chromium-review.googlesource.com/c/chromium/src/+/5806403 * 5666874: [3/N] Remove old OnPowerChange in PowerObserver https://chromium-review.googlesource.com/c/chromium/src/+/5666874 * 5829085: [v8] Differentiate between UserVisible and BestEffort task runners https://chromium-review.googlesource.com/c/chromium/src/+/5829085 * 5791112: [webrtc] Use `c/b/permissions/system` for system permissions https://chromium-review.googlesource.com/c/chromium/src/+/5791112 * 5825636: [Extensions] Create WebContentsObservers with ExtensionsBrowserClient https://chromium-review.googlesource.com/c/chromium/src/+/5825636 * fixup! (multiple CLs): Use an opaque type for FrameTreeNode IDs * fixup! 5791112: [webrtc] Use `c/b/permissions/system` for system permissions https://chromium-review.googlesource.com/c/chromium/src/+/5791112 * chore: bump chromium in DEPS to 131.0.6726.0 * chore: update patches * chore: update libc++ filenames * 5858119: Declutter: Allow opening to a specific feature https://chromium-review.googlesource.com/c/chromium/src/+/5858119 * fix: macOS SDK 15 error Not sure exactly what changed in the upgrade to macOS SDK 15, but it triggered a new error: ``` electron/shell/browser/ui/message_box_mac.mm:84:7: error: multiple methods named 'highlight:' found with mismatched result, parameter type or attributes ``` The `highlight:` selector a few lines down was ambiguous because the object type of the `NSArray` was not specified. Specifying `NSButton` as the element type makes the selector unambiguous for type checking. * 5854143: [File Download Access Prevention] Obfuscate download file for enterprise deep scan https://chromium-review.googlesource.com/c/chromium/src/+/5854143 * 5854811: Use kNotAllowedError instead of kSecurityError for Web MIDI https://chromium-review.googlesource.com/c/chromium/src/+/5854811 * chore: bump chromium in DEPS to 131.0.6728.0 * chore: update patches * disable invalid test * chore: bump chromium in DEPS to 131.0.6730.0 * chore: update patches * update build tools target commit for new macOS SDK * chore: update libc++ file names * chore: bump chromium in DEPS to 131.0.6732.0 * chore: bump chromium in DEPS to 131.0.6734.0 * 5856527: [UI] Use mojo enum for `WindowShowState` in ui/ https://chromium-review.googlesource.com/c/chromium/src/+/5856527 * chore: update build-tools sha to include macOD 15.0 SDK --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: alice <alice@makenotion.com>
2024-09-25 06:19:39 -05:00
expect(error).to.equal('NotAllowedError');
});
it('emits when using navigator.requestMIDIAccess with sysex api', async () => {
const errorFromRenderer = once(ipcMain, 'message');
loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/midi-sysex.html`,
partition,
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
});
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
setUpRequestHandler(webViewContents.id, 'midiSysex');
const [, error] = await errorFromRenderer;
chore: bump chromium to 131.0.6734.0 (main) (#43769) * chore: bump chromium in DEPS to 130.0.6723.4 * chore: bump chromium in DEPS to 131.0.6724.0 * chore: update patches * chore: update libc++ filenames * 5844369: controlledframe: Disable Web Bluetooth for <webview> & <controlledframe> https://chromium-review.googlesource.com/c/chromium/src/+/5844369 * (multiple CLs): Use an opaque type for FrameTreeNode IDs 5807683: Use an opaque type for FrameTreeNode IDs, part 1 | https://chromium-review.googlesource.com/c/chromium/src/+/5807683 5829746: Use an opaque type for FrameTreeNode IDs, part 2 | https://chromium-review.googlesource.com/c/chromium/src/+/5829746 5836903: Use an opaque type for FrameTreeNode IDs, part 7 | https://chromium-review.googlesource.com/c/chromium/src/+/5836903 5837249: Use an opaque type for FrameTreeNode IDs, part 8 | https://chromium-review.googlesource.com/c/chromium/src/+/5837249 5836564: Use an opaque type for FrameTreeNode IDs, part 12 | https://chromium-review.googlesource.com/c/chromium/src/+/5836564 5837180: Use an opaque type for FrameTreeNode IDs, part 15 | https://chromium-review.googlesource.com/c/chromium/src/+/5837180 * 5822889: [task] Make GetForegroundTaskRunner non-virtual https://chromium-review.googlesource.com/c/v8/v8/+/5822889 * 5833297: Remove unused inner WebContents attach params https://chromium-review.googlesource.com/c/chromium/src/+/5833297 * 5806403: Shift PowerMonitor to non static https://chromium-review.googlesource.com/c/chromium/src/+/5806403 * 5666874: [3/N] Remove old OnPowerChange in PowerObserver https://chromium-review.googlesource.com/c/chromium/src/+/5666874 * 5829085: [v8] Differentiate between UserVisible and BestEffort task runners https://chromium-review.googlesource.com/c/chromium/src/+/5829085 * 5791112: [webrtc] Use `c/b/permissions/system` for system permissions https://chromium-review.googlesource.com/c/chromium/src/+/5791112 * 5825636: [Extensions] Create WebContentsObservers with ExtensionsBrowserClient https://chromium-review.googlesource.com/c/chromium/src/+/5825636 * fixup! (multiple CLs): Use an opaque type for FrameTreeNode IDs * fixup! 5791112: [webrtc] Use `c/b/permissions/system` for system permissions https://chromium-review.googlesource.com/c/chromium/src/+/5791112 * chore: bump chromium in DEPS to 131.0.6726.0 * chore: update patches * chore: update libc++ filenames * 5858119: Declutter: Allow opening to a specific feature https://chromium-review.googlesource.com/c/chromium/src/+/5858119 * fix: macOS SDK 15 error Not sure exactly what changed in the upgrade to macOS SDK 15, but it triggered a new error: ``` electron/shell/browser/ui/message_box_mac.mm:84:7: error: multiple methods named 'highlight:' found with mismatched result, parameter type or attributes ``` The `highlight:` selector a few lines down was ambiguous because the object type of the `NSArray` was not specified. Specifying `NSButton` as the element type makes the selector unambiguous for type checking. * 5854143: [File Download Access Prevention] Obfuscate download file for enterprise deep scan https://chromium-review.googlesource.com/c/chromium/src/+/5854143 * 5854811: Use kNotAllowedError instead of kSecurityError for Web MIDI https://chromium-review.googlesource.com/c/chromium/src/+/5854811 * chore: bump chromium in DEPS to 131.0.6728.0 * chore: update patches * disable invalid test * chore: bump chromium in DEPS to 131.0.6730.0 * chore: update patches * update build tools target commit for new macOS SDK * chore: update libc++ file names * chore: bump chromium in DEPS to 131.0.6732.0 * chore: bump chromium in DEPS to 131.0.6734.0 * 5856527: [UI] Use mojo enum for `WindowShowState` in ui/ https://chromium-review.googlesource.com/c/chromium/src/+/5856527 * chore: update build-tools sha to include macOD 15.0 SDK --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: alice <alice@makenotion.com>
2024-09-25 06:19:39 -05:00
expect(error).to.equal('NotAllowedError');
});
it('emits when accessing external protocol', async () => {
loadWebView(w.webContents, {
src: 'magnet:test',
2019-11-01 13:37:02 -07:00
partition
});
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
await setUpRequestHandler(webViewContents.id, 'openExternal');
});
it('emits when using Notification.requestPermission', async () => {
const errorFromRenderer = once(ipcMain, 'message');
loadWebView(w.webContents, {
src: `file://${fixtures}/pages/permissions/notification.html`,
partition,
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
});
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
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)
})`);
});
});
describe('attributes', () => {
let w: WebContents;
before(async () => {
const window = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: false
}
});
await window.loadURL(`file://${fixtures}/pages/blank.html`);
w = window.webContents;
});
afterEach(async () => {
await w.executeJavaScript(`{
for (const el of document.querySelectorAll('webview')) el.remove();
}`);
});
after(closeAllWindows);
describe('src attribute', () => {
it('specifies the page to load', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
src: `file://${fixtures}/pages/a.html`
});
expect(message).to.equal('a');
});
it('navigates to new page when changed', async () => {
await loadWebView(w, {
src: `file://${fixtures}/pages/a.html`
});
const { message } = await w.executeJavaScript(`new Promise(resolve => {
webview.addEventListener('console-message', e => resolve({message: e.message}))
webview.src = ${JSON.stringify(`file://${fixtures}/pages/b.html`)}
})`);
expect(message).to.equal('b');
});
it('resolves relative URLs', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
src: './e.html'
});
expect(message).to.equal('Window script is loaded before preload script');
});
it('ignores empty values', async () => {
loadWebView(w, {});
for (const emptyValue of ['""', 'null', 'undefined']) {
const src = await w.executeJavaScript(`webview.src = ${emptyValue}, webview.src`);
expect(src).to.equal('');
}
});
it('does not wait until loadURL is resolved', async () => {
await loadWebView(w, { src: 'about:blank' });
const delay = await w.executeJavaScript(`new Promise(resolve => {
const before = Date.now();
webview.src = 'file://${fixtures}/pages/blank.html';
const now = Date.now();
resolve(now - before);
})`);
// Setting src is essentially sending a sync IPC message, which should
// not exceed more than a few ms.
//
// This is for testing #18638.
expect(delay).to.be.below(100);
});
});
describe('nodeintegration attribute', () => {
it('inserts no node symbols when not set', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
src: `file://${fixtures}/pages/c.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'undefined',
module: 'undefined',
process: 'undefined',
global: 'undefined'
});
});
it('inserts node symbols when set', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/d.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function',
module: 'object',
process: 'object'
});
});
it('loads node symbols after POST navigation when set', async function () {
const message = await loadWebViewAndWaitForMessage(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/post.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function',
module: 'object',
process: 'object'
});
});
it('disables node integration on child windows when it is disabled on the webview', async () => {
const src = url.format({
pathname: `${fixtures}/pages/webview-opener-no-node-integration.html`,
protocol: 'file',
query: {
p: `${fixtures}/pages/window-opener-node.html`
},
slashes: true
});
const message = await loadWebViewAndWaitForMessage(w, {
allowpopups: 'on',
webpreferences: 'contextIsolation=no',
src
});
expect(JSON.parse(message).isProcessGlobalUndefined).to.be.true();
});
ifit(!process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS)('loads native modules when navigation happens', async function () {
await loadWebView(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/native-module.html`
});
const message = await w.executeJavaScript(`new Promise(resolve => {
webview.addEventListener('console-message', e => resolve(e.message))
webview.reload();
})`);
expect(message).to.equal('function');
});
});
describe('preload attribute', () => {
useRemoteContext({ webPreferences: { webviewTag: true } });
it('loads the script before other scripts in window', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
preload: `${fixtures}/module/preload.js`,
src: `file://${fixtures}/pages/e.html`
});
expect(message).to.be.a('string');
expect(message).to.be.not.equal('Window script is loaded before preload script');
});
it('preload script can still use "process" and "Buffer" when nodeintegration is off', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
preload: `${fixtures}/module/preload-node-off.js`,
src: `file://${fixtures}/api/blank.html`
});
const types = JSON.parse(message);
expect(types).to.include({
process: 'object',
Buffer: 'function'
});
});
it('runs in the correct scope when sandboxed', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
preload: `${fixtures}/module/preload-context.js`,
src: `file://${fixtures}/api/blank.html`,
webpreferences: 'sandbox=yes'
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function', // arguments passed to it should be available
electron: 'undefined', // objects from the scope it is called from should not be available
window: 'object', // the window object should be available
localVar: 'undefined' // but local variables should not be exposed to the window
});
});
it('preload script can require modules that still use "process" and "Buffer" when nodeintegration is off', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
preload: `${fixtures}/module/preload-node-off-wrapper.js`,
webpreferences: 'sandbox=no',
src: `file://${fixtures}/api/blank.html`
});
const types = JSON.parse(message);
expect(types).to.include({
process: 'object',
Buffer: 'function'
});
});
it('receives ipc message in preload script', async () => {
await loadWebView(w, {
preload: `${fixtures}/module/preload-ipc.js`,
src: `file://${fixtures}/pages/e.html`
});
const message = 'boom!';
const { channel, args } = await w.executeJavaScript(`new Promise(resolve => {
webview.send('ping', ${JSON.stringify(message)})
webview.addEventListener('ipc-message', ({channel, args}) => resolve({channel, args}))
})`);
expect(channel).to.equal('pong');
expect(args).to.deep.equal([message]);
});
itremote('<webview>.sendToFrame()', async (fixtures: string) => {
const w = new WebView();
w.setAttribute('nodeintegration', 'on');
w.setAttribute('webpreferences', 'contextIsolation=no');
w.setAttribute('preload', `file://${fixtures}/module/preload-ipc.js`);
w.setAttribute('src', `file://${fixtures}/pages/ipc-message.html`);
document.body.appendChild(w);
const { frameId } = await new Promise<any>(resolve => w.addEventListener('ipc-message', resolve, { once: true }));
const message = 'boom!';
w.sendToFrame(frameId, 'ping', message);
const { channel, args } = await new Promise<any>(resolve => w.addEventListener('ipc-message', resolve, { once: true }));
expect(channel).to.equal('pong');
expect(args).to.deep.equal([message]);
}, [fixtures]);
it('works without script tag in page', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
preload: `${fixtures}/module/preload.js`,
webpreferences: 'sandbox=no',
src: `file://${fixtures}/pages/base-page.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function',
module: 'object',
process: 'object',
Buffer: 'function'
});
});
it('resolves relative URLs', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
preload: '../module/preload.js',
webpreferences: 'sandbox=no',
src: `file://${fixtures}/pages/e.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function',
module: 'object',
process: 'object',
Buffer: 'function'
});
});
itremote('ignores empty values', async () => {
const webview = new WebView();
for (const emptyValue of ['', null, undefined]) {
webview.preload = emptyValue;
expect(webview.preload).to.equal('');
}
});
});
describe('httpreferrer attribute', () => {
it('sets the referrer url', async () => {
const referrer = 'http://github.com/';
const received = await new Promise<string | undefined>((resolve, reject) => {
const server = http.createServer((req, res) => {
try {
resolve(req.headers.referer);
} catch (e) {
reject(e);
} finally {
res.end();
server.close();
}
});
listen(server).then(({ url }) => {
loadWebView(w, {
httpreferrer: referrer,
src: url
});
});
});
expect(received).to.equal(referrer);
});
});
describe('useragent attribute', () => {
it('sets the user agent', async () => {
const referrer = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko';
const message = await loadWebViewAndWaitForMessage(w, {
src: `file://${fixtures}/pages/useragent.html`,
useragent: referrer
});
expect(message).to.equal(referrer);
});
});
describe('disablewebsecurity attribute', () => {
it('does not disable web security when not set', async () => {
await loadWebView(w, { src: 'about:blank' });
const result = await w.executeJavaScript(`webview.executeJavaScript(\`fetch(${JSON.stringify(blankPageUrl)}).then(() => 'ok', () => 'failed')\`)`);
expect(result).to.equal('failed');
});
it('disables web security when set', async () => {
await loadWebView(w, { src: 'about:blank', disablewebsecurity: '' });
const result = await w.executeJavaScript(`webview.executeJavaScript(\`fetch(${JSON.stringify(blankPageUrl)}).then(() => 'ok', () => 'failed')\`)`);
expect(result).to.equal('ok');
});
it('does not break node integration', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
disablewebsecurity: '',
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/d.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function',
module: 'object',
process: 'object'
});
});
it('does not break preload script', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
disablewebsecurity: '',
preload: `${fixtures}/module/preload.js`,
webpreferences: 'sandbox=no',
src: `file://${fixtures}/pages/e.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function',
module: 'object',
process: 'object',
Buffer: 'function'
});
});
});
describe('partition attribute', () => {
it('inserts no node symbols when not set', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
partition: 'test1',
src: `file://${fixtures}/pages/c.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'undefined',
module: 'undefined',
process: 'undefined',
global: 'undefined'
});
});
it('inserts node symbols when set', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
nodeintegration: 'on',
partition: 'test2',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/d.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function',
module: 'object',
process: 'object'
});
});
it('isolates storage for different id', async () => {
await w.executeJavaScript('localStorage.setItem(\'test\', \'one\')');
const message = await loadWebViewAndWaitForMessage(w, {
partition: 'test3',
src: `file://${fixtures}/pages/partition/one.html`
});
const parsedMessage = JSON.parse(message);
expect(parsedMessage).to.include({
numberOfEntries: 0,
testValue: null
});
});
it('uses current session storage when no id is provided', async () => {
await w.executeJavaScript('localStorage.setItem(\'test\', \'two\')');
const testValue = 'two';
const message = await loadWebViewAndWaitForMessage(w, {
src: `file://${fixtures}/pages/partition/one.html`
});
const parsedMessage = JSON.parse(message);
expect(parsedMessage).to.include({
testValue
});
});
});
describe('allowpopups attribute', () => {
const generateSpecs = (description: string, webpreferences = '') => {
describe(description, () => {
it('can not open new window when not set', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
webpreferences,
src: `file://${fixtures}/pages/window-open-hide.html`
});
expect(message).to.equal('null');
});
it('can open new window when set', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
webpreferences,
allowpopups: 'on',
src: `file://${fixtures}/pages/window-open-hide.html`
});
expect(message).to.equal('window');
});
});
};
generateSpecs('without sandbox');
generateSpecs('with sandbox', 'sandbox=yes');
});
describe('webpreferences attribute', () => {
it('can enable nodeintegration', async () => {
const message = await loadWebViewAndWaitForMessage(w, {
src: `file://${fixtures}/pages/d.html`,
webpreferences: 'nodeIntegration,contextIsolation=no'
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'function',
module: 'object',
process: 'object'
});
});
it('can disable web security and enable nodeintegration', async () => {
await loadWebView(w, { src: 'about:blank', webpreferences: 'webSecurity=no, nodeIntegration=yes, contextIsolation=no' });
const result = await w.executeJavaScript(`webview.executeJavaScript(\`fetch(${JSON.stringify(blankPageUrl)}).then(() => 'ok', () => 'failed')\`)`);
expect(result).to.equal('ok');
const type = await w.executeJavaScript('webview.executeJavaScript("typeof require")');
expect(type).to.equal('function');
});
});
});
describe('events', () => {
useRemoteContext({ webPreferences: { webviewTag: true } });
let w: WebContents;
before(async () => {
const window = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: false
}
});
await window.loadURL(`file://${fixtures}/pages/blank.html`);
w = window.webContents;
});
afterEach(async () => {
await w.executeJavaScript(`{
for (const el of document.querySelectorAll('webview')) el.remove();
}`);
});
after(closeAllWindows);
describe('ipc-message event', () => {
it('emits when guest sends an ipc message to browser', async () => {
const { frameId, channel, args } = await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/ipc-message.html`,
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
}, 'ipc-message');
expect(frameId).to.be.an('array').that.has.lengthOf(2);
expect(channel).to.equal('channel');
expect(args).to.deep.equal(['arg1', 'arg2']);
});
});
describe('page-title-updated event', () => {
it('emits when title is set', async () => {
const { title, explicitSet } = await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/a.html`
}, 'page-title-updated');
expect(title).to.equal('test');
expect(explicitSet).to.be.true();
});
});
describe('page-favicon-updated event', () => {
it('emits when favicon urls are received', async () => {
const { favicons } = await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/a.html`
}, 'page-favicon-updated');
expect(favicons).to.be.an('array').of.length(2);
if (process.platform === 'win32') {
expect(favicons[0]).to.match(/^file:\/\/\/[A-Z]:\/favicon.png$/i);
} else {
expect(favicons[0]).to.equal('file:///favicon.png');
}
});
});
describe('did-redirect-navigation event', () => {
it('is emitted on redirects', async () => {
const server = http.createServer((req, res) => {
if (req.url === '/302') {
res.setHeader('Location', '/200');
res.statusCode = 302;
res.end();
} else {
res.end();
}
});
const { url } = await listen(server);
defer(() => { server.close(); });
const event = await loadWebViewAndWaitForEvent(w, {
src: `${url}/302`
}, 'did-redirect-navigation');
expect(event.url).to.equal(`${url}/200`);
expect(event.isInPlace).to.be.false();
expect(event.isMainFrame).to.be.true();
expect(event.frameProcessId).to.be.a('number');
expect(event.frameRoutingId).to.be.a('number');
});
});
describe('will-navigate event', () => {
feat: add `will-frame-navigate` event (#34418) * feat: add will-navigate-in-frame event to webContents * docs: add documentation for webview will-frame-navigate event * feat: Eliminate isInPlace argument from will-frame-navigate event * fix: Fire will-frame-navigate before will-navigate * feat: send will-frame-navigate with a WebFrameMain in the event details * docs: Update WebContents docs for new API signature * feat: Add custom event forwarding for <webview> will-frame-navigate * fix: wrap WebFrameMain so it can be sent as an event * test: update webContents and <webview> tests to match new signatures * chore: undo unnecessary change * fix: don't switch will-navigate to use EmitNavigationEventDetails * test: clean up will-navigate and will-frame-navigate tests for <webview> * chore: apply lint fixes * chore: move GetRenderFrameHost helper into anonymous namespace * docs: auto-generate WillFrameNavigateDetails rather than defining it manually * test: Update <webview> tests to actually pass under new spec runner * docs: Add section explaining relationship between various nav events * test: Add some tests to ensure navigation event order doesn't silently change * test: Always monitor all nav events to ensure unexpected ones don't fire * test: Add test to verify in-page navigation event order * feat: Change to new style where extra params are exposed as event props * fix: Remove unused EmitNavigationEventDetails * fix: Update tests to use new async helpers * docs: Rename and reorder sections documenting navigation events --------- Co-authored-by: Milan Burda <milan.burda@gmail.com>
2023-03-28 07:55:41 -07:00
it('emits when a url that leads to outside of the page is loaded', async () => {
const { url } = await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/webview-will-navigate.html`
}, 'will-navigate');
expect(url).to.equal('http://host/');
});
});
feat: add `will-frame-navigate` event (#34418) * feat: add will-navigate-in-frame event to webContents * docs: add documentation for webview will-frame-navigate event * feat: Eliminate isInPlace argument from will-frame-navigate event * fix: Fire will-frame-navigate before will-navigate * feat: send will-frame-navigate with a WebFrameMain in the event details * docs: Update WebContents docs for new API signature * feat: Add custom event forwarding for <webview> will-frame-navigate * fix: wrap WebFrameMain so it can be sent as an event * test: update webContents and <webview> tests to match new signatures * chore: undo unnecessary change * fix: don't switch will-navigate to use EmitNavigationEventDetails * test: clean up will-navigate and will-frame-navigate tests for <webview> * chore: apply lint fixes * chore: move GetRenderFrameHost helper into anonymous namespace * docs: auto-generate WillFrameNavigateDetails rather than defining it manually * test: Update <webview> tests to actually pass under new spec runner * docs: Add section explaining relationship between various nav events * test: Add some tests to ensure navigation event order doesn't silently change * test: Always monitor all nav events to ensure unexpected ones don't fire * test: Add test to verify in-page navigation event order * feat: Change to new style where extra params are exposed as event props * fix: Remove unused EmitNavigationEventDetails * fix: Update tests to use new async helpers * docs: Rename and reorder sections documenting navigation events --------- Co-authored-by: Milan Burda <milan.burda@gmail.com>
2023-03-28 07:55:41 -07:00
describe('will-frame-navigate event', () => {
it('emits when a link that leads to outside of the page is loaded', async () => {
const { url, isMainFrame } = await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/webview-will-navigate.html`
}, 'will-frame-navigate');
expect(url).to.equal('http://host/');
expect(isMainFrame).to.be.true();
});
it('emits when a link within an iframe, which leads to outside of the page, is loaded', async () => {
await loadWebView(w, {
src: `file://${fixtures}/pages/webview-will-navigate-in-frame.html`,
nodeIntegration: ''
});
const { url, frameProcessId, frameRoutingId } = await w.executeJavaScript(`
new Promise((resolve, reject) => {
let hasFrameNavigatedOnce = false;
const webview = document.getElementById('webview');
webview.addEventListener('will-frame-navigate', ({url, isMainFrame, frameProcessId, frameRoutingId}) => {
if (isMainFrame) return;
if (hasFrameNavigatedOnce) resolve({
url,
isMainFrame,
frameProcessId,
frameRoutingId,
});
// First navigation is the initial iframe load within the <webview>
hasFrameNavigatedOnce = true;
});
webview.executeJavaScript('loadSubframe()');
});
`);
expect(url).to.equal('http://host/');
expect(frameProcessId).to.be.a('number');
expect(frameRoutingId).to.be.a('number');
});
});
describe('did-navigate event', () => {
it('emits when a url that leads to outside of the page is clicked', async () => {
const pageUrl = url.pathToFileURL(path.join(fixtures, 'pages', 'webview-will-navigate.html')).toString();
const event = await loadWebViewAndWaitForEvent(w, { src: pageUrl }, 'did-navigate');
expect(event.url).to.equal(pageUrl);
});
});
describe('did-navigate-in-page event', () => {
it('emits when an anchor link is clicked', async () => {
const pageUrl = url.pathToFileURL(path.join(fixtures, 'pages', 'webview-did-navigate-in-page.html')).toString();
const event = await loadWebViewAndWaitForEvent(w, { src: pageUrl }, 'did-navigate-in-page');
expect(event.url).to.equal(`${pageUrl}#test_content`);
});
it('emits when window.history.replaceState is called', async () => {
const { url } = await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/webview-did-navigate-in-page-with-history.html`
}, 'did-navigate-in-page');
expect(url).to.equal('http://host/');
});
it('emits when window.location.hash is changed', async () => {
const pageUrl = url.pathToFileURL(path.join(fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html')).toString();
const event = await loadWebViewAndWaitForEvent(w, { src: pageUrl }, 'did-navigate-in-page');
expect(event.url).to.equal(`${pageUrl}#test`);
});
});
describe('close event', () => {
it('should fire when interior page calls window.close', async () => {
await loadWebViewAndWaitForEvent(w, { src: `file://${fixtures}/pages/close.html` }, 'close');
});
});
describe('devtools-opened event', () => {
it('should fire when webview.openDevTools() is called', async () => {
await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/base-page.html`
}, 'dom-ready');
await w.executeJavaScript(`new Promise((resolve) => {
webview.openDevTools()
webview.addEventListener('devtools-opened', () => resolve(), {once: true})
})`);
await w.executeJavaScript('webview.closeDevTools()');
});
});
describe('devtools-closed event', () => {
itremote('should fire when webview.closeDevTools() is called', async (fixtures: string) => {
const webview = new WebView();
webview.src = `file://${fixtures}/pages/base-page.html`;
document.body.appendChild(webview);
await new Promise(resolve => webview.addEventListener('dom-ready', resolve, { once: true }));
webview.openDevTools();
await new Promise(resolve => webview.addEventListener('devtools-opened', resolve, { once: true }));
webview.closeDevTools();
await new Promise(resolve => webview.addEventListener('devtools-closed', resolve, { once: true }));
}, [fixtures]);
});
describe('devtools-focused event', () => {
itremote('should fire when webview.openDevTools() is called', async (fixtures: string) => {
const webview = new WebView();
webview.src = `file://${fixtures}/pages/base-page.html`;
document.body.appendChild(webview);
const waitForDevToolsFocused = new Promise(resolve => webview.addEventListener('devtools-focused', resolve, { once: true }));
await new Promise(resolve => webview.addEventListener('dom-ready', resolve, { once: true }));
webview.openDevTools();
await waitForDevToolsFocused;
webview.closeDevTools();
}, [fixtures]);
});
describe('dom-ready event', () => {
it('emits when document is loaded', async () => {
const server = http.createServer(() => {});
const { port } = await listen(server);
await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/dom-ready.html?port=${port}`
}, 'dom-ready');
build: use github actions for windows (#44136) * build: test windows runner * build: try build windows on windows? * build: take win/cross changes * build: use bash as default shell always * build: configure git for windows build tools * build: bash as default * build: configure windows correctly * build: use sha1sum * build: force windows cipd init and python3 existence * just pain * build: restore cache on windows * build: use build-tools gclient * build: sync gclient vars to build windows job * build: output depshash for debugging * build: past sam was a silly goose * build: depshash logging * build: force lf endings for lock and DEPS * build: platform strings are hard * build: checkout on windows host * sup * no check * idk * sigh * ... * no double checkout * build: yolo some stuff * build: run gn-check for windows on linux hosts for speed * use container... * cry ? * build: e d * e d * no log * fix toolchain on windows cross check * build: use powershell to add mksnapshot_args * build: enable x86 and arm64 windows builds too * clean up * maybe not needed * build: keep action around for post step * build: configure git global on win * build: ia32 zip manifest * build: no patch depot_tools for tests * build: get arm64 windows closer to working * build: windows tar is ass * 32 bit on 32 bit * maybe bash * build: set up nodejs * correct windows sharding * fix some spec runner stuff * fix windows tests * overwrite -Force * sigh * screen res * wat * logs * ... more logs * line endings will be the death of me * remove 1080p force thing * vsctools + logging * disable some fullscreen tests on GHA * no progress * run all CI * install visual studio on arm64 * windows hax for non windows * maybe arm sdk * clean up depshash logic * build: use single check per platform * ensure clean args * fix loop * remove debug * update default build image sha for dispatch * plzzzz * one more try * arm64 vctools * sad * build: fix non-dispatch windows gn check * chore: debug datadog-ci location * chore: update build-tools for newer toolchain * chore: set path for datadog-ci * try this * chore: fixup gn check * fixup gn-check some more * fixup windows gn check * chore: fixup windows gn check * test: use cmd for Windows testing * fixup use cmd for testing on Windows * fixup windows GN check * fixup npm config arch for x86 * Can we set test files via powershell * fixup to set test files via powershell * fixup set test files via powershell * Don't check cross instance cache disk space on Windows * Use separate step to set env variables for testing * fixup Use separate step to set env variables for testing * fixup Use separate step to set env variables for testing * fixup Use separate step to set env variables for testing (AGAIN) * use powershell if in powershell * fixup use powershell if in powershell * chore: remove no longer needed changes to depot_tools xref: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5669094 and https://chromium-review.googlesource.com/c/chromium/src/+/5844046 * chore: try using 7zip on Windows to extract tarball * Revert "chore: try using 7zip on Windows to extract tarball" This reverts commit c7432b6a37857fd0746b8f1776fbd1103dba0b85. * test: debug failing tests on GHA windows * fix: ftbfs when including simdjson in Node.js (cherry picked from commit 48e44c40d61b7aa843a990d4e0c8dec676b4ce8f) * chore: try to track down Windows testing hang * use correct timeout * try this * see if this helps * try to figure out why node is running * shard tests to try to narrow down WOA lockup * try to narrow down problem test * Narrow down blocking test more * do we need a combo to repro * see if this cleans up the tests * fixup navigator.usb test * remove logging from problematic tests * Revert "shard tests to try to narrow down WOA lockup" This reverts commit a1806583769678491814cb8b008131c32be4e8fb. * remove logging * debug keyboard test * add timeout for Windows since arm64 sometimes hangs * see if this helps * put back original timeout * try to use screenCapture to get screenshots of what is going on on WOA * try using electron screencapture to debug WOA hang * chore: turn off privacy experience * run screenshot on both shards * fixup screencap * try to narrow down hanging spec * chore: cleanup servers left open * cleanup tests * Revert "try to narrow down hanging spec" This reverts commit a0f959f5382f4012a9919ac535d42c5333eb7d5f. * cleanup test debugging * fixup extensions spec * cleanup unneeded items * run wtf with 2 shards instead of 6 * Revert "run wtf with 2 shards instead of 6" This reverts commit ca2d282129ee42c535d80f9876d6fa0dc6c08344. * debug windows version on woa * dump more info * Get detailed CPU info * revert debugging * use same args as AppVeyor WOA for GHA WOA * fixup use same args as AppVeyor WOA for GHA WOA * fixup use same args as AppVeyor WOA for GHA WOA * try to track down which tests trigger hang * one or more of these combinations should hang * break up web contents spec to find hang * further break down api-web-contents to find hang * test: ensure all webContents are closed * test: fix require is not defined error * see if api-web-contents spec is now good * test: ensure all webContents are closed * Revert "try to track down which tests trigger hang" This reverts commit 07298d6ffeb4873ef7615a8ec3d1a6696e354ff4. * chore: use alternate location for windows toolchain * Reapply "try to track down which tests trigger hang" This reverts commit 0321f76d01069ef325339b6fe6ed39700eae2b6b. * try to narrow down problem test * fix TEST_SHARD env var * no, really fix TEST_SHARD env var * see if this fixes it * test: cleanup any remaining windows and webcontents * see if new cleanup helps * dont destroy webcontents for now * fixup dont destroy webcontents for now * Only cleanup right before process.exit * see if this fixes the hang * actually destroy webcontents * Revert "Reapply "try to track down which tests trigger hang"" This reverts commit cdee7de049ce6bb5f67bbcc64882c56aa2c73027. * see if this helps * Revert "see if this helps" This reverts commit 9a15a69cf7dbc456db7a61efa5b6870535bae993. * Is it all about the web contents? * it is all about the webcontents but which one? * Narrow down problem webcontents test * try to speed up git install on WOA * disable problematic test on WOA * remove debugging * remove debugging from choco installs * Revert "disable problematic test on WOA" This reverts commit e060fb0839b73d53cfde1f8acdca634f8e267937. * Revert "remove debugging" This reverts commit f18dd8b1a555f56bb06d0ea996a6eff31b424bf1. * run against all the tests in the failing shard * don't run visibility tests first * remove debugging * 3 is a magic number * Revert "3 is a magic number" This reverts commit 36b91ccf9f03a4b34230cd69ceca482f7d8428c1. * match what Appveyor runs exactly * Revert "match what Appveyor runs exactly" This reverts commit 7260dd432216c62696e4bc864930f17c857eabbe. * chore: sort files alphabetically * find out what spec is leaving stuff open * chore: Checkout PR HEAD commit instead of merge commit * try using app.exit instead of process.exit * test: cleanup BrowserWindows and webContents * Revert "chore: sort files alphabetically" This reverts commit d9e217ffb1522076e150fce9e43a31bf56716acb. * chore: use win32 to match process.platform Needed for build-tools to download from PRs * chore: cache yarn dir * fixup cache yarn * fixup use win32 to match process.platform * fixup use win32 to match process.platform * fixup cache yarn * Add debugging for WOA hang * Add debugging for failing keyboard lock test * Revert "Add debugging for WOA hang" This reverts commit 8df03d568d15a269e4026140d1158e8cdf551dec. * try using process.kill * add more debugging to keyboard.lock test * Revert "Add debugging for failing keyboard lock test" * remove debugging * test: disable keyboard.lock on Windows * test: disable fullscreen tests on Windows * test: only force test suite exit on WOA * fixup test: only force test suite exit on WOA * cleanup tests * extract yarn caching/install to action * try using bash to run windows tests * remove left over debugging * standardize on 'win' for Windows builds * use 'x86' for arch for manifest files * fixup try using bash to run windows tests * fixup use 'x86' for arch for manifest files * standardize on 'win' for Windows builds * fixup use 'x86' for arch for manifest files * fixup try using bash to run windows tests --------- Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-12-12 08:51:24 -08:00
defer(() => { server.close(); });
});
itremote('throws a custom error when an API method is called before the event is emitted', () => {
const expectedErrorMessage =
'The WebView must be attached to the DOM ' +
'and the dom-ready event emitted before this method can be called.';
const webview = new WebView();
expect(() => { webview.stop(); }).to.throw(expectedErrorMessage);
});
});
describe('context-menu event', () => {
it('emits when right-clicked in page', async () => {
await loadWebView(w, { src: 'about:blank' });
const { params, url } = await w.executeJavaScript(`new Promise(resolve => {
webview.addEventListener('context-menu', (e) => resolve({...e, url: webview.getURL() }), {once: true})
// Simulate right-click to create context-menu event.
const opts = { x: 0, y: 0, button: 'right' };
webview.sendInputEvent({ ...opts, type: 'mouseDown' });
webview.sendInputEvent({ ...opts, type: 'mouseUp' });
})`);
expect(params.pageURL).to.equal(url);
expect(params.frame).to.be.undefined();
expect(params.x).to.be.a('number');
expect(params.y).to.be.a('number');
});
});
describe('found-in-page event', () => {
itremote('emits when a request is made', async (fixtures: string) => {
const webview = new WebView();
const didFinishLoad = new Promise(resolve => webview.addEventListener('did-finish-load', resolve, { once: true }));
webview.src = `file://${fixtures}/pages/content.html`;
document.body.appendChild(webview);
// TODO(deepak1556): With https://codereview.chromium.org/2836973002
// focus of the webContents is required when triggering the api.
// Remove this workaround after determining the cause for
// incorrect focus.
webview.focus();
await didFinishLoad;
const activeMatchOrdinal = [];
for (;;) {
const foundInPage = new Promise<any>(resolve => webview.addEventListener('found-in-page', resolve, { once: true }));
const requestId = webview.findInPage('virtual');
const event = await foundInPage;
expect(event.result.requestId).to.equal(requestId);
expect(event.result.matches).to.equal(3);
activeMatchOrdinal.push(event.result.activeMatchOrdinal);
if (event.result.activeMatchOrdinal === event.result.matches) {
break;
}
}
expect(activeMatchOrdinal).to.deep.equal([1, 2, 3]);
webview.stopFindInPage('clearSelection');
}, [fixtures]);
});
describe('will-attach-webview event', () => {
itremote('does not emit when src is not changed', async () => {
const webview = new WebView();
document.body.appendChild(webview);
await setTimeout();
const expectedErrorMessage = 'The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.';
expect(() => { webview.stop(); }).to.throw(expectedErrorMessage);
});
it('supports changing the web preferences', async () => {
w.once('will-attach-webview', (event, webPreferences, params) => {
params.src = `file://${path.join(fixtures, 'pages', 'c.html')}`;
webPreferences.nodeIntegration = false;
});
const message = await loadWebViewAndWaitForMessage(w, {
nodeintegration: 'yes',
src: `file://${fixtures}/pages/a.html`
});
const types = JSON.parse(message);
expect(types).to.include({
require: 'undefined',
module: 'undefined',
process: 'undefined',
global: 'undefined'
});
});
it('handler modifying params.instanceId does not break <webview>', async () => {
w.once('will-attach-webview', (event, webPreferences, params) => {
params.instanceId = null as any;
});
await loadWebViewAndWaitForMessage(w, {
src: `file://${fixtures}/pages/a.html`
});
});
it('supports preventing a webview from being created', async () => {
w.once('will-attach-webview', event => event.preventDefault());
await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/c.html`
}, 'destroyed');
});
it('supports removing the preload script', async () => {
w.once('will-attach-webview', (event, webPreferences, params) => {
params.src = url.pathToFileURL(path.join(fixtures, 'pages', 'webview-stripped-preload.html')).toString();
delete webPreferences.preload;
});
const message = await loadWebViewAndWaitForMessage(w, {
nodeintegration: 'yes',
preload: path.join(fixtures, 'module', 'preload-set-global.js'),
src: `file://${fixtures}/pages/a.html`
});
expect(message).to.equal('undefined');
});
});
describe('media-started-playing and media-paused events', () => {
it('emits when audio starts and stops playing', async function () {
if (!await w.executeJavaScript('document.createElement(\'audio\').canPlayType(\'audio/wav\')')) {
return this.skip();
}
await loadWebView(w, { src: blankPageUrl });
// With the new autoplay policy, audio elements must be unmuted
// see https://goo.gl/xX8pDD.
await w.executeJavaScript(`new Promise(resolve => {
webview.executeJavaScript(\`
const audio = document.createElement("audio")
audio.src = "../assets/tone.wav"
document.body.appendChild(audio);
audio.play()
\`, true)
webview.addEventListener('media-started-playing', () => resolve(), {once: true})
})`);
await w.executeJavaScript(`new Promise(resolve => {
webview.executeJavaScript(\`
document.querySelector("audio").pause()
\`, true)
webview.addEventListener('media-paused', () => resolve(), {once: true})
})`);
});
});
});
describe('methods', () => {
let w: WebContents;
before(async () => {
const window = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: false
}
});
await window.loadURL(`file://${fixtures}/pages/blank.html`);
w = window.webContents;
});
afterEach(async () => {
await w.executeJavaScript(`{
for (const el of document.querySelectorAll('webview')) el.remove();
}`);
});
after(closeAllWindows);
describe('<webview>.reload()', () => {
it('should emit beforeunload handler', async () => {
await loadWebView(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/beforeunload-false.html`
});
// Event handler has to be added before reload.
const channel = await w.executeJavaScript(`new Promise(resolve => {
webview.addEventListener('ipc-message', e => resolve(e.channel))
webview.reload();
})`);
expect(channel).to.equal('onbeforeunload');
});
it('does not crash when renderer process crashes', async function () {
// It takes more time to wait for the rendering process to crash
this.timeout(120000);
await loadWebView(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: blankPageUrl
});
// Create a crash in the rendering process of a webview
await w.executeJavaScript(`new Promise((resolve, reject) => {
webview.addEventListener('render-process-gone', (e) => resolve({...e}), {once: true})
webview.executeJavaScript('process.crash()', true)
})`);
// Reload the webview and the main process will not crash.
await w.executeJavaScript(`new Promise((resolve, reject) => {
webview.reload()
webview.addEventListener('did-finish-load', () => {
resolve()
})
})`);
});
});
describe('<webview>.goForward()', () => {
useRemoteContext({ webPreferences: { webviewTag: true } });
itremote('should work after a replaced history entry', async (fixtures: string) => {
function waitForEvent (target: EventTarget, event: string) {
return new Promise<any>(resolve => target.addEventListener(event, resolve, { once: true }));
}
function waitForEvents (target: EventTarget, ...events: string[]) {
return Promise.all(events.map(event => waitForEvent(webview, event)));
}
const webview = new WebView();
webview.setAttribute('nodeintegration', 'on');
webview.setAttribute('webpreferences', 'contextIsolation=no');
webview.src = `file://${fixtures}/pages/history-replace.html`;
document.body.appendChild(webview);
{
const [e] = await waitForEvents(webview, 'ipc-message', 'did-stop-loading');
expect(e.channel).to.equal('history');
expect(e.args[0]).to.equal(1);
expect(webview.canGoBack()).to.be.false();
expect(webview.canGoForward()).to.be.false();
}
webview.src = `file://${fixtures}/pages/base-page.html`;
await new Promise<void>(resolve => webview.addEventListener('did-stop-loading', resolve, { once: true }));
expect(webview.canGoBack()).to.be.true();
expect(webview.canGoForward()).to.be.false();
webview.goBack();
{
const [e] = await waitForEvents(webview, 'ipc-message', 'did-stop-loading');
expect(e.channel).to.equal('history');
expect(e.args[0]).to.equal(2);
expect(webview.canGoBack()).to.be.false();
expect(webview.canGoForward()).to.be.true();
}
webview.goForward();
await new Promise<void>(resolve => webview.addEventListener('did-stop-loading', resolve, { once: true }));
expect(webview.canGoBack()).to.be.true();
expect(webview.canGoForward()).to.be.false();
}, [fixtures]);
});
describe('<webview>.clearHistory()', () => {
it('should clear the navigation history', async () => {
await loadWebView(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: blankPageUrl
});
// Navigation must be triggered by a user gesture to make canGoBack() return true
await w.executeJavaScript('webview.executeJavaScript(`history.pushState(null, "", "foo.html")`, true)');
expect(await w.executeJavaScript('webview.canGoBack()')).to.be.true();
await w.executeJavaScript('webview.clearHistory()');
expect(await w.executeJavaScript('webview.canGoBack()')).to.be.false();
});
});
describe('executeJavaScript', () => {
it('can return the result of the executed script', async () => {
await loadWebView(w, {
src: 'about:blank'
});
const jsScript = "'4'+2";
const expectedResult = '42';
const result = await w.executeJavaScript(`webview.executeJavaScript(${JSON.stringify(jsScript)})`);
expect(result).to.equal(expectedResult);
});
});
it('supports inserting CSS', async () => {
await loadWebView(w, { src: `file://${fixtures}/pages/base-page.html` });
await w.executeJavaScript('webview.insertCSS(\'body { background-repeat: round; }\')');
const result = await w.executeJavaScript('webview.executeJavaScript(\'window.getComputedStyle(document.body).getPropertyValue("background-repeat")\')');
expect(result).to.equal('round');
});
it('supports removing inserted CSS', async () => {
await loadWebView(w, { src: `file://${fixtures}/pages/base-page.html` });
const key = await w.executeJavaScript('webview.insertCSS(\'body { background-repeat: round; }\')');
await w.executeJavaScript(`webview.removeInsertedCSS(${JSON.stringify(key)})`);
const result = await w.executeJavaScript('webview.executeJavaScript(\'window.getComputedStyle(document.body).getPropertyValue("background-repeat")\')');
expect(result).to.equal('repeat');
});
describe('sendInputEvent', () => {
it('can send keyboard event', async () => {
await loadWebViewAndWaitForEvent(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/onkeyup.html`
}, 'dom-ready');
const waitForIpcMessage = w.executeJavaScript('new Promise(resolve => webview.addEventListener("ipc-message", e => resolve({...e})), {once: true})');
w.executeJavaScript(`webview.sendInputEvent({
type: 'keyup',
keyCode: 'c',
modifiers: ['shift']
})`);
const { channel, args } = await waitForIpcMessage;
expect(channel).to.equal('keyup');
expect(args).to.deep.equal(['C', 'KeyC', 67, true, false]);
});
it('can send mouse event', async () => {
await loadWebViewAndWaitForEvent(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/onmouseup.html`
}, 'dom-ready');
const waitForIpcMessage = w.executeJavaScript('new Promise(resolve => webview.addEventListener("ipc-message", e => resolve({...e})), {once: true})');
w.executeJavaScript(`webview.sendInputEvent({
type: 'mouseup',
modifiers: ['ctrl'],
x: 10,
y: 20
})`);
const { channel, args } = await waitForIpcMessage;
expect(channel).to.equal('mouseup');
expect(args).to.deep.equal([10, 20, false, true]);
});
});
describe('<webview>.getWebContentsId', () => {
it('can return the WebContents ID', async () => {
await loadWebView(w, { src: 'about:blank' });
expect(await w.executeJavaScript('webview.getWebContentsId()')).to.be.a('number');
});
});
ifdescribe(features.isPrintingEnabled())('<webview>.printToPDF()', () => {
it('rejects on incorrectly typed parameters', async () => {
const badTypes = {
landscape: [],
displayHeaderFooter: '123',
printBackground: 2,
scale: 'not-a-number',
pageSize: 'IAmAPageSize',
margins: 'terrible',
pageRanges: { oops: 'im-not-the-right-key' },
headerTemplate: [1, 2, 3],
footerTemplate: [4, 5, 6],
preferCSSPageSize: 'no'
};
// These will hard crash in Chromium unless we type-check
for (const [key, value] of Object.entries(badTypes)) {
const param = { [key]: value };
const src = 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E';
await loadWebView(w, { src });
await expect(w.executeJavaScript(`webview.printToPDF(${JSON.stringify(param)})`)).to.eventually.be.rejected();
}
});
it('can print to PDF', async () => {
const src = 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E';
await loadWebView(w, { src });
const data = await w.executeJavaScript('webview.printToPDF({})');
expect(data).to.be.an.instanceof(Uint8Array).that.is.not.empty();
});
});
describe('DOM events', () => {
for (const [description, sandbox] of [
['without sandbox', false] as const,
['with sandbox', true] as const
]) {
describe(description, () => {
it('emits focus event', async () => {
await loadWebViewAndWaitForEvent(w, {
src: `file://${fixtures}/pages/a.html`,
webpreferences: `sandbox=${sandbox ? 'yes' : 'no'}`
}, 'dom-ready');
// If this test fails, check if webview.focus() still works.
await w.executeJavaScript(`new Promise(resolve => {
webview.addEventListener('focus', () => resolve(), {once: true});
webview.focus();
})`);
});
});
}
});
// FIXME: This test is flaking constantly on Linux and macOS.
xdescribe('<webview>.capturePage()', () => {
it('returns a Promise with a NativeImage', async function () {
this.retries(5);
const src = 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E';
await loadWebViewAndWaitForEvent(w, { src }, 'did-stop-loading');
const image = await w.executeJavaScript('webview.capturePage()');
expect(image.isEmpty()).to.be.false();
// Check the 25th byte in the PNG.
// Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha
const imgBuffer = image.toPNG();
expect(imgBuffer[25]).to.equal(6);
});
it('returns a Promise with a NativeImage in the renderer', async function () {
this.retries(5);
const src = 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E';
await loadWebViewAndWaitForEvent(w, { src }, 'did-stop-loading');
const byte = await w.executeJavaScript(`new Promise(resolve => {
webview.capturePage().then(image => {
resolve(image.toPNG()[25])
});
})`);
expect(byte).to.equal(6);
});
});
// FIXME(zcbenz): Disabled because of moving to OOPIF webview.
xdescribe('setDevToolsWebContents() API', () => {
/*
it('sets webContents of webview as devtools', async () => {
const webview2 = new WebView();
loadWebView(webview2);
// Setup an event handler for further usage.
const waitForDomReady = waitForEvent(webview2, 'dom-ready');
loadWebView(webview, { src: 'about:blank' });
await waitForEvent(webview, 'dom-ready');
webview.getWebContents().setDevToolsWebContents(webview2.getWebContents());
webview.getWebContents().openDevTools();
await waitForDomReady;
// Its WebContents should be a DevTools.
const devtools = webview2.getWebContents();
expect(devtools.getURL().startsWith('devtools://devtools')).to.be.true();
const name = await devtools.executeJavaScript('InspectorFrontendHost.constructor.name');
document.body.removeChild(webview2);
expect(name).to.be.equal('InspectorFrontendHostImpl');
});
*/
});
});
describe('basic auth', () => {
let w: WebContents;
before(async () => {
const window = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
contextIsolation: false
}
});
await window.loadURL(`file://${fixtures}/pages/blank.html`);
w = window.webContents;
});
afterEach(async () => {
await w.executeJavaScript(`{
for (const el of document.querySelectorAll('webview')) el.remove();
}`);
});
after(closeAllWindows);
it('should authenticate with correct credentials', async () => {
const message = 'Authenticated';
const server = http.createServer((req, res) => {
const credentials = auth(req)!;
if (credentials.name === 'test' && credentials.pass === 'test') {
res.end(message);
} else {
res.end('failed');
}
});
defer(() => {
server.close();
});
const { port } = await listen(server);
const e = await loadWebViewAndWaitForEvent(w, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
src: `file://${fixtures}/pages/basic-auth.html?port=${port}`
}, 'ipc-message');
expect(e.channel).to.equal(message);
});
});
refactor: use v8 serialization for ipc (#20214) * refactor: use v8 serialization for ipc * cloning process.env doesn't work * serialize host objects by enumerating key/values * new serialization can handle NaN, Infinity, and undefined correctly * can't allocate v8 objects during GC * backport microtasks fix * fix compile * fix node_stream_loader reentrancy * update subframe spec to expect undefined instead of null * write undefined instead of crashing when serializing host objects * fix webview spec * fix download spec * buffers are transformed into uint8arrays * can't serialize promises * fix chrome.i18n.getMessage * fix devtools tests * fix zoom test * fix debug build * fix lint * update ipcRenderer tests * fix printToPDF test * update patch * remove accidentally re-added remote-side spec * wip * don't attempt to serialize host objects * jump through different hoops to set options.webContents sometimes * whoops * fix lint * clean up error-handling logic * fix memory leak * fix lint * convert host objects using old base::Value serialization * fix lint more * fall back to base::Value-based serialization * remove commented-out code * add docs to breaking-changes.md * Update breaking-changes.md * update ipcRenderer and WebContents docs * lint * use named values for format tag * save a memcpy for ~30% speedup * get rid of calls to ShallowClone * extra debugging for paranoia * d'oh, use the correct named tags * apparently msstl doesn't like this DCHECK * funny story about that DCHECK * disable remote-related functions when enable_remote_module = false * nits * use EnableIf to disable remote methods in mojom * fix include * review comments
2019-10-09 10:59:08 -07:00
});