2010-10-18 12:02:00 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/AddonUpdateChecker.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
|
|
|
|
|
|
|
const RELATIVE_DIR = "browser/mobile/chrome/";
|
|
|
|
const TESTROOT = "http://example.com/" + RELATIVE_DIR;
|
|
|
|
const TESTROOT2 = "http://example.org/" + RELATIVE_DIR;
|
|
|
|
const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
|
|
|
|
const PREF_SEARCH_MAXRESULTS = "extensions.getAddons.maxResults";
|
|
|
|
const CHROME_NAME = "mochikit";
|
|
|
|
const PREF_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault"
|
|
|
|
const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL";
|
|
|
|
const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
|
2010-12-07 10:38:00 -08:00
|
|
|
const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url";
|
2010-10-18 12:02:00 -07:00
|
|
|
const PREF_GETADDONS_BROWSERECOMMENDED = "extensions.getAddons.recommended.browseURL";
|
2010-12-07 10:38:00 -08:00
|
|
|
const PREF_GETADDONS_UPDATE = "extensions.update.url";
|
2010-10-18 12:02:00 -07:00
|
|
|
const SEARCH_URL = TESTROOT + "browser_details.xml";
|
|
|
|
|
|
|
|
var addons = [{
|
|
|
|
id: "addon1@tests.mozilla.org",
|
|
|
|
name : "Install Tests",
|
|
|
|
iconURL: "http://example.com/icon.png",
|
|
|
|
homepageURL: "http://example.com/",
|
|
|
|
version: "1.0",
|
|
|
|
description: "Test add-on",
|
2010-11-15 13:00:00 -08:00
|
|
|
sourceURL: TESTROOT + "addons/browser_install1_1.xpi",
|
|
|
|
bootstrapped: true,
|
|
|
|
willFail: false,
|
|
|
|
updateIndex: 2,
|
2010-10-18 12:02:00 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "addon2@tests.mozilla.org",
|
|
|
|
name : "Install Tests 2",
|
|
|
|
iconURL: "http://example.com/icon.png",
|
|
|
|
homepageURL: "http://example.com/",
|
|
|
|
version: "1.0",
|
|
|
|
description: "Test add-on 2",
|
2010-11-15 13:00:00 -08:00
|
|
|
sourceURL: TESTROOT + "addons/browser_install1_2.xpi",
|
|
|
|
bootstrapped: false,
|
|
|
|
willFail: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "addon1@tests.mozilla.org",
|
|
|
|
name : "Install Tests 3",
|
|
|
|
iconURL: "http://example.com/icon.png",
|
|
|
|
homepageURL: "http://example.com/",
|
|
|
|
version: "1.0",
|
|
|
|
description: "Test add-on 3",
|
|
|
|
sourceURL: TESTROOT + "addons/browser_install1_3.xpi",
|
|
|
|
bootstrapped: false,
|
|
|
|
willFail: false,
|
2010-10-18 12:02:00 -07:00
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
var gPendingTests = [];
|
|
|
|
var gTestsRun = 0;
|
|
|
|
var gTestStart = null;
|
|
|
|
var gDate = new Date(2010, 7, 1);
|
|
|
|
var gApp = document.getElementById("bundle_brand").getString("brandShortName");
|
|
|
|
var gCategoryUtilities;
|
|
|
|
var gSearchCount = 0;
|
|
|
|
var gProvider = null;
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, TESTROOT + "browser_install.xml");
|
|
|
|
Services.prefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, TESTROOT + "browser_install.xml");
|
|
|
|
Services.prefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, TESTROOT + "browser_install.xml");
|
|
|
|
Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, TESTROOT + "browser_install.xml");
|
2010-12-07 10:38:00 -08:00
|
|
|
Services.prefs.setCharPref(PREF_GETADDONS_UPDATE, TESTROOT + "browser_upgrade.rdf");
|
2010-10-18 12:02:00 -07:00
|
|
|
Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
|
|
|
|
run_next_test();
|
|
|
|
}
|
|
|
|
|
|
|
|
function end_test() {
|
2010-11-15 13:00:00 -08:00
|
|
|
close_manager();
|
|
|
|
Services.prefs.clearUserPref(PREF_GETADDONS_GETRECOMMENDED);
|
|
|
|
Services.prefs.clearUserPref(PREF_GETADDONS_BROWSERECOMMENDED);
|
|
|
|
Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS);
|
|
|
|
Services.prefs.clearUserPref(PREF_GETADDONS_BROWSESEARCHRESULTS);
|
|
|
|
finish();
|
2010-10-18 12:02:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_test(test) {
|
|
|
|
gPendingTests.push(test);
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_next_test() {
|
|
|
|
if (gTestsRun > 0)
|
|
|
|
info("Test " + gTestsRun + " took " + (Date.now() - gTestStart) + "ms");
|
|
|
|
|
|
|
|
if (gPendingTests.length == 0) {
|
|
|
|
end_test();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gTestsRun++;
|
|
|
|
var test = gPendingTests.shift();
|
|
|
|
if (test.name)
|
|
|
|
info("Running test " + gTestsRun + " (" + test.name + ")");
|
|
|
|
else
|
|
|
|
info("Running test " + gTestsRun);
|
|
|
|
|
|
|
|
gTestStart = Date.now();
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAttribute(aElt, aAttr, aVal) {
|
|
|
|
ok(aElt.hasAttribute(aAttr), "Element has " + aAttr + " attribute");
|
|
|
|
if(aVal)
|
|
|
|
is(aElt.getAttribute(aAttr), aVal, "Element has " + aAttr + " attribute with value " + aVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
function installExtension(elt, aListener) {
|
|
|
|
elt.parentNode.ensureElementIsVisible(elt);
|
|
|
|
elt.install.addListener(aListener)
|
|
|
|
|
|
|
|
var button = document.getAnonymousElementByAttribute(elt, "class", "addon-install hide-on-install hide-on-restart");
|
|
|
|
ok(!!button, "Extension has install button");
|
|
|
|
ExtensionsView.installFromRepo(elt);
|
|
|
|
}
|
|
|
|
|
2010-11-15 13:00:00 -08:00
|
|
|
function isRestartShown(aShown, isUpdate, aCallback) {
|
2010-10-18 12:02:00 -07:00
|
|
|
let msg = document.getElementById("addons-messages");
|
|
|
|
ok(!!msg, "Have message box");
|
2010-11-15 13:00:00 -08:00
|
|
|
|
|
|
|
let done = function(aNotification) {
|
|
|
|
is(!!aNotification, aShown, "Restart exists = " + aShown);
|
|
|
|
if (aShown && aNotification) {
|
|
|
|
let showsUpdate = aNotification.label.match(/update/i) != null;
|
|
|
|
// this test regularly fails due to race conditions here
|
|
|
|
is(showsUpdate, isUpdate, "Restart shows correct message");
|
|
|
|
}
|
|
|
|
msg.removeAllNotifications(true);
|
|
|
|
aCallback();
|
|
|
|
}
|
|
|
|
|
2010-10-18 12:02:00 -07:00
|
|
|
let notification = msg.getNotificationWithValue("restart-app");
|
2010-11-15 13:00:00 -08:00
|
|
|
if (!notification && aShown) {
|
|
|
|
window.addEventListener("AlertActive", function() {
|
|
|
|
window.removeEventListener("AlertActive", arguments.callee, true);
|
|
|
|
notification = msg.getNotificationWithValue("restart-app");
|
|
|
|
done(notification);
|
|
|
|
}, true);
|
|
|
|
} else {
|
|
|
|
done(notification);
|
2010-10-18 12:02:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAddonListing(aAddon, elt) {
|
|
|
|
ok(!!elt, "Element exists for addon");
|
|
|
|
checkAttribute(elt, "id", "urn:mozilla:item:" + aAddon.id);
|
|
|
|
checkAttribute(elt, "addonID", aAddon.id);
|
|
|
|
checkAttribute(elt, "typeName", "search");
|
|
|
|
checkAttribute(elt, "name", aAddon.name);
|
|
|
|
checkAttribute(elt, "version", aAddon.version);
|
|
|
|
checkAttribute(elt, "iconURL", aAddon.iconURL);
|
|
|
|
checkAttribute(elt, "description", aAddon.description)
|
|
|
|
checkAttribute(elt, "homepageURL", aAddon.homepageURL);
|
|
|
|
checkAttribute(elt, "sourceURL", aAddon.sourceURL);
|
|
|
|
ok(elt.install, "Extension has install property");
|
|
|
|
}
|
2010-11-15 13:00:00 -08:00
|
|
|
function checkUpdate(aSettings) {
|
2010-10-18 12:02:00 -07:00
|
|
|
let os = Services.obs;
|
|
|
|
let ul = new updateListener(aSettings);
|
|
|
|
os.addObserver(ul, "addon-update-ended", false);
|
|
|
|
|
|
|
|
ExtensionsView.updateAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_addon_element(aId) {
|
2010-11-15 13:00:00 -08:00
|
|
|
return document.getElementById("urn:mozilla:item:" + aId);
|
2010-10-18 12:02:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function open_manager(aView, aCallback) {
|
2010-11-15 13:00:00 -08:00
|
|
|
BrowserUI.showPanel("addons-container");
|
|
|
|
|
|
|
|
ExtensionsView.init();
|
|
|
|
ExtensionsView._delayedInit();
|
|
|
|
|
|
|
|
window.addEventListener("ViewChanged", function() {
|
|
|
|
window.removeEventListener("ViewChanged", arguments.callee, true);
|
|
|
|
aCallback();
|
|
|
|
}, true);
|
2010-10-18 12:02:00 -07:00
|
|
|
}
|
|
|
|
|
2010-11-15 13:00:00 -08:00
|
|
|
function close_manager() {
|
2010-10-18 12:02:00 -07:00
|
|
|
var prefsButton = document.getElementById("tool-preferences");
|
|
|
|
prefsButton.click();
|
2010-11-15 13:00:00 -08:00
|
|
|
|
|
|
|
ExtensionsView.clearSection();
|
|
|
|
ExtensionsView.clearSection("local");
|
|
|
|
ExtensionsView._list = null;
|
|
|
|
ExtensionsView._restartCount = 0;
|
2010-10-18 12:02:00 -07:00
|
|
|
BrowserUI.hidePanel();
|
|
|
|
}
|
|
|
|
|
2010-11-15 13:00:00 -08:00
|
|
|
// Installs an addon from the addons pref pane, and then
|
|
|
|
// updates it if requested. Checks to make sure
|
|
|
|
// restart notifications are shown at the right time
|
|
|
|
function installFromAddonsPage(aAddon, aDoUpdate) {
|
|
|
|
return function() {
|
|
|
|
open_manager(null, function() {
|
|
|
|
var elt = get_addon_element(aAddon.id);
|
|
|
|
checkAddonListing(aAddon, elt);
|
|
|
|
installExtension(elt, new installListener({
|
|
|
|
addon: aAddon,
|
|
|
|
onComplete: function() {
|
|
|
|
if (aDoUpdate) {
|
|
|
|
checkUpdate({
|
|
|
|
addon: addons[aAddon.updateIndex],
|
|
|
|
onComplete: function() {
|
|
|
|
close_manager();
|
|
|
|
run_next_test();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
close_manager();
|
|
|
|
run_next_test();
|
2010-10-18 12:02:00 -07:00
|
|
|
}
|
2010-11-15 13:00:00 -08:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
add_test(installFromAddonsPage(addons[0], true));
|
|
|
|
add_test(installFromAddonsPage(addons[1], false));
|
2010-10-18 12:02:00 -07:00
|
|
|
|
|
|
|
function installListener(aSettings) {
|
2010-11-15 13:00:00 -08:00
|
|
|
this.onComplete = aSettings.onComplete;
|
|
|
|
this.addon = aSettings.addon;
|
2010-10-18 12:02:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
installListener.prototype = {
|
|
|
|
onNewInstall : function(install) { },
|
|
|
|
onDownloadStarted : function(install) {
|
|
|
|
info("download started");
|
|
|
|
},
|
|
|
|
onDownloadProgress : function(install) {
|
|
|
|
info("download progress");
|
|
|
|
},
|
|
|
|
onDownloadEnded : function(install) {
|
|
|
|
info("download ended");
|
|
|
|
},
|
|
|
|
onDownloadCancelled : function(install) {
|
|
|
|
info("download cancelled");
|
|
|
|
},
|
|
|
|
onDownloadFailed : function(install) {
|
2010-11-15 13:00:00 -08:00
|
|
|
if(this.addon.willFail)
|
2010-10-18 12:02:00 -07:00
|
|
|
ok(false, "Install failed");
|
|
|
|
info("download failed");
|
|
|
|
},
|
|
|
|
onInstallStarted : function(install) {
|
|
|
|
info("Install started");
|
|
|
|
},
|
|
|
|
onInstallEnded : function(install, addon) {
|
2010-11-15 13:00:00 -08:00
|
|
|
info("Install ended");
|
2010-10-18 12:02:00 -07:00
|
|
|
let self = this;
|
2010-11-15 13:00:00 -08:00
|
|
|
isRestartShown(!this.addon.bootstrapped, false, function() {
|
2010-10-18 12:02:00 -07:00
|
|
|
if(self.onComplete)
|
2010-11-15 13:00:00 -08:00
|
|
|
self.onComplete();
|
|
|
|
});
|
2010-10-18 12:02:00 -07:00
|
|
|
},
|
|
|
|
onInstallCancelled : function(install) {
|
|
|
|
info("Install cancelled");
|
|
|
|
},
|
|
|
|
onInstallFailed : function(install) {
|
|
|
|
if(this.willFail)
|
|
|
|
ok(false, "Install failed");
|
|
|
|
info("install failed");
|
|
|
|
},
|
|
|
|
onExternalInstall : function(install, existing, needsRestart) { },
|
|
|
|
};
|
|
|
|
|
|
|
|
function updateListener(aSettings) {
|
|
|
|
this.onComplete = aSettings.onComplete;
|
|
|
|
this.addon = aSettings.addon;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateListener.prototype = {
|
|
|
|
observe: function (aSubject, aTopic, aData) {
|
|
|
|
switch(aTopic) {
|
|
|
|
case "addon-update-ended" :
|
|
|
|
let json = aSubject.QueryInterface(Ci.nsISupportsString).data;
|
|
|
|
let update = JSON.parse(json);
|
|
|
|
if(update.id == this.addon.id) {
|
|
|
|
let os = Services.obs;
|
|
|
|
os.removeObserver(this, "addon-update-ended", false);
|
2010-11-15 13:00:00 -08:00
|
|
|
|
|
|
|
let element = get_addon_element(update.id);
|
|
|
|
ok(!!element, "Have element for upgrade");
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
isRestartShown(!this.addon.bootstrapped, true, function() {
|
|
|
|
if(self.onComplete)
|
|
|
|
self.onComplete();
|
|
|
|
});
|
2010-10-18 12:02:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|