electron/spec/chromium-spec.ts

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

3818 lines
148 KiB
TypeScript
Raw Normal View History

import { expect } from 'chai';
import { BrowserWindow, WebContents, webFrameMain, session, ipcMain, app, protocol, webContents, dialog, MessageBoxOptions } from 'electron/main';
import { clipboard } from 'electron/common';
import { closeAllWindows } from './lib/window-helpers';
import * as https from 'node:https';
import * as http from 'node:http';
import * as path from 'node:path';
import * as fs from 'node:fs';
import * as url from 'node:url';
import * as ChildProcess from 'node:child_process';
import { EventEmitter, once } from 'node:events';
import { ifit, ifdescribe, defer, itremote, listen } from './lib/spec-helpers';
import { PipeTransport } from './pipe-transport';
import * as ws from 'ws';
import { setTimeout } from 'node:timers/promises';
import { AddressInfo } from 'node:net';
import { MediaAccessPermissionRequest } from 'electron';
2020-03-20 20:28:31 +00:00
const features = process._linkedBinding('electron_common_features');
2020-03-20 20:28:31 +00:00
const fixturesPath = path.resolve(__dirname, 'fixtures');
const certPath = path.join(fixturesPath, 'certificates');
2019-05-29 23:33:19 +00:00
describe('reporting api', () => {
it('sends a report for an intervention', async () => {
const reporting = new EventEmitter();
2019-05-29 23:33:19 +00:00
// The Reporting API only works on https with valid certs. To dodge having
// to set up a trusted certificate, hack the validator.
session.defaultSession.setCertificateVerifyProc((req, cb) => {
cb(0);
});
2019-05-29 23:33:19 +00:00
const options = {
key: fs.readFileSync(path.join(certPath, 'server.key')),
cert: fs.readFileSync(path.join(certPath, 'server.pem')),
ca: [
fs.readFileSync(path.join(certPath, 'rootCA.pem')),
fs.readFileSync(path.join(certPath, 'intermediateCA.pem'))
],
requestCert: true,
rejectUnauthorized: false
};
const server = https.createServer(options, (req, res) => {
if (req.url?.endsWith('report')) {
2019-05-29 23:33:19 +00:00
let data = '';
2019-11-01 20:37:02 +00:00
req.on('data', (d) => { data += d.toString('utf-8'); });
2019-05-29 23:33:19 +00:00
req.on('end', () => {
reporting.emit('report', JSON.parse(data));
2019-05-29 23:33:19 +00:00
});
}
const { port } = server.address() as any;
res.setHeader('Reporting-Endpoints', `default="https://localhost:${port}/report"`);
2019-05-29 23:33:19 +00:00
res.setHeader('Content-Type', 'text/html');
res.end('<script>window.navigator.vibrate(1)</script>');
2019-05-29 23:33:19 +00:00
});
await listen(server);
const bw = new BrowserWindow({ show: false });
2019-05-29 23:33:19 +00:00
try {
const reportGenerated = once(reporting, 'report');
await bw.loadURL(`https://localhost:${(server.address() as AddressInfo).port}/a`);
const [reports] = await reportGenerated;
expect(reports).to.be.an('array').with.lengthOf(1);
const { type, url, body } = reports[0];
expect(type).to.equal('intervention');
expect(url).to.equal(url);
expect(body.id).to.equal('NavigatorVibrate');
expect(body.message).to.match(/Blocked call to navigator.vibrate because user hasn't tapped on the frame or any embedded frame yet/);
2019-05-29 23:33:19 +00:00
} finally {
bw.destroy();
server.close();
}
});
});
describe('window.postMessage', () => {
afterEach(async () => {
await closeAllWindows();
});
it('sets the source and origin correctly', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL(`file://${fixturesPath}/pages/window-open-postMessage-driver.html`);
const [, message] = await once(ipcMain, 'complete');
expect(message.data).to.equal('testing');
expect(message.origin).to.equal('file://');
expect(message.sourceEqualsOpener).to.equal(true);
expect(message.eventOrigin).to.equal('file://');
});
});
describe('focus handling', () => {
let webviewContents: WebContents;
let w: BrowserWindow;
beforeEach(async () => {
w = new BrowserWindow({
show: true,
webPreferences: {
nodeIntegration: true,
webviewTag: true,
contextIsolation: false
}
});
const webviewReady = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
await w.loadFile(path.join(fixturesPath, 'pages', 'tab-focus-loop-elements.html'));
const [, wvContents] = await webviewReady;
webviewContents = wvContents;
await once(webviewContents, 'did-finish-load');
w.focus();
});
afterEach(() => {
webviewContents = null as unknown as WebContents;
w.destroy();
w = null as unknown as BrowserWindow;
});
const expectFocusChange = async () => {
const [, focusedElementId] = await once(ipcMain, 'focus-changed');
return focusedElementId;
};
describe('a TAB press', () => {
const tabPressEvent: any = {
type: 'keyDown',
keyCode: 'Tab'
};
it('moves focus to the next focusable item', async () => {
let focusChange = expectFocusChange();
w.webContents.sendInputEvent(tabPressEvent);
let focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-element-1', `should start focused in element-1, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
w.webContents.sendInputEvent(tabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-element-2', `focus should've moved to element-2, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
w.webContents.sendInputEvent(tabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-wv-element-1', `focus should've moved to the webview's element-1, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
webviewContents.sendInputEvent(tabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-wv-element-2', `focus should've moved to the webview's element-2, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
webviewContents.sendInputEvent(tabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-element-3', `focus should've moved to element-3, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
w.webContents.sendInputEvent(tabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-element-1', `focus should've looped back to element-1, it's instead in ${focusedElementId}`);
});
});
describe('a SHIFT + TAB press', () => {
const shiftTabPressEvent: any = {
type: 'keyDown',
modifiers: ['Shift'],
keyCode: 'Tab'
};
it('moves focus to the previous focusable item', async () => {
let focusChange = expectFocusChange();
w.webContents.sendInputEvent(shiftTabPressEvent);
let focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-element-3', `should start focused in element-3, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
w.webContents.sendInputEvent(shiftTabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-wv-element-2', `focus should've moved to the webview's element-2, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
webviewContents.sendInputEvent(shiftTabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-wv-element-1', `focus should've moved to the webview's element-1, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
webviewContents.sendInputEvent(shiftTabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-element-2', `focus should've moved to element-2, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
w.webContents.sendInputEvent(shiftTabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-element-1', `focus should've moved to element-1, it's instead in ${focusedElementId}`);
2020-03-20 20:28:31 +00:00
focusChange = expectFocusChange();
w.webContents.sendInputEvent(shiftTabPressEvent);
focusedElementId = await focusChange;
expect(focusedElementId).to.equal('BUTTON-element-3', `focus should've looped back to element-3, it's instead in ${focusedElementId}`);
});
});
});
describe('web security', () => {
afterEach(closeAllWindows);
let server: http.Server;
let serverUrl: string;
before(async () => {
server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end('<body>');
});
serverUrl = (await listen(server)).url;
});
after(() => {
server.close();
});
it('engages CORB when web security is not disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true, nodeIntegration: true, contextIsolation: false } });
const p = once(ipcMain, 'success');
await w.loadURL(`data:text/html,<script>
const s = document.createElement('script')
s.src = "${serverUrl}"
chore: bump chromium to 123.0.6296.0 (main) (#41204) * chore: bump chromium in DEPS to 123.0.6273.0 * chore: update patches * chore: bump chromium in DEPS to 123.0.6274.0 * chore: update patches * chore: bump chromium in DEPS to 123.0.6276.0 * chore: update patches * WIP: 5239586: Change View::Layout() to take a PassKey. https://chromium-review.googlesource.com/c/chromium/src/+/5239586 * WIP: 5239586: Change View::Layout() to take a PassKey. https://chromium-review.googlesource.com/c/chromium/src/+/5239586 * chore: bump chromium in DEPS to 123.0.6278.0 * chore: bump chromium in DEPS to 123.0.6280.0 * chore: update patches * chore: use net::CanonicalCookie::SecureAttribute() renamed from IsSecure() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5245913 * refactor: handle multiple requested device ids Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5132210 * refactor: trigger View layouts async with View::InvalidateLayout() Upstream has introduced a PassKey to restrict who can call Layout() directly. I've opted for calling `InvalidateLayout()` which is the approach that upstream recommends. If for some reason this approach doesn't work for us, we could use `DeprecatedLayoutImmediately()` as a stopgap. Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5239586 Xref: https://chromium.googlesource.com/chromium/src/+/main/ui/views/view.h#809 Xref: https://chromium.googlesource.com/chromium/src/+/main/docs/ui/learn/bestpractices/layout.md?pli=1#don_t-invoke-layout_directly * chore: bump chromium in DEPS to 123.0.6282.0 * chore: bump chromium in DEPS to 123.0.6284.0 * chore: update patches * refactor: remove use of blink::MainThreadIsolate() pt 1/3 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5249640 * refactor: remove use of blink::MainThreadIsolate() pt 2/3 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5249640 * refactor: remove use of blink::MainThreadIsolate() pt 3/3 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5249640 * chore: update enum name to ui::AXMode::kPDFPrinting Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5270301 * chore: rebuild filenames.libcxx.gni * chore: sync with upstream rename of PortProvider.TaskForHandle() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5259103 * chore: bump chromium in DEPS to 123.0.6286.0 * chore: bump chromium in DEPS to 123.0.6288.0 * WebPreferences: Initialize in declaration. Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5277099 * chore: update webview_fullscreen.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5053508 Simple update to fix patch shear * chore: update feat_configure_launch_options_for_service_process.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5254861 Simple update to fix patch shear * chore: add IWC::Delegate::RecordResize() stub to fix FTBFS https://chromium-review.googlesource.com/c/chromium/src/+/5268963 * chore: add FormControlType::kButtonPopover to the FormControlType converter Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5230929 * chore: e patches all * chore: node script/gen-libc++-filenames.js * chore: bump chromium in DEPS to 123.0.6290.0 * chore: bump chromium in DEPS to 123.0.6291.0 * chore: bump chromium in DEPS to 123.0.6292.0 * chore: bump chromium in DEPS to 123.0.6294.0 * chore: update fix_aspect_ratio_with_max_size.patch Xref: fix_aspect_ratio_with_max_size.patch note: simple absl::optional -> std::optional conversion * chore: update feat_filter_out_non-shareable_windows_in_the_current_application_in.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5272337 * chore: update add_maximized_parameter_to_linuxui_getwindowframeprovider.patch No manual changes; just adjusting line patch offsets Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5258688 * chore: update feat_configure_launch_options_for_service_process.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5281322 * chore: update fix_select_The_first_menu_item_when_opened_via_keyboard.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5279376 note: simple absl::optional -> std::optional conversion * chore: update feat_allow_code_cache_in_custom_schemes.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5268792 * chore: script/export_all_patches.py * chore: bump chromium in DEPS to 123.0.6296.0 * chore: update patches * fixup! chore: update feat_allow_code_cache_in_custom_schemes.patch * fix: restore MessagePort close event * spec: fix CORB testing Refs https://chromium-review.googlesource.com/c/chromium/src/+/5231506 * fix: use sync layout when content view changes * fixup! chore: update feat_configure_launch_options_for_service_process.patch * Add remote-cocoa support for context menus. Refs https://chromium-review.googlesource.com/c/chromium/src/+/5259806 * Rename //net/base/mac directory to //net/base/apple (1/n) Refs https://chromium-review.googlesource.com/c/chromium/src/+/5211389 * fixup! Add remote-cocoa support for context menus. * [Clipboard] Don't add meta charset tag for async write() method on Mac. Refs https://chromium-review.googlesource.com/c/chromium/src/+/5187335 --------- 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: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com>
2024-02-14 17:33:32 +00:00
// The script will not load under ORB, refs https://chromium-review.googlesource.com/c/chromium/src/+/3785025.
// Before ORB an empty response is sent, which is now replaced by a network error.
s.onerror = () => { require('electron').ipcRenderer.send('success') }
document.documentElement.appendChild(s)
</script>`);
await p;
});
it('bypasses CORB when web security is disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false, nodeIntegration: true, contextIsolation: false } });
const p = once(ipcMain, 'success');
await w.loadURL(`data:text/html,
<script>
window.onerror = (e) => { require('electron').ipcRenderer.send('success', e) }
</script>
<script src="${serverUrl}"></script>`);
await p;
});
it('engages CORS when web security is not disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true, nodeIntegration: true, contextIsolation: false } });
const p = once(ipcMain, 'response');
await w.loadURL(`data:text/html,<script>
(async function() {
try {
await fetch('${serverUrl}');
require('electron').ipcRenderer.send('response', 'passed');
} catch {
require('electron').ipcRenderer.send('response', 'failed');
}
})();
</script>`);
const [, response] = await p;
expect(response).to.equal('failed');
});
it('bypasses CORS when web security is disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false, nodeIntegration: true, contextIsolation: false } });
const p = once(ipcMain, 'response');
await w.loadURL(`data:text/html,<script>
(async function() {
try {
await fetch('${serverUrl}');
require('electron').ipcRenderer.send('response', 'passed');
} catch {
require('electron').ipcRenderer.send('response', 'failed');
}
})();
</script>`);
const [, response] = await p;
expect(response).to.equal('passed');
});
describe('accessing file://', () => {
async function loadFile (w: BrowserWindow) {
const thisFile = url.format({
pathname: __filename.replaceAll('\\', '/'),
protocol: 'file',
slashes: true
});
await w.loadURL(`data:text/html,<script>
function loadFile() {
return new Promise((resolve) => {
fetch('${thisFile}').then(
() => resolve('loaded'),
() => resolve('failed')
)
});
}
</script>`);
return await w.webContents.executeJavaScript('loadFile()');
}
it('is forbidden when web security is enabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true } });
const result = await loadFile(w);
expect(result).to.equal('failed');
});
it('is allowed when web security is disabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false } });
const result = await loadFile(w);
expect(result).to.equal('loaded');
});
});
describe('wasm-eval csp', () => {
async function loadWasm (csp: string) {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
enableBlinkFeatures: 'WebAssemblyCSP'
}
});
await w.loadURL(`data:text/html,<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' ${csp}">
</head>
<script>
function loadWasm() {
const wasmBin = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0])
return new Promise((resolve) => {
WebAssembly.instantiate(wasmBin).then(() => {
resolve('loaded')
}).catch((error) => {
resolve(error.message)
})
});
}
</script>`);
return await w.webContents.executeJavaScript('loadWasm()');
}
it('wasm codegen is disallowed by default', async () => {
const r = await loadWasm('');
chore: bump chromium to 105.0.5187.0 (main) (#34921) * chore: bump chromium in DEPS to 105.0.5179.0 * chore: update patches * 3758224: Reland^2 "[flags] Enable freezing of flags" https://chromium-review.googlesource.com/c/v8/v8/+/3758224 * chore: bump chromium in DEPS to 105.0.5181.0 * chore: update patches * chore: bump chromium in DEPS to 105.0.5183.0 * chore: bump chromium in DEPS to 105.0.5185.0 * chore: bump chromium in DEPS to 105.0.5187.0 * chore: update patches * 3723298: Pass RemoteFrame mojo channels through its creation messages. https://chromium-review.googlesource.com/c/chromium/src/+/3723298 * 3737382: [Code Heath] Replace base::{ListValue,DictionaryValue} in skia et al https://chromium-review.googlesource.com/c/chromium/src/+/3737382 * Pass RemoteFrame mojo channels through its creation messages. https://chromium-review.googlesource.com/c/chromium/src/+/3723298 * Changed PrintRenderFrame.PrintWithParams mojo interface to use callback. https://chromium-review.googlesource.com/c/chromium/src/+/3761203 * 3738183: [CSP] Add support for `DisableWasmEval` https://chromium-review.googlesource.com/c/chromium/src/+/3738183 * 3740498: Move LinuxUI from //ui/views/linux_ui to //ui/linux https://chromium-review.googlesource.com/c/chromium/src/+/3740498 * 3558277: Moves subsystem and semantics to enum class https://chromium-review.googlesource.com/c/chromium/src/+/3558277 * chore: fix broken steps-electron-gn-check * 3749583: [arm64] Fix undefined symbol linker error https://chromium-review.googlesource.com/c/v8/v8/+/3749583 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: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-07-20 11:03:34 +00:00
expect(r).to.equal('WebAssembly.instantiate(): Refused to compile or instantiate WebAssembly module because \'unsafe-eval\' is not an allowed source of script in the following Content Security Policy directive: "script-src \'self\' \'unsafe-inline\'"');
});
it('wasm codegen is allowed with "wasm-unsafe-eval" csp', async () => {
const r = await loadWasm("'wasm-unsafe-eval'");
expect(r).to.equal('loaded');
});
});
describe('csp', () => {
for (const sandbox of [true, false]) {
describe(`when sandbox: ${sandbox}`, () => {
for (const contextIsolation of [true, false]) {
describe(`when contextIsolation: ${contextIsolation}`, () => {
it('prevents eval from running in an inline script', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: { sandbox, contextIsolation }
});
w.loadURL(`data:text/html,<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline'">
</head>
<script>
try {
// We use console.log here because it is easier than making a
// preload script, and the behavior under test changes when
// contextIsolation: false
console.log(eval('true'))
} catch (e) {
console.log(e.message)
}
</script>`);
const [,, message] = await once(w.webContents, 'console-message');
expect(message).to.match(/Refused to evaluate a string/);
});
it('does not prevent eval from running in an inline script when there is no csp', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: { sandbox, contextIsolation }
});
w.loadURL(`data:text/html,
<script>
try {
// We use console.log here because it is easier than making a
// preload script, and the behavior under test changes when
// contextIsolation: false
console.log(eval('true'))
} catch (e) {
console.log(e.message)
}
</script>`);
const [,, message] = await once(w.webContents, 'console-message');
expect(message).to.equal('true');
});
it('prevents eval from running in executeJavaScript', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: { sandbox, contextIsolation }
});
w.loadURL('data:text/html,<head><meta http-equiv="Content-Security-Policy" content="default-src \'self\'; script-src \'self\' \'unsafe-inline\'"></meta></head>');
await expect(w.webContents.executeJavaScript('eval("true")')).to.be.rejected();
});
it('does not prevent eval from running in executeJavaScript when there is no csp', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: { sandbox, contextIsolation }
});
w.loadURL('data:text/html,');
expect(await w.webContents.executeJavaScript('eval("true")')).to.be.true();
});
});
}
});
}
});
it('does not crash when multiple WebContent are created with web security disabled', () => {
const options = { show: false, webPreferences: { webSecurity: false } };
const w1 = new BrowserWindow(options);
w1.loadURL(serverUrl);
const w2 = new BrowserWindow(options);
w2.loadURL(serverUrl);
});
});
describe('command line switches', () => {
let appProcess: ChildProcess.ChildProcessWithoutNullStreams | undefined;
afterEach(() => {
if (appProcess && !appProcess.killed) {
appProcess.kill();
appProcess = undefined;
}
});
describe('--lang switch', () => {
const currentLocale = app.getLocale();
const currentSystemLocale = app.getSystemLocale();
const currentPreferredLanguages = JSON.stringify(app.getPreferredSystemLanguages());
const testLocale = async (locale: string, result: string, printEnv: boolean = false) => {
const appPath = path.join(fixturesPath, 'api', 'locale-check');
const args = [appPath, `--set-lang=${locale}`];
if (printEnv) {
args.push('--print-env');
}
appProcess = ChildProcess.spawn(process.execPath, args);
let output = '';
appProcess.stdout.on('data', (data) => { output += data; });
let stderr = '';
appProcess.stderr.on('data', (data) => { stderr += data; });
const [code, signal] = await once(appProcess, 'exit');
if (code !== 0) {
throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
}
output = output.replaceAll(/(\r\n|\n|\r)/gm, '');
expect(output).to.equal(result);
};
it('should set the locale', async () => testLocale('fr', `fr|${currentSystemLocale}|${currentPreferredLanguages}`));
it('should set the locale with country code', async () => testLocale('zh-CN', `zh-CN|${currentSystemLocale}|${currentPreferredLanguages}`));
it('should not set an invalid locale', async () => testLocale('asdfkl', `${currentLocale}|${currentSystemLocale}|${currentPreferredLanguages}`));
const lcAll = String(process.env.LC_ALL);
ifit(process.platform === 'linux')('current process has a valid LC_ALL env', async () => {
// The LC_ALL env should not be set to DOM locale string.
expect(lcAll).to.not.equal(app.getLocale());
});
ifit(process.platform === 'linux')('should not change LC_ALL', async () => testLocale('fr', lcAll, true));
ifit(process.platform === 'linux')('should not change LC_ALL when setting invalid locale', async () => testLocale('asdfkl', lcAll, true));
ifit(process.platform === 'linux')('should not change LC_ALL when --lang is not set', async () => testLocale('', lcAll, true));
});
describe('--remote-debugging-pipe switch', () => {
it('should expose CDP via pipe', async () => {
const electronPath = process.execPath;
appProcess = ChildProcess.spawn(electronPath, ['--remote-debugging-pipe'], {
stdio: ['inherit', 'inherit', 'inherit', 'pipe', 'pipe']
}) as ChildProcess.ChildProcessWithoutNullStreams;
const stdio = appProcess.stdio as unknown as [NodeJS.ReadableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.ReadableStream];
const pipe = new PipeTransport(stdio[3], stdio[4]);
const versionPromise = new Promise(resolve => { pipe.onmessage = resolve; });
pipe.send({ id: 1, method: 'Browser.getVersion', params: {} });
const message = (await versionPromise) as any;
expect(message.id).to.equal(1);
expect(message.result.product).to.contain('Chrome');
expect(message.result.userAgent).to.contain('Electron');
});
it('should override --remote-debugging-port switch', async () => {
const electronPath = process.execPath;
appProcess = ChildProcess.spawn(electronPath, ['--remote-debugging-pipe', '--remote-debugging-port=0'], {
stdio: ['inherit', 'inherit', 'pipe', 'pipe', 'pipe']
}) as ChildProcess.ChildProcessWithoutNullStreams;
let stderr = '';
appProcess.stderr.on('data', (data: string) => { stderr += data; });
const stdio = appProcess.stdio as unknown as [NodeJS.ReadableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.ReadableStream];
const pipe = new PipeTransport(stdio[3], stdio[4]);
const versionPromise = new Promise(resolve => { pipe.onmessage = resolve; });
pipe.send({ id: 1, method: 'Browser.getVersion', params: {} });
const message = (await versionPromise) as any;
expect(message.id).to.equal(1);
expect(stderr).to.not.include('DevTools listening on');
});
it('should shut down Electron upon Browser.close CDP command', async () => {
const electronPath = process.execPath;
appProcess = ChildProcess.spawn(electronPath, ['--remote-debugging-pipe'], {
stdio: ['inherit', 'inherit', 'inherit', 'pipe', 'pipe']
}) as ChildProcess.ChildProcessWithoutNullStreams;
const stdio = appProcess.stdio as unknown as [NodeJS.ReadableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.ReadableStream];
const pipe = new PipeTransport(stdio[3], stdio[4]);
pipe.send({ id: 1, method: 'Browser.close', params: {} });
await once(appProcess, 'exit');
});
});
describe('--remote-debugging-port switch', () => {
it('should display the discovery page', (done) => {
const electronPath = process.execPath;
let output = '';
appProcess = ChildProcess.spawn(electronPath, ['--remote-debugging-port=']);
appProcess.stdout.on('data', (data) => {
console.log(data);
});
appProcess.stderr.on('data', (data) => {
console.log(data);
output += data;
const m = /DevTools listening on ws:\/\/127.0.0.1:(\d+)\//.exec(output);
if (m) {
appProcess!.stderr.removeAllListeners('data');
const port = m[1];
http.get(`http://127.0.0.1:${port}`, (res) => {
try {
expect(res.statusCode).to.eql(200);
expect(parseInt(res.headers['content-length']!)).to.be.greaterThan(0);
done();
} catch (e) {
done(e);
} finally {
res.destroy();
}
});
}
});
});
});
});
describe('chromium features', () => {
afterEach(closeAllWindows);
describe('accessing key names also used as Node.js module names', () => {
it('does not crash', (done) => {
const w = new BrowserWindow({ show: false });
w.webContents.once('did-finish-load', () => { done(); });
w.webContents.once('render-process-gone', () => done(new Error('WebContents crashed.')));
w.loadFile(path.join(fixturesPath, 'pages', 'external-string.html'));
});
});
describe('first party sets', () => {
const fps = [
'https://fps-member1.glitch.me',
'https://fps-member2.glitch.me',
'https://fps-member3.glitch.me'
];
it('loads first party sets', async () => {
const appPath = path.join(fixturesPath, 'api', 'first-party-sets', 'base');
const fpsProcess = ChildProcess.spawn(process.execPath, [appPath]);
let output = '';
fpsProcess.stdout.on('data', data => { output += data; });
await once(fpsProcess, 'exit');
expect(output).to.include(fps.join(','));
});
it('loads sets from the command line', async () => {
const appPath = path.join(fixturesPath, 'api', 'first-party-sets', 'command-line');
const args = [appPath, `--use-first-party-set=${fps}`];
const fpsProcess = ChildProcess.spawn(process.execPath, args);
let output = '';
fpsProcess.stdout.on('data', data => { output += data; });
await once(fpsProcess, 'exit');
expect(output).to.include(fps.join(','));
});
});
describe('loading jquery', () => {
it('does not crash', (done) => {
const w = new BrowserWindow({ show: false });
w.webContents.once('did-finish-load', () => { done(); });
w.webContents.once('render-process-gone', () => done(new Error('WebContents crashed.')));
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'jquery.html'));
});
});
describe('navigator.keyboard', () => {
afterEach(closeAllWindows);
it('getLayoutMap() should return a KeyboardLayoutMap object', async () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const size = await w.webContents.executeJavaScript(`
navigator.keyboard.getLayoutMap().then(map => map.size)
`);
expect(size).to.be.a('number');
});
it('should lock the keyboard', async () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'modal.html'));
// Test that without lock, with ESC:
// - the window leaves fullscreen
// - the dialog is not closed
const enterFS1 = once(w, 'enter-full-screen');
await w.webContents.executeJavaScript('document.body.requestFullscreen()', true);
await enterFS1;
await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').showModal()', true);
const open1 = await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').open');
expect(open1).to.be.true();
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
await setTimeout(1000);
const openAfter1 = await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').open');
expect(openAfter1).to.be.true();
expect(w.isFullScreen()).to.be.false();
// Test that with lock, with ESC:
// - the window does not leave fullscreen
// - the dialog is closed
const enterFS2 = once(w, 'enter-full-screen');
await w.webContents.executeJavaScript(`
navigator.keyboard.lock(['Escape']);
document.body.requestFullscreen();
`, true);
await enterFS2;
await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').showModal()', true);
const open2 = await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').open');
expect(open2).to.be.true();
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
await setTimeout(1000);
const openAfter2 = await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').open');
expect(openAfter2).to.be.false();
expect(w.isFullScreen()).to.be.true();
});
});
describe('navigator.languages', () => {
it('should return the system locale only', async () => {
const appLocale = app.getLocale();
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
const languages = await w.webContents.executeJavaScript('navigator.languages');
expect(languages.length).to.be.greaterThan(0);
expect(languages).to.contain(appLocale);
});
});
describe('navigator.serviceWorker', () => {
it('should register for file scheme', (done) => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
partition: 'sw-file-scheme-spec',
contextIsolation: false
}
});
w.webContents.on('ipc-message', (event, channel, message) => {
if (channel === 'reload') {
w.webContents.reload();
} else if (channel === 'error') {
done(message);
} else if (channel === 'response') {
expect(message).to.equal('Hello from serviceWorker!');
session.fromPartition('sw-file-scheme-spec').clearStorageData({
storages: ['serviceworkers']
}).then(() => done());
}
});
w.webContents.on('render-process-gone', () => done(new Error('WebContents crashed.')));
w.loadFile(path.join(fixturesPath, 'pages', 'service-worker', 'index.html'));
});
it('should register for intercepted file scheme', (done) => {
const customSession = session.fromPartition('intercept-file');
customSession.protocol.interceptBufferProtocol('file', (request, callback) => {
let file = url.parse(request.url).pathname!;
if (file[0] === '/' && process.platform === 'win32') file = file.slice(1);
const content = fs.readFileSync(path.normalize(file));
const ext = path.extname(file);
let type = 'text/html';
if (ext === '.js') type = 'application/javascript';
callback({ data: content, mimeType: type } as any);
});
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
session: customSession,
contextIsolation: false
}
});
w.webContents.on('ipc-message', (event, channel, message) => {
if (channel === 'reload') {
w.webContents.reload();
} else if (channel === 'error') {
done(`unexpected error : ${message}`);
} else if (channel === 'response') {
expect(message).to.equal('Hello from serviceWorker!');
customSession.clearStorageData({
storages: ['serviceworkers']
}).then(() => {
customSession.protocol.uninterceptProtocol('file');
done();
});
}
});
w.webContents.on('render-process-gone', () => done(new Error('WebContents crashed.')));
w.loadFile(path.join(fixturesPath, 'pages', 'service-worker', 'index.html'));
});
it('should register for custom scheme', (done) => {
const customSession = session.fromPartition('custom-scheme');
customSession.protocol.registerFileProtocol(serviceWorkerScheme, (request, callback) => {
let file = url.parse(request.url).pathname!;
if (file[0] === '/' && process.platform === 'win32') file = file.slice(1);
callback({ path: path.normalize(file) } as any);
});
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
session: customSession,
contextIsolation: false
}
});
w.webContents.on('ipc-message', (event, channel, message) => {
if (channel === 'reload') {
w.webContents.reload();
} else if (channel === 'error') {
done(`unexpected error : ${message}`);
} else if (channel === 'response') {
expect(message).to.equal('Hello from serviceWorker!');
customSession.clearStorageData({
storages: ['serviceworkers']
}).then(() => {
customSession.protocol.uninterceptProtocol(serviceWorkerScheme);
done();
});
}
});
w.webContents.on('render-process-gone', () => done(new Error('WebContents crashed.')));
w.loadFile(path.join(fixturesPath, 'pages', 'service-worker', 'custom-scheme-index.html'));
});
it('should not allow nodeIntegrationInWorker', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
partition: 'sw-file-scheme-worker-spec',
contextIsolation: false
}
});
await w.loadURL(`file://${fixturesPath}/pages/service-worker/empty.html`);
const data = await w.webContents.executeJavaScript(`
navigator.serviceWorker.register('worker-no-node.js', {
scope: './'
}).then(() => navigator.serviceWorker.ready)
new Promise((resolve) => {
navigator.serviceWorker.onmessage = event => resolve(event.data);
});
`);
expect(data).to.equal('undefined undefined undefined undefined');
});
});
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 14:47:48 +00:00
describe('navigator.geolocation', () => {
ifit(features.isFakeLocationProviderEnabled())('returns error when permission is denied', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
partition: 'geolocation-spec',
contextIsolation: false
}
});
const message = once(w.webContents, 'ipc-message');
w.webContents.session.setPermissionRequestHandler((wc, permission, callback) => {
if (permission === 'geolocation') {
callback(false);
} else {
callback(true);
}
});
w.loadFile(path.join(fixturesPath, 'pages', 'geolocation', 'index.html'));
const [, channel] = await message;
expect(channel).to.equal('success', 'unexpected response from geolocation api');
});
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 14:47:48 +00:00
ifit(!features.isFakeLocationProviderEnabled())('returns position when permission is granted', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
partition: 'geolocation-spec'
}
});
w.webContents.session.setPermissionRequestHandler((_wc, _permission, callback) => {
callback(true);
});
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const position = await w.webContents.executeJavaScript(`new Promise((resolve, reject) =>
navigator.geolocation.getCurrentPosition(
x => resolve({coords: x.coords, timestamp: x.timestamp}),
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 14:47:48 +00:00
err => reject(new Error(err.message))))`);
expect(position).to.have.property('coords');
expect(position).to.have.property('timestamp');
});
});
describe('File System API,', () => {
afterEach(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionRequestHandler(null);
});
it('allows access by default to reading an OPFS file', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
partition: 'file-system-spec',
contextIsolation: false
}
});
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const result = await w.webContents.executeJavaScript(`
new Promise(async (resolve, reject) => {
const root = await navigator.storage.getDirectory();
const fileHandle = await root.getFileHandle('test', { create: true });
const { name, size } = await fileHandle.getFile();
resolve({ name, size });
}
)`, true);
expect(result).to.deep.equal({ name: 'test', size: 0 });
});
it('fileHandle.queryPermission by default has permission to read and write to OPFS files', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
partition: 'file-system-spec',
contextIsolation: false
}
});
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const status = await w.webContents.executeJavaScript(`
new Promise(async (resolve, reject) => {
const root = await navigator.storage.getDirectory();
const fileHandle = await root.getFileHandle('test', { create: true });
const status = await fileHandle.queryPermission({ mode: 'readwrite' });
resolve(status);
}
)`, true);
expect(status).to.equal('granted');
});
it('fileHandle.requestPermission automatically grants permission to read and write to OPFS files', async () => {
const w = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
partition: 'file-system-spec',
contextIsolation: false
}
});
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const status = await w.webContents.executeJavaScript(`
new Promise(async (resolve, reject) => {
const root = await navigator.storage.getDirectory();
const fileHandle = await root.getFileHandle('test', { create: true });
const status = await fileHandle.requestPermission({ mode: 'readwrite' });
resolve(status);
}
)`, true);
expect(status).to.equal('granted');
});
it('requests permission when trying to create a writable file handle', (done) => {
const writablePath = path.join(fixturesPath, 'file-system', 'test-writable.html');
const testFile = path.join(fixturesPath, 'file-system', 'test.txt');
const w = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
sandbox: false
}
});
w.webContents.session.setPermissionRequestHandler((wc, permission, callback, details) => {
expect(permission).to.equal('fileSystem');
const { href } = url.pathToFileURL(writablePath);
expect(details).to.deep.equal({
fileAccessType: 'writable',
isDirectory: false,
isMainFrame: true,
filePath: testFile,
requestingUrl: href
});
callback(true);
});
ipcMain.once('did-create-file-handle', async () => {
const result = await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
try {
const writable = fileHandle.createWritable();
resolve(true);
} catch {
resolve(false);
}
})
`, true);
expect(result).to.be.true();
done();
});
w.loadFile(writablePath);
w.webContents.once('did-finish-load', () => {
// @ts-expect-error Undocumented testing method.
clipboard._writeFilesForTesting([testFile]);
w.webContents.paste();
});
});
});
describe('web workers', () => {
let appProcess: ChildProcess.ChildProcessWithoutNullStreams | undefined;
afterEach(() => {
if (appProcess && !appProcess.killed) {
appProcess.kill();
appProcess = undefined;
}
});
it('Worker with nodeIntegrationInWorker has access to self.module.paths', async () => {
const appPath = path.join(__dirname, 'fixtures', 'apps', 'self-module-paths');
appProcess = ChildProcess.spawn(process.execPath, [appPath]);
const [code] = await once(appProcess, 'exit');
expect(code).to.equal(0);
});
it('Worker can work', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const data = await w.webContents.executeJavaScript(`
const worker = new Worker('../workers/worker.js');
const message = 'ping';
const eventPromise = new Promise((resolve) => { worker.onmessage = resolve; });
worker.postMessage(message);
eventPromise.then(t => t.data)
`);
expect(data).to.equal('ping');
});
it('Worker has no node integration by default', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const data = await w.webContents.executeJavaScript(`
const worker = new Worker('../workers/worker_node.js');
new Promise((resolve) => { worker.onmessage = e => resolve(e.data); })
`);
expect(data).to.equal('undefined undefined undefined undefined');
});
it('Worker has node integration with nodeIntegrationInWorker', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, nodeIntegrationInWorker: true, contextIsolation: false } });
w.loadURL(`file://${fixturesPath}/pages/worker.html`);
const [, data] = await once(ipcMain, 'worker-result');
expect(data).to.equal('object function object function');
});
describe('SharedWorker', () => {
it('can work', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const data = await w.webContents.executeJavaScript(`
const worker = new SharedWorker('../workers/shared_worker.js');
const message = 'ping';
const eventPromise = new Promise((resolve) => { worker.port.onmessage = e => resolve(e.data); });
worker.port.postMessage(message);
eventPromise
`);
expect(data).to.equal('ping');
});
it('has no node integration by default', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const data = await w.webContents.executeJavaScript(`
const worker = new SharedWorker('../workers/shared_worker_node.js');
new Promise((resolve) => { worker.port.onmessage = e => resolve(e.data); })
`);
expect(data).to.equal('undefined undefined undefined undefined');
});
it('does not have node integration with nodeIntegrationInWorker', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
contextIsolation: false
}
});
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const data = await w.webContents.executeJavaScript(`
const worker = new SharedWorker('../workers/shared_worker_node.js');
new Promise((resolve) => { worker.port.onmessage = e => resolve(e.data); })
`);
expect(data).to.equal('undefined undefined undefined undefined');
});
});
});
describe('form submit', () => {
let server: http.Server;
let serverUrl: string;
before(async () => {
server = http.createServer((req, res) => {
let body = '';
req.on('data', (chunk) => {
body += chunk;
});
res.setHeader('Content-Type', 'application/json');
req.on('end', () => {
res.end(`body:${body}`);
});
});
serverUrl = (await listen(server)).url;
});
after(async () => {
server.close();
await closeAllWindows();
});
for (const isSandboxEnabled of [true, false]) {
describe(`sandbox=${isSandboxEnabled}`, () => {
it('posts data in the same window', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: isSandboxEnabled
}
});
await w.loadFile(path.join(fixturesPath, 'pages', 'form-with-data.html'));
const loadPromise = once(w.webContents, 'did-finish-load');
w.webContents.executeJavaScript(`
const form = document.querySelector('form')
form.action = '${serverUrl}';
form.submit();
`);
await loadPromise;
const res = await w.webContents.executeJavaScript('document.body.innerText');
expect(res).to.equal('body:greeting=hello');
});
it('posts data to a new window with target=_blank', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: isSandboxEnabled
}
});
await w.loadFile(path.join(fixturesPath, 'pages', 'form-with-data.html'));
const windowCreatedPromise = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
w.webContents.executeJavaScript(`
const form = document.querySelector('form')
form.action = '${serverUrl}';
form.target = '_blank';
form.submit();
`);
const [, newWin] = await windowCreatedPromise;
const res = await newWin.webContents.executeJavaScript('document.body.innerText');
expect(res).to.equal('body:greeting=hello');
});
});
}
});
describe('window.open', () => {
for (const show of [true, false]) {
it(`shows the child regardless of parent visibility when parent {show=${show}}`, async () => {
const w = new BrowserWindow({ show });
// toggle visibility
if (show) {
w.hide();
} else {
w.show();
}
defer(() => { w.close(); });
const promise = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
w.loadFile(path.join(fixturesPath, 'pages', 'window-open.html'));
const [, newWindow] = await promise;
expect(newWindow.isVisible()).to.equal(true);
});
}
// FIXME(zcbenz): This test is making the spec runner hang on exit on Windows.
ifit(process.platform !== 'win32')('disables node integration when it is disabled on the parent window', async () => {
const windowUrl = url.pathToFileURL(path.join(fixturesPath, 'pages', 'window-opener-no-node-integration.html'));
windowUrl.searchParams.set('p', `${fixturesPath}/pages/window-opener-node.html`);
const w = new BrowserWindow({ show: false });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const { eventData } = await w.webContents.executeJavaScript(`(async () => {
const message = new Promise(resolve => window.addEventListener('message', resolve, {once: true}));
const b = window.open(${JSON.stringify(windowUrl)}, '', 'show=false')
const e = await message
b.close();
return {
eventData: e.data
}
})()`);
expect(eventData.isProcessGlobalUndefined).to.be.true();
});
it('disables node integration when it is disabled on the parent window for chrome devtools URLs', async () => {
// NB. webSecurity is disabled because native window.open() is not
// allowed to load devtools:// URLs.
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webSecurity: false } });
w.loadURL('about:blank');
w.webContents.executeJavaScript(`
{ b = window.open('devtools://devtools/bundled/inspector.html', '', 'nodeIntegration=no,show=no'); null }
`);
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
const typeofProcessGlobal = await contents.executeJavaScript('typeof process');
expect(typeofProcessGlobal).to.equal('undefined');
});
it('can disable node integration when it is enabled on the parent window', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
w.loadURL('about:blank');
w.webContents.executeJavaScript(`
{ b = window.open('about:blank', '', 'nodeIntegration=no,show=no'); null }
`);
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
const typeofProcessGlobal = await contents.executeJavaScript('typeof process');
expect(typeofProcessGlobal).to.equal('undefined');
});
chore: bump chromium to 100.0.4894.0 (main) (#32852) * chore: bump chromium in DEPS to 100.0.4880.0 * resolve conflicts * chore: update patches * fix patch * PIP20: add a new DocumentOverlayWindowViews subtype https://chromium-review.googlesource.com/c/chromium/src/+/3252789 * Clean up PictureInPictureWindowManager::EnterPictureInPicture() https://chromium-review.googlesource.com/c/chromium/src/+/3424145 * Remove StoragePartitionId. https://chromium-review.googlesource.com/c/chromium/src/+/2811120 * Remove FLoC code https://chromium-review.googlesource.com/c/chromium/src/+/3424359 * media: Make AddSupportedKeySystems() Async https://chromium-review.googlesource.com/c/chromium/src/+/3430502 * [Extensions] Move some l10n file util methods to //extensions/browser https://chromium-review.googlesource.com/c/chromium/src/+/3408192 * chore: IWYU * Reland "webhid: Grant permissions for policy-allowed devices" https://chromium-review.googlesource.com/c/chromium/src/+/3444147 * Migrate base::Value::GetList() to base::Value::GetListDeprecated(): 2/N. https://chromium-review.googlesource.com/c/chromium/src/+/3435727 https://chromium-review.googlesource.com/c/chromium/src/+/3440910 https://chromium-review.googlesource.com/c/chromium/src/+/3440088 * [text blink period] Cache blink period instead of fetching from defaults https://chromium-review.googlesource.com/c/chromium/src/+/3419059 * chore: update picture-in-picture.patch https://chromium-review.googlesource.com/c/chromium/src/+/3252789 * ci: update to Xcode 13.2.1 https://chromium-review.googlesource.com/c/chromium/src/+/3437552 * chore: bump chromium in DEPS to 100.0.4882.1 * chore: update patches * chore: bump chromium in DEPS to 100.0.4884.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4886.0 * chore: update patches * Refactor DownloadManager to use StoragePartitionConfig https://chromium-review.googlesource.com/c/chromium/src/+/3222011 * Remove ToWebInputElement() in favor of new WebNode::DynamicTo<> helpers. https://chromium-review.googlesource.com/c/chromium/src/+/3433852 * refactor: autofill to use the color pipeline https://bugs.chromium.org/p/chromium/issues/detail?id=1249558 https://bugs.chromium.org/p/chromium/issues/detail?id=1003612 * [ProcessSingleton] Add many more trace events to cover all scenarios https://chromium-review.googlesource.com/c/chromium/src/+/3429325 * fixup! PIP20: add a new DocumentOverlayWindowViews subtype * chore: bump chromium in DEPS to 100.0.4888.0 * chore: update patches * chore: update picture-in-picture.patch * fixup! refactor: autofill to use the color pipeline * ci: fixup fix sync (cherry picked from commit c1e3e395465739bce5ca8e1c5ec1f5bd72b99ebd) * chore: bump chromium in DEPS to 100.0.4889.0 * chore: update patches * chore: fix feat_add_data_transfer_to_requestsingleinstancelock.patch * fixup! PIP20: add a new DocumentOverlayWindowViews subtype * Remove remaining NativeTheme::GetSystemColor() machinery. https://chromium-review.googlesource.com/c/chromium/src/+/3421719 * ci: fetch proper esbuild for macos * ci: fixup fetch proper esbuild for macos * fix: failing Node.js test on outdated CurrentValueSerializerFormatVersion * chore: bump chromium in DEPS to 100.0.4892.0 * 3460365: Set V8 fatal error callbacks during Isolate initialization https://chromium-review.googlesource.com/c/chromium/src/+/3460365 * 3454343: PIP20: use permanent top controls https://chromium-review.googlesource.com/c/chromium/src/+/3454343 * 3465574: Move most of GTK color mixers to ui/color/. https://chromium-review.googlesource.com/c/chromium/src/+/3465574 * chore: fixup patch indices * 3445327: [locales] Remove locales reference https://chromium-review.googlesource.com/c/chromium/src/+/3445327 * 3456548: [DBB][#7] Blue border falls back to all tab if cropped-to zero pixels https://chromium-review.googlesource.com/c/chromium/src/+/3456548 * 3441196: Convert GuestView's remaining legacy IPC messages to Mojo https://chromium-review.googlesource.com/c/chromium/src/+/3441196 * 3455491: Don't include run_loop.h in thread_task_runner_handle.h https://chromium-review.googlesource.com/c/chromium/src/+/3455491 * fixup! 3454343: PIP20: use permanent top controls * 3442501: Add missing includes of //base/observer_list.h https://chromium-review.googlesource.com/c/chromium/src/+/3442501 * 3437552: mac: Deploy a new hermetic build of Xcode 13.2.1 13C100 https://chromium-review.googlesource.com/c/chromium/src/+/3437552 * chore: bump chromium in DEPS to 100.0.4894.0 * fixup! 3460365: Set V8 fatal error callbacks during Isolate initialization * chore: update patches * 3425231: Use DnsOverHttpsConfig where appropriate https://chromium-review.googlesource.com/c/chromium/src/+/3425231 * test: disable test-heapsnapshot-near-heap-limit-worker.js As a result of CLs linked in https://bugs.chromium.org/p/v8/issues/detail?id=12503, heap snapshotting near the heap limit DCHECKS in Node.js specs. This will likely require a larger refactor in Node.js so i've disabled the test for now and opened an upstream issue on node-v8 issue at https://github.com/nodejs/node-v8/issues/218. * Port all usage of NativeTheme color IDs to color pipeline https://bugs.chromium.org/p/chromium/issues/detail?id=1249558 * chore: update patches after rebase * ci: use gen2 machine for more disk space * ci: don't try to make root volume writeable * ci: use older xcode/macos for tests * fix: html fullscreen transitions stacking (cherry picked from commit 5e10965cdd7b2a024def5fc568912cefd0f05b44) * ci: speed up woa testing (cherry picked from commit 75c33c48b032137794f5734348a9ee3daa60d9de) (cherry picked from commit e81996234029669663bf0daaababd34684dcbb17) * ci: disable flaky tests on WOA * ci: run remote tests separately to isolate issue there * tests: disable node test parallel/test-worker-debug for now * revert: fix: html fullscreen transitions stacking * tests: disable flaky test on macOS arm64 * fixup circleci config so build tools can find xcode version * make sure the workspace is clean before job runs (cherry picked from commit 75f713c9748ac1a356846c39f268886130554fd6) * tests: disable flaky test on Linux * ci: debug why windows i32 is crashing * Revert "ci: debug why windows i32 is crashing" This reverts commit 4c4bba87ea76f16ef3b304dadff59ad4d366f60f. Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-02-25 18:17:35 +00:00
// TODO(jkleinsc) fix this flaky test on WOA
ifit(process.platform !== 'win32' || process.arch !== 'arm64')('disables JavaScript when it is disabled on the parent window', async () => {
const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true } });
w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const windowUrl = require('node:url').format({
pathname: `${fixturesPath}/pages/window-no-javascript.html`,
protocol: 'file',
slashes: true
});
w.webContents.executeJavaScript(`
{ b = window.open(${JSON.stringify(windowUrl)}, '', 'javascript=no,show=no'); null }
`);
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
await once(contents, 'did-finish-load');
// Click link on page
contents.sendInputEvent({ type: 'mouseDown', clickCount: 1, x: 1, y: 1 });
contents.sendInputEvent({ type: 'mouseUp', clickCount: 1, x: 1, y: 1 });
const [, window] = await once(app, 'browser-window-created') as [any, BrowserWindow];
const preferences = window.webContents.getLastWebPreferences();
expect(preferences!.javascript).to.be.false();
});
it('defines a window.location getter', async () => {
let targetURL: string;
if (process.platform === 'win32') {
targetURL = `file:///${fixturesPath.replaceAll('\\', '/')}/pages/base-page.html`;
} else {
targetURL = `file://${fixturesPath}/pages/base-page.html`;
}
const w = new BrowserWindow({ show: false });
w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
w.webContents.executeJavaScript(`{ b = window.open(${JSON.stringify(targetURL)}); null }`);
const [, window] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(window.webContents, 'did-finish-load');
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal(targetURL);
});
it('defines a window.location setter', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
w.webContents.executeJavaScript('{ b = window.open("about:blank"); null }');
const [, { webContents }] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(webContents, 'did-finish-load');
// When it loads, redirect
w.webContents.executeJavaScript(`{ b.location = ${JSON.stringify(`file://${fixturesPath}/pages/base-page.html`)}; null }`);
await once(webContents, 'did-finish-load');
});
it('defines a window.location.href setter', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
w.webContents.executeJavaScript('{ b = window.open("about:blank"); null }');
const [, { webContents }] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(webContents, 'did-finish-load');
// When it loads, redirect
w.webContents.executeJavaScript(`{ b.location.href = ${JSON.stringify(`file://${fixturesPath}/pages/base-page.html`)}; null }`);
await once(webContents, 'did-finish-load');
});
it('open a blank page when no URL is specified', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('{ b = window.open(); null }');
const [, { webContents }] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(webContents, 'did-finish-load');
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal('about:blank');
});
it('open a blank page when an empty URL is specified', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('{ b = window.open(\'\'); null }');
const [, { webContents }] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(webContents, 'did-finish-load');
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal('about:blank');
});
it('does not throw an exception when the frameName is a built-in object property', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('{ b = window.open(\'\', \'__proto__\'); null }');
const frameName = await new Promise((resolve) => {
w.webContents.setWindowOpenHandler(details => {
setImmediate(() => resolve(details.frameName));
return { action: 'allow' };
});
});
expect(frameName).to.equal('__proto__');
});
it('works when used in conjunction with the vm module', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
await w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const { contextObject } = await w.webContents.executeJavaScript(`(async () => {
const vm = require('node:vm');
const contextObject = { count: 1, type: 'gecko' };
window.open('');
vm.runInNewContext('count += 1; type = "chameleon";', contextObject);
return { contextObject };
})()`);
expect(contextObject).to.deep.equal({ count: 2, type: 'chameleon' });
});
// FIXME(nornagon): I'm not sure this ... ever was correct?
xit('inherit options of parent window', async () => {
const w = new BrowserWindow({ show: false, width: 123, height: 456 });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const url = `file://${fixturesPath}/pages/window-open-size.html`;
const { width, height, eventData } = await w.webContents.executeJavaScript(`(async () => {
const message = new Promise(resolve => window.addEventListener('message', resolve, {once: true}));
const b = window.open(${JSON.stringify(url)}, '', 'show=false')
const e = await message
b.close();
const width = outerWidth;
const height = outerHeight;
return {
width,
height,
eventData: e.data
}
})()`);
expect(eventData).to.equal(`size: ${width} ${height}`);
expect(eventData).to.equal('size: 123 456');
});
it('does not override child options', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const windowUrl = `file://${fixturesPath}/pages/window-open-size.html`;
const { eventData } = await w.webContents.executeJavaScript(`(async () => {
const message = new Promise(resolve => window.addEventListener('message', resolve, {once: true}));
const b = window.open(${JSON.stringify(windowUrl)}, '', 'show=no,width=350,height=450')
const e = await message
b.close();
return { eventData: e.data }
})()`);
expect(eventData).to.equal('size: 350 450');
});
it('loads preload script after setting opener to null', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
preload: path.join(fixturesPath, 'module', 'preload.js')
}
}
}));
w.loadURL('about:blank');
w.webContents.executeJavaScript('window.child = window.open(); child.opener = null');
const [, { webContents }] = await once(app, 'browser-window-created');
const [,, message] = await once(webContents, 'console-message');
expect(message).to.equal('{"require":"function","module":"object","exports":"object","process":"object","Buffer":"function"}');
});
it('disables the <webview> tag when it is disabled on the parent window', async () => {
const windowUrl = url.pathToFileURL(path.join(fixturesPath, 'pages', 'window-opener-no-webview-tag.html'));
windowUrl.searchParams.set('p', `${fixturesPath}/pages/window-opener-webview.html`);
const w = new BrowserWindow({ show: false });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const { eventData } = await w.webContents.executeJavaScript(`(async () => {
const message = new Promise(resolve => window.addEventListener('message', resolve, {once: true}));
const b = window.open(${JSON.stringify(windowUrl)}, '', 'webviewTag=no,contextIsolation=no,nodeIntegration=yes,show=no')
const e = await message
b.close();
return { eventData: e.data }
})()`);
expect(eventData.isWebViewGlobalUndefined).to.be.true();
});
it('throws an exception when the arguments cannot be converted to strings', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
await expect(
w.webContents.executeJavaScript('window.open(\'\', { toString: null })')
).to.eventually.be.rejected();
await expect(
w.webContents.executeJavaScript('window.open(\'\', \'\', { toString: 3 })')
).to.eventually.be.rejected();
});
it('does not throw an exception when the features include webPreferences', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
await expect(
w.webContents.executeJavaScript('window.open(\'\', \'\', \'show=no,webPreferences=\'); null')
).to.eventually.be.fulfilled();
});
});
describe('window.opener', () => {
it('is null for main window', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
w.loadFile(path.join(fixturesPath, 'pages', 'window-opener.html'));
const [, channel, opener] = await once(w.webContents, 'ipc-message');
expect(channel).to.equal('opener');
expect(opener).to.equal(null);
});
it('is not null for window opened by window.open', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const windowUrl = `file://${fixturesPath}/pages/window-opener.html`;
const eventData = await w.webContents.executeJavaScript(`
const b = window.open(${JSON.stringify(windowUrl)}, '', 'show=no');
new Promise(resolve => window.addEventListener('message', resolve, {once: true})).then(e => e.data);
`);
expect(eventData).to.equal('object');
});
});
describe('window.opener.postMessage', () => {
it('sets source and origin correctly', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const windowUrl = `file://${fixturesPath}/pages/window-opener-postMessage.html`;
const { sourceIsChild, origin } = await w.webContents.executeJavaScript(`
const b = window.open(${JSON.stringify(windowUrl)}, '', 'show=no');
new Promise(resolve => window.addEventListener('message', resolve, {once: true})).then(e => ({
sourceIsChild: e.source === b,
origin: e.origin
}));
`);
expect(sourceIsChild).to.be.true();
expect(origin).to.equal('file://');
});
it('supports windows opened from a <webview>', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { webviewTag: true } });
w.loadURL('about:blank');
const childWindowUrl = url.pathToFileURL(path.join(fixturesPath, 'pages', 'webview-opener-postMessage.html'));
childWindowUrl.searchParams.set('p', `${fixturesPath}/pages/window-opener-postMessage.html`);
const message = await w.webContents.executeJavaScript(`
const webview = new WebView();
webview.allowpopups = true;
webview.setAttribute('webpreferences', 'contextIsolation=no');
webview.src = ${JSON.stringify(childWindowUrl)}
const consoleMessage = new Promise(resolve => webview.addEventListener('console-message', resolve, {once: true}));
document.body.appendChild(webview);
consoleMessage.then(e => e.message)
`);
expect(message).to.equal('message');
});
describe('targetOrigin argument', () => {
let serverURL: string;
let server: any;
beforeEach(async () => {
server = http.createServer((req, res) => {
res.writeHead(200);
const filePath = path.join(fixturesPath, 'pages', 'window-opener-targetOrigin.html');
res.end(fs.readFileSync(filePath, 'utf8'));
});
serverURL = (await listen(server)).url;
});
afterEach(() => {
server.close();
});
it('delivers messages that match the origin', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const data = await w.webContents.executeJavaScript(`
window.open(${JSON.stringify(serverURL)}, '', 'show=no,contextIsolation=no,nodeIntegration=yes');
new Promise(resolve => window.addEventListener('message', resolve, {once: true})).then(e => e.data)
`);
expect(data).to.equal('deliver');
});
});
});
describe('Storage Access API', () => {
afterEach(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionCheckHandler(null);
session.defaultSession.setPermissionRequestHandler(null);
});
it('can determine if a permission is granted for "storage-access"', async () => {
session.defaultSession.setPermissionCheckHandler(
(_wc, permission) => permission === 'storage-access'
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
const permission = await w.webContents.executeJavaScript(`
navigator.permissions.query({ name: 'storage-access' })
.then(permission => permission.state).catch(err => err.message);
`, true);
expect(permission).to.eq('granted');
});
it('can determine if a permission is denied for "storage-access"', async () => {
session.defaultSession.setPermissionCheckHandler(
(_wc, permission) => permission !== 'storage-access'
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
const permission = await w.webContents.executeJavaScript(`
navigator.permissions.query({ name: 'storage-access' })
.then(permission => permission.state).catch(err => err.message);
`, true);
expect(permission).to.eq('denied');
});
it('can determine if a permission is granted for "top-level-storage-access"', async () => {
session.defaultSession.setPermissionCheckHandler(
(_wc, permission) => permission === 'top-level-storage-access'
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
const permission = await w.webContents.executeJavaScript(`
navigator.permissions.query({
name: 'top-level-storage-access',
requestedOrigin: "https://www.example.com",
}).then(permission => permission.state).catch(err => err.message);
`, true);
expect(permission).to.eq('granted');
});
it('can determine if a permission is denied for "top-level-storage-access"', async () => {
session.defaultSession.setPermissionCheckHandler(
(_wc, permission) => permission !== 'top-level-storage-access'
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
const permission = await w.webContents.executeJavaScript(`
navigator.permissions.query({
name: 'top-level-storage-access',
requestedOrigin: "https://www.example.com",
}).then(permission => permission.state).catch(err => err.message);
`, true);
expect(permission).to.eq('denied');
});
it('can grant a permission request for "top-level-storage-access"', async () => {
session.defaultSession.setPermissionRequestHandler(
(_wc, permission, callback) => {
callback(permission === 'top-level-storage-access');
}
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
// requestStorageAccessFor returns a Promise that fulfills with undefined
// if the access to third-party cookies was granted and rejects if access was denied.
const permission = await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const button = document.getElementById('button');
button.addEventListener("click", () => {
document.requestStorageAccessFor('https://myfakesite').then(
(res) => { resolve('granted') },
(err) => { resolve('denied') },
);
});
button.click();
});
`, true);
expect(permission).to.eq('granted');
});
it('can deny a permission request for "top-level-storage-access"', async () => {
session.defaultSession.setPermissionRequestHandler(
(_wc, permission, callback) => {
callback(permission !== 'top-level-storage-access');
}
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
// requestStorageAccessFor returns a Promise that fulfills with undefined
// if the access to third-party cookies was granted and rejects if access was denied.
const permission = await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const button = document.getElementById('button');
button.addEventListener("click", () => {
document.requestStorageAccessFor('https://myfakesite').then(
(res) => { resolve('granted') },
(err) => { resolve('denied') },
);
});
button.click();
});
`, true);
expect(permission).to.eq('denied');
});
});
describe('IdleDetection', () => {
afterEach(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionCheckHandler(null);
session.defaultSession.setPermissionRequestHandler(null);
});
it('can grant a permission request', async () => {
session.defaultSession.setPermissionRequestHandler(
(_wc, permission, callback) => {
callback(permission === 'idle-detection');
}
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
const permission = await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const button = document.getElementById('button');
button.addEventListener("click", async () => {
const permission = await IdleDetector.requestPermission();
resolve(permission);
});
button.click();
});
`, true);
expect(permission).to.eq('granted');
});
it('can deny a permission request', async () => {
session.defaultSession.setPermissionRequestHandler(
(_wc, permission, callback) => {
callback(permission !== 'idle-detection');
}
);
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'button.html'));
const permission = await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const button = document.getElementById('button');
button.addEventListener("click", async () => {
const permission = await IdleDetector.requestPermission();
resolve(permission);
});
button.click();
});
`, true);
expect(permission).to.eq('denied');
});
it('can allow the IdleDetector to start', async () => {
session.defaultSession.setPermissionCheckHandler((wc, permission) => {
return permission === 'idle-detection';
});
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const result = await w.webContents.executeJavaScript(`
const detector = new IdleDetector({ threshold: 60000 });
detector.start().then(() => {
return 'success';
}).catch(e => e.message);
`, true);
expect(result).to.eq('success');
});
it('can prevent the IdleDetector from starting', async () => {
session.defaultSession.setPermissionCheckHandler((wc, permission) => {
return permission !== 'idle-detection';
});
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const result = await w.webContents.executeJavaScript(`
const detector = new IdleDetector({ threshold: 60000 });
detector.start().then(() => {
console.log('success')
}).catch(e => e.message);
`, true);
expect(result).to.eq('Idle detection permission denied');
});
});
describe('navigator.mediaDevices', () => {
afterEach(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionCheckHandler(null);
session.defaultSession.setPermissionRequestHandler(null);
});
it('can return labels of enumerated devices', async () => {
2019-11-01 20:37:02 +00:00
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const labels = await w.webContents.executeJavaScript('navigator.mediaDevices.enumerateDevices().then(ds => ds.map(d => d.label))');
expect(labels.some((l: any) => l)).to.be.true();
});
it('does not return labels of enumerated devices when permission denied', async () => {
session.defaultSession.setPermissionCheckHandler(() => false);
2019-11-01 20:37:02 +00:00
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const labels = await w.webContents.executeJavaScript('navigator.mediaDevices.enumerateDevices().then(ds => ds.map(d => d.label))');
expect(labels.some((l: any) => l)).to.be.false();
});
it('returns the same device ids across reloads', async () => {
const ses = session.fromPartition('persist:media-device-id');
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
session: ses,
contextIsolation: false
}
});
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'));
const [, firstDeviceIds] = await once(ipcMain, 'deviceIds');
w.webContents.reload();
const [, secondDeviceIds] = await once(ipcMain, 'deviceIds');
expect(firstDeviceIds).to.deep.equal(secondDeviceIds);
});
it('can return new device id when cookie storage is cleared', async () => {
const ses = session.fromPartition('persist:media-device-id');
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
session: ses,
contextIsolation: false
}
});
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'));
const [, firstDeviceIds] = await once(ipcMain, 'deviceIds');
await ses.clearStorageData({ storages: ['cookies'] });
w.webContents.reload();
const [, secondDeviceIds] = await once(ipcMain, 'deviceIds');
expect(firstDeviceIds).to.not.deep.equal(secondDeviceIds);
});
it('provides a securityOrigin to the request handler', async () => {
session.defaultSession.setPermissionRequestHandler(
(wc, permission, callback, details) => {
if ((details as MediaAccessPermissionRequest).securityOrigin !== undefined) {
callback(true);
} else {
callback(false);
}
}
);
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const labels = await w.webContents.executeJavaScript(`navigator.mediaDevices.getUserMedia({
video: {
mandatory: {
chromeMediaSource: "desktop",
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,
maxHeight: 720
}
}
}).then((stream) => stream.getVideoTracks())`);
expect(labels.some((l: any) => l)).to.be.true();
});
it('fails with "not supported" for getDisplayMedia', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.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 11:43:42 +00:00
const { ok, err } = await w.webContents.executeJavaScript('navigator.mediaDevices.getDisplayMedia({video: true}).then(s => ({ok: true}), e => ({ok: false, err: e.message}))', true);
expect(ok).to.be.false();
expect(err).to.equal('Not supported');
});
});
describe('window.opener access', () => {
const scheme = 'app';
const fileUrl = `file://${fixturesPath}/pages/window-opener-location.html`;
const httpUrl1 = `${scheme}://origin1`;
const httpUrl2 = `${scheme}://origin2`;
const fileBlank = `file://${fixturesPath}/pages/blank.html`;
const httpBlank = `${scheme}://origin1/blank`;
const table = [
{ parent: fileBlank, child: httpUrl1, nodeIntegration: false, openerAccessible: false },
{ parent: fileBlank, child: httpUrl1, nodeIntegration: true, openerAccessible: false },
// {parent: httpBlank, child: fileUrl, nodeIntegration: false, openerAccessible: false}, // can't window.open()
// {parent: httpBlank, child: fileUrl, nodeIntegration: true, openerAccessible: false}, // can't window.open()
// NB. this is different from Chrome's behavior, which isolates file: urls from each other
{ parent: fileBlank, child: fileUrl, nodeIntegration: false, openerAccessible: true },
{ parent: fileBlank, child: fileUrl, nodeIntegration: true, openerAccessible: true },
{ parent: httpBlank, child: httpUrl1, nodeIntegration: false, openerAccessible: true },
{ parent: httpBlank, child: httpUrl1, nodeIntegration: true, openerAccessible: true },
{ parent: httpBlank, child: httpUrl2, nodeIntegration: false, openerAccessible: false },
{ parent: httpBlank, child: httpUrl2, nodeIntegration: true, openerAccessible: false }
];
const s = (url: string) => url.startsWith('file') ? 'file://...' : url;
before(() => {
protocol.registerFileProtocol(scheme, (request, callback) => {
if (request.url.includes('blank')) {
callback(`${fixturesPath}/pages/blank.html`);
} else {
callback(`${fixturesPath}/pages/window-opener-location.html`);
}
});
});
after(() => {
protocol.unregisterProtocol(scheme);
});
afterEach(closeAllWindows);
describe('when opened from main window', () => {
for (const { parent, child, nodeIntegration, openerAccessible } of table) {
for (const sandboxPopup of [false, true]) {
const description = `when parent=${s(parent)} opens child=${s(child)} with nodeIntegration=${nodeIntegration} sandboxPopup=${sandboxPopup}, child should ${openerAccessible ? '' : 'not '}be able to access opener`;
it(description, async () => {
const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
sandbox: sandboxPopup
}
}
}));
await w.loadURL(parent);
const childOpenerLocation = await w.webContents.executeJavaScript(`new Promise(resolve => {
window.addEventListener('message', function f(e) {
resolve(e.data)
})
window.open(${JSON.stringify(child)}, "", "show=no,nodeIntegration=${nodeIntegration ? 'yes' : 'no'}")
})`);
if (openerAccessible) {
expect(childOpenerLocation).to.be.a('string');
} else {
expect(childOpenerLocation).to.be.null();
}
});
}
}
});
describe('when opened from <webview>', () => {
for (const { parent, child, nodeIntegration, openerAccessible } of table) {
const description = `when parent=${s(parent)} opens child=${s(child)} with nodeIntegration=${nodeIntegration}, child should ${openerAccessible ? '' : 'not '}be able to access opener`;
it(description, async () => {
// This test involves three contexts:
// 1. The root BrowserWindow in which the test is run,
// 2. A <webview> belonging to the root window,
// 3. A window opened by calling window.open() from within the <webview>.
// We are testing whether context (3) can access context (2) under various conditions.
// This is context (1), the base window for the test.
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, webviewTag: true, contextIsolation: false } });
await w.loadURL('about:blank');
const parentCode = `new Promise((resolve) => {
// This is context (3), a child window of the WebView.
const child = window.open(${JSON.stringify(child)}, "", "show=no,contextIsolation=no,nodeIntegration=yes")
window.addEventListener("message", e => {
resolve(e.data)
})
})`;
const childOpenerLocation = await w.webContents.executeJavaScript(`new Promise((resolve, reject) => {
// This is context (2), a WebView which will call window.open()
const webview = new WebView()
2019-11-01 20:37:02 +00:00
webview.setAttribute('nodeintegration', '${nodeIntegration ? 'on' : 'off'}')
webview.setAttribute('webpreferences', 'contextIsolation=no')
webview.setAttribute('allowpopups', 'on')
webview.src = ${JSON.stringify(parent + '?p=' + encodeURIComponent(child))}
webview.addEventListener('dom-ready', async () => {
webview.executeJavaScript(${JSON.stringify(parentCode)}).then(resolve, reject)
})
document.body.appendChild(webview)
})`);
if (openerAccessible) {
expect(childOpenerLocation).to.be.a('string');
} else {
expect(childOpenerLocation).to.be.null();
}
});
}
});
});
describe('storage', () => {
describe('custom non standard schemes', () => {
const protocolName = 'storage';
let contents: WebContents;
before(() => {
protocol.registerFileProtocol(protocolName, (request, callback) => {
const parsedUrl = url.parse(request.url);
let filename;
switch (parsedUrl.pathname) {
case '/localStorage' : filename = 'local_storage.html'; break;
case '/sessionStorage' : filename = 'session_storage.html'; break;
case '/WebSQL' : filename = 'web_sql.html'; break;
case '/indexedDB' : filename = 'indexed_db.html'; break;
case '/cookie' : filename = 'cookie.html'; break;
default : filename = '';
}
callback({ path: `${fixturesPath}/pages/storage/${filename}` });
});
});
after(() => {
protocol.unregisterProtocol(protocolName);
});
beforeEach(() => {
contents = (webContents as typeof ElectronInternal.WebContents).create({
nodeIntegration: true,
contextIsolation: false
});
});
afterEach(() => {
contents.destroy();
contents = null as any;
});
it('cannot access localStorage', async () => {
const response = once(ipcMain, 'local-storage-response');
contents.loadURL(protocolName + '://host/localStorage');
const [, error] = await response;
expect(error).to.equal('Failed to read the \'localStorage\' property from \'Window\': Access is denied for this document.');
});
it('cannot access sessionStorage', async () => {
const response = once(ipcMain, 'session-storage-response');
contents.loadURL(`${protocolName}://host/sessionStorage`);
const [, error] = await response;
expect(error).to.equal('Failed to read the \'sessionStorage\' property from \'Window\': Access is denied for this document.');
});
it('cannot access WebSQL database', async () => {
const response = once(ipcMain, 'web-sql-response');
contents.loadURL(`${protocolName}://host/WebSQL`);
const [, error] = await response;
expect(error).to.equal('Failed to execute \'openDatabase\' on \'Window\': Access to the WebDatabase API is denied in this context.');
});
it('cannot access indexedDB', async () => {
const response = once(ipcMain, 'indexed-db-response');
contents.loadURL(`${protocolName}://host/indexedDB`);
const [, error] = await response;
expect(error).to.equal('Failed to execute \'open\' on \'IDBFactory\': access to the Indexed Database API is denied in this context.');
});
it('cannot access cookie', async () => {
const response = once(ipcMain, 'cookie-response');
contents.loadURL(`${protocolName}://host/cookie`);
const [, error] = await response;
expect(error).to.equal('Failed to set the \'cookie\' property on \'Document\': Access is denied for this document.');
});
});
describe('can be accessed', () => {
let server: http.Server;
let serverUrl: string;
let serverCrossSiteUrl: string;
before(async () => {
server = http.createServer((req, res) => {
const respond = () => {
if (req.url === '/redirect-cross-site') {
res.setHeader('Location', `${serverCrossSiteUrl}/redirected`);
res.statusCode = 302;
res.end();
} else if (req.url === '/redirected') {
res.end('<html><script>window.localStorage</script></html>');
} else {
res.end();
}
};
setTimeout().then(respond);
});
serverUrl = (await listen(server)).url;
serverCrossSiteUrl = serverUrl.replace('127.0.0.1', 'localhost');
});
after(() => {
server.close();
server = null as any;
});
afterEach(closeAllWindows);
const testLocalStorageAfterXSiteRedirect = (testTitle: string, extraPreferences = {}) => {
it(testTitle, async () => {
const w = new BrowserWindow({
show: false,
...extraPreferences
});
let redirected = false;
w.webContents.on('render-process-gone', () => {
expect.fail('renderer crashed / was killed');
});
w.webContents.on('did-redirect-navigation', (event, url) => {
expect(url).to.equal(`${serverCrossSiteUrl}/redirected`);
redirected = true;
});
await w.loadURL(`${serverUrl}/redirect-cross-site`);
expect(redirected).to.be.true('didnt redirect');
});
};
2020-03-20 20:28:31 +00:00
testLocalStorageAfterXSiteRedirect('after a cross-site redirect');
testLocalStorageAfterXSiteRedirect('after a cross-site redirect in sandbox mode', { sandbox: true });
});
describe('enableWebSQL webpreference', () => {
const origin = `${standardScheme}://fake-host`;
const filePath = path.join(fixturesPath, 'pages', 'storage', 'web_sql.html');
const sqlPartition = 'web-sql-preference-test';
const sqlSession = session.fromPartition(sqlPartition);
const securityError = 'An attempt was made to break through the security policy of the user agent.';
let contents: WebContents, w: BrowserWindow;
before(() => {
sqlSession.protocol.registerFileProtocol(standardScheme, (request, callback) => {
callback({ path: filePath });
});
});
after(() => {
sqlSession.protocol.unregisterProtocol(standardScheme);
});
afterEach(async () => {
if (contents) {
contents.destroy();
contents = null as any;
}
await closeAllWindows();
(w as any) = null;
});
it('default value allows websql', async () => {
contents = (webContents as typeof ElectronInternal.WebContents).create({
session: sqlSession,
nodeIntegration: true,
contextIsolation: false
});
contents.loadURL(origin);
const [, error] = await once(ipcMain, 'web-sql-response');
expect(error).to.be.null();
});
it('when set to false can disallow websql', async () => {
contents = (webContents as typeof ElectronInternal.WebContents).create({
session: sqlSession,
nodeIntegration: true,
enableWebSQL: false,
contextIsolation: false
});
contents.loadURL(origin);
const [, error] = await once(ipcMain, 'web-sql-response');
expect(error).to.equal(securityError);
});
it('when set to false does not disable indexedDB', async () => {
contents = (webContents as typeof ElectronInternal.WebContents).create({
session: sqlSession,
nodeIntegration: true,
enableWebSQL: false,
contextIsolation: false
});
contents.loadURL(origin);
const [, error] = await once(ipcMain, 'web-sql-response');
expect(error).to.equal(securityError);
const dbName = 'random';
const result = await contents.executeJavaScript(`
new Promise((resolve, reject) => {
try {
let req = window.indexedDB.open('${dbName}');
req.onsuccess = (event) => {
let db = req.result;
resolve(db.name);
}
req.onerror = (event) => { resolve(event.target.code); }
} catch (e) {
resolve(e.message);
}
});
`);
expect(result).to.equal(dbName);
});
it('child webContents can override when the embedder has allowed websql', async () => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
webviewTag: true,
session: sqlSession,
contextIsolation: false
}
});
w.webContents.loadURL(origin);
const [, error] = await once(ipcMain, 'web-sql-response');
expect(error).to.be.null();
const webviewResult = once(ipcMain, 'web-sql-response');
await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const webview = new WebView();
webview.setAttribute('src', '${origin}');
webview.setAttribute('webpreferences', 'enableWebSQL=0,contextIsolation=no');
webview.setAttribute('partition', '${sqlPartition}');
webview.setAttribute('nodeIntegration', 'on');
document.body.appendChild(webview);
webview.addEventListener('dom-ready', () => resolve());
});
`);
const [, childError] = await webviewResult;
expect(childError).to.equal(securityError);
});
it('child webContents cannot override when the embedder has disallowed websql', async () => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
enableWebSQL: false,
webviewTag: true,
session: sqlSession,
contextIsolation: false
}
});
w.webContents.loadURL('data:text/html,<html></html>');
const webviewResult = once(ipcMain, 'web-sql-response');
await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const webview = new WebView();
webview.setAttribute('src', '${origin}');
webview.setAttribute('webpreferences', 'enableWebSQL=1,contextIsolation=no');
webview.setAttribute('partition', '${sqlPartition}');
webview.setAttribute('nodeIntegration', 'on');
document.body.appendChild(webview);
webview.addEventListener('dom-ready', () => resolve());
});
`);
const [, childError] = await webviewResult;
expect(childError).to.equal(securityError);
});
it('child webContents can use websql when the embedder has allowed websql', async () => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
webviewTag: true,
session: sqlSession,
contextIsolation: false
}
});
w.webContents.loadURL(origin);
const [, error] = await once(ipcMain, 'web-sql-response');
expect(error).to.be.null();
const webviewResult = once(ipcMain, 'web-sql-response');
await w.webContents.executeJavaScript(`
new Promise((resolve, reject) => {
const webview = new WebView();
webview.setAttribute('src', '${origin}');
webview.setAttribute('webpreferences', 'enableWebSQL=1,contextIsolation=no');
webview.setAttribute('partition', '${sqlPartition}');
webview.setAttribute('nodeIntegration', 'on');
document.body.appendChild(webview);
webview.addEventListener('dom-ready', () => resolve());
});
`);
const [, childError] = await webviewResult;
expect(childError).to.be.null();
});
});
describe('DOM storage quota increase', () => {
for (const storageName of ['localStorage', 'sessionStorage']) {
it(`allows saving at least 40MiB in ${storageName}`, async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
// Although JavaScript strings use UTF-16, the underlying
// storage provider may encode strings differently, muddling the
// translation between character and byte counts. However,
// a string of 40 * 2^20 characters will require at least 40MiB
// and presumably no more than 80MiB, a size guaranteed to
// to exceed the original 10MiB quota yet stay within the
// new 100MiB quota.
// Note that both the key name and value affect the total size.
const testKeyName = '_electronDOMStorageQuotaIncreasedTest';
const length = 40 * Math.pow(2, 20) - testKeyName.length;
await w.webContents.executeJavaScript(`
${storageName}.setItem(${JSON.stringify(testKeyName)}, 'X'.repeat(${length}));
`);
// Wait at least one turn of the event loop to help avoid false positives
// Although not entirely necessary, the previous version of this test case
// failed to detect a real problem (perhaps related to DOM storage data caching)
// wherein calling `getItem` immediately after `setItem` would appear to work
// but then later (e.g. next tick) it would not.
await setTimeout(1);
try {
const storedLength = await w.webContents.executeJavaScript(`${storageName}.getItem(${JSON.stringify(testKeyName)}).length`);
expect(storedLength).to.equal(length);
} finally {
await w.webContents.executeJavaScript(`${storageName}.removeItem(${JSON.stringify(testKeyName)});`);
}
});
it(`throws when attempting to use more than 128MiB in ${storageName}`, async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
await expect((async () => {
const testKeyName = '_electronDOMStorageQuotaStillEnforcedTest';
const length = 128 * Math.pow(2, 20) - testKeyName.length;
try {
await w.webContents.executeJavaScript(`
${storageName}.setItem(${JSON.stringify(testKeyName)}, 'X'.repeat(${length}));
`);
} finally {
await w.webContents.executeJavaScript(`${storageName}.removeItem(${JSON.stringify(testKeyName)});`);
}
})()).to.eventually.be.rejected();
});
}
});
describe('persistent storage', () => {
it('can be requested', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const grantedBytes = await w.webContents.executeJavaScript(`new Promise(resolve => {
navigator.webkitPersistentStorage.requestQuota(1024 * 1024, resolve);
})`);
expect(grantedBytes).to.equal(1048576);
});
});
});
ifdescribe(features.isPDFViewerEnabled())('PDF Viewer', () => {
const pdfSource = url.format({
pathname: path.join(__dirname, 'fixtures', 'cat.pdf').replaceAll('\\', '/'),
protocol: 'file',
slashes: true
});
it('successfully loads a PDF file', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(pdfSource);
await once(w.webContents, 'did-finish-load');
});
2020-02-13 00:39:12 +00:00
it('opens when loading a pdf resource as top level navigation', async () => {
const w = new BrowserWindow({ show: false });
2020-02-13 00:39:12 +00:00
w.loadURL(pdfSource);
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
await once(contents, 'did-navigate');
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
});
2020-02-13 00:39:12 +00:00
it('opens when loading a pdf resource in a iframe', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'pdf-in-iframe.html'));
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
await once(contents, 'did-navigate');
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
});
});
describe('window.history', () => {
describe('window.history.pushState', () => {
it('should push state after calling history.pushState() from the same url', async () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
// History should have current page by now.
expect(w.webContents.navigationHistory.length()).to.equal(1);
const waitCommit = once(w.webContents, 'navigation-entry-committed');
w.webContents.executeJavaScript('window.history.pushState({}, "")');
await waitCommit;
// Initial page + pushed state.
expect(w.webContents.navigationHistory.length()).to.equal(2);
});
});
describe('window.history.back', () => {
it('should not allow sandboxed iframe to modify main frame state', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('data:text/html,<iframe sandbox="allow-scripts"></iframe>');
await Promise.all([
once(w.webContents, 'navigation-entry-committed'),
once(w.webContents, 'did-frame-navigate'),
once(w.webContents, 'did-navigate')
]);
w.webContents.executeJavaScript('window.history.pushState(1, "")');
await Promise.all([
once(w.webContents, 'navigation-entry-committed'),
once(w.webContents, 'did-navigate-in-page')
]);
w.webContents.once('navigation-entry-committed' as any, () => {
expect.fail('Unexpected navigation-entry-committed');
});
w.webContents.once('did-navigate-in-page', () => {
expect.fail('Unexpected did-navigate-in-page');
});
await w.webContents.mainFrame.frames[0].executeJavaScript('window.history.back()');
expect(await w.webContents.executeJavaScript('window.history.state')).to.equal(1);
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(1);
});
});
});
describe('chrome:// pages', () => {
const urls = [
'chrome://accessibility',
'chrome://gpu',
'chrome://media-internals',
'chrome://tracing',
'chrome://webrtc-internals',
'chrome://process-internals'
];
for (const url of urls) {
describe(url, () => {
it('loads the page successfully', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(url);
const host = url.substring('chrome://'.length);
const pageExists = await w.webContents.executeJavaScript(
`window.hasOwnProperty('chrome') && window.location.host === '${host}'`
);
expect(pageExists).to.be.true();
});
});
}
});
describe('document.hasFocus', () => {
it('has correct value when multiple windows are opened', async () => {
const w1 = new BrowserWindow({ show: true });
const w2 = new BrowserWindow({ show: true });
const w3 = new BrowserWindow({ show: false });
await w1.loadFile(path.join(__dirname, 'fixtures', 'blank.html'));
await w2.loadFile(path.join(__dirname, 'fixtures', 'blank.html'));
await w3.loadFile(path.join(__dirname, 'fixtures', 'blank.html'));
expect(webContents.getFocusedWebContents()?.id).to.equal(w2.webContents.id);
let focus = false;
focus = await w1.webContents.executeJavaScript(
'document.hasFocus()'
);
expect(focus).to.be.false();
focus = await w2.webContents.executeJavaScript(
'document.hasFocus()'
);
expect(focus).to.be.true();
focus = await w3.webContents.executeJavaScript(
'document.hasFocus()'
);
expect(focus).to.be.false();
});
});
// https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation
describe('navigator.connection', () => {
it('returns the correct value', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.session.enableNetworkEmulation({
latency: 500,
downloadThroughput: 6400,
uploadThroughput: 6400
});
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const rtt = await w.webContents.executeJavaScript('navigator.connection.rtt');
expect(rtt).to.be.a('number');
const downlink = await w.webContents.executeJavaScript('navigator.connection.downlink');
expect(downlink).to.be.a('number');
const effectiveTypes = ['slow-2g', '2g', '3g', '4g'];
const effectiveType = await w.webContents.executeJavaScript('navigator.connection.effectiveType');
expect(effectiveTypes).to.include(effectiveType);
});
});
describe('navigator.userAgentData', () => {
// These tests are done on an http server because navigator.userAgentData
// requires a secure context.
let server: http.Server;
let serverUrl: string;
before(async () => {
server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end('');
});
serverUrl = (await listen(server)).url;
});
after(() => {
server.close();
});
describe('is not empty', () => {
it('by default', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(serverUrl);
const platform = await w.webContents.executeJavaScript('navigator.userAgentData.platform');
expect(platform).not.to.be.empty();
});
it('when there is a session-wide UA override', async () => {
const ses = session.fromPartition(`${Math.random()}`);
ses.setUserAgent('foobar');
const w = new BrowserWindow({ show: false, webPreferences: { session: ses } });
await w.loadURL(serverUrl);
const platform = await w.webContents.executeJavaScript('navigator.userAgentData.platform');
expect(platform).not.to.be.empty();
});
it('when there is a WebContents-specific UA override', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.setUserAgent('foo');
await w.loadURL(serverUrl);
const platform = await w.webContents.executeJavaScript('navigator.userAgentData.platform');
expect(platform).not.to.be.empty();
});
it('when there is a WebContents-specific UA override at load time', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(serverUrl, {
userAgent: 'foo'
});
const platform = await w.webContents.executeJavaScript('navigator.userAgentData.platform');
expect(platform).not.to.be.empty();
});
});
describe('brand list', () => {
it('contains chromium', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(serverUrl);
const brands = await w.webContents.executeJavaScript('navigator.userAgentData.brands');
expect(brands.map((b: any) => b.brand)).to.include('Chromium');
});
});
});
describe('Badging API', () => {
it('does not crash', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
await w.webContents.executeJavaScript('navigator.setAppBadge(42)');
await w.webContents.executeJavaScript('navigator.setAppBadge()');
await w.webContents.executeJavaScript('navigator.clearAppBadge()');
});
});
describe('navigator.webkitGetUserMedia', () => {
it('calls its callbacks', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
await w.webContents.executeJavaScript(`new Promise((resolve) => {
navigator.webkitGetUserMedia({
audio: true,
video: false
}, () => resolve(),
() => resolve());
})`);
});
});
describe('navigator.language', () => {
it('should not be empty', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
expect(await w.webContents.executeJavaScript('navigator.language')).to.not.equal('');
});
});
describe('heap snapshot', () => {
it('does not crash', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
w.loadURL('about:blank');
await w.webContents.executeJavaScript('process._linkedBinding(\'electron_common_v8_util\').takeHeapSnapshot()');
});
});
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 11:43:42 +00:00
// This is intentionally disabled on arm macs: https://chromium-review.googlesource.com/c/chromium/src/+/4143761
ifdescribe(process.platform === 'darwin' && process.arch !== 'arm64')('webgl', () => {
it('can be gotten as context in canvas', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const canWebglContextBeCreated = await w.webContents.executeJavaScript(`
document.createElement('canvas').getContext('webgl') != null;
`);
expect(canWebglContextBeCreated).to.be.true();
});
});
describe('iframe', () => {
it('does not have node integration', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const result = await w.webContents.executeJavaScript(`
const iframe = document.createElement('iframe')
iframe.src = './set-global.html';
document.body.appendChild(iframe);
new Promise(resolve => iframe.onload = e => resolve(iframe.contentWindow.test))
`);
expect(result).to.equal('undefined undefined undefined');
});
});
describe('websockets', () => {
it('has user agent', async () => {
const server = http.createServer();
const { port } = await listen(server);
const wss = new ws.Server({ server: server });
const finished = new Promise<string | undefined>((resolve, reject) => {
wss.on('error', reject);
wss.on('connection', (ws, upgradeReq) => {
resolve(upgradeReq.headers['user-agent']);
});
});
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript(`
new WebSocket('ws://127.0.0.1:${port}');
`);
expect(await finished).to.include('Electron');
});
});
describe('fetch', () => {
it('does not crash', async () => {
const server = http.createServer((req, res) => {
res.end('test');
});
defer(() => server.close());
const { port } = await listen(server);
const w = new BrowserWindow({ show: false });
w.loadURL(`file://${fixturesPath}/pages/blank.html`);
const x = await w.webContents.executeJavaScript(`
fetch('http://127.0.0.1:${port}').then((res) => res.body.getReader())
.then((reader) => {
return reader.read().then((r) => {
reader.cancel();
return r.value;
});
})
`);
expect(x).to.deep.equal(new Uint8Array([116, 101, 115, 116]));
});
});
describe('Promise', () => {
before(() => {
ipcMain.handle('ping', (e, arg) => arg);
});
after(() => {
ipcMain.removeHandler('ping');
});
itremote('resolves correctly in Node.js calls', async () => {
await new Promise<void>((resolve, reject) => {
class XElement extends HTMLElement {}
customElements.define('x-element', XElement);
setImmediate(() => {
let called = false;
Promise.resolve().then(() => {
if (called) resolve();
else reject(new Error('wrong sequence'));
});
document.createElement('x-element');
called = true;
});
});
});
itremote('resolves correctly in Electron calls', async () => {
await new Promise<void>((resolve, reject) => {
class YElement extends HTMLElement {}
customElements.define('y-element', YElement);
require('electron').ipcRenderer.invoke('ping').then(() => {
let called = false;
Promise.resolve().then(() => {
if (called) resolve();
else reject(new Error('wrong sequence'));
});
document.createElement('y-element');
called = true;
});
});
});
});
describe('synchronous prompts', () => {
describe('window.alert(message, title)', () => {
itremote('throws an exception when the arguments cannot be converted to strings', () => {
expect(() => {
window.alert({ toString: null });
}).to.throw('Cannot convert object to primitive value');
});
it('shows a message box', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
const p = once(w.webContents, '-run-dialog');
w.webContents.executeJavaScript('alert("hello")', true);
const [info] = await p;
expect(info.frame).to.equal(w.webContents.mainFrame);
expect(info.messageText).to.equal('hello');
expect(info.dialogType).to.equal('alert');
});
it('does not crash if a webContents is destroyed while an alert is showing', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
const p = once(w.webContents, '-run-dialog');
w.webContents.executeJavaScript('alert("hello")', true);
await p;
w.webContents.close();
});
});
describe('window.confirm(message, title)', () => {
itremote('throws an exception when the arguments cannot be converted to strings', () => {
expect(() => {
(window.confirm as any)({ toString: null }, 'title');
}).to.throw('Cannot convert object to primitive value');
});
it('shows a message box', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
const p = once(w.webContents, '-run-dialog');
const resultPromise = w.webContents.executeJavaScript('confirm("hello")', true);
const [info, cb] = await p;
expect(info.frame).to.equal(w.webContents.mainFrame);
expect(info.messageText).to.equal('hello');
expect(info.dialogType).to.equal('confirm');
cb(true, '');
const result = await resultPromise;
expect(result).to.be.true();
});
});
describe('safeDialogs web preference', () => {
const originalShowMessageBox = dialog.showMessageBox;
afterEach(() => {
dialog.showMessageBox = originalShowMessageBox;
if (protocol.isProtocolHandled('https')) protocol.unhandle('https');
if (protocol.isProtocolHandled('file')) protocol.unhandle('file');
});
it('does not show the checkbox if not enabled', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { safeDialogs: false } });
w.loadURL('about:blank');
// 1. The first alert() doesn't show the safeDialogs message.
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
await w.webContents.executeJavaScript('alert("hi")');
let recordedOpts: MessageBoxOptions | undefined;
dialog.showMessageBox = (bw, opts?: MessageBoxOptions) => {
recordedOpts = opts;
return Promise.resolve({ response: 0, checkboxChecked: false });
};
await w.webContents.executeJavaScript('alert("hi")');
expect(recordedOpts?.checkboxLabel).to.equal('');
});
it('is respected', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { safeDialogs: true } });
w.loadURL('about:blank');
// 1. The first alert() doesn't show the safeDialogs message.
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
await w.webContents.executeJavaScript('alert("hi")');
// 2. The second alert() shows the message with a checkbox. Respond that we checked it.
let recordedOpts: MessageBoxOptions | undefined;
dialog.showMessageBox = (bw, opts?: MessageBoxOptions) => {
recordedOpts = opts;
return Promise.resolve({ response: 0, checkboxChecked: true });
};
await w.webContents.executeJavaScript('alert("hi")');
expect(recordedOpts?.checkboxLabel).to.be.a('string').with.length.above(0);
// 3. The third alert() shouldn't show a dialog.
dialog.showMessageBox = () => Promise.reject(new Error('unexpected showMessageBox'));
await w.webContents.executeJavaScript('alert("hi")');
});
it('shows the safeDialogMessage', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { safeDialogs: true, safeDialogsMessage: 'foo bar' } });
w.loadURL('about:blank');
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
await w.webContents.executeJavaScript('alert("hi")');
let recordedOpts: MessageBoxOptions | undefined;
dialog.showMessageBox = (bw, opts?: MessageBoxOptions) => {
recordedOpts = opts;
return Promise.resolve({ response: 0, checkboxChecked: true });
};
await w.webContents.executeJavaScript('alert("hi")');
expect(recordedOpts?.checkboxLabel).to.equal('foo bar');
});
it('has persistent state across navigations', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { safeDialogs: true } });
w.loadURL('about:blank');
// 1. The first alert() doesn't show the safeDialogs message.
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
await w.webContents.executeJavaScript('alert("hi")');
// 2. The second alert() shows the message with a checkbox. Respond that we checked it.
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: true });
await w.webContents.executeJavaScript('alert("hi")');
// 3. The third alert() shouldn't show a dialog.
dialog.showMessageBox = () => Promise.reject(new Error('unexpected showMessageBox'));
await w.webContents.executeJavaScript('alert("hi")');
// 4. After navigating to the same origin, message boxes should still be hidden.
w.loadURL('about:blank');
await w.webContents.executeJavaScript('alert("hi")');
});
it('is separated by origin', async () => {
protocol.handle('https', () => new Response(''));
const w = new BrowserWindow({ show: false, webPreferences: { safeDialogs: true } });
w.loadURL('https://example1');
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
await w.webContents.executeJavaScript('alert("hi")');
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: true });
await w.webContents.executeJavaScript('alert("hi")');
dialog.showMessageBox = () => Promise.reject(new Error('unexpected showMessageBox'));
await w.webContents.executeJavaScript('alert("hi")');
// A different origin is allowed to show message boxes after navigation.
w.loadURL('https://example2');
let dialogWasShown = false;
dialog.showMessageBox = () => {
dialogWasShown = true;
return Promise.resolve({ response: 0, checkboxChecked: false });
};
await w.webContents.executeJavaScript('alert("hi")');
expect(dialogWasShown).to.be.true();
// Navigating back to the first origin means alerts are blocked again.
w.loadURL('https://example1');
dialog.showMessageBox = () => Promise.reject(new Error('unexpected showMessageBox'));
await w.webContents.executeJavaScript('alert("hi")');
});
it('treats different file: paths as different origins', async () => {
protocol.handle('file', () => new Response(''));
const w = new BrowserWindow({ show: false, webPreferences: { safeDialogs: true } });
w.loadURL('file:///path/1');
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
await w.webContents.executeJavaScript('alert("hi")');
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: true });
await w.webContents.executeJavaScript('alert("hi")');
dialog.showMessageBox = () => Promise.reject(new Error('unexpected showMessageBox'));
await w.webContents.executeJavaScript('alert("hi")');
w.loadURL('file:///path/2');
let dialogWasShown = false;
dialog.showMessageBox = () => {
dialogWasShown = true;
return Promise.resolve({ response: 0, checkboxChecked: false });
};
await w.webContents.executeJavaScript('alert("hi")');
expect(dialogWasShown).to.be.true();
});
});
describe('disableDialogs web preference', () => {
const originalShowMessageBox = dialog.showMessageBox;
afterEach(() => {
dialog.showMessageBox = originalShowMessageBox;
if (protocol.isProtocolHandled('https')) protocol.unhandle('https');
});
it('is respected', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { disableDialogs: true } });
w.loadURL('about:blank');
dialog.showMessageBox = () => Promise.reject(new Error('unexpected message box'));
await w.webContents.executeJavaScript('alert("hi")');
});
});
});
describe('window.history', () => {
describe('window.history.go(offset)', () => {
itremote('throws an exception when the argument cannot be converted to a string', () => {
expect(() => {
(window.history.go as any)({ toString: null });
}).to.throw('Cannot convert object to primitive value');
});
});
});
describe('console functions', () => {
itremote('should exist', () => {
expect(console.log, 'log').to.be.a('function');
expect(console.error, 'error').to.be.a('function');
expect(console.warn, 'warn').to.be.a('function');
expect(console.info, 'info').to.be.a('function');
expect(console.debug, 'debug').to.be.a('function');
expect(console.trace, 'trace').to.be.a('function');
expect(console.time, 'time').to.be.a('function');
expect(console.timeEnd, 'timeEnd').to.be.a('function');
});
});
// FIXME(nornagon): this is broken on CI, it triggers:
// [FATAL:speech_synthesis.mojom-shared.h(237)] The outgoing message will
// trigger VALIDATION_ERROR_UNEXPECTED_NULL_POINTER at the receiving side
// (null text in SpeechSynthesisUtterance struct).
describe('SpeechSynthesis', () => {
itremote('should emit lifecycle events', async () => {
const sentence = `long sentence which will take at least a few seconds to
utter so that it's possible to pause and resume before the end`;
const utter = new SpeechSynthesisUtterance(sentence);
// Create a dummy utterance so that speech synthesis state
// is initialized for later calls.
speechSynthesis.speak(new SpeechSynthesisUtterance());
speechSynthesis.cancel();
speechSynthesis.speak(utter);
// paused state after speak()
expect(speechSynthesis.paused).to.be.false();
await new Promise((resolve) => { utter.onstart = resolve; });
// paused state after start event
expect(speechSynthesis.paused).to.be.false();
speechSynthesis.pause();
// paused state changes async, right before the pause event
expect(speechSynthesis.paused).to.be.false();
await new Promise((resolve) => { utter.onpause = resolve; });
expect(speechSynthesis.paused).to.be.true();
speechSynthesis.resume();
await new Promise((resolve) => { utter.onresume = resolve; });
// paused state after resume event
expect(speechSynthesis.paused).to.be.false();
await new Promise((resolve) => { utter.onend = resolve; });
});
});
});
describe('font fallback', () => {
async function getRenderedFonts (html: string) {
const w = new BrowserWindow({ show: false });
try {
await w.loadURL(`data:text/html,${html}`);
w.webContents.debugger.attach();
const sendCommand = (method: string, commandParams?: any) => w.webContents.debugger.sendCommand(method, commandParams);
const { nodeId } = (await sendCommand('DOM.getDocument')).root.children[0];
await sendCommand('CSS.enable');
const { fonts } = await sendCommand('CSS.getPlatformFontsForNode', { nodeId });
return fonts;
} finally {
w.close();
}
}
it('should use Helvetica for sans-serif on Mac, and Arial on Windows and Linux', async () => {
const html = '<body style="font-family: sans-serif">test</body>';
const fonts = await getRenderedFonts(html);
expect(fonts).to.be.an('array');
expect(fonts).to.have.length(1);
if (process.platform === 'win32') {
expect(fonts[0].familyName).to.equal('Arial');
} else if (process.platform === 'darwin') {
expect(fonts[0].familyName).to.equal('Helvetica');
} else if (process.platform === 'linux') {
expect(fonts[0].familyName).to.equal('DejaVu Sans');
} // I think this depends on the distro? We don't specify a default.
});
ifit(process.platform !== 'linux')('should fall back to Japanese font for sans-serif Japanese script', async function () {
const html = `
<html lang="ja-JP">
<head>
<meta charset="utf-8" />
</head>
<body style="font-family: sans-serif">test </body>
</html>
`;
const fonts = await getRenderedFonts(html);
expect(fonts).to.be.an('array');
expect(fonts).to.have.length(1);
2019-11-01 20:37:02 +00:00
if (process.platform === 'win32') { expect(fonts[0].familyName).to.be.oneOf(['Meiryo', 'Yu Gothic']); } else if (process.platform === 'darwin') { expect(fonts[0].familyName).to.equal('Hiragino Kaku Gothic ProN'); }
});
2019-11-01 20:37:02 +00:00
});
describe('iframe using HTML fullscreen API while window is OS-fullscreened', () => {
const fullscreenChildHtml = fs.promises.readFile(
path.join(fixturesPath, 'pages', 'fullscreen-oopif.html')
);
let w: BrowserWindow;
let server: http.Server;
let crossSiteUrl: string;
beforeEach(async () => {
server = http.createServer(async (_req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write(await fullscreenChildHtml);
res.end();
});
const serverUrl = (await listen(server)).url;
crossSiteUrl = serverUrl.replace('127.0.0.1', 'localhost');
w = new BrowserWindow({
show: true,
fullscreen: true,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInSubFrames: true,
contextIsolation: false
}
});
});
afterEach(async () => {
await closeAllWindows();
(w as any) = null;
server.close();
});
ifit(process.platform !== 'darwin')('can fullscreen from out-of-process iframes (non-macOS)', async () => {
const fullscreenChange = once(ipcMain, 'fullscreenChange');
const html =
`<iframe style="width: 0" frameborder=0 src="${crossSiteUrl}" allowfullscreen></iframe>`;
w.loadURL(`data:text/html,${html}`);
await fullscreenChange;
const fullscreenWidth = await w.webContents.executeJavaScript(
"document.querySelector('iframe').offsetWidth"
);
expect(fullscreenWidth > 0).to.be.true();
await w.webContents.executeJavaScript(
"document.querySelector('iframe').contentWindow.postMessage('exitFullscreen', '*')"
);
await setTimeout(500);
const width = await w.webContents.executeJavaScript(
"document.querySelector('iframe').offsetWidth"
);
expect(width).to.equal(0);
});
ifit(process.platform === 'darwin')('can fullscreen from out-of-process iframes (macOS)', async () => {
await once(w, 'enter-full-screen');
const fullscreenChange = once(ipcMain, 'fullscreenChange');
const html =
`<iframe style="width: 0" frameborder=0 src="${crossSiteUrl}" allowfullscreen></iframe>`;
w.loadURL(`data:text/html,${html}`);
await fullscreenChange;
const fullscreenWidth = await w.webContents.executeJavaScript(
"document.querySelector('iframe').offsetWidth"
);
expect(fullscreenWidth > 0).to.be.true();
await w.webContents.executeJavaScript(
"document.querySelector('iframe').contentWindow.postMessage('exitFullscreen', '*')"
);
await once(w.webContents, 'leave-html-full-screen');
const width = await w.webContents.executeJavaScript(
"document.querySelector('iframe').offsetWidth"
);
expect(width).to.equal(0);
w.setFullScreen(false);
await once(w, 'leave-full-screen');
});
chore: bump chromium to 100.0.4894.0 (main) (#32852) * chore: bump chromium in DEPS to 100.0.4880.0 * resolve conflicts * chore: update patches * fix patch * PIP20: add a new DocumentOverlayWindowViews subtype https://chromium-review.googlesource.com/c/chromium/src/+/3252789 * Clean up PictureInPictureWindowManager::EnterPictureInPicture() https://chromium-review.googlesource.com/c/chromium/src/+/3424145 * Remove StoragePartitionId. https://chromium-review.googlesource.com/c/chromium/src/+/2811120 * Remove FLoC code https://chromium-review.googlesource.com/c/chromium/src/+/3424359 * media: Make AddSupportedKeySystems() Async https://chromium-review.googlesource.com/c/chromium/src/+/3430502 * [Extensions] Move some l10n file util methods to //extensions/browser https://chromium-review.googlesource.com/c/chromium/src/+/3408192 * chore: IWYU * Reland "webhid: Grant permissions for policy-allowed devices" https://chromium-review.googlesource.com/c/chromium/src/+/3444147 * Migrate base::Value::GetList() to base::Value::GetListDeprecated(): 2/N. https://chromium-review.googlesource.com/c/chromium/src/+/3435727 https://chromium-review.googlesource.com/c/chromium/src/+/3440910 https://chromium-review.googlesource.com/c/chromium/src/+/3440088 * [text blink period] Cache blink period instead of fetching from defaults https://chromium-review.googlesource.com/c/chromium/src/+/3419059 * chore: update picture-in-picture.patch https://chromium-review.googlesource.com/c/chromium/src/+/3252789 * ci: update to Xcode 13.2.1 https://chromium-review.googlesource.com/c/chromium/src/+/3437552 * chore: bump chromium in DEPS to 100.0.4882.1 * chore: update patches * chore: bump chromium in DEPS to 100.0.4884.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4886.0 * chore: update patches * Refactor DownloadManager to use StoragePartitionConfig https://chromium-review.googlesource.com/c/chromium/src/+/3222011 * Remove ToWebInputElement() in favor of new WebNode::DynamicTo<> helpers. https://chromium-review.googlesource.com/c/chromium/src/+/3433852 * refactor: autofill to use the color pipeline https://bugs.chromium.org/p/chromium/issues/detail?id=1249558 https://bugs.chromium.org/p/chromium/issues/detail?id=1003612 * [ProcessSingleton] Add many more trace events to cover all scenarios https://chromium-review.googlesource.com/c/chromium/src/+/3429325 * fixup! PIP20: add a new DocumentOverlayWindowViews subtype * chore: bump chromium in DEPS to 100.0.4888.0 * chore: update patches * chore: update picture-in-picture.patch * fixup! refactor: autofill to use the color pipeline * ci: fixup fix sync (cherry picked from commit c1e3e395465739bce5ca8e1c5ec1f5bd72b99ebd) * chore: bump chromium in DEPS to 100.0.4889.0 * chore: update patches * chore: fix feat_add_data_transfer_to_requestsingleinstancelock.patch * fixup! PIP20: add a new DocumentOverlayWindowViews subtype * Remove remaining NativeTheme::GetSystemColor() machinery. https://chromium-review.googlesource.com/c/chromium/src/+/3421719 * ci: fetch proper esbuild for macos * ci: fixup fetch proper esbuild for macos * fix: failing Node.js test on outdated CurrentValueSerializerFormatVersion * chore: bump chromium in DEPS to 100.0.4892.0 * 3460365: Set V8 fatal error callbacks during Isolate initialization https://chromium-review.googlesource.com/c/chromium/src/+/3460365 * 3454343: PIP20: use permanent top controls https://chromium-review.googlesource.com/c/chromium/src/+/3454343 * 3465574: Move most of GTK color mixers to ui/color/. https://chromium-review.googlesource.com/c/chromium/src/+/3465574 * chore: fixup patch indices * 3445327: [locales] Remove locales reference https://chromium-review.googlesource.com/c/chromium/src/+/3445327 * 3456548: [DBB][#7] Blue border falls back to all tab if cropped-to zero pixels https://chromium-review.googlesource.com/c/chromium/src/+/3456548 * 3441196: Convert GuestView's remaining legacy IPC messages to Mojo https://chromium-review.googlesource.com/c/chromium/src/+/3441196 * 3455491: Don't include run_loop.h in thread_task_runner_handle.h https://chromium-review.googlesource.com/c/chromium/src/+/3455491 * fixup! 3454343: PIP20: use permanent top controls * 3442501: Add missing includes of //base/observer_list.h https://chromium-review.googlesource.com/c/chromium/src/+/3442501 * 3437552: mac: Deploy a new hermetic build of Xcode 13.2.1 13C100 https://chromium-review.googlesource.com/c/chromium/src/+/3437552 * chore: bump chromium in DEPS to 100.0.4894.0 * fixup! 3460365: Set V8 fatal error callbacks during Isolate initialization * chore: update patches * 3425231: Use DnsOverHttpsConfig where appropriate https://chromium-review.googlesource.com/c/chromium/src/+/3425231 * test: disable test-heapsnapshot-near-heap-limit-worker.js As a result of CLs linked in https://bugs.chromium.org/p/v8/issues/detail?id=12503, heap snapshotting near the heap limit DCHECKS in Node.js specs. This will likely require a larger refactor in Node.js so i've disabled the test for now and opened an upstream issue on node-v8 issue at https://github.com/nodejs/node-v8/issues/218. * Port all usage of NativeTheme color IDs to color pipeline https://bugs.chromium.org/p/chromium/issues/detail?id=1249558 * chore: update patches after rebase * ci: use gen2 machine for more disk space * ci: don't try to make root volume writeable * ci: use older xcode/macos for tests * fix: html fullscreen transitions stacking (cherry picked from commit 5e10965cdd7b2a024def5fc568912cefd0f05b44) * ci: speed up woa testing (cherry picked from commit 75c33c48b032137794f5734348a9ee3daa60d9de) (cherry picked from commit e81996234029669663bf0daaababd34684dcbb17) * ci: disable flaky tests on WOA * ci: run remote tests separately to isolate issue there * tests: disable node test parallel/test-worker-debug for now * revert: fix: html fullscreen transitions stacking * tests: disable flaky test on macOS arm64 * fixup circleci config so build tools can find xcode version * make sure the workspace is clean before job runs (cherry picked from commit 75f713c9748ac1a356846c39f268886130554fd6) * tests: disable flaky test on Linux * ci: debug why windows i32 is crashing * Revert "ci: debug why windows i32 is crashing" This reverts commit 4c4bba87ea76f16ef3b304dadff59ad4d366f60f. Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-02-25 18:17:35 +00:00
// TODO(jkleinsc) fix this flaky test on WOA
ifit(process.platform !== 'win32' || process.arch !== 'arm64')('can fullscreen from in-process iframes', async () => {
if (process.platform === 'darwin') await once(w, 'enter-full-screen');
const fullscreenChange = once(ipcMain, 'fullscreenChange');
w.loadFile(path.join(fixturesPath, 'pages', 'fullscreen-ipif.html'));
await fullscreenChange;
const fullscreenWidth = await w.webContents.executeJavaScript(
"document.querySelector('iframe').offsetWidth"
);
expect(fullscreenWidth > 0).to.true();
2020-03-20 20:28:31 +00:00
await w.webContents.executeJavaScript('document.exitFullscreen()');
const width = await w.webContents.executeJavaScript(
"document.querySelector('iframe').offsetWidth"
);
expect(width).to.equal(0);
});
});
describe('navigator.serial', () => {
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow({
show: false
});
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
});
const getPorts: any = () => {
return w.webContents.executeJavaScript(`
navigator.serial.requestPort().then(port => port.toString()).catch(err => err.toString());
`, true);
};
chore: bump chromium to 109.0.5382.0 (main) (#36057) * chore: bump chromium in DEPS to 109.0.5364.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5366.0 * chore: update patches * i3940364: Change PermissionType::WINDOW_PLACEMENT to WINDOW_MANAGEMENT https://chromium-review.googlesource.com/c/chromium/src/+/3940364 * 3866812: Change content::PluginList to only run on the UI thread. https://chromium-review.googlesource.com/c/chromium/src/+/3866812 * chore: bump chromium in DEPS to 109.0.5368.0 * [cleanup] Replace enable_basic_printing with enable_printing https://chromium-review.googlesource.com/c/chromium/src/+/3957357 * chore: update patches * 3956318: Desktop PWAs: Retire kWebAppWindowControlsOverlay flag https://chromium-review.googlesource.com/c/chromium/src/+/3956318 * fixup! Change content::PluginList to only run on the UI thread. (cherry picked from commit 7b5ec87d4ff5d34e7493b4fb46c40c0afeef2005) Co-Authored-By: Robo <hop2deep@gmail.com> * chore: bump chromium in DEPS to 109.0.5370.0 * 3956299: Quota: Cleanup QuotaPermissionContext https://chromium-review.googlesource.com/c/chromium/src/+/3956299 * chore: update patches * 3803867: Add Mojo interface to parse XML for OOP printer capabilities https://chromium-review.googlesource.com/c/chromium/src/+/3803867 * fixup: Add Mojo interface to parse XML for OOP printer capabilities * chore: bump chromium in DEPS to 109.0.5372.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5374.0 * chore: bump chromium in DEPS to 109.0.5376.0 * chore: bump chromium in DEPS to 109.0.5378.0 * chore: update patches * Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * 3955976: serial: Create DOMException with V8ThrowDOMException https://chromium-review.googlesource.com/c/chromium/src/+/3955976 * 3758405: Append trailer data to serialized messages. https://chromium-review.googlesource.com/c/chromium/src/+/3758405 * chore: revert clang roll This patch reverts https://chromium-review.googlesource.com/c/chromium/src/+/3967491 because that roll breaks the WOA build: https://crbug.com/1377819 * chore: update patches * chore: bump chromium in DEPS to 109.0.5380.0 * chore: update patches * 3859750: [linux/wayland] Added plumbing for the state of tiled edges. https://chromium-review.googlesource.com/c/chromium/src/+/3859750 Also 3970920: [linux/wayland] Fixed the tiled edges for the GTK frame. https://chromium-review.googlesource.com/c/chromium/src/+/3970920 * chore: bump chromium in DEPS to 109.0.5382.0 * chore: update patches * chore: revert Use accessibility.pkey when setting page access. https://chromium-review.googlesource.com/c/chromium/src/+/3949281 breaks our Linux builds run under Docker. This patch should be removed once https://chromium-review.googlesource.com/c/chromium/src/+/3949284 is merged. * 3976312: Roll clang llvmorg-16-init-8189-g97196a2d-2 : llvmorg-16-init-8697-g60809cd2-1 https://chromium-review.googlesource.com/c/chromium/src/+/3976312 * 3967841: [heap] Remove AllocationSpace::MAP_SPACE enum constant https://chromium-review.googlesource.com/c/v8/v8/+/3967841 * 3956131: [cleanup] Remove flag for Wasm threads & atomics https://chromium-review.googlesource.com/c/v8/v8/+/3956131 * chore: update docs for Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * test: fixup HID test for ARM CI Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
2022-10-27 16:37:04 +00:00
const notFoundError = 'NotFoundError: Failed to execute \'requestPort\' on \'Serial\': No port selected by the user.';
after(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionCheckHandler(null);
session.defaultSession.removeAllListeners('select-serial-port');
});
it('does not return a port if select-serial-port event is not defined', async () => {
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const port = await getPorts();
chore: bump chromium to 109.0.5382.0 (main) (#36057) * chore: bump chromium in DEPS to 109.0.5364.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5366.0 * chore: update patches * i3940364: Change PermissionType::WINDOW_PLACEMENT to WINDOW_MANAGEMENT https://chromium-review.googlesource.com/c/chromium/src/+/3940364 * 3866812: Change content::PluginList to only run on the UI thread. https://chromium-review.googlesource.com/c/chromium/src/+/3866812 * chore: bump chromium in DEPS to 109.0.5368.0 * [cleanup] Replace enable_basic_printing with enable_printing https://chromium-review.googlesource.com/c/chromium/src/+/3957357 * chore: update patches * 3956318: Desktop PWAs: Retire kWebAppWindowControlsOverlay flag https://chromium-review.googlesource.com/c/chromium/src/+/3956318 * fixup! Change content::PluginList to only run on the UI thread. (cherry picked from commit 7b5ec87d4ff5d34e7493b4fb46c40c0afeef2005) Co-Authored-By: Robo <hop2deep@gmail.com> * chore: bump chromium in DEPS to 109.0.5370.0 * 3956299: Quota: Cleanup QuotaPermissionContext https://chromium-review.googlesource.com/c/chromium/src/+/3956299 * chore: update patches * 3803867: Add Mojo interface to parse XML for OOP printer capabilities https://chromium-review.googlesource.com/c/chromium/src/+/3803867 * fixup: Add Mojo interface to parse XML for OOP printer capabilities * chore: bump chromium in DEPS to 109.0.5372.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5374.0 * chore: bump chromium in DEPS to 109.0.5376.0 * chore: bump chromium in DEPS to 109.0.5378.0 * chore: update patches * Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * 3955976: serial: Create DOMException with V8ThrowDOMException https://chromium-review.googlesource.com/c/chromium/src/+/3955976 * 3758405: Append trailer data to serialized messages. https://chromium-review.googlesource.com/c/chromium/src/+/3758405 * chore: revert clang roll This patch reverts https://chromium-review.googlesource.com/c/chromium/src/+/3967491 because that roll breaks the WOA build: https://crbug.com/1377819 * chore: update patches * chore: bump chromium in DEPS to 109.0.5380.0 * chore: update patches * 3859750: [linux/wayland] Added plumbing for the state of tiled edges. https://chromium-review.googlesource.com/c/chromium/src/+/3859750 Also 3970920: [linux/wayland] Fixed the tiled edges for the GTK frame. https://chromium-review.googlesource.com/c/chromium/src/+/3970920 * chore: bump chromium in DEPS to 109.0.5382.0 * chore: update patches * chore: revert Use accessibility.pkey when setting page access. https://chromium-review.googlesource.com/c/chromium/src/+/3949281 breaks our Linux builds run under Docker. This patch should be removed once https://chromium-review.googlesource.com/c/chromium/src/+/3949284 is merged. * 3976312: Roll clang llvmorg-16-init-8189-g97196a2d-2 : llvmorg-16-init-8697-g60809cd2-1 https://chromium-review.googlesource.com/c/chromium/src/+/3976312 * 3967841: [heap] Remove AllocationSpace::MAP_SPACE enum constant https://chromium-review.googlesource.com/c/v8/v8/+/3967841 * 3956131: [cleanup] Remove flag for Wasm threads & atomics https://chromium-review.googlesource.com/c/v8/v8/+/3956131 * chore: update docs for Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * test: fixup HID test for ARM CI Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
2022-10-27 16:37:04 +00:00
expect(port).to.equal(notFoundError);
});
it('does not return a port when permission denied', async () => {
w.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
callback(portList[0].portId);
});
session.defaultSession.setPermissionCheckHandler(() => false);
const port = await getPorts();
chore: bump chromium to 109.0.5382.0 (main) (#36057) * chore: bump chromium in DEPS to 109.0.5364.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5366.0 * chore: update patches * i3940364: Change PermissionType::WINDOW_PLACEMENT to WINDOW_MANAGEMENT https://chromium-review.googlesource.com/c/chromium/src/+/3940364 * 3866812: Change content::PluginList to only run on the UI thread. https://chromium-review.googlesource.com/c/chromium/src/+/3866812 * chore: bump chromium in DEPS to 109.0.5368.0 * [cleanup] Replace enable_basic_printing with enable_printing https://chromium-review.googlesource.com/c/chromium/src/+/3957357 * chore: update patches * 3956318: Desktop PWAs: Retire kWebAppWindowControlsOverlay flag https://chromium-review.googlesource.com/c/chromium/src/+/3956318 * fixup! Change content::PluginList to only run on the UI thread. (cherry picked from commit 7b5ec87d4ff5d34e7493b4fb46c40c0afeef2005) Co-Authored-By: Robo <hop2deep@gmail.com> * chore: bump chromium in DEPS to 109.0.5370.0 * 3956299: Quota: Cleanup QuotaPermissionContext https://chromium-review.googlesource.com/c/chromium/src/+/3956299 * chore: update patches * 3803867: Add Mojo interface to parse XML for OOP printer capabilities https://chromium-review.googlesource.com/c/chromium/src/+/3803867 * fixup: Add Mojo interface to parse XML for OOP printer capabilities * chore: bump chromium in DEPS to 109.0.5372.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5374.0 * chore: bump chromium in DEPS to 109.0.5376.0 * chore: bump chromium in DEPS to 109.0.5378.0 * chore: update patches * Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * 3955976: serial: Create DOMException with V8ThrowDOMException https://chromium-review.googlesource.com/c/chromium/src/+/3955976 * 3758405: Append trailer data to serialized messages. https://chromium-review.googlesource.com/c/chromium/src/+/3758405 * chore: revert clang roll This patch reverts https://chromium-review.googlesource.com/c/chromium/src/+/3967491 because that roll breaks the WOA build: https://crbug.com/1377819 * chore: update patches * chore: bump chromium in DEPS to 109.0.5380.0 * chore: update patches * 3859750: [linux/wayland] Added plumbing for the state of tiled edges. https://chromium-review.googlesource.com/c/chromium/src/+/3859750 Also 3970920: [linux/wayland] Fixed the tiled edges for the GTK frame. https://chromium-review.googlesource.com/c/chromium/src/+/3970920 * chore: bump chromium in DEPS to 109.0.5382.0 * chore: update patches * chore: revert Use accessibility.pkey when setting page access. https://chromium-review.googlesource.com/c/chromium/src/+/3949281 breaks our Linux builds run under Docker. This patch should be removed once https://chromium-review.googlesource.com/c/chromium/src/+/3949284 is merged. * 3976312: Roll clang llvmorg-16-init-8189-g97196a2d-2 : llvmorg-16-init-8697-g60809cd2-1 https://chromium-review.googlesource.com/c/chromium/src/+/3976312 * 3967841: [heap] Remove AllocationSpace::MAP_SPACE enum constant https://chromium-review.googlesource.com/c/v8/v8/+/3967841 * 3956131: [cleanup] Remove flag for Wasm threads & atomics https://chromium-review.googlesource.com/c/v8/v8/+/3956131 * chore: update docs for Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * test: fixup HID test for ARM CI Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
2022-10-27 16:37:04 +00:00
expect(port).to.equal(notFoundError);
});
it('does not crash when select-serial-port is called with an invalid port', async () => {
w.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
callback('i-do-not-exist');
});
const port = await getPorts();
chore: bump chromium to 109.0.5382.0 (main) (#36057) * chore: bump chromium in DEPS to 109.0.5364.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5366.0 * chore: update patches * i3940364: Change PermissionType::WINDOW_PLACEMENT to WINDOW_MANAGEMENT https://chromium-review.googlesource.com/c/chromium/src/+/3940364 * 3866812: Change content::PluginList to only run on the UI thread. https://chromium-review.googlesource.com/c/chromium/src/+/3866812 * chore: bump chromium in DEPS to 109.0.5368.0 * [cleanup] Replace enable_basic_printing with enable_printing https://chromium-review.googlesource.com/c/chromium/src/+/3957357 * chore: update patches * 3956318: Desktop PWAs: Retire kWebAppWindowControlsOverlay flag https://chromium-review.googlesource.com/c/chromium/src/+/3956318 * fixup! Change content::PluginList to only run on the UI thread. (cherry picked from commit 7b5ec87d4ff5d34e7493b4fb46c40c0afeef2005) Co-Authored-By: Robo <hop2deep@gmail.com> * chore: bump chromium in DEPS to 109.0.5370.0 * 3956299: Quota: Cleanup QuotaPermissionContext https://chromium-review.googlesource.com/c/chromium/src/+/3956299 * chore: update patches * 3803867: Add Mojo interface to parse XML for OOP printer capabilities https://chromium-review.googlesource.com/c/chromium/src/+/3803867 * fixup: Add Mojo interface to parse XML for OOP printer capabilities * chore: bump chromium in DEPS to 109.0.5372.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5374.0 * chore: bump chromium in DEPS to 109.0.5376.0 * chore: bump chromium in DEPS to 109.0.5378.0 * chore: update patches * Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * 3955976: serial: Create DOMException with V8ThrowDOMException https://chromium-review.googlesource.com/c/chromium/src/+/3955976 * 3758405: Append trailer data to serialized messages. https://chromium-review.googlesource.com/c/chromium/src/+/3758405 * chore: revert clang roll This patch reverts https://chromium-review.googlesource.com/c/chromium/src/+/3967491 because that roll breaks the WOA build: https://crbug.com/1377819 * chore: update patches * chore: bump chromium in DEPS to 109.0.5380.0 * chore: update patches * 3859750: [linux/wayland] Added plumbing for the state of tiled edges. https://chromium-review.googlesource.com/c/chromium/src/+/3859750 Also 3970920: [linux/wayland] Fixed the tiled edges for the GTK frame. https://chromium-review.googlesource.com/c/chromium/src/+/3970920 * chore: bump chromium in DEPS to 109.0.5382.0 * chore: update patches * chore: revert Use accessibility.pkey when setting page access. https://chromium-review.googlesource.com/c/chromium/src/+/3949281 breaks our Linux builds run under Docker. This patch should be removed once https://chromium-review.googlesource.com/c/chromium/src/+/3949284 is merged. * 3976312: Roll clang llvmorg-16-init-8189-g97196a2d-2 : llvmorg-16-init-8697-g60809cd2-1 https://chromium-review.googlesource.com/c/chromium/src/+/3976312 * 3967841: [heap] Remove AllocationSpace::MAP_SPACE enum constant https://chromium-review.googlesource.com/c/v8/v8/+/3967841 * 3956131: [cleanup] Remove flag for Wasm threads & atomics https://chromium-review.googlesource.com/c/v8/v8/+/3956131 * chore: update docs for Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * test: fixup HID test for ARM CI Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
2022-10-27 16:37:04 +00:00
expect(port).to.equal(notFoundError);
});
it('returns a port when select-serial-port event is defined', async () => {
let havePorts = false;
w.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
if (portList.length > 0) {
havePorts = true;
callback(portList[0].portId);
} else {
callback('');
}
});
const port = await getPorts();
if (havePorts) {
expect(port).to.equal('[object SerialPort]');
} else {
chore: bump chromium to 109.0.5382.0 (main) (#36057) * chore: bump chromium in DEPS to 109.0.5364.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5366.0 * chore: update patches * i3940364: Change PermissionType::WINDOW_PLACEMENT to WINDOW_MANAGEMENT https://chromium-review.googlesource.com/c/chromium/src/+/3940364 * 3866812: Change content::PluginList to only run on the UI thread. https://chromium-review.googlesource.com/c/chromium/src/+/3866812 * chore: bump chromium in DEPS to 109.0.5368.0 * [cleanup] Replace enable_basic_printing with enable_printing https://chromium-review.googlesource.com/c/chromium/src/+/3957357 * chore: update patches * 3956318: Desktop PWAs: Retire kWebAppWindowControlsOverlay flag https://chromium-review.googlesource.com/c/chromium/src/+/3956318 * fixup! Change content::PluginList to only run on the UI thread. (cherry picked from commit 7b5ec87d4ff5d34e7493b4fb46c40c0afeef2005) Co-Authored-By: Robo <hop2deep@gmail.com> * chore: bump chromium in DEPS to 109.0.5370.0 * 3956299: Quota: Cleanup QuotaPermissionContext https://chromium-review.googlesource.com/c/chromium/src/+/3956299 * chore: update patches * 3803867: Add Mojo interface to parse XML for OOP printer capabilities https://chromium-review.googlesource.com/c/chromium/src/+/3803867 * fixup: Add Mojo interface to parse XML for OOP printer capabilities * chore: bump chromium in DEPS to 109.0.5372.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5374.0 * chore: bump chromium in DEPS to 109.0.5376.0 * chore: bump chromium in DEPS to 109.0.5378.0 * chore: update patches * Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * 3955976: serial: Create DOMException with V8ThrowDOMException https://chromium-review.googlesource.com/c/chromium/src/+/3955976 * 3758405: Append trailer data to serialized messages. https://chromium-review.googlesource.com/c/chromium/src/+/3758405 * chore: revert clang roll This patch reverts https://chromium-review.googlesource.com/c/chromium/src/+/3967491 because that roll breaks the WOA build: https://crbug.com/1377819 * chore: update patches * chore: bump chromium in DEPS to 109.0.5380.0 * chore: update patches * 3859750: [linux/wayland] Added plumbing for the state of tiled edges. https://chromium-review.googlesource.com/c/chromium/src/+/3859750 Also 3970920: [linux/wayland] Fixed the tiled edges for the GTK frame. https://chromium-review.googlesource.com/c/chromium/src/+/3970920 * chore: bump chromium in DEPS to 109.0.5382.0 * chore: update patches * chore: revert Use accessibility.pkey when setting page access. https://chromium-review.googlesource.com/c/chromium/src/+/3949281 breaks our Linux builds run under Docker. This patch should be removed once https://chromium-review.googlesource.com/c/chromium/src/+/3949284 is merged. * 3976312: Roll clang llvmorg-16-init-8189-g97196a2d-2 : llvmorg-16-init-8697-g60809cd2-1 https://chromium-review.googlesource.com/c/chromium/src/+/3976312 * 3967841: [heap] Remove AllocationSpace::MAP_SPACE enum constant https://chromium-review.googlesource.com/c/v8/v8/+/3967841 * 3956131: [cleanup] Remove flag for Wasm threads & atomics https://chromium-review.googlesource.com/c/v8/v8/+/3956131 * chore: update docs for Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * test: fixup HID test for ARM CI Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
2022-10-27 16:37:04 +00:00
expect(port).to.equal(notFoundError);
}
});
it('navigator.serial.getPorts() returns values', async () => {
let havePorts = false;
w.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
if (portList.length > 0) {
havePorts = true;
callback(portList[0].portId);
} else {
callback('');
}
});
await getPorts();
if (havePorts) {
const grantedPorts = await w.webContents.executeJavaScript('navigator.serial.getPorts()');
expect(grantedPorts).to.not.be.empty();
}
});
it('supports port.forget()', async () => {
let forgottenPortFromEvent = {};
let havePorts = false;
w.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
if (portList.length > 0) {
havePorts = true;
callback(portList[0].portId);
} else {
callback('');
}
});
w.webContents.session.on('serial-port-revoked', (event, details) => {
forgottenPortFromEvent = details.port;
});
await getPorts();
if (havePorts) {
const grantedPorts = await w.webContents.executeJavaScript('navigator.serial.getPorts()');
if (grantedPorts.length > 0) {
const forgottenPort = await w.webContents.executeJavaScript(`
navigator.serial.getPorts().then(async(ports) => {
const portInfo = await ports[0].getInfo();
await ports[0].forget();
if (portInfo.usbVendorId && portInfo.usbProductId) {
return {
vendorId: '' + portInfo.usbVendorId,
productId: '' + portInfo.usbProductId
}
} else {
return {};
}
})
`);
const grantedPorts2 = await w.webContents.executeJavaScript('navigator.serial.getPorts()');
expect(grantedPorts2.length).to.be.lessThan(grantedPorts.length);
if (forgottenPort.vendorId && forgottenPort.productId) {
expect(forgottenPortFromEvent).to.include(forgottenPort);
}
}
}
});
});
describe('window.getScreenDetails', () => {
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow({
show: false
});
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
});
after(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionRequestHandler(null);
});
const getScreenDetails: any = () => {
return w.webContents.executeJavaScript('window.getScreenDetails().then(data => data.screens).catch(err => err.message)', true);
};
it('returns screens when a PermissionRequestHandler is not defined', async () => {
const screens = await getScreenDetails();
expect(screens).to.not.equal('Read permission denied.');
});
it('returns an error when permission denied', async () => {
session.defaultSession.setPermissionRequestHandler((wc, permission, callback) => {
if (permission === 'window-management') {
callback(false);
} else {
callback(true);
}
});
const screens = await getScreenDetails();
expect(screens).to.equal('Permission denied.');
});
it('returns screens when permission is granted', async () => {
session.defaultSession.setPermissionRequestHandler((wc, permission, callback) => {
if (permission === 'window-management') {
callback(true);
} else {
callback(false);
}
});
const screens = await getScreenDetails();
expect(screens).to.not.equal('Permission denied.');
});
});
describe('navigator.clipboard.read', () => {
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow();
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
});
const readClipboard: any = () => {
return w.webContents.executeJavaScript(`
navigator.clipboard.read().then(clipboard => clipboard.toString()).catch(err => err.message);
`, true);
};
after(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionRequestHandler(null);
});
it('returns clipboard contents when a PermissionRequestHandler is not defined', async () => {
const clipboard = await readClipboard();
chore: bump chromium to 122.0.6261.6 (main) (#40949) * chore: bump chromium in DEPS to 122.0.6239.2 * chore: update patches * refactor: extensions replaced StringPiece with string_view Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5171926 * chore: bump chromium in DEPS to 122.0.6240.0 * chore: update patches * chore: bump chromium in DEPS to 122.0.6241.5 * chore: bump chromium in DEPS to 122.0.6245.0 * chore: bump chromium in DEPS to 122.0.6247.0 * chore: bump chromium in DEPS to 122.0.6249.0 * chore: bump chromium in DEPS to 122.0.6251.0 * 5192010: Rename {absl => std}::optional in //chrome/ https://chromium-review.googlesource.com/c/chromium/src/+/5192010 * 5109767: CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * 5105227: [media_preview] Show requested device in permission bubble https://chromium-review.googlesource.com/c/chromium/src/+/5105227 * chore: bump chromium in DEPS to 122.0.6253.0 * chore: update patches * 5180720: Polish tiled browser window UI on Linux | https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * chore: update patches * chore: bump chromium in DEPS to 122.0.6255.0 * chore: update patches * 5186276: [autopip] Make "allow once" per navigation | https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: bump chromium in DEPS to 122.0.6257.0 * chore: bump chromium in DEPS to 122.0.6259.0 * chore: update patches * 5190661: Automated T* -> raw_ptr<T> rewrite "refresh" | https://chromium-review.googlesource.com/c/chromium/src/+/5190661 * 5206106: Make sure RenderFrameHosts are active when printing | https://chromium-review.googlesource.com/c/chromium/src/+/5206106 * 5202674: Reland "Automated T* -> raw_ptr<T> rewrite 'refresh'" https://chromium-review.googlesource.com/c/chromium/src/+/5202674 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * fixup 5206106: Make sure RenderFrameHosts are active when printing * Make legacy ToV8() helpers private to ScriptPromiseResolver, their only user https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: update patches after rebase * chore: bump chromium in DEPS to 122.0.6260.0 * 5191363: Mark LOG(FATAL) [[noreturn]] https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * fixup Make legacy ToV8() helpers private to ScriptPromiseResolver https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * chore: update patches * chore: bump chromium in DEPS to 122.0.6261.0 * chore: update patches * chore: restore patch that was mistakenly removed * 5181931: Improve LoginHandler (Part 9 / N) https://chromium-review.googlesource.com/c/chromium/src/+/5181931 * Dispatch SiteInstanceGotProcess() only when both process and site are set. https://chromium-review.googlesource.com/c/chromium/src/+/5142354 * 5171446: [AsyncSB] Pass navigation_id into CreateURLLoaderThrottles https://chromium-review.googlesource.com/c/chromium/src/+/5171446 * 5213708: Move DownloadTargetInfo into components/download https://chromium-review.googlesource.com/c/chromium/src/+/5213708 * extensions: Add a loader for Controlled Frame embedder scripts https://chromium-review.googlesource.com/c/chromium/src/+/5202765 * [CSC][Zoom] Add initial_zoom_level to DisplayMediaInformation https://chromium-review.googlesource.com/c/chromium/src/+/5168626 * chore: bump chromium in DEPS to 123.0.6262.0 * chore: bump chromium in DEPS to 122.0.6261.6 * fix: suppress clang -Wimplicit-const-int-float-conversion * fixup 5191363: Mark LOG(FATAL) [[noreturn]] for Windows https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * 5167921: Remove Widget::IsTranslucentWindowOpacitySupported https://chromium-review.googlesource.com/c/chromium/src/+/5167921 Also 5148392: PinnedState: Support pinned state in PlatformWindowState | https://chromium-review.googlesource.com/c/chromium/src/+/5148392 * fixup: 5180720: Polish tiled browser window UI on Linux https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * 5170669: clipboard: Migrate DOMException constructors to RejectWith- https://chromium-review.googlesource.com/c/chromium/src/+/5170669 * 5178824: [Fullscreen] Record UKM data https://chromium-review.googlesource.com/c/chromium/src/+/5178824 * chore: update patches after rebase --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2024-01-25 17:46:30 +00:00
expect(clipboard).to.not.contain('Read permission denied.');
});
it('returns an error when permission denied', async () => {
session.defaultSession.setPermissionRequestHandler((wc, permission, callback) => {
if (permission === 'clipboard-read') {
callback(false);
} else {
callback(true);
}
});
const clipboard = await readClipboard();
chore: bump chromium to 122.0.6261.6 (main) (#40949) * chore: bump chromium in DEPS to 122.0.6239.2 * chore: update patches * refactor: extensions replaced StringPiece with string_view Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5171926 * chore: bump chromium in DEPS to 122.0.6240.0 * chore: update patches * chore: bump chromium in DEPS to 122.0.6241.5 * chore: bump chromium in DEPS to 122.0.6245.0 * chore: bump chromium in DEPS to 122.0.6247.0 * chore: bump chromium in DEPS to 122.0.6249.0 * chore: bump chromium in DEPS to 122.0.6251.0 * 5192010: Rename {absl => std}::optional in //chrome/ https://chromium-review.googlesource.com/c/chromium/src/+/5192010 * 5109767: CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * 5105227: [media_preview] Show requested device in permission bubble https://chromium-review.googlesource.com/c/chromium/src/+/5105227 * chore: bump chromium in DEPS to 122.0.6253.0 * chore: update patches * 5180720: Polish tiled browser window UI on Linux | https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * chore: update patches * chore: bump chromium in DEPS to 122.0.6255.0 * chore: update patches * 5186276: [autopip] Make "allow once" per navigation | https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: bump chromium in DEPS to 122.0.6257.0 * chore: bump chromium in DEPS to 122.0.6259.0 * chore: update patches * 5190661: Automated T* -> raw_ptr<T> rewrite "refresh" | https://chromium-review.googlesource.com/c/chromium/src/+/5190661 * 5206106: Make sure RenderFrameHosts are active when printing | https://chromium-review.googlesource.com/c/chromium/src/+/5206106 * 5202674: Reland "Automated T* -> raw_ptr<T> rewrite 'refresh'" https://chromium-review.googlesource.com/c/chromium/src/+/5202674 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * fixup 5206106: Make sure RenderFrameHosts are active when printing * Make legacy ToV8() helpers private to ScriptPromiseResolver, their only user https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: update patches after rebase * chore: bump chromium in DEPS to 122.0.6260.0 * 5191363: Mark LOG(FATAL) [[noreturn]] https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * fixup Make legacy ToV8() helpers private to ScriptPromiseResolver https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * chore: update patches * chore: bump chromium in DEPS to 122.0.6261.0 * chore: update patches * chore: restore patch that was mistakenly removed * 5181931: Improve LoginHandler (Part 9 / N) https://chromium-review.googlesource.com/c/chromium/src/+/5181931 * Dispatch SiteInstanceGotProcess() only when both process and site are set. https://chromium-review.googlesource.com/c/chromium/src/+/5142354 * 5171446: [AsyncSB] Pass navigation_id into CreateURLLoaderThrottles https://chromium-review.googlesource.com/c/chromium/src/+/5171446 * 5213708: Move DownloadTargetInfo into components/download https://chromium-review.googlesource.com/c/chromium/src/+/5213708 * extensions: Add a loader for Controlled Frame embedder scripts https://chromium-review.googlesource.com/c/chromium/src/+/5202765 * [CSC][Zoom] Add initial_zoom_level to DisplayMediaInformation https://chromium-review.googlesource.com/c/chromium/src/+/5168626 * chore: bump chromium in DEPS to 123.0.6262.0 * chore: bump chromium in DEPS to 122.0.6261.6 * fix: suppress clang -Wimplicit-const-int-float-conversion * fixup 5191363: Mark LOG(FATAL) [[noreturn]] for Windows https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * 5167921: Remove Widget::IsTranslucentWindowOpacitySupported https://chromium-review.googlesource.com/c/chromium/src/+/5167921 Also 5148392: PinnedState: Support pinned state in PlatformWindowState | https://chromium-review.googlesource.com/c/chromium/src/+/5148392 * fixup: 5180720: Polish tiled browser window UI on Linux https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * 5170669: clipboard: Migrate DOMException constructors to RejectWith- https://chromium-review.googlesource.com/c/chromium/src/+/5170669 * 5178824: [Fullscreen] Record UKM data https://chromium-review.googlesource.com/c/chromium/src/+/5178824 * chore: update patches after rebase --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2024-01-25 17:46:30 +00:00
expect(clipboard).to.contain('Read permission denied.');
});
it('returns clipboard contents when permission is granted', async () => {
session.defaultSession.setPermissionRequestHandler((wc, permission, callback) => {
if (permission === 'clipboard-read') {
callback(true);
} else {
callback(false);
}
});
const clipboard = await readClipboard();
chore: bump chromium to 122.0.6261.6 (main) (#40949) * chore: bump chromium in DEPS to 122.0.6239.2 * chore: update patches * refactor: extensions replaced StringPiece with string_view Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5171926 * chore: bump chromium in DEPS to 122.0.6240.0 * chore: update patches * chore: bump chromium in DEPS to 122.0.6241.5 * chore: bump chromium in DEPS to 122.0.6245.0 * chore: bump chromium in DEPS to 122.0.6247.0 * chore: bump chromium in DEPS to 122.0.6249.0 * chore: bump chromium in DEPS to 122.0.6251.0 * 5192010: Rename {absl => std}::optional in //chrome/ https://chromium-review.googlesource.com/c/chromium/src/+/5192010 * 5109767: CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * 5105227: [media_preview] Show requested device in permission bubble https://chromium-review.googlesource.com/c/chromium/src/+/5105227 * chore: bump chromium in DEPS to 122.0.6253.0 * chore: update patches * 5180720: Polish tiled browser window UI on Linux | https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * chore: update patches * chore: bump chromium in DEPS to 122.0.6255.0 * chore: update patches * 5186276: [autopip] Make "allow once" per navigation | https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: bump chromium in DEPS to 122.0.6257.0 * chore: bump chromium in DEPS to 122.0.6259.0 * chore: update patches * 5190661: Automated T* -> raw_ptr<T> rewrite "refresh" | https://chromium-review.googlesource.com/c/chromium/src/+/5190661 * 5206106: Make sure RenderFrameHosts are active when printing | https://chromium-review.googlesource.com/c/chromium/src/+/5206106 * 5202674: Reland "Automated T* -> raw_ptr<T> rewrite 'refresh'" https://chromium-review.googlesource.com/c/chromium/src/+/5202674 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * fixup 5206106: Make sure RenderFrameHosts are active when printing * Make legacy ToV8() helpers private to ScriptPromiseResolver, their only user https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: update patches after rebase * chore: bump chromium in DEPS to 122.0.6260.0 * 5191363: Mark LOG(FATAL) [[noreturn]] https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * fixup Make legacy ToV8() helpers private to ScriptPromiseResolver https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * chore: update patches * chore: bump chromium in DEPS to 122.0.6261.0 * chore: update patches * chore: restore patch that was mistakenly removed * 5181931: Improve LoginHandler (Part 9 / N) https://chromium-review.googlesource.com/c/chromium/src/+/5181931 * Dispatch SiteInstanceGotProcess() only when both process and site are set. https://chromium-review.googlesource.com/c/chromium/src/+/5142354 * 5171446: [AsyncSB] Pass navigation_id into CreateURLLoaderThrottles https://chromium-review.googlesource.com/c/chromium/src/+/5171446 * 5213708: Move DownloadTargetInfo into components/download https://chromium-review.googlesource.com/c/chromium/src/+/5213708 * extensions: Add a loader for Controlled Frame embedder scripts https://chromium-review.googlesource.com/c/chromium/src/+/5202765 * [CSC][Zoom] Add initial_zoom_level to DisplayMediaInformation https://chromium-review.googlesource.com/c/chromium/src/+/5168626 * chore: bump chromium in DEPS to 123.0.6262.0 * chore: bump chromium in DEPS to 122.0.6261.6 * fix: suppress clang -Wimplicit-const-int-float-conversion * fixup 5191363: Mark LOG(FATAL) [[noreturn]] for Windows https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * 5167921: Remove Widget::IsTranslucentWindowOpacitySupported https://chromium-review.googlesource.com/c/chromium/src/+/5167921 Also 5148392: PinnedState: Support pinned state in PlatformWindowState | https://chromium-review.googlesource.com/c/chromium/src/+/5148392 * fixup: 5180720: Polish tiled browser window UI on Linux https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * 5170669: clipboard: Migrate DOMException constructors to RejectWith- https://chromium-review.googlesource.com/c/chromium/src/+/5170669 * 5178824: [Fullscreen] Record UKM data https://chromium-review.googlesource.com/c/chromium/src/+/5178824 * chore: update patches after rebase --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2024-01-25 17:46:30 +00:00
expect(clipboard).to.not.contain('Read permission denied.');
});
});
describe('navigator.clipboard.write', () => {
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow();
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
});
const writeClipboard: any = () => {
return w.webContents.executeJavaScript(`
navigator.clipboard.writeText('Hello World!').catch(err => err.message);
`, true);
};
after(closeAllWindows);
afterEach(() => {
session.defaultSession.setPermissionRequestHandler(null);
});
it('returns clipboard contents when a PermissionRequestHandler is not defined', async () => {
const clipboard = await writeClipboard();
chore: bump chromium to 122.0.6261.6 (main) (#40949) * chore: bump chromium in DEPS to 122.0.6239.2 * chore: update patches * refactor: extensions replaced StringPiece with string_view Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5171926 * chore: bump chromium in DEPS to 122.0.6240.0 * chore: update patches * chore: bump chromium in DEPS to 122.0.6241.5 * chore: bump chromium in DEPS to 122.0.6245.0 * chore: bump chromium in DEPS to 122.0.6247.0 * chore: bump chromium in DEPS to 122.0.6249.0 * chore: bump chromium in DEPS to 122.0.6251.0 * 5192010: Rename {absl => std}::optional in //chrome/ https://chromium-review.googlesource.com/c/chromium/src/+/5192010 * 5109767: CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * 5105227: [media_preview] Show requested device in permission bubble https://chromium-review.googlesource.com/c/chromium/src/+/5105227 * chore: bump chromium in DEPS to 122.0.6253.0 * chore: update patches * 5180720: Polish tiled browser window UI on Linux | https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * chore: update patches * chore: bump chromium in DEPS to 122.0.6255.0 * chore: update patches * 5186276: [autopip] Make "allow once" per navigation | https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: bump chromium in DEPS to 122.0.6257.0 * chore: bump chromium in DEPS to 122.0.6259.0 * chore: update patches * 5190661: Automated T* -> raw_ptr<T> rewrite "refresh" | https://chromium-review.googlesource.com/c/chromium/src/+/5190661 * 5206106: Make sure RenderFrameHosts are active when printing | https://chromium-review.googlesource.com/c/chromium/src/+/5206106 * 5202674: Reland "Automated T* -> raw_ptr<T> rewrite 'refresh'" https://chromium-review.googlesource.com/c/chromium/src/+/5202674 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * fixup 5206106: Make sure RenderFrameHosts are active when printing * Make legacy ToV8() helpers private to ScriptPromiseResolver, their only user https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: update patches after rebase * chore: bump chromium in DEPS to 122.0.6260.0 * 5191363: Mark LOG(FATAL) [[noreturn]] https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * fixup Make legacy ToV8() helpers private to ScriptPromiseResolver https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * chore: update patches * chore: bump chromium in DEPS to 122.0.6261.0 * chore: update patches * chore: restore patch that was mistakenly removed * 5181931: Improve LoginHandler (Part 9 / N) https://chromium-review.googlesource.com/c/chromium/src/+/5181931 * Dispatch SiteInstanceGotProcess() only when both process and site are set. https://chromium-review.googlesource.com/c/chromium/src/+/5142354 * 5171446: [AsyncSB] Pass navigation_id into CreateURLLoaderThrottles https://chromium-review.googlesource.com/c/chromium/src/+/5171446 * 5213708: Move DownloadTargetInfo into components/download https://chromium-review.googlesource.com/c/chromium/src/+/5213708 * extensions: Add a loader for Controlled Frame embedder scripts https://chromium-review.googlesource.com/c/chromium/src/+/5202765 * [CSC][Zoom] Add initial_zoom_level to DisplayMediaInformation https://chromium-review.googlesource.com/c/chromium/src/+/5168626 * chore: bump chromium in DEPS to 123.0.6262.0 * chore: bump chromium in DEPS to 122.0.6261.6 * fix: suppress clang -Wimplicit-const-int-float-conversion * fixup 5191363: Mark LOG(FATAL) [[noreturn]] for Windows https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * 5167921: Remove Widget::IsTranslucentWindowOpacitySupported https://chromium-review.googlesource.com/c/chromium/src/+/5167921 Also 5148392: PinnedState: Support pinned state in PlatformWindowState | https://chromium-review.googlesource.com/c/chromium/src/+/5148392 * fixup: 5180720: Polish tiled browser window UI on Linux https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * 5170669: clipboard: Migrate DOMException constructors to RejectWith- https://chromium-review.googlesource.com/c/chromium/src/+/5170669 * 5178824: [Fullscreen] Record UKM data https://chromium-review.googlesource.com/c/chromium/src/+/5178824 * chore: update patches after rebase --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2024-01-25 17:46:30 +00:00
expect(clipboard).to.be.undefined();
});
it('returns an error when permission denied', async () => {
session.defaultSession.setPermissionRequestHandler((wc, permission, callback) => {
if (permission === 'clipboard-sanitized-write') {
callback(false);
} else {
callback(true);
}
});
const clipboard = await writeClipboard();
chore: bump chromium to 122.0.6261.6 (main) (#40949) * chore: bump chromium in DEPS to 122.0.6239.2 * chore: update patches * refactor: extensions replaced StringPiece with string_view Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5171926 * chore: bump chromium in DEPS to 122.0.6240.0 * chore: update patches * chore: bump chromium in DEPS to 122.0.6241.5 * chore: bump chromium in DEPS to 122.0.6245.0 * chore: bump chromium in DEPS to 122.0.6247.0 * chore: bump chromium in DEPS to 122.0.6249.0 * chore: bump chromium in DEPS to 122.0.6251.0 * 5192010: Rename {absl => std}::optional in //chrome/ https://chromium-review.googlesource.com/c/chromium/src/+/5192010 * 5109767: CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * 5105227: [media_preview] Show requested device in permission bubble https://chromium-review.googlesource.com/c/chromium/src/+/5105227 * chore: bump chromium in DEPS to 122.0.6253.0 * chore: update patches * 5180720: Polish tiled browser window UI on Linux | https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * chore: update patches * chore: bump chromium in DEPS to 122.0.6255.0 * chore: update patches * 5186276: [autopip] Make "allow once" per navigation | https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: bump chromium in DEPS to 122.0.6257.0 * chore: bump chromium in DEPS to 122.0.6259.0 * chore: update patches * 5190661: Automated T* -> raw_ptr<T> rewrite "refresh" | https://chromium-review.googlesource.com/c/chromium/src/+/5190661 * 5206106: Make sure RenderFrameHosts are active when printing | https://chromium-review.googlesource.com/c/chromium/src/+/5206106 * 5202674: Reland "Automated T* -> raw_ptr<T> rewrite 'refresh'" https://chromium-review.googlesource.com/c/chromium/src/+/5202674 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * fixup 5206106: Make sure RenderFrameHosts are active when printing * Make legacy ToV8() helpers private to ScriptPromiseResolver, their only user https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: update patches after rebase * chore: bump chromium in DEPS to 122.0.6260.0 * 5191363: Mark LOG(FATAL) [[noreturn]] https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * fixup Make legacy ToV8() helpers private to ScriptPromiseResolver https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * chore: update patches * chore: bump chromium in DEPS to 122.0.6261.0 * chore: update patches * chore: restore patch that was mistakenly removed * 5181931: Improve LoginHandler (Part 9 / N) https://chromium-review.googlesource.com/c/chromium/src/+/5181931 * Dispatch SiteInstanceGotProcess() only when both process and site are set. https://chromium-review.googlesource.com/c/chromium/src/+/5142354 * 5171446: [AsyncSB] Pass navigation_id into CreateURLLoaderThrottles https://chromium-review.googlesource.com/c/chromium/src/+/5171446 * 5213708: Move DownloadTargetInfo into components/download https://chromium-review.googlesource.com/c/chromium/src/+/5213708 * extensions: Add a loader for Controlled Frame embedder scripts https://chromium-review.googlesource.com/c/chromium/src/+/5202765 * [CSC][Zoom] Add initial_zoom_level to DisplayMediaInformation https://chromium-review.googlesource.com/c/chromium/src/+/5168626 * chore: bump chromium in DEPS to 123.0.6262.0 * chore: bump chromium in DEPS to 122.0.6261.6 * fix: suppress clang -Wimplicit-const-int-float-conversion * fixup 5191363: Mark LOG(FATAL) [[noreturn]] for Windows https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * 5167921: Remove Widget::IsTranslucentWindowOpacitySupported https://chromium-review.googlesource.com/c/chromium/src/+/5167921 Also 5148392: PinnedState: Support pinned state in PlatformWindowState | https://chromium-review.googlesource.com/c/chromium/src/+/5148392 * fixup: 5180720: Polish tiled browser window UI on Linux https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * 5170669: clipboard: Migrate DOMException constructors to RejectWith- https://chromium-review.googlesource.com/c/chromium/src/+/5170669 * 5178824: [Fullscreen] Record UKM data https://chromium-review.googlesource.com/c/chromium/src/+/5178824 * chore: update patches after rebase --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2024-01-25 17:46:30 +00:00
expect(clipboard).to.contain('Write permission denied.');
});
it('returns clipboard contents when permission is granted', async () => {
session.defaultSession.setPermissionRequestHandler((wc, permission, callback) => {
if (permission === 'clipboard-sanitized-write') {
callback(true);
} else {
callback(false);
}
});
const clipboard = await writeClipboard();
chore: bump chromium to 122.0.6261.6 (main) (#40949) * chore: bump chromium in DEPS to 122.0.6239.2 * chore: update patches * refactor: extensions replaced StringPiece with string_view Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5171926 * chore: bump chromium in DEPS to 122.0.6240.0 * chore: update patches * chore: bump chromium in DEPS to 122.0.6241.5 * chore: bump chromium in DEPS to 122.0.6245.0 * chore: bump chromium in DEPS to 122.0.6247.0 * chore: bump chromium in DEPS to 122.0.6249.0 * chore: bump chromium in DEPS to 122.0.6251.0 * 5192010: Rename {absl => std}::optional in //chrome/ https://chromium-review.googlesource.com/c/chromium/src/+/5192010 * 5109767: CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * 5105227: [media_preview] Show requested device in permission bubble https://chromium-review.googlesource.com/c/chromium/src/+/5105227 * chore: bump chromium in DEPS to 122.0.6253.0 * chore: update patches * 5180720: Polish tiled browser window UI on Linux | https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * chore: update patches * chore: bump chromium in DEPS to 122.0.6255.0 * chore: update patches * 5186276: [autopip] Make "allow once" per navigation | https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: bump chromium in DEPS to 122.0.6257.0 * chore: bump chromium in DEPS to 122.0.6259.0 * chore: update patches * 5190661: Automated T* -> raw_ptr<T> rewrite "refresh" | https://chromium-review.googlesource.com/c/chromium/src/+/5190661 * 5206106: Make sure RenderFrameHosts are active when printing | https://chromium-review.googlesource.com/c/chromium/src/+/5206106 * 5202674: Reland "Automated T* -> raw_ptr<T> rewrite 'refresh'" https://chromium-review.googlesource.com/c/chromium/src/+/5202674 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton https://chromium-review.googlesource.com/c/chromium/src/+/5109767 * fixup 5206106: Make sure RenderFrameHosts are active when printing * Make legacy ToV8() helpers private to ScriptPromiseResolver, their only user https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * fixup CodeHealth: Fix leaked raw_ptr in Linux ProcessSingleton * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * chore: update patches after rebase * chore: bump chromium in DEPS to 122.0.6260.0 * 5191363: Mark LOG(FATAL) [[noreturn]] https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * fixup 5186276: [autopip] Make "allow once" per navigation https://chromium-review.googlesource.com/c/chromium/src/+/5186276 * fixup Make legacy ToV8() helpers private to ScriptPromiseResolver https://chromium-review.googlesource.com/c/chromium/src/+/5207474 * chore: update patches * chore: bump chromium in DEPS to 122.0.6261.0 * chore: update patches * chore: restore patch that was mistakenly removed * 5181931: Improve LoginHandler (Part 9 / N) https://chromium-review.googlesource.com/c/chromium/src/+/5181931 * Dispatch SiteInstanceGotProcess() only when both process and site are set. https://chromium-review.googlesource.com/c/chromium/src/+/5142354 * 5171446: [AsyncSB] Pass navigation_id into CreateURLLoaderThrottles https://chromium-review.googlesource.com/c/chromium/src/+/5171446 * 5213708: Move DownloadTargetInfo into components/download https://chromium-review.googlesource.com/c/chromium/src/+/5213708 * extensions: Add a loader for Controlled Frame embedder scripts https://chromium-review.googlesource.com/c/chromium/src/+/5202765 * [CSC][Zoom] Add initial_zoom_level to DisplayMediaInformation https://chromium-review.googlesource.com/c/chromium/src/+/5168626 * chore: bump chromium in DEPS to 123.0.6262.0 * chore: bump chromium in DEPS to 122.0.6261.6 * fix: suppress clang -Wimplicit-const-int-float-conversion * fixup 5191363: Mark LOG(FATAL) [[noreturn]] for Windows https://chromium-review.googlesource.com/c/chromium/src/+/5191363 * 5167921: Remove Widget::IsTranslucentWindowOpacitySupported https://chromium-review.googlesource.com/c/chromium/src/+/5167921 Also 5148392: PinnedState: Support pinned state in PlatformWindowState | https://chromium-review.googlesource.com/c/chromium/src/+/5148392 * fixup: 5180720: Polish tiled browser window UI on Linux https://chromium-review.googlesource.com/c/chromium/src/+/5180720 * 5170669: clipboard: Migrate DOMException constructors to RejectWith- https://chromium-review.googlesource.com/c/chromium/src/+/5170669 * 5178824: [Fullscreen] Record UKM data https://chromium-review.googlesource.com/c/chromium/src/+/5178824 * chore: update patches after rebase --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2024-01-25 17:46:30 +00:00
expect(clipboard).to.be.undefined();
});
});
ifdescribe((process.platform !== 'linux' || app.isUnityRunning()))('navigator.setAppBadge/clearAppBadge', () => {
let w: BrowserWindow;
const expectedBadgeCount = 42;
const fireAppBadgeAction: any = (action: string, value: any) => {
return w.webContents.executeJavaScript(`
navigator.${action}AppBadge(${value}).then(() => 'success').catch(err => err.message)`);
};
// For some reason on macOS changing the badge count doesn't happen right away, so wait
// until it changes.
async function waitForBadgeCount (value: number) {
let badgeCount = app.getBadgeCount();
while (badgeCount !== value) {
await setTimeout(10);
badgeCount = app.getBadgeCount();
}
return badgeCount;
}
describe('in the renderer', () => {
before(async () => {
w = new BrowserWindow({
show: false
});
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
});
after(() => {
app.badgeCount = 0;
closeAllWindows();
});
it('setAppBadge can set a numerical value', async () => {
const result = await fireAppBadgeAction('set', expectedBadgeCount);
expect(result).to.equal('success');
expect(waitForBadgeCount(expectedBadgeCount)).to.eventually.equal(expectedBadgeCount);
});
it('setAppBadge can set an empty(dot) value', async () => {
const result = await fireAppBadgeAction('set');
expect(result).to.equal('success');
expect(waitForBadgeCount(0)).to.eventually.equal(0);
});
it('clearAppBadge can clear a value', async () => {
let result = await fireAppBadgeAction('set', expectedBadgeCount);
expect(result).to.equal('success');
expect(waitForBadgeCount(expectedBadgeCount)).to.eventually.equal(expectedBadgeCount);
result = await fireAppBadgeAction('clear');
expect(result).to.equal('success');
expect(waitForBadgeCount(0)).to.eventually.equal(0);
});
});
describe('in a service worker', () => {
beforeEach(async () => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
partition: 'sw-file-scheme-spec',
contextIsolation: false
}
});
});
afterEach(() => {
app.badgeCount = 0;
closeAllWindows();
});
it('setAppBadge can be called in a ServiceWorker', (done) => {
w.webContents.on('ipc-message', (event, channel, message) => {
if (channel === 'reload') {
w.webContents.reload();
} else if (channel === 'error') {
done(message);
} else if (channel === 'response') {
expect(message).to.equal('SUCCESS setting app badge');
expect(waitForBadgeCount(expectedBadgeCount)).to.eventually.equal(expectedBadgeCount);
session.fromPartition('sw-file-scheme-spec').clearStorageData({
storages: ['serviceworkers']
}).then(() => done());
}
});
w.webContents.on('render-process-gone', () => done(new Error('WebContents crashed.')));
w.loadFile(path.join(fixturesPath, 'pages', 'service-worker', 'badge-index.html'), { search: '?setBadge' });
});
it('clearAppBadge can be called in a ServiceWorker', (done) => {
w.webContents.on('ipc-message', (event, channel, message) => {
if (channel === 'reload') {
w.webContents.reload();
} else if (channel === 'setAppBadge') {
expect(message).to.equal('SUCCESS setting app badge');
expect(waitForBadgeCount(expectedBadgeCount)).to.eventually.equal(expectedBadgeCount);
} else if (channel === 'error') {
done(message);
} else if (channel === 'response') {
expect(message).to.equal('SUCCESS clearing app badge');
expect(waitForBadgeCount(expectedBadgeCount)).to.eventually.equal(expectedBadgeCount);
session.fromPartition('sw-file-scheme-spec').clearStorageData({
storages: ['serviceworkers']
}).then(() => done());
}
});
w.webContents.on('render-process-gone', () => done(new Error('WebContents crashed.')));
w.loadFile(path.join(fixturesPath, 'pages', 'service-worker', 'badge-index.html'), { search: '?clearBadge' });
});
});
});
describe('navigator.bluetooth', () => {
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow({
show: false,
webPreferences: {
enableBlinkFeatures: 'WebBluetooth'
}
});
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
});
after(closeAllWindows);
it('can request bluetooth devices', async () => {
const bluetooth = await w.webContents.executeJavaScript(`
navigator.bluetooth.requestDevice({ acceptAllDevices: true}).then(device => "Found a device!").catch(err => err.message);`, true);
expect(bluetooth).to.be.oneOf(['Found a device!', 'Bluetooth adapter not available.', 'User cancelled the requestDevice() chooser.']);
});
});
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
describe('navigator.hid', () => {
let w: BrowserWindow;
let server: http.Server;
let serverUrl: string;
before(async () => {
w = new BrowserWindow({
show: false
});
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end('<body>');
});
serverUrl = (await listen(server)).url;
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
});
const requestDevices: any = () => {
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
return w.webContents.executeJavaScript(`
navigator.hid.requestDevice({filters: []}).then(device => device.toString()).catch(err => err.toString());
`, true);
};
after(() => {
server.close();
closeAllWindows();
});
afterEach(() => {
session.defaultSession.setPermissionCheckHandler(null);
session.defaultSession.setDevicePermissionHandler(null);
session.defaultSession.removeAllListeners('select-hid-device');
});
it('does not return a device if select-hid-device event is not defined', async () => {
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const device = await requestDevices();
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
expect(device).to.equal('');
});
it('does not return a device when permission denied', async () => {
let selectFired = false;
w.webContents.session.on('select-hid-device', (event, details, callback) => {
selectFired = true;
callback();
});
session.defaultSession.setPermissionCheckHandler(() => false);
const device = await requestDevices();
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
expect(selectFired).to.be.false();
expect(device).to.equal('');
});
it('returns a device when select-hid-device event is defined', async () => {
let haveDevices = false;
let selectFired = false;
w.webContents.session.on('select-hid-device', (event, details, callback) => {
expect(details.frame).to.have.property('frameTreeNodeId').that.is.a('number');
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
selectFired = true;
if (details.deviceList.length > 0) {
haveDevices = true;
callback(details.deviceList[0].deviceId);
} else {
callback();
}
});
const device = await requestDevices();
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
expect(selectFired).to.be.true();
if (haveDevices) {
expect(device).to.contain('[object HIDDevice]');
} else {
expect(device).to.equal('');
}
chore: bump chromium to 109.0.5382.0 (main) (#36057) * chore: bump chromium in DEPS to 109.0.5364.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5366.0 * chore: update patches * i3940364: Change PermissionType::WINDOW_PLACEMENT to WINDOW_MANAGEMENT https://chromium-review.googlesource.com/c/chromium/src/+/3940364 * 3866812: Change content::PluginList to only run on the UI thread. https://chromium-review.googlesource.com/c/chromium/src/+/3866812 * chore: bump chromium in DEPS to 109.0.5368.0 * [cleanup] Replace enable_basic_printing with enable_printing https://chromium-review.googlesource.com/c/chromium/src/+/3957357 * chore: update patches * 3956318: Desktop PWAs: Retire kWebAppWindowControlsOverlay flag https://chromium-review.googlesource.com/c/chromium/src/+/3956318 * fixup! Change content::PluginList to only run on the UI thread. (cherry picked from commit 7b5ec87d4ff5d34e7493b4fb46c40c0afeef2005) Co-Authored-By: Robo <hop2deep@gmail.com> * chore: bump chromium in DEPS to 109.0.5370.0 * 3956299: Quota: Cleanup QuotaPermissionContext https://chromium-review.googlesource.com/c/chromium/src/+/3956299 * chore: update patches * 3803867: Add Mojo interface to parse XML for OOP printer capabilities https://chromium-review.googlesource.com/c/chromium/src/+/3803867 * fixup: Add Mojo interface to parse XML for OOP printer capabilities * chore: bump chromium in DEPS to 109.0.5372.0 * chore: update patches * chore: bump chromium in DEPS to 109.0.5374.0 * chore: bump chromium in DEPS to 109.0.5376.0 * chore: bump chromium in DEPS to 109.0.5378.0 * chore: update patches * Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * 3955976: serial: Create DOMException with V8ThrowDOMException https://chromium-review.googlesource.com/c/chromium/src/+/3955976 * 3758405: Append trailer data to serialized messages. https://chromium-review.googlesource.com/c/chromium/src/+/3758405 * chore: revert clang roll This patch reverts https://chromium-review.googlesource.com/c/chromium/src/+/3967491 because that roll breaks the WOA build: https://crbug.com/1377819 * chore: update patches * chore: bump chromium in DEPS to 109.0.5380.0 * chore: update patches * 3859750: [linux/wayland] Added plumbing for the state of tiled edges. https://chromium-review.googlesource.com/c/chromium/src/+/3859750 Also 3970920: [linux/wayland] Fixed the tiled edges for the GTK frame. https://chromium-review.googlesource.com/c/chromium/src/+/3970920 * chore: bump chromium in DEPS to 109.0.5382.0 * chore: update patches * chore: revert Use accessibility.pkey when setting page access. https://chromium-review.googlesource.com/c/chromium/src/+/3949281 breaks our Linux builds run under Docker. This patch should be removed once https://chromium-review.googlesource.com/c/chromium/src/+/3949284 is merged. * 3976312: Roll clang llvmorg-16-init-8189-g97196a2d-2 : llvmorg-16-init-8697-g60809cd2-1 https://chromium-review.googlesource.com/c/chromium/src/+/3976312 * 3967841: [heap] Remove AllocationSpace::MAP_SPACE enum constant https://chromium-review.googlesource.com/c/v8/v8/+/3967841 * 3956131: [cleanup] Remove flag for Wasm threads & atomics https://chromium-review.googlesource.com/c/v8/v8/+/3956131 * chore: update docs for Quota: Cleanup kPersistent in BrowsingDataRemover https://chromium-review.googlesource.com/c/chromium/src/+/3964859 * test: fixup HID test for ARM CI Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com>
2022-10-27 16:37:04 +00:00
if (haveDevices) {
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
// Verify that navigation will clear device permissions
const grantedDevices = await w.webContents.executeJavaScript('navigator.hid.getDevices()');
expect(grantedDevices).to.not.be.empty();
w.loadURL(serverUrl);
const [,,,,, frameProcessId, frameRoutingId] = await once(w.webContents, 'did-frame-navigate');
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
const frame = webFrameMain.fromId(frameProcessId, frameRoutingId);
expect(!!frame).to.be.true();
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
if (frame) {
const grantedDevicesOnNewPage = await frame.executeJavaScript('navigator.hid.getDevices()');
expect(grantedDevicesOnNewPage).to.be.empty();
}
}
});
it('returns a device when DevicePermissionHandler is defined', async () => {
let haveDevices = false;
let selectFired = false;
let gotDevicePerms = false;
w.webContents.session.on('select-hid-device', (event, details, callback) => {
selectFired = true;
if (details.deviceList.length > 0) {
const foundDevice = details.deviceList.find((device) => {
if (device.name && device.name !== '' && device.serialNumber && device.serialNumber !== '') {
haveDevices = true;
return true;
}
});
if (foundDevice) {
callback(foundDevice.deviceId);
return;
}
}
callback();
});
session.defaultSession.setDevicePermissionHandler(() => {
gotDevicePerms = true;
return true;
});
await w.webContents.executeJavaScript('navigator.hid.getDevices();', true);
const device = await requestDevices();
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
expect(selectFired).to.be.true();
if (haveDevices) {
expect(device).to.contain('[object HIDDevice]');
expect(gotDevicePerms).to.be.true();
} else {
expect(device).to.equal('');
}
});
chore: bump chromium to 102.0.4989.0 (main) (#33557) * chore: bump chromium in DEPS to 102.0.4975.0 * chore: bump chromium in DEPS to 102.0.4977.0 * chore: update patches * Remove parameter of OnGpuProcessCrashed() https://chromium-review.googlesource.com/c/chromium/src/+/3543396 * hid: Add exclusionFilters option to requestDevice https://chromium-review.googlesource.com/c/chromium/src/+/3478175 * chore: bump chromium in DEPS to 102.0.4979.0 * chore: bump chromium in DEPS to 102.0.4981.0 * chore: update patches * Deny notification/push permission for documents in non-standard StoragePartitions https://chromium-review.googlesource.com/c/chromium/src/+/3257305 * Improve FrameTreeNode tracking in URLLoaderNetworkContext https://chromium-review.googlesource.com/c/chromium/src/+/3341866 * fixup! Remove parameter of OnGpuProcessCrashed() * chore: fix lint * Reland "Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome" https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * chore: bump chromium in DEPS to 102.0.4983.0 * Ensure EyeDropperView does not access a destroyed window https://chromium-review.googlesource.com/c/chromium/src/+/3561542 * ci: don't delete dawn .git directory 83901: Adds a generated file with the dawn git hash encoded at build time. | https://dawn-review.googlesource.com/c/dawn/+/83901 * ci: update Windows toolchain 3550827: New toolchain for Windows 10 20348 SDK | https://chromium-review.googlesource.com/c/chromium/src/+/3550827 * chore: bump chromium in DEPS to 102.0.4985.0 * chore: update patches * chore: bump chromium in DEPS to 102.0.4987.0 * chore: update patches * 3563432: codehealth: remove uses of DictionaryValue in cbui/webui https://chromium-review.googlesource.com/c/chromium/src/+/3563432 * chore: update patches after rebase * Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * 3565724: Preserve "proper method names" as-is in error.stack. https://chromium-review.googlesource.com/c/v8/v8/+/3565724 * chore: bump chromium in DEPS to 102.0.4989.0 * chore: update patches * fixup ci: don't delete dawn .git directory for Windows * 3560843: Remove multi-parameter version of gfx::Rect[F]::Inset() https://chromium-review.googlesource.com/c/chromium/src/+/3560843 * 3572711: Remove unused IDS_PDF_TOOLTIP_ROTATE_CW resource. https://chromium-review.googlesource.com/c/chromium/src/+/3572711 * 3572926: Reland "[Sysroot] Switch to Debian Bullseye stable" https://chromium-review.googlesource.com/c/chromium/src/+/3572926 * build: fixup sysroots with electron specific dependencies * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * fixup 3565724: Preserve "proper method names" as-is in error.stack. * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * test: add spec for navigator.hid.requestDevice({ exclusionFilters: [...] } * fixup 3565724: Preserve "proper method names" as-is in error.stack. * ci: use python3 to get the windows toolchain profile 3525960: Explicitly run everything with python3 | https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3525960 * chore: add diagnostic logging * fix: try calling process.crash() * chore: remove logging Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-04-12 11:19:14 +00:00
it('excludes a device when a exclusionFilter is specified', async () => {
chore: bump chromium to 102.0.4989.0 (main) (#33557) * chore: bump chromium in DEPS to 102.0.4975.0 * chore: bump chromium in DEPS to 102.0.4977.0 * chore: update patches * Remove parameter of OnGpuProcessCrashed() https://chromium-review.googlesource.com/c/chromium/src/+/3543396 * hid: Add exclusionFilters option to requestDevice https://chromium-review.googlesource.com/c/chromium/src/+/3478175 * chore: bump chromium in DEPS to 102.0.4979.0 * chore: bump chromium in DEPS to 102.0.4981.0 * chore: update patches * Deny notification/push permission for documents in non-standard StoragePartitions https://chromium-review.googlesource.com/c/chromium/src/+/3257305 * Improve FrameTreeNode tracking in URLLoaderNetworkContext https://chromium-review.googlesource.com/c/chromium/src/+/3341866 * fixup! Remove parameter of OnGpuProcessCrashed() * chore: fix lint * Reland "Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome" https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * chore: bump chromium in DEPS to 102.0.4983.0 * Ensure EyeDropperView does not access a destroyed window https://chromium-review.googlesource.com/c/chromium/src/+/3561542 * ci: don't delete dawn .git directory 83901: Adds a generated file with the dawn git hash encoded at build time. | https://dawn-review.googlesource.com/c/dawn/+/83901 * ci: update Windows toolchain 3550827: New toolchain for Windows 10 20348 SDK | https://chromium-review.googlesource.com/c/chromium/src/+/3550827 * chore: bump chromium in DEPS to 102.0.4985.0 * chore: update patches * chore: bump chromium in DEPS to 102.0.4987.0 * chore: update patches * 3563432: codehealth: remove uses of DictionaryValue in cbui/webui https://chromium-review.googlesource.com/c/chromium/src/+/3563432 * chore: update patches after rebase * Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * 3565724: Preserve "proper method names" as-is in error.stack. https://chromium-review.googlesource.com/c/v8/v8/+/3565724 * chore: bump chromium in DEPS to 102.0.4989.0 * chore: update patches * fixup ci: don't delete dawn .git directory for Windows * 3560843: Remove multi-parameter version of gfx::Rect[F]::Inset() https://chromium-review.googlesource.com/c/chromium/src/+/3560843 * 3572711: Remove unused IDS_PDF_TOOLTIP_ROTATE_CW resource. https://chromium-review.googlesource.com/c/chromium/src/+/3572711 * 3572926: Reland "[Sysroot] Switch to Debian Bullseye stable" https://chromium-review.googlesource.com/c/chromium/src/+/3572926 * build: fixup sysroots with electron specific dependencies * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * fixup 3565724: Preserve "proper method names" as-is in error.stack. * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * test: add spec for navigator.hid.requestDevice({ exclusionFilters: [...] } * fixup 3565724: Preserve "proper method names" as-is in error.stack. * ci: use python3 to get the windows toolchain profile 3525960: Explicitly run everything with python3 | https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3525960 * chore: add diagnostic logging * fix: try calling process.crash() * chore: remove logging Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-04-12 11:19:14 +00:00
const exclusionFilters = <any>[];
let haveDevices = false;
let checkForExcludedDevice = false;
w.webContents.session.on('select-hid-device', (event, details, callback) => {
if (details.deviceList.length > 0) {
details.deviceList.find((device) => {
if (device.name && device.name !== '' && device.serialNumber && device.serialNumber !== '') {
if (checkForExcludedDevice) {
const compareDevice = {
vendorId: device.vendorId,
productId: device.productId
};
expect(compareDevice).to.not.equal(exclusionFilters[0], 'excluded device should not be returned');
} else {
haveDevices = true;
exclusionFilters.push({
vendorId: device.vendorId,
productId: device.productId
});
return true;
}
}
});
}
callback();
});
await requestDevices();
chore: bump chromium to 102.0.4989.0 (main) (#33557) * chore: bump chromium in DEPS to 102.0.4975.0 * chore: bump chromium in DEPS to 102.0.4977.0 * chore: update patches * Remove parameter of OnGpuProcessCrashed() https://chromium-review.googlesource.com/c/chromium/src/+/3543396 * hid: Add exclusionFilters option to requestDevice https://chromium-review.googlesource.com/c/chromium/src/+/3478175 * chore: bump chromium in DEPS to 102.0.4979.0 * chore: bump chromium in DEPS to 102.0.4981.0 * chore: update patches * Deny notification/push permission for documents in non-standard StoragePartitions https://chromium-review.googlesource.com/c/chromium/src/+/3257305 * Improve FrameTreeNode tracking in URLLoaderNetworkContext https://chromium-review.googlesource.com/c/chromium/src/+/3341866 * fixup! Remove parameter of OnGpuProcessCrashed() * chore: fix lint * Reland "Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome" https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * chore: bump chromium in DEPS to 102.0.4983.0 * Ensure EyeDropperView does not access a destroyed window https://chromium-review.googlesource.com/c/chromium/src/+/3561542 * ci: don't delete dawn .git directory 83901: Adds a generated file with the dawn git hash encoded at build time. | https://dawn-review.googlesource.com/c/dawn/+/83901 * ci: update Windows toolchain 3550827: New toolchain for Windows 10 20348 SDK | https://chromium-review.googlesource.com/c/chromium/src/+/3550827 * chore: bump chromium in DEPS to 102.0.4985.0 * chore: update patches * chore: bump chromium in DEPS to 102.0.4987.0 * chore: update patches * 3563432: codehealth: remove uses of DictionaryValue in cbui/webui https://chromium-review.googlesource.com/c/chromium/src/+/3563432 * chore: update patches after rebase * Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * 3565724: Preserve "proper method names" as-is in error.stack. https://chromium-review.googlesource.com/c/v8/v8/+/3565724 * chore: bump chromium in DEPS to 102.0.4989.0 * chore: update patches * fixup ci: don't delete dawn .git directory for Windows * 3560843: Remove multi-parameter version of gfx::Rect[F]::Inset() https://chromium-review.googlesource.com/c/chromium/src/+/3560843 * 3572711: Remove unused IDS_PDF_TOOLTIP_ROTATE_CW resource. https://chromium-review.googlesource.com/c/chromium/src/+/3572711 * 3572926: Reland "[Sysroot] Switch to Debian Bullseye stable" https://chromium-review.googlesource.com/c/chromium/src/+/3572926 * build: fixup sysroots with electron specific dependencies * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * fixup 3565724: Preserve "proper method names" as-is in error.stack. * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * test: add spec for navigator.hid.requestDevice({ exclusionFilters: [...] } * fixup 3565724: Preserve "proper method names" as-is in error.stack. * ci: use python3 to get the windows toolchain profile 3525960: Explicitly run everything with python3 | https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3525960 * chore: add diagnostic logging * fix: try calling process.crash() * chore: remove logging Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-04-12 11:19:14 +00:00
if (haveDevices) {
// We have devices to exclude, so check if exclusionFilters work
chore: bump chromium to 102.0.4989.0 (main) (#33557) * chore: bump chromium in DEPS to 102.0.4975.0 * chore: bump chromium in DEPS to 102.0.4977.0 * chore: update patches * Remove parameter of OnGpuProcessCrashed() https://chromium-review.googlesource.com/c/chromium/src/+/3543396 * hid: Add exclusionFilters option to requestDevice https://chromium-review.googlesource.com/c/chromium/src/+/3478175 * chore: bump chromium in DEPS to 102.0.4979.0 * chore: bump chromium in DEPS to 102.0.4981.0 * chore: update patches * Deny notification/push permission for documents in non-standard StoragePartitions https://chromium-review.googlesource.com/c/chromium/src/+/3257305 * Improve FrameTreeNode tracking in URLLoaderNetworkContext https://chromium-review.googlesource.com/c/chromium/src/+/3341866 * fixup! Remove parameter of OnGpuProcessCrashed() * chore: fix lint * Reland "Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome" https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * chore: bump chromium in DEPS to 102.0.4983.0 * Ensure EyeDropperView does not access a destroyed window https://chromium-review.googlesource.com/c/chromium/src/+/3561542 * ci: don't delete dawn .git directory 83901: Adds a generated file with the dawn git hash encoded at build time. | https://dawn-review.googlesource.com/c/dawn/+/83901 * ci: update Windows toolchain 3550827: New toolchain for Windows 10 20348 SDK | https://chromium-review.googlesource.com/c/chromium/src/+/3550827 * chore: bump chromium in DEPS to 102.0.4985.0 * chore: update patches * chore: bump chromium in DEPS to 102.0.4987.0 * chore: update patches * 3563432: codehealth: remove uses of DictionaryValue in cbui/webui https://chromium-review.googlesource.com/c/chromium/src/+/3563432 * chore: update patches after rebase * Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * 3565724: Preserve "proper method names" as-is in error.stack. https://chromium-review.googlesource.com/c/v8/v8/+/3565724 * chore: bump chromium in DEPS to 102.0.4989.0 * chore: update patches * fixup ci: don't delete dawn .git directory for Windows * 3560843: Remove multi-parameter version of gfx::Rect[F]::Inset() https://chromium-review.googlesource.com/c/chromium/src/+/3560843 * 3572711: Remove unused IDS_PDF_TOOLTIP_ROTATE_CW resource. https://chromium-review.googlesource.com/c/chromium/src/+/3572711 * 3572926: Reland "[Sysroot] Switch to Debian Bullseye stable" https://chromium-review.googlesource.com/c/chromium/src/+/3572926 * build: fixup sysroots with electron specific dependencies * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * fixup 3565724: Preserve "proper method names" as-is in error.stack. * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * test: add spec for navigator.hid.requestDevice({ exclusionFilters: [...] } * fixup 3565724: Preserve "proper method names" as-is in error.stack. * ci: use python3 to get the windows toolchain profile 3525960: Explicitly run everything with python3 | https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3525960 * chore: add diagnostic logging * fix: try calling process.crash() * chore: remove logging Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-04-12 11:19:14 +00:00
checkForExcludedDevice = true;
await w.webContents.executeJavaScript(`
navigator.hid.requestDevice({filters: [], exclusionFilters: ${JSON.stringify(exclusionFilters)}}).then(device => device.toString()).catch(err => err.toString());
chore: bump chromium to 102.0.4989.0 (main) (#33557) * chore: bump chromium in DEPS to 102.0.4975.0 * chore: bump chromium in DEPS to 102.0.4977.0 * chore: update patches * Remove parameter of OnGpuProcessCrashed() https://chromium-review.googlesource.com/c/chromium/src/+/3543396 * hid: Add exclusionFilters option to requestDevice https://chromium-review.googlesource.com/c/chromium/src/+/3478175 * chore: bump chromium in DEPS to 102.0.4979.0 * chore: bump chromium in DEPS to 102.0.4981.0 * chore: update patches * Deny notification/push permission for documents in non-standard StoragePartitions https://chromium-review.googlesource.com/c/chromium/src/+/3257305 * Improve FrameTreeNode tracking in URLLoaderNetworkContext https://chromium-review.googlesource.com/c/chromium/src/+/3341866 * fixup! Remove parameter of OnGpuProcessCrashed() * chore: fix lint * Reland "Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome" https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * chore: bump chromium in DEPS to 102.0.4983.0 * Ensure EyeDropperView does not access a destroyed window https://chromium-review.googlesource.com/c/chromium/src/+/3561542 * ci: don't delete dawn .git directory 83901: Adds a generated file with the dawn git hash encoded at build time. | https://dawn-review.googlesource.com/c/dawn/+/83901 * ci: update Windows toolchain 3550827: New toolchain for Windows 10 20348 SDK | https://chromium-review.googlesource.com/c/chromium/src/+/3550827 * chore: bump chromium in DEPS to 102.0.4985.0 * chore: update patches * chore: bump chromium in DEPS to 102.0.4987.0 * chore: update patches * 3563432: codehealth: remove uses of DictionaryValue in cbui/webui https://chromium-review.googlesource.com/c/chromium/src/+/3563432 * chore: update patches after rebase * Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * 3565724: Preserve "proper method names" as-is in error.stack. https://chromium-review.googlesource.com/c/v8/v8/+/3565724 * chore: bump chromium in DEPS to 102.0.4989.0 * chore: update patches * fixup ci: don't delete dawn .git directory for Windows * 3560843: Remove multi-parameter version of gfx::Rect[F]::Inset() https://chromium-review.googlesource.com/c/chromium/src/+/3560843 * 3572711: Remove unused IDS_PDF_TOOLTIP_ROTATE_CW resource. https://chromium-review.googlesource.com/c/chromium/src/+/3572711 * 3572926: Reland "[Sysroot] Switch to Debian Bullseye stable" https://chromium-review.googlesource.com/c/chromium/src/+/3572926 * build: fixup sysroots with electron specific dependencies * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * fixup 3565724: Preserve "proper method names" as-is in error.stack. * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * test: add spec for navigator.hid.requestDevice({ exclusionFilters: [...] } * fixup 3565724: Preserve "proper method names" as-is in error.stack. * ci: use python3 to get the windows toolchain profile 3525960: Explicitly run everything with python3 | https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3525960 * chore: add diagnostic logging * fix: try calling process.crash() * chore: remove logging Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-04-12 11:19:14 +00:00
`, true);
}
});
it('supports device.forget()', async () => {
let deletedDeviceFromEvent;
let haveDevices = false;
w.webContents.session.on('select-hid-device', (event, details, callback) => {
if (details.deviceList.length > 0) {
haveDevices = true;
callback(details.deviceList[0].deviceId);
} else {
callback();
}
});
w.webContents.session.on('hid-device-revoked', (event, details) => {
deletedDeviceFromEvent = details.device;
});
await requestDevices();
if (haveDevices) {
const grantedDevices = await w.webContents.executeJavaScript('navigator.hid.getDevices()');
if (grantedDevices.length > 0) {
const deletedDevice = await w.webContents.executeJavaScript(`
navigator.hid.getDevices().then(devices => {
devices[0].forget();
return {
vendorId: devices[0].vendorId,
productId: devices[0].productId,
name: devices[0].productName
}
})
`);
const grantedDevices2 = await w.webContents.executeJavaScript('navigator.hid.getDevices()');
expect(grantedDevices2.length).to.be.lessThan(grantedDevices.length);
if (deletedDevice.name !== '' && deletedDevice.productId && deletedDevice.vendorId) {
expect(deletedDeviceFromEvent).to.include(deletedDevice);
}
}
}
});
feat: add support for WebHID (#30213) * feat: add support for WebHID * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * Address review feedback * Address review feedback * chore: clear granted_devices on navigation Also added test to verify devices get cleared * fixup testing for device clear * make sure navigator.hid.getDevices is run on correct frame * clear granted devices on RenderFrameHost deletion/change * manage device permissions per RenderFrameHost This change makes sure we don't clear device permission prematurely due to child frame navigation * Update shell/browser/api/electron_api_web_contents.cc Co-authored-by: Jeremy Rose <jeremya@chromium.org> * apply review feedback from @zcbenz * Match upstream ObjectMap This change matches what ObjectPermissionContextBase uses to cache object permissions: https://source.chromium.org/chromium/chromium/src/+/main:components/permissions/object_permission_context_base.h;l=52;drc=8f95b5eab2797a3e26bba299f3b0df85bfc98bf5;bpv=1;bpt=0 The main reason for this was to resolve this crash on Win x64: ok 2 WebContentsView doesn't crash when GCed during allocation Received fatal exception EXCEPTION_ACCESS_VIOLATION Backtrace: gin::WrappableBase::SecondWeakCallback [0x00007FF6F2AFA005+133] (o:\gin\wrappable.cc:53) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacks [0x00007FF6F028F9AB+171] (o:\v8\src\handles\global-handles.cc:1400) v8::internal::GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask [0x00007FF6F028F867+391] (o:\v8\src\handles\global-handles.cc:1387) node::PerIsolatePlatformData::RunForegroundTask [0x00007FF6F3B4D065+317] (o:\third_party\electron_node\src\node_platform.cc:415) node::PerIsolatePlatformData::FlushForegroundTasksInternal [0x00007FF6F3B4C424+776] (o:\third_party\electron_node\src\node_platform.cc:479) uv_run [0x00007FF6F2DDD07C+492] (o:\third_party\electron_node\deps\uv\src\win\core.c:609) electron::NodeBindings::UvRunOnce [0x00007FF6EEE1E036+294] (o:\electron\shell\common\node_bindings.cc:631) base::TaskAnnotator::RunTask [0x00007FF6F2318A19+457] (o:\base\task\common\task_annotator.cc:178) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl [0x00007FF6F2E6F553+963] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:361) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork [0x00007FF6F2E6EC69+137] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:266) base::MessagePumpForUI::DoRunLoop [0x00007FF6F235AA58+216] (o:\base\message_loop\message_pump_win.cc:221) base::MessagePumpWin::Run [0x00007FF6F235A01A+106] (o:\base\message_loop\message_pump_win.cc:79) base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run [0x00007FF6F2E702DA+682] (o:\base\task\sequence_manager\thread_controller_with_message_pump_impl.cc:470) base::RunLoop::Run [0x00007FF6F22F95BA+842] (o:\base\run_loop.cc:136) content::BrowserMainLoop::RunMainMessageLoop [0x00007FF6F14423CC+208] (o:\content\browser\browser_main_loop.cc:990) content::BrowserMainRunnerImpl::Run [0x00007FF6F144402F+143] (o:\content\browser\browser_main_runner_impl.cc:153) content::BrowserMain [0x00007FF6F143F911+257] (o:\content\browser\browser_main.cc:49) content::RunBrowserProcessMain [0x00007FF6EFFA7D18+112] (o:\content\app\content_main_runner_impl.cc:608) content::ContentMainRunnerImpl::RunBrowser [0x00007FF6EFFA8CF4+1220] (o:\content\app\content_main_runner_impl.cc:1104) content::ContentMainRunnerImpl::Run [0x00007FF6EFFA87C9+393] (o:\content\app\content_main_runner_impl.cc:971) content::RunContentProcess [0x00007FF6EFFA73BD+733] (o:\content\app\content_main.cc:394) content::ContentMain [0x00007FF6EFFA79E1+54] (o:\content\app\content_main.cc:422) wWinMain [0x00007FF6EECA1535+889] (o:\electron\shell\app\electron_main.cc:291) __scrt_common_main_seh [0x00007FF6F6F88482+262] (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) BaseThreadInitThunk [0x00007FFEC0087034+20] RtlUserThreadStart [0x00007FFEC1F02651+33] ✗ Electron tests failed with code 0xc0000005. Co-authored-by: Jeremy Rose <jeremya@chromium.org>
2021-09-23 11:00:11 +00:00
});
describe('navigator.usb', () => {
let w: BrowserWindow;
let server: http.Server;
let serverUrl: string;
before(async () => {
w = new BrowserWindow({
show: false
});
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end('<body>');
});
serverUrl = (await listen(server)).url;
});
const requestDevices: any = () => {
return w.webContents.executeJavaScript(`
navigator.usb.requestDevice({filters: []}).then(device => device.toString()).catch(err => err.toString());
`, true);
};
const notFoundError = 'NotFoundError: Failed to execute \'requestDevice\' on \'USB\': No device selected.';
after(() => {
server.close();
closeAllWindows();
});
afterEach(() => {
session.defaultSession.setPermissionCheckHandler(null);
session.defaultSession.setDevicePermissionHandler(null);
session.defaultSession.removeAllListeners('select-usb-device');
});
it('does not return a device if select-usb-device event is not defined', async () => {
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const device = await requestDevices();
expect(device).to.equal(notFoundError);
});
it('does not return a device when permission denied', async () => {
let selectFired = false;
w.webContents.session.on('select-usb-device', (event, details, callback) => {
selectFired = true;
callback();
});
session.defaultSession.setPermissionCheckHandler(() => false);
const device = await requestDevices();
expect(selectFired).to.be.false();
expect(device).to.equal(notFoundError);
});
it('returns a device when select-usb-device event is defined', async () => {
let haveDevices = false;
let selectFired = false;
w.webContents.session.on('select-usb-device', (event, details, callback) => {
expect(details.frame).to.have.property('frameTreeNodeId').that.is.a('number');
selectFired = true;
if (details.deviceList.length > 0) {
haveDevices = true;
callback(details.deviceList[0].deviceId);
} else {
callback();
}
});
const device = await requestDevices();
expect(selectFired).to.be.true();
if (haveDevices) {
expect(device).to.contain('[object USBDevice]');
} else {
expect(device).to.equal(notFoundError);
}
if (haveDevices) {
// Verify that navigation will clear device permissions
const grantedDevices = await w.webContents.executeJavaScript('navigator.usb.getDevices()');
expect(grantedDevices).to.not.be.empty();
w.loadURL(serverUrl);
const [,,,,, frameProcessId, frameRoutingId] = await once(w.webContents, 'did-frame-navigate');
const frame = webFrameMain.fromId(frameProcessId, frameRoutingId);
expect(!!frame).to.be.true();
if (frame) {
const grantedDevicesOnNewPage = await frame.executeJavaScript('navigator.usb.getDevices()');
expect(grantedDevicesOnNewPage).to.be.empty();
}
}
});
it('returns a device when DevicePermissionHandler is defined', async () => {
let haveDevices = false;
let selectFired = false;
let gotDevicePerms = false;
w.webContents.session.on('select-usb-device', (event, details, callback) => {
selectFired = true;
if (details.deviceList.length > 0) {
const foundDevice = details.deviceList.find((device) => {
if (device.productName && device.productName !== '' && device.serialNumber && device.serialNumber !== '') {
haveDevices = true;
return true;
}
});
if (foundDevice) {
callback(foundDevice.deviceId);
return;
}
}
callback();
});
session.defaultSession.setDevicePermissionHandler(() => {
gotDevicePerms = true;
return true;
});
await w.webContents.executeJavaScript('navigator.usb.getDevices();', true);
const device = await requestDevices();
expect(selectFired).to.be.true();
if (haveDevices) {
expect(device).to.contain('[object USBDevice]');
expect(gotDevicePerms).to.be.true();
} else {
expect(device).to.equal(notFoundError);
}
});
it('supports device.forget()', async () => {
let deletedDeviceFromEvent;
let haveDevices = false;
w.webContents.session.on('select-usb-device', (event, details, callback) => {
if (details.deviceList.length > 0) {
haveDevices = true;
callback(details.deviceList[0].deviceId);
} else {
callback();
}
});
w.webContents.session.on('usb-device-revoked', (event, details) => {
deletedDeviceFromEvent = details.device;
});
await requestDevices();
if (haveDevices) {
const grantedDevices = await w.webContents.executeJavaScript('navigator.usb.getDevices()');
if (grantedDevices.length > 0) {
const deletedDevice: Electron.USBDevice = await w.webContents.executeJavaScript(`
navigator.usb.getDevices().then(devices => {
devices[0].forget();
return {
vendorId: devices[0].vendorId,
productId: devices[0].productId,
productName: devices[0].productName
}
})
`);
const grantedDevices2 = await w.webContents.executeJavaScript('navigator.usb.getDevices()');
expect(grantedDevices2.length).to.be.lessThan(grantedDevices.length);
if (deletedDevice.productName !== '' && deletedDevice.productId && deletedDevice.vendorId) {
expect(deletedDeviceFromEvent).to.include(deletedDevice);
}
}
}
});
});