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: // install.rdf size, icon.png size, subfile.txt size michael@0: const ADDON_SIZE = 672 + 15 + 26; michael@0: michael@0: // This verifies the functionality of getResourceURI michael@0: // There are two cases - with a filename it returns an nsIFileURL to the filename michael@0: // and with no parameters, it returns an nsIFileURL to the root of the addon michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); michael@0: michael@0: startupManager(); michael@0: michael@0: AddonManager.getInstallForFile(do_get_addon("test_getresource"), function(aInstall) { michael@0: do_check_true(aInstall.addon.hasResource("install.rdf")); michael@0: do_check_eq(aInstall.addon.getResourceURI().spec, aInstall.sourceURI.spec); michael@0: michael@0: do_check_true(aInstall.addon.hasResource("icon.png")); michael@0: do_check_eq(aInstall.addon.getResourceURI("icon.png").spec, michael@0: "jar:" + aInstall.sourceURI.spec + "!/icon.png"); michael@0: michael@0: do_check_false(aInstall.addon.hasResource("missing.txt")); michael@0: michael@0: do_check_true(aInstall.addon.hasResource("subdir/subfile.txt")); michael@0: do_check_eq(aInstall.addon.getResourceURI("subdir/subfile.txt").spec, michael@0: "jar:" + aInstall.sourceURI.spec + "!/subdir/subfile.txt"); michael@0: michael@0: do_check_false(aInstall.addon.hasResource("subdir/missing.txt")); michael@0: michael@0: do_check_eq(aInstall.addon.size, ADDON_SIZE); michael@0: michael@0: completeAllInstalls([aInstall], function() { michael@0: restartManager(); michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { michael@0: do_check_neq(a1, null); michael@0: michael@0: let addonDir = gProfD.clone(); michael@0: addonDir.append("extensions"); michael@0: let rootUri = do_get_addon_root_uri(addonDir, "addon1@tests.mozilla.org"); michael@0: michael@0: let uri = a1.getResourceURI("/"); michael@0: do_check_eq(uri.spec, rootUri); michael@0: michael@0: let file = rootUri + "install.rdf"; michael@0: do_check_true(a1.hasResource("install.rdf")); michael@0: uri = a1.getResourceURI("install.rdf") michael@0: do_check_eq(uri.spec, file); michael@0: michael@0: file = rootUri + "icon.png"; michael@0: do_check_true(a1.hasResource("icon.png")); michael@0: uri = a1.getResourceURI("icon.png") michael@0: do_check_eq(uri.spec, file); michael@0: michael@0: do_check_false(a1.hasResource("missing.txt")); michael@0: michael@0: file = rootUri + "subdir/subfile.txt"; michael@0: do_check_true(a1.hasResource("subdir/subfile.txt")); michael@0: uri = a1.getResourceURI("subdir/subfile.txt") michael@0: do_check_eq(uri.spec, file); michael@0: michael@0: do_check_false(a1.hasResource("subdir/missing.txt")); michael@0: michael@0: do_check_eq(a1.size, ADDON_SIZE); michael@0: michael@0: a1.uninstall(); michael@0: michael@0: try { michael@0: // hasResource should never throw an exception. michael@0: do_check_false(a1.hasResource("icon.png")); michael@0: } catch (e) { michael@0: do_check_true(false); michael@0: } michael@0: michael@0: AddonManager.getInstallForFile(do_get_addon("test_getresource"), michael@0: callback_soon(function(aInstall) { michael@0: do_check_false(a1.hasResource("icon.png")); michael@0: do_check_true(aInstall.addon.hasResource("icon.png")); michael@0: michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) { michael@0: do_check_eq(newa1, null); michael@0: michael@0: do_execute_soon(do_test_finished); michael@0: }); michael@0: })); michael@0: }); michael@0: }); michael@0: }); michael@0: }