summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-navigation.js
blob: 6cf5c0ec5f35577b407db072d7cbd4a67c5b78c5 (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
72
73
/* 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/>. */

"use strict";

const SOURCES = [
  "simple1.js",
  "simple2.js",
  "simple3.js",
  "long.js",
  "doc-scripts.html",
];

/**
 * Test navigating
 * navigating while paused will reset the pause state and sources
 */
add_task(async function () {
  const dbg = await initDebugger("doc-script-switching.html");
  const {
    selectors: { getSelectedSource, getIsPaused, getCurrentThread },
  } = dbg;
  ok(getCurrentThread(), "We get a thread selected on debugger opening");

  info("Pause in the first document");
  invokeInTab("firstCall");
  await waitForPaused(dbg);

  info("Navigate while being paused in the first document");
  await navigate(dbg, "doc-scripts.html", "simple1.js");
  ok(
    getCurrentThread(),
    "The new top level thread is selected after navigation"
  );

  info("Set a breakpoint on the second document and pause on it");
  await selectSource(dbg, "simple1.js");
  await addBreakpoint(dbg, "simple1.js", 4);
  invokeInTab("main");
  await waitForPaused(dbg);
  const source = findSource(dbg, "simple1.js");
  assertPausedAtSourceAndLine(dbg, source.id, 4);
  is(countSources(dbg), 5, "5 sources are loaded.");

  await waitForRequestsToSettle(dbg);
  let onBreakpoint = waitForDispatch(dbg.store, "SET_BREAKPOINT");
  await navigate(dbg, "doc-scripts.html", ...SOURCES);
  await onBreakpoint;
  is(countSources(dbg), 5, "5 sources are loaded.");
  ok(!getIsPaused(getCurrentThread()), "Is not paused");

  await waitForRequestsToSettle(dbg);
  onBreakpoint = waitForDispatch(dbg.store, "SET_BREAKPOINT");
  await navigate(dbg, "doc-scripts.html", ...SOURCES);
  await onBreakpoint;
  is(countSources(dbg), 5, "5 sources are loaded.");

  info("Test that the current selected source persists across reloads");
  await selectSource(dbg, "long.js");

  await waitForRequestsToSettle(dbg);
  onBreakpoint = waitForDispatch(dbg.store, "SET_BREAKPOINT");
  await reload(dbg, "long.js");
  await onBreakpoint;
  await waitForSelectedSource(dbg, "long.js");

  ok(getSelectedSource().url.includes("long.js"), "Selected source is long.js");
});

function countSources(dbg) {
  return dbg.selectors.getSourceCount();
}