michael@0: /* michael@0: * Copyright 2012, Mozilla Foundation and contributors michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: 'use strict'; michael@0: // michael@0: michael@0: // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT michael@0: // DO NOT EDIT IT DIRECTLY michael@0: michael@0: var exports = {}; michael@0: michael@0: var TEST_URI = "data:text/html;charset=utf-8,

gcli-testInputter.js

"; michael@0: michael@0: function test() { michael@0: return Task.spawn(function() { michael@0: let options = yield helpers.openTab(TEST_URI); michael@0: yield helpers.openToolbar(options); michael@0: gcli.addItems(mockCommands.items); michael@0: michael@0: yield helpers.runTests(options, exports); michael@0: michael@0: gcli.removeItems(mockCommands.items); michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: }).then(finish, helpers.handleError); michael@0: } michael@0: michael@0: // michael@0: michael@0: // var assert = require('../testharness/assert'); michael@0: var KeyEvent = require('gcli/util/util').KeyEvent; michael@0: michael@0: var latestEvent; michael@0: var latestData; michael@0: michael@0: var outputted = function(ev) { michael@0: latestEvent = ev; michael@0: michael@0: ev.output.promise.then(function() { michael@0: latestData = ev.output.data; michael@0: }); michael@0: }; michael@0: michael@0: michael@0: exports.setup = function(options) { michael@0: options.requisition.commandOutputManager.onOutput.add(outputted); michael@0: }; michael@0: michael@0: exports.shutdown = function(options) { michael@0: options.requisition.commandOutputManager.onOutput.remove(outputted); michael@0: }; michael@0: michael@0: exports.testOutput = function(options) { michael@0: latestEvent = undefined; michael@0: latestData = undefined; michael@0: michael@0: var terminal = options.terminal; michael@0: if (!terminal) { michael@0: assert.log('Skipping testInputter.testOutput due to lack of terminal.'); michael@0: return; michael@0: } michael@0: michael@0: var focusManager = terminal.focusManager; michael@0: michael@0: terminal.setInput('tss'); michael@0: michael@0: var ev0 = { keyCode: KeyEvent.DOM_VK_RETURN }; michael@0: terminal.onKeyDown(ev0); michael@0: michael@0: assert.is(terminal.getInputState().typed, michael@0: 'tss', michael@0: 'terminal should do nothing on RETURN keyDown'); michael@0: assert.is(latestEvent, undefined, 'no events this test'); michael@0: assert.is(latestData, undefined, 'no data this test'); michael@0: michael@0: var ev1 = { keyCode: KeyEvent.DOM_VK_RETURN }; michael@0: return terminal.handleKeyUp(ev1).then(function() { michael@0: assert.ok(latestEvent != null, 'events this test'); michael@0: assert.is(latestData, 'Exec: tss ', 'last command is tss'); michael@0: michael@0: assert.is(terminal.getInputState().typed, michael@0: '', michael@0: 'terminal should exec on RETURN keyUp'); michael@0: michael@0: assert.ok(focusManager._recentOutput, 'recent output happened'); michael@0: michael@0: var ev2 = { keyCode: KeyEvent.DOM_VK_F1 }; michael@0: return terminal.handleKeyUp(ev2).then(function() { michael@0: assert.ok(!focusManager._recentOutput, 'no recent output happened post F1'); michael@0: assert.ok(focusManager._helpRequested, 'F1 = help'); michael@0: michael@0: var ev3 = { keyCode: KeyEvent.DOM_VK_ESCAPE }; michael@0: return terminal.handleKeyUp(ev3).then(function() { michael@0: assert.ok(!focusManager._helpRequested, 'ESCAPE = anti help'); michael@0: }); michael@0: }); michael@0: michael@0: }); michael@0: };