summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-many-breakpoints-same-line.js
blob: d6d1fc30c76179f0dd8910a6aec6c7987c9d4bea (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
/* 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/>. */

// Test settings multiple types of breakpoints on the same line
// Only the last should be used

"use strict";

// Line where we set a breakpoint in simple2.js
const BREAKPOINT_LINE = 5;

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

  await selectSource(dbg, "simple2.js");
  await waitForSelectedSource(dbg, "simple2.js");

  await testSimpleAndLog(dbg);

  await testLogUpdates(dbg);
});

async function testSimpleAndLog(dbg) {
  info("Add a simple breakpoint");
  await addBreakpoint(dbg, "simple2.js", BREAKPOINT_LINE);

  info("Add a log breakpoint, replacing the breakpoint into a logpoint");
  await setLogPoint(dbg, BREAKPOINT_LINE, "`log point ${x}`");
  await waitForLog(dbg, "`log point ${x}`");
  await assertLogBreakpoint(dbg, BREAKPOINT_LINE);

  const bp = findBreakpoint(dbg, "simple2.js", BREAKPOINT_LINE);
  is(
    bp.options.logValue,
    "`log point ${x}`",
    "log breakpoint value is correct"
  );

  info(
    "Eval foo() and trigger the breakpoints. If this freeze here, it means that the log point has been ignored."
  );
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.wrappedJSObject.foo(42);
  });

  info(
    "Wait for the log-point message. Only log-point breakpoint should work."
  );

  await waitForMessageByType(dbg, "log point 42", ".logPoint");

  const source = findSource(dbg, "simple2.js");
  await removeBreakpoint(dbg, source.id, BREAKPOINT_LINE);
}

async function testLogUpdates(dbg) {
  info("Add a log breakpoint");
  await setLogPoint(dbg, BREAKPOINT_LINE, "`log point`");
  await waitForLog(dbg, "`log point`");
  await assertLogBreakpoint(dbg, BREAKPOINT_LINE);

  const bp = findBreakpoint(dbg, "simple2.js", BREAKPOINT_LINE);
  is(bp.options.logValue, "`log point`", "log breakpoint value is correct");

  info("Edit the log breakpoint");
  await setLogPoint(dbg, BREAKPOINT_LINE, " + ` edited`");
  await waitForLog(dbg, "`log point` + ` edited`");
  await assertLogBreakpoint(dbg, BREAKPOINT_LINE);

  const bp2 = findBreakpoint(dbg, "simple2.js", BREAKPOINT_LINE);
  is(
    bp2.options.logValue,
    "`log point` + ` edited`",
    "log breakpoint value is correct"
  );

  info("Eval foo() and trigger the breakpoints");
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.wrappedJSObject.foo();
  });

  info("Wait for the log-point message. Only the edited one should appear");
  await waitForMessageByType(dbg, "log point edited", ".logPoint");
}

async function waitForMessageByType(dbg, msg, typeSelector) {
  const webConsolePanel = await getDebuggerSplitConsole(dbg);
  const hud = webConsolePanel.hud;
  return waitFor(
    async () => !!findMessagesByType(hud, msg, typeSelector).length
  );
}