diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/mozapps/extensions/test/xpcshell/test_getresource.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_getresource.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_getresource.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_getresource.js b/toolkit/mozapps/extensions/test/xpcshell/test_getresource.js new file mode 100644 index 000000000..c83638d54 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_getresource.js @@ -0,0 +1,94 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// install.rdf size, icon.png size, subfile.txt size +const ADDON_SIZE = 672 + 15 + 26; + +// This verifies the functionality of getResourceURI +// There are two cases - with a filename it returns an nsIFileURL to the filename +// and with no parameters, it returns an nsIFileURL to the root of the addon + +function run_test() { + do_test_pending(); + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); + + startupManager(); + + AddonManager.getInstallForFile(do_get_addon("test_getresource"), function(aInstall) { + do_check_true(aInstall.addon.hasResource("install.rdf")); + do_check_eq(aInstall.addon.getResourceURI().spec, aInstall.sourceURI.spec); + + do_check_true(aInstall.addon.hasResource("icon.png")); + do_check_eq(aInstall.addon.getResourceURI("icon.png").spec, + "jar:" + aInstall.sourceURI.spec + "!/icon.png"); + + do_check_false(aInstall.addon.hasResource("missing.txt")); + + do_check_true(aInstall.addon.hasResource("subdir/subfile.txt")); + do_check_eq(aInstall.addon.getResourceURI("subdir/subfile.txt").spec, + "jar:" + aInstall.sourceURI.spec + "!/subdir/subfile.txt"); + + do_check_false(aInstall.addon.hasResource("subdir/missing.txt")); + + do_check_eq(aInstall.addon.size, ADDON_SIZE); + + completeAllInstalls([aInstall], function() { + restartManager(); + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { + do_check_neq(a1, null); + + let addonDir = gProfD.clone(); + addonDir.append("extensions"); + let rootUri = do_get_addon_root_uri(addonDir, "addon1@tests.mozilla.org"); + + let uri = a1.getResourceURI("/"); + do_check_eq(uri.spec, rootUri); + + let file = rootUri + "install.rdf"; + do_check_true(a1.hasResource("install.rdf")); + uri = a1.getResourceURI("install.rdf") + do_check_eq(uri.spec, file); + + file = rootUri + "icon.png"; + do_check_true(a1.hasResource("icon.png")); + uri = a1.getResourceURI("icon.png") + do_check_eq(uri.spec, file); + + do_check_false(a1.hasResource("missing.txt")); + + file = rootUri + "subdir/subfile.txt"; + do_check_true(a1.hasResource("subdir/subfile.txt")); + uri = a1.getResourceURI("subdir/subfile.txt") + do_check_eq(uri.spec, file); + + do_check_false(a1.hasResource("subdir/missing.txt")); + + do_check_eq(a1.size, ADDON_SIZE); + + a1.uninstall(); + + try { + // hasResource should never throw an exception. + do_check_false(a1.hasResource("icon.png")); + } catch (e) { + do_check_true(false); + } + + AddonManager.getInstallForFile(do_get_addon("test_getresource"), + callback_soon(function(aInstall_2) { + do_check_false(a1.hasResource("icon.png")); + do_check_true(aInstall_2.addon.hasResource("icon.png")); + + restartManager(); + + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) { + do_check_eq(newa1, null); + + do_execute_soon(do_test_finished); + }); + })); + }); + }); + }); +} |