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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_URI =
"http://example.com/browser/devtools/client/webconsole/test/browser/" +
"test-console-trace-duplicates.html";
add_task(async function testTraceMessages() {
const hud = await openNewTabAndConsole(TEST_URI);
const message = await waitFor(() => findConsoleAPIMessage(hud, "foo1"));
// Wait until stacktrace is displayed.
await waitFor(() => !!message.querySelector(".frames"));
is(
message.querySelector(".message-body").textContent,
"console.trace()",
"console.trace message body has expected text"
);
is(
message.querySelector(".message-repeats").textContent,
"3",
"console.trace has the expected content for the repeat badge"
);
is(
message.querySelector(".frame-link-filename").textContent,
"test-console-trace-duplicates.html",
"message frame has expected text content"
);
const [, line, column] = message
.querySelector(".frame-link-line")
.textContent.split(":");
is(line, "20", "message frame has expected line");
is(column, "11", "message frame has expected column");
const stack = message.querySelector(".stacktrace");
ok(!!stack, "There's a stacktrace element");
const frames = Array.from(stack.querySelectorAll(".frame"));
checkStacktraceFrames(frames, [
{
functionName: "foo3",
filename: TEST_URI,
line: 20,
},
{
functionName: "foo2",
filename: TEST_URI,
line: 16,
},
{
functionName: "foo1",
filename: TEST_URI,
line: 12,
},
{
functionName: "<anonymous>",
filename: TEST_URI,
line: 23,
},
]);
});
/**
* Check stack info returned by getStackInfo().
*
* @param {Object} stackInfo
* A stackInfo object returned by getStackInfo().
* @param {Object} expected
* An object in the same format as the expected stackInfo object.
*/
function checkStacktraceFrames(frames, expectedFrames) {
is(
frames.length,
expectedFrames.length,
`There are ${frames.length} frames in the stacktrace`
);
frames.forEach((frameEl, i) => {
const expected = expectedFrames[i];
is(
frameEl.querySelector(".title").textContent,
expected.functionName,
`expected function name is displayed for frame #${i}`
);
is(
frameEl.querySelector(".location .filename").textContent,
expected.filename,
`expected filename is displayed for frame #${i}`
);
is(
frameEl.querySelector(".location .line").textContent,
`${expected.line}`,
`expected line is displayed for frame #${i}`
);
});
}
|