test: add setTitlebarOverlay spec (#34221)

spec: add setTitlebarOverlay spec
This commit is contained in:
Shelley Vohr 2022-05-16 18:14:27 +02:00 committed by GitHub
parent cc411946d7
commit 7af0b58c98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2245,9 +2245,15 @@ describe('BrowserWindow module', () => {
const overlayEnabled = await w.webContents.executeJavaScript('navigator.windowControlsOverlay.visible');
expect(overlayEnabled).to.be.true('overlayEnabled');
const overlayRectPreMax = await w.webContents.executeJavaScript('getJSOverlayProperties()');
await w.maximize();
const max = await w.isMaximized();
expect(max).to.equal(true);
if (!w.isMaximized()) {
const maximize = emittedOnce(w, 'maximize');
w.show();
w.maximize();
await maximize;
}
expect(w.isMaximized()).to.be.true('not maximized');
const overlayRectPostMax = await w.webContents.executeJavaScript('getJSOverlayProperties()');
expect(overlayRectPreMax.y).to.equal(0);
@ -2269,6 +2275,61 @@ describe('BrowserWindow module', () => {
});
});
ifdescribe(process.platform === 'win32')('BrowserWindow.setTitlebarOverlay', () => {
afterEach(closeAllWindows);
afterEach(() => { ipcMain.removeAllListeners('geometrychange'); });
it('correctly updates the height of the overlay', async () => {
const testOverlay = async (w: BrowserWindow, size: Number) => {
const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');
w.loadFile(overlayHTML);
await emittedOnce(ipcMain, 'geometrychange');
const overlayEnabled = await w.webContents.executeJavaScript('navigator.windowControlsOverlay.visible');
expect(overlayEnabled).to.be.true('overlayEnabled');
const { height: preMaxHeight } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
if (!w.isMaximized()) {
const maximize = emittedOnce(w, 'maximize');
w.show();
w.maximize();
await maximize;
}
expect(w.isMaximized()).to.be.true('not maximized');
const { x, y, width, height } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
expect(x).to.equal(0);
expect(y).to.equal(0);
expect(width).to.be.greaterThan(0);
expect(height).to.equal(size);
expect(preMaxHeight).to.equal(size);
};
const INITIAL_SIZE = 40;
const w = new BrowserWindow({
show: false,
width: 400,
height: 400,
titleBarStyle: 'hidden',
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
titleBarOverlay: {
height: INITIAL_SIZE
}
});
await testOverlay(w, INITIAL_SIZE);
w.setTitleBarOverlay({
height: INITIAL_SIZE + 10
});
await testOverlay(w, INITIAL_SIZE + 10);
});
});
ifdescribe(process.platform === 'darwin')('"enableLargerThanScreen" option', () => {
afterEach(closeAllWindows);
it('can move the window out of screen', () => {