michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests that attempting to install a corrupt XPI file doesn't break the universe michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); michael@0: michael@0: startupManager(); michael@0: michael@0: if (TEST_UNPACKED) michael@0: run_test_unpacked(); michael@0: else michael@0: run_test_packed(); michael@0: } michael@0: michael@0: // When installing packed we won't detect corruption in the XPI until we attempt michael@0: // to load bootstrap.js so everything will look normal from the outside. michael@0: function run_test_packed() { michael@0: do_test_pending(); michael@0: michael@0: prepare_test({ michael@0: "corrupt@tests.mozilla.org": [ michael@0: ["onInstalling", false], michael@0: ["onInstalled", false] michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onInstallStarted", michael@0: "onInstallEnded" michael@0: ]); michael@0: michael@0: installAllFiles([do_get_file("data/corruptfile.xpi")], function() { michael@0: ensure_test_completed(); michael@0: michael@0: AddonManager.getAddonByID("corrupt@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: michael@0: do_test_finished(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: // When extracting the corruption will be detected and the add-on fails to michael@0: // install michael@0: function run_test_unpacked() { michael@0: do_test_pending(); michael@0: michael@0: prepare_test({ michael@0: "corrupt@tests.mozilla.org": [ michael@0: ["onInstalling", false], michael@0: "onOperationCancelled" michael@0: ] michael@0: }, [ michael@0: "onNewInstall", michael@0: "onInstallStarted", michael@0: "onInstallFailed" michael@0: ]); michael@0: michael@0: installAllFiles([do_get_file("data/corruptfile.xpi")], function() { michael@0: ensure_test_completed(); michael@0: michael@0: // Check the add-on directory isn't left over michael@0: var addonDir = profileDir.clone(); michael@0: addonDir.append("corrupt@tests.mozilla.org"); michael@0: pathShouldntExist(addonDir); michael@0: michael@0: // Check the staging directory isn't left over michael@0: var stageDir = profileDir.clone(); michael@0: stageDir.append("staged"); michael@0: pathShouldntExist(stageDir); michael@0: michael@0: AddonManager.getAddonByID("corrupt@tests.mozilla.org", function(addon) { michael@0: do_check_eq(addon, null); michael@0: michael@0: do_test_finished(); michael@0: }); michael@0: }); michael@0: }