summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_shutdown_early.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_shutdown_early.js')
-rw-r--r--toolkit/mozapps/extensions/test/xpcshell/test_shutdown_early.js62
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"
+ );
+});