summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
commit9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
parentInitial commit. (diff)
downloadthunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz
thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.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 'toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js')
-rw-r--r--toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js b/toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
new file mode 100644
index 0000000000..f6039b29bf
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_cacheflush.js
@@ -0,0 +1,86 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// This verifies that flushing the zipreader cache happens when appropriate
+
+var gExpectedFile = null;
+var gCacheFlushCount = 0;
+
+var CacheFlushObserver = {
+ observe(aSubject, aTopic, aData) {
+ if (aTopic != "flush-cache-entry") {
+ return;
+ }
+
+ // Ignore flushes from the fake cert DB or extension-process-script
+ if (aData == "cert-override" || aSubject == null) {
+ return;
+ }
+
+ if (!gExpectedFile) {
+ return;
+ }
+ ok(aSubject instanceof Ci.nsIFile);
+ equal(aSubject.path, gExpectedFile.path);
+ gCacheFlushCount++;
+ },
+};
+
+add_task(async function setup() {
+ Services.obs.addObserver(CacheFlushObserver, "flush-cache-entry");
+ createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2");
+
+ await promiseStartupManager();
+});
+
+// Tests that the cache is flushed when installing a restartless add-on
+add_task(async function test_flush_restartless_install() {
+ let xpi = await createTempWebExtensionFile({
+ manifest: {
+ name: "Cache Flush Test",
+ version: "2.0",
+ browser_specific_settings: { gecko: { id: "addon2@tests.mozilla.org" } },
+ },
+ });
+
+ let install = await AddonManager.getInstallForFile(xpi);
+
+ await new Promise(resolve => {
+ install.addListener({
+ onInstallStarted() {
+ // We should flush the staged XPI when completing the install
+ gExpectedFile = gProfD.clone();
+ gExpectedFile.append("extensions");
+ gExpectedFile.append("staged");
+ gExpectedFile.append("addon2@tests.mozilla.org.xpi");
+ },
+
+ onInstallEnded() {
+ equal(gCacheFlushCount, 1);
+ gExpectedFile = null;
+ gCacheFlushCount = 0;
+
+ resolve();
+ },
+ });
+
+ install.install();
+ });
+});
+
+// Tests that the cache is flushed when uninstalling a restartless add-on
+add_task(async function test_flush_uninstall() {
+ let addon = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
+
+ // We should flush the installed XPI when uninstalling
+ gExpectedFile = gProfD.clone();
+ gExpectedFile.append("extensions");
+ gExpectedFile.append("addon2@tests.mozilla.org.xpi");
+
+ await addon.uninstall();
+
+ ok(gCacheFlushCount >= 1);
+ gExpectedFile = null;
+ gCacheFlushCount = 0;
+});