|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that the discovery view loads properly |
|
6 |
|
7 const MAIN_URL = "https://example.com/" + RELATIVE_DIR + "discovery.html"; |
|
8 |
|
9 var gManagerWindow; |
|
10 var gCategoryUtilities; |
|
11 var gProvider; |
|
12 |
|
13 var gLoadCompleteCallback = null; |
|
14 |
|
15 var gProgressListener = { |
|
16 onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) { |
|
17 // Only care about the network stop status events |
|
18 if (!(aStateFlags & (Ci.nsIWebProgressListener.STATE_IS_NETWORK)) || |
|
19 !(aStateFlags & (Ci.nsIWebProgressListener.STATE_STOP))) |
|
20 return; |
|
21 |
|
22 if (gLoadCompleteCallback) |
|
23 executeSoon(gLoadCompleteCallback); |
|
24 gLoadCompleteCallback = null; |
|
25 }, |
|
26 |
|
27 onLocationChange: function() { }, |
|
28 onSecurityChange: function() { }, |
|
29 onProgressChange: function() { }, |
|
30 onStatusChange: function() { }, |
|
31 |
|
32 QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, |
|
33 Ci.nsISupportsWeakReference]), |
|
34 }; |
|
35 |
|
36 function test() { |
|
37 // Switch to a known url |
|
38 Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL); |
|
39 // Temporarily enable caching |
|
40 Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); |
|
41 |
|
42 waitForExplicitFinish(); |
|
43 |
|
44 gProvider = new MockProvider(); |
|
45 |
|
46 gProvider.createAddons([{ |
|
47 id: "addon1@tests.mozilla.org", |
|
48 name: "Test add-on 1", |
|
49 type: "extension", |
|
50 version: "2.2", |
|
51 isCompatible: false, |
|
52 blocklistState: Ci.nsIBlocklistService.STATE_SOFTBLOCKED, |
|
53 userDisabled: false |
|
54 }, { |
|
55 id: "addon2@tests.mozilla.org", |
|
56 name: "Test add-on 2", |
|
57 type: "plugin", |
|
58 version: "3.1.5", |
|
59 isCompatible: true, |
|
60 blocklistState: Ci.nsIBlocklistService.STATE_NOT_BLOCKED, |
|
61 userDisabled: false |
|
62 }, { |
|
63 id: "addon3@tests.mozilla.org", |
|
64 name: "Test add-on 3", |
|
65 type: "theme", |
|
66 version: "1.2b1", |
|
67 isCompatible: false, |
|
68 blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED, |
|
69 userDisabled: true |
|
70 }]); |
|
71 |
|
72 run_next_test(); |
|
73 } |
|
74 |
|
75 function end_test() { |
|
76 finish(); |
|
77 } |
|
78 |
|
79 function getURL(aBrowser) { |
|
80 if (gManagerWindow.document.getElementById("discover-view").selectedPanel != |
|
81 aBrowser) |
|
82 return null; |
|
83 |
|
84 var url = aBrowser.currentURI.spec; |
|
85 var pos = url.indexOf("#"); |
|
86 if (pos != -1) |
|
87 return url.substring(0, pos); |
|
88 return url; |
|
89 } |
|
90 |
|
91 function getHash(aBrowser) { |
|
92 if (gManagerWindow.document.getElementById("discover-view").selectedPanel != |
|
93 aBrowser) |
|
94 return null; |
|
95 |
|
96 var url = aBrowser.currentURI.spec; |
|
97 var pos = url.indexOf("#"); |
|
98 if (pos != -1) |
|
99 return decodeURIComponent(url.substring(pos + 1)); |
|
100 return null; |
|
101 } |
|
102 |
|
103 function testHash(aBrowser, aTestAddonVisible, aCallback) { |
|
104 var hash = getHash(aBrowser); |
|
105 isnot(hash, null, "There should be a hash"); |
|
106 try { |
|
107 var data = JSON.parse(hash); |
|
108 } |
|
109 catch (e) { |
|
110 ok(false, "Hash should have been valid JSON: " + e); |
|
111 aCallback(); |
|
112 return; |
|
113 } |
|
114 is(typeof data, "object", "Hash should be a JS object"); |
|
115 |
|
116 // Ensure that at least the test add-ons are present |
|
117 if (aTestAddonVisible[0]) |
|
118 ok("addon1@tests.mozilla.org" in data, "Test add-on 1 should be listed"); |
|
119 else |
|
120 ok(!("addon1@tests.mozilla.org" in data), "Test add-on 1 should not be listed"); |
|
121 if (aTestAddonVisible[1]) |
|
122 ok("addon2@tests.mozilla.org" in data, "Test add-on 2 should be listed"); |
|
123 else |
|
124 ok(!("addon2@tests.mozilla.org" in data), "Test add-on 2 should not be listed"); |
|
125 if (aTestAddonVisible[2]) |
|
126 ok("addon3@tests.mozilla.org" in data, "Test add-on 3 should be listed"); |
|
127 else |
|
128 ok(!("addon3@tests.mozilla.org" in data), "Test add-on 3 should not be listed"); |
|
129 |
|
130 // Test against all the add-ons the manager knows about since plugins and |
|
131 // app extensions may exist |
|
132 AddonManager.getAllAddons(function(aAddons) { |
|
133 for (let addon of aAddons) { |
|
134 if (!(addon.id in data)) { |
|
135 // Test add-ons will have shown an error if necessary above |
|
136 if (addon.id.substring(6) != "@tests.mozilla.org") |
|
137 ok(false, "Add-on " + addon.id + " was not included in the data"); |
|
138 continue; |
|
139 } |
|
140 |
|
141 info("Testing data for add-on " + addon.id); |
|
142 var addonData = data[addon.id]; |
|
143 is(addonData.name, addon.name, "Name should be correct"); |
|
144 is(addonData.version, addon.version, "Version should be correct"); |
|
145 is(addonData.type, addon.type, "Type should be correct"); |
|
146 is(addonData.userDisabled, addon.userDisabled, "userDisabled should be correct"); |
|
147 is(addonData.isBlocklisted, addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED, "blocklisted should be correct"); |
|
148 is(addonData.isCompatible, addon.isCompatible, "isCompatible should be correct"); |
|
149 } |
|
150 aCallback(); |
|
151 }); |
|
152 } |
|
153 |
|
154 function isLoading() { |
|
155 var loading = gManagerWindow.document.getElementById("discover-view").selectedPanel == |
|
156 gManagerWindow.document.getElementById("discover-loading"); |
|
157 if (loading) { |
|
158 is_element_visible(gManagerWindow.document.querySelector("#discover-loading .loading"), |
|
159 "Loading message should be visible when its panel is the selected panel"); |
|
160 } |
|
161 return loading; |
|
162 } |
|
163 |
|
164 function isError() { |
|
165 return gManagerWindow.document.getElementById("discover-view").selectedPanel == |
|
166 gManagerWindow.document.getElementById("discover-error"); |
|
167 } |
|
168 |
|
169 function clickLink(aId, aCallback) { |
|
170 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
171 browser.addProgressListener(gProgressListener); |
|
172 |
|
173 gLoadCompleteCallback = function() { |
|
174 browser.removeProgressListener(gProgressListener); |
|
175 aCallback(); |
|
176 }; |
|
177 |
|
178 var link = browser.contentDocument.getElementById(aId); |
|
179 EventUtils.sendMouseEvent({type: "click"}, link); |
|
180 |
|
181 executeSoon(function() { |
|
182 ok(isLoading(), "Clicking a link should show the loading pane"); |
|
183 }); |
|
184 } |
|
185 |
|
186 // Tests that switching to the discovery view displays the right url |
|
187 add_test(function() { |
|
188 open_manager("addons://list/extension", function(aWindow) { |
|
189 gManagerWindow = aWindow; |
|
190 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
191 |
|
192 gCategoryUtilities.openType("discover", function() { |
|
193 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
194 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
195 |
|
196 testHash(browser, [true, true, true], function() { |
|
197 close_manager(gManagerWindow, run_next_test); |
|
198 }); |
|
199 }); |
|
200 |
|
201 ok(isLoading(), "Should be loading at first"); |
|
202 }); |
|
203 }); |
|
204 |
|
205 // Tests that loading the add-ons manager with the discovery view as the last |
|
206 // selected view displays the right url |
|
207 add_test(function() { |
|
208 // Hide one of the test add-ons |
|
209 Services.prefs.setBoolPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled", false); |
|
210 Services.prefs.setBoolPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled", true); |
|
211 |
|
212 open_manager(null, function(aWindow) { |
|
213 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
214 is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view"); |
|
215 |
|
216 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
217 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
218 |
|
219 testHash(browser, [true, false, true], function() { |
|
220 close_manager(gManagerWindow, run_next_test); |
|
221 }); |
|
222 }, function(aWindow) { |
|
223 gManagerWindow = aWindow; |
|
224 ok(isLoading(), "Should be loading at first"); |
|
225 }); |
|
226 }); |
|
227 |
|
228 // Tests that loading the add-ons manager with the discovery view as the initial |
|
229 // view displays the right url |
|
230 add_test(function() { |
|
231 Services.prefs.clearUserPref("extensions.addon2@tests.mozilla.org.getAddons.cache.enabled"); |
|
232 Services.prefs.setBoolPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled", false); |
|
233 |
|
234 open_manager(null, function(aWindow) { |
|
235 gManagerWindow = aWindow; |
|
236 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
237 gCategoryUtilities.openType("extension", function() { |
|
238 close_manager(gManagerWindow, function() { |
|
239 open_manager("addons://discover/", function(aWindow) { |
|
240 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
241 is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view"); |
|
242 |
|
243 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
244 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
245 |
|
246 testHash(browser, [true, true, false], function() { |
|
247 Services.prefs.clearUserPref("extensions.addon3@tests.mozilla.org.getAddons.cache.enabled"); |
|
248 close_manager(gManagerWindow, run_next_test); |
|
249 }); |
|
250 }, function(aWindow) { |
|
251 gManagerWindow = aWindow; |
|
252 ok(isLoading(), "Should be loading at first"); |
|
253 }); |
|
254 }); |
|
255 }); |
|
256 }); |
|
257 }); |
|
258 |
|
259 // Tests that switching to the discovery view displays the right url |
|
260 add_test(function() { |
|
261 Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, false); |
|
262 |
|
263 open_manager("addons://list/extension", function(aWindow) { |
|
264 gManagerWindow = aWindow; |
|
265 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
266 |
|
267 gCategoryUtilities.openType("discover", function() { |
|
268 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
269 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
270 |
|
271 is(getHash(browser), null, "Hash should not have been passed"); |
|
272 close_manager(gManagerWindow, run_next_test); |
|
273 }); |
|
274 }); |
|
275 }); |
|
276 |
|
277 // Tests that loading the add-ons manager with the discovery view as the last |
|
278 // selected view displays the right url |
|
279 add_test(function() { |
|
280 open_manager(null, function(aWindow) { |
|
281 gManagerWindow = aWindow; |
|
282 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
283 is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view"); |
|
284 |
|
285 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
286 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
287 |
|
288 is(getHash(browser), null, "Hash should not have been passed"); |
|
289 close_manager(gManagerWindow, run_next_test); |
|
290 }); |
|
291 }); |
|
292 |
|
293 // Tests that loading the add-ons manager with the discovery view as the initial |
|
294 // view displays the right url |
|
295 add_test(function() { |
|
296 open_manager(null, function(aWindow) { |
|
297 gManagerWindow = aWindow; |
|
298 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
299 gCategoryUtilities.openType("extension", function() { |
|
300 close_manager(gManagerWindow, function() { |
|
301 open_manager("addons://discover/", function(aWindow) { |
|
302 gManagerWindow = aWindow; |
|
303 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
304 is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view"); |
|
305 |
|
306 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
307 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
308 |
|
309 is(getHash(browser), null, "Hash should not have been passed"); |
|
310 close_manager(gManagerWindow, run_next_test); |
|
311 }); |
|
312 }); |
|
313 }); |
|
314 }); |
|
315 }); |
|
316 |
|
317 // Tests that navigating to an insecure page fails |
|
318 add_test(function() { |
|
319 open_manager("addons://discover/", function(aWindow) { |
|
320 gManagerWindow = aWindow; |
|
321 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
322 |
|
323 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
324 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
325 |
|
326 clickLink("link-http", function() { |
|
327 ok(isError(), "Should have shown the error page"); |
|
328 |
|
329 gCategoryUtilities.openType("extension", function() { |
|
330 gCategoryUtilities.openType("discover", function() { |
|
331 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
332 |
|
333 close_manager(gManagerWindow, run_next_test); |
|
334 }); |
|
335 ok(isLoading(), "Should start loading again"); |
|
336 }); |
|
337 }); |
|
338 }); |
|
339 }); |
|
340 |
|
341 // Tests that navigating to a different domain fails |
|
342 add_test(function() { |
|
343 open_manager("addons://discover/", function(aWindow) { |
|
344 gManagerWindow = aWindow; |
|
345 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
346 |
|
347 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
348 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
349 |
|
350 clickLink("link-domain", function() { |
|
351 ok(isError(), "Should have shown the error page"); |
|
352 |
|
353 gCategoryUtilities.openType("extension", function() { |
|
354 gCategoryUtilities.openType("discover", function() { |
|
355 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
356 |
|
357 close_manager(gManagerWindow, run_next_test); |
|
358 }); |
|
359 ok(isLoading(), "Should start loading again"); |
|
360 }); |
|
361 }); |
|
362 }); |
|
363 }); |
|
364 |
|
365 // Tests that navigating to a missing page fails |
|
366 add_test(function() { |
|
367 open_manager("addons://discover/", function(aWindow) { |
|
368 gManagerWindow = aWindow; |
|
369 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
370 |
|
371 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
372 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
373 |
|
374 clickLink("link-bad", function() { |
|
375 ok(isError(), "Should have shown the error page"); |
|
376 |
|
377 gCategoryUtilities.openType("extension", function() { |
|
378 gCategoryUtilities.openType("discover", function() { |
|
379 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
380 |
|
381 close_manager(gManagerWindow, run_next_test); |
|
382 }); |
|
383 ok(isLoading(), "Should start loading again"); |
|
384 }); |
|
385 }); |
|
386 }); |
|
387 }); |
|
388 |
|
389 // Tests that navigating to a page on the same domain works |
|
390 add_test(function() { |
|
391 open_manager("addons://discover/", function(aWindow) { |
|
392 gManagerWindow = aWindow; |
|
393 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
394 |
|
395 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
396 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
397 |
|
398 clickLink("link-good", function() { |
|
399 is(getURL(browser), "https://example.com/" + RELATIVE_DIR + "releaseNotes.xhtml", "Should have loaded the right url"); |
|
400 |
|
401 gCategoryUtilities.openType("extension", function() { |
|
402 gCategoryUtilities.openType("discover", function() { |
|
403 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
404 |
|
405 close_manager(gManagerWindow, run_next_test); |
|
406 }); |
|
407 }); |
|
408 }); |
|
409 }); |
|
410 }); |
|
411 |
|
412 // Tests repeated navigation to the same page followed by a navigation to a |
|
413 // different domain |
|
414 add_test(function() { |
|
415 open_manager("addons://discover/", function(aWindow) { |
|
416 gManagerWindow = aWindow; |
|
417 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
418 |
|
419 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
420 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
421 |
|
422 var count = 10; |
|
423 function clickAgain(aCallback) { |
|
424 if (count-- == 0) |
|
425 aCallback(); |
|
426 else |
|
427 clickLink("link-normal", clickAgain.bind(null, aCallback)); |
|
428 } |
|
429 |
|
430 clickAgain(function() { |
|
431 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
432 |
|
433 clickLink("link-domain", function() { |
|
434 ok(isError(), "Should have shown the error page"); |
|
435 |
|
436 gCategoryUtilities.openType("extension", function() { |
|
437 gCategoryUtilities.openType("discover", function() { |
|
438 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
439 |
|
440 close_manager(gManagerWindow, run_next_test); |
|
441 }); |
|
442 ok(isLoading(), "Should start loading again"); |
|
443 }); |
|
444 }); |
|
445 }); |
|
446 }); |
|
447 }); |
|
448 |
|
449 // Loading an insecure main page should work if that is what the prefs say, should |
|
450 // also be able to navigate to a https page and back again |
|
451 add_test(function() { |
|
452 Services.prefs.setCharPref(PREF_DISCOVERURL, TESTROOT + "discovery.html"); |
|
453 |
|
454 open_manager("addons://discover/", function(aWindow) { |
|
455 gManagerWindow = aWindow; |
|
456 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
457 |
|
458 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
459 is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url"); |
|
460 |
|
461 clickLink("link-normal", function() { |
|
462 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
463 |
|
464 clickLink("link-http", function() { |
|
465 is(getURL(browser), TESTROOT + "discovery.html", "Should have loaded the right url"); |
|
466 |
|
467 close_manager(gManagerWindow, run_next_test); |
|
468 }); |
|
469 }); |
|
470 }); |
|
471 }); |
|
472 |
|
473 // Stopping the initial load should display the error page and then correctly |
|
474 // reload when switching away and back again |
|
475 add_test(function() { |
|
476 Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL); |
|
477 |
|
478 open_manager("addons://list/extension", function(aWindow) { |
|
479 gManagerWindow = aWindow; |
|
480 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
481 |
|
482 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
483 |
|
484 EventUtils.synthesizeMouse(gCategoryUtilities.get("discover"), 2, 2, { }, gManagerWindow); |
|
485 |
|
486 wait_for_view_load(gManagerWindow, function() { |
|
487 ok(isError(), "Should have shown the error page"); |
|
488 |
|
489 gCategoryUtilities.openType("extension", function() { |
|
490 EventUtils.synthesizeMouse(gCategoryUtilities.get("discover"), 2, 2, { }, gManagerWindow); |
|
491 |
|
492 wait_for_view_load(gManagerWindow, function() { |
|
493 ok(isError(), "Should have shown the error page"); |
|
494 |
|
495 gCategoryUtilities.openType("extension", function() { |
|
496 gCategoryUtilities.openType("discover", function() { |
|
497 is(getURL(browser), MAIN_URL, "Should have loaded the right url"); |
|
498 |
|
499 close_manager(gManagerWindow, run_next_test); |
|
500 }); |
|
501 }); |
|
502 }); |
|
503 |
|
504 ok(isLoading(), "Should be loading"); |
|
505 // This will stop the real page load |
|
506 browser.stop(); |
|
507 }); |
|
508 }); |
|
509 |
|
510 ok(isLoading(), "Should be loading"); |
|
511 // This will actually stop the about:blank load |
|
512 browser.stop(); |
|
513 }); |
|
514 }); |
|
515 |
|
516 // Test for Bug 703929 - Loading the discover view from a chrome XUL file fails when |
|
517 // the add-on manager is reopened. |
|
518 add_test(function() { |
|
519 const url = "chrome://mochitests/content/" + RELATIVE_DIR + "addon_about.xul"; |
|
520 Services.prefs.setCharPref(PREF_DISCOVERURL, url); |
|
521 |
|
522 open_manager("addons://discover/", function(aWindow) { |
|
523 gManagerWindow = aWindow; |
|
524 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
525 |
|
526 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
527 is(getURL(browser), url, "Loading a chrome XUL file should work"); |
|
528 |
|
529 restart_manager(gManagerWindow, "addons://discover/", function(aWindow) { |
|
530 gManagerWindow = aWindow; |
|
531 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
532 |
|
533 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
534 is(getURL(browser), url, "Should be able to load the chrome XUL file a second time"); |
|
535 |
|
536 close_manager(gManagerWindow, run_next_test); |
|
537 }); |
|
538 }); |
|
539 }); |
|
540 |
|
541 // Bug 711693 - Send the compatibility mode when loading the Discovery pane |
|
542 add_test(function() { |
|
543 info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'normal'"); |
|
544 Services.prefs.setCharPref(PREF_DISCOVERURL, MAIN_URL + "?mode=%COMPATIBILITY_MODE%"); |
|
545 Services.prefs.setBoolPref(PREF_STRICT_COMPAT, false); |
|
546 |
|
547 open_manager("addons://discover/", function(aWindow) { |
|
548 gManagerWindow = aWindow; |
|
549 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
550 is(getURL(browser), MAIN_URL + "?mode=normal", "Should have loaded the right url"); |
|
551 close_manager(gManagerWindow, run_next_test); |
|
552 }); |
|
553 }); |
|
554 |
|
555 add_test(function() { |
|
556 info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'strict'"); |
|
557 Services.prefs.setBoolPref(PREF_STRICT_COMPAT, true); |
|
558 |
|
559 open_manager("addons://discover/", function(aWindow) { |
|
560 gManagerWindow = aWindow; |
|
561 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
562 is(getURL(browser), MAIN_URL + "?mode=strict", "Should have loaded the right url"); |
|
563 close_manager(gManagerWindow, run_next_test); |
|
564 }); |
|
565 }); |
|
566 |
|
567 add_test(function() { |
|
568 info("Test '%COMPATIBILITY_MODE%' in the URL is correctly replaced by 'ignore'"); |
|
569 Services.prefs.setBoolPref(PREF_CHECK_COMPATIBILITY, false); |
|
570 |
|
571 open_manager("addons://discover/", function(aWindow) { |
|
572 gManagerWindow = aWindow; |
|
573 var browser = gManagerWindow.document.getElementById("discover-browser"); |
|
574 is(getURL(browser), MAIN_URL + "?mode=ignore", "Should have loaded the right url"); |
|
575 close_manager(gManagerWindow, run_next_test); |
|
576 }); |
|
577 }); |
|
578 |
|
579 // Test for Bug 601442 - extensions.getAddons.showPane need to be update |
|
580 // for the new addon manager. |
|
581 function bug_601442_test_elements(visible) { |
|
582 open_manager("addons://list/extension", function(aWindow) { |
|
583 gManagerWindow = aWindow; |
|
584 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
585 if(visible) |
|
586 ok(gCategoryUtilities.isTypeVisible("discover"), "Discover category should be visible"); |
|
587 else |
|
588 ok(!gCategoryUtilities.isTypeVisible("discover"), "Discover category should not be visible"); |
|
589 |
|
590 gManagerWindow.loadView("addons://list/dictionary"); |
|
591 wait_for_view_load(gManagerWindow, function(aManager) { |
|
592 var button = aManager.document.getElementById("discover-button-install"); |
|
593 if(visible) |
|
594 ok(!is_hidden(button), "Discover button should be visible!"); |
|
595 else |
|
596 ok(is_hidden(button), "Discover button should not be visible!"); |
|
597 |
|
598 close_manager(gManagerWindow, run_next_test); |
|
599 }); |
|
600 }); |
|
601 } |
|
602 |
|
603 add_test(function() { |
|
604 Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, false); |
|
605 Services.prefs.setBoolPref(PREF_XPI_ENABLED, true); |
|
606 bug_601442_test_elements(false); |
|
607 }); |
|
608 add_test(function() { |
|
609 Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, true); |
|
610 Services.prefs.setBoolPref(PREF_XPI_ENABLED, false); |
|
611 bug_601442_test_elements(false); |
|
612 }); |
|
613 add_test(function() { |
|
614 Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, false); |
|
615 Services.prefs.setBoolPref(PREF_XPI_ENABLED, false); |
|
616 bug_601442_test_elements(false); |
|
617 }); |
|
618 add_test(function() { |
|
619 Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, true); |
|
620 Services.prefs.setBoolPref(PREF_XPI_ENABLED, true); |
|
621 bug_601442_test_elements(true); |
|
622 }); |