tor-browser

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

browser_dbg-outline-focus.js (2692B)


      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 after clicking a function in edtior, outline focuses that function
      6 
      7 "use strict";
      8 
      9 // Tests that after clicking a function in edtior, outline focuses that function
     10 add_task(async function () {
     11  const dbg = await initDebugger("doc-sources.html", "long.js");
     12 
     13  await selectSource(dbg, "long.js", 1);
     14  await openOutlinePanel(dbg);
     15 
     16  is(
     17    findAllElements(dbg, "outlineItems").length,
     18    9,
     19    "9 items in the outline list"
     20  );
     21 
     22  info("Clicking inside a function in editor should focus the outline");
     23  await clickAtPos(dbg, { line: 15, column: 3 });
     24  await waitForElementWithSelector(dbg, ".outline-list__element.focused");
     25  ok(
     26    getFocusedFunction(dbg).includes("addTodo"),
     27    "The right function is focused"
     28  );
     29 
     30  info("Clicking an empty line in the editor should unfocus the outline");
     31  await clickAtPos(dbg, { line: 12, column: 3 });
     32  // Wait for the node to be unfocused
     33  await waitFor(() => !getFocusedNode(dbg));
     34  is(getFocusedNode(dbg), null, "should not exist");
     35 });
     36 
     37 // Tests that clicking a function in outline panel, the editor highlights the correct location.
     38 add_task(async function () {
     39  const dbg = await initDebugger("doc-scripts.html", "simple1.js");
     40 
     41  await selectSource(dbg, "simple1.js", 1);
     42 
     43  await openOutlinePanel(dbg);
     44 
     45  assertOutlineItems(dbg, [
     46    "λmain()",
     47    "λdoEval()",
     48    "λevaledFunc()",
     49    "λdoNamedEval()",
     50    // evaledFunc is set twice
     51    "λevaledFunc()",
     52    "λnormalFunction(foo)",
     53    "λletFunction(a)",
     54    "λconstFunction(x)",
     55    "λProtoClass(a)",
     56    "λprotoFoo(foo)",
     57    "λprotoBar(x, y)",
     58    "λprotoBoo(x)",
     59    "λ1234()",
     60    "λmemFoo(a, b)",
     61    "λarrFoo(c)",
     62    "class MyClass",
     63    "λconstructor(a, b)",
     64    "λtest()",
     65    "λ#privateFunc(a, b)",
     66    "class Klass",
     67    "λconstructor()",
     68    "λtest()",
     69    "λbar()",
     70    "λboo(a)",
     71  ]);
     72 
     73  info("Click an item in outline panel");
     74  const item = getNthItem(dbg, 3);
     75  item.click();
     76  await waitForLoadedSource(dbg, "simple1.js");
     77  assertHighlightLocation(dbg, "simple1.js", 15);
     78  ok(
     79    item.parentNode.classList.contains("focused"),
     80    "The clicked item li is focused"
     81  );
     82 });
     83 
     84 // Clicking on a class heading  select the correct class line
     85 
     86 function getFocusedNode(dbg) {
     87  return findElementWithSelector(dbg, ".outline-list__element.focused");
     88 }
     89 
     90 function getFocusedFunction(dbg) {
     91  return getFocusedNode(dbg).innerText;
     92 }
     93 
     94 function getNthItem(dbg, index) {
     95  return findElement(dbg, "outlineItem", index);
     96 }