diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index d91f54ac07..5b089079f4 100755 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -67,6 +67,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'); @@ -3141,6 +3144,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', () => { @@ -3439,6 +3453,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.