summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-search-file-paused.js
blob: 54a493fc2db15b2e2b0464c75e0bc2e30f8466ab (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
65
66
67
68
69
70
71
/* 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/>. */

// Tests the search bar correctly responds to queries, enter, shift enter

"use strict";

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

  info("Add a breakpoint, wait for pause");
  const source = findSource(dbg, "simple2.js");
  await selectSource(dbg, source);
  await addBreakpoint(dbg, source, 5);
  invokeInTab("main");
  await waitForPaused(dbg);

  info("Starting a search for 'bar'");
  const cm = getCM(dbg);
  pressKey(dbg, "fileSearch");
  is(dbg.selectors.getActiveSearch(), "file");
  const el = getFocusedEl(dbg);
  type(dbg, "bar");
  await waitForSearchState(dbg);

  info("Ensuring 'bar' matches are highlighted");
  pressKey(dbg, "Enter");
  is(cm.state.search.posFrom.line, 1);
  pressKey(dbg, "Enter");
  is(cm.state.search.posFrom.line, 4);

  info("Switching files via frame click");
  const frames = findAllElements(dbg, "frames");
  pressMouseDown(dbg, frames[1]);

  // Ensure that the debug line is in view, and not the first "bar" instance,
  // which the user would have to scroll down for
  const { top } = cm.getScrollInfo();
  is(top, 0, "First search term is not in view");

  // Change the search term and go back to the first source in stack
  info("Switching to paused file via frame click");
  pressKey(dbg, "fileSearch");
  el.value = "";
  type(dbg, "func");
  await waitForSearchState(dbg);
  pressMouseDown(dbg, frames[0]);
  await waitFor(() => cm.state.search.query === "func");

  // Ensure there is a match for the new term
  pressKey(dbg, "Enter");
  await waitFor(() => cm.state.search.posFrom.line === 0);
  is(cm.state.search.posFrom.line, 0);
  pressKey(dbg, "Enter");
  await waitFor(() => cm.state.search.posFrom.line === 1);
  is(cm.state.search.posFrom.line, 1);
});

function getFocusedEl(dbg) {
  const doc = dbg.win.document;
  return doc.activeElement;
}

function pressMouseDown(dbg, node) {
  EventUtils.sendMouseEvent({ type: "mousedown" }, node, dbg.win);
}