forked from libapps/libapps-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhterm_keyboard_tests.js
More file actions
43 lines (37 loc) · 1.35 KB
/
hterm_keyboard_tests.js
File metadata and controls
43 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Keyboard test suite.
*
* Test that KeyDefActions are resolved correctly.
*/
import {hterm} from '../index.js';
/**
* Mock terminal, set up keyMap.
*/
beforeEach(function() {
this.terminal = /** @type {!hterm.Terminal} */ ({
contextMenu: {hide: () => {}},
key: null,
onVTKeystroke: (key) => { this.terminal.key = key; },
wipeContentsCalled: false,
wipeContents: () => { this.terminal.wipeContentsCalled = true; },
});
this.keyboard = new hterm.Keyboard(this.terminal);
});
/** Verify user bindings override. */
it('user-bindings-override-defaults', function() {
const ctrlShiftK = new KeyboardEvent(
'keydown', {keyCode: 'K'.charCodeAt(0), ctrlKey: true, shiftKey: true});
// Without user bindings, terminal.wipeContents() is called.
this.keyboard.onKeyDown_(ctrlShiftK);
assert.isTrue(this.terminal.wipeContentsCalled);
assert.isNull(this.terminal.key);
// With a user binding, terminal.wipeContents() is not called.
this.terminal.wipeContentsCalled = false;
this.keyboard.bindings.addBindings({'Ctrl+Shift+K': '"x"'});
this.keyboard.onKeyDown_(ctrlShiftK);
assert.isFalse(this.terminal.wipeContentsCalled);
assert.equal('x', this.terminal.key);
});