tor-browser

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

browser_prefs-01.js (1512B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests that the preference helpers work properly.
      7 
      8 const { PrefsHelper } = require("resource://devtools/client/shared/prefs.js");
      9 
     10 function test() {
     11  const Prefs = new PrefsHelper("devtools.debugger", {
     12    foo: ["Bool", "enabled"],
     13  });
     14 
     15  const originalPrefValue = Services.prefs.getBoolPref(
     16    "devtools.debugger.enabled"
     17  );
     18  is(Prefs.foo, originalPrefValue, "The pref value was correctly fetched.");
     19 
     20  Prefs.foo = !originalPrefValue;
     21  is(Prefs.foo, !originalPrefValue, "The pref was was correctly changed (1).");
     22  is(
     23    Services.prefs.getBoolPref("devtools.debugger.enabled"),
     24    !originalPrefValue,
     25    "The pref was was correctly changed (2)."
     26  );
     27 
     28  Services.prefs.setBoolPref("devtools.debugger.enabled", originalPrefValue);
     29  info("The pref value was reset (1).");
     30  is(
     31    Prefs.foo,
     32    !originalPrefValue,
     33    "The cached pref value hasn't changed yet (1)."
     34  );
     35 
     36  Services.prefs.setBoolPref("devtools.debugger.enabled", !originalPrefValue);
     37  info("The pref value was reset (2).");
     38  is(
     39    Prefs.foo,
     40    !originalPrefValue,
     41    "The cached pref value hasn't changed yet (2)."
     42  );
     43 
     44  Prefs.registerObserver();
     45 
     46  Services.prefs.setBoolPref("devtools.debugger.enabled", originalPrefValue);
     47  info("The pref value was reset (3).");
     48  is(Prefs.foo, originalPrefValue, "The cached pref value has changed now.");
     49 
     50  Prefs.unregisterObserver();
     51 
     52  finish();
     53 }