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