1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/commandline/test/browser_gcli_inputter.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +/* 1.5 + * Copyright 2012, Mozilla Foundation and contributors 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +'use strict'; 1.21 +// <INJECTED SOURCE:START> 1.22 + 1.23 +// THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT 1.24 +// DO NOT EDIT IT DIRECTLY 1.25 + 1.26 +var exports = {}; 1.27 + 1.28 +var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testInputter.js</p>"; 1.29 + 1.30 +function test() { 1.31 + return Task.spawn(function() { 1.32 + let options = yield helpers.openTab(TEST_URI); 1.33 + yield helpers.openToolbar(options); 1.34 + gcli.addItems(mockCommands.items); 1.35 + 1.36 + yield helpers.runTests(options, exports); 1.37 + 1.38 + gcli.removeItems(mockCommands.items); 1.39 + yield helpers.closeToolbar(options); 1.40 + yield helpers.closeTab(options); 1.41 + }).then(finish, helpers.handleError); 1.42 +} 1.43 + 1.44 +// <INJECTED SOURCE:END> 1.45 + 1.46 +// var assert = require('../testharness/assert'); 1.47 +var KeyEvent = require('gcli/util/util').KeyEvent; 1.48 + 1.49 +var latestEvent; 1.50 +var latestData; 1.51 + 1.52 +var outputted = function(ev) { 1.53 + latestEvent = ev; 1.54 + 1.55 + ev.output.promise.then(function() { 1.56 + latestData = ev.output.data; 1.57 + }); 1.58 +}; 1.59 + 1.60 + 1.61 +exports.setup = function(options) { 1.62 + options.requisition.commandOutputManager.onOutput.add(outputted); 1.63 +}; 1.64 + 1.65 +exports.shutdown = function(options) { 1.66 + options.requisition.commandOutputManager.onOutput.remove(outputted); 1.67 +}; 1.68 + 1.69 +exports.testOutput = function(options) { 1.70 + latestEvent = undefined; 1.71 + latestData = undefined; 1.72 + 1.73 + var terminal = options.terminal; 1.74 + if (!terminal) { 1.75 + assert.log('Skipping testInputter.testOutput due to lack of terminal.'); 1.76 + return; 1.77 + } 1.78 + 1.79 + var focusManager = terminal.focusManager; 1.80 + 1.81 + terminal.setInput('tss'); 1.82 + 1.83 + var ev0 = { keyCode: KeyEvent.DOM_VK_RETURN }; 1.84 + terminal.onKeyDown(ev0); 1.85 + 1.86 + assert.is(terminal.getInputState().typed, 1.87 + 'tss', 1.88 + 'terminal should do nothing on RETURN keyDown'); 1.89 + assert.is(latestEvent, undefined, 'no events this test'); 1.90 + assert.is(latestData, undefined, 'no data this test'); 1.91 + 1.92 + var ev1 = { keyCode: KeyEvent.DOM_VK_RETURN }; 1.93 + return terminal.handleKeyUp(ev1).then(function() { 1.94 + assert.ok(latestEvent != null, 'events this test'); 1.95 + assert.is(latestData, 'Exec: tss ', 'last command is tss'); 1.96 + 1.97 + assert.is(terminal.getInputState().typed, 1.98 + '', 1.99 + 'terminal should exec on RETURN keyUp'); 1.100 + 1.101 + assert.ok(focusManager._recentOutput, 'recent output happened'); 1.102 + 1.103 + var ev2 = { keyCode: KeyEvent.DOM_VK_F1 }; 1.104 + return terminal.handleKeyUp(ev2).then(function() { 1.105 + assert.ok(!focusManager._recentOutput, 'no recent output happened post F1'); 1.106 + assert.ok(focusManager._helpRequested, 'F1 = help'); 1.107 + 1.108 + var ev3 = { keyCode: KeyEvent.DOM_VK_ESCAPE }; 1.109 + return terminal.handleKeyUp(ev3).then(function() { 1.110 + assert.ok(!focusManager._helpRequested, 'ESCAPE = anti help'); 1.111 + }); 1.112 + }); 1.113 + 1.114 + }); 1.115 +};