Files
Alexandre Poirot 7610af1774 Bug 2064424 - [devtools] Always use CommandsFactory helpers to instantiate local DevToolsClient's. r=devtools-reviewers,nchevobbe
This helps share the logic to create the DevToolsServer
and better highlights tab-debugger client (createLocalClientForTests)
versus browser-toolbox-debugger client (spawnClientToDebugSystemPrincipal).

Differential Revision: https://phabricator.services.mozilla.com/D319532
2026-08-24 18:50:34 +00:00

54 lines
1.3 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// DevToolsClient tests
add_task(async function () {
await testCloseLoops();
await fakeTransportShutdown();
});
// Ensure that closing the client while it is closing doesn't loop
async function testCloseLoops() {
const client = await createLocalClientForTests();
await new Promise(resolve => {
let called = false;
client.on("closed", async () => {
dump(">> CLOSED\n");
if (called) {
ok(
false,
"Calling client.close from closed event listener introduce loops"
);
return;
}
called = true;
await client.close();
resolve();
});
client.close();
});
}
// Check that, if we fake a transport shutdown (like if a device is unplugged)
// the client is automatically closed, and we can still call client.close.
async function fakeTransportShutdown() {
const client = await createLocalClientForTests();
await new Promise(resolve => {
const onClosed = async function () {
client.off("closed", onClosed);
ok(true, "Client emitted 'closed' event");
resolve();
};
client.on("closed", onClosed);
client.transport.close();
});
await client.close();
ok(true, "client.close() successfully resolves");
}