Bug 1486820 - Part 2: Add tests to ensure valid manifest. r=rpl
authorDale Harvey <dale@arandomurl.com>
Thu, 11 Apr 2019 20:48:22 +0000
changeset 469098 041d3ca2a427f411d361ce55d6398bf749944cae
parent 469097 111b88dd28d6af3ba647b025d1fa25b502020385
child 469099 7efb082cc25d1a58fe343055982b1459b2f9e1ee
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1486820
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1486820 - Part 2: Add tests to ensure valid manifest. r=rpl Differential Revision: https://phabricator.services.mozilla.com/D25381
toolkit/components/search/tests/xpcshell/test_validate_manifests.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_validate_manifests.js
@@ -0,0 +1,53 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Cu.importGlobalProperties(["fetch"]);
+
+const {ExtensionData} = ChromeUtils.import("resource://gre/modules/Extension.jsm");
+const {ExtensionPermissions} = ChromeUtils.import("resource://gre/modules/ExtensionPermissions.jsm");
+
+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] !== "list.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 > 0, `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);
+    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}`);
+      }
+    }
+  }
+});
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -86,8 +86,9 @@ skip-if = (verify && !debug && (os == 'l
 [test_addEngineWithDetailsObject.js]
 [test_addEngineWithExtensionID.js]
 [test_chromeresource_icon1.js]
 [test_chromeresource_icon2.js]
 [test_engineUpdate.js]
 [test_paramSubstitution.js]
 [test_migrateWebExtensionEngine.js]
 [test_sendSubmissionURL.js]
+[test_validate_manifests.js]