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 | // Tests that attempting to install a corrupt XPI file doesn't break the universe |
michael@0 | 6 | |
michael@0 | 7 | const profileDir = gProfD.clone(); |
michael@0 | 8 | profileDir.append("extensions"); |
michael@0 | 9 | |
michael@0 | 10 | function run_test() { |
michael@0 | 11 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); |
michael@0 | 12 | |
michael@0 | 13 | startupManager(); |
michael@0 | 14 | |
michael@0 | 15 | if (TEST_UNPACKED) |
michael@0 | 16 | run_test_unpacked(); |
michael@0 | 17 | else |
michael@0 | 18 | run_test_packed(); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | // When installing packed we won't detect corruption in the XPI until we attempt |
michael@0 | 22 | // to load bootstrap.js so everything will look normal from the outside. |
michael@0 | 23 | function run_test_packed() { |
michael@0 | 24 | do_test_pending(); |
michael@0 | 25 | |
michael@0 | 26 | prepare_test({ |
michael@0 | 27 | "corrupt@tests.mozilla.org": [ |
michael@0 | 28 | ["onInstalling", false], |
michael@0 | 29 | ["onInstalled", false] |
michael@0 | 30 | ] |
michael@0 | 31 | }, [ |
michael@0 | 32 | "onNewInstall", |
michael@0 | 33 | "onInstallStarted", |
michael@0 | 34 | "onInstallEnded" |
michael@0 | 35 | ]); |
michael@0 | 36 | |
michael@0 | 37 | installAllFiles([do_get_file("data/corruptfile.xpi")], function() { |
michael@0 | 38 | ensure_test_completed(); |
michael@0 | 39 | |
michael@0 | 40 | AddonManager.getAddonByID("corrupt@tests.mozilla.org", function(addon) { |
michael@0 | 41 | do_check_neq(addon, null); |
michael@0 | 42 | |
michael@0 | 43 | do_test_finished(); |
michael@0 | 44 | }); |
michael@0 | 45 | }); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | // When extracting the corruption will be detected and the add-on fails to |
michael@0 | 49 | // install |
michael@0 | 50 | function run_test_unpacked() { |
michael@0 | 51 | do_test_pending(); |
michael@0 | 52 | |
michael@0 | 53 | prepare_test({ |
michael@0 | 54 | "corrupt@tests.mozilla.org": [ |
michael@0 | 55 | ["onInstalling", false], |
michael@0 | 56 | "onOperationCancelled" |
michael@0 | 57 | ] |
michael@0 | 58 | }, [ |
michael@0 | 59 | "onNewInstall", |
michael@0 | 60 | "onInstallStarted", |
michael@0 | 61 | "onInstallFailed" |
michael@0 | 62 | ]); |
michael@0 | 63 | |
michael@0 | 64 | installAllFiles([do_get_file("data/corruptfile.xpi")], function() { |
michael@0 | 65 | ensure_test_completed(); |
michael@0 | 66 | |
michael@0 | 67 | // Check the add-on directory isn't left over |
michael@0 | 68 | var addonDir = profileDir.clone(); |
michael@0 | 69 | addonDir.append("corrupt@tests.mozilla.org"); |
michael@0 | 70 | pathShouldntExist(addonDir); |
michael@0 | 71 | |
michael@0 | 72 | // Check the staging directory isn't left over |
michael@0 | 73 | var stageDir = profileDir.clone(); |
michael@0 | 74 | stageDir.append("staged"); |
michael@0 | 75 | pathShouldntExist(stageDir); |
michael@0 | 76 | |
michael@0 | 77 | AddonManager.getAddonByID("corrupt@tests.mozilla.org", function(addon) { |
michael@0 | 78 | do_check_eq(addon, null); |
michael@0 | 79 | |
michael@0 | 80 | do_test_finished(); |
michael@0 | 81 | }); |
michael@0 | 82 | }); |
michael@0 | 83 | } |