|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // This verifies that the extensions.checkCompatibility.* preferences work. |
|
6 |
|
7 var ADDONS = [{ |
|
8 // Cannot be enabled as it has no target app info for the applciation |
|
9 id: "addon1@tests.mozilla.org", |
|
10 version: "1.0", |
|
11 name: "Test 1", |
|
12 targetApplications: [{ |
|
13 id: "unknown@tests.mozilla.org", |
|
14 minVersion: "1", |
|
15 maxVersion: "1" |
|
16 }] |
|
17 }, { |
|
18 // Always appears incompatible but can be enabled if compatibility checking is |
|
19 // disabled |
|
20 id: "addon2@tests.mozilla.org", |
|
21 version: "1.0", |
|
22 name: "Test 2", |
|
23 targetApplications: [{ |
|
24 id: "toolkit@mozilla.org", |
|
25 minVersion: "1", |
|
26 maxVersion: "1" |
|
27 }] |
|
28 }, { |
|
29 // Always appears incompatible but can be enabled if compatibility checking is |
|
30 // disabled |
|
31 id: "addon3@tests.mozilla.org", |
|
32 version: "1.0", |
|
33 name: "Test 3", |
|
34 targetApplications: [{ |
|
35 id: "xpcshell@tests.mozilla.org", |
|
36 minVersion: "1", |
|
37 maxVersion: "1" |
|
38 }] |
|
39 }, { // Always compatible and enabled |
|
40 id: "addon4@tests.mozilla.org", |
|
41 version: "1.0", |
|
42 name: "Test 4", |
|
43 targetApplications: [{ |
|
44 id: "toolkit@mozilla.org", |
|
45 minVersion: "1", |
|
46 maxVersion: "2" |
|
47 }] |
|
48 }, { // Always compatible and enabled |
|
49 id: "addon5@tests.mozilla.org", |
|
50 version: "1.0", |
|
51 name: "Test 5", |
|
52 targetApplications: [{ |
|
53 id: "xpcshell@tests.mozilla.org", |
|
54 minVersion: "1", |
|
55 maxVersion: "3" |
|
56 }] |
|
57 }]; |
|
58 |
|
59 const profileDir = gProfD.clone(); |
|
60 profileDir.append("extensions"); |
|
61 |
|
62 var gIsNightly = false; |
|
63 |
|
64 function run_test() { |
|
65 do_test_pending("checkcompatibility.js"); |
|
66 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2.2.3", "2"); |
|
67 |
|
68 ADDONS.forEach(function(a) { |
|
69 writeInstallRDFForExtension(a, profileDir); |
|
70 }); |
|
71 |
|
72 gIsNightly = isNightlyChannel(); |
|
73 |
|
74 startupManager(); |
|
75 |
|
76 run_test_1(); |
|
77 } |
|
78 |
|
79 /** |
|
80 * Checks that the add-ons are enabled as expected. |
|
81 * @param overridden |
|
82 * A boolean indicating that compatibility checking is overridden |
|
83 * @param a1 |
|
84 * The Addon for addon1@tests.mozilla.org |
|
85 * @param a2 |
|
86 * The Addon for addon2@tests.mozilla.org |
|
87 * @param a3 |
|
88 * The Addon for addon3@tests.mozilla.org |
|
89 * @param a4 |
|
90 * The Addon for addon4@tests.mozilla.org |
|
91 * @param a5 |
|
92 * The Addon for addon5@tests.mozilla.org |
|
93 */ |
|
94 function check_state(overridden, a1, a2, a3, a4, a5) { |
|
95 do_check_neq(a1, null); |
|
96 do_check_false(a1.isActive); |
|
97 do_check_false(a1.isCompatible); |
|
98 |
|
99 do_check_neq(a2, null); |
|
100 if (overridden) |
|
101 do_check_true(a2.isActive); |
|
102 else |
|
103 do_check_false(a2.isActive); |
|
104 do_check_false(a2.isCompatible); |
|
105 |
|
106 do_check_neq(a3, null); |
|
107 if (overridden) |
|
108 do_check_true(a3.isActive); |
|
109 else |
|
110 do_check_false(a3.isActive); |
|
111 do_check_false(a3.isCompatible); |
|
112 |
|
113 do_check_neq(a4, null); |
|
114 do_check_true(a4.isActive); |
|
115 do_check_true(a4.isCompatible); |
|
116 |
|
117 do_check_neq(a5, null); |
|
118 do_check_true(a5.isActive); |
|
119 do_check_true(a5.isCompatible); |
|
120 } |
|
121 |
|
122 // Tests that with compatibility checking enabled we see the incompatible |
|
123 // add-ons disabled |
|
124 function run_test_1() { |
|
125 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
126 "addon2@tests.mozilla.org", |
|
127 "addon3@tests.mozilla.org", |
|
128 "addon4@tests.mozilla.org", |
|
129 "addon5@tests.mozilla.org"], |
|
130 function([a1, a2, a3, a4, a5]) { |
|
131 check_state(false, a1, a2, a3, a4, a5); |
|
132 |
|
133 do_execute_soon(run_test_2); |
|
134 }); |
|
135 } |
|
136 |
|
137 // Tests that with compatibility checking disabled we see the incompatible |
|
138 // add-ons enabled |
|
139 function run_test_2() { |
|
140 if (gIsNightly) |
|
141 Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", false); |
|
142 else |
|
143 Services.prefs.setBoolPref("extensions.checkCompatibility.2.2", false); |
|
144 restartManager(); |
|
145 |
|
146 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
147 "addon2@tests.mozilla.org", |
|
148 "addon3@tests.mozilla.org", |
|
149 "addon4@tests.mozilla.org", |
|
150 "addon5@tests.mozilla.org"], |
|
151 function([a1, a2, a3, a4, a5]) { |
|
152 check_state(true, a1, a2, a3, a4, a5); |
|
153 |
|
154 do_execute_soon(run_test_3); |
|
155 }); |
|
156 } |
|
157 |
|
158 // Tests that with compatibility checking disabled we see the incompatible |
|
159 // add-ons enabled. |
|
160 function run_test_3() { |
|
161 if (!gIsNightly) |
|
162 Services.prefs.setBoolPref("extensions.checkCompatibility.2.1a", false); |
|
163 restartManager("2.1a4"); |
|
164 |
|
165 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
166 "addon2@tests.mozilla.org", |
|
167 "addon3@tests.mozilla.org", |
|
168 "addon4@tests.mozilla.org", |
|
169 "addon5@tests.mozilla.org"], |
|
170 function([a1, a2, a3, a4, a5]) { |
|
171 check_state(true, a1, a2, a3, a4, a5); |
|
172 |
|
173 do_execute_soon(run_test_4); |
|
174 }); |
|
175 } |
|
176 |
|
177 // Tests that with compatibility checking enabled we see the incompatible |
|
178 // add-ons disabled. |
|
179 function run_test_4() { |
|
180 if (gIsNightly) |
|
181 Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", true); |
|
182 else |
|
183 Services.prefs.setBoolPref("extensions.checkCompatibility.2.1a", true); |
|
184 restartManager(); |
|
185 |
|
186 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
187 "addon2@tests.mozilla.org", |
|
188 "addon3@tests.mozilla.org", |
|
189 "addon4@tests.mozilla.org", |
|
190 "addon5@tests.mozilla.org"], |
|
191 function([a1, a2, a3, a4, a5]) { |
|
192 check_state(false, a1, a2, a3, a4, a5); |
|
193 |
|
194 do_execute_soon(do_test_finished); |
|
195 }); |
|
196 } |