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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_corruptfile.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +// Tests that attempting to install a corrupt XPI file doesn't break the universe
     1.9 +
    1.10 +const profileDir = gProfD.clone();
    1.11 +profileDir.append("extensions");
    1.12 +
    1.13 +function run_test() {
    1.14 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
    1.15 +
    1.16 +  startupManager();
    1.17 +
    1.18 +  if (TEST_UNPACKED)
    1.19 +    run_test_unpacked();
    1.20 +  else
    1.21 +    run_test_packed();
    1.22 +}
    1.23 +
    1.24 +// When installing packed we won't detect corruption in the XPI until we attempt
    1.25 +// to load bootstrap.js so everything will look normal from the outside.
    1.26 +function run_test_packed() {
    1.27 +  do_test_pending();
    1.28 +
    1.29 +  prepare_test({
    1.30 +    "corrupt@tests.mozilla.org": [
    1.31 +      ["onInstalling", false],
    1.32 +      ["onInstalled", false]
    1.33 +    ]
    1.34 +  }, [
    1.35 +    "onNewInstall",
    1.36 +    "onInstallStarted",
    1.37 +    "onInstallEnded"
    1.38 +  ]);
    1.39 +
    1.40 +  installAllFiles([do_get_file("data/corruptfile.xpi")], function() {
    1.41 +    ensure_test_completed();
    1.42 +
    1.43 +    AddonManager.getAddonByID("corrupt@tests.mozilla.org", function(addon) {
    1.44 +      do_check_neq(addon, null);
    1.45 +
    1.46 +      do_test_finished();
    1.47 +    });
    1.48 +  });
    1.49 +}
    1.50 +
    1.51 +// When extracting the corruption will be detected and the add-on fails to
    1.52 +// install
    1.53 +function run_test_unpacked() {
    1.54 +  do_test_pending();
    1.55 +
    1.56 +  prepare_test({
    1.57 +    "corrupt@tests.mozilla.org": [
    1.58 +      ["onInstalling", false],
    1.59 +      "onOperationCancelled"
    1.60 +    ]
    1.61 +  }, [
    1.62 +    "onNewInstall",
    1.63 +    "onInstallStarted",
    1.64 +    "onInstallFailed"
    1.65 +  ]);
    1.66 +
    1.67 +  installAllFiles([do_get_file("data/corruptfile.xpi")], function() {
    1.68 +    ensure_test_completed();
    1.69 +
    1.70 +    // Check the add-on directory isn't left over
    1.71 +    var addonDir = profileDir.clone();
    1.72 +    addonDir.append("corrupt@tests.mozilla.org");
    1.73 +    pathShouldntExist(addonDir);
    1.74 +
    1.75 +    // Check the staging directory isn't left over
    1.76 +    var stageDir = profileDir.clone();
    1.77 +    stageDir.append("staged");
    1.78 +    pathShouldntExist(stageDir);
    1.79 +
    1.80 +    AddonManager.getAddonByID("corrupt@tests.mozilla.org", function(addon) {
    1.81 +      do_check_eq(addon, null);
    1.82 +
    1.83 +      do_test_finished();
    1.84 +    });
    1.85 +  });
    1.86 +}

mercurial