michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests various aspects of the details view michael@0: michael@0: var gManagerWindow; michael@0: var gCategoryUtilities; michael@0: var gProvider; michael@0: michael@0: const SETTINGS_ROWS = 9; michael@0: michael@0: var MockFilePicker = SpecialPowers.MockFilePicker; michael@0: MockFilePicker.init(window); michael@0: michael@0: var observer = { michael@0: lastDisplayed: null, michael@0: callback: null, michael@0: checkDisplayed: function(aExpected) { michael@0: is(this.lastDisplayed, aExpected, "'addon-options-displayed' notification should have fired"); michael@0: this.lastDisplayed = null; michael@0: }, michael@0: checkNotDisplayed: function() { michael@0: is(this.lastDisplayed, null, "'addon-options-displayed' notification should not have fired"); michael@0: }, michael@0: lastHidden: null, michael@0: checkHidden: function(aExpected) { michael@0: is(this.lastHidden, aExpected, "'addon-options-hidden' notification should have fired"); michael@0: this.lastHidden = null; michael@0: }, michael@0: checkNotHidden: function() { michael@0: is(this.lastHidden, null, "'addon-options-hidden' notification should not have fired"); michael@0: }, michael@0: observe: function(aSubject, aTopic, aData) { michael@0: if (aTopic == AddonManager.OPTIONS_NOTIFICATION_DISPLAYED) { michael@0: this.lastDisplayed = aData; michael@0: // Test if the binding has applied before the observers are notified. We test the second setting here, michael@0: // because the code operates on the first setting and we want to check it applies to all. michael@0: var setting = aSubject.querySelector("rows > setting[first-row] ~ setting"); michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(setting, "class", "preferences-title"); michael@0: isnot(input, null, "XBL binding should be applied"); michael@0: michael@0: // Add some extra height to the scrolling pane to ensure that it needs to scroll when appropriate. michael@0: gManagerWindow.document.getElementById("detail-controls").style.marginBottom = "1000px"; michael@0: michael@0: if (this.callback) { michael@0: var tempCallback = this.callback; michael@0: this.callback = null; michael@0: tempCallback(); michael@0: } michael@0: } else if (aTopic == AddonManager.OPTIONS_NOTIFICATION_HIDDEN) { michael@0: this.lastHidden = aData; michael@0: } michael@0: } michael@0: }; michael@0: michael@0: function installAddon(aCallback) { michael@0: AddonManager.getInstallForURL(TESTROOT + "addons/browser_inlinesettings1.xpi", michael@0: function(aInstall) { michael@0: aInstall.addListener({ michael@0: onInstallEnded: function() { michael@0: executeSoon(aCallback); michael@0: } michael@0: }); michael@0: aInstall.install(); michael@0: }, "application/x-xpinstall"); michael@0: } michael@0: michael@0: function checkScrolling(aShouldHaveScrolled) { michael@0: var detailView = gManagerWindow.document.getElementById("detail-view"); michael@0: var boxObject = detailView.boxObject; michael@0: boxObject.QueryInterface(Ci.nsIScrollBoxObject); michael@0: ok(detailView.scrollHeight > boxObject.height, "Page should require scrolling"); michael@0: if (aShouldHaveScrolled) michael@0: isnot(detailView.scrollTop, 0, "Page should have scrolled"); michael@0: else michael@0: is(detailView.scrollTop, 0, "Page should not have scrolled"); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: gProvider.createAddons([{ michael@0: id: "inlinesettings2@tests.mozilla.org", michael@0: name: "Inline Settings (Regular)", michael@0: version: "1", michael@0: optionsURL: CHROMEROOT + "options.xul", michael@0: optionsType: AddonManager.OPTIONS_TYPE_INLINE, michael@0: operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_DISABLE, michael@0: },{ michael@0: id: "inlinesettings3@tests.mozilla.org", michael@0: name: "Inline Settings (More Options)", michael@0: description: "Tests for option types introduced after Mozilla 7.0", michael@0: version: "1", michael@0: optionsURL: CHROMEROOT + "more_options.xul", michael@0: optionsType: AddonManager.OPTIONS_TYPE_INLINE michael@0: },{ michael@0: id: "noninlinesettings@tests.mozilla.org", michael@0: name: "Non-Inline Settings", michael@0: version: "1", michael@0: optionsURL: CHROMEROOT + "addon_prefs.xul" michael@0: }]); michael@0: michael@0: installAddon(function () { michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: michael@0: Services.obs.addObserver(observer, michael@0: AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, michael@0: false); michael@0: Services.obs.addObserver(observer, michael@0: AddonManager.OPTIONS_NOTIFICATION_HIDDEN, michael@0: false); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: Services.obs.removeObserver(observer, michael@0: AddonManager.OPTIONS_NOTIFICATION_DISPLAYED); michael@0: michael@0: Services.prefs.clearUserPref("extensions.inlinesettings1.bool"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings1.boolint"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings1.integer"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings1.string"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings1.color"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings1.file"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings1.directory"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings3.radioBool"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings3.radioInt"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings3.radioString"); michael@0: Services.prefs.clearUserPref("extensions.inlinesettings3.menulist"); michael@0: michael@0: MockFilePicker.cleanup(); michael@0: michael@0: close_manager(gManagerWindow, function() { michael@0: observer.checkHidden("inlinesettings3@tests.mozilla.org"); michael@0: Services.obs.removeObserver(observer, michael@0: AddonManager.OPTIONS_NOTIFICATION_HIDDEN); michael@0: michael@0: AddonManager.getAddonByID("inlinesettings1@tests.mozilla.org", function(aAddon) { michael@0: aAddon.uninstall(); michael@0: finish(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: // Addon with options.xul michael@0: add_test(function() { michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); michael@0: is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, "Options should be inline type"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: is_element_visible(button, "Preferences button should be visible"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Addon with inline preferences as optionsURL michael@0: add_test(function() { michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org"); michael@0: is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, "Options should be inline type"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: is_element_visible(button, "Preferences button should be visible"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Addon with non-inline preferences as optionsURL michael@0: add_test(function() { michael@0: var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org"); michael@0: is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_DIALOG, "Options should be dialog type"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: is_element_visible(button, "Preferences button should be visible"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Addon with options.xul, also a test for the setting.xml bindings michael@0: add_test(function() { michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: observer.checkDisplayed("inlinesettings1@tests.mozilla.org"); michael@0: is(gManagerWindow.gViewController.currentViewId, michael@0: "addons://detail/inlinesettings1%40tests.mozilla.org/preferences", michael@0: "Current view should scroll to preferences"); michael@0: checkScrolling(true); michael@0: michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: is(settings.length, SETTINGS_ROWS, "Grid should have settings children"); michael@0: michael@0: ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute"); michael@0: Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false); michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input"); michael@0: isnot(input.checked, true, "Checkbox should have initial value"); michael@0: is(input.label, "Check box label", "Checkbox should be labelled"); michael@0: EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); michael@0: is(input.checked, true, "Checkbox should have updated value"); michael@0: is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), true, "Bool pref should have been updated"); michael@0: EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); michael@0: isnot(input.checked, true, "Checkbox should have updated value"); michael@0: is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), false, "Bool pref should have been updated"); michael@0: michael@0: ok(!settings[1].hasAttribute("first-row"), "Not the first row"); michael@0: Services.prefs.setIntPref("extensions.inlinesettings1.boolint", 0); michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[1], "anonid", "input"); michael@0: isnot(input.checked, true, "Checkbox should have initial value"); michael@0: EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); michael@0: is(input.checked, true, "Checkbox should have updated value"); michael@0: is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 1, "BoolInt pref should have been updated"); michael@0: EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); michael@0: isnot(input.checked, true, "Checkbox should have updated value"); michael@0: is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 2, "BoolInt pref should have been updated"); michael@0: michael@0: ok(!settings[2].hasAttribute("first-row"), "Not the first row"); michael@0: Services.prefs.setIntPref("extensions.inlinesettings1.integer", 0); michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input"); michael@0: is(input.value, "0", "Number box should have initial value"); michael@0: input.select(); michael@0: EventUtils.synthesizeKey("1", {}, gManagerWindow); michael@0: EventUtils.synthesizeKey("3", {}, gManagerWindow); michael@0: is(input.value, "13", "Number box should have updated value"); michael@0: is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 13, "Integer pref should have been updated"); michael@0: EventUtils.synthesizeKey("VK_DOWN", {}, gManagerWindow); michael@0: is(input.value, "12", "Number box should have updated value"); michael@0: is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 12, "Integer pref should have been updated"); michael@0: michael@0: ok(!settings[3].hasAttribute("first-row"), "Not the first row"); michael@0: Services.prefs.setCharPref("extensions.inlinesettings1.string", "foo"); michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[3], "anonid", "input"); michael@0: is(input.value, "foo", "Text box should have initial value"); michael@0: input.select(); michael@0: EventUtils.synthesizeKey("b", {}, gManagerWindow); michael@0: EventUtils.synthesizeKey("a", {}, gManagerWindow); michael@0: EventUtils.synthesizeKey("r", {}, gManagerWindow); michael@0: is(input.value, "bar", "Text box should have updated value"); michael@0: EventUtils.synthesizeKey("/", {}, gManagerWindow); michael@0: is(input.value, "bar/", "Text box should have updated value"); michael@0: is(gManagerWindow.document.getBindingParent(gManagerWindow.document.activeElement), input, "Search box should not have focus"); michael@0: is(Services.prefs.getCharPref("extensions.inlinesettings1.string"), "bar/", "String pref should have been updated"); michael@0: michael@0: ok(!settings[4].hasAttribute("first-row"), "Not the first row"); michael@0: var input = settings[4].firstElementChild; michael@0: is(input.value, "1", "Menulist should have initial value"); michael@0: input.focus(); michael@0: EventUtils.synthesizeKey("b", {}, gManagerWindow); michael@0: is(input.value, "2", "Menulist should have updated value"); michael@0: is(gManagerWindow._testValue, "2", "Menulist oncommand handler should've updated the test value"); michael@0: delete gManagerWindow._testValue; michael@0: michael@0: ok(!settings[5].hasAttribute("first-row"), "Not the first row"); michael@0: Services.prefs.setCharPref("extensions.inlinesettings1.color", "#FF0000"); michael@0: input = gManagerWindow.document.getAnonymousElementByAttribute(settings[5], "anonid", "input"); michael@0: is(input.color, "#FF0000", "Color picker should have initial value"); michael@0: input.focus(); michael@0: EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow); michael@0: EventUtils.synthesizeKey("VK_RIGHT", {}, gManagerWindow); michael@0: EventUtils.synthesizeKey("VK_RETURN", {}, gManagerWindow); michael@0: input.hidePopup(); michael@0: is(input.color, "#FF9900", "Color picker should have updated value"); michael@0: is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated"); michael@0: michael@0: try { michael@0: ok(!settings[6].hasAttribute("first-row"), "Not the first row"); michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button"); michael@0: input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input"); michael@0: is(input.value, "", "Label value should be empty"); michael@0: is(input.tooltipText, "", "Label tooltip should be empty"); michael@0: michael@0: var profD = Services.dirsvc.get("ProfD", Ci.nsIFile); michael@0: var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile); michael@0: michael@0: MockFilePicker.returnFiles = [profD]; michael@0: MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file"); michael@0: is(input.value, profD.path, "Label value should match file chosen"); michael@0: is(input.tooltipText, profD.path, "Label tooltip should match file chosen"); michael@0: is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should match file chosen"); michael@0: michael@0: MockFilePicker.returnFiles = [curProcD]; michael@0: MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel; michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file"); michael@0: is(input.value, profD.path, "Label value should not have changed"); michael@0: is(input.tooltipText, profD.path, "Label tooltip should not have changed"); michael@0: is(Services.prefs.getCharPref("extensions.inlinesettings1.file"), profD.path, "File pref should not have changed"); michael@0: michael@0: ok(!settings[7].hasAttribute("first-row"), "Not the first row"); michael@0: button = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "button"); michael@0: input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input"); michael@0: is(input.value, "", "Label value should be empty"); michael@0: is(input.tooltipText, "", "Label tooltip should be empty"); michael@0: michael@0: MockFilePicker.returnFiles = [profD]; michael@0: MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory"); michael@0: is(input.value, profD.path, "Label value should match file chosen"); michael@0: is(input.tooltipText, profD.path, "Label tooltip should match file chosen"); michael@0: is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should match file chosen"); michael@0: michael@0: MockFilePicker.returnFiles = [curProcD]; michael@0: MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel; michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory"); michael@0: is(input.value, profD.path, "Label value should not have changed"); michael@0: is(input.tooltipText, profD.path, "Label tooltip should not have changed"); michael@0: is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should not have changed"); michael@0: michael@0: var unsizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input"); michael@0: var sizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[8], "anonid", "input"); michael@0: is(unsizedInput.clientWidth > sizedInput.clientWidth, true, "Input with size attribute should be smaller than input without"); michael@0: } finally { michael@0: button = gManagerWindow.document.getElementById("detail-prefs-btn"); michael@0: is_element_hidden(button, "Preferences button should not be visible"); michael@0: michael@0: gCategoryUtilities.openType("extension", run_next_test); michael@0: } michael@0: }); michael@0: }); michael@0: michael@0: // Tests for the setting.xml bindings introduced after Mozilla 7 michael@0: add_test(function() { michael@0: observer.checkHidden("inlinesettings1@tests.mozilla.org"); michael@0: michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings3@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: observer.checkDisplayed("inlinesettings3@tests.mozilla.org"); michael@0: michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: is(settings.length, 4, "Grid should have settings children"); michael@0: michael@0: ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute"); michael@0: Services.prefs.setBoolPref("extensions.inlinesettings3.radioBool", false); michael@0: var radios = settings[0].getElementsByTagName("radio"); michael@0: isnot(radios[0].selected, true, "Correct radio button should be selected"); michael@0: is(radios[1].selected, true, "Correct radio button should be selected"); michael@0: EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow); michael@0: is(Services.prefs.getBoolPref("extensions.inlinesettings3.radioBool"), true, "Radio pref should have been updated"); michael@0: EventUtils.synthesizeMouseAtCenter(radios[1], { clickCount: 1 }, gManagerWindow); michael@0: is(Services.prefs.getBoolPref("extensions.inlinesettings3.radioBool"), false, "Radio pref should have been updated"); michael@0: michael@0: ok(!settings[1].hasAttribute("first-row"), "Not the first row"); michael@0: Services.prefs.setIntPref("extensions.inlinesettings3.radioInt", 5); michael@0: var radios = settings[1].getElementsByTagName("radio"); michael@0: isnot(radios[0].selected, true, "Correct radio button should be selected"); michael@0: is(radios[1].selected, true, "Correct radio button should be selected"); michael@0: isnot(radios[2].selected, true, "Correct radio button should be selected"); michael@0: EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow); michael@0: is(Services.prefs.getIntPref("extensions.inlinesettings3.radioInt"), 4, "Radio pref should have been updated"); michael@0: EventUtils.synthesizeMouseAtCenter(radios[2], { clickCount: 1 }, gManagerWindow); michael@0: is(Services.prefs.getIntPref("extensions.inlinesettings3.radioInt"), 6, "Radio pref should have been updated"); michael@0: michael@0: ok(!settings[2].hasAttribute("first-row"), "Not the first row"); michael@0: Services.prefs.setCharPref("extensions.inlinesettings3.radioString", "juliet"); michael@0: var radios = settings[2].getElementsByTagName("radio"); michael@0: isnot(radios[0].selected, true, "Correct radio button should be selected"); michael@0: is(radios[1].selected, true, "Correct radio button should be selected"); michael@0: isnot(radios[2].selected, true, "Correct radio button should be selected"); michael@0: EventUtils.synthesizeMouseAtCenter(radios[0], { clickCount: 1 }, gManagerWindow); michael@0: is(Services.prefs.getCharPref("extensions.inlinesettings3.radioString"), "india", "Radio pref should have been updated"); michael@0: EventUtils.synthesizeMouseAtCenter(radios[2], { clickCount: 1 }, gManagerWindow); michael@0: is(Services.prefs.getCharPref("extensions.inlinesettings3.radioString"), "kilo", "Radio pref should have been updated"); michael@0: michael@0: ok(!settings[3].hasAttribute("first-row"), "Not the first row"); michael@0: Services.prefs.setIntPref("extensions.inlinesettings3.menulist", 8); michael@0: var input = settings[3].firstElementChild; michael@0: is(input.value, "8", "Menulist should have initial value"); michael@0: input.focus(); michael@0: EventUtils.synthesizeKey("n", {}, gManagerWindow); michael@0: is(input.value, "9", "Menulist should have updated value"); michael@0: is(Services.prefs.getIntPref("extensions.inlinesettings3.menulist"), 9, "Menulist pref should have been updated"); michael@0: michael@0: button = gManagerWindow.document.getElementById("detail-prefs-btn"); michael@0: is_element_hidden(button, "Preferences button should not be visible"); michael@0: michael@0: gCategoryUtilities.openType("extension", run_next_test); michael@0: }); michael@0: }); michael@0: michael@0: // Addon with inline preferences as optionsURL michael@0: add_test(function() { michael@0: observer.checkHidden("inlinesettings3@tests.mozilla.org"); michael@0: michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: observer.checkDisplayed("inlinesettings2@tests.mozilla.org"); michael@0: michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: is(settings.length, 5, "Grid should have settings children"); michael@0: michael@0: var node = settings[0]; michael@0: node = settings[0]; michael@0: is_element_hidden(node, "Unsupported settings should not be visible"); michael@0: ok(!node.hasAttribute("first-row"), "Hidden row is not the first row"); michael@0: michael@0: node = settings[1]; michael@0: is(node.nodeName, "setting", "Should be a setting node"); michael@0: ok(node.hasAttribute("first-row"), "First visible row should have first-row attribute"); michael@0: var description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description"); michael@0: is(description.textContent, "Description Attribute", "Description node should contain description"); michael@0: michael@0: node = settings[2]; michael@0: is(node.nodeName, "setting", "Should be a setting node"); michael@0: ok(!node.hasAttribute("first-row"), "Not the first row"); michael@0: description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description"); michael@0: is(description.textContent, "Description Text Node", "Description node should contain description"); michael@0: michael@0: node = settings[3]; michael@0: is(node.nodeName, "setting", "Should be a setting node"); michael@0: ok(!node.hasAttribute("first-row"), "Not the first row"); michael@0: description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description"); michael@0: is(description.textContent, "This is a test, all this text should be visible", "Description node should contain description"); michael@0: var button = node.firstElementChild; michael@0: isnot(button, null, "There should be a button"); michael@0: michael@0: node = settings[4]; michael@0: is_element_hidden(node, "Unsupported settings should not be visible"); michael@0: ok(!node.hasAttribute("first-row"), "Hidden row is not the first row"); michael@0: michael@0: var button = gManagerWindow.document.getElementById("detail-prefs-btn"); michael@0: is_element_hidden(button, "Preferences button should not be visible"); michael@0: michael@0: gCategoryUtilities.openType("extension", run_next_test); michael@0: }); michael@0: }); michael@0: michael@0: // Addon with non-inline preferences as optionsURL michael@0: add_test(function() { michael@0: observer.checkHidden("inlinesettings2@tests.mozilla.org"); michael@0: michael@0: var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: observer.checkNotDisplayed(); michael@0: michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: is(settings.length, 0, "Grid should not have settings children"); michael@0: michael@0: var button = gManagerWindow.document.getElementById("detail-prefs-btn"); michael@0: is_element_visible(button, "Preferences button should be visible"); michael@0: michael@0: gCategoryUtilities.openType("extension", run_next_test); michael@0: }); michael@0: }); michael@0: michael@0: // Addon with options.xul, disabling and enabling should hide and show settings UI michael@0: add_test(function() { michael@0: observer.checkNotHidden(); michael@0: michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: observer.checkDisplayed("inlinesettings1@tests.mozilla.org"); michael@0: is(gManagerWindow.gViewController.currentViewId, michael@0: "addons://detail/inlinesettings1%40tests.mozilla.org", michael@0: "Current view should not scroll to preferences"); michael@0: checkScrolling(false); michael@0: michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: is(settings.length, SETTINGS_ROWS, "Grid should have settings children"); michael@0: michael@0: // disable michael@0: var button = gManagerWindow.document.getElementById("detail-disable-btn"); michael@0: button.focus(); // make sure it's in view michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: observer.checkHidden("inlinesettings1@tests.mozilla.org"); michael@0: michael@0: settings = grid.querySelectorAll("rows > setting"); michael@0: is(settings.length, 0, "Grid should not have settings children"); michael@0: michael@0: gCategoryUtilities.openType("extension", function() { michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: is_element_hidden(button, "Preferences button should not be visible"); michael@0: michael@0: button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: is(settings.length, 0, "Grid should not have settings children"); michael@0: michael@0: // enable michael@0: var button = gManagerWindow.document.getElementById("detail-enable-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: observer.callback = function() { michael@0: observer.checkDisplayed("inlinesettings1@tests.mozilla.org"); michael@0: michael@0: settings = grid.querySelectorAll("rows > setting"); michael@0: is(settings.length, SETTINGS_ROWS, "Grid should have settings children"); michael@0: michael@0: gCategoryUtilities.openType("extension", run_next_test); michael@0: }; michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: michael@0: // Addon with options.xul that requires a restart to disable, michael@0: // disabling and enabling should not hide and show settings UI. michael@0: add_test(function() { michael@0: observer.checkHidden("inlinesettings1@tests.mozilla.org"); michael@0: michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: observer.checkDisplayed("inlinesettings2@tests.mozilla.org"); michael@0: michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: ok(settings.length > 0, "Grid should have settings children"); michael@0: michael@0: // disable michael@0: var button = gManagerWindow.document.getElementById("detail-disable-btn"); michael@0: button.focus(); // make sure it's in view michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: observer.checkNotHidden(); michael@0: michael@0: settings = grid.querySelectorAll("rows > setting"); michael@0: ok(settings.length > 0, "Grid should still have settings children"); michael@0: michael@0: // cancel pending disable michael@0: button = gManagerWindow.document.getElementById("detail-enable-btn"); michael@0: button.focus(); // make sure it's in view michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: observer.checkNotDisplayed(); michael@0: michael@0: gCategoryUtilities.openType("extension", run_next_test); michael@0: }); michael@0: }); michael@0: michael@0: // Tests bindings with existing prefs. michael@0: add_test(function() { michael@0: observer.checkHidden("inlinesettings2@tests.mozilla.org"); michael@0: michael@0: // Ensure these prefs are set. They should be set above, but somebody might michael@0: // change the tests above. michael@0: var profD = Services.dirsvc.get("ProfD", Ci.nsIFile); michael@0: Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false); michael@0: Services.prefs.setIntPref("extensions.inlinesettings1.boolint", 1); michael@0: Services.prefs.setIntPref("extensions.inlinesettings1.integer", 12); michael@0: Services.prefs.setCharPref("extensions.inlinesettings1.string", "bar/"); michael@0: Services.prefs.setCharPref("extensions.inlinesettings1.color", "#FF9900"); michael@0: Services.prefs.setCharPref("extensions.inlinesettings1.file", profD.path); michael@0: Services.prefs.setCharPref("extensions.inlinesettings1.directory", profD.path); michael@0: michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: observer.checkDisplayed("inlinesettings1@tests.mozilla.org"); michael@0: michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input"); michael@0: is(input.checked, false, "Checkbox should have initial value"); michael@0: michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[1], "anonid", "input"); michael@0: is(input.checked, true, "Checkbox should have initial value"); michael@0: michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input"); michael@0: is(input.value, "12", "Number box should have initial value"); michael@0: michael@0: var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[3], "anonid", "input"); michael@0: is(input.value, "bar/", "Text box should have initial value"); michael@0: michael@0: input = gManagerWindow.document.getAnonymousElementByAttribute(settings[5], "anonid", "input"); michael@0: is(input.color, "#FF9900", "Color picker should have initial value"); michael@0: michael@0: input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input"); michael@0: is(input.value, profD.path, "Label should have initial value"); michael@0: is(input.tooltipText, profD.path, "Label tooltip should have initial value"); michael@0: michael@0: input = gManagerWindow.document.getAnonymousElementByAttribute(settings[7], "anonid", "input"); michael@0: is(input.value, profD.path, "Label value should have initial value"); michael@0: is(input.tooltipText, profD.path, "Label tooltip should have initial value"); michael@0: michael@0: gCategoryUtilities.openType("extension", run_next_test); michael@0: }); michael@0: }); michael@0: michael@0: // Tests bindings with existing prefs. michael@0: add_test(function() { michael@0: observer.checkHidden("inlinesettings1@tests.mozilla.org"); michael@0: michael@0: // Ensure these prefs are set. They should be set above, but somebody might michael@0: // change the tests above. michael@0: Services.prefs.setBoolPref("extensions.inlinesettings3.radioBool", false); michael@0: Services.prefs.setIntPref("extensions.inlinesettings3.radioInt", 6); michael@0: Services.prefs.setCharPref("extensions.inlinesettings3.radioString", "kilo"); michael@0: Services.prefs.setIntPref("extensions.inlinesettings3.menulist", 9); michael@0: michael@0: var addon = get_addon_element(gManagerWindow, "inlinesettings3@tests.mozilla.org"); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: observer.checkDisplayed("inlinesettings3@tests.mozilla.org"); michael@0: michael@0: var grid = gManagerWindow.document.getElementById("detail-grid"); michael@0: var settings = grid.querySelectorAll("rows > setting"); michael@0: michael@0: var radios = settings[0].getElementsByTagName("radio"); michael@0: isnot(radios[0].selected, true, "Correct radio button should be selected"); michael@0: is(radios[1].selected, true, "Correct radio button should be selected"); michael@0: michael@0: var radios = settings[1].getElementsByTagName("radio"); michael@0: isnot(radios[0].selected, true, "Correct radio button should be selected"); michael@0: isnot(radios[1].selected, true, "Correct radio button should be selected"); michael@0: is(radios[2].selected, true, "Correct radio button should be selected"); michael@0: michael@0: var radios = settings[2].getElementsByTagName("radio"); michael@0: isnot(radios[0].selected, true, "Correct radio button should be selected"); michael@0: isnot(radios[1].selected, true, "Correct radio button should be selected"); michael@0: is(radios[2].selected, true, "Correct radio button should be selected"); michael@0: michael@0: var input = settings[3].firstElementChild; michael@0: is(input.value, "9", "Menulist should have initial value"); michael@0: michael@0: gCategoryUtilities.openType("extension", run_next_test); michael@0: }); michael@0: });