diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/mozapps/extensions/test/xpcshell/test_shutdown_early.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_shutdown_early.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_shutdown_early.js b/toolkit/mozapps/extensions/test/xpcshell/test_shutdown_early.js new file mode 100644 index 0000000000..2af6d42365 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_shutdown_early.js @@ -0,0 +1,62 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ +"use strict"; + +const { TelemetryEnvironment } = ChromeUtils.importESModule( + "resource://gre/modules/TelemetryEnvironment.sys.mjs" +); + +// Regression test for bug 1665568: verifies that AddonManager unblocks shutdown +// when startup is interrupted very early. +add_task(async function test_shutdown_immediately_after_startup() { + // Set as migrated to prevent sync DB load at startup. + Services.prefs.setCharPref("extensions.lastAppVersion", "42"); + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "42"); + + Cc["@mozilla.org/addons/integration;1"] + .getService(Ci.nsIObserver) + .observe(null, "addons-startup", null); + + // Above, we have configured the runtime to avoid a forced synchronous load + // of the database. Confirm that this is indeed the case. + equal(AddonManagerPrivate.isDBLoaded(), false, "DB not loaded synchronously"); + + let shutdownCount = 0; + AddonManager.beforeShutdown.addBlocker("count", async () => ++shutdownCount); + + let databaseLoaded = false; + AddonManagerPrivate.databaseReady.then(() => { + databaseLoaded = true; + }); + + // Accessing TelemetryEnvironment.currentEnvironment triggers initialization + // of TelemetryEnvironment / EnvironmentAddonBuilder, which registers a + // shutdown blocker. + equal( + TelemetryEnvironment.currentEnvironment.addons, + undefined, + "TelemetryEnvironment.currentEnvironment.addons is uninitialized" + ); + + info("Immediate exit at startup, without quit-application-granted"); + Services.startup.advanceShutdownPhase( + Services.startup.SHUTDOWN_PHASE_APPSHUTDOWN + ); + let shutdownPromise = MockAsyncShutdown.profileBeforeChange.trigger(); + equal(shutdownCount, 1, "AddonManager.beforeShutdown has started"); + + // Note: Until now everything ran in the same tick of the event loop. + + // Waiting for AddonManager to have shut down. + await shutdownPromise; + + ok(databaseLoaded, "Addon DB loaded for use by TelemetryEnvironment"); + equal(AddonManagerPrivate.isDBLoaded(), false, "DB unloaded after shutdown"); + + Assert.deepEqual( + TelemetryEnvironment.currentEnvironment.addons.activeAddons, + {}, + "TelemetryEnvironment.currentEnvironment.addons is initialized" + ); +}); |