Bug 1464755: Get rid of unused getAddonByInstanceID method. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 27 May 2018 22:57:49 -0700
changeset 800449 c16c83d678a6845e7a75853d228cd1d3226c4050
parent 800448 978eebcc14ee7842cfbd31152d59d63301525657
push id111357
push usermaglione.k@gmail.com
push dateMon, 28 May 2018 05:58:47 +0000
reviewersaswan
bugs1464755
milestone62.0a1
Bug 1464755: Get rid of unused getAddonByInstanceID method. r?aswan MozReview-Commit-ID: JOBUROgOdVU
toolkit/mozapps/extensions/AddonManager.jsm
toolkit/mozapps/extensions/internal/XPIDatabase.jsm
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_pass_symbol.js
toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -2049,43 +2049,16 @@ var AddonManagerInternal = {
     if (!(aFile instanceof Ci.nsIFile))
       throw Components.Exception("aFile must be a nsIFile",
                                  Cr.NS_ERROR_INVALID_ARG);
 
     return AddonManagerInternal._getProviderByName("XPIProvider")
                                .installTemporaryAddon(aFile);
   },
 
-  /**
-   * Returns an Addon corresponding to an instance ID.
-   * @param aInstanceID
-   *        An Addon Instance ID symbol
-   * @return {Promise}
-   * @resolves The found Addon or null if no such add-on exists.
-   * @rejects  Never
-   * @throws if the aInstanceID argument is not specified
-   *         or the AddonManager is not initialized
-   */
-   async getAddonByInstanceID(aInstanceID) {
-     return this.syncGetAddonByInstanceID(aInstanceID);
-   },
-
-   syncGetAddonByInstanceID(aInstanceID) {
-     if (!gStarted)
-       throw Components.Exception("AddonManager is not initialized",
-                                  Cr.NS_ERROR_NOT_INITIALIZED);
-
-     if (!aInstanceID || typeof aInstanceID != "symbol")
-       throw Components.Exception("aInstanceID must be a Symbol()",
-                                  Cr.NS_ERROR_INVALID_ARG);
-
-     return AddonManagerInternal._getProviderByName("XPIProvider")
-                                .getAddonByInstanceID(aInstanceID);
-   },
-
    syncGetAddonIDByInstanceID(aInstanceID) {
      if (!gStarted)
        throw Components.Exception("AddonManager is not initialized",
                                   Cr.NS_ERROR_NOT_INITIALIZED);
 
      if (!aInstanceID || typeof aInstanceID != "symbol")
        throw Components.Exception("aInstanceID must be a Symbol()",
                                   Cr.NS_ERROR_INVALID_ARG);
@@ -3384,20 +3357,16 @@ var AddonManager = {
   installAddonFromAOM(aBrowser, aUri, aInstall) {
     AddonManagerInternal.installAddonFromAOM(aBrowser, aUri, aInstall);
   },
 
   installTemporaryAddon(aDirectory) {
     return AddonManagerInternal.installTemporaryAddon(aDirectory);
   },
 
-  getAddonByInstanceID(aInstanceID) {
-    return AddonManagerInternal.getAddonByInstanceID(aInstanceID);
-  },
-
   addManagerListener(aListener) {
     AddonManagerInternal.addManagerListener(aListener);
   },
 
   removeManagerListener(aListener) {
     AddonManagerInternal.removeManagerListener(aListener);
   },
 
--- a/toolkit/mozapps/extensions/internal/XPIDatabase.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIDatabase.jsm
@@ -1676,20 +1676,16 @@ this.XPIDatabase = {
     return this.asyncLoadDB()
       .then(addonDB => getRepositoryAddon(_findAddon(addonDB, aFilter)))
       .catch(
         error => {
           logger.error("getAddon failed", error);
         });
   },
 
-  syncGetAddon(aFilter) {
-    return _findAddon(this.addonDB, aFilter);
-  },
-
   /**
    * Asynchronously gets an add-on with a particular ID in a particular
    * install location.
    *
    * @param {string} aId
    *        The ID of the add-on to retrieve
    * @param {string} aLocation
    *        The name of the install location
@@ -1717,20 +1713,16 @@ this.XPIDatabase = {
    * @param {string} aId
    *        The ID of the add-on to retrieve
    * @returns {Promise<AddonInternal?>}
    */
   getVisibleAddonForID(aId) {
     return this.getAddon(aAddon => ((aAddon.id == aId) && aAddon.visible));
   },
 
-  syncGetVisibleAddonForID(aId) {
-    return this.syncGetAddon(aAddon => ((aAddon.id == aId) && aAddon.visible));
-  },
-
   /**
    * Asynchronously gets the visible add-ons, optionally restricting by type.
    *
    * @param {Set<string>?} aTypes
    *        An array of types to include or null to include all types
    * @returns {Promise<Array<AddonInternal>>}
    */
   getVisibleAddons(aTypes) {
@@ -1796,36 +1788,16 @@ this.XPIDatabase = {
    * @returns {Addon?}
    */
   async getAddonByID(aId) {
     let aAddon = await this.getVisibleAddonForID(aId);
     return aAddon ? aAddon.wrapper : null;
   },
 
   /**
-   * Synchronously returns the Addon object for the add-on with the
-   * given ID.
-   *
-   * *DO NOT USE THIS IF YOU CAN AT ALL AVOID IT*
-   *
-   * This will always return null if the add-on database has not been
-   * loaded, and the resulting Addon object may not yet include a
-   * reference to its corresponding repository add-on object.
-   *
-   * @param {string} aId
-   *        The ID of the add-on to return.
-   * @returns {DBAddonInternal?}
-   *        The Addon object, if available.
-   */
-  syncGetAddonByID(aId) {
-    let aAddon = this.syncGetVisibleAddonForID(aId);
-    return aAddon ? aAddon.wrapper : null;
-  },
-
-  /**
    * Obtain an Addon having the specified Sync GUID.
    *
    * @param {string} aGUID
    *        String GUID of add-on to retrieve
    * @returns {Addon?}
    */
   async getAddonBySyncGUID(aGUID) {
     let addon = await this.getAddon(aAddon => aAddon.syncGUID == aGUID);
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -2600,35 +2600,16 @@ var XPIProvider = {
    *        The data to store.  Must be JSON serializable.
    */
   setStartupData(aID, aData) {
     let state = XPIStates.findAddon(aID);
     state.startupData = aData;
     XPIStates.save();
   },
 
-  /**
-   * Returns an Addon corresponding to an instance ID.
-   *
-   * @param {Symbol} aInstanceID
-   *        An Addon Instance ID
-   *
-   * @returns {AddonInternal?}
-   *
-   * @throws if the aInstanceID argument is not valid.
-   */
-   getAddonByInstanceID(aInstanceID) {
-     let id = this.getAddonIDByInstanceID(aInstanceID);
-     if (id) {
-       return XPIDatabase.syncGetAddonByID(id);
-     }
-
-     return null;
-   },
-
    getAddonIDByInstanceID(aInstanceID) {
      if (!aInstanceID || typeof aInstanceID != "symbol")
        throw Components.Exception("aInstanceID must be a Symbol()",
                                   Cr.NS_ERROR_INVALID_ARG);
 
      for (let [id, val] of this.activeAddons) {
        if (aInstanceID == val.instanceID) {
          return id;
deleted file mode 100644
--- a/toolkit/mozapps/extensions/test/xpcshell/test_pass_symbol.js
+++ /dev/null
@@ -1,116 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-const PASS_PREF = "symboltest.instanceid.pass";
-const FAIL_BOGUS_PREF = "symboltest.instanceid.fail_bogus";
-const FAIL_ID_PREF = "symboltest.instanceid.fail_bogus";
-const ADDON_ID = "test_symbol@tests.mozilla.org";
-
-createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
-
-BootstrapMonitor.init();
-
-const ADDONS = {
-  test_symbol: {
-    "install.rdf": {
-      "id": "test_symbol@tests.mozilla.org",
-      "name": "Test Symbol",
-    },
-    "bootstrap.js": String.raw`ChromeUtils.import("resource://gre/modules/Services.jsm");
-ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
-
-const PASS_PREF = "symboltest.instanceid.pass";
-const FAIL_BOGUS_PREF = "symboltest.instanceid.fail_bogus";
-const FAIL_ID_PREF = "symboltest.instanceid.fail_bogus";
-const ADDON_ID = "test_symbol@tests.mozilla.org";
-
-// normally we would use BootstrapMonitor here, but we need a reference to
-// the symbol inside XPIProvider.jsm.
-function startup(data, reason) {
-  Services.prefs.setBoolPref(PASS_PREF, false);
-  Services.prefs.setBoolPref(FAIL_BOGUS_PREF, false);
-  Services.prefs.setBoolPref(FAIL_ID_PREF, false);
-
-  // test with the correct symbol
-  if (data.hasOwnProperty("instanceID") && data.instanceID) {
-    AddonManager.getAddonByInstanceID(data.instanceID)
-      .then(addon => {
-        if (addon.id == ADDON_ID) {
-          Services.prefs.setBoolPref(PASS_PREF, true);
-        }
-      }).catch(err => {
-        throw Error("no addon found for symbol");
-      });
-
-  }
-
-  // test with a totally bogus symbol
-  AddonManager.getAddonByInstanceID(Symbol("bad symbol"))
-    .then(addon => {
-      // there is no symbol by this name, so null should be returned
-      if (addon == null) {
-        Services.prefs.setBoolPref(FAIL_BOGUS_PREF, true);
-      } else {
-        throw Error("bad symbol should not match:", addon);
-      }
-    }).catch(err => {
-      throw Error("promise should not have rejected: " + err);
-    });
-
-  // try to make a matching symbol - this should fail because it's not a
-  // reference to the same symbol stored inside the addons manager.
-  AddonManager.getAddonByInstanceID(Symbol(ADDON_ID))
-    .then(addon => {
-      // there is no symbol by this name, so null should be returned
-      if (addon == null) {
-        Services.prefs.setBoolPref(FAIL_ID_PREF, true);
-      } else {
-        throw Error("bad symbol should not match:", addon);
-      }
-    }).catch(err => {
-      throw Error("promise should not have rejected: " + err);
-    });
-
-}
-
-function install(data, reason) {}
-function shutdown(data, reason) {}
-function uninstall(data, reason) {}
-`,
-  },
-};
-
-// symbol is passed when add-on is installed
-add_task(async function() {
-  await promiseStartupManager();
-
-  PromiseTestUtils.expectUncaughtRejection(/no addon found for symbol/);
-
-  for (let pref of [PASS_PREF, FAIL_BOGUS_PREF, FAIL_ID_PREF])
-    Services.prefs.clearUserPref(pref);
-
-  await AddonTestUtils.promiseInstallXPI(ADDONS.test_symbol);
-
-  let addon = await promiseAddonByID(ADDON_ID);
-
-  Assert.notEqual(addon, null);
-  Assert.equal(addon.version, "1.0");
-  Assert.equal(addon.name, "Test Symbol");
-  Assert.ok(addon.isCompatible);
-  Assert.ok(!addon.appDisabled);
-  Assert.ok(addon.isActive);
-  Assert.equal(addon.type, "extension");
-
-  // most of the test is in bootstrap.js in the addon because BootstrapMonitor
-  // currently requires the objects in `data` to be serializable, and we
-  // need a real reference to the symbol to test this.
-  executeSoon(function() {
-    // give the startup time to run
-    Assert.ok(Services.prefs.getBoolPref(PASS_PREF));
-    Assert.ok(Services.prefs.getBoolPref(FAIL_BOGUS_PREF));
-    Assert.ok(Services.prefs.getBoolPref(FAIL_ID_PREF));
-  });
-
-  await promiseRestartManager();
-});
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
@@ -156,17 +156,16 @@ skip-if = !allow_legacy_extensions || ap
 skip-if = os == "android"
 [test_moved_extension_metadata.js]
 [test_no_addons.js]
 [test_nodisable_hidden.js]
 [test_onPropertyChanged_appDisabled.js]
 [test_overrideblocklist.js]
 run-sequentially = Uses global XCurProcD dir.
 tags = blocklist
-[test_pass_symbol.js]
 [test_permissions.js]
 [test_permissions_prefs.js]
 [test_pluginBlocklistCtp.js]
 # Bug 676992: test consistently fails on Android
 fail-if = os == "android"
 tags = blocklist
 [test_pluginInfoURL.js]
 tags = blocklist