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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // This verifies that hotfix installation works |
michael@0 | 6 | |
michael@0 | 7 | // The test extension uses an insecure update url. |
michael@0 | 8 | Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
michael@0 | 9 | // Ignore any certificate requirements the app has set |
michael@0 | 10 | Services.prefs.setBoolPref("extensions.hotfix.cert.checkAttributes", false); |
michael@0 | 11 | |
michael@0 | 12 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 13 | var testserver = new HttpServer(); |
michael@0 | 14 | testserver.start(-1); |
michael@0 | 15 | gPort = testserver.identity.primaryPort; |
michael@0 | 16 | testserver.registerDirectory("/addons/", do_get_file("addons")); |
michael@0 | 17 | mapFile("/data/test_hotfix_1.rdf", testserver); |
michael@0 | 18 | mapFile("/data/test_hotfix_2.rdf", testserver); |
michael@0 | 19 | mapFile("/data/test_hotfix_3.rdf", testserver); |
michael@0 | 20 | |
michael@0 | 21 | const profileDir = gProfD.clone(); |
michael@0 | 22 | profileDir.append("extensions"); |
michael@0 | 23 | |
michael@0 | 24 | function run_test() { |
michael@0 | 25 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 26 | |
michael@0 | 27 | startupManager(); |
michael@0 | 28 | |
michael@0 | 29 | do_test_pending(); |
michael@0 | 30 | run_test_1(); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function end_test() { |
michael@0 | 34 | testserver.stop(do_test_finished); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | // Test that background updates find and install any available hotfix |
michael@0 | 38 | function run_test_1() { |
michael@0 | 39 | Services.prefs.setCharPref("extensions.hotfix.id", "hotfix@tests.mozilla.org"); |
michael@0 | 40 | Services.prefs.setCharPref("extensions.update.background.url", "http://localhost:" + |
michael@0 | 41 | gPort + "/data/test_hotfix_1.rdf"); |
michael@0 | 42 | |
michael@0 | 43 | prepare_test({ |
michael@0 | 44 | "hotfix@tests.mozilla.org": [ |
michael@0 | 45 | "onInstalling" |
michael@0 | 46 | ] |
michael@0 | 47 | }, [ |
michael@0 | 48 | "onNewInstall", |
michael@0 | 49 | "onDownloadStarted", |
michael@0 | 50 | "onDownloadEnded", |
michael@0 | 51 | "onInstallStarted", |
michael@0 | 52 | "onInstallEnded", |
michael@0 | 53 | ], callback_soon(check_test_1)); |
michael@0 | 54 | |
michael@0 | 55 | // Fake a timer event |
michael@0 | 56 | gInternalManager.notify(null); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function check_test_1() { |
michael@0 | 60 | restartManager(); |
michael@0 | 61 | |
michael@0 | 62 | AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) { |
michael@0 | 63 | do_check_neq(aAddon, null); |
michael@0 | 64 | do_check_eq(aAddon.version, "1.0"); |
michael@0 | 65 | |
michael@0 | 66 | aAddon.uninstall(); |
michael@0 | 67 | do_execute_soon(run_test_2); |
michael@0 | 68 | }); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | // Don't install an already used hotfix |
michael@0 | 72 | function run_test_2() { |
michael@0 | 73 | restartManager(); |
michael@0 | 74 | |
michael@0 | 75 | AddonManager.addInstallListener({ |
michael@0 | 76 | onNewInstall: function() { |
michael@0 | 77 | do_throw("Should not have seen a new install created"); |
michael@0 | 78 | } |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | function observer() { |
michael@0 | 82 | Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); |
michael@0 | 83 | do_execute_soon(run_test_3); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | Services.obs.addObserver(observer, "addons-background-update-complete", false); |
michael@0 | 87 | |
michael@0 | 88 | // Fake a timer event |
michael@0 | 89 | gInternalManager.notify(null); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | // Install a newer hotfix |
michael@0 | 93 | function run_test_3() { |
michael@0 | 94 | restartManager(); |
michael@0 | 95 | Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + |
michael@0 | 96 | gPort + "/data/test_hotfix_2.rdf"); |
michael@0 | 97 | |
michael@0 | 98 | prepare_test({ |
michael@0 | 99 | "hotfix@tests.mozilla.org": [ |
michael@0 | 100 | "onInstalling" |
michael@0 | 101 | ] |
michael@0 | 102 | }, [ |
michael@0 | 103 | "onNewInstall", |
michael@0 | 104 | "onDownloadStarted", |
michael@0 | 105 | "onDownloadEnded", |
michael@0 | 106 | "onInstallStarted", |
michael@0 | 107 | "onInstallEnded", |
michael@0 | 108 | ], callback_soon(check_test_3)); |
michael@0 | 109 | |
michael@0 | 110 | // Fake a timer event |
michael@0 | 111 | gInternalManager.notify(null); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function check_test_3() { |
michael@0 | 115 | restartManager(); |
michael@0 | 116 | |
michael@0 | 117 | AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) { |
michael@0 | 118 | do_check_neq(aAddon, null); |
michael@0 | 119 | do_check_eq(aAddon.version, "2.0"); |
michael@0 | 120 | |
michael@0 | 121 | aAddon.uninstall(); |
michael@0 | 122 | do_execute_soon(run_test_4); |
michael@0 | 123 | }); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | // Don't install an incompatible hotfix |
michael@0 | 127 | function run_test_4() { |
michael@0 | 128 | restartManager(); |
michael@0 | 129 | |
michael@0 | 130 | Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + |
michael@0 | 131 | gPort + "/data/test_hotfix_3.rdf"); |
michael@0 | 132 | |
michael@0 | 133 | AddonManager.addInstallListener({ |
michael@0 | 134 | onNewInstall: function() { |
michael@0 | 135 | do_throw("Should not have seen a new install created"); |
michael@0 | 136 | } |
michael@0 | 137 | }); |
michael@0 | 138 | |
michael@0 | 139 | function observer() { |
michael@0 | 140 | Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); |
michael@0 | 141 | do_execute_soon(run_test_5); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | Services.obs.addObserver(observer, "addons-background-update-complete", false); |
michael@0 | 145 | |
michael@0 | 146 | // Fake a timer event |
michael@0 | 147 | gInternalManager.notify(null); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | // Don't install an older hotfix |
michael@0 | 151 | function run_test_5() { |
michael@0 | 152 | restartManager(); |
michael@0 | 153 | |
michael@0 | 154 | Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + |
michael@0 | 155 | gPort + "/data/test_hotfix_1.rdf"); |
michael@0 | 156 | |
michael@0 | 157 | AddonManager.addInstallListener({ |
michael@0 | 158 | onNewInstall: function() { |
michael@0 | 159 | do_throw("Should not have seen a new install created"); |
michael@0 | 160 | } |
michael@0 | 161 | }); |
michael@0 | 162 | |
michael@0 | 163 | function observer() { |
michael@0 | 164 | Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); |
michael@0 | 165 | do_execute_soon(run_test_6); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | Services.obs.addObserver(observer, "addons-background-update-complete", false); |
michael@0 | 169 | |
michael@0 | 170 | // Fake a timer event |
michael@0 | 171 | gInternalManager.notify(null); |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | // Don't re-download an already pending install |
michael@0 | 175 | function run_test_6() { |
michael@0 | 176 | restartManager(); |
michael@0 | 177 | |
michael@0 | 178 | Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0"); |
michael@0 | 179 | Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + |
michael@0 | 180 | gPort + "/data/test_hotfix_1.rdf"); |
michael@0 | 181 | |
michael@0 | 182 | prepare_test({ |
michael@0 | 183 | "hotfix@tests.mozilla.org": [ |
michael@0 | 184 | "onInstalling" |
michael@0 | 185 | ] |
michael@0 | 186 | }, [ |
michael@0 | 187 | "onNewInstall", |
michael@0 | 188 | "onDownloadStarted", |
michael@0 | 189 | "onDownloadEnded", |
michael@0 | 190 | "onInstallStarted", |
michael@0 | 191 | "onInstallEnded", |
michael@0 | 192 | ], callback_soon(check_test_6)); |
michael@0 | 193 | |
michael@0 | 194 | // Fake a timer event |
michael@0 | 195 | gInternalManager.notify(null); |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | function check_test_6() { |
michael@0 | 199 | AddonManager.addInstallListener({ |
michael@0 | 200 | onNewInstall: function() { |
michael@0 | 201 | do_throw("Should not have seen a new install created"); |
michael@0 | 202 | } |
michael@0 | 203 | }); |
michael@0 | 204 | |
michael@0 | 205 | function observer() { |
michael@0 | 206 | Services.obs.removeObserver(arguments.callee, "addons-background-update-complete"); |
michael@0 | 207 | restartManager(); |
michael@0 | 208 | |
michael@0 | 209 | AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) { |
michael@0 | 210 | aAddon.uninstall(); |
michael@0 | 211 | do_execute_soon(run_test_7); |
michael@0 | 212 | }); |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | Services.obs.addObserver(observer, "addons-background-update-complete", false); |
michael@0 | 216 | |
michael@0 | 217 | // Fake a timer event |
michael@0 | 218 | gInternalManager.notify(null); |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | // Start downloading again if something cancels the install |
michael@0 | 222 | function run_test_7() { |
michael@0 | 223 | restartManager(); |
michael@0 | 224 | |
michael@0 | 225 | Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0"); |
michael@0 | 226 | |
michael@0 | 227 | prepare_test({ |
michael@0 | 228 | "hotfix@tests.mozilla.org": [ |
michael@0 | 229 | "onInstalling" |
michael@0 | 230 | ] |
michael@0 | 231 | }, [ |
michael@0 | 232 | "onNewInstall", |
michael@0 | 233 | "onDownloadStarted", |
michael@0 | 234 | "onDownloadEnded", |
michael@0 | 235 | "onInstallStarted", |
michael@0 | 236 | "onInstallEnded", |
michael@0 | 237 | ], check_test_7); |
michael@0 | 238 | |
michael@0 | 239 | // Fake a timer event |
michael@0 | 240 | gInternalManager.notify(null); |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | function check_test_7(aInstall) { |
michael@0 | 244 | prepare_test({ |
michael@0 | 245 | "hotfix@tests.mozilla.org": [ |
michael@0 | 246 | "onOperationCancelled" |
michael@0 | 247 | ] |
michael@0 | 248 | }, [ |
michael@0 | 249 | "onInstallCancelled", |
michael@0 | 250 | ]); |
michael@0 | 251 | |
michael@0 | 252 | aInstall.cancel(); |
michael@0 | 253 | |
michael@0 | 254 | prepare_test({ |
michael@0 | 255 | "hotfix@tests.mozilla.org": [ |
michael@0 | 256 | "onInstalling" |
michael@0 | 257 | ] |
michael@0 | 258 | }, [ |
michael@0 | 259 | "onNewInstall", |
michael@0 | 260 | "onDownloadStarted", |
michael@0 | 261 | "onDownloadEnded", |
michael@0 | 262 | "onInstallStarted", |
michael@0 | 263 | "onInstallEnded", |
michael@0 | 264 | ], callback_soon(finish_test_7)); |
michael@0 | 265 | |
michael@0 | 266 | // Fake a timer event |
michael@0 | 267 | gInternalManager.notify(null); |
michael@0 | 268 | } |
michael@0 | 269 | |
michael@0 | 270 | function finish_test_7() { |
michael@0 | 271 | restartManager(); |
michael@0 | 272 | |
michael@0 | 273 | AddonManager.getAddonByID("hotfix@tests.mozilla.org", function(aAddon) { |
michael@0 | 274 | do_check_neq(aAddon, null); |
michael@0 | 275 | do_check_eq(aAddon.version, "1.0"); |
michael@0 | 276 | |
michael@0 | 277 | aAddon.uninstall(); |
michael@0 | 278 | do_execute_soon(run_test_8); |
michael@0 | 279 | }); |
michael@0 | 280 | } |
michael@0 | 281 | |
michael@0 | 282 | // Cancel a pending install when a newer version is already available |
michael@0 | 283 | function run_test_8() { |
michael@0 | 284 | restartManager(); |
michael@0 | 285 | |
michael@0 | 286 | Services.prefs.setCharPref("extensions.hotfix.lastVersion", "0"); |
michael@0 | 287 | Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + |
michael@0 | 288 | gPort + "/data/test_hotfix_1.rdf"); |
michael@0 | 289 | |
michael@0 | 290 | prepare_test({ |
michael@0 | 291 | "hotfix@tests.mozilla.org": [ |
michael@0 | 292 | "onInstalling" |
michael@0 | 293 | ] |
michael@0 | 294 | }, [ |
michael@0 | 295 | "onNewInstall", |
michael@0 | 296 | "onDownloadStarted", |
michael@0 | 297 | "onDownloadEnded", |
michael@0 | 298 | "onInstallStarted", |
michael@0 | 299 | "onInstallEnded", |
michael@0 | 300 | ], check_test_8); |
michael@0 | 301 | |
michael@0 | 302 | // Fake a timer event |
michael@0 | 303 | gInternalManager.notify(null); |
michael@0 | 304 | } |
michael@0 | 305 | |
michael@0 | 306 | function check_test_8() { |
michael@0 | 307 | Services.prefs.setCharPref("extensions.hotfix.url", "http://localhost:" + |
michael@0 | 308 | gPort + "/data/test_hotfix_2.rdf"); |
michael@0 | 309 | |
michael@0 | 310 | prepare_test({ |
michael@0 | 311 | "hotfix@tests.mozilla.org": [ |
michael@0 | 312 | "onOperationCancelled", |
michael@0 | 313 | "onInstalling" |
michael@0 | 314 | ] |
michael@0 | 315 | }, [ |
michael@0 | 316 | "onNewInstall", |
michael@0 | 317 | "onDownloadStarted", |
michael@0 | 318 | "onDownloadEnded", |
michael@0 | 319 | "onInstallStarted", |
michael@0 | 320 | "onInstallCancelled", |
michael@0 | 321 | "onInstallEnded", |
michael@0 | 322 | ], finish_test_8); |
michael@0 | 323 | |
michael@0 | 324 | // Fake a timer event |
michael@0 | 325 | gInternalManager.notify(null); |
michael@0 | 326 | } |
michael@0 | 327 | |
michael@0 | 328 | function finish_test_8() { |
michael@0 | 329 | AddonManager.getAllInstalls(callback_soon(function(aInstalls) { |
michael@0 | 330 | do_check_eq(aInstalls.length, 1); |
michael@0 | 331 | do_check_eq(aInstalls[0].version, "2.0"); |
michael@0 | 332 | |
michael@0 | 333 | restartManager(); |
michael@0 | 334 | |
michael@0 | 335 | AddonManager.getAddonByID("hotfix@tests.mozilla.org", callback_soon(function(aAddon) { |
michael@0 | 336 | do_check_neq(aAddon, null); |
michael@0 | 337 | do_check_eq(aAddon.version, "2.0"); |
michael@0 | 338 | |
michael@0 | 339 | aAddon.uninstall(); |
michael@0 | 340 | restartManager(); |
michael@0 | 341 | |
michael@0 | 342 | end_test(); |
michael@0 | 343 | })); |
michael@0 | 344 | })); |
michael@0 | 345 | } |