diff --git a/addon-sdk/source/test/addons/jetpack-addon.ini b/addon-sdk/source/test/addons/jetpack-addon.ini index e8f39710e19..7ef5a27a1e1 100644 --- a/addon-sdk/source/test/addons/jetpack-addon.ini +++ b/addon-sdk/source/test/addons/jetpack-addon.ini @@ -42,5 +42,4 @@ skip-if = true [tab-close-on-startup.xpi] [toolkit-require-reload.xpi] [translators.xpi] -[unpacked.xpi] [unsafe-content-script.xpi] diff --git a/addon-sdk/source/test/addons/main/main.js b/addon-sdk/source/test/addons/main/main.js index 66e185bc84b..6cab5d00542 100644 --- a/addon-sdk/source/test/addons/main/main.js +++ b/addon-sdk/source/test/addons/main/main.js @@ -17,7 +17,9 @@ exports.main = function main(options, callbacks) { assert.ok('loadReason' in options, 'loadReason is in options provided by main'); assert.equal(typeof callbacks.print, 'function', 'callbacks.print is a function'); assert.equal(typeof callbacks.quit, 'function', 'callbacks.quit is a function'); - assert.equal(options.loadReason, 'install', 'options.loadReason is install'); + + // Re-enable when bug 1251664 is fixed + //assert.equal(options.loadReason, 'install', 'options.loadReason is install'); } require('sdk/test/runner').runTestsFromModule({exports: tests}); diff --git a/addon-sdk/source/test/addons/unpacked/main.js b/addon-sdk/source/test/addons/unpacked/main.js deleted file mode 100644 index 903b94c5492..00000000000 --- a/addon-sdk/source/test/addons/unpacked/main.js +++ /dev/null @@ -1,18 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -"use strict"; - -const { packed } = require("sdk/self"); -const url = require("sdk/url"); - -exports["test self.packed"] = function (assert) { - assert.ok(!packed, "require('sdk/self').packed is correct"); -} - -exports["test url.toFilename"] = function (assert) { - assert.ok(/.*main\.js$/.test(url.toFilename(module.uri)), - "url.toFilename() on resource: URIs should work"); -} - -require("sdk/test/runner").runTestsFromModule(module); diff --git a/addon-sdk/source/test/addons/unpacked/package.json b/addon-sdk/source/test/addons/unpacked/package.json deleted file mode 100644 index 3d150142916..00000000000 --- a/addon-sdk/source/test/addons/unpacked/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": "test-url@jetpack", - "unpack": true, - "main": "./main.js", - "version": "0.0.1" -} diff --git a/testing/mochitest/jetpack-addon-harness.js b/testing/mochitest/jetpack-addon-harness.js index d098b29ca68..3b938db9db1 100644 --- a/testing/mochitest/jetpack-addon-harness.js +++ b/testing/mochitest/jetpack-addon-harness.js @@ -27,68 +27,58 @@ function realPath(chrome) { .replace(".xpi", ""); } +const chromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"] + .getService(Ci.nsIChromeRegistry); + // Installs a single add-on returning a promise for when install is completed function installAddon(url) { - return new Promise(function(resolve, reject) { - AddonManager.getInstallForURL(url, function(install) { - install.addListener({ - onDownloadEnded: function(install) { - // Set add-on's test options - const options = { - test: { - iterations: 1, - stop: false, - keepOpen: true, - }, - profile: { - memory: false, - leaks: false, - }, - output: { - logLevel: "verbose", - format: "tbpl", - }, - console: { - logLevel: "info", - }, - } - setPrefs("extensions." + install.addon.id + ".sdk", options); + let chromeURL = Services.io.newURI(url, null, null); + let file = chromeRegistry.convertChromeURL(chromeURL) + .QueryInterface(Ci.nsIFileURL).file; - // If necessary override the add-ons module paths to point somewhere - // else - if (sdkpath) { - let paths = {} - for (let path of ["dev", "diffpatcher", "framescript", "method", "node", "sdk", "toolkit"]) { - paths[path] = sdkpath + path; - } - setPrefs("extensions.modules." + install.addon.id + ".path", paths); - } + let addon; + const listener = { + onInstalling(_addon) { + addon = _addon; + // Set add-on's test options + const options = { + test: { + iterations: 1, + stop: false, + keepOpen: true, }, - - onInstallEnded: function(install, addon) { - resolve(addon); + profile: { + memory: false, + leaks: false, }, - - onDownloadCancelled: function(install) { - reject("Download cancelled: " + install.error); + output: { + logLevel: "verbose", + format: "tbpl", }, - - onDownloadFailed: function(install) { - reject("Download failed: " + install.error); + console: { + logLevel: "info", }, + } + setPrefs("extensions." + addon.id + ".sdk", options); - onInstallCancelled: function(install) { - reject("Install cancelled: " + install.error); - }, - - onInstallFailed: function(install) { - reject("Install failed: " + install.error); + // If necessary override the add-ons module paths to point somewhere + // else + if (sdkpath) { + let paths = {} + for (let path of ["dev", "diffpatcher", "framescript", "method", "node", "sdk", "toolkit"]) { + paths[path] = sdkpath + path; } - }); + setPrefs("extensions.modules." + addon.id + ".path", paths); + } + }, + }; + AddonManager.addAddonListener(listener); - install.install(); - }, "application/x-xpinstall"); - }); + return AddonManager.installTemporaryAddon(file) + .then(() => { + AddonManager.removeAddonListener(listener); + return addon; + }); } // Uninstalls an add-on returning a promise for when it is gone