summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-sourcemaps-reloading.js
blob: 5814e423f26dc7204c0a0324cbdd9825dd2204c4 (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
/* 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";

requestLongerTimeout(2);

add_task(async function () {
  // NOTE: the CORS call makes the test run times inconsistent
  const dbg = await initDebugger("doc-sourcemaps.html");
  const {
    selectors: { getBreakpoint, getBreakpointCount },
  } = dbg;

  await waitForSources(dbg, "entry.js", "output.js", "times2.js", "opts.js");
  ok(true, "Original sources exist");
  const entrySrc = findSource(dbg, "entry.js");

  await selectSource(dbg, entrySrc);
  ok(
    getCM(dbg).getValue().includes("window.keepMeAlive"),
    "Original source text loaded correctly"
  );

  await addBreakpoint(dbg, entrySrc, 5);
  await addBreakpoint(dbg, entrySrc, 15, 1);
  await disableBreakpoint(dbg, entrySrc, 15, 1);

  // Test reloading the debugger
  const onReloaded = reload(dbg, "opts.js");
  await waitForDispatch(dbg.store, "LOAD_ORIGINAL_SOURCE_TEXT");

  await waitForPausedInOriginalFileAndToggleMapScopes(dbg, "entry.js");
  assertPausedAtSourceAndLine(dbg, findSource(dbg, "entry.js").id, 5);

  await waitForBreakpointCount(dbg, 2);
  is(getBreakpointCount(), 2, "Two breakpoints exist");

  const bp = getBreakpoint(
    createLocation({
      source: entrySrc,
      line: 15,
      column: 0,
    })
  );
  ok(bp, "Breakpoint is on the correct line");
  ok(bp.disabled, "Breakpoint is disabled");
  await assertBreakpoint(dbg, 15);

  await resume(dbg);
  info("Wait for reload to complete after resume");
  await onReloaded;
});

async function waitForBreakpointCount(dbg, count) {
  return waitForState(dbg, () => dbg.selectors.getBreakpointCount() === count);
}