Wed, 31 Dec 2014 06:09:35 +0100
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 | // Update check listener. |
michael@0 | 10 | const checkListener = { |
michael@0 | 11 | pendingCount: 0, |
michael@0 | 12 | |
michael@0 | 13 | onUpdateAvailable: function onUpdateAvailable(aAddon, aInstall) { |
michael@0 | 14 | for (let currentAddon of ADDONS) { |
michael@0 | 15 | if (currentAddon.id == aAddon.id) { |
michael@0 | 16 | currentAddon.newInstall = aInstall; |
michael@0 | 17 | return; |
michael@0 | 18 | } |
michael@0 | 19 | } |
michael@0 | 20 | }, |
michael@0 | 21 | |
michael@0 | 22 | onUpdateFinished: function onUpdateFinished() { |
michael@0 | 23 | if (--this.pendingCount == 0) |
michael@0 | 24 | next_test(); |
michael@0 | 25 | } |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | // Get the HTTP server. |
michael@0 | 29 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 30 | var testserver; |
michael@0 | 31 | |
michael@0 | 32 | var ADDONS = [ |
michael@0 | 33 | // XPCShell |
michael@0 | 34 | { |
michael@0 | 35 | id: "bug299716-a@tests.mozilla.org", |
michael@0 | 36 | addon: "test_bug299716_a_1", |
michael@0 | 37 | installed: true, |
michael@0 | 38 | item: null, |
michael@0 | 39 | newInstall: null |
michael@0 | 40 | }, |
michael@0 | 41 | |
michael@0 | 42 | // Toolkit |
michael@0 | 43 | { |
michael@0 | 44 | id: "bug299716-b@tests.mozilla.org", |
michael@0 | 45 | addon: "test_bug299716_b_1", |
michael@0 | 46 | installed: true, |
michael@0 | 47 | item: null, |
michael@0 | 48 | newInstall: null |
michael@0 | 49 | }, |
michael@0 | 50 | |
michael@0 | 51 | // XPCShell + Toolkit |
michael@0 | 52 | { |
michael@0 | 53 | id: "bug299716-c@tests.mozilla.org", |
michael@0 | 54 | addon: "test_bug299716_c_1", |
michael@0 | 55 | installed: true, |
michael@0 | 56 | item: null, |
michael@0 | 57 | newInstall: null |
michael@0 | 58 | }, |
michael@0 | 59 | |
michael@0 | 60 | // XPCShell (Toolkit invalid) |
michael@0 | 61 | { |
michael@0 | 62 | id: "bug299716-d@tests.mozilla.org", |
michael@0 | 63 | addon: "test_bug299716_d_1", |
michael@0 | 64 | installed: true, |
michael@0 | 65 | item: null, |
michael@0 | 66 | newInstall: null |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | // Toolkit (XPCShell invalid) |
michael@0 | 70 | { |
michael@0 | 71 | id: "bug299716-e@tests.mozilla.org", |
michael@0 | 72 | addon: "test_bug299716_e_1", |
michael@0 | 73 | installed: false, |
michael@0 | 74 | item: null, |
michael@0 | 75 | newInstall: null, |
michael@0 | 76 | failedAppName: "XPCShell" |
michael@0 | 77 | }, |
michael@0 | 78 | |
michael@0 | 79 | // None (XPCShell, Toolkit invalid) |
michael@0 | 80 | { |
michael@0 | 81 | id: "bug299716-f@tests.mozilla.org", |
michael@0 | 82 | addon: "test_bug299716_f_1", |
michael@0 | 83 | installed: false, |
michael@0 | 84 | item: null, |
michael@0 | 85 | newInstall: null, |
michael@0 | 86 | failedAppName: "XPCShell" |
michael@0 | 87 | }, |
michael@0 | 88 | |
michael@0 | 89 | // None (Toolkit invalid) |
michael@0 | 90 | { |
michael@0 | 91 | id: "bug299716-g@tests.mozilla.org", |
michael@0 | 92 | addon: "test_bug299716_g_1", |
michael@0 | 93 | installed: false, |
michael@0 | 94 | item: null, |
michael@0 | 95 | newInstall: null, |
michael@0 | 96 | failedAppName: "Toolkit" |
michael@0 | 97 | }, |
michael@0 | 98 | ]; |
michael@0 | 99 | |
michael@0 | 100 | var next_test = function() {}; |
michael@0 | 101 | |
michael@0 | 102 | function do_check_item(aItem, aVersion, aAddonsEntry) { |
michael@0 | 103 | if (aAddonsEntry.installed) { |
michael@0 | 104 | if (aItem == null) |
michael@0 | 105 | do_throw("Addon " + aAddonsEntry.id + " wasn't detected"); |
michael@0 | 106 | if (aItem.version != aVersion) |
michael@0 | 107 | do_throw("Addon " + aAddonsEntry.id + " was version " + aItem.version + " instead of " + aVersion); |
michael@0 | 108 | } else { |
michael@0 | 109 | if (aItem != null) |
michael@0 | 110 | do_throw("Addon " + aAddonsEntry.id + " was detected"); |
michael@0 | 111 | } |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * Start the test by installing extensions. |
michael@0 | 116 | */ |
michael@0 | 117 | function run_test() { |
michael@0 | 118 | do_test_pending(); |
michael@0 | 119 | |
michael@0 | 120 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "5", "1.9"); |
michael@0 | 121 | |
michael@0 | 122 | const dataDir = do_get_file("data"); |
michael@0 | 123 | const addonsDir = do_get_addon(ADDONS[0].addon).parent; |
michael@0 | 124 | |
michael@0 | 125 | // Make sure we can actually get our data files. |
michael@0 | 126 | const xpiFile = addonsDir.clone(); |
michael@0 | 127 | xpiFile.append("test_bug299716_a_2.xpi"); |
michael@0 | 128 | do_check_true(xpiFile.exists()); |
michael@0 | 129 | |
michael@0 | 130 | // Create and configure the HTTP server. |
michael@0 | 131 | testserver = new HttpServer(); |
michael@0 | 132 | testserver.registerDirectory("/addons/", addonsDir); |
michael@0 | 133 | testserver.registerDirectory("/data/", dataDir); |
michael@0 | 134 | testserver.start(4444); |
michael@0 | 135 | |
michael@0 | 136 | // Make sure we can fetch the files over HTTP. |
michael@0 | 137 | const Ci = Components.interfaces; |
michael@0 | 138 | const xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] |
michael@0 | 139 | .createInstance(Ci.nsIXMLHttpRequest) |
michael@0 | 140 | xhr.open("GET", "http://localhost:4444/addons/test_bug299716_a_2.xpi", false); |
michael@0 | 141 | xhr.send(null); |
michael@0 | 142 | do_check_true(xhr.status == 200); |
michael@0 | 143 | |
michael@0 | 144 | xhr.open("GET", "http://localhost:4444/data/test_bug299716.rdf", false); |
michael@0 | 145 | xhr.send(null); |
michael@0 | 146 | do_check_true(xhr.status == 200); |
michael@0 | 147 | |
michael@0 | 148 | // Start the real test. |
michael@0 | 149 | startupManager(); |
michael@0 | 150 | dump("\n\n*** INSTALLING NEW ITEMS\n\n"); |
michael@0 | 151 | |
michael@0 | 152 | installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], run_test_pt2, |
michael@0 | 153 | true); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | /** |
michael@0 | 157 | * Check the versions of all items, and ask the extension manager to find updates. |
michael@0 | 158 | */ |
michael@0 | 159 | function run_test_pt2() { |
michael@0 | 160 | dump("\n\n*** DONE INSTALLING NEW ITEMS\n\n"); |
michael@0 | 161 | dump("\n\n*** RESTARTING EXTENSION MANAGER\n\n"); |
michael@0 | 162 | restartManager(); |
michael@0 | 163 | |
michael@0 | 164 | AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(items) { |
michael@0 | 165 | dump("\n\n*** REQUESTING UPDATE\n\n"); |
michael@0 | 166 | // checkListener will call run_test_pt3(). |
michael@0 | 167 | next_test = run_test_pt3; |
michael@0 | 168 | |
michael@0 | 169 | // Try to update the items. |
michael@0 | 170 | for (var i = 0; i < ADDONS.length; i++) { |
michael@0 | 171 | var item = items[i]; |
michael@0 | 172 | do_check_item(item, "0.1", ADDONS[i]); |
michael@0 | 173 | |
michael@0 | 174 | if (item) { |
michael@0 | 175 | checkListener.pendingCount++; |
michael@0 | 176 | ADDONS[i].item = item; |
michael@0 | 177 | item.findUpdates(checkListener, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
michael@0 | 178 | } |
michael@0 | 179 | } |
michael@0 | 180 | }); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | /** |
michael@0 | 184 | * Install new items for each enabled extension. |
michael@0 | 185 | */ |
michael@0 | 186 | function run_test_pt3() { |
michael@0 | 187 | // Install the new items. |
michael@0 | 188 | dump("\n\n*** UPDATING ITEMS\n\n"); |
michael@0 | 189 | completeAllInstalls([a.newInstall for each(a in ADDONS) if (a.newInstall)], |
michael@0 | 190 | run_test_pt4); |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | /** |
michael@0 | 194 | * Check the final version of each extension. |
michael@0 | 195 | */ |
michael@0 | 196 | function run_test_pt4() { |
michael@0 | 197 | dump("\n\n*** RESTARTING EXTENSION MANAGER\n\n"); |
michael@0 | 198 | restartManager(); |
michael@0 | 199 | |
michael@0 | 200 | dump("\n\n*** FINAL CHECKS\n\n"); |
michael@0 | 201 | AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(items) { |
michael@0 | 202 | for (var i = 0; i < ADDONS.length; i++) { |
michael@0 | 203 | var item = items[i]; |
michael@0 | 204 | do_check_item(item, "0.2", ADDONS[i]); |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | testserver.stop(do_test_finished); |
michael@0 | 208 | }); |
michael@0 | 209 | } |