Skip to content

Commit

Permalink
Also test Ctrl+AltGr, as that is what browsers use
Browse files Browse the repository at this point in the history
Modern browsers now send the odd sequence of Ctrl+AltGr, rather than the
raw Ctrl+Alt, or the fully adjusted just AltGr.

Make sure we have a test for this scenario and don't break it.
  • Loading branch information
CendioOssman committed Jan 15, 2025
1 parent c7bd247 commit 83a5e9e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test.keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,37 @@ describe('Key event handling', function () {
expect(kbd.onkeyevent).to.not.have.been.called;
});

it('should generate AltGraph for quick Ctrl+AltGraph sequence', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1, timeStamp: Date.now()}));
this.clock.tick(20);
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'AltGraph', location: 2, timeStamp: Date.now()}));
expect(kbd.onkeyevent).to.have.been.calledOnce;
expect(kbd.onkeyevent).to.have.been.calledWith(0xfe03, 'AltRight', true);

// Check that the timer is properly dead
kbd.onkeyevent.resetHistory();
this.clock.tick(100);
expect(kbd.onkeyevent).to.not.have.been.called;
});

it('should generate Ctrl, AltGraph for slow Ctrl+AltGraph sequence', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1, timeStamp: Date.now()}));
this.clock.tick(60);
kbd._handleKeyDown(keyevent('keydown', {code: 'AltRight', key: 'AltGraph', location: 2, timeStamp: Date.now()}));
expect(kbd.onkeyevent).to.have.been.calledTwice;
expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(0xffe3, "ControlLeft", true);
expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(0xfe03, "AltRight", true);

// Check that the timer is properly dead
kbd.onkeyevent.resetHistory();
this.clock.tick(100);
expect(kbd.onkeyevent).to.not.have.been.called;
});

it('should pass through single Alt', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
Expand Down

0 comments on commit 83a5e9e

Please sign in to comment.