From 97c9451efc3035a1072b1ff87aee125f7a9fa053 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 17 May 2022 17:50:27 +0200 Subject: [PATCH] fix: WCO crash on bad `titlebarStyle` (#34140) fix: WCO crash on bad titlebarStyle --- shell/browser/ui/views/win_frame_view.cc | 4 ++-- spec-main/api-browser-window-spec.ts | 27 ++++++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/shell/browser/ui/views/win_frame_view.cc b/shell/browser/ui/views/win_frame_view.cc index 8a25bcdd73e8e..cea0b2937c92a 100644 --- a/shell/browser/ui/views/win_frame_view.cc +++ b/shell/browser/ui/views/win_frame_view.cc @@ -55,8 +55,8 @@ SkColor WinFrameView::GetReadableFeatureColor(SkColor background_color) { } void WinFrameView::InvalidateCaptionButtons() { - // Ensure that the caption buttons container exists - DCHECK(caption_button_container_); + if (!caption_button_container_) + return; caption_button_container_->InvalidateLayout(); caption_button_container_->SchedulePaint(); diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index adbfd107c5e9a..4d348bb924c47 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -2,10 +2,8 @@ import { expect } from 'chai'; import * as childProcess from 'child_process'; import * as path from 'path'; import * as fs from 'fs'; -import * as os from 'os'; import * as qs from 'querystring'; import * as http from 'http'; -import * as semver from 'semver'; import { AddressInfo } from 'net'; 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 w = new BrowserWindow({ 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 w = new BrowserWindow({ show: false, @@ -2279,6 +2277,27 @@ describe('BrowserWindow module', () => { afterEach(closeAllWindows); 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 () => { const testOverlay = async (w: BrowserWindow, size: Number) => { const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');