toolkit/mozapps/extensions/test/xpcshell/test_corruptfile.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.

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

mercurial