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

This commit is contained in:
Milan Burda 2022-05-23 16:39:50 +02:00 committed by GitHub
parent 887b5a7dc7
commit 09a80ea48c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1563,9 +1563,10 @@ describe('webContents module', () => {
server.listen(0, '127.0.0.1', () => { server.listen(0, '127.0.0.1', () => {
const url = 'http://127.0.0.1:' + (server.address() as AddressInfo).port + '/'; const url = 'http://127.0.0.1:' + (server.address() as AddressInfo).port + '/';
w.webContents.once('did-finish-load', () => { w.webContents.once('did-finish-load', () => {
w.webContents.once('new-window', (event, newUrl, frameName, disposition, options, features, referrer) => { w.webContents.setWindowOpenHandler(details => {
expect(referrer.url).to.equal(url); expect(details.referrer.url).to.equal(url);
expect(referrer.policy).to.equal('strict-origin-when-cross-origin'); expect(details.referrer.policy).to.equal('strict-origin-when-cross-origin');
return { action: 'allow' };
}); });
w.webContents.executeJavaScript('a.click()'); w.webContents.executeJavaScript('a.click()');
}); });
@ -1591,9 +1592,10 @@ describe('webContents module', () => {
server.listen(0, '127.0.0.1', () => { server.listen(0, '127.0.0.1', () => {
const url = 'http://127.0.0.1:' + (server.address() as AddressInfo).port + '/'; const url = 'http://127.0.0.1:' + (server.address() as AddressInfo).port + '/';
w.webContents.once('did-finish-load', () => { w.webContents.once('did-finish-load', () => {
w.webContents.once('new-window', (event, newUrl, frameName, disposition, options, features, referrer) => { w.webContents.setWindowOpenHandler(details => {
expect(referrer.url).to.equal(url); expect(details.referrer.url).to.equal(url);
expect(referrer.policy).to.equal('no-referrer-when-downgrade'); expect(details.referrer.policy).to.equal('no-referrer-when-downgrade');
return { action: 'allow' };
}); });
w.webContents.executeJavaScript('window.open(location.href + "should_have_referrer")'); w.webContents.executeJavaScript('window.open(location.href + "should_have_referrer")');
}); });