tor-browser

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

browser_jsterm_editor_code_folding.js (2161B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests for code folding appears in editor mode, does not appear in inline mode,
      5 // and that folded code does not remain folded when switched to inline mode.
      6 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1581641
      7 
      8 "use strict";
      9 
     10 const TEST_URI =
     11  "data:text/html;charset=utf-8,<!DOCTYPE html>Test JsTerm editor code folding";
     12 
     13 add_task(async function () {
     14  await pushPref("devtools.webconsole.input.editor", true);
     15 
     16  const hud = await openNewTabAndConsole(TEST_URI);
     17 
     18  info("Check that code folding gutter & arrow are rendered in editor mode");
     19 
     20  const multilineExpression = `function() {
     21    // Silence is golden
     22  }`;
     23  await setInputValue(hud, multilineExpression);
     24 
     25  ok(
     26    await waitFor(() => getFoldArrowOpenElement(hud)),
     27    "code folding gutter was rendered in editor mode"
     28  );
     29 
     30  const foldingArrow = getFoldArrowOpenElement(hud);
     31  ok(foldingArrow, "code folding arrow was rendered in code folding gutter");
     32  is(getCodeLines(hud).length, 3, "There are 3 lines displayed");
     33 
     34  info("Check that code folds when gutter marker clicked");
     35  EventUtils.synthesizeMouseAtCenter(
     36    foldingArrow,
     37    {},
     38    foldingArrow.ownerDocument.defaultView
     39  );
     40  await waitFor(() => getCodeLines(hud).length === 1);
     41  ok(true, "The code was folded, there's only one line displayed now");
     42 
     43  info("Check that folded code is expanded when rendered inline");
     44 
     45  await toggleLayout(hud);
     46 
     47  is(
     48    getCodeLines(hud).length,
     49    3,
     50    "folded code is expended when rendered in inline"
     51  );
     52 
     53  info(
     54    "Check that code folding gutter is hidden when we switch to inline mode"
     55  );
     56  ok(
     57    !getFoldGutterElement(hud),
     58    "code folding gutter is hidden when we switsch to inline mode"
     59  );
     60 });
     61 
     62 function getCodeLines(hud) {
     63  return hud.ui.outputNode.querySelectorAll(
     64    ".CodeMirror-code pre.CodeMirror-line"
     65  );
     66 }
     67 
     68 function getFoldGutterElement(hud) {
     69  return hud.ui.outputNode.querySelector(".CodeMirror-foldgutter");
     70 }
     71 
     72 function getFoldArrowOpenElement(hud) {
     73  return hud.ui.outputNode.querySelector(".CodeMirror-foldgutter-open");
     74 }