summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-breakpoints-columns.js
blob: 3793efb74d8f553214b7896ecbf5646f13cafaab (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* 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 that breakpoints set in the pretty printed files display and paused
// correctly.

"use strict";

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

  await selectSource(dbg, "pretty.js");
  await prettyPrint(dbg);

  info(
    "Add breakpoint in funcWithMultipleBreakableColumns, on the for-loop line"
  );
  const LINE_INDEX_TO_BREAK_ON = 15;
  const prettySourceFileName = "pretty.js:formatted";
  await addBreakpoint(dbg, prettySourceFileName, LINE_INDEX_TO_BREAK_ON);
  const prettySource = findSource(dbg, prettySourceFileName);

  info("Check that multiple column breakpoints can be set");
  const columnBreakpointMarkers = await waitForAllElements(
    dbg,
    "columnBreakpoints"
  );
  /*
   * We're pausing on the following line, which should have those breakpoints (marked with ➤)
   *
   * for( ➤let i=0; ➤i < items.length; ➤i++ ) {
   *
   */
  is(
    columnBreakpointMarkers.length,
    3,
    "We have the expected numbers of possible column breakpoints"
  );

  info("Enable the second column breakpoint");
  columnBreakpointMarkers[1].click();
  await waitForBreakpointCount(dbg, 2);
  await waitForAllElements(dbg, "breakpointItems", 2);

  info("Check that we do pause at expected locations");
  invokeInTab("funcWithMultipleBreakableColumns");

  info("We pause on the first column breakpoint (before `i` init)");
  await waitForPaused(dbg);
  await waitForInlinePreviews(dbg);
  await assertPausedAtSourceAndLine(
    dbg,
    prettySource.id,
    LINE_INDEX_TO_BREAK_ON,
    16
  );
  await resume(dbg);

  info(
    "We pause at the second column breakpoint, before the first loop iteration"
  );
  await waitForPaused(dbg);
  await waitForInlinePreviews(dbg);
  await assertPausedAtSourceAndLine(
    dbg,
    prettySource.id,
    LINE_INDEX_TO_BREAK_ON,
    19
  );
  const assertScopesForSecondColumnBreakpoint = topBlockItems =>
    assertScopes(dbg, [
      "Block",
      ["<this>", "Window"],
      ...topBlockItems,
      "funcWithMultipleBreakableColumns",
      ["arguments", "Arguments"],
      ["items", "(2) […]"],
    ]);
  await assertScopesForSecondColumnBreakpoint([["i", "0"]]);
  await resume(dbg);

  info(
    "We pause at the second column breakpoint, before the second loop iteration"
  );
  await waitForPaused(dbg);
  await waitForInlinePreviews(dbg);
  await assertPausedAtSourceAndLine(
    dbg,
    prettySource.id,
    LINE_INDEX_TO_BREAK_ON,
    19
  );
  await assertScopesForSecondColumnBreakpoint([["i", "1"]]);
  await resume(dbg);

  info(
    "We pause at the second column breakpoint, before we exit the loop (`items.length` is 2, so the condition will fail)"
  );
  await waitForPaused(dbg);
  await waitForInlinePreviews(dbg);
  await assertPausedAtSourceAndLine(
    dbg,
    prettySource.id,
    LINE_INDEX_TO_BREAK_ON,
    19
  );
  await assertScopesForSecondColumnBreakpoint([["i", "2"]]);
  await resume(dbg);

  info("Remove all breakpoints");
  await clickGutter(dbg, LINE_INDEX_TO_BREAK_ON);
  await waitForBreakpointCount(dbg, 0);

  ok(
    !findAllElements(dbg, "columnBreakpoints").length,
    "There is no column breakpoints anymore after clicking on the gutter"
  );
});