fix: navigator.keyboard.lock()
fullscreen exit handling (#40365)
fix: navigator.keyboard.lock() fullscreen exit handling
This commit is contained in:
parent
4b1c31e4db
commit
fcdd5cba71
5 changed files with 86 additions and 16 deletions
|
@ -606,6 +606,63 @@ describe('chromium features', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('navigator.keyboard', () => {
|
||||
afterEach(closeAllWindows);
|
||||
|
||||
it('getLayoutMap() should return a KeyboardLayoutMap object', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
|
||||
const size = await w.webContents.executeJavaScript(`
|
||||
navigator.keyboard.getLayoutMap().then(map => map.size)
|
||||
`);
|
||||
|
||||
expect(size).to.be.a('number');
|
||||
});
|
||||
|
||||
it('should lock the keyboard', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
await w.loadFile(path.join(fixturesPath, 'pages', 'modal.html'));
|
||||
|
||||
// Test that without lock, with ESC:
|
||||
// - the window leaves fullscreen
|
||||
// - the dialog is not closed
|
||||
const enterFS1 = once(w, 'enter-full-screen');
|
||||
await w.webContents.executeJavaScript('document.body.requestFullscreen()', true);
|
||||
await enterFS1;
|
||||
|
||||
await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').showModal()', true);
|
||||
const open1 = await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').open');
|
||||
expect(open1).to.be.true();
|
||||
|
||||
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
|
||||
await setTimeout(1000);
|
||||
const openAfter1 = await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').open');
|
||||
expect(openAfter1).to.be.true();
|
||||
expect(w.isFullScreen()).to.be.false();
|
||||
|
||||
// Test that with lock, with ESC:
|
||||
// - the window does not leave fullscreen
|
||||
// - the dialog is closed
|
||||
const enterFS2 = once(w, 'enter-full-screen');
|
||||
await w.webContents.executeJavaScript(`
|
||||
navigator.keyboard.lock(['Escape']);
|
||||
document.body.requestFullscreen();
|
||||
`, true);
|
||||
|
||||
await enterFS2;
|
||||
|
||||
await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').showModal()', true);
|
||||
const open2 = await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').open');
|
||||
expect(open2).to.be.true();
|
||||
|
||||
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
|
||||
await setTimeout(1000);
|
||||
const openAfter2 = await w.webContents.executeJavaScript('document.getElementById(\'favDialog\').open');
|
||||
expect(openAfter2).to.be.false();
|
||||
expect(w.isFullScreen()).to.be.true();
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigator.languages', () => {
|
||||
it('should return the system locale only', async () => {
|
||||
const appLocale = app.getLocale();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue