keyboard.spec.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. var sinon = require('sinon');
  2. var assert = require('assert');
  3. var Keyboard = require('../lib/keyboard');
  4. var KeyCombo = require('../lib/key-combo');
  5. var Locale = require('../lib/locale');
  6. var doc = require('./fixtures/document');
  7. var win = require('./fixtures/window');
  8. describe('Keyboard', function() {
  9. var keyboard;
  10. beforeEach(function() {
  11. keyboard = new Keyboard(win, doc);
  12. });
  13. describe('#setLocale', function() {
  14. it('creates and sets a locale', function() {
  15. keyboard.setLocale('testName', function(locale, platform, userAgent) {
  16. assert.equal(platform, 'test-platform');
  17. assert.equal(userAgent, 'test-user-agent');
  18. locale.test = 1;
  19. });
  20. assert.equal(keyboard._locale.test, 1);
  21. assert.equal(keyboard._locales.testName.test, 1);
  22. });
  23. it('sets a locale', function() {
  24. keyboard._locales.testName = { test: 2 };
  25. keyboard.setLocale('testName');
  26. assert.equal(keyboard._locale.test, 2);
  27. });
  28. it('accepts locale instance and sets it', function() {
  29. keyboard.setLocale({
  30. localeName: 'testName',
  31. test: 3
  32. });
  33. assert.equal(keyboard._locale.test, 3);
  34. });
  35. });
  36. describe('#getLocale', function() {
  37. it('returns the current locale', function() {
  38. keyboard._locales.testName = { test: 4, localeName: 'testName' };
  39. keyboard._locale = keyboard._locales.testName;
  40. var locale = keyboard.getLocale();
  41. assert.equal(locale.test, 4);
  42. });
  43. it('returns the a locale by name', function() {
  44. keyboard._locales.testName = { test: 5 };
  45. keyboard._locale = keyboard._locales.testName;
  46. var locale = keyboard.getLocale('testName');
  47. assert.equal(locale.test, 5);
  48. });
  49. });
  50. describe('#bind', function() {
  51. it('binds a combo to press handler and release handlers', function() {
  52. var pressHandler = function() {};
  53. var releaseHandler = function() {};
  54. keyboard.bind('a', pressHandler, releaseHandler);
  55. assert.equal(keyboard._listeners[0].keyCombo.sourceStr, 'a');
  56. assert.equal(keyboard._listeners[0].pressHandler, pressHandler);
  57. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  58. });
  59. it('binds a combo to a press handler', function() {
  60. var pressHandler = function() {};
  61. keyboard.bind('a', pressHandler);
  62. assert.equal(keyboard._listeners[0].keyCombo.sourceStr, 'a');
  63. assert.equal(keyboard._listeners[0].pressHandler, pressHandler);
  64. assert.equal(keyboard._listeners[0].releaseHandler, null);
  65. });
  66. it('binds a combo to a release handler', function() {
  67. var releaseHandler = function() {};
  68. keyboard.bind('a', null, releaseHandler);
  69. assert.equal(keyboard._listeners[0].keyCombo.sourceStr, 'a');
  70. assert.equal(keyboard._listeners[0].pressHandler, null);
  71. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  72. });
  73. it('binds several combos to press and release handlers', function() {
  74. var pressHandler = function() {};
  75. var releaseHandler = function() {};
  76. keyboard.bind(['a', 'b'], pressHandler, releaseHandler);
  77. assert.equal(keyboard._listeners[0].keyCombo.sourceStr, 'a');
  78. assert.equal(keyboard._listeners[1].keyCombo.sourceStr, 'b');
  79. assert.equal(keyboard._listeners[0].pressHandler, pressHandler);
  80. assert.equal(keyboard._listeners[1].pressHandler, pressHandler);
  81. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  82. assert.equal(keyboard._listeners[1].releaseHandler, releaseHandler);
  83. });
  84. it('binds press and release handlers to any keypress', function() {
  85. var pressHandler = function() {};
  86. var releaseHandler = function() {};
  87. keyboard.bind(pressHandler, releaseHandler);
  88. assert.equal(keyboard._listeners[0].keyCombo, null);
  89. assert.equal(keyboard._listeners[0].pressHandler, pressHandler);
  90. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  91. });
  92. it('accepts preventRepeat as a final argument', function() {
  93. var pressHandler = function() {};
  94. var releaseHandler = function() {};
  95. keyboard.bind('a', pressHandler, releaseHandler, true);
  96. keyboard.bind(pressHandler, releaseHandler, true);
  97. assert.equal(keyboard._listeners[0].keyCombo.sourceStr, 'a');
  98. assert.equal(keyboard._listeners[0].pressHandler, pressHandler);
  99. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  100. assert.equal(keyboard._listeners[0].preventRepeat, true);
  101. assert.equal(keyboard._listeners[1].keyCombo, null);
  102. assert.equal(keyboard._listeners[1].pressHandler, pressHandler);
  103. assert.equal(keyboard._listeners[1].releaseHandler, releaseHandler);
  104. assert.equal(keyboard._listeners[1].preventRepeat, true);
  105. });
  106. });
  107. describe('#addListener', function() {
  108. it('is an alias for bind', function() {
  109. assert.equal(keyboard.addListener, keyboard.bind);
  110. });
  111. });
  112. describe('#on', function() {
  113. it('is an alias for bind', function() {
  114. assert.equal(keyboard.on, keyboard.bind);
  115. });
  116. });
  117. describe('#unbind', function() {
  118. var pressHandler = function() {};
  119. var releaseHandler = function() {};
  120. beforeEach(function() {
  121. keyboard._listeners.push({
  122. keyCombo: new KeyCombo('a'),
  123. pressHandler: pressHandler,
  124. releaseHandler: releaseHandler,
  125. preventRepeat: false
  126. });
  127. keyboard._listeners.push({
  128. keyCombo: new KeyCombo('a'),
  129. pressHandler: null,
  130. releaseHandler: releaseHandler,
  131. preventRepeat: false
  132. });
  133. keyboard._listeners.push({
  134. keyCombo: new KeyCombo('a'),
  135. pressHandler: pressHandler,
  136. releaseHandler: null,
  137. preventRepeat: false
  138. });
  139. });
  140. afterEach(function() {
  141. keyboard._listeners.length = 0;
  142. });
  143. it('unbinds a combo from press handler and release handlers', function() {
  144. keyboard.unbind('a', pressHandler, releaseHandler);
  145. assert.equal(keyboard._listeners.length, 2);
  146. assert.equal(keyboard._listeners[0].pressHandler, null);
  147. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  148. assert.equal(keyboard._listeners[1].pressHandler, pressHandler);
  149. assert.equal(keyboard._listeners[1].releaseHandler, null);
  150. });
  151. it('unbinds a combo from a press handler', function() {
  152. keyboard.unbind('a', pressHandler);
  153. assert.equal(keyboard._listeners.length, 2);
  154. assert.equal(keyboard._listeners[0].pressHandler, pressHandler);
  155. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  156. assert.equal(keyboard._listeners[1].pressHandler, null);
  157. assert.equal(keyboard._listeners[1].releaseHandler, releaseHandler);
  158. });
  159. it('unbinds a combo from a release handler', function() {
  160. keyboard.unbind('a', null, releaseHandler);
  161. assert.equal(keyboard._listeners.length, 2);
  162. assert.equal(keyboard._listeners[0].pressHandler, pressHandler);
  163. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  164. assert.equal(keyboard._listeners[1].pressHandler, pressHandler);
  165. assert.equal(keyboard._listeners[1].releaseHandler, null);
  166. });
  167. it('unbinds a several combos from press and release handlers', function() {
  168. keyboard._listeners.push({
  169. keyCombo: new KeyCombo('b'),
  170. pressHandler: pressHandler,
  171. releaseHandler: releaseHandler,
  172. preventRepeat: false
  173. });
  174. keyboard.unbind(['a', 'b'], pressHandler, releaseHandler);
  175. assert.equal(keyboard._listeners.length, 2);
  176. assert.equal(keyboard._listeners[0].pressHandler, null);
  177. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  178. assert.equal(keyboard._listeners[1].pressHandler, pressHandler);
  179. assert.equal(keyboard._listeners[1].releaseHandler, null);
  180. });
  181. it('unbinds press and release handlers bound to any key press', function() {
  182. keyboard._listeners.push({
  183. keyCombo: null,
  184. pressHandler: pressHandler,
  185. releaseHandler: releaseHandler,
  186. preventRepeat: false
  187. });
  188. keyboard.unbind(pressHandler, releaseHandler);
  189. assert.equal(keyboard._listeners.length, 3);
  190. assert.equal(keyboard._listeners[0].pressHandler, pressHandler);
  191. assert.equal(keyboard._listeners[0].releaseHandler, releaseHandler);
  192. assert.equal(keyboard._listeners[1].pressHandler, null);
  193. assert.equal(keyboard._listeners[1].releaseHandler, releaseHandler);
  194. assert.equal(keyboard._listeners[2].pressHandler, pressHandler);
  195. assert.equal(keyboard._listeners[2].releaseHandler, null);
  196. });
  197. });
  198. describe('#removeListener', function() {
  199. it('is an alias for unbind', function() {
  200. assert.equal(keyboard.removeListener, keyboard.unbind);
  201. });
  202. });
  203. describe('#off', function() {
  204. it('is an alias for unbind', function() {
  205. assert.equal(keyboard.off, keyboard.unbind);
  206. });
  207. });
  208. describe('#setContext', function() {
  209. it('releases all keys before setting the context', function() {
  210. keyboard._locale = {};
  211. sinon.stub(keyboard, 'releaseAllKeys');
  212. keyboard.setContext('myContext');
  213. assert.ok(keyboard.releaseAllKeys.calledOnce);
  214. keyboard.releaseAllKeys.restore();
  215. });
  216. it('creates a new context with the given name if it doesn\'t exist.', function() {
  217. keyboard.setContext('myContext');
  218. assert.ok(keyboard._contexts.myContext);
  219. assert.equal(keyboard._currentContext, 'myContext');
  220. });
  221. it('applies an existing context if one with the given name already exists', function() {
  222. keyboard._contexts.myContext = [1];
  223. keyboard.setContext('myContext');
  224. assert.equal(keyboard._currentContext, 'myContext');
  225. assert.equal(keyboard._contexts[keyboard._currentContext][0], 1);
  226. });
  227. });
  228. describe('#getContext', function() {
  229. it('returns the current context', function() {
  230. keyboard._currentContext = 'myContext';
  231. assert.equal(keyboard.getContext(), 'myContext');
  232. });
  233. });
  234. describe('#watch', function() {
  235. it('calls stop', function() {
  236. sinon.stub(keyboard, 'stop');
  237. keyboard.watch(win, doc);
  238. assert.ok(keyboard.stop.calledOnce);
  239. keyboard.stop.restore();
  240. });
  241. it('attaches to a given window and document', function() {
  242. var win = { addEventListener: sinon.stub() };
  243. var doc = { addEventListener: sinon.stub() };
  244. keyboard.watch(win, doc);
  245. assert.equal(keyboard._isModernBrowser, true);
  246. assert.equal(keyboard._targetWindow, win);
  247. assert.equal(keyboard._targetElement, doc);
  248. assert.ok(win.addEventListener.firstCall.args[0], 'focus');
  249. assert.ok(win.addEventListener.secondCall.args[0], 'blur');
  250. assert.ok(doc.addEventListener.firstCall.args[0], 'keydown');
  251. assert.ok(doc.addEventListener.secondCall.args[0], 'keyup');
  252. });
  253. it('attaches to a given window and document (Legacy IE)', function() {
  254. var win = { attachEvent: sinon.stub() };
  255. var doc = { attachEvent: sinon.stub() };
  256. keyboard.watch(win, doc);
  257. assert.equal(keyboard._isModernBrowser, false);
  258. assert.equal(keyboard._targetWindow, win);
  259. assert.equal(keyboard._targetElement, doc);
  260. assert.ok(win.attachEvent.firstCall.args[0], 'onfocus');
  261. assert.ok(win.attachEvent.secondCall.args[0], 'onblur');
  262. assert.ok(doc.attachEvent.firstCall.args[0], 'onkeydown');
  263. assert.ok(doc.attachEvent.secondCall.args[0], 'onkeyup');
  264. });
  265. it('attaches to the global namespace if a window and document is not given', function() {
  266. global.addEventListener = sinon.stub();
  267. global.document = { addEventListener: sinon.stub() };
  268. keyboard.watch();
  269. assert.equal(keyboard._isModernBrowser, true);
  270. assert.equal(keyboard._targetWindow, global);
  271. assert.equal(keyboard._targetElement, global.document);
  272. assert.ok(global.addEventListener.firstCall.args[0], 'focus');
  273. assert.ok(global.addEventListener.secondCall.args[0], 'blur');
  274. assert.ok(global.document.addEventListener.firstCall.args[0], 'keydown');
  275. assert.ok(global.document.addEventListener.secondCall.args[0], 'keyup');
  276. delete global.addEventListener;
  277. delete global.document;
  278. });
  279. it('throws is error if the target window does not have the nessisary methods', function() {
  280. var win = {};
  281. var doc = {};
  282. assert.throws(function() {
  283. keyboard.watch(win, doc);
  284. }, /^(?=.*targetWindow)(?=.*addEventListener)(?=.*attachEvent).*$/);
  285. });
  286. it('throws is error a target window was not given and if the global does contain the nessisary functions', function() {
  287. assert.throws(function() {
  288. keyboard.watch();
  289. }, /^(?=.*global)(?=.*addEventListener)(?=.*attachEvent).*$/);
  290. });
  291. });
  292. describe('#stop', function() {
  293. it('dettaches from the currently attached window and document', function() {
  294. var doc = keyboard._targetElement = { removeEventListener: sinon.stub() };
  295. var win = keyboard._targetWindow = { removeEventListener: sinon.stub() };
  296. keyboard.stop();
  297. assert.equal(keyboard._targetWindow, null);
  298. assert.equal(keyboard._targetElement, null);
  299. assert.ok(win.removeEventListener.firstCall.args[0], 'focus');
  300. assert.ok(win.removeEventListener.secondCall.args[0], 'blur');
  301. assert.ok(doc.removeEventListener.firstCall.args[0], 'keydown');
  302. assert.ok(doc.removeEventListener.secondCall.args[0], 'keyup');
  303. });
  304. it('dettaches from the currently attached window and document (Legacy IE)', function() {
  305. var doc = { detachEvent: sinon.stub() };
  306. var win = { detachEvent: sinon.stub() };
  307. keyboard._isModernBrowser = false;
  308. keyboard._targetElement = doc;
  309. keyboard._targetWindow = win;
  310. keyboard.stop();
  311. assert.equal(keyboard._targetWindow, null);
  312. assert.equal(keyboard._targetElement, null);
  313. assert.ok(win.detachEvent.firstCall.args[0], 'onfocus');
  314. assert.ok(win.detachEvent.secondCall.args[0], 'onblur');
  315. assert.ok(doc.detachEvent.firstCall.args[0], 'onkeydown');
  316. assert.ok(doc.detachEvent.secondCall.args[0], 'onkeyup');
  317. });
  318. });
  319. describe('#pressKey', function() {
  320. var locale;
  321. beforeEach(function() {
  322. locale = new Locale('test');
  323. locale.bindKeyCode(0, 'a');
  324. locale.bindKeyCode(1, 'b');
  325. keyboard._locale = locale;
  326. });
  327. it('calls pressKey on the locale', function() {
  328. sinon.stub(locale, 'pressKey');
  329. keyboard.pressKey('a');
  330. assert.equal(locale.pressKey.lastCall.args[0], 'a');
  331. locale.pressKey.restore();
  332. });
  333. it('executes bindings with a combo matching the pressed keys within the locale', function() {
  334. var pressHandler = sinon.stub();
  335. keyboard._listeners.push({
  336. keyCombo: new KeyCombo('a'),
  337. pressHandler: pressHandler,
  338. releaseHandler: null,
  339. preventRepeat: false
  340. });
  341. keyboard.pressKey('a');
  342. assert.ok(pressHandler.calledOnce);
  343. });
  344. it('executes bindings without a combo', function() {
  345. var pressHandler = sinon.stub();
  346. keyboard._listeners.push({
  347. keyCombo: null,
  348. pressHandler: pressHandler,
  349. releaseHandler: null,
  350. preventRepeat: false
  351. });
  352. keyboard.pressKey('a');
  353. keyboard.pressKey('b');
  354. assert.ok(pressHandler.calledTwice);
  355. });
  356. it('prevents combo overlap by marking off keys once they have been used by a combo', function() {
  357. var aPressHandler = sinon.stub();
  358. var aBPressHandler = sinon.stub();
  359. keyboard._listeners.push({
  360. keyCombo: new KeyCombo('a'),
  361. pressHandler: aPressHandler,
  362. releaseHandler: null,
  363. preventRepeat: false
  364. });
  365. keyboard._listeners.push({
  366. keyCombo: new KeyCombo('a + b'),
  367. pressHandler: aBPressHandler,
  368. releaseHandler: null,
  369. preventRepeat: false
  370. });
  371. keyboard.pressKey('a'); // combo a fires
  372. keyboard.pressKey('b'); // combo a + b fires, but not combo a because the
  373. // a key has been consumed by combo a + b
  374. assert.ok(aPressHandler.calledOnce);
  375. assert.ok(aBPressHandler.calledOnce);
  376. });
  377. it('allows any number of identical bindings to fire without inhibiting each other', function() {
  378. var a1PressHandler = sinon.stub();
  379. var a2PressHandler = sinon.stub();
  380. keyboard._listeners.push({
  381. keyCombo: new KeyCombo('a'),
  382. pressHandler: a1PressHandler,
  383. releaseHandler: null,
  384. preventRepeat: false
  385. });
  386. keyboard._listeners.push({
  387. keyCombo: new KeyCombo('a'),
  388. pressHandler: a2PressHandler,
  389. releaseHandler: null,
  390. preventRepeat: false
  391. });
  392. keyboard.pressKey('a'); // combo a1 and a2 fires
  393. assert.ok(a1PressHandler.calledOnce);
  394. assert.ok(a2PressHandler.calledOnce);
  395. });
  396. it('does nothing when paused', function() {
  397. sinon.stub(locale, 'pressKey');
  398. keyboard._paused = true;
  399. keyboard.pressKey('a');
  400. assert.equal(locale.pressKey.called, false);
  401. assert.equal(locale.pressedKeys.length, 0);
  402. locale.pressKey.restore();
  403. });
  404. });
  405. describe('#releaseKey', function() {
  406. var locale;
  407. beforeEach(function() {
  408. locale = new Locale('test');
  409. locale.bindKeyCode(0, 'a');
  410. keyboard._locale = locale;
  411. });
  412. it('calls releaseKey on the locale', function() {
  413. sinon.stub(locale, 'releaseKey');
  414. keyboard.releaseKey('a');
  415. assert.equal(locale.releaseKey.lastCall.args[0], 'a');
  416. locale.releaseKey.restore();
  417. });
  418. it('will not execute a binding\'s releaseHandler unless it was triggered first by a press', function() {
  419. var releaseHandler = sinon.stub();
  420. keyboard.pressKey('a');
  421. keyboard._listeners.push({
  422. keyCombo: new KeyCombo('a'),
  423. pressHandler: null,
  424. releaseHandler: releaseHandler,
  425. preventRepeat: false
  426. });
  427. keyboard.releaseKey('a');
  428. assert.equal(releaseHandler.calledOnce, false);
  429. });
  430. it('executes the releaseHandler of active bindings that no longer match the pressed keys', function() {
  431. var releaseHandler = sinon.stub();
  432. keyboard._listeners.push({
  433. keyCombo: new KeyCombo('a'),
  434. pressHandler: null,
  435. releaseHandler: releaseHandler,
  436. preventRepeat: false
  437. });
  438. keyboard.pressKey('a');
  439. keyboard.releaseKey('a');
  440. assert.ok(releaseHandler.calledOnce);
  441. });
  442. it('executes the releaseHandler without a combo', function() {
  443. var releaseHandler = sinon.stub();
  444. keyboard._listeners.push({
  445. keyCombo: null,
  446. pressHandler: null,
  447. releaseHandler: releaseHandler,
  448. preventRepeat: false
  449. });
  450. keyboard.pressKey('a');
  451. keyboard.pressKey('b');
  452. keyboard.releaseKey('a');
  453. keyboard.releaseKey('b');
  454. assert.ok(releaseHandler.calledTwice);
  455. });
  456. });
  457. describe('#releaseAllKeys', function() {
  458. var locale;
  459. beforeEach(function() {
  460. locale = new Locale('test');
  461. locale.bindKeyCode(0, 'a');
  462. keyboard._locale = locale;
  463. });
  464. it('clears pressedKeys on the locale', function() {
  465. keyboard.releaseAllKeys();
  466. assert.equal(locale.pressedKeys.length, 0);
  467. });
  468. it('will not execute a binding\'s releaseHandler unless it was triggered first by a press', function() {
  469. var releaseHandler = sinon.stub();
  470. keyboard.pressKey('a');
  471. keyboard._listeners.push({
  472. keyCombo: new KeyCombo('a'),
  473. pressHandler: null,
  474. releaseHandler: releaseHandler,
  475. preventRepeat: false
  476. });
  477. keyboard.releaseAllKeys();
  478. assert.equal(releaseHandler.calledOnce, false);
  479. });
  480. it('executes the releaseHandler of active bindings that no longer match the pressed keys', function() {
  481. var releaseHandler = sinon.stub();
  482. keyboard._listeners.push({
  483. keyCombo: new KeyCombo('a'),
  484. pressHandler: null,
  485. releaseHandler: releaseHandler,
  486. preventRepeat: false
  487. });
  488. keyboard.pressKey('a');
  489. keyboard.releaseAllKeys();
  490. assert.ok(releaseHandler.calledOnce);
  491. });
  492. });
  493. describe('#pause', function() {
  494. it('pauses the instance', function() {
  495. keyboard.pause();
  496. assert.ok(keyboard._paused);
  497. });
  498. });
  499. describe('#resume', function() {
  500. it('resumes the instance', function() {
  501. keyboard.resume();
  502. assert.equal(keyboard._paused, false);
  503. });
  504. });
  505. describe('#reset', function() {
  506. it('calls releaseAllKeys', function() {
  507. sinon.stub(keyboard, 'releaseAllKeys');
  508. keyboard.reset();
  509. assert.ok(keyboard.releaseAllKeys.calledOnce);
  510. keyboard.releaseAllKeys.reset();
  511. });
  512. it('clears all listeners', function() {
  513. sinon.stub(keyboard, 'releaseAllKeys');
  514. keyboard._listeners = [1];
  515. keyboard.reset();
  516. assert.equal(keyboard._listeners.length, 0);
  517. keyboard.releaseAllKeys.reset();
  518. });
  519. });
  520. });