summaryrefslogtreecommitdiff
path: root/tests/test.keyboard.js
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-12-10 10:01:04 +0100
committerPierre Ossman <ossman@cendio.se>2020-12-10 10:21:21 +0100
commit0cdf2962c0600727dbc8bc7bc15eb0cef19f18c0 (patch)
tree6de1a7a0e58b262ef2a2c425dc2d3d2bb0c7ff7a /tests/test.keyboard.js
parent146258291ad546a18b05a6c3704a26b8c5d819d4 (diff)
downloadnovnc-0cdf2962c0600727dbc8bc7bc15eb0cef19f18c0.tar.gz
Fake key releases for some Japanese IM keys
Windows behaves very oddly for some Japanese IM keys in that it won't send a key release event when the key is released. In some keys it never sends the event, and in some cases it sends the release as the key is pressed the subsequent time.
Diffstat (limited to 'tests/test.keyboard.js')
-rw-r--r--tests/test.keyboard.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test.keyboard.js b/tests/test.keyboard.js
index 940769e..f460eb3 100644
--- a/tests/test.keyboard.js
+++ b/tests/test.keyboard.js
@@ -268,6 +268,47 @@ describe('Key Event Handling', function () {
});
});
+ describe('Japanese IM keys on Windows', function () {
+ let origNavigator;
+ beforeEach(function () {
+ // window.navigator is a protected read-only property in many
+ // environments, so we need to redefine it whilst running these
+ // tests.
+ origNavigator = Object.getOwnPropertyDescriptor(window, "navigator");
+
+ Object.defineProperty(window, "navigator", {value: {}});
+ if (window.navigator.platform !== undefined) {
+ // Object.defineProperty() doesn't work properly in old
+ // versions of Chrome
+ this.skip();
+ }
+
+ window.navigator.platform = "Windows";
+ });
+
+ afterEach(function () {
+ if (origNavigator !== undefined) {
+ Object.defineProperty(window, "navigator", origNavigator);
+ }
+ });
+
+ const keys = { 'Zenkaku': 0xff2a, 'Hankaku': 0xff2a,
+ 'Alphanumeric': 0xff30, 'Katakana': 0xff26,
+ 'Hiragana': 0xff25, 'Romaji': 0xff24,
+ 'KanaMode': 0xff24 };
+ for (let [key, keysym] of Object.entries(keys)) {
+ it(`should fake key release for ${key} on Windows`, function () {
+ let kbd = new Keyboard(document);
+ kbd.onkeyevent = sinon.spy();
+ kbd._handleKeyDown(keyevent('keydown', {code: 'FakeIM', key: key}));
+
+ expect(kbd.onkeyevent).to.have.been.calledTwice;
+ expect(kbd.onkeyevent.firstCall).to.have.been.calledWith(keysym, "FakeIM", true);
+ expect(kbd.onkeyevent.secondCall).to.have.been.calledWith(keysym, "FakeIM", false);
+ });
+ }
+ });
+
describe('Escape AltGraph on Windows', function () {
let origNavigator;
beforeEach(function () {