browser_jsterm_editor_enter.js (2585B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test that hitting Ctrl (or Cmd on OSX) + Enter does execute the input 5 // and Enter does not when in editor mode. 6 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1519314 7 8 "use strict"; 9 10 const TEST_URI = 11 "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test for bug 1519314"; 12 13 add_task(async function () { 14 await pushPref("devtools.webconsole.input.editor", true); 15 await performEditorEnabledTests(); 16 }); 17 18 add_task(async function () { 19 await pushPref("devtools.webconsole.input.editor", false); 20 await performEditorDisabledTests(); 21 }); 22 23 const first_expression = `x = 10`; 24 const second_expression = `x + 1`; 25 26 /** 27 * Simulates typing of the two expressions above in the console 28 * for the two test cases below. 29 */ 30 function simulateConsoleInput() { 31 EventUtils.sendString(first_expression); 32 EventUtils.sendKey("return"); 33 EventUtils.sendString(second_expression); 34 } 35 36 async function performEditorEnabledTests() { 37 const hud = await openNewTabAndConsole(TEST_URI); 38 39 simulateConsoleInput(); 40 41 is( 42 getInputValue(hud), 43 `${first_expression}\n${second_expression}`, 44 "text input after pressing the return key is present" 45 ); 46 47 const { visibleMessages } = hud.ui.wrapper.getStore().getState().messages; 48 is( 49 visibleMessages.length, 50 0, 51 "input expressions should not have been executed" 52 ); 53 54 let onMessage = waitForMessageByType(hud, "11", ".result"); 55 EventUtils.synthesizeKey("KEY_Enter", { 56 [Services.appinfo.OS === "Darwin" ? "metaKey" : "ctrlKey"]: true, 57 }); 58 await onMessage; 59 ok(true, "Input was executed on Ctrl/Cmd + Enter"); 60 61 setInputValue(hud, "function x() {"); 62 onMessage = waitForMessageByType(hud, "SyntaxError", ".error"); 63 EventUtils.synthesizeKey("KEY_Enter", { 64 [Services.appinfo.OS === "Darwin" ? "metaKey" : "ctrlKey"]: true, 65 }); 66 await onMessage; 67 ok(true, "The expression was evaluated, even if it wasn't well-formed"); 68 } 69 70 async function performEditorDisabledTests() { 71 const hud = await openNewTabAndConsole(TEST_URI); 72 73 simulateConsoleInput(); 74 // execute the 2nd expression which should have been entered but not executed 75 EventUtils.sendKey("return"); 76 77 let msg = await waitFor(() => findEvaluationResultMessage(hud, "10")); 78 ok(msg, "found evaluation result of 1st expression"); 79 80 msg = await waitFor(() => findEvaluationResultMessage(hud, "11")); 81 ok(msg, "found evaluation result of 2nd expression"); 82 83 is(getInputValue(hud), "", "input line is cleared after execution"); 84 }