Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // Tests various aspects of the details view
7 var gManagerWindow;
8 var gCategoryUtilities;
9 var gProvider;
11 const SETTINGS_ROWS = 8;
13 var MockFilePicker = SpecialPowers.MockFilePicker;
14 MockFilePicker.init(window);
16 var observer = {
17 lastDisplayed: null,
18 callback: null,
19 checkDisplayed: function(aExpected) {
20 is(this.lastDisplayed, aExpected, "'addon-options-displayed' notification should have fired");
21 this.lastDisplayed = null;
22 },
23 checkNotDisplayed: function() {
24 is(this.lastDisplayed, null, "'addon-options-displayed' notification should not have fired");
25 },
26 lastHidden: null,
27 checkHidden: function(aExpected) {
28 is(this.lastHidden, aExpected, "'addon-options-hidden' notification should have fired");
29 this.lastHidden = null;
30 },
31 checkNotHidden: function() {
32 is(this.lastHidden, null, "'addon-options-hidden' notification should not have fired");
33 },
34 observe: function(aSubject, aTopic, aData) {
35 if (aTopic == AddonManager.OPTIONS_NOTIFICATION_DISPLAYED) {
36 this.lastDisplayed = aData;
37 // Test if the binding has applied before the observers are notified. We test the second setting here,
38 // because the code operates on the first setting and we want to check it applies to all.
39 var setting = aSubject.querySelector("rows > setting[first-row] ~ setting");
40 var input = gManagerWindow.document.getAnonymousElementByAttribute(setting, "class", "preferences-title");
41 isnot(input, null, "XBL binding should be applied");
43 // Add some extra height to the scrolling pane to ensure that it needs to scroll when appropriate.
44 gManagerWindow.document.getElementById("detail-controls").style.marginBottom = "1000px";
46 if (this.callback) {
47 var tempCallback = this.callback;
48 this.callback = null;
49 tempCallback();
50 }
51 } else if (aTopic == AddonManager.OPTIONS_NOTIFICATION_HIDDEN) {
52 this.lastHidden = aData;
53 }
54 }
55 };
57 function installAddon(aCallback) {
58 AddonManager.getInstallForURL(TESTROOT + "addons/browser_inlinesettings1_info.xpi",
59 function(aInstall) {
60 aInstall.addListener({
61 onInstallEnded: function() {
62 executeSoon(aCallback);
63 }
64 });
65 aInstall.install();
66 }, "application/x-xpinstall");
67 }
69 function checkScrolling(aShouldHaveScrolled) {
70 var detailView = gManagerWindow.document.getElementById("detail-view");
71 var boxObject = detailView.boxObject;
72 boxObject.QueryInterface(Ci.nsIScrollBoxObject);
73 ok(detailView.scrollHeight > boxObject.height, "Page should require scrolling");
74 if (aShouldHaveScrolled)
75 isnot(detailView.scrollTop, 0, "Page should have scrolled");
76 else
77 is(detailView.scrollTop, 0, "Page should not have scrolled");
78 }
80 function test() {
81 waitForExplicitFinish();
83 gProvider = new MockProvider();
85 gProvider.createAddons([{
86 id: "inlinesettings2@tests.mozilla.org",
87 name: "Inline Settings (Regular)",
88 version: "1",
89 optionsURL: CHROMEROOT + "options.xul",
90 optionsType: AddonManager.OPTIONS_TYPE_INLINE_INFO,
91 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_DISABLE,
92 },{
93 id: "inlinesettings3@tests.mozilla.org",
94 name: "Inline Settings (More Options)",
95 description: "Tests for option types introduced after Mozilla 7.0",
96 version: "1",
97 optionsURL: CHROMEROOT + "more_options.xul",
98 optionsType: AddonManager.OPTIONS_TYPE_INLINE_INFO
99 },{
100 id: "noninlinesettings@tests.mozilla.org",
101 name: "Non-Inline Settings",
102 version: "1",
103 optionsURL: CHROMEROOT + "addon_prefs.xul"
104 }]);
106 installAddon(function () {
107 open_manager("addons://list/extension", function(aWindow) {
108 gManagerWindow = aWindow;
109 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
111 Services.obs.addObserver(observer,
112 AddonManager.OPTIONS_NOTIFICATION_DISPLAYED,
113 false);
114 Services.obs.addObserver(observer,
115 AddonManager.OPTIONS_NOTIFICATION_HIDDEN,
116 false);
118 run_next_test();
119 });
120 });
121 }
123 function end_test() {
124 Services.obs.removeObserver(observer,
125 AddonManager.OPTIONS_NOTIFICATION_DISPLAYED);
127 Services.prefs.clearUserPref("extensions.inlinesettings1.bool");
128 Services.prefs.clearUserPref("extensions.inlinesettings1.boolint");
129 Services.prefs.clearUserPref("extensions.inlinesettings1.integer");
130 Services.prefs.clearUserPref("extensions.inlinesettings1.string");
131 Services.prefs.clearUserPref("extensions.inlinesettings1.color");
132 Services.prefs.clearUserPref("extensions.inlinesettings1.file");
133 Services.prefs.clearUserPref("extensions.inlinesettings1.directory");
134 Services.prefs.clearUserPref("extensions.inlinesettings3.radioBool");
135 Services.prefs.clearUserPref("extensions.inlinesettings3.radioInt");
136 Services.prefs.clearUserPref("extensions.inlinesettings3.radioString");
137 Services.prefs.clearUserPref("extensions.inlinesettings3.menulist");
139 MockFilePicker.cleanup();
141 close_manager(gManagerWindow, function() {
142 observer.checkHidden("inlinesettings2@tests.mozilla.org");
143 Services.obs.removeObserver(observer,
144 AddonManager.OPTIONS_NOTIFICATION_HIDDEN);
146 AddonManager.getAddonByID("inlinesettings1@tests.mozilla.org", function(aAddon) {
147 aAddon.uninstall();
148 finish();
149 });
150 });
151 }
153 // Addon with options.xul
154 add_test(function() {
155 var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
156 is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE_INFO, "Options should be inline info type");
157 addon.parentNode.ensureElementIsVisible(addon);
159 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
160 is_element_hidden(button, "Preferences button should be hidden");
162 run_next_test();
163 });
165 // Addon with inline preferences as optionsURL
166 add_test(function() {
167 var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org");
168 is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE_INFO, "Options should be inline info type");
169 addon.parentNode.ensureElementIsVisible(addon);
171 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
172 is_element_hidden(button, "Preferences button should be hidden");
174 run_next_test();
175 });
177 // Addon with non-inline preferences as optionsURL
178 add_test(function() {
179 var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org");
180 is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_DIALOG, "Options should be dialog type");
181 addon.parentNode.ensureElementIsVisible(addon);
183 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
184 is_element_visible(button, "Preferences button should be visible");
186 run_next_test();
187 });
189 // Addon with options.xul, also a test for the setting.xml bindings
190 add_test(function() {
191 var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
192 addon.parentNode.ensureElementIsVisible(addon);
194 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
195 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
197 wait_for_view_load(gManagerWindow, function() {
198 observer.checkDisplayed("inlinesettings1@tests.mozilla.org");
200 var grid = gManagerWindow.document.getElementById("detail-grid");
201 var settings = grid.querySelectorAll("rows > setting");
202 is(settings.length, SETTINGS_ROWS, "Grid should have settings children");
204 ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute");
205 Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false);
206 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input");
207 isnot(input.checked, true, "Checkbox should have initial value");
208 is(input.label, "Check box label", "Checkbox should be labelled");
209 EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
210 is(input.checked, true, "Checkbox should have updated value");
211 is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), true, "Bool pref should have been updated");
212 EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
213 isnot(input.checked, true, "Checkbox should have updated value");
214 is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), false, "Bool pref should have been updated");
216 ok(!settings[1].hasAttribute("first-row"), "Not the first row");
217 Services.prefs.setIntPref("extensions.inlinesettings1.boolint", 0);
218 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[1], "anonid", "input");
219 isnot(input.checked, true, "Checkbox should have initial value");
220 EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
221 is(input.checked, true, "Checkbox should have updated value");
222 is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 1, "BoolInt pref should have been updated");
223 EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
224 isnot(input.checked, true, "Checkbox should have updated value");
225 is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 2, "BoolInt pref should have been updated");
227 ok(!settings[2].hasAttribute("first-row"), "Not the first row");
228 Services.prefs.setIntPref("extensions.inlinesettings1.integer", 0);
229 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input");
230 is(input.value, "0", "Number box should have initial value");
231 input.select();
232 EventUtils.synthesizeKey("1", {}, gManagerWindow);
233 EventUtils.synthesizeKey("3", {}, gManagerWindow);
234 is(input.value, "13", "Number box should have updated value");
235 is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 13, "Integer pref should have been updated");
236 EventUtils.synthesizeKey("VK_DOWN", {}, gManagerWindow);
237 is(input.value, "12", "Number box should have updated value");
238 is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 12, "Integer pref should have been updated");
240 ok(!settings[3].hasAttribute("first-row"), "Not the first row");
241 Services.prefs.setCharPref("extensions.inlinesettings1.string", "foo");
242 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[3], "anonid", "input");
243 is(input.value, "foo", "Text box should have initial value");
244 input.select();
245 EventUtils.synthesizeKey("b", {}, gManagerWindow);
246 EventUtils.synthesizeKey("a", {}, gManagerWindow);
247 EventUtils.synthesizeKey("r", {}, gManagerWindow);
248 is(input.value, "bar", "Text box should have updated value");
249 is(Services.prefs.getCharPref("extensions.inlinesettings1.string"), "bar", "String pref should have been updated");
251 ok(!settings[4].hasAttribute("first-row"), "Not the first row");
252 var input = settings[4].firstElementChild;
253 is(input.value, "1", "Menulist should have initial value");
254 input.focus();
255 EventUtils.synthesizeKey("b", {}, gManagerWindow);
256 is(input.value, "2", "Menulist should have updated value");
257 is(gManagerWindow._testValue, "2", "Menulist oncommand handler should've updated the test value");
258 delete gManagerWindow._testValue;
260 ok(!settings[5].hasAttribute("first-row"), "Not the first row");
261 Services.prefs.setCharPref("extensions.inlinesettings1.color", "#FF0000");
262 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[5], "anonid", "input");
263 is(input.color, "#FF0000", "Color picker should have initial value");
264 input.focus();
265 EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow);
266 EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow);
267 EventUtils.synthesizeKey("VK_RETURN", {}, gManagerWindow);
268 input.hidePopup();
269 is(input.color, "#FF9900", "Color picker should have updated value");
270 is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated");
272 try {
273 ok(!settings[6].hasAttribute("first-row"), "Not the first row");
274 var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button");
275 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input");
276 is(input.value, "", "Label value should be empty");
277 is(input.tooltipText, "", "Label tooltip should be empty");
279 var profD = Services.dirsvc.get("ProfD", Ci.nsIFile);
280 var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile);
282 MockFilePicker.returnFiles = [profD];
283 MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
284 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
285 is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
286 is(input.value, profD.path, "Label value should match file chosen");
287 is(input.tooltipText, profD.path, "Label tooltip should match file chosen");
288 is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should match file chosen");
290 MockFilePicker.returnFiles = [curProcD];
291 MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
292 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
293 is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
294 is(input.value, profD.path, "Label value should not have changed");
295 is(input.tooltipText, profD.path, "Label tooltip should not have changed");
296 is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should not have changed");
298 ok(!settings[7].hasAttribute("first-row"), "Not the first row");
299 button = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "button");
300 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input");
301 is(input.value, "", "Label value should be empty");
302 is(input.tooltipText, "", "Label tooltip should be empty");
304 MockFilePicker.returnFiles = [profD];
305 MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
306 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
307 is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
308 is(input.value, profD.path, "Label value should match file chosen");
309 is(input.tooltipText, profD.path, "Label tooltip should match file chosen");
310 is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should match file chosen");
312 MockFilePicker.returnFiles = [curProcD];
313 MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
314 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
315 is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
316 is(input.value, profD.path, "Label value should not have changed");
317 is(input.tooltipText, profD.path, "Label tooltip should not have changed");
318 is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should not have changed");
320 } finally {
321 button = gManagerWindow.document.getElementById("detail-prefs-btn");
322 is_element_hidden(button, "Preferences button should not be visible");
324 gCategoryUtilities.openType("extension", run_next_test);
325 }
326 });
327 });
329 // Tests for the setting.xml bindings introduced after Mozilla 7
330 add_test(function() {
331 observer.checkHidden("inlinesettings1@tests.mozilla.org");
333 var addon = get_addon_element(gManagerWindow, "inlinesettings3@tests.mozilla.org");
334 addon.parentNode.ensureElementIsVisible(addon);
336 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
337 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
339 wait_for_view_load(gManagerWindow, function() {
340 observer.checkDisplayed("inlinesettings3@tests.mozilla.org");
342 var grid = gManagerWindow.document.getElementById("detail-grid");
343 var settings = grid.querySelectorAll("rows > setting");
344 is(settings.length, 4, "Grid should have settings children");
346 ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute");
347 Services.prefs.setBoolPref("extensions.inlinesettings3.radioBool", false);
348 var radios = settings[0].getElementsByTagName("radio");
349 isnot(radios[0].selected, true, "Correct radio button should be selected");
350 is(radios[1].selected, true, "Correct radio button should be selected");
351 EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow);
352 is(Services.prefs.getBoolPref("extensions.inlinesettings3.radioBool"), true, "Radio pref should have been updated");
353 EventUtils.synthesizeMouseAtCenter(radios[1], { clickCount: 1 }, gManagerWindow);
354 is(Services.prefs.getBoolPref("extensions.inlinesettings3.radioBool"), false, "Radio pref should have been updated");
356 ok(!settings[1].hasAttribute("first-row"), "Not the first row");
357 Services.prefs.setIntPref("extensions.inlinesettings3.radioInt", 5);
358 var radios = settings[1].getElementsByTagName("radio");
359 isnot(radios[0].selected, true, "Correct radio button should be selected");
360 is(radios[1].selected, true, "Correct radio button should be selected");
361 isnot(radios[2].selected, true, "Correct radio button should be selected");
362 EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow);
363 is(Services.prefs.getIntPref("extensions.inlinesettings3.radioInt"), 4, "Radio pref should have been updated");
364 EventUtils.synthesizeMouseAtCenter(radios[2], { clickCount: 1 }, gManagerWindow);
365 is(Services.prefs.getIntPref("extensions.inlinesettings3.radioInt"), 6, "Radio pref should have been updated");
367 ok(!settings[2].hasAttribute("first-row"), "Not the first row");
368 Services.prefs.setCharPref("extensions.inlinesettings3.radioString", "juliet");
369 var radios = settings[2].getElementsByTagName("radio");
370 isnot(radios[0].selected, true, "Correct radio button should be selected");
371 is(radios[1].selected, true, "Correct radio button should be selected");
372 isnot(radios[2].selected, true, "Correct radio button should be selected");
373 EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow);
374 is(Services.prefs.getCharPref("extensions.inlinesettings3.radioString"), "india", "Radio pref should have been updated");
375 EventUtils.synthesizeMouseAtCenter(radios[2], { clickCount: 1 }, gManagerWindow);
376 is(Services.prefs.getCharPref("extensions.inlinesettings3.radioString"), "kilo", "Radio pref should have been updated");
378 ok(!settings[3].hasAttribute("first-row"), "Not the first row");
379 Services.prefs.setIntPref("extensions.inlinesettings3.menulist", 8);
380 var input = settings[3].firstElementChild;
381 is(input.value, "8", "Menulist should have initial value");
382 input.focus();
383 EventUtils.synthesizeKey("n", {}, gManagerWindow);
384 is(input.value, "9", "Menulist should have updated value");
385 is(Services.prefs.getIntPref("extensions.inlinesettings3.menulist"), 9, "Menulist pref should have been updated");
387 button = gManagerWindow.document.getElementById("detail-prefs-btn");
388 is_element_hidden(button, "Preferences button should not be visible");
390 gCategoryUtilities.openType("extension", run_next_test);
391 });
392 });
394 // Addon with inline preferences as optionsURL
395 add_test(function() {
396 observer.checkHidden("inlinesettings3@tests.mozilla.org");
398 var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org");
399 addon.parentNode.ensureElementIsVisible(addon);
401 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
402 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
404 wait_for_view_load(gManagerWindow, function() {
405 observer.checkDisplayed("inlinesettings2@tests.mozilla.org");
407 var grid = gManagerWindow.document.getElementById("detail-grid");
408 var settings = grid.querySelectorAll("rows > setting");
409 is(settings.length, 5, "Grid should have settings children");
411 var node = settings[0];
412 node = settings[0];
413 is_element_hidden(node, "Unsupported settings should not be visible");
414 ok(!node.hasAttribute("first-row"), "Hidden row is not the first row");
416 node = settings[1];
417 is(node.nodeName, "setting", "Should be a setting node");
418 ok(node.hasAttribute("first-row"), "First visible row should have first-row attribute");
419 var description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
420 is(description.textContent, "Description Attribute", "Description node should contain description");
422 node = settings[2];
423 is(node.nodeName, "setting", "Should be a setting node");
424 ok(!node.hasAttribute("first-row"), "Not the first row");
425 description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
426 is(description.textContent, "Description Text Node", "Description node should contain description");
428 node = settings[3];
429 is(node.nodeName, "setting", "Should be a setting node");
430 ok(!node.hasAttribute("first-row"), "Not the first row");
431 description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
432 is(description.textContent, "This is a test, all this text should be visible", "Description node should contain description");
433 var button = node.firstElementChild;
434 isnot(button, null, "There should be a button");
436 node = settings[4];
437 is_element_hidden(node, "Unsupported settings should not be visible");
438 ok(!node.hasAttribute("first-row"), "Hidden row is not the first row");
440 var button = gManagerWindow.document.getElementById("detail-prefs-btn");
441 is_element_hidden(button, "Preferences button should not be visible");
443 gCategoryUtilities.openType("extension", run_next_test);
444 });
445 });
447 // Addon with non-inline preferences as optionsURL
448 add_test(function() {
449 observer.checkHidden("inlinesettings2@tests.mozilla.org");
451 var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org");
452 addon.parentNode.ensureElementIsVisible(addon);
454 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
455 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
457 wait_for_view_load(gManagerWindow, function() {
458 observer.checkNotDisplayed();
460 var grid = gManagerWindow.document.getElementById("detail-grid");
461 var settings = grid.querySelectorAll("rows > setting");
462 is(settings.length, 0, "Grid should not have settings children");
464 var button = gManagerWindow.document.getElementById("detail-prefs-btn");
465 is_element_visible(button, "Preferences button should be visible");
467 gCategoryUtilities.openType("extension", run_next_test);
468 });
469 });
471 // Addon with options.xul, disabling and enabling should hide and show settings UI
472 add_test(function() {
473 observer.checkNotHidden();
475 var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
476 addon.parentNode.ensureElementIsVisible(addon);
478 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
479 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
481 wait_for_view_load(gManagerWindow, function() {
482 observer.checkDisplayed("inlinesettings1@tests.mozilla.org");
483 is(gManagerWindow.gViewController.currentViewId,
484 "addons://detail/inlinesettings1%40tests.mozilla.org",
485 "Current view should not scroll to preferences");
486 checkScrolling(false);
488 var grid = gManagerWindow.document.getElementById("detail-grid");
489 var settings = grid.querySelectorAll("rows > setting");
490 is(settings.length, SETTINGS_ROWS, "Grid should have settings children");
492 // disable
493 var button = gManagerWindow.document.getElementById("detail-disable-btn");
494 button.focus(); // make sure it's in view
495 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
497 observer.checkHidden("inlinesettings1@tests.mozilla.org");
499 settings = grid.querySelectorAll("rows > setting");
500 is(settings.length, 0, "Grid should not have settings children");
502 gCategoryUtilities.openType("extension", function() {
503 var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
504 addon.parentNode.ensureElementIsVisible(addon);
506 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
507 is_element_hidden(button, "Preferences button should not be visible");
509 button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
510 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
512 wait_for_view_load(gManagerWindow, function() {
513 var grid = gManagerWindow.document.getElementById("detail-grid");
514 var settings = grid.querySelectorAll("rows > setting");
515 is(settings.length, 0, "Grid should not have settings children");
517 // enable
518 var button = gManagerWindow.document.getElementById("detail-enable-btn");
519 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
521 observer.callback = function() {
522 observer.checkDisplayed("inlinesettings1@tests.mozilla.org");
524 settings = grid.querySelectorAll("rows > setting");
525 is(settings.length, SETTINGS_ROWS, "Grid should have settings children");
527 gCategoryUtilities.openType("extension", run_next_test);
528 };
529 });
530 });
531 });
532 });
535 // Addon with options.xul that requires a restart to disable,
536 // disabling and enabling should not hide and show settings UI.
537 add_test(function() {
538 observer.checkHidden("inlinesettings1@tests.mozilla.org");
540 var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org");
541 addon.parentNode.ensureElementIsVisible(addon);
543 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
544 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
546 wait_for_view_load(gManagerWindow, function() {
547 observer.checkDisplayed("inlinesettings2@tests.mozilla.org");
549 var grid = gManagerWindow.document.getElementById("detail-grid");
550 var settings = grid.querySelectorAll("rows > setting");
551 ok(settings.length > 0, "Grid should have settings children");
553 // disable
554 var button = gManagerWindow.document.getElementById("detail-disable-btn");
555 button.focus(); // make sure it's in view
556 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
557 observer.checkNotHidden();
559 settings = grid.querySelectorAll("rows > setting");
560 ok(settings.length > 0, "Grid should still have settings children");
562 // cancel pending disable
563 button = gManagerWindow.document.getElementById("detail-enable-btn");
564 button.focus(); // make sure it's in view
565 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
566 observer.checkNotDisplayed();
568 gCategoryUtilities.openType("extension", run_next_test);
569 });
570 });