test: improve browser window layout coverage (#51213)

* test: browser window webContents viewport matches content bounds

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* test: browser window webContents same after vibrancy change

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fixup! test: browser window webContents viewport matches content bounds

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: extract-method helper getViewportSize()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: remove non-spec change

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* chore: more accurate naming

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot]
2026-04-21 15:32:38 -05:00
committed by GitHub
parent e851c0bbe1
commit 22d7934612

View File

@@ -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.