browser_gcli_inputter.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2012, Mozilla Foundation and contributors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. "use strict";
  17. // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
  18. // PLEASE TALK TO SOMEONE IN DEVELOPER TOOLS BEFORE EDITING IT
  19. const exports = {};
  20. function test() {
  21. helpers.runTestModule(exports, "browser_gcli_inputter.js");
  22. }
  23. // var assert = require('../testharness/assert');
  24. var KeyEvent = require("gcli/util/util").KeyEvent;
  25. var latestEvent;
  26. var latestData;
  27. var outputted = function (ev) {
  28. latestEvent = ev;
  29. ev.output.promise.then(function () {
  30. latestData = ev.output.data;
  31. });
  32. };
  33. exports.setup = function (options) {
  34. options.requisition.commandOutputManager.onOutput.add(outputted);
  35. };
  36. exports.shutdown = function (options) {
  37. options.requisition.commandOutputManager.onOutput.remove(outputted);
  38. };
  39. exports.testOutput = function (options) {
  40. latestEvent = undefined;
  41. latestData = undefined;
  42. var terminal = options.terminal;
  43. if (!terminal) {
  44. assert.log("Skipping testInputter.testOutput due to lack of terminal.");
  45. return;
  46. }
  47. var focusManager = terminal.focusManager;
  48. terminal.setInput("tss");
  49. var ev0 = { keyCode: KeyEvent.DOM_VK_RETURN };
  50. terminal.onKeyDown(ev0);
  51. assert.is(terminal.getInputState().typed,
  52. "tss",
  53. "terminal should do nothing on RETURN keyDown");
  54. assert.is(latestEvent, undefined, "no events this test");
  55. assert.is(latestData, undefined, "no data this test");
  56. var ev1 = { keyCode: KeyEvent.DOM_VK_RETURN };
  57. return terminal.handleKeyUp(ev1).then(function () {
  58. assert.ok(latestEvent != null, "events this test");
  59. assert.is(latestData.name, "tss", "last command is tss");
  60. assert.is(terminal.getInputState().typed,
  61. "",
  62. "terminal should exec on RETURN keyUp");
  63. assert.ok(focusManager._recentOutput, "recent output happened");
  64. var ev2 = { keyCode: KeyEvent.DOM_VK_F1 };
  65. return terminal.handleKeyUp(ev2).then(function () {
  66. assert.ok(!focusManager._recentOutput, "no recent output happened post F1");
  67. assert.ok(focusManager._helpRequested, "F1 = help");
  68. var ev3 = { keyCode: KeyEvent.DOM_VK_ESCAPE };
  69. return terminal.handleKeyUp(ev3).then(function () {
  70. assert.ok(!focusManager._helpRequested, "ESCAPE = anti help");
  71. });
  72. });
  73. });
  74. };