|
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 // The maximum allowable time since install. If an add-on claims to have been |
|
8 // installed longer ago than this the the test will fail. |
|
9 const MAX_INSTALL_TIME = 10000; |
|
10 |
|
11 // This verifies that themes behave as expected |
|
12 |
|
13 const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin"; |
|
14 |
|
15 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); |
|
16 |
|
17 const profileDir = gProfD.clone(); |
|
18 profileDir.append("extensions"); |
|
19 |
|
20 // Observer to ensure a "lightweight-theme-styling-update" notification is sent |
|
21 // when expected |
|
22 var gLWThemeChanged = false; |
|
23 var LightweightThemeObserver = { |
|
24 observe: function(aSubject, aTopic, aData) { |
|
25 if (aTopic != "lightweight-theme-styling-update") |
|
26 return; |
|
27 |
|
28 gLWThemeChanged = true; |
|
29 } |
|
30 }; |
|
31 |
|
32 AM_Cc["@mozilla.org/observer-service;1"] |
|
33 .getService(Components.interfaces.nsIObserverService) |
|
34 .addObserver(LightweightThemeObserver, "lightweight-theme-styling-update", false); |
|
35 |
|
36 |
|
37 function run_test() { |
|
38 do_test_pending(); |
|
39 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
40 |
|
41 Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0"); |
|
42 writeInstallRDFForExtension({ |
|
43 id: "theme1@tests.mozilla.org", |
|
44 version: "1.0", |
|
45 name: "Test 1", |
|
46 type: 4, |
|
47 skinnable: true, |
|
48 internalName: "theme1/1.0", |
|
49 targetApplications: [{ |
|
50 id: "xpcshell@tests.mozilla.org", |
|
51 minVersion: "1", |
|
52 maxVersion: "2" |
|
53 }] |
|
54 }, profileDir); |
|
55 |
|
56 writeInstallRDFForExtension({ |
|
57 id: "theme2@tests.mozilla.org", |
|
58 version: "1.0", |
|
59 name: "Test 1", |
|
60 skinnable: false, |
|
61 internalName: "theme2/1.0", |
|
62 targetApplications: [{ |
|
63 id: "xpcshell@tests.mozilla.org", |
|
64 minVersion: "1", |
|
65 maxVersion: "2" |
|
66 }] |
|
67 }, profileDir); |
|
68 |
|
69 // We need a default theme for some of these things to work but we have hidden |
|
70 // the one in the application directory. |
|
71 writeInstallRDFForExtension({ |
|
72 id: "default@tests.mozilla.org", |
|
73 version: "1.0", |
|
74 name: "Default", |
|
75 internalName: "classic/1.0", |
|
76 targetApplications: [{ |
|
77 id: "xpcshell@tests.mozilla.org", |
|
78 minVersion: "1", |
|
79 maxVersion: "2" |
|
80 }] |
|
81 }, profileDir); |
|
82 |
|
83 startupManager(); |
|
84 // Make sure we only register once despite multiple calls |
|
85 AddonManager.addInstallListener(InstallListener); |
|
86 AddonManager.addAddonListener(AddonListener); |
|
87 AddonManager.addInstallListener(InstallListener); |
|
88 AddonManager.addAddonListener(AddonListener); |
|
89 AddonManager.addInstallListener(InstallListener); |
|
90 |
|
91 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
92 "theme1@tests.mozilla.org", |
|
93 "theme2@tests.mozilla.org"], |
|
94 function([d, t1, t2]) { |
|
95 do_check_neq(d, null); |
|
96 do_check_false(d.skinnable); |
|
97 do_check_false(d.foreignInstall); |
|
98 |
|
99 do_check_neq(t1, null); |
|
100 do_check_false(t1.userDisabled); |
|
101 do_check_false(t1.appDisabled); |
|
102 do_check_true(t1.isActive); |
|
103 do_check_true(t1.skinnable); |
|
104 do_check_true(t1.foreignInstall); |
|
105 do_check_eq(t1.screenshots, null); |
|
106 do_check_true(isThemeInAddonsList(profileDir, t1.id)); |
|
107 do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
108 do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
109 do_check_eq(t1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_UNINSTALL | |
|
110 AddonManager.OP_NEEDS_RESTART_DISABLE); |
|
111 |
|
112 do_check_neq(t2, null); |
|
113 do_check_true(t2.userDisabled); |
|
114 do_check_false(t2.appDisabled); |
|
115 do_check_false(t2.isActive); |
|
116 do_check_false(t2.skinnable); |
|
117 do_check_true(t2.foreignInstall); |
|
118 do_check_eq(t2.screenshots, null); |
|
119 do_check_false(isThemeInAddonsList(profileDir, t2.id)); |
|
120 do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
121 do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
122 do_check_eq(t2.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE); |
|
123 |
|
124 do_execute_soon(run_test_1); |
|
125 }); |
|
126 } |
|
127 |
|
128 function end_test() { |
|
129 do_execute_soon(do_test_finished); |
|
130 } |
|
131 |
|
132 // Checks enabling one theme disables the others |
|
133 function run_test_1() { |
|
134 prepare_test({ |
|
135 "theme1@tests.mozilla.org": [ |
|
136 "onDisabling" |
|
137 ], |
|
138 "theme2@tests.mozilla.org": [ |
|
139 "onEnabling" |
|
140 ] |
|
141 }); |
|
142 AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
|
143 "theme2@tests.mozilla.org"], function([t1, t2]) { |
|
144 t2.userDisabled = false; |
|
145 |
|
146 ensure_test_completed(); |
|
147 do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
148 do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
149 |
|
150 do_check_true(t1.userDisabled); |
|
151 do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
152 do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
153 |
|
154 do_execute_soon(check_test_1); |
|
155 }); |
|
156 } |
|
157 |
|
158 function check_test_1() { |
|
159 restartManager(); |
|
160 do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme2/1.0"); |
|
161 |
|
162 AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
|
163 "theme2@tests.mozilla.org"], function([t1, t2]) { |
|
164 do_check_neq(t1, null); |
|
165 do_check_true(t1.userDisabled); |
|
166 do_check_false(t1.appDisabled); |
|
167 do_check_false(t1.isActive); |
|
168 do_check_false(isThemeInAddonsList(profileDir, t1.id)); |
|
169 do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
170 do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
171 do_check_eq(t1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE); |
|
172 |
|
173 do_check_neq(t2, null); |
|
174 do_check_false(t2.userDisabled); |
|
175 do_check_false(t2.appDisabled); |
|
176 do_check_true(t2.isActive); |
|
177 do_check_true(isThemeInAddonsList(profileDir, t2.id)); |
|
178 do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
179 do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
180 do_check_eq(t2.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_UNINSTALL | |
|
181 AddonManager.OP_NEEDS_RESTART_DISABLE); |
|
182 do_check_false(gLWThemeChanged); |
|
183 |
|
184 do_execute_soon(run_test_2); |
|
185 }); |
|
186 } |
|
187 |
|
188 // Removing the active theme should fall back to the default (not ideal in this |
|
189 // case since we don't have the default theme installed) |
|
190 function run_test_2() { |
|
191 var dest = profileDir.clone(); |
|
192 dest.append(do_get_expected_addon_name("theme2@tests.mozilla.org")); |
|
193 dest.remove(true); |
|
194 |
|
195 restartManager(); |
|
196 do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0"); |
|
197 |
|
198 AddonManager.getAddonsByIDs(["theme1@tests.mozilla.org", |
|
199 "theme2@tests.mozilla.org"], function([t1, t2]) { |
|
200 do_check_neq(t1, null); |
|
201 do_check_true(t1.userDisabled); |
|
202 do_check_false(t1.appDisabled); |
|
203 do_check_false(t1.isActive); |
|
204 do_check_false(isThemeInAddonsList(profileDir, t1.id)); |
|
205 do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE)); |
|
206 do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
207 |
|
208 do_check_eq(t2, null); |
|
209 do_check_false(isThemeInAddonsList(profileDir, "theme2@tests.mozilla.org")); |
|
210 do_check_false(gLWThemeChanged); |
|
211 |
|
212 do_execute_soon(run_test_3); |
|
213 }); |
|
214 } |
|
215 |
|
216 // Installing a lightweight theme should happen instantly and disable the default theme |
|
217 function run_test_3() { |
|
218 writeInstallRDFForExtension({ |
|
219 id: "theme2@tests.mozilla.org", |
|
220 version: "1.0", |
|
221 name: "Test 1", |
|
222 internalName: "theme2/1.0", |
|
223 targetApplications: [{ |
|
224 id: "xpcshell@tests.mozilla.org", |
|
225 minVersion: "1", |
|
226 maxVersion: "2" |
|
227 }] |
|
228 }, profileDir); |
|
229 restartManager(); |
|
230 |
|
231 prepare_test({ |
|
232 "1@personas.mozilla.org": [ |
|
233 ["onInstalling", false], |
|
234 "onInstalled", |
|
235 ["onEnabling", false], |
|
236 "onEnabled" |
|
237 ], |
|
238 "default@tests.mozilla.org": [ |
|
239 ["onDisabling", false], |
|
240 "onDisabled", |
|
241 ] |
|
242 }, [ |
|
243 "onExternalInstall" |
|
244 ]); |
|
245 |
|
246 LightweightThemeManager.currentTheme = { |
|
247 id: "1", |
|
248 version: "1", |
|
249 name: "Test LW Theme", |
|
250 description: "A test theme", |
|
251 author: "Mozilla", |
|
252 homepageURL: "http://localhost/data/index.html", |
|
253 headerURL: "http://localhost/data/header.png", |
|
254 footerURL: "http://localhost/data/footer.png", |
|
255 previewURL: "http://localhost/data/preview.png", |
|
256 iconURL: "http://localhost/data/icon.png" |
|
257 }; |
|
258 |
|
259 ensure_test_completed(); |
|
260 |
|
261 AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
|
262 do_check_neq(null, p1); |
|
263 do_check_eq(p1.name, "Test LW Theme"); |
|
264 do_check_eq(p1.version, "1"); |
|
265 do_check_eq(p1.type, "theme"); |
|
266 do_check_eq(p1.description, "A test theme"); |
|
267 do_check_eq(p1.creator, "Mozilla"); |
|
268 do_check_eq(p1.homepageURL, "http://localhost/data/index.html"); |
|
269 do_check_eq(p1.iconURL, "http://localhost/data/icon.png"); |
|
270 do_check_eq(p1.screenshots.length, 1); |
|
271 do_check_eq(p1.screenshots[0], "http://localhost/data/preview.png"); |
|
272 do_check_false(p1.appDisabled); |
|
273 do_check_false(p1.userDisabled); |
|
274 do_check_true(p1.isCompatible); |
|
275 do_check_true(p1.providesUpdatesSecurely); |
|
276 do_check_eq(p1.blocklistState, 0); |
|
277 do_check_true(p1.isActive); |
|
278 do_check_eq(p1.pendingOperations, 0); |
|
279 do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE); |
|
280 do_check_eq(p1.scope, AddonManager.SCOPE_PROFILE); |
|
281 do_check_true("isCompatibleWith" in p1); |
|
282 do_check_true("findUpdates" in p1); |
|
283 do_check_eq(p1.installDate.getTime(), p1.updateDate.getTime()); |
|
284 |
|
285 // Should have been installed sometime in the last few seconds. |
|
286 let difference = Date.now() - p1.installDate.getTime(); |
|
287 if (difference > MAX_INSTALL_TIME) |
|
288 do_throw("Add-on was installed " + difference + "ms ago"); |
|
289 else if (difference < 0) |
|
290 do_throw("Add-on was installed " + difference + "ms in the future"); |
|
291 |
|
292 AddonManager.getAddonsByTypes(["theme"], function(addons) { |
|
293 let seen = false; |
|
294 addons.forEach(function(a) { |
|
295 if (a.id == "1@personas.mozilla.org") { |
|
296 seen = true; |
|
297 } |
|
298 else { |
|
299 dump("Checking theme " + a.id + "\n"); |
|
300 do_check_false(a.isActive); |
|
301 do_check_true(a.userDisabled); |
|
302 } |
|
303 }); |
|
304 do_check_true(seen); |
|
305 |
|
306 do_check_true(gLWThemeChanged); |
|
307 gLWThemeChanged = false; |
|
308 |
|
309 do_execute_soon(run_test_4); |
|
310 }); |
|
311 }); |
|
312 } |
|
313 |
|
314 // Installing a second lightweight theme should disable the first with no restart |
|
315 function run_test_4() { |
|
316 prepare_test({ |
|
317 "1@personas.mozilla.org": [ |
|
318 ["onDisabling", false], |
|
319 "onDisabled", |
|
320 ], |
|
321 "2@personas.mozilla.org": [ |
|
322 ["onInstalling", false], |
|
323 "onInstalled", |
|
324 ["onEnabling", false], |
|
325 "onEnabled" |
|
326 ] |
|
327 }, [ |
|
328 "onExternalInstall" |
|
329 ]); |
|
330 |
|
331 LightweightThemeManager.currentTheme = { |
|
332 id: "2", |
|
333 version: "1", |
|
334 name: "Test LW Theme", |
|
335 description: "A second test theme", |
|
336 author: "Mozilla", |
|
337 homepageURL: "http://localhost/data/index.html", |
|
338 headerURL: "http://localhost/data/header.png", |
|
339 footerURL: "http://localhost/data/footer.png", |
|
340 previewURL: "http://localhost/data/preview.png", |
|
341 iconURL: "http://localhost/data/icon.png" |
|
342 }; |
|
343 |
|
344 ensure_test_completed(); |
|
345 |
|
346 AddonManager.getAddonsByIDs(["1@personas.mozilla.org", |
|
347 "2@personas.mozilla.org"], function([p1, p2]) { |
|
348 do_check_neq(null, p2); |
|
349 do_check_false(p2.appDisabled); |
|
350 do_check_false(p2.userDisabled); |
|
351 do_check_true(p2.isActive); |
|
352 do_check_eq(p2.pendingOperations, 0); |
|
353 do_check_eq(p2.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE); |
|
354 do_check_eq(p2.installDate.getTime(), p2.updateDate.getTime()); |
|
355 |
|
356 // Should have been installed sometime in the last few seconds. |
|
357 let difference = Date.now() - p2.installDate.getTime(); |
|
358 if (difference > MAX_INSTALL_TIME) |
|
359 do_throw("Add-on was installed " + difference + "ms ago"); |
|
360 else if (difference < 0) |
|
361 do_throw("Add-on was installed " + difference + "ms in the future"); |
|
362 |
|
363 do_check_neq(null, p1); |
|
364 do_check_false(p1.appDisabled); |
|
365 do_check_true(p1.userDisabled); |
|
366 do_check_false(p1.isActive); |
|
367 do_check_eq(p1.pendingOperations, 0); |
|
368 do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_ENABLE); |
|
369 |
|
370 AddonManager.getAddonsByTypes(["theme"], function(addons) { |
|
371 let seen = false; |
|
372 addons.forEach(function(a) { |
|
373 if (a.id == "2@personas.mozilla.org") { |
|
374 seen = true; |
|
375 } |
|
376 else { |
|
377 dump("Checking theme " + a.id + "\n"); |
|
378 do_check_false(a.isActive); |
|
379 do_check_true(a.userDisabled); |
|
380 } |
|
381 }); |
|
382 do_check_true(seen); |
|
383 |
|
384 do_check_true(gLWThemeChanged); |
|
385 gLWThemeChanged = false; |
|
386 |
|
387 do_execute_soon(run_test_5); |
|
388 }); |
|
389 }); |
|
390 } |
|
391 |
|
392 // Switching to a custom theme should disable the lightweight theme and require |
|
393 // a restart. Cancelling that should also be possible. |
|
394 function run_test_5() { |
|
395 prepare_test({ |
|
396 "2@personas.mozilla.org": [ |
|
397 "onDisabling", |
|
398 ], |
|
399 "theme2@tests.mozilla.org": [ |
|
400 "onEnabling" |
|
401 ] |
|
402 }); |
|
403 |
|
404 AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
|
405 "theme2@tests.mozilla.org"], function([p2, t2]) { |
|
406 t2.userDisabled = false; |
|
407 |
|
408 ensure_test_completed(); |
|
409 |
|
410 prepare_test({ |
|
411 "2@personas.mozilla.org": [ |
|
412 "onOperationCancelled", |
|
413 ], |
|
414 "theme2@tests.mozilla.org": [ |
|
415 "onOperationCancelled" |
|
416 ] |
|
417 }); |
|
418 |
|
419 p2.userDisabled = false; |
|
420 |
|
421 ensure_test_completed(); |
|
422 |
|
423 prepare_test({ |
|
424 "2@personas.mozilla.org": [ |
|
425 "onDisabling", |
|
426 ], |
|
427 "theme2@tests.mozilla.org": [ |
|
428 "onEnabling" |
|
429 ] |
|
430 }); |
|
431 |
|
432 t2.userDisabled = false; |
|
433 |
|
434 ensure_test_completed(); |
|
435 |
|
436 do_check_false(t2.isActive); |
|
437 do_check_false(t2.userDisabled); |
|
438 do_check_true(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations)); |
|
439 do_check_true(p2.isActive); |
|
440 do_check_true(p2.userDisabled); |
|
441 do_check_true(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations)); |
|
442 do_check_true(hasFlag(AddonManager.PERM_CAN_ENABLE, p2.permissions)); |
|
443 do_check_false(gLWThemeChanged); |
|
444 |
|
445 do_execute_soon(check_test_5); |
|
446 }); |
|
447 } |
|
448 |
|
449 function check_test_5() { |
|
450 restartManager(); |
|
451 |
|
452 AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
|
453 "theme2@tests.mozilla.org"], function([p2, t2]) { |
|
454 do_check_true(t2.isActive); |
|
455 do_check_false(t2.userDisabled); |
|
456 do_check_false(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations)); |
|
457 do_check_false(p2.isActive); |
|
458 do_check_true(p2.userDisabled); |
|
459 do_check_false(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations)); |
|
460 |
|
461 do_check_true(gLWThemeChanged); |
|
462 gLWThemeChanged = false; |
|
463 |
|
464 do_execute_soon(run_test_6); |
|
465 }); |
|
466 } |
|
467 |
|
468 // Switching from a custom theme to a lightweight theme should require a restart |
|
469 function run_test_6() { |
|
470 prepare_test({ |
|
471 "2@personas.mozilla.org": [ |
|
472 "onEnabling", |
|
473 ], |
|
474 "theme2@tests.mozilla.org": [ |
|
475 "onDisabling" |
|
476 ] |
|
477 }); |
|
478 |
|
479 AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
|
480 "theme2@tests.mozilla.org"], function([p2, t2]) { |
|
481 p2.userDisabled = false; |
|
482 |
|
483 ensure_test_completed(); |
|
484 |
|
485 prepare_test({ |
|
486 "2@personas.mozilla.org": [ |
|
487 "onOperationCancelled", |
|
488 ], |
|
489 "theme2@tests.mozilla.org": [ |
|
490 "onOperationCancelled" |
|
491 ] |
|
492 }); |
|
493 |
|
494 t2.userDisabled = false; |
|
495 |
|
496 ensure_test_completed(); |
|
497 |
|
498 prepare_test({ |
|
499 "2@personas.mozilla.org": [ |
|
500 "onEnabling", |
|
501 ], |
|
502 "theme2@tests.mozilla.org": [ |
|
503 "onDisabling" |
|
504 ] |
|
505 }); |
|
506 |
|
507 p2.userDisabled = false; |
|
508 |
|
509 ensure_test_completed(); |
|
510 |
|
511 do_check_false(p2.isActive); |
|
512 do_check_false(p2.userDisabled); |
|
513 do_check_true(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations)); |
|
514 do_check_true(t2.isActive); |
|
515 do_check_true(t2.userDisabled); |
|
516 do_check_true(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations)); |
|
517 do_check_false(gLWThemeChanged); |
|
518 |
|
519 do_execute_soon(check_test_6); |
|
520 }); |
|
521 } |
|
522 |
|
523 function check_test_6() { |
|
524 restartManager(); |
|
525 |
|
526 AddonManager.getAddonsByIDs(["2@personas.mozilla.org", |
|
527 "theme2@tests.mozilla.org"], function([p2, t2]) { |
|
528 do_check_true(p2.isActive); |
|
529 do_check_false(p2.userDisabled); |
|
530 do_check_false(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations)); |
|
531 do_check_false(t2.isActive); |
|
532 do_check_true(t2.userDisabled); |
|
533 do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations)); |
|
534 |
|
535 do_check_true(gLWThemeChanged); |
|
536 gLWThemeChanged = false; |
|
537 |
|
538 do_execute_soon(run_test_7); |
|
539 }); |
|
540 } |
|
541 |
|
542 // Uninstalling a lightweight theme should not require a restart |
|
543 function run_test_7() { |
|
544 prepare_test({ |
|
545 "1@personas.mozilla.org": [ |
|
546 ["onUninstalling", false], |
|
547 "onUninstalled" |
|
548 ] |
|
549 }); |
|
550 |
|
551 AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
|
552 p1.uninstall(); |
|
553 |
|
554 ensure_test_completed(); |
|
555 do_check_eq(LightweightThemeManager.usedThemes.length, 1); |
|
556 do_check_false(gLWThemeChanged); |
|
557 |
|
558 do_execute_soon(run_test_8); |
|
559 }); |
|
560 } |
|
561 |
|
562 // Uninstalling a lightweight theme in use should not require a restart and it |
|
563 // should reactivate the default theme |
|
564 // Also, uninstalling a lightweight theme in use should send a |
|
565 // "lightweight-theme-styling-update" notification through the observer service |
|
566 function run_test_8() { |
|
567 prepare_test({ |
|
568 "2@personas.mozilla.org": [ |
|
569 ["onUninstalling", false], |
|
570 "onUninstalled" |
|
571 ], |
|
572 "default@tests.mozilla.org": [ |
|
573 ["onEnabling", false], |
|
574 "onEnabled" |
|
575 ] |
|
576 }); |
|
577 |
|
578 AddonManager.getAddonByID("2@personas.mozilla.org", function(p2) { |
|
579 p2.uninstall(); |
|
580 |
|
581 ensure_test_completed(); |
|
582 do_check_eq(LightweightThemeManager.usedThemes.length, 0); |
|
583 |
|
584 do_check_true(gLWThemeChanged); |
|
585 gLWThemeChanged = false; |
|
586 |
|
587 do_execute_soon(run_test_9); |
|
588 }); |
|
589 } |
|
590 |
|
591 // Uninstalling a theme not in use should not require a restart |
|
592 function run_test_9() { |
|
593 AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
|
594 prepare_test({ |
|
595 "theme1@tests.mozilla.org": [ |
|
596 ["onUninstalling", false], |
|
597 "onUninstalled" |
|
598 ] |
|
599 }); |
|
600 |
|
601 t1.uninstall(); |
|
602 |
|
603 ensure_test_completed(); |
|
604 |
|
605 AddonManager.getAddonByID("theme1@tests.mozilla.org", function(newt1) { |
|
606 do_check_eq(newt1, null); |
|
607 do_check_false(gLWThemeChanged); |
|
608 |
|
609 do_execute_soon(run_test_10); |
|
610 }); |
|
611 }); |
|
612 } |
|
613 |
|
614 // Uninstalling a custom theme in use should require a restart |
|
615 function run_test_10() { |
|
616 AddonManager.getAddonByID("theme2@tests.mozilla.org", callback_soon(function(oldt2) { |
|
617 prepare_test({ |
|
618 "theme2@tests.mozilla.org": [ |
|
619 "onEnabling", |
|
620 ], |
|
621 "default@tests.mozilla.org": [ |
|
622 "onDisabling" |
|
623 ] |
|
624 }); |
|
625 |
|
626 oldt2.userDisabled = false; |
|
627 |
|
628 ensure_test_completed(); |
|
629 |
|
630 restartManager(); |
|
631 |
|
632 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
633 "theme2@tests.mozilla.org"], function([d, t2]) { |
|
634 do_check_true(t2.isActive); |
|
635 do_check_false(t2.userDisabled); |
|
636 do_check_false(t2.appDisabled); |
|
637 do_check_false(d.isActive); |
|
638 do_check_true(d.userDisabled); |
|
639 do_check_false(d.appDisabled); |
|
640 |
|
641 prepare_test({ |
|
642 "theme2@tests.mozilla.org": [ |
|
643 "onUninstalling", |
|
644 ], |
|
645 "default@tests.mozilla.org": [ |
|
646 "onEnabling" |
|
647 ] |
|
648 }); |
|
649 |
|
650 t2.uninstall(); |
|
651 |
|
652 ensure_test_completed(); |
|
653 do_check_false(gLWThemeChanged); |
|
654 |
|
655 do_execute_soon(run_test_11); |
|
656 }); |
|
657 })); |
|
658 } |
|
659 |
|
660 // Installing a custom theme not in use should not require a restart |
|
661 function run_test_11() { |
|
662 restartManager(); |
|
663 |
|
664 prepare_test({ }, [ |
|
665 "onNewInstall" |
|
666 ]); |
|
667 |
|
668 AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
|
669 ensure_test_completed(); |
|
670 |
|
671 do_check_neq(install, null); |
|
672 do_check_eq(install.type, "theme"); |
|
673 do_check_eq(install.version, "1.0"); |
|
674 do_check_eq(install.name, "Test Theme 1"); |
|
675 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
676 do_check_true(install.addon.skinnable, true); |
|
677 do_check_false(hasFlag(install.addon.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_INSTALL)); |
|
678 |
|
679 prepare_test({ |
|
680 "theme1@tests.mozilla.org": [ |
|
681 ["onInstalling", false], |
|
682 "onInstalled" |
|
683 ] |
|
684 }, [ |
|
685 "onInstallStarted", |
|
686 "onInstallEnded", |
|
687 ], check_test_11); |
|
688 install.install(); |
|
689 }); |
|
690 } |
|
691 |
|
692 function check_test_11() { |
|
693 AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
|
694 do_check_neq(t1, null); |
|
695 var previewSpec = do_get_addon_root_uri(profileDir, "theme1@tests.mozilla.org") + "preview.png"; |
|
696 do_check_eq(t1.screenshots.length, 1); |
|
697 do_check_eq(t1.screenshots[0], previewSpec); |
|
698 do_check_true(t1.skinnable); |
|
699 do_check_false(gLWThemeChanged); |
|
700 |
|
701 do_execute_soon(run_test_12); |
|
702 }); |
|
703 } |
|
704 |
|
705 // Updating a custom theme not in use should not require a restart |
|
706 function run_test_12() { |
|
707 prepare_test({ }, [ |
|
708 "onNewInstall" |
|
709 ]); |
|
710 |
|
711 AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
|
712 ensure_test_completed(); |
|
713 |
|
714 do_check_neq(install, null); |
|
715 do_check_eq(install.type, "theme"); |
|
716 do_check_eq(install.version, "1.0"); |
|
717 do_check_eq(install.name, "Test Theme 1"); |
|
718 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
719 do_check_false(hasFlag(install.addon.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_INSTALL)); |
|
720 |
|
721 prepare_test({ |
|
722 "theme1@tests.mozilla.org": [ |
|
723 ["onInstalling", false], |
|
724 "onInstalled" |
|
725 ] |
|
726 }, [ |
|
727 "onInstallStarted", |
|
728 "onInstallEnded", |
|
729 ], check_test_12); |
|
730 install.install(); |
|
731 }); |
|
732 } |
|
733 |
|
734 function check_test_12() { |
|
735 AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) { |
|
736 do_check_neq(t1, null); |
|
737 do_check_false(gLWThemeChanged); |
|
738 |
|
739 do_execute_soon(run_test_13); |
|
740 }); |
|
741 } |
|
742 |
|
743 // Updating a custom theme in use should require a restart |
|
744 function run_test_13() { |
|
745 AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
|
746 prepare_test({ |
|
747 "theme1@tests.mozilla.org": [ |
|
748 "onEnabling", |
|
749 ], |
|
750 "default@tests.mozilla.org": [ |
|
751 "onDisabling" |
|
752 ] |
|
753 }); |
|
754 |
|
755 t1.userDisabled = false; |
|
756 ensure_test_completed(); |
|
757 restartManager(); |
|
758 |
|
759 prepare_test({ }, [ |
|
760 "onNewInstall" |
|
761 ]); |
|
762 |
|
763 AddonManager.getInstallForFile(do_get_addon("test_theme"), function(install) { |
|
764 ensure_test_completed(); |
|
765 |
|
766 do_check_neq(install, null); |
|
767 do_check_eq(install.type, "theme"); |
|
768 do_check_eq(install.version, "1.0"); |
|
769 do_check_eq(install.name, "Test Theme 1"); |
|
770 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); |
|
771 do_check_true(hasFlag(install.addon.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_INSTALL)); |
|
772 |
|
773 prepare_test({ |
|
774 "theme1@tests.mozilla.org": [ |
|
775 "onInstalling", |
|
776 ] |
|
777 }, [ |
|
778 "onInstallStarted", |
|
779 "onInstallEnded", |
|
780 ], callback_soon(check_test_13)); |
|
781 install.install(); |
|
782 }); |
|
783 })); |
|
784 } |
|
785 |
|
786 function check_test_13() { |
|
787 restartManager(); |
|
788 |
|
789 AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
|
790 do_check_neq(t1, null); |
|
791 do_check_true(t1.isActive); |
|
792 do_check_false(gLWThemeChanged); |
|
793 t1.uninstall(); |
|
794 restartManager(); |
|
795 |
|
796 do_execute_soon(run_test_14); |
|
797 })); |
|
798 } |
|
799 |
|
800 // Switching from a lightweight theme to the default theme should not require |
|
801 // a restart |
|
802 function run_test_14() { |
|
803 LightweightThemeManager.currentTheme = { |
|
804 id: "1", |
|
805 version: "1", |
|
806 name: "Test LW Theme", |
|
807 description: "A test theme", |
|
808 author: "Mozilla", |
|
809 homepageURL: "http://localhost/data/index.html", |
|
810 headerURL: "http://localhost/data/header.png", |
|
811 footerURL: "http://localhost/data/footer.png", |
|
812 previewURL: "http://localhost/data/preview.png", |
|
813 iconURL: "http://localhost/data/icon.png" |
|
814 }; |
|
815 |
|
816 AddonManager.getAddonByID("default@tests.mozilla.org", function(d) { |
|
817 do_check_true(d.userDisabled); |
|
818 do_check_false(d.isActive); |
|
819 |
|
820 prepare_test({ |
|
821 "1@personas.mozilla.org": [ |
|
822 ["onDisabling", false], |
|
823 "onDisabled" |
|
824 ], |
|
825 "default@tests.mozilla.org": [ |
|
826 ["onEnabling", false], |
|
827 "onEnabled" |
|
828 ] |
|
829 }); |
|
830 |
|
831 d.userDisabled = false; |
|
832 ensure_test_completed(); |
|
833 |
|
834 do_check_false(d.userDisabled); |
|
835 do_check_true(d.isActive); |
|
836 |
|
837 do_check_true(gLWThemeChanged); |
|
838 gLWThemeChanged = false; |
|
839 |
|
840 do_execute_soon(run_test_15); |
|
841 }); |
|
842 } |
|
843 |
|
844 // Upgrading the application with a custom theme in use should not disable it |
|
845 function run_test_15() { |
|
846 restartManager(); |
|
847 |
|
848 installAllFiles([do_get_addon("test_theme")], function() { |
|
849 AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
|
850 t1.userDisabled = false; |
|
851 |
|
852 restartManager(); |
|
853 |
|
854 do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme1/1.0"); |
|
855 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
856 "theme1@tests.mozilla.org"], |
|
857 callback_soon(function([d, t1]) { |
|
858 do_check_true(d.userDisabled); |
|
859 do_check_false(d.appDisabled); |
|
860 do_check_false(d.isActive); |
|
861 |
|
862 do_check_false(t1.userDisabled); |
|
863 do_check_false(t1.appDisabled); |
|
864 do_check_true(t1.isActive); |
|
865 |
|
866 restartManager("2"); |
|
867 |
|
868 do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "theme1/1.0"); |
|
869 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
870 "theme1@tests.mozilla.org"], function([d, t1]) { |
|
871 do_check_true(d.userDisabled); |
|
872 do_check_false(d.appDisabled); |
|
873 do_check_false(d.isActive); |
|
874 |
|
875 do_check_false(t1.userDisabled); |
|
876 do_check_false(t1.appDisabled); |
|
877 do_check_true(t1.isActive); |
|
878 |
|
879 do_execute_soon(run_test_16); |
|
880 }); |
|
881 })); |
|
882 })); |
|
883 }); |
|
884 } |
|
885 |
|
886 // Upgrading the application with a custom theme in use should disable it if it |
|
887 // is no longer compatible |
|
888 function run_test_16() { |
|
889 restartManager("3"); |
|
890 |
|
891 do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0"); |
|
892 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
893 "theme1@tests.mozilla.org"], function([d, t1]) { |
|
894 do_check_false(d.userDisabled); |
|
895 do_check_false(d.appDisabled); |
|
896 do_check_true(d.isActive); |
|
897 |
|
898 do_check_true(t1.userDisabled); |
|
899 do_check_true(t1.appDisabled); |
|
900 do_check_false(t1.isActive); |
|
901 |
|
902 do_execute_soon(run_test_17); |
|
903 }); |
|
904 } |
|
905 |
|
906 // Verifies that if the selected theme pref is changed by a different version |
|
907 // of the application that we correctly reset it when it points to an |
|
908 // incompatible theme |
|
909 function run_test_17() { |
|
910 restartManager("2"); |
|
911 shutdownManager(); |
|
912 |
|
913 Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0"); |
|
914 |
|
915 restartManager("3"); |
|
916 |
|
917 do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0"); |
|
918 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
919 "theme1@tests.mozilla.org"], function([d, t1]) { |
|
920 do_check_false(d.userDisabled); |
|
921 do_check_false(d.appDisabled); |
|
922 do_check_true(d.isActive); |
|
923 |
|
924 do_check_true(t1.userDisabled); |
|
925 do_check_true(t1.appDisabled); |
|
926 do_check_false(t1.isActive); |
|
927 |
|
928 do_execute_soon(run_test_18); |
|
929 }); |
|
930 } |
|
931 |
|
932 // Disabling the active theme should switch back to the default theme |
|
933 function run_test_18() { |
|
934 restartManager(2); |
|
935 |
|
936 AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
|
937 t1.userDisabled = false; |
|
938 |
|
939 restartManager(); |
|
940 |
|
941 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
942 "theme1@tests.mozilla.org"], |
|
943 callback_soon(function([d, t1]) { |
|
944 do_check_true(d.userDisabled); |
|
945 do_check_false(d.appDisabled); |
|
946 do_check_false(d.isActive); |
|
947 |
|
948 do_check_false(t1.userDisabled); |
|
949 do_check_false(t1.appDisabled); |
|
950 do_check_true(t1.isActive); |
|
951 |
|
952 prepare_test({ |
|
953 "theme1@tests.mozilla.org": [ |
|
954 "onDisabling", |
|
955 ], |
|
956 "default@tests.mozilla.org": [ |
|
957 "onEnabling", |
|
958 ] |
|
959 }); |
|
960 t1.userDisabled = true; |
|
961 ensure_test_completed(); |
|
962 |
|
963 do_check_false(d.userDisabled); |
|
964 do_check_false(d.appDisabled); |
|
965 do_check_false(d.isActive); |
|
966 |
|
967 do_check_true(t1.userDisabled); |
|
968 do_check_false(t1.appDisabled); |
|
969 do_check_true(t1.isActive); |
|
970 |
|
971 restartManager(); |
|
972 |
|
973 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
974 "theme1@tests.mozilla.org"], function([d, t1]) { |
|
975 do_check_false(d.userDisabled); |
|
976 do_check_false(d.appDisabled); |
|
977 do_check_true(d.isActive); |
|
978 |
|
979 do_check_true(t1.userDisabled); |
|
980 do_check_false(t1.appDisabled); |
|
981 do_check_false(t1.isActive); |
|
982 |
|
983 do_execute_soon(run_test_19); |
|
984 }); |
|
985 })); |
|
986 })); |
|
987 } |
|
988 |
|
989 // Disabling the active persona should switch back to the default theme |
|
990 function run_test_19() { |
|
991 AddonManager.getAddonsByIDs(["default@tests.mozilla.org", |
|
992 "1@personas.mozilla.org"], function([d, p1]) { |
|
993 p1.userDisabled = false; |
|
994 |
|
995 do_check_true(d.userDisabled); |
|
996 do_check_false(d.appDisabled); |
|
997 do_check_false(d.isActive); |
|
998 |
|
999 do_check_false(p1.userDisabled); |
|
1000 do_check_false(p1.appDisabled); |
|
1001 do_check_true(p1.isActive); |
|
1002 |
|
1003 prepare_test({ |
|
1004 "1@personas.mozilla.org": [ |
|
1005 ["onDisabling", false], |
|
1006 "onDisabled" |
|
1007 ], |
|
1008 "default@tests.mozilla.org": [ |
|
1009 ["onEnabling", false], |
|
1010 "onEnabled" |
|
1011 ] |
|
1012 }); |
|
1013 p1.userDisabled = true; |
|
1014 ensure_test_completed(); |
|
1015 |
|
1016 do_check_false(d.userDisabled); |
|
1017 do_check_false(d.appDisabled); |
|
1018 do_check_true(d.isActive); |
|
1019 |
|
1020 do_check_true(p1.userDisabled); |
|
1021 do_check_false(p1.appDisabled); |
|
1022 do_check_false(p1.isActive); |
|
1023 |
|
1024 do_execute_soon(run_test_20); |
|
1025 }); |
|
1026 } |
|
1027 |
|
1028 // Tests that you cannot disable the default theme |
|
1029 function run_test_20() { |
|
1030 AddonManager.getAddonByID("default@tests.mozilla.org", function(d) { |
|
1031 do_check_false(d.userDisabled); |
|
1032 do_check_false(d.appDisabled); |
|
1033 do_check_true(d.isActive); |
|
1034 |
|
1035 try { |
|
1036 d.userDisabled = true; |
|
1037 do_throw("Disabling the default theme should throw an exception"); |
|
1038 } |
|
1039 catch (e) { |
|
1040 } |
|
1041 |
|
1042 do_execute_soon(run_test_21); |
|
1043 }); |
|
1044 } |
|
1045 |
|
1046 // Tests that cached copies of a lightweight theme have the right permissions |
|
1047 // and pendingOperations during the onEnabling event |
|
1048 function run_test_21() { |
|
1049 AddonManager.getAddonByID("theme1@tests.mozilla.org", callback_soon(function(t1) { |
|
1050 // Switch to a custom theme so we can test pendingOperations properly. |
|
1051 |
|
1052 prepare_test({ |
|
1053 "theme1@tests.mozilla.org": [ |
|
1054 "onEnabling" |
|
1055 ], |
|
1056 "default@tests.mozilla.org": [ |
|
1057 "onDisabling" |
|
1058 ] |
|
1059 }); |
|
1060 |
|
1061 t1.userDisabled = false; |
|
1062 ensure_test_completed(); |
|
1063 |
|
1064 restartManager(); |
|
1065 |
|
1066 AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) { |
|
1067 AddonManager.addAddonListener({ |
|
1068 onEnabling: function(aAddon) { |
|
1069 do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE)); |
|
1070 do_check_true(hasFlag(aAddon.pendingOperations, AddonManager.PENDING_ENABLE)); |
|
1071 |
|
1072 do_check_eq(aAddon.permissions, p1.permissions); |
|
1073 do_check_eq(aAddon.pendingOperations, p1.pendingOperations); |
|
1074 } |
|
1075 }); |
|
1076 |
|
1077 prepare_test({ |
|
1078 "1@personas.mozilla.org": [ |
|
1079 "onEnabling" |
|
1080 ], |
|
1081 "theme1@tests.mozilla.org": [ |
|
1082 "onDisabling" |
|
1083 ] |
|
1084 }); |
|
1085 |
|
1086 p1.userDisabled = false; |
|
1087 ensure_test_completed(); |
|
1088 |
|
1089 end_test(); |
|
1090 }); |
|
1091 })); |
|
1092 } |