tor-browser

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

test_locked_file_prefs.js (1966B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/licenses/publicdomain/  */
      3 
      4 // This file tests the `locked` attribute in default pref files.
      5 
      6 const ps = Services.prefs;
      7 
      8 // It is necessary to manually disable `xpc::IsInAutomation` since
      9 // `resetPrefs` will flip the preference to re-enable `once`-synced
     10 // preference change assertions, and also change the value of those
     11 // preferences.
     12 Services.prefs.setBoolPref(
     13  "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer",
     14  false
     15 );
     16 
     17 add_test(function notChangedFromAPI() {
     18  ps.resetPrefs();
     19  ps.readDefaultPrefsFromFile(do_get_file("data/testPrefLocked.js"));
     20  Assert.strictEqual(ps.getIntPref("testPref.unlocked.int"), 333);
     21  Assert.strictEqual(ps.getIntPref("testPref.locked.int"), 444);
     22 
     23  // Unlocked pref: can set the user value, which is used upon reading.
     24  ps.setIntPref("testPref.unlocked.int", 334);
     25  Assert.ok(ps.prefHasUserValue("testPref.unlocked.int"), "has a user value");
     26  Assert.strictEqual(ps.getIntPref("testPref.unlocked.int"), 334);
     27 
     28  // Locked pref: can set the user value, but the default value is used upon
     29  // reading.
     30  ps.setIntPref("testPref.locked.int", 445);
     31  Assert.ok(ps.prefHasUserValue("testPref.locked.int"), "has a user value");
     32  Assert.strictEqual(ps.getIntPref("testPref.locked.int"), 444);
     33 
     34  // After unlocking, the user value is used.
     35  ps.unlockPref("testPref.locked.int");
     36  Assert.ok(ps.prefHasUserValue("testPref.locked.int"), "has a user value");
     37  Assert.strictEqual(ps.getIntPref("testPref.locked.int"), 445);
     38 
     39  run_next_test();
     40 });
     41 
     42 add_test(function notChangedFromUserPrefs() {
     43  ps.resetPrefs();
     44  ps.readDefaultPrefsFromFile(do_get_file("data/testPrefLocked.js"));
     45  ps.readUserPrefsFromFile(do_get_file("data/testPrefLockedUser.js"));
     46 
     47  Assert.strictEqual(ps.getIntPref("testPref.unlocked.int"), 333);
     48  Assert.strictEqual(ps.getIntPref("testPref.locked.int"), 444);
     49 
     50  run_next_test();
     51 });