1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,678 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Tests various aspects of the details view 1.9 + 1.10 +var gManagerWindow; 1.11 +var gCategoryUtilities; 1.12 +var gProvider; 1.13 + 1.14 +const SETTINGS_ROWS = 9; 1.15 + 1.16 +var MockFilePicker = SpecialPowers.MockFilePicker; 1.17 +MockFilePicker.init(window); 1.18 + 1.19 +var observer = { 1.20 + lastDisplayed: null, 1.21 + callback: null, 1.22 + checkDisplayed: function(aExpected) { 1.23 + is(this.lastDisplayed, aExpected, "'addon-options-displayed' notification should have fired"); 1.24 + this.lastDisplayed = null; 1.25 + }, 1.26 + checkNotDisplayed: function() { 1.27 + is(this.lastDisplayed, null, "'addon-options-displayed' notification should not have fired"); 1.28 + }, 1.29 + lastHidden: null, 1.30 + checkHidden: function(aExpected) { 1.31 + is(this.lastHidden, aExpected, "'addon-options-hidden' notification should have fired"); 1.32 + this.lastHidden = null; 1.33 + }, 1.34 + checkNotHidden: function() { 1.35 + is(this.lastHidden, null, "'addon-options-hidden' notification should not have fired"); 1.36 + }, 1.37 + observe: function(aSubject, aTopic, aData) { 1.38 + if (aTopic == AddonManager.OPTIONS_NOTIFICATION_DISPLAYED) { 1.39 + this.lastDisplayed = aData; 1.40 + // Test if the binding has applied before the observers are notified. We test the second setting here, 1.41 + // because the code operates on the first setting and we want to check it applies to all. 1.42 + var setting = aSubject.querySelector("rows > setting[first-row] ~ setting"); 1.43 + var input = gManagerWindow.document.getAnonymousElementByAttribute(setting, "class", "preferences-title"); 1.44 + isnot(input, null, "XBL binding should be applied"); 1.45 + 1.46 + // Add some extra height to the scrolling pane to ensure that it needs to scroll when appropriate. 1.47 + gManagerWindow.document.getElementById("detail-controls").style.marginBottom = "1000px"; 1.48 + 1.49 + if (this.callback) { 1.50 + var tempCallback = this.callback; 1.51 + this.callback = null; 1.52 + tempCallback(); 1.53 + } 1.54 + } else if (aTopic == AddonManager.OPTIONS_NOTIFICATION_HIDDEN) { 1.55 + this.lastHidden = aData; 1.56 + } 1.57 + } 1.58 +}; 1.59 + 1.60 +function installAddon(aCallback) { 1.61 + AddonManager.getInstallForURL(TESTROOT + "addons/browser_inlinesettings1.xpi", 1.62 + function(aInstall) { 1.63 + aInstall.addListener({ 1.64 + onInstallEnded: function() { 1.65 + executeSoon(aCallback); 1.66 + } 1.67 + }); 1.68 + aInstall.install(); 1.69 + }, "application/x-xpinstall"); 1.70 +} 1.71 + 1.72 +function checkScrolling(aShouldHaveScrolled) { 1.73 + var detailView = gManagerWindow.document.getElementById("detail-view"); 1.74 + var boxObject = detailView.boxObject; 1.75 + boxObject.QueryInterface(Ci.nsIScrollBoxObject); 1.76 + ok(detailView.scrollHeight > boxObject.height, "Page should require scrolling"); 1.77 + if (aShouldHaveScrolled) 1.78 + isnot(detailView.scrollTop, 0, "Page should have scrolled"); 1.79 + else 1.80 + is(detailView.scrollTop, 0, "Page should not have scrolled"); 1.81 +} 1.82 + 1.83 +function test() { 1.84 + waitForExplicitFinish(); 1.85 + 1.86 + gProvider = new MockProvider(); 1.87 + 1.88 + gProvider.createAddons([{ 1.89 + id: "inlinesettings2@tests.mozilla.org", 1.90 + name: "Inline Settings (Regular)", 1.91 + version: "1", 1.92 + optionsURL: CHROMEROOT + "options.xul", 1.93 + optionsType: AddonManager.OPTIONS_TYPE_INLINE, 1.94 + operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_DISABLE, 1.95 + },{ 1.96 + id: "inlinesettings3@tests.mozilla.org", 1.97 + name: "Inline Settings (More Options)", 1.98 + description: "Tests for option types introduced after Mozilla 7.0", 1.99 + version: "1", 1.100 + optionsURL: CHROMEROOT + "more_options.xul", 1.101 + optionsType: AddonManager.OPTIONS_TYPE_INLINE 1.102 + },{ 1.103 + id: "noninlinesettings@tests.mozilla.org", 1.104 + name: "Non-Inline Settings", 1.105 + version: "1", 1.106 + optionsURL: CHROMEROOT + "addon_prefs.xul" 1.107 + }]); 1.108 + 1.109 + installAddon(function () { 1.110 + open_manager("addons://list/extension", function(aWindow) { 1.111 + gManagerWindow = aWindow; 1.112 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.113 + 1.114 + Services.obs.addObserver(observer, 1.115 + AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, 1.116 + false); 1.117 + Services.obs.addObserver(observer, 1.118 + AddonManager.OPTIONS_NOTIFICATION_HIDDEN, 1.119 + false); 1.120 + 1.121 + run_next_test(); 1.122 + }); 1.123 + }); 1.124 +} 1.125 + 1.126 +function end_test() { 1.127 + Services.obs.removeObserver(observer, 1.128 + AddonManager.OPTIONS_NOTIFICATION_DISPLAYED); 1.129 + 1.130 + Services.prefs.clearUserPref("extensions.inlinesettings1.bool"); 1.131 + Services.prefs.clearUserPref("extensions.inlinesettings1.boolint"); 1.132 + Services.prefs.clearUserPref("extensions.inlinesettings1.integer"); 1.133 + Services.prefs.clearUserPref("extensions.inlinesettings1.string"); 1.134 + Services.prefs.clearUserPref("extensions.inlinesettings1.color"); 1.135 + Services.prefs.clearUserPref("extensions.inlinesettings1.file"); 1.136 + Services.prefs.clearUserPref("extensions.inlinesettings1.directory"); 1.137 + Services.prefs.clearUserPref("extensions.inlinesettings3.radioBool"); 1.138 + Services.prefs.clearUserPref("extensions.inlinesettings3.radioInt"); 1.139 + Services.prefs.clearUserPref("extensions.inlinesettings3.radioString"); 1.140 + Services.prefs.clearUserPref("extensions.inlinesettings3.menulist"); 1.141 + 1.142 + MockFilePicker.cleanup(); 1.143 + 1.144 + close_manager(gManagerWindow, function() { 1.145 + observer.checkHidden("inlinesettings3@tests.mozilla.org"); 1.146 + Services.obs.removeObserver(observer, 1.147 + AddonManager.OPTIONS_NOTIFICATION_HIDDEN); 1.148 + 1.149 + AddonManager.getAddonByID("inlinesettings1@tests.mozilla.org", function(aAddon) { 1.150 + aAddon.uninstall(); 1.151 + finish(); 1.152 + }); 1.153 + }); 1.154 +} 1.155 + 1.156 +// Addon with options.xul 1.157 +add_test(function() { 1.158 + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); 1.159 + is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, "Options should be inline type"); 1.160 + addon.parentNode.ensureElementIsVisible(addon); 1.161 + 1.162 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.163 + is_element_visible(button, "Preferences button should be visible"); 1.164 + 1.165 + run_next_test(); 1.166 +}); 1.167 + 1.168 +// Addon with inline preferences as optionsURL 1.169 +add_test(function() { 1.170 + var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org"); 1.171 + is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, "Options should be inline type"); 1.172 + addon.parentNode.ensureElementIsVisible(addon); 1.173 + 1.174 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.175 + is_element_visible(button, "Preferences button should be visible"); 1.176 + 1.177 + run_next_test(); 1.178 +}); 1.179 + 1.180 +// Addon with non-inline preferences as optionsURL 1.181 +add_test(function() { 1.182 + var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org"); 1.183 + is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_DIALOG, "Options should be dialog type"); 1.184 + addon.parentNode.ensureElementIsVisible(addon); 1.185 + 1.186 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.187 + is_element_visible(button, "Preferences button should be visible"); 1.188 + 1.189 + run_next_test(); 1.190 +}); 1.191 + 1.192 +// Addon with options.xul, also a test for the setting.xml bindings 1.193 +add_test(function() { 1.194 + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); 1.195 + addon.parentNode.ensureElementIsVisible(addon); 1.196 + 1.197 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.198 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.199 + 1.200 + wait_for_view_load(gManagerWindow, function() { 1.201 + observer.checkDisplayed("inlinesettings1@tests.mozilla.org"); 1.202 + is(gManagerWindow.gViewController.currentViewId, 1.203 + "addons://detail/inlinesettings1%40tests.mozilla.org/preferences", 1.204 + "Current view should scroll to preferences"); 1.205 + checkScrolling(true); 1.206 + 1.207 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.208 + var settings = grid.querySelectorAll("rows > setting"); 1.209 + is(settings.length, SETTINGS_ROWS, "Grid should have settings children"); 1.210 + 1.211 + ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute"); 1.212 + Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false); 1.213 + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input"); 1.214 + isnot(input.checked, true, "Checkbox should have initial value"); 1.215 + is(input.label, "Check box label", "Checkbox should be labelled"); 1.216 + EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); 1.217 + is(input.checked, true, "Checkbox should have updated value"); 1.218 + is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), true, "Bool pref should have been updated"); 1.219 + EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); 1.220 + isnot(input.checked, true, "Checkbox should have updated value"); 1.221 + is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), false, "Bool pref should have been updated"); 1.222 + 1.223 + ok(!settings[1].hasAttribute("first-row"), "Not the first row"); 1.224 + Services.prefs.setIntPref("extensions.inlinesettings1.boolint", 0); 1.225 + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[1], "anonid", "input"); 1.226 + isnot(input.checked, true, "Checkbox should have initial value"); 1.227 + EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); 1.228 + is(input.checked, true, "Checkbox should have updated value"); 1.229 + is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 1, "BoolInt pref should have been updated"); 1.230 + EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); 1.231 + isnot(input.checked, true, "Checkbox should have updated value"); 1.232 + is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 2, "BoolInt pref should have been updated"); 1.233 + 1.234 + ok(!settings[2].hasAttribute("first-row"), "Not the first row"); 1.235 + Services.prefs.setIntPref("extensions.inlinesettings1.integer", 0); 1.236 + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input"); 1.237 + is(input.value, "0", "Number box should have initial value"); 1.238 + input.select(); 1.239 + EventUtils.synthesizeKey("1", {}, gManagerWindow); 1.240 + EventUtils.synthesizeKey("3", {}, gManagerWindow); 1.241 + is(input.value, "13", "Number box should have updated value"); 1.242 + is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 13, "Integer pref should have been updated"); 1.243 + EventUtils.synthesizeKey("VK_DOWN", {}, gManagerWindow); 1.244 + is(input.value, "12", "Number box should have updated value"); 1.245 + is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 12, "Integer pref should have been updated"); 1.246 + 1.247 + ok(!settings[3].hasAttribute("first-row"), "Not the first row"); 1.248 + Services.prefs.setCharPref("extensions.inlinesettings1.string", "foo"); 1.249 + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[3], "anonid", "input"); 1.250 + is(input.value, "foo", "Text box should have initial value"); 1.251 + input.select(); 1.252 + EventUtils.synthesizeKey("b", {}, gManagerWindow); 1.253 + EventUtils.synthesizeKey("a", {}, gManagerWindow); 1.254 + EventUtils.synthesizeKey("r", {}, gManagerWindow); 1.255 + is(input.value, "bar", "Text box should have updated value"); 1.256 + EventUtils.synthesizeKey("/", {}, gManagerWindow); 1.257 + is(input.value, "bar/", "Text box should have updated value"); 1.258 + is(gManagerWindow.document.getBindingParent(gManagerWindow.document.activeElement), input, "Search box should not have focus"); 1.259 + is(Services.prefs.getCharPref("extensions.inlinesettings1.string"), "bar/", "String pref should have been updated"); 1.260 + 1.261 + ok(!settings[4].hasAttribute("first-row"), "Not the first row"); 1.262 + var input = settings[4].firstElementChild; 1.263 + is(input.value, "1", "Menulist should have initial value"); 1.264 + input.focus(); 1.265 + EventUtils.synthesizeKey("b", {}, gManagerWindow); 1.266 + is(input.value, "2", "Menulist should have updated value"); 1.267 + is(gManagerWindow._testValue, "2", "Menulist oncommand handler should've updated the test value"); 1.268 + delete gManagerWindow._testValue; 1.269 + 1.270 + ok(!settings[5].hasAttribute("first-row"), "Not the first row"); 1.271 + Services.prefs.setCharPref("extensions.inlinesettings1.color", "#FF0000"); 1.272 + input = gManagerWindow.document.getAnonymousElementByAttribute(settings[5], "anonid", "input"); 1.273 + is(input.color, "#FF0000", "Color picker should have initial value"); 1.274 + input.focus(); 1.275 + EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow); 1.276 + EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow); 1.277 + EventUtils.synthesizeKey("VK_RETURN", {}, gManagerWindow); 1.278 + input.hidePopup(); 1.279 + is(input.color, "#FF9900", "Color picker should have updated value"); 1.280 + is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated"); 1.281 + 1.282 + try { 1.283 + ok(!settings[6].hasAttribute("first-row"), "Not the first row"); 1.284 + var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button"); 1.285 + input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input"); 1.286 + is(input.value, "", "Label value should be empty"); 1.287 + is(input.tooltipText, "", "Label tooltip should be empty"); 1.288 + 1.289 + var profD = Services.dirsvc.get("ProfD", Ci.nsIFile); 1.290 + var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile); 1.291 + 1.292 + MockFilePicker.returnFiles = [profD]; 1.293 + MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; 1.294 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.295 + is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file"); 1.296 + is(input.value, profD.path, "Label value should match file chosen"); 1.297 + is(input.tooltipText, profD.path, "Label tooltip should match file chosen"); 1.298 + is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should match file chosen"); 1.299 + 1.300 + MockFilePicker.returnFiles = [curProcD]; 1.301 + MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel; 1.302 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.303 + is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file"); 1.304 + is(input.value, profD.path, "Label value should not have changed"); 1.305 + is(input.tooltipText, profD.path, "Label tooltip should not have changed"); 1.306 + is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should not have changed"); 1.307 + 1.308 + ok(!settings[7].hasAttribute("first-row"), "Not the first row"); 1.309 + button = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "button"); 1.310 + input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input"); 1.311 + is(input.value, "", "Label value should be empty"); 1.312 + is(input.tooltipText, "", "Label tooltip should be empty"); 1.313 + 1.314 + MockFilePicker.returnFiles = [profD]; 1.315 + MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; 1.316 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.317 + is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory"); 1.318 + is(input.value, profD.path, "Label value should match file chosen"); 1.319 + is(input.tooltipText, profD.path, "Label tooltip should match file chosen"); 1.320 + is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should match file chosen"); 1.321 + 1.322 + MockFilePicker.returnFiles = [curProcD]; 1.323 + MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel; 1.324 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.325 + is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory"); 1.326 + is(input.value, profD.path, "Label value should not have changed"); 1.327 + is(input.tooltipText, profD.path, "Label tooltip should not have changed"); 1.328 + is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should not have changed"); 1.329 + 1.330 + var unsizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input"); 1.331 + var sizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[8], "anonid", "input"); 1.332 + is(unsizedInput.clientWidth > sizedInput.clientWidth, true, "Input with size attribute should be smaller than input without"); 1.333 + } finally { 1.334 + button = gManagerWindow.document.getElementById("detail-prefs-btn"); 1.335 + is_element_hidden(button, "Preferences button should not be visible"); 1.336 + 1.337 + gCategoryUtilities.openType("extension", run_next_test); 1.338 + } 1.339 + }); 1.340 +}); 1.341 + 1.342 +// Tests for the setting.xml bindings introduced after Mozilla 7 1.343 +add_test(function() { 1.344 + observer.checkHidden("inlinesettings1@tests.mozilla.org"); 1.345 + 1.346 + var addon = get_addon_element(gManagerWindow, "inlinesettings3@tests.mozilla.org"); 1.347 + addon.parentNode.ensureElementIsVisible(addon); 1.348 + 1.349 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.350 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.351 + 1.352 + wait_for_view_load(gManagerWindow, function() { 1.353 + observer.checkDisplayed("inlinesettings3@tests.mozilla.org"); 1.354 + 1.355 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.356 + var settings = grid.querySelectorAll("rows > setting"); 1.357 + is(settings.length, 4, "Grid should have settings children"); 1.358 + 1.359 + ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute"); 1.360 + Services.prefs.setBoolPref("extensions.inlinesettings3.radioBool", false); 1.361 + var radios = settings[0].getElementsByTagName("radio"); 1.362 + isnot(radios[0].selected, true, "Correct radio button should be selected"); 1.363 + is(radios[1].selected, true, "Correct radio button should be selected"); 1.364 + EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow); 1.365 + is(Services.prefs.getBoolPref("extensions.inlinesettings3.radioBool"), true, "Radio pref should have been updated"); 1.366 + EventUtils.synthesizeMouseAtCenter(radios[1], { clickCount: 1 }, gManagerWindow); 1.367 + is(Services.prefs.getBoolPref("extensions.inlinesettings3.radioBool"), false, "Radio pref should have been updated"); 1.368 + 1.369 + ok(!settings[1].hasAttribute("first-row"), "Not the first row"); 1.370 + Services.prefs.setIntPref("extensions.inlinesettings3.radioInt", 5); 1.371 + var radios = settings[1].getElementsByTagName("radio"); 1.372 + isnot(radios[0].selected, true, "Correct radio button should be selected"); 1.373 + is(radios[1].selected, true, "Correct radio button should be selected"); 1.374 + isnot(radios[2].selected, true, "Correct radio button should be selected"); 1.375 + EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow); 1.376 + is(Services.prefs.getIntPref("extensions.inlinesettings3.radioInt"), 4, "Radio pref should have been updated"); 1.377 + EventUtils.synthesizeMouseAtCenter(radios[2], { clickCount: 1 }, gManagerWindow); 1.378 + is(Services.prefs.getIntPref("extensions.inlinesettings3.radioInt"), 6, "Radio pref should have been updated"); 1.379 + 1.380 + ok(!settings[2].hasAttribute("first-row"), "Not the first row"); 1.381 + Services.prefs.setCharPref("extensions.inlinesettings3.radioString", "juliet"); 1.382 + var radios = settings[2].getElementsByTagName("radio"); 1.383 + isnot(radios[0].selected, true, "Correct radio button should be selected"); 1.384 + is(radios[1].selected, true, "Correct radio button should be selected"); 1.385 + isnot(radios[2].selected, true, "Correct radio button should be selected"); 1.386 + EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow); 1.387 + is(Services.prefs.getCharPref("extensions.inlinesettings3.radioString"), "india", "Radio pref should have been updated"); 1.388 + EventUtils.synthesizeMouseAtCenter(radios[2], { clickCount: 1 }, gManagerWindow); 1.389 + is(Services.prefs.getCharPref("extensions.inlinesettings3.radioString"), "kilo", "Radio pref should have been updated"); 1.390 + 1.391 + ok(!settings[3].hasAttribute("first-row"), "Not the first row"); 1.392 + Services.prefs.setIntPref("extensions.inlinesettings3.menulist", 8); 1.393 + var input = settings[3].firstElementChild; 1.394 + is(input.value, "8", "Menulist should have initial value"); 1.395 + input.focus(); 1.396 + EventUtils.synthesizeKey("n", {}, gManagerWindow); 1.397 + is(input.value, "9", "Menulist should have updated value"); 1.398 + is(Services.prefs.getIntPref("extensions.inlinesettings3.menulist"), 9, "Menulist pref should have been updated"); 1.399 + 1.400 + button = gManagerWindow.document.getElementById("detail-prefs-btn"); 1.401 + is_element_hidden(button, "Preferences button should not be visible"); 1.402 + 1.403 + gCategoryUtilities.openType("extension", run_next_test); 1.404 + }); 1.405 +}); 1.406 + 1.407 +// Addon with inline preferences as optionsURL 1.408 +add_test(function() { 1.409 + observer.checkHidden("inlinesettings3@tests.mozilla.org"); 1.410 + 1.411 + var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org"); 1.412 + addon.parentNode.ensureElementIsVisible(addon); 1.413 + 1.414 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.415 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.416 + 1.417 + wait_for_view_load(gManagerWindow, function() { 1.418 + observer.checkDisplayed("inlinesettings2@tests.mozilla.org"); 1.419 + 1.420 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.421 + var settings = grid.querySelectorAll("rows > setting"); 1.422 + is(settings.length, 5, "Grid should have settings children"); 1.423 + 1.424 + var node = settings[0]; 1.425 + node = settings[0]; 1.426 + is_element_hidden(node, "Unsupported settings should not be visible"); 1.427 + ok(!node.hasAttribute("first-row"), "Hidden row is not the first row"); 1.428 + 1.429 + node = settings[1]; 1.430 + is(node.nodeName, "setting", "Should be a setting node"); 1.431 + ok(node.hasAttribute("first-row"), "First visible row should have first-row attribute"); 1.432 + var description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description"); 1.433 + is(description.textContent, "Description Attribute", "Description node should contain description"); 1.434 + 1.435 + node = settings[2]; 1.436 + is(node.nodeName, "setting", "Should be a setting node"); 1.437 + ok(!node.hasAttribute("first-row"), "Not the first row"); 1.438 + description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description"); 1.439 + is(description.textContent, "Description Text Node", "Description node should contain description"); 1.440 + 1.441 + node = settings[3]; 1.442 + is(node.nodeName, "setting", "Should be a setting node"); 1.443 + ok(!node.hasAttribute("first-row"), "Not the first row"); 1.444 + description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description"); 1.445 + is(description.textContent, "This is a test, all this text should be visible", "Description node should contain description"); 1.446 + var button = node.firstElementChild; 1.447 + isnot(button, null, "There should be a button"); 1.448 + 1.449 + node = settings[4]; 1.450 + is_element_hidden(node, "Unsupported settings should not be visible"); 1.451 + ok(!node.hasAttribute("first-row"), "Hidden row is not the first row"); 1.452 + 1.453 + var button = gManagerWindow.document.getElementById("detail-prefs-btn"); 1.454 + is_element_hidden(button, "Preferences button should not be visible"); 1.455 + 1.456 + gCategoryUtilities.openType("extension", run_next_test); 1.457 + }); 1.458 +}); 1.459 + 1.460 +// Addon with non-inline preferences as optionsURL 1.461 +add_test(function() { 1.462 + observer.checkHidden("inlinesettings2@tests.mozilla.org"); 1.463 + 1.464 + var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org"); 1.465 + addon.parentNode.ensureElementIsVisible(addon); 1.466 + 1.467 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); 1.468 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.469 + 1.470 + wait_for_view_load(gManagerWindow, function() { 1.471 + observer.checkNotDisplayed(); 1.472 + 1.473 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.474 + var settings = grid.querySelectorAll("rows > setting"); 1.475 + is(settings.length, 0, "Grid should not have settings children"); 1.476 + 1.477 + var button = gManagerWindow.document.getElementById("detail-prefs-btn"); 1.478 + is_element_visible(button, "Preferences button should be visible"); 1.479 + 1.480 + gCategoryUtilities.openType("extension", run_next_test); 1.481 + }); 1.482 +}); 1.483 + 1.484 +// Addon with options.xul, disabling and enabling should hide and show settings UI 1.485 +add_test(function() { 1.486 + observer.checkNotHidden(); 1.487 + 1.488 + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); 1.489 + addon.parentNode.ensureElementIsVisible(addon); 1.490 + 1.491 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); 1.492 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.493 + 1.494 + wait_for_view_load(gManagerWindow, function() { 1.495 + observer.checkDisplayed("inlinesettings1@tests.mozilla.org"); 1.496 + is(gManagerWindow.gViewController.currentViewId, 1.497 + "addons://detail/inlinesettings1%40tests.mozilla.org", 1.498 + "Current view should not scroll to preferences"); 1.499 + checkScrolling(false); 1.500 + 1.501 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.502 + var settings = grid.querySelectorAll("rows > setting"); 1.503 + is(settings.length, SETTINGS_ROWS, "Grid should have settings children"); 1.504 + 1.505 + // disable 1.506 + var button = gManagerWindow.document.getElementById("detail-disable-btn"); 1.507 + button.focus(); // make sure it's in view 1.508 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.509 + 1.510 + observer.checkHidden("inlinesettings1@tests.mozilla.org"); 1.511 + 1.512 + settings = grid.querySelectorAll("rows > setting"); 1.513 + is(settings.length, 0, "Grid should not have settings children"); 1.514 + 1.515 + gCategoryUtilities.openType("extension", function() { 1.516 + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); 1.517 + addon.parentNode.ensureElementIsVisible(addon); 1.518 + 1.519 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.520 + is_element_hidden(button, "Preferences button should not be visible"); 1.521 + 1.522 + button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); 1.523 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.524 + 1.525 + wait_for_view_load(gManagerWindow, function() { 1.526 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.527 + var settings = grid.querySelectorAll("rows > setting"); 1.528 + is(settings.length, 0, "Grid should not have settings children"); 1.529 + 1.530 + // enable 1.531 + var button = gManagerWindow.document.getElementById("detail-enable-btn"); 1.532 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.533 + 1.534 + observer.callback = function() { 1.535 + observer.checkDisplayed("inlinesettings1@tests.mozilla.org"); 1.536 + 1.537 + settings = grid.querySelectorAll("rows > setting"); 1.538 + is(settings.length, SETTINGS_ROWS, "Grid should have settings children"); 1.539 + 1.540 + gCategoryUtilities.openType("extension", run_next_test); 1.541 + }; 1.542 + }); 1.543 + }); 1.544 + }); 1.545 +}); 1.546 + 1.547 + 1.548 +// Addon with options.xul that requires a restart to disable, 1.549 +// disabling and enabling should not hide and show settings UI. 1.550 +add_test(function() { 1.551 + observer.checkHidden("inlinesettings1@tests.mozilla.org"); 1.552 + 1.553 + var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org"); 1.554 + addon.parentNode.ensureElementIsVisible(addon); 1.555 + 1.556 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); 1.557 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.558 + 1.559 + wait_for_view_load(gManagerWindow, function() { 1.560 + observer.checkDisplayed("inlinesettings2@tests.mozilla.org"); 1.561 + 1.562 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.563 + var settings = grid.querySelectorAll("rows > setting"); 1.564 + ok(settings.length > 0, "Grid should have settings children"); 1.565 + 1.566 + // disable 1.567 + var button = gManagerWindow.document.getElementById("detail-disable-btn"); 1.568 + button.focus(); // make sure it's in view 1.569 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.570 + observer.checkNotHidden(); 1.571 + 1.572 + settings = grid.querySelectorAll("rows > setting"); 1.573 + ok(settings.length > 0, "Grid should still have settings children"); 1.574 + 1.575 + // cancel pending disable 1.576 + button = gManagerWindow.document.getElementById("detail-enable-btn"); 1.577 + button.focus(); // make sure it's in view 1.578 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.579 + observer.checkNotDisplayed(); 1.580 + 1.581 + gCategoryUtilities.openType("extension", run_next_test); 1.582 + }); 1.583 +}); 1.584 + 1.585 +// Tests bindings with existing prefs. 1.586 +add_test(function() { 1.587 + observer.checkHidden("inlinesettings2@tests.mozilla.org"); 1.588 + 1.589 + // Ensure these prefs are set. They should be set above, but somebody might 1.590 + // change the tests above. 1.591 + var profD = Services.dirsvc.get("ProfD", Ci.nsIFile); 1.592 + Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false); 1.593 + Services.prefs.setIntPref("extensions.inlinesettings1.boolint", 1); 1.594 + Services.prefs.setIntPref("extensions.inlinesettings1.integer", 12); 1.595 + Services.prefs.setCharPref("extensions.inlinesettings1.string", "bar/"); 1.596 + Services.prefs.setCharPref("extensions.inlinesettings1.color", "#FF9900"); 1.597 + Services.prefs.setCharPref("extensions.inlinesettings1.file", profD.path); 1.598 + Services.prefs.setCharPref("extensions.inlinesettings1.directory", profD.path); 1.599 + 1.600 + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); 1.601 + addon.parentNode.ensureElementIsVisible(addon); 1.602 + 1.603 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.604 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.605 + 1.606 + wait_for_view_load(gManagerWindow, function() { 1.607 + observer.checkDisplayed("inlinesettings1@tests.mozilla.org"); 1.608 + 1.609 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.610 + var settings = grid.querySelectorAll("rows > setting"); 1.611 + 1.612 + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input"); 1.613 + is(input.checked, false, "Checkbox should have initial value"); 1.614 + 1.615 + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[1], "anonid", "input"); 1.616 + is(input.checked, true, "Checkbox should have initial value"); 1.617 + 1.618 + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input"); 1.619 + is(input.value, "12", "Number box should have initial value"); 1.620 + 1.621 + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[3], "anonid", "input"); 1.622 + is(input.value, "bar/", "Text box should have initial value"); 1.623 + 1.624 + input = gManagerWindow.document.getAnonymousElementByAttribute(settings[5], "anonid", "input"); 1.625 + is(input.color, "#FF9900", "Color picker should have initial value"); 1.626 + 1.627 + input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input"); 1.628 + is(input.value, profD.path, "Label should have initial value"); 1.629 + is(input.tooltipText, profD.path, "Label tooltip should have initial value"); 1.630 + 1.631 + input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input"); 1.632 + is(input.value, profD.path, "Label value should have initial value"); 1.633 + is(input.tooltipText, profD.path, "Label tooltip should have initial value"); 1.634 + 1.635 + gCategoryUtilities.openType("extension", run_next_test); 1.636 + }); 1.637 +}); 1.638 + 1.639 +// Tests bindings with existing prefs. 1.640 +add_test(function() { 1.641 + observer.checkHidden("inlinesettings1@tests.mozilla.org"); 1.642 + 1.643 + // Ensure these prefs are set. They should be set above, but somebody might 1.644 + // change the tests above. 1.645 + Services.prefs.setBoolPref("extensions.inlinesettings3.radioBool", false); 1.646 + Services.prefs.setIntPref("extensions.inlinesettings3.radioInt", 6); 1.647 + Services.prefs.setCharPref("extensions.inlinesettings3.radioString", "kilo"); 1.648 + Services.prefs.setIntPref("extensions.inlinesettings3.menulist", 9); 1.649 + 1.650 + var addon = get_addon_element(gManagerWindow, "inlinesettings3@tests.mozilla.org"); 1.651 + addon.parentNode.ensureElementIsVisible(addon); 1.652 + 1.653 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.654 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.655 + 1.656 + wait_for_view_load(gManagerWindow, function() { 1.657 + observer.checkDisplayed("inlinesettings3@tests.mozilla.org"); 1.658 + 1.659 + var grid = gManagerWindow.document.getElementById("detail-grid"); 1.660 + var settings = grid.querySelectorAll("rows > setting"); 1.661 + 1.662 + var radios = settings[0].getElementsByTagName("radio"); 1.663 + isnot(radios[0].selected, true, "Correct radio button should be selected"); 1.664 + is(radios[1].selected, true, "Correct radio button should be selected"); 1.665 + 1.666 + var radios = settings[1].getElementsByTagName("radio"); 1.667 + isnot(radios[0].selected, true, "Correct radio button should be selected"); 1.668 + isnot(radios[1].selected, true, "Correct radio button should be selected"); 1.669 + is(radios[2].selected, true, "Correct radio button should be selected"); 1.670 + 1.671 + var radios = settings[2].getElementsByTagName("radio"); 1.672 + isnot(radios[0].selected, true, "Correct radio button should be selected"); 1.673 + isnot(radios[1].selected, true, "Correct radio button should be selected"); 1.674 + is(radios[2].selected, true, "Correct radio button should be selected"); 1.675 + 1.676 + var input = settings[3].firstElementChild; 1.677 + is(input.value, "9", "Menulist should have initial value"); 1.678 + 1.679 + gCategoryUtilities.openType("extension", run_next_test); 1.680 + }); 1.681 +});