fix: WCO crash on bad titlebarStyle (#34140)

fix: WCO crash on bad titlebarStyle
This commit is contained in:
Shelley Vohr 2022-05-17 17:50:27 +02:00 committed by GitHub
parent 4e3587c7c6
commit 97c9451efc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View file

@ -55,8 +55,8 @@ SkColor WinFrameView::GetReadableFeatureColor(SkColor background_color) {
} }
void WinFrameView::InvalidateCaptionButtons() { void WinFrameView::InvalidateCaptionButtons() {
// Ensure that the caption buttons container exists if (!caption_button_container_)
DCHECK(caption_button_container_); return;
caption_button_container_->InvalidateLayout(); caption_button_container_->InvalidateLayout();
caption_button_container_->SchedulePaint(); caption_button_container_->SchedulePaint();

View file

@ -2,10 +2,8 @@ import { expect } from 'chai';
import * as childProcess from 'child_process'; import * as childProcess from 'child_process';
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
import * as os from 'os';
import * as qs from 'querystring'; import * as qs from 'querystring';
import * as http from 'http'; import * as http from 'http';
import * as semver from 'semver';
import { AddressInfo } from 'net'; import { AddressInfo } from 'net';
import { app, BrowserWindow, BrowserView, dialog, ipcMain, OnBeforeSendHeadersListenerDetails, protocol, screen, webContents, session, WebContents, BrowserWindowConstructorOptions } from 'electron/main'; import { app, BrowserWindow, BrowserView, dialog, ipcMain, OnBeforeSendHeadersListenerDetails, protocol, screen, webContents, session, WebContents, BrowserWindowConstructorOptions } from 'electron/main';
@ -2150,7 +2148,7 @@ describe('BrowserWindow module', () => {
}); });
}); });
ifdescribe(process.platform === 'win32' || (process.platform === 'darwin' && semver.gte(os.release(), '14.0.0')))('"titleBarStyle" option', () => { ifdescribe(['win32', 'darwin'].includes(process.platform))('"titleBarStyle" option', () => {
const testWindowsOverlay = async (style: any) => { const testWindowsOverlay = async (style: any) => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
@ -2219,7 +2217,7 @@ describe('BrowserWindow module', () => {
}); });
}); });
ifdescribe(process.platform === 'win32' || (process.platform === 'darwin' && semver.gte(os.release(), '14.0.0')))('"titleBarOverlay" option', () => { ifdescribe(['win32', 'darwin'].includes(process.platform))('"titleBarOverlay" option', () => {
const testWindowsOverlayHeight = async (size: any) => { const testWindowsOverlayHeight = async (size: any) => {
const w = new BrowserWindow({ const w = new BrowserWindow({
show: false, show: false,
@ -2279,6 +2277,27 @@ describe('BrowserWindow module', () => {
afterEach(closeAllWindows); afterEach(closeAllWindows);
afterEach(() => { ipcMain.removeAllListeners('geometrychange'); }); afterEach(() => { ipcMain.removeAllListeners('geometrychange'); });
it('does not crash when an invalid titleBarStyle was initially set', () => {
const win = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
titleBarOverlay: {
color: '#0000f0',
symbolColor: '#ffffff'
},
titleBarStyle: 'hiddenInset'
});
expect(() => {
win.setTitleBarOverlay({
color: '#000000'
});
}).to.not.throw();
});
it('correctly updates the height of the overlay', async () => { it('correctly updates the height of the overlay', async () => {
const testOverlay = async (w: BrowserWindow, size: Number) => { const testOverlay = async (w: BrowserWindow, size: Number) => {
const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html'); const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');