browser_jsterm_autocomplete_commands.js (1847B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that console commands are autocompleted. 7 8 const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>Test command autocomplete`; 9 10 const { 11 WebConsoleCommandsManager, 12 } = require("resource://devtools/server/actors/webconsole/commands/manager.js"); 13 14 add_task(async function () { 15 const hud = await openNewTabAndConsole(TEST_URI); 16 const { jsterm } = hud; 17 const { autocompletePopup } = jsterm; 18 19 info(`Enter ":"`); 20 jsterm.focus(); 21 let onAutocompleUpdated = jsterm.once("autocomplete-updated"); 22 EventUtils.sendString(":"); 23 await onAutocompleUpdated; 24 25 const expectedCommands = 26 WebConsoleCommandsManager.getAllColonCommandNames().map(name => `:${name}`); 27 ok( 28 hasExactPopupLabels(autocompletePopup, expectedCommands), 29 "popup contains expected commands" 30 ); 31 32 onAutocompleUpdated = jsterm.once("autocomplete-updated"); 33 EventUtils.sendString("s"); 34 await onAutocompleUpdated; 35 checkInputCompletionValue( 36 hud, 37 "creenshot", 38 "completion node has expected :screenshot value" 39 ); 40 41 onAutocompleUpdated = jsterm.once("autocomplete-updated"); 42 EventUtils.synthesizeKey("KEY_Tab"); 43 await onAutocompleUpdated; 44 is( 45 getInputValue(hud), 46 ":screenshot", 47 "Tab key correctly completed :screenshot" 48 ); 49 50 ok(!autocompletePopup.isOpen, "popup is closed after Tab"); 51 52 info("Test :hel completion"); 53 await setInputValue(hud, ":he"); 54 onAutocompleUpdated = jsterm.once("autocomplete-updated"); 55 EventUtils.sendString("l"); 56 57 await onAutocompleUpdated; 58 checkInputCompletionValue( 59 hud, 60 "p", 61 "completion node has expected :help value" 62 ); 63 64 EventUtils.synthesizeKey("KEY_Tab"); 65 is(getInputValue(hud), ":help", "Tab key correctly completes :help"); 66 });