tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_jsterm_multiline.js (2150B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Tests that the console waits for more input instead of evaluating
      6 // when valid, but incomplete, statements are present upon pressing enter
      7 // -or- when the user ends a line with shift + enter.
      8 
      9 "use strict";
     10 
     11 const TEST_URI =
     12  "http://example.com/browser/devtools/client/webconsole/test/browser/test-console.html";
     13 
     14 const SHOULD_ENTER_MULTILINE = [
     15  { input: "function foo() {" },
     16  { input: "var a = 1," },
     17  { input: "var a = 1;", shiftKey: true },
     18  { input: "function foo() { }", shiftKey: true },
     19  { input: "function" },
     20  { input: "(x) =>" },
     21  { input: "let b = {" },
     22  { input: "let a = [" },
     23  { input: "{" },
     24  { input: "{ bob: 3343," },
     25  { input: "function x(y=" },
     26  { input: "Array.from(" },
     27  // shift + enter creates a new line despite parse errors
     28  { input: "{2,}", shiftKey: true },
     29 ];
     30 const SHOULD_EXECUTE = [
     31  { input: "function foo() { }" },
     32  { input: "var a = 1;" },
     33  { input: "function foo() { var a = 1; }" },
     34  { input: '"asdf"' },
     35  { input: "99 + 3" },
     36  { input: "1, 2, 3" },
     37  // errors
     38  { input: "function f(x) { let y = 1, }" },
     39  { input: "function f(x=,) {" },
     40  { input: "{2,}" },
     41 ];
     42 
     43 add_task(async function () {
     44  const hud = await openNewTabAndConsole(TEST_URI);
     45 
     46  for (const { input, shiftKey } of SHOULD_ENTER_MULTILINE) {
     47    setInputValue(hud, input);
     48    EventUtils.synthesizeKey("VK_RETURN", { shiftKey });
     49 
     50    // We need to remove the spaces at the end of the input since code mirror do some
     51    // automatic indent in some case.
     52    const newValue = getInputValue(hud).replace(/ +$/g, "");
     53    is(newValue, input + "\n", "A new line was added");
     54  }
     55 
     56  for (const { input, shiftKey } of SHOULD_EXECUTE) {
     57    setInputValue(hud, input);
     58    const onMessage = waitForMessageByType(hud, "", ".result");
     59    EventUtils.synthesizeKey("VK_RETURN", { shiftKey });
     60    await onMessage;
     61 
     62    await waitFor(() => !getInputValue(hud));
     63    is(getInputValue(hud), "", "Input is cleared");
     64  }
     65 });