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