toolkit/mozapps/extensions/test/xpcshell/test_bug324121.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4 */
michael@0 5
michael@0 6 // Disables security checking our updates which haven't been signed
michael@0 7 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
michael@0 8
michael@0 9 // Get the HTTP server.
michael@0 10 Components.utils.import("resource://testing-common/httpd.js");
michael@0 11 var testserver;
michael@0 12
michael@0 13 var next_test = null;
michael@0 14 var gItemsNotChecked =[];
michael@0 15
michael@0 16 var ADDONS = [ {id: "bug324121_1@tests.mozilla.org",
michael@0 17 addon: "test_bug324121_1",
michael@0 18 shouldCheck: false },
michael@0 19 {id: "bug324121_2@tests.mozilla.org",
michael@0 20 addon: "test_bug324121_2",
michael@0 21 shouldCheck: true },
michael@0 22 {id: "bug324121_3@tests.mozilla.org",
michael@0 23 addon: "test_bug324121_3",
michael@0 24 shouldCheck: true },
michael@0 25 {id: "bug324121_4@tests.mozilla.org",
michael@0 26 addon: "test_bug324121_4",
michael@0 27 shouldCheck: true },
michael@0 28 {id: "bug324121_5@tests.mozilla.org",
michael@0 29 addon: "test_bug324121_5",
michael@0 30 shouldCheck: false },
michael@0 31 {id: "bug324121_6@tests.mozilla.org",
michael@0 32 addon: "test_bug324121_6",
michael@0 33 shouldCheck: true },
michael@0 34 {id: "bug324121_7@tests.mozilla.org",
michael@0 35 addon: "test_bug324121_7",
michael@0 36 shouldCheck: true },
michael@0 37 {id: "bug324121_8@tests.mozilla.org",
michael@0 38 addon: "test_bug324121_8",
michael@0 39 shouldCheck: true },
michael@0 40 {id: "bug324121_9@tests.mozilla.org",
michael@0 41 addon: "test_bug324121_9",
michael@0 42 shouldCheck: false } ];
michael@0 43
michael@0 44 // nsIAddonUpdateCheckListener
michael@0 45 var updateListener = {
michael@0 46 pendingCount: 0,
michael@0 47
michael@0 48 onUpdateAvailable: function onAddonUpdateEnded(aAddon) {
michael@0 49 switch (aAddon.id) {
michael@0 50 // add-on disabled - should not happen
michael@0 51 case "bug324121_1@tests.mozilla.org":
michael@0 52 // app id already compatible - should not happen
michael@0 53 case "bug324121_5@tests.mozilla.org":
michael@0 54 // toolkit id already compatible - should not happen
michael@0 55 case "bug324121_9@tests.mozilla.org":
michael@0 56 do_throw("Should not have seen an update check for " + aAddon.id);
michael@0 57 break;
michael@0 58
michael@0 59 // app id incompatible update available
michael@0 60 case "bug324121_3@tests.mozilla.org":
michael@0 61 // update rdf not found
michael@0 62 case "bug324121_4@tests.mozilla.org":
michael@0 63 // toolkit id incompatible update available
michael@0 64 case "bug324121_7@tests.mozilla.org":
michael@0 65 // update rdf not found
michael@0 66 case "bug324121_8@tests.mozilla.org":
michael@0 67 do_throw("Should be no update available for " + aAddon.id);
michael@0 68 break;
michael@0 69
michael@0 70 // Updates available
michael@0 71 case "bug324121_2@tests.mozilla.org":
michael@0 72 case "bug324121_6@tests.mozilla.org":
michael@0 73 break;
michael@0 74
michael@0 75 default:
michael@0 76 do_throw("Update check for unknown " + aAddon.id);
michael@0 77 }
michael@0 78
michael@0 79 // pos should always be >= 0 so just let this throw if this fails
michael@0 80 var pos = gItemsNotChecked.indexOf(aAddon.id);
michael@0 81 gItemsNotChecked.splice(pos, 1);
michael@0 82 },
michael@0 83
michael@0 84 onNoUpdateAvailable: function onNoUpdateAvailable(aAddon) {
michael@0 85 switch (aAddon.id) {
michael@0 86 // add-on disabled - should not happen
michael@0 87 case "bug324121_1@tests.mozilla.org":
michael@0 88 // app id already compatible - should not happen
michael@0 89 case "bug324121_5@tests.mozilla.org":
michael@0 90 // toolkit id already compatible - should not happen
michael@0 91 case "bug324121_9@tests.mozilla.org":
michael@0 92 do_throw("Should not have seen an update check for " + aAddon.id);
michael@0 93 break;
michael@0 94
michael@0 95 // app id incompatible update available
michael@0 96 case "bug324121_3@tests.mozilla.org":
michael@0 97 // update rdf not found
michael@0 98 case "bug324121_4@tests.mozilla.org":
michael@0 99 // toolkit id incompatible update available
michael@0 100 case "bug324121_7@tests.mozilla.org":
michael@0 101 // update rdf not found
michael@0 102 case "bug324121_8@tests.mozilla.org":
michael@0 103 break;
michael@0 104
michael@0 105 // Updates available
michael@0 106 case "bug324121_2@tests.mozilla.org":
michael@0 107 case "bug324121_6@tests.mozilla.org":
michael@0 108 do_throw("Should be an update available for " + aAddon.id);
michael@0 109 break;
michael@0 110
michael@0 111 default:
michael@0 112 do_throw("Update check for unknown " + aAddon.id);
michael@0 113 }
michael@0 114
michael@0 115 // pos should always be >= 0 so just let this throw if this fails
michael@0 116 var pos = gItemsNotChecked.indexOf(aAddon.id);
michael@0 117 gItemsNotChecked.splice(pos, 1);
michael@0 118 },
michael@0 119
michael@0 120 onUpdateFinished: function onUpdateFinished(aAddon) {
michael@0 121 if (--this.pendingCount == 0)
michael@0 122 test_complete();
michael@0 123 }
michael@0 124 };
michael@0 125
michael@0 126 function run_test() {
michael@0 127 do_test_pending();
michael@0 128 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
michael@0 129
michael@0 130 const dataDir = do_get_file("data");
michael@0 131
michael@0 132 // Create and configure the HTTP server.
michael@0 133 testserver = new HttpServer();
michael@0 134 testserver.registerDirectory("/data/", dataDir);
michael@0 135 testserver.start(4444);
michael@0 136
michael@0 137 startupManager();
michael@0 138
michael@0 139 installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], function() {
michael@0 140 restartManager();
michael@0 141 AddonManager.getAddonByID(ADDONS[0].id, callback_soon(function(addon) {
michael@0 142 do_check_true(!(!addon));
michael@0 143 addon.userDisabled = true;
michael@0 144 restartManager();
michael@0 145
michael@0 146 AddonManager.getAddonsByTypes(["extension"], function(installedItems) {
michael@0 147 var items = [];
michael@0 148
michael@0 149 for (let addon of ADDONS) {
michael@0 150 for (let installedItem of installedItems) {
michael@0 151 if (addon.id != installedItem.id)
michael@0 152 continue;
michael@0 153 if (installedItem.userDisabled)
michael@0 154 continue;
michael@0 155
michael@0 156 if (addon.shouldCheck == installedItem.isCompatibleWith("3", "3")) {
michael@0 157 do_throw(installedItem.id + " had the wrong compatibility: " +
michael@0 158 installedItem.isCompatibleWith("3", "3"));
michael@0 159 }
michael@0 160
michael@0 161 if (addon.shouldCheck) {
michael@0 162 gItemsNotChecked.push(addon.id);
michael@0 163 updateListener.pendingCount++;
michael@0 164 installedItem.findUpdates(updateListener,
michael@0 165 AddonManager.UPDATE_WHEN_USER_REQUESTED,
michael@0 166 "3", "3");
michael@0 167 }
michael@0 168 }
michael@0 169 }
michael@0 170 });
michael@0 171 }));
michael@0 172 });
michael@0 173 }
michael@0 174
michael@0 175 function test_complete() {
michael@0 176 do_check_eq(gItemsNotChecked.length, 0);
michael@0 177 testserver.stop(do_test_finished);
michael@0 178 }

mercurial