1
/* Any copyright is dedicated to the Public Domain.
2
* http://creativecommons.org/publicdomain/zero/1.0/
5
Components.utils.import("resource://gre/modules/AddonManager.jsm");
6
Components.utils.import("resource://gre/modules/AddonUpdateChecker.jsm");
7
Components.utils.import("resource://gre/modules/Services.jsm");
8
Components.utils.import("resource://gre/modules/NetUtil.jsm");
10
const RELATIVE_DIR = "browser/mobile/chrome/";
11
const TESTROOT = "http://example.com/" + RELATIVE_DIR;
12
const TESTROOT2 = "http://example.org/" + RELATIVE_DIR;
13
const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
14
const PREF_SEARCH_MAXRESULTS = "extensions.getAddons.maxResults";
15
const CHROME_NAME = "mochikit";
16
const PREF_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault"
17
const PREF_GETADDONS_BROWSESEARCHRESULTS = "extensions.getAddons.search.browseURL";
18
const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
19
const PREF_GETADDONS_GETRECOMMENDED = "extensions.getAddons.recommended.url";
20
const PREF_GETADDONS_BROWSERECOMMENDED = "extensions.getAddons.recommended.browseURL";
21
const PREF_GETADDONS_UPDATE = "extensions.update.url";
22
const SEARCH_URL = TESTROOT + "browser_details.xml";
25
id: "addon1@tests.mozilla.org",
26
name : "Install Tests",
27
iconURL: "http://example.com/icon.png",
28
homepageURL: "http://example.com/",
30
description: "Test add-on",
31
sourceURL: TESTROOT + "addons/browser_install1_1.xpi",
37
id: "addon2@tests.mozilla.org",
38
name : "Install Tests 2",
39
iconURL: "http://example.com/icon.png",
40
homepageURL: "http://example.com/",
42
description: "Test add-on 2",
43
sourceURL: TESTROOT + "addons/browser_install1_2.xpi",
48
id: "addon1@tests.mozilla.org",
49
name : "Install Tests 3",
50
iconURL: "http://example.com/icon.png",
51
homepageURL: "http://example.com/",
53
description: "Test add-on 3",
54
sourceURL: TESTROOT + "addons/browser_install1_3.xpi",
60
var gPendingTests = [];
62
var gTestStart = null;
63
var gDate = new Date(2010, 7, 1);
64
var gApp = document.getElementById("bundle_brand").getString("brandShortName");
65
var gCategoryUtilities;
70
waitForExplicitFinish();
71
Services.prefs.setCharPref(PREF_GETADDONS_GETRECOMMENDED, TESTROOT + "browser_install.xml");
72
Services.prefs.setCharPref(PREF_GETADDONS_BROWSERECOMMENDED, TESTROOT + "browser_install.xml");
73
Services.prefs.setCharPref(PREF_GETADDONS_BROWSESEARCHRESULTS, TESTROOT + "browser_install.xml");
74
Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, TESTROOT + "browser_install.xml");
75
Services.prefs.setCharPref(PREF_GETADDONS_UPDATE, TESTROOT + "browser_upgrade.rdf");
76
Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
82
Services.prefs.clearUserPref(PREF_GETADDONS_GETRECOMMENDED);
83
Services.prefs.clearUserPref(PREF_GETADDONS_BROWSERECOMMENDED);
84
Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS);
85
Services.prefs.clearUserPref(PREF_GETADDONS_BROWSESEARCHRESULTS);
89
function add_test(test) {
90
gPendingTests.push(test);
93
function run_next_test() {
95
info("Test " + gTestsRun + " took " + (Date.now() - gTestStart) + "ms");
97
if (gPendingTests.length == 0) {
103
var test = gPendingTests.shift();
105
info("Running test " + gTestsRun + " (" + test.name + ")");
107
info("Running test " + gTestsRun);
109
gTestStart = Date.now();
113
function checkAttribute(aElt, aAttr, aVal) {
114
ok(aElt.hasAttribute(aAttr), "Element has " + aAttr + " attribute");
116
is(aElt.getAttribute(aAttr), aVal, "Element has " + aAttr + " attribute with value " + aVal);
119
function installExtension(elt, aListener) {
120
elt.parentNode.ensureElementIsVisible(elt);
121
elt.install.addListener(aListener)
123
var button = document.getAnonymousElementByAttribute(elt, "class", "addon-install hide-on-install hide-on-restart");
124
ok(!!button, "Extension has install button");
125
ExtensionsView.installFromRepo(elt);
128
function isRestartShown(aShown, isUpdate, aCallback) {
129
let msg = document.getElementById("addons-messages");
130
ok(!!msg, "Have message box");
132
let done = function(aNotification) {
133
is(!!aNotification, aShown, "Restart exists = " + aShown);
134
if (aShown && aNotification) {
135
let showsUpdate = aNotification.label.match(/update/i) != null;
136
// this test regularly fails due to race conditions here
137
is(showsUpdate, isUpdate, "Restart shows correct message");
139
msg.removeAllNotifications(true);
143
let notification = msg.getNotificationWithValue("restart-app");
144
if (!notification && aShown) {
145
window.addEventListener("AlertActive", function() {
146
window.removeEventListener("AlertActive", arguments.callee, true);
147
notification = msg.getNotificationWithValue("restart-app");
155
function checkAddonListing(aAddon, elt) {
156
ok(!!elt, "Element exists for addon");
157
checkAttribute(elt, "id", "urn:mozilla:item:" + aAddon.id);
158
checkAttribute(elt, "addonID", aAddon.id);
159
checkAttribute(elt, "typeName", "search");
160
checkAttribute(elt, "name", aAddon.name);
161
checkAttribute(elt, "version", aAddon.version);
162
checkAttribute(elt, "iconURL", aAddon.iconURL);
163
checkAttribute(elt, "description", aAddon.description)
164
checkAttribute(elt, "homepageURL", aAddon.homepageURL);
165
checkAttribute(elt, "sourceURL", aAddon.sourceURL);
166
ok(elt.install, "Extension has install property");
168
function checkUpdate(aSettings) {
169
let os = Services.obs;
170
let ul = new updateListener(aSettings);
171
os.addObserver(ul, "addon-update-ended", false);
173
ExtensionsView.updateAll();
176
function get_addon_element(aId) {
177
return document.getElementById("urn:mozilla:item:" + aId);
180
function open_manager(aView, aCallback) {
181
BrowserUI.showPanel("addons-container");
183
ExtensionsView.init();
184
ExtensionsView._delayedInit();
186
window.addEventListener("ViewChanged", function() {
187
window.removeEventListener("ViewChanged", arguments.callee, true);
192
function close_manager() {
193
var prefsButton = document.getElementById("tool-preferences");
196
ExtensionsView.clearSection();
197
ExtensionsView.clearSection("local");
198
ExtensionsView._list = null;
199
ExtensionsView._restartCount = 0;
200
BrowserUI.hidePanel();
203
// Installs an addon from the addons pref pane, and then
204
// updates it if requested. Checks to make sure
205
// restart notifications are shown at the right time
206
function installFromAddonsPage(aAddon, aDoUpdate) {
208
open_manager(null, function() {
209
var elt = get_addon_element(aAddon.id);
210
checkAddonListing(aAddon, elt);
211
installExtension(elt, new installListener({
213
onComplete: function() {
216
addon: addons[aAddon.updateIndex],
217
onComplete: function() {
232
add_test(installFromAddonsPage(addons[0], true));
233
add_test(installFromAddonsPage(addons[1], false));
235
function installListener(aSettings) {
236
this.onComplete = aSettings.onComplete;
237
this.addon = aSettings.addon;
240
installListener.prototype = {
241
onNewInstall : function(install) { },
242
onDownloadStarted : function(install) {
243
info("download started");
245
onDownloadProgress : function(install) {
246
info("download progress");
248
onDownloadEnded : function(install) {
249
info("download ended");
251
onDownloadCancelled : function(install) {
252
info("download cancelled");
254
onDownloadFailed : function(install) {
255
if(this.addon.willFail)
256
ok(false, "Install failed");
257
info("download failed");
259
onInstallStarted : function(install) {
260
info("Install started");
262
onInstallEnded : function(install, addon) {
263
info("Install ended");
265
isRestartShown(!this.addon.bootstrapped, false, function() {
270
onInstallCancelled : function(install) {
271
info("Install cancelled");
273
onInstallFailed : function(install) {
275
ok(false, "Install failed");
276
info("install failed");
278
onExternalInstall : function(install, existing, needsRestart) { },
281
function updateListener(aSettings) {
282
this.onComplete = aSettings.onComplete;
283
this.addon = aSettings.addon;
286
updateListener.prototype = {
287
observe: function (aSubject, aTopic, aData) {
289
case "addon-update-ended" :
290
let json = aSubject.QueryInterface(Ci.nsISupportsString).data;
291
let update = JSON.parse(json);
292
if(update.id == this.addon.id) {
293
let os = Services.obs;
294
os.removeObserver(this, "addon-update-ended", false);
296
let element = get_addon_element(update.id);
297
ok(!!element, "Have element for upgrade");
300
isRestartShown(!this.addon.bootstrapped, true, function() {