Bug 1251412 - use installTemporaryAddon for jetpack-addons tests r=mossop

MozReview-Commit-ID: Bd10uC4pEfP

--HG--
extra : rebase_source : 2f261194ff07a25c13aaad91255147e98e7c5127
This commit is contained in:
Andrew Swan 2016-02-25 15:45:31 -08:00
Родитель a0129dc275
Коммит 96c88d557a
5 изменённых файлов: 45 добавлений и 78 удалений

Просмотреть файл

@ -42,5 +42,4 @@ skip-if = true
[tab-close-on-startup.xpi]
[toolkit-require-reload.xpi]
[translators.xpi]
[unpacked.xpi]
[unsafe-content-script.xpi]

Просмотреть файл

@ -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});

Просмотреть файл

@ -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);

Просмотреть файл

@ -1,6 +0,0 @@
{
"id": "test-url@jetpack",
"unpack": true,
"main": "./main.js",
"version": "0.0.1"
}

Просмотреть файл

@ -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