1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug324121.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,178 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +// Disables security checking our updates which haven't been signed 1.10 +Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); 1.11 + 1.12 +// Get the HTTP server. 1.13 +Components.utils.import("resource://testing-common/httpd.js"); 1.14 +var testserver; 1.15 + 1.16 +var next_test = null; 1.17 +var gItemsNotChecked =[]; 1.18 + 1.19 +var ADDONS = [ {id: "bug324121_1@tests.mozilla.org", 1.20 + addon: "test_bug324121_1", 1.21 + shouldCheck: false }, 1.22 + {id: "bug324121_2@tests.mozilla.org", 1.23 + addon: "test_bug324121_2", 1.24 + shouldCheck: true }, 1.25 + {id: "bug324121_3@tests.mozilla.org", 1.26 + addon: "test_bug324121_3", 1.27 + shouldCheck: true }, 1.28 + {id: "bug324121_4@tests.mozilla.org", 1.29 + addon: "test_bug324121_4", 1.30 + shouldCheck: true }, 1.31 + {id: "bug324121_5@tests.mozilla.org", 1.32 + addon: "test_bug324121_5", 1.33 + shouldCheck: false }, 1.34 + {id: "bug324121_6@tests.mozilla.org", 1.35 + addon: "test_bug324121_6", 1.36 + shouldCheck: true }, 1.37 + {id: "bug324121_7@tests.mozilla.org", 1.38 + addon: "test_bug324121_7", 1.39 + shouldCheck: true }, 1.40 + {id: "bug324121_8@tests.mozilla.org", 1.41 + addon: "test_bug324121_8", 1.42 + shouldCheck: true }, 1.43 + {id: "bug324121_9@tests.mozilla.org", 1.44 + addon: "test_bug324121_9", 1.45 + shouldCheck: false } ]; 1.46 + 1.47 +// nsIAddonUpdateCheckListener 1.48 +var updateListener = { 1.49 + pendingCount: 0, 1.50 + 1.51 + onUpdateAvailable: function onAddonUpdateEnded(aAddon) { 1.52 + switch (aAddon.id) { 1.53 + // add-on disabled - should not happen 1.54 + case "bug324121_1@tests.mozilla.org": 1.55 + // app id already compatible - should not happen 1.56 + case "bug324121_5@tests.mozilla.org": 1.57 + // toolkit id already compatible - should not happen 1.58 + case "bug324121_9@tests.mozilla.org": 1.59 + do_throw("Should not have seen an update check for " + aAddon.id); 1.60 + break; 1.61 + 1.62 + // app id incompatible update available 1.63 + case "bug324121_3@tests.mozilla.org": 1.64 + // update rdf not found 1.65 + case "bug324121_4@tests.mozilla.org": 1.66 + // toolkit id incompatible update available 1.67 + case "bug324121_7@tests.mozilla.org": 1.68 + // update rdf not found 1.69 + case "bug324121_8@tests.mozilla.org": 1.70 + do_throw("Should be no update available for " + aAddon.id); 1.71 + break; 1.72 + 1.73 + // Updates available 1.74 + case "bug324121_2@tests.mozilla.org": 1.75 + case "bug324121_6@tests.mozilla.org": 1.76 + break; 1.77 + 1.78 + default: 1.79 + do_throw("Update check for unknown " + aAddon.id); 1.80 + } 1.81 + 1.82 + // pos should always be >= 0 so just let this throw if this fails 1.83 + var pos = gItemsNotChecked.indexOf(aAddon.id); 1.84 + gItemsNotChecked.splice(pos, 1); 1.85 + }, 1.86 + 1.87 + onNoUpdateAvailable: function onNoUpdateAvailable(aAddon) { 1.88 + switch (aAddon.id) { 1.89 + // add-on disabled - should not happen 1.90 + case "bug324121_1@tests.mozilla.org": 1.91 + // app id already compatible - should not happen 1.92 + case "bug324121_5@tests.mozilla.org": 1.93 + // toolkit id already compatible - should not happen 1.94 + case "bug324121_9@tests.mozilla.org": 1.95 + do_throw("Should not have seen an update check for " + aAddon.id); 1.96 + break; 1.97 + 1.98 + // app id incompatible update available 1.99 + case "bug324121_3@tests.mozilla.org": 1.100 + // update rdf not found 1.101 + case "bug324121_4@tests.mozilla.org": 1.102 + // toolkit id incompatible update available 1.103 + case "bug324121_7@tests.mozilla.org": 1.104 + // update rdf not found 1.105 + case "bug324121_8@tests.mozilla.org": 1.106 + break; 1.107 + 1.108 + // Updates available 1.109 + case "bug324121_2@tests.mozilla.org": 1.110 + case "bug324121_6@tests.mozilla.org": 1.111 + do_throw("Should be an update available for " + aAddon.id); 1.112 + break; 1.113 + 1.114 + default: 1.115 + do_throw("Update check for unknown " + aAddon.id); 1.116 + } 1.117 + 1.118 + // pos should always be >= 0 so just let this throw if this fails 1.119 + var pos = gItemsNotChecked.indexOf(aAddon.id); 1.120 + gItemsNotChecked.splice(pos, 1); 1.121 + }, 1.122 + 1.123 + onUpdateFinished: function onUpdateFinished(aAddon) { 1.124 + if (--this.pendingCount == 0) 1.125 + test_complete(); 1.126 + } 1.127 +}; 1.128 + 1.129 +function run_test() { 1.130 + do_test_pending(); 1.131 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); 1.132 + 1.133 + const dataDir = do_get_file("data"); 1.134 + 1.135 + // Create and configure the HTTP server. 1.136 + testserver = new HttpServer(); 1.137 + testserver.registerDirectory("/data/", dataDir); 1.138 + testserver.start(4444); 1.139 + 1.140 + startupManager(); 1.141 + 1.142 + installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() { 1.143 + restartManager(); 1.144 + AddonManager.getAddonByID(ADDONS[0].id, callback_soon(function(addon) { 1.145 + do_check_true(!(!addon)); 1.146 + addon.userDisabled = true; 1.147 + restartManager(); 1.148 + 1.149 + AddonManager.getAddonsByTypes(["extension"], function(installedItems) { 1.150 + var items = []; 1.151 + 1.152 + for (let addon of ADDONS) { 1.153 + for (let installedItem of installedItems) { 1.154 + if (addon.id != installedItem.id) 1.155 + continue; 1.156 + if (installedItem.userDisabled) 1.157 + continue; 1.158 + 1.159 + if (addon.shouldCheck == installedItem.isCompatibleWith("3", "3")) { 1.160 + do_throw(installedItem.id + " had the wrong compatibility: " + 1.161 + installedItem.isCompatibleWith("3", "3")); 1.162 + } 1.163 + 1.164 + if (addon.shouldCheck) { 1.165 + gItemsNotChecked.push(addon.id); 1.166 + updateListener.pendingCount++; 1.167 + installedItem.findUpdates(updateListener, 1.168 + AddonManager.UPDATE_WHEN_USER_REQUESTED, 1.169 + "3", "3"); 1.170 + } 1.171 + } 1.172 + } 1.173 + }); 1.174 + })); 1.175 + }); 1.176 +} 1.177 + 1.178 +function test_complete() { 1.179 + do_check_eq(gItemsNotChecked.length, 0); 1.180 + testserver.stop(do_test_finished); 1.181 +}