commit 1f0813b5a9fe5b31afaf2adc2bc3d036592c23b8
parent 2bb28c0e6805312a443420d99b822fb21b3e3070
Author: Lorenz A <me@lorenzackermann.xyz>
Date: Mon, 8 Dec 2025 16:26:41 +0000
Bug 2004212 - [devtools] Turn devtools/shared/protocol/tests/xpcshell/head.js into an ES class. r=devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D275473
Diffstat:
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/devtools/shared/protocol/tests/xpcshell/head.js b/devtools/shared/protocol/tests/xpcshell/head.js
@@ -25,17 +25,16 @@ function connectPipeTracing() {
* Mock the `Transport` class in order to intercept all the packet
* getting in and out and then being able to assert them and dump them.
*/
-function TracingTransport(childTransport) {
- this.hooks = null;
- this.child = childTransport;
- this.child.hooks = this;
+class TracingTransport {
+ constructor(childTransport) {
+ this.hooks = null;
+ this.child = childTransport;
+ this.child.hooks = this;
- this.expectations = [];
- this.packets = [];
- this.checkIndex = 0;
-}
-
-TracingTransport.prototype = {
+ this.expectations = [];
+ this.packets = [];
+ this.checkIndex = 0;
+ }
// Remove actor names
normalize(packet) {
return JSON.parse(
@@ -46,44 +45,44 @@ TracingTransport.prototype = {
return value;
})
);
- },
+ }
send(packet) {
this.packets.push({
type: "sent",
packet: this.normalize(packet),
});
return this.child.send(packet);
- },
+ }
close() {
return this.child.close();
- },
+ }
ready() {
return this.child.ready();
- },
+ }
onPacket(packet) {
this.packets.push({
type: "received",
packet: this.normalize(packet),
});
this.hooks.onPacket(packet);
- },
+ }
onTransportClosed() {
if (this.hooks.onTransportClosed) {
this.hooks.onTransportClosed();
}
- },
+ }
expectSend(expected) {
const packet = this.packets[this.checkIndex++];
Assert.equal(packet.type, "sent");
deepEqual(packet.packet, this.normalize(expected));
- },
+ }
expectReceive(expected) {
const packet = this.packets[this.checkIndex++];
Assert.equal(packet.type, "received");
deepEqual(packet.packet, this.normalize(expected));
- },
+ }
// Write your tests, call dumpLog at the end, inspect the output,
// then sprinkle the calls through the right places in your test.
@@ -95,5 +94,5 @@ TracingTransport.prototype = {
dumpn("trace.expectReceive(" + entry.packet + ");");
}
}
- },
-};
+ }
+}