tor-browser

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

browser_dbg-go-to-line.js (2457B)


      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 // Test the "go to line" feature correctly responses to keyboard shortcuts.
      6 
      7 "use strict";
      8 
      9 add_task(async function () {
     10  const dbg = await initDebugger("doc-scripts.html", "long.js");
     11  await selectSource(dbg, "long.js");
     12  await waitForSelectedSource(dbg, "long.js");
     13 
     14  info("Test opening");
     15  pressKey(dbg, "goToLine");
     16  assertEnabled(dbg);
     17  is(
     18    dbg.win.document.activeElement.tagName,
     19    "INPUT",
     20    "The input area of 'go to line' box is focused"
     21  );
     22 
     23  info("Test closing by the same keyboard shortcut");
     24  pressKey(dbg, "goToLine");
     25  assertDisabled(dbg);
     26  is(findElement(dbg, "searchField"), null, "The 'go to line' box is closed");
     27 
     28  info("Test the sourceeditor shortcut");
     29  pressKey(dbg, "sourceeditorGoToLine");
     30  assertEnabled(dbg);
     31 
     32  pressKey(dbg, "Escape");
     33  assertDisabled(dbg);
     34  is(findElement(dbg, "searchField"), null, "The 'go to line' box is closed");
     35 
     36  info("Test closing by escape");
     37  pressKey(dbg, "goToLine");
     38  assertEnabled(dbg);
     39 
     40  pressKey(dbg, "Escape");
     41  assertDisabled(dbg);
     42  is(findElement(dbg, "searchField"), null, "The 'go to line' box is closed");
     43 
     44  info("Test going to the correct line");
     45  pressKey(dbg, "goToLine");
     46  await waitForGoToLineBoxFocus(dbg);
     47  type(dbg, "66");
     48  pressKey(dbg, "Enter");
     49  await assertLine(dbg, 66);
     50 
     51  info("Add breakpoint on line 66 using keyboard shortcut");
     52  pressKey(dbg, "toggleBreakpoint");
     53  await waitForDispatch(dbg.store, "SET_BREAKPOINT");
     54  await assertBreakpoint(dbg, 66);
     55 
     56  info("Remove breakpoint on line 66 using keyboard shortcut");
     57  pressKey(dbg, "toggleBreakpoint");
     58  await waitForBreakpointCount(dbg, 0);
     59  await assertNoBreakpoint(dbg, 66);
     60 });
     61 
     62 function assertEnabled(dbg) {
     63  is(dbg.selectors.getQuickOpenEnabled(), true, "quickOpen enabled");
     64 }
     65 
     66 function assertDisabled(dbg) {
     67  is(dbg.selectors.getQuickOpenEnabled(), false, "quickOpen disabled");
     68 }
     69 
     70 async function waitForGoToLineBoxFocus(dbg) {
     71  await waitFor(() => dbg.win.document.activeElement.tagName === "INPUT");
     72 }
     73 
     74 async function assertLine(dbg, lineNumber) {
     75  // Wait for the line to be set
     76  await waitUntil(() => !!dbg.selectors.getSelectedLocation().line);
     77  is(
     78    dbg.selectors.getSelectedLocation().line,
     79    lineNumber,
     80    `goto line is ${lineNumber}`
     81  );
     82 }