test: remove a few casts to any (#39713)
This commit is contained in:
parent
c5b20eeb13
commit
d76a35afe4
7 changed files with 29 additions and 21 deletions
|
@ -2343,7 +2343,7 @@ describe('BrowserWindow module', () => {
|
||||||
|
|
||||||
expect(w.isAlwaysOnTop()).to.be.false();
|
expect(w.isAlwaysOnTop()).to.be.false();
|
||||||
expect(c.isAlwaysOnTop()).to.be.true('child is not always on top');
|
expect(c.isAlwaysOnTop()).to.be.true('child is not always on top');
|
||||||
expect((c as any)._getAlwaysOnTopLevel()).to.equal('screen-saver');
|
expect(c._getAlwaysOnTopLevel()).to.equal('screen-saver');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ describe('debugger module', () => {
|
||||||
});
|
});
|
||||||
await detach;
|
await detach;
|
||||||
expect(w.webContents.debugger.isAttached()).to.be.false();
|
expect(w.webContents.debugger.isAttached()).to.be.false();
|
||||||
expect((w as any).devToolsWebContents.isDestroyed()).to.be.false();
|
expect(w.devToolsWebContents.isDestroyed()).to.be.false();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -119,9 +119,9 @@ describe('debugger module', () => {
|
||||||
w.webContents.debugger.sendCommand('Console.enable');
|
w.webContents.debugger.sendCommand('Console.enable');
|
||||||
const [,, params] = await message;
|
const [,, params] = await message;
|
||||||
w.webContents.debugger.detach();
|
w.webContents.debugger.detach();
|
||||||
expect((params as any).message.level).to.equal('log');
|
expect(params.message.level).to.equal('log');
|
||||||
expect((params as any).message.url).to.equal(url);
|
expect(params.message.url).to.equal(url);
|
||||||
expect((params as any).message.text).to.equal('a');
|
expect(params.message.text).to.equal('a');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns error message when command fails', async () => {
|
it('returns error message when command fails', async () => {
|
||||||
|
|
|
@ -239,7 +239,7 @@ describe('ipc module', () => {
|
||||||
const p = once(ipcMain, 'port');
|
const p = once(ipcMain, 'port');
|
||||||
await w.webContents.executeJavaScript(`(${function () {
|
await w.webContents.executeJavaScript(`(${function () {
|
||||||
const channel = new MessageChannel();
|
const channel = new MessageChannel();
|
||||||
(channel.port2 as any).onmessage = (ev: any) => {
|
channel.port2.onmessage = (ev: any) => {
|
||||||
channel.port2.postMessage(ev.data * 2);
|
channel.port2.postMessage(ev.data * 2);
|
||||||
};
|
};
|
||||||
require('electron').ipcRenderer.postMessage('port', '', [channel.port1]);
|
require('electron').ipcRenderer.postMessage('port', '', [channel.port1]);
|
||||||
|
@ -280,7 +280,7 @@ describe('ipc module', () => {
|
||||||
w2.loadURL('about:blank');
|
w2.loadURL('about:blank');
|
||||||
w1.webContents.executeJavaScript(`(${function () {
|
w1.webContents.executeJavaScript(`(${function () {
|
||||||
const channel = new MessageChannel();
|
const channel = new MessageChannel();
|
||||||
(channel.port2 as any).onmessage = (ev: any) => {
|
channel.port2.onmessage = (ev: any) => {
|
||||||
require('electron').ipcRenderer.send('message received', ev.data);
|
require('electron').ipcRenderer.send('message received', ev.data);
|
||||||
};
|
};
|
||||||
require('electron').ipcRenderer.postMessage('port', '', [channel.port1]);
|
require('electron').ipcRenderer.postMessage('port', '', [channel.port1]);
|
||||||
|
@ -306,7 +306,7 @@ describe('ipc module', () => {
|
||||||
ipcRenderer.on('port', e => {
|
ipcRenderer.on('port', e => {
|
||||||
const [port] = e.ports;
|
const [port] = e.ports;
|
||||||
port.start();
|
port.start();
|
||||||
(port as any).onclose = () => {
|
port.onclose = () => {
|
||||||
ipcRenderer.send('closed');
|
ipcRenderer.send('closed');
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -322,9 +322,9 @@ describe('ipc module', () => {
|
||||||
w.loadURL('about:blank');
|
w.loadURL('about:blank');
|
||||||
await w.webContents.executeJavaScript(`(${async function () {
|
await w.webContents.executeJavaScript(`(${async function () {
|
||||||
const { port2 } = new MessageChannel();
|
const { port2 } = new MessageChannel();
|
||||||
await new Promise(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
port2.start();
|
port2.start();
|
||||||
(port2 as any).onclose = resolve;
|
port2.onclose = resolve;
|
||||||
process._linkedBinding('electron_common_v8_util').requestGarbageCollectionForTesting();
|
process._linkedBinding('electron_common_v8_util').requestGarbageCollectionForTesting();
|
||||||
});
|
});
|
||||||
}})()`);
|
}})()`);
|
||||||
|
@ -336,9 +336,9 @@ describe('ipc module', () => {
|
||||||
ipcMain.once('do-a-gc', () => v8Util.requestGarbageCollectionForTesting());
|
ipcMain.once('do-a-gc', () => v8Util.requestGarbageCollectionForTesting());
|
||||||
await w.webContents.executeJavaScript(`(${async function () {
|
await w.webContents.executeJavaScript(`(${async function () {
|
||||||
const { port1, port2 } = new MessageChannel();
|
const { port1, port2 } = new MessageChannel();
|
||||||
await new Promise(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
port2.start();
|
port2.start();
|
||||||
(port2 as any).onclose = resolve;
|
port2.onclose = resolve;
|
||||||
require('electron').ipcRenderer.postMessage('nobody-listening', null, [port1]);
|
require('electron').ipcRenderer.postMessage('nobody-listening', null, [port1]);
|
||||||
require('electron').ipcRenderer.send('do-a-gc');
|
require('electron').ipcRenderer.send('do-a-gc');
|
||||||
});
|
});
|
||||||
|
|
|
@ -1911,7 +1911,7 @@ describe('webContents module', () => {
|
||||||
it('does not crash when called via BrowserWindow', () => {
|
it('does not crash when called via BrowserWindow', () => {
|
||||||
const w = new BrowserWindow({ show: false });
|
const w = new BrowserWindow({ show: false });
|
||||||
|
|
||||||
(w as any).setBackgroundThrottling(true);
|
w.setBackgroundThrottling(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not crash when disallowing', () => {
|
it('does not crash when disallowing', () => {
|
||||||
|
@ -1946,11 +1946,11 @@ describe('webContents module', () => {
|
||||||
it('works via BrowserWindow', () => {
|
it('works via BrowserWindow', () => {
|
||||||
const w = new BrowserWindow({ show: false });
|
const w = new BrowserWindow({ show: false });
|
||||||
|
|
||||||
(w as any).setBackgroundThrottling(false);
|
w.setBackgroundThrottling(false);
|
||||||
expect((w as any).getBackgroundThrottling()).to.equal(false);
|
expect(w.getBackgroundThrottling()).to.equal(false);
|
||||||
|
|
||||||
(w as any).setBackgroundThrottling(true);
|
w.setBackgroundThrottling(true);
|
||||||
expect((w as any).getBackgroundThrottling()).to.equal(true);
|
expect(w.getBackgroundThrottling()).to.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2012,13 +2012,13 @@ describe('chromium features', () => {
|
||||||
const w = new BrowserWindow({ show: false });
|
const w = new BrowserWindow({ show: false });
|
||||||
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
|
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
|
||||||
// History should have current page by now.
|
// History should have current page by now.
|
||||||
expect((w.webContents as any).length()).to.equal(1);
|
expect(w.webContents.length()).to.equal(1);
|
||||||
|
|
||||||
const waitCommit = once(w.webContents, 'navigation-entry-committed');
|
const waitCommit = once(w.webContents, 'navigation-entry-committed');
|
||||||
w.webContents.executeJavaScript('window.history.pushState({}, "")');
|
w.webContents.executeJavaScript('window.history.pushState({}, "")');
|
||||||
await waitCommit;
|
await waitCommit;
|
||||||
// Initial page + pushed state.
|
// Initial page + pushed state.
|
||||||
expect((w.webContents as any).length()).to.equal(2);
|
expect(w.webContents.length()).to.equal(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2038,7 +2038,7 @@ describe('chromium features', () => {
|
||||||
once(w.webContents, 'did-navigate-in-page')
|
once(w.webContents, 'did-navigate-in-page')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
(w.webContents as any).once('navigation-entry-committed', () => {
|
w.webContents.once('navigation-entry-committed' as any, () => {
|
||||||
expect.fail('Unexpected navigation-entry-committed');
|
expect.fail('Unexpected navigation-entry-committed');
|
||||||
});
|
});
|
||||||
w.webContents.once('did-navigate-in-page', () => {
|
w.webContents.once('did-navigate-in-page', () => {
|
||||||
|
@ -2046,7 +2046,7 @@ describe('chromium features', () => {
|
||||||
});
|
});
|
||||||
await w.webContents.mainFrame.frames[0].executeJavaScript('window.history.back()');
|
await w.webContents.mainFrame.frames[0].executeJavaScript('window.history.back()');
|
||||||
expect(await w.webContents.executeJavaScript('window.history.state')).to.equal(1);
|
expect(await w.webContents.executeJavaScript('window.history.state')).to.equal(1);
|
||||||
expect((w.webContents as any).getActiveIndex()).to.equal(1);
|
expect(w.webContents.getActiveIndex()).to.equal(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
6
typings/internal-ambient.d.ts
vendored
6
typings/internal-ambient.d.ts
vendored
|
@ -291,6 +291,12 @@ declare interface Window {
|
||||||
trustedTypes: TrustedTypePolicyFactory;
|
trustedTypes: TrustedTypePolicyFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/electron/electron/blob/main/docs/tutorial/message-ports.md#extension-close-event
|
||||||
|
|
||||||
|
interface MessagePort {
|
||||||
|
onclose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
|
// https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
|
||||||
|
|
||||||
type TrustedHTML = string;
|
type TrustedHTML = string;
|
||||||
|
|
2
typings/internal-electron.d.ts
vendored
2
typings/internal-electron.d.ts
vendored
|
@ -32,6 +32,8 @@ declare namespace Electron {
|
||||||
_setEscapeTouchBarItem: (item: TouchBarItemType | {}) => void;
|
_setEscapeTouchBarItem: (item: TouchBarItemType | {}) => void;
|
||||||
_refreshTouchBarItem: (itemID: string) => void;
|
_refreshTouchBarItem: (itemID: string) => void;
|
||||||
_getWindowButtonVisibility: () => boolean;
|
_getWindowButtonVisibility: () => boolean;
|
||||||
|
_getAlwaysOnTopLevel: () => string;
|
||||||
|
devToolsWebContents: WebContents;
|
||||||
frameName: string;
|
frameName: string;
|
||||||
on(event: '-touch-bar-interaction', listener: (event: Event, itemID: string, details: any) => void): this;
|
on(event: '-touch-bar-interaction', listener: (event: Event, itemID: string, details: any) => void): this;
|
||||||
removeListener(event: '-touch-bar-interaction', listener: (event: Event, itemID: string, details: any) => void): this;
|
removeListener(event: '-touch-bar-interaction', listener: (event: Event, itemID: string, details: any) => void): this;
|
||||||
|
|
Loading…
Reference in a new issue