electron/spec/api-browser-window-spec.ts

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

6851 строка
238 KiB
TypeScript
Исходник Постоянная ссылка Обычный вид История

import { nativeImage } from 'electron';
import { app, BrowserWindow, BrowserView, dialog, ipcMain, OnBeforeSendHeadersListenerDetails, net, protocol, screen, webContents, webFrameMain, session, WebContents, WebFrameMain } from 'electron/main';
import { expect } from 'chai';
import * as childProcess from 'node:child_process';
import { once } from 'node:events';
import * as fs from 'node:fs';
import * as http from 'node:http';
import { AddressInfo } from 'node:net';
import * as os from 'node:os';
import * as path from 'node:path';
import * as qs from 'node:querystring';
import { setTimeout as syncSetTimeout } from 'node:timers';
import { setTimeout } from 'node:timers/promises';
import * as nodeUrl from 'node:url';
import { emittedUntil, emittedNTimes } from './lib/events-helpers';
import { HexColors, hasCapturableScreen, ScreenCapture } from './lib/screen-helpers';
import { ifit, ifdescribe, defer, listen, waitUntil } from './lib/spec-helpers';
import { closeWindow, closeAllWindows } from './lib/window-helpers';
const fixtures = path.resolve(__dirname, 'fixtures');
const mainFixtures = path.resolve(__dirname, 'fixtures');
// Is the display's scale factor possibly causing rounding of pixel coordinate
// values?
const isScaleFactorRounding = () => {
const { scaleFactor } = screen.getPrimaryDisplay();
// Return true if scale factor is non-integer value
if (Math.round(scaleFactor) !== scaleFactor) return true;
// Return true if scale factor is odd number above 2
return scaleFactor > 2 && scaleFactor % 2 === 1;
};
const expectBoundsEqual = (actual: any, expected: any) => {
if (!isScaleFactorRounding()) {
expect(actual).to.deep.equal(expected);
} else if (Array.isArray(actual)) {
expect(actual[0]).to.be.closeTo(expected[0], 1);
expect(actual[1]).to.be.closeTo(expected[1], 1);
} else {
expect(actual.x).to.be.closeTo(expected.x, 1);
expect(actual.y).to.be.closeTo(expected.y, 1);
expect(actual.width).to.be.closeTo(expected.width, 1);
expect(actual.height).to.be.closeTo(expected.height, 1);
}
};
const isBeforeUnload = (event: Event, level: number, message: string) => {
return (message === 'beforeunload');
};
describe('BrowserWindow module', () => {
it('sets the correct class name on the prototype', () => {
expect(BrowserWindow.prototype.constructor.name).to.equal('BrowserWindow');
});
describe('BrowserWindow constructor', () => {
it('allows passing void 0 as the webContents', async () => {
expect(() => {
const w = new BrowserWindow({
show: false,
// apparently void 0 had different behaviour from undefined in the
// issue that this test is supposed to catch.
webContents: void 0 // eslint-disable-line no-void
} as any);
w.destroy();
}).not.to.throw();
});
chore: bump chromium to d66c2e32380bf5d1eb5e1fe37faef (master) (#23791) * chore: bump chromium in DEPS to db7d7b3e7cb2bc925f2abfde526280cfdfc21a41 * Update patches * chore: bump chromium in DEPS to 5613e1b99a44fcbe22f3910f803ca76903a77ec1 * Update patches * Network service: Remove primary_network_context bool. https://chromium-review.googlesource.com/c/chromium/src/+/2204678 * WebContentsObserver now implements OnRendererResponsive https://chromium-review.googlesource.com/c/chromium/src/+/2211066 * update patches * Fixup printing patch * chore: bump chromium in DEPS to e387b972cdd7160c416fa6c64a724e2258aa0218 * update patches * [printing] Move PrintHostMsg_DidPrintContent_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2212110 * [XProto] Move items from ::x11::XProto to ::x11 https://chromium-review.googlesource.com/c/chromium/src/+/2218476 * revert Add IChromeAccessible This was added in https://chromium-review.googlesource.com/c/chromium/src/+/2206224 but it breaks WOA builds because third_party/win_build_output/midl/ui/accessibility/platform/arm64 does not exist. The link above says that the new interface is behind a feature flag which is disabled by default so it is safe to remove for now. * rebaseline ichromeaccessible for Windows arm64 This patch will not be needed once we get the next roll. * Update to 1b9e01844e8bf1aaafc4a52c0c62af7f56d9637b to get arm64 fix * update patches * chore: bump chromium in DEPS to 096aefa04092ea00f7b68d8d19345883f20db3c3 * chore: bump chromium in DEPS to a524a45ffd1d6fd46a7a86138fe2b22df5b6651a * chore: update patches * Window Placement: Gate cross-screen fullscreen behavior on permission https://chromium-review.googlesource.com/c/chromium/src/+/2203268 * chore: add spec for https://crbug.com/1085836 * chore: bump chromium in DEPS to ff6c4f4b826d66c2e32380bf5d1eb5e1fe37faef * update patches Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: deepak1556 <hop2deep@gmail.com>
2020-06-01 23:34:34 +03:00
ifit(process.platform === 'linux')('does not crash when setting large window icons', async () => {
const appPath = path.join(fixtures, 'apps', 'xwindow-icon');
chore: bump chromium to d66c2e32380bf5d1eb5e1fe37faef (master) (#23791) * chore: bump chromium in DEPS to db7d7b3e7cb2bc925f2abfde526280cfdfc21a41 * Update patches * chore: bump chromium in DEPS to 5613e1b99a44fcbe22f3910f803ca76903a77ec1 * Update patches * Network service: Remove primary_network_context bool. https://chromium-review.googlesource.com/c/chromium/src/+/2204678 * WebContentsObserver now implements OnRendererResponsive https://chromium-review.googlesource.com/c/chromium/src/+/2211066 * update patches * Fixup printing patch * chore: bump chromium in DEPS to e387b972cdd7160c416fa6c64a724e2258aa0218 * update patches * [printing] Move PrintHostMsg_DidPrintContent_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2212110 * [XProto] Move items from ::x11::XProto to ::x11 https://chromium-review.googlesource.com/c/chromium/src/+/2218476 * revert Add IChromeAccessible This was added in https://chromium-review.googlesource.com/c/chromium/src/+/2206224 but it breaks WOA builds because third_party/win_build_output/midl/ui/accessibility/platform/arm64 does not exist. The link above says that the new interface is behind a feature flag which is disabled by default so it is safe to remove for now. * rebaseline ichromeaccessible for Windows arm64 This patch will not be needed once we get the next roll. * Update to 1b9e01844e8bf1aaafc4a52c0c62af7f56d9637b to get arm64 fix * update patches * chore: bump chromium in DEPS to 096aefa04092ea00f7b68d8d19345883f20db3c3 * chore: bump chromium in DEPS to a524a45ffd1d6fd46a7a86138fe2b22df5b6651a * chore: update patches * Window Placement: Gate cross-screen fullscreen behavior on permission https://chromium-review.googlesource.com/c/chromium/src/+/2203268 * chore: add spec for https://crbug.com/1085836 * chore: bump chromium in DEPS to ff6c4f4b826d66c2e32380bf5d1eb5e1fe37faef * update patches Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: deepak1556 <hop2deep@gmail.com>
2020-06-01 23:34:34 +03:00
const appProcess = childProcess.spawn(process.execPath, [appPath]);
await once(appProcess, 'exit');
chore: bump chromium to d66c2e32380bf5d1eb5e1fe37faef (master) (#23791) * chore: bump chromium in DEPS to db7d7b3e7cb2bc925f2abfde526280cfdfc21a41 * Update patches * chore: bump chromium in DEPS to 5613e1b99a44fcbe22f3910f803ca76903a77ec1 * Update patches * Network service: Remove primary_network_context bool. https://chromium-review.googlesource.com/c/chromium/src/+/2204678 * WebContentsObserver now implements OnRendererResponsive https://chromium-review.googlesource.com/c/chromium/src/+/2211066 * update patches * Fixup printing patch * chore: bump chromium in DEPS to e387b972cdd7160c416fa6c64a724e2258aa0218 * update patches * [printing] Move PrintHostMsg_DidPrintContent_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2212110 * [XProto] Move items from ::x11::XProto to ::x11 https://chromium-review.googlesource.com/c/chromium/src/+/2218476 * revert Add IChromeAccessible This was added in https://chromium-review.googlesource.com/c/chromium/src/+/2206224 but it breaks WOA builds because third_party/win_build_output/midl/ui/accessibility/platform/arm64 does not exist. The link above says that the new interface is behind a feature flag which is disabled by default so it is safe to remove for now. * rebaseline ichromeaccessible for Windows arm64 This patch will not be needed once we get the next roll. * Update to 1b9e01844e8bf1aaafc4a52c0c62af7f56d9637b to get arm64 fix * update patches * chore: bump chromium in DEPS to 096aefa04092ea00f7b68d8d19345883f20db3c3 * chore: bump chromium in DEPS to a524a45ffd1d6fd46a7a86138fe2b22df5b6651a * chore: update patches * Window Placement: Gate cross-screen fullscreen behavior on permission https://chromium-review.googlesource.com/c/chromium/src/+/2203268 * chore: add spec for https://crbug.com/1085836 * chore: bump chromium in DEPS to ff6c4f4b826d66c2e32380bf5d1eb5e1fe37faef * update patches Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: deepak1556 <hop2deep@gmail.com>
2020-06-01 23:34:34 +03:00
});
it('does not crash or throw when passed an invalid icon', async () => {
expect(() => {
const w = new BrowserWindow({
icon: undefined
} as any);
w.destroy();
}).not.to.throw();
});
});
describe('garbage collection', () => {
const v8Util = process._linkedBinding('electron_common_v8_util');
afterEach(closeAllWindows);
it('window does not get garbage collected when opened', async () => {
const w = new BrowserWindow({ show: false });
// Keep a weak reference to the window.
const wr = new WeakRef(w);
await setTimeout();
// Do garbage collection, since |w| is not referenced in this closure
// it would be gone after next call if there is no other reference.
v8Util.requestGarbageCollectionForTesting();
await setTimeout();
expect(wr.deref()).to.not.be.undefined();
});
});
describe('BrowserWindow.close()', () => {
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
});
afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
it('should work if called when a messageBox is showing', async () => {
const closed = once(w, 'closed');
dialog.showMessageBox(w, { message: 'Hello Error' });
w.close();
await closed;
});
it('should work if called when multiple messageBoxes are showing', async () => {
const closed = once(w, 'closed');
dialog.showMessageBox(w, { message: 'Hello Error' });
dialog.showMessageBox(w, { message: 'Hello Error' });
w.close();
await closed;
});
it('closes window without rounded corners', async () => {
await closeWindow(w);
w = new BrowserWindow({ show: false, frame: false, roundedCorners: false });
const closed = once(w, 'closed');
w.close();
await closed;
});
it('should not crash if called after webContents is destroyed', () => {
w.webContents.destroy();
w.webContents.on('destroyed', () => w.close());
});
it('should allow access to id after destruction', async () => {
const closed = once(w, 'closed');
w.destroy();
await closed;
expect(w.id).to.be.a('number');
});
it('should emit unload handler', async () => {
await w.loadFile(path.join(fixtures, 'api', 'unload.html'));
const closed = once(w, 'closed');
w.close();
await closed;
const test = path.join(fixtures, 'api', 'unload');
const content = fs.readFileSync(test);
fs.unlinkSync(test);
expect(String(content)).to.equal('unload');
});
it('should emit beforeunload handler', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false.html'));
w.close();
await once(w.webContents, '-before-unload-fired');
});
it('should not crash when keyboard event is sent before closing', async () => {
await w.loadURL('data:text/html,pls no crash');
const closed = once(w, 'closed');
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
w.close();
await closed;
});
describe('when invoked synchronously inside navigation observer', () => {
let server: http.Server;
let url: string;
before(async () => {
server = http.createServer((request, response) => {
switch (request.url) {
case '/net-error':
response.destroy();
break;
case '/301':
response.statusCode = 301;
response.setHeader('Location', '/200');
response.end();
break;
case '/200':
response.statusCode = 200;
response.end('hello');
break;
case '/title':
response.statusCode = 200;
response.end('<title>Hello</title>');
break;
default:
throw new Error(`unsupported endpoint: ${request.url}`);
}
});
url = (await listen(server)).url;
});
after(() => {
server.close();
});
const events = [
{ name: 'did-start-loading', path: '/200' },
{ name: 'dom-ready', path: '/200' },
{ name: 'page-title-updated', path: '/title' },
{ name: 'did-stop-loading', path: '/200' },
{ name: 'did-finish-load', path: '/200' },
{ name: 'did-frame-finish-load', path: '/200' },
{ name: 'did-fail-load', path: '/net-error' }
];
2019-11-01 23:37:02 +03:00
for (const { name, path } of events) {
it(`should not crash when closed during ${name}`, async () => {
const w = new BrowserWindow({ show: false });
w.webContents.once((name as any), () => {
w.close();
});
const destroyed = once(w.webContents, 'destroyed');
w.webContents.loadURL(url + path);
await destroyed;
});
}
});
});
describe('window.close()', () => {
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
});
afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
it('should emit unload event', async () => {
w.loadFile(path.join(fixtures, 'api', 'close.html'));
await once(w, 'closed');
const test = path.join(fixtures, 'api', 'close');
const content = fs.readFileSync(test).toString();
fs.unlinkSync(test);
expect(content).to.equal('close');
});
it('should emit beforeunload event', async function () {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false.html'));
w.webContents.executeJavaScript('window.close()', true);
await once(w.webContents, '-before-unload-fired');
});
});
describe('BrowserWindow.destroy()', () => {
let w: BrowserWindow;
beforeEach(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
});
afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
it('prevents users to access methods of webContents', async () => {
const contents = w.webContents;
w.destroy();
await new Promise(setImmediate);
expect(() => {
contents.getProcessId();
}).to.throw('Object has been destroyed');
});
it('should not crash when destroying windows with pending events', () => {
const focusListener = () => { };
app.on('browser-window-focus', focusListener);
const windowCount = 3;
const windowOptions = {
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false
}
};
2019-11-01 23:37:02 +03:00
const windows = Array.from(Array(windowCount)).map(() => new BrowserWindow(windowOptions));
for (const win of windows) win.show();
for (const win of windows) win.focus();
for (const win of windows) win.destroy();
app.removeListener('browser-window-focus', focusListener);
});
});
describe('BrowserWindow.loadURL(url)', () => {
let w: BrowserWindow;
chore: bump chromium to f1d9522c04ca8fa0a906f88ababe9 (master) (#18648) * chore: bump chromium in DEPS to 675d7dc9f3334b15c3ec28c27db3dc19b26bd12e * chore: update patches * chore: bump chromium in DEPS to dce3562696f165a324273fcb6893f0e1fef42ab1 * chore: const interfaces are being removed from //content Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1631749 Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=908139 * chore: update patches * chore: blink::MediaStreamType is now consistent and deduplicated * chore: update patches and printing code for ref -> uniq * chore: bridge_impl() --> GetInProcessNSWindowBridge Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1642988 * fixme: TotalMarkedObjectSize has been removed * chore: fix linting * chore: bump chromium in DEPS to 9503e1a2fcbf17db08094d8caae3e1407e918af3 * chore: fix slightly broken printing patch * chore: update patches for SiteInstanceImpl changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1612025 * chore: update patches for SiteInstanceImpl changes * chore: bump chromium in DEPS to 6801e6c1ddd1b7b73e594e97157ddd539ca335d7 * chore: update patches * chore: bump chromium in DEPS to 27e198912d7c1767052ec785c22e2e88b2cb4d8b * chore: remove system_request_context Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1647172 * chore: creation of FtpProtocolHandler needs an auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639683 * fixme: disable marked spec * chore: bump chromium in DEPS to 3dcd7fe453ad13a22b114b95f05590eba74c5471 * chore: bump chromium in DEPS to bdc24128b75008743d819e298557a53205706e7c * chore: bump chromium in DEPS to 7da330b58fbe0ba94b9b94abbb8085bead220228 * update patches * remove TotalMarkedObjectSize https://chromium-review.googlesource.com/c/chromium/src/+/1631708 * add libvulkan.so to dist zip manifest on linux * chore: bump chromium in DEPS to 1e85d0f45b52649efd0010cc9dab6d2804f24443 * update patches * add angle features to gpuinfo https://chromium-review.googlesource.com/c/chromium/src/+/1638658 * mark 'marked' property as deprecated * disable webview resize test * FIXME: disable vulkan on 32-bit arm * chore: bump chromium in DEPS to cd0297c6a83fdd2b1f6bc312e7d5acca736a3c56 * Revert "FIXME: disable vulkan on 32-bit arm" This reverts commit 5c1e0ef302a6db1e72231d4e823f91bb08e281af. * backport from upstream: fix swiftshader build on arm https://swiftshader-review.googlesource.com/c/SwiftShader/+/32768/ * update patches * viz: update OutputDeviceWin to new shared memory api https://chromium-review.googlesource.com/c/chromium/src/+/1649574 * base::Contains{Key,Value} => base::Contains https://chromium-review.googlesource.com/c/chromium/src/+/1649478 * fixup! viz: update OutputDeviceWin to new shared memory api * stub out StatusIconLinuxDbus-related delegate methods https://chromium-review.googlesource.com/c/chromium/src/+/1638180 * chore: bump chromium in DEPS to 964ea3fd4bdc006d62533f5755043076220181f1 * Remove the BrowserContext methods to create URLRequestContexts for main/media partitions when a partition_domain is specified https://chromium-review.googlesource.com/c/chromium/src/+/1655087 * fixup! stub out StatusIconLinuxDbus-related delegate methods * add remote_cocoa to chromium_src deps https://chromium-review.googlesource.com/c/chromium/src/+/1657068 * fixup! stub out StatusIconLinuxDbus-related delegate methods * attempt at fix linux-debug build * add swiftshader/libvulkan.so to arm manifest * chore: bump chromium in DEPS to 28688f76afef27c36631aa274691e333ddecdc22 * update patches * chore: bump chromium in DEPS to fe7450e1578a9584189f87d59d0d1a8548bf6b90 * chore: bump chromium in DEPS to f304dfd682dc86a755a6c49a16ee6876e0db45fb * chore: bump chromium in DEPS to f0fd4d6c365aad9edd83bdfff9954c47d271b75c * Update patches * Remove no longer needed WOA patch * Put back IOThread in BrowserProcess We need this until we enable the network service. * move atom.ico to inputs * Update to latest LKGR to fix no template named 'bitset' in namespace 'std' * fixup! Put back IOThread in BrowserProcess * chore: bump chromium in DEPS to dcf9662dc9a896a175d791001350324167b1cad3 * Update patches content_allow_embedder_to_prevent_locking_scheme_registry.patch is no longer necessary as it was upstreamed via https://chromium-review.googlesource.com/c/chromium/src/+/1637040 * Fix renamed enum * Use newer docker container Contains updated dependencies * Try to track down arm test failures * Fix arm tests * chore: bump chromium in DEPS to 8cbceef57b37ee14b9c4c3405a3f7663922c5b5d * Update patches * Add needed dependencies for testing 32-bit linux * Remove arm debugging. * Remove additional debugging * Fix compiler errors * Handle new macOS helper * Fix compile error on Linux * chore: bump chromium in DEPS to 66a93991ddaff6a9f1b13d110959947cb03a1860 * Add new helper files to manifests * fix BUILD.gn for macOS * Fix compile errors * Add patch to put back colors needed for autofill/datalist * chore: bump chromium in DEPS to e89617079f11e33f33cdb3924f719a579c73704b * Updated patches * Remove no longer needed patch * Remove no longer needed patch * Fix compile error with patch * Really fix the patch * chore: bump chromium in DEPS to c70f12476a45840408f1d5ff5968e7f7ceaad9d4 * chore: bump chromium in DEPS to 06d2dd7a8933b41545a7c26349c802f570563fd5 * chore: bump chromium in DEPS to b0b9ff8f727deb519ccbec7cf1c8d9ed543d88ab * Update patches * Fix compiler errors * Fix removed ChromeNetLog * Revert "Fix removed ChromeNetLog" This reverts commit 426dfd90b5ab0a9c1df415d71c88e8aed2bd5bbe. * Remove ChromeNetLog. https://chromium-review.googlesource.com/c/chromium/src/+/1663846 * chore: bump chromium in DEPS to fefcc4926d58dccd59ac95be65eab3a4ebfe2f29 * Update patches * Update v8 patches * Fix lint error * Fix compile errors * chore: bump chromium in DEPS to 4de815ef92ef2eef515506fe09bdc466526a8fd9 * Use custom protocol to test baseURLForDataURL * Use newer SDK (10.0.18362) for Windows * Update patches * Update arm manifest since swiftshader reenabled. * Don't delete dir that isn't ever there. * Fix compile errors. * Need src dir created * Update for removed InspectorFrontendAPI.addExtensions * Revert "Use newer SDK (10.0.18362) for Windows" This reverts commit 68763a0c88cdc44b971462e49662aecc167d3d99. * Revert "Need src dir created" This reverts commit 7daedc29d0844316d4097648dde7f40f1a3848fb. * Revert "Don't delete dir that isn't ever there." This reverts commit bf424bc30ffcb23b1d9a634d4df410342536640e. * chore: bump chromium in DEPS to 97dab6b0124ea53244caf123921b5d14893bcca7 * chore: bump chromium in DEPS to c87d16d49a85dc7122781f6c979d354c20f7f78b * chore: bump chromium in DEPS to 004bcee2ea336687cedfda8f8a151806ac757d15 * chore: bump chromium in DEPS to 24428b26a9d15a013b2a253e1084ec3cb54b660b * chore: bump chromium in DEPS to fd25914e875237df88035a6abf89a70bf1360b57 * Update patches * Update node to fix build error * Fix compile errors * chore: bump chromium in DEPS to 3062b7cf090f1d9522c04ca8fa0a906f88ababe9 * chore: update node ref for pushed tags * chore: update patches for new chromium * chore: fix printing patches * Use new (10.0.18362) Windows SDK * roll node to fix v8 build issues in debug build * Add support for plugin helper * fix: add patch to fix gpu info enumeration Can be removed once CL lands upstream. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1685993 * spec: navigator.requestMIDIAccess now requires a secure origin This test requires a secure origin so we fake one. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1657952 * FIXME: temporarily disable SharedWorker tests * use released version of node-abstractsocket * fix abstract-socket
2019-07-03 04:22:09 +03:00
const scheme = 'other';
const srcPath = path.join(fixtures, 'api');
before(() => {
protocol.handle(scheme, (req) => {
const reqURL = new URL(req.url);
return net.fetch(nodeUrl.pathToFileURL(path.join(srcPath, reqURL.pathname)).toString());
});
chore: bump chromium to f1d9522c04ca8fa0a906f88ababe9 (master) (#18648) * chore: bump chromium in DEPS to 675d7dc9f3334b15c3ec28c27db3dc19b26bd12e * chore: update patches * chore: bump chromium in DEPS to dce3562696f165a324273fcb6893f0e1fef42ab1 * chore: const interfaces are being removed from //content Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1631749 Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=908139 * chore: update patches * chore: blink::MediaStreamType is now consistent and deduplicated * chore: update patches and printing code for ref -> uniq * chore: bridge_impl() --> GetInProcessNSWindowBridge Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1642988 * fixme: TotalMarkedObjectSize has been removed * chore: fix linting * chore: bump chromium in DEPS to 9503e1a2fcbf17db08094d8caae3e1407e918af3 * chore: fix slightly broken printing patch * chore: update patches for SiteInstanceImpl changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1612025 * chore: update patches for SiteInstanceImpl changes * chore: bump chromium in DEPS to 6801e6c1ddd1b7b73e594e97157ddd539ca335d7 * chore: update patches * chore: bump chromium in DEPS to 27e198912d7c1767052ec785c22e2e88b2cb4d8b * chore: remove system_request_context Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1647172 * chore: creation of FtpProtocolHandler needs an auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639683 * fixme: disable marked spec * chore: bump chromium in DEPS to 3dcd7fe453ad13a22b114b95f05590eba74c5471 * chore: bump chromium in DEPS to bdc24128b75008743d819e298557a53205706e7c * chore: bump chromium in DEPS to 7da330b58fbe0ba94b9b94abbb8085bead220228 * update patches * remove TotalMarkedObjectSize https://chromium-review.googlesource.com/c/chromium/src/+/1631708 * add libvulkan.so to dist zip manifest on linux * chore: bump chromium in DEPS to 1e85d0f45b52649efd0010cc9dab6d2804f24443 * update patches * add angle features to gpuinfo https://chromium-review.googlesource.com/c/chromium/src/+/1638658 * mark 'marked' property as deprecated * disable webview resize test * FIXME: disable vulkan on 32-bit arm * chore: bump chromium in DEPS to cd0297c6a83fdd2b1f6bc312e7d5acca736a3c56 * Revert "FIXME: disable vulkan on 32-bit arm" This reverts commit 5c1e0ef302a6db1e72231d4e823f91bb08e281af. * backport from upstream: fix swiftshader build on arm https://swiftshader-review.googlesource.com/c/SwiftShader/+/32768/ * update patches * viz: update OutputDeviceWin to new shared memory api https://chromium-review.googlesource.com/c/chromium/src/+/1649574 * base::Contains{Key,Value} => base::Contains https://chromium-review.googlesource.com/c/chromium/src/+/1649478 * fixup! viz: update OutputDeviceWin to new shared memory api * stub out StatusIconLinuxDbus-related delegate methods https://chromium-review.googlesource.com/c/chromium/src/+/1638180 * chore: bump chromium in DEPS to 964ea3fd4bdc006d62533f5755043076220181f1 * Remove the BrowserContext methods to create URLRequestContexts for main/media partitions when a partition_domain is specified https://chromium-review.googlesource.com/c/chromium/src/+/1655087 * fixup! stub out StatusIconLinuxDbus-related delegate methods * add remote_cocoa to chromium_src deps https://chromium-review.googlesource.com/c/chromium/src/+/1657068 * fixup! stub out StatusIconLinuxDbus-related delegate methods * attempt at fix linux-debug build * add swiftshader/libvulkan.so to arm manifest * chore: bump chromium in DEPS to 28688f76afef27c36631aa274691e333ddecdc22 * update patches * chore: bump chromium in DEPS to fe7450e1578a9584189f87d59d0d1a8548bf6b90 * chore: bump chromium in DEPS to f304dfd682dc86a755a6c49a16ee6876e0db45fb * chore: bump chromium in DEPS to f0fd4d6c365aad9edd83bdfff9954c47d271b75c * Update patches * Remove no longer needed WOA patch * Put back IOThread in BrowserProcess We need this until we enable the network service. * move atom.ico to inputs * Update to latest LKGR to fix no template named 'bitset' in namespace 'std' * fixup! Put back IOThread in BrowserProcess * chore: bump chromium in DEPS to dcf9662dc9a896a175d791001350324167b1cad3 * Update patches content_allow_embedder_to_prevent_locking_scheme_registry.patch is no longer necessary as it was upstreamed via https://chromium-review.googlesource.com/c/chromium/src/+/1637040 * Fix renamed enum * Use newer docker container Contains updated dependencies * Try to track down arm test failures * Fix arm tests * chore: bump chromium in DEPS to 8cbceef57b37ee14b9c4c3405a3f7663922c5b5d * Update patches * Add needed dependencies for testing 32-bit linux * Remove arm debugging. * Remove additional debugging * Fix compiler errors * Handle new macOS helper * Fix compile error on Linux * chore: bump chromium in DEPS to 66a93991ddaff6a9f1b13d110959947cb03a1860 * Add new helper files to manifests * fix BUILD.gn for macOS * Fix compile errors * Add patch to put back colors needed for autofill/datalist * chore: bump chromium in DEPS to e89617079f11e33f33cdb3924f719a579c73704b * Updated patches * Remove no longer needed patch * Remove no longer needed patch * Fix compile error with patch * Really fix the patch * chore: bump chromium in DEPS to c70f12476a45840408f1d5ff5968e7f7ceaad9d4 * chore: bump chromium in DEPS to 06d2dd7a8933b41545a7c26349c802f570563fd5 * chore: bump chromium in DEPS to b0b9ff8f727deb519ccbec7cf1c8d9ed543d88ab * Update patches * Fix compiler errors * Fix removed ChromeNetLog * Revert "Fix removed ChromeNetLog" This reverts commit 426dfd90b5ab0a9c1df415d71c88e8aed2bd5bbe. * Remove ChromeNetLog. https://chromium-review.googlesource.com/c/chromium/src/+/1663846 * chore: bump chromium in DEPS to fefcc4926d58dccd59ac95be65eab3a4ebfe2f29 * Update patches * Update v8 patches * Fix lint error * Fix compile errors * chore: bump chromium in DEPS to 4de815ef92ef2eef515506fe09bdc466526a8fd9 * Use custom protocol to test baseURLForDataURL * Use newer SDK (10.0.18362) for Windows * Update patches * Update arm manifest since swiftshader reenabled. * Don't delete dir that isn't ever there. * Fix compile errors. * Need src dir created * Update for removed InspectorFrontendAPI.addExtensions * Revert "Use newer SDK (10.0.18362) for Windows" This reverts commit 68763a0c88cdc44b971462e49662aecc167d3d99. * Revert "Need src dir created" This reverts commit 7daedc29d0844316d4097648dde7f40f1a3848fb. * Revert "Don't delete dir that isn't ever there." This reverts commit bf424bc30ffcb23b1d9a634d4df410342536640e. * chore: bump chromium in DEPS to 97dab6b0124ea53244caf123921b5d14893bcca7 * chore: bump chromium in DEPS to c87d16d49a85dc7122781f6c979d354c20f7f78b * chore: bump chromium in DEPS to 004bcee2ea336687cedfda8f8a151806ac757d15 * chore: bump chromium in DEPS to 24428b26a9d15a013b2a253e1084ec3cb54b660b * chore: bump chromium in DEPS to fd25914e875237df88035a6abf89a70bf1360b57 * Update patches * Update node to fix build error * Fix compile errors * chore: bump chromium in DEPS to 3062b7cf090f1d9522c04ca8fa0a906f88ababe9 * chore: update node ref for pushed tags * chore: update patches for new chromium * chore: fix printing patches * Use new (10.0.18362) Windows SDK * roll node to fix v8 build issues in debug build * Add support for plugin helper * fix: add patch to fix gpu info enumeration Can be removed once CL lands upstream. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1685993 * spec: navigator.requestMIDIAccess now requires a secure origin This test requires a secure origin so we fake one. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1657952 * FIXME: temporarily disable SharedWorker tests * use released version of node-abstractsocket * fix abstract-socket
2019-07-03 04:22:09 +03:00
});
after(() => {
protocol.unhandle(scheme);
chore: bump chromium to f1d9522c04ca8fa0a906f88ababe9 (master) (#18648) * chore: bump chromium in DEPS to 675d7dc9f3334b15c3ec28c27db3dc19b26bd12e * chore: update patches * chore: bump chromium in DEPS to dce3562696f165a324273fcb6893f0e1fef42ab1 * chore: const interfaces are being removed from //content Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1631749 Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=908139 * chore: update patches * chore: blink::MediaStreamType is now consistent and deduplicated * chore: update patches and printing code for ref -> uniq * chore: bridge_impl() --> GetInProcessNSWindowBridge Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1642988 * fixme: TotalMarkedObjectSize has been removed * chore: fix linting * chore: bump chromium in DEPS to 9503e1a2fcbf17db08094d8caae3e1407e918af3 * chore: fix slightly broken printing patch * chore: update patches for SiteInstanceImpl changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1612025 * chore: update patches for SiteInstanceImpl changes * chore: bump chromium in DEPS to 6801e6c1ddd1b7b73e594e97157ddd539ca335d7 * chore: update patches * chore: bump chromium in DEPS to 27e198912d7c1767052ec785c22e2e88b2cb4d8b * chore: remove system_request_context Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1647172 * chore: creation of FtpProtocolHandler needs an auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639683 * fixme: disable marked spec * chore: bump chromium in DEPS to 3dcd7fe453ad13a22b114b95f05590eba74c5471 * chore: bump chromium in DEPS to bdc24128b75008743d819e298557a53205706e7c * chore: bump chromium in DEPS to 7da330b58fbe0ba94b9b94abbb8085bead220228 * update patches * remove TotalMarkedObjectSize https://chromium-review.googlesource.com/c/chromium/src/+/1631708 * add libvulkan.so to dist zip manifest on linux * chore: bump chromium in DEPS to 1e85d0f45b52649efd0010cc9dab6d2804f24443 * update patches * add angle features to gpuinfo https://chromium-review.googlesource.com/c/chromium/src/+/1638658 * mark 'marked' property as deprecated * disable webview resize test * FIXME: disable vulkan on 32-bit arm * chore: bump chromium in DEPS to cd0297c6a83fdd2b1f6bc312e7d5acca736a3c56 * Revert "FIXME: disable vulkan on 32-bit arm" This reverts commit 5c1e0ef302a6db1e72231d4e823f91bb08e281af. * backport from upstream: fix swiftshader build on arm https://swiftshader-review.googlesource.com/c/SwiftShader/+/32768/ * update patches * viz: update OutputDeviceWin to new shared memory api https://chromium-review.googlesource.com/c/chromium/src/+/1649574 * base::Contains{Key,Value} => base::Contains https://chromium-review.googlesource.com/c/chromium/src/+/1649478 * fixup! viz: update OutputDeviceWin to new shared memory api * stub out StatusIconLinuxDbus-related delegate methods https://chromium-review.googlesource.com/c/chromium/src/+/1638180 * chore: bump chromium in DEPS to 964ea3fd4bdc006d62533f5755043076220181f1 * Remove the BrowserContext methods to create URLRequestContexts for main/media partitions when a partition_domain is specified https://chromium-review.googlesource.com/c/chromium/src/+/1655087 * fixup! stub out StatusIconLinuxDbus-related delegate methods * add remote_cocoa to chromium_src deps https://chromium-review.googlesource.com/c/chromium/src/+/1657068 * fixup! stub out StatusIconLinuxDbus-related delegate methods * attempt at fix linux-debug build * add swiftshader/libvulkan.so to arm manifest * chore: bump chromium in DEPS to 28688f76afef27c36631aa274691e333ddecdc22 * update patches * chore: bump chromium in DEPS to fe7450e1578a9584189f87d59d0d1a8548bf6b90 * chore: bump chromium in DEPS to f304dfd682dc86a755a6c49a16ee6876e0db45fb * chore: bump chromium in DEPS to f0fd4d6c365aad9edd83bdfff9954c47d271b75c * Update patches * Remove no longer needed WOA patch * Put back IOThread in BrowserProcess We need this until we enable the network service. * move atom.ico to inputs * Update to latest LKGR to fix no template named 'bitset' in namespace 'std' * fixup! Put back IOThread in BrowserProcess * chore: bump chromium in DEPS to dcf9662dc9a896a175d791001350324167b1cad3 * Update patches content_allow_embedder_to_prevent_locking_scheme_registry.patch is no longer necessary as it was upstreamed via https://chromium-review.googlesource.com/c/chromium/src/+/1637040 * Fix renamed enum * Use newer docker container Contains updated dependencies * Try to track down arm test failures * Fix arm tests * chore: bump chromium in DEPS to 8cbceef57b37ee14b9c4c3405a3f7663922c5b5d * Update patches * Add needed dependencies for testing 32-bit linux * Remove arm debugging. * Remove additional debugging * Fix compiler errors * Handle new macOS helper * Fix compile error on Linux * chore: bump chromium in DEPS to 66a93991ddaff6a9f1b13d110959947cb03a1860 * Add new helper files to manifests * fix BUILD.gn for macOS * Fix compile errors * Add patch to put back colors needed for autofill/datalist * chore: bump chromium in DEPS to e89617079f11e33f33cdb3924f719a579c73704b * Updated patches * Remove no longer needed patch * Remove no longer needed patch * Fix compile error with patch * Really fix the patch * chore: bump chromium in DEPS to c70f12476a45840408f1d5ff5968e7f7ceaad9d4 * chore: bump chromium in DEPS to 06d2dd7a8933b41545a7c26349c802f570563fd5 * chore: bump chromium in DEPS to b0b9ff8f727deb519ccbec7cf1c8d9ed543d88ab * Update patches * Fix compiler errors * Fix removed ChromeNetLog * Revert "Fix removed ChromeNetLog" This reverts commit 426dfd90b5ab0a9c1df415d71c88e8aed2bd5bbe. * Remove ChromeNetLog. https://chromium-review.googlesource.com/c/chromium/src/+/1663846 * chore: bump chromium in DEPS to fefcc4926d58dccd59ac95be65eab3a4ebfe2f29 * Update patches * Update v8 patches * Fix lint error * Fix compile errors * chore: bump chromium in DEPS to 4de815ef92ef2eef515506fe09bdc466526a8fd9 * Use custom protocol to test baseURLForDataURL * Use newer SDK (10.0.18362) for Windows * Update patches * Update arm manifest since swiftshader reenabled. * Don't delete dir that isn't ever there. * Fix compile errors. * Need src dir created * Update for removed InspectorFrontendAPI.addExtensions * Revert "Use newer SDK (10.0.18362) for Windows" This reverts commit 68763a0c88cdc44b971462e49662aecc167d3d99. * Revert "Need src dir created" This reverts commit 7daedc29d0844316d4097648dde7f40f1a3848fb. * Revert "Don't delete dir that isn't ever there." This reverts commit bf424bc30ffcb23b1d9a634d4df410342536640e. * chore: bump chromium in DEPS to 97dab6b0124ea53244caf123921b5d14893bcca7 * chore: bump chromium in DEPS to c87d16d49a85dc7122781f6c979d354c20f7f78b * chore: bump chromium in DEPS to 004bcee2ea336687cedfda8f8a151806ac757d15 * chore: bump chromium in DEPS to 24428b26a9d15a013b2a253e1084ec3cb54b660b * chore: bump chromium in DEPS to fd25914e875237df88035a6abf89a70bf1360b57 * Update patches * Update node to fix build error * Fix compile errors * chore: bump chromium in DEPS to 3062b7cf090f1d9522c04ca8fa0a906f88ababe9 * chore: update node ref for pushed tags * chore: update patches for new chromium * chore: fix printing patches * Use new (10.0.18362) Windows SDK * roll node to fix v8 build issues in debug build * Add support for plugin helper * fix: add patch to fix gpu info enumeration Can be removed once CL lands upstream. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1685993 * spec: navigator.requestMIDIAccess now requires a secure origin This test requires a secure origin so we fake one. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1657952 * FIXME: temporarily disable SharedWorker tests * use released version of node-abstractsocket * fix abstract-socket
2019-07-03 04:22:09 +03:00
});
beforeEach(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
});
afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
let server: http.Server;
let url: string;
let postData = null as any;
before(async () => {
const filePath = path.join(fixtures, 'pages', 'a.html');
const fileStats = fs.statSync(filePath);
postData = [
{
type: 'rawData',
bytes: Buffer.from('username=test&file=')
},
{
type: 'file',
filePath,
offset: 0,
length: fileStats.size,
modificationTime: fileStats.mtime.getTime() / 1000
}
];
server = http.createServer((req, res) => {
function respond () {
if (req.method === 'POST') {
let body = '';
req.on('data', (data) => {
if (data) body += data;
});
req.on('end', () => {
const parsedData = qs.parse(body);
fs.readFile(filePath, (err, data) => {
if (err) return;
if (parsedData.username === 'test' &&
parsedData.file === data.toString()) {
res.end();
}
});
});
} else if (req.url === '/302') {
res.setHeader('Location', '/200');
res.statusCode = 302;
res.end();
} else {
res.end();
}
}
setTimeout(req.url && req.url.includes('slow') ? 200 : 0).then(respond);
});
url = (await listen(server)).url;
});
after(() => {
server.close();
});
it('should emit did-start-loading event', async () => {
const didStartLoading = once(w.webContents, 'did-start-loading');
w.loadURL('about:blank');
await didStartLoading;
});
it('should emit ready-to-show event', async () => {
const readyToShow = once(w, 'ready-to-show');
w.loadURL('about:blank');
await readyToShow;
});
// DISABLED-FIXME(deepak1556): The error code now seems to be `ERR_FAILED`, verify what
// changed and adjust the test.
it('should emit did-fail-load event for files that do not exist', async () => {
const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadURL('file://a.txt');
const [, code, desc, , isMainFrame] = await didFailLoad;
expect(code).to.equal(-6);
expect(desc).to.equal('ERR_FILE_NOT_FOUND');
expect(isMainFrame).to.equal(true);
});
it('should emit did-fail-load event for invalid URL', async () => {
const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadURL('http://example:port');
const [, code, desc, , isMainFrame] = await didFailLoad;
expect(desc).to.equal('ERR_INVALID_URL');
expect(code).to.equal(-300);
expect(isMainFrame).to.equal(true);
});
it('should not emit did-fail-load for a successfully loaded media file', async () => {
w.webContents.on('did-fail-load', () => {
expect.fail('did-fail-load should not emit on media file loads');
});
const mediaStarted = once(w.webContents, 'media-started-playing');
w.loadFile(path.join(fixtures, 'cat-spin.mp4'));
await mediaStarted;
});
it('should set `mainFrame = false` on did-fail-load events in iframes', async () => {
const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadFile(path.join(fixtures, 'api', 'did-fail-load-iframe.html'));
const [, , , , isMainFrame] = await didFailLoad;
expect(isMainFrame).to.equal(false);
});
it('does not crash in did-fail-provisional-load handler', (done) => {
w.webContents.once('did-fail-provisional-load', () => {
w.loadURL('http://127.0.0.1:11111');
done();
});
w.loadURL('http://127.0.0.1:11111');
});
it('should emit did-fail-load event for URL exceeding character limit', async () => {
const data = Buffer.alloc(2 * 1024 * 1024).toString('base64');
const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadURL(`data:image/png;base64,${data}`);
const [, code, desc, , isMainFrame] = await didFailLoad;
expect(desc).to.equal('ERR_INVALID_URL');
expect(code).to.equal(-300);
expect(isMainFrame).to.equal(true);
});
it('should return a promise', () => {
const p = w.loadURL('about:blank');
expect(p).to.have.property('then');
});
it('should return a promise that resolves', async () => {
await expect(w.loadURL('about:blank')).to.eventually.be.fulfilled();
});
it('should return a promise that rejects on a load failure', async () => {
const data = Buffer.alloc(2 * 1024 * 1024).toString('base64');
const p = w.loadURL(`data:image/png;base64,${data}`);
await expect(p).to.eventually.be.rejected;
});
it('should return a promise that resolves even if pushState occurs during navigation', async () => {
const p = w.loadURL('data:text/html,<script>window.history.pushState({}, "/foo")</script>');
await expect(p).to.eventually.be.fulfilled;
});
describe('POST navigations', () => {
afterEach(() => { w.webContents.session.webRequest.onBeforeSendHeaders(null); });
it('supports specifying POST data', async () => {
await w.loadURL(url, { postData });
});
it('sets the content type header on URL encoded forms', async () => {
await w.loadURL(url);
const requestDetails: Promise<OnBeforeSendHeadersListenerDetails> = new Promise(resolve => {
2019-11-01 23:37:02 +03:00
w.webContents.session.webRequest.onBeforeSendHeaders((details) => {
resolve(details);
});
});
w.webContents.executeJavaScript(`
form = document.createElement('form')
document.body.appendChild(form)
form.method = 'POST'
form.submit()
`);
const details = await requestDetails;
expect(details.requestHeaders['Content-Type']).to.equal('application/x-www-form-urlencoded');
});
it('sets the content type header on multi part forms', async () => {
await w.loadURL(url);
const requestDetails: Promise<OnBeforeSendHeadersListenerDetails> = new Promise(resolve => {
2019-11-01 23:37:02 +03:00
w.webContents.session.webRequest.onBeforeSendHeaders((details) => {
resolve(details);
});
});
w.webContents.executeJavaScript(`
form = document.createElement('form')
document.body.appendChild(form)
form.method = 'POST'
form.enctype = 'multipart/form-data'
file = document.createElement('input')
file.type = 'file'
file.name = 'file'
form.appendChild(file)
form.submit()
`);
const details = await requestDetails;
expect(details.requestHeaders['Content-Type'].startsWith('multipart/form-data; boundary=----WebKitFormBoundary')).to.equal(true);
});
});
chore: bump chromium to 130.0.6695.0 (main) (#43454) * chore: bump chromium in DEPS to 130.0.6673.0 * chore: bump chromium in DEPS to 130.0.6675.0 * chore: bump chromium in DEPS to 130.0.6677.2 * chore: bump chromium in DEPS to 130.0.6679.0 * 5802981: [Partitioned Popins] UKM https://chromium-review.googlesource.com/c/chromium/src/+/5802981 * 5799275: ash: Create //chrome/browser/ui/ash/web_view https://chromium-review.googlesource.com/c/chromium/src/+/5799275 * 5791853: [PWA] Allow WebContentsImpl::CreateNewWindow() to use new web contents for loading url https://chromium-review.googlesource.com/c/chromium/src/+/5791853 * 5805208: Move third_party/jacoco to a cipd/ subdirectory. https://chromium-review.googlesource.com/c/chromium/src/+/5805208 * chore: fixup patch indices * 5771091: Introduce InputManager class for handling input in Viz. https://chromium-review.googlesource.com/c/chromium/src/+/5771091 * 5498921: [Permission] Remove SubscribeToPermissionStatusChange from PermissionManager https://chromium-review.googlesource.com/c/chromium/src/+/5498921 * 5791853: [PWA] Allow WebContentsImpl::CreateNewWindow() to use new web contents for loading url https://chromium-review.googlesource.com/c/chromium/src/+/5791853 * 5801311: Don't use int for bindings https://chromium-review.googlesource.com/c/chromium/src/+/5801311 * 5548827: [Web Install] Define the web-app-installation PermissionPolicy https://chromium-review.googlesource.com/c/chromium/src/+/5548827 * 5786325: Add Infrastructure for Hand tracking permission https://chromium-review.googlesource.com/c/chromium/src/+/5786325 * chore: fixup patch indices * chore: bump chromium in DEPS to 130.0.6681.0 * [Views AX] Move BrowserAccessibility* to //ui/accessibility/platform Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5520052 * chore: e patches all * Don't have default arguments on virtual functions in render_frame_host.h https://chromium-review.googlesource.com/c/chromium/src/+/5809399 * test: log if loadURL fails in base url test * chore: bump chromium in DEPS to 130.0.6683.2 * chore: fix support_mixed_sandbox_with_zygote.patch content: restore old DisableJit behavior https://chromium-review.googlesource.com/c/chromium/src/+/5804255 * chore: update patch indices * chore: bump chromium in DEPS to 130.0.6685.0 * Parallel process launching Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5015584 * chore: update feat_expose_documentloader_setdefersloading_on_webdocumentloader.patch No manual changes; patch applied with fuzz 1 * chore: e patches all * chore: bump chromium in DEPS to 130.0.6687.0 * chore: bump chromium in DEPS to 130.0.6689.0 * chore: bump chromium in DEPS to 130.0.6691.0 * chore: bump chromium in DEPS to 130.0.6693.0 * chore: update patches * chore: bump chromium in DEPS to 130.0.6695.0 * chore: free up macos disk space as soon as possible * 5824143: Use checked in source lists for third_party/boringssl https://chromium-review.googlesource.com/c/chromium/src/+/5824143 * chore: update patches * 5824122: Extensions: Add a new view type enum for developer tools contexts https://chromium-review.googlesource.com/c/chromium/src/+/5824122 * 5806109: Option for JavaScriptExecuteRequestForTests() to ignore content settings https://chromium-review.googlesource.com/c/chromium/src/+/5806109 * build: free up disk space on gn check too * 5799369: [Refactoring] Make allow_http1_for_streaming_upload flags false. https://chromium-review.googlesource.com/c/chromium/src/+/5799369 * fixup! 5015584: Parallel process launching | https://chromium-review.googlesource.com/c/chromium/src/+/5015584 * Disable failing test for short-term See: https://github.com/electron/electron/issues/43730 * oops --------- 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: Charles Kerr <charles@charleskerr.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: clavin <clavin@electronjs.org>
2024-09-18 04:12:11 +03:00
// FIXME(#43730): fix underlying bug and re-enable asap
it.skip('should support base url for data urls', async () => {
await w
.loadURL('data:text/html,<script src="loaded-from-dataurl.js"></script>', { baseURLForDataURL: 'other://' })
chore: bump chromium to 130.0.6695.0 (main) (#43454) * chore: bump chromium in DEPS to 130.0.6673.0 * chore: bump chromium in DEPS to 130.0.6675.0 * chore: bump chromium in DEPS to 130.0.6677.2 * chore: bump chromium in DEPS to 130.0.6679.0 * 5802981: [Partitioned Popins] UKM https://chromium-review.googlesource.com/c/chromium/src/+/5802981 * 5799275: ash: Create //chrome/browser/ui/ash/web_view https://chromium-review.googlesource.com/c/chromium/src/+/5799275 * 5791853: [PWA] Allow WebContentsImpl::CreateNewWindow() to use new web contents for loading url https://chromium-review.googlesource.com/c/chromium/src/+/5791853 * 5805208: Move third_party/jacoco to a cipd/ subdirectory. https://chromium-review.googlesource.com/c/chromium/src/+/5805208 * chore: fixup patch indices * 5771091: Introduce InputManager class for handling input in Viz. https://chromium-review.googlesource.com/c/chromium/src/+/5771091 * 5498921: [Permission] Remove SubscribeToPermissionStatusChange from PermissionManager https://chromium-review.googlesource.com/c/chromium/src/+/5498921 * 5791853: [PWA] Allow WebContentsImpl::CreateNewWindow() to use new web contents for loading url https://chromium-review.googlesource.com/c/chromium/src/+/5791853 * 5801311: Don't use int for bindings https://chromium-review.googlesource.com/c/chromium/src/+/5801311 * 5548827: [Web Install] Define the web-app-installation PermissionPolicy https://chromium-review.googlesource.com/c/chromium/src/+/5548827 * 5786325: Add Infrastructure for Hand tracking permission https://chromium-review.googlesource.com/c/chromium/src/+/5786325 * chore: fixup patch indices * chore: bump chromium in DEPS to 130.0.6681.0 * [Views AX] Move BrowserAccessibility* to //ui/accessibility/platform Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5520052 * chore: e patches all * Don't have default arguments on virtual functions in render_frame_host.h https://chromium-review.googlesource.com/c/chromium/src/+/5809399 * test: log if loadURL fails in base url test * chore: bump chromium in DEPS to 130.0.6683.2 * chore: fix support_mixed_sandbox_with_zygote.patch content: restore old DisableJit behavior https://chromium-review.googlesource.com/c/chromium/src/+/5804255 * chore: update patch indices * chore: bump chromium in DEPS to 130.0.6685.0 * Parallel process launching Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5015584 * chore: update feat_expose_documentloader_setdefersloading_on_webdocumentloader.patch No manual changes; patch applied with fuzz 1 * chore: e patches all * chore: bump chromium in DEPS to 130.0.6687.0 * chore: bump chromium in DEPS to 130.0.6689.0 * chore: bump chromium in DEPS to 130.0.6691.0 * chore: bump chromium in DEPS to 130.0.6693.0 * chore: update patches * chore: bump chromium in DEPS to 130.0.6695.0 * chore: free up macos disk space as soon as possible * 5824143: Use checked in source lists for third_party/boringssl https://chromium-review.googlesource.com/c/chromium/src/+/5824143 * chore: update patches * 5824122: Extensions: Add a new view type enum for developer tools contexts https://chromium-review.googlesource.com/c/chromium/src/+/5824122 * 5806109: Option for JavaScriptExecuteRequestForTests() to ignore content settings https://chromium-review.googlesource.com/c/chromium/src/+/5806109 * build: free up disk space on gn check too * 5799369: [Refactoring] Make allow_http1_for_streaming_upload flags false. https://chromium-review.googlesource.com/c/chromium/src/+/5799369 * fixup! 5015584: Parallel process launching | https://chromium-review.googlesource.com/c/chromium/src/+/5015584 * Disable failing test for short-term See: https://github.com/electron/electron/issues/43730 * oops --------- 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: Charles Kerr <charles@charleskerr.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: clavin <clavin@electronjs.org>
2024-09-18 04:12:11 +03:00
.catch((e) => console.log(e));
expect(await w.webContents.executeJavaScript('window.ping')).to.equal('pong');
});
});
for (const sandbox of [false, true]) {
describe(`navigation events${sandbox ? ' with sandbox' : ''}`, () => {
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: false, sandbox } });
});
afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
describe('will-navigate event', () => {
let server: http.Server;
let url: string;
before(async () => {
server = http.createServer((req, res) => {
if (req.url === '/navigate-top') {
res.end('<a target=_top href="/">navigate _top</a>');
} else {
res.end('');
}
});
url = (await listen(server)).url;
});
after(() => {
server.close();
});
it('allows the window to be closed from the event listener', async () => {
const event = once(w.webContents, 'will-navigate');
w.loadFile(path.join(fixtures, 'pages', 'will-navigate.html'));
await event;
w.close();
});
it('can be prevented', (done) => {
let willNavigate = false;
w.webContents.once('will-navigate', (e) => {
willNavigate = true;
e.preventDefault();
});
w.webContents.on('did-stop-loading', () => {
if (willNavigate) {
// i.e. it shouldn't have had '?navigated' appended to it.
try {
expect(w.webContents.getURL().endsWith('will-navigate.html')).to.be.true();
done();
} catch (e) {
done(e);
}
}
});
w.loadFile(path.join(fixtures, 'pages', 'will-navigate.html'));
});
it('is triggered when navigating from file: to http:', async () => {
await w.loadFile(path.join(fixtures, 'api', 'blank.html'));
w.webContents.executeJavaScript(`location.href = ${JSON.stringify(url)}`);
const navigatedTo = await new Promise(resolve => {
w.webContents.once('will-navigate', (e, url) => {
e.preventDefault();
resolve(url);
});
});
expect(navigatedTo).to.equal(url + '/');
expect(w.webContents.getURL()).to.match(/^file:/);
});
it('is triggered when navigating from about:blank to http:', async () => {
await w.loadURL('about:blank');
w.webContents.executeJavaScript(`location.href = ${JSON.stringify(url)}`);
const navigatedTo = await new Promise(resolve => {
w.webContents.once('will-navigate', (e, url) => {
e.preventDefault();
resolve(url);
});
});
expect(navigatedTo).to.equal(url + '/');
expect(w.webContents.getURL()).to.equal('about:blank');
});
it('is triggered when a cross-origin iframe navigates _top', async () => {
w.loadURL(`data:text/html,<iframe src="http://127.0.0.1:${(server.address() as AddressInfo).port}/navigate-top"></iframe>`);
await emittedUntil(w.webContents, 'did-frame-finish-load', (e: any, isMainFrame: boolean) => !isMainFrame);
let initiator: WebFrameMain | null | undefined;
w.webContents.on('will-navigate', (e) => {
initiator = e.initiator;
});
const subframe = w.webContents.mainFrame.frames[0];
subframe.executeJavaScript('document.getElementsByTagName("a")[0].click()', true);
await once(w.webContents, 'did-navigate');
expect(initiator).not.to.be.undefined();
expect(initiator).to.equal(subframe);
});
it('is triggered when navigating from chrome: to http:', async () => {
let hasEmittedWillNavigate = false;
const willNavigatePromise = new Promise((resolve) => {
w.webContents.once('will-navigate', e => {
e.preventDefault();
hasEmittedWillNavigate = true;
resolve(e.url);
});
});
await w.loadURL('chrome://gpu');
// shouldn't emit for browser-initiated request via loadURL
expect(hasEmittedWillNavigate).to.equal(false);
w.webContents.executeJavaScript(`location.href = ${JSON.stringify(url)}`);
const navigatedTo = await willNavigatePromise;
expect(navigatedTo).to.equal(url + '/');
expect(w.webContents.getURL()).to.equal('chrome://gpu/');
});
});
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 17:55:41 +03:00
describe('will-frame-navigate event', () => {
let server = null as unknown as http.Server;
let url = null as unknown as string;
before(async () => {
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 17:55:41 +03:00
server = http.createServer((req, res) => {
if (req.url === '/navigate-top') {
res.end('<a target=_top href="/">navigate _top</a>');
} else if (req.url === '/navigate-iframe') {
res.end('<a href="/test">navigate iframe</a>');
} else if (req.url === '/navigate-iframe?navigated') {
res.end('Successfully navigated');
} else if (req.url === '/navigate-iframe-immediately') {
res.end(`
<script type="text/javascript" charset="utf-8">
location.href += '?navigated'
</script>
`);
} else if (req.url === '/navigate-iframe-immediately?navigated') {
res.end('Successfully navigated');
} else {
res.end('');
}
});
url = (await listen(server)).url;
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 17:55:41 +03:00
});
after(() => {
server.close();
});
it('allows the window to be closed from the event listener', (done) => {
w.webContents.once('will-frame-navigate', () => {
w.close();
done();
});
w.loadFile(path.join(fixtures, 'pages', 'will-navigate.html'));
});
it('can be prevented', (done) => {
let willNavigate = false;
w.webContents.once('will-frame-navigate', (e) => {
willNavigate = true;
e.preventDefault();
});
w.webContents.on('did-stop-loading', () => {
if (willNavigate) {
// i.e. it shouldn't have had '?navigated' appended to it.
try {
expect(w.webContents.getURL().endsWith('will-navigate.html')).to.be.true();
done();
} catch (e) {
done(e);
}
}
});
w.loadFile(path.join(fixtures, 'pages', 'will-navigate.html'));
});
it('can be prevented when navigating subframe', (done) => {
let willNavigate = false;
w.webContents.on('did-frame-navigate', (_event, _url, _httpResponseCode, _httpStatusText, isMainFrame, frameProcessId, frameRoutingId) => {
if (isMainFrame) return;
w.webContents.once('will-frame-navigate', (e) => {
willNavigate = true;
e.preventDefault();
});
w.webContents.on('did-stop-loading', () => {
const frame = webFrameMain.fromId(frameProcessId, frameRoutingId);
expect(frame).to.not.be.undefined();
if (willNavigate) {
// i.e. it shouldn't have had '?navigated' appended to it.
try {
expect(frame!.url.endsWith('/navigate-iframe-immediately')).to.be.true();
done();
} catch (e) {
done(e);
}
}
});
});
w.loadURL(`data:text/html,<iframe src="http://127.0.0.1:${(server.address() as AddressInfo).port}/navigate-iframe-immediately"></iframe>`);
});
it('is triggered when navigating from file: to http:', async () => {
await w.loadFile(path.join(fixtures, 'api', 'blank.html'));
w.webContents.executeJavaScript(`location.href = ${JSON.stringify(url)}`);
const navigatedTo = await new Promise(resolve => {
w.webContents.once('will-frame-navigate', (e) => {
e.preventDefault();
resolve(e.url);
});
});
expect(navigatedTo).to.equal(url + '/');
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 17:55:41 +03:00
expect(w.webContents.getURL()).to.match(/^file:/);
});
it('is triggered when navigating from about:blank to http:', async () => {
await w.loadURL('about:blank');
w.webContents.executeJavaScript(`location.href = ${JSON.stringify(url)}`);
const navigatedTo = await new Promise(resolve => {
w.webContents.once('will-frame-navigate', (e) => {
e.preventDefault();
resolve(e.url);
});
});
expect(navigatedTo).to.equal(url + '/');
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 17:55:41 +03:00
expect(w.webContents.getURL()).to.equal('about:blank');
});
it('is triggered when a cross-origin iframe navigates _top', async () => {
await w.loadURL(`data:text/html,<iframe src="http://127.0.0.1:${(server.address() as AddressInfo).port}/navigate-top"></iframe>`);
await setTimeout(1000);
let willFrameNavigateEmitted = false;
let isMainFrameValue;
w.webContents.on('will-frame-navigate', (event) => {
willFrameNavigateEmitted = true;
isMainFrameValue = event.isMainFrame;
});
const didNavigatePromise = once(w.webContents, 'did-navigate');
w.webContents.debugger.attach('1.1');
const targets = await w.webContents.debugger.sendCommand('Target.getTargets');
const iframeTarget = targets.targetInfos.find((t: any) => t.type === 'iframe');
const { sessionId } = await w.webContents.debugger.sendCommand('Target.attachToTarget', {
targetId: iframeTarget.targetId,
flatten: true
});
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mousePressed',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mouseReleased',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await didNavigatePromise;
expect(willFrameNavigateEmitted).to.be.true();
expect(isMainFrameValue).to.be.true();
});
it('is triggered when a cross-origin iframe navigates itself', async () => {
await w.loadURL(`data:text/html,<iframe src="http://127.0.0.1:${(server.address() as AddressInfo).port}/navigate-iframe"></iframe>`);
await setTimeout(1000);
let willNavigateEmitted = false;
let isMainFrameValue;
w.webContents.on('will-frame-navigate', (event) => {
willNavigateEmitted = true;
isMainFrameValue = event.isMainFrame;
});
const didNavigatePromise = once(w.webContents, 'did-frame-navigate');
w.webContents.debugger.attach('1.1');
const targets = await w.webContents.debugger.sendCommand('Target.getTargets');
const iframeTarget = targets.targetInfos.find((t: any) => t.type === 'iframe');
const { sessionId } = await w.webContents.debugger.sendCommand('Target.attachToTarget', {
targetId: iframeTarget.targetId,
flatten: true
});
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mousePressed',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mouseReleased',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await didNavigatePromise;
expect(willNavigateEmitted).to.be.true();
expect(isMainFrameValue).to.be.false();
});
it('can cancel when a cross-origin iframe navigates itself', async () => {
});
});
describe('will-redirect event', () => {
let server: http.Server;
let url: string;
before(async () => {
server = http.createServer((req, res) => {
if (req.url === '/302') {
res.setHeader('Location', '/200');
res.statusCode = 302;
res.end();
} else if (req.url === '/navigate-302') {
res.end(`<html><body><script>window.location='${url}/302'</script></body></html>`);
} else {
res.end();
}
});
url = (await listen(server)).url;
});
after(() => {
server.close();
});
it('is emitted on redirects', async () => {
const willRedirect = once(w.webContents, 'will-redirect');
w.loadURL(`${url}/302`);
await willRedirect;
});
it('is emitted after will-navigate on redirects', async () => {
let navigateCalled = false;
w.webContents.on('will-navigate', () => {
navigateCalled = true;
});
const willRedirect = once(w.webContents, 'will-redirect');
w.loadURL(`${url}/navigate-302`);
await willRedirect;
expect(navigateCalled).to.equal(true, 'should have called will-navigate first');
});
it('is emitted before did-stop-loading on redirects', async () => {
let stopCalled = false;
w.webContents.on('did-stop-loading', () => {
stopCalled = true;
});
const willRedirect = once(w.webContents, 'will-redirect');
w.loadURL(`${url}/302`);
await willRedirect;
expect(stopCalled).to.equal(false, 'should not have called did-stop-loading first');
});
it('allows the window to be closed from the event listener', async () => {
const event = once(w.webContents, 'will-redirect');
w.loadURL(`${url}/302`);
await event;
w.close();
});
it('can be prevented', (done) => {
w.webContents.once('will-redirect', (event) => {
event.preventDefault();
});
w.webContents.on('will-navigate', (e, u) => {
expect(u).to.equal(`${url}/302`);
});
w.webContents.on('did-stop-loading', () => {
try {
expect(w.webContents.getURL()).to.equal(
`${url}/navigate-302`,
'url should not have changed after navigation event'
);
done();
} catch (e) {
done(e);
}
});
w.webContents.on('will-redirect', (e, u) => {
try {
expect(u).to.equal(`${url}/200`);
} catch (e) {
done(e);
}
});
w.loadURL(`${url}/navigate-302`);
});
});
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 17:55:41 +03:00
describe('ordering', () => {
let server = null as unknown as http.Server;
let url = null as unknown as string;
const navigationEvents = [
'did-start-navigation',
'did-navigate-in-page',
'will-frame-navigate',
'will-navigate',
'will-redirect',
'did-redirect-navigation',
'did-frame-navigate',
'did-navigate'
];
before(async () => {
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 17:55:41 +03:00
server = http.createServer((req, res) => {
if (req.url === '/navigate') {
res.end('<a href="/">navigate</a>');
} else if (req.url === '/redirect') {
res.end('<a href="/redirect2">redirect</a>');
} else if (req.url === '/redirect2') {
res.statusCode = 302;
res.setHeader('location', url);
res.end();
} else if (req.url === '/in-page') {
res.end('<a href="#in-page">redirect</a><div id="in-page"></div>');
} else {
res.end('');
}
});
url = (await listen(server)).url;
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 17:55:41 +03:00
});
it('for initial navigation, event order is consistent', async () => {
const firedEvents: string[] = [];
const expectedEventOrder = [
'did-start-navigation',
'did-frame-navigate',
'did-navigate'
];
const allEvents = Promise.all(expectedEventOrder.map(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 17:55:41 +03:00
once(w.webContents, event).then(() => firedEvents.push(event))
));
w.loadURL(url);
await allEvents;
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 17:55:41 +03:00
expect(firedEvents).to.deep.equal(expectedEventOrder);
});
it('for second navigation, event order is consistent', async () => {
const firedEvents: string[] = [];
const expectedEventOrder = [
'did-start-navigation',
'will-frame-navigate',
'will-navigate',
'did-frame-navigate',
'did-navigate'
];
w.loadURL(url + '/navigate');
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 17:55:41 +03:00
await once(w.webContents, 'did-navigate');
chore: bump chromium to 116.0.5817.0 (main) (#38465) * chore: bump chromium in DEPS to 116.0.5793.3 * chore: update patches * chore: bump chromium in DEPS to 116.0.5795.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5797.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5799.0 * 4522192: [serial] Allow Bluetooth ports to be requested by service class ID. | https://chromium-review.googlesource.com/c/chromium/src/+/4522192 * 4545385: Create base::apple::Owned[frameworktype], use it for gfx::NativeEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4545385 * chore: bump chromium in DEPS to 116.0.5801.0 * chore: update patches * 4562796: Use base::apple::Owned[frameworktype] for ui::PlatformEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4562796 * 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 * chore: bump chromium in DEPS to 116.0.5803.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5805.2 * chore: update patches * 4547630: Move content/public/common/network_service_util.h to c/p/browser/ | https://chromium-review.googlesource.com/c/chromium/src/+/4547630 * 4510075: Adding extensions to network response experiment | https://chromium-review.googlesource.com/c/chromium/src/+/4510075 * 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: bump chromium in DEPS to 116.0.5807.0 * chore: update patches * 4533536: [Privacy Hub] Geolocation manager used directly | https://chromium-review.googlesource.com/c/chromium/src/+/4533536 * chore: patch out ARC support from /chrome/browser 4571955: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4571955 * chore: bump chromium in DEPS to 116.0.5809.2 * chore: bump chromium in DEPS to 116.0.5811.0 * chore: update patches * 4573627: Adopt base::NoDestructor for KeyedService factories | https://chromium-review.googlesource.com/c/chromium/src/+/4573627 * 4576878: Reland "Shared Storage: Add mojo method for observing response headers" | https://chromium-review.googlesource.com/c/chromium/src/+/4576878 * chore: bump chromium in DEPS to 116.0.5813.0 * chore: update patches * fixup! 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: fix up lint * test: (debug) use Promise.all in asan tests * chore: manually roll DEPS to 116.0.5815.0 * chore: update patches * 4585150: Convert /printing to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4585150 * test: (asan) extend timeout, clean up debugging * chore: remove ARC chromium patch * chore: update patches after main sync * 4546398: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4546398 * build: add chrome_lib_arc for chromium_src/BUILD.gn sources * fixup! 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
2023-06-10 02:08:36 +03:00
await setTimeout(2000);
Promise.all(navigationEvents.map(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 17:55:41 +03:00
once(w.webContents, event).then(() => firedEvents.push(event))
chore: bump chromium to 116.0.5817.0 (main) (#38465) * chore: bump chromium in DEPS to 116.0.5793.3 * chore: update patches * chore: bump chromium in DEPS to 116.0.5795.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5797.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5799.0 * 4522192: [serial] Allow Bluetooth ports to be requested by service class ID. | https://chromium-review.googlesource.com/c/chromium/src/+/4522192 * 4545385: Create base::apple::Owned[frameworktype], use it for gfx::NativeEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4545385 * chore: bump chromium in DEPS to 116.0.5801.0 * chore: update patches * 4562796: Use base::apple::Owned[frameworktype] for ui::PlatformEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4562796 * 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 * chore: bump chromium in DEPS to 116.0.5803.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5805.2 * chore: update patches * 4547630: Move content/public/common/network_service_util.h to c/p/browser/ | https://chromium-review.googlesource.com/c/chromium/src/+/4547630 * 4510075: Adding extensions to network response experiment | https://chromium-review.googlesource.com/c/chromium/src/+/4510075 * 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: bump chromium in DEPS to 116.0.5807.0 * chore: update patches * 4533536: [Privacy Hub] Geolocation manager used directly | https://chromium-review.googlesource.com/c/chromium/src/+/4533536 * chore: patch out ARC support from /chrome/browser 4571955: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4571955 * chore: bump chromium in DEPS to 116.0.5809.2 * chore: bump chromium in DEPS to 116.0.5811.0 * chore: update patches * 4573627: Adopt base::NoDestructor for KeyedService factories | https://chromium-review.googlesource.com/c/chromium/src/+/4573627 * 4576878: Reland "Shared Storage: Add mojo method for observing response headers" | https://chromium-review.googlesource.com/c/chromium/src/+/4576878 * chore: bump chromium in DEPS to 116.0.5813.0 * chore: update patches * fixup! 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: fix up lint * test: (debug) use Promise.all in asan tests * chore: manually roll DEPS to 116.0.5815.0 * chore: update patches * 4585150: Convert /printing to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4585150 * test: (asan) extend timeout, clean up debugging * chore: remove ARC chromium patch * chore: update patches after main sync * 4546398: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4546398 * build: add chrome_lib_arc for chromium_src/BUILD.gn sources * fixup! 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
2023-06-10 02:08:36 +03:00
));
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 17:55:41 +03:00
const navigationFinished = once(w.webContents, 'did-navigate');
w.webContents.debugger.attach('1.1');
const targets = await w.webContents.debugger.sendCommand('Target.getTargets');
const pageTarget = targets.targetInfos.find((t: any) => t.type === 'page');
const { sessionId } = await w.webContents.debugger.sendCommand('Target.attachToTarget', {
targetId: pageTarget.targetId,
flatten: true
});
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mousePressed',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mouseReleased',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await navigationFinished;
expect(firedEvents).to.deep.equal(expectedEventOrder);
});
it('when navigating with redirection, event order is consistent', async () => {
const firedEvents: string[] = [];
const expectedEventOrder = [
'did-start-navigation',
'will-frame-navigate',
'will-navigate',
'will-redirect',
'did-redirect-navigation',
'did-frame-navigate',
'did-navigate'
];
w.loadURL(url + '/redirect');
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 17:55:41 +03:00
await once(w.webContents, 'did-navigate');
chore: bump chromium to 116.0.5817.0 (main) (#38465) * chore: bump chromium in DEPS to 116.0.5793.3 * chore: update patches * chore: bump chromium in DEPS to 116.0.5795.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5797.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5799.0 * 4522192: [serial] Allow Bluetooth ports to be requested by service class ID. | https://chromium-review.googlesource.com/c/chromium/src/+/4522192 * 4545385: Create base::apple::Owned[frameworktype], use it for gfx::NativeEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4545385 * chore: bump chromium in DEPS to 116.0.5801.0 * chore: update patches * 4562796: Use base::apple::Owned[frameworktype] for ui::PlatformEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4562796 * 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 * chore: bump chromium in DEPS to 116.0.5803.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5805.2 * chore: update patches * 4547630: Move content/public/common/network_service_util.h to c/p/browser/ | https://chromium-review.googlesource.com/c/chromium/src/+/4547630 * 4510075: Adding extensions to network response experiment | https://chromium-review.googlesource.com/c/chromium/src/+/4510075 * 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: bump chromium in DEPS to 116.0.5807.0 * chore: update patches * 4533536: [Privacy Hub] Geolocation manager used directly | https://chromium-review.googlesource.com/c/chromium/src/+/4533536 * chore: patch out ARC support from /chrome/browser 4571955: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4571955 * chore: bump chromium in DEPS to 116.0.5809.2 * chore: bump chromium in DEPS to 116.0.5811.0 * chore: update patches * 4573627: Adopt base::NoDestructor for KeyedService factories | https://chromium-review.googlesource.com/c/chromium/src/+/4573627 * 4576878: Reland "Shared Storage: Add mojo method for observing response headers" | https://chromium-review.googlesource.com/c/chromium/src/+/4576878 * chore: bump chromium in DEPS to 116.0.5813.0 * chore: update patches * fixup! 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: fix up lint * test: (debug) use Promise.all in asan tests * chore: manually roll DEPS to 116.0.5815.0 * chore: update patches * 4585150: Convert /printing to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4585150 * test: (asan) extend timeout, clean up debugging * chore: remove ARC chromium patch * chore: update patches after main sync * 4546398: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4546398 * build: add chrome_lib_arc for chromium_src/BUILD.gn sources * fixup! 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
2023-06-10 02:08:36 +03:00
await setTimeout(2000);
Promise.all(navigationEvents.map(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 17:55:41 +03:00
once(w.webContents, event).then(() => firedEvents.push(event))
chore: bump chromium to 116.0.5817.0 (main) (#38465) * chore: bump chromium in DEPS to 116.0.5793.3 * chore: update patches * chore: bump chromium in DEPS to 116.0.5795.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5797.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5799.0 * 4522192: [serial] Allow Bluetooth ports to be requested by service class ID. | https://chromium-review.googlesource.com/c/chromium/src/+/4522192 * 4545385: Create base::apple::Owned[frameworktype], use it for gfx::NativeEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4545385 * chore: bump chromium in DEPS to 116.0.5801.0 * chore: update patches * 4562796: Use base::apple::Owned[frameworktype] for ui::PlatformEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4562796 * 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 * chore: bump chromium in DEPS to 116.0.5803.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5805.2 * chore: update patches * 4547630: Move content/public/common/network_service_util.h to c/p/browser/ | https://chromium-review.googlesource.com/c/chromium/src/+/4547630 * 4510075: Adding extensions to network response experiment | https://chromium-review.googlesource.com/c/chromium/src/+/4510075 * 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: bump chromium in DEPS to 116.0.5807.0 * chore: update patches * 4533536: [Privacy Hub] Geolocation manager used directly | https://chromium-review.googlesource.com/c/chromium/src/+/4533536 * chore: patch out ARC support from /chrome/browser 4571955: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4571955 * chore: bump chromium in DEPS to 116.0.5809.2 * chore: bump chromium in DEPS to 116.0.5811.0 * chore: update patches * 4573627: Adopt base::NoDestructor for KeyedService factories | https://chromium-review.googlesource.com/c/chromium/src/+/4573627 * 4576878: Reland "Shared Storage: Add mojo method for observing response headers" | https://chromium-review.googlesource.com/c/chromium/src/+/4576878 * chore: bump chromium in DEPS to 116.0.5813.0 * chore: update patches * fixup! 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: fix up lint * test: (debug) use Promise.all in asan tests * chore: manually roll DEPS to 116.0.5815.0 * chore: update patches * 4585150: Convert /printing to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4585150 * test: (asan) extend timeout, clean up debugging * chore: remove ARC chromium patch * chore: update patches after main sync * 4546398: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4546398 * build: add chrome_lib_arc for chromium_src/BUILD.gn sources * fixup! 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
2023-06-10 02:08:36 +03:00
));
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 17:55:41 +03:00
const navigationFinished = once(w.webContents, 'did-navigate');
w.webContents.debugger.attach('1.1');
const targets = await w.webContents.debugger.sendCommand('Target.getTargets');
const pageTarget = targets.targetInfos.find((t: any) => t.type === 'page');
const { sessionId } = await w.webContents.debugger.sendCommand('Target.attachToTarget', {
targetId: pageTarget.targetId,
flatten: true
});
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mousePressed',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mouseReleased',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await navigationFinished;
expect(firedEvents).to.deep.equal(expectedEventOrder);
});
it('when navigating in-page, event order is consistent', async () => {
const firedEvents: string[] = [];
const expectedEventOrder = [
'did-start-navigation',
'did-navigate-in-page'
];
w.loadURL(url + '/in-page');
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 17:55:41 +03:00
await once(w.webContents, 'did-navigate');
chore: bump chromium to 116.0.5817.0 (main) (#38465) * chore: bump chromium in DEPS to 116.0.5793.3 * chore: update patches * chore: bump chromium in DEPS to 116.0.5795.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5797.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5799.0 * 4522192: [serial] Allow Bluetooth ports to be requested by service class ID. | https://chromium-review.googlesource.com/c/chromium/src/+/4522192 * 4545385: Create base::apple::Owned[frameworktype], use it for gfx::NativeEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4545385 * chore: bump chromium in DEPS to 116.0.5801.0 * chore: update patches * 4562796: Use base::apple::Owned[frameworktype] for ui::PlatformEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4562796 * 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 * chore: bump chromium in DEPS to 116.0.5803.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5805.2 * chore: update patches * 4547630: Move content/public/common/network_service_util.h to c/p/browser/ | https://chromium-review.googlesource.com/c/chromium/src/+/4547630 * 4510075: Adding extensions to network response experiment | https://chromium-review.googlesource.com/c/chromium/src/+/4510075 * 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: bump chromium in DEPS to 116.0.5807.0 * chore: update patches * 4533536: [Privacy Hub] Geolocation manager used directly | https://chromium-review.googlesource.com/c/chromium/src/+/4533536 * chore: patch out ARC support from /chrome/browser 4571955: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4571955 * chore: bump chromium in DEPS to 116.0.5809.2 * chore: bump chromium in DEPS to 116.0.5811.0 * chore: update patches * 4573627: Adopt base::NoDestructor for KeyedService factories | https://chromium-review.googlesource.com/c/chromium/src/+/4573627 * 4576878: Reland "Shared Storage: Add mojo method for observing response headers" | https://chromium-review.googlesource.com/c/chromium/src/+/4576878 * chore: bump chromium in DEPS to 116.0.5813.0 * chore: update patches * fixup! 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: fix up lint * test: (debug) use Promise.all in asan tests * chore: manually roll DEPS to 116.0.5815.0 * chore: update patches * 4585150: Convert /printing to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4585150 * test: (asan) extend timeout, clean up debugging * chore: remove ARC chromium patch * chore: update patches after main sync * 4546398: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4546398 * build: add chrome_lib_arc for chromium_src/BUILD.gn sources * fixup! 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
2023-06-10 02:08:36 +03:00
await setTimeout(2000);
Promise.all(navigationEvents.map(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 17:55:41 +03:00
once(w.webContents, event).then(() => firedEvents.push(event))
chore: bump chromium to 116.0.5817.0 (main) (#38465) * chore: bump chromium in DEPS to 116.0.5793.3 * chore: update patches * chore: bump chromium in DEPS to 116.0.5795.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5797.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5799.0 * 4522192: [serial] Allow Bluetooth ports to be requested by service class ID. | https://chromium-review.googlesource.com/c/chromium/src/+/4522192 * 4545385: Create base::apple::Owned[frameworktype], use it for gfx::NativeEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4545385 * chore: bump chromium in DEPS to 116.0.5801.0 * chore: update patches * 4562796: Use base::apple::Owned[frameworktype] for ui::PlatformEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4562796 * 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 * chore: bump chromium in DEPS to 116.0.5803.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5805.2 * chore: update patches * 4547630: Move content/public/common/network_service_util.h to c/p/browser/ | https://chromium-review.googlesource.com/c/chromium/src/+/4547630 * 4510075: Adding extensions to network response experiment | https://chromium-review.googlesource.com/c/chromium/src/+/4510075 * 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: bump chromium in DEPS to 116.0.5807.0 * chore: update patches * 4533536: [Privacy Hub] Geolocation manager used directly | https://chromium-review.googlesource.com/c/chromium/src/+/4533536 * chore: patch out ARC support from /chrome/browser 4571955: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4571955 * chore: bump chromium in DEPS to 116.0.5809.2 * chore: bump chromium in DEPS to 116.0.5811.0 * chore: update patches * 4573627: Adopt base::NoDestructor for KeyedService factories | https://chromium-review.googlesource.com/c/chromium/src/+/4573627 * 4576878: Reland "Shared Storage: Add mojo method for observing response headers" | https://chromium-review.googlesource.com/c/chromium/src/+/4576878 * chore: bump chromium in DEPS to 116.0.5813.0 * chore: update patches * fixup! 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: fix up lint * test: (debug) use Promise.all in asan tests * chore: manually roll DEPS to 116.0.5815.0 * chore: update patches * 4585150: Convert /printing to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4585150 * test: (asan) extend timeout, clean up debugging * chore: remove ARC chromium patch * chore: update patches after main sync * 4546398: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4546398 * build: add chrome_lib_arc for chromium_src/BUILD.gn sources * fixup! 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
2023-06-10 02:08:36 +03:00
));
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 17:55:41 +03:00
const navigationFinished = once(w.webContents, 'did-navigate-in-page');
w.webContents.debugger.attach('1.1');
const targets = await w.webContents.debugger.sendCommand('Target.getTargets');
const pageTarget = targets.targetInfos.find((t: any) => t.type === 'page');
const { sessionId } = await w.webContents.debugger.sendCommand('Target.attachToTarget', {
targetId: pageTarget.targetId,
flatten: true
});
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mousePressed',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await w.webContents.debugger.sendCommand('Input.dispatchMouseEvent', {
type: 'mouseReleased',
x: 10,
y: 10,
clickCount: 1,
button: 'left'
}, sessionId);
await navigationFinished;
expect(firedEvents).to.deep.equal(expectedEventOrder);
});
});
});
}
describe('focus and visibility', () => {
let w: BrowserWindow;
beforeEach(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false });
});
afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
describe('BrowserWindow.show()', () => {
it('should focus on window', async () => {
const p = once(w, 'focus');
w.show();
await p;
2019-10-31 02:38:21 +03:00
expect(w.isFocused()).to.equal(true);
});
it('should make the window visible', async () => {
const p = once(w, 'focus');
w.show();
await p;
expect(w.isVisible()).to.equal(true);
});
it('emits when window is shown', async () => {
const show = once(w, 'show');
w.show();
await show;
expect(w.isVisible()).to.equal(true);
});
});
describe('BrowserWindow.hide()', () => {
it('should defocus on window', () => {
w.hide();
expect(w.isFocused()).to.equal(false);
});
it('should make the window not visible', () => {
w.show();
w.hide();
expect(w.isVisible()).to.equal(false);
});
it('emits when window is hidden', async () => {
const shown = once(w, 'show');
w.show();
await shown;
const hidden = once(w, 'hide');
w.hide();
await hidden;
expect(w.isVisible()).to.equal(false);
});
});
describe('BrowserWindow.minimize()', () => {
// TODO(codebytere): Enable for Linux once maximize/minimize events work in CI.
ifit(process.platform !== 'linux')('should not be visible when the window is minimized', async () => {
const minimize = once(w, 'minimize');
w.minimize();
await minimize;
expect(w.isMinimized()).to.equal(true);
expect(w.isVisible()).to.equal(false);
});
});
describe('BrowserWindow.showInactive()', () => {
it('should not focus on window', () => {
w.showInactive();
expect(w.isFocused()).to.equal(false);
});
// TODO(dsanders11): Enable for Linux once CI plays nice with these kinds of tests
ifit(process.platform !== 'linux')('should not restore maximized windows', async () => {
const maximize = once(w, 'maximize');
const shown = once(w, 'show');
w.maximize();
// TODO(dsanders11): The maximize event isn't firing on macOS for a window initially hidden
if (process.platform !== 'darwin') {
await maximize;
} else {
await setTimeout(1000);
}
w.showInactive();
await shown;
expect(w.isMaximized()).to.equal(true);
});
ifit(process.platform === 'darwin')('should attach child window to parent', async () => {
const wShow = once(w, 'show');
w.show();
await wShow;
const c = new BrowserWindow({ show: false, parent: w });
const cShow = once(c, 'show');
c.showInactive();
await cShow;
// verifying by checking that the child tracks the parent's visibility
const minimized = once(w, 'minimize');
w.minimize();
await minimized;
expect(w.isVisible()).to.be.false('parent is visible');
expect(c.isVisible()).to.be.false('child is visible');
const restored = once(w, 'restore');
w.restore();
await restored;
expect(w.isVisible()).to.be.true('parent is visible');
expect(c.isVisible()).to.be.true('child is visible');
closeWindow(c);
});
});
describe('BrowserWindow.focus()', () => {
it('does not make the window become visible', () => {
expect(w.isVisible()).to.equal(false);
w.focus();
expect(w.isVisible()).to.equal(false);
});
ifit(process.platform !== 'win32')('focuses a blurred window', async () => {
{
const isBlurred = once(w, 'blur');
const isShown = once(w, 'show');
w.show();
w.blur();
await isShown;
await isBlurred;
}
expect(w.isFocused()).to.equal(false);
w.focus();
expect(w.isFocused()).to.equal(true);
});
ifit(process.platform !== 'linux')('acquires focus status from the other windows', async () => {
const w1 = new BrowserWindow({ show: false });
const w2 = new BrowserWindow({ show: false });
const w3 = new BrowserWindow({ show: false });
{
const isFocused3 = once(w3, 'focus');
const isShown1 = once(w1, 'show');
const isShown2 = once(w2, 'show');
const isShown3 = once(w3, 'show');
w1.show();
w2.show();
w3.show();
await isShown1;
await isShown2;
await isShown3;
await isFocused3;
}
// TODO(RaisinTen): Investigate why this assertion fails only on Linux.
expect(w1.isFocused()).to.equal(false);
expect(w2.isFocused()).to.equal(false);
expect(w3.isFocused()).to.equal(true);
w1.focus();
expect(w1.isFocused()).to.equal(true);
expect(w2.isFocused()).to.equal(false);
expect(w3.isFocused()).to.equal(false);
w2.focus();
expect(w1.isFocused()).to.equal(false);
expect(w2.isFocused()).to.equal(true);
expect(w3.isFocused()).to.equal(false);
w3.focus();
expect(w1.isFocused()).to.equal(false);
expect(w2.isFocused()).to.equal(false);
expect(w3.isFocused()).to.equal(true);
{
const isClosed1 = once(w1, 'closed');
const isClosed2 = once(w2, 'closed');
const isClosed3 = once(w3, 'closed');
w1.destroy();
w2.destroy();
w3.destroy();
await isClosed1;
await isClosed2;
await isClosed3;
}
});
ifit(process.platform === 'darwin')('it does not activate the app if focusing an inactive panel', async () => {
// Show to focus app, then remove existing window
w.show();
w.destroy();
// We first need to resign app focus for this test to work
const isInactive = once(app, 'did-resign-active');
childProcess.execSync('osascript -e \'tell application "Finder" to activate\'');
await isInactive;
// Create new window
w = new BrowserWindow({
type: 'panel',
height: 200,
width: 200,
center: true,
show: false
});
const isShow = once(w, 'show');
const isFocus = once(w, 'focus');
w.show();
w.focus();
await isShow;
await isFocus;
const getActiveAppOsa = 'tell application "System Events" to get the name of the first process whose frontmost is true';
const activeApp = childProcess.execSync(`osascript -e '${getActiveAppOsa}'`).toString().trim();
expect(activeApp).to.equal('Finder');
});
});
// TODO(RaisinTen): Make this work on Windows too.
// Refs: https://github.com/electron/electron/issues/20464.
ifdescribe(process.platform !== 'win32')('BrowserWindow.blur()', () => {
it('removes focus from window', async () => {
{
const isFocused = once(w, 'focus');
const isShown = once(w, 'show');
w.show();
await isShown;
await isFocused;
}
expect(w.isFocused()).to.equal(true);
w.blur();
expect(w.isFocused()).to.equal(false);
});
ifit(process.platform !== 'linux')('transfers focus status to the next window', async () => {
const w1 = new BrowserWindow({ show: false });
const w2 = new BrowserWindow({ show: false });
const w3 = new BrowserWindow({ show: false });
{
const isFocused3 = once(w3, 'focus');
const isShown1 = once(w1, 'show');
const isShown2 = once(w2, 'show');
const isShown3 = once(w3, 'show');
w1.show();
w2.show();
w3.show();
await isShown1;
await isShown2;
await isShown3;
await isFocused3;
}
// TODO(RaisinTen): Investigate why this assertion fails only on Linux.
expect(w1.isFocused()).to.equal(false);
expect(w2.isFocused()).to.equal(false);
expect(w3.isFocused()).to.equal(true);
w3.blur();
expect(w1.isFocused()).to.equal(false);
expect(w2.isFocused()).to.equal(true);
expect(w3.isFocused()).to.equal(false);
w2.blur();
expect(w1.isFocused()).to.equal(true);
expect(w2.isFocused()).to.equal(false);
expect(w3.isFocused()).to.equal(false);
w1.blur();
expect(w1.isFocused()).to.equal(false);
expect(w2.isFocused()).to.equal(false);
expect(w3.isFocused()).to.equal(true);
{
const isClosed1 = once(w1, 'closed');
const isClosed2 = once(w2, 'closed');
const isClosed3 = once(w3, 'closed');
w1.destroy();
w2.destroy();
w3.destroy();
await isClosed1;
await isClosed2;
await isClosed3;
}
});
});
describe('BrowserWindow.getFocusedWindow()', () => {
it('returns the opener window when dev tools window is focused', async () => {
const p = once(w, 'focus');
w.show();
await p;
w.webContents.openDevTools({ mode: 'undocked' });
await once(w.webContents, 'devtools-focused');
expect(BrowserWindow.getFocusedWindow()).to.equal(w);
});
});
describe('BrowserWindow.moveTop()', () => {
afterEach(closeAllWindows);
it('should not steal focus', async () => {
const posDelta = 50;
const wShownInactive = once(w, 'show');
w.showInactive();
await wShownInactive;
expect(w.isFocused()).to.equal(false);
2020-03-20 23:28:31 +03:00
const otherWindow = new BrowserWindow({ show: false, title: 'otherWindow' });
const otherWindowShown = once(otherWindow, 'show');
const otherWindowFocused = once(otherWindow, 'focus');
otherWindow.show();
await otherWindowShown;
await otherWindowFocused;
expect(otherWindow.isFocused()).to.equal(true);
2020-03-20 23:28:31 +03:00
w.moveTop();
const wPos = w.getPosition();
const wMoving = once(w, 'move');
w.setPosition(wPos[0] + posDelta, wPos[1] + posDelta);
await wMoving;
expect(w.isFocused()).to.equal(false);
expect(otherWindow.isFocused()).to.equal(true);
2020-03-20 23:28:31 +03:00
const wFocused = once(w, 'focus');
const otherWindowBlurred = once(otherWindow, 'blur');
w.focus();
await wFocused;
chore: bump chromium to 93.0.4530.0 (master) (#29256) * chore: bump chromium in DEPS to 92.0.4512.6 * 2887336: [CaptureHandle][#2] Propagate CaptureHandleConfig in browser process https://chromium-review.googlesource.com/c/chromium/src/+/2887336 * refactor: base::Optional -> absl::optional * chore: fixup patch indices * chore: bump chromium in DEPS to 92.0.4514.0 * 2899417: Make build work when enable_pdf is set to false. https://chromium-review.googlesource.com/c/chromium/src/+/2899417 * 2904731: use BrowserContext instead of Profile in PreconnectManager https://chromium-review.googlesource.com/c/chromium/src/+/2904731 * 2295749: fix: check IsSecureEventInputEnabled in constructor before setting SetPasswordInputEnabled to true https://chromium-review.googlesource.com/c/chromium/src/+/2295749 * 2893803: Add a GetWebView to RenderFrame. https://chromium-review.googlesource.com/c/chromium/src/+/2893803 * 2892345: Implement WebContents::ForEachRenderFrameHost https://chromium-review.googlesource.com/c/chromium/src/+/2892345 * chore: fixup patch indices * 2892048: Real instance methods for BrowserContext: remaining 5 methods. https://chromium-review.googlesource.com/c/chromium/src/+/2892048 * 2902821: [mojo] Don't require full header includes for referenced interfaces https://chromium-review.googlesource.com/c/chromium/src/+/2902821 * 2496500: Remove last deprecated extension Event ctor. https://chromium-review.googlesource.com/c/chromium/src/+/2496500 * chore: fixup malformed pepper support patch * chore: bump chromium in DEPS to 92.0.4515.0 * 2908461: Add CreateEmptyPrintPagesParamsPtr() inside print_view_manager_base.cc. https://chromium-review.googlesource.com/c/chromium/src/+/2908461 * 2880838: viz: add optional HDRMetadata to TransferableResource https://chromium-review.googlesource.com/c/chromium/src/+/2880838 * chore: fixup patch indices * chore: bump chromium in DEPS to 92.0.4515.5 * chore: update patches * chore: bump chromium in DEPS to 92.0.4515.7 * chore: bump chromium in DEPS to 92.0.4515.9 * chore: bump chromium in DEPS to 93.0.4522.0 * chore: bump chromium in DEPS to 93.0.4523.0 * chore: bump chromium in DEPS to 93.0.4524.0 * chore: update patches * chore: enable_pak_file_integrity_checks was reverted * chore: update patches * refactor: base/optional was replaced with absl::optional Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace all usages of base::nullopt with absl::nullopt Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * chore: add missing base::Contains include Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace all usages of base::make_optional with absl::make_optional Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace WorldScriptContext() with GetScriptContextFromWorldId Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2893213 * chore: clean up left over opening namespace Refs: https://github.com/electron/electron/commit/95bfe6d08f65471394fb3005dbfa177cdf71210a * chore: add missing base::Contains include Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace GetCurrentDisplayIterator with the hard checker GetCurrentDisplay This code looks suspicious but if the iterator was invalid before it will also be invalid now. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2893191 * refactor: headers are now passed directly in extensions client Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2918906 * refactor: base::DictionaryValue::empty() has been removed Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2912424 * chore: add missing includes for network URLLoaderFactory Refs: unknown, probably a side effect of header changes * refactor: make convenience wrapper around AppendArg There is no converter FromV8 for base::StringPiece (apparently its not possible). So we now take in an std::string and use the construct for StringPiece to do implicit conversion. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2905544 * chore: add patch * chore: bump chromium in DEPS to 93.0.4525.0 * chore: update patches * refactor: CanResize has been de-virtualized Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2485774 * chore: update resource integrity patch * chore: add character encoding idl patch * chore: bump chromium in DEPS to 93.0.4526.0 * chore: update patches * chore: bump chromium in DEPS to 93.0.4527.0 * chore: bump chromium in DEPS to 93.0.4528.0 * chore: update patches * chore: update idl encoding patch * chore: bump chromium in DEPS to 93.0.4529.0 * chore: update patches * chore: bump chromium in DEPS to 93.0.4530.0 * chore: update patches * fix: only SetCanResize after the widget has been initialized * chore: add patch for vr on windows gn gen * spec: fix focus related tests on linux due to delay in focus swap * chore: remove new usages of base::Optional from main 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 <sattard@slack-corp.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2021-06-03 11:05:04 +03:00
await otherWindowBlurred;
expect(w.isFocused()).to.equal(true);
2020-03-20 23:28:31 +03:00
otherWindow.moveTop();
const otherWindowPos = otherWindow.getPosition();
const otherWindowMoving = once(otherWindow, 'move');
otherWindow.setPosition(otherWindowPos[0] + posDelta, otherWindowPos[1] + posDelta);
await otherWindowMoving;
expect(otherWindow.isFocused()).to.equal(false);
expect(w.isFocused()).to.equal(true);
2020-03-20 23:28:31 +03:00
await closeWindow(otherWindow, { assertNotWindows: false });
expect(BrowserWindow.getAllWindows()).to.have.lengthOf(1);
});
it('should not crash when called on a modal child window', async () => {
const shown = once(w, 'show');
w.show();
await shown;
const child = new BrowserWindow({ modal: true, parent: w });
expect(() => { child.moveTop(); }).to.not.throw();
});
});
describe('BrowserWindow.moveAbove(mediaSourceId)', () => {
it('should throw an exception if wrong formatting', async () => {
const fakeSourceIds = [
'none', 'screen:0', 'window:fake', 'window:1234', 'foobar:1:2'
];
for (const sourceId of fakeSourceIds) {
expect(() => {
w.moveAbove(sourceId);
}).to.throw(/Invalid media source id/);
}
});
it('should throw an exception if wrong type', async () => {
const fakeSourceIds = [null as any, 123 as any];
for (const sourceId of fakeSourceIds) {
expect(() => {
w.moveAbove(sourceId);
}).to.throw(/Error processing argument at index 0 */);
}
});
it('should throw an exception if invalid window', async () => {
// It is very unlikely that these window id exist.
const fakeSourceIds = ['window:99999999:0', 'window:123456:1',
'window:123456:9'];
for (const sourceId of fakeSourceIds) {
expect(() => {
w.moveAbove(sourceId);
}).to.throw(/Invalid media source id/);
}
});
it('should not throw an exception', async () => {
const w2 = new BrowserWindow({ show: false, title: 'window2' });
const w2Shown = once(w2, 'show');
w2.show();
await w2Shown;
expect(() => {
w.moveAbove(w2.getMediaSourceId());
}).to.not.throw();
await closeWindow(w2, { assertNotWindows: false });
});
});
describe('BrowserWindow.setFocusable()', () => {
it('can set unfocusable window to focusable', async () => {
const w2 = new BrowserWindow({ focusable: false });
const w2Focused = once(w2, 'focus');
w2.setFocusable(true);
w2.focus();
await w2Focused;
await closeWindow(w2, { assertNotWindows: false });
});
});
describe('BrowserWindow.isFocusable()', () => {
it('correctly returns whether a window is focusable', async () => {
const w2 = new BrowserWindow({ focusable: false });
expect(w2.isFocusable()).to.be.false();
w2.setFocusable(true);
expect(w2.isFocusable()).to.be.true();
await closeWindow(w2, { assertNotWindows: false });
});
});
});
describe('sizing', () => {
let w: BrowserWindow;
beforeEach(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false, width: 400, height: 400 });
});
afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
describe('BrowserWindow.setBounds(bounds[, animate])', () => {
it('sets the window bounds with full bounds', () => {
const fullBounds = { x: 440, y: 225, width: 500, height: 400 };
w.setBounds(fullBounds);
expectBoundsEqual(w.getBounds(), fullBounds);
});
it('rounds non-integer bounds', () => {
w.setBounds({ x: 440.5, y: 225.1, width: 500.4, height: 400.9 });
const bounds = w.getBounds();
expect(bounds).to.deep.equal({ x: 441, y: 225, width: 500, height: 401 });
});
it('sets the window bounds with partial bounds', () => {
const fullBounds = { x: 440, y: 225, width: 500, height: 400 };
w.setBounds(fullBounds);
const boundsUpdate = { width: 200 };
w.setBounds(boundsUpdate as any);
const expectedBounds = { ...fullBounds, ...boundsUpdate };
expectBoundsEqual(w.getBounds(), expectedBounds);
});
ifit(process.platform === 'darwin')('on macOS', () => {
it('emits \'resized\' event after animating', async () => {
const fullBounds = { x: 440, y: 225, width: 500, height: 400 };
w.setBounds(fullBounds, true);
await expect(once(w, 'resized')).to.eventually.be.fulfilled();
});
});
});
describe('BrowserWindow.setSize(width, height)', () => {
it('sets the window size', async () => {
const size = [300, 400];
const resized = once(w, 'resize');
w.setSize(size[0], size[1]);
await resized;
expectBoundsEqual(w.getSize(), size);
});
ifit(process.platform === 'darwin')('on macOS', () => {
it('emits \'resized\' event after animating', async () => {
const size = [300, 400];
w.setSize(size[0], size[1], true);
await expect(once(w, 'resized')).to.eventually.be.fulfilled();
});
});
});
describe('BrowserWindow.setMinimum/MaximumSize(width, height)', () => {
it('sets the maximum and minimum size of the window', () => {
expect(w.getMinimumSize()).to.deep.equal([0, 0]);
expect(w.getMaximumSize()).to.deep.equal([0, 0]);
w.setMinimumSize(100, 100);
expectBoundsEqual(w.getMinimumSize(), [100, 100]);
expectBoundsEqual(w.getMaximumSize(), [0, 0]);
w.setMaximumSize(900, 600);
expectBoundsEqual(w.getMinimumSize(), [100, 100]);
expectBoundsEqual(w.getMaximumSize(), [900, 600]);
});
});
describe('BrowserWindow.setAspectRatio(ratio)', () => {
it('resets the behaviour when passing in 0', async () => {
const size = [300, 400];
w.setAspectRatio(1 / 2);
w.setAspectRatio(0);
const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
expectBoundsEqual(w.getSize(), size);
});
it('doesn\'t change bounds when maximum size is set', () => {
w.setMenu(null);
w.setMaximumSize(400, 400);
// Without https://github.com/electron/electron/pull/29101
// following call would shrink the window to 384x361.
// There would be also DCHECK in resize_utils.cc on
// debug build.
w.setAspectRatio(1.0);
expectBoundsEqual(w.getSize(), [400, 400]);
});
});
describe('BrowserWindow.setPosition(x, y)', () => {
it('sets the window position', async () => {
const pos = [10, 10];
const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
expect(w.getPosition()).to.deep.equal(pos);
});
});
describe('BrowserWindow.setContentSize(width, height)', () => {
it('sets the content size', async () => {
// NB. The CI server has a very small screen. Attempting to size the window
// larger than the screen will limit the window's size to the screen and
// cause the test to fail.
const size = [456, 567];
w.setContentSize(size[0], size[1]);
await new Promise(setImmediate);
const after = w.getContentSize();
expect(after).to.deep.equal(size);
});
it('works for a frameless window', async () => {
w.destroy();
w = new BrowserWindow({
show: false,
frame: false,
width: 400,
height: 400
});
const size = [456, 567];
w.setContentSize(size[0], size[1]);
await new Promise(setImmediate);
const after = w.getContentSize();
expect(after).to.deep.equal(size);
});
});
describe('BrowserWindow.setContentBounds(bounds)', () => {
it('sets the content size and position', async () => {
const bounds = { x: 10, y: 10, width: 250, height: 250 };
const resize = once(w, 'resize');
w.setContentBounds(bounds);
await resize;
await setTimeout();
expectBoundsEqual(w.getContentBounds(), bounds);
});
it('works for a frameless window', async () => {
w.destroy();
w = new BrowserWindow({
show: false,
frame: false,
width: 300,
height: 300
});
const bounds = { x: 10, y: 10, width: 250, height: 250 };
const resize = once(w, 'resize');
w.setContentBounds(bounds);
await resize;
await setTimeout();
expectBoundsEqual(w.getContentBounds(), bounds);
});
});
describe('BrowserWindow.getBackgroundColor()', () => {
it('returns default value if no backgroundColor is set', () => {
w.destroy();
w = new BrowserWindow({});
expect(w.getBackgroundColor()).to.equal('#FFFFFF');
});
it('returns correct value if backgroundColor is set', () => {
const backgroundColor = '#BBAAFF';
w.destroy();
w = new BrowserWindow({
backgroundColor
});
expect(w.getBackgroundColor()).to.equal(backgroundColor);
});
it('returns correct value from setBackgroundColor()', () => {
const backgroundColor = '#AABBFF';
w.destroy();
w = new BrowserWindow({});
w.setBackgroundColor(backgroundColor);
expect(w.getBackgroundColor()).to.equal(backgroundColor);
});
it('returns correct color with multiple passed formats', async () => {
w.destroy();
w = new BrowserWindow({});
await w.loadURL('about:blank');
const colors = new Map([
['blueviolet', '#8A2BE2'],
['rgb(255, 0, 185)', '#FF00B9'],
['hsl(155, 100%, 50%)', '#00FF95'],
['#355E3B', '#355E3B']
]);
for (const [color, hex] of colors) {
w.setBackgroundColor(color);
expect(w.getBackgroundColor()).to.equal(hex);
}
});
it('can set the background color with transparency', async () => {
w.destroy();
w = new BrowserWindow({});
await w.loadURL('about:blank');
const colors = new Map([
['hsl(155, 100%, 50%)', '#00FF95'],
['rgba(245, 40, 145, 0.8)', '#F52891'],
['#1D1F21d9', '#1F21D9']
]);
for (const [color, hex] of colors) {
w.setBackgroundColor(color);
expect(w.getBackgroundColor()).to.equal(hex);
}
});
});
describe('BrowserWindow.getNormalBounds()', () => {
describe('Normal state', () => {
it('checks normal bounds after resize', async () => {
const size = [300, 400];
const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
expectBoundsEqual(w.getNormalBounds(), w.getBounds());
});
it('checks normal bounds after move', async () => {
const pos = [10, 10];
const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
expectBoundsEqual(w.getNormalBounds(), w.getBounds());
});
});
ifdescribe(process.platform !== 'linux')('Maximized state', () => {
it('checks normal bounds when maximized', async () => {
const bounds = w.getBounds();
const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
it('updates normal bounds after resize and maximize', async () => {
const size = [300, 400];
const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
const original = w.getBounds();
const maximize = once(w, 'maximize');
w.maximize();
await maximize;
const normal = w.getNormalBounds();
const bounds = w.getBounds();
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
const close = once(w, 'close');
w.close();
await close;
});
it('updates normal bounds after move and maximize', async () => {
const pos = [10, 10];
const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
const original = w.getBounds();
const maximize = once(w, 'maximize');
w.maximize();
await maximize;
const normal = w.getNormalBounds();
const bounds = w.getBounds();
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
const close = once(w, 'close');
w.close();
await close;
});
it('checks normal bounds when unmaximized', async () => {
const bounds = w.getBounds();
w.once('maximize', () => {
w.unmaximize();
});
const unmaximize = once(w, 'unmaximize');
w.show();
w.maximize();
await unmaximize;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
it('correctly reports maximized state after maximizing then minimizing', async () => {
w.destroy();
w = new BrowserWindow({ show: false });
w.show();
const maximize = once(w, 'maximize');
w.maximize();
await maximize;
const minimize = once(w, 'minimize');
w.minimize();
await minimize;
expect(w.isMaximized()).to.equal(false);
expect(w.isMinimized()).to.equal(true);
});
it('correctly reports maximized state after maximizing then fullscreening', async () => {
w.destroy();
w = new BrowserWindow({ show: false });
w.show();
const maximize = once(w, 'maximize');
w.maximize();
await maximize;
const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
expect(w.isMaximized()).to.equal(false);
expect(w.isFullScreen()).to.equal(true);
});
it('does not crash if maximized, minimized, then restored to maximized state', (done) => {
w.destroy();
w = new BrowserWindow({ show: false });
w.show();
let count = 0;
w.on('maximize', () => {
if (count === 0) syncSetTimeout(() => { w.minimize(); });
count++;
});
w.on('minimize', () => {
if (count === 1) syncSetTimeout(() => { w.restore(); });
count++;
});
w.on('restore', () => {
try {
throw new Error('hey!');
} catch (e: any) {
expect(e.message).to.equal('hey!');
done();
}
});
w.maximize();
});
it('checks normal bounds for maximized transparent window', async () => {
w.destroy();
w = new BrowserWindow({
transparent: true,
show: false
});
w.show();
const bounds = w.getNormalBounds();
const maximize = once(w, 'maximize');
w.maximize();
await maximize;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
it('does not change size for a frameless window with min size', async () => {
w.destroy();
w = new BrowserWindow({
show: false,
frame: false,
width: 300,
height: 300,
minWidth: 300,
minHeight: 300
});
const bounds = w.getBounds();
w.once('maximize', () => {
w.unmaximize();
});
const unmaximize = once(w, 'unmaximize');
w.show();
w.maximize();
await unmaximize;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
it('correctly checks transparent window maximization state', async () => {
w.destroy();
w = new BrowserWindow({
show: false,
width: 300,
height: 300,
transparent: true
});
const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
expect(w.isMaximized()).to.equal(true);
const unmaximize = once(w, 'unmaximize');
w.unmaximize();
await unmaximize;
expect(w.isMaximized()).to.equal(false);
});
it('returns the correct value for windows with an aspect ratio', async () => {
w.destroy();
w = new BrowserWindow({
show: false,
fullscreenable: false
});
w.setAspectRatio(16 / 11);
const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
expect(w.isMaximized()).to.equal(true);
w.resizable = false;
expect(w.isMaximized()).to.equal(true);
});
});
ifdescribe(process.platform !== 'linux')('Minimized state', () => {
it('checks normal bounds when minimized', async () => {
const bounds = w.getBounds();
const minimize = once(w, 'minimize');
w.show();
w.minimize();
await minimize;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
it('updates normal bounds after move and minimize', async () => {
const pos = [10, 10];
const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
const original = w.getBounds();
const minimize = once(w, 'minimize');
w.minimize();
await minimize;
const normal = w.getNormalBounds();
expect(original).to.deep.equal(normal);
expectBoundsEqual(normal, w.getBounds());
});
it('updates normal bounds after resize and minimize', async () => {
const size = [300, 400];
const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
const original = w.getBounds();
const minimize = once(w, 'minimize');
w.minimize();
await minimize;
const normal = w.getNormalBounds();
expect(original).to.deep.equal(normal);
expectBoundsEqual(normal, w.getBounds());
});
it('checks normal bounds when restored', async () => {
const bounds = w.getBounds();
w.once('minimize', () => {
w.restore();
});
const restore = once(w, 'restore');
w.show();
w.minimize();
await restore;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
it('does not change size for a frameless window with min size', async () => {
w.destroy();
w = new BrowserWindow({
show: false,
frame: false,
width: 300,
height: 300,
minWidth: 300,
minHeight: 300
});
const bounds = w.getBounds();
w.once('minimize', () => {
w.restore();
});
const restore = once(w, 'restore');
w.show();
w.minimize();
await restore;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
});
2020-07-09 20:18:49 +03:00
ifdescribe(process.platform === 'win32')('Fullscreen state', () => {
it('with properties', () => {
it('can be set with the fullscreen constructor option', () => {
w = new BrowserWindow({ fullscreen: true });
expect(w.fullScreen).to.be.true();
});
it('does not go fullscreen if roundedCorners are enabled', async () => {
w = new BrowserWindow({ frame: false, roundedCorners: false, fullscreen: true });
expect(w.fullScreen).to.be.false();
});
it('can be changed', () => {
w.fullScreen = false;
expect(w.fullScreen).to.be.false();
w.fullScreen = true;
expect(w.fullScreen).to.be.true();
});
2020-07-09 20:18:49 +03:00
it('checks normal bounds when fullscreen\'ed', async () => {
const bounds = w.getBounds();
const enterFullScreen = once(w, 'enter-full-screen');
w.show();
w.fullScreen = true;
await enterFullScreen;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
it('updates normal bounds after resize and fullscreen', async () => {
const size = [300, 400];
const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
const original = w.getBounds();
const fsc = once(w, 'enter-full-screen');
w.fullScreen = true;
await fsc;
const normal = w.getNormalBounds();
const bounds = w.getBounds();
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
const close = once(w, 'close');
w.close();
await close;
});
it('updates normal bounds after move and fullscreen', async () => {
const pos = [10, 10];
const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
const original = w.getBounds();
const fsc = once(w, 'enter-full-screen');
w.fullScreen = true;
await fsc;
const normal = w.getNormalBounds();
const bounds = w.getBounds();
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
const close = once(w, 'close');
w.close();
await close;
});
2020-07-09 20:18:49 +03:00
it('checks normal bounds when unfullscreen\'ed', async () => {
const bounds = w.getBounds();
w.once('enter-full-screen', () => {
w.fullScreen = false;
});
const leaveFullScreen = once(w, 'leave-full-screen');
w.show();
w.fullScreen = true;
await leaveFullScreen;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
});
it('with functions', () => {
it('can be set with the fullscreen constructor option', () => {
w = new BrowserWindow({ fullscreen: true });
expect(w.isFullScreen()).to.be.true();
});
it('can be changed', () => {
w.setFullScreen(false);
expect(w.isFullScreen()).to.be.false();
w.setFullScreen(true);
expect(w.isFullScreen()).to.be.true();
});
2020-07-09 20:18:49 +03:00
it('checks normal bounds when fullscreen\'ed', async () => {
const bounds = w.getBounds();
w.show();
const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
it('updates normal bounds after resize and fullscreen', async () => {
const size = [300, 400];
const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
const original = w.getBounds();
const fsc = once(w, 'enter-full-screen');
w.setFullScreen(true);
await fsc;
const normal = w.getNormalBounds();
const bounds = w.getBounds();
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
const close = once(w, 'close');
w.close();
await close;
});
it('updates normal bounds after move and fullscreen', async () => {
const pos = [10, 10];
const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
const original = w.getBounds();
const fsc = once(w, 'enter-full-screen');
w.setFullScreen(true);
await fsc;
const normal = w.getNormalBounds();
const bounds = w.getBounds();
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
const close = once(w, 'close');
w.close();
await close;
});
2020-07-09 20:18:49 +03:00
it('checks normal bounds when unfullscreen\'ed', async () => {
const bounds = w.getBounds();
w.show();
const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
expectBoundsEqual(w.getNormalBounds(), bounds);
});
});
});
});
});
ifdescribe(process.platform === 'darwin')('tabbed windows', () => {
let w: BrowserWindow;
beforeEach(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false });
});
afterEach(closeAllWindows);
describe('BrowserWindow.selectPreviousTab()', () => {
it('does not throw', () => {
expect(() => {
w.selectPreviousTab();
}).to.not.throw();
});
});
describe('BrowserWindow.selectNextTab()', () => {
it('does not throw', () => {
expect(() => {
w.selectNextTab();
}).to.not.throw();
});
});
describe('BrowserWindow.showAllTabs()', () => {
it('does not throw', () => {
expect(() => {
w.showAllTabs();
}).to.not.throw();
});
});
describe('BrowserWindow.mergeAllWindows()', () => {
it('does not throw', () => {
expect(() => {
w.mergeAllWindows();
}).to.not.throw();
});
});
describe('BrowserWindow.moveTabToNewWindow()', () => {
it('does not throw', () => {
expect(() => {
w.moveTabToNewWindow();
}).to.not.throw();
});
});
describe('BrowserWindow.toggleTabBar()', () => {
it('does not throw', () => {
expect(() => {
w.toggleTabBar();
}).to.not.throw();
});
});
describe('BrowserWindow.addTabbedWindow()', () => {
it('does not throw', async () => {
const tabbedWindow = new BrowserWindow({});
expect(() => {
w.addTabbedWindow(tabbedWindow);
}).to.not.throw();
expect(BrowserWindow.getAllWindows()).to.have.lengthOf(2); // w + tabbedWindow
await closeWindow(tabbedWindow, { assertNotWindows: false });
expect(BrowserWindow.getAllWindows()).to.have.lengthOf(1); // w
});
it('throws when called on itself', () => {
expect(() => {
w.addTabbedWindow(w);
}).to.throw('AddTabbedWindow cannot be called by a window on itself.');
});
});
describe('BrowserWindow.tabbingIdentifier', () => {
it('is undefined if no tabbingIdentifier was set', () => {
const w = new BrowserWindow({ show: false });
expect(w.tabbingIdentifier).to.be.undefined('tabbingIdentifier');
});
it('returns the window tabbingIdentifier', () => {
const w = new BrowserWindow({ show: false, tabbingIdentifier: 'group1' });
expect(w.tabbingIdentifier).to.equal('group1');
});
});
});
describe('autoHideMenuBar state', () => {
afterEach(closeAllWindows);
it('for properties', () => {
it('can be set with autoHideMenuBar constructor option', () => {
const w = new BrowserWindow({ show: false, autoHideMenuBar: true });
expect(w.autoHideMenuBar).to.be.true('autoHideMenuBar');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.autoHideMenuBar).to.be.false('autoHideMenuBar');
w.autoHideMenuBar = true;
expect(w.autoHideMenuBar).to.be.true('autoHideMenuBar');
w.autoHideMenuBar = false;
expect(w.autoHideMenuBar).to.be.false('autoHideMenuBar');
});
});
it('for functions', () => {
it('can be set with autoHideMenuBar constructor option', () => {
const w = new BrowserWindow({ show: false, autoHideMenuBar: true });
expect(w.isMenuBarAutoHide()).to.be.true('autoHideMenuBar');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isMenuBarAutoHide()).to.be.false('autoHideMenuBar');
w.setAutoHideMenuBar(true);
expect(w.isMenuBarAutoHide()).to.be.true('autoHideMenuBar');
w.setAutoHideMenuBar(false);
expect(w.isMenuBarAutoHide()).to.be.false('autoHideMenuBar');
});
});
});
describe('BrowserWindow.capturePage(rect)', () => {
afterEach(closeAllWindows);
it('returns a Promise with a Buffer', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const image = await w.capturePage({
x: 0,
y: 0,
width: 100,
height: 100
});
expect(image.isEmpty()).to.equal(true);
});
ifit(process.platform === 'darwin')('honors the stayHidden argument', async () => {
const w = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
{
const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('visible');
expect(hidden).to.be.false('hidden');
}
w.hide();
{
const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('hidden');
expect(hidden).to.be.true('hidden');
}
await w.capturePage({ x: 0, y: 0, width: 0, height: 0 }, { stayHidden: true });
const visible = await w.webContents.executeJavaScript('document.visibilityState');
expect(visible).to.equal('hidden');
});
it('resolves when the window is occluded', async () => {
const w1 = new BrowserWindow({ show: false });
w1.loadFile(path.join(fixtures, 'pages', 'a.html'));
await once(w1, 'ready-to-show');
w1.show();
const w2 = new BrowserWindow({ show: false });
w2.loadFile(path.join(fixtures, 'pages', 'a.html'));
await once(w2, 'ready-to-show');
w2.show();
const visibleImage = await w1.capturePage();
expect(visibleImage.isEmpty()).to.equal(false);
});
it('resolves when the window is not visible', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixtures, 'pages', 'a.html'));
await once(w, 'ready-to-show');
w.show();
const visibleImage = await w.capturePage();
expect(visibleImage.isEmpty()).to.equal(false);
w.minimize();
const hiddenImage = await w.capturePage();
expect(hiddenImage.isEmpty()).to.equal(false);
});
it('preserves transparency', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false, transparent: true });
w.loadFile(path.join(fixtures, 'pages', 'theme-color.html'));
await once(w, 'ready-to-show');
w.show();
const image = await w.capturePage();
const imgBuffer = image.toPNG();
// Check the 25th byte in the PNG.
// Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha
expect(imgBuffer[25]).to.equal(6);
});
});
describe('BrowserWindow.setProgressBar(progress)', () => {
let w: BrowserWindow;
before(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false });
});
after(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
it('sets the progress', () => {
expect(() => {
if (process.platform === 'darwin') {
app.dock.setIcon(path.join(fixtures, 'assets', 'logo.png'));
}
w.setProgressBar(0.5);
if (process.platform === 'darwin') {
app.dock.setIcon(null as any);
}
w.setProgressBar(-1);
}).to.not.throw();
});
it('sets the progress using "paused" mode', () => {
expect(() => {
w.setProgressBar(0.5, { mode: 'paused' });
}).to.not.throw();
});
it('sets the progress using "error" mode', () => {
expect(() => {
w.setProgressBar(0.5, { mode: 'error' });
}).to.not.throw();
});
it('sets the progress using "normal" mode', () => {
expect(() => {
w.setProgressBar(0.5, { mode: 'normal' });
}).to.not.throw();
});
});
describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => {
let w: BrowserWindow;
afterEach(closeAllWindows);
beforeEach(() => {
chore: bump chromium to 6d130075d378a64187360ba4e7820 (master) (#24256) * chore: bump chromium in DEPS to 7fb9778894d73378bff51087ce869ea5aa6e5d5d * chore: bump chromium in DEPS to 83da426e53d423f0530fc23433b6d2c4d0548442 * update patches * remove chromeos-only TtsControllerDelegate Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2255314 * SharedUserScriptMaster -> SharedUserScriptManager Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2258357 * avoid deprecated DISALLOW_COPY_AND_ASSIGN https://groups.google.com/a/chromium.org/forum/#!msg/cxx/qwH2hxaEjac/TUKq6eqfCwAJ * chore: bump chromium in DEPS to b2eaf9ff4e6b03267bf279583ea20ceb2b25e9d0 * update patches * rename GetHighContrastColorScheme -> GetPlatformHighContrastColorScheme Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2250224 * remove vulkan info collection Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * add max_xcode_version build var Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2264867 * add missing headers * chore: bump chromium in DEPS to cded18ca1138f7e8efc904f077ddcca34f0135cf * update patches * add empty floc blocklist to BrowserProcessImpl Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2240873 * chore: bump chromium in DEPS to f06602226cd80bf677b2ce013a94a2fb7f6ac58d * chore: bump chromium in DEPS to 747aa4bfc74fc6cf7f08ee72624cd69ae41ae28d * chore: bump chromium in DEPS to 31c0105e50fcc4e94de33e5c8602c755ace4a32b * chore: update patches * Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" https://chromium-review.googlesource.com/c/chromium/src/+/2264297 * X11 and Ozone: make sure gfx::AcceleratedWidget to be uint32_t https://chromium-review.googlesource.com/c/chromium/src/+/2260554 * Move zygote from //services/service_manager back to //content https://chromium-review.googlesource.com/c/chromium/src/+/2252466 * chore: update v8 patches * [XProto] Remove usage of Shape extension https://chromium-review.googlesource.com/c/chromium/src/+/2262113 * fixup! add empty floc blocklist to BrowserProcessImpl * Require macOS 10.15.1 sdk https://chromium-review.googlesource.com/c/chromium/src/+/2238504 * Use newer Xcode version 11.5.0 * update src cache * chore: bump chromium in DEPS to 60a9883e35db3f6f91916f0878e88e1849c17b11 * chore: update patches * Reland "Reland "New toolchain for Windows 10 19041 SDK"" https://chromium-review.googlesource.com/c/chromium/src/+/2255527 * update patches * Convert raw NonClientFrameViews to unique_ptrs https://chromium-review.googlesource.com/c/chromium/src/+/2240417 * [printing] Move PrintHostMsg_DidPreviewDocument_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2257035 * chore: bump chromium in DEPS to 12c233c2a85bfa28fb279f390121ba681e52a71b * chore: update patches * Removing oppressive language for the directory chrome/browser/apps https://chromium-review.googlesource.com/c/chromium/src/+/2269822 * Inclusion: rename SpellcheckLanguageBlacklistPolicyHandler https://chromium-review.googlesource.com/c/chromium/src/+/2267646 * Clean up duplicate WebContents "is fullscreen" functions https://chromium-review.googlesource.com/c/chromium/src/+/2275148 * Adds icon loading service with sandbox for Windows. https://chromium-review.googlesource.com/c/chromium/src/+/1987273 * No more Vulkan info collection for UMA on Windows https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * fix lint * chore: update buildflag conditions * chore: bump chromium in DEPS to a837d4c4230ace4f10b2768728f4044b7995dfa5 * update hunspell files * chore: update patches * Make content::FileSelectListener a RefCounted https://chromium-review.googlesource.com/c/chromium/src/+/2275338 * fix build failures on MAS * update patches * fixup! Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" * fix build on windows * Check for GDI exhaustion if window creation fails https://chromium-review.googlesource.com/c/chromium/src/+/2244124 * chore: bump chromium in DEPS to 2c9b2a73be4ef9ec22d8b6da8e174cb80753f125 * chore: update patches * Network Service: Move DeleteCookiePredicate into public folder https://chromium-review.googlesource.com/c/chromium/src/+/2264186 * chore: bump chromium in DEPS to fa2606299bcc02c362528d26b5dcf8c8a0db0735 * chore: bump chromium in DEPS to d9c235d1227204dbae3708daae851573a3566b94 * chore: bump chromium in DEPS to 2f82c284243c035f49a747fd1ead6c44b4b31093 * chore: update patches * Move creating the LayerTreeSettings into blink. https://chromium-review.googlesource.com/c/chromium/src/+/2267720 * chore: bump chromium in DEPS to 914112f1d9af9e4974059dc403da62699a55550f * update patches * chore: bump chromium in DEPS to e0bc1ffae6393fc543a2da94c88167df75859b36 * refactor: match upstream print preview handling (#24452) * update patches * chore: bump chromium in DEPS to 0881423156abe084164b51ab58ce93a8bd380524 * update patches * update patches * give a type to pendingPromise * chore: bump chromium in DEPS to 11a8c1534b16d130075d378a64187360ba4e7820 * update patches * 2272609: Move //services/service_manager/sandbox to //sandbox/policy. https://chromium-review.googlesource.com/c/chromium/src/+/2272609 * update patches * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * 2264511: Cookies: Update SetCanonicalCookie to return CookieAccessResult https://chromium-review.googlesource.com/c/chromium/src/+/2264511 * chore: fix setAlwaysOnTop test The window must be visible for state to be updated properly. * Revert "Migrate modules/desktop_capture and modules/video_capture to webrtc::Mutex." https://webrtc-review.googlesource.com/c/src/+/179080 * update patches Co-authored-by: Andy Locascio <andy@slack-corp.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
2020-07-14 04:13:34 +03:00
w = new BrowserWindow({ show: true });
});
it('sets the window as always on top', () => {
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
w.setAlwaysOnTop(true, 'screen-saver');
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop');
w.setAlwaysOnTop(false);
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
w.setAlwaysOnTop(true);
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop');
});
chore: bump chromium to 115.0.5760.0 (main) (#38033) * chore: bump chromium in DEPS to 114.0.5721.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5723.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5725.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5727.0 * chore: bump chromium in DEPS to 114.0.5729.0 * chore: bump chromium in DEPS to 114.0.5731.0 * chore: update patches * 4450570: Clean up content shell https://chromium-review.googlesource.com/c/chromium/src/+/4450570 * 4262527: geolocation: Introduce mojom::GeopositionResult https://chromium-review.googlesource.com/c/chromium/src/+/4262527 * 4450327: Android/Nav: Stop taking content timeout timer from old host. https://chromium-review.googlesource.com/c/chromium/src/+/4450327 Also, see: 4451366: Reland "Prerender: Fix prerender new content timeout start timing" https://chromium-review.googlesource.com/c/chromium/src/+/4451366 * chore: bump chromium in DEPS to 114.0.5733.2 * chore: update patches * chore: bump CircleCI xcode version this will hopefully get us the necessary macOS sdk 13.3 on CI. * chore: bump chromium in DEPS to 114.0.5735.0 * chore: update patches * test: fix geolocation test * chore: bump chromium in DEPS to 115.0.5736.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5738.0 * chore: update patches * fix: remove profiles from spellcheck service * chore: update libc++ filenames * chore: bump chromium in DEPS to 115.0.5740.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5742.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5744.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5746.0 * chore: update patches * chore: update filenames.libcxx.gni * chore: bump chromium in DEPS to 115.0.5748.0 * chore: update patches * build: update libcxx filenames * chore: bump chromium in DEPS to 115.0.5750.0 * chore: bump chromium in DEPS to 115.0.5752.2 * chore: bump chromium in DEPS to 115.0.5754.0 * chore: bump chromium in DEPS to 115.0.5756.0 * chore: bump chromium in DEPS to 115.0.5758.0 * chore: update patches * chore: update patch after rebase * 4500969: Delete content/dev_ui_content_resources.grd file. https://chromium-review.googlesource.com/c/chromium/src/+/4500969 * Use base.Value.Dict in OmahaAttributesHandler related code https://chromium-review.googlesource.com/c/chromium/src/+/4506402 * chore: bump chromium in DEPS to 115.0.5760.0 * chore: update patches * chore: fixup line endings * 4336172: Include client-drawn window decorations in aspect ratio. | Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4336172 (cherry picked from commit 27c2f6c43e8e4a792b33fdf8cf3af880376406be) * spec: fix race condition in alwaysOnTop test (cherry picked from commit 2ec5213fa0998d9cf21248257e7b5a5581044ea3) * build: use xcode 14.2 not 14.3 (cherry picked from commit b7c62351a77102e854a801c363f391b177ebf672) * build: use macOS 12 to run tests The new macOS 13 VMs appear to have different screen / display behavior (cherry picked from commit 14dc1dbc24cec85111a7482b49049f6acbfbc5f1) * Remove always-true flag --harmony-sharedarraybuffer https://chromium-review.googlesource.com/c/v8/v8/+/4429630 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2023-05-10 17:47:48 +03:00
ifit(process.platform === 'darwin')('resets the windows level on minimize', async () => {
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
w.setAlwaysOnTop(true, 'screen-saver');
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop');
chore: bump chromium to 115.0.5760.0 (main) (#38033) * chore: bump chromium in DEPS to 114.0.5721.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5723.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5725.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5727.0 * chore: bump chromium in DEPS to 114.0.5729.0 * chore: bump chromium in DEPS to 114.0.5731.0 * chore: update patches * 4450570: Clean up content shell https://chromium-review.googlesource.com/c/chromium/src/+/4450570 * 4262527: geolocation: Introduce mojom::GeopositionResult https://chromium-review.googlesource.com/c/chromium/src/+/4262527 * 4450327: Android/Nav: Stop taking content timeout timer from old host. https://chromium-review.googlesource.com/c/chromium/src/+/4450327 Also, see: 4451366: Reland "Prerender: Fix prerender new content timeout start timing" https://chromium-review.googlesource.com/c/chromium/src/+/4451366 * chore: bump chromium in DEPS to 114.0.5733.2 * chore: update patches * chore: bump CircleCI xcode version this will hopefully get us the necessary macOS sdk 13.3 on CI. * chore: bump chromium in DEPS to 114.0.5735.0 * chore: update patches * test: fix geolocation test * chore: bump chromium in DEPS to 115.0.5736.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5738.0 * chore: update patches * fix: remove profiles from spellcheck service * chore: update libc++ filenames * chore: bump chromium in DEPS to 115.0.5740.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5742.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5744.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5746.0 * chore: update patches * chore: update filenames.libcxx.gni * chore: bump chromium in DEPS to 115.0.5748.0 * chore: update patches * build: update libcxx filenames * chore: bump chromium in DEPS to 115.0.5750.0 * chore: bump chromium in DEPS to 115.0.5752.2 * chore: bump chromium in DEPS to 115.0.5754.0 * chore: bump chromium in DEPS to 115.0.5756.0 * chore: bump chromium in DEPS to 115.0.5758.0 * chore: update patches * chore: update patch after rebase * 4500969: Delete content/dev_ui_content_resources.grd file. https://chromium-review.googlesource.com/c/chromium/src/+/4500969 * Use base.Value.Dict in OmahaAttributesHandler related code https://chromium-review.googlesource.com/c/chromium/src/+/4506402 * chore: bump chromium in DEPS to 115.0.5760.0 * chore: update patches * chore: fixup line endings * 4336172: Include client-drawn window decorations in aspect ratio. | Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4336172 (cherry picked from commit 27c2f6c43e8e4a792b33fdf8cf3af880376406be) * spec: fix race condition in alwaysOnTop test (cherry picked from commit 2ec5213fa0998d9cf21248257e7b5a5581044ea3) * build: use xcode 14.2 not 14.3 (cherry picked from commit b7c62351a77102e854a801c363f391b177ebf672) * build: use macOS 12 to run tests The new macOS 13 VMs appear to have different screen / display behavior (cherry picked from commit 14dc1dbc24cec85111a7482b49049f6acbfbc5f1) * Remove always-true flag --harmony-sharedarraybuffer https://chromium-review.googlesource.com/c/v8/v8/+/4429630 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2023-05-10 17:47:48 +03:00
const minimized = once(w, 'minimize');
w.minimize();
chore: bump chromium to 115.0.5760.0 (main) (#38033) * chore: bump chromium in DEPS to 114.0.5721.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5723.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5725.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5727.0 * chore: bump chromium in DEPS to 114.0.5729.0 * chore: bump chromium in DEPS to 114.0.5731.0 * chore: update patches * 4450570: Clean up content shell https://chromium-review.googlesource.com/c/chromium/src/+/4450570 * 4262527: geolocation: Introduce mojom::GeopositionResult https://chromium-review.googlesource.com/c/chromium/src/+/4262527 * 4450327: Android/Nav: Stop taking content timeout timer from old host. https://chromium-review.googlesource.com/c/chromium/src/+/4450327 Also, see: 4451366: Reland "Prerender: Fix prerender new content timeout start timing" https://chromium-review.googlesource.com/c/chromium/src/+/4451366 * chore: bump chromium in DEPS to 114.0.5733.2 * chore: update patches * chore: bump CircleCI xcode version this will hopefully get us the necessary macOS sdk 13.3 on CI. * chore: bump chromium in DEPS to 114.0.5735.0 * chore: update patches * test: fix geolocation test * chore: bump chromium in DEPS to 115.0.5736.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5738.0 * chore: update patches * fix: remove profiles from spellcheck service * chore: update libc++ filenames * chore: bump chromium in DEPS to 115.0.5740.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5742.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5744.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5746.0 * chore: update patches * chore: update filenames.libcxx.gni * chore: bump chromium in DEPS to 115.0.5748.0 * chore: update patches * build: update libcxx filenames * chore: bump chromium in DEPS to 115.0.5750.0 * chore: bump chromium in DEPS to 115.0.5752.2 * chore: bump chromium in DEPS to 115.0.5754.0 * chore: bump chromium in DEPS to 115.0.5756.0 * chore: bump chromium in DEPS to 115.0.5758.0 * chore: update patches * chore: update patch after rebase * 4500969: Delete content/dev_ui_content_resources.grd file. https://chromium-review.googlesource.com/c/chromium/src/+/4500969 * Use base.Value.Dict in OmahaAttributesHandler related code https://chromium-review.googlesource.com/c/chromium/src/+/4506402 * chore: bump chromium in DEPS to 115.0.5760.0 * chore: update patches * chore: fixup line endings * 4336172: Include client-drawn window decorations in aspect ratio. | Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4336172 (cherry picked from commit 27c2f6c43e8e4a792b33fdf8cf3af880376406be) * spec: fix race condition in alwaysOnTop test (cherry picked from commit 2ec5213fa0998d9cf21248257e7b5a5581044ea3) * build: use xcode 14.2 not 14.3 (cherry picked from commit b7c62351a77102e854a801c363f391b177ebf672) * build: use macOS 12 to run tests The new macOS 13 VMs appear to have different screen / display behavior (cherry picked from commit 14dc1dbc24cec85111a7482b49049f6acbfbc5f1) * Remove always-true flag --harmony-sharedarraybuffer https://chromium-review.googlesource.com/c/v8/v8/+/4429630 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2023-05-10 17:47:48 +03:00
await minimized;
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
chore: bump chromium to 115.0.5760.0 (main) (#38033) * chore: bump chromium in DEPS to 114.0.5721.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5723.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5725.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5727.0 * chore: bump chromium in DEPS to 114.0.5729.0 * chore: bump chromium in DEPS to 114.0.5731.0 * chore: update patches * 4450570: Clean up content shell https://chromium-review.googlesource.com/c/chromium/src/+/4450570 * 4262527: geolocation: Introduce mojom::GeopositionResult https://chromium-review.googlesource.com/c/chromium/src/+/4262527 * 4450327: Android/Nav: Stop taking content timeout timer from old host. https://chromium-review.googlesource.com/c/chromium/src/+/4450327 Also, see: 4451366: Reland "Prerender: Fix prerender new content timeout start timing" https://chromium-review.googlesource.com/c/chromium/src/+/4451366 * chore: bump chromium in DEPS to 114.0.5733.2 * chore: update patches * chore: bump CircleCI xcode version this will hopefully get us the necessary macOS sdk 13.3 on CI. * chore: bump chromium in DEPS to 114.0.5735.0 * chore: update patches * test: fix geolocation test * chore: bump chromium in DEPS to 115.0.5736.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5738.0 * chore: update patches * fix: remove profiles from spellcheck service * chore: update libc++ filenames * chore: bump chromium in DEPS to 115.0.5740.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5742.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5744.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5746.0 * chore: update patches * chore: update filenames.libcxx.gni * chore: bump chromium in DEPS to 115.0.5748.0 * chore: update patches * build: update libcxx filenames * chore: bump chromium in DEPS to 115.0.5750.0 * chore: bump chromium in DEPS to 115.0.5752.2 * chore: bump chromium in DEPS to 115.0.5754.0 * chore: bump chromium in DEPS to 115.0.5756.0 * chore: bump chromium in DEPS to 115.0.5758.0 * chore: update patches * chore: update patch after rebase * 4500969: Delete content/dev_ui_content_resources.grd file. https://chromium-review.googlesource.com/c/chromium/src/+/4500969 * Use base.Value.Dict in OmahaAttributesHandler related code https://chromium-review.googlesource.com/c/chromium/src/+/4506402 * chore: bump chromium in DEPS to 115.0.5760.0 * chore: update patches * chore: fixup line endings * 4336172: Include client-drawn window decorations in aspect ratio. | Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4336172 (cherry picked from commit 27c2f6c43e8e4a792b33fdf8cf3af880376406be) * spec: fix race condition in alwaysOnTop test (cherry picked from commit 2ec5213fa0998d9cf21248257e7b5a5581044ea3) * build: use xcode 14.2 not 14.3 (cherry picked from commit b7c62351a77102e854a801c363f391b177ebf672) * build: use macOS 12 to run tests The new macOS 13 VMs appear to have different screen / display behavior (cherry picked from commit 14dc1dbc24cec85111a7482b49049f6acbfbc5f1) * Remove always-true flag --harmony-sharedarraybuffer https://chromium-review.googlesource.com/c/v8/v8/+/4429630 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2023-05-10 17:47:48 +03:00
const restored = once(w, 'restore');
w.restore();
chore: bump chromium to 115.0.5760.0 (main) (#38033) * chore: bump chromium in DEPS to 114.0.5721.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5723.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5725.0 * chore: update patches * chore: bump chromium in DEPS to 114.0.5727.0 * chore: bump chromium in DEPS to 114.0.5729.0 * chore: bump chromium in DEPS to 114.0.5731.0 * chore: update patches * 4450570: Clean up content shell https://chromium-review.googlesource.com/c/chromium/src/+/4450570 * 4262527: geolocation: Introduce mojom::GeopositionResult https://chromium-review.googlesource.com/c/chromium/src/+/4262527 * 4450327: Android/Nav: Stop taking content timeout timer from old host. https://chromium-review.googlesource.com/c/chromium/src/+/4450327 Also, see: 4451366: Reland "Prerender: Fix prerender new content timeout start timing" https://chromium-review.googlesource.com/c/chromium/src/+/4451366 * chore: bump chromium in DEPS to 114.0.5733.2 * chore: update patches * chore: bump CircleCI xcode version this will hopefully get us the necessary macOS sdk 13.3 on CI. * chore: bump chromium in DEPS to 114.0.5735.0 * chore: update patches * test: fix geolocation test * chore: bump chromium in DEPS to 115.0.5736.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5738.0 * chore: update patches * fix: remove profiles from spellcheck service * chore: update libc++ filenames * chore: bump chromium in DEPS to 115.0.5740.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5742.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5744.0 * chore: update patches * chore: bump chromium in DEPS to 115.0.5746.0 * chore: update patches * chore: update filenames.libcxx.gni * chore: bump chromium in DEPS to 115.0.5748.0 * chore: update patches * build: update libcxx filenames * chore: bump chromium in DEPS to 115.0.5750.0 * chore: bump chromium in DEPS to 115.0.5752.2 * chore: bump chromium in DEPS to 115.0.5754.0 * chore: bump chromium in DEPS to 115.0.5756.0 * chore: bump chromium in DEPS to 115.0.5758.0 * chore: update patches * chore: update patch after rebase * 4500969: Delete content/dev_ui_content_resources.grd file. https://chromium-review.googlesource.com/c/chromium/src/+/4500969 * Use base.Value.Dict in OmahaAttributesHandler related code https://chromium-review.googlesource.com/c/chromium/src/+/4506402 * chore: bump chromium in DEPS to 115.0.5760.0 * chore: update patches * chore: fixup line endings * 4336172: Include client-drawn window decorations in aspect ratio. | Ref: https://chromium-review.googlesource.com/c/chromium/src/+/4336172 (cherry picked from commit 27c2f6c43e8e4a792b33fdf8cf3af880376406be) * spec: fix race condition in alwaysOnTop test (cherry picked from commit 2ec5213fa0998d9cf21248257e7b5a5581044ea3) * build: use xcode 14.2 not 14.3 (cherry picked from commit b7c62351a77102e854a801c363f391b177ebf672) * build: use macOS 12 to run tests The new macOS 13 VMs appear to have different screen / display behavior (cherry picked from commit 14dc1dbc24cec85111a7482b49049f6acbfbc5f1) * Remove always-true flag --harmony-sharedarraybuffer https://chromium-review.googlesource.com/c/v8/v8/+/4429630 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2023-05-10 17:47:48 +03:00
await restored;
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop');
});
it('causes the right value to be emitted on `always-on-top-changed`', async () => {
const alwaysOnTopChanged = once(w, 'always-on-top-changed') as Promise<[any, boolean]>;
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
w.setAlwaysOnTop(true);
const [, alwaysOnTop] = await alwaysOnTopChanged;
expect(alwaysOnTop).to.be.true('is not alwaysOnTop');
});
ifit(process.platform === 'darwin')('honors the alwaysOnTop level of a child window', () => {
w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ parent: w });
c.setAlwaysOnTop(true, 'screen-saver');
expect(w.isAlwaysOnTop()).to.be.false();
expect(c.isAlwaysOnTop()).to.be.true('child is not always on top');
expect(c._getAlwaysOnTopLevel()).to.equal('screen-saver');
});
it('works when called prior to show', async () => {
w = new BrowserWindow({ show: false });
w.setAlwaysOnTop(true, 'screen-saver');
w.show();
await setTimeout(1000);
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop');
});
it('works when called prior to showInactive', async () => {
w = new BrowserWindow({ show: false });
w.setAlwaysOnTop(true, 'screen-saver');
w.showInactive();
await setTimeout(1000);
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop');
});
});
describe('preconnect feature', () => {
let w: BrowserWindow;
let server: http.Server;
let url: string;
let connections = 0;
beforeEach(async () => {
connections = 0;
server = http.createServer((req, res) => {
if (req.url === '/link') {
res.setHeader('Content-type', 'text/html');
res.end('<head><link rel="preconnect" href="//example.com" /></head><body>foo</body>');
return;
}
res.end();
});
2019-11-01 23:37:02 +03:00
server.on('connection', () => { connections++; });
url = (await listen(server)).url;
});
afterEach(async () => {
server.close();
await closeWindow(w);
w = null as unknown as BrowserWindow;
server = null as unknown as http.Server;
});
it('calling preconnect() connects to the server', async () => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false });
w.webContents.on('did-start-navigation', (event, url) => {
w.webContents.session.preconnect({ url, numSockets: 4 });
});
await w.loadURL(url);
expect(connections).to.equal(4);
});
it('does not preconnect unless requested', async () => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false });
await w.loadURL(url);
expect(connections).to.equal(1);
});
it('parses <link rel=preconnect>', async () => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: true });
const p = once(w.webContents.session, 'preconnect');
w.loadURL(url + '/link');
const [, preconnectUrl, allowCredentials] = await p;
expect(preconnectUrl).to.equal('http://example.com/');
expect(allowCredentials).to.be.true('allowCredentials');
});
});
describe('BrowserWindow.setAutoHideCursor(autoHide)', () => {
let w: BrowserWindow;
beforeEach(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false });
});
afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});
ifit(process.platform === 'darwin')('on macOS', () => {
it('allows changing cursor auto-hiding', () => {
expect(() => {
w.setAutoHideCursor(false);
w.setAutoHideCursor(true);
}).to.not.throw();
});
});
ifit(process.platform !== 'darwin')('on non-macOS platforms', () => {
it('is not available', () => {
expect(w.setAutoHideCursor).to.be.undefined('setAutoHideCursor function');
});
});
});
ifdescribe(process.platform === 'darwin')('BrowserWindow.setWindowButtonVisibility()', () => {
afterEach(closeAllWindows);
it('does not throw', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
expect(() => {
w.setWindowButtonVisibility(true);
w.setWindowButtonVisibility(false);
}).to.not.throw();
});
it('changes window button visibility for normal window', () => {
const w = new BrowserWindow({ show: false });
expect(w._getWindowButtonVisibility()).to.equal(true);
w.setWindowButtonVisibility(false);
expect(w._getWindowButtonVisibility()).to.equal(false);
w.setWindowButtonVisibility(true);
expect(w._getWindowButtonVisibility()).to.equal(true);
});
it('changes window button visibility for frameless window', () => {
const w = new BrowserWindow({ show: false, frame: false });
expect(w._getWindowButtonVisibility()).to.equal(false);
w.setWindowButtonVisibility(true);
expect(w._getWindowButtonVisibility()).to.equal(true);
w.setWindowButtonVisibility(false);
expect(w._getWindowButtonVisibility()).to.equal(false);
});
it('changes window button visibility for hiddenInset window', () => {
const w = new BrowserWindow({ show: false, frame: false, titleBarStyle: 'hiddenInset' });
expect(w._getWindowButtonVisibility()).to.equal(true);
w.setWindowButtonVisibility(false);
expect(w._getWindowButtonVisibility()).to.equal(false);
w.setWindowButtonVisibility(true);
expect(w._getWindowButtonVisibility()).to.equal(true);
});
// Buttons of customButtonsOnHover are always hidden unless hovered.
it('does not change window button visibility for customButtonsOnHover window', () => {
const w = new BrowserWindow({ show: false, frame: false, titleBarStyle: 'customButtonsOnHover' });
expect(w._getWindowButtonVisibility()).to.equal(false);
w.setWindowButtonVisibility(true);
expect(w._getWindowButtonVisibility()).to.equal(false);
w.setWindowButtonVisibility(false);
expect(w._getWindowButtonVisibility()).to.equal(false);
});
it('correctly updates when entering/exiting fullscreen for hidden style', async () => {
const w = new BrowserWindow({ show: false, frame: false, titleBarStyle: 'hidden' });
expect(w._getWindowButtonVisibility()).to.equal(true);
w.setWindowButtonVisibility(false);
expect(w._getWindowButtonVisibility()).to.equal(false);
const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
const leaveFS = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFS;
w.setWindowButtonVisibility(true);
expect(w._getWindowButtonVisibility()).to.equal(true);
});
it('correctly updates when entering/exiting fullscreen for hiddenInset style', async () => {
const w = new BrowserWindow({ show: false, frame: false, titleBarStyle: 'hiddenInset' });
expect(w._getWindowButtonVisibility()).to.equal(true);
w.setWindowButtonVisibility(false);
expect(w._getWindowButtonVisibility()).to.equal(false);
const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
const leaveFS = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFS;
w.setWindowButtonVisibility(true);
expect(w._getWindowButtonVisibility()).to.equal(true);
});
});
ifdescribe(process.platform === 'darwin')('BrowserWindow.setVibrancy(type)', () => {
afterEach(closeAllWindows);
it('allows setting, changing, and removing the vibrancy', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
expect(() => {
chore: bump chromium to 117.0.5852.0 (main) (#38891) * chore: bump chromium in DEPS to 117.0.5846.0 * chore: update patches * 4628901: Bump the macOS deployment target to 10.15 https://chromium-review.googlesource.com/c/chromium/src/+/4628901 * 4593350: [Private Network Access] Trigger Permission Prompt https://chromium-review.googlesource.com/c/chromium/src/+/4593350 * 4631011: Remove unlaunched "InstallReplacementAndroidApp" Platform App APIs https://chromium-review.googlesource.com/c/chromium/src/+/4631011 * chore: disable API deprecation warnings in NSKeyedArchiver * chore: update libcxx filenames * chore: bump chromium in DEPS to 117.0.5848.2 * chore: update feat_add_set_theme_source_to_allow_apps_to.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4629743 No manual changes; patch succeeded with fuzz * chore: update process_singleton.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4605398 Trivial manual patch adjustments to account for code shear. * chore: remove electron::BrowserContext::GetMediaDeviceIDSalt() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4608130 upstream tldr: - content::BrowserContext::GetMediaDeviceIDSalt() - content::ContentBrowserClient::ArePersistentMediaDeviceIDsAllowed() + content::ContentBrowserClient::GetMediaDeviceIDSalt() This commit leaves ElectronBrowserContext::GetMediaDeviceIDSalt() in place (now non-virtual, non-override). It is now called by the new function ElectronBrowserClient::GetMediaDeviceIDSalt(). As a followup, we might want to consider using the new upstream media_device_salt::MediaDeviceSaltService and removing our electron::MediaDeviceIDSalt code. CC @MarshallOfSound for 2nd opinion since he has done the most work on MediaDeviceIDSalt and may have more context. * chore: fix iwyu breakage Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4629624 electron_browser_main_parts.cc uses ui::ColorProviderManager but didn't include it. Things worked anyway because we got it indirectly from content/public/browser/web_contents.h until 4629624. * chore: remove call to base::mac::IsAtLeastOS10_14 upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove obsolete API_AVAILABLE calls in IAP upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove obsolete API_AVAILABLE calls in electron_application_delegate upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove broken-before-macOS-10.15 patch in mas_avoid_usage_of_private_macos_apis.patch Upstream has bumped minimum to macOS 10.15 * chore: remove @available(macOS 10.14) check Upstream minimum requirement for macOS is now 10.15 * chore: update patches * chore: bump chromium in DEPS to 117.0.5850.0 * chore: update patches * chore: bump chromium in DEPS to 117.0.5852.0 * chore: update patches * Move two params from NetworkContextParams to NetworkContextFilePaths. https://chromium-review.googlesource.com/c/chromium/src/+/4615930 * WebUSB: Add exclusionFilters to USBRequestDeviceOptions https://chromium-review.googlesource.com/c/chromium/src/+/4614682 * Convert /chrome/browser/ui to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4615920 * fixup! Bump the macOS deployment target to 10.15 * fixup! Bump the macOS deployment target to 10.15 * chore: update libcxx files * win: Remove 10Glass from Windows10Glass function and var names https://chromium-review.googlesource.com/c/chromium/src/+/4641314 * chore: revert 392e5f43 from chromium * Add an ExecutionContext to ScriptState https://chromium-review.googlesource.com/c/chromium/src/+/4609446 * fixup! Add an ExecutionContext to ScriptState * chore: fix header * Revert "chore: revert 392e5f43 from chromium" This reverts commit b7f782943e4ce83cae8cd35780d8d3618cf0772c. * fix: return correct min/max sizes in WinFrameView * fixup! Revert chore: revert 392e5f43 from chromium * fixup! Add an ExecutionContext to ScriptState * Revert "fixup! Revert chore: revert 392e5f43 from chromium" This reverts commit 7e2c7281abfc4f309255339fdba073d90a9ae3eb. * Revert "fix: return correct min/max sizes in WinFrameView" This reverts commit 3f418b1ab5155686730e087ae6cabe4a21b4bb61. * Revert "Revert "chore: revert 392e5f43 from chromium"" This reverts commit 56296d8b7c434147e032e3c3b08c0e371b6c27ba. --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
2023-07-01 23:22:55 +03:00
w.setVibrancy('titlebar');
w.setVibrancy('selection');
w.setVibrancy(null);
chore: bump chromium to 117.0.5852.0 (main) (#38891) * chore: bump chromium in DEPS to 117.0.5846.0 * chore: update patches * 4628901: Bump the macOS deployment target to 10.15 https://chromium-review.googlesource.com/c/chromium/src/+/4628901 * 4593350: [Private Network Access] Trigger Permission Prompt https://chromium-review.googlesource.com/c/chromium/src/+/4593350 * 4631011: Remove unlaunched "InstallReplacementAndroidApp" Platform App APIs https://chromium-review.googlesource.com/c/chromium/src/+/4631011 * chore: disable API deprecation warnings in NSKeyedArchiver * chore: update libcxx filenames * chore: bump chromium in DEPS to 117.0.5848.2 * chore: update feat_add_set_theme_source_to_allow_apps_to.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4629743 No manual changes; patch succeeded with fuzz * chore: update process_singleton.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4605398 Trivial manual patch adjustments to account for code shear. * chore: remove electron::BrowserContext::GetMediaDeviceIDSalt() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4608130 upstream tldr: - content::BrowserContext::GetMediaDeviceIDSalt() - content::ContentBrowserClient::ArePersistentMediaDeviceIDsAllowed() + content::ContentBrowserClient::GetMediaDeviceIDSalt() This commit leaves ElectronBrowserContext::GetMediaDeviceIDSalt() in place (now non-virtual, non-override). It is now called by the new function ElectronBrowserClient::GetMediaDeviceIDSalt(). As a followup, we might want to consider using the new upstream media_device_salt::MediaDeviceSaltService and removing our electron::MediaDeviceIDSalt code. CC @MarshallOfSound for 2nd opinion since he has done the most work on MediaDeviceIDSalt and may have more context. * chore: fix iwyu breakage Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4629624 electron_browser_main_parts.cc uses ui::ColorProviderManager but didn't include it. Things worked anyway because we got it indirectly from content/public/browser/web_contents.h until 4629624. * chore: remove call to base::mac::IsAtLeastOS10_14 upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove obsolete API_AVAILABLE calls in IAP upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove obsolete API_AVAILABLE calls in electron_application_delegate upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove broken-before-macOS-10.15 patch in mas_avoid_usage_of_private_macos_apis.patch Upstream has bumped minimum to macOS 10.15 * chore: remove @available(macOS 10.14) check Upstream minimum requirement for macOS is now 10.15 * chore: update patches * chore: bump chromium in DEPS to 117.0.5850.0 * chore: update patches * chore: bump chromium in DEPS to 117.0.5852.0 * chore: update patches * Move two params from NetworkContextParams to NetworkContextFilePaths. https://chromium-review.googlesource.com/c/chromium/src/+/4615930 * WebUSB: Add exclusionFilters to USBRequestDeviceOptions https://chromium-review.googlesource.com/c/chromium/src/+/4614682 * Convert /chrome/browser/ui to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4615920 * fixup! Bump the macOS deployment target to 10.15 * fixup! Bump the macOS deployment target to 10.15 * chore: update libcxx files * win: Remove 10Glass from Windows10Glass function and var names https://chromium-review.googlesource.com/c/chromium/src/+/4641314 * chore: revert 392e5f43 from chromium * Add an ExecutionContext to ScriptState https://chromium-review.googlesource.com/c/chromium/src/+/4609446 * fixup! Add an ExecutionContext to ScriptState * chore: fix header * Revert "chore: revert 392e5f43 from chromium" This reverts commit b7f782943e4ce83cae8cd35780d8d3618cf0772c. * fix: return correct min/max sizes in WinFrameView * fixup! Revert chore: revert 392e5f43 from chromium * fixup! Add an ExecutionContext to ScriptState * Revert "fixup! Revert chore: revert 392e5f43 from chromium" This reverts commit 7e2c7281abfc4f309255339fdba073d90a9ae3eb. * Revert "fix: return correct min/max sizes in WinFrameView" This reverts commit 3f418b1ab5155686730e087ae6cabe4a21b4bb61. * Revert "Revert "chore: revert 392e5f43 from chromium"" This reverts commit 56296d8b7c434147e032e3c3b08c0e371b6c27ba. --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
2023-07-01 23:22:55 +03:00
w.setVibrancy('menu');
w.setVibrancy('' as any);
}).to.not.throw();
});
it('does not crash if vibrancy is set to an invalid value', () => {
const w = new BrowserWindow({ show: false });
expect(() => {
w.setVibrancy('i-am-not-a-valid-vibrancy-type' as any);
}).to.not.throw();
});
});
ifdescribe(process.platform === 'darwin')('trafficLightPosition', () => {
const pos = { x: 10, y: 10 };
afterEach(closeAllWindows);
describe('BrowserWindow.getWindowButtonPosition(pos)', () => {
it('returns null when there is no custom position', () => {
const w = new BrowserWindow({ show: false });
expect(w.getWindowButtonPosition()).to.be.null('getWindowButtonPosition');
});
it('gets position property for "hidden" titleBarStyle', () => {
const w = new BrowserWindow({ show: false, titleBarStyle: 'hidden', trafficLightPosition: pos });
expect(w.getWindowButtonPosition()).to.deep.equal(pos);
});
it('gets position property for "customButtonsOnHover" titleBarStyle', () => {
const w = new BrowserWindow({ show: false, titleBarStyle: 'customButtonsOnHover', trafficLightPosition: pos });
expect(w.getWindowButtonPosition()).to.deep.equal(pos);
});
});
describe('BrowserWindow.setWindowButtonPosition(pos)', () => {
it('resets the position when null is passed', () => {
const w = new BrowserWindow({ show: false, titleBarStyle: 'hidden', trafficLightPosition: pos });
w.setWindowButtonPosition(null);
expect(w.getWindowButtonPosition()).to.be.null('setWindowButtonPosition');
});
it('sets position property for "hidden" titleBarStyle', () => {
const w = new BrowserWindow({ show: false, titleBarStyle: 'hidden', trafficLightPosition: pos });
const newPos = { x: 20, y: 20 };
w.setWindowButtonPosition(newPos);
expect(w.getWindowButtonPosition()).to.deep.equal(newPos);
});
it('sets position property for "customButtonsOnHover" titleBarStyle', () => {
const w = new BrowserWindow({ show: false, titleBarStyle: 'customButtonsOnHover', trafficLightPosition: pos });
const newPos = { x: 20, y: 20 };
w.setWindowButtonPosition(newPos);
expect(w.getWindowButtonPosition()).to.deep.equal(newPos);
});
});
});
ifdescribe(process.platform === 'win32')('BrowserWindow.setAppDetails(options)', () => {
afterEach(closeAllWindows);
it('supports setting the app details', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const iconPath = path.join(fixtures, 'assets', 'icon.ico');
expect(() => {
w.setAppDetails({ appId: 'my.app.id' });
w.setAppDetails({ appIconPath: iconPath, appIconIndex: 0 });
w.setAppDetails({ appIconPath: iconPath });
w.setAppDetails({ relaunchCommand: 'my-app.exe arg1 arg2', relaunchDisplayName: 'My app name' });
w.setAppDetails({ relaunchCommand: 'my-app.exe arg1 arg2' });
w.setAppDetails({ relaunchDisplayName: 'My app name' });
w.setAppDetails({
appId: 'my.app.id',
appIconPath: iconPath,
appIconIndex: 0,
relaunchCommand: 'my-app.exe arg1 arg2',
relaunchDisplayName: 'My app name'
});
w.setAppDetails({});
}).to.not.throw();
expect(() => {
(w.setAppDetails as any)();
}).to.throw('Insufficient number of arguments.');
});
});
describe('BrowserWindow.fromId(id)', () => {
afterEach(closeAllWindows);
it('returns the window with id', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
expect(BrowserWindow.fromId(w.id)!.id).to.equal(w.id);
});
});
describe('Opening a BrowserWindow from a link', () => {
let appProcess: childProcess.ChildProcessWithoutNullStreams | undefined;
afterEach(() => {
if (appProcess && !appProcess.killed) {
appProcess.kill();
appProcess = undefined;
}
});
it('can properly open and load a new window from a link', async () => {
const appPath = path.join(__dirname, 'fixtures', 'apps', 'open-new-window-from-link');
appProcess = childProcess.spawn(process.execPath, [appPath]);
const [code] = await once(appProcess, 'exit');
expect(code).to.equal(0);
});
});
describe('BrowserWindow.fromWebContents(webContents)', () => {
afterEach(closeAllWindows);
it('returns the window with the webContents', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const found = BrowserWindow.fromWebContents(w.webContents);
expect(found!.id).to.equal(w.id);
});
it('returns null for webContents without a BrowserWindow', () => {
const contents = (webContents as typeof ElectronInternal.WebContents).create();
try {
expect(BrowserWindow.fromWebContents(contents)).to.be.null('BrowserWindow.fromWebContents(contents)');
} finally {
contents.destroy();
}
});
it('returns the correct window for a BrowserView webcontents', async () => {
const w = new BrowserWindow({ show: false });
const bv = new BrowserView();
w.setBrowserView(bv);
defer(() => {
w.removeBrowserView(bv);
bv.webContents.destroy();
});
await bv.webContents.loadURL('about:blank');
expect(BrowserWindow.fromWebContents(bv.webContents)!.id).to.equal(w.id);
});
it('returns the correct window for a WebView webcontents', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webviewTag: true } });
w.loadURL('data:text/html,<webview src="data:text/html,hi"></webview>');
// NOTE(nornagon): Waiting for 'did-attach-webview' is a workaround for
// https://github.com/electron/electron/issues/25413, and is not integral
// to the test.
const p = once(w.webContents, 'did-attach-webview');
const [, webviewContents] = await once(app, 'web-contents-created') as [any, WebContents];
expect(BrowserWindow.fromWebContents(webviewContents)!.id).to.equal(w.id);
await p;
});
it('is usable immediately on browser-window-created', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('window.open(""); null');
const [win, winFromWebContents] = await new Promise<any>((resolve) => {
app.once('browser-window-created', (e, win) => {
resolve([win, BrowserWindow.fromWebContents(win.webContents)]);
});
});
expect(winFromWebContents).to.equal(win);
});
});
describe('BrowserWindow.openDevTools()', () => {
afterEach(closeAllWindows);
it('does not crash for frameless window', () => {
const w = new BrowserWindow({ show: false, frame: false });
w.webContents.openDevTools();
});
});
describe('BrowserWindow.fromBrowserView(browserView)', () => {
afterEach(closeAllWindows);
it('returns the window with the BrowserView', () => {
const w = new BrowserWindow({ show: false });
2019-11-01 23:37:02 +03:00
const bv = new BrowserView();
w.setBrowserView(bv);
2020-07-09 18:48:39 +03:00
defer(() => {
w.removeBrowserView(bv);
bv.webContents.destroy();
2020-07-09 18:48:39 +03:00
});
expect(BrowserWindow.fromBrowserView(bv)!.id).to.equal(w.id);
});
it('returns the window when there are multiple BrowserViews', () => {
const w = new BrowserWindow({ show: false });
const bv1 = new BrowserView();
w.addBrowserView(bv1);
const bv2 = new BrowserView();
w.addBrowserView(bv2);
defer(() => {
w.removeBrowserView(bv1);
w.removeBrowserView(bv2);
bv1.webContents.destroy();
bv2.webContents.destroy();
});
expect(BrowserWindow.fromBrowserView(bv1)!.id).to.equal(w.id);
expect(BrowserWindow.fromBrowserView(bv2)!.id).to.equal(w.id);
});
it('returns undefined if not attached', () => {
2019-11-01 23:37:02 +03:00
const bv = new BrowserView();
2020-07-09 18:48:39 +03:00
defer(() => {
bv.webContents.destroy();
2020-07-09 18:48:39 +03:00
});
expect(BrowserWindow.fromBrowserView(bv)).to.be.null('BrowserWindow associated with bv');
});
});
describe('BrowserWindow.setOpacity(opacity)', () => {
afterEach(closeAllWindows);
ifdescribe(process.platform !== 'linux')(('Windows and Mac'), () => {
it('make window with initial opacity', () => {
const w = new BrowserWindow({ show: false, opacity: 0.5 });
expect(w.getOpacity()).to.equal(0.5);
});
it('allows setting the opacity', () => {
const w = new BrowserWindow({ show: false });
expect(() => {
w.setOpacity(0.0);
expect(w.getOpacity()).to.equal(0.0);
w.setOpacity(0.5);
expect(w.getOpacity()).to.equal(0.5);
w.setOpacity(1.0);
expect(w.getOpacity()).to.equal(1.0);
}).to.not.throw();
});
it('clamps opacity to [0.0...1.0]', () => {
const w = new BrowserWindow({ show: false, opacity: 0.5 });
w.setOpacity(100);
expect(w.getOpacity()).to.equal(1.0);
w.setOpacity(-100);
expect(w.getOpacity()).to.equal(0.0);
});
});
ifdescribe(process.platform === 'linux')(('Linux'), () => {
it('sets 1 regardless of parameter', () => {
const w = new BrowserWindow({ show: false });
w.setOpacity(0);
expect(w.getOpacity()).to.equal(1.0);
w.setOpacity(0.5);
expect(w.getOpacity()).to.equal(1.0);
});
});
});
describe('BrowserWindow.setShape(rects)', () => {
afterEach(closeAllWindows);
it('allows setting shape', () => {
const w = new BrowserWindow({ show: false });
expect(() => {
w.setShape([]);
w.setShape([{ x: 0, y: 0, width: 100, height: 100 }]);
w.setShape([{ x: 0, y: 0, width: 100, height: 100 }, { x: 0, y: 200, width: 1000, height: 100 }]);
w.setShape([]);
}).to.not.throw();
});
});
describe('"useContentSize" option', () => {
afterEach(closeAllWindows);
it('make window created with content size when used', () => {
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
useContentSize: true
});
const contentSize = w.getContentSize();
expect(contentSize).to.deep.equal([400, 400]);
});
it('make window created with window size when not used', () => {
const w = new BrowserWindow({
show: false,
width: 400,
2019-11-01 23:37:02 +03:00
height: 400
});
const size = w.getSize();
expect(size).to.deep.equal([400, 400]);
});
it('works for a frameless window', () => {
const w = new BrowserWindow({
show: false,
frame: false,
width: 400,
height: 400,
useContentSize: true
});
const contentSize = w.getContentSize();
expect(contentSize).to.deep.equal([400, 400]);
const size = w.getSize();
expect(size).to.deep.equal([400, 400]);
});
});
describe('"titleBarStyle" option', () => {
const testWindowsOverlay = async (style: any) => {
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
titleBarStyle: style,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
titleBarOverlay: true
});
const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');
feat: enable windows control overlay on Windows (#29600) * rebase "feat: enable windows control overlay on Windows" * correct compilation error * fix linting errors * modify includes and build file * change `hidden` option to `overlay` * add patch to fix visual layout * add button background color parameter * add button text color parameter * modify `overlay` in docs and modify button hover/press transition color * change `text` to `symbol` * remove todo and fix `text` replacement * add new titleBarOverlay property and remove titleBarStyle `overlay` * update browser and frameless window docs * remove chromium patches * chore: update patches * change button hover color, update trailing `_`, update test file * add dchecks, update title bar drawing checks, update test file * modify for mac and linux builds * update docs with overlayColor and overlaySymbolColor * add corner and side hit test info * modify docs and copyright info * modify `titlebar_overlay_` as boolean or object * move `title_bar_style_ to `NativeWindow` * update docs with boolean and object titlebar_overlay_ * add `IsEmpty` checks * move get options for boolean and object checks * fix linting error * disable `use_lld` for macos * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Apply docs suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * modify `true` option description `titleBarOverlay` * ci: cleanup keychain after tests on arm64 mac (#30472) Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-08-11 21:07:36 +03:00
if (process.platform === 'darwin') {
await w.loadFile(overlayHTML);
} else {
const overlayReady = once(ipcMain, 'geometrychange');
feat: enable windows control overlay on Windows (#29600) * rebase "feat: enable windows control overlay on Windows" * correct compilation error * fix linting errors * modify includes and build file * change `hidden` option to `overlay` * add patch to fix visual layout * add button background color parameter * add button text color parameter * modify `overlay` in docs and modify button hover/press transition color * change `text` to `symbol` * remove todo and fix `text` replacement * add new titleBarOverlay property and remove titleBarStyle `overlay` * update browser and frameless window docs * remove chromium patches * chore: update patches * change button hover color, update trailing `_`, update test file * add dchecks, update title bar drawing checks, update test file * modify for mac and linux builds * update docs with overlayColor and overlaySymbolColor * add corner and side hit test info * modify docs and copyright info * modify `titlebar_overlay_` as boolean or object * move `title_bar_style_ to `NativeWindow` * update docs with boolean and object titlebar_overlay_ * add `IsEmpty` checks * move get options for boolean and object checks * fix linting error * disable `use_lld` for macos * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Apply docs suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * modify `true` option description `titleBarOverlay` * ci: cleanup keychain after tests on arm64 mac (#30472) Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-08-11 21:07:36 +03:00
await w.loadFile(overlayHTML);
await overlayReady;
}
const overlayEnabled = await w.webContents.executeJavaScript('navigator.windowControlsOverlay.visible');
expect(overlayEnabled).to.be.true('overlayEnabled');
const overlayRect = await w.webContents.executeJavaScript('getJSOverlayProperties()');
expect(overlayRect.y).to.equal(0);
feat: enable windows control overlay on Windows (#29600) * rebase "feat: enable windows control overlay on Windows" * correct compilation error * fix linting errors * modify includes and build file * change `hidden` option to `overlay` * add patch to fix visual layout * add button background color parameter * add button text color parameter * modify `overlay` in docs and modify button hover/press transition color * change `text` to `symbol` * remove todo and fix `text` replacement * add new titleBarOverlay property and remove titleBarStyle `overlay` * update browser and frameless window docs * remove chromium patches * chore: update patches * change button hover color, update trailing `_`, update test file * add dchecks, update title bar drawing checks, update test file * modify for mac and linux builds * update docs with overlayColor and overlaySymbolColor * add corner and side hit test info * modify docs and copyright info * modify `titlebar_overlay_` as boolean or object * move `title_bar_style_ to `NativeWindow` * update docs with boolean and object titlebar_overlay_ * add `IsEmpty` checks * move get options for boolean and object checks * fix linting error * disable `use_lld` for macos * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Apply docs suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * modify `true` option description `titleBarOverlay` * ci: cleanup keychain after tests on arm64 mac (#30472) Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-08-11 21:07:36 +03:00
if (process.platform === 'darwin') {
expect(overlayRect.x).to.be.greaterThan(0);
} else {
expect(overlayRect.x).to.equal(0);
}
expect(overlayRect.width).to.be.greaterThan(0);
expect(overlayRect.height).to.be.greaterThan(0);
const cssOverlayRect = await w.webContents.executeJavaScript('getCssOverlayProperties();');
expect(cssOverlayRect).to.deep.equal(overlayRect);
const geometryChange = once(ipcMain, 'geometrychange');
w.setBounds({ width: 800 });
const [, newOverlayRect] = await geometryChange;
expect(newOverlayRect.width).to.equal(overlayRect.width + 400);
};
afterEach(async () => {
await closeAllWindows();
ipcMain.removeAllListeners('geometrychange');
});
it('creates browser window with hidden title bar', () => {
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
titleBarStyle: 'hidden'
});
const contentSize = w.getContentSize();
expect(contentSize).to.deep.equal([400, 400]);
});
feat: enable windows control overlay on Windows (#29600) * rebase "feat: enable windows control overlay on Windows" * correct compilation error * fix linting errors * modify includes and build file * change `hidden` option to `overlay` * add patch to fix visual layout * add button background color parameter * add button text color parameter * modify `overlay` in docs and modify button hover/press transition color * change `text` to `symbol` * remove todo and fix `text` replacement * add new titleBarOverlay property and remove titleBarStyle `overlay` * update browser and frameless window docs * remove chromium patches * chore: update patches * change button hover color, update trailing `_`, update test file * add dchecks, update title bar drawing checks, update test file * modify for mac and linux builds * update docs with overlayColor and overlaySymbolColor * add corner and side hit test info * modify docs and copyright info * modify `titlebar_overlay_` as boolean or object * move `title_bar_style_ to `NativeWindow` * update docs with boolean and object titlebar_overlay_ * add `IsEmpty` checks * move get options for boolean and object checks * fix linting error * disable `use_lld` for macos * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Apply docs suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * modify `true` option description `titleBarOverlay` * ci: cleanup keychain after tests on arm64 mac (#30472) Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-08-11 21:07:36 +03:00
ifit(process.platform === 'darwin')('creates browser window with hidden inset title bar', () => {
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
titleBarStyle: 'hiddenInset'
});
const contentSize = w.getContentSize();
expect(contentSize).to.deep.equal([400, 400]);
});
it('sets Window Control Overlay with hidden title bar', async () => {
await testWindowsOverlay('hidden');
});
feat: enable windows control overlay on Windows (#29600) * rebase "feat: enable windows control overlay on Windows" * correct compilation error * fix linting errors * modify includes and build file * change `hidden` option to `overlay` * add patch to fix visual layout * add button background color parameter * add button text color parameter * modify `overlay` in docs and modify button hover/press transition color * change `text` to `symbol` * remove todo and fix `text` replacement * add new titleBarOverlay property and remove titleBarStyle `overlay` * update browser and frameless window docs * remove chromium patches * chore: update patches * change button hover color, update trailing `_`, update test file * add dchecks, update title bar drawing checks, update test file * modify for mac and linux builds * update docs with overlayColor and overlaySymbolColor * add corner and side hit test info * modify docs and copyright info * modify `titlebar_overlay_` as boolean or object * move `title_bar_style_ to `NativeWindow` * update docs with boolean and object titlebar_overlay_ * add `IsEmpty` checks * move get options for boolean and object checks * fix linting error * disable `use_lld` for macos * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Update docs/api/frameless-window.md Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> * Apply docs suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * modify `true` option description `titleBarOverlay` * ci: cleanup keychain after tests on arm64 mac (#30472) Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-08-11 21:07:36 +03:00
ifit(process.platform === 'darwin')('sets Window Control Overlay with hidden inset title bar', async () => {
await testWindowsOverlay('hiddenInset');
});
ifdescribe(process.platform !== 'darwin')('when an invalid titleBarStyle is initially set', () => {
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
titleBarOverlay: {
color: '#0000f0',
symbolColor: '#ffffff'
},
titleBarStyle: 'hiddenInset'
});
});
afterEach(async () => {
await closeAllWindows();
});
it('does not crash changing minimizability ', () => {
expect(() => {
w.setMinimizable(false);
}).to.not.throw();
});
it('does not crash changing maximizability', () => {
expect(() => {
w.setMaximizable(false);
}).to.not.throw();
});
});
});
describe('"titleBarOverlay" option', () => {
const testWindowsOverlayHeight = async (size: any) => {
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
titleBarStyle: 'hidden',
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
titleBarOverlay: {
height: size
}
});
const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');
if (process.platform === 'darwin') {
await w.loadFile(overlayHTML);
} else {
const overlayReady = once(ipcMain, 'geometrychange');
await w.loadFile(overlayHTML);
await overlayReady;
}
const overlayEnabled = await w.webContents.executeJavaScript('navigator.windowControlsOverlay.visible');
expect(overlayEnabled).to.be.true('overlayEnabled');
const overlayRectPreMax = await w.webContents.executeJavaScript('getJSOverlayProperties()');
expect(overlayRectPreMax.y).to.equal(0);
if (process.platform === 'darwin') {
expect(overlayRectPreMax.x).to.be.greaterThan(0);
} else {
expect(overlayRectPreMax.x).to.equal(0);
}
expect(overlayRectPreMax.width).to.be.greaterThan(0);
expect(overlayRectPreMax.height).to.equal(size);
// 'maximize' event is not emitted on Linux in CI.
if (process.platform !== 'linux' && !w.isMaximized()) {
const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
expect(w.isMaximized()).to.be.true('not maximized');
const overlayRectPostMax = await w.webContents.executeJavaScript('getJSOverlayProperties()');
expect(overlayRectPostMax.height).to.equal(size);
}
};
afterEach(async () => {
await closeAllWindows();
ipcMain.removeAllListeners('geometrychange');
});
it('sets Window Control Overlay with title bar height of 40', async () => {
await testWindowsOverlayHeight(40);
});
});
ifdescribe(process.platform !== 'darwin')('BrowserWindow.setTitlebarOverlay', () => {
afterEach(async () => {
await closeAllWindows();
ipcMain.removeAllListeners('geometrychange');
});
it('throws when an invalid titleBarStyle is initially set', () => {
const win = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
titleBarOverlay: {
color: '#0000f0',
symbolColor: '#ffffff'
},
titleBarStyle: 'hiddenInset'
});
expect(() => {
win.setTitleBarOverlay({
color: '#000000'
});
}).to.throw('Titlebar overlay is not enabled');
});
it('correctly updates the height of the overlay', async () => {
const testOverlay = async (w: BrowserWindow, size: Number, firstRun: boolean) => {
const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');
const overlayReady = once(ipcMain, 'geometrychange');
await w.loadFile(overlayHTML);
if (firstRun) {
await overlayReady;
}
const overlayEnabled = await w.webContents.executeJavaScript('navigator.windowControlsOverlay.visible');
expect(overlayEnabled).to.be.true('overlayEnabled');
const { height: preMaxHeight } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
expect(preMaxHeight).to.equal(size);
// 'maximize' event is not emitted on Linux in CI.
if (process.platform !== 'linux' && !w.isMaximized()) {
const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
expect(w.isMaximized()).to.be.true('not maximized');
const { x, y, width, height } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
expect(x).to.equal(0);
expect(y).to.equal(0);
expect(width).to.be.greaterThan(0);
expect(height).to.equal(size);
}
};
const INITIAL_SIZE = 40;
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
titleBarStyle: 'hidden',
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
titleBarOverlay: {
height: INITIAL_SIZE
}
});
await testOverlay(w, INITIAL_SIZE, true);
w.setTitleBarOverlay({
height: INITIAL_SIZE + 10
});
await testOverlay(w, INITIAL_SIZE + 10, false);
});
});
ifdescribe(process.platform === 'darwin')('"enableLargerThanScreen" option', () => {
afterEach(closeAllWindows);
it('can move the window out of screen', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: true });
w.setPosition(-10, 50);
const after = w.getPosition();
expect(after).to.deep.equal([-10, 50]);
});
it('cannot move the window behind menu bar', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: true });
w.setPosition(-10, -10);
const after = w.getPosition();
expect(after[1]).to.be.at.least(0);
});
it('can move the window behind menu bar if it has no frame', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: true, frame: false });
w.setPosition(-10, -10);
const after = w.getPosition();
expect(after[0]).to.be.equal(-10);
expect(after[1]).to.be.equal(-10);
});
it('without it, cannot move the window out of screen', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: false });
w.setPosition(-10, -10);
const after = w.getPosition();
expect(after[1]).to.be.at.least(0);
});
it('can set the window larger than screen', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: true });
const size = screen.getPrimaryDisplay().size;
size.width += 100;
size.height += 100;
w.setSize(size.width, size.height);
expectBoundsEqual(w.getSize(), [size.width, size.height]);
});
it('without it, cannot set the window larger than screen', () => {
const w = new BrowserWindow({ show: true, enableLargerThanScreen: false });
const size = screen.getPrimaryDisplay().size;
size.width += 100;
size.height += 100;
w.setSize(size.width, size.height);
expect(w.getSize()[1]).to.at.most(screen.getPrimaryDisplay().size.height);
});
});
ifdescribe(process.platform === 'darwin')('"zoomToPageWidth" option', () => {
afterEach(closeAllWindows);
it('sets the window width to the page width when used', () => {
const w = new BrowserWindow({
show: false,
width: 500,
height: 400,
zoomToPageWidth: true
});
w.maximize();
expect(w.getSize()[0]).to.equal(500);
});
});
describe('"tabbingIdentifier" option', () => {
afterEach(closeAllWindows);
it('can be set on a window', () => {
expect(() => {
/* eslint-disable-next-line no-new */
new BrowserWindow({
tabbingIdentifier: 'group1'
});
/* eslint-disable-next-line no-new */
new BrowserWindow({
tabbingIdentifier: 'group2',
frame: false
});
}).not.to.throw();
});
});
describe('"webPreferences" option', () => {
afterEach(() => { ipcMain.removeAllListeners('answer'); });
afterEach(closeAllWindows);
describe('"preload" option', () => {
const doesNotLeakSpec = (name: string, webPrefs: { nodeIntegration: boolean, sandbox: boolean, contextIsolation: boolean }) => {
it(name, async () => {
const w = new BrowserWindow({
webPreferences: {
...webPrefs,
preload: path.resolve(fixtures, 'module', 'empty.js')
},
show: false
});
w.loadFile(path.join(fixtures, 'api', 'no-leak.html'));
const [, result] = await once(ipcMain, 'leak-result');
expect(result).to.have.property('require', 'undefined');
expect(result).to.have.property('exports', 'undefined');
expect(result).to.have.property('windowExports', 'undefined');
expect(result).to.have.property('windowPreload', 'undefined');
expect(result).to.have.property('windowRequire', 'undefined');
});
};
doesNotLeakSpec('does not leak require', {
nodeIntegration: false,
sandbox: false,
contextIsolation: false
});
doesNotLeakSpec('does not leak require when sandbox is enabled', {
nodeIntegration: false,
sandbox: true,
contextIsolation: false
});
doesNotLeakSpec('does not leak require when context isolation is enabled', {
nodeIntegration: false,
sandbox: false,
contextIsolation: true
});
doesNotLeakSpec('does not leak require when context isolation and sandbox are enabled', {
nodeIntegration: false,
sandbox: true,
contextIsolation: true
});
it('does not leak any node globals on the window object with nodeIntegration is disabled', async () => {
let w = new BrowserWindow({
webPreferences: {
contextIsolation: false,
nodeIntegration: false,
preload: path.resolve(fixtures, 'module', 'empty.js')
},
show: false
});
w.loadFile(path.join(fixtures, 'api', 'globals.html'));
const [, notIsolated] = await once(ipcMain, 'leak-result');
expect(notIsolated).to.have.property('globals');
w.destroy();
w = new BrowserWindow({
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
preload: path.resolve(fixtures, 'module', 'empty.js')
},
show: false
});
w.loadFile(path.join(fixtures, 'api', 'globals.html'));
const [, isolated] = await once(ipcMain, 'leak-result');
expect(isolated).to.have.property('globals');
const notIsolatedGlobals = new Set(notIsolated.globals);
for (const isolatedGlobal of isolated.globals) {
notIsolatedGlobals.delete(isolatedGlobal);
}
expect([...notIsolatedGlobals]).to.deep.equal([], 'non-isolated renderer should have no additional globals');
});
it('loads the script before other scripts in window', async () => {
const preload = path.join(fixtures, 'module', 'set-global.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload
}
});
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
const [, test] = await once(ipcMain, 'answer');
expect(test).to.eql('preload');
});
it('has synchronous access to all eventual window APIs', async () => {
const preload = path.join(fixtures, 'module', 'access-blink-apis.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload
}
});
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
const [, test] = await once(ipcMain, 'answer');
expect(test).to.be.an('object');
expect(test.atPreload).to.be.an('array');
expect(test.atLoad).to.be.an('array');
expect(test.atPreload).to.deep.equal(test.atLoad, 'should have access to the same window APIs');
});
});
describe('session preload scripts', function () {
const preloads = [
path.join(fixtures, 'module', 'set-global-preload-1.js'),
path.join(fixtures, 'module', 'set-global-preload-2.js'),
path.relative(process.cwd(), path.join(fixtures, 'module', 'set-global-preload-3.js'))
];
const defaultSession = session.defaultSession;
beforeEach(() => {
expect(defaultSession.getPreloads()).to.deep.equal([]);
defaultSession.setPreloads(preloads);
});
afterEach(() => {
defaultSession.setPreloads([]);
});
it('can set multiple session preload script', () => {
expect(defaultSession.getPreloads()).to.deep.equal(preloads);
});
const generateSpecs = (description: string, sandbox: boolean) => {
describe(description, () => {
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 20:59:08 +03:00
it('loads the script before other scripts in window including normal preloads', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox,
preload: path.join(fixtures, 'module', 'get-global-preload.js'),
contextIsolation: false
}
});
w.loadURL('about:blank');
const [, preload1, preload2, preload3] = await once(ipcMain, 'vars');
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 20:59:08 +03:00
expect(preload1).to.equal('preload-1');
expect(preload2).to.equal('preload-1-2');
expect(preload3).to.be.undefined('preload 3');
});
});
};
2020-03-20 23:28:31 +03:00
generateSpecs('without sandbox', false);
generateSpecs('with sandbox', true);
});
describe('"additionalArguments" option', () => {
it('adds extra args to process.argv in the renderer process', async () => {
const preload = path.join(fixtures, 'module', 'check-arguments.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
preload,
additionalArguments: ['--my-magic-arg']
}
});
w.loadFile(path.join(fixtures, 'api', 'blank.html'));
const [, argv] = await once(ipcMain, 'answer');
expect(argv).to.include('--my-magic-arg');
});
it('adds extra value args to process.argv in the renderer process', async () => {
const preload = path.join(fixtures, 'module', 'check-arguments.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
preload,
additionalArguments: ['--my-magic-arg=foo']
}
});
w.loadFile(path.join(fixtures, 'api', 'blank.html'));
const [, argv] = await once(ipcMain, 'answer');
expect(argv).to.include('--my-magic-arg=foo');
});
});
describe('"node-integration" option', () => {
it('disables node integration by default', async () => {
const preload = path.join(fixtures, 'module', 'send-later.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
preload,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'api', 'blank.html'));
const [, typeofProcess, typeofBuffer] = await once(ipcMain, 'answer');
expect(typeofProcess).to.equal('undefined');
expect(typeofBuffer).to.equal('undefined');
});
});
describe('"sandbox" option', () => {
const preload = path.join(path.resolve(__dirname, 'fixtures'), 'module', 'preload-sandbox.js');
let server: http.Server;
let serverUrl: string;
before(async () => {
server = http.createServer((request, response) => {
switch (request.url) {
case '/cross-site':
response.end(`<html><body><h1>${request.url}</h1></body></html>`);
break;
default:
throw new Error(`unsupported endpoint: ${request.url}`);
}
});
serverUrl = (await listen(server)).url;
});
after(() => {
server.close();
});
it('exposes ipcRenderer to preload script', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
const [, test] = await once(ipcMain, 'answer');
expect(test).to.equal('preload');
});
it('exposes ipcRenderer to preload script (path has special chars)', async () => {
const preloadSpecialChars = path.join(fixtures, 'module', 'preload-sandboxæø åü.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload: preloadSpecialChars,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
const [, test] = await once(ipcMain, 'answer');
expect(test).to.equal('preload');
});
it('exposes "loaded" event to preload script', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload
}
});
w.loadURL('about:blank');
await once(ipcMain, 'process-loaded');
});
it('exposes "exit" event to preload script', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload,
contextIsolation: false
}
});
const htmlPath = path.join(__dirname, 'fixtures', 'api', 'sandbox.html?exit-event');
const pageUrl = 'file://' + htmlPath;
w.loadURL(pageUrl);
const [, url] = await once(ipcMain, 'answer');
const expectedUrl = process.platform === 'win32'
? 'file:///' + htmlPath.replaceAll('\\', '/')
: pageUrl;
expect(url).to.equal(expectedUrl);
});
it('exposes full EventEmitter object to preload script', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload: path.join(fixtures, 'module', 'preload-eventemitter.js')
}
});
w.loadURL('about:blank');
const [, rendererEventEmitterProperties] = await once(ipcMain, 'answer');
const { EventEmitter } = require('node:events');
const emitter = new EventEmitter();
const browserEventEmitterProperties = [];
let currentObj = emitter;
do {
browserEventEmitterProperties.push(...Object.getOwnPropertyNames(currentObj));
} while ((currentObj = Object.getPrototypeOf(currentObj)));
expect(rendererEventEmitterProperties).to.deep.equal(browserEventEmitterProperties);
});
it('should open windows in same domain with cross-scripting enabled', async () => {
const w = new BrowserWindow({
show: true,
webPreferences: {
sandbox: true,
preload,
contextIsolation: false
}
});
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
preload
}
}
}));
const htmlPath = path.join(__dirname, 'fixtures', 'api', 'sandbox.html?window-open');
const pageUrl = 'file://' + htmlPath;
const answer = once(ipcMain, 'answer');
w.loadURL(pageUrl);
const [, { url, frameName, options }] = await once(w.webContents, 'did-create-window') as [BrowserWindow, Electron.DidCreateWindowDetails];
const expectedUrl = process.platform === 'win32'
? 'file:///' + htmlPath.replaceAll('\\', '/')
: pageUrl;
expect(url).to.equal(expectedUrl);
expect(frameName).to.equal('popup!');
expect(options.width).to.equal(500);
expect(options.height).to.equal(600);
const [, html] = await answer;
expect(html).to.equal('<h1>scripting from opener</h1>');
});
it('should open windows in another domain with cross-scripting disabled', async () => {
const w = new BrowserWindow({
show: true,
webPreferences: {
sandbox: true,
preload,
contextIsolation: false
}
});
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
preload
}
}
}));
w.loadFile(
path.join(__dirname, 'fixtures', 'api', 'sandbox.html'),
{ search: 'window-open-external' }
);
// Wait for a message from the main window saying that it's ready.
await once(ipcMain, 'opener-loaded');
// Ask the opener to open a popup with window.opener.
const expectedPopupUrl = `${serverUrl}/cross-site`; // Set in "sandbox.html".
w.webContents.send('open-the-popup', expectedPopupUrl);
// The page is going to open a popup that it won't be able to close.
// We have to close it from here later.
const [, popupWindow] = await once(app, 'browser-window-created') as [any, BrowserWindow];
// Ask the popup window for details.
const detailsAnswer = once(ipcMain, 'child-loaded');
popupWindow.webContents.send('provide-details');
const [, openerIsNull, , locationHref] = await detailsAnswer;
expect(openerIsNull).to.be.false('window.opener is null');
expect(locationHref).to.equal(expectedPopupUrl);
// Ask the page to access the popup.
const touchPopupResult = once(ipcMain, 'answer');
w.webContents.send('touch-the-popup');
const [, popupAccessMessage] = await touchPopupResult;
// Ask the popup to access the opener.
const touchOpenerResult = once(ipcMain, 'answer');
popupWindow.webContents.send('touch-the-opener');
const [, openerAccessMessage] = await touchOpenerResult;
// We don't need the popup anymore, and its parent page can't close it,
// so let's close it from here before we run any checks.
await closeWindow(popupWindow, { assertNotWindows: false });
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 23:44:09 +03:00
const errorPattern = /Failed to read a named property 'document' from 'Window': Blocked a frame with origin "(.*?)" from accessing a cross-origin frame./;
expect(popupAccessMessage).to.be.a('string',
'child\'s .document is accessible from its parent window');
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 23:44:09 +03:00
expect(popupAccessMessage).to.match(errorPattern);
expect(openerAccessMessage).to.be.a('string',
'opener .document is accessible from a popup window');
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 23:44:09 +03:00
expect(openerAccessMessage).to.match(errorPattern);
});
it('should inherit the sandbox setting in opened windows', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
});
const preloadPath = path.join(mainFixtures, 'api', 'new-window-preload.js');
w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload: preloadPath } } }));
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
const [, { argv }] = await once(ipcMain, 'answer');
expect(argv).to.include('--enable-sandbox');
});
it('should open windows with the options configured via setWindowOpenHandler handlers', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
});
const preloadPath = path.join(mainFixtures, 'api', 'new-window-preload.js');
w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload: preloadPath, contextIsolation: false } } }));
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
const [[, childWebContents]] = await Promise.all([
once(app, 'web-contents-created') as Promise<[any, WebContents]>,
once(ipcMain, 'answer')
]);
const webPreferences = childWebContents.getLastWebPreferences();
expect(webPreferences!.contextIsolation).to.equal(false);
});
it('should set ipc event sender correctly', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload,
contextIsolation: false
}
});
let childWc: WebContents | null = null;
w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload, contextIsolation: false } } }));
w.webContents.on('did-create-window', (win) => {
childWc = win.webContents;
expect(w.webContents).to.not.equal(childWc);
});
ipcMain.once('parent-ready', function (event) {
expect(event.sender).to.equal(w.webContents, 'sender should be the parent');
event.sender.send('verified');
});
ipcMain.once('child-ready', function (event) {
expect(childWc).to.not.be.null('child webcontents should be available');
expect(event.sender).to.equal(childWc, 'sender should be the child');
event.sender.send('verified');
});
const done = Promise.all([
'parent-answer',
'child-answer'
].map(name => once(ipcMain, name)));
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'sandbox.html'), { search: 'verify-ipc-sender' });
await done;
});
describe('event handling', () => {
let w: BrowserWindow;
beforeEach(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
});
it('works for window events', async () => {
const pageTitleUpdated = once(w, 'page-title-updated');
w.loadURL('data:text/html,<script>document.title = \'changed\'</script>');
await pageTitleUpdated;
});
it('works for stop events', async () => {
const done = Promise.all([
'did-navigate',
'did-fail-load',
'did-stop-loading'
].map(name => once(w.webContents, name)));
w.loadURL('data:text/html,<script>stop()</script>');
await done;
});
it('works for web contents events', async () => {
const done = Promise.all([
'did-finish-load',
'did-frame-finish-load',
'did-navigate-in-page',
'will-navigate',
'did-start-loading',
'did-stop-loading',
'did-frame-finish-load',
'dom-ready'
].map(name => once(w.webContents, name)));
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'sandbox.html'), { search: 'webcontents-events' });
await done;
});
});
it('validates process APIs access in sandboxed renderer', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload,
contextIsolation: false
}
});
w.webContents.once('preload-error', (event, preloadPath, error) => {
throw error;
});
process.env.sandboxmain = 'foo';
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
const [, test] = await once(ipcMain, 'answer');
expect(test.hasCrash).to.be.true('has crash');
expect(test.hasHang).to.be.true('has hang');
expect(test.heapStatistics).to.be.an('object');
expect(test.blinkMemoryInfo).to.be.an('object');
expect(test.processMemoryInfo).to.be.an('object');
expect(test.systemVersion).to.be.a('string');
expect(test.cpuUsage).to.be.an('object');
expect(test.uptime).to.be.a('number');
expect(test.arch).to.equal(process.arch);
expect(test.platform).to.equal(process.platform);
expect(test.env).to.deep.equal(process.env);
expect(test.execPath).to.equal(process.helperExecPath);
expect(test.sandboxed).to.be.true('sandboxed');
expect(test.contextIsolated).to.be.false('contextIsolated');
expect(test.type).to.equal('renderer');
expect(test.version).to.equal(process.version);
expect(test.versions).to.deep.equal(process.versions);
expect(test.contextId).to.be.a('string');
expect(test.nodeEvents).to.equal(true);
expect(test.nodeTimers).to.equal(true);
expect(test.nodeUrl).to.equal(true);
if (process.platform === 'linux' && test.osSandbox) {
expect(test.creationTime).to.be.null('creation time');
expect(test.systemMemoryInfo).to.be.null('system memory info');
} else {
expect(test.creationTime).to.be.a('number');
expect(test.systemMemoryInfo).to.be.an('object');
}
});
it('webview in sandbox renderer', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload,
webviewTag: 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('child windows', () => {
let w: BrowserWindow;
beforeEach(() => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
// tests relies on preloads in opened windows
nodeIntegrationInSubFrames: true,
contextIsolation: false
}
});
});
it('opens window of about:blank with cross-scripting enabled', async () => {
const answer = once(ipcMain, 'answer');
w.loadFile(path.join(fixtures, 'api', 'native-window-open-blank.html'));
const [, content] = await answer;
expect(content).to.equal('Hello');
});
it('opens window of same domain with cross-scripting enabled', async () => {
const answer = once(ipcMain, 'answer');
w.loadFile(path.join(fixtures, 'api', 'native-window-open-file.html'));
const [, content] = await answer;
expect(content).to.equal('Hello');
});
it('blocks accessing cross-origin frames', async () => {
const answer = once(ipcMain, 'answer');
w.loadFile(path.join(fixtures, 'api', 'native-window-open-cross-origin.html'));
const [, content] = await answer;
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 23:44:09 +03:00
expect(content).to.equal('Failed to read a named property \'toString\' from \'Location\': Blocked a frame with origin "file://" from accessing a cross-origin frame.');
});
it('opens window from <iframe> tags', async () => {
const answer = once(ipcMain, 'answer');
w.loadFile(path.join(fixtures, 'api', 'native-window-open-iframe.html'));
const [, content] = await answer;
expect(content).to.equal('Hello');
2019-11-01 23:37:02 +03:00
});
it('opens window with cross-scripting enabled from isolated context', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(fixtures, 'api', 'native-window-open-isolated-preload.js')
}
});
w.loadFile(path.join(fixtures, 'api', 'native-window-open-isolated.html'));
const [, content] = await once(ipcMain, 'answer');
expect(content).to.equal('Hello');
});
ifit(!process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS)('loads native addons correctly after reload', async () => {
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'native-window-open-native-addon.html'));
{
const [, content] = await once(ipcMain, 'answer');
expect(content).to.equal('function');
}
w.reload();
{
const [, content] = await once(ipcMain, 'answer');
expect(content).to.equal('function');
}
});
it('<webview> works in a scriptable popup', async () => {
const preload = path.join(fixtures, 'api', 'new-window-webview-preload.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegrationInSubFrames: true,
webviewTag: true,
contextIsolation: false,
preload
}
});
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
show: false,
webPreferences: {
contextIsolation: false,
webviewTag: true,
nodeIntegrationInSubFrames: true,
preload
}
}
}));
const webviewLoaded = once(ipcMain, 'webview-loaded');
w.loadFile(path.join(fixtures, 'api', 'new-window-webview.html'));
await webviewLoaded;
});
it('should open windows with the options configured via setWindowOpenHandler handlers', async () => {
const preloadPath = path.join(mainFixtures, 'api', 'new-window-preload.js');
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
preload: preloadPath,
contextIsolation: false
}
}
}));
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
const [[, childWebContents]] = await Promise.all([
once(app, 'web-contents-created') as Promise<[any, WebContents]>,
once(ipcMain, 'answer')
]);
const webPreferences = childWebContents.getLastWebPreferences();
expect(webPreferences!.contextIsolation).to.equal(false);
});
describe('window.location', () => {
const protocols = [
['foo', path.join(fixtures, 'api', 'window-open-location-change.html')],
['bar', path.join(fixtures, 'api', 'window-open-location-final.html')]
];
beforeEach(() => {
for (const [scheme, path] of protocols) {
protocol.registerBufferProtocol(scheme, (request, callback) => {
callback({
mimeType: 'text/html',
data: fs.readFileSync(path)
});
});
}
});
afterEach(() => {
for (const [scheme] of protocols) {
protocol.unregisterProtocol(scheme);
}
});
it('retains the original web preferences when window.location is changed to a new origin', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
// test relies on preloads in opened window
nodeIntegrationInSubFrames: true,
contextIsolation: false
}
});
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
preload: path.join(mainFixtures, 'api', 'window-open-preload.js'),
contextIsolation: false,
nodeIntegrationInSubFrames: true
}
}
}));
w.loadFile(path.join(fixtures, 'api', 'window-open-location-open.html'));
const [, { nodeIntegration, typeofProcess }] = await once(ipcMain, 'answer');
expect(nodeIntegration).to.be.false();
expect(typeofProcess).to.eql('undefined');
});
it('window.opener is not null when window.location is changed to a new origin', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
// test relies on preloads in opened window
nodeIntegrationInSubFrames: true
}
});
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
preload: path.join(mainFixtures, 'api', 'window-open-preload.js')
}
}
}));
w.loadFile(path.join(fixtures, 'api', 'window-open-location-open.html'));
const [, { windowOpenerIsNull }] = await once(ipcMain, 'answer');
expect(windowOpenerIsNull).to.be.false('window.opener is null');
});
});
});
describe('"disableHtmlFullscreenWindowResize" option', () => {
it('prevents window from resizing when set', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
disableHtmlFullscreenWindowResize: true
}
});
await w.loadURL('about:blank');
const size = w.getSize();
const enterHtmlFullScreen = once(w.webContents, 'enter-html-full-screen');
w.webContents.executeJavaScript('document.body.webkitRequestFullscreen()', true);
await enterHtmlFullScreen;
expect(w.getSize()).to.deep.equal(size);
});
});
describe('"defaultFontFamily" option', () => {
it('can change the standard font family', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
defaultFontFamily: {
standard: 'Impact'
}
}
});
await w.loadFile(path.join(fixtures, 'pages', 'content.html'));
const fontFamily = await w.webContents.executeJavaScript("window.getComputedStyle(document.getElementsByTagName('p')[0])['font-family']", true);
expect(fontFamily).to.equal('Impact');
});
});
});
describe('beforeunload handler', function () {
let w: BrowserWindow;
beforeEach(() => {
2019-11-01 23:37:02 +03:00
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
});
afterEach(closeAllWindows);
it('returning undefined would not prevent close', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-undefined.html'));
const wait = once(w, 'closed');
w.close();
await wait;
});
it('returning false would prevent close', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false.html'));
w.close();
const [, proceed] = await once(w.webContents, '-before-unload-fired');
expect(proceed).to.equal(false);
});
it('returning empty string would prevent close', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-empty-string.html'));
w.close();
const [, proceed] = await once(w.webContents, '-before-unload-fired');
expect(proceed).to.equal(false);
});
it('emits for each close attempt', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
const destroyListener = () => { expect.fail('Close was not prevented'); };
w.webContents.once('destroyed', destroyListener);
w.webContents.executeJavaScript('installBeforeUnload(2)', true);
// The renderer needs to report the status of beforeunload handler
// back to main process, so wait for next console message, which means
// the SuddenTerminationStatus message have been flushed.
await once(w.webContents, 'console-message');
w.close();
await once(w.webContents, '-before-unload-fired');
w.close();
await once(w.webContents, '-before-unload-fired');
w.webContents.removeListener('destroyed', destroyListener);
const wait = once(w, 'closed');
w.close();
await wait;
});
it('emits for each reload attempt', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
const navigationListener = () => { expect.fail('Reload was not prevented'); };
w.webContents.once('did-start-navigation', navigationListener);
w.webContents.executeJavaScript('installBeforeUnload(2)', true);
// The renderer needs to report the status of beforeunload handler
// back to main process, so wait for next console message, which means
// the SuddenTerminationStatus message have been flushed.
await once(w.webContents, 'console-message');
w.reload();
// Chromium does not emit '-before-unload-fired' on WebContents for
// navigations, so we have to use other ways to know if beforeunload
// is fired.
await emittedUntil(w.webContents, 'console-message', isBeforeUnload);
w.reload();
await emittedUntil(w.webContents, 'console-message', isBeforeUnload);
w.webContents.removeListener('did-start-navigation', navigationListener);
w.reload();
await once(w.webContents, 'did-finish-load');
});
it('emits for each navigation attempt', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false-prevent3.html'));
const navigationListener = () => { expect.fail('Reload was not prevented'); };
w.webContents.once('did-start-navigation', navigationListener);
w.webContents.executeJavaScript('installBeforeUnload(2)', true);
// The renderer needs to report the status of beforeunload handler
// back to main process, so wait for next console message, which means
// the SuddenTerminationStatus message have been flushed.
await once(w.webContents, 'console-message');
w.loadURL('about:blank');
// Chromium does not emit '-before-unload-fired' on WebContents for
// navigations, so we have to use other ways to know if beforeunload
// is fired.
await emittedUntil(w.webContents, 'console-message', isBeforeUnload);
w.loadURL('about:blank');
await emittedUntil(w.webContents, 'console-message', isBeforeUnload);
w.webContents.removeListener('did-start-navigation', navigationListener);
await w.loadURL('about:blank');
});
});
// TODO(codebytere): figure out how to make these pass in CI on Windows.
ifdescribe(process.platform !== 'win32')('document.visibilityState/hidden', () => {
afterEach(closeAllWindows);
it('visibilityState is initially visible despite window being hidden', async () => {
const w = new BrowserWindow({
show: false,
width: 100,
height: 100,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
let readyToShow = false;
w.once('ready-to-show', () => {
readyToShow = true;
});
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(readyToShow).to.be.false('ready to show');
expect(visibilityState).to.equal('visible');
expect(hidden).to.be.false('hidden');
});
it('visibilityState changes when window is hidden', async () => {
const w = new BrowserWindow({
width: 100,
height: 100,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
{
const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('visible');
expect(hidden).to.be.false('hidden');
}
w.hide();
{
const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('hidden');
expect(hidden).to.be.true('hidden');
}
});
it('visibilityState changes when window is shown', async () => {
const w = new BrowserWindow({
width: 100,
height: 100,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
if (process.platform === 'darwin') {
// See https://github.com/electron/electron/issues/8664
await once(w, 'show');
}
w.hide();
w.show();
const [, visibilityState] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('visible');
});
it('visibilityState changes when window is shown inactive', async () => {
const w = new BrowserWindow({
width: 100,
height: 100,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
if (process.platform === 'darwin') {
// See https://github.com/electron/electron/issues/8664
await once(w, 'show');
}
w.hide();
w.showInactive();
const [, visibilityState] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('visible');
});
ifit(process.platform === 'darwin')('visibilityState changes when window is minimized', async () => {
const w = new BrowserWindow({
width: 100,
height: 100,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
{
const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('visible');
expect(hidden).to.be.false('hidden');
}
w.minimize();
{
const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('hidden');
expect(hidden).to.be.true('hidden');
}
});
it('visibilityState remains visible if backgroundThrottling is disabled', async () => {
const w = new BrowserWindow({
show: false,
width: 100,
height: 100,
webPreferences: {
backgroundThrottling: false,
nodeIntegration: true,
contextIsolation: false
}
});
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
{
const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('visible');
expect(hidden).to.be.false('hidden');
}
ipcMain.once('pong', (event, visibilityState, hidden) => {
throw new Error(`Unexpected visibility change event. visibilityState: ${visibilityState} hidden: ${hidden}`);
});
try {
const shown1 = once(w, 'show');
w.show();
await shown1;
const hidden = once(w, 'hide');
w.hide();
await hidden;
const shown2 = once(w, 'show');
w.show();
await shown2;
} finally {
ipcMain.removeAllListeners('pong');
}
});
});
ifdescribe(process.platform !== 'linux')('max/minimize events', () => {
afterEach(closeAllWindows);
it('emits an event when window is maximized', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
});
it('emits an event when a transparent window is maximized', async () => {
const w = new BrowserWindow({
show: false,
frame: false,
transparent: true
});
const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
});
it('emits only one event when frameless window is maximized', () => {
const w = new BrowserWindow({ show: false, frame: false });
let emitted = 0;
w.on('maximize', () => emitted++);
w.show();
w.maximize();
expect(emitted).to.equal(1);
});
it('emits an event when window is unmaximized', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const unmaximize = once(w, 'unmaximize');
w.show();
w.maximize();
w.unmaximize();
await unmaximize;
});
it('emits an event when a transparent window is unmaximized', async () => {
const w = new BrowserWindow({
show: false,
frame: false,
transparent: true
});
const maximize = once(w, 'maximize');
const unmaximize = once(w, 'unmaximize');
w.show();
w.maximize();
await maximize;
w.unmaximize();
await unmaximize;
});
it('emits an event when window is minimized', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const minimize = once(w, 'minimize');
w.show();
w.minimize();
await minimize;
});
});
describe('beginFrameSubscription method', () => {
it('does not crash when callback returns nothing', (done) => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
let called = false;
w.loadFile(path.join(fixtures, 'api', 'frame-subscriber.html'));
w.webContents.on('dom-ready', () => {
2019-11-01 23:37:02 +03:00
w.webContents.beginFrameSubscription(function () {
// This callback might be called twice.
if (called) return;
called = true;
// Pending endFrameSubscription to next tick can reliably reproduce
// a crash which happens when nothing is returned in the callback.
setTimeout().then(() => {
w.webContents.endFrameSubscription();
done();
});
});
});
});
it('subscribes to frame updates', (done) => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
let called = false;
w.loadFile(path.join(fixtures, 'api', 'frame-subscriber.html'));
w.webContents.on('dom-ready', () => {
w.webContents.beginFrameSubscription(function (data) {
// This callback might be called twice.
if (called) return;
called = true;
try {
expect(data.constructor.name).to.equal('NativeImage');
expect(data.isEmpty()).to.be.false('data is empty');
done();
} catch (e) {
done(e);
} finally {
w.webContents.endFrameSubscription();
}
});
});
});
it('subscribes to frame updates (only dirty rectangle)', (done) => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
let called = false;
let gotInitialFullSizeFrame = false;
const [contentWidth, contentHeight] = w.getContentSize();
w.webContents.on('did-finish-load', () => {
w.webContents.beginFrameSubscription(true, (image, rect) => {
if (image.isEmpty()) {
// Chromium sometimes sends a 0x0 frame at the beginning of the
// page load.
return;
}
if (rect.height === contentHeight && rect.width === contentWidth &&
!gotInitialFullSizeFrame) {
// The initial frame is full-size, but we're looking for a call
// with just the dirty-rect. The next frame should be a smaller
// rect.
gotInitialFullSizeFrame = true;
return;
}
// This callback might be called twice.
if (called) return;
// We asked for just the dirty rectangle, so we expect to receive a
// rect smaller than the full size.
// TODO(jeremy): this is failing on windows currently; investigate.
// assert(rect.width < contentWidth || rect.height < contentHeight)
called = true;
try {
const expectedSize = rect.width * rect.height * 4;
expect(image.getBitmap()).to.be.an.instanceOf(Buffer).with.lengthOf(expectedSize);
done();
} catch (e) {
done(e);
} finally {
w.webContents.endFrameSubscription();
}
});
});
w.loadFile(path.join(fixtures, 'api', 'frame-subscriber.html'));
});
it('throws error when subscriber is not well defined', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
expect(() => {
w.webContents.beginFrameSubscription(true, true as any);
// TODO(zcbenz): gin is weak at guessing parameter types, we should
// upstream native_mate's implementation to gin.
}).to.throw('Error processing argument at index 1, conversion failure from ');
});
});
describe('savePage method', () => {
const savePageDir = path.join(fixtures, 'save_page');
const savePageHtmlPath = path.join(savePageDir, 'save_page.html');
const savePageJsPath = path.join(savePageDir, 'save_page_files', 'test.js');
const savePageCssPath = path.join(savePageDir, 'save_page_files', 'test.css');
afterEach(() => {
closeAllWindows();
try {
fs.unlinkSync(savePageCssPath);
fs.unlinkSync(savePageJsPath);
fs.unlinkSync(savePageHtmlPath);
fs.rmdirSync(path.join(savePageDir, 'save_page_files'));
fs.rmdirSync(savePageDir);
} catch { }
});
it('should throw when passing relative paths', async () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixtures, 'pages', 'save_page', 'index.html'));
await expect(
w.webContents.savePage('save_page.html', 'HTMLComplete')
).to.eventually.be.rejectedWith('Path must be absolute');
await expect(
w.webContents.savePage('save_page.html', 'HTMLOnly')
).to.eventually.be.rejectedWith('Path must be absolute');
await expect(
w.webContents.savePage('save_page.html', 'MHTML')
).to.eventually.be.rejectedWith('Path must be absolute');
});
it('should save page to disk with HTMLOnly', async () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixtures, 'pages', 'save_page', 'index.html'));
await w.webContents.savePage(savePageHtmlPath, 'HTMLOnly');
expect(fs.existsSync(savePageHtmlPath)).to.be.true('html path');
expect(fs.existsSync(savePageJsPath)).to.be.false('js path');
expect(fs.existsSync(savePageCssPath)).to.be.false('css path');
});
it('should save page to disk with MHTML', async () => {
chore: bump chromium to 111.0.5544.3 (main) (#36820) * chore: bump chromium in DEPS to 111.0.5522.0 * chore: bump chromium in DEPS to 111.0.5524.0 * chore: bump chromium in DEPS to 111.0.5526.0 * chore: bump chromium in DEPS to 111.0.5528.0 * chore: update patches/chromium/mas_avoid_usage_of_private_macos_apis.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4132807 Fix simple code shear * chore: update patches/chromium/unsandboxed_ppapi_processes_skip_zygote.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4130675 Fix simple code shear * chore: update patches/chromium/hack_plugin_response_interceptor_to_point_to_electron.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/disable_unload_metrics.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126173 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/feat_add_data_parameter_to_processsingleton.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/preconnect_manager.patch https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/v8/force_cppheapcreateparams_to_be_noncopyable.patch https://chromium-review.googlesource.com/c/v8/v8/+/3533019 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches * chore: update patches/chromium/add_maximized_parameter_to_linuxui_getwindowframeprovider.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4128765 Upstream added a new call to HeaderContext(), whose signature we have patched * chore: bump chromium in DEPS to 111.0.5530.0 * chore: update patches * Move ChildProcessHost* from content/common to content/browser Xref: Move ChildProcessHost* from content/common to content/browser * Remove RenderViewHostChanged Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103 [upstream removal of RenderViewHostChanged] Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4092763 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4093234 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133892 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103 [examples of upstream code adjusting to the change] Upstream handles this change in roughly two approaches: 1. Move the code over to RenderFrameHostChanged(old_host, new_host) but test for new_host->IsInPrimaryMainFrame() before acting 2. Migrate to the PrimaryPageChanged(page) API and use page.GetMainDocument() to get the RenderFrameHost. I've chosen 1. because electron_api_web_contents needed that pointer to old_host to call RemoveInputEventListener(), but I may be missing some context & would appreciate review on this commit. * Make electron/shell/browser/relauncher_win.cc use <winternl.h> Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4129135 Many internal Windows types are now available in winternl.h so upstrem no longer defines the types themselves. * Move ChildProcessHost* from content/common to content/browser Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134795 * fixup! Make electron/shell/browser/relauncher_win.cc use <winternl.h> winternl.h does not define the field we need, so clone the struct Chromium was using into unnamed namespace * fixup! Move ChildProcessHost* from content/common to content/browser chore: update #includes too * chore: bump chromium in DEPS to 111.0.5532.0 * chore: sync patches/chromium/pepper_plugin_support.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 manually reync patch; no code changes * chore: sync patches/chromium/mas_no_private_api.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4143865 the content/common/pseudonymization_salt.cc patch is no longer needed * chore: sync patches/chromium/mas_disable_remote_accessibility.patch patch-fuzz update; no manual changes * chore: sync patches/chromium/build_do_not_depend_on_packed_resource_integrity.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4111725 manually reync patch; no code changes * chore: sync patches/chromium/create_browser_v8_snapshot_file_name_fuse.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 manually reync patch; no code changes * chore: sync patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch Xref: https://chromium-review.googlesource.com/c/v8/v8/+/4127230 patch-fuzz update; no manual changes * chore: rebuild patches * fixup! Remove RenderViewHostChanged Use PrimaryPageChanged() * chore: remove unused method TabsUpdateFunction::OnExecuteCodeFinished() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133991 This private, already-unused function showed up as a FTBFS because it took a base::ListValue parameter and ListValue was removed upstream. * task posting v3: remove includes of runner handles and IWYU task runners Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 * chore: lint * chore: more lint * fixup! task posting v3: remove includes of runner handles and IWYU task runners macOS, too * fixup! task posting v3: remove includes of runner handles and IWYU task runners * chore: bump chromium in DEPS to 111.0.5534.0 * chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141862 patch-fuzz update; no manual changes * chore: sync patches/chromium/logging_win32_only_create_a_console_if_logging_to_stderr.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4153110 Sync to minor upstream changes. Add const correctness. * chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch https://chromium-review.googlesource.com/c/chromium/src/+/4141862 patch-fuzz update; no manual changes * chore: patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch sync https://chromium-review.googlesource.com/c/v8/v8/+/4147787 patch-fuzz update; no manual changes * chore: update patches * chore: bump chromium in DEPS to 111.0.5536.0 * chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863 Sync with upstream code changes. Minor code golf for readability. Note: upstream is laying groundwork for being able to work off of env vars instead of switches. Doesn't affect us yet but worth being aware of. > + // Environment variables could be supported in the future, but are not > + // currently supported when launching with the zygote. * chore: update patches/chromium/feat_expose_raw_response_headers_from_urlloader.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126836 patch-fuzz update; no manual changes * chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863 manual sync * chore: sync electron/patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch https://chromium-review.googlesource.com/c/v8/v8/+/4147788 fuzz-patch * chore: rebuild patches * chore: bump chromium in DEPS to 111.0.5538.0 * chore: bump chromium in DEPS to 111.0.5540.0 * chore: update patches * Remove sdk_forward_declarations https://chromium-review.googlesource.com/c/chromium/src/+/4166680 * task posting v3: Remove task runner handles from codebase entirely Refs https://chromium-review.googlesource.com/c/chromium/src/+/4150928 * Cleanup child_process_launcher_helper* Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863 * fix: utilityprocess spec on macOS * fix: build on windows Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863 * chore: fix lint * chore: bump chromium 111.0.5544.3 * chore: gen filenames.libcxx.gni * Add check for Executable+Writable handles in renderer processes. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3774416 * fixup! Add check for Executable+Writable handles in renderer processes. * 4143761: [110] Disable SwiftShader for WebGL on M1 Macs. https://chromium-review.googlesource.com/c/chromium/src/+/4143761 (cherry picked from commit 2f74db3c2139424c416f92d9169aeaa8a2f9c1ec) * chore: bump chromium to 111.0.5555.0 * 56085: Remove hmac.h include from ssl.h. https://boringssl-review.googlesource.com/c/boringssl/+/56085 * 4167020: Remove forwarding headers https://chromium-review.googlesource.com/c/chromium/src/+/4167020 * chore: bump chromium to 111.0.5559.0 * 4181044: Restrict WebCursor usage to RenderWidgetHostViewAura https://chromium-review.googlesource.com/c/chromium/src/+/4181044 * 4189437: views: rename ink_drop_host_view to ink_drop_host https://chromium-review.googlesource.com/c/chromium/src/+/4189437 * chore: bump chromium to 111.0.5560.0 * 4167016: win7dep: remove non aeroglass code https://chromium-review.googlesource.com/c/chromium/src/+/4167016 * fixup after rebase: Remove forwarding header s https://chromium-review.googlesource.com/c/chromium/src/+/4167020 * 4125755: Reland "Reject getDisplayMedia calls without user activation" https://chromium-review.googlesource.com/c/chromium/src/+/4125755 * test: add workaround * chore: update patches * fix: alter coreModuleRegExp to prevent arm crash * Revert "fix: alter coreModuleRegExp to prevent arm crash" This reverts commit 7e50630c98137831a711c5abdbc8809e60cf1d73. * 4218354: Disable the use of preserve_most on arm64 Windows https://chromium-review.googlesource.com/c/v8/v8/+/4218354 * chore: review changes --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2023-02-03 14:43:42 +03:00
/* Use temp directory for saving MHTML file since the write handle
* gets passed to untrusted process and chromium will deny exec access to
* the path. To perform this task, chromium requires that the path is one
* of the browser controlled paths, refs https://chromium-review.googlesource.com/c/chromium/src/+/3774416
*/
const tmpDir = await fs.promises.mkdtemp(path.resolve(os.tmpdir(), 'electron-mhtml-save-'));
const savePageMHTMLPath = path.join(tmpDir, 'save_page.html');
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixtures, 'pages', 'save_page', 'index.html'));
chore: bump chromium to 111.0.5544.3 (main) (#36820) * chore: bump chromium in DEPS to 111.0.5522.0 * chore: bump chromium in DEPS to 111.0.5524.0 * chore: bump chromium in DEPS to 111.0.5526.0 * chore: bump chromium in DEPS to 111.0.5528.0 * chore: update patches/chromium/mas_avoid_usage_of_private_macos_apis.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4132807 Fix simple code shear * chore: update patches/chromium/unsandboxed_ppapi_processes_skip_zygote.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4130675 Fix simple code shear * chore: update patches/chromium/hack_plugin_response_interceptor_to_point_to_electron.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/disable_unload_metrics.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126173 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/feat_add_data_parameter_to_processsingleton.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/preconnect_manager.patch https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/v8/force_cppheapcreateparams_to_be_noncopyable.patch https://chromium-review.googlesource.com/c/v8/v8/+/3533019 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches * chore: update patches/chromium/add_maximized_parameter_to_linuxui_getwindowframeprovider.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4128765 Upstream added a new call to HeaderContext(), whose signature we have patched * chore: bump chromium in DEPS to 111.0.5530.0 * chore: update patches * Move ChildProcessHost* from content/common to content/browser Xref: Move ChildProcessHost* from content/common to content/browser * Remove RenderViewHostChanged Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103 [upstream removal of RenderViewHostChanged] Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4092763 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4093234 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133892 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103 [examples of upstream code adjusting to the change] Upstream handles this change in roughly two approaches: 1. Move the code over to RenderFrameHostChanged(old_host, new_host) but test for new_host->IsInPrimaryMainFrame() before acting 2. Migrate to the PrimaryPageChanged(page) API and use page.GetMainDocument() to get the RenderFrameHost. I've chosen 1. because electron_api_web_contents needed that pointer to old_host to call RemoveInputEventListener(), but I may be missing some context & would appreciate review on this commit. * Make electron/shell/browser/relauncher_win.cc use <winternl.h> Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4129135 Many internal Windows types are now available in winternl.h so upstrem no longer defines the types themselves. * Move ChildProcessHost* from content/common to content/browser Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134795 * fixup! Make electron/shell/browser/relauncher_win.cc use <winternl.h> winternl.h does not define the field we need, so clone the struct Chromium was using into unnamed namespace * fixup! Move ChildProcessHost* from content/common to content/browser chore: update #includes too * chore: bump chromium in DEPS to 111.0.5532.0 * chore: sync patches/chromium/pepper_plugin_support.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 manually reync patch; no code changes * chore: sync patches/chromium/mas_no_private_api.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4143865 the content/common/pseudonymization_salt.cc patch is no longer needed * chore: sync patches/chromium/mas_disable_remote_accessibility.patch patch-fuzz update; no manual changes * chore: sync patches/chromium/build_do_not_depend_on_packed_resource_integrity.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4111725 manually reync patch; no code changes * chore: sync patches/chromium/create_browser_v8_snapshot_file_name_fuse.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 manually reync patch; no code changes * chore: sync patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch Xref: https://chromium-review.googlesource.com/c/v8/v8/+/4127230 patch-fuzz update; no manual changes * chore: rebuild patches * fixup! Remove RenderViewHostChanged Use PrimaryPageChanged() * chore: remove unused method TabsUpdateFunction::OnExecuteCodeFinished() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133991 This private, already-unused function showed up as a FTBFS because it took a base::ListValue parameter and ListValue was removed upstream. * task posting v3: remove includes of runner handles and IWYU task runners Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 * chore: lint * chore: more lint * fixup! task posting v3: remove includes of runner handles and IWYU task runners macOS, too * fixup! task posting v3: remove includes of runner handles and IWYU task runners * chore: bump chromium in DEPS to 111.0.5534.0 * chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141862 patch-fuzz update; no manual changes * chore: sync patches/chromium/logging_win32_only_create_a_console_if_logging_to_stderr.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4153110 Sync to minor upstream changes. Add const correctness. * chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch https://chromium-review.googlesource.com/c/chromium/src/+/4141862 patch-fuzz update; no manual changes * chore: patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch sync https://chromium-review.googlesource.com/c/v8/v8/+/4147787 patch-fuzz update; no manual changes * chore: update patches * chore: bump chromium in DEPS to 111.0.5536.0 * chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863 Sync with upstream code changes. Minor code golf for readability. Note: upstream is laying groundwork for being able to work off of env vars instead of switches. Doesn't affect us yet but worth being aware of. > + // Environment variables could be supported in the future, but are not > + // currently supported when launching with the zygote. * chore: update patches/chromium/feat_expose_raw_response_headers_from_urlloader.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126836 patch-fuzz update; no manual changes * chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863 manual sync * chore: sync electron/patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch https://chromium-review.googlesource.com/c/v8/v8/+/4147788 fuzz-patch * chore: rebuild patches * chore: bump chromium in DEPS to 111.0.5538.0 * chore: bump chromium in DEPS to 111.0.5540.0 * chore: update patches * Remove sdk_forward_declarations https://chromium-review.googlesource.com/c/chromium/src/+/4166680 * task posting v3: Remove task runner handles from codebase entirely Refs https://chromium-review.googlesource.com/c/chromium/src/+/4150928 * Cleanup child_process_launcher_helper* Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863 * fix: utilityprocess spec on macOS * fix: build on windows Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863 * chore: fix lint * chore: bump chromium 111.0.5544.3 * chore: gen filenames.libcxx.gni * Add check for Executable+Writable handles in renderer processes. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3774416 * fixup! Add check for Executable+Writable handles in renderer processes. * 4143761: [110] Disable SwiftShader for WebGL on M1 Macs. https://chromium-review.googlesource.com/c/chromium/src/+/4143761 (cherry picked from commit 2f74db3c2139424c416f92d9169aeaa8a2f9c1ec) * chore: bump chromium to 111.0.5555.0 * 56085: Remove hmac.h include from ssl.h. https://boringssl-review.googlesource.com/c/boringssl/+/56085 * 4167020: Remove forwarding headers https://chromium-review.googlesource.com/c/chromium/src/+/4167020 * chore: bump chromium to 111.0.5559.0 * 4181044: Restrict WebCursor usage to RenderWidgetHostViewAura https://chromium-review.googlesource.com/c/chromium/src/+/4181044 * 4189437: views: rename ink_drop_host_view to ink_drop_host https://chromium-review.googlesource.com/c/chromium/src/+/4189437 * chore: bump chromium to 111.0.5560.0 * 4167016: win7dep: remove non aeroglass code https://chromium-review.googlesource.com/c/chromium/src/+/4167016 * fixup after rebase: Remove forwarding header s https://chromium-review.googlesource.com/c/chromium/src/+/4167020 * 4125755: Reland "Reject getDisplayMedia calls without user activation" https://chromium-review.googlesource.com/c/chromium/src/+/4125755 * test: add workaround * chore: update patches * fix: alter coreModuleRegExp to prevent arm crash * Revert "fix: alter coreModuleRegExp to prevent arm crash" This reverts commit 7e50630c98137831a711c5abdbc8809e60cf1d73. * 4218354: Disable the use of preserve_most on arm64 Windows https://chromium-review.googlesource.com/c/v8/v8/+/4218354 * chore: review changes --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2023-02-03 14:43:42 +03:00
await w.webContents.savePage(savePageMHTMLPath, 'MHTML');
chore: bump chromium to 111.0.5544.3 (main) (#36820) * chore: bump chromium in DEPS to 111.0.5522.0 * chore: bump chromium in DEPS to 111.0.5524.0 * chore: bump chromium in DEPS to 111.0.5526.0 * chore: bump chromium in DEPS to 111.0.5528.0 * chore: update patches/chromium/mas_avoid_usage_of_private_macos_apis.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4132807 Fix simple code shear * chore: update patches/chromium/unsandboxed_ppapi_processes_skip_zygote.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4130675 Fix simple code shear * chore: update patches/chromium/hack_plugin_response_interceptor_to_point_to_electron.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/disable_unload_metrics.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126173 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/feat_add_data_parameter_to_processsingleton.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/preconnect_manager.patch https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/v8/force_cppheapcreateparams_to_be_noncopyable.patch https://chromium-review.googlesource.com/c/v8/v8/+/3533019 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches * chore: update patches/chromium/add_maximized_parameter_to_linuxui_getwindowframeprovider.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4128765 Upstream added a new call to HeaderContext(), whose signature we have patched * chore: bump chromium in DEPS to 111.0.5530.0 * chore: update patches * Move ChildProcessHost* from content/common to content/browser Xref: Move ChildProcessHost* from content/common to content/browser * Remove RenderViewHostChanged Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103 [upstream removal of RenderViewHostChanged] Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4092763 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4093234 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133892 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103 [examples of upstream code adjusting to the change] Upstream handles this change in roughly two approaches: 1. Move the code over to RenderFrameHostChanged(old_host, new_host) but test for new_host->IsInPrimaryMainFrame() before acting 2. Migrate to the PrimaryPageChanged(page) API and use page.GetMainDocument() to get the RenderFrameHost. I've chosen 1. because electron_api_web_contents needed that pointer to old_host to call RemoveInputEventListener(), but I may be missing some context & would appreciate review on this commit. * Make electron/shell/browser/relauncher_win.cc use <winternl.h> Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4129135 Many internal Windows types are now available in winternl.h so upstrem no longer defines the types themselves. * Move ChildProcessHost* from content/common to content/browser Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134795 * fixup! Make electron/shell/browser/relauncher_win.cc use <winternl.h> winternl.h does not define the field we need, so clone the struct Chromium was using into unnamed namespace * fixup! Move ChildProcessHost* from content/common to content/browser chore: update #includes too * chore: bump chromium in DEPS to 111.0.5532.0 * chore: sync patches/chromium/pepper_plugin_support.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 manually reync patch; no code changes * chore: sync patches/chromium/mas_no_private_api.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4143865 the content/common/pseudonymization_salt.cc patch is no longer needed * chore: sync patches/chromium/mas_disable_remote_accessibility.patch patch-fuzz update; no manual changes * chore: sync patches/chromium/build_do_not_depend_on_packed_resource_integrity.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4111725 manually reync patch; no code changes * chore: sync patches/chromium/create_browser_v8_snapshot_file_name_fuse.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 manually reync patch; no code changes * chore: sync patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch Xref: https://chromium-review.googlesource.com/c/v8/v8/+/4127230 patch-fuzz update; no manual changes * chore: rebuild patches * fixup! Remove RenderViewHostChanged Use PrimaryPageChanged() * chore: remove unused method TabsUpdateFunction::OnExecuteCodeFinished() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133991 This private, already-unused function showed up as a FTBFS because it took a base::ListValue parameter and ListValue was removed upstream. * task posting v3: remove includes of runner handles and IWYU task runners Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 * chore: lint * chore: more lint * fixup! task posting v3: remove includes of runner handles and IWYU task runners macOS, too * fixup! task posting v3: remove includes of runner handles and IWYU task runners * chore: bump chromium in DEPS to 111.0.5534.0 * chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141862 patch-fuzz update; no manual changes * chore: sync patches/chromium/logging_win32_only_create_a_console_if_logging_to_stderr.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4153110 Sync to minor upstream changes. Add const correctness. * chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch https://chromium-review.googlesource.com/c/chromium/src/+/4141862 patch-fuzz update; no manual changes * chore: patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch sync https://chromium-review.googlesource.com/c/v8/v8/+/4147787 patch-fuzz update; no manual changes * chore: update patches * chore: bump chromium in DEPS to 111.0.5536.0 * chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863 Sync with upstream code changes. Minor code golf for readability. Note: upstream is laying groundwork for being able to work off of env vars instead of switches. Doesn't affect us yet but worth being aware of. > + // Environment variables could be supported in the future, but are not > + // currently supported when launching with the zygote. * chore: update patches/chromium/feat_expose_raw_response_headers_from_urlloader.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126836 patch-fuzz update; no manual changes * chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863 manual sync * chore: sync electron/patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch https://chromium-review.googlesource.com/c/v8/v8/+/4147788 fuzz-patch * chore: rebuild patches * chore: bump chromium in DEPS to 111.0.5538.0 * chore: bump chromium in DEPS to 111.0.5540.0 * chore: update patches * Remove sdk_forward_declarations https://chromium-review.googlesource.com/c/chromium/src/+/4166680 * task posting v3: Remove task runner handles from codebase entirely Refs https://chromium-review.googlesource.com/c/chromium/src/+/4150928 * Cleanup child_process_launcher_helper* Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863 * fix: utilityprocess spec on macOS * fix: build on windows Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863 * chore: fix lint * chore: bump chromium 111.0.5544.3 * chore: gen filenames.libcxx.gni * Add check for Executable+Writable handles in renderer processes. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3774416 * fixup! Add check for Executable+Writable handles in renderer processes. * 4143761: [110] Disable SwiftShader for WebGL on M1 Macs. https://chromium-review.googlesource.com/c/chromium/src/+/4143761 (cherry picked from commit 2f74db3c2139424c416f92d9169aeaa8a2f9c1ec) * chore: bump chromium to 111.0.5555.0 * 56085: Remove hmac.h include from ssl.h. https://boringssl-review.googlesource.com/c/boringssl/+/56085 * 4167020: Remove forwarding headers https://chromium-review.googlesource.com/c/chromium/src/+/4167020 * chore: bump chromium to 111.0.5559.0 * 4181044: Restrict WebCursor usage to RenderWidgetHostViewAura https://chromium-review.googlesource.com/c/chromium/src/+/4181044 * 4189437: views: rename ink_drop_host_view to ink_drop_host https://chromium-review.googlesource.com/c/chromium/src/+/4189437 * chore: bump chromium to 111.0.5560.0 * 4167016: win7dep: remove non aeroglass code https://chromium-review.googlesource.com/c/chromium/src/+/4167016 * fixup after rebase: Remove forwarding header s https://chromium-review.googlesource.com/c/chromium/src/+/4167020 * 4125755: Reland "Reject getDisplayMedia calls without user activation" https://chromium-review.googlesource.com/c/chromium/src/+/4125755 * test: add workaround * chore: update patches * fix: alter coreModuleRegExp to prevent arm crash * Revert "fix: alter coreModuleRegExp to prevent arm crash" This reverts commit 7e50630c98137831a711c5abdbc8809e60cf1d73. * 4218354: Disable the use of preserve_most on arm64 Windows https://chromium-review.googlesource.com/c/v8/v8/+/4218354 * chore: review changes --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2023-02-03 14:43:42 +03:00
expect(fs.existsSync(savePageMHTMLPath)).to.be.true('html path');
expect(fs.existsSync(savePageJsPath)).to.be.false('js path');
expect(fs.existsSync(savePageCssPath)).to.be.false('css path');
chore: bump chromium to 111.0.5544.3 (main) (#36820) * chore: bump chromium in DEPS to 111.0.5522.0 * chore: bump chromium in DEPS to 111.0.5524.0 * chore: bump chromium in DEPS to 111.0.5526.0 * chore: bump chromium in DEPS to 111.0.5528.0 * chore: update patches/chromium/mas_avoid_usage_of_private_macos_apis.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4132807 Fix simple code shear * chore: update patches/chromium/unsandboxed_ppapi_processes_skip_zygote.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4130675 Fix simple code shear * chore: update patches/chromium/hack_plugin_response_interceptor_to_point_to_electron.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/disable_unload_metrics.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126173 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/feat_add_data_parameter_to_processsingleton.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/chromium/preconnect_manager.patch https://chromium-review.googlesource.com/c/chromium/src/+/4144281 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches/v8/force_cppheapcreateparams_to_be_noncopyable.patch https://chromium-review.googlesource.com/c/v8/v8/+/3533019 Fix simple code shear; applied cleanly w/patch-fuzz * chore: update patches * chore: update patches/chromium/add_maximized_parameter_to_linuxui_getwindowframeprovider.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4128765 Upstream added a new call to HeaderContext(), whose signature we have patched * chore: bump chromium in DEPS to 111.0.5530.0 * chore: update patches * Move ChildProcessHost* from content/common to content/browser Xref: Move ChildProcessHost* from content/common to content/browser * Remove RenderViewHostChanged Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103 [upstream removal of RenderViewHostChanged] Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4092763 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4093234 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133892 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103 [examples of upstream code adjusting to the change] Upstream handles this change in roughly two approaches: 1. Move the code over to RenderFrameHostChanged(old_host, new_host) but test for new_host->IsInPrimaryMainFrame() before acting 2. Migrate to the PrimaryPageChanged(page) API and use page.GetMainDocument() to get the RenderFrameHost. I've chosen 1. because electron_api_web_contents needed that pointer to old_host to call RemoveInputEventListener(), but I may be missing some context & would appreciate review on this commit. * Make electron/shell/browser/relauncher_win.cc use <winternl.h> Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4129135 Many internal Windows types are now available in winternl.h so upstrem no longer defines the types themselves. * Move ChildProcessHost* from content/common to content/browser Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134795 * fixup! Make electron/shell/browser/relauncher_win.cc use <winternl.h> winternl.h does not define the field we need, so clone the struct Chromium was using into unnamed namespace * fixup! Move ChildProcessHost* from content/common to content/browser chore: update #includes too * chore: bump chromium in DEPS to 111.0.5532.0 * chore: sync patches/chromium/pepper_plugin_support.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 manually reync patch; no code changes * chore: sync patches/chromium/mas_no_private_api.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4143865 the content/common/pseudonymization_salt.cc patch is no longer needed * chore: sync patches/chromium/mas_disable_remote_accessibility.patch patch-fuzz update; no manual changes * chore: sync patches/chromium/build_do_not_depend_on_packed_resource_integrity.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4111725 manually reync patch; no code changes * chore: sync patches/chromium/create_browser_v8_snapshot_file_name_fuse.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 manually reync patch; no code changes * chore: sync patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch Xref: https://chromium-review.googlesource.com/c/v8/v8/+/4127230 patch-fuzz update; no manual changes * chore: rebuild patches * fixup! Remove RenderViewHostChanged Use PrimaryPageChanged() * chore: remove unused method TabsUpdateFunction::OnExecuteCodeFinished() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133991 This private, already-unused function showed up as a FTBFS because it took a base::ListValue parameter and ListValue was removed upstream. * task posting v3: remove includes of runner handles and IWYU task runners Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323 * chore: lint * chore: more lint * fixup! task posting v3: remove includes of runner handles and IWYU task runners macOS, too * fixup! task posting v3: remove includes of runner handles and IWYU task runners * chore: bump chromium in DEPS to 111.0.5534.0 * chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141862 patch-fuzz update; no manual changes * chore: sync patches/chromium/logging_win32_only_create_a_console_if_logging_to_stderr.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4153110 Sync to minor upstream changes. Add const correctness. * chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch https://chromium-review.googlesource.com/c/chromium/src/+/4141862 patch-fuzz update; no manual changes * chore: patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch sync https://chromium-review.googlesource.com/c/v8/v8/+/4147787 patch-fuzz update; no manual changes * chore: update patches * chore: bump chromium in DEPS to 111.0.5536.0 * chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863 Sync with upstream code changes. Minor code golf for readability. Note: upstream is laying groundwork for being able to work off of env vars instead of switches. Doesn't affect us yet but worth being aware of. > + // Environment variables could be supported in the future, but are not > + // currently supported when launching with the zygote. * chore: update patches/chromium/feat_expose_raw_response_headers_from_urlloader.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126836 patch-fuzz update; no manual changes * chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863 manual sync * chore: sync electron/patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch https://chromium-review.googlesource.com/c/v8/v8/+/4147788 fuzz-patch * chore: rebuild patches * chore: bump chromium in DEPS to 111.0.5538.0 * chore: bump chromium in DEPS to 111.0.5540.0 * chore: update patches * Remove sdk_forward_declarations https://chromium-review.googlesource.com/c/chromium/src/+/4166680 * task posting v3: Remove task runner handles from codebase entirely Refs https://chromium-review.googlesource.com/c/chromium/src/+/4150928 * Cleanup child_process_launcher_helper* Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863 * fix: utilityprocess spec on macOS * fix: build on windows Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863 * chore: fix lint * chore: bump chromium 111.0.5544.3 * chore: gen filenames.libcxx.gni * Add check for Executable+Writable handles in renderer processes. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3774416 * fixup! Add check for Executable+Writable handles in renderer processes. * 4143761: [110] Disable SwiftShader for WebGL on M1 Macs. https://chromium-review.googlesource.com/c/chromium/src/+/4143761 (cherry picked from commit 2f74db3c2139424c416f92d9169aeaa8a2f9c1ec) * chore: bump chromium to 111.0.5555.0 * 56085: Remove hmac.h include from ssl.h. https://boringssl-review.googlesource.com/c/boringssl/+/56085 * 4167020: Remove forwarding headers https://chromium-review.googlesource.com/c/chromium/src/+/4167020 * chore: bump chromium to 111.0.5559.0 * 4181044: Restrict WebCursor usage to RenderWidgetHostViewAura https://chromium-review.googlesource.com/c/chromium/src/+/4181044 * 4189437: views: rename ink_drop_host_view to ink_drop_host https://chromium-review.googlesource.com/c/chromium/src/+/4189437 * chore: bump chromium to 111.0.5560.0 * 4167016: win7dep: remove non aeroglass code https://chromium-review.googlesource.com/c/chromium/src/+/4167016 * fixup after rebase: Remove forwarding header s https://chromium-review.googlesource.com/c/chromium/src/+/4167020 * 4125755: Reland "Reject getDisplayMedia calls without user activation" https://chromium-review.googlesource.com/c/chromium/src/+/4125755 * test: add workaround * chore: update patches * fix: alter coreModuleRegExp to prevent arm crash * Revert "fix: alter coreModuleRegExp to prevent arm crash" This reverts commit 7e50630c98137831a711c5abdbc8809e60cf1d73. * 4218354: Disable the use of preserve_most on arm64 Windows https://chromium-review.googlesource.com/c/v8/v8/+/4218354 * chore: review changes --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2023-02-03 14:43:42 +03:00
try {
await fs.promises.unlink(savePageMHTMLPath);
await fs.promises.rmdir(tmpDir);
} catch { }
});
it('should save page to disk with HTMLComplete', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixtures, 'pages', 'save_page', 'index.html'));
await w.webContents.savePage(savePageHtmlPath, 'HTMLComplete');
expect(fs.existsSync(savePageHtmlPath)).to.be.true('html path');
expect(fs.existsSync(savePageJsPath)).to.be.true('js path');
expect(fs.existsSync(savePageCssPath)).to.be.true('css path');
});
});
describe('BrowserWindow options argument is optional', () => {
afterEach(closeAllWindows);
it('should create a window with default size (800x600)', () => {
const w = new BrowserWindow();
expect(w.getSize()).to.deep.equal([800, 600]);
});
});
describe('BrowserWindow.restore()', () => {
afterEach(closeAllWindows);
it('should restore the previous window size', () => {
const w = new BrowserWindow({
minWidth: 800,
width: 800
});
const initialSize = w.getSize();
w.minimize();
w.restore();
expectBoundsEqual(w.getSize(), initialSize);
});
it('does not crash when restoring hidden minimized window', () => {
const w = new BrowserWindow({});
w.minimize();
w.hide();
w.show();
});
// TODO(zcbenz):
// This test does not run on Linux CI. See:
// https://github.com/electron/electron/issues/28699
ifit(process.platform === 'linux' && !process.env.CI)('should bring a minimized maximized window back to maximized state', async () => {
const w = new BrowserWindow({});
const maximize = once(w, 'maximize');
w.maximize();
await maximize;
const minimize = once(w, 'minimize');
w.minimize();
await minimize;
expect(w.isMaximized()).to.equal(false);
const restore = once(w, 'restore');
w.restore();
await restore;
expect(w.isMaximized()).to.equal(true);
});
});
// TODO(dsanders11): Enable once maximize event works on Linux again on CI
ifdescribe(process.platform !== 'linux')('BrowserWindow.maximize()', () => {
afterEach(closeAllWindows);
it('should show the window if it is not currently shown', async () => {
const w = new BrowserWindow({ show: false });
const hidden = once(w, 'hide');
let shown = once(w, 'show');
const maximize = once(w, 'maximize');
expect(w.isVisible()).to.be.false('visible');
w.maximize();
await maximize;
await shown;
expect(w.isMaximized()).to.be.true('maximized');
expect(w.isVisible()).to.be.true('visible');
// Even if the window is already maximized
w.hide();
await hidden;
expect(w.isVisible()).to.be.false('visible');
shown = once(w, 'show');
w.maximize();
await shown;
expect(w.isVisible()).to.be.true('visible');
});
});
describe('BrowserWindow.unmaximize()', () => {
afterEach(closeAllWindows);
it('should restore the previous window position', () => {
const w = new BrowserWindow();
const initialPosition = w.getPosition();
w.maximize();
w.unmaximize();
expectBoundsEqual(w.getPosition(), initialPosition);
});
// TODO(dsanders11): Enable once minimize event works on Linux again.
// See https://github.com/electron/electron/issues/28699
ifit(process.platform !== 'linux')('should not restore a minimized window', async () => {
const w = new BrowserWindow();
const minimize = once(w, 'minimize');
w.minimize();
await minimize;
w.unmaximize();
await setTimeout(1000);
expect(w.isMinimized()).to.be.true();
});
it('should not change the size or position of a normal window', async () => {
const w = new BrowserWindow();
const initialSize = w.getSize();
const initialPosition = w.getPosition();
w.unmaximize();
await setTimeout(1000);
expectBoundsEqual(w.getSize(), initialSize);
expectBoundsEqual(w.getPosition(), initialPosition);
});
ifit(process.platform === 'darwin')('should not change size or position of a window which is functionally maximized', async () => {
const { workArea } = screen.getPrimaryDisplay();
const bounds = {
x: workArea.x,
y: workArea.y,
width: workArea.width,
height: workArea.height
};
const w = new BrowserWindow(bounds);
w.unmaximize();
await setTimeout(1000);
expectBoundsEqual(w.getBounds(), bounds);
});
});
describe('setFullScreen(false)', () => {
afterEach(closeAllWindows);
// only applicable to windows: https://github.com/electron/electron/issues/6036
ifdescribe(process.platform === 'win32')('on windows', () => {
it('should restore a normal visible window from a fullscreen startup state', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
const shown = once(w, 'show');
// start fullscreen and hidden
w.setFullScreen(true);
w.show();
await shown;
const leftFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leftFullScreen;
expect(w.isVisible()).to.be.true('visible');
expect(w.isFullScreen()).to.be.false('fullscreen');
});
it('should keep window hidden if already in hidden state', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
const leftFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leftFullScreen;
expect(w.isVisible()).to.be.false('visible');
expect(w.isFullScreen()).to.be.false('fullscreen');
});
});
ifdescribe(process.platform === 'darwin')('BrowserWindow.setFullScreen(false) when HTML fullscreen', () => {
it('exits HTML fullscreen when window leaves fullscreen', async () => {
const w = new BrowserWindow();
await w.loadURL('about:blank');
await w.webContents.executeJavaScript('document.body.webkitRequestFullscreen()', true);
await once(w, 'enter-full-screen');
// Wait a tick for the full-screen state to 'stick'
await setTimeout();
w.setFullScreen(false);
await once(w, 'leave-html-full-screen');
});
});
});
describe('parent window', () => {
afterEach(closeAllWindows);
ifit(process.platform === 'darwin')('sheet-begin event emits when window opens a sheet', async () => {
const w = new BrowserWindow();
const sheetBegin = once(w, 'sheet-begin');
2019-11-01 23:37:02 +03:00
// eslint-disable-next-line no-new
new BrowserWindow({
modal: true,
parent: w
});
await sheetBegin;
});
ifit(process.platform === 'darwin')('sheet-end event emits when window has closed a sheet', async () => {
const w = new BrowserWindow();
const sheet = new BrowserWindow({
modal: true,
parent: w
});
const sheetEnd = once(w, 'sheet-end');
sheet.close();
await sheetEnd;
});
describe('parent option', () => {
it('sets parent window', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w });
expect(c.getParentWindow()).to.equal(w);
});
it('adds window to child windows of parent', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w });
expect(w.getChildWindows()).to.deep.equal([c]);
});
it('removes from child windows of parent when window is closed', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w });
const closed = once(c, 'closed');
c.close();
await closed;
// The child window list is not immediately cleared, so wait a tick until it's ready.
await setTimeout();
expect(w.getChildWindows().length).to.equal(0);
});
it('can handle child window close and reparent multiple times', async () => {
const w = new BrowserWindow({ show: false });
let c: BrowserWindow | null;
for (let i = 0; i < 5; i++) {
c = new BrowserWindow({ show: false, parent: w });
const closed = once(c, 'closed');
c.close();
await closed;
}
await setTimeout();
expect(w.getChildWindows().length).to.equal(0);
});
ifit(process.platform === 'darwin')('only shows the intended window when a child with siblings is shown', async () => {
const w = new BrowserWindow({ show: false });
const childOne = new BrowserWindow({ show: false, parent: w });
const childTwo = new BrowserWindow({ show: false, parent: w });
const parentShown = once(w, 'show');
w.show();
await parentShown;
expect(childOne.isVisible()).to.be.false('childOne is visible');
expect(childTwo.isVisible()).to.be.false('childTwo is visible');
const childOneShown = once(childOne, 'show');
childOne.show();
await childOneShown;
expect(childOne.isVisible()).to.be.true('childOne is not visible');
expect(childTwo.isVisible()).to.be.false('childTwo is visible');
});
ifit(process.platform === 'darwin')('child matches parent visibility when parent visibility changes', async () => {
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w });
const wShow = once(w, 'show');
const cShow = once(c, 'show');
w.show();
c.show();
await Promise.all([wShow, cShow]);
const minimized = once(w, 'minimize');
w.minimize();
await minimized;
expect(w.isVisible()).to.be.false('parent is visible');
expect(c.isVisible()).to.be.false('child is visible');
const restored = once(w, 'restore');
w.restore();
await restored;
expect(w.isVisible()).to.be.true('parent is visible');
expect(c.isVisible()).to.be.true('child is visible');
});
ifit(process.platform === 'darwin')('parent matches child visibility when child visibility changes', async () => {
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w });
const wShow = once(w, 'show');
const cShow = once(c, 'show');
w.show();
c.show();
await Promise.all([wShow, cShow]);
const minimized = once(c, 'minimize');
c.minimize();
await minimized;
expect(c.isVisible()).to.be.false('child is visible');
const restored = once(c, 'restore');
c.restore();
await restored;
expect(w.isVisible()).to.be.true('parent is visible');
expect(c.isVisible()).to.be.true('child is visible');
});
it('closes a grandchild window when a middle child window is destroyed', async () => {
const w = new BrowserWindow();
w.loadFile(path.join(fixtures, 'pages', 'base-page.html'));
w.webContents.executeJavaScript('window.open("")');
w.webContents.on('did-create-window', async (window) => {
const childWindow = new BrowserWindow({ parent: window });
await setTimeout();
const closed = once(childWindow, 'closed');
window.close();
await closed;
expect(() => { BrowserWindow.getFocusedWindow(); }).to.not.throw();
});
});
it('should not affect the show option', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w });
expect(c.isVisible()).to.be.false('child is visible');
expect(c.getParentWindow()!.isVisible()).to.be.false('parent is visible');
});
});
describe('win.setParentWindow(parent)', () => {
it('sets parent window', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false });
expect(w.getParentWindow()).to.be.null('w.parent');
expect(c.getParentWindow()).to.be.null('c.parent');
c.setParentWindow(w);
expect(c.getParentWindow()).to.equal(w);
c.setParentWindow(null);
expect(c.getParentWindow()).to.be.null('c.parent');
});
it('adds window to child windows of parent', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false });
expect(w.getChildWindows()).to.deep.equal([]);
c.setParentWindow(w);
expect(w.getChildWindows()).to.deep.equal([c]);
c.setParentWindow(null);
expect(w.getChildWindows()).to.deep.equal([]);
});
it('removes from child windows of parent when window is closed', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false });
const closed = once(c, 'closed');
c.setParentWindow(w);
c.close();
await closed;
// The child window list is not immediately cleared, so wait a tick until it's ready.
await setTimeout();
expect(w.getChildWindows().length).to.equal(0);
});
ifit(process.platform === 'darwin')('can reparent when the first parent is destroyed', async () => {
const w1 = new BrowserWindow({ show: false });
const w2 = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false });
c.setParentWindow(w1);
expect(w1.getChildWindows().length).to.equal(1);
const closed = once(w1, 'closed');
w1.destroy();
await closed;
c.setParentWindow(w2);
await setTimeout();
const children = w2.getChildWindows();
expect(children[0]).to.equal(c);
});
});
describe('modal option', () => {
it('does not freeze or crash', async () => {
const parentWindow = new BrowserWindow();
const createTwo = async () => {
const two = new BrowserWindow({
width: 300,
height: 200,
parent: parentWindow,
modal: true,
show: false
});
const twoShown = once(two, 'show');
two.show();
await twoShown;
setTimeout(500).then(() => two.close());
await once(two, 'closed');
};
const one = new BrowserWindow({
width: 600,
height: 400,
parent: parentWindow,
modal: true,
show: false
});
const oneShown = once(one, 'show');
one.show();
await oneShown;
setTimeout(500).then(() => one.destroy());
await once(one, 'closed');
await createTwo();
});
ifit(process.platform !== 'darwin')('can disable and enable a window', () => {
const w = new BrowserWindow({ show: false });
w.setEnabled(false);
expect(w.isEnabled()).to.be.false('w.isEnabled()');
w.setEnabled(true);
expect(w.isEnabled()).to.be.true('!w.isEnabled()');
});
ifit(process.platform !== 'darwin')('disables parent window', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w, modal: true });
expect(w.isEnabled()).to.be.true('w.isEnabled');
c.show();
expect(w.isEnabled()).to.be.false('w.isEnabled');
});
ifit(process.platform !== 'darwin')('re-enables an enabled parent window when closed', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w, modal: true });
const closed = once(c, 'closed');
c.show();
c.close();
await closed;
expect(w.isEnabled()).to.be.true('w.isEnabled');
});
ifit(process.platform !== 'darwin')('does not re-enable a disabled parent window when closed', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w, modal: true });
const closed = once(c, 'closed');
w.setEnabled(false);
c.show();
c.close();
await closed;
expect(w.isEnabled()).to.be.false('w.isEnabled');
});
ifit(process.platform !== 'darwin')('disables parent window recursively', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w, modal: true });
const c2 = new BrowserWindow({ show: false, parent: w, modal: true });
c.show();
expect(w.isEnabled()).to.be.false('w.isEnabled');
c2.show();
expect(w.isEnabled()).to.be.false('w.isEnabled');
c.destroy();
expect(w.isEnabled()).to.be.false('w.isEnabled');
c2.destroy();
expect(w.isEnabled()).to.be.true('w.isEnabled');
});
});
});
describe('window states', () => {
afterEach(closeAllWindows);
it('does not resize frameless windows when states change', () => {
const w = new BrowserWindow({
frame: false,
width: 300,
height: 200,
show: false
});
w.minimizable = false;
w.minimizable = true;
expect(w.getSize()).to.deep.equal([300, 200]);
w.resizable = false;
w.resizable = true;
expect(w.getSize()).to.deep.equal([300, 200]);
w.maximizable = false;
w.maximizable = true;
expect(w.getSize()).to.deep.equal([300, 200]);
w.fullScreenable = false;
w.fullScreenable = true;
expect(w.getSize()).to.deep.equal([300, 200]);
w.closable = false;
w.closable = true;
expect(w.getSize()).to.deep.equal([300, 200]);
});
describe('resizable state', () => {
it('with properties', () => {
it('can be set with resizable constructor option', () => {
const w = new BrowserWindow({ show: false, resizable: false });
expect(w.resizable).to.be.false('resizable');
if (process.platform === 'darwin') {
expect(w.maximizable).to.to.true('maximizable');
}
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.resizable).to.be.true('resizable');
w.resizable = false;
expect(w.resizable).to.be.false('resizable');
w.resizable = true;
expect(w.resizable).to.be.true('resizable');
});
});
it('with functions', () => {
it('can be set with resizable constructor option', () => {
const w = new BrowserWindow({ show: false, resizable: false });
expect(w.isResizable()).to.be.false('resizable');
if (process.platform === 'darwin') {
expect(w.isMaximizable()).to.to.true('maximizable');
}
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isResizable()).to.be.true('resizable');
w.setResizable(false);
expect(w.isResizable()).to.be.false('resizable');
w.setResizable(true);
expect(w.isResizable()).to.be.true('resizable');
});
});
it('works for a frameless window', () => {
const w = new BrowserWindow({ show: false, frame: false });
expect(w.resizable).to.be.true('resizable');
if (process.platform === 'win32') {
const w = new BrowserWindow({ show: false, thickFrame: false });
expect(w.resizable).to.be.false('resizable');
}
});
// On Linux there is no "resizable" property of a window.
ifit(process.platform !== 'linux')('does affect maximizability when disabled and enabled', () => {
const w = new BrowserWindow({ show: false });
expect(w.resizable).to.be.true('resizable');
expect(w.maximizable).to.be.true('maximizable');
w.resizable = false;
expect(w.maximizable).to.be.false('not maximizable');
w.resizable = true;
expect(w.maximizable).to.be.true('maximizable');
});
ifit(process.platform === 'win32')('works for a window smaller than 64x64', () => {
const w = new BrowserWindow({
show: false,
frame: false,
resizable: false,
transparent: true
});
w.setContentSize(60, 60);
expectBoundsEqual(w.getContentSize(), [60, 60]);
w.setContentSize(30, 30);
expectBoundsEqual(w.getContentSize(), [30, 30]);
w.setContentSize(10, 10);
expectBoundsEqual(w.getContentSize(), [10, 10]);
});
ifit(process.platform === 'win32')('do not change window with frame bounds when maximized', () => {
const w = new BrowserWindow({
show: true,
frame: true,
thickFrame: true
});
expect(w.isResizable()).to.be.true('resizable');
w.maximize();
expect(w.isMaximized()).to.be.true('maximized');
const bounds = w.getBounds();
w.setResizable(false);
expectBoundsEqual(w.getBounds(), bounds);
w.setResizable(true);
expectBoundsEqual(w.getBounds(), bounds);
});
ifit(process.platform === 'win32')('do not change window without frame bounds when maximized', () => {
const w = new BrowserWindow({
show: true,
frame: false,
thickFrame: true
});
expect(w.isResizable()).to.be.true('resizable');
w.maximize();
expect(w.isMaximized()).to.be.true('maximized');
const bounds = w.getBounds();
w.setResizable(false);
expectBoundsEqual(w.getBounds(), bounds);
w.setResizable(true);
expectBoundsEqual(w.getBounds(), bounds);
});
ifit(process.platform === 'win32')('do not change window transparent without frame bounds when maximized', () => {
const w = new BrowserWindow({
show: true,
frame: false,
thickFrame: true,
transparent: true
});
expect(w.isResizable()).to.be.true('resizable');
w.maximize();
expect(w.isMaximized()).to.be.true('maximized');
const bounds = w.getBounds();
w.setResizable(false);
expectBoundsEqual(w.getBounds(), bounds);
w.setResizable(true);
expectBoundsEqual(w.getBounds(), bounds);
});
});
describe('loading main frame state', () => {
let server: http.Server;
let serverUrl: string;
before(async () => {
server = http.createServer((request, response) => {
response.end();
});
serverUrl = (await listen(server)).url;
});
after(() => {
server.close();
});
it('is true when the main frame is loading', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const didStartLoading = once(w.webContents, 'did-start-loading');
w.webContents.loadURL(serverUrl);
await didStartLoading;
expect(w.webContents.isLoadingMainFrame()).to.be.true('isLoadingMainFrame');
});
it('is false when only a subframe is loading', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const didStopLoading = once(w.webContents, 'did-stop-loading');
w.webContents.loadURL(serverUrl);
await didStopLoading;
expect(w.webContents.isLoadingMainFrame()).to.be.false('isLoadingMainFrame');
const didStartLoading = once(w.webContents, 'did-start-loading');
w.webContents.executeJavaScript(`
var iframe = document.createElement('iframe')
iframe.src = '${serverUrl}/page2'
document.body.appendChild(iframe)
`);
await didStartLoading;
expect(w.webContents.isLoadingMainFrame()).to.be.false('isLoadingMainFrame');
});
it('is true when navigating to pages from the same origin', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const didStopLoading = once(w.webContents, 'did-stop-loading');
w.webContents.loadURL(serverUrl);
await didStopLoading;
expect(w.webContents.isLoadingMainFrame()).to.be.false('isLoadingMainFrame');
const didStartLoading = once(w.webContents, 'did-start-loading');
w.webContents.loadURL(`${serverUrl}/page2`);
await didStartLoading;
expect(w.webContents.isLoadingMainFrame()).to.be.true('isLoadingMainFrame');
});
});
});
ifdescribe(process.platform !== 'linux')('window states (excluding Linux)', () => {
// Not implemented on Linux.
afterEach(closeAllWindows);
describe('movable state', () => {
it('with properties', () => {
it('can be set with movable constructor option', () => {
const w = new BrowserWindow({ show: false, movable: false });
expect(w.movable).to.be.false('movable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.movable).to.be.true('movable');
w.movable = false;
expect(w.movable).to.be.false('movable');
w.movable = true;
expect(w.movable).to.be.true('movable');
});
});
it('with functions', () => {
it('can be set with movable constructor option', () => {
const w = new BrowserWindow({ show: false, movable: false });
expect(w.isMovable()).to.be.false('movable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isMovable()).to.be.true('movable');
w.setMovable(false);
expect(w.isMovable()).to.be.false('movable');
w.setMovable(true);
expect(w.isMovable()).to.be.true('movable');
});
});
});
describe('visibleOnAllWorkspaces state', () => {
it('with properties', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.visibleOnAllWorkspaces).to.be.false();
w.visibleOnAllWorkspaces = true;
expect(w.visibleOnAllWorkspaces).to.be.true();
});
});
it('with functions', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isVisibleOnAllWorkspaces()).to.be.false();
w.setVisibleOnAllWorkspaces(true);
expect(w.isVisibleOnAllWorkspaces()).to.be.true();
});
});
});
ifdescribe(process.platform === 'darwin')('documentEdited state', () => {
it('with properties', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.documentEdited).to.be.false();
w.documentEdited = true;
expect(w.documentEdited).to.be.true();
});
});
it('with functions', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isDocumentEdited()).to.be.false();
w.setDocumentEdited(true);
expect(w.isDocumentEdited()).to.be.true();
});
});
});
ifdescribe(process.platform === 'darwin')('representedFilename', () => {
it('with properties', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.representedFilename).to.eql('');
w.representedFilename = 'a name';
expect(w.representedFilename).to.eql('a name');
});
});
it('with functions', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.getRepresentedFilename()).to.eql('');
w.setRepresentedFilename('a name');
expect(w.getRepresentedFilename()).to.eql('a name');
});
});
});
describe('native window title', () => {
it('with properties', () => {
it('can be set with title constructor option', () => {
const w = new BrowserWindow({ show: false, title: 'mYtItLe' });
expect(w.title).to.eql('mYtItLe');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.title).to.eql('Electron Test Main');
w.title = 'NEW TITLE';
expect(w.title).to.eql('NEW TITLE');
});
});
it('with functions', () => {
it('can be set with minimizable constructor option', () => {
const w = new BrowserWindow({ show: false, title: 'mYtItLe' });
expect(w.getTitle()).to.eql('mYtItLe');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.getTitle()).to.eql('Electron Test Main');
w.setTitle('NEW TITLE');
expect(w.getTitle()).to.eql('NEW TITLE');
});
});
});
describe('minimizable state', () => {
it('with properties', () => {
it('can be set with minimizable constructor option', () => {
const w = new BrowserWindow({ show: false, minimizable: false });
expect(w.minimizable).to.be.false('minimizable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.minimizable).to.be.true('minimizable');
w.minimizable = false;
expect(w.minimizable).to.be.false('minimizable');
w.minimizable = true;
expect(w.minimizable).to.be.true('minimizable');
});
});
it('with functions', () => {
it('can be set with minimizable constructor option', () => {
const w = new BrowserWindow({ show: false, minimizable: false });
expect(w.isMinimizable()).to.be.false('movable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isMinimizable()).to.be.true('isMinimizable');
w.setMinimizable(false);
expect(w.isMinimizable()).to.be.false('isMinimizable');
w.setMinimizable(true);
expect(w.isMinimizable()).to.be.true('isMinimizable');
});
});
});
describe('maximizable state (property)', () => {
it('with properties', () => {
it('can be set with maximizable constructor option', () => {
const w = new BrowserWindow({ show: false, maximizable: false });
expect(w.maximizable).to.be.false('maximizable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.maximizable).to.be.true('maximizable');
w.maximizable = false;
expect(w.maximizable).to.be.false('maximizable');
w.maximizable = true;
expect(w.maximizable).to.be.true('maximizable');
});
it('is not affected when changing other states', () => {
const w = new BrowserWindow({ show: false });
w.maximizable = false;
expect(w.maximizable).to.be.false('maximizable');
w.minimizable = false;
expect(w.maximizable).to.be.false('maximizable');
w.closable = false;
expect(w.maximizable).to.be.false('maximizable');
2020-03-20 23:28:31 +03:00
w.maximizable = true;
expect(w.maximizable).to.be.true('maximizable');
w.closable = true;
expect(w.maximizable).to.be.true('maximizable');
w.fullScreenable = false;
expect(w.maximizable).to.be.true('maximizable');
});
});
it('with functions', () => {
it('can be set with maximizable constructor option', () => {
const w = new BrowserWindow({ show: false, maximizable: false });
expect(w.isMaximizable()).to.be.false('isMaximizable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isMaximizable()).to.be.true('isMaximizable');
w.setMaximizable(false);
expect(w.isMaximizable()).to.be.false('isMaximizable');
w.setMaximizable(true);
expect(w.isMaximizable()).to.be.true('isMaximizable');
});
it('is not affected when changing other states', () => {
const w = new BrowserWindow({ show: false });
w.setMaximizable(false);
expect(w.isMaximizable()).to.be.false('isMaximizable');
w.setMinimizable(false);
expect(w.isMaximizable()).to.be.false('isMaximizable');
w.setClosable(false);
expect(w.isMaximizable()).to.be.false('isMaximizable');
2020-03-20 23:28:31 +03:00
w.setMaximizable(true);
expect(w.isMaximizable()).to.be.true('isMaximizable');
w.setClosable(true);
expect(w.isMaximizable()).to.be.true('isMaximizable');
w.setFullScreenable(false);
expect(w.isMaximizable()).to.be.true('isMaximizable');
});
});
});
ifdescribe(process.platform === 'win32')('maximizable state', () => {
it('with properties', () => {
it('is reset to its former state', () => {
const w = new BrowserWindow({ show: false });
w.maximizable = false;
w.resizable = false;
w.resizable = true;
expect(w.maximizable).to.be.false('maximizable');
w.maximizable = true;
w.resizable = false;
w.resizable = true;
expect(w.maximizable).to.be.true('maximizable');
});
});
it('with functions', () => {
it('is reset to its former state', () => {
const w = new BrowserWindow({ show: false });
w.setMaximizable(false);
w.setResizable(false);
w.setResizable(true);
expect(w.isMaximizable()).to.be.false('isMaximizable');
w.setMaximizable(true);
w.setResizable(false);
w.setResizable(true);
expect(w.isMaximizable()).to.be.true('isMaximizable');
});
});
});
ifdescribe(process.platform !== 'darwin')('menuBarVisible state', () => {
describe('with properties', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.menuBarVisible).to.be.true();
w.menuBarVisible = false;
expect(w.menuBarVisible).to.be.false();
w.menuBarVisible = true;
expect(w.menuBarVisible).to.be.true();
});
});
describe('with functions', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
w.setMenuBarVisibility(false);
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
w.setMenuBarVisibility(true);
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
});
});
});
ifdescribe(process.platform !== 'darwin')('when fullscreen state is changed', () => {
it('correctly remembers state prior to fullscreen change', async () => {
const w = new BrowserWindow({ show: false });
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
w.setMenuBarVisibility(false);
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
expect(w.fullScreen).to.be.true('not fullscreen');
const exitFS = once(w, 'leave-full-screen');
w.setFullScreen(false);
await exitFS;
expect(w.fullScreen).to.be.false('not fullscreen');
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
});
it('correctly remembers state prior to fullscreen change with autoHide', async () => {
const w = new BrowserWindow({ show: false });
expect(w.autoHideMenuBar).to.be.false('autoHideMenuBar');
w.autoHideMenuBar = true;
expect(w.autoHideMenuBar).to.be.true('autoHideMenuBar');
w.setMenuBarVisibility(false);
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
expect(w.fullScreen).to.be.true('not fullscreen');
const exitFS = once(w, 'leave-full-screen');
w.setFullScreen(false);
await exitFS;
expect(w.fullScreen).to.be.false('not fullscreen');
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
});
});
ifdescribe(process.platform !== 'darwin')('fullscreen state', () => {
it('correctly remembers state prior to HTML fullscreen transition', async () => {
const w = new BrowserWindow();
await w.loadFile(path.join(fixtures, 'pages', 'a.html'));
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
expect(w.isFullScreen()).to.be.false('is fullscreen');
const enterFullScreen = once(w, 'enter-full-screen');
const leaveFullScreen = once(w, 'leave-full-screen');
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;
await w.webContents.executeJavaScript('document.exitFullscreen()', true);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('is fullscreen');
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
w.setMenuBarVisibility(false);
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;
await w.webContents.executeJavaScript('document.exitFullscreen()', true);
await leaveFullScreen;
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
});
});
ifdescribe(process.platform === 'darwin')('fullscreenable state', () => {
it('with functions', () => {
it('can be set with fullscreenable constructor option', () => {
const w = new BrowserWindow({ show: false, fullscreenable: false });
expect(w.isFullScreenable()).to.be.false('isFullScreenable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isFullScreenable()).to.be.true('isFullScreenable');
w.setFullScreenable(false);
expect(w.isFullScreenable()).to.be.false('isFullScreenable');
w.setFullScreenable(true);
expect(w.isFullScreenable()).to.be.true('isFullScreenable');
});
});
it('does not open non-fullscreenable child windows in fullscreen if parent is fullscreen', async () => {
const w = new BrowserWindow();
const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
const child = new BrowserWindow({ parent: w, resizable: false, fullscreenable: false });
const shown = once(child, 'show');
await shown;
expect(child.resizable).to.be.false('resizable');
expect(child.fullScreen).to.be.false('fullscreen');
expect(child.fullScreenable).to.be.false('fullscreenable');
});
it('is set correctly with different resizable values', async () => {
const w1 = new BrowserWindow({
resizable: false,
fullscreenable: false
});
const w2 = new BrowserWindow({
resizable: true,
fullscreenable: false
});
const w3 = new BrowserWindow({
fullscreenable: false
});
expect(w1.isFullScreenable()).to.be.false('isFullScreenable');
expect(w2.isFullScreenable()).to.be.false('isFullScreenable');
expect(w3.isFullScreenable()).to.be.false('isFullScreenable');
});
it('does not disable maximize button if window is resizable', () => {
const w = new BrowserWindow({
resizable: true,
fullscreenable: false
});
expect(w.isMaximizable()).to.be.true('isMaximizable');
w.setResizable(false);
expect(w.isMaximizable()).to.be.false('isMaximizable');
});
});
ifdescribe(process.platform === 'darwin')('isHiddenInMissionControl state', () => {
it('with functions', () => {
it('can be set with ignoreMissionControl constructor option', () => {
const w = new BrowserWindow({ show: false, hiddenInMissionControl: true });
expect(w.isHiddenInMissionControl()).to.be.true('isHiddenInMissionControl');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isHiddenInMissionControl()).to.be.false('isHiddenInMissionControl');
w.setHiddenInMissionControl(true);
expect(w.isHiddenInMissionControl()).to.be.true('isHiddenInMissionControl');
w.setHiddenInMissionControl(false);
expect(w.isHiddenInMissionControl()).to.be.false('isHiddenInMissionControl');
});
});
});
// fullscreen events are dispatched eagerly and twiddling things too fast can confuse poor Electron
ifdescribe(process.platform === 'darwin')('kiosk state', () => {
it('with properties', () => {
it('can be set with a constructor property', () => {
const w = new BrowserWindow({ kiosk: true });
expect(w.kiosk).to.be.true();
});
it('can be changed ', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.kiosk = true;
expect(w.isKiosk()).to.be.true('isKiosk');
await enterFullScreen;
await setTimeout();
const leaveFullScreen = once(w, 'leave-full-screen');
w.kiosk = false;
expect(w.isKiosk()).to.be.false('isKiosk');
await leaveFullScreen;
});
});
it('with functions', () => {
it('can be set with a constructor property', () => {
const w = new BrowserWindow({ kiosk: true });
expect(w.isKiosk()).to.be.true();
});
it('can be changed ', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.setKiosk(true);
expect(w.isKiosk()).to.be.true('isKiosk');
await enterFullScreen;
await setTimeout();
const leaveFullScreen = once(w, 'leave-full-screen');
w.setKiosk(false);
expect(w.isKiosk()).to.be.false('isKiosk');
await leaveFullScreen;
});
});
});
ifdescribe(process.platform === 'darwin')('fullscreen state with resizable set', () => {
it('resizable flag should be set to false and restored', async () => {
const w = new BrowserWindow({ resizable: false });
const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
expect(w.resizable).to.be.false('resizable');
await setTimeout();
const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
expect(w.resizable).to.be.false('resizable');
});
it('default resizable flag should be restored after entering/exiting fullscreen', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
expect(w.resizable).to.be.false('resizable');
await setTimeout();
const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
expect(w.resizable).to.be.true('resizable');
});
});
ifdescribe(process.platform === 'darwin')('fullscreen state', () => {
it('should not cause a crash if called when exiting fullscreen', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
await setTimeout();
const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
});
it('should be able to load a URL while transitioning to fullscreen', async () => {
const w = new BrowserWindow({ fullscreen: true });
w.loadFile(path.join(fixtures, 'pages', 'c.html'));
const load = once(w.webContents, 'did-finish-load');
const enterFS = once(w, 'enter-full-screen');
await Promise.all([enterFS, load]);
expect(w.fullScreen).to.be.true();
await setTimeout();
const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
});
it('can be changed with setFullScreen method', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
expect(w.isFullScreen()).to.be.true('isFullScreen');
await setTimeout();
const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('isFullScreen');
});
it('handles several transitions starting with fullscreen', async () => {
const w = new BrowserWindow({ fullscreen: true, show: true });
expect(w.isFullScreen()).to.be.true('not fullscreen');
w.setFullScreen(false);
w.setFullScreen(true);
const enterFullScreen = emittedNTimes(w, 'enter-full-screen', 2);
await enterFullScreen;
expect(w.isFullScreen()).to.be.true('not fullscreen');
await setTimeout();
const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('is fullscreen');
});
it('handles several HTML fullscreen transitions', async () => {
const w = new BrowserWindow();
await w.loadFile(path.join(fixtures, 'pages', 'a.html'));
expect(w.isFullScreen()).to.be.false('is fullscreen');
const enterFullScreen = once(w, 'enter-full-screen');
const leaveFullScreen = once(w, 'leave-full-screen');
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;
await w.webContents.executeJavaScript('document.exitFullscreen()', true);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('is fullscreen');
await setTimeout();
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;
await w.webContents.executeJavaScript('document.exitFullscreen()', true);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('is fullscreen');
});
it('handles several transitions in close proximity', async () => {
const w = new BrowserWindow();
expect(w.isFullScreen()).to.be.false('is fullscreen');
const enterFS = emittedNTimes(w, 'enter-full-screen', 2);
const leaveFS = emittedNTimes(w, 'leave-full-screen', 2);
w.setFullScreen(true);
w.setFullScreen(false);
w.setFullScreen(true);
w.setFullScreen(false);
await Promise.all([enterFS, leaveFS]);
expect(w.isFullScreen()).to.be.false('not fullscreen');
});
it('handles several chromium-initiated transitions in close proximity', async () => {
const w = new BrowserWindow();
await w.loadFile(path.join(fixtures, 'pages', 'a.html'));
expect(w.isFullScreen()).to.be.false('is fullscreen');
let enterCount = 0;
let exitCount = 0;
const done = new Promise<void>(resolve => {
const checkDone = () => {
if (enterCount === 2 && exitCount === 2) resolve();
};
w.webContents.on('enter-html-full-screen', () => {
enterCount++;
checkDone();
});
w.webContents.on('leave-html-full-screen', () => {
exitCount++;
checkDone();
});
});
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await w.webContents.executeJavaScript('document.exitFullscreen()');
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await w.webContents.executeJavaScript('document.exitFullscreen()');
await done;
});
it('handles HTML fullscreen transitions when fullscreenable is false', async () => {
const w = new BrowserWindow({ fullscreenable: false });
await w.loadFile(path.join(fixtures, 'pages', 'a.html'));
expect(w.isFullScreen()).to.be.false('is fullscreen');
let enterCount = 0;
let exitCount = 0;
const done = new Promise<void>((resolve, reject) => {
const checkDone = () => {
if (enterCount === 2 && exitCount === 2) resolve();
};
w.webContents.on('enter-html-full-screen', async () => {
enterCount++;
if (w.isFullScreen()) reject(new Error('w.isFullScreen should be false'));
await waitUntil(async () => {
const isFS = await w.webContents.executeJavaScript('!!document.fullscreenElement');
return isFS === true;
});
checkDone();
});
w.webContents.on('leave-html-full-screen', () => {
exitCount++;
if (w.isFullScreen()) reject(new Error('w.isFullScreen should be false'));
checkDone();
});
});
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await w.webContents.executeJavaScript('document.exitFullscreen()');
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await w.webContents.executeJavaScript('document.exitFullscreen()');
await expect(done).to.eventually.be.fulfilled();
});
it('does not crash when exiting simpleFullScreen (properties)', async () => {
const w = new BrowserWindow();
w.setSimpleFullScreen(true);
await setTimeout(1000);
w.setFullScreen(!w.isFullScreen());
});
it('does not crash when exiting simpleFullScreen (functions)', async () => {
const w = new BrowserWindow();
w.simpleFullScreen = true;
await setTimeout(1000);
w.setFullScreen(!w.isFullScreen());
});
it('should not be changed by setKiosk method', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.setKiosk(true);
await enterFullScreen;
expect(w.isFullScreen()).to.be.true('isFullScreen');
const leaveFullScreen = once(w, 'leave-full-screen');
w.setKiosk(false);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('isFullScreen');
});
it('should stay fullscreen if fullscreen before kiosk', async () => {
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
expect(w.isFullScreen()).to.be.true('isFullScreen');
w.setKiosk(true);
w.setKiosk(false);
// Wait enough time for a fullscreen change to take effect.
await setTimeout(2000);
expect(w.isFullScreen()).to.be.true('isFullScreen');
});
2021-07-09 23:38:25 +03:00
it('multiple windows inherit correct fullscreen state', async () => {
2021-07-09 23:38:25 +03:00
const w = new BrowserWindow();
const enterFullScreen = once(w, 'enter-full-screen');
2021-07-09 23:38:25 +03:00
w.setFullScreen(true);
await enterFullScreen;
expect(w.isFullScreen()).to.be.true('isFullScreen');
await setTimeout(1000);
const w2 = new BrowserWindow({ show: false });
const enterFullScreen2 = once(w2, 'enter-full-screen');
w2.show();
await enterFullScreen2;
2021-07-09 23:38:25 +03:00
expect(w2.isFullScreen()).to.be.true('isFullScreen');
});
});
describe('closable state', () => {
it('with properties', () => {
it('can be set with closable constructor option', () => {
const w = new BrowserWindow({ show: false, closable: false });
expect(w.closable).to.be.false('closable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.closable).to.be.true('closable');
w.closable = false;
expect(w.closable).to.be.false('closable');
w.closable = true;
expect(w.closable).to.be.true('closable');
});
});
it('with functions', () => {
it('can be set with closable constructor option', () => {
const w = new BrowserWindow({ show: false, closable: false });
expect(w.isClosable()).to.be.false('isClosable');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isClosable()).to.be.true('isClosable');
w.setClosable(false);
expect(w.isClosable()).to.be.false('isClosable');
w.setClosable(true);
expect(w.isClosable()).to.be.true('isClosable');
});
});
});
describe('hasShadow state', () => {
it('with properties', () => {
it('returns a boolean on all platforms', () => {
const w = new BrowserWindow({ show: false });
expect(w.shadow).to.be.a('boolean');
});
// On Windows there's no shadow by default & it can't be changed dynamically.
it('can be changed with hasShadow option', () => {
const hasShadow = process.platform !== 'darwin';
const w = new BrowserWindow({ show: false, hasShadow });
expect(w.shadow).to.equal(hasShadow);
});
it('can be changed with setHasShadow method', () => {
const w = new BrowserWindow({ show: false });
w.shadow = false;
expect(w.shadow).to.be.false('hasShadow');
w.shadow = true;
expect(w.shadow).to.be.true('hasShadow');
w.shadow = false;
expect(w.shadow).to.be.false('hasShadow');
});
});
describe('with functions', () => {
it('returns a boolean on all platforms', () => {
const w = new BrowserWindow({ show: false });
const hasShadow = w.hasShadow();
expect(hasShadow).to.be.a('boolean');
});
// On Windows there's no shadow by default & it can't be changed dynamically.
it('can be changed with hasShadow option', () => {
const hasShadow = process.platform !== 'darwin';
const w = new BrowserWindow({ show: false, hasShadow });
expect(w.hasShadow()).to.equal(hasShadow);
});
it('can be changed with setHasShadow method', () => {
const w = new BrowserWindow({ show: false });
w.setHasShadow(false);
expect(w.hasShadow()).to.be.false('hasShadow');
w.setHasShadow(true);
expect(w.hasShadow()).to.be.true('hasShadow');
w.setHasShadow(false);
expect(w.hasShadow()).to.be.false('hasShadow');
});
});
});
});
describe('window.getMediaSourceId()', () => {
afterEach(closeAllWindows);
it('returns valid source id', async () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const shown = once(w, 'show');
w.show();
await shown;
// Check format 'window:1234:0'.
const sourceId = w.getMediaSourceId();
expect(sourceId).to.match(/^window:\d+:\d+$/);
});
});
ifdescribe(!process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS)('window.getNativeWindowHandle()', () => {
afterEach(closeAllWindows);
it('returns valid handle', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
const isValidWindow = require('@electron-ci/is-valid-window');
expect(isValidWindow(w.getNativeWindowHandle())).to.be.true('is valid window');
});
});
ifdescribe(process.platform === 'darwin')('previewFile', () => {
afterEach(closeAllWindows);
it('opens the path in Quick Look on macOS', () => {
2019-11-01 23:37:02 +03:00
const w = new BrowserWindow({ show: false });
expect(() => {
w.previewFile(__filename);
w.closeFilePreview();
}).to.not.throw();
});
it('should not call BrowserWindow show event', async () => {
const w = new BrowserWindow({ show: false });
const shown = once(w, 'show');
w.show();
await shown;
let showCalled = false;
w.on('show', () => {
showCalled = true;
});
w.previewFile(__filename);
await setTimeout(500);
expect(showCalled).to.equal(false, 'should not have called show twice');
});
});
// TODO (jkleinsc) renable these tests on mas arm64
ifdescribe(!process.mas || process.arch !== 'arm64')('contextIsolation option with and without sandbox option', () => {
const expectedContextData = {
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'
}
};
afterEach(closeAllWindows);
it('separates the page context from the Electron/preload context', async () => {
const iw = new BrowserWindow({
show: false,
webPreferences: {
contextIsolation: true,
preload: path.join(fixtures, 'api', 'isolated-preload.js')
}
});
const p = once(ipcMain, 'isolated-world');
iw.loadFile(path.join(fixtures, 'api', 'isolated.html'));
const [, data] = await p;
expect(data).to.deep.equal(expectedContextData);
});
it('recreates the contexts on reload', async () => {
const iw = new BrowserWindow({
show: false,
webPreferences: {
contextIsolation: true,
preload: path.join(fixtures, 'api', 'isolated-preload.js')
}
});
await iw.loadFile(path.join(fixtures, 'api', 'isolated.html'));
const isolatedWorld = once(ipcMain, 'isolated-world');
iw.webContents.reload();
const [, data] = await isolatedWorld;
expect(data).to.deep.equal(expectedContextData);
});
it('enables context isolation on child windows', async () => {
const iw = new BrowserWindow({
show: false,
webPreferences: {
contextIsolation: true,
preload: path.join(fixtures, 'api', 'isolated-preload.js')
}
});
const browserWindowCreated = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
iw.loadFile(path.join(fixtures, 'pages', 'window-open.html'));
const [, window] = await browserWindowCreated;
expect(window.webContents.getLastWebPreferences()!.contextIsolation).to.be.true('contextIsolation');
});
it('separates the page context from the Electron/preload context with sandbox on', async () => {
const ws = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
contextIsolation: true,
preload: path.join(fixtures, 'api', 'isolated-preload.js')
}
});
const p = once(ipcMain, 'isolated-world');
ws.loadFile(path.join(fixtures, 'api', 'isolated.html'));
const [, data] = await p;
expect(data).to.deep.equal(expectedContextData);
});
it('recreates the contexts on reload with sandbox on', async () => {
const ws = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
contextIsolation: true,
preload: path.join(fixtures, 'api', 'isolated-preload.js')
}
});
await ws.loadFile(path.join(fixtures, 'api', 'isolated.html'));
const isolatedWorld = once(ipcMain, 'isolated-world');
ws.webContents.reload();
const [, data] = await isolatedWorld;
expect(data).to.deep.equal(expectedContextData);
});
it('supports fetch api', async () => {
const fetchWindow = new BrowserWindow({
show: false,
webPreferences: {
contextIsolation: true,
preload: path.join(fixtures, 'api', 'isolated-fetch-preload.js')
}
});
const p = once(ipcMain, 'isolated-fetch-error');
fetchWindow.loadURL('about:blank');
const [, error] = await p;
expect(error).to.equal('Failed to fetch');
});
it('doesn\'t break ipc serialization', async () => {
const iw = new BrowserWindow({
show: false,
webPreferences: {
contextIsolation: true,
preload: path.join(fixtures, 'api', 'isolated-preload.js')
}
});
const p = once(ipcMain, 'isolated-world');
iw.loadURL('about:blank');
iw.webContents.executeJavaScript(`
const opened = window.open()
openedLocation = opened.location.href
opened.close()
window.postMessage({openedLocation}, '*')
`);
const [, data] = await p;
expect(data.pageContext.openedLocation).to.equal('about:blank');
});
it('reports process.contextIsolated', async () => {
const iw = new BrowserWindow({
show: false,
webPreferences: {
contextIsolation: true,
preload: path.join(fixtures, 'api', 'isolated-process.js')
}
});
const p = once(ipcMain, 'context-isolation');
iw.loadURL('about:blank');
const [, contextIsolation] = await p;
expect(contextIsolation).to.be.true('contextIsolation');
});
});
it('reloading does not cause Node.js module API hangs after reload', (done) => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
let count = 0;
ipcMain.on('async-node-api-done', () => {
if (count === 3) {
ipcMain.removeAllListeners('async-node-api-done');
done();
} else {
count++;
w.reload();
}
});
w.loadFile(path.join(fixtures, 'pages', 'send-after-node.html'));
});
describe('window.webContents.focus()', () => {
afterEach(closeAllWindows);
it('focuses window', async () => {
const w1 = new BrowserWindow({ x: 100, y: 300, width: 300, height: 200 });
w1.loadURL('about:blank');
const w2 = new BrowserWindow({ x: 300, y: 300, width: 300, height: 200 });
w2.loadURL('about:blank');
const w1Focused = once(w1, 'focus');
w1.webContents.focus();
chore: bump chromium to 98.0.4706.0 (main) (#31555) * chore: bump chromium in DEPS to 97.0.4678.0 * chore: bump chromium in DEPS to 97.0.4679.0 * chore: bump chromium in DEPS to 97.0.4680.0 * chore: bump chromium in DEPS to 97.0.4681.0 * chore: bump chromium in DEPS to 97.0.4682.0 * chore: update patches * 3234737: Disable -Wunused-but-set-variable Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3234737 * 3216953: Reland "Move task-related files from base/ to base/task/" Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3216953 * 3202710: TimeDelta factory function migration. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3202710 * 3226841: Rename WCO::RenderProcessGone to PrimaryMainFrameRenderProcessGone Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3226841 * 3212165: blink/gin: changes blink to load snapshot based on runtime information Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3212165 * 3220292: Deprecate returning a GURL from GURL::GetOrigin() Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3220292 * 3231995: build: Enable -Wbitwise-instead-of-logical everywhere except iOS and Windows Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3231995 * 3205121: Remove base::DictionaryValue::GetDouble Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3205121 * 3208413: [flags] Make --js-flags settings have priority over V8 features Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3208413 * chore: bump chromium in DEPS to 97.0.4683.0 * chore: update patches * 3188834: Combine RWHVBase GetCurrentDeviceScaleFactor/GetDeviceScaleFactor Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3188834 * chore: update process_singleton patches * chore: bump chromium in DEPS to 97.0.4684.0 * chore: update patches * chore: bump chromium in DEPS to 97.0.4685.0 * chore: update patches * chore: bump chromium in DEPS to 97.0.4686.0 * chore: update patches * chore: bump chromium in DEPS to 97.0.4687.0 * chore: update patches * chore: bump chromium in DEPS to 97.0.4688.0 * chore: update patches * 3247722: Use correct source_site_instance if navigating via context menu Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3247722 Update signature of HandleContextMenu() * 3247722: Use correct source_site_instance if navigating via context menu Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3247722 Update signature of HandleContextMenu() * 3223422: Remove PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE enum option Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3223422 sync pepper_plugin_support.patch with upstream * chore: bump chromium in DEPS to 97.0.4689.0 * 3247791: ax_mac_merge: Merge AX Math attribute implementations Xref: ax_mac_merge: Merge AX Math attribute implementations chore: fix minor patch shear in #includes * 3243425: Add VisibleTimeRequestTrigger helper class Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3243425 chore: fix minor patch shear in #includes * chore: regen chromium patches * fixup! 3247722: Use correct source_site_instance if navigating via context menu * chore: bump chromium in DEPS to 97.0.4690.0 * 3188659: Window Placement: make GetScreenInfo(s) const Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3188659 simple sync GetScreenInfo with upstream refactor * chore: update patches * chore: bump chromium in DEPS to 97.0.4690.4 * chore: bump chromium in DEPS to 97.0.4692.0 * 3198073: ozone: //content: clean up from USE_X11 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3198073 Fixing patch shear. Nothing to see here. * 3252338: Remove label images checkbox from chrome://accessibility page Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3252338 Part of our a11y patch is no longer needed due to upstream label removal * 3258183: Remove DISALLOW_IMPLICIT_CONSTRUCTORS() definition Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3258183 Replace our use of the macro with explicitly-deleted class methods. See https://chromium-review.googlesource.com/c/chromium/src/+/3256952 for upstream examples of this same replacement. * chore: update patches * 3247295: Unwind SecurityStyleExplanations Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3247295 update GetSecurityStyle() signature and impl to match upstream changes * 3259578: media: grabs lock to ensure video output when occluded Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3259578 Add stub for new upstream virtual method OnCapturerCountChanged() * fixup! 3247295: Unwind SecurityStyleExplanations * 3238504: Fix up drag image is not shown from bookmark bar Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3238504 SetDragImage() no longer takes a widget argument * 3217452: [devtools] Add getSyncInformation host binding Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3217452 Add stub for new upstream method GetSyncInformation(). Stub sends info back to caller saying that syncing is disabled. * chore: bump chromium in DEPS to 98.0.4693.0 * chore: bump chromium in DEPS to 98.0.4694.0 * chore: bump chromium in DEPS to 98.0.4695.0 * chore: bump chromium in DEPS to 98.0.4696.0 * chore: bump chromium in DEPS to 98.0.4697.0 * chore: bump chromium in DEPS to 98.0.4699.0 * chore: bump chromium in DEPS to 98.0.4701.0 * chore: bump chromium in DEPS to 98.0.4703.0 * chore: bump chromium in DEPS to 98.0.4705.0 * chore: bump chromium in DEPS to 98.0.4706.0 * chore: update patches * 3279210: Rename "base/macros.h" => "base/ignore_result.h" https://chromium-review.googlesource.com/c/chromium/src/+/3279210 * 3259964: Remove all DISALLOW_COPY_AND_ASSIGNs https://chromium-review.googlesource.com/c/chromium/src/+/3259964 * 3269029: blink/gin: sets histogram callbacks during isolate creation https://chromium-review.googlesource.com/c/chromium/src/+/3269029 * fixup after rebase * [content] Make ContentMainParams and MainFunctionParams move-only https://chromium-review.googlesource.com/c/chromium/src/+/3244976 * 3255305: Stop sending the securityStateChanged event and unwind https://chromium-review.googlesource.com/c/chromium/src/+/3255305 * [Blink] Add promise support to WebLocalFrame::RequestExecuteScript() https://chromium-review.googlesource.com/c/chromium/src/+/3230010 * 3256162: Simplify RWHV Show and ShowWithVisibility handling https://chromium-review.googlesource.com/c/chromium/src/+/3256162 * 3263824: ozone: //ui/base: clean up from USE_X11 1/* https://chromium-review.googlesource.com/c/chromium/src/+/3263824 * Request or cancel RecordContentToPresentationTimeRequest during capture https://chromium-review.googlesource.com/c/chromium/src/+/3256802 * appcache: remove BrowsingData/quota references https://chromium-review.googlesource.com/c/chromium/src/+/3255725 * [Autofill] Don't show Autofill dropdown if overlaps with permissions https://chromium-review.googlesource.com/c/chromium/src/+/3236729 * Rename to_different_document to should_show_loading_ui in LoadingStateChanged() callbacks https://chromium-review.googlesource.com/c/chromium/src/+/3268574 * cleanup patch * fixup [content] Make ContentMainParams and MainFunctionParams move-only * 3279210: Rename "base/macros.h" => "base/ignore_result.h" https://chromium-review.googlesource.com/c/chromium/src/+/3279210 * ozone: //chrome/browser clean up from USE_X11 https://chromium-review.googlesource.com/c/chromium/src/+/3186490 Refs: https://github.com/electron/electron/issues/31382 * chore: update support_mixed_sandbox_with_zygote.patch * Enable -Wunused-but-set-variable. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3234737 * fixup! ozone: //ui/base: clean up from USE_X11 1/* * fixup! ozone: //chrome/browser clean up from USE_X11 * chore: fix deprecation warning in libuv * chore: fixup for lint * 3251161: Reland "Make the Clang update.py script require Python 3" https://chromium-review.googlesource.com/c/chromium/src/+/3251161 * fixup: Enable -Wunused-but-set-variable. * [base][win] Rename DIR_APP_DATA to DIR_ROAMING_APP_DATA https://chromium-review.googlesource.com/c/chromium/src/+/3262369 * Replace sandbox::policy::SandboxType with mojom Sandbox enum https://chromium-review.googlesource.com/c/chromium/src/+/3213677 * fixup: [content] Make ContentMainParams and MainFunctionParams move-only * build: ensure angle has a full git checkout available to it * fixup: [base][win] Rename DIR_APP_DATA to DIR_ROAMING_APP_DATA * fixup lint * [unseasoned-pdf] Dispatch 'afterprint' event in PDF plugin frame https://chromium-review.googlesource.com/c/chromium/src/+/3223434 * fixup: [Autofill] Don't show Autofill dropdown if overlaps with permissions * 3217591: Move browser UI CSS color parsing to own file part 2/2 https://chromium-review.googlesource.com/c/chromium/src/+/3217591 * Make kNoSandboxAndElevatedPrivileges only available to utilities https://chromium-review.googlesource.com/c/chromium/src/+/3276784 * 3211575: [modules] Change ScriptOrModule to custom Struct https://chromium-review.googlesource.com/c/v8/v8/+/3211575 * Address review feedback * chore: update patches * 3211575: [modules] Change ScriptOrModule to custom Struct https://chromium-review.googlesource.com/c/v8/v8/+/3211575 * fix: unused variable compat * chore: remove redundant patch * fixup for 3262517: Re-enable WindowCaptureMacV2 https://chromium-review.googlesource.com/c/chromium/src/+/3262517 * chore: cleanup todo The functions added in https://chromium-review.googlesource.com/c/chromium/src/+/3256802 are not used by offscreen rendering. * fixup: update mas_no_private_api.patch * 3216879: [PA] Make features::kPartitionAllocLazyCommit to be PartitionOptions::LazyCommit Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3216879 Fixes up commit b2f1aca95604ec61649808c846657454097e6935 * chore: cleanup support_mixed_sandbox_with_zygote.patch * test: use window focus event instead of delay to wait for webContents focus Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <khammond@slack-corp.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2021-11-24 11:45:59 +03:00
await w1Focused;
expect(w1.webContents.isFocused()).to.be.true('focuses window');
});
});
describe('offscreen rendering', () => {
let w: BrowserWindow;
beforeEach(function () {
w = new BrowserWindow({
width: 100,
height: 100,
show: false,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
});
});
afterEach(closeAllWindows);
it('creates offscreen window with correct size', async () => {
const paint = once(w.webContents, 'paint') as Promise<[any, Electron.Rectangle, Electron.NativeImage]>;
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
const [, , data] = await paint;
expect(data.constructor.name).to.equal('NativeImage');
expect(data.isEmpty()).to.be.false('data is empty');
const size = data.getSize();
const { scaleFactor } = screen.getPrimaryDisplay();
expect(size.width).to.be.closeTo(100 * scaleFactor, 2);
expect(size.height).to.be.closeTo(100 * scaleFactor, 2);
});
it('does not crash after navigation', () => {
w.webContents.loadURL('about:blank');
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
});
describe('window.webContents.isOffscreen()', () => {
it('is true for offscreen type', () => {
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
expect(w.webContents.isOffscreen()).to.be.true('isOffscreen');
});
it('is false for regular window', () => {
const c = new BrowserWindow({ show: false });
expect(c.webContents.isOffscreen()).to.be.false('isOffscreen');
c.destroy();
});
});
describe('window.webContents.isPainting()', () => {
it('returns whether is currently painting', async () => {
const paint = once(w.webContents, 'paint') as Promise<[any, Electron.Rectangle, Electron.NativeImage]>;
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await paint;
expect(w.webContents.isPainting()).to.be.true('isPainting');
});
});
describe('window.webContents.stopPainting()', () => {
it('stops painting', async () => {
const domReady = once(w.webContents, 'dom-ready');
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await domReady;
w.webContents.stopPainting();
expect(w.webContents.isPainting()).to.be.false('isPainting');
});
});
describe('window.webContents.startPainting()', () => {
it('starts painting', async () => {
const domReady = once(w.webContents, 'dom-ready');
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await domReady;
w.webContents.stopPainting();
w.webContents.startPainting();
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.isPainting()).to.be.true('isPainting');
});
});
describe('frameRate APIs', () => {
it('has default frame rate (function)', async () => {
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.getFrameRate()).to.equal(60);
});
it('has default frame rate (property)', async () => {
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.frameRate).to.equal(60);
});
it('sets custom frame rate (function)', async () => {
const domReady = once(w.webContents, 'dom-ready');
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await domReady;
w.webContents.setFrameRate(30);
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.getFrameRate()).to.equal(30);
});
it('sets custom frame rate (property)', async () => {
const domReady = once(w.webContents, 'dom-ready');
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await domReady;
w.webContents.frameRate = 30;
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.frameRate).to.equal(30);
});
});
});
describe('offscreen rendering image', () => {
afterEach(closeAllWindows);
const imagePath = path.join(fixtures, 'assets', 'osr.png');
const targetImage = nativeImage.createFromPath(imagePath);
const nativeModulesEnabled = !process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS;
ifit(nativeModulesEnabled && ['win32'].includes(process.platform))('use shared texture, hardware acceleration enabled', (done) => {
const { ExtractPixels, InitializeGpu } = require('@electron-ci/osr-gpu');
try {
InitializeGpu();
} catch (e) {
console.log('Failed to initialize GPU, this spec needs a valid GPU device. Skipping...');
console.error(e);
done();
return;
}
const w = new BrowserWindow({
show: false,
webPreferences: {
offscreen: {
useSharedTexture: true
}
},
transparent: true,
frame: false,
width: 128,
height: 128
});
w.webContents.once('paint', async (e, dirtyRect) => {
try {
expect(e.texture).to.be.not.null();
const pixels = ExtractPixels(e.texture!.textureInfo);
const img = nativeImage.createFromBitmap(pixels, { width: dirtyRect.width, height: dirtyRect.height, scaleFactor: 1 });
expect(img.toBitmap().equals(targetImage.toBitmap())).to.equal(true);
done();
} catch (e) {
done(e);
}
});
w.loadFile(imagePath);
});
});
describe('"transparent" option', () => {
afterEach(closeAllWindows);
ifit(process.platform !== 'linux')('correctly returns isMaximized() when the window is maximized then minimized', async () => {
const w = new BrowserWindow({
frame: false,
transparent: true
});
const maximize = once(w, 'maximize');
w.maximize();
await maximize;
const minimize = once(w, 'minimize');
w.minimize();
await minimize;
expect(w.isMaximized()).to.be.false();
expect(w.isMinimized()).to.be.true();
});
// Only applicable on Windows where transparent windows can't be maximized.
ifit(process.platform === 'win32')('can show maximized frameless window', async () => {
const display = screen.getPrimaryDisplay();
const w = new BrowserWindow({
...display.bounds,
frame: false,
transparent: true,
show: true
});
w.loadURL('about:blank');
await once(w, 'ready-to-show');
expect(w.isMaximized()).to.be.true();
// Fails when the transparent HWND is in an invalid maximized state.
expect(w.getBounds()).to.deep.equal(display.workArea);
const newBounds = { width: 256, height: 256, x: 0, y: 0 };
w.setBounds(newBounds);
expect(w.getBounds()).to.deep.equal(newBounds);
});
// FIXME(codebytere): figure out why these are failing on MAS arm64.
ifit(hasCapturableScreen() && !(process.mas && process.arch === 'arm64'))('should not display a visible background', async () => {
const display = screen.getPrimaryDisplay();
const backgroundWindow = new BrowserWindow({
...display.bounds,
frame: false,
backgroundColor: HexColors.GREEN,
hasShadow: false
});
await backgroundWindow.loadURL('about:blank');
const foregroundWindow = new BrowserWindow({
...display.bounds,
show: true,
transparent: true,
frame: false,
hasShadow: false
});
const colorFile = path.join(__dirname, 'fixtures', 'pages', 'half-background-color.html');
await foregroundWindow.loadFile(colorFile);
const screenCapture = new ScreenCapture(display);
await screenCapture.expectColorAtPointOnDisplayMatches(
HexColors.GREEN,
(size) => ({
x: size.width / 4,
y: size.height / 2
})
);
await screenCapture.expectColorAtPointOnDisplayMatches(
HexColors.RED,
(size) => ({
x: size.width * 3 / 4,
y: size.height / 2
})
);
});
// FIXME(codebytere): figure out why these are failing on MAS arm64.
ifit(hasCapturableScreen() && !(process.mas && process.arch === 'arm64'))('Allows setting a transparent window via CSS', async () => {
const display = screen.getPrimaryDisplay();
const backgroundWindow = new BrowserWindow({
...display.bounds,
frame: false,
backgroundColor: HexColors.PURPLE,
hasShadow: false
});
await backgroundWindow.loadURL('about:blank');
const foregroundWindow = new BrowserWindow({
...display.bounds,
frame: false,
transparent: true,
hasShadow: false,
webPreferences: {
contextIsolation: false,
nodeIntegration: true
}
});
foregroundWindow.loadFile(path.join(__dirname, 'fixtures', 'pages', 'css-transparent.html'));
await once(ipcMain, 'set-transparent');
const screenCapture = new ScreenCapture(display);
await screenCapture.expectColorAtCenterMatches(HexColors.PURPLE);
});
ifit(hasCapturableScreen())('should not make background transparent if falsy', async () => {
const display = screen.getPrimaryDisplay();
for (const transparent of [false, undefined]) {
const window = new BrowserWindow({
...display.bounds,
transparent
});
await once(window, 'show');
await window.webContents.loadURL('data:text/html,<head><meta name="color-scheme" content="dark"></head>');
const screenCapture = new ScreenCapture(display);
// color-scheme is set to dark so background should not be white
await screenCapture.expectColorAtCenterDoesNotMatch(HexColors.WHITE);
window.close();
}
});
});
describe('"backgroundColor" option', () => {
afterEach(closeAllWindows);
ifit(hasCapturableScreen())('should display the set color', async () => {
const display = screen.getPrimaryDisplay();
const w = new BrowserWindow({
...display.bounds,
show: true,
backgroundColor: HexColors.BLUE
});
w.loadURL('about:blank');
await once(w, 'ready-to-show');
const screenCapture = new ScreenCapture(display);
await screenCapture.expectColorAtCenterMatches(HexColors.BLUE);
});
});
describe('draggable regions', () => {
afterEach(closeAllWindows);
ifit(hasCapturableScreen())('should allow the window to be dragged when enabled', async () => {
// FIXME: nut-js has been removed from npm; we need to find a replacement
// WOA fails to load libnut so we're using require to defer loading only
// on supported platforms.
// "@nut-tree\libnut-win32\build\Release\libnut.node is not a valid Win32 application."
chore: bump chromium to 123.0.6272.0 (main) (#41130) * chore: bump chromium in DEPS to 123.0.6265.0 * chore: bump chromium in DEPS to 123.0.6266.0 * chore: update feat_ensure_mas_builds_of_the_same_application_can_use_safestorage.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5232280 reverts the revert *and* undoes the rewrites :dizzy_face: * chore: update chromium/disable_hidden.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5148491 minor manual intervention * chore: update patches * chore: Rename mouse lock to pointer lock Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5148491 * refactor: fix use of newly-removed QuitCurrentWhenIdleClosureDeprecated() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4710351 Xref: https://github.com/electron/electron/pull/26022 This usage was added in #26022 as part of Wayland support and some simple fiddles WfM with this patch on Wayland, but I'm unsure what to be testing for & would like a second opinion on this commit. * chore: bump chromium in DEPS to 123.0.6268.0 * chore: update patches * 5235021: WebUI: Migrate accessibility and bluetooth internals to WebUIConfig https://chromium-review.googlesource.com/c/chromium/src/+/5235021 * address review comment for 5196547 See: https://chromium-review.googlesource.com/c/chromium/src/+/5196547 Review comment: https://github.com/electron/electron/pull/41130#discussion_r1468973786 * 5075962: Introduce URLLoaderFactoryBuilder https://chromium-review.googlesource.com/c/chromium/src/+/5075962 * chore: bump chromium in DEPS to 123.0.6270.0 * the missing semicolon strikes again * chore: update chromium patches * chore: update v8 patches * 5242326: Some followup cleanup to Fuchia files in chrome | https://chromium-review.googlesource.com/c/chromium/src/+/5242326 * chore: bump chromium in DEPS to 123.0.6272.0 * chore: update patches * chore: update patch after rebase * 5247339: [Clipboard] Remove ClipboardContentType enum. https://chromium-review.googlesource.com/c/chromium/src/+/5247339 * Reland: "Allow content shell to enable the built-in DNS resolver" https://chromium-review.googlesource.com/c/chromium/src/+/5232354 * 5018206: [accessibility] Migrate to ScopedAccessibilityMode https://chromium-review.googlesource.com/c/chromium/src/+/5018206 * 5246669: [Default Nav Transition]Add GetBackForwardTransitionAnimationManager on WebContentsView | https://chromium-review.googlesource.com/c/chromium/src/+/5246669 * fix: move nut-js to optional spec deps (#41199) * chore: bump chromium in DEPS to 123.0.6265.0 * chore: bump chromium in DEPS to 123.0.6266.0 * chore: update feat_ensure_mas_builds_of_the_same_application_can_use_safestorage.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5232280 reverts the revert *and* undoes the rewrites :dizzy_face: * chore: update chromium/disable_hidden.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5148491 minor manual intervention * chore: update patches * chore: Rename mouse lock to pointer lock Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5148491 * refactor: fix use of newly-removed QuitCurrentWhenIdleClosureDeprecated() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4710351 Xref: https://github.com/electron/electron/pull/26022 This usage was added in #26022 as part of Wayland support and some simple fiddles WfM with this patch on Wayland, but I'm unsure what to be testing for & would like a second opinion on this commit. * chore: bump chromium in DEPS to 123.0.6268.0 * chore: update patches * 5235021: WebUI: Migrate accessibility and bluetooth internals to WebUIConfig https://chromium-review.googlesource.com/c/chromium/src/+/5235021 * address review comment for 5196547 See: https://chromium-review.googlesource.com/c/chromium/src/+/5196547 Review comment: https://github.com/electron/electron/pull/41130#discussion_r1468973786 * 5075962: Introduce URLLoaderFactoryBuilder https://chromium-review.googlesource.com/c/chromium/src/+/5075962 * chore: bump chromium in DEPS to 123.0.6270.0 * the missing semicolon strikes again * chore: update chromium patches * chore: update v8 patches * 5242326: Some followup cleanup to Fuchia files in chrome | https://chromium-review.googlesource.com/c/chromium/src/+/5242326 * chore: bump chromium in DEPS to 123.0.6272.0 * chore: update patches * chore: update patch after rebase * 5247339: [Clipboard] Remove ClipboardContentType enum. https://chromium-review.googlesource.com/c/chromium/src/+/5247339 * Reland: "Allow content shell to enable the built-in DNS resolver" https://chromium-review.googlesource.com/c/chromium/src/+/5232354 * 5018206: [accessibility] Migrate to ScopedAccessibilityMode https://chromium-review.googlesource.com/c/chromium/src/+/5018206 * 5246669: [Default Nav Transition]Add GetBackForwardTransitionAnimationManager on WebContentsView | https://chromium-review.googlesource.com/c/chromium/src/+/5246669 * fix: typescript error for optional dependency (cherry picked from commit ea17105c8c01bd1f4c1df5e72190a687d92f93cc) --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Sam Maddock <smaddock@slack-corp.com>
2024-02-01 02:04:13 +03:00
// @ts-ignore: nut-js is an optional dependency so it may not be installed
const { mouse, straightTo, centerOf, Region, Button } = require('@nut-tree/nut-js') as typeof import('@nut-tree/nut-js');
const display = screen.getPrimaryDisplay();
const w = new BrowserWindow({
x: 0,
y: 0,
width: display.bounds.width / 2,
height: display.bounds.height / 2,
frame: false,
titleBarStyle: 'hidden'
});
const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');
w.loadFile(overlayHTML);
await once(w, 'ready-to-show');
const winBounds = w.getBounds();
const titleBarHeight = 30;
const titleBarRegion = new Region(winBounds.x, winBounds.y, winBounds.width, titleBarHeight);
const screenRegion = new Region(display.bounds.x, display.bounds.y, display.bounds.width, display.bounds.height);
const startPos = w.getPosition();
await mouse.setPosition(await centerOf(titleBarRegion));
await mouse.pressButton(Button.LEFT);
await mouse.drag(straightTo(centerOf(screenRegion)));
// Wait for move to complete
await Promise.race([
once(w, 'move'),
setTimeout(100) // fallback for possible race condition
]);
const endPos = w.getPosition();
expect(startPos).to.not.deep.equal(endPos);
});
ifit(hasCapturableScreen())('should allow the window to be dragged when no WCO and --webkit-app-region: drag enabled', async () => {
// FIXME: nut-js has been removed from npm; we need to find a replacement
// @ts-ignore: nut-js is an optional dependency so it may not be installed
const { mouse, straightTo, centerOf, Region, Button } = require('@nut-tree/nut-js') as typeof import('@nut-tree/nut-js');
const display = screen.getPrimaryDisplay();
const w = new BrowserWindow({
x: 0,
y: 0,
width: display.bounds.width / 2,
height: display.bounds.height / 2,
frame: false
});
const basePageHTML = path.join(__dirname, 'fixtures', 'pages', 'base-page.html');
w.loadFile(basePageHTML);
await once(w, 'ready-to-show');
await w.webContents.executeJavaScript(`
const style = document.createElement('style');
style.innerHTML = \`
#titlebar {
background-color: red;
height: 30px;
width: 100%;
-webkit-user-select: none;
-webkit-app-region: drag;
position: fixed;
top: 0;
left: 0;
z-index: 1000000000000;
}
\`;
const titleBar = document.createElement('title-bar');
titleBar.id = 'titlebar';
titleBar.textContent = 'test-titlebar';
document.body.append(style);
document.body.append(titleBar);
`);
// allow time for titlebar to finish loading
await setTimeout(2000);
const winBounds = w.getBounds();
const titleBarHeight = 30;
const titleBarRegion = new Region(winBounds.x, winBounds.y, winBounds.width, titleBarHeight);
const screenRegion = new Region(display.bounds.x, display.bounds.y, display.bounds.width, display.bounds.height);
const startPos = w.getPosition();
await mouse.setPosition(await centerOf(titleBarRegion));
await mouse.pressButton(Button.LEFT);
await mouse.drag(straightTo(centerOf(screenRegion)));
// Wait for move to complete
await Promise.race([
once(w, 'move'),
setTimeout(1000) // fallback for possible race condition
]);
const endPos = w.getPosition();
expect(startPos).to.not.deep.equal(endPos);
});
});
});