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 | // install.rdf size, icon.png size, subfile.txt size |
michael@0 | 6 | const ADDON_SIZE = 672 + 15 + 26; |
michael@0 | 7 | |
michael@0 | 8 | // This verifies the functionality of getResourceURI |
michael@0 | 9 | // There are two cases - with a filename it returns an nsIFileURL to the filename |
michael@0 | 10 | // and with no parameters, it returns an nsIFileURL to the root of the addon |
michael@0 | 11 | |
michael@0 | 12 | function run_test() { |
michael@0 | 13 | do_test_pending(); |
michael@0 | 14 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); |
michael@0 | 15 | |
michael@0 | 16 | startupManager(); |
michael@0 | 17 | |
michael@0 | 18 | AddonManager.getInstallForFile(do_get_addon("test_getresource"), function(aInstall) { |
michael@0 | 19 | do_check_true(aInstall.addon.hasResource("install.rdf")); |
michael@0 | 20 | do_check_eq(aInstall.addon.getResourceURI().spec, aInstall.sourceURI.spec); |
michael@0 | 21 | |
michael@0 | 22 | do_check_true(aInstall.addon.hasResource("icon.png")); |
michael@0 | 23 | do_check_eq(aInstall.addon.getResourceURI("icon.png").spec, |
michael@0 | 24 | "jar:" + aInstall.sourceURI.spec + "!/icon.png"); |
michael@0 | 25 | |
michael@0 | 26 | do_check_false(aInstall.addon.hasResource("missing.txt")); |
michael@0 | 27 | |
michael@0 | 28 | do_check_true(aInstall.addon.hasResource("subdir/subfile.txt")); |
michael@0 | 29 | do_check_eq(aInstall.addon.getResourceURI("subdir/subfile.txt").spec, |
michael@0 | 30 | "jar:" + aInstall.sourceURI.spec + "!/subdir/subfile.txt"); |
michael@0 | 31 | |
michael@0 | 32 | do_check_false(aInstall.addon.hasResource("subdir/missing.txt")); |
michael@0 | 33 | |
michael@0 | 34 | do_check_eq(aInstall.addon.size, ADDON_SIZE); |
michael@0 | 35 | |
michael@0 | 36 | completeAllInstalls([aInstall], function() { |
michael@0 | 37 | restartManager(); |
michael@0 | 38 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 39 | do_check_neq(a1, null); |
michael@0 | 40 | |
michael@0 | 41 | let addonDir = gProfD.clone(); |
michael@0 | 42 | addonDir.append("extensions"); |
michael@0 | 43 | let rootUri = do_get_addon_root_uri(addonDir, "addon1@tests.mozilla.org"); |
michael@0 | 44 | |
michael@0 | 45 | let uri = a1.getResourceURI("/"); |
michael@0 | 46 | do_check_eq(uri.spec, rootUri); |
michael@0 | 47 | |
michael@0 | 48 | let file = rootUri + "install.rdf"; |
michael@0 | 49 | do_check_true(a1.hasResource("install.rdf")); |
michael@0 | 50 | uri = a1.getResourceURI("install.rdf") |
michael@0 | 51 | do_check_eq(uri.spec, file); |
michael@0 | 52 | |
michael@0 | 53 | file = rootUri + "icon.png"; |
michael@0 | 54 | do_check_true(a1.hasResource("icon.png")); |
michael@0 | 55 | uri = a1.getResourceURI("icon.png") |
michael@0 | 56 | do_check_eq(uri.spec, file); |
michael@0 | 57 | |
michael@0 | 58 | do_check_false(a1.hasResource("missing.txt")); |
michael@0 | 59 | |
michael@0 | 60 | file = rootUri + "subdir/subfile.txt"; |
michael@0 | 61 | do_check_true(a1.hasResource("subdir/subfile.txt")); |
michael@0 | 62 | uri = a1.getResourceURI("subdir/subfile.txt") |
michael@0 | 63 | do_check_eq(uri.spec, file); |
michael@0 | 64 | |
michael@0 | 65 | do_check_false(a1.hasResource("subdir/missing.txt")); |
michael@0 | 66 | |
michael@0 | 67 | do_check_eq(a1.size, ADDON_SIZE); |
michael@0 | 68 | |
michael@0 | 69 | a1.uninstall(); |
michael@0 | 70 | |
michael@0 | 71 | try { |
michael@0 | 72 | // hasResource should never throw an exception. |
michael@0 | 73 | do_check_false(a1.hasResource("icon.png")); |
michael@0 | 74 | } catch (e) { |
michael@0 | 75 | do_check_true(false); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | AddonManager.getInstallForFile(do_get_addon("test_getresource"), |
michael@0 | 79 | callback_soon(function(aInstall) { |
michael@0 | 80 | do_check_false(a1.hasResource("icon.png")); |
michael@0 | 81 | do_check_true(aInstall.addon.hasResource("icon.png")); |
michael@0 | 82 | |
michael@0 | 83 | restartManager(); |
michael@0 | 84 | |
michael@0 | 85 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) { |
michael@0 | 86 | do_check_eq(newa1, null); |
michael@0 | 87 | |
michael@0 | 88 | do_execute_soon(do_test_finished); |
michael@0 | 89 | }); |
michael@0 | 90 | })); |
michael@0 | 91 | }); |
michael@0 | 92 | }); |
michael@0 | 93 | }); |
michael@0 | 94 | } |