summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_validate_manifests.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/search/tests/xpcshell/test_validate_manifests.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.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/components/search/tests/xpcshell/test_validate_manifests.js')
-rw-r--r--toolkit/components/search/tests/xpcshell/test_validate_manifests.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/toolkit/components/search/tests/xpcshell/test_validate_manifests.js b/toolkit/components/search/tests/xpcshell/test_validate_manifests.js
new file mode 100644
index 0000000000..c840009ab6
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_validate_manifests.js
@@ -0,0 +1,64 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Cu.importGlobalProperties(["fetch"]);
+
+const { ExtensionData } = ChromeUtils.importESModule(
+ "resource://gre/modules/Extension.sys.mjs"
+);
+
+const SEARCH_EXTENSIONS_PATH = "resource://search-extensions";
+
+function getFileURI(resourceURI) {
+ let resHandler = Services.io
+ .getProtocolHandler("resource")
+ .QueryInterface(Ci.nsIResProtocolHandler);
+ let filePath = resHandler.resolveURI(Services.io.newURI(resourceURI));
+ return Services.io.newURI(filePath);
+}
+
+async function getSearchExtensions() {
+ // Fetching the root will give us the directory listing which we can parse
+ // for each file name
+ let list = await fetch(`${SEARCH_EXTENSIONS_PATH}/`).then(req => req.text());
+ return list
+ .split("\n")
+ .slice(2)
+ .reduce((acc, line) => {
+ let parts = line.split(" ");
+ if (parts.length > 2 && !parts[1].endsWith(".json")) {
+ // When the directory listing comes from omni jar each engine
+ // has a trailing slash (engine/) which we dont get locally, or want.
+ acc.push(parts[1].split("/")[0]);
+ }
+ return acc;
+ }, []);
+}
+
+add_task(async function test_validate_manifest() {
+ let searchExtensions = await getSearchExtensions();
+ ok(
+ !!searchExtensions.length,
+ `Found ${searchExtensions.length} search extensions`
+ );
+ for (const xpi of searchExtensions) {
+ info(`loading: ${SEARCH_EXTENSIONS_PATH}/${xpi}/`);
+ let fileURI = getFileURI(`${SEARCH_EXTENSIONS_PATH}/${xpi}/`);
+ let extension = new ExtensionData(fileURI, false);
+ await extension.loadManifest();
+ let locales = await extension.promiseLocales();
+ for (let locale of locales.keys()) {
+ try {
+ let manifest = await extension.getLocalizedManifest(locale);
+ ok(!!manifest, `parsed manifest ${xpi.leafName} in ${locale}`);
+ } catch (e) {
+ ok(
+ false,
+ `FAIL manifest for ${xpi.leafName} in locale ${locale} failed ${e} :: ${e.stack}`
+ );
+ }
+ }
+ }
+});