summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-pause-points.js
blob: 456e4e10f56bf67d97e90290a5066c21ca0f3092 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* 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);

async function testCase(dbg, { name, steps }) {
  info(` ### Execute testCase "${name}"`);

  const {
    selectors: { getTopFrame, getCurrentThread },
  } = dbg;
  const locations = [];

  const recordFrame = state => {
    const { line, column } = getTopFrame(getCurrentThread()).location;
    locations.push([line, column]);
    info(`Break on ${line}:${column}`);
  };

  info("Trigger the expected debugger statement");
  const onPaused = waitForPaused(dbg);
  invokeInTab(name);
  await onPaused;
  recordFrame();

  info("Start stepping over");
  for (let i = 0; i < steps.length - 1; i++) {
    await dbg.actions.stepOver();
    await waitForPaused(dbg);
    recordFrame();
  }

  is(formatSteps(locations), formatSteps(steps), name);

  await resume(dbg);
}

add_task(async function test() {
  const dbg = await initDebugger("doc-pause-points.html", "pause-points.js");

  await selectSource(dbg, "pause-points.js");
  await testCase(dbg, {
    name: "statements",
    steps: [
      [9, 2],
      [10, 4],
      [10, 13],
      [11, 2],
      [11, 21],
      [12, 2],
      [12, 12],
      [13, 0],
    ],
  });

  await testCase(dbg, {
    name: "expressions",
    steps: [
      [40, 2],
      [41, 2],
      [42, 12],
      [43, 0],
    ],
  });

  await testCase(dbg, {
    name: "sequences",
    steps: [
      [23, 2],
      [25, 12],
      [29, 12],
      [34, 2],
      [37, 0],
    ],
  });

  await testCase(dbg, {
    name: "flow",
    steps: [
      [16, 2],
      [17, 12],
      [18, 10],
      [19, 8],
      [19, 17],
      [19, 8],
      [19, 17],
      [19, 8],
    ],
  });
});

function formatSteps(steps) {
  return steps.map(loc => `(${loc.join(",")})`).join(", ");
}