tor-browser

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

test_user_default_prefs.js (2147B)


      1 const pb = Services.prefs;
      2 
      3 // This pref is chosen somewhat arbitrarily --- we just need one
      4 // that's guaranteed to have a default value.
      5 const kPrefName = "intl.accept_languages"; // of type char, which we
      6 // assume below
      7 var initialValue = null;
      8 
      9 function check_child_pref_info_eq(continuation) {
     10  sendCommand(
     11    'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n' +
     12      // Returns concatenation "[value],[isUser]"
     13      'pb.getCharPref("' +
     14      kPrefName +
     15      '")+ "," +' +
     16      'pb.prefHasUserValue("' +
     17      kPrefName +
     18      '");',
     19    function (info) {
     20      let [value, isUser] = info.split(",");
     21      Assert.equal(pb.getCharPref(kPrefName), value);
     22      Assert.equal(pb.prefHasUserValue(kPrefName), isUser == "true");
     23      continuation();
     24    }
     25  );
     26 }
     27 
     28 function run_test() {
     29  // We finish in clean_up()
     30  do_test_pending();
     31 
     32  initialValue = pb.getCharPref(kPrefName);
     33 
     34  test_user_setting();
     35 }
     36 
     37 function test_user_setting() {
     38  // We rely on setting this before the content process starts up.
     39  // When it starts up, it should recognize this as a user pref, not
     40  // a default pref.
     41  pb.setCharPref(kPrefName, "i-imaginarylanguage");
     42  // NB: processing of the value-change notification in the child
     43  // process triggered by the above set happens-before the remaining
     44  // code here
     45  check_child_pref_info_eq(function () {
     46    Assert.equal(pb.prefHasUserValue(kPrefName), true);
     47 
     48    test_cleared_is_default();
     49  });
     50 }
     51 
     52 function test_cleared_is_default() {
     53  pb.clearUserPref(kPrefName);
     54  // NB: processing of the value-change notification in the child
     55  // process triggered by the above set happens-before the remaining
     56  // code here
     57  check_child_pref_info_eq(function () {
     58    Assert.equal(pb.prefHasUserValue(kPrefName), false);
     59 
     60    clean_up();
     61  });
     62 }
     63 
     64 function clean_up() {
     65  pb.setCharPref(kPrefName, initialValue);
     66  // NB: processing of the value-change notification in the child
     67  // process triggered by the above set happens-before the remaining
     68  // code here
     69  check_child_pref_info_eq(function () {
     70    do_test_finished();
     71  });
     72 }