electron/spec-main/api-web-contents-spec.ts

2081 lines
74 KiB
TypeScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
import { expect } from 'chai';
import { AddressInfo } from 'net';
import * as path from 'path';
import * as fs from 'fs';
import * as http from 'http';
import { BrowserWindow, ipcMain, webContents, session, WebContents, app, BrowserView } from 'electron/main';
import { clipboard } from 'electron/common';
2020-03-20 20:28:31 +00:00
import { emittedOnce } from './events-helpers';
import { closeAllWindows } from './window-helpers';
import { ifdescribe, ifit, delay, defer } from './spec-helpers';
2020-03-20 20:28:31 +00:00
const pdfjs = require('pdfjs-dist');
const fixturesPath = path.resolve(__dirname, '..', 'spec', 'fixtures');
const mainFixturesPath = path.resolve(__dirname, 'fixtures');
const features = process._linkedBinding('electron_common_features');
describe('webContents module', () => {
describe('getAllWebContents() API', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('returns an array of web contents', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: { webviewTag: true }
2020-03-20 20:28:31 +00:00
});
w.loadFile(path.join(fixturesPath, 'pages', 'webview-zoom-factor.html'));
2020-03-20 20:28:31 +00:00
await emittedOnce(w.webContents, 'did-attach-webview');
2020-03-20 20:28:31 +00:00
w.webContents.openDevTools();
2020-03-20 20:28:31 +00:00
await emittedOnce(w.webContents, 'devtools-opened');
const all = webContents.getAllWebContents().sort((a, b) => {
2020-03-20 20:28:31 +00:00
return a.id - b.id;
});
2020-03-20 20:28:31 +00:00
expect(all).to.have.length(3);
expect(all[0].getType()).to.equal('window');
expect(all[all.length - 2].getType()).to.equal('webview');
expect(all[all.length - 1].getType()).to.equal('remote');
});
});
describe('fromId()', () => {
it('returns undefined for an unknown id', () => {
expect(webContents.fromId(12345)).to.be.undefined();
});
});
describe('fromDevToolsTargetId()', () => {
it('returns WebContents for attached DevTools target', async () => {
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
try {
await w.webContents.debugger.attach('1.3');
const { targetInfo } = await w.webContents.debugger.sendCommand('Target.getTargetInfo');
expect(webContents.fromDevToolsTargetId(targetInfo.targetId)).to.equal(w.webContents);
} finally {
await w.webContents.debugger.detach();
}
});
it('returns undefined for an unknown id', () => {
expect(webContents.fromDevToolsTargetId('nope')).to.be.undefined();
});
});
2020-05-18 15:04:41 +00:00
describe('will-prevent-unload event', function () {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('does not emit if beforeunload returns undefined in a BrowserWindow', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
2019-11-01 20:37:02 +00:00
w.webContents.once('will-prevent-unload', () => {
2020-03-20 20:28:31 +00:00
expect.fail('should not have fired');
});
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-undefined.html'));
const wait = emittedOnce(w, 'closed');
w.close();
await wait;
2020-03-20 20:28:31 +00:00
});
it('does not emit if beforeunload returns undefined in a BrowserView', async () => {
const w = new BrowserWindow({ show: false });
const view = new BrowserView();
w.setBrowserView(view);
view.setBounds(w.getBounds());
view.webContents.once('will-prevent-unload', () => {
expect.fail('should not have fired');
});
await view.webContents.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-undefined.html'));
const wait = emittedOnce(w, 'closed');
w.close();
await wait;
});
it('emits if beforeunload returns false in a BrowserWindow', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false.html'));
w.close();
2020-03-20 20:28:31 +00:00
await emittedOnce(w.webContents, 'will-prevent-unload');
});
it('emits if beforeunload returns false in a BrowserView', async () => {
const w = new BrowserWindow({ show: false });
const view = new BrowserView();
w.setBrowserView(view);
view.setBounds(w.getBounds());
await view.webContents.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false.html'));
w.close();
await emittedOnce(view.webContents, 'will-prevent-unload');
});
it('supports calling preventDefault on will-prevent-unload events in a BrowserWindow', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
w.webContents.once('will-prevent-unload', event => event.preventDefault());
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false.html'));
const wait = emittedOnce(w, 'closed');
w.close();
await wait;
2020-03-20 20:28:31 +00:00
});
});
describe('webContents.send(channel, args...)', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('throws an error when the channel is missing', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
expect(() => {
2020-03-20 20:28:31 +00:00
(w.webContents.send as any)();
}).to.throw('Missing required channel argument');
expect(() => {
2020-03-20 20:28:31 +00:00
w.webContents.send(null as any);
}).to.throw('Missing required channel argument');
});
it('does not block node async APIs when sent before document is ready', (done) => {
// Please reference https://github.com/electron/electron/issues/19368 if
// this test fails.
ipcMain.once('async-node-api-done', () => {
2020-03-20 20:28:31 +00:00
done();
});
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
sandbox: false,
contextIsolation: false
}
2020-03-20 20:28:31 +00:00
});
w.loadFile(path.join(fixturesPath, 'pages', 'send-after-node.html'));
setTimeout(() => {
2020-03-20 20:28:31 +00:00
w.webContents.send('test');
}, 50);
});
});
ifdescribe(features.isPrintingEnabled())('webContents.print()', () => {
2020-03-20 20:28:31 +00:00
let w: BrowserWindow;
beforeEach(() => {
2020-03-20 20:28:31 +00:00
w = new BrowserWindow({ show: false });
});
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('throws when invalid settings are passed', () => {
expect(() => {
// @ts-ignore this line is intentionally incorrect
2020-03-20 20:28:31 +00:00
w.webContents.print(true);
}).to.throw('webContents.print(): Invalid print settings specified.');
});
it('throws when an invalid callback is passed', () => {
expect(() => {
// @ts-ignore this line is intentionally incorrect
2020-03-20 20:28:31 +00:00
w.webContents.print({}, true);
}).to.throw('webContents.print(): Invalid optional callback provided.');
});
ifit(process.platform !== 'linux')('throws when an invalid deviceName is passed', () => {
expect(() => {
2020-03-20 20:28:31 +00:00
w.webContents.print({ deviceName: 'i-am-a-nonexistent-printer' }, () => {});
}).to.throw('webContents.print(): Invalid deviceName provided.');
});
it('throws when an invalid pageSize is passed', () => {
expect(() => {
// @ts-ignore this line is intentionally incorrect
2020-03-20 20:28:31 +00:00
w.webContents.print({ pageSize: 'i-am-a-bad-pagesize' }, () => {});
}).to.throw('Unsupported pageSize: i-am-a-bad-pagesize');
});
it('throws when an invalid custom pageSize is passed', () => {
expect(() => {
w.webContents.print({
pageSize: {
width: 100,
height: 200
}
});
}).to.throw('height and width properties must be minimum 352 microns.');
});
it('does not crash with custom margins', () => {
expect(() => {
w.webContents.print({
silent: true,
margins: {
marginType: 'custom',
top: 1,
bottom: 1,
left: 1,
right: 1
}
2020-03-20 20:28:31 +00:00
});
}).to.not.throw();
});
});
describe('webContents.executeJavaScript', () => {
describe('in about:blank', () => {
2020-03-20 20:28:31 +00:00
const expected = 'hello, world!';
const expectedErrorMsg = 'woops!';
const code = `(() => "${expected}")()`;
const asyncCode = `(() => new Promise(r => setTimeout(() => r("${expected}"), 500)))()`;
const badAsyncCode = `(() => new Promise((r, e) => setTimeout(() => e("${expectedErrorMsg}"), 500)))()`;
const errorTypes = new Set([
Error,
ReferenceError,
EvalError,
RangeError,
SyntaxError,
TypeError,
URIError
2020-03-20 20:28:31 +00:00
]);
let w: BrowserWindow;
before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: false } });
2020-03-20 20:28:31 +00:00
await w.loadURL('about:blank');
});
after(closeAllWindows);
it('resolves the returned promise with the result', async () => {
2020-03-20 20:28:31 +00:00
const result = await w.webContents.executeJavaScript(code);
expect(result).to.equal(expected);
});
it('resolves the returned promise with the result if the code returns an asyncronous promise', async () => {
2020-03-20 20:28:31 +00:00
const result = await w.webContents.executeJavaScript(asyncCode);
expect(result).to.equal(expected);
});
it('rejects the returned promise if an async error is thrown', async () => {
2020-03-20 20:28:31 +00:00
await expect(w.webContents.executeJavaScript(badAsyncCode)).to.eventually.be.rejectedWith(expectedErrorMsg);
});
it('rejects the returned promise with an error if an Error.prototype is thrown', async () => {
for (const error of errorTypes) {
await expect(w.webContents.executeJavaScript(`Promise.reject(new ${error.name}("Wamp-wamp"))`))
2020-03-20 20:28:31 +00:00
.to.eventually.be.rejectedWith(error);
}
2020-03-20 20:28:31 +00:00
});
});
2019-11-01 20:37:02 +00:00
describe('on a real page', () => {
2020-03-20 20:28:31 +00:00
let w: BrowserWindow;
beforeEach(() => {
2020-03-20 20:28:31 +00:00
w = new BrowserWindow({ show: false });
});
afterEach(closeAllWindows);
2020-03-20 20:28:31 +00:00
let server: http.Server = null as unknown as http.Server;
let serverUrl: string = null as unknown as string;
before((done) => {
server = http.createServer((request, response) => {
2020-03-20 20:28:31 +00:00
response.end();
}).listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
serverUrl = 'http://127.0.0.1:' + (server.address() as AddressInfo).port;
done();
});
});
after(() => {
2020-03-20 20:28:31 +00:00
server.close();
});
it('works after page load and during subframe load', async () => {
await w.loadURL(serverUrl);
// initiate a sub-frame load, then try and execute script during it
await w.webContents.executeJavaScript(`
var iframe = document.createElement('iframe')
iframe.src = '${serverUrl}/slow'
document.body.appendChild(iframe)
null // don't return the iframe
`);
await w.webContents.executeJavaScript('console.log(\'hello\')');
});
it('executes after page load', async () => {
const executeJavaScript = w.webContents.executeJavaScript('(() => "test")()');
2020-03-20 20:28:31 +00:00
w.loadURL(serverUrl);
const result = await executeJavaScript;
expect(result).to.equal('test');
2020-03-20 20:28:31 +00:00
});
});
});
describe('webContents.executeJavaScriptInIsolatedWorld', () => {
2020-03-20 20:28:31 +00:00
let w: BrowserWindow;
before(async () => {
2020-03-20 20:28:31 +00:00
w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: true } });
await w.loadURL('about:blank');
});
it('resolves the returned promise with the result', async () => {
2020-03-20 20:28:31 +00:00
await w.webContents.executeJavaScriptInIsolatedWorld(999, [{ code: 'window.X = 123' }]);
const isolatedResult = await w.webContents.executeJavaScriptInIsolatedWorld(999, [{ code: 'window.X' }]);
const mainWorldResult = await w.webContents.executeJavaScript('window.X');
expect(isolatedResult).to.equal(123);
expect(mainWorldResult).to.equal(undefined);
});
});
describe('loadURL() promise API', () => {
2020-03-20 20:28:31 +00:00
let w: BrowserWindow;
beforeEach(async () => {
2020-03-20 20:28:31 +00:00
w = new BrowserWindow({ show: false });
});
afterEach(closeAllWindows);
it('resolves when done loading', async () => {
2020-03-20 20:28:31 +00:00
await expect(w.loadURL('about:blank')).to.eventually.be.fulfilled();
});
it('resolves when done loading a file URL', async () => {
2020-03-20 20:28:31 +00:00
await expect(w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'))).to.eventually.be.fulfilled();
});
it('rejects when failing to load a file URL', async () => {
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected()
2020-03-20 20:28:31 +00:00
.and.have.property('code', 'ERR_FILE_NOT_FOUND');
});
// Temporarily disable on WOA until
// https://github.com/electron/electron/issues/20008 is resolved
2020-03-20 20:28:31 +00:00
const testFn = (process.platform === 'win32' && process.arch === 'arm64' ? it.skip : it);
testFn('rejects when loading fails due to DNS not resolved', async () => {
await expect(w.loadURL('https://err.name.not.resolved')).to.eventually.be.rejected()
2020-03-20 20:28:31 +00:00
.and.have.property('code', 'ERR_NAME_NOT_RESOLVED');
});
it('rejects when navigation is cancelled due to a bad scheme', async () => {
await expect(w.loadURL('bad-scheme://foo')).to.eventually.be.rejected()
2020-03-20 20:28:31 +00:00
.and.have.property('code', 'ERR_FAILED');
});
it('sets appropriate error information on rejection', async () => {
2020-03-20 20:28:31 +00:00
let err;
try {
2020-03-20 20:28:31 +00:00
await w.loadURL('file:non-existent');
} catch (e) {
2020-03-20 20:28:31 +00:00
err = e;
}
2020-03-20 20:28:31 +00:00
expect(err).not.to.be.null();
expect(err.code).to.eql('ERR_FILE_NOT_FOUND');
expect(err.errno).to.eql(-6);
expect(err.url).to.eql(process.platform === 'win32' ? 'file://non-existent/' : 'file:///non-existent');
});
it('rejects if the load is aborted', async () => {
2020-03-20 20:28:31 +00:00
const s = http.createServer(() => { /* never complete the request */ });
await new Promise<void>(resolve => s.listen(0, '127.0.0.1', resolve));
2020-03-20 20:28:31 +00:00
const { port } = s.address() as AddressInfo;
const p = expect(w.loadURL(`http://127.0.0.1:${port}`)).to.eventually.be.rejectedWith(Error, /ERR_ABORTED/);
// load a different file before the first load completes, causing the
// first load to be aborted.
2020-03-20 20:28:31 +00:00
await w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'));
await p;
s.close();
});
it("doesn't reject when a subframe fails to load", async () => {
2020-03-20 20:28:31 +00:00
let resp = null as unknown as http.ServerResponse;
const s = http.createServer((req, res) => {
2020-03-20 20:28:31 +00:00
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<iframe src="http://err.name.not.resolved"></iframe>');
resp = res;
// don't end the response yet
2020-03-20 20:28:31 +00:00
});
await new Promise<void>(resolve => s.listen(0, '127.0.0.1', resolve));
2020-03-20 20:28:31 +00:00
const { port } = s.address() as AddressInfo;
const p = new Promise<void>(resolve => {
2019-11-01 20:37:02 +00:00
w.webContents.on('did-fail-load', (event, errorCode, errorDescription, validatedURL, isMainFrame) => {
if (!isMainFrame) {
2020-03-20 20:28:31 +00:00
resolve();
}
2020-03-20 20:28:31 +00:00
});
});
const main = w.loadURL(`http://127.0.0.1:${port}`);
await p;
resp.end();
await main;
s.close();
});
it("doesn't resolve when a subframe loads", async () => {
2020-03-20 20:28:31 +00:00
let resp = null as unknown as http.ServerResponse;
const s = http.createServer((req, res) => {
2020-03-20 20:28:31 +00:00
res.writeHead(200, { 'Content-Type': 'text/html' });
chore: bump chromium to ec5bc1743792d64724693eb357083 (master) (#24984) * chore: bump chromium in DEPS to cbdeef954dfc34e94c8ca9cf72ad326b4a121158 * chore: bump chromium in DEPS to 29723f905baeab1d4228eef2c31cdb341ebeffe0 * chore: bump chromium in DEPS to 44d6d78e852137fff58c14ed26ab1e803e5bf822 * update patches * chore: bump chromium in DEPS to 8a3a0fccb39d6b8334c9a0496c0d5056e50cdb3f * chore: update patches * refactor: fix PrintBackend::CreateInstance() calls Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2354541 * chore: bump chromium in DEPS to b9ebec3bcb1cabdd1426f367636f54cc98e0500e * chore: remove patches to code that was deleted upstream CL: https://chromium-review.googlesource.com/c/chromium/src/+/2360314 * Remove uses of kCGColorSpaceITUR_2020_PQ_EOTF/HLG CL: https://chromium-review.googlesource.com/c/chromium/src/+/2363950 just garden variety code shear * chore: update patch indices * Move ColorModel to //printing/mojom/print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2355083 sync with printing ColorModel changes: moved to mojo, different naming scheme * chore: bump chromium in DEPS to 56c4b4d2ce5ba941acd2e0fdb5100e8a48847134 * chore: bump chromium in DEPS to 130501f220b684a79dc82c17e236e63ac1f2a093 * Convert PrintHostMsg_DidGetPrintedPagesCount to Mojo https://chromium-review.googlesource.com/c/chromium/src/+/2326857 Update argument list to Print() * chore: update patch indices * DumpAccTree: convert utf16 to utf8 in PropertyFilter https://chromium-review.googlesource.com/c/chromium/src/+/2360218 * chore: bump chromium in DEPS to 3058368c6646e0dc8be6f8ea838b0343428b7998 * chore: bump chromium in DEPS to f51b4e6555364363c61438dac7afd988c8347bfc * chore: bump chromium in DEPS to 2dcc6f8fc23ac41b2499eb69dee0b4017e9d1046 * update patches * chore: bump chromium in DEPS to 2d8e98ecedc7e4905540b053bc1c87e964715be5 * update patches * 2345900: Move content::RecordContentToVisibleTimeRequest struct to mojo https://chromium-review.googlesource.com/c/chromium/src/+/2345900 * update patches * 2345900: Move content::RecordContentToVisibleTimeRequest struct to mojo https://chromium-review.googlesource.com/c/chromium/src/+/2345900 * 2367394: Remove net::LOAD_DO_NOT_SEND_COOKIES and net::LOAD_DO_NOT_SEND_AUTH_DATA. https://chromium-review.googlesource.com/c/chromium/src/+/2367394 * 2373227: [XProto] Consolidate all <X11/*> includes to //ui/gfx/x/x11.h https://chromium-review.googlesource.com/c/chromium/src/+/2373227 * fixup! 2373227: [XProto] Consolidate all <X11/*> includes to //ui/gfx/x/x11.h * chore: bump chromium in DEPS to c090e3f960520cbd2328608b97f87238c76d6143 * update patches * chore: bump chromium in DEPS to 13a25e0a755de9a14271022c595f3d2e29829e1a * chore: bump chromium in DEPS to 6adbb767b012c41efaeab0d1bdbb3eefed0977bc * chore: bump chromium in DEPS to 339ec5455c5932ef1322ea9953a6349b0732199e * chore: bump chromium in DEPS to 20291807c33f7ef4ef4f57d62075e099b027bfe6 * chore: bump chromium in DEPS to 226fbd1b8b17d4ac84fdb9548ef3a1c646878d47 * update patches * fixup disable_color_correct_rendering patch * chore: bump chromium in DEPS to 577c45979cad4359f2e206d68efd9317d3d79315 * update patches * viz: Rename RenderPass to CompositorRenderPass (and related types). https://chromium-review.googlesource.com/c/chromium/src/+/2380730 * chore: bump chromium in DEPS to 37e2ad5303f2c03a1b5d8eda65341bf2561196cd * update patches * add kOmitCookies_Electron * update patch * chore: bump chromium in DEPS to 256e42409ea63a7e71016de07818a983a97db463 * update patches * fix worker script ready hook https://chromium-review.googlesource.com/c/chromium/src/+/2335713 * Fixup printing page ranges patch * [printing] Move PrintMsg_PrintPages_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2340854 * Add MIME sniffer overloads that take base::StringPieces https://chromium-review.googlesource.com/c/chromium/src/+/2382896 * [printing] Move PrintHostMsg_PreviewIds to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2379455 * fixup test due to new DCHECK https://chromium-review.googlesource.com/c/chromium/src/+/2333750 * stop sending cookies when useSessionCookies is false * chore: bump chromium in DEPS to dd429dbc556449951ee8160d8a4d61fd95a139d5 * update patches * chore: bump chromium in DEPS to 5202bde3f9f44c2065f5dacf27e7000dd19e4e4d * chore: bump chromium in DEPS to 099e8e07b89da65932431bb0fd51b6f7f5344c19 * chore: bump chromium in DEPS to 104e5da2a43b759732d5b94bfc750b3a9a639653 * chore: bump chromium in DEPS to a4519ce657af25834e355315fd7fefa77b13426a * update patches * Make FileURLLoaderFactory always owned by its |receivers_|. https://chromium-review.googlesource.com/c/chromium/src/+/2337411 * Make FileURLLoaderFactory always owned by its |receivers_|. https://chromium-review.googlesource.com/c/chromium/src/+/2337411 * chore: bump chromium in DEPS to 1b62e9e8c8eaf6b8e3a9c77ee67a4c1bfa6a4d6b * chore: update patches * fixup! Make FileURLLoaderFactory always owned by its |receivers_|. * chore: update patches - mac: Disable CoreServices _CSCheckFix. https://chromium-review.googlesource.com/c/chromium/src/+/2401334 - [XProto] Remove bad DCHECK in x11_error_tracker.cc https://chromium-review.googlesource.com/c/chromium/src/+/2402304 - Move content/browser/frame_host/* over to content/browser/renderer_host/ https://chromium-review.googlesource.com/c/chromium/src/+/2401303 * Refactor WebContentSettingsClient to dedupe AllowXYZ methods https://chromium-review.googlesource.com/c/chromium/src/+/2353552 * Introduce NonNetworkURLLoaderFactoryBase class. https://chromium-review.googlesource.com/c/chromium/src/+/2357559 * [XProto] Remove usage of all Xlib headers https://chromium-review.googlesource.com/c/chromium/src/+/2392140 * fixup! chore: update patches * chore: bump chromium in DEPS to c1df55fbeb8207d036a604f59e4ea4e8ee79930a * chore: update patches * Move content::WebPreferences struct to Blink https://chromium-review.googlesource.com/c/chromium/src/+/2397670 * chore: bump chromium in DEPS to 57a23ec4884fff6c2f8d9b8536131cdc9b551ec2 * Set appid on Pip windows. https://chromium-review.googlesource.com/c/chromium/src/+/2388274 * fixup! Set appid on Pip windows. * fix: add a patch to remove deprecated factory * chore: bump chromium in DEPS to 1a9ddb7ea43955877823d5c4dcbf241b64228635 * fix compilation on windows * chore: bump chromium in DEPS to 234e6c6a77f61ffad9335099d9b13892cf88fd44 * chore: update patches * chore: bump chromium in DEPS to 7631eb0a9f57a8a47d3c28e1d265961b3a4d6b2b * chore: update patches * chore: bump chromium in DEPS to f9c34cd485845b95c2d17a7f55fdf92cda9a1b3a * chore: update patches * chore: implement GetSurveyAPIKey Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2362182 * chore: replace CreateWebUIURLLoader with CreateWebUIURLLoaderFactory Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2358309 * chore: bump chromium in DEPS to 5bdbd2373da884adf41c087be1465fcc344d168c * chore: update node patches for common.gypi * chore: update patches * chore: non_network_url_loader_factory_base was moved Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2357431 * 2415752: Reland "Reland "OOR-CORS: Remove BlinkCORS supporting code outside Blink"" Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2415752 * chore: bump chromium in DEPS to b943d006a33ec5bc1743792d64724693eb357083 * fix: replace x11::None with x11::Window::None * chore: update patches * chore: update patches * fix: cast x11::Window to int * 2402123: Use end date when deleting http auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2402123 * 2320268: Migrate DragHostMsg_StartDragging to Mojo Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2320268 * 2401303: Move content/browser/frame_host/* over to content/browser/renderer_host/ https://chromium-review.googlesource.com/c/chromium/src/+/2401303 * chore: fix lint * chore: fix build * Update config.yml Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: Samuel Attard <sattard@slack-corp.com>
2020-09-21 08:00:36 +00:00
res.write('<iframe src="about:blank"></iframe>');
2020-03-20 20:28:31 +00:00
resp = res;
// don't end the response yet
2020-03-20 20:28:31 +00:00
});
await new Promise<void>(resolve => s.listen(0, '127.0.0.1', resolve));
2020-03-20 20:28:31 +00:00
const { port } = s.address() as AddressInfo;
const p = new Promise<void>(resolve => {
2019-11-01 20:37:02 +00:00
w.webContents.on('did-frame-finish-load', (event, isMainFrame) => {
if (!isMainFrame) {
2020-03-20 20:28:31 +00:00
resolve();
}
2020-03-20 20:28:31 +00:00
});
});
const main = w.loadURL(`http://127.0.0.1:${port}`);
await p;
resp.destroy(); // cause the main request to fail
await expect(main).to.eventually.be.rejected()
2020-03-20 20:28:31 +00:00
.and.have.property('errno', -355); // ERR_INCOMPLETE_CHUNKED_ENCODING
s.close();
});
});
describe('getFocusedWebContents() API', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
2020-03-20 20:28:31 +00:00
const testFn = (process.platform === 'win32' && process.arch === 'arm64' ? it.skip : it);
testFn('returns the focused web contents', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: true });
await w.loadFile(path.join(__dirname, 'fixtures', 'blank.html'));
2020-03-20 20:28:31 +00:00
expect(webContents.getFocusedWebContents().id).to.equal(w.webContents.id);
const devToolsOpened = emittedOnce(w.webContents, 'devtools-opened');
w.webContents.openDevTools();
await devToolsOpened;
expect(webContents.getFocusedWebContents().id).to.equal(w.webContents.devToolsWebContents!.id);
2020-03-20 20:28:31 +00:00
const devToolsClosed = emittedOnce(w.webContents, 'devtools-closed');
w.webContents.closeDevTools();
await devToolsClosed;
expect(webContents.getFocusedWebContents().id).to.equal(w.webContents.id);
});
it('does not crash when called on a detached dev tools window', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: true });
2020-03-20 20:28:31 +00:00
w.webContents.openDevTools({ mode: 'detach' });
w.webContents.inspectElement(100, 100);
// For some reason we have to wait for two focused events...?
2020-03-20 20:28:31 +00:00
await emittedOnce(w.webContents, 'devtools-focused');
2020-03-20 20:28:31 +00:00
expect(() => { webContents.getFocusedWebContents(); }).to.not.throw();
// Work around https://github.com/electron/electron/issues/19985
2020-06-26 20:59:54 +00:00
await delay();
2020-03-20 20:28:31 +00:00
const devToolsClosed = emittedOnce(w.webContents, 'devtools-closed');
w.webContents.closeDevTools();
await devToolsClosed;
expect(() => { webContents.getFocusedWebContents(); }).to.not.throw();
});
});
describe('setDevToolsWebContents() API', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('sets arbitrary webContents as devtools', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const devtools = new BrowserWindow({ show: false });
const promise = emittedOnce(devtools.webContents, 'dom-ready');
w.webContents.setDevToolsWebContents(devtools.webContents);
w.webContents.openDevTools();
await promise;
expect(devtools.webContents.getURL().startsWith('devtools://devtools')).to.be.true();
const result = await devtools.webContents.executeJavaScript('InspectorFrontendHost.constructor.name');
expect(result).to.equal('InspectorFrontendHostImpl');
devtools.destroy();
});
});
describe('isFocused() API', () => {
it('returns false when the window is hidden', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
expect(w.isVisible()).to.be.false();
expect(w.webContents.isFocused()).to.be.false();
});
});
describe('isCurrentlyAudible() API', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('returns whether audio is playing', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
await w.webContents.executeJavaScript(`
window.context = new AudioContext
// Start in suspended state, because of the
// new web audio api policy.
context.suspend()
window.oscillator = context.createOscillator()
oscillator.connect(context.destination)
oscillator.start()
2020-03-20 20:28:31 +00:00
`);
let p = emittedOnce(w.webContents, '-audio-state-changed');
w.webContents.executeJavaScript('context.resume()');
await p;
expect(w.webContents.isCurrentlyAudible()).to.be.true();
p = emittedOnce(w.webContents, '-audio-state-changed');
w.webContents.executeJavaScript('oscillator.stop()');
await p;
expect(w.webContents.isCurrentlyAudible()).to.be.false();
});
});
describe('openDevTools() API', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('can show window with activation', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const focused = emittedOnce(w, 'focus');
w.show();
await focused;
expect(w.isFocused()).to.be.true();
chore: bump chromium to 93.0.4530.0 (master) (#29256) * chore: bump chromium in DEPS to 92.0.4512.6 * 2887336: [CaptureHandle][#2] Propagate CaptureHandleConfig in browser process https://chromium-review.googlesource.com/c/chromium/src/+/2887336 * refactor: base::Optional -> absl::optional * chore: fixup patch indices * chore: bump chromium in DEPS to 92.0.4514.0 * 2899417: Make build work when enable_pdf is set to false. https://chromium-review.googlesource.com/c/chromium/src/+/2899417 * 2904731: use BrowserContext instead of Profile in PreconnectManager https://chromium-review.googlesource.com/c/chromium/src/+/2904731 * 2295749: fix: check IsSecureEventInputEnabled in constructor before setting SetPasswordInputEnabled to true https://chromium-review.googlesource.com/c/chromium/src/+/2295749 * 2893803: Add a GetWebView to RenderFrame. https://chromium-review.googlesource.com/c/chromium/src/+/2893803 * 2892345: Implement WebContents::ForEachRenderFrameHost https://chromium-review.googlesource.com/c/chromium/src/+/2892345 * chore: fixup patch indices * 2892048: Real instance methods for BrowserContext: remaining 5 methods. https://chromium-review.googlesource.com/c/chromium/src/+/2892048 * 2902821: [mojo] Don't require full header includes for referenced interfaces https://chromium-review.googlesource.com/c/chromium/src/+/2902821 * 2496500: Remove last deprecated extension Event ctor. https://chromium-review.googlesource.com/c/chromium/src/+/2496500 * chore: fixup malformed pepper support patch * chore: bump chromium in DEPS to 92.0.4515.0 * 2908461: Add CreateEmptyPrintPagesParamsPtr() inside print_view_manager_base.cc. https://chromium-review.googlesource.com/c/chromium/src/+/2908461 * 2880838: viz: add optional HDRMetadata to TransferableResource https://chromium-review.googlesource.com/c/chromium/src/+/2880838 * chore: fixup patch indices * chore: bump chromium in DEPS to 92.0.4515.5 * chore: update patches * chore: bump chromium in DEPS to 92.0.4515.7 * chore: bump chromium in DEPS to 92.0.4515.9 * chore: bump chromium in DEPS to 93.0.4522.0 * chore: bump chromium in DEPS to 93.0.4523.0 * chore: bump chromium in DEPS to 93.0.4524.0 * chore: update patches * chore: enable_pak_file_integrity_checks was reverted * chore: update patches * refactor: base/optional was replaced with absl::optional Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace all usages of base::nullopt with absl::nullopt Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * chore: add missing base::Contains include Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace all usages of base::make_optional with absl::make_optional Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace WorldScriptContext() with GetScriptContextFromWorldId Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2893213 * chore: clean up left over opening namespace Refs: https://github.com/electron/electron/commit/95bfe6d08f65471394fb3005dbfa177cdf71210a * chore: add missing base::Contains include Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace GetCurrentDisplayIterator with the hard checker GetCurrentDisplay This code looks suspicious but if the iterator was invalid before it will also be invalid now. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2893191 * refactor: headers are now passed directly in extensions client Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2918906 * refactor: base::DictionaryValue::empty() has been removed Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2912424 * chore: add missing includes for network URLLoaderFactory Refs: unknown, probably a side effect of header changes * refactor: make convenience wrapper around AppendArg There is no converter FromV8 for base::StringPiece (apparently its not possible). So we now take in an std::string and use the construct for StringPiece to do implicit conversion. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2905544 * chore: add patch * chore: bump chromium in DEPS to 93.0.4525.0 * chore: update patches * refactor: CanResize has been de-virtualized Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2485774 * chore: update resource integrity patch * chore: add character encoding idl patch * chore: bump chromium in DEPS to 93.0.4526.0 * chore: update patches * chore: bump chromium in DEPS to 93.0.4527.0 * chore: bump chromium in DEPS to 93.0.4528.0 * chore: update patches * chore: update idl encoding patch * chore: bump chromium in DEPS to 93.0.4529.0 * chore: update patches * chore: bump chromium in DEPS to 93.0.4530.0 * chore: update patches * fix: only SetCanResize after the widget has been initialized * chore: add patch for vr on windows gn gen * spec: fix focus related tests on linux due to delay in focus swap * chore: remove new usages of base::Optional from main Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <sattard@slack-corp.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2021-06-03 08:05:04 +00:00
const blurred = emittedOnce(w, 'blur');
2020-03-20 20:28:31 +00:00
w.webContents.openDevTools({ mode: 'detach', activate: true });
await Promise.all([
emittedOnce(w.webContents, 'devtools-opened'),
2019-11-01 20:37:02 +00:00
emittedOnce(w.webContents, 'devtools-focused')
2020-03-20 20:28:31 +00:00
]);
chore: bump chromium to 93.0.4530.0 (master) (#29256) * chore: bump chromium in DEPS to 92.0.4512.6 * 2887336: [CaptureHandle][#2] Propagate CaptureHandleConfig in browser process https://chromium-review.googlesource.com/c/chromium/src/+/2887336 * refactor: base::Optional -> absl::optional * chore: fixup patch indices * chore: bump chromium in DEPS to 92.0.4514.0 * 2899417: Make build work when enable_pdf is set to false. https://chromium-review.googlesource.com/c/chromium/src/+/2899417 * 2904731: use BrowserContext instead of Profile in PreconnectManager https://chromium-review.googlesource.com/c/chromium/src/+/2904731 * 2295749: fix: check IsSecureEventInputEnabled in constructor before setting SetPasswordInputEnabled to true https://chromium-review.googlesource.com/c/chromium/src/+/2295749 * 2893803: Add a GetWebView to RenderFrame. https://chromium-review.googlesource.com/c/chromium/src/+/2893803 * 2892345: Implement WebContents::ForEachRenderFrameHost https://chromium-review.googlesource.com/c/chromium/src/+/2892345 * chore: fixup patch indices * 2892048: Real instance methods for BrowserContext: remaining 5 methods. https://chromium-review.googlesource.com/c/chromium/src/+/2892048 * 2902821: [mojo] Don't require full header includes for referenced interfaces https://chromium-review.googlesource.com/c/chromium/src/+/2902821 * 2496500: Remove last deprecated extension Event ctor. https://chromium-review.googlesource.com/c/chromium/src/+/2496500 * chore: fixup malformed pepper support patch * chore: bump chromium in DEPS to 92.0.4515.0 * 2908461: Add CreateEmptyPrintPagesParamsPtr() inside print_view_manager_base.cc. https://chromium-review.googlesource.com/c/chromium/src/+/2908461 * 2880838: viz: add optional HDRMetadata to TransferableResource https://chromium-review.googlesource.com/c/chromium/src/+/2880838 * chore: fixup patch indices * chore: bump chromium in DEPS to 92.0.4515.5 * chore: update patches * chore: bump chromium in DEPS to 92.0.4515.7 * chore: bump chromium in DEPS to 92.0.4515.9 * chore: bump chromium in DEPS to 93.0.4522.0 * chore: bump chromium in DEPS to 93.0.4523.0 * chore: bump chromium in DEPS to 93.0.4524.0 * chore: update patches * chore: enable_pak_file_integrity_checks was reverted * chore: update patches * refactor: base/optional was replaced with absl::optional Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace all usages of base::nullopt with absl::nullopt Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * chore: add missing base::Contains include Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace all usages of base::make_optional with absl::make_optional Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace WorldScriptContext() with GetScriptContextFromWorldId Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2893213 * chore: clean up left over opening namespace Refs: https://github.com/electron/electron/commit/95bfe6d08f65471394fb3005dbfa177cdf71210a * chore: add missing base::Contains include Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2910202 * refactor: replace GetCurrentDisplayIterator with the hard checker GetCurrentDisplay This code looks suspicious but if the iterator was invalid before it will also be invalid now. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2893191 * refactor: headers are now passed directly in extensions client Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2918906 * refactor: base::DictionaryValue::empty() has been removed Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2912424 * chore: add missing includes for network URLLoaderFactory Refs: unknown, probably a side effect of header changes * refactor: make convenience wrapper around AppendArg There is no converter FromV8 for base::StringPiece (apparently its not possible). So we now take in an std::string and use the construct for StringPiece to do implicit conversion. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2905544 * chore: add patch * chore: bump chromium in DEPS to 93.0.4525.0 * chore: update patches * refactor: CanResize has been de-virtualized Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2485774 * chore: update resource integrity patch * chore: add character encoding idl patch * chore: bump chromium in DEPS to 93.0.4526.0 * chore: update patches * chore: bump chromium in DEPS to 93.0.4527.0 * chore: bump chromium in DEPS to 93.0.4528.0 * chore: update patches * chore: update idl encoding patch * chore: bump chromium in DEPS to 93.0.4529.0 * chore: update patches * chore: bump chromium in DEPS to 93.0.4530.0 * chore: update patches * fix: only SetCanResize after the widget has been initialized * chore: add patch for vr on windows gn gen * spec: fix focus related tests on linux due to delay in focus swap * chore: remove new usages of base::Optional from main Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <sattard@slack-corp.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2021-06-03 08:05:04 +00:00
await blurred;
2020-03-20 20:28:31 +00:00
expect(w.isFocused()).to.be.false();
});
it('can show window without activation', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const devtoolsOpened = emittedOnce(w.webContents, 'devtools-opened');
w.webContents.openDevTools({ mode: 'detach', activate: false });
await devtoolsOpened;
expect(w.webContents.isDevToolsOpened()).to.be.true();
});
});
describe('before-input-event event', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('can prevent document keyboard events', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
2020-03-20 20:28:31 +00:00
await w.loadFile(path.join(fixturesPath, 'pages', 'key-events.html'));
const keyDown = new Promise(resolve => {
2020-03-20 20:28:31 +00:00
ipcMain.once('keydown', (event, key) => resolve(key));
});
w.webContents.once('before-input-event', (event, input) => {
2020-03-20 20:28:31 +00:00
if (input.key === 'a') event.preventDefault();
});
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'a' });
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'b' });
expect(await keyDown).to.equal('b');
});
it('has the correct properties', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'));
const testBeforeInput = async (opts: any) => {
2020-03-20 20:28:31 +00:00
const modifiers = [];
if (opts.shift) modifiers.push('shift');
if (opts.control) modifiers.push('control');
if (opts.alt) modifiers.push('alt');
if (opts.meta) modifiers.push('meta');
if (opts.isAutoRepeat) modifiers.push('isAutoRepeat');
const p = emittedOnce(w.webContents, 'before-input-event');
w.webContents.sendInputEvent({
type: opts.type,
keyCode: opts.keyCode,
modifiers: modifiers as any
2020-03-20 20:28:31 +00:00
});
const [, input] = await p;
expect(input.type).to.equal(opts.type);
expect(input.key).to.equal(opts.key);
expect(input.code).to.equal(opts.code);
expect(input.isAutoRepeat).to.equal(opts.isAutoRepeat);
expect(input.shift).to.equal(opts.shift);
expect(input.control).to.equal(opts.control);
expect(input.alt).to.equal(opts.alt);
expect(input.meta).to.equal(opts.meta);
};
await testBeforeInput({
type: 'keyDown',
key: 'A',
code: 'KeyA',
keyCode: 'a',
shift: true,
control: true,
alt: true,
meta: true,
isAutoRepeat: true
2020-03-20 20:28:31 +00:00
});
await testBeforeInput({
type: 'keyUp',
key: '.',
code: 'Period',
keyCode: '.',
shift: false,
control: true,
alt: true,
meta: false,
isAutoRepeat: false
2020-03-20 20:28:31 +00:00
});
await testBeforeInput({
type: 'keyUp',
key: '!',
code: 'Digit1',
keyCode: '1',
shift: true,
control: false,
alt: false,
meta: true,
isAutoRepeat: false
2020-03-20 20:28:31 +00:00
});
await testBeforeInput({
type: 'keyUp',
key: 'Tab',
code: 'Tab',
keyCode: 'Tab',
shift: false,
control: true,
alt: false,
meta: false,
isAutoRepeat: true
2020-03-20 20:28:31 +00:00
});
});
});
// On Mac, zooming isn't done with the mouse wheel.
ifdescribe(process.platform !== 'darwin')('zoom-changed', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('is emitted with the correct zoom-in info', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'));
const testZoomChanged = async () => {
w.webContents.sendInputEvent({
type: 'mouseWheel',
x: 300,
y: 300,
deltaX: 0,
deltaY: 1,
wheelTicksX: 0,
wheelTicksY: 1,
modifiers: ['control', 'meta']
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
const [, zoomDirection] = await emittedOnce(w.webContents, 'zoom-changed');
expect(zoomDirection).to.equal('in');
2020-03-20 20:28:31 +00:00
};
await testZoomChanged();
});
it('is emitted with the correct zoom-out info', async () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'));
const testZoomChanged = async () => {
w.webContents.sendInputEvent({
type: 'mouseWheel',
x: 300,
y: 300,
deltaX: 0,
deltaY: -1,
wheelTicksX: 0,
wheelTicksY: -1,
modifiers: ['control', 'meta']
});
const [, zoomDirection] = await emittedOnce(w.webContents, 'zoom-changed');
expect(zoomDirection).to.equal('out');
};
await testZoomChanged();
2020-03-20 20:28:31 +00:00
});
});
describe('sendInputEvent(event)', () => {
2020-03-20 20:28:31 +00:00
let w: BrowserWindow;
beforeEach(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
2020-03-20 20:28:31 +00:00
await w.loadFile(path.join(fixturesPath, 'pages', 'key-events.html'));
});
afterEach(closeAllWindows);
it('can send keydown events', async () => {
const keydown = emittedOnce(ipcMain, 'keydown');
2020-03-20 20:28:31 +00:00
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'A' });
const [, key, code, keyCode, shiftKey, ctrlKey, altKey] = await keydown;
expect(key).to.equal('a');
expect(code).to.equal('KeyA');
expect(keyCode).to.equal(65);
expect(shiftKey).to.be.false();
expect(ctrlKey).to.be.false();
expect(altKey).to.be.false();
2020-03-20 20:28:31 +00:00
});
it('can send keydown events with modifiers', async () => {
const keydown = emittedOnce(ipcMain, 'keydown');
2020-03-20 20:28:31 +00:00
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Z', modifiers: ['shift', 'ctrl'] });
const [, key, code, keyCode, shiftKey, ctrlKey, altKey] = await keydown;
expect(key).to.equal('Z');
expect(code).to.equal('KeyZ');
expect(keyCode).to.equal(90);
expect(shiftKey).to.be.true();
expect(ctrlKey).to.be.true();
expect(altKey).to.be.false();
2020-03-20 20:28:31 +00:00
});
it('can send keydown events with special keys', async () => {
const keydown = emittedOnce(ipcMain, 'keydown');
2020-03-20 20:28:31 +00:00
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab', modifiers: ['alt'] });
const [, key, code, keyCode, shiftKey, ctrlKey, altKey] = await keydown;
expect(key).to.equal('Tab');
expect(code).to.equal('Tab');
expect(keyCode).to.equal(9);
expect(shiftKey).to.be.false();
expect(ctrlKey).to.be.false();
expect(altKey).to.be.true();
2020-03-20 20:28:31 +00:00
});
it('can send char events', async () => {
const keypress = emittedOnce(ipcMain, 'keypress');
2020-03-20 20:28:31 +00:00
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'A' });
w.webContents.sendInputEvent({ type: 'char', keyCode: 'A' });
const [, key, code, keyCode, shiftKey, ctrlKey, altKey] = await keypress;
expect(key).to.equal('a');
expect(code).to.equal('KeyA');
expect(keyCode).to.equal(65);
expect(shiftKey).to.be.false();
expect(ctrlKey).to.be.false();
expect(altKey).to.be.false();
2020-03-20 20:28:31 +00:00
});
it('can send char events with modifiers', async () => {
const keypress = emittedOnce(ipcMain, 'keypress');
2020-03-20 20:28:31 +00:00
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Z' });
w.webContents.sendInputEvent({ type: 'char', keyCode: 'Z', modifiers: ['shift', 'ctrl'] });
const [, key, code, keyCode, shiftKey, ctrlKey, altKey] = await keypress;
expect(key).to.equal('Z');
expect(code).to.equal('KeyZ');
expect(keyCode).to.equal(90);
expect(shiftKey).to.be.true();
expect(ctrlKey).to.be.true();
expect(altKey).to.be.false();
2020-03-20 20:28:31 +00:00
});
});
describe('insertCSS', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('supports inserting CSS', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
await w.webContents.insertCSS('body { background-repeat: round; }');
const result = await w.webContents.executeJavaScript('window.getComputedStyle(document.body).getPropertyValue("background-repeat")');
expect(result).to.equal('round');
});
it('supports removing inserted CSS', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
const key = await w.webContents.insertCSS('body { background-repeat: round; }');
await w.webContents.removeInsertedCSS(key);
const result = await w.webContents.executeJavaScript('window.getComputedStyle(document.body).getPropertyValue("background-repeat")');
expect(result).to.equal('repeat');
});
});
describe('inspectElement()', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('supports inspecting an element in the devtools', (done) => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.once('devtools-opened', () => { done(); });
w.webContents.inspectElement(10, 10);
});
});
describe('startDrag({file, icon})', () => {
it('throws errors for a missing file or a missing/empty icon', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
expect(() => {
2020-03-20 20:28:31 +00:00
w.webContents.startDrag({ icon: path.join(fixturesPath, 'assets', 'logo.png') } as any);
}).to.throw('Must specify either \'file\' or \'files\' option');
expect(() => {
2020-03-20 20:28:31 +00:00
w.webContents.startDrag({ file: __filename } as any);
}).to.throw('\'icon\' parameter is required');
expect(() => {
w.webContents.startDrag({ file: __filename, icon: path.join(mainFixturesPath, 'blank.png') });
}).to.throw(/Failed to load image from path (.+)/);
2020-03-20 20:28:31 +00:00
});
});
describe('focus()', () => {
describe('when the web contents is hidden', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('does not blur the focused window', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
w.show();
await w.loadURL('about:blank');
w.focus();
const child = new BrowserWindow({ show: false });
child.loadURL('about:blank');
child.webContents.focus();
const currentFocused = w.isFocused();
const childFocused = child.isFocused();
child.close();
expect(currentFocused).to.be.true();
expect(childFocused).to.be.false();
});
});
});
describe('getOSProcessId()', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('returns a valid procress id', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
expect(w.webContents.getOSProcessId()).to.equal(0);
2020-03-20 20:28:31 +00:00
await w.loadURL('about:blank');
expect(w.webContents.getOSProcessId()).to.be.above(0);
});
});
describe('userAgent APIs', () => {
it('can set the user agent (functions)', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const userAgent = w.webContents.getUserAgent();
2020-03-20 20:28:31 +00:00
w.webContents.setUserAgent('my-user-agent');
expect(w.webContents.getUserAgent()).to.equal('my-user-agent');
2020-03-20 20:28:31 +00:00
w.webContents.setUserAgent(userAgent);
expect(w.webContents.getUserAgent()).to.equal(userAgent);
});
it('can set the user agent (properties)', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const userAgent = w.webContents.userAgent;
2020-03-20 20:28:31 +00:00
w.webContents.userAgent = 'my-user-agent';
expect(w.webContents.userAgent).to.equal('my-user-agent');
2020-03-20 20:28:31 +00:00
w.webContents.userAgent = userAgent;
expect(w.webContents.userAgent).to.equal(userAgent);
});
});
describe('audioMuted APIs', () => {
it('can set the audio mute level (functions)', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
2020-03-20 20:28:31 +00:00
w.webContents.setAudioMuted(true);
expect(w.webContents.isAudioMuted()).to.be.true();
2020-03-20 20:28:31 +00:00
w.webContents.setAudioMuted(false);
expect(w.webContents.isAudioMuted()).to.be.false();
});
it('can set the audio mute level (functions)', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
2020-03-20 20:28:31 +00:00
w.webContents.audioMuted = true;
expect(w.webContents.audioMuted).to.be.true();
2020-03-20 20:28:31 +00:00
w.webContents.audioMuted = false;
expect(w.webContents.audioMuted).to.be.false();
});
});
describe('zoom api', () => {
2020-03-20 20:28:31 +00:00
const scheme = (global as any).standardScheme;
const hostZoomMap: Record<string, number> = {
host1: 0.3,
host2: 0.7,
host3: 0.2
2020-03-20 20:28:31 +00:00
};
before(() => {
2020-03-20 20:28:31 +00:00
const protocol = session.defaultSession.protocol;
protocol.registerStringProtocol(scheme, (request, callback) => {
const response = `<script>
const {ipcRenderer} = require('electron')
ipcRenderer.send('set-zoom', window.location.hostname)
ipcRenderer.on(window.location.hostname + '-zoom-set', () => {
ipcRenderer.send(window.location.hostname + '-zoom-level')
})
2020-03-20 20:28:31 +00:00
</script>`;
callback({ data: response, mimeType: 'text/html' });
});
2020-03-20 20:28:31 +00:00
});
after(() => {
2020-03-20 20:28:31 +00:00
const protocol = session.defaultSession.protocol;
protocol.unregisterProtocol(scheme);
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('throws on an invalid zoomFactor', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
await w.loadURL('about:blank');
expect(() => {
2020-03-20 20:28:31 +00:00
w.webContents.setZoomFactor(0.0);
}).to.throw(/'zoomFactor' must be a double greater than 0.0/);
expect(() => {
2020-03-20 20:28:31 +00:00
w.webContents.setZoomFactor(-2.0);
}).to.throw(/'zoomFactor' must be a double greater than 0.0/);
});
it('can set the correct zoom level (functions)', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
try {
2020-03-20 20:28:31 +00:00
await w.loadURL('about:blank');
const zoomLevel = w.webContents.getZoomLevel();
expect(zoomLevel).to.eql(0.0);
w.webContents.setZoomLevel(0.5);
const newZoomLevel = w.webContents.getZoomLevel();
expect(newZoomLevel).to.eql(0.5);
} finally {
2020-03-20 20:28:31 +00:00
w.webContents.setZoomLevel(0);
}
2020-03-20 20:28:31 +00:00
});
it('can set the correct zoom level (properties)', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
try {
2020-03-20 20:28:31 +00:00
await w.loadURL('about:blank');
const zoomLevel = w.webContents.zoomLevel;
expect(zoomLevel).to.eql(0.0);
w.webContents.zoomLevel = 0.5;
const newZoomLevel = w.webContents.zoomLevel;
expect(newZoomLevel).to.eql(0.5);
} finally {
2020-03-20 20:28:31 +00:00
w.webContents.zoomLevel = 0;
}
2020-03-20 20:28:31 +00:00
});
it('can set the correct zoom factor (functions)', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
try {
2020-03-20 20:28:31 +00:00
await w.loadURL('about:blank');
const zoomFactor = w.webContents.getZoomFactor();
expect(zoomFactor).to.eql(1.0);
2020-03-20 20:28:31 +00:00
w.webContents.setZoomFactor(0.5);
const newZoomFactor = w.webContents.getZoomFactor();
expect(newZoomFactor).to.eql(0.5);
} finally {
2020-03-20 20:28:31 +00:00
w.webContents.setZoomFactor(1.0);
}
2020-03-20 20:28:31 +00:00
});
it('can set the correct zoom factor (properties)', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
try {
2020-03-20 20:28:31 +00:00
await w.loadURL('about:blank');
const zoomFactor = w.webContents.zoomFactor;
expect(zoomFactor).to.eql(1.0);
2020-03-20 20:28:31 +00:00
w.webContents.zoomFactor = 0.5;
const newZoomFactor = w.webContents.zoomFactor;
expect(newZoomFactor).to.eql(0.5);
} finally {
2020-03-20 20:28:31 +00:00
w.webContents.zoomFactor = 1.0;
}
2020-03-20 20:28:31 +00:00
});
it('can persist zoom level across navigation', (done) => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
2020-03-20 20:28:31 +00:00
let finalNavigation = false;
ipcMain.on('set-zoom', (e, host) => {
2020-03-20 20:28:31 +00:00
const zoomLevel = hostZoomMap[host];
if (!finalNavigation) w.webContents.zoomLevel = zoomLevel;
e.sender.send(`${host}-zoom-set`);
});
ipcMain.on('host1-zoom-level', (e) => {
try {
const zoomLevel = e.sender.getZoomLevel();
const expectedZoomLevel = hostZoomMap.host1;
expect(zoomLevel).to.equal(expectedZoomLevel);
if (finalNavigation) {
done();
} else {
w.loadURL(`${scheme}://host2`);
}
} catch (e) {
done(e);
}
2020-03-20 20:28:31 +00:00
});
ipcMain.once('host2-zoom-level', (e) => {
try {
const zoomLevel = e.sender.getZoomLevel();
const expectedZoomLevel = hostZoomMap.host2;
expect(zoomLevel).to.equal(expectedZoomLevel);
finalNavigation = true;
w.webContents.goBack();
} catch (e) {
done(e);
}
2020-03-20 20:28:31 +00:00
});
w.loadURL(`${scheme}://host1`);
});
it('can propagate zoom level across same session', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
2020-03-20 20:28:31 +00:00
const w2 = new BrowserWindow({ show: false });
defer(() => {
2020-03-20 20:28:31 +00:00
w2.setClosable(true);
w2.close();
});
await w.loadURL(`${scheme}://host3`);
w.webContents.zoomLevel = hostZoomMap.host3;
await w2.loadURL(`${scheme}://host3`);
const zoomLevel1 = w.webContents.zoomLevel;
expect(zoomLevel1).to.equal(hostZoomMap.host3);
const zoomLevel2 = w2.webContents.zoomLevel;
expect(zoomLevel1).to.equal(zoomLevel2);
2020-03-20 20:28:31 +00:00
});
it('cannot propagate zoom level across different session', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
const w2 = new BrowserWindow({
show: false,
webPreferences: {
partition: 'temp'
}
2020-03-20 20:28:31 +00:00
});
const protocol = w2.webContents.session.protocol;
protocol.registerStringProtocol(scheme, (request, callback) => {
2020-03-20 20:28:31 +00:00
callback('hello');
});
defer(() => {
w2.setClosable(true);
w2.close();
protocol.unregisterProtocol(scheme);
});
await w.loadURL(`${scheme}://host3`);
w.webContents.zoomLevel = hostZoomMap.host3;
await w2.loadURL(`${scheme}://host3`);
const zoomLevel1 = w.webContents.zoomLevel;
expect(zoomLevel1).to.equal(hostZoomMap.host3);
const zoomLevel2 = w2.webContents.zoomLevel;
expect(zoomLevel2).to.equal(0);
expect(zoomLevel1).to.not.equal(zoomLevel2);
2020-03-20 20:28:31 +00:00
});
it('can persist when it contains iframe', (done) => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const server = http.createServer((req, res) => {
setTimeout(() => {
2020-03-20 20:28:31 +00:00
res.end();
}, 200);
});
server.listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
const url = 'http://127.0.0.1:' + (server.address() as AddressInfo).port;
const content = `<iframe src=${url}></iframe>`;
w.webContents.on('did-frame-finish-load', (e, isMainFrame) => {
if (!isMainFrame) {
try {
const zoomLevel = w.webContents.zoomLevel;
expect(zoomLevel).to.equal(2.0);
w.webContents.zoomLevel = 0;
done();
} catch (e) {
done(e);
} finally {
server.close();
}
}
2020-03-20 20:28:31 +00:00
});
w.webContents.on('dom-ready', () => {
2020-03-20 20:28:31 +00:00
w.webContents.zoomLevel = 2.0;
});
w.loadURL(`data:text/html,${content}`);
});
});
it('cannot propagate when used with webframe', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
const w2 = new BrowserWindow({ show: false });
const temporaryZoomSet = emittedOnce(ipcMain, 'temporary-zoom-set');
2020-03-20 20:28:31 +00:00
w.loadFile(path.join(fixturesPath, 'pages', 'webframe-zoom.html'));
await temporaryZoomSet;
const finalZoomLevel = w.webContents.getZoomLevel();
await w2.loadFile(path.join(fixturesPath, 'pages', 'c.html'));
const zoomLevel1 = w.webContents.zoomLevel;
const zoomLevel2 = w2.webContents.zoomLevel;
w2.setClosable(true);
w2.close();
expect(zoomLevel1).to.equal(finalZoomLevel);
expect(zoomLevel2).to.equal(0);
expect(zoomLevel1).to.not.equal(zoomLevel2);
2020-03-20 20:28:31 +00:00
});
describe('with unique domains', () => {
2020-03-20 20:28:31 +00:00
let server: http.Server;
let serverUrl: string;
let crossSiteUrl: string;
before((done) => {
server = http.createServer((req, res) => {
2020-03-20 20:28:31 +00:00
setTimeout(() => res.end('hey'), 0);
});
server.listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
serverUrl = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
crossSiteUrl = `http://localhost:${(server.address() as AddressInfo).port}`;
done();
});
});
after(() => {
2020-03-20 20:28:31 +00:00
server.close();
});
it('cannot persist zoom level after navigation with webFrame', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
const source = `
const {ipcRenderer, webFrame} = require('electron')
webFrame.setZoomLevel(0.6)
ipcRenderer.send('zoom-level-set', webFrame.getZoomLevel())
2020-03-20 20:28:31 +00:00
`;
const zoomLevelPromise = emittedOnce(ipcMain, 'zoom-level-set');
await w.loadURL(serverUrl);
await w.webContents.executeJavaScript(source);
let [, zoomLevel] = await zoomLevelPromise;
expect(zoomLevel).to.equal(0.6);
const loadPromise = emittedOnce(w.webContents, 'did-finish-load');
await w.loadURL(crossSiteUrl);
await loadPromise;
zoomLevel = w.webContents.zoomLevel;
expect(zoomLevel).to.equal(0);
});
});
});
describe('webrtc ip policy api', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('can set and get webrtc ip policies', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const policies = [
'default',
'default_public_interface_only',
'default_public_and_private_interfaces',
'disable_non_proxied_udp'
2020-03-20 20:28:31 +00:00
];
policies.forEach((policy) => {
2020-03-20 20:28:31 +00:00
w.webContents.setWebRTCIPHandlingPolicy(policy as any);
expect(w.webContents.getWebRTCIPHandlingPolicy()).to.equal(policy);
});
});
});
describe('render view deleted events', () => {
2020-03-20 20:28:31 +00:00
let server: http.Server;
let serverUrl: string;
let crossSiteUrl: string;
before((done) => {
server = http.createServer((req, res) => {
const respond = () => {
if (req.url === '/redirect-cross-site') {
2020-03-20 20:28:31 +00:00
res.setHeader('Location', `${crossSiteUrl}/redirected`);
res.statusCode = 302;
res.end();
} else if (req.url === '/redirected') {
2020-03-20 20:28:31 +00:00
res.end('<html><script>window.localStorage</script></html>');
} else if (req.url === '/first-window-open') {
res.end(`<html><script>window.open('${serverUrl}/second-window-open', 'first child');</script></html>`);
} else if (req.url === '/second-window-open') {
res.end('<html><script>window.open(\'wrong://url\', \'second child\');</script></html>');
} else {
2020-03-20 20:28:31 +00:00
res.end();
}
2020-03-20 20:28:31 +00:00
};
setTimeout(respond, 0);
});
server.listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
serverUrl = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
crossSiteUrl = `http://localhost:${(server.address() as AddressInfo).port}`;
done();
});
});
after(() => {
2020-03-20 20:28:31 +00:00
server.close();
});
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('does not emit current-render-view-deleted when speculative RVHs are deleted', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
let currentRenderViewDeletedEmitted = false;
const renderViewDeletedHandler = () => {
2020-03-20 20:28:31 +00:00
currentRenderViewDeletedEmitted = true;
};
w.webContents.on('current-render-view-deleted' as any, renderViewDeletedHandler);
w.webContents.on('did-finish-load', () => {
2020-03-20 20:28:31 +00:00
w.webContents.removeListener('current-render-view-deleted' as any, renderViewDeletedHandler);
w.close();
});
const destroyed = emittedOnce(w.webContents, 'destroyed');
2020-03-20 20:28:31 +00:00
w.loadURL(`${serverUrl}/redirect-cross-site`);
await destroyed;
expect(currentRenderViewDeletedEmitted).to.be.false('current-render-view-deleted was emitted');
2020-03-20 20:28:31 +00:00
});
it('does not emit current-render-view-deleted when speculative RVHs are deleted and nativeWindowOpen is set to true', async () => {
const parentWindow = new BrowserWindow({ show: false, webPreferences: { nativeWindowOpen: true } });
let currentRenderViewDeletedEmitted = false;
let childWindow: BrowserWindow | null = null;
const destroyed = emittedOnce(parentWindow.webContents, 'destroyed');
const renderViewDeletedHandler = () => {
currentRenderViewDeletedEmitted = true;
};
const childWindowCreated = new Promise<void>((resolve) => {
app.once('browser-window-created', (event, window) => {
childWindow = window;
window.webContents.on('current-render-view-deleted' as any, renderViewDeletedHandler);
resolve();
});
});
parentWindow.loadURL(`${serverUrl}/first-window-open`);
await childWindowCreated;
childWindow!.webContents.removeListener('current-render-view-deleted' as any, renderViewDeletedHandler);
parentWindow.close();
await destroyed;
expect(currentRenderViewDeletedEmitted).to.be.false('child window was destroyed');
});
it('emits current-render-view-deleted if the current RVHs are deleted', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
let currentRenderViewDeletedEmitted = false;
w.webContents.on('current-render-view-deleted' as any, () => {
2020-03-20 20:28:31 +00:00
currentRenderViewDeletedEmitted = true;
});
w.webContents.on('did-finish-load', () => {
2020-03-20 20:28:31 +00:00
w.close();
});
const destroyed = emittedOnce(w.webContents, 'destroyed');
2020-03-20 20:28:31 +00:00
w.loadURL(`${serverUrl}/redirect-cross-site`);
await destroyed;
expect(currentRenderViewDeletedEmitted).to.be.true('current-render-view-deleted wasn\'t emitted');
2020-03-20 20:28:31 +00:00
});
it('emits render-view-deleted if any RVHs are deleted', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
let rvhDeletedCount = 0;
w.webContents.on('render-view-deleted' as any, () => {
2020-03-20 20:28:31 +00:00
rvhDeletedCount++;
});
w.webContents.on('did-finish-load', () => {
2020-03-20 20:28:31 +00:00
w.close();
});
const destroyed = emittedOnce(w.webContents, 'destroyed');
2020-03-20 20:28:31 +00:00
w.loadURL(`${serverUrl}/redirect-cross-site`);
await destroyed;
const expectedRenderViewDeletedEventCount = 1;
expect(rvhDeletedCount).to.equal(expectedRenderViewDeletedEventCount, 'render-view-deleted wasn\'t emitted the expected nr. of times');
2020-03-20 20:28:31 +00:00
});
});
describe('setIgnoreMenuShortcuts(ignore)', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('does not throw', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
expect(() => {
2020-03-20 20:28:31 +00:00
w.webContents.setIgnoreMenuShortcuts(true);
w.webContents.setIgnoreMenuShortcuts(false);
}).to.not.throw();
});
});
const crashPrefs = [
{
nodeIntegration: true
},
{
sandbox: true
}
];
const nicePrefs = (o: any) => {
let s = '';
for (const key of Object.keys(o)) {
s += `${key}=${o[key]}, `;
}
return `(${s.slice(0, s.length - 2)})`;
};
for (const prefs of crashPrefs) {
describe(`crash with webPreferences ${nicePrefs(prefs)}`, () => {
let w: BrowserWindow;
beforeEach(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
await w.loadURL('about:blank');
});
afterEach(closeAllWindows);
it('isCrashed() is false by default', () => {
expect(w.webContents.isCrashed()).to.equal(false);
});
it('forcefullyCrashRenderer() crashes the process with reason=killed||crashed', async () => {
expect(w.webContents.isCrashed()).to.equal(false);
const crashEvent = emittedOnce(w.webContents, 'render-process-gone');
w.webContents.forcefullyCrashRenderer();
const [, details] = await crashEvent;
expect(details.reason === 'killed' || details.reason === 'crashed').to.equal(true, 'reason should be killed || crashed');
expect(w.webContents.isCrashed()).to.equal(true);
});
it('a crashed process is recoverable with reload()', async () => {
expect(w.webContents.isCrashed()).to.equal(false);
w.webContents.forcefullyCrashRenderer();
w.webContents.reload();
expect(w.webContents.isCrashed()).to.equal(false);
});
});
}
// Destroying webContents in its event listener is going to crash when
// Electron is built in Debug mode.
describe('destroy()', () => {
2020-03-20 20:28:31 +00:00
let server: http.Server;
let serverUrl: string;
before((done) => {
server = http.createServer((request, response) => {
switch (request.url) {
case '/net-error':
2020-03-20 20:28:31 +00:00
response.destroy();
break;
case '/200':
2020-03-20 20:28:31 +00:00
response.end();
break;
default:
2020-03-20 20:28:31 +00:00
done('unsupported endpoint');
}
}).listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
serverUrl = 'http://127.0.0.1:' + (server.address() as AddressInfo).port;
done();
});
});
after(() => {
2020-03-20 20:28:31 +00:00
server.close();
});
const events = [
{ name: 'did-start-loading', url: '/200' },
{ name: 'dom-ready', url: '/200' },
{ name: 'did-stop-loading', url: '/200' },
{ name: 'did-finish-load', url: '/200' },
// FIXME: Multiple Emit calls inside an observer assume that object
// will be alive till end of the observer. Synchronous `destroy` api
// violates this contract and crashes.
{ name: 'did-frame-finish-load', url: '/200' },
{ name: 'did-fail-load', url: '/net-error' }
2020-03-20 20:28:31 +00:00
];
for (const e of events) {
it(`should not crash when invoked synchronously inside ${e.name} handler`, async function () {
// This test is flaky on Windows CI and we don't know why, but the
// purpose of this test is to make sure Electron does not crash so it
// is fine to retry this test for a few times.
2020-03-20 20:28:31 +00:00
this.retries(3);
const contents = (webContents as any).create() as WebContents;
const originalEmit = contents.emit.bind(contents);
contents.emit = (...args) => { return originalEmit(...args); };
contents.once(e.name as any, () => (contents as any).destroy());
const destroyed = emittedOnce(contents, 'destroyed');
contents.loadURL(serverUrl + e.url);
await destroyed;
});
}
2020-03-20 20:28:31 +00:00
});
describe('did-change-theme-color event', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('is triggered with correct theme color', (done) => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: true });
let count = 0;
w.webContents.on('did-change-theme-color', (e, color) => {
try {
if (count === 0) {
count += 1;
expect(color).to.equal('#FFEEDD');
w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'));
} else if (count === 1) {
expect(color).to.be.null();
done();
}
} catch (e) {
done(e);
}
2020-03-20 20:28:31 +00:00
});
w.loadFile(path.join(fixturesPath, 'pages', 'theme-color.html'));
});
});
describe('console-message event', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('is triggered with correct log message', (done) => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: true });
w.webContents.on('console-message', (e, level, message) => {
// Don't just assert as Chromium might emit other logs that we should ignore.
if (message === 'a') {
2020-03-20 20:28:31 +00:00
done();
}
2020-03-20 20:28:31 +00:00
});
w.loadFile(path.join(fixturesPath, 'pages', 'a.html'));
});
});
describe('ipc-message event', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('emits when the renderer process sends an asynchronous message', async () => {
const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, contextIsolation: false } });
2020-03-20 20:28:31 +00:00
await w.webContents.loadURL('about:blank');
w.webContents.executeJavaScript(`
require('electron').ipcRenderer.send('message', 'Hello World!')
2020-03-20 20:28:31 +00:00
`);
2020-03-20 20:28:31 +00:00
const [, channel, message] = await emittedOnce(w.webContents, 'ipc-message');
expect(channel).to.equal('message');
expect(message).to.equal('Hello World!');
});
});
describe('ipc-message-sync event', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('emits when the renderer process sends a synchronous message', async () => {
const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, contextIsolation: false } });
2020-03-20 20:28:31 +00:00
await w.webContents.loadURL('about:blank');
const promise: Promise<[string, string]> = new Promise(resolve => {
w.webContents.once('ipc-message-sync', (event, channel, arg) => {
2020-03-20 20:28:31 +00:00
event.returnValue = 'foobar' as any;
resolve([channel, arg]);
});
});
const result = await w.webContents.executeJavaScript(`
require('electron').ipcRenderer.sendSync('message', 'Hello World!')
2020-03-20 20:28:31 +00:00
`);
2020-03-20 20:28:31 +00:00
const [channel, message] = await promise;
expect(channel).to.equal('message');
expect(message).to.equal('Hello World!');
expect(result).to.equal('foobar');
});
});
describe('referrer', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('propagates referrer information to new target=_blank windows', (done) => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const server = http.createServer((req, res) => {
if (req.url === '/should_have_referrer') {
try {
expect(req.headers.referer).to.equal(`http://127.0.0.1:${(server.address() as AddressInfo).port}/`);
return done();
} catch (e) {
return done(e);
} finally {
server.close();
}
}
2020-03-20 20:28:31 +00:00
res.end('<a id="a" href="/should_have_referrer" target="_blank">link</a>');
});
server.listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
const url = 'http://127.0.0.1:' + (server.address() as AddressInfo).port + '/';
w.webContents.once('did-finish-load', () => {
w.webContents.once('new-window', (event, newUrl, frameName, disposition, options, features, referrer) => {
2020-03-20 20:28:31 +00:00
expect(referrer.url).to.equal(url);
chore: bump chromium to 096e5313aaf19dfa0c4710145c34d (master) (#26535) * chore: bump chromium in DEPS to 1d6b29cd85c1c3cba093b8b69b2727cc26eaac97 * update patches * chore: use 'libvulkan.so.1' in the linux manifests CL: https://chromium-review.googlesource.com/c/angle/angle/+/2538430 Upstream renamed libvulkan.so to libvulkan.so.1, so sync our manifests. * chore: update expected window-open default policy. CL: https://chromium-review.googlesource.com/c/chromium/src/+/2429247 Upstream CL contiues the work to make `strict-origin-when-cross-origin` the default referrer policy. This commit changes our window-open tests to expect that policy over the previous `no-referrer-when-downgrade`. * chore: bump chromium in DEPS to 69cb7c65ad845cdab1cd5f4256237e72fceba2dd * chore: re-export chromium patches No code changes; just line numbers. `git am` failed because the upstream changes were just large enough to require patching to fail w/o fuzzing. The broken patch was patches/chromium/feat_allow_disabling_blink_scheduler_throttling_per_renderview.patch * update patches * chore: bump chromium in DEPS to c6d97a240d30e5f5166856f5ae6ee14d95b9a4f0 * update patches * fixup! chore: update expected window-open default policy. * chore: disallow copying CppHeapCreateParams Experimental commit to resolve FTBS https://ci.appveyor.com/project/electron-bot/electron-ljo26/builds/36405680#L25345 which introduces a new struct CppHeapCreateParams that aggregates a vector of unique_ptrs. Our Windows CI is unhappy that this struct implicitly deletes its copy ctor, so this commit makes it explicit. Xref: https://chromium-review.googlesource.com/c/v8/v8/+/2536642 * update patches * chore: bump chromium in DEPS to 0df9a85ffa0ad4711b41a089842e40b87ba88055 * update patches * fixup! chore: bump chromium to ac06d6903a2c981ab90a8162f1ba0 (master) (#26499) * chore: update calls to gfx::RemoveAcceleratorChar. The call signature for gfx::RemoveAccelerator changed in https://chromium-review.googlesource.com/c/chromium/src/+/2546471 . This commit updates use to match that. * chore: bump chromium in DEPS to 43d6c496251e08d3781bfadbe9727688551f74a9 * update patches * chore: bump chromium in DEPS to 1fb5c9825be4e2271c4fef0e802f5d970b32f62f * update patches * chore: bump chromium in DEPS to 8a1f078d67825e727a598b89a8924699df8d3850 * chore: bump chromium in DEPS to 28ff715b3a97d8cedc143bad671edb08b6de5fc2 * chore: update patches * Remove most service manifest remnants from Content https://chromium-review.googlesource.com/c/chromium/src/+/2296482 * Reland "Portals: Fix a11y for orphaned portals" https://chromium-review.googlesource.com/c/chromium/src/+/2542812 * Convert CallbackList::Subscription to a standalone class. https://chromium-review.googlesource.com/c/chromium/src/+/2522860 * fix: actually apply the zlib patch * chore: bump chromium in DEPS to 75b464e6357190ca302ba9ce8f8c2bf5a3b709ae * chore: update patches * chore: bump chromium@b884b9b2f647c59a75f5d2055030afa33d50ca10 * chore: bump chromium in DEPS to 829261dadcefdc54ce5fdf7c5fac2929786a63ce * chore: bump chromium in DEPS to 5df3e69605c7c0130374aaccb91fc4726a558db2 * chore: bump chromium in DEPS to 22db748d5b7b90f87e6e97ef4c92a727ac753ea4 * chore: bump chromium in DEPS to 1475df80282b7eeeb0e153d8375bfe651f083bf8 * chore: bump chromium in DEPS to 6d34fe9e9b7386edd90574617bfa4008de972d72 * chore: update patches * Disable CertVerifierService for now 2559260: Enable CertVerifierService by default | https://chromium-review.googlesource.com/c/chromium/src/+/2559260 * Remove force_ignore_site_for_cookies until we figure out what to do instead 2499162: Remove |force_ignore_site_for_cookies| from IPCs (e.g. ResourceRequest). | https://chromium-review.googlesource.com/c/chromium/src/+/2499162 * chore: bump chromium in DEPS to 95aeb1c59ebc03d19ba077b0cd707463d1b2865e * update patches * Set site_for_cookies to request url so that URLLoader::ShouldForceIgnoreSiteForCookies returns true * 2490383: a11y inspect reorg: implement accessible tree formatter factory https://chromium-review.googlesource.com/c/chromium/src/+/2490383 * 2485887: [Extensions][web_accessible_resources] Use |matches|. https://chromium-review.googlesource.com/c/chromium/src/+/2485887 * update v8 headers * chore: bump chromium in DEPS to 38587dc379a8cf4d4a13e482a6e89f2fe681144e * update patches * 2555005: [api] Simplify ScriptOrigin https://chromium-review.googlesource.com/c/v8/v8/+/2555005 * 2563553: Remove Flash from PermissionRequestTypes and PermissionTypes. https://chromium-review.googlesource.com/c/chromium/src/+/2563553 * 2546146: Remove browser-hosted InterfaceProvider https://chromium-review.googlesource.com/c/chromium/src/+/2546146 * Actually apply nan patch * update patches * chore: bump chromium in DEPS to 6718d4b50c9db975c5642ca5b68e8dc7ee1b7615 * update patches * 2546146: Remove browser-hosted InterfaceProvider https://chromium-review.googlesource.com/c/chromium/src/+/2546146 * chore: bump chromium in DEPS to 338cc300e3fe3a4cb4883e9ccdc34a32f3dfe034 * chore: bump chromium in DEPS to d9baeb1d192c23ceb1e1c4bbe6af98380b263bc1 * chore: bump chromium in DEPS to 3ca3051932683739b304e721cc394b6c66f841fe * chore: bump chromium in DEPS to 89292a4ae29096e5313aaf19dfa0c4710145c34d * 2571639: mac: Remove code to support OS X 10.10 in //sandbox https://chromium-review.googlesource.com/c/chromium/src/+/2571639 * Fixup patch indices * Do not build MTLManagedObjectAdapter It's been removed in newer Mantle versions and uses a deprecated enum * update patches * Remove sendToAll https://github.com/electron/electron/pull/26771 * 2569367: Remove dead fullscreen code in RenderWidgetHostView and friends https://chromium-review.googlesource.com/c/chromium/src/+/2569367 * Remove deprecated performFileOperation usage * 2568359: mac: Ignore Wdeprecated-declarations for LSSharedFileList* functions. https://chromium-review.googlesource.com/c/chromium/src/+/2568359 * 2561401: Add OutputPresenterX11 which uses X11 present extension. https://chromium-review.googlesource.com/c/chromium/src/+/2561401 * 2565511: [objects] Remove MakeExternal case for uncached internal strings https://chromium-review.googlesource.com/c/v8/v8/+/2565511 * fixup: Add disconnect logic to ElectronBrowserHandlerImpl * Allow local networking override for ATS https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html * Refactor: clean up rfh getters in ElectronBrowserHandlerImpl * Update patches * Remove unneeded BindTo * Don't assign ElectronBrowserHandlerImpl at all Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2020-12-14 18:57:36 +00:00
expect(referrer.policy).to.equal('strict-origin-when-cross-origin');
2020-03-20 20:28:31 +00:00
});
w.webContents.executeJavaScript('a.click()');
});
w.loadURL(url);
});
});
// TODO(jeremy): window.open() in a real browser passes the referrer, but
// our hacked-up window.open() shim doesn't. It should.
xit('propagates referrer information to windows opened with window.open', (done) => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
const server = http.createServer((req, res) => {
if (req.url === '/should_have_referrer') {
try {
expect(req.headers.referer).to.equal(`http://127.0.0.1:${(server.address() as AddressInfo).port}/`);
return done();
} catch (e) {
return done(e);
}
}
2020-03-20 20:28:31 +00:00
res.end('');
});
server.listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
const url = 'http://127.0.0.1:' + (server.address() as AddressInfo).port + '/';
w.webContents.once('did-finish-load', () => {
w.webContents.once('new-window', (event, newUrl, frameName, disposition, options, features, referrer) => {
2020-03-20 20:28:31 +00:00
expect(referrer.url).to.equal(url);
expect(referrer.policy).to.equal('no-referrer-when-downgrade');
});
w.webContents.executeJavaScript('window.open(location.href + "should_have_referrer")');
});
w.loadURL(url);
});
});
});
describe('webframe messages in sandboxed contents', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('responds to executeJavaScript', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadURL('about:blank');
const result = await w.webContents.executeJavaScript('37 + 5');
expect(result).to.equal(42);
});
});
describe('preload-error event', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
const generateSpecs = (description: string, sandbox: boolean) => {
describe(description, () => {
it('is triggered when unhandled exception is thrown', async () => {
2020-03-20 20:28:31 +00:00
const preload = path.join(fixturesPath, 'module', 'preload-error-exception.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox,
preload
}
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
const promise = emittedOnce(w.webContents, 'preload-error');
w.loadURL('about:blank');
2020-03-20 20:28:31 +00:00
const [, preloadPath, error] = await promise;
expect(preloadPath).to.equal(preload);
expect(error.message).to.equal('Hello World!');
});
it('is triggered on syntax errors', async () => {
2020-03-20 20:28:31 +00:00
const preload = path.join(fixturesPath, 'module', 'preload-error-syntax.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox,
preload
}
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
const promise = emittedOnce(w.webContents, 'preload-error');
w.loadURL('about:blank');
2020-03-20 20:28:31 +00:00
const [, preloadPath, error] = await promise;
expect(preloadPath).to.equal(preload);
expect(error.message).to.equal('foobar is not defined');
});
it('is triggered when preload script loading fails', async () => {
2020-03-20 20:28:31 +00:00
const preload = path.join(fixturesPath, 'module', 'preload-invalid.js');
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox,
preload
}
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
const promise = emittedOnce(w.webContents, 'preload-error');
w.loadURL('about:blank');
2020-03-20 20:28:31 +00:00
const [, preloadPath, error] = await promise;
expect(preloadPath).to.equal(preload);
expect(error.message).to.contain('preload-invalid.js');
});
});
};
2020-03-20 20:28:31 +00:00
generateSpecs('without sandbox', false);
generateSpecs('with sandbox', true);
});
describe('takeHeapSnapshot()', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('works with sandboxed renderers', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
await w.loadURL('about:blank');
2020-03-20 20:28:31 +00:00
const filePath = path.join(app.getPath('temp'), 'test.heapsnapshot');
const cleanup = () => {
try {
2020-03-20 20:28:31 +00:00
fs.unlinkSync(filePath);
} catch (e) {
// ignore error
}
2020-03-20 20:28:31 +00:00
};
try {
2020-03-20 20:28:31 +00:00
await w.webContents.takeHeapSnapshot(filePath);
const stats = fs.statSync(filePath);
expect(stats.size).not.to.be.equal(0);
} finally {
2020-03-20 20:28:31 +00:00
cleanup();
}
2020-03-20 20:28:31 +00:00
});
it('fails with invalid file path', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
await w.loadURL('about:blank');
2020-03-20 20:28:31 +00:00
const promise = w.webContents.takeHeapSnapshot('');
return expect(promise).to.be.eventually.rejectedWith(Error, 'takeHeapSnapshot failed');
});
});
describe('setBackgroundThrottling()', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('does not crash when allowing', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
w.webContents.setBackgroundThrottling(true);
});
it('does not crash when called via BrowserWindow', () => {
const w = new BrowserWindow({ show: false });
2020-03-20 20:28:31 +00:00
(w as any).setBackgroundThrottling(true);
});
it('does not crash when disallowing', () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false, webPreferences: { backgroundThrottling: true } });
2020-03-20 20:28:31 +00:00
w.webContents.setBackgroundThrottling(false);
});
});
describe('getBackgroundThrottling()', () => {
afterEach(closeAllWindows);
it('works via getter', () => {
const w = new BrowserWindow({ show: false });
w.webContents.setBackgroundThrottling(false);
expect(w.webContents.getBackgroundThrottling()).to.equal(false);
w.webContents.setBackgroundThrottling(true);
expect(w.webContents.getBackgroundThrottling()).to.equal(true);
});
it('works via property', () => {
const w = new BrowserWindow({ show: false });
w.webContents.backgroundThrottling = false;
expect(w.webContents.backgroundThrottling).to.equal(false);
w.webContents.backgroundThrottling = true;
expect(w.webContents.backgroundThrottling).to.equal(true);
});
it('works via BrowserWindow', () => {
const w = new BrowserWindow({ show: false });
(w as any).setBackgroundThrottling(false);
expect((w as any).getBackgroundThrottling()).to.equal(false);
(w as any).setBackgroundThrottling(true);
expect((w as any).getBackgroundThrottling()).to.equal(true);
});
});
ifdescribe(features.isPrintingEnabled())('getPrinters()', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('can get printer list', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadURL('about:blank');
const printers = w.webContents.getPrinters();
expect(printers).to.be.an('array');
});
});
ifdescribe(features.isPrintingEnabled())('printToPDF()', () => {
2020-03-20 20:28:31 +00:00
let w: BrowserWindow;
beforeEach(async () => {
2020-03-20 20:28:31 +00:00
w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadURL('data:text/html,<h1>Hello, World!</h1>');
});
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('rejects on incorrectly typed parameters', async () => {
const badTypes = {
marginsType: 'terrible',
scaleFactor: 'not-a-number',
landscape: [],
pageRanges: { oops: 'im-not-the-right-key' },
headerFooter: '123',
printSelectionOnly: 1,
printBackground: 2,
pageSize: 'IAmAPageSize'
2020-03-20 20:28:31 +00:00
};
// These will hard crash in Chromium unless we type-check
for (const [key, value] of Object.entries(badTypes)) {
2020-03-20 20:28:31 +00:00
const param = { [key]: value };
await expect(w.webContents.printToPDF(param)).to.eventually.be.rejected();
}
2020-03-20 20:28:31 +00:00
});
it('can print to PDF', async () => {
2020-03-20 20:28:31 +00:00
const data = await w.webContents.printToPDF({});
expect(data).to.be.an.instanceof(Buffer).that.is.not.empty();
});
chore: bump chromium to 6d130075d378a64187360ba4e7820 (master) (#24256) * chore: bump chromium in DEPS to 7fb9778894d73378bff51087ce869ea5aa6e5d5d * chore: bump chromium in DEPS to 83da426e53d423f0530fc23433b6d2c4d0548442 * update patches * remove chromeos-only TtsControllerDelegate Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2255314 * SharedUserScriptMaster -> SharedUserScriptManager Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2258357 * avoid deprecated DISALLOW_COPY_AND_ASSIGN https://groups.google.com/a/chromium.org/forum/#!msg/cxx/qwH2hxaEjac/TUKq6eqfCwAJ * chore: bump chromium in DEPS to b2eaf9ff4e6b03267bf279583ea20ceb2b25e9d0 * update patches * rename GetHighContrastColorScheme -> GetPlatformHighContrastColorScheme Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2250224 * remove vulkan info collection Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * add max_xcode_version build var Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2264867 * add missing headers * chore: bump chromium in DEPS to cded18ca1138f7e8efc904f077ddcca34f0135cf * update patches * add empty floc blocklist to BrowserProcessImpl Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2240873 * chore: bump chromium in DEPS to f06602226cd80bf677b2ce013a94a2fb7f6ac58d * chore: bump chromium in DEPS to 747aa4bfc74fc6cf7f08ee72624cd69ae41ae28d * chore: bump chromium in DEPS to 31c0105e50fcc4e94de33e5c8602c755ace4a32b * chore: update patches * Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" https://chromium-review.googlesource.com/c/chromium/src/+/2264297 * X11 and Ozone: make sure gfx::AcceleratedWidget to be uint32_t https://chromium-review.googlesource.com/c/chromium/src/+/2260554 * Move zygote from //services/service_manager back to //content https://chromium-review.googlesource.com/c/chromium/src/+/2252466 * chore: update v8 patches * [XProto] Remove usage of Shape extension https://chromium-review.googlesource.com/c/chromium/src/+/2262113 * fixup! add empty floc blocklist to BrowserProcessImpl * Require macOS 10.15.1 sdk https://chromium-review.googlesource.com/c/chromium/src/+/2238504 * Use newer Xcode version 11.5.0 * update src cache * chore: bump chromium in DEPS to 60a9883e35db3f6f91916f0878e88e1849c17b11 * chore: update patches * Reland "Reland "New toolchain for Windows 10 19041 SDK"" https://chromium-review.googlesource.com/c/chromium/src/+/2255527 * update patches * Convert raw NonClientFrameViews to unique_ptrs https://chromium-review.googlesource.com/c/chromium/src/+/2240417 * [printing] Move PrintHostMsg_DidPreviewDocument_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2257035 * chore: bump chromium in DEPS to 12c233c2a85bfa28fb279f390121ba681e52a71b * chore: update patches * Removing oppressive language for the directory chrome/browser/apps https://chromium-review.googlesource.com/c/chromium/src/+/2269822 * Inclusion: rename SpellcheckLanguageBlacklistPolicyHandler https://chromium-review.googlesource.com/c/chromium/src/+/2267646 * Clean up duplicate WebContents "is fullscreen" functions https://chromium-review.googlesource.com/c/chromium/src/+/2275148 * Adds icon loading service with sandbox for Windows. https://chromium-review.googlesource.com/c/chromium/src/+/1987273 * No more Vulkan info collection for UMA on Windows https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * fix lint * chore: update buildflag conditions * chore: bump chromium in DEPS to a837d4c4230ace4f10b2768728f4044b7995dfa5 * update hunspell files * chore: update patches * Make content::FileSelectListener a RefCounted https://chromium-review.googlesource.com/c/chromium/src/+/2275338 * fix build failures on MAS * update patches * fixup! Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" * fix build on windows * Check for GDI exhaustion if window creation fails https://chromium-review.googlesource.com/c/chromium/src/+/2244124 * chore: bump chromium in DEPS to 2c9b2a73be4ef9ec22d8b6da8e174cb80753f125 * chore: update patches * Network Service: Move DeleteCookiePredicate into public folder https://chromium-review.googlesource.com/c/chromium/src/+/2264186 * chore: bump chromium in DEPS to fa2606299bcc02c362528d26b5dcf8c8a0db0735 * chore: bump chromium in DEPS to d9c235d1227204dbae3708daae851573a3566b94 * chore: bump chromium in DEPS to 2f82c284243c035f49a747fd1ead6c44b4b31093 * chore: update patches * Move creating the LayerTreeSettings into blink. https://chromium-review.googlesource.com/c/chromium/src/+/2267720 * chore: bump chromium in DEPS to 914112f1d9af9e4974059dc403da62699a55550f * update patches * chore: bump chromium in DEPS to e0bc1ffae6393fc543a2da94c88167df75859b36 * refactor: match upstream print preview handling (#24452) * update patches * chore: bump chromium in DEPS to 0881423156abe084164b51ab58ce93a8bd380524 * update patches * update patches * give a type to pendingPromise * chore: bump chromium in DEPS to 11a8c1534b16d130075d378a64187360ba4e7820 * update patches * 2272609: Move //services/service_manager/sandbox to //sandbox/policy. https://chromium-review.googlesource.com/c/chromium/src/+/2272609 * update patches * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * 2264511: Cookies: Update SetCanonicalCookie to return CookieAccessResult https://chromium-review.googlesource.com/c/chromium/src/+/2264511 * chore: fix setAlwaysOnTop test The window must be visible for state to be updated properly. * Revert "Migrate modules/desktop_capture and modules/video_capture to webrtc::Mutex." https://webrtc-review.googlesource.com/c/src/+/179080 * update patches Co-authored-by: Andy Locascio <andy@slack-corp.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
2020-07-14 01:13:34 +00:00
it('does not crash when called multiple times in parallel', async () => {
2020-03-20 20:28:31 +00:00
const promises = [];
chore: bump chromium to 6d130075d378a64187360ba4e7820 (master) (#24256) * chore: bump chromium in DEPS to 7fb9778894d73378bff51087ce869ea5aa6e5d5d * chore: bump chromium in DEPS to 83da426e53d423f0530fc23433b6d2c4d0548442 * update patches * remove chromeos-only TtsControllerDelegate Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2255314 * SharedUserScriptMaster -> SharedUserScriptManager Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2258357 * avoid deprecated DISALLOW_COPY_AND_ASSIGN https://groups.google.com/a/chromium.org/forum/#!msg/cxx/qwH2hxaEjac/TUKq6eqfCwAJ * chore: bump chromium in DEPS to b2eaf9ff4e6b03267bf279583ea20ceb2b25e9d0 * update patches * rename GetHighContrastColorScheme -> GetPlatformHighContrastColorScheme Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2250224 * remove vulkan info collection Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * add max_xcode_version build var Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2264867 * add missing headers * chore: bump chromium in DEPS to cded18ca1138f7e8efc904f077ddcca34f0135cf * update patches * add empty floc blocklist to BrowserProcessImpl Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2240873 * chore: bump chromium in DEPS to f06602226cd80bf677b2ce013a94a2fb7f6ac58d * chore: bump chromium in DEPS to 747aa4bfc74fc6cf7f08ee72624cd69ae41ae28d * chore: bump chromium in DEPS to 31c0105e50fcc4e94de33e5c8602c755ace4a32b * chore: update patches * Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" https://chromium-review.googlesource.com/c/chromium/src/+/2264297 * X11 and Ozone: make sure gfx::AcceleratedWidget to be uint32_t https://chromium-review.googlesource.com/c/chromium/src/+/2260554 * Move zygote from //services/service_manager back to //content https://chromium-review.googlesource.com/c/chromium/src/+/2252466 * chore: update v8 patches * [XProto] Remove usage of Shape extension https://chromium-review.googlesource.com/c/chromium/src/+/2262113 * fixup! add empty floc blocklist to BrowserProcessImpl * Require macOS 10.15.1 sdk https://chromium-review.googlesource.com/c/chromium/src/+/2238504 * Use newer Xcode version 11.5.0 * update src cache * chore: bump chromium in DEPS to 60a9883e35db3f6f91916f0878e88e1849c17b11 * chore: update patches * Reland "Reland "New toolchain for Windows 10 19041 SDK"" https://chromium-review.googlesource.com/c/chromium/src/+/2255527 * update patches * Convert raw NonClientFrameViews to unique_ptrs https://chromium-review.googlesource.com/c/chromium/src/+/2240417 * [printing] Move PrintHostMsg_DidPreviewDocument_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2257035 * chore: bump chromium in DEPS to 12c233c2a85bfa28fb279f390121ba681e52a71b * chore: update patches * Removing oppressive language for the directory chrome/browser/apps https://chromium-review.googlesource.com/c/chromium/src/+/2269822 * Inclusion: rename SpellcheckLanguageBlacklistPolicyHandler https://chromium-review.googlesource.com/c/chromium/src/+/2267646 * Clean up duplicate WebContents "is fullscreen" functions https://chromium-review.googlesource.com/c/chromium/src/+/2275148 * Adds icon loading service with sandbox for Windows. https://chromium-review.googlesource.com/c/chromium/src/+/1987273 * No more Vulkan info collection for UMA on Windows https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * fix lint * chore: update buildflag conditions * chore: bump chromium in DEPS to a837d4c4230ace4f10b2768728f4044b7995dfa5 * update hunspell files * chore: update patches * Make content::FileSelectListener a RefCounted https://chromium-review.googlesource.com/c/chromium/src/+/2275338 * fix build failures on MAS * update patches * fixup! Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" * fix build on windows * Check for GDI exhaustion if window creation fails https://chromium-review.googlesource.com/c/chromium/src/+/2244124 * chore: bump chromium in DEPS to 2c9b2a73be4ef9ec22d8b6da8e174cb80753f125 * chore: update patches * Network Service: Move DeleteCookiePredicate into public folder https://chromium-review.googlesource.com/c/chromium/src/+/2264186 * chore: bump chromium in DEPS to fa2606299bcc02c362528d26b5dcf8c8a0db0735 * chore: bump chromium in DEPS to d9c235d1227204dbae3708daae851573a3566b94 * chore: bump chromium in DEPS to 2f82c284243c035f49a747fd1ead6c44b4b31093 * chore: update patches * Move creating the LayerTreeSettings into blink. https://chromium-review.googlesource.com/c/chromium/src/+/2267720 * chore: bump chromium in DEPS to 914112f1d9af9e4974059dc403da62699a55550f * update patches * chore: bump chromium in DEPS to e0bc1ffae6393fc543a2da94c88167df75859b36 * refactor: match upstream print preview handling (#24452) * update patches * chore: bump chromium in DEPS to 0881423156abe084164b51ab58ce93a8bd380524 * update patches * update patches * give a type to pendingPromise * chore: bump chromium in DEPS to 11a8c1534b16d130075d378a64187360ba4e7820 * update patches * 2272609: Move //services/service_manager/sandbox to //sandbox/policy. https://chromium-review.googlesource.com/c/chromium/src/+/2272609 * update patches * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * 2264511: Cookies: Update SetCanonicalCookie to return CookieAccessResult https://chromium-review.googlesource.com/c/chromium/src/+/2264511 * chore: fix setAlwaysOnTop test The window must be visible for state to be updated properly. * Revert "Migrate modules/desktop_capture and modules/video_capture to webrtc::Mutex." https://webrtc-review.googlesource.com/c/src/+/179080 * update patches Co-authored-by: Andy Locascio <andy@slack-corp.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
2020-07-14 01:13:34 +00:00
for (let i = 0; i < 3; i++) {
2020-03-20 20:28:31 +00:00
promises.push(w.webContents.printToPDF({}));
}
chore: bump chromium to 6d130075d378a64187360ba4e7820 (master) (#24256) * chore: bump chromium in DEPS to 7fb9778894d73378bff51087ce869ea5aa6e5d5d * chore: bump chromium in DEPS to 83da426e53d423f0530fc23433b6d2c4d0548442 * update patches * remove chromeos-only TtsControllerDelegate Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2255314 * SharedUserScriptMaster -> SharedUserScriptManager Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2258357 * avoid deprecated DISALLOW_COPY_AND_ASSIGN https://groups.google.com/a/chromium.org/forum/#!msg/cxx/qwH2hxaEjac/TUKq6eqfCwAJ * chore: bump chromium in DEPS to b2eaf9ff4e6b03267bf279583ea20ceb2b25e9d0 * update patches * rename GetHighContrastColorScheme -> GetPlatformHighContrastColorScheme Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2250224 * remove vulkan info collection Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * add max_xcode_version build var Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2264867 * add missing headers * chore: bump chromium in DEPS to cded18ca1138f7e8efc904f077ddcca34f0135cf * update patches * add empty floc blocklist to BrowserProcessImpl Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2240873 * chore: bump chromium in DEPS to f06602226cd80bf677b2ce013a94a2fb7f6ac58d * chore: bump chromium in DEPS to 747aa4bfc74fc6cf7f08ee72624cd69ae41ae28d * chore: bump chromium in DEPS to 31c0105e50fcc4e94de33e5c8602c755ace4a32b * chore: update patches * Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" https://chromium-review.googlesource.com/c/chromium/src/+/2264297 * X11 and Ozone: make sure gfx::AcceleratedWidget to be uint32_t https://chromium-review.googlesource.com/c/chromium/src/+/2260554 * Move zygote from //services/service_manager back to //content https://chromium-review.googlesource.com/c/chromium/src/+/2252466 * chore: update v8 patches * [XProto] Remove usage of Shape extension https://chromium-review.googlesource.com/c/chromium/src/+/2262113 * fixup! add empty floc blocklist to BrowserProcessImpl * Require macOS 10.15.1 sdk https://chromium-review.googlesource.com/c/chromium/src/+/2238504 * Use newer Xcode version 11.5.0 * update src cache * chore: bump chromium in DEPS to 60a9883e35db3f6f91916f0878e88e1849c17b11 * chore: update patches * Reland "Reland "New toolchain for Windows 10 19041 SDK"" https://chromium-review.googlesource.com/c/chromium/src/+/2255527 * update patches * Convert raw NonClientFrameViews to unique_ptrs https://chromium-review.googlesource.com/c/chromium/src/+/2240417 * [printing] Move PrintHostMsg_DidPreviewDocument_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2257035 * chore: bump chromium in DEPS to 12c233c2a85bfa28fb279f390121ba681e52a71b * chore: update patches * Removing oppressive language for the directory chrome/browser/apps https://chromium-review.googlesource.com/c/chromium/src/+/2269822 * Inclusion: rename SpellcheckLanguageBlacklistPolicyHandler https://chromium-review.googlesource.com/c/chromium/src/+/2267646 * Clean up duplicate WebContents "is fullscreen" functions https://chromium-review.googlesource.com/c/chromium/src/+/2275148 * Adds icon loading service with sandbox for Windows. https://chromium-review.googlesource.com/c/chromium/src/+/1987273 * No more Vulkan info collection for UMA on Windows https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * fix lint * chore: update buildflag conditions * chore: bump chromium in DEPS to a837d4c4230ace4f10b2768728f4044b7995dfa5 * update hunspell files * chore: update patches * Make content::FileSelectListener a RefCounted https://chromium-review.googlesource.com/c/chromium/src/+/2275338 * fix build failures on MAS * update patches * fixup! Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" * fix build on windows * Check for GDI exhaustion if window creation fails https://chromium-review.googlesource.com/c/chromium/src/+/2244124 * chore: bump chromium in DEPS to 2c9b2a73be4ef9ec22d8b6da8e174cb80753f125 * chore: update patches * Network Service: Move DeleteCookiePredicate into public folder https://chromium-review.googlesource.com/c/chromium/src/+/2264186 * chore: bump chromium in DEPS to fa2606299bcc02c362528d26b5dcf8c8a0db0735 * chore: bump chromium in DEPS to d9c235d1227204dbae3708daae851573a3566b94 * chore: bump chromium in DEPS to 2f82c284243c035f49a747fd1ead6c44b4b31093 * chore: update patches * Move creating the LayerTreeSettings into blink. https://chromium-review.googlesource.com/c/chromium/src/+/2267720 * chore: bump chromium in DEPS to 914112f1d9af9e4974059dc403da62699a55550f * update patches * chore: bump chromium in DEPS to e0bc1ffae6393fc543a2da94c88167df75859b36 * refactor: match upstream print preview handling (#24452) * update patches * chore: bump chromium in DEPS to 0881423156abe084164b51ab58ce93a8bd380524 * update patches * update patches * give a type to pendingPromise * chore: bump chromium in DEPS to 11a8c1534b16d130075d378a64187360ba4e7820 * update patches * 2272609: Move //services/service_manager/sandbox to //sandbox/policy. https://chromium-review.googlesource.com/c/chromium/src/+/2272609 * update patches * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * 2264511: Cookies: Update SetCanonicalCookie to return CookieAccessResult https://chromium-review.googlesource.com/c/chromium/src/+/2264511 * chore: fix setAlwaysOnTop test The window must be visible for state to be updated properly. * Revert "Migrate modules/desktop_capture and modules/video_capture to webrtc::Mutex." https://webrtc-review.googlesource.com/c/src/+/179080 * update patches Co-authored-by: Andy Locascio <andy@slack-corp.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
2020-07-14 01:13:34 +00:00
2020-03-20 20:28:31 +00:00
const results = await Promise.all(promises);
for (const data of results) {
2020-03-20 20:28:31 +00:00
expect(data).to.be.an.instanceof(Buffer).that.is.not.empty();
}
2020-03-20 20:28:31 +00:00
});
chore: bump chromium to 6d130075d378a64187360ba4e7820 (master) (#24256) * chore: bump chromium in DEPS to 7fb9778894d73378bff51087ce869ea5aa6e5d5d * chore: bump chromium in DEPS to 83da426e53d423f0530fc23433b6d2c4d0548442 * update patches * remove chromeos-only TtsControllerDelegate Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2255314 * SharedUserScriptMaster -> SharedUserScriptManager Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2258357 * avoid deprecated DISALLOW_COPY_AND_ASSIGN https://groups.google.com/a/chromium.org/forum/#!msg/cxx/qwH2hxaEjac/TUKq6eqfCwAJ * chore: bump chromium in DEPS to b2eaf9ff4e6b03267bf279583ea20ceb2b25e9d0 * update patches * rename GetHighContrastColorScheme -> GetPlatformHighContrastColorScheme Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2250224 * remove vulkan info collection Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * add max_xcode_version build var Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2264867 * add missing headers * chore: bump chromium in DEPS to cded18ca1138f7e8efc904f077ddcca34f0135cf * update patches * add empty floc blocklist to BrowserProcessImpl Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2240873 * chore: bump chromium in DEPS to f06602226cd80bf677b2ce013a94a2fb7f6ac58d * chore: bump chromium in DEPS to 747aa4bfc74fc6cf7f08ee72624cd69ae41ae28d * chore: bump chromium in DEPS to 31c0105e50fcc4e94de33e5c8602c755ace4a32b * chore: update patches * Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" https://chromium-review.googlesource.com/c/chromium/src/+/2264297 * X11 and Ozone: make sure gfx::AcceleratedWidget to be uint32_t https://chromium-review.googlesource.com/c/chromium/src/+/2260554 * Move zygote from //services/service_manager back to //content https://chromium-review.googlesource.com/c/chromium/src/+/2252466 * chore: update v8 patches * [XProto] Remove usage of Shape extension https://chromium-review.googlesource.com/c/chromium/src/+/2262113 * fixup! add empty floc blocklist to BrowserProcessImpl * Require macOS 10.15.1 sdk https://chromium-review.googlesource.com/c/chromium/src/+/2238504 * Use newer Xcode version 11.5.0 * update src cache * chore: bump chromium in DEPS to 60a9883e35db3f6f91916f0878e88e1849c17b11 * chore: update patches * Reland "Reland "New toolchain for Windows 10 19041 SDK"" https://chromium-review.googlesource.com/c/chromium/src/+/2255527 * update patches * Convert raw NonClientFrameViews to unique_ptrs https://chromium-review.googlesource.com/c/chromium/src/+/2240417 * [printing] Move PrintHostMsg_DidPreviewDocument_Params to print.mojom https://chromium-review.googlesource.com/c/chromium/src/+/2257035 * chore: bump chromium in DEPS to 12c233c2a85bfa28fb279f390121ba681e52a71b * chore: update patches * Removing oppressive language for the directory chrome/browser/apps https://chromium-review.googlesource.com/c/chromium/src/+/2269822 * Inclusion: rename SpellcheckLanguageBlacklistPolicyHandler https://chromium-review.googlesource.com/c/chromium/src/+/2267646 * Clean up duplicate WebContents "is fullscreen" functions https://chromium-review.googlesource.com/c/chromium/src/+/2275148 * Adds icon loading service with sandbox for Windows. https://chromium-review.googlesource.com/c/chromium/src/+/1987273 * No more Vulkan info collection for UMA on Windows https://chromium-review.googlesource.com/c/chromium/src/+/2252818 * fix lint * chore: update buildflag conditions * chore: bump chromium in DEPS to a837d4c4230ace4f10b2768728f4044b7995dfa5 * update hunspell files * chore: update patches * Make content::FileSelectListener a RefCounted https://chromium-review.googlesource.com/c/chromium/src/+/2275338 * fix build failures on MAS * update patches * fixup! Reland "[base] Stop including check.h, notreached.h, etc. in logging.h" * fix build on windows * Check for GDI exhaustion if window creation fails https://chromium-review.googlesource.com/c/chromium/src/+/2244124 * chore: bump chromium in DEPS to 2c9b2a73be4ef9ec22d8b6da8e174cb80753f125 * chore: update patches * Network Service: Move DeleteCookiePredicate into public folder https://chromium-review.googlesource.com/c/chromium/src/+/2264186 * chore: bump chromium in DEPS to fa2606299bcc02c362528d26b5dcf8c8a0db0735 * chore: bump chromium in DEPS to d9c235d1227204dbae3708daae851573a3566b94 * chore: bump chromium in DEPS to 2f82c284243c035f49a747fd1ead6c44b4b31093 * chore: update patches * Move creating the LayerTreeSettings into blink. https://chromium-review.googlesource.com/c/chromium/src/+/2267720 * chore: bump chromium in DEPS to 914112f1d9af9e4974059dc403da62699a55550f * update patches * chore: bump chromium in DEPS to e0bc1ffae6393fc543a2da94c88167df75859b36 * refactor: match upstream print preview handling (#24452) * update patches * chore: bump chromium in DEPS to 0881423156abe084164b51ab58ce93a8bd380524 * update patches * update patches * give a type to pendingPromise * chore: bump chromium in DEPS to 11a8c1534b16d130075d378a64187360ba4e7820 * update patches * 2272609: Move //services/service_manager/sandbox to //sandbox/policy. https://chromium-review.googlesource.com/c/chromium/src/+/2272609 * update patches * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * fixup! 2272609: Move //services/service_manager/sandbox to //sandbox/policy. * 2264511: Cookies: Update SetCanonicalCookie to return CookieAccessResult https://chromium-review.googlesource.com/c/chromium/src/+/2264511 * chore: fix setAlwaysOnTop test The window must be visible for state to be updated properly. * Revert "Migrate modules/desktop_capture and modules/video_capture to webrtc::Mutex." https://webrtc-review.googlesource.com/c/src/+/179080 * update patches Co-authored-by: Andy Locascio <andy@slack-corp.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: Electron Bot <anonymous@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
2020-07-14 01:13:34 +00:00
it('does not crash when called multiple times in sequence', async () => {
const results = [];
for (let i = 0; i < 3; i++) {
const result = await w.webContents.printToPDF({});
results.push(result);
}
for (const data of results) {
expect(data).to.be.an.instanceof(Buffer).that.is.not.empty();
}
});
describe('using a large document', () => {
beforeEach(async () => {
w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'print-to-pdf.html'));
});
afterEach(closeAllWindows);
it('respects custom settings', async () => {
const data = await w.webContents.printToPDF({
pageRanges: {
from: 0,
to: 2
},
landscape: true
});
const doc = await pdfjs.getDocument(data).promise;
// Check that correct # of pages are rendered.
expect(doc.numPages).to.equal(3);
// Check that PDF is generated in landscape mode.
const firstPage = await doc.getPage(1);
const { width, height } = firstPage.getViewport({ scale: 100 });
expect(width).to.be.greaterThan(height);
});
});
2020-03-20 20:28:31 +00:00
});
describe('PictureInPicture video', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('works as expected', async function () {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadFile(path.join(fixturesPath, 'api', 'picture-in-picture.html'));
if (!await w.webContents.executeJavaScript('document.createElement(\'video\').canPlayType(\'video/webm; codecs="vp8.0"\')')) {
this.skip();
}
const result = await w.webContents.executeJavaScript(
`runTest(${features.isPictureInPictureEnabled()})`, true);
expect(result).to.be.true();
2020-03-20 20:28:31 +00:00
});
});
describe('devtools window', () => {
2020-03-20 20:28:31 +00:00
let hasRobotJS = false;
try {
// We have other tests that check if native modules work, if we fail to require
// robotjs let's skip this test to avoid false negatives
2020-03-20 20:28:31 +00:00
require('robotjs');
hasRobotJS = true;
} catch (err) { /* no-op */ }
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
// NB. on macOS, this requires that you grant your terminal the ability to
// control your computer. Open System Preferences > Security & Privacy >
// Privacy > Accessibility and grant your terminal the permission to control
// your computer.
ifit(hasRobotJS)('can receive and handle menu events', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true } });
w.loadFile(path.join(fixturesPath, 'pages', 'key-events.html'));
// Ensure the devtools are loaded
2020-03-20 20:28:31 +00:00
w.webContents.closeDevTools();
const opened = emittedOnce(w.webContents, 'devtools-opened');
w.webContents.openDevTools();
await opened;
await emittedOnce(w.webContents.devToolsWebContents!, 'did-finish-load');
w.webContents.devToolsWebContents!.focus();
// Focus an input field
await w.webContents.devToolsWebContents!.executeJavaScript(`
const input = document.createElement('input')
document.body.innerHTML = ''
document.body.appendChild(input)
input.focus()
2020-03-20 20:28:31 +00:00
`);
// Write something to the clipboard
2020-03-20 20:28:31 +00:00
clipboard.writeText('test value');
const pasted = w.webContents.devToolsWebContents!.executeJavaScript(`new Promise(resolve => {
document.querySelector('input').addEventListener('paste', (e) => {
resolve(e.target.value)
})
2020-03-20 20:28:31 +00:00
})`);
// Fake a paste request using robotjs to emulate a REAL keyboard paste event
2020-03-20 20:28:31 +00:00
require('robotjs').keyTap('v', process.platform === 'darwin' ? ['command'] : ['control']);
2020-03-20 20:28:31 +00:00
const val = await pasted;
// Once we're done expect the paste to have been successful
2020-03-20 20:28:31 +00:00
expect(val).to.equal('test value', 'value should eventually become the pasted value');
});
});
describe('Shared Workers', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
it('can get multiple shared workers', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
2020-03-20 20:28:31 +00:00
const ready = emittedOnce(ipcMain, 'ready');
w.loadFile(path.join(fixturesPath, 'api', 'shared-worker', 'shared-worker.html'));
await ready;
2020-03-20 20:28:31 +00:00
const sharedWorkers = w.webContents.getAllSharedWorkers();
2020-03-20 20:28:31 +00:00
expect(sharedWorkers).to.have.lengthOf(2);
expect(sharedWorkers[0].url).to.contain('shared-worker');
expect(sharedWorkers[1].url).to.contain('shared-worker');
});
it('can inspect a specific shared worker', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
2020-03-20 20:28:31 +00:00
const ready = emittedOnce(ipcMain, 'ready');
w.loadFile(path.join(fixturesPath, 'api', 'shared-worker', 'shared-worker.html'));
await ready;
2020-03-20 20:28:31 +00:00
const sharedWorkers = w.webContents.getAllSharedWorkers();
2020-03-20 20:28:31 +00:00
const devtoolsOpened = emittedOnce(w.webContents, 'devtools-opened');
w.webContents.inspectSharedWorkerById(sharedWorkers[0].id);
await devtoolsOpened;
2020-03-20 20:28:31 +00:00
const devtoolsClosed = emittedOnce(w.webContents, 'devtools-closed');
w.webContents.closeDevTools();
await devtoolsClosed;
});
});
describe('login event', () => {
2020-03-20 20:28:31 +00:00
afterEach(closeAllWindows);
2020-03-20 20:28:31 +00:00
let server: http.Server;
let serverUrl: string;
let serverPort: number;
let proxyServer: http.Server;
let proxyServerPort: number;
before((done) => {
server = http.createServer((request, response) => {
if (request.url === '/no-auth') {
2020-03-20 20:28:31 +00:00
return response.end('ok');
}
if (request.headers.authorization) {
2020-03-20 20:28:31 +00:00
response.writeHead(200, { 'Content-type': 'text/plain' });
return response.end(request.headers.authorization);
}
response
.writeHead(401, { 'WWW-Authenticate': 'Basic realm="Foo"' })
2020-03-20 20:28:31 +00:00
.end('401');
}).listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
serverPort = (server.address() as AddressInfo).port;
serverUrl = `http://127.0.0.1:${serverPort}`;
done();
});
});
before((done) => {
proxyServer = http.createServer((request, response) => {
if (request.headers['proxy-authorization']) {
2020-03-20 20:28:31 +00:00
response.writeHead(200, { 'Content-type': 'text/plain' });
return response.end(request.headers['proxy-authorization']);
}
response
.writeHead(407, { 'Proxy-Authenticate': 'Basic realm="Foo"' })
2020-03-20 20:28:31 +00:00
.end();
}).listen(0, '127.0.0.1', () => {
2020-03-20 20:28:31 +00:00
proxyServerPort = (proxyServer.address() as AddressInfo).port;
done();
});
});
afterEach(async () => {
2020-03-20 20:28:31 +00:00
await session.defaultSession.clearAuthCache();
});
after(() => {
2020-03-20 20:28:31 +00:00
server.close();
proxyServer.close();
});
it('is emitted when navigating', async () => {
2020-03-20 20:28:31 +00:00
const [user, pass] = ['user', 'pass'];
const w = new BrowserWindow({ show: false });
let eventRequest: any;
let eventAuthInfo: any;
w.webContents.on('login', (event, request, authInfo, cb) => {
2020-03-20 20:28:31 +00:00
eventRequest = request;
eventAuthInfo = authInfo;
event.preventDefault();
cb(user, pass);
});
await w.loadURL(serverUrl);
const body = await w.webContents.executeJavaScript('document.documentElement.textContent');
expect(body).to.equal(`Basic ${Buffer.from(`${user}:${pass}`).toString('base64')}`);
expect(eventRequest.url).to.equal(serverUrl + '/');
expect(eventAuthInfo.isProxy).to.be.false();
expect(eventAuthInfo.scheme).to.equal('basic');
expect(eventAuthInfo.host).to.equal('127.0.0.1');
expect(eventAuthInfo.port).to.equal(serverPort);
expect(eventAuthInfo.realm).to.equal('Foo');
});
it('is emitted when a proxy requests authorization', async () => {
2020-03-20 20:28:31 +00:00
const customSession = session.fromPartition(`${Math.random()}`);
await customSession.setProxy({ proxyRules: `127.0.0.1:${proxyServerPort}`, proxyBypassRules: '<-loopback>' });
const [user, pass] = ['user', 'pass'];
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession } });
let eventRequest: any;
let eventAuthInfo: any;
w.webContents.on('login', (event, request, authInfo, cb) => {
2020-03-20 20:28:31 +00:00
eventRequest = request;
eventAuthInfo = authInfo;
event.preventDefault();
cb(user, pass);
});
await w.loadURL(`${serverUrl}/no-auth`);
const body = await w.webContents.executeJavaScript('document.documentElement.textContent');
expect(body).to.equal(`Basic ${Buffer.from(`${user}:${pass}`).toString('base64')}`);
expect(eventRequest.url).to.equal(`${serverUrl}/no-auth`);
expect(eventAuthInfo.isProxy).to.be.true();
expect(eventAuthInfo.scheme).to.equal('basic');
expect(eventAuthInfo.host).to.equal('127.0.0.1');
expect(eventAuthInfo.port).to.equal(proxyServerPort);
expect(eventAuthInfo.realm).to.equal('Foo');
});
it('cancels authentication when callback is called with no arguments', async () => {
2020-03-20 20:28:31 +00:00
const w = new BrowserWindow({ show: false });
w.webContents.on('login', (event, request, authInfo, cb) => {
2020-03-20 20:28:31 +00:00
event.preventDefault();
cb();
});
await w.loadURL(serverUrl);
const body = await w.webContents.executeJavaScript('document.documentElement.textContent');
expect(body).to.equal('401');
});
});
describe('page-title-updated event', () => {
afterEach(closeAllWindows);
it('is emitted with a full title for pages with no navigation', async () => {
const bw = new BrowserWindow({ show: false, webPreferences: { nativeWindowOpen: true } });
await bw.loadURL('about:blank');
bw.webContents.executeJavaScript('child = window.open("", "", "show=no"); null');
const [, child] = await emittedOnce(app, 'web-contents-created');
bw.webContents.executeJavaScript('child.document.title = "new title"');
const [, title] = await emittedOnce(child, 'page-title-updated');
expect(title).to.equal('new title');
});
});
describe('crashed event', () => {
it('does not crash main process when destroying WebContents in it', (done) => {
const contents = (webContents as any).create({ nodeIntegration: true });
contents.once('crashed', () => {
contents.destroy();
done();
});
contents.loadURL('about:blank').then(() => contents.forcefullyCrashRenderer());
});
});
it('emits a cancelable event before creating a child webcontents', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
});
w.webContents.on('-will-add-new-contents' as any, (event: any, url: any) => {
expect(url).to.equal('about:blank');
event.preventDefault();
});
let wasCalled = false;
w.webContents.on('new-window' as any, () => {
wasCalled = true;
});
await w.loadURL('about:blank');
2020-07-09 17:18:49 +00:00
await w.webContents.executeJavaScript('window.open(\'about:blank\')');
await new Promise((resolve) => { process.nextTick(resolve); });
expect(wasCalled).to.equal(false);
await closeAllWindows();
});
2020-03-20 20:28:31 +00:00
});