summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-go-to-line.js
blob: d151d03a519160e3f77ff55c7ffe0764f4eff8d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// Test the "go to line" feature correctly responses to keyboard shortcuts.

"use strict";

add_task(async function () {
  const dbg = await initDebugger("doc-scripts.html", "long.js");
  await selectSource(dbg, "long.js");
  await waitForSelectedSource(dbg, "long.js");

  info("Test opening");
  pressKey(dbg, "goToLine");
  assertEnabled(dbg);
  is(
    dbg.win.document.activeElement.tagName,
    "INPUT",
    "The input area of 'go to line' box is focused"
  );

  info("Test closing by the same keyboard shortcut");
  pressKey(dbg, "goToLine");
  assertDisabled(dbg);
  is(findElement(dbg, "searchField"), null, "The 'go to line' box is closed");

  info("Test closing by escape");
  pressKey(dbg, "goToLine");
  assertEnabled(dbg);

  pressKey(dbg, "Escape");
  assertDisabled(dbg);
  is(findElement(dbg, "searchField"), null, "The 'go to line' box is closed");

  info("Test going to the correct line");
  pressKey(dbg, "goToLine");
  await waitForGoToLineBoxFocus(dbg);
  type(dbg, "66");
  pressKey(dbg, "Enter");
  await assertLine(dbg, 66);
});

function assertEnabled(dbg) {
  is(dbg.selectors.getQuickOpenEnabled(), true, "quickOpen enabled");
}

function assertDisabled(dbg) {
  is(dbg.selectors.getQuickOpenEnabled(), false, "quickOpen disabled");
}

async function waitForGoToLineBoxFocus(dbg) {
  await waitFor(() => dbg.win.document.activeElement.tagName === "INPUT");
}

async function assertLine(dbg, lineNumber) {
  // Wait for the line to be set
  await waitUntil(() => !!dbg.selectors.getSelectedLocation().line);
  is(
    dbg.selectors.getSelectedLocation().line,
    lineNumber,
    `goto line is ${lineNumber}`
  );
}