browser_jsterm_history.js (1795B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Tests the console history feature accessed via the up and down arrow keys. 5 6 "use strict"; 7 8 const TEST_URI = "data:text/html;charset=UTF-8,<!DOCTYPE html>test"; 9 const COMMANDS = ["document", "window", "window.location"]; 10 11 add_task(async function () { 12 const hud = await openNewTabAndConsole(TEST_URI); 13 const { jsterm } = hud; 14 jsterm.focus(); 15 16 for (const command of COMMANDS) { 17 info(`Executing command ${command}`); 18 await executeAndWaitForResultMessage(hud, command, ""); 19 } 20 21 for (let x = COMMANDS.length - 1; x != -1; x--) { 22 EventUtils.synthesizeKey("KEY_ArrowUp"); 23 is(getInputValue(hud), COMMANDS[x], "check history previous idx:" + x); 24 } 25 26 EventUtils.synthesizeKey("KEY_ArrowUp"); 27 is(getInputValue(hud), COMMANDS[0], "test that item is still index 0"); 28 29 EventUtils.synthesizeKey("KEY_ArrowUp"); 30 is(getInputValue(hud), COMMANDS[0], "test that item is still still index 0"); 31 32 for (let i = 1; i < COMMANDS.length; i++) { 33 EventUtils.synthesizeKey("KEY_ArrowDown"); 34 is(getInputValue(hud), COMMANDS[i], "check history next idx:" + i); 35 } 36 37 EventUtils.synthesizeKey("KEY_ArrowDown"); 38 is(getInputValue(hud), "", "check input is empty again"); 39 40 // Simulate pressing Arrow_Down a few times and then if Arrow_Up shows 41 // the previous item from history again. 42 EventUtils.synthesizeKey("KEY_ArrowDown"); 43 EventUtils.synthesizeKey("KEY_ArrowDown"); 44 EventUtils.synthesizeKey("KEY_ArrowDown"); 45 46 is(getInputValue(hud), "", "check input is still empty"); 47 48 const idxLast = COMMANDS.length - 1; 49 EventUtils.synthesizeKey("KEY_ArrowUp"); 50 is( 51 getInputValue(hud), 52 COMMANDS[idxLast], 53 "check history next idx:" + idxLast 54 ); 55 });