Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from novnc:master #57

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions core/input/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class Keyboard {
if ((code === "ControlLeft") && browser.isWindows() &&
!("ControlLeft" in this._keyDownList)) {
this._altGrArmed = true;
this._altGrTimeout = setTimeout(this._handleAltGrTimeout.bind(this), 100);
this._altGrTimeout = setTimeout(this._interruptAltGrSequence.bind(this), 100);
this._altGrCtrlTime = e.timeStamp;
return;
}
Expand All @@ -218,11 +218,7 @@ export default class Keyboard {

// We can't get a release in the middle of an AltGr sequence, so
// abort that detection
if (this._altGrArmed) {
this._altGrArmed = false;
clearTimeout(this._altGrTimeout);
this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true);
}
this._interruptAltGrSequence();

// See comment in _handleKeyDown()
if ((browser.isMac() || browser.isIOS()) && (code === 'CapsLock')) {
Expand All @@ -249,14 +245,20 @@ export default class Keyboard {
}
}

_handleAltGrTimeout() {
this._altGrArmed = false;
clearTimeout(this._altGrTimeout);
this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true);
_interruptAltGrSequence() {
if (this._altGrArmed) {
this._altGrArmed = false;
clearTimeout(this._altGrTimeout);
this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true);
}
}

_allKeysUp() {
Log.Debug(">> Keyboard.allKeysUp");

// Prevent control key being processed after losing focus.
this._interruptAltGrSequence();

for (let code in this._keyDownList) {
this._sendKeyEvent(this._keyDownList[code], code, false);
}
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default [
...globals.node,
...globals.mocha,
sinon: false,
chai: false,
expect: false,
}
},
rules: {
Expand Down
11 changes: 9 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ module.exports = (config) => {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'sinon-chai'],
frameworks: ['mocha'],

// list of files / patterns to load in the browser (loaded in order)
// list of files / patterns to load in the browser
files: [
// node modules
{ pattern: 'node_modules/chai/**', included: false },
{ pattern: 'node_modules/sinon/**', included: false },
{ pattern: 'node_modules/sinon-chai/**', included: false },
// modules to test
{ pattern: 'app/localization.js', included: false, type: 'module' },
{ pattern: 'app/webutil.js', included: false, type: 'module' },
{ pattern: 'core/**/*.js', included: false, type: 'module' },
{ pattern: 'vendor/pako/**/*.js', included: false, type: 'module' },
// tests
{ pattern: 'tests/test.*.js', type: 'module' },
// test support files
{ pattern: 'tests/fake.*.js', included: false, type: 'module' },
{ pattern: 'tests/assertions.js', type: 'module' },
],
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"karma-mocha-reporter": "latest",
"karma-safari-launcher": "latest",
"karma-script-launcher": "latest",
"karma-sinon-chai": "latest",
"mocha": "latest",
"node-getopt": "latest",
"po2json": "latest",
Expand Down
9 changes: 9 additions & 0 deletions tests/assertions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import * as chai from '../node_modules/chai/chai.js';
import sinon from '../node_modules/sinon/pkg/sinon-esm.js';
import sinonChai from '../node_modules/sinon-chai/lib/sinon-chai.js';

window.expect = chai.expect;

window.sinon = sinon;
chai.use(sinonChai);

// noVNC specific assertions
chai.use(function (_chai, utils) {
function _equal(a, b) {
Expand Down
2 changes: 0 additions & 2 deletions tests/test.base64.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Base64 from '../core/base64.js';

describe('Base64 Tools', function () {
Expand Down
2 changes: 0 additions & 2 deletions tests/test.browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import { isMac, isWindows, isIOS, isAndroid, isChromeOS,
isSafari, isFirefox, isChrome, isChromium, isOpera, isEdge,
isGecko, isWebKit, isBlink } from '../core/util/browser.js';
Expand Down
2 changes: 0 additions & 2 deletions tests/test.copyrect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import Display from '../core/display.js';

Expand Down
2 changes: 0 additions & 2 deletions tests/test.deflator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import { inflateInit, inflate } from "../vendor/pako/lib/zlib/inflate.js";
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
import Deflator from "../core/deflator.js";
Expand Down
2 changes: 0 additions & 2 deletions tests/test.display.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Base64 from '../core/base64.js';
import Display from '../core/display.js';

Expand Down
2 changes: 0 additions & 2 deletions tests/test.gesturehandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import EventTargetMixin from '../core/util/eventtarget.js';

import GestureHandler from '../core/input/gesturehandler.js';
Expand Down
2 changes: 0 additions & 2 deletions tests/test.helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import keysyms from '../core/input/keysymdef.js';
import * as KeyboardUtil from "../core/input/util.js";

Expand Down
2 changes: 0 additions & 2 deletions tests/test.hextile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import Display from '../core/display.js';

Expand Down
2 changes: 0 additions & 2 deletions tests/test.inflator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import { deflateInit, deflate, Z_FULL_FLUSH } from "../vendor/pako/lib/zlib/deflate.js";
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
import Inflator from "../core/inflator.js";
Expand Down
2 changes: 0 additions & 2 deletions tests/test.int.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import { toUnsigned32bit, toSigned32bit } from '../core/util/int.js';

describe('Integer casting', function () {
Expand Down
2 changes: 0 additions & 2 deletions tests/test.jpeg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import Display from '../core/display.js';

Expand Down
18 changes: 16 additions & 2 deletions tests/test.keyboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Keyboard from '../core/input/keyboard.js';

describe('Key Event Handling', function () {
Expand Down Expand Up @@ -480,6 +478,22 @@ describe('Key Event Handling', function () {
expect(kbd.onkeyevent).to.not.have.been.called;
});

it('should release ControlLeft on blur', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
kbd._handleKeyDown(keyevent('keydown', {code: 'ControlLeft', key: 'Control', location: 1}));
expect(kbd.onkeyevent).to.not.have.been.called;
kbd._allKeysUp();
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(0xffe3, "ControlLeft", false);

// 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 AltGraph for quick Ctrl+Alt sequence', function () {
const kbd = new Keyboard(document);
kbd.onkeyevent = sinon.spy();
Expand Down
1 change: 0 additions & 1 deletion tests/test.localization.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const expect = chai.expect;
import _, { Localizer, l10n } from '../app/localization.js';

describe('Localization', function () {
Expand Down
2 changes: 0 additions & 2 deletions tests/test.raw.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import Display from '../core/display.js';

Expand Down
2 changes: 0 additions & 2 deletions tests/test.rfb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import RFB from '../core/rfb.js';
import Websock from '../core/websock.js';
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
Expand Down
2 changes: 0 additions & 2 deletions tests/test.rre.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import Display from '../core/display.js';

Expand Down
2 changes: 0 additions & 2 deletions tests/test.tight.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import Display from '../core/display.js';

Expand Down
2 changes: 0 additions & 2 deletions tests/test.tightpng.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import Display from '../core/display.js';

Expand Down
2 changes: 0 additions & 2 deletions tests/test.util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable no-console */
const expect = chai.expect;

import * as Log from '../core/util/logging.js';
import { encodeUTF8, decodeUTF8 } from '../core/util/strings.js';

Expand Down
2 changes: 0 additions & 2 deletions tests/test.websock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import FakeWebSocket from './fake.websocket.js';

Expand Down
11 changes: 4 additions & 7 deletions tests/test.webutil.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* jshint expr: true */

const expect = chai.expect;

import * as WebUtil from '../app/webutil.js';

describe('WebUtil', function () {
Expand Down Expand Up @@ -182,16 +180,15 @@ describe('WebUtil', function () {
window.chrome = chrome;
});

const csSandbox = sinon.createSandbox();

beforeEach(function () {
settings = {};
csSandbox.spy(window.chrome.storage.sync, 'set');
csSandbox.spy(window.chrome.storage.sync, 'remove');
sinon.spy(window.chrome.storage.sync, 'set');
sinon.spy(window.chrome.storage.sync, 'remove');
return WebUtil.initSettings();
});
afterEach(function () {
csSandbox.restore();
window.chrome.storage.sync.set.restore();
window.chrome.storage.sync.remove.restore();
});

describe('writeSetting', function () {
Expand Down
2 changes: 0 additions & 2 deletions tests/test.zrle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

import Websock from '../core/websock.js';
import Display from '../core/display.js';

Expand Down