toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial