mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
test: improve browser window layout coverage (#51189)
* test: browser window webContents viewport matches content bounds * test: browser window webContents same after vibrancy change * fixup! test: browser window webContents viewport matches content bounds * refactor: extract-method helper getViewportSize() * refactor: remove non-spec change * chore: more accurate naming
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user