test: use webContents.setWindowOpenHandler() in specs (#34514)

* test: use webContents.setWindowOpenHandler() in specs

* test: use browser-window-created instead of new-window for visibility spec
This commit is contained in:
Milan Burda 2022-06-13 19:07:47 +02:00 committed by GitHub
parent 954fd72500
commit 16cd22ff6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 11 deletions

View file

@ -3265,9 +3265,6 @@ describe('BrowserWindow module', () => {
action: 'allow',
overrideBrowserWindowOptions: { show: false, webPreferences: { contextIsolation: false, webviewTag: true, nodeIntegrationInSubFrames: true } }
}));
w.webContents.once('new-window', (event, url, frameName, disposition, options) => {
options.show = false;
});
const webviewLoaded = emittedOnce(ipcMain, 'webview-loaded');
w.loadFile(path.join(fixtures, 'api', 'new-window-webview.html'));

View file

@ -788,10 +788,10 @@ describe('chromium features', () => {
defer(() => { w.close(); });
const newWindow = emittedOnce(w.webContents, 'new-window');
const promise = emittedOnce(app, 'browser-window-created');
w.loadFile(path.join(fixturesPath, 'pages', 'window-open.html'));
const [,,,, options] = await newWindow;
expect(options.show).to.equal(true);
const [, newWindow] = await promise;
expect(newWindow.isVisible()).to.equal(true);
});
}
@ -900,8 +900,12 @@ describe('chromium features', () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('{ b = window.open(\'\', \'__proto__\'); null }');
const [, , frameName] = await emittedOnce(w.webContents, 'new-window');
const frameName = await new Promise((resolve) => {
w.webContents.setWindowOpenHandler(details => {
setImmediate(() => resolve(details.frameName));
return { action: 'allow' };
});
});
expect(frameName).to.equal('__proto__');
});
});

View file

@ -32,9 +32,12 @@ describe('<webview> tag', function () {
afterEach(closeAllWindows);
function hideChildWindows (e: any, wc: WebContents) {
wc.on('new-window', (event, url, frameName, disposition, options) => {
options.show = false;
});
wc.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
show: false
}
}));
}
before(() => {