tor-browser

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

browser_jsterm_editor_execute_selection.js (2250B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that the user can execute only the code that is selected in the input, in editor
      5 // mode.
      6 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1576563
      7 
      8 "use strict";
      9 
     10 const TEST_URI =
     11  "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test for executing input selection";
     12 
     13 add_task(async function () {
     14  await pushPref("devtools.webconsole.input.editor", true);
     15  const hud = await openNewTabAndConsole(TEST_URI);
     16 
     17  const expression = `x = "first assignment";x;
     18    x = "second assignment";x;`;
     19 
     20  info("Evaluate the whole expression");
     21  setInputValue(hud, expression);
     22 
     23  let onResultMessage = waitForMessageByType(
     24    hud,
     25    "second assignment",
     26    ".result"
     27  );
     28  synthesizeKeyboardEvaluation();
     29  await onResultMessage;
     30  ok(true, "The whole expression is evaluated when there's no selection");
     31 
     32  info("Select the first line and evaluate");
     33  hud.ui.jsterm.editor.setSelection(
     34    { line: 0, ch: 0 },
     35    { line: 0, ch: expression.split("\n")[0].length }
     36  );
     37  onResultMessage = waitForMessageByType(hud, "first assignment", ".result");
     38  synthesizeKeyboardEvaluation();
     39  await onResultMessage;
     40  ok(true, "Only the expression on the first line was evaluated");
     41 
     42  info("Check that it also works when clicking on the Run button");
     43  onResultMessage = waitForMessageByType(hud, "first assignment", ".result");
     44  hud.ui.outputNode
     45    .querySelector(".webconsole-editor-toolbar-executeButton")
     46    .click();
     47  await onResultMessage;
     48  ok(
     49    true,
     50    "Only the expression on the first line was evaluated when clicking the Run button"
     51  );
     52 
     53  info("Check that this is disabled in inline mode");
     54  await toggleLayout(hud);
     55  hud.ui.jsterm.editor.setSelection(
     56    { line: 0, ch: 0 },
     57    { line: 0, ch: expression.split("\n")[0].length }
     58  );
     59  onResultMessage = waitForMessageByType(hud, "second assignment", ".result");
     60  synthesizeKeyboardEvaluation();
     61  await onResultMessage;
     62  ok(true, "The whole expression was evaluated in inline mode");
     63 });
     64 
     65 function synthesizeKeyboardEvaluation() {
     66  EventUtils.synthesizeKey("KEY_Enter", {
     67    [Services.appinfo.OS === "Darwin" ? "metaKey" : "ctrlKey"]: true,
     68  });
     69 }