fix: normalize behavior of win.setOpacity()
for invalid number values across operating systems (#19535)
* fix: define behavior for out-of-bounds setOpacity * fix linux issue * fix getOpacity behaviour * wrong variable * normalize more stuff * docs * test: use ifdescribe helper * Update spec-main/api-browser-window-spec.ts Co-Authored-By: Charles Kerr <ckerr@github.com> * fixes * more tests!!! * Update shell/browser/native_window_views.cc Co-Authored-By: Charles Kerr <ckerr@github.com> * Update shell/browser/native_window_mac.mm Co-Authored-By: Charles Kerr <ckerr@github.com>
This commit is contained in:
parent
761a4deab3
commit
8a9a5d69b6
4 changed files with 51 additions and 20 deletions
|
@ -8,9 +8,10 @@ import * as qs from 'querystring'
|
|||
import * as http from 'http'
|
||||
import { AddressInfo } from 'net'
|
||||
import { app, BrowserWindow, BrowserView, ipcMain, OnBeforeSendHeadersListenerDetails, protocol, screen, webContents, session, WebContents } from 'electron'
|
||||
import { emittedOnce } from './events-helpers';
|
||||
import { closeWindow } from './window-helpers';
|
||||
|
||||
import { emittedOnce } from './events-helpers'
|
||||
import { ifit, ifdescribe } from './spec-helpers'
|
||||
import { closeWindow } from './window-helpers'
|
||||
|
||||
const { expect } = chai
|
||||
|
||||
|
@ -1242,22 +1243,44 @@ describe('BrowserWindow module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
|
||||
describe('BrowserWindow.setOpacity(opacity)', () => {
|
||||
afterEach(closeAllWindows)
|
||||
it('make window with initial opacity', () => {
|
||||
const w = new BrowserWindow({ show: false, opacity: 0.5 })
|
||||
expect(w.getOpacity()).to.equal(0.5)
|
||||
})
|
||||
it('allows setting the opacity', () => {
|
||||
const w = new BrowserWindow({ show: false })
|
||||
expect(() => {
|
||||
w.setOpacity(0.0)
|
||||
expect(w.getOpacity()).to.equal(0.0)
|
||||
w.setOpacity(0.5)
|
||||
|
||||
ifdescribe(process.platform !== 'linux')(('Windows and Mac'), () => {
|
||||
it('make window with initial opacity', () => {
|
||||
const w = new BrowserWindow({ show: false, opacity: 0.5 })
|
||||
expect(w.getOpacity()).to.equal(0.5)
|
||||
w.setOpacity(1.0)
|
||||
})
|
||||
it('allows setting the opacity', () => {
|
||||
const w = new BrowserWindow({ show: false })
|
||||
expect(() => {
|
||||
w.setOpacity(0.0)
|
||||
expect(w.getOpacity()).to.equal(0.0)
|
||||
w.setOpacity(0.5)
|
||||
expect(w.getOpacity()).to.equal(0.5)
|
||||
w.setOpacity(1.0)
|
||||
expect(w.getOpacity()).to.equal(1.0)
|
||||
}).to.not.throw()
|
||||
})
|
||||
|
||||
it('clamps opacity to [0.0...1.0]', () => {
|
||||
const w = new BrowserWindow({ show: false, opacity: 0.5 })
|
||||
w.setOpacity(100)
|
||||
expect(w.getOpacity()).to.equal(1.0)
|
||||
}).to.not.throw()
|
||||
w.setOpacity(-100)
|
||||
expect(w.getOpacity()).to.equal(0.0)
|
||||
})
|
||||
})
|
||||
|
||||
ifdescribe(process.platform === 'linux')(('Linux'), () => {
|
||||
it('sets 1 regardless of parameter', () => {
|
||||
const w = new BrowserWindow({ show: false })
|
||||
w.setOpacity(0)
|
||||
expect(w.getOpacity()).to.equal(1.0)
|
||||
w.setOpacity(0.5)
|
||||
expect(w.getOpacity()).to.equal(1.0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue