Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 = 9;
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.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,
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
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("inlinesettings3@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, "Options should be inline type");
157 addon.parentNode.ensureElementIsVisible(addon);
159 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
160 is_element_visible(button, "Preferences button should be visible");
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, "Options should be inline type");
169 addon.parentNode.ensureElementIsVisible(addon);
171 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
172 is_element_visible(button, "Preferences button should be visible");
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", "preferences-btn");
195 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
197 wait_for_view_load(gManagerWindow, function() {
198 observer.checkDisplayed("inlinesettings1@tests.mozilla.org");
199 is(gManagerWindow.gViewController.currentViewId,
200 "addons://detail/inlinesettings1%40tests.mozilla.org/preferences",
201 "Current view should scroll to preferences");
202 checkScrolling(true);
204 var grid = gManagerWindow.document.getElementById("detail-grid");
205 var settings = grid.querySelectorAll("rows > setting");
206 is(settings.length, SETTINGS_ROWS, "Grid should have settings children");
208 ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute");
209 Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false);
210 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input");
211 isnot(input.checked, true, "Checkbox should have initial value");
212 is(input.label, "Check box label", "Checkbox should be labelled");
213 EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
214 is(input.checked, true, "Checkbox should have updated value");
215 is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), true, "Bool pref should have been updated");
216 EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
217 isnot(input.checked, true, "Checkbox should have updated value");
218 is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), false, "Bool pref should have been updated");
220 ok(!settings[1].hasAttribute("first-row"), "Not the first row");
221 Services.prefs.setIntPref("extensions.inlinesettings1.boolint", 0);
222 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[1], "anonid", "input");
223 isnot(input.checked, true, "Checkbox should have initial value");
224 EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
225 is(input.checked, true, "Checkbox should have updated value");
226 is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 1, "BoolInt pref should have been updated");
227 EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
228 isnot(input.checked, true, "Checkbox should have updated value");
229 is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 2, "BoolInt pref should have been updated");
231 ok(!settings[2].hasAttribute("first-row"), "Not the first row");
232 Services.prefs.setIntPref("extensions.inlinesettings1.integer", 0);
233 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input");
234 is(input.value, "0", "Number box should have initial value");
235 input.select();
236 EventUtils.synthesizeKey("1", {}, gManagerWindow);
237 EventUtils.synthesizeKey("3", {}, gManagerWindow);
238 is(input.value, "13", "Number box should have updated value");
239 is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 13, "Integer pref should have been updated");
240 EventUtils.synthesizeKey("VK_DOWN", {}, gManagerWindow);
241 is(input.value, "12", "Number box should have updated value");
242 is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 12, "Integer pref should have been updated");
244 ok(!settings[3].hasAttribute("first-row"), "Not the first row");
245 Services.prefs.setCharPref("extensions.inlinesettings1.string", "foo");
246 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[3], "anonid", "input");
247 is(input.value, "foo", "Text box should have initial value");
248 input.select();
249 EventUtils.synthesizeKey("b", {}, gManagerWindow);
250 EventUtils.synthesizeKey("a", {}, gManagerWindow);
251 EventUtils.synthesizeKey("r", {}, gManagerWindow);
252 is(input.value, "bar", "Text box should have updated value");
253 EventUtils.synthesizeKey("/", {}, gManagerWindow);
254 is(input.value, "bar/", "Text box should have updated value");
255 is(gManagerWindow.document.getBindingParent(gManagerWindow.document.activeElement), input, "Search box should not have focus");
256 is(Services.prefs.getCharPref("extensions.inlinesettings1.string"), "bar/", "String pref should have been updated");
258 ok(!settings[4].hasAttribute("first-row"), "Not the first row");
259 var input = settings[4].firstElementChild;
260 is(input.value, "1", "Menulist should have initial value");
261 input.focus();
262 EventUtils.synthesizeKey("b", {}, gManagerWindow);
263 is(input.value, "2", "Menulist should have updated value");
264 is(gManagerWindow._testValue, "2", "Menulist oncommand handler should've updated the test value");
265 delete gManagerWindow._testValue;
267 ok(!settings[5].hasAttribute("first-row"), "Not the first row");
268 Services.prefs.setCharPref("extensions.inlinesettings1.color", "#FF0000");
269 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[5], "anonid", "input");
270 is(input.color, "#FF0000", "Color picker should have initial value");
271 input.focus();
272 EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow);
273 EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow);
274 EventUtils.synthesizeKey("VK_RETURN", {}, gManagerWindow);
275 input.hidePopup();
276 is(input.color, "#FF9900", "Color picker should have updated value");
277 is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated");
279 try {
280 ok(!settings[6].hasAttribute("first-row"), "Not the first row");
281 var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button");
282 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input");
283 is(input.value, "", "Label value should be empty");
284 is(input.tooltipText, "", "Label tooltip should be empty");
286 var profD = Services.dirsvc.get("ProfD", Ci.nsIFile);
287 var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile);
289 MockFilePicker.returnFiles = [profD];
290 MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
291 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
292 is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
293 is(input.value, profD.path, "Label value should match file chosen");
294 is(input.tooltipText, profD.path, "Label tooltip should match file chosen");
295 is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should match file chosen");
297 MockFilePicker.returnFiles = [curProcD];
298 MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
299 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
300 is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
301 is(input.value, profD.path, "Label value should not have changed");
302 is(input.tooltipText, profD.path, "Label tooltip should not have changed");
303 is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should not have changed");
305 ok(!settings[7].hasAttribute("first-row"), "Not the first row");
306 button = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "button");
307 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input");
308 is(input.value, "", "Label value should be empty");
309 is(input.tooltipText, "", "Label tooltip should be empty");
311 MockFilePicker.returnFiles = [profD];
312 MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
313 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
314 is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
315 is(input.value, profD.path, "Label value should match file chosen");
316 is(input.tooltipText, profD.path, "Label tooltip should match file chosen");
317 is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should match file chosen");
319 MockFilePicker.returnFiles = [curProcD];
320 MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
321 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
322 is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
323 is(input.value, profD.path, "Label value should not have changed");
324 is(input.tooltipText, profD.path, "Label tooltip should not have changed");
325 is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should not have changed");
327 var unsizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input");
328 var sizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[8], "anonid", "input");
329 is(unsizedInput.clientWidth > sizedInput.clientWidth, true, "Input with size attribute should be smaller than input without");
330 } finally {
331 button = gManagerWindow.document.getElementById("detail-prefs-btn");
332 is_element_hidden(button, "Preferences button should not be visible");
334 gCategoryUtilities.openType("extension", run_next_test);
335 }
336 });
337 });
339 // Tests for the setting.xml bindings introduced after Mozilla 7
340 add_test(function() {
341 observer.checkHidden("inlinesettings1@tests.mozilla.org");
343 var addon = get_addon_element(gManagerWindow, "inlinesettings3@tests.mozilla.org");
344 addon.parentNode.ensureElementIsVisible(addon);
346 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
347 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
349 wait_for_view_load(gManagerWindow, function() {
350 observer.checkDisplayed("inlinesettings3@tests.mozilla.org");
352 var grid = gManagerWindow.document.getElementById("detail-grid");
353 var settings = grid.querySelectorAll("rows > setting");
354 is(settings.length, 4, "Grid should have settings children");
356 ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute");
357 Services.prefs.setBoolPref("extensions.inlinesettings3.radioBool", false);
358 var radios = settings[0].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 EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow);
362 is(Services.prefs.getBoolPref("extensions.inlinesettings3.radioBool"), true, "Radio pref should have been updated");
363 EventUtils.synthesizeMouseAtCenter(radios[1], { clickCount: 1 }, gManagerWindow);
364 is(Services.prefs.getBoolPref("extensions.inlinesettings3.radioBool"), false, "Radio pref should have been updated");
366 ok(!settings[1].hasAttribute("first-row"), "Not the first row");
367 Services.prefs.setIntPref("extensions.inlinesettings3.radioInt", 5);
368 var radios = settings[1].getElementsByTagName("radio");
369 isnot(radios[0].selected, true, "Correct radio button should be selected");
370 is(radios[1].selected, true, "Correct radio button should be selected");
371 isnot(radios[2].selected, true, "Correct radio button should be selected");
372 EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow);
373 is(Services.prefs.getIntPref("extensions.inlinesettings3.radioInt"), 4, "Radio pref should have been updated");
374 EventUtils.synthesizeMouseAtCenter(radios[2], { clickCount: 1 }, gManagerWindow);
375 is(Services.prefs.getIntPref("extensions.inlinesettings3.radioInt"), 6, "Radio pref should have been updated");
377 ok(!settings[2].hasAttribute("first-row"), "Not the first row");
378 Services.prefs.setCharPref("extensions.inlinesettings3.radioString", "juliet");
379 var radios = settings[2].getElementsByTagName("radio");
380 isnot(radios[0].selected, true, "Correct radio button should be selected");
381 is(radios[1].selected, true, "Correct radio button should be selected");
382 isnot(radios[2].selected, true, "Correct radio button should be selected");
383 EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow);
384 is(Services.prefs.getCharPref("extensions.inlinesettings3.radioString"), "india", "Radio pref should have been updated");
385 EventUtils.synthesizeMouseAtCenter(radios[2], { clickCount: 1 }, gManagerWindow);
386 is(Services.prefs.getCharPref("extensions.inlinesettings3.radioString"), "kilo", "Radio pref should have been updated");
388 ok(!settings[3].hasAttribute("first-row"), "Not the first row");
389 Services.prefs.setIntPref("extensions.inlinesettings3.menulist", 8);
390 var input = settings[3].firstElementChild;
391 is(input.value, "8", "Menulist should have initial value");
392 input.focus();
393 EventUtils.synthesizeKey("n", {}, gManagerWindow);
394 is(input.value, "9", "Menulist should have updated value");
395 is(Services.prefs.getIntPref("extensions.inlinesettings3.menulist"), 9, "Menulist pref should have been updated");
397 button = gManagerWindow.document.getElementById("detail-prefs-btn");
398 is_element_hidden(button, "Preferences button should not be visible");
400 gCategoryUtilities.openType("extension", run_next_test);
401 });
402 });
404 // Addon with inline preferences as optionsURL
405 add_test(function() {
406 observer.checkHidden("inlinesettings3@tests.mozilla.org");
408 var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org");
409 addon.parentNode.ensureElementIsVisible(addon);
411 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
412 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
414 wait_for_view_load(gManagerWindow, function() {
415 observer.checkDisplayed("inlinesettings2@tests.mozilla.org");
417 var grid = gManagerWindow.document.getElementById("detail-grid");
418 var settings = grid.querySelectorAll("rows > setting");
419 is(settings.length, 5, "Grid should have settings children");
421 var node = settings[0];
422 node = settings[0];
423 is_element_hidden(node, "Unsupported settings should not be visible");
424 ok(!node.hasAttribute("first-row"), "Hidden row is not the first row");
426 node = settings[1];
427 is(node.nodeName, "setting", "Should be a setting node");
428 ok(node.hasAttribute("first-row"), "First visible row should have first-row attribute");
429 var description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
430 is(description.textContent, "Description Attribute", "Description node should contain description");
432 node = settings[2];
433 is(node.nodeName, "setting", "Should be a setting node");
434 ok(!node.hasAttribute("first-row"), "Not the first row");
435 description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
436 is(description.textContent, "Description Text Node", "Description node should contain description");
438 node = settings[3];
439 is(node.nodeName, "setting", "Should be a setting node");
440 ok(!node.hasAttribute("first-row"), "Not the first row");
441 description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
442 is(description.textContent, "This is a test, all this text should be visible", "Description node should contain description");
443 var button = node.firstElementChild;
444 isnot(button, null, "There should be a button");
446 node = settings[4];
447 is_element_hidden(node, "Unsupported settings should not be visible");
448 ok(!node.hasAttribute("first-row"), "Hidden row is not the first row");
450 var button = gManagerWindow.document.getElementById("detail-prefs-btn");
451 is_element_hidden(button, "Preferences button should not be visible");
453 gCategoryUtilities.openType("extension", run_next_test);
454 });
455 });
457 // Addon with non-inline preferences as optionsURL
458 add_test(function() {
459 observer.checkHidden("inlinesettings2@tests.mozilla.org");
461 var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org");
462 addon.parentNode.ensureElementIsVisible(addon);
464 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
465 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
467 wait_for_view_load(gManagerWindow, function() {
468 observer.checkNotDisplayed();
470 var grid = gManagerWindow.document.getElementById("detail-grid");
471 var settings = grid.querySelectorAll("rows > setting");
472 is(settings.length, 0, "Grid should not have settings children");
474 var button = gManagerWindow.document.getElementById("detail-prefs-btn");
475 is_element_visible(button, "Preferences button should be visible");
477 gCategoryUtilities.openType("extension", run_next_test);
478 });
479 });
481 // Addon with options.xul, disabling and enabling should hide and show settings UI
482 add_test(function() {
483 observer.checkNotHidden();
485 var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
486 addon.parentNode.ensureElementIsVisible(addon);
488 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
489 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
491 wait_for_view_load(gManagerWindow, function() {
492 observer.checkDisplayed("inlinesettings1@tests.mozilla.org");
493 is(gManagerWindow.gViewController.currentViewId,
494 "addons://detail/inlinesettings1%40tests.mozilla.org",
495 "Current view should not scroll to preferences");
496 checkScrolling(false);
498 var grid = gManagerWindow.document.getElementById("detail-grid");
499 var settings = grid.querySelectorAll("rows > setting");
500 is(settings.length, SETTINGS_ROWS, "Grid should have settings children");
502 // disable
503 var button = gManagerWindow.document.getElementById("detail-disable-btn");
504 button.focus(); // make sure it's in view
505 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
507 observer.checkHidden("inlinesettings1@tests.mozilla.org");
509 settings = grid.querySelectorAll("rows > setting");
510 is(settings.length, 0, "Grid should not have settings children");
512 gCategoryUtilities.openType("extension", function() {
513 var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
514 addon.parentNode.ensureElementIsVisible(addon);
516 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
517 is_element_hidden(button, "Preferences button should not be visible");
519 button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
520 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
522 wait_for_view_load(gManagerWindow, function() {
523 var grid = gManagerWindow.document.getElementById("detail-grid");
524 var settings = grid.querySelectorAll("rows > setting");
525 is(settings.length, 0, "Grid should not have settings children");
527 // enable
528 var button = gManagerWindow.document.getElementById("detail-enable-btn");
529 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
531 observer.callback = function() {
532 observer.checkDisplayed("inlinesettings1@tests.mozilla.org");
534 settings = grid.querySelectorAll("rows > setting");
535 is(settings.length, SETTINGS_ROWS, "Grid should have settings children");
537 gCategoryUtilities.openType("extension", run_next_test);
538 };
539 });
540 });
541 });
542 });
545 // Addon with options.xul that requires a restart to disable,
546 // disabling and enabling should not hide and show settings UI.
547 add_test(function() {
548 observer.checkHidden("inlinesettings1@tests.mozilla.org");
550 var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org");
551 addon.parentNode.ensureElementIsVisible(addon);
553 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn");
554 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
556 wait_for_view_load(gManagerWindow, function() {
557 observer.checkDisplayed("inlinesettings2@tests.mozilla.org");
559 var grid = gManagerWindow.document.getElementById("detail-grid");
560 var settings = grid.querySelectorAll("rows > setting");
561 ok(settings.length > 0, "Grid should have settings children");
563 // disable
564 var button = gManagerWindow.document.getElementById("detail-disable-btn");
565 button.focus(); // make sure it's in view
566 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
567 observer.checkNotHidden();
569 settings = grid.querySelectorAll("rows > setting");
570 ok(settings.length > 0, "Grid should still have settings children");
572 // cancel pending disable
573 button = gManagerWindow.document.getElementById("detail-enable-btn");
574 button.focus(); // make sure it's in view
575 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
576 observer.checkNotDisplayed();
578 gCategoryUtilities.openType("extension", run_next_test);
579 });
580 });
582 // Tests bindings with existing prefs.
583 add_test(function() {
584 observer.checkHidden("inlinesettings2@tests.mozilla.org");
586 // Ensure these prefs are set. They should be set above, but somebody might
587 // change the tests above.
588 var profD = Services.dirsvc.get("ProfD", Ci.nsIFile);
589 Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false);
590 Services.prefs.setIntPref("extensions.inlinesettings1.boolint", 1);
591 Services.prefs.setIntPref("extensions.inlinesettings1.integer", 12);
592 Services.prefs.setCharPref("extensions.inlinesettings1.string", "bar/");
593 Services.prefs.setCharPref("extensions.inlinesettings1.color", "#FF9900");
594 Services.prefs.setCharPref("extensions.inlinesettings1.file", profD.path);
595 Services.prefs.setCharPref("extensions.inlinesettings1.directory", profD.path);
597 var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
598 addon.parentNode.ensureElementIsVisible(addon);
600 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
601 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
603 wait_for_view_load(gManagerWindow, function() {
604 observer.checkDisplayed("inlinesettings1@tests.mozilla.org");
606 var grid = gManagerWindow.document.getElementById("detail-grid");
607 var settings = grid.querySelectorAll("rows > setting");
609 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input");
610 is(input.checked, false, "Checkbox should have initial value");
612 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[1], "anonid", "input");
613 is(input.checked, true, "Checkbox should have initial value");
615 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input");
616 is(input.value, "12", "Number box should have initial value");
618 var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[3], "anonid", "input");
619 is(input.value, "bar/", "Text box should have initial value");
621 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[5], "anonid", "input");
622 is(input.color, "#FF9900", "Color picker should have initial value");
624 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input");
625 is(input.value, profD.path, "Label should have initial value");
626 is(input.tooltipText, profD.path, "Label tooltip should have initial value");
628 input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input");
629 is(input.value, profD.path, "Label value should have initial value");
630 is(input.tooltipText, profD.path, "Label tooltip should have initial value");
632 gCategoryUtilities.openType("extension", run_next_test);
633 });
634 });
636 // Tests bindings with existing prefs.
637 add_test(function() {
638 observer.checkHidden("inlinesettings1@tests.mozilla.org");
640 // Ensure these prefs are set. They should be set above, but somebody might
641 // change the tests above.
642 Services.prefs.setBoolPref("extensions.inlinesettings3.radioBool", false);
643 Services.prefs.setIntPref("extensions.inlinesettings3.radioInt", 6);
644 Services.prefs.setCharPref("extensions.inlinesettings3.radioString", "kilo");
645 Services.prefs.setIntPref("extensions.inlinesettings3.menulist", 9);
647 var addon = get_addon_element(gManagerWindow, "inlinesettings3@tests.mozilla.org");
648 addon.parentNode.ensureElementIsVisible(addon);
650 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
651 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
653 wait_for_view_load(gManagerWindow, function() {
654 observer.checkDisplayed("inlinesettings3@tests.mozilla.org");
656 var grid = gManagerWindow.document.getElementById("detail-grid");
657 var settings = grid.querySelectorAll("rows > setting");
659 var radios = settings[0].getElementsByTagName("radio");
660 isnot(radios[0].selected, true, "Correct radio button should be selected");
661 is(radios[1].selected, true, "Correct radio button should be selected");
663 var radios = settings[1].getElementsByTagName("radio");
664 isnot(radios[0].selected, true, "Correct radio button should be selected");
665 isnot(radios[1].selected, true, "Correct radio button should be selected");
666 is(radios[2].selected, true, "Correct radio button should be selected");
668 var radios = settings[2].getElementsByTagName("radio");
669 isnot(radios[0].selected, true, "Correct radio button should be selected");
670 isnot(radios[1].selected, true, "Correct radio button should be selected");
671 is(radios[2].selected, true, "Correct radio button should be selected");
673 var input = settings[3].firstElementChild;
674 is(input.value, "9", "Menulist should have initial value");
676 gCategoryUtilities.openType("extension", run_next_test);
677 });
678 });