feat: add property support for remainder of BrowserWindow (#22771)

Adds property-based support for the remainder of primitive gette/setter pairs on `BrowserWindow`.

Namely:
- `win.simpleFullScreen`
- `win.title`
- `win.visibleOnAllWorkspaces`
- `win.documentEdited`
- `win.representedFilename`
- `win.shadow`
- `win.kiosk`
- `win.menuBarVisible`
This commit is contained in:
Shelley Vohr 2020-04-01 08:22:32 -07:00 committed by GitHub
parent 5715e94db0
commit da67cbf551
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 330 additions and 90 deletions

View file

@ -959,6 +959,7 @@ describe('BrowserWindow module', () => {
w.setPosition(pos[0], pos[1]);
});
});
ifdescribe(process.platform !== 'linux')('Maximized state', () => {
it('checks normal bounds when maximized', (done) => {
const bounds = w.getBounds();
@ -982,6 +983,7 @@ describe('BrowserWindow module', () => {
w.maximize();
});
});
ifdescribe(process.platform !== 'linux')('Minimized state', () => {
it('checks normal bounds when minimized', (done) => {
const bounds = w.getBounds();
@ -1005,8 +1007,9 @@ describe('BrowserWindow module', () => {
w.minimize();
});
});
ifdescribe(process.platform === 'win32')('Fullscreen state', () => {
it('checks normal bounds when fullscreen\'ed', (done) => {
ifdescribe(process.platform === 'win32')(`Fullscreen state`, () => {
it(`checks normal bounds when fullscreen'ed`, (done) => {
const bounds = w.getBounds();
w.once('enter-full-screen', () => {
expectBoundsEqual(w.getNormalBounds(), bounds);
@ -1015,7 +1018,8 @@ describe('BrowserWindow module', () => {
w.show();
w.setFullScreen(true);
});
it('checks normal bounds when unfullscreen\'ed', (done) => {
it(`checks normal bounds when unfullscreen'ed`, (done) => {
const bounds = w.getBounds();
w.once('enter-full-screen', () => {
w.setFullScreen(false);
@ -3437,6 +3441,96 @@ describe('BrowserWindow module', () => {
});
});
describe('visibleOnAllWorkspaces state', () => {
it('with properties', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.visibleOnAllWorkspaces).to.be.false();
w.visibleOnAllWorkspaces = true;
expect(w.visibleOnAllWorkspaces).to.be.true();
});
});
it('with functions', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isVisibleOnAllWorkspaces()).to.be.false();
w.setVisibleOnAllWorkspaces(true);
expect(w.isVisibleOnAllWorkspaces()).to.be.true();
});
});
});
ifdescribe(process.platform === 'darwin')('documentEdited state', () => {
it('with properties', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.documentEdited).to.be.false();
w.documentEdited = true;
expect(w.documentEdited).to.be.true();
});
});
it('with functions', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isDocumentEdited()).to.be.false();
w.setDocumentEdited(true);
expect(w.isDocumentEdited()).to.be.true();
});
});
});
ifdescribe(process.platform === 'darwin')('representedFilename', () => {
it('with properties', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.representedFilename).to.eql('');
w.representedFilename = 'a name';
expect(w.representedFilename).to.eql('a name');
});
});
it('with functions', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.getRepresentedFilename()).to.eql('');
w.setRepresentedFilename('a name');
expect(w.getRepresentedFilename()).to.eql('a name');
});
});
});
describe('native window title', () => {
it('with properties', () => {
it('can be set with title constructor option', () => {
const w = new BrowserWindow({ show: false, title: 'mYtItLe' });
expect(w.title).to.eql('mYtItLe');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.title).to.eql('Electron Test Main');
w.title = 'NEW TITLE';
expect(w.title).to.eql('NEW TITLE');
});
});
it('with functions', () => {
it('can be set with minimizable constructor option', () => {
const w = new BrowserWindow({ show: false, title: 'mYtItLe' });
expect(w.getTitle()).to.eql('mYtItLe');
});
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.getTitle()).to.eql('Electron Test Main');
w.setTitle('NEW TITLE');
expect(w.getTitle()).to.eql('NEW TITLE');
});
});
});
describe('minimizable state', () => {
it('with properties', () => {
it('can be set with minimizable constructor option', () => {
@ -3569,23 +3663,31 @@ describe('BrowserWindow module', () => {
});
});
ifdescribe(process.platform === 'darwin')('fullscreenable state', () => {
it('with properties', () => {
it('can be set with fullscreenable constructor option', () => {
const w = new BrowserWindow({ show: false, fullscreenable: false });
expect(w.fullScreenable).to.be.false('fullScreenable');
});
ifdescribe(process.platform !== 'darwin')('menuBarVisible state', () => {
describe('with properties', () => {
it('can be changed', () => {
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');
expect(w.menuBarVisible).to.be.true();
w.menuBarVisible = false;
expect(w.menuBarVisible).to.be.false();
w.menuBarVisible = true;
expect(w.menuBarVisible).to.be.true();
});
});
describe('with functions', () => {
it('can be changed', () => {
const w = new BrowserWindow({ show: false });
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
w.setMenuBarVisibility(false);
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
w.setMenuBarVisibility(true);
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
});
});
});
ifdescribe(process.platform === 'darwin')('fullscreenable state', () => {
it('with functions', () => {
it('can be set with fullscreenable constructor option', () => {
const w = new BrowserWindow({ show: false, fullscreenable: false });
@ -3607,18 +3709,46 @@ describe('BrowserWindow module', () => {
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');
it('with properties', () => {
it('can be set with a constructor property', () => {
const w = new BrowserWindow({ kiosk: true });
expect(w.kiosk).to.be.true();
});
w.once('leave-full-screen', () => {
done();
it('can be changed ', (done) => {
const w = new BrowserWindow();
w.once('enter-full-screen', async () => {
await tick();
w.kiosk = false;
expect(w.kiosk).to.be.false();
});
w.once('leave-full-screen', () => {
done();
});
w.kiosk = true;
expect(w.kiosk).to.be.true();
});
});
it('with functions', () => {
it('can be set with a constructor property', () => {
const w = new BrowserWindow({ kiosk: true });
expect(w.isKiosk()).to.be.true();
});
it('can be changed ', (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');
});
w.setKiosk(true);
expect(w.isKiosk()).to.be.true('isKiosk');
});
});
@ -3653,7 +3783,7 @@ describe('BrowserWindow module', () => {
w.setFullScreen(true);
});
it('does not crash when exiting simpleFullScreen', (done) => {
it('does not crash when exiting simpleFullScreen (properties)', (done) => {
const w = new BrowserWindow();
w.setSimpleFullScreen(true);
@ -3663,6 +3793,16 @@ describe('BrowserWindow module', () => {
}, 1000);
});
it('does not crash when exiting simpleFullScreen (functions)', (done) => {
const w = new BrowserWindow();
w.simpleFullScreen = true;
setTimeout(() => {
w.setFullScreen(!w.isFullScreen());
done();
}, 1000);
});
it('should not be changed by setKiosk method', (done) => {
const w = new BrowserWindow();
w.once('enter-full-screen', async () => {
@ -3717,27 +3857,53 @@ describe('BrowserWindow module', () => {
});
describe('hasShadow state', () => {
it('returns a boolean on all platforms', () => {
const w = new BrowserWindow({ show: false });
const hasShadow = w.hasShadow();
expect(hasShadow).to.be.a('boolean');
it('with properties', () => {
it('returns a boolean on all platforms', () => {
const w = new BrowserWindow({ show: false });
expect(w.shadow).to.be.a('boolean');
});
// On Windows there's no shadow by default & it can't be changed dynamically.
it('can be changed with hasShadow option', () => {
const hasShadow = process.platform !== 'darwin';
const w = new BrowserWindow({ show: false, hasShadow });
expect(w.shadow).to.equal(hasShadow);
});
it('can be changed with setHasShadow method', () => {
const w = new BrowserWindow({ show: false });
w.shadow = false;
expect(w.shadow).to.be.false('hasShadow');
w.shadow = true;
expect(w.shadow).to.be.true('hasShadow');
w.shadow = false;
expect(w.shadow).to.be.false('hasShadow');
});
});
// On Windows there's no shadow by default & it can't be changed dynamically.
it('can be changed with hasShadow option', () => {
const hasShadow = process.platform !== 'darwin';
const w = new BrowserWindow({ show: false, hasShadow });
expect(w.hasShadow()).to.equal(hasShadow);
});
describe('with functions', () => {
it('returns a boolean on all platforms', () => {
const w = new BrowserWindow({ show: false });
const hasShadow = w.hasShadow();
expect(hasShadow).to.be.a('boolean');
});
it('can be changed with setHasShadow method', () => {
const w = new BrowserWindow({ show: false });
w.setHasShadow(false);
expect(w.hasShadow()).to.be.false('hasShadow');
w.setHasShadow(true);
expect(w.hasShadow()).to.be.true('hasShadow');
w.setHasShadow(false);
expect(w.hasShadow()).to.be.false('hasShadow');
// On Windows there's no shadow by default & it can't be changed dynamically.
it('can be changed with hasShadow option', () => {
const hasShadow = process.platform !== 'darwin';
const w = new BrowserWindow({ show: false, hasShadow });
expect(w.hasShadow()).to.equal(hasShadow);
});
it('can be changed with setHasShadow method', () => {
const w = new BrowserWindow({ show: false });
w.setHasShadow(false);
expect(w.hasShadow()).to.be.false('hasShadow');
w.setHasShadow(true);
expect(w.hasShadow()).to.be.true('hasShadow');
w.setHasShadow(false);
expect(w.hasShadow()).to.be.false('hasShadow');
});
});
});
});