tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_dynamic_tool_enabling.js (1185B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests that toggling prefs immediately (de)activates the relevant menuitem
      5 
      6 var gItemsToTest = {
      7  menu_browserToolbox: [
      8    "devtools.chrome.enabled",
      9    "devtools.debugger.remote-enabled",
     10  ],
     11 };
     12 
     13 function expectedAttributeValueFromPrefs(prefs) {
     14  return prefs.every(pref => Services.prefs.getBoolPref(pref));
     15 }
     16 
     17 function checkItem(el, prefs) {
     18  const expectedValue = expectedAttributeValueFromPrefs(prefs);
     19  is(
     20    el.hasAttribute("disabled"),
     21    !expectedValue,
     22    "disabled attribute should match current pref state"
     23  );
     24  is(
     25    el.hasAttribute("hidden"),
     26    !expectedValue,
     27    "hidden attribute should match current pref state"
     28  );
     29 }
     30 
     31 function test() {
     32  for (const k in gItemsToTest) {
     33    const el = document.getElementById(k);
     34    const prefs = gItemsToTest[k];
     35    checkItem(el, prefs);
     36    for (const pref of prefs) {
     37      Services.prefs.setBoolPref(pref, !Services.prefs.getBoolPref(pref));
     38      checkItem(el, prefs);
     39      Services.prefs.setBoolPref(pref, !Services.prefs.getBoolPref(pref));
     40      checkItem(el, prefs);
     41    }
     42  }
     43  finish();
     44 }