refactor: use types for once() return values in spec (#38872)

This commit is contained in:
Milan Burda 2023-06-22 20:38:52 +02:00 коммит произвёл GitHub
Родитель abec9ead06
Коммит 9226cc662b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 85 добавлений и 85 удалений

Просмотреть файл

@ -6,7 +6,7 @@ import * as net from 'node:net';
import * as fs from 'fs-extra';
import * as path from 'node:path';
import { promisify } from 'node:util';
import { app, BrowserWindow, Menu, session, net as electronNet } from 'electron/main';
import { app, BrowserWindow, Menu, session, net as electronNet, WebContents } from 'electron/main';
import { closeWindow, closeAllWindows } from './lib/window-helpers';
import { ifdescribe, ifit, listen, waitUntil } from './lib/spec-helpers';
import { once } from 'node:events';
@ -495,7 +495,7 @@ describe('app module', () => {
afterEach(() => closeWindow(w).then(() => { w = null as any; }));
it('should emit browser-window-focus event when window is focused', async () => {
const emitted = once(app, 'browser-window-focus');
const emitted = once(app, 'browser-window-focus') as Promise<[any, BrowserWindow]>;
w = new BrowserWindow({ show: false });
w.emit('focus');
const [, window] = await emitted;
@ -503,7 +503,7 @@ describe('app module', () => {
});
it('should emit browser-window-blur event when window is blurred', async () => {
const emitted = once(app, 'browser-window-blur');
const emitted = once(app, 'browser-window-blur') as Promise<[any, BrowserWindow]>;
w = new BrowserWindow({ show: false });
w.emit('blur');
const [, window] = await emitted;
@ -511,14 +511,14 @@ describe('app module', () => {
});
it('should emit browser-window-created event when window is created', async () => {
const emitted = once(app, 'browser-window-created');
const emitted = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
w = new BrowserWindow({ show: false });
const [, window] = await emitted;
expect(window.id).to.equal(w.id);
});
it('should emit web-contents-created event when a webContents is created', async () => {
const emitted = once(app, 'web-contents-created');
const emitted = once(app, 'web-contents-created') as Promise<[any, WebContents]>;
w = new BrowserWindow({ show: false });
const [, webContents] = await emitted;
expect(webContents.id).to.equal(w.webContents.id);
@ -535,7 +535,7 @@ describe('app module', () => {
});
await w.loadURL('about:blank');
const emitted = once(app, 'renderer-process-crashed');
const emitted = once(app, 'renderer-process-crashed') as Promise<[any, WebContents]>;
w.webContents.executeJavaScript('process.crash()');
const [, webContents] = await emitted;
@ -553,7 +553,7 @@ describe('app module', () => {
});
await w.loadURL('about:blank');
const emitted = once(app, 'render-process-gone');
const emitted = once(app, 'render-process-gone') as Promise<[any, WebContents, Electron.RenderProcessGoneDetails]>;
w.webContents.executeJavaScript('process.crash()');
const [, webContents, details] = await emitted;
@ -1935,7 +1935,7 @@ describe('default behavior', () => {
it('should emit a login event on app when a WebContents hits a 401', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(serverUrl);
const [, webContents] = await once(app, 'login');
const [, webContents] = await once(app, 'login') as [any, WebContents];
expect(webContents).to.equal(w.webContents);
});
});

Просмотреть файл

@ -6,7 +6,7 @@ import { once } from 'node:events';
ifdescribe(!process.mas)('autoUpdater module', function () {
describe('checkForUpdates', function () {
ifit(process.platform === 'win32')('emits an error on Windows if the feed URL is not set', async function () {
const errorEvent = once(autoUpdater, 'error');
const errorEvent = once(autoUpdater, 'error') as Promise<[Error]>;
autoUpdater.setFeedURL({ url: '' });
autoUpdater.checkForUpdates();
const [error] = await errorEvent;
@ -56,7 +56,7 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
ifdescribe(process.platform === 'darwin' && process.arch !== 'arm64')('on Mac', function () {
it('emits an error when the application is unsigned', async () => {
const errorEvent = once(autoUpdater, 'error');
const errorEvent = once(autoUpdater, 'error') as Promise<[Error]>;
autoUpdater.setFeedURL({ url: '' });
const [error] = await errorEvent;
expect(error.message).equal('Could not get code signature for running application');
@ -80,7 +80,7 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
describe('quitAndInstall', () => {
ifit(process.platform === 'win32')('emits an error on Windows when no update is available', async function () {
const errorEvent = once(autoUpdater, 'error');
const errorEvent = once(autoUpdater, 'error') as Promise<[Error]>;
autoUpdater.quitAndInstall();
const [error] = await errorEvent;
expect(error.message).to.equal('No update available, can\'t quit and install');

Просмотреть файл

@ -2312,7 +2312,7 @@ describe('BrowserWindow module', () => {
});
it('causes the right value to be emitted on `always-on-top-changed`', async () => {
const alwaysOnTopChanged = once(w, 'always-on-top-changed');
const alwaysOnTopChanged = once(w, 'always-on-top-changed') as Promise<[any, boolean]>;
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
w.setAlwaysOnTop(true);
const [, alwaysOnTop] = await alwaysOnTopChanged;
@ -2694,7 +2694,7 @@ describe('BrowserWindow module', () => {
// https://github.com/electron/electron/issues/25413, and is not integral
// to the test.
const p = once(w.webContents, 'did-attach-webview');
const [, webviewContents] = await once(app, 'web-contents-created');
const [, webviewContents] = await once(app, 'web-contents-created') as [any, WebContents];
expect(BrowserWindow.fromWebContents(webviewContents)!.id).to.equal(w.id);
await p;
});
@ -3496,7 +3496,7 @@ describe('BrowserWindow module', () => {
const pageUrl = 'file://' + htmlPath;
const answer = once(ipcMain, 'answer');
w.loadURL(pageUrl);
const [, { url, frameName, options }] = await once(w.webContents, 'did-create-window');
const [, { url, frameName, options }] = await once(w.webContents, 'did-create-window') as [BrowserWindow, Electron.DidCreateWindowDetails];
const expectedUrl = process.platform === 'win32'
? 'file:///' + htmlPath.replace(/\\/g, '/')
: pageUrl;
@ -3542,7 +3542,7 @@ describe('BrowserWindow module', () => {
// The page is going to open a popup that it won't be able to close.
// We have to close it from here later.
const [, popupWindow] = await once(app, 'browser-window-created');
const [, popupWindow] = await once(app, 'browser-window-created') as [any, BrowserWindow];
// Ask the popup window for details.
const detailsAnswer = once(ipcMain, 'child-loaded');
@ -3600,11 +3600,11 @@ describe('BrowserWindow module', () => {
w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload: preloadPath, contextIsolation: false } } }));
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
const [[, childWebContents]] = await Promise.all([
once(app, 'web-contents-created'),
once(app, 'web-contents-created') as Promise<[any, WebContents]>,
once(ipcMain, 'answer')
]);
const webPreferences = childWebContents.getLastWebPreferences();
expect(webPreferences.contextIsolation).to.equal(false);
expect(webPreferences!.contextIsolation).to.equal(false);
});
it('should set ipc event sender correctly', async () => {
@ -3736,7 +3736,7 @@ describe('BrowserWindow module', () => {
contextIsolation: false
}
});
const didAttachWebview = once(w.webContents, 'did-attach-webview');
const didAttachWebview = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
const webviewDomReady = once(ipcMain, 'webview-dom-ready');
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'));
@ -3850,11 +3850,11 @@ describe('BrowserWindow module', () => {
}));
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
const [[, childWebContents]] = await Promise.all([
once(app, 'web-contents-created'),
once(app, 'web-contents-created') as Promise<[any, WebContents]>,
once(ipcMain, 'answer')
]);
const webPreferences = childWebContents.getLastWebPreferences();
expect(webPreferences.contextIsolation).to.equal(false);
expect(webPreferences!.contextIsolation).to.equal(false);
});
describe('window.location', () => {
@ -5952,10 +5952,10 @@ describe('BrowserWindow module', () => {
preload: path.join(fixtures, 'api', 'isolated-preload.js')
}
});
const browserWindowCreated = once(app, 'browser-window-created');
const browserWindowCreated = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
iw.loadFile(path.join(fixtures, 'pages', 'window-open.html'));
const [, window] = await browserWindowCreated;
expect(window.webContents.getLastWebPreferences().contextIsolation).to.be.true('contextIsolation');
expect(window.webContents.getLastWebPreferences()!.contextIsolation).to.be.true('contextIsolation');
});
it('separates the page context from the Electron/preload context with sandbox on', async () => {
const ws = new BrowserWindow({
@ -6086,7 +6086,7 @@ describe('BrowserWindow module', () => {
afterEach(closeAllWindows);
it('creates offscreen window with correct size', async () => {
const paint = once(w.webContents, 'paint');
const paint = once(w.webContents, 'paint') as Promise<[any, Electron.Rectangle, Electron.NativeImage]>;
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
const [,, data] = await paint;
expect(data.constructor.name).to.equal('NativeImage');
@ -6117,7 +6117,7 @@ describe('BrowserWindow module', () => {
describe('window.webContents.isPainting()', () => {
it('returns whether is currently painting', async () => {
const paint = once(w.webContents, 'paint');
const paint = once(w.webContents, 'paint') as Promise<[any, Electron.Rectangle, Electron.NativeImage]>;
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await paint;
expect(w.webContents.isPainting()).to.be.true('isPainting');
@ -6144,7 +6144,7 @@ describe('BrowserWindow module', () => {
w.webContents.stopPainting();
w.webContents.startPainting();
await once(w.webContents, 'paint');
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.isPainting()).to.be.true('isPainting');
});
});
@ -6152,13 +6152,13 @@ describe('BrowserWindow module', () => {
describe('frameRate APIs', () => {
it('has default frame rate (function)', async () => {
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await once(w.webContents, 'paint');
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.getFrameRate()).to.equal(60);
});
it('has default frame rate (property)', async () => {
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'));
await once(w.webContents, 'paint');
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.frameRate).to.equal(60);
});
@ -6169,7 +6169,7 @@ describe('BrowserWindow module', () => {
w.webContents.setFrameRate(30);
await once(w.webContents, 'paint');
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.getFrameRate()).to.equal(30);
});
@ -6180,7 +6180,7 @@ describe('BrowserWindow module', () => {
w.webContents.frameRate = 30;
await once(w.webContents, 'paint');
await once(w.webContents, 'paint') as [any, Electron.Rectangle, Electron.NativeImage];
expect(w.webContents.frameRate).to.equal(30);
});
});

Просмотреть файл

@ -84,7 +84,7 @@ describe('nativeTheme module', () => {
.addEventListener('change', () => require('electron').ipcRenderer.send('theme-change'))
`);
const originalSystemIsDark = await getPrefersColorSchemeIsDark(w);
let changePromise: Promise<any[]> = once(ipcMain, 'theme-change');
let changePromise = once(ipcMain, 'theme-change');
nativeTheme.themeSource = 'dark';
if (!originalSystemIsDark) await changePromise;
expect(await getPrefersColorSchemeIsDark(w)).to.equal(true);

Просмотреть файл

@ -1412,7 +1412,7 @@ describe('session module', () => {
describe('session-created event', () => {
it('is emitted when a session is created', async () => {
const sessionCreated = once(app, 'session-created');
const sessionCreated = once(app, 'session-created') as Promise<[any, Session]>;
const session1 = session.fromPartition('' + Math.random());
const [session2] = await sessionCreated;
expect(session1).to.equal(session2);

Просмотреть файл

@ -3,7 +3,7 @@ import { AddressInfo } from 'node:net';
import * as path from 'node:path';
import * as fs from 'node:fs';
import * as http from 'node:http';
import { BrowserWindow, ipcMain, webContents, session, app, BrowserView } from 'electron/main';
import { BrowserWindow, ipcMain, webContents, session, app, BrowserView, WebContents } from 'electron/main';
import { closeAllWindows } from './lib/window-helpers';
import { ifdescribe, defer, waitUntil, listen, ifit } from './lib/spec-helpers';
import { once } from 'node:events';
@ -24,7 +24,7 @@ describe('webContents module', () => {
});
w.loadFile(path.join(fixturesPath, 'pages', 'webview-zoom-factor.html'));
await once(w.webContents, 'did-attach-webview');
await once(w.webContents, 'did-attach-webview') as [any, WebContents];
w.webContents.openDevTools();
@ -637,7 +637,7 @@ describe('webContents module', () => {
if (opts.meta) modifiers.push('meta');
if (opts.isAutoRepeat) modifiers.push('isAutoRepeat');
const p = once(w.webContents, 'before-input-event');
const p = once(w.webContents, 'before-input-event') as Promise<[any, Electron.Input]>;
w.webContents.sendInputEvent({
type: opts.type,
keyCode: opts.keyCode,
@ -720,7 +720,7 @@ describe('webContents module', () => {
modifiers: ['control', 'meta']
});
const [, zoomDirection] = await once(w.webContents, 'zoom-changed');
const [, zoomDirection] = await once(w.webContents, 'zoom-changed') as [any, string];
expect(zoomDirection).to.equal('in');
};
@ -743,7 +743,7 @@ describe('webContents module', () => {
modifiers: ['control', 'meta']
});
const [, zoomDirection] = await once(w.webContents, 'zoom-changed');
const [, zoomDirection] = await once(w.webContents, 'zoom-changed') as [any, string];
expect(zoomDirection).to.equal('out');
};
@ -1293,7 +1293,7 @@ describe('webContents module', () => {
it('can get opener with window.open()', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadURL('about:blank');
const childPromise = once(w.webContents, 'did-create-window');
const childPromise = once(w.webContents, 'did-create-window') as Promise<[BrowserWindow, Electron.DidCreateWindowDetails]>;
w.webContents.executeJavaScript('window.open("about:blank")', true);
const [childWindow] = await childPromise;
expect(childWindow.webContents.opener).to.equal(w.webContents.mainFrame);
@ -1301,7 +1301,7 @@ describe('webContents module', () => {
it('has no opener when using "noopener"', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadURL('about:blank');
const childPromise = once(w.webContents, 'did-create-window');
const childPromise = once(w.webContents, 'did-create-window') as Promise<[BrowserWindow, Electron.DidCreateWindowDetails]>;
w.webContents.executeJavaScript('window.open("about:blank", undefined, "noopener")', true);
const [childWindow] = await childPromise;
expect(childWindow.webContents.opener).to.be.null();
@ -1309,7 +1309,7 @@ describe('webContents module', () => {
it('can get opener with a[target=_blank][rel=opener]', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadURL('about:blank');
const childPromise = once(w.webContents, 'did-create-window');
const childPromise = once(w.webContents, 'did-create-window') as Promise<[BrowserWindow, Electron.DidCreateWindowDetails]>;
w.webContents.executeJavaScript(`(function() {
const a = document.createElement('a');
a.target = '_blank';
@ -1323,7 +1323,7 @@ describe('webContents module', () => {
it('has no opener with a[target=_blank][rel=noopener]', async () => {
const w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
await w.loadURL('about:blank');
const childPromise = once(w.webContents, 'did-create-window');
const childPromise = once(w.webContents, 'did-create-window') as Promise<[BrowserWindow, Electron.DidCreateWindowDetails]>;
w.webContents.executeJavaScript(`(function() {
const a = document.createElement('a');
a.target = '_blank';
@ -1485,7 +1485,7 @@ describe('webContents module', () => {
it('forcefullyCrashRenderer() crashes the process with reason=killed||crashed', async () => {
expect(w.webContents.isCrashed()).to.equal(false);
const crashEvent = once(w.webContents, 'render-process-gone');
const crashEvent = once(w.webContents, 'render-process-gone') as Promise<[any, Electron.RenderProcessGoneDetails]>;
w.webContents.forcefullyCrashRenderer();
const [, details] = await crashEvent;
expect(details.reason === 'killed' || details.reason === 'crashed').to.equal(true, 'reason should be killed || crashed');
@ -1716,7 +1716,7 @@ describe('webContents module', () => {
}
});
const promise = once(w.webContents, 'preload-error');
const promise = once(w.webContents, 'preload-error') as Promise<[any, string, Error]>;
w.loadURL('about:blank');
const [, preloadPath, error] = await promise;
@ -1735,7 +1735,7 @@ describe('webContents module', () => {
}
});
const promise = once(w.webContents, 'preload-error');
const promise = once(w.webContents, 'preload-error') as Promise<[any, string, Error]>;
w.loadURL('about:blank');
const [, preloadPath, error] = await promise;
@ -1754,7 +1754,7 @@ describe('webContents module', () => {
}
});
const promise = once(w.webContents, 'preload-error');
const promise = once(w.webContents, 'preload-error') as Promise<[any, string, Error]>;
w.loadURL('about:blank');
const [, preloadPath, error] = await promise;
@ -2227,9 +2227,9 @@ describe('webContents module', () => {
const bw = new BrowserWindow({ show: false });
await bw.loadURL('about:blank');
bw.webContents.executeJavaScript('child = window.open("", "", "show=no"); null');
const [, child] = await once(app, 'web-contents-created');
const [, child] = await once(app, 'web-contents-created') as [any, WebContents];
bw.webContents.executeJavaScript('child.document.title = "new title"');
const [, title] = await once(child, 'page-title-updated');
const [, title] = await once(child, 'page-title-updated') as [any, string];
expect(title).to.equal('new title');
});
});
@ -2251,7 +2251,7 @@ describe('webContents module', () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'));
const promise = once(w.webContents, 'context-menu');
const promise = once(w.webContents, 'context-menu') as Promise<[any, Electron.ContextMenuParams]>;
// Simulate right-click to create context-menu event.
const opts = { x: 0, y: 0, button: 'right' as any };
@ -2350,7 +2350,7 @@ describe('webContents module', () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('window.moveTo(100, 100)', true);
const [, rect] = await once(w.webContents, 'content-bounds-updated');
const [, rect] = await once(w.webContents, 'content-bounds-updated') as [any, Electron.Rectangle];
const { width, height } = w.getBounds();
expect(rect).to.deep.equal({
x: 100,
@ -2367,7 +2367,7 @@ describe('webContents module', () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('window.resizeTo(100, 100)', true);
const [, rect] = await once(w.webContents, 'content-bounds-updated');
const [, rect] = await once(w.webContents, 'content-bounds-updated') as [any, Electron.Rectangle];
const { x, y } = w.getBounds();
expect(rect).to.deep.equal({
x,

Просмотреть файл

@ -143,7 +143,7 @@ describe('webFrameMain module', () => {
it('should show parent origin when child page is about:blank', async () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixtures, 'pages', 'blank.html'));
const webContentsCreated: Promise<[unknown, WebContents]> = once(app, 'web-contents-created') as any;
const webContentsCreated = once(app, 'web-contents-created') as Promise<[any, WebContents]>;
expect(w.webContents.mainFrame.origin).to.equal('file://');
await w.webContents.executeJavaScript('window.open("", null, "show=false"), null');
const [, childWebContents] = await webContentsCreated;
@ -163,7 +163,7 @@ describe('webFrameMain module', () => {
expect(mainFrame.origin).to.equal(serverA.url.replace(/\/$/, ''));
const [childFrame] = mainFrame.frames;
expect(childFrame.origin).to.equal(serverB.url.replace(/\/$/, ''));
const webContentsCreated: Promise<[unknown, WebContents]> = once(app, 'web-contents-created') as any;
const webContentsCreated = once(app, 'web-contents-created') as Promise<[any, WebContents]>;
await childFrame.executeJavaScript('window.open("", null, "show=false"), null');
const [, childWebContents] = await webContentsCreated;
expect(childWebContents.mainFrame.origin).to.equal(childFrame.origin);
@ -367,7 +367,7 @@ describe('webFrameMain module', () => {
describe('"frame-created" event', () => {
it('emits when the main frame is created', async () => {
const w = new BrowserWindow({ show: false });
const promise = once(w.webContents, 'frame-created');
const promise = once(w.webContents, 'frame-created') as Promise<[any, Electron.FrameCreatedDetails]>;
w.webContents.loadFile(path.join(subframesPath, 'frame.html'));
const [, details] = await promise;
expect(details.frame).to.equal(w.webContents.mainFrame);
@ -375,7 +375,7 @@ describe('webFrameMain module', () => {
it('emits when nested frames are created', async () => {
const w = new BrowserWindow({ show: false });
const promise = emittedNTimes(w.webContents, 'frame-created', 2);
const promise = emittedNTimes(w.webContents, 'frame-created', 2) as Promise<[any, Electron.FrameCreatedDetails][]>;
w.webContents.loadFile(path.join(subframesPath, 'frame-container.html'));
const [[, mainDetails], [, nestedDetails]] = await promise;
expect(mainDetails.frame).to.equal(w.webContents.mainFrame);

Просмотреть файл

@ -107,7 +107,7 @@ describe('focus handling', () => {
}
});
const webviewReady = once(w.webContents, 'did-attach-webview');
const webviewReady = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
await w.loadFile(path.join(fixturesPath, 'pages', 'tab-focus-loop-elements.html'));
const [, wvContents] = await webviewReady;
webviewContents = wvContents;
@ -940,7 +940,7 @@ describe('chromium features', () => {
await w.loadFile(path.join(fixturesPath, 'pages', 'form-with-data.html'));
const windowCreatedPromise = once(app, 'browser-window-created');
const windowCreatedPromise = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
w.webContents.executeJavaScript(`
const form = document.querySelector('form')
@ -972,7 +972,7 @@ describe('chromium features', () => {
defer(() => { w.close(); });
const promise = once(app, 'browser-window-created');
const promise = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
w.loadFile(path.join(fixturesPath, 'pages', 'window-open.html'));
const [, newWindow] = await promise;
expect(newWindow.isVisible()).to.equal(true);
@ -1008,7 +1008,7 @@ describe('chromium features', () => {
w.webContents.executeJavaScript(`
{ b = window.open('devtools://devtools/bundled/inspector.html', '', 'nodeIntegration=no,show=no'); null }
`);
const [, contents] = await once(app, 'web-contents-created');
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
const typeofProcessGlobal = await contents.executeJavaScript('typeof process');
expect(typeofProcessGlobal).to.equal('undefined');
});
@ -1019,7 +1019,7 @@ describe('chromium features', () => {
w.webContents.executeJavaScript(`
{ b = window.open('about:blank', '', 'nodeIntegration=no,show=no'); null }
`);
const [, contents] = await once(app, 'web-contents-created');
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
const typeofProcessGlobal = await contents.executeJavaScript('typeof process');
expect(typeofProcessGlobal).to.equal('undefined');
});
@ -1036,14 +1036,14 @@ describe('chromium features', () => {
w.webContents.executeJavaScript(`
{ b = window.open(${JSON.stringify(windowUrl)}, '', 'javascript=no,show=no'); null }
`);
const [, contents] = await once(app, 'web-contents-created');
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
await once(contents, 'did-finish-load');
// Click link on page
contents.sendInputEvent({ type: 'mouseDown', clickCount: 1, x: 1, y: 1 });
contents.sendInputEvent({ type: 'mouseUp', clickCount: 1, x: 1, y: 1 });
const [, window] = await once(app, 'browser-window-created');
const [, window] = await once(app, 'browser-window-created') as [any, BrowserWindow];
const preferences = window.webContents.getLastWebPreferences();
expect(preferences.javascript).to.be.false();
expect(preferences!.javascript).to.be.false();
});
it('defines a window.location getter', async () => {
@ -1056,7 +1056,7 @@ describe('chromium features', () => {
const w = new BrowserWindow({ show: false });
w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
w.webContents.executeJavaScript(`{ b = window.open(${JSON.stringify(targetURL)}); null }`);
const [, window] = await once(app, 'browser-window-created');
const [, window] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(window.webContents, 'did-finish-load');
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal(targetURL);
});
@ -1065,7 +1065,7 @@ describe('chromium features', () => {
const w = new BrowserWindow({ show: false });
w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
w.webContents.executeJavaScript('{ b = window.open("about:blank"); null }');
const [, { webContents }] = await once(app, 'browser-window-created');
const [, { webContents }] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(webContents, 'did-finish-load');
// When it loads, redirect
w.webContents.executeJavaScript(`{ b.location = ${JSON.stringify(`file://${fixturesPath}/pages/base-page.html`)}; null }`);
@ -1076,7 +1076,7 @@ describe('chromium features', () => {
const w = new BrowserWindow({ show: false });
w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
w.webContents.executeJavaScript('{ b = window.open("about:blank"); null }');
const [, { webContents }] = await once(app, 'browser-window-created');
const [, { webContents }] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(webContents, 'did-finish-load');
// When it loads, redirect
w.webContents.executeJavaScript(`{ b.location.href = ${JSON.stringify(`file://${fixturesPath}/pages/base-page.html`)}; null }`);
@ -1087,7 +1087,7 @@ describe('chromium features', () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('{ b = window.open(); null }');
const [, { webContents }] = await once(app, 'browser-window-created');
const [, { webContents }] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(webContents, 'did-finish-load');
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal('about:blank');
});
@ -1096,7 +1096,7 @@ describe('chromium features', () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('{ b = window.open(\'\'); null }');
const [, { webContents }] = await once(app, 'browser-window-created');
const [, { webContents }] = await once(app, 'browser-window-created') as [any, BrowserWindow];
await once(webContents, 'did-finish-load');
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal('about:blank');
});
@ -1864,7 +1864,7 @@ describe('chromium features', () => {
it('opens when loading a pdf resource as top level navigation', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(pdfSource);
const [, contents] = await once(app, 'web-contents-created');
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
await once(contents, 'did-navigate');
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
});
@ -1872,7 +1872,7 @@ describe('chromium features', () => {
it('opens when loading a pdf resource in a iframe', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'pdf-in-iframe.html'));
const [, contents] = await once(app, 'web-contents-created');
const [, contents] = await once(app, 'web-contents-created') as [any, WebContents];
await once(contents, 'did-navigate');
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
});

Просмотреть файл

@ -54,7 +54,7 @@ describe('chrome extensions', () => {
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, sandbox: true } });
await w.loadURL('about:blank');
const promise = once(app, 'web-contents-created');
const promise = once(app, 'web-contents-created') as Promise<[any, WebContents]>;
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
const args: any = await promise;
const wc: Electron.WebContents = args[1];
@ -74,7 +74,7 @@ describe('chrome extensions', () => {
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, sandbox: true } });
await w.loadURL('about:blank');
const promise = once(app, 'web-contents-created');
const promise = once(app, 'web-contents-created') as Promise<[any, WebContents]>;
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
const args: any = await promise;
const wc: Electron.WebContents = args[1];
@ -457,7 +457,7 @@ describe('chrome extensions', () => {
it('has session in background page', async () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`);
const promise = once(app, 'web-contents-created');
const promise = once(app, 'web-contents-created') as Promise<[any, WebContents]>;
const { id } = await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
const [, bgPageContents] = await promise;
expect(bgPageContents.getType()).to.equal('backgroundPage');
@ -468,7 +468,7 @@ describe('chrome extensions', () => {
it('can open devtools of background page', async () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`);
const promise = once(app, 'web-contents-created');
const promise = once(app, 'web-contents-created') as Promise<[any, WebContents]>;
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
const [, bgPageContents] = await promise;
expect(bgPageContents.getType()).to.equal('backgroundPage');

Просмотреть файл

@ -182,7 +182,7 @@ describe('webContents.setWindowOpenHandler', () => {
it('can change webPreferences of child windows', async () => {
browserWindow.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { defaultFontSize: 30 } } }));
const didCreateWindow = once(browserWindow.webContents, 'did-create-window');
const didCreateWindow = once(browserWindow.webContents, 'did-create-window') as Promise<[BrowserWindow, Electron.DidCreateWindowDetails]>;
browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true");
const [childWindow] = await didCreateWindow;

Просмотреть файл

@ -208,7 +208,7 @@ describe('<webview> tag', function () {
contextIsolation: false
}
});
const didAttachWebview = once(w.webContents, 'did-attach-webview');
const didAttachWebview = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
const webviewDomReady = once(ipcMain, 'webview-dom-ready');
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'));
@ -434,7 +434,7 @@ describe('<webview> tag', function () {
contextIsolation: false
}
});
const attachPromise = once(w.webContents, 'did-attach-webview');
const attachPromise = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
const readyPromise = once(ipcMain, 'dom-ready');
w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-inherited.html'));
const [, webview] = await attachPromise;
@ -453,7 +453,7 @@ describe('<webview> tag', function () {
contextIsolation: false
}
});
const attachPromise = once(w.webContents, 'did-attach-webview');
const attachPromise = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
await w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-inherited.html'));
await attachPromise;
await w.webContents.executeJavaScript('view.remove()');
@ -463,7 +463,7 @@ describe('<webview> tag', function () {
describe('requestFullscreen from webview', () => {
afterEach(closeAllWindows);
const loadWebViewWindow = async () => {
async function loadWebViewWindow (): Promise<[BrowserWindow, WebContents]> {
const w = new BrowserWindow({
webPreferences: {
webviewTag: true,
@ -472,7 +472,7 @@ describe('<webview> tag', function () {
}
});
const attachPromise = once(w.webContents, 'did-attach-webview');
const attachPromise = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
const loadPromise = once(w.webContents, 'did-finish-load');
const readyPromise = once(ipcMain, 'webview-ready');
@ -572,7 +572,7 @@ describe('<webview> tag', function () {
}
});
const didAttachWebview = once(w.webContents, 'did-attach-webview');
const didAttachWebview = once(w.webContents, 'did-attach-webview') as Promise<[any, WebContents]>;
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'));
const [, webContents] = await didAttachWebview;
@ -792,7 +792,7 @@ describe('<webview> tag', function () {
partition,
nodeintegration: 'on'
});
const [, webViewContents] = await once(app, 'web-contents-created');
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
setUpRequestHandler(webViewContents.id, 'media');
const [, errorName] = await errorFromRenderer;
expect(errorName).to.equal('PermissionDeniedError');
@ -806,7 +806,7 @@ describe('<webview> tag', function () {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
});
const [, webViewContents] = await once(app, 'web-contents-created');
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
setUpRequestHandler(webViewContents.id, 'geolocation');
const [, error] = await errorFromRenderer;
expect(error).to.equal('User denied Geolocation');
@ -820,7 +820,7 @@ describe('<webview> tag', function () {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
});
const [, webViewContents] = await once(app, 'web-contents-created');
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
setUpRequestHandler(webViewContents.id, 'midi');
const [, error] = await errorFromRenderer;
expect(error).to.equal('SecurityError');
@ -834,7 +834,7 @@ describe('<webview> tag', function () {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
});
const [, webViewContents] = await once(app, 'web-contents-created');
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
setUpRequestHandler(webViewContents.id, 'midiSysex');
const [, error] = await errorFromRenderer;
expect(error).to.equal('SecurityError');
@ -845,7 +845,7 @@ describe('<webview> tag', function () {
src: 'magnet:test',
partition
});
const [, webViewContents] = await once(app, 'web-contents-created');
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
await setUpRequestHandler(webViewContents.id, 'openExternal');
});
@ -857,7 +857,7 @@ describe('<webview> tag', function () {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no'
});
const [, webViewContents] = await once(app, 'web-contents-created');
const [, webViewContents] = await once(app, 'web-contents-created') as [any, WebContents];
await setUpRequestHandler(webViewContents.id, 'notifications');