electron/spec-main/api-global-shortcut-spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
2.2 KiB
TypeScript
Raw Normal View History

import { expect } from 'chai';
import { globalShortcut } from 'electron/main';
2019-10-30 23:38:21 +00:00
import { ifdescribe } from './spec-helpers';
2019-10-30 23:38:21 +00:00
ifdescribe(process.platform !== 'win32')('globalShortcut module', () => {
2016-08-09 22:10:51 +00:00
beforeEach(() => {
globalShortcut.unregisterAll();
});
it('can register and unregister single accelerators', () => {
const accelerator = 'CmdOrCtrl+A+B+C';
2016-08-09 22:10:51 +00:00
expect(globalShortcut.isRegistered(accelerator)).to.be.false('initially registered');
2016-08-09 22:10:51 +00:00
globalShortcut.register(accelerator, () => {});
expect(globalShortcut.isRegistered(accelerator)).to.be.true('registration worked');
2016-08-09 22:10:51 +00:00
globalShortcut.unregister(accelerator);
expect(globalShortcut.isRegistered(accelerator)).to.be.false('unregistration worked');
2016-08-09 22:10:51 +00:00
globalShortcut.register(accelerator, () => {});
expect(globalShortcut.isRegistered(accelerator)).to.be.true('reregistration worked');
2016-08-09 22:10:51 +00:00
globalShortcut.unregisterAll();
expect(globalShortcut.isRegistered(accelerator)).to.be.false('re-unregistration worked');
2016-08-09 22:10:51 +00:00
});
it('can register and unregister multiple accelerators', () => {
const accelerators = ['CmdOrCtrl+X', 'CmdOrCtrl+Y'];
expect(globalShortcut.isRegistered(accelerators[0])).to.be.false('first initially unregistered');
expect(globalShortcut.isRegistered(accelerators[1])).to.be.false('second initially unregistered');
globalShortcut.registerAll(accelerators, () => {});
expect(globalShortcut.isRegistered(accelerators[0])).to.be.true('first registration worked');
expect(globalShortcut.isRegistered(accelerators[1])).to.be.true('second registration worked');
globalShortcut.unregisterAll();
expect(globalShortcut.isRegistered(accelerators[0])).to.be.false('first unregistered');
expect(globalShortcut.isRegistered(accelerators[1])).to.be.false('second unregistered');
});
it('does not crash when registering media keys as global shortcuts', () => {
const accelerators = [
'VolumeUp',
'VolumeDown',
'VolumeMute',
'MediaNextTrack',
'MediaPreviousTrack',
'MediaStop', 'MediaPlayPause'
];
expect(() => {
globalShortcut.registerAll(accelerators, () => {});
}).to.not.throw();
globalShortcut.unregisterAll();
});
2016-08-09 22:10:51 +00:00
});