fix: hiding window menu should work on startup (#21436)

* fix: menu visibility should not be overwritten on startup

* fix: removing menu for window without global menubar

* test: setMenu tests are not for mac
This commit is contained in:
Cheng Zhao 2019-12-10 04:17:36 +09:00 committed by Samuel Attard
parent 7f6b308bf1
commit 3cb0ed306b
7 changed files with 88 additions and 15 deletions

View file

@ -1,8 +1,14 @@
import * as cp from 'child_process'
import * as path from 'path'
import { expect } from 'chai'
import { BrowserWindow, Menu, MenuItem } from 'electron'
import { sortMenuItems } from '../lib/browser/api/menu-utils'
import { emittedOnce } from './events-helpers'
import { ifit } from './spec-helpers'
import { closeWindow } from './window-helpers'
const fixturesPath = path.resolve(__dirname, 'fixtures')
describe('Menu module', function () {
this.timeout(5000)
describe('Menu.buildFromTemplate', () => {
@ -864,5 +870,27 @@ describe('Menu module', function () {
Menu.setApplicationMenu(null)
expect(Menu.getApplicationMenu()).to.be.null('application menu')
})
ifit(process.platform !== 'darwin')('does not override menu visibility on startup', async () => {
const appPath = path.join(fixturesPath, 'api', 'test-menu-visibility')
const appProcess = cp.spawn(process.execPath, [appPath])
let output = ''
appProcess.stdout.on('data', data => { output += data })
await emittedOnce(appProcess, 'close')
expect(output).to.include('Window has no menu')
})
ifit(process.platform !== 'darwin')('does not override null menu on startup', async () => {
const appPath = path.join(fixturesPath, 'api', 'test-menu-null')
const appProcess = cp.spawn(process.execPath, [appPath])
let output = ''
appProcess.stdout.on('data', data => { output += data })
await emittedOnce(appProcess, 'close')
expect(output).to.include('Window has no menu')
})
})
})