feat: remove nativeWindowOpen option (#29405)
Co-authored-by: Cheng Zhao <zcbenz@gmail.com> Co-authored-by: Milan Burda <milan.burda@gmail.com>
This commit is contained in:
parent
2f9fd06534
commit
d44a187d0b
39 changed files with 316 additions and 1164 deletions
|
@ -15,6 +15,7 @@ import { closeWindow, closeAllWindows } from './window-helpers';
|
|||
|
||||
const features = process._linkedBinding('electron_common_features');
|
||||
const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures');
|
||||
const mainFixtures = path.resolve(__dirname, 'fixtures');
|
||||
|
||||
// Is the display's scale factor possibly causing rounding of pixel coordinate
|
||||
// values?
|
||||
|
@ -2450,7 +2451,7 @@ describe('BrowserWindow module', () => {
|
|||
}
|
||||
});
|
||||
|
||||
const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js');
|
||||
const preloadPath = path.join(mainFixtures, 'api', 'new-window-preload.js');
|
||||
w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload: preloadPath } } }));
|
||||
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
|
||||
const [, { argv }] = await emittedOnce(ipcMain, 'answer');
|
||||
|
@ -2465,7 +2466,7 @@ describe('BrowserWindow module', () => {
|
|||
}
|
||||
});
|
||||
|
||||
const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js');
|
||||
const preloadPath = path.join(mainFixtures, 'api', 'new-window-preload.js');
|
||||
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([
|
||||
|
@ -2636,7 +2637,7 @@ describe('BrowserWindow module', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('nativeWindowOpen option', () => {
|
||||
describe('child windows', () => {
|
||||
let w: BrowserWindow = null as unknown as BrowserWindow;
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -2644,7 +2645,6 @@ describe('BrowserWindow module', () => {
|
|||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
nativeWindowOpen: true,
|
||||
// tests relies on preloads in opened windows
|
||||
nodeIntegrationInSubFrames: true,
|
||||
contextIsolation: false
|
||||
|
@ -2676,6 +2676,17 @@ describe('BrowserWindow module', () => {
|
|||
const [, content] = await answer;
|
||||
expect(content).to.equal('Hello');
|
||||
});
|
||||
it('opens window with cross-scripting enabled from isolated context', async () => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
preload: path.join(fixtures, 'api', 'native-window-open-isolated-preload.js')
|
||||
}
|
||||
});
|
||||
w.loadFile(path.join(fixtures, 'api', 'native-window-open-isolated.html'));
|
||||
const [, content] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(content).to.equal('Hello');
|
||||
});
|
||||
ifit(!process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS)('loads native addons correctly after reload', async () => {
|
||||
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'native-window-open-native-addon.html'));
|
||||
{
|
||||
|
@ -2695,7 +2706,6 @@ describe('BrowserWindow module', () => {
|
|||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegrationInSubFrames: true,
|
||||
nativeWindowOpen: true,
|
||||
webviewTag: true,
|
||||
contextIsolation: false,
|
||||
preload
|
||||
|
@ -2703,7 +2713,7 @@ describe('BrowserWindow module', () => {
|
|||
});
|
||||
w.webContents.setWindowOpenHandler(() => ({
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: { show: false, webPreferences: { contextIsolation: false, webviewTag: true, nativeWindowOpen: true, nodeIntegrationInSubFrames: true } }
|
||||
overrideBrowserWindowOptions: { show: false, webPreferences: { contextIsolation: false, webviewTag: true, nodeIntegrationInSubFrames: true } }
|
||||
}));
|
||||
w.webContents.once('new-window', (event, url, frameName, disposition, options) => {
|
||||
options.show = false;
|
||||
|
@ -2713,23 +2723,8 @@ describe('BrowserWindow module', () => {
|
|||
w.loadFile(path.join(fixtures, 'api', 'new-window-webview.html'));
|
||||
await webviewLoaded;
|
||||
});
|
||||
it('should inherit the nativeWindowOpen setting in opened windows', async () => {
|
||||
const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js');
|
||||
|
||||
w.webContents.setWindowOpenHandler(() => ({
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: {
|
||||
preload: preloadPath
|
||||
}
|
||||
}
|
||||
}));
|
||||
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
|
||||
const [, { nativeWindowOpen }] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(nativeWindowOpen).to.be.true();
|
||||
});
|
||||
it('should open windows with the options configured via new-window event listeners', async () => {
|
||||
const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js');
|
||||
const preloadPath = path.join(mainFixtures, 'api', 'new-window-preload.js');
|
||||
w.webContents.setWindowOpenHandler(() => ({
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
|
@ -2772,7 +2767,6 @@ describe('BrowserWindow module', () => {
|
|||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nativeWindowOpen: true,
|
||||
// test relies on preloads in opened window
|
||||
nodeIntegrationInSubFrames: true,
|
||||
contextIsolation: false
|
||||
|
@ -2783,7 +2777,7 @@ describe('BrowserWindow module', () => {
|
|||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: {
|
||||
preload: path.join(fixtures, 'api', 'window-open-preload.js'),
|
||||
preload: path.join(mainFixtures, 'api', 'window-open-preload.js'),
|
||||
contextIsolation: false,
|
||||
nodeIntegrationInSubFrames: true
|
||||
}
|
||||
|
@ -2791,9 +2785,8 @@ describe('BrowserWindow module', () => {
|
|||
}));
|
||||
|
||||
w.loadFile(path.join(fixtures, 'api', 'window-open-location-open.html'));
|
||||
const [, { nodeIntegration, nativeWindowOpen, typeofProcess }] = await emittedOnce(ipcMain, 'answer');
|
||||
const [, { nodeIntegration, typeofProcess }] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(nodeIntegration).to.be.false();
|
||||
expect(nativeWindowOpen).to.be.true();
|
||||
expect(typeofProcess).to.eql('undefined');
|
||||
});
|
||||
|
||||
|
@ -2801,7 +2794,6 @@ describe('BrowserWindow module', () => {
|
|||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nativeWindowOpen: true,
|
||||
// test relies on preloads in opened window
|
||||
nodeIntegrationInSubFrames: true
|
||||
}
|
||||
|
@ -2811,7 +2803,7 @@ describe('BrowserWindow module', () => {
|
|||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: {
|
||||
preload: path.join(fixtures, 'api', 'window-open-preload.js')
|
||||
preload: path.join(mainFixtures, 'api', 'window-open-preload.js')
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
@ -2840,23 +2832,6 @@ describe('BrowserWindow module', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('nativeWindowOpen + contextIsolation options', () => {
|
||||
afterEach(closeAllWindows);
|
||||
it('opens window with cross-scripting enabled from isolated context', async () => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nativeWindowOpen: true,
|
||||
contextIsolation: true,
|
||||
preload: path.join(fixtures, 'api', 'native-window-open-isolated-preload.js')
|
||||
}
|
||||
});
|
||||
w.loadFile(path.join(fixtures, 'api', 'native-window-open-isolated.html'));
|
||||
const [, content] = await emittedOnce(ipcMain, 'answer');
|
||||
expect(content).to.equal('Hello');
|
||||
});
|
||||
});
|
||||
|
||||
describe('beforeunload handler', function () {
|
||||
let w: BrowserWindow = null as unknown as BrowserWindow;
|
||||
beforeEach(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue