From 70857e9a5d9a9daf2e900c51d7eeeb53b656b821 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Tue, 16 Jul 2019 16:37:17 -0700 Subject: [PATCH] test: move more BrowserWindow specs (#19290) * test: move more BrowserWindow specs * use async instead of setTimeout for cleaner code --- docs/api/browser-window.md | 4 +- spec-main/api-browser-window-spec.ts | 465 ++++++++++++++++++++++++++ spec/api-browser-window-spec.js | 481 --------------------------- 3 files changed, 467 insertions(+), 483 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index ef47f92cf11..5be728aec17 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -784,13 +784,13 @@ A `Boolean` property that determines whether the window can be manually closed b On Linux the setter is a no-op, although the getter returns `true`. -### `win.movable` +#### `win.movable` A `Boolean` property that determines Whether the window can be moved by user. On Linux the setter is a no-op, although the getter returns `true`. -### `win.excludedFromShownWindowsMenu` _macOS_ +#### `win.excludedFromShownWindowsMenu` _macOS_ A `Boolean` property that determines whether the window is excluded from the application’s Windows menu. `false` by default. diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 03145918b11..691d96769a8 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -2863,4 +2863,469 @@ describe('BrowserWindow module', () => { }) }) + describe('window states', () => { + afterEach(closeAllWindows) + it('does not resize frameless windows when states change', () => { + const w = new BrowserWindow({ + frame: false, + width: 300, + height: 200, + show: false + }) + + w.minimizable = false + w.minimizable = true + expect(w.getSize()).to.deep.equal([300, 200]) + + w.resizable = false + w.resizable = true + expect(w.getSize()).to.deep.equal([300, 200]) + + w.maximizable = false + w.maximizable = true + expect(w.getSize()).to.deep.equal([300, 200]) + + w.fullScreenable = false + w.fullScreenable = true + expect(w.getSize()).to.deep.equal([300, 200]) + + w.closable = false + w.closable = true + expect(w.getSize()).to.deep.equal([300, 200]) + }) + + describe('resizable state', () => { + it('can be changed with resizable option', () => { + const w = new BrowserWindow({ show: false, resizable: false }) + expect(w.resizable).to.be.false('resizable') + + if (process.platform === 'darwin') { + expect(w.maximizable).to.to.true('maximizable') + } + }) + + // TODO(codebytere): remove when propertyification is complete + it('can be changed with setResizable method', () => { + const w = new BrowserWindow({ show: false }) + expect(w.isResizable()).to.be.true('resizable') + w.setResizable(false) + expect(w.isResizable()).to.be.false('resizable') + w.setResizable(true) + expect(w.isResizable()).to.be.true('resizable') + }) + + it('can be changed with resizable property', () => { + const w = new BrowserWindow({ show: false }) + expect(w.resizable).to.be.true('resizable') + w.resizable = false + expect(w.resizable).to.be.false('resizable') + w.resizable = true + expect(w.resizable).to.be.true('resizable') + }) + + it('works for a frameless window', () => { + const w = new BrowserWindow({ show: false, frame: false }) + expect(w.resizable).to.be.true('resizable') + + if (process.platform === 'win32') { + const w = new BrowserWindow({ show: false, thickFrame: false }) + expect(w.resizable).to.be.false('resizable') + } + }) + + ifit(process.platform === 'win32')('works for a window smaller than 64x64', () => { + const w = new BrowserWindow({ + show: false, + frame: false, + resizable: false, + transparent: true + }) + w.setContentSize(60, 60) + expectBoundsEqual(w.getContentSize(), [60, 60]) + w.setContentSize(30, 30) + expectBoundsEqual(w.getContentSize(), [30, 30]) + w.setContentSize(10, 10) + expectBoundsEqual(w.getContentSize(), [10, 10]) + }) + }) + + describe('loading main frame state', () => { + let server: http.Server = null as unknown as http.Server + let serverUrl: string = null as unknown as string + + before((done) => { + server = http.createServer((request, response) => { + response.end() + }).listen(0, '127.0.0.1', () => { + serverUrl = 'http://127.0.0.1:' + (server.address() as AddressInfo).port + done() + }) + }) + + after(() => { + server.close() + }) + + it('is true when the main frame is loading', (done) => { + const w = new BrowserWindow({show: false}) + w.webContents.on('did-start-loading', () => { + expect(w.webContents.isLoadingMainFrame()).to.be.true('isLoadingMainFrame') + done() + }) + w.webContents.loadURL(serverUrl) + }) + it('is false when only a subframe is loading', (done) => { + const w = new BrowserWindow({show: false}) + w.webContents.once('did-stop-loading', () => { + expect(w.webContents.isLoadingMainFrame()).to.be.false('isLoadingMainFrame') + w.webContents.on('did-start-loading', () => { + expect(w.webContents.isLoadingMainFrame()).to.be.false('isLoadingMainFrame') + done() + }) + w.webContents.executeJavaScript(` + var iframe = document.createElement('iframe') + iframe.src = '${serverUrl}/page2' + document.body.appendChild(iframe) + `) + }) + w.webContents.loadURL(serverUrl) + }) + it('is true when navigating to pages from the same origin', (done) => { + const w = new BrowserWindow({show: false}) + w.webContents.once('did-stop-loading', () => { + expect(w.webContents.isLoadingMainFrame()).to.be.false('isLoadingMainFrame') + w.webContents.on('did-start-loading', () => { + expect(w.webContents.isLoadingMainFrame()).to.be.true('isLoadingMainFrame') + done() + }) + w.webContents.loadURL(`${serverUrl}/page2`) + }) + w.webContents.loadURL(serverUrl) + }) + }) + }) + + ifdescribe(process.platform !== 'linux')('window states (excluding Linux)', () => { + // Not implemented on Linux. + afterEach(closeAllWindows) + + describe('movable state (property)', () => { + it('can be changed with movable option', () => { + const w = new BrowserWindow({ show: false, movable: false }) + expect(w.movable).to.be.false('movable') + }) + it('can be changed with movable property', () => { + const w = new BrowserWindow({ show: false }) + expect(w.movable).to.be.true('movable') + w.movable = false + expect(w.movable).to.be.false('movable') + w.movable = true + expect(w.movable).to.be.true('movable') + }) + }) + + // TODO(codebytere): remove when propertyification is complete + describe('movable state (methods)', () => { + it('can be changed with movable option', () => { + const w = new BrowserWindow({ show: false, movable: false }) + expect(w.isMovable()).to.be.false('movable') + }) + it('can be changed with setMovable method', () => { + const w = new BrowserWindow({ show: false }) + expect(w.isMovable()).to.be.true('movable') + w.setMovable(false) + expect(w.isMovable()).to.be.false('movable') + w.setMovable(true) + expect(w.isMovable()).to.be.true('movable') + }) + }) + + describe('minimizable state (property)', () => { + it('can be changed with minimizable option', () => { + const w = new BrowserWindow({ show: false, minimizable: false }) + expect(w.minimizable).to.be.false('minimizable') + }) + + it('can be changed with minimizable property', () => { + const w = new BrowserWindow({ show: false }) + expect(w.minimizable).to.be.true('minimizable') + w.minimizable = false + expect(w.minimizable).to.be.false('minimizable') + w.minimizable = true + expect(w.minimizable).to.be.true('minimizable') + }) + }) + + // TODO(codebytere): remove when propertyification is complete + describe('minimizable state (methods)', () => { + it('can be changed with minimizable option', () => { + const w = new BrowserWindow({ show: false, minimizable: false }) + expect(w.isMinimizable()).to.be.false('movable') + }) + + it('can be changed with setMinimizable method', () => { + const w = new BrowserWindow({ show: false }) + expect(w.isMinimizable()).to.be.true('isMinimizable') + w.setMinimizable(false) + expect(w.isMinimizable()).to.be.false('isMinimizable') + w.setMinimizable(true) + expect(w.isMinimizable()).to.be.true('isMinimizable') + }) + }) + + describe('maximizable state (property)', () => { + it('can be changed with maximizable option', () => { + const w = new BrowserWindow({ show: false, maximizable: false }) + expect(w.maximizable).to.be.false('maximizable') + }) + + it('can be changed with maximizable property', () => { + const w = new BrowserWindow({ show: false }) + expect(w.maximizable).to.be.true('maximizable') + w.maximizable = false + expect(w.maximizable).to.be.false('maximizable') + w.maximizable = true + expect(w.maximizable).to.be.true('maximizable') + }) + + it('is not affected when changing other states', () => { + const w = new BrowserWindow({ show: false }) + w.maximizable = false + expect(w.maximizable).to.be.false('maximizable') + w.minimizable = false + expect(w.maximizable).to.be.false('maximizable') + w.closable = false + expect(w.maximizable).to.be.false('maximizable') + + w.maximizable = true + expect(w.maximizable).to.be.true('maximizable') + w.closable = true + expect(w.maximizable).to.be.true('maximizable') + w.fullScreenable = false + expect(w.maximizable).to.be.true('maximizable') + }) + }) + + // TODO(codebytere): remove when propertyification is complete + describe('maximizable state (methods)', () => { + it('can be changed with maximizable option', () => { + const w = new BrowserWindow({ show: false, maximizable: false }) + expect(w.isMaximizable()).to.be.false('isMaximizable') + }) + + it('can be changed with setMaximizable method', () => { + const w = new BrowserWindow({ show: false }) + expect(w.isMaximizable()).to.be.true('isMaximizable') + w.setMaximizable(false) + expect(w.isMaximizable()).to.be.false('isMaximizable') + w.setMaximizable(true) + expect(w.isMaximizable()).to.be.true('isMaximizable') + }) + + it('is not affected when changing other states', () => { + const w = new BrowserWindow({ show: false }) + w.setMaximizable(false) + expect(w.isMaximizable()).to.be.false('isMaximizable') + w.setMinimizable(false) + expect(w.isMaximizable()).to.be.false('isMaximizable') + w.setClosable(false) + expect(w.isMaximizable()).to.be.false('isMaximizable') + + w.setMaximizable(true) + expect(w.isMaximizable()).to.be.true('isMaximizable') + w.setClosable(true) + expect(w.isMaximizable()).to.be.true('isMaximizable') + w.setFullScreenable(false) + expect(w.isMaximizable()).to.be.true('isMaximizable') + }) + }) + + ifdescribe(process.platform === 'win32')('maximizable state (Windows only)', () => { + // Only implemented on windows. + + it('is reset to its former state', () => { + const w = new BrowserWindow({ show: false }) + w.maximizable = false + w.resizable = false + w.resizable = true + expect(w.maximizable).to.be.false('maximizable') + w.maximizable = true + w.resizable = false + w.resizable = true + expect(w.maximizable).to.be.true('maximizable') + }) + }) + + // TODO(codebytere): remove when propertyification is complete + ifdescribe(process.platform === 'win32')('maximizable state (Windows only) (methods)', () => { + // Only implemented on windows. + + it('is reset to its former state', () => { + const w = new BrowserWindow({ show: false }) + w.setMaximizable(false) + w.setResizable(false) + w.setResizable(true) + expect(w.isMaximizable()).to.be.false('isMaximizable') + w.setMaximizable(true) + w.setResizable(false) + w.setResizable(true) + expect(w.isMaximizable()).to.be.true('isMaximizable') + }) + }) + + ifdescribe(process.platform === 'darwin')('fullscreenable state (property)', () => { + it('can be changed with fullscreenable option', () => { + const w = new BrowserWindow({ show: false, fullscreenable: false }) + expect(w.fullScreenable).to.be.false('fullScreenable') + }) + + it('can be changed with fullScreenable property', () => { + const w = new BrowserWindow({ show: false }) + expect(w.fullScreenable).to.be.true('fullScreenable') + w.fullScreenable = false + expect(w.fullScreenable).to.be.false('fullScreenable') + w.fullScreenable = true + expect(w.fullScreenable).to.be.true('fullScreenable') + }) + }) + + // TODO(codebytere): remove when propertyification is complete + ifdescribe(process.platform === 'darwin')('fullscreenable state (methods)', () => { + it('can be changed with fullscreenable option', () => { + const w = new BrowserWindow({ show: false, fullscreenable: false }) + expect(w.isFullScreenable()).to.be.false('isFullScreenable') + }) + + it('can be changed with setFullScreenable method', () => { + const w = new BrowserWindow({ show: false }) + expect(w.isFullScreenable()).to.be.true('isFullScreenable') + w.setFullScreenable(false) + expect(w.isFullScreenable()).to.be.false('isFullScreenable') + w.setFullScreenable(true) + expect(w.isFullScreenable()).to.be.true('isFullScreenable') + }) + }) + + // fullscreen events are dispatched eagerly and twiddling things too fast can confuse poor Electron + const tick = () => new Promise(resolve => setTimeout(resolve)) + + ifdescribe(process.platform === 'darwin')('kiosk state', () => { + it('can be changed with setKiosk method', (done) => { + const w = new BrowserWindow() + w.once('enter-full-screen', async () => { + await tick() + w.setKiosk(false) + expect(w.isKiosk()).to.be.false('isKiosk') + }) + w.once('leave-full-screen', () => { + done() + }) + w.setKiosk(true) + expect(w.isKiosk()).to.be.true('isKiosk') + }) + }) + + ifdescribe(process.platform === 'darwin')('fullscreen state with resizable set', () => { + it('resizable flag should be set to true and restored', (done) => { + const w = new BrowserWindow({ resizable: false }) + w.once('enter-full-screen', async () => { + expect(w.resizable).to.be.true('resizable') + await tick() + w.setFullScreen(false) + }) + w.once('leave-full-screen', () => { + expect(w.resizable).to.be.false('resizable') + done() + }) + w.setFullScreen(true) + }) + }) + + ifdescribe(process.platform === 'darwin')('fullscreen state', () => { + it('can be changed with setFullScreen method', (done) => { + const w = new BrowserWindow() + w.once('enter-full-screen', async () => { + expect(w.isFullScreen()).to.be.true('isFullScreen') + await tick() + w.setFullScreen(false) + }) + w.once('leave-full-screen', () => { + expect(w.isFullScreen()).to.be.false('isFullScreen') + done() + }) + w.setFullScreen(true) + }) + + it('should not be changed by setKiosk method', (done) => { + const w = new BrowserWindow() + w.once('enter-full-screen', async () => { + expect(w.isFullScreen()).to.be.true('isFullScreen') + await tick() + w.setKiosk(true) + await tick() + w.setKiosk(false) + expect(w.isFullScreen()).to.be.true('isFullScreen') + w.setFullScreen(false) + }) + w.once('leave-full-screen', () => { + expect(w.isFullScreen()).to.be.false('isFullScreen') + done() + }) + w.setFullScreen(true) + }) + }) + + describe('closable state (property)', () => { + it('can be changed with closable option', () => { + const w = new BrowserWindow({ show: false, closable: false }) + expect(w.closable).to.be.false('closable') + }) + + it('can be changed with setClosable method', () => { + const w = new BrowserWindow({ show: false }) + expect(w.closable).to.be.true('closable') + w.closable = false + expect(w.closable).to.be.false('closable') + w.closable = true + expect(w.closable).to.be.true('closable') + }) + }) + + // TODO(codebytere): remove when propertyification is complete + describe('closable state (methods)', () => { + it('can be changed with closable option', () => { + const w = new BrowserWindow({ show: false, closable: false }) + expect(w.isClosable()).to.be.false('isClosable') + }) + + it('can be changed with setClosable method', () => { + const w = new BrowserWindow({ show: false }) + expect(w.isClosable()).to.be.true('isClosable') + w.setClosable(false) + expect(w.isClosable()).to.be.false('isClosable') + w.setClosable(true) + expect(w.isClosable()).to.be.true('isClosable') + }) + }) + + describe('hasShadow state', () => { + // On Windows there is no shadow by default and it can not be changed + // dynamically. + it('can be changed with hasShadow option', () => { + const hasShadow = process.platform !== 'darwin' + const w = new BrowserWindow({ show: false, hasShadow: hasShadow }) + expect(w.hasShadow()).to.equal(hasShadow) + }) + + ifit(process.platform === 'darwin')('can be changed with setHasShadow method', () => { + const w = new BrowserWindow({ show: false }) + expect(w.hasShadow()).to.be.true('hasShadow') + w.setHasShadow(false) + expect(w.hasShadow()).to.be.false('hasShadow') + w.setHasShadow(true) + expect(w.hasShadow()).to.be.true('hasShadow') + }) + }) + }) + }) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index c028e0af4ef..3b7e14c59f0 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -112,487 +112,6 @@ describe('BrowserWindow module', () => { afterEach(closeTheWindow) - describe('window states', () => { - it('does not resize frameless windows when states change', () => { - w.destroy() - w = new BrowserWindow({ - frame: false, - width: 300, - height: 200, - show: false - }) - - w.minimizable = false - w.minimizable = true - expect(w.getSize()).to.deep.equal([300, 200]) - - w.resizable = false - w.resizable = true - expect(w.getSize()).to.deep.equal([300, 200]) - - w.maximizable = false - w.maximizable = true - expect(w.getSize()).to.deep.equal([300, 200]) - - w.fullScreenable = false - w.fullScreenable = true - expect(w.getSize()).to.deep.equal([300, 200]) - - w.closable = false - w.closable = true - expect(w.getSize()).to.deep.equal([300, 200]) - }) - - describe('resizable state', () => { - it('can be changed with resizable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, resizable: false }) - expect(w.resizable).to.be.false() - - if (process.platform === 'darwin') { - expect(w.maximizable).to.to.true() - } - }) - - // TODO(codebytere): remove when propertyification is complete - it('can be changed with setResizable method', () => { - expect(w.isResizable()).to.be.true() - w.setResizable(false) - expect(w.isResizable()).to.be.false() - w.setResizable(true) - expect(w.isResizable()).to.be.true() - }) - - it('can be changed with resizable property', () => { - expect(w.resizable).to.be.true() - w.resizable = false - expect(w.resizable).to.be.false() - w.resizable = true - expect(w.resizable).to.be.true() - }) - - it('works for a frameless window', () => { - w.destroy() - w = new BrowserWindow({ show: false, frame: false }) - expect(w.resizable).to.be.true() - - if (process.platform === 'win32') { - w.destroy() - w = new BrowserWindow({ show: false, thickFrame: false }) - expect(w.resizable).to.be.false() - } - }) - - if (process.platform === 'win32') { - it('works for a window smaller than 64x64', () => { - w.destroy() - w = new BrowserWindow({ - show: false, - frame: false, - resizable: false, - transparent: true - }) - w.setContentSize(60, 60) - expectBoundsEqual(w.getContentSize(), [60, 60]) - w.setContentSize(30, 30) - expectBoundsEqual(w.getContentSize(), [30, 30]) - w.setContentSize(10, 10) - expectBoundsEqual(w.getContentSize(), [10, 10]) - }) - } - }) - - describe('loading main frame state', () => { - it('is true when the main frame is loading', (done) => { - w.webContents.on('did-start-loading', () => { - expect(w.webContents.isLoadingMainFrame()).to.be.true() - done() - }) - w.webContents.loadURL(server.url) - }) - it('is false when only a subframe is loading', (done) => { - w.webContents.once('did-finish-load', () => { - expect(w.webContents.isLoadingMainFrame()).to.be.false() - w.webContents.on('did-start-loading', () => { - expect(w.webContents.isLoadingMainFrame()).to.be.false() - done() - }) - w.webContents.executeJavaScript(` - var iframe = document.createElement('iframe') - iframe.src = '${server.url}/page2' - document.body.appendChild(iframe) - `) - }) - w.webContents.loadURL(server.url) - }) - it('is true when navigating to pages from the same origin', (done) => { - w.webContents.once('did-finish-load', () => { - expect(w.webContents.isLoadingMainFrame()).to.be.false() - w.webContents.on('did-start-loading', () => { - expect(w.webContents.isLoadingMainFrame()).to.be.true() - done() - }) - w.webContents.loadURL(`${server.url}/page2`) - }) - w.webContents.loadURL(server.url) - }) - }) - }) - - describe('window states (excluding Linux)', () => { - // FIXME(alexeykuzmin): Skip the tests instead of using the `return` here. - // Why it cannot be done now: - // - `.skip()` called in the 'before' hook doesn't affect - // nested `describe`s. - // - `.skip()` called in the 'beforeEach' hook prevents 'afterEach' - // hook from being called. - // Not implemented on Linux. - if (process.platform === 'linux') { - return - } - - describe('movable state (property)', () => { - it('can be changed with movable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, movable: false }) - expect(w.movable).to.be.false() - }) - it('can be changed with movable property', () => { - expect(w.movable).to.be.true() - w.movable = false - expect(w.movable).to.be.false() - w.movable = true - expect(w.movable).to.be.true() - }) - }) - - // TODO(codebytere): remove when propertyification is complete - describe('movable state (methods)', () => { - it('can be changed with movable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, movable: false }) - expect(w.isMovable()).to.be.false() - }) - it('can be changed with setMovable method', () => { - expect(w.isMovable()).to.be.true() - w.setMovable(false) - expect(w.isMovable()).to.be.false() - w.setMovable(true) - expect(w.isMovable()).to.be.true() - }) - }) - - describe('minimizable state (property)', () => { - it('can be changed with minimizable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, minimizable: false }) - expect(w.minimizable).to.be.false() - }) - - it('can be changed with minimizable property', () => { - expect(w.minimizable).to.be.true() - w.minimizable = false - expect(w.minimizable).to.be.false() - w.minimizable = true - expect(w.minimizable).to.be.true() - }) - }) - - // TODO(codebytere): remove when propertyification is complete - describe('minimizable state (methods)', () => { - it('can be changed with minimizable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, minimizable: false }) - expect(w.isMinimizable()).to.be.false() - }) - - it('can be changed with setMinimizable method', () => { - expect(w.isMinimizable()).to.be.true() - w.setMinimizable(false) - expect(w.isMinimizable()).to.be.false() - w.setMinimizable(true) - expect(w.isMinimizable()).to.be.true() - }) - }) - - describe('maximizable state (property)', () => { - it('can be changed with maximizable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, maximizable: false }) - expect(w.maximizable).to.be.false() - }) - - it('can be changed with maximizable property', () => { - expect(w.maximizable).to.be.true() - w.maximizable = false - expect(w.maximizable).to.be.false() - w.maximizable = true - expect(w.maximizable).to.be.true() - }) - - it('is not affected when changing other states', () => { - w.maximizable = false - expect(w.maximizable).to.be.false() - w.minimizable = false - expect(w.maximizable).to.be.false() - w.closable = false - expect(w.maximizable).to.be.false() - - w.maximizable = true - expect(w.maximizable).to.be.true() - w.closable = true - expect(w.maximizable).to.be.true() - w.fullScreenable = false - expect(w.maximizable).to.be.true() - }) - }) - - // TODO(codebytere): remove when propertyification is complete - describe('maximizable state (methods)', () => { - it('can be changed with maximizable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, maximizable: false }) - expect(w.isMaximizable()).to.be.false() - }) - - it('can be changed with setMaximizable method', () => { - expect(w.isMaximizable()).to.be.true() - w.setMaximizable(false) - expect(w.isMaximizable()).to.be.false() - w.setMaximizable(true) - expect(w.isMaximizable()).to.be.true() - }) - - it('is not affected when changing other states', () => { - w.setMaximizable(false) - expect(w.isMaximizable()).to.be.false() - w.setMinimizable(false) - expect(w.isMaximizable()).to.be.false() - w.setClosable(false) - expect(w.isMaximizable()).to.be.false() - - w.setMaximizable(true) - expect(w.isMaximizable()).to.be.true() - w.setClosable(true) - expect(w.isMaximizable()).to.be.true() - w.setFullScreenable(false) - expect(w.isMaximizable()).to.be.true() - }) - }) - - describe('maximizable state (Windows only)', () => { - // Only implemented on windows. - if (process.platform !== 'win32') return - - it('is reset to its former state', () => { - w.maximizable = false - w.resizable = false - w.resizable = true - expect(w.maximizable).to.be.false() - w.maximizable = true - w.resizable = false - w.resizable = true - expect(w.maximizable).to.be.true() - }) - }) - - // TODO(codebytere): remove when propertyification is complete - describe('maximizable state (Windows only) (methods)', () => { - // Only implemented on windows. - if (process.platform !== 'win32') return - - it('is reset to its former state', () => { - w.setMaximizable(false) - w.setResizable(false) - w.setResizable(true) - expect(w.isMaximizable()).to.be.false() - w.setMaximizable(true) - w.setResizable(false) - w.setResizable(true) - expect(w.isMaximizable()).to.be.true() - }) - }) - - describe('fullscreenable state (property)', () => { - before(function () { - if (process.platform !== 'darwin') this.skip() - }) - - it('can be changed with fullscreenable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, fullscreenable: false }) - expect(w.fullScreenable).to.be.false() - }) - - it('can be changed with fullScreenable property', () => { - expect(w.fullScreenable).to.be.true() - w.fullScreenable = false - expect(w.fullScreenable).to.be.false() - w.fullScreenable = true - expect(w.fullScreenable).to.be.true() - }) - }) - - // TODO(codebytere): remove when propertyification is complete - describe('fullscreenable state (methods)', () => { - before(function () { - if (process.platform !== 'darwin') this.skip() - }) - - it('can be changed with fullscreenable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, fullscreenable: false }) - expect(w.isFullScreenable()).to.be.false() - }) - - it('can be changed with setFullScreenable method', () => { - expect(w.isFullScreenable()).to.be.true() - w.setFullScreenable(false) - expect(w.isFullScreenable()).to.be.false() - w.setFullScreenable(true) - expect(w.isFullScreenable()).to.be.true() - }) - }) - - describe('kiosk state', () => { - before(function () { - // Only implemented on macOS. - if (process.platform !== 'darwin') { - this.skip() - } - }) - - it('can be changed with setKiosk method', (done) => { - w.destroy() - w = new BrowserWindow() - w.setKiosk(true) - expect(w.isKiosk()).to.be.true() - - w.once('enter-full-screen', () => { - w.setKiosk(false) - expect(w.isKiosk()).to.be.false() - }) - w.once('leave-full-screen', () => { - done() - }) - }) - }) - - describe('fullscreen state with resizable set', () => { - before(function () { - if (process.platform !== 'darwin') this.skip() - }) - - it('resizable flag should be set to true and restored', (done) => { - w.destroy() - w = new BrowserWindow({ resizable: false }) - w.once('enter-full-screen', () => { - expect(w.resizable).to.be.true() - w.setFullScreen(false) - }) - w.once('leave-full-screen', () => { - expect(w.resizable).to.be.false() - done() - }) - w.setFullScreen(true) - }) - }) - - describe('fullscreen state', () => { - before(function () { - // Only implemented on macOS. - if (process.platform !== 'darwin') { - this.skip() - } - }) - - it('can be changed with setFullScreen method', (done) => { - w.destroy() - w = new BrowserWindow() - w.once('enter-full-screen', () => { - expect(w.isFullScreen()).to.be.true() - w.setFullScreen(false) - }) - w.once('leave-full-screen', () => { - expect(w.isFullScreen()).to.be.false() - done() - }) - w.setFullScreen(true) - }) - - it('should not be changed by setKiosk method', (done) => { - w.destroy() - w = new BrowserWindow() - w.once('enter-full-screen', () => { - expect(w.isFullScreen()).to.be.true() - w.setKiosk(true) - w.setKiosk(false) - expect(w.isFullScreen()).to.be.true() - w.setFullScreen(false) - }) - w.once('leave-full-screen', () => { - expect(w.isFullScreen()).to.be.false() - done() - }) - w.setFullScreen(true) - }) - }) - - describe('closable state (property)', () => { - it('can be changed with closable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, closable: false }) - expect(w.closable).to.be.false() - }) - - it('can be changed with setClosable method', () => { - expect(w.closable).to.be.true() - w.closable = false - expect(w.closable).to.be.false() - w.closable = true - expect(w.closable).to.be.true() - }) - }) - - // TODO(codebytere): remove when propertyification is complete - describe('closable state (methods)', () => { - it('can be changed with closable option', () => { - w.destroy() - w = new BrowserWindow({ show: false, closable: false }) - expect(w.isClosable()).to.be.false() - }) - - it('can be changed with setClosable method', () => { - expect(w.isClosable()).to.be.true() - w.setClosable(false) - expect(w.isClosable()).to.be.false() - w.setClosable(true) - expect(w.isClosable()).to.be.true() - }) - }) - - describe('hasShadow state', () => { - // On Window there is no shadow by default and it can not be changed - // dynamically. - it('can be changed with hasShadow option', () => { - w.destroy() - const hasShadow = process.platform !== 'darwin' - w = new BrowserWindow({ show: false, hasShadow: hasShadow }) - expect(w.hasShadow()).to.equal(hasShadow) - }) - - it('can be changed with setHasShadow method', () => { - if (process.platform !== 'darwin') return - - expect(w.hasShadow()).to.be.true() - w.setHasShadow(false) - expect(w.hasShadow()).to.be.false() - w.setHasShadow(true) - expect(w.hasShadow()).to.be.true() - }) - }) - }) - describe('window.webContents.send(channel, args...)', () => { it('throws an error when the channel is missing', () => { expect(() => {