From 544b5f5fbf0c82c8048d0835ea20875e24e8c0b1 Mon Sep 17 00:00:00 2001 From: Tariq Bashir Date: Thu, 18 Dec 2025 14:58:34 +0000 Subject: [PATCH 1/2] fix: Fix test specs that rely on chrome-error --- spec/api-browser-window-spec.ts | 48 +++++++++++++++++-- .../api/native-window-open-cross-origin.html | 4 +- spec/fixtures/api/new-window.html | 4 +- spec/webview-spec.ts | 10 +++- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 64d55589fb1b8..f90f01829c0cb 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -3716,11 +3716,21 @@ describe('BrowserWindow module', () => { } }); + const server = http.createServer((req, res) => { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end('Blank Page'); + }); + const serverUrl = (await listen(server)).url; + 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')); + await w.loadFile(path.join(fixtures, 'api', 'new-window.html'), { + query: { url: serverUrl } + }); const [, { argv }] = await once(ipcMain, 'answer'); expect(argv).to.include('--enable-sandbox'); + + server.close(); }); it('should open windows with the options configured via setWindowOpenHandler handlers', async () => { @@ -3731,15 +3741,25 @@ describe('BrowserWindow module', () => { } }); + const server = http.createServer((req, res) => { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end('Blank Page'); + }); + const serverUrl = (await listen(server)).url; + 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')); + await w.loadFile(path.join(fixtures, 'api', 'new-window.html'), { + query: { url: serverUrl } + }); const [[, childWebContents]] = await Promise.all([ once(app, 'web-contents-created') as Promise<[any, WebContents]>, once(ipcMain, 'answer') ]); const webPreferences = childWebContents.getLastWebPreferences(); expect(webPreferences!.contextIsolation).to.equal(false); + + server.close(); }); it('should set ipc event sender correctly', async () => { @@ -3909,10 +3929,20 @@ describe('BrowserWindow module', () => { expect(content).to.equal('Hello'); }); it('blocks accessing cross-origin frames', async () => { + const server = http.createServer((req, res) => { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end('Blank Page'); + }); + const serverUrl = (await listen(server)).url; + const answer = once(ipcMain, 'answer'); - w.loadFile(path.join(fixtures, 'api', 'native-window-open-cross-origin.html')); + await w.loadFile(path.join(fixtures, 'api', 'native-window-open-cross-origin.html'), { + query: { url: serverUrl } + }); const [, content] = await answer; expect(content).to.equal('Failed to read a named property \'toString\' from \'Location\': Blocked a frame with origin "file://" from accessing a cross-origin frame.'); + + server.close(); }); it('opens window from