Bug 1413322 Don't load old-style language packs draft
authorAndrew Swan <aswan@mozilla.com>
Tue, 31 Oct 2017 14:23:06 -0700 (2017-10-31)
changeset 693065 0e05795f5c56d1827dbd1257750341304dccb410
parent 688758 a89e5587c7a761fa59b82270b861c7f547968145
child 738940 ff0a57e255a2b64fc1fdaab4e509ebb0e153c905
push id87697
push useraswan@mozilla.com
push dateSat, 04 Nov 2017 02:04:27 +0000 (2017-11-04)
bugs1413322
milestone58.0a1
Bug 1413322 Don't load old-style language packs MozReview-Commit-ID: GnG6UznHFZR
testing/mozbase/mozprofile/tests/addonid.py
toolkit/mozapps/extensions/internal/XPIInstall.jsm
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/addons/test_langpack/chrome.manifest
toolkit/mozapps/extensions/test/addons/test_langpack/install.rdf
toolkit/mozapps/extensions/test/xpcshell/test_langpack.js
toolkit/mozapps/extensions/test/xpcshell/test_legacy.js
toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini
--- a/testing/mozbase/mozprofile/tests/addonid.py
+++ b/testing/mozbase/mozprofile/tests/addonid.py
@@ -152,39 +152,14 @@ class AddonIDTest(unittest.TestCase):
      <foobar:id>winning</foobar:id>
      <foobar:name>MozMill</foobar:name>
      <foobar:version>2.0a</foobar:version>
      <foobar:creator>Adam Christian</foobar:creator>
      <foobar:description>A testing extension based on the
             Windmill Testing Framework client source</foobar:description>
      <foobar:unpack>true</foobar:unpack>
     </Description>
- </RDF>""",
-            """<?xml version="1.0"?>
-<!--
-
--->
-
-<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
-  <Description about="urn:mozilla:install-manifest"
-               em:id="winning"
-               em:name="Language Pack"
-               em:version="42.0a2"
-               em:type="8"
-               em:creator="Some Contributor">
-    <em:contributor></em:contributor>
-
-    <em:targetApplication>
-      <Description>
-        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
-        <em:minVersion>42.0a2</em:minVersion>
-        <em:maxVersion>42.0a2</em:maxVersion>
-      </Description>
-    </em:targetApplication>
-  </Description>
-</RDF>
-"""]
+ </RDF>"""]
         return tests
 
 
 if __name__ == '__main__':
     mozunit.main()
--- a/toolkit/mozapps/extensions/internal/XPIInstall.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIInstall.jsm
@@ -138,38 +138,37 @@ const PREFIX_NS_EM                    = 
 // Properties that exist in the install manifest
 const PROP_METADATA      = ["id", "version", "type", "internalName", "updateURL",
                             "updateKey", "optionsURL", "optionsType", "aboutURL",
                             "iconURL", "icon64URL"];
 const PROP_LOCALE_SINGLE = ["name", "description", "creator", "homepageURL"];
 const PROP_LOCALE_MULTI  = ["developers", "translators", "contributors"];
 const PROP_TARGETAPP     = ["id", "minVersion", "maxVersion"];
 
-// Map new string type identifiers to old style nsIUpdateItem types
-// Type 32 was previously used for multipackage xpi files so it should
-// not be re-used since old files with that type may be floating around.
+// Map new string type identifiers to old style nsIUpdateItem types.
+// Retired values:
+// 32 = multipackage xpi file
+// 8 = locale
 const TYPES = {
   extension: 2,
   theme: 4,
-  locale: 8,
   dictionary: 64,
   experiment: 128,
   apiextension: 256,
 };
 
 const COMPATIBLE_BY_DEFAULT_TYPES = {
   extension: true,
   dictionary: true,
 };
 
 const RESTARTLESS_TYPES = new Set([
   "apiextension",
   "dictionary",
   "experiment",
-  "locale",
   "webextension",
   "webextension-theme",
 ]);
 
 const SIGNED_TYPES = new Set([
   "apiextension",
   "extension",
   "experiment",
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -207,17 +207,16 @@ const TYPE_ALIASES = {
   "apiextension": "extension",
   "webextension": "extension",
   "webextension-theme": "theme",
   "webextension-langpack": "locale",
 };
 
 const CHROME_TYPES = new Set([
   "extension",
-  "locale",
   "experiment",
 ]);
 
 const SIGNED_TYPES = new Set([
   "apiextension",
   "extension",
   "experiment",
   "webextension",
@@ -4188,21 +4187,16 @@ this.XPIProvider = {
       started: false,
     });
 
     // Mark the add-on as active for the crash reporter before loading
     this.addAddonsToCrashReporter();
 
     let activeAddon = this.activeAddons.get(aId);
 
-    // Locales only contain chrome and can't have bootstrap scripts
-    if (aType == "locale") {
-      return;
-    }
-
     logger.debug("Loading bootstrap scope from " + aFile.path);
 
     let principal = Cc["@mozilla.org/systemprincipal;1"].
                     createInstance(Ci.nsIPrincipal);
     if (!aMultiprocessCompatible && Services.prefs.getBoolPref(PREF_INTERPOSITION_ENABLED, false)) {
       let interposition = Cc["@mozilla.org/addons/multiprocess-shims;1"].
         getService(Ci.nsIAddonInterposition);
       Cu.setAddonInterposition(aId, interposition);
@@ -4324,20 +4318,16 @@ this.XPIProvider = {
 
       if (aMethod == "startup" || aMethod == "shutdown") {
         if (!aExtraParams) {
           aExtraParams = {};
         }
         aExtraParams.instanceID = this.activeAddons.get(aAddon.id).instanceID;
       }
 
-      // Nothing to call for locales
-      if (aAddon.type == "locale")
-        return;
-
       let method = undefined;
       let scope = activeAddon.bootstrapScope;
       try {
         method = scope[aMethod] || Cu.evalInSandbox(`${aMethod};`, scope);
       } catch (e) {
         // An exception will be caught if the expected method is not defined.
         // That will be logged below.
       }
deleted file mode 100644
--- a/toolkit/mozapps/extensions/test/addons/test_langpack/chrome.manifest
+++ /dev/null
@@ -1,1 +0,0 @@
-locale test-langpack    x-testing locale/x-testing
deleted file mode 100644
--- a/toolkit/mozapps/extensions/test/addons/test_langpack/install.rdf
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0"?>
-
-<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
-
-  <Description about="urn:mozilla:install-manifest">
-    <em:id>langpack-x-testing@tests.mozilla.org</em:id>
-    <em:type>8</em:type>
-    <em:version>1.0</em:version>
-
-    <!-- Front End MetaData -->
-    <em:name>Language Pack x-testing</em:name>
-
-    <em:targetApplication>
-      <Description>
-        <em:id>xpcshell@tests.mozilla.org</em:id>
-        <em:minVersion>1</em:minVersion>
-        <em:maxVersion>2</em:maxVersion>
-      </Description>
-    </em:targetApplication>
-
-  </Description>
-</RDF>
deleted file mode 100644
--- a/toolkit/mozapps/extensions/test/xpcshell/test_langpack.js
+++ /dev/null
@@ -1,337 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-// This verifies that language packs can be used without restarts.
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-// Enable loading extensions from the user scopes
-Services.prefs.setIntPref("extensions.enabledScopes",
-                          AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER);
-// Enable installing distribution add-ons
-Services.prefs.setBoolPref("extensions.installDistroAddons", true);
-
-createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
-
-const profileDir = gProfD.clone();
-profileDir.append("extensions");
-const userExtDir = gProfD.clone();
-userExtDir.append("extensions2");
-userExtDir.append(gAppInfo.ID);
-registerDirectory("XREUSysExt", userExtDir.parent);
-const distroDir = gProfD.clone();
-distroDir.append("distribution");
-distroDir.append("extensions");
-registerDirectory("XREAppDist", distroDir.parent);
-
-var chrome = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
-  .getService(Components.interfaces.nsIXULChromeRegistry);
-
-function do_unregister_manifest() {
-  let path = getFileForAddon(profileDir, "langpack-x-testing@tests.mozilla.org");
-  Components.manager.removeBootstrappedManifestLocation(path);
-}
-
-function do_check_locale_not_registered(provider) {
-  let didThrow = false;
-  try {
-    chrome.getSelectedLocale(provider);
-  } catch (e) {
-    didThrow = true;
-  }
-  do_check_true(didThrow);
-}
-
-function run_test() {
-  do_test_pending();
-
-  startupManager();
-
-  run_test_1();
-}
-
-// Tests that installing doesn't require a restart
-function run_test_1() {
-  do_check_locale_not_registered("test-langpack");
-
-  prepare_test({ }, [
-    "onNewInstall"
-  ]);
-
-  AddonManager.getInstallForFile(do_get_addon("test_langpack"), function(install) {
-    ensure_test_completed();
-
-    do_check_neq(install, null);
-    do_check_eq(install.type, "locale");
-    do_check_eq(install.version, "1.0");
-    do_check_eq(install.name, "Language Pack x-testing");
-    do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
-    do_check_true(install.addon.hasResource("install.rdf"));
-    do_check_false(install.addon.hasResource("bootstrap.js"));
-    do_check_eq(install.addon.operationsRequiringRestart &
-                AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
-
-    let addon = install.addon;
-    prepare_test({
-      "langpack-x-testing@tests.mozilla.org": [
-        ["onInstalling", false],
-        "onInstalled"
-      ]
-    }, [
-      "onInstallStarted",
-      "onInstallEnded",
-    ], function() {
-      do_check_true(addon.hasResource("install.rdf"));
-      // spin to let the startup complete
-      do_execute_soon(check_test_1);
-    });
-    install.install();
-  });
-}
-
-function check_test_1() {
-  AddonManager.getAllInstalls(function(installs) {
-    // There should be no active installs now since the install completed and
-    // doesn't require a restart.
-    do_check_eq(installs.length, 0);
-
-    AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(b1) {
-      do_check_neq(b1, null);
-      do_check_eq(b1.version, "1.0");
-      do_check_false(b1.appDisabled);
-      do_check_false(b1.userDisabled);
-      do_check_true(b1.isActive);
-      // check chrome reg that language pack is registered
-      do_check_eq(chrome.getSelectedLocale("test-langpack"), "x-testing");
-      do_check_true(b1.hasResource("install.rdf"));
-      do_check_false(b1.hasResource("bootstrap.js"));
-
-      AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
-        do_check_eq(list.length, 0);
-
-        run_test_2();
-      });
-    });
-  });
-}
-
-// Tests that disabling doesn't require a restart
-function run_test_2() {
-  AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(b1) {
-    prepare_test({
-      "langpack-x-testing@tests.mozilla.org": [
-        ["onDisabling", false],
-        "onDisabled"
-      ]
-    });
-
-    do_check_eq(b1.operationsRequiringRestart &
-                AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
-    b1.userDisabled = true;
-    ensure_test_completed();
-
-    do_check_neq(b1, null);
-    do_check_eq(b1.version, "1.0");
-    do_check_false(b1.appDisabled);
-    do_check_true(b1.userDisabled);
-    do_check_false(b1.isActive);
-    // check chrome reg that language pack is not registered
-    do_check_locale_not_registered("test-langpack");
-
-    AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(newb1) {
-      do_check_neq(newb1, null);
-      do_check_eq(newb1.version, "1.0");
-      do_check_false(newb1.appDisabled);
-      do_check_true(newb1.userDisabled);
-      do_check_false(newb1.isActive);
-
-      do_execute_soon(run_test_3);
-    });
-  });
-}
-
-// Test that restarting doesn't accidentally re-enable
-function run_test_3() {
-  shutdownManager();
-  startupManager(false);
-  // check chrome reg that language pack is not registered
-  do_check_locale_not_registered("test-langpack");
-
-  AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(b1) {
-    do_check_neq(b1, null);
-    do_check_eq(b1.version, "1.0");
-    do_check_false(b1.appDisabled);
-    do_check_true(b1.userDisabled);
-    do_check_false(b1.isActive);
-
-    run_test_4();
-  });
-}
-
-// Tests that enabling doesn't require a restart
-function run_test_4() {
-  AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(b1) {
-    prepare_test({
-      "langpack-x-testing@tests.mozilla.org": [
-        ["onEnabling", false],
-        "onEnabled"
-      ]
-    });
-
-    do_check_eq(b1.operationsRequiringRestart &
-                AddonManager.OP_NEEDS_RESTART_ENABLE, 0);
-    b1.userDisabled = false;
-    ensure_test_completed();
-
-    do_check_neq(b1, null);
-    do_check_eq(b1.version, "1.0");
-    do_check_false(b1.appDisabled);
-    do_check_false(b1.userDisabled);
-    do_check_true(b1.isActive);
-    // check chrome reg that language pack is registered
-    do_check_eq(chrome.getSelectedLocale("test-langpack"), "x-testing");
-
-    AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(newb1) {
-      do_check_neq(newb1, null);
-      do_check_eq(newb1.version, "1.0");
-      do_check_false(newb1.appDisabled);
-      do_check_false(newb1.userDisabled);
-      do_check_true(newb1.isActive);
-
-      do_execute_soon(run_test_5);
-    });
-  });
-}
-
-// Tests that a restart shuts down and restarts the add-on
-function run_test_5() {
-  shutdownManager();
-  do_unregister_manifest();
-  // check chrome reg that language pack is not registered
-  do_check_locale_not_registered("test-langpack");
-  startupManager(false);
-  // check chrome reg that language pack is registered
-  do_check_eq(chrome.getSelectedLocale("test-langpack"), "x-testing");
-
-  AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(b1) {
-    do_check_neq(b1, null);
-    do_check_eq(b1.version, "1.0");
-    do_check_false(b1.appDisabled);
-    do_check_false(b1.userDisabled);
-    do_check_true(b1.isActive);
-    do_check_false(isExtensionInAddonsList(profileDir, b1.id));
-
-    run_test_7();
-  });
-}
-
-// Tests that uninstalling doesn't require a restart
-function run_test_7() {
-  AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(b1) {
-    prepare_test({
-      "langpack-x-testing@tests.mozilla.org": [
-        ["onUninstalling", false],
-        "onUninstalled"
-      ]
-    });
-
-    do_check_eq(b1.operationsRequiringRestart &
-                AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
-    b1.uninstall();
-
-    check_test_7();
-  });
-}
-
-function check_test_7() {
-  ensure_test_completed();
-  // check chrome reg that language pack is not registered
-  do_check_locale_not_registered("test-langpack");
-
-  AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org",
-   callback_soon(function(b1) {
-    do_check_eq(b1, null);
-
-    restartManager();
-
-    AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(newb1) {
-      do_check_eq(newb1, null);
-
-      do_execute_soon(run_test_8);
-    });
-  }));
-}
-
-// Tests that a locale detected in the profile starts working immediately
-function run_test_8() {
-  shutdownManager();
-
-  manuallyInstall(do_get_addon("test_langpack"), profileDir, "langpack-x-testing@tests.mozilla.org");
-
-  startupManager(false);
-
-  AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org",
-   callback_soon(function(b1) {
-    do_check_neq(b1, null);
-    do_check_eq(b1.version, "1.0");
-    do_check_false(b1.appDisabled);
-    do_check_false(b1.userDisabled);
-    do_check_true(b1.isActive);
-    // check chrome reg that language pack is registered
-    do_check_eq(chrome.getSelectedLocale("test-langpack"), "x-testing");
-    do_check_true(b1.hasResource("install.rdf"));
-    do_check_false(b1.hasResource("bootstrap.js"));
-
-    shutdownManager();
-    do_unregister_manifest();
-    // check chrome reg that language pack is not registered
-    do_check_locale_not_registered("test-langpack");
-    startupManager(false);
-    // check chrome reg that language pack is registered
-    do_check_eq(chrome.getSelectedLocale("test-langpack"), "x-testing");
-
-    AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", function(b2) {
-      prepare_test({
-        "langpack-x-testing@tests.mozilla.org": [
-          ["onUninstalling", false],
-          "onUninstalled"
-        ]
-      });
-
-      b2.uninstall();
-      ensure_test_completed();
-      do_execute_soon(run_test_9);
-    });
-  }));
-}
-
-// Tests that a locale from distribution/extensions gets installed and starts
-// working immediately
-function run_test_9() {
-  shutdownManager();
-  manuallyInstall(do_get_addon("test_langpack"), distroDir, "langpack-x-testing@tests.mozilla.org");
-  gAppInfo.version = "2.0";
-  startupManager(true);
-
-  AddonManager.getAddonByID("langpack-x-testing@tests.mozilla.org", callback_soon(function(b1) {
-    do_check_neq(b1, null);
-    do_check_eq(b1.version, "1.0");
-    do_check_false(b1.appDisabled);
-    do_check_false(b1.userDisabled);
-    do_check_true(b1.isActive);
-    // check chrome reg that language pack is registered
-    do_check_eq(chrome.getSelectedLocale("test-langpack"), "x-testing");
-    do_check_true(b1.hasResource("install.rdf"));
-    do_check_false(b1.hasResource("bootstrap.js"));
-
-    shutdownManager();
-    do_unregister_manifest();
-    // check chrome reg that language pack is not registered
-    do_check_locale_not_registered("test-langpack");
-    startupManager(false);
-    // check chrome reg that language pack is registered
-    do_check_eq(chrome.getSelectedLocale("test-langpack"), "x-testing");
-
-    do_test_finished();
-  }));
-}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_legacy.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_legacy.js
@@ -38,22 +38,16 @@ add_task(async function test_disable() {
     {
       id: "privileged@tests.mozilla.org",
       name: "Privileged Bootstrap add-on",
       version: "1.0",
       bootstrap: true,
       multiprocessCompatible: true,
     },
     {
-      id: "langpack@tests.mozilla.org",
-      name: "Test Langpack",
-      version: "1.0",
-      type: "8",
-    },
-    {
       id: "dictionary@tests.mozilla.org",
       name: "Test Dictionary",
       version: "1.0",
       type: "64",
     }
   ];
 
   function makeXPI(info) {
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini
@@ -169,17 +169,16 @@ tags = blocklist
 [test_ChromeManifestParser.js]
 [test_compatoverrides.js]
 [test_corrupt.js]
 [test_corrupt_strictcompat.js]
 [test_corruptfile.js]
 [test_dataDirectory.js]
 [test_default_providers_pref.js]
 [test_dictionary.js]
-[test_langpack.js]
 [test_disable.js]
 [test_distribution.js]
 [test_duplicateplugins.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 [test_error.js]
 [test_experiment.js]
 [test_filepointer.js]