1
0
Fork 0
firefox/services/fxaccounts/tests/xpcshell/test_browser_lifetime.js
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

49 lines
1.5 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { XPCShellContentUtils } = ChromeUtils.importESModule(
"resource://testing-common/XPCShellContentUtils.sys.mjs"
);
XPCShellContentUtils.ensureInitialized(this);
const server = XPCShellContentUtils.createHttpServer({
hosts: ["example.com"],
});
server.registerPathHandler("/dummy", (request, response) => {
response.setStatusLine(request.httpVersion, 200, "OK");
response.write("ok");
});
add_task(async function () {
const { FxAccountsPairingChannel } = ChromeUtils.importESModule(
"resource://gre/modules/FxAccountsPairingChannel.sys.mjs"
);
// Collect the module top-level variables and the pointed objects.
for (let i = 0; i < 100; i++) {
Cu.forceGC();
Cu.forceCC();
await new Promise(resolve => executeSoon(resolve));
}
let caught = false;
try {
// The windowless browser in FxAccountsPairingChannel.sys.mjs should still
// be alive, and the `new WebSocket(...)` call inside it shouldn't hit the
// dead object error.
//
// NOTE: The connection itself will hit error.
await FxAccountsPairingChannel._makePairingChannel(
"ws://example.com/dummy"
);
} catch (e) {
caught = true;
Assert.notEqual(
e.message,
"can't access dead object",
"Touching the windowless browser after GC/CC should not hit dead object"
);
}
Assert.ok(caught, "Exception should be caught for connection");
});