michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests that toggling prefs immediately (de)activates the relevant menuitem michael@0: michael@0: let gItemsToTest = { michael@0: "menu_devToolbar": "devtools.toolbar.enabled", michael@0: "menu_devAppMgr": "devtools.appmanager.enabled", michael@0: "menu_browserToolbox": ["devtools.chrome.enabled", "devtools.debugger.remote-enabled", "devtools.debugger.chrome-enabled"], michael@0: "javascriptConsole": "devtools.errorconsole.enabled", michael@0: "menu_devtools_connect": "devtools.debugger.remote-enabled", michael@0: }; michael@0: michael@0: function expectedAttributeValueFromPrefs(prefs) { michael@0: return prefs.every((pref) => Services.prefs.getBoolPref(pref)) ? michael@0: "" : "true"; michael@0: } michael@0: michael@0: function checkItem(el, prefs) { michael@0: let expectedValue = expectedAttributeValueFromPrefs(prefs); michael@0: is(el.getAttribute("disabled"), expectedValue, "disabled attribute should match current pref state"); michael@0: is(el.getAttribute("hidden"), expectedValue, "hidden attribute should match current pref state"); michael@0: } michael@0: michael@0: function test() { michael@0: for (let k in gItemsToTest) { michael@0: let el = document.getElementById(k); michael@0: let prefs = gItemsToTest[k]; michael@0: if (typeof prefs == "string") { michael@0: prefs = [prefs]; michael@0: } michael@0: checkItem(el, prefs); michael@0: for (let pref of prefs) { michael@0: Services.prefs.setBoolPref(pref, !Services.prefs.getBoolPref(pref)); michael@0: checkItem(el, prefs); michael@0: Services.prefs.setBoolPref(pref, !Services.prefs.getBoolPref(pref)); michael@0: checkItem(el, prefs); michael@0: } michael@0: } michael@0: }