Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
fix: WCO crash on bad titlebarStyle (electron#34140)
Browse files Browse the repository at this point in the history
fix: WCO crash on bad titlebarStyle
  • Loading branch information
codebytere authored and khalwa committed Feb 22, 2023
1 parent c9d62c1 commit 851d994
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions shell/browser/ui/views/win_frame_view.cc
Expand Up @@ -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();
Expand Down
27 changes: 23 additions & 4 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 851d994

Please sign in to comment.