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 various error conditions are handled correctly |
michael@0 | 6 | |
michael@0 | 7 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 8 | |
michael@0 | 9 | const profileDir = gProfD.clone(); |
michael@0 | 10 | profileDir.append("extensions"); |
michael@0 | 11 | |
michael@0 | 12 | function run_test() { |
michael@0 | 13 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 14 | |
michael@0 | 15 | startupManager(); |
michael@0 | 16 | |
michael@0 | 17 | do_test_pending(); |
michael@0 | 18 | run_test_1(); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | // Checks that a local file validates ok |
michael@0 | 22 | function run_test_1() { |
michael@0 | 23 | AddonManager.getInstallForFile(do_get_file("data/unsigned.xpi"), function(install) { |
michael@0 | 24 | do_check_neq(install, null); |
michael@0 | 25 | do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
michael@0 | 26 | do_check_eq(install.error, 0); |
michael@0 | 27 | |
michael@0 | 28 | install.cancel(); |
michael@0 | 29 | |
michael@0 | 30 | run_test_2(); |
michael@0 | 31 | }); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | // Checks that a corrupt file shows an error |
michael@0 | 35 | function run_test_2() { |
michael@0 | 36 | AddonManager.getInstallForFile(do_get_file("data/corrupt.xpi"), function(install) { |
michael@0 | 37 | do_check_neq(install, null); |
michael@0 | 38 | do_check_eq(install.state, AddonManager.STATE_DOWNLOAD_FAILED); |
michael@0 | 39 | do_check_eq(install.error, AddonManager.ERROR_CORRUPT_FILE); |
michael@0 | 40 | |
michael@0 | 41 | run_test_3(); |
michael@0 | 42 | }); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | // Checks that an empty file shows an error |
michael@0 | 46 | function run_test_3() { |
michael@0 | 47 | AddonManager.getInstallForFile(do_get_file("data/empty.xpi"), function(install) { |
michael@0 | 48 | do_check_neq(install, null); |
michael@0 | 49 | do_check_eq(install.state, AddonManager.STATE_DOWNLOAD_FAILED); |
michael@0 | 50 | do_check_eq(install.error, AddonManager.ERROR_CORRUPT_FILE); |
michael@0 | 51 | |
michael@0 | 52 | run_test_4(); |
michael@0 | 53 | }); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | // Checks that a file that doesn't match its hash shows an error |
michael@0 | 57 | function run_test_4() { |
michael@0 | 58 | let url = Services.io.newFileURI(do_get_file("data/unsigned.xpi")).spec; |
michael@0 | 59 | AddonManager.getInstallForURL(url, function(install) { |
michael@0 | 60 | do_check_neq(install, null); |
michael@0 | 61 | do_check_eq(install.state, AddonManager.STATE_DOWNLOAD_FAILED); |
michael@0 | 62 | do_check_eq(install.error, AddonManager.ERROR_INCORRECT_HASH); |
michael@0 | 63 | |
michael@0 | 64 | run_test_5(); |
michael@0 | 65 | }, "application/x-xpinstall", "sha1:foo"); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | // Checks that a file that doesn't exist shows an error |
michael@0 | 69 | function run_test_4() { |
michael@0 | 70 | let file = do_get_file("data"); |
michael@0 | 71 | file.append("missing.xpi"); |
michael@0 | 72 | AddonManager.getInstallForFile(file, function(install) { |
michael@0 | 73 | do_check_neq(install, null); |
michael@0 | 74 | do_check_eq(install.state, AddonManager.STATE_DOWNLOAD_FAILED); |
michael@0 | 75 | do_check_eq(install.error, AddonManager.ERROR_NETWORK_FAILURE); |
michael@0 | 76 | |
michael@0 | 77 | run_test_5(); |
michael@0 | 78 | }); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | // Checks that an add-on with an illegal ID shows an error |
michael@0 | 82 | function run_test_5() { |
michael@0 | 83 | AddonManager.getInstallForFile(do_get_addon("test_bug567173"), function(install) { |
michael@0 | 84 | do_check_neq(install, null); |
michael@0 | 85 | do_check_eq(install.state, AddonManager.STATE_DOWNLOAD_FAILED); |
michael@0 | 86 | do_check_eq(install.error, AddonManager.ERROR_CORRUPT_FILE); |
michael@0 | 87 | |
michael@0 | 88 | do_execute_soon(do_test_finished); |
michael@0 | 89 | }); |
michael@0 | 90 | } |