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: // Get the HTTP server. michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var testserver; michael@0: michael@0: var next_test = null; michael@0: var gItemsNotChecked =[]; michael@0: michael@0: var ADDONS = [ {id: "bug324121_1@tests.mozilla.org", michael@0: addon: "test_bug324121_1", michael@0: shouldCheck: false }, michael@0: {id: "bug324121_2@tests.mozilla.org", michael@0: addon: "test_bug324121_2", michael@0: shouldCheck: true }, michael@0: {id: "bug324121_3@tests.mozilla.org", michael@0: addon: "test_bug324121_3", michael@0: shouldCheck: true }, michael@0: {id: "bug324121_4@tests.mozilla.org", michael@0: addon: "test_bug324121_4", michael@0: shouldCheck: true }, michael@0: {id: "bug324121_5@tests.mozilla.org", michael@0: addon: "test_bug324121_5", michael@0: shouldCheck: false }, michael@0: {id: "bug324121_6@tests.mozilla.org", michael@0: addon: "test_bug324121_6", michael@0: shouldCheck: true }, michael@0: {id: "bug324121_7@tests.mozilla.org", michael@0: addon: "test_bug324121_7", michael@0: shouldCheck: true }, michael@0: {id: "bug324121_8@tests.mozilla.org", michael@0: addon: "test_bug324121_8", michael@0: shouldCheck: true }, michael@0: {id: "bug324121_9@tests.mozilla.org", michael@0: addon: "test_bug324121_9", michael@0: shouldCheck: false } ]; michael@0: michael@0: // nsIAddonUpdateCheckListener michael@0: var updateListener = { michael@0: pendingCount: 0, michael@0: michael@0: onUpdateAvailable: function onAddonUpdateEnded(aAddon) { michael@0: switch (aAddon.id) { michael@0: // add-on disabled - should not happen michael@0: case "bug324121_1@tests.mozilla.org": michael@0: // app id already compatible - should not happen michael@0: case "bug324121_5@tests.mozilla.org": michael@0: // toolkit id already compatible - should not happen michael@0: case "bug324121_9@tests.mozilla.org": michael@0: do_throw("Should not have seen an update check for " + aAddon.id); michael@0: break; michael@0: michael@0: // app id incompatible update available michael@0: case "bug324121_3@tests.mozilla.org": michael@0: // update rdf not found michael@0: case "bug324121_4@tests.mozilla.org": michael@0: // toolkit id incompatible update available michael@0: case "bug324121_7@tests.mozilla.org": michael@0: // update rdf not found michael@0: case "bug324121_8@tests.mozilla.org": michael@0: do_throw("Should be no update available for " + aAddon.id); michael@0: break; michael@0: michael@0: // Updates available michael@0: case "bug324121_2@tests.mozilla.org": michael@0: case "bug324121_6@tests.mozilla.org": michael@0: break; michael@0: michael@0: default: michael@0: do_throw("Update check for unknown " + aAddon.id); michael@0: } michael@0: michael@0: // pos should always be >= 0 so just let this throw if this fails michael@0: var pos = gItemsNotChecked.indexOf(aAddon.id); michael@0: gItemsNotChecked.splice(pos, 1); michael@0: }, michael@0: michael@0: onNoUpdateAvailable: function onNoUpdateAvailable(aAddon) { michael@0: switch (aAddon.id) { michael@0: // add-on disabled - should not happen michael@0: case "bug324121_1@tests.mozilla.org": michael@0: // app id already compatible - should not happen michael@0: case "bug324121_5@tests.mozilla.org": michael@0: // toolkit id already compatible - should not happen michael@0: case "bug324121_9@tests.mozilla.org": michael@0: do_throw("Should not have seen an update check for " + aAddon.id); michael@0: break; michael@0: michael@0: // app id incompatible update available michael@0: case "bug324121_3@tests.mozilla.org": michael@0: // update rdf not found michael@0: case "bug324121_4@tests.mozilla.org": michael@0: // toolkit id incompatible update available michael@0: case "bug324121_7@tests.mozilla.org": michael@0: // update rdf not found michael@0: case "bug324121_8@tests.mozilla.org": michael@0: break; michael@0: michael@0: // Updates available michael@0: case "bug324121_2@tests.mozilla.org": michael@0: case "bug324121_6@tests.mozilla.org": michael@0: do_throw("Should be an update available for " + aAddon.id); michael@0: break; michael@0: michael@0: default: michael@0: do_throw("Update check for unknown " + aAddon.id); michael@0: } michael@0: michael@0: // pos should always be >= 0 so just let this throw if this fails michael@0: var pos = gItemsNotChecked.indexOf(aAddon.id); michael@0: gItemsNotChecked.splice(pos, 1); michael@0: }, michael@0: michael@0: onUpdateFinished: function onUpdateFinished(aAddon) { michael@0: if (--this.pendingCount == 0) michael@0: test_complete(); michael@0: } michael@0: }; michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); michael@0: michael@0: const dataDir = do_get_file("data"); michael@0: michael@0: // Create and configure the HTTP server. michael@0: testserver = new HttpServer(); michael@0: testserver.registerDirectory("/data/", dataDir); michael@0: testserver.start(4444); michael@0: michael@0: startupManager(); michael@0: michael@0: installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() { michael@0: restartManager(); michael@0: AddonManager.getAddonByID(ADDONS[0].id, callback_soon(function(addon) { michael@0: do_check_true(!(!addon)); michael@0: addon.userDisabled = true; michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonsByTypes(["extension"], function(installedItems) { michael@0: var items = []; michael@0: michael@0: for (let addon of ADDONS) { michael@0: for (let installedItem of installedItems) { michael@0: if (addon.id != installedItem.id) michael@0: continue; michael@0: if (installedItem.userDisabled) michael@0: continue; michael@0: michael@0: if (addon.shouldCheck == installedItem.isCompatibleWith("3", "3")) { michael@0: do_throw(installedItem.id + " had the wrong compatibility: " + michael@0: installedItem.isCompatibleWith("3", "3")); michael@0: } michael@0: michael@0: if (addon.shouldCheck) { michael@0: gItemsNotChecked.push(addon.id); michael@0: updateListener.pendingCount++; michael@0: installedItem.findUpdates(updateListener, michael@0: AddonManager.UPDATE_WHEN_USER_REQUESTED, michael@0: "3", "3"); michael@0: } michael@0: } michael@0: } michael@0: }); michael@0: })); michael@0: }); michael@0: } michael@0: michael@0: function test_complete() { michael@0: do_check_eq(gItemsNotChecked.length, 0); michael@0: testserver.stop(do_test_finished); michael@0: }