|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
|
6 |
|
7 // This verifies that add-ons can be disabled and enabled. |
|
8 |
|
9 var addon1 = { |
|
10 id: "addon1@tests.mozilla.org", |
|
11 version: "1.0", |
|
12 name: "Test 1", |
|
13 optionsURL: "chrome://foo/content/options.xul", |
|
14 aboutURL: "chrome://foo/content/about.xul", |
|
15 iconURL: "chrome://foo/content/icon.png", |
|
16 targetApplications: [{ |
|
17 id: "xpcshell@tests.mozilla.org", |
|
18 minVersion: "1", |
|
19 maxVersion: "1" |
|
20 }] |
|
21 }; |
|
22 |
|
23 const profileDir = gProfD.clone(); |
|
24 profileDir.append("extensions"); |
|
25 |
|
26 var gIconURL = null; |
|
27 |
|
28 // Sets up the profile by installing an add-on. |
|
29 function run_test() { |
|
30 do_test_pending(); |
|
31 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
32 |
|
33 startupManager(); |
|
34 |
|
35 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { |
|
36 do_check_eq(a1, null); |
|
37 do_check_not_in_crash_annotation(addon1.id, addon1.version); |
|
38 |
|
39 writeInstallRDFForExtension(addon1, profileDir, addon1.id, "icon.png"); |
|
40 gIconURL = do_get_addon_root_uri(profileDir.clone(), addon1.id) + "icon.png"; |
|
41 |
|
42 restartManager(); |
|
43 |
|
44 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) { |
|
45 do_check_neq(newa1, null); |
|
46 do_check_true(newa1.isActive); |
|
47 do_check_false(newa1.userDisabled); |
|
48 do_check_eq(newa1.aboutURL, "chrome://foo/content/about.xul"); |
|
49 do_check_eq(newa1.optionsURL, "chrome://foo/content/options.xul"); |
|
50 do_check_eq(newa1.iconURL, "chrome://foo/content/icon.png"); |
|
51 do_check_true(isExtensionInAddonsList(profileDir, newa1.id)); |
|
52 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
53 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
54 do_check_eq(newa1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_DISABLE | |
|
55 AddonManager.OP_NEEDS_RESTART_UNINSTALL); |
|
56 do_check_in_crash_annotation(addon1.id, addon1.version); |
|
57 |
|
58 run_test_1(); |
|
59 }); |
|
60 })); |
|
61 } |
|
62 |
|
63 // Disabling an add-on should work |
|
64 function run_test_1() { |
|
65 prepare_test({ |
|
66 "addon1@tests.mozilla.org": [ |
|
67 "onDisabling" |
|
68 ] |
|
69 }); |
|
70 |
|
71 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
|
72 do_check_neq(a1.operationsRequiringRestart & |
|
73 AddonManager.OP_NEEDS_RESTART_DISABLE, 0); |
|
74 a1.userDisabled = true; |
|
75 do_check_eq(a1.aboutURL, "chrome://foo/content/about.xul"); |
|
76 do_check_eq(a1.optionsURL, "chrome://foo/content/options.xul"); |
|
77 do_check_eq(a1.iconURL, "chrome://foo/content/icon.png"); |
|
78 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
79 do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
80 do_check_eq(a1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_DISABLE | |
|
81 AddonManager.OP_NEEDS_RESTART_UNINSTALL); |
|
82 do_check_in_crash_annotation(addon1.id, addon1.version); |
|
83 |
|
84 ensure_test_completed(); |
|
85 |
|
86 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) { |
|
87 do_check_eq(list.length, 1); |
|
88 do_check_eq(list[0].id, "addon1@tests.mozilla.org"); |
|
89 |
|
90 restartManager(); |
|
91 |
|
92 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) { |
|
93 do_check_neq(newa1, null); |
|
94 do_check_false(newa1.isActive); |
|
95 do_check_true(newa1.userDisabled); |
|
96 do_check_eq(newa1.aboutURL, null); |
|
97 do_check_eq(newa1.optionsURL, null); |
|
98 do_check_eq(newa1.iconURL, gIconURL); |
|
99 do_check_false(isExtensionInAddonsList(profileDir, newa1.id)); |
|
100 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
101 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
102 do_check_eq(newa1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE); |
|
103 do_check_not_in_crash_annotation(addon1.id, addon1.version); |
|
104 |
|
105 run_test_2(); |
|
106 }); |
|
107 })); |
|
108 }); |
|
109 } |
|
110 |
|
111 // Enabling an add-on should work. |
|
112 function run_test_2() { |
|
113 prepare_test({ |
|
114 "addon1@tests.mozilla.org": [ |
|
115 "onEnabling" |
|
116 ] |
|
117 }); |
|
118 |
|
119 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
|
120 a1.userDisabled = false; |
|
121 do_check_eq(a1.aboutURL, null); |
|
122 do_check_eq(a1.optionsURL, null); |
|
123 do_check_eq(a1.iconURL, gIconURL); |
|
124 do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
125 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
126 do_check_eq(a1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE); |
|
127 |
|
128 ensure_test_completed(); |
|
129 |
|
130 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) { |
|
131 do_check_eq(list.length, 1); |
|
132 do_check_eq(list[0].id, "addon1@tests.mozilla.org"); |
|
133 |
|
134 restartManager(); |
|
135 |
|
136 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) { |
|
137 do_check_neq(newa1, null); |
|
138 do_check_true(newa1.isActive); |
|
139 do_check_false(newa1.userDisabled); |
|
140 do_check_eq(newa1.aboutURL, "chrome://foo/content/about.xul"); |
|
141 do_check_eq(newa1.optionsURL, "chrome://foo/content/options.xul"); |
|
142 do_check_eq(newa1.iconURL, "chrome://foo/content/icon.png"); |
|
143 do_check_true(isExtensionInAddonsList(profileDir, newa1.id)); |
|
144 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
145 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
146 do_check_eq(newa1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_DISABLE | |
|
147 AddonManager.OP_NEEDS_RESTART_UNINSTALL); |
|
148 do_check_in_crash_annotation(addon1.id, addon1.version); |
|
149 |
|
150 run_test_3(); |
|
151 }); |
|
152 })); |
|
153 }); |
|
154 } |
|
155 |
|
156 // Disabling then enabling without restart should fire onOperationCancelled. |
|
157 function run_test_3() { |
|
158 prepare_test({ |
|
159 "addon1@tests.mozilla.org": [ |
|
160 "onDisabling" |
|
161 ] |
|
162 }); |
|
163 |
|
164 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { |
|
165 a1.userDisabled = true; |
|
166 ensure_test_completed(); |
|
167 prepare_test({ |
|
168 "addon1@tests.mozilla.org": [ |
|
169 "onOperationCancelled" |
|
170 ] |
|
171 }); |
|
172 a1.userDisabled = false; |
|
173 do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
174 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
175 |
|
176 ensure_test_completed(); |
|
177 |
|
178 restartManager(); |
|
179 |
|
180 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) { |
|
181 do_check_neq(newa1, null); |
|
182 do_check_true(newa1.isActive); |
|
183 do_check_false(newa1.userDisabled); |
|
184 do_check_eq(newa1.aboutURL, "chrome://foo/content/about.xul"); |
|
185 do_check_eq(newa1.optionsURL, "chrome://foo/content/options.xul"); |
|
186 do_check_eq(newa1.iconURL, "chrome://foo/content/icon.png"); |
|
187 do_check_true(isExtensionInAddonsList(profileDir, newa1.id)); |
|
188 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
189 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
190 |
|
191 do_execute_soon(do_test_finished); |
|
192 }); |
|
193 })); |
|
194 } |