diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/mozapps/extensions/test/xpcshell/test_error.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_error.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_error.js b/toolkit/mozapps/extensions/test/xpcshell/test_error.js new file mode 100644 index 0000000000..ee972f222e --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_error.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Tests that various error conditions are handled correctly + +add_task(async function setup() { + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); + + await promiseStartupManager(); +}); + +// Checks that a local file validates ok +add_task(async function run_test_1() { + let xpi = await createTempWebExtensionFile({}); + let install = await AddonManager.getInstallForFile(xpi); + Assert.notEqual(install, null); + Assert.equal(install.state, AddonManager.STATE_DOWNLOADED); + Assert.equal(install.error, 0); + + install.cancel(); +}); + +// Checks that a corrupt file shows an error +add_task(async function run_test_2() { + let xpi = AddonTestUtils.allocTempXPIFile(); + await IOUtils.writeUTF8(xpi.path, "this is not a zip file"); + + let install = await AddonManager.getInstallForFile(xpi); + Assert.notEqual(install, null); + Assert.equal(install.state, AddonManager.STATE_DOWNLOAD_FAILED); + Assert.equal(install.error, AddonManager.ERROR_CORRUPT_FILE); +}); + +// Checks that an empty file shows an error +add_task(async function run_test_3() { + let xpi = await AddonTestUtils.createTempXPIFile({}); + let install = await AddonManager.getInstallForFile(xpi); + Assert.notEqual(install, null); + Assert.equal(install.state, AddonManager.STATE_DOWNLOAD_FAILED); + Assert.equal(install.error, AddonManager.ERROR_CORRUPT_FILE); +}); + +// Checks that a file that doesn't match its hash shows an error +add_task(async function run_test_4() { + let xpi = await createTempWebExtensionFile({}); + let url = Services.io.newFileURI(xpi).spec; + let install = await AddonManager.getInstallForURL(url, { hash: "sha1:foo" }); + Assert.notEqual(install, null); + Assert.equal(install.state, AddonManager.STATE_DOWNLOAD_FAILED); + Assert.equal(install.error, AddonManager.ERROR_INCORRECT_HASH); +}); + +// Checks that a file that doesn't exist shows an error +add_task(async function run_test_5() { + let file = do_get_file("data"); + file.append("missing.xpi"); + let install = await AddonManager.getInstallForFile(file); + Assert.notEqual(install, null); + Assert.equal(install.state, AddonManager.STATE_DOWNLOAD_FAILED); + Assert.equal(install.error, AddonManager.ERROR_NETWORK_FAILURE); +}); + +// Checks that an add-on with an illegal ID shows an error +add_task(async function run_test_6() { + let xpi = await createTempWebExtensionFile({ + manifest: { + browser_specific_settings: { gecko: { id: "invalid" } }, + }, + }); + let install = await AddonManager.getInstallForFile(xpi); + Assert.notEqual(install, null); + Assert.equal(install.state, AddonManager.STATE_DOWNLOAD_FAILED); + Assert.equal(install.error, AddonManager.ERROR_CORRUPT_FILE); +}); |