summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/new/test/mochitest/browser_dbg-editor-highlight.js
blob: d7892e629f887368a031189286eb9c0859c013d4 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests that the editor will always highight the right line, no
// matter if the source text doesn't exist yet or even if the source
// doesn't exist.

add_task(function* () {
  const dbg = yield initDebugger("doc-scripts.html");
  const { selectors: { getSourceText }, getState } = dbg;
  const sourceUrl = EXAMPLE_URL + "long.js";

  // The source itself doesn't even exist yet, and using
  // `selectSourceURL` will set a pending request to load this source
  // and highlight a specific line.
  dbg.actions.selectSourceURL(sourceUrl, { line: 66 });

  // Wait for the source text to load and make sure we're in the right
  // place.
  yield waitForDispatch(dbg, "LOAD_SOURCE_TEXT");
  assertHighlightLocation(dbg, "long.js", 66);

  // Jump to line 16 and make sure the editor scrolled.
  yield selectSource(dbg, "long.js", 16);
  assertHighlightLocation(dbg, "long.js", 16);

  // Make sure only one line is ever highlighted and the flash
  // animation is cancelled on old lines.
  yield selectSource(dbg, "long.js", 17);
  yield selectSource(dbg, "long.js", 18);
  assertHighlightLocation(dbg, "long.js", 18);
  is(findAllElements(dbg, "highlightLine").length, 1,
     "Only 1 line is highlighted");

  // Test jumping to a line in a source that exists but hasn't been
  // loaded yet.
  selectSource(dbg, "simple1.js", 6);

  // Make sure the source is in the loading state, wait for it to be
  // fully loaded, and check the highlighted line.
  const simple1 = findSource(dbg, "simple1.js");
  ok(getSourceText(getState(), simple1.id).get("loading"));
  yield waitForDispatch(dbg, "LOAD_SOURCE_TEXT");
  ok(getSourceText(getState(), simple1.id).get("text"));
  assertHighlightLocation(dbg, "simple1.js", 6);
});