test: use node helpers for events.once and setTimeout promise (#37374)
This commit is contained in:
parent
46c8b9c728
commit
a3e3efe4c4
47 changed files with 932 additions and 927 deletions
|
@ -1,6 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import { BrowserWindow, WebContents, webFrameMain, session, ipcMain, app, protocol, webContents } from 'electron/main';
|
||||
import { emittedOnce } from './lib/events-helpers';
|
||||
import { closeAllWindows } from './lib/window-helpers';
|
||||
import * as https from 'https';
|
||||
import * as http from 'http';
|
||||
|
@ -8,11 +7,12 @@ import * as path from 'path';
|
|||
import * as fs from 'fs';
|
||||
import * as url from 'url';
|
||||
import * as ChildProcess from 'child_process';
|
||||
import { EventEmitter } from 'events';
|
||||
import { EventEmitter, once } from 'events';
|
||||
import { promisify } from 'util';
|
||||
import { ifit, ifdescribe, defer, delay, itremote, listen } from './lib/spec-helpers';
|
||||
import { ifit, ifdescribe, defer, itremote, listen } from './lib/spec-helpers';
|
||||
import { PipeTransport } from './pipe-transport';
|
||||
import * as ws from 'ws';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
|
||||
const features = process._linkedBinding('electron_common_features');
|
||||
|
||||
|
@ -64,7 +64,7 @@ describe('reporting api', () => {
|
|||
show: false
|
||||
});
|
||||
try {
|
||||
const reportGenerated = emittedOnce(reports, 'report');
|
||||
const reportGenerated = once(reports, 'report');
|
||||
await bw.loadURL(url);
|
||||
const [report] = await reportGenerated;
|
||||
expect(report).to.be.an('array');
|
||||
|
@ -86,7 +86,7 @@ describe('window.postMessage', () => {
|
|||
it('sets the source and origin correctly', async () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
|
||||
w.loadURL(`file://${fixturesPath}/pages/window-open-postMessage-driver.html`);
|
||||
const [, message] = await emittedOnce(ipcMain, 'complete');
|
||||
const [, message] = await once(ipcMain, 'complete');
|
||||
expect(message.data).to.equal('testing');
|
||||
expect(message.origin).to.equal('file://');
|
||||
expect(message.sourceEqualsOpener).to.equal(true);
|
||||
|
@ -108,11 +108,11 @@ describe('focus handling', () => {
|
|||
}
|
||||
});
|
||||
|
||||
const webviewReady = emittedOnce(w.webContents, 'did-attach-webview');
|
||||
const webviewReady = once(w.webContents, 'did-attach-webview');
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'tab-focus-loop-elements.html'));
|
||||
const [, wvContents] = await webviewReady;
|
||||
webviewContents = wvContents;
|
||||
await emittedOnce(webviewContents, 'did-finish-load');
|
||||
await once(webviewContents, 'did-finish-load');
|
||||
w.focus();
|
||||
});
|
||||
|
||||
|
@ -123,7 +123,7 @@ describe('focus handling', () => {
|
|||
});
|
||||
|
||||
const expectFocusChange = async () => {
|
||||
const [, focusedElementId] = await emittedOnce(ipcMain, 'focus-changed');
|
||||
const [, focusedElementId] = await once(ipcMain, 'focus-changed');
|
||||
return focusedElementId;
|
||||
};
|
||||
|
||||
|
@ -224,7 +224,7 @@ describe('web security', () => {
|
|||
|
||||
it('engages CORB when web security is not disabled', async () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true, nodeIntegration: true, contextIsolation: false } });
|
||||
const p = emittedOnce(ipcMain, 'success');
|
||||
const p = once(ipcMain, 'success');
|
||||
await w.loadURL(`data:text/html,<script>
|
||||
const s = document.createElement('script')
|
||||
s.src = "${serverUrl}"
|
||||
|
@ -238,7 +238,7 @@ describe('web security', () => {
|
|||
|
||||
it('bypasses CORB when web security is disabled', async () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false, nodeIntegration: true, contextIsolation: false } });
|
||||
const p = emittedOnce(ipcMain, 'success');
|
||||
const p = once(ipcMain, 'success');
|
||||
await w.loadURL(`data:text/html,
|
||||
<script>
|
||||
window.onerror = (e) => { require('electron').ipcRenderer.send('success', e) }
|
||||
|
@ -249,7 +249,7 @@ describe('web security', () => {
|
|||
|
||||
it('engages CORS when web security is not disabled', async () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: true, nodeIntegration: true, contextIsolation: false } });
|
||||
const p = emittedOnce(ipcMain, 'response');
|
||||
const p = once(ipcMain, 'response');
|
||||
await w.loadURL(`data:text/html,<script>
|
||||
(async function() {
|
||||
try {
|
||||
|
@ -266,7 +266,7 @@ describe('web security', () => {
|
|||
|
||||
it('bypasses CORS when web security is disabled', async () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { webSecurity: false, nodeIntegration: true, contextIsolation: false } });
|
||||
const p = emittedOnce(ipcMain, 'response');
|
||||
const p = once(ipcMain, 'response');
|
||||
await w.loadURL(`data:text/html,<script>
|
||||
(async function() {
|
||||
try {
|
||||
|
@ -371,7 +371,7 @@ describe('web security', () => {
|
|||
console.log('success')
|
||||
}
|
||||
</script>`);
|
||||
const [,, message] = await emittedOnce(w.webContents, 'console-message');
|
||||
const [,, message] = await once(w.webContents, 'console-message');
|
||||
expect(message).to.equal('success');
|
||||
});
|
||||
});
|
||||
|
@ -410,7 +410,7 @@ describe('command line switches', () => {
|
|||
let stderr = '';
|
||||
appProcess.stderr.on('data', (data) => { stderr += data; });
|
||||
|
||||
const [code, signal] = await emittedOnce(appProcess, 'exit');
|
||||
const [code, signal] = await once(appProcess, 'exit');
|
||||
if (code !== 0) {
|
||||
throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ describe('command line switches', () => {
|
|||
const stdio = appProcess.stdio as unknown as [NodeJS.ReadableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.ReadableStream];
|
||||
const pipe = new PipeTransport(stdio[3], stdio[4]);
|
||||
pipe.send({ id: 1, method: 'Browser.close', params: {} });
|
||||
await emittedOnce(appProcess, 'exit');
|
||||
await once(appProcess, 'exit');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -533,7 +533,7 @@ describe('chromium features', () => {
|
|||
|
||||
let output = '';
|
||||
fpsProcess.stdout.on('data', data => { output += data; });
|
||||
await emittedOnce(fpsProcess, 'exit');
|
||||
await once(fpsProcess, 'exit');
|
||||
|
||||
expect(output).to.include(fps.join(','));
|
||||
});
|
||||
|
@ -545,7 +545,7 @@ describe('chromium features', () => {
|
|||
|
||||
let output = '';
|
||||
fpsProcess.stdout.on('data', data => { output += data; });
|
||||
await emittedOnce(fpsProcess, 'exit');
|
||||
await once(fpsProcess, 'exit');
|
||||
|
||||
expect(output).to.include(fps.join(','));
|
||||
});
|
||||
|
@ -711,7 +711,7 @@ describe('chromium features', () => {
|
|||
contextIsolation: false
|
||||
}
|
||||
});
|
||||
const message = emittedOnce(w.webContents, 'ipc-message');
|
||||
const message = once(w.webContents, 'ipc-message');
|
||||
w.webContents.session.setPermissionRequestHandler((wc, permission, callback) => {
|
||||
if (permission === 'geolocation') {
|
||||
callback(false);
|
||||
|
@ -751,7 +751,7 @@ describe('chromium features', () => {
|
|||
|
||||
appProcess = ChildProcess.spawn(process.execPath, [appPath]);
|
||||
|
||||
const [code] = await emittedOnce(appProcess, 'exit');
|
||||
const [code] = await once(appProcess, 'exit');
|
||||
expect(code).to.equal(0);
|
||||
});
|
||||
|
||||
|
@ -781,7 +781,7 @@ describe('chromium features', () => {
|
|||
it('Worker has node integration with nodeIntegrationInWorker', async () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, nodeIntegrationInWorker: true, contextIsolation: false } });
|
||||
w.loadURL(`file://${fixturesPath}/pages/worker.html`);
|
||||
const [, data] = await emittedOnce(ipcMain, 'worker-result');
|
||||
const [, data] = await once(ipcMain, 'worker-result');
|
||||
expect(data).to.equal('object function object function');
|
||||
});
|
||||
|
||||
|
@ -863,7 +863,7 @@ describe('chromium features', () => {
|
|||
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'form-with-data.html'));
|
||||
|
||||
const loadPromise = emittedOnce(w.webContents, 'did-finish-load');
|
||||
const loadPromise = once(w.webContents, 'did-finish-load');
|
||||
|
||||
w.webContents.executeJavaScript(`
|
||||
const form = document.querySelector('form')
|
||||
|
@ -887,7 +887,7 @@ describe('chromium features', () => {
|
|||
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'form-with-data.html'));
|
||||
|
||||
const windowCreatedPromise = emittedOnce(app, 'browser-window-created');
|
||||
const windowCreatedPromise = once(app, 'browser-window-created');
|
||||
|
||||
w.webContents.executeJavaScript(`
|
||||
const form = document.querySelector('form')
|
||||
|
@ -919,7 +919,7 @@ describe('chromium features', () => {
|
|||
|
||||
defer(() => { w.close(); });
|
||||
|
||||
const promise = emittedOnce(app, 'browser-window-created');
|
||||
const promise = once(app, 'browser-window-created');
|
||||
w.loadFile(path.join(fixturesPath, 'pages', 'window-open.html'));
|
||||
const [, newWindow] = await promise;
|
||||
expect(newWindow.isVisible()).to.equal(true);
|
||||
|
@ -955,7 +955,7 @@ describe('chromium features', () => {
|
|||
w.webContents.executeJavaScript(`
|
||||
{ b = window.open('devtools://devtools/bundled/inspector.html', '', 'nodeIntegration=no,show=no'); null }
|
||||
`);
|
||||
const [, contents] = await emittedOnce(app, 'web-contents-created');
|
||||
const [, contents] = await once(app, 'web-contents-created');
|
||||
const typeofProcessGlobal = await contents.executeJavaScript('typeof process');
|
||||
expect(typeofProcessGlobal).to.equal('undefined');
|
||||
});
|
||||
|
@ -966,7 +966,7 @@ describe('chromium features', () => {
|
|||
w.webContents.executeJavaScript(`
|
||||
{ b = window.open('about:blank', '', 'nodeIntegration=no,show=no'); null }
|
||||
`);
|
||||
const [, contents] = await emittedOnce(app, 'web-contents-created');
|
||||
const [, contents] = await once(app, 'web-contents-created');
|
||||
const typeofProcessGlobal = await contents.executeJavaScript('typeof process');
|
||||
expect(typeofProcessGlobal).to.equal('undefined');
|
||||
});
|
||||
|
@ -983,12 +983,12 @@ describe('chromium features', () => {
|
|||
w.webContents.executeJavaScript(`
|
||||
{ b = window.open(${JSON.stringify(windowUrl)}, '', 'javascript=no,show=no'); null }
|
||||
`);
|
||||
const [, contents] = await emittedOnce(app, 'web-contents-created');
|
||||
await emittedOnce(contents, 'did-finish-load');
|
||||
const [, contents] = await once(app, 'web-contents-created');
|
||||
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 emittedOnce(app, 'browser-window-created');
|
||||
const [, window] = await once(app, 'browser-window-created');
|
||||
const preferences = window.webContents.getLastWebPreferences();
|
||||
expect(preferences.javascript).to.be.false();
|
||||
});
|
||||
|
@ -1003,8 +1003,8 @@ 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 emittedOnce(app, 'browser-window-created');
|
||||
await emittedOnce(window.webContents, 'did-finish-load');
|
||||
const [, window] = await once(app, 'browser-window-created');
|
||||
await once(window.webContents, 'did-finish-load');
|
||||
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal(targetURL);
|
||||
});
|
||||
|
||||
|
@ -1012,30 +1012,30 @@ 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 emittedOnce(app, 'browser-window-created');
|
||||
await emittedOnce(webContents, 'did-finish-load');
|
||||
const [, { webContents }] = await once(app, 'browser-window-created');
|
||||
await once(webContents, 'did-finish-load');
|
||||
// When it loads, redirect
|
||||
w.webContents.executeJavaScript(`{ b.location = ${JSON.stringify(`file://${fixturesPath}/pages/base-page.html`)}; null }`);
|
||||
await emittedOnce(webContents, 'did-finish-load');
|
||||
await once(webContents, 'did-finish-load');
|
||||
});
|
||||
|
||||
it('defines a window.location.href setter', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
|
||||
w.webContents.executeJavaScript('{ b = window.open("about:blank"); null }');
|
||||
const [, { webContents }] = await emittedOnce(app, 'browser-window-created');
|
||||
await emittedOnce(webContents, 'did-finish-load');
|
||||
const [, { webContents }] = await once(app, 'browser-window-created');
|
||||
await once(webContents, 'did-finish-load');
|
||||
// When it loads, redirect
|
||||
w.webContents.executeJavaScript(`{ b.location.href = ${JSON.stringify(`file://${fixturesPath}/pages/base-page.html`)}; null }`);
|
||||
await emittedOnce(webContents, 'did-finish-load');
|
||||
await once(webContents, 'did-finish-load');
|
||||
});
|
||||
|
||||
it('open a blank page when no URL is specified', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.loadURL('about:blank');
|
||||
w.webContents.executeJavaScript('{ b = window.open(); null }');
|
||||
const [, { webContents }] = await emittedOnce(app, 'browser-window-created');
|
||||
await emittedOnce(webContents, 'did-finish-load');
|
||||
const [, { webContents }] = await once(app, 'browser-window-created');
|
||||
await once(webContents, 'did-finish-load');
|
||||
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal('about:blank');
|
||||
});
|
||||
|
||||
|
@ -1043,8 +1043,8 @@ describe('chromium features', () => {
|
|||
const w = new BrowserWindow({ show: false });
|
||||
w.loadURL('about:blank');
|
||||
w.webContents.executeJavaScript('{ b = window.open(\'\'); null }');
|
||||
const [, { webContents }] = await emittedOnce(app, 'browser-window-created');
|
||||
await emittedOnce(webContents, 'did-finish-load');
|
||||
const [, { webContents }] = await once(app, 'browser-window-created');
|
||||
await once(webContents, 'did-finish-load');
|
||||
expect(await w.webContents.executeJavaScript('b.location.href')).to.equal('about:blank');
|
||||
});
|
||||
|
||||
|
@ -1145,7 +1145,7 @@ describe('chromium features', () => {
|
|||
}
|
||||
});
|
||||
w.loadFile(path.join(fixturesPath, 'pages', 'window-opener.html'));
|
||||
const [, channel, opener] = await emittedOnce(w.webContents, 'ipc-message');
|
||||
const [, channel, opener] = await once(w.webContents, 'ipc-message');
|
||||
expect(channel).to.equal('opener');
|
||||
expect(opener).to.equal(null);
|
||||
});
|
||||
|
@ -1267,8 +1267,9 @@ describe('chromium features', () => {
|
|||
}
|
||||
});
|
||||
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'));
|
||||
const [, firstDeviceIds] = await emittedOnce(ipcMain, 'deviceIds');
|
||||
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds', () => w.webContents.reload());
|
||||
const [, firstDeviceIds] = await once(ipcMain, 'deviceIds');
|
||||
w.webContents.reload();
|
||||
const [, secondDeviceIds] = await once(ipcMain, 'deviceIds');
|
||||
expect(firstDeviceIds).to.deep.equal(secondDeviceIds);
|
||||
});
|
||||
|
||||
|
@ -1283,9 +1284,10 @@ describe('chromium features', () => {
|
|||
}
|
||||
});
|
||||
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'));
|
||||
const [, firstDeviceIds] = await emittedOnce(ipcMain, 'deviceIds');
|
||||
const [, firstDeviceIds] = await once(ipcMain, 'deviceIds');
|
||||
await ses.clearStorageData({ storages: ['cookies'] });
|
||||
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds', () => w.webContents.reload());
|
||||
w.webContents.reload();
|
||||
const [, secondDeviceIds] = await once(ipcMain, 'deviceIds');
|
||||
expect(firstDeviceIds).to.not.deep.equal(secondDeviceIds);
|
||||
});
|
||||
|
||||
|
@ -1477,35 +1479,35 @@ describe('chromium features', () => {
|
|||
});
|
||||
|
||||
it('cannot access localStorage', async () => {
|
||||
const response = emittedOnce(ipcMain, 'local-storage-response');
|
||||
const response = once(ipcMain, 'local-storage-response');
|
||||
contents.loadURL(protocolName + '://host/localStorage');
|
||||
const [, error] = await response;
|
||||
expect(error).to.equal('Failed to read the \'localStorage\' property from \'Window\': Access is denied for this document.');
|
||||
});
|
||||
|
||||
it('cannot access sessionStorage', async () => {
|
||||
const response = emittedOnce(ipcMain, 'session-storage-response');
|
||||
const response = once(ipcMain, 'session-storage-response');
|
||||
contents.loadURL(`${protocolName}://host/sessionStorage`);
|
||||
const [, error] = await response;
|
||||
expect(error).to.equal('Failed to read the \'sessionStorage\' property from \'Window\': Access is denied for this document.');
|
||||
});
|
||||
|
||||
it('cannot access WebSQL database', async () => {
|
||||
const response = emittedOnce(ipcMain, 'web-sql-response');
|
||||
const response = once(ipcMain, 'web-sql-response');
|
||||
contents.loadURL(`${protocolName}://host/WebSQL`);
|
||||
const [, error] = await response;
|
||||
expect(error).to.equal('Failed to execute \'openDatabase\' on \'Window\': Access to the WebDatabase API is denied in this context.');
|
||||
});
|
||||
|
||||
it('cannot access indexedDB', async () => {
|
||||
const response = emittedOnce(ipcMain, 'indexed-db-response');
|
||||
const response = once(ipcMain, 'indexed-db-response');
|
||||
contents.loadURL(`${protocolName}://host/indexedDB`);
|
||||
const [, error] = await response;
|
||||
expect(error).to.equal('Failed to execute \'open\' on \'IDBFactory\': access to the Indexed Database API is denied in this context.');
|
||||
});
|
||||
|
||||
it('cannot access cookie', async () => {
|
||||
const response = emittedOnce(ipcMain, 'cookie-response');
|
||||
const response = once(ipcMain, 'cookie-response');
|
||||
contents.loadURL(`${protocolName}://host/cookie`);
|
||||
const [, error] = await response;
|
||||
expect(error).to.equal('Failed to set the \'cookie\' property on \'Document\': Access is denied for this document.');
|
||||
|
@ -1529,7 +1531,7 @@ describe('chromium features', () => {
|
|||
res.end();
|
||||
}
|
||||
};
|
||||
setTimeout(respond, 0);
|
||||
setTimeout().then(respond);
|
||||
});
|
||||
serverUrl = (await listen(server)).url;
|
||||
serverCrossSiteUrl = serverUrl.replace('127.0.0.1', 'localhost');
|
||||
|
@ -1599,7 +1601,7 @@ describe('chromium features', () => {
|
|||
contextIsolation: false
|
||||
});
|
||||
contents.loadURL(origin);
|
||||
const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
|
||||
const [, error] = await once(ipcMain, 'web-sql-response');
|
||||
expect(error).to.be.null();
|
||||
});
|
||||
|
||||
|
@ -1611,7 +1613,7 @@ describe('chromium features', () => {
|
|||
contextIsolation: false
|
||||
});
|
||||
contents.loadURL(origin);
|
||||
const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
|
||||
const [, error] = await once(ipcMain, 'web-sql-response');
|
||||
expect(error).to.equal(securityError);
|
||||
});
|
||||
|
||||
|
@ -1623,7 +1625,7 @@ describe('chromium features', () => {
|
|||
contextIsolation: false
|
||||
});
|
||||
contents.loadURL(origin);
|
||||
const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
|
||||
const [, error] = await once(ipcMain, 'web-sql-response');
|
||||
expect(error).to.equal(securityError);
|
||||
const dbName = 'random';
|
||||
const result = await contents.executeJavaScript(`
|
||||
|
@ -1654,9 +1656,9 @@ describe('chromium features', () => {
|
|||
}
|
||||
});
|
||||
w.webContents.loadURL(origin);
|
||||
const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
|
||||
const [, error] = await once(ipcMain, 'web-sql-response');
|
||||
expect(error).to.be.null();
|
||||
const webviewResult = emittedOnce(ipcMain, 'web-sql-response');
|
||||
const webviewResult = once(ipcMain, 'web-sql-response');
|
||||
await w.webContents.executeJavaScript(`
|
||||
new Promise((resolve, reject) => {
|
||||
const webview = new WebView();
|
||||
|
@ -1684,7 +1686,7 @@ describe('chromium features', () => {
|
|||
}
|
||||
});
|
||||
w.webContents.loadURL('data:text/html,<html></html>');
|
||||
const webviewResult = emittedOnce(ipcMain, 'web-sql-response');
|
||||
const webviewResult = once(ipcMain, 'web-sql-response');
|
||||
await w.webContents.executeJavaScript(`
|
||||
new Promise((resolve, reject) => {
|
||||
const webview = new WebView();
|
||||
|
@ -1711,9 +1713,9 @@ describe('chromium features', () => {
|
|||
}
|
||||
});
|
||||
w.webContents.loadURL(origin);
|
||||
const [, error] = await emittedOnce(ipcMain, 'web-sql-response');
|
||||
const [, error] = await once(ipcMain, 'web-sql-response');
|
||||
expect(error).to.be.null();
|
||||
const webviewResult = emittedOnce(ipcMain, 'web-sql-response');
|
||||
const webviewResult = once(ipcMain, 'web-sql-response');
|
||||
await w.webContents.executeJavaScript(`
|
||||
new Promise((resolve, reject) => {
|
||||
const webview = new WebView();
|
||||
|
@ -1753,7 +1755,7 @@ describe('chromium features', () => {
|
|||
// failed to detect a real problem (perhaps related to DOM storage data caching)
|
||||
// wherein calling `getItem` immediately after `setItem` would appear to work
|
||||
// but then later (e.g. next tick) it would not.
|
||||
await delay(1);
|
||||
await setTimeout(1);
|
||||
try {
|
||||
const storedLength = await w.webContents.executeJavaScript(`${storageName}.getItem(${JSON.stringify(testKeyName)}).length`);
|
||||
expect(storedLength).to.equal(length);
|
||||
|
@ -1803,22 +1805,22 @@ describe('chromium features', () => {
|
|||
const w = new BrowserWindow({ show: false });
|
||||
|
||||
w.loadURL(pdfSource);
|
||||
await emittedOnce(w.webContents, 'did-finish-load');
|
||||
await once(w.webContents, 'did-finish-load');
|
||||
});
|
||||
|
||||
it('opens when loading a pdf resource as top level navigation', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.loadURL(pdfSource);
|
||||
const [, contents] = await emittedOnce(app, 'web-contents-created');
|
||||
await emittedOnce(contents, 'did-navigate');
|
||||
const [, contents] = await once(app, 'web-contents-created');
|
||||
await once(contents, 'did-navigate');
|
||||
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
|
||||
});
|
||||
|
||||
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 emittedOnce(app, 'web-contents-created');
|
||||
await emittedOnce(contents, 'did-navigate');
|
||||
const [, contents] = await once(app, 'web-contents-created');
|
||||
await once(contents, 'did-navigate');
|
||||
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
|
||||
});
|
||||
});
|
||||
|
@ -1831,7 +1833,7 @@ describe('chromium features', () => {
|
|||
// History should have current page by now.
|
||||
expect((w.webContents as any).length()).to.equal(1);
|
||||
|
||||
const waitCommit = emittedOnce(w.webContents, 'navigation-entry-committed');
|
||||
const waitCommit = once(w.webContents, 'navigation-entry-committed');
|
||||
w.webContents.executeJavaScript('window.history.pushState({}, "")');
|
||||
await waitCommit;
|
||||
// Initial page + pushed state.
|
||||
|
@ -1844,15 +1846,15 @@ describe('chromium features', () => {
|
|||
const w = new BrowserWindow({ show: false });
|
||||
w.loadURL('data:text/html,<iframe sandbox="allow-scripts"></iframe>');
|
||||
await Promise.all([
|
||||
emittedOnce(w.webContents, 'navigation-entry-committed'),
|
||||
emittedOnce(w.webContents, 'did-frame-navigate'),
|
||||
emittedOnce(w.webContents, 'did-navigate')
|
||||
once(w.webContents, 'navigation-entry-committed'),
|
||||
once(w.webContents, 'did-frame-navigate'),
|
||||
once(w.webContents, 'did-navigate')
|
||||
]);
|
||||
|
||||
w.webContents.executeJavaScript('window.history.pushState(1, "")');
|
||||
await Promise.all([
|
||||
emittedOnce(w.webContents, 'navigation-entry-committed'),
|
||||
emittedOnce(w.webContents, 'did-navigate-in-page')
|
||||
once(w.webContents, 'navigation-entry-committed'),
|
||||
once(w.webContents, 'did-navigate-in-page')
|
||||
]);
|
||||
|
||||
(w.webContents as any).once('navigation-entry-committed', () => {
|
||||
|
@ -2287,7 +2289,7 @@ describe('iframe using HTML fullscreen API while window is OS-fullscreened', ()
|
|||
});
|
||||
|
||||
ifit(process.platform !== 'darwin')('can fullscreen from out-of-process iframes (non-macOS)', async () => {
|
||||
const fullscreenChange = emittedOnce(ipcMain, 'fullscreenChange');
|
||||
const fullscreenChange = once(ipcMain, 'fullscreenChange');
|
||||
const html =
|
||||
`<iframe style="width: 0" frameborder=0 src="${crossSiteUrl}" allowfullscreen></iframe>`;
|
||||
w.loadURL(`data:text/html,${html}`);
|
||||
|
@ -2302,7 +2304,7 @@ describe('iframe using HTML fullscreen API while window is OS-fullscreened', ()
|
|||
"document.querySelector('iframe').contentWindow.postMessage('exitFullscreen', '*')"
|
||||
);
|
||||
|
||||
await delay(500);
|
||||
await setTimeout(500);
|
||||
|
||||
const width = await w.webContents.executeJavaScript(
|
||||
"document.querySelector('iframe').offsetWidth"
|
||||
|
@ -2311,8 +2313,8 @@ describe('iframe using HTML fullscreen API while window is OS-fullscreened', ()
|
|||
});
|
||||
|
||||
ifit(process.platform === 'darwin')('can fullscreen from out-of-process iframes (macOS)', async () => {
|
||||
await emittedOnce(w, 'enter-full-screen');
|
||||
const fullscreenChange = emittedOnce(ipcMain, 'fullscreenChange');
|
||||
await once(w, 'enter-full-screen');
|
||||
const fullscreenChange = once(ipcMain, 'fullscreenChange');
|
||||
const html =
|
||||
`<iframe style="width: 0" frameborder=0 src="${crossSiteUrl}" allowfullscreen></iframe>`;
|
||||
w.loadURL(`data:text/html,${html}`);
|
||||
|
@ -2326,7 +2328,7 @@ describe('iframe using HTML fullscreen API while window is OS-fullscreened', ()
|
|||
await w.webContents.executeJavaScript(
|
||||
"document.querySelector('iframe').contentWindow.postMessage('exitFullscreen', '*')"
|
||||
);
|
||||
await emittedOnce(w.webContents, 'leave-html-full-screen');
|
||||
await once(w.webContents, 'leave-html-full-screen');
|
||||
|
||||
const width = await w.webContents.executeJavaScript(
|
||||
"document.querySelector('iframe').offsetWidth"
|
||||
|
@ -2334,14 +2336,14 @@ describe('iframe using HTML fullscreen API while window is OS-fullscreened', ()
|
|||
expect(width).to.equal(0);
|
||||
|
||||
w.setFullScreen(false);
|
||||
await emittedOnce(w, 'leave-full-screen');
|
||||
await once(w, 'leave-full-screen');
|
||||
});
|
||||
|
||||
// TODO(jkleinsc) fix this flaky test on WOA
|
||||
ifit(process.platform !== 'win32' || process.arch !== 'arm64')('can fullscreen from in-process iframes', async () => {
|
||||
if (process.platform === 'darwin') await emittedOnce(w, 'enter-full-screen');
|
||||
if (process.platform === 'darwin') await once(w, 'enter-full-screen');
|
||||
|
||||
const fullscreenChange = emittedOnce(ipcMain, 'fullscreenChange');
|
||||
const fullscreenChange = once(ipcMain, 'fullscreenChange');
|
||||
w.loadFile(path.join(fixturesPath, 'pages', 'fullscreen-ipif.html'));
|
||||
await fullscreenChange;
|
||||
|
||||
|
@ -2644,7 +2646,7 @@ ifdescribe((process.platform !== 'linux' || app.isUnityRunning()))('navigator.se
|
|||
async function waitForBadgeCount (value: number) {
|
||||
let badgeCount = app.getBadgeCount();
|
||||
while (badgeCount !== value) {
|
||||
await delay(10);
|
||||
await setTimeout(10);
|
||||
badgeCount = app.getBadgeCount();
|
||||
}
|
||||
return badgeCount;
|
||||
|
@ -2839,7 +2841,7 @@ describe('navigator.hid', () => {
|
|||
const grantedDevices = await w.webContents.executeJavaScript('navigator.hid.getDevices()');
|
||||
expect(grantedDevices).to.not.be.empty();
|
||||
w.loadURL(serverUrl);
|
||||
const [,,,,, frameProcessId, frameRoutingId] = await emittedOnce(w.webContents, 'did-frame-navigate');
|
||||
const [,,,,, frameProcessId, frameRoutingId] = await once(w.webContents, 'did-frame-navigate');
|
||||
const frame = webFrameMain.fromId(frameProcessId, frameRoutingId);
|
||||
expect(!!frame).to.be.true();
|
||||
if (frame) {
|
||||
|
@ -3039,7 +3041,7 @@ describe('navigator.usb', () => {
|
|||
const grantedDevices = await w.webContents.executeJavaScript('navigator.usb.getDevices()');
|
||||
expect(grantedDevices).to.not.be.empty();
|
||||
w.loadURL(serverUrl);
|
||||
const [,,,,, frameProcessId, frameRoutingId] = await emittedOnce(w.webContents, 'did-frame-navigate');
|
||||
const [,,,,, frameProcessId, frameRoutingId] = await once(w.webContents, 'did-frame-navigate');
|
||||
const frame = webFrameMain.fromId(frameProcessId, frameRoutingId);
|
||||
expect(!!frame).to.be.true();
|
||||
if (frame) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue