michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: // Disables security checking our updates which haven't been signed michael@0: Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); michael@0: michael@0: // Update check listener. michael@0: const checkListener = { michael@0: pendingCount: 0, michael@0: michael@0: onUpdateAvailable: function onUpdateAvailable(aAddon, aInstall) { michael@0: for (let currentAddon of ADDONS) { michael@0: if (currentAddon.id == aAddon.id) { michael@0: currentAddon.newInstall = aInstall; michael@0: return; michael@0: } michael@0: } michael@0: }, michael@0: michael@0: onUpdateFinished: function onUpdateFinished() { michael@0: if (--this.pendingCount == 0) michael@0: next_test(); michael@0: } michael@0: } michael@0: michael@0: // Get the HTTP server. michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var testserver; michael@0: michael@0: var ADDONS = [ michael@0: // XPCShell michael@0: { michael@0: id: "bug299716-a@tests.mozilla.org", michael@0: addon: "test_bug299716_a_1", michael@0: installed: true, michael@0: item: null, michael@0: newInstall: null michael@0: }, michael@0: michael@0: // Toolkit michael@0: { michael@0: id: "bug299716-b@tests.mozilla.org", michael@0: addon: "test_bug299716_b_1", michael@0: installed: true, michael@0: item: null, michael@0: newInstall: null michael@0: }, michael@0: michael@0: // XPCShell + Toolkit michael@0: { michael@0: id: "bug299716-c@tests.mozilla.org", michael@0: addon: "test_bug299716_c_1", michael@0: installed: true, michael@0: item: null, michael@0: newInstall: null michael@0: }, michael@0: michael@0: // XPCShell (Toolkit invalid) michael@0: { michael@0: id: "bug299716-d@tests.mozilla.org", michael@0: addon: "test_bug299716_d_1", michael@0: installed: true, michael@0: item: null, michael@0: newInstall: null michael@0: }, michael@0: michael@0: // Toolkit (XPCShell invalid) michael@0: { michael@0: id: "bug299716-e@tests.mozilla.org", michael@0: addon: "test_bug299716_e_1", michael@0: installed: false, michael@0: item: null, michael@0: newInstall: null, michael@0: failedAppName: "XPCShell" michael@0: }, michael@0: michael@0: // None (XPCShell, Toolkit invalid) michael@0: { michael@0: id: "bug299716-f@tests.mozilla.org", michael@0: addon: "test_bug299716_f_1", michael@0: installed: false, michael@0: item: null, michael@0: newInstall: null, michael@0: failedAppName: "XPCShell" michael@0: }, michael@0: michael@0: // None (Toolkit invalid) michael@0: { michael@0: id: "bug299716-g@tests.mozilla.org", michael@0: addon: "test_bug299716_g_1", michael@0: installed: false, michael@0: item: null, michael@0: newInstall: null, michael@0: failedAppName: "Toolkit" michael@0: }, michael@0: ]; michael@0: michael@0: var next_test = function() {}; michael@0: michael@0: function do_check_item(aItem, aVersion, aAddonsEntry) { michael@0: if (aAddonsEntry.installed) { michael@0: if (aItem == null) michael@0: do_throw("Addon " + aAddonsEntry.id + " wasn't detected"); michael@0: if (aItem.version != aVersion) michael@0: do_throw("Addon " + aAddonsEntry.id + " was version " + aItem.version + " instead of " + aVersion); michael@0: } else { michael@0: if (aItem != null) michael@0: do_throw("Addon " + aAddonsEntry.id + " was detected"); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Start the test by installing extensions. michael@0: */ michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "5", "1.9"); michael@0: michael@0: const dataDir = do_get_file("data"); michael@0: const addonsDir = do_get_addon(ADDONS[0].addon).parent; michael@0: michael@0: // Make sure we can actually get our data files. michael@0: const xpiFile = addonsDir.clone(); michael@0: xpiFile.append("test_bug299716_a_2.xpi"); michael@0: do_check_true(xpiFile.exists()); michael@0: michael@0: // Create and configure the HTTP server. michael@0: testserver = new HttpServer(); michael@0: testserver.registerDirectory("/addons/", addonsDir); michael@0: testserver.registerDirectory("/data/", dataDir); michael@0: testserver.start(4444); michael@0: michael@0: // Make sure we can fetch the files over HTTP. michael@0: const Ci = Components.interfaces; michael@0: const xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] michael@0: .createInstance(Ci.nsIXMLHttpRequest) michael@0: xhr.open("GET", "http://localhost:4444/addons/test_bug299716_a_2.xpi", false); michael@0: xhr.send(null); michael@0: do_check_true(xhr.status == 200); michael@0: michael@0: xhr.open("GET", "http://localhost:4444/data/test_bug299716.rdf", false); michael@0: xhr.send(null); michael@0: do_check_true(xhr.status == 200); michael@0: michael@0: // Start the real test. michael@0: startupManager(); michael@0: dump("\n\n*** INSTALLING NEW ITEMS\n\n"); michael@0: michael@0: installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], run_test_pt2, michael@0: true); michael@0: } michael@0: michael@0: /** michael@0: * Check the versions of all items, and ask the extension manager to find updates. michael@0: */ michael@0: function run_test_pt2() { michael@0: dump("\n\n*** DONE INSTALLING NEW ITEMS\n\n"); michael@0: dump("\n\n*** RESTARTING EXTENSION MANAGER\n\n"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(items) { michael@0: dump("\n\n*** REQUESTING UPDATE\n\n"); michael@0: // checkListener will call run_test_pt3(). michael@0: next_test = run_test_pt3; michael@0: michael@0: // Try to update the items. michael@0: for (var i = 0; i < ADDONS.length; i++) { michael@0: var item = items[i]; michael@0: do_check_item(item, "0.1", ADDONS[i]); michael@0: michael@0: if (item) { michael@0: checkListener.pendingCount++; michael@0: ADDONS[i].item = item; michael@0: item.findUpdates(checkListener, AddonManager.UPDATE_WHEN_USER_REQUESTED); michael@0: } michael@0: } michael@0: }); michael@0: } michael@0: michael@0: /** michael@0: * Install new items for each enabled extension. michael@0: */ michael@0: function run_test_pt3() { michael@0: // Install the new items. michael@0: dump("\n\n*** UPDATING ITEMS\n\n"); michael@0: completeAllInstalls([a.newInstall for each(a in ADDONS) if (a.newInstall)], michael@0: run_test_pt4); michael@0: } michael@0: michael@0: /** michael@0: * Check the final version of each extension. michael@0: */ michael@0: function run_test_pt4() { michael@0: dump("\n\n*** RESTARTING EXTENSION MANAGER\n\n"); michael@0: restartManager(); michael@0: michael@0: dump("\n\n*** FINAL CHECKS\n\n"); michael@0: AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(items) { michael@0: for (var i = 0; i < ADDONS.length; i++) { michael@0: var item = items[i]; michael@0: do_check_item(item, "0.2", ADDONS[i]); michael@0: } michael@0: michael@0: testserver.stop(do_test_finished); michael@0: }); michael@0: }