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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/* 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 basic pretty-printing functionality.
"use strict";
requestLongerTimeout(2);
add_task(async function () {
const dbg = await initDebugger("doc-minified.html", "math.min.js");
await selectSource(dbg, "math.min.js", 2);
clickElement(dbg, "prettyPrintButton");
await waitForSelectedSource(dbg, "math.min.js:formatted");
ok(
!findElement(dbg, "mappedSourceLink"),
"When we are on the pretty printed source, we don't show the link to the minified source"
);
const ppSrc = findSource(dbg, "math.min.js:formatted");
ok(ppSrc, "Pretty-printed source exists");
// this is not implemented yet
// assertHighlightLocation(dbg, "math.min.js:formatted", 18);
// await selectSource(dbg, "math.min.js")
await addBreakpoint(dbg, ppSrc, 18);
invokeInTab("arithmetic");
await waitForPaused(dbg);
assertPausedAtSourceAndLine(dbg, ppSrc.id, 18);
await stepOver(dbg);
assertPausedAtSourceAndLine(dbg, ppSrc.id, 39);
await resume(dbg);
// The pretty-print button should be disabled in the pretty-printed source.
ok(
findElement(dbg, "prettyPrintButton").disabled,
"Pretty Print Button should be disabled"
);
await selectSource(dbg, "math.min.js");
await waitForSelectedSource(dbg, "math.min.js");
ok(
!findElement(dbg, "mappedSourceLink"),
"When we are on the minified source, we don't show the link to the pretty printed source"
);
ok(
!findElement(dbg, "prettyPrintButton").disabled,
"Pretty Print Button should be enabled"
);
});
add_task(async function testPrivateFields() {
// Create a source containing a class with private fields
const httpServer = createTestHTTPServer();
httpServer.registerContentType("html", "text/html");
httpServer.registerContentType("js", "application/javascript");
httpServer.registerPathHandler(`/`, function (request, response) {
response.setStatusLine(request.httpVersion, 200, "OK");
response.write(`
<html>
Test pretty-printing class with private fields
<script type="text/javascript" src="class-with-private-fields.js"></script>
</html>`);
});
httpServer.registerPathHandler(
"/class-with-private-fields.js",
function (request, response) {
response.setHeader("Content-Type", "application/javascript");
response.write(`
class MyClass {
constructor(a) {
this.#a = a;this.#b = Math.random();this.ab = this.#getAB();
}
#a
#b = "default value"
static #someStaticPrivate
#getA() {
return this.#a;
}
#getAB() {
return this.#getA()+this.
#b
}
}
`);
}
);
const port = httpServer.identity.primaryPort;
const TEST_URL = `http://localhost:${port}/`;
info("Open toolbox");
const dbg = await initDebuggerWithAbsoluteURL(TEST_URL);
info("Select script with private fields");
await selectSource(dbg, "class-with-private-fields.js", 2);
info("Pretty print the script");
clickElement(dbg, "prettyPrintButton");
info("Wait until the script is pretty-printed");
await waitForSelectedSource(dbg, "class-with-private-fields.js:formatted");
info("Check that the script was pretty-printed as expected");
const prettyPrintedSource = await findSourceContent(
dbg,
"class-with-private-fields.js:formatted"
);
is(
prettyPrintedSource.value.trim(),
`
class MyClass {
constructor(a) {
this.#a = a;
this.#b = Math.random();
this.ab = this.#getAB();
}
#a
#b = 'default value'
static #someStaticPrivate
#getA() {
return this.#a;
}
#getAB() {
return this.#getA() + this.#b
}
}
`.trim(),
"script was pretty printed as expected"
);
});
|