From 22d7934612979dcd5c6b9cbbb77d1760e2f7385e Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 21 Apr 2026 15:32:38 -0500 Subject: [PATCH] test: improve browser window layout coverage (#51213) * test: browser window webContents viewport matches content bounds Co-authored-by: Charles Kerr * test: browser window webContents same after vibrancy change Co-authored-by: Charles Kerr * fixup! test: browser window webContents viewport matches content bounds Co-authored-by: Charles Kerr * refactor: extract-method helper getViewportSize() Co-authored-by: Charles Kerr * refactor: remove non-spec change Co-authored-by: Charles Kerr * chore: more accurate naming Co-authored-by: Charles Kerr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- spec/api-browser-window-spec.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index d303a98480..6093aec63e 100755 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -51,6 +51,9 @@ const isBeforeUnload = (event: Event, level: number, message: string) => { return (message === 'beforeunload'); }; +const getViewportSize = (w: BrowserWindow) => + w.webContents.executeJavaScript('[window.innerWidth, window.innerHeight]'); + describe('BrowserWindow module', () => { it('sets the correct class name on the prototype', () => { expect(BrowserWindow.prototype.constructor.name).to.equal('BrowserWindow'); @@ -3076,6 +3079,17 @@ describe('BrowserWindow module', () => { w.setVibrancy('i-am-not-a-valid-vibrancy-type' as any); }).to.not.throw(); }); + + it('preserves the web content viewport after setting vibrancy', async () => { + const w = new BrowserWindow({ show: true, width: 800, height: 600 }); + + await w.loadURL('about:blank'); + const contentSize = w.getContentSize(); + expect(await getViewportSize(w)).to.deep.equal(contentSize); + + w.setVibrancy('titlebar'); + expect(await getViewportSize(w)).to.deep.equal(contentSize); + }); }); ifdescribe(process.platform === 'darwin')('trafficLightPosition', () => { @@ -3371,6 +3385,16 @@ describe('BrowserWindow module', () => { }); }); + describe('post-construction web content viewport', () => { + afterEach(closeAllWindows); + it('matches content size', async () => { + const w = new BrowserWindow({ show: true, width: 800, height: 600 }); + + await w.loadURL('about:blank'); + expect(await getViewportSize(w)).to.deep.equal(w.getContentSize()); + }); + }); + // On Wayland, hidden windows may not have mapped surfaces or finalized geometry // until shown. Tests that depend on real geometry or frame events may need // to show the window first.