1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_getresource.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// install.rdf size, icon.png size, subfile.txt size 1.9 +const ADDON_SIZE = 672 + 15 + 26; 1.10 + 1.11 +// This verifies the functionality of getResourceURI 1.12 +// There are two cases - with a filename it returns an nsIFileURL to the filename 1.13 +// and with no parameters, it returns an nsIFileURL to the root of the addon 1.14 + 1.15 +function run_test() { 1.16 + do_test_pending(); 1.17 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); 1.18 + 1.19 + startupManager(); 1.20 + 1.21 + AddonManager.getInstallForFile(do_get_addon("test_getresource"), function(aInstall) { 1.22 + do_check_true(aInstall.addon.hasResource("install.rdf")); 1.23 + do_check_eq(aInstall.addon.getResourceURI().spec, aInstall.sourceURI.spec); 1.24 + 1.25 + do_check_true(aInstall.addon.hasResource("icon.png")); 1.26 + do_check_eq(aInstall.addon.getResourceURI("icon.png").spec, 1.27 + "jar:" + aInstall.sourceURI.spec + "!/icon.png"); 1.28 + 1.29 + do_check_false(aInstall.addon.hasResource("missing.txt")); 1.30 + 1.31 + do_check_true(aInstall.addon.hasResource("subdir/subfile.txt")); 1.32 + do_check_eq(aInstall.addon.getResourceURI("subdir/subfile.txt").spec, 1.33 + "jar:" + aInstall.sourceURI.spec + "!/subdir/subfile.txt"); 1.34 + 1.35 + do_check_false(aInstall.addon.hasResource("subdir/missing.txt")); 1.36 + 1.37 + do_check_eq(aInstall.addon.size, ADDON_SIZE); 1.38 + 1.39 + completeAllInstalls([aInstall], function() { 1.40 + restartManager(); 1.41 + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { 1.42 + do_check_neq(a1, null); 1.43 + 1.44 + let addonDir = gProfD.clone(); 1.45 + addonDir.append("extensions"); 1.46 + let rootUri = do_get_addon_root_uri(addonDir, "addon1@tests.mozilla.org"); 1.47 + 1.48 + let uri = a1.getResourceURI("/"); 1.49 + do_check_eq(uri.spec, rootUri); 1.50 + 1.51 + let file = rootUri + "install.rdf"; 1.52 + do_check_true(a1.hasResource("install.rdf")); 1.53 + uri = a1.getResourceURI("install.rdf") 1.54 + do_check_eq(uri.spec, file); 1.55 + 1.56 + file = rootUri + "icon.png"; 1.57 + do_check_true(a1.hasResource("icon.png")); 1.58 + uri = a1.getResourceURI("icon.png") 1.59 + do_check_eq(uri.spec, file); 1.60 + 1.61 + do_check_false(a1.hasResource("missing.txt")); 1.62 + 1.63 + file = rootUri + "subdir/subfile.txt"; 1.64 + do_check_true(a1.hasResource("subdir/subfile.txt")); 1.65 + uri = a1.getResourceURI("subdir/subfile.txt") 1.66 + do_check_eq(uri.spec, file); 1.67 + 1.68 + do_check_false(a1.hasResource("subdir/missing.txt")); 1.69 + 1.70 + do_check_eq(a1.size, ADDON_SIZE); 1.71 + 1.72 + a1.uninstall(); 1.73 + 1.74 + try { 1.75 + // hasResource should never throw an exception. 1.76 + do_check_false(a1.hasResource("icon.png")); 1.77 + } catch (e) { 1.78 + do_check_true(false); 1.79 + } 1.80 + 1.81 + AddonManager.getInstallForFile(do_get_addon("test_getresource"), 1.82 + callback_soon(function(aInstall) { 1.83 + do_check_false(a1.hasResource("icon.png")); 1.84 + do_check_true(aInstall.addon.hasResource("icon.png")); 1.85 + 1.86 + restartManager(); 1.87 + 1.88 + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) { 1.89 + do_check_eq(newa1, null); 1.90 + 1.91 + do_execute_soon(do_test_finished); 1.92 + }); 1.93 + })); 1.94 + }); 1.95 + }); 1.96 + }); 1.97 +}