tor-browser

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

test_dirtyPrefs.js (2394B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /* Tests for handling of the preferences 'dirty' flag (bug 985998) */
      6 
      7 function run_test() {
      8  const ps = Services.prefs;
      9 
     10  let defaultBranch = ps.getDefaultBranch("");
     11  let userBranch = ps.getBranch("");
     12 
     13  let prefFile = do_get_profile();
     14  prefFile.append("prefs.js");
     15 
     16  //* *************************************************************************//
     17  // prefs are not dirty after a write
     18  ps.savePrefFile(null);
     19  Assert.ok(!ps.dirty);
     20 
     21  // set a new a user value, we should become dirty
     22  userBranch.setBoolPref("DirtyTest.new.bool", true);
     23  Assert.ok(ps.dirty);
     24  ps.savePrefFile(null);
     25  // Overwrite a pref with the same value => not dirty
     26  userBranch.setBoolPref("DirtyTest.new.bool", true);
     27  Assert.ok(!ps.dirty);
     28 
     29  // Repeat for the other two types
     30  userBranch.setIntPref("DirtyTest.new.int", 1);
     31  Assert.ok(ps.dirty);
     32  ps.savePrefFile(null);
     33  // Overwrite a pref with the same value => not dirty
     34  userBranch.setIntPref("DirtyTest.new.int", 1);
     35  Assert.ok(!ps.dirty);
     36 
     37  userBranch.setCharPref("DirtyTest.new.char", "oop");
     38  Assert.ok(ps.dirty);
     39  ps.savePrefFile(null);
     40  // Overwrite a pref with the same value => not dirty
     41  userBranch.setCharPref("DirtyTest.new.char", "oop");
     42  Assert.ok(!ps.dirty);
     43 
     44  // change *type* of a user value -> dirty
     45  userBranch.setBoolPref("DirtyTest.new.char", false);
     46  Assert.ok(ps.dirty);
     47  ps.savePrefFile(null);
     48 
     49  // Set a default pref => not dirty (defaults don't go into prefs.js)
     50  defaultBranch.setBoolPref("DirtyTest.existing.bool", true);
     51  Assert.ok(!ps.dirty);
     52  // Fail to change type of a pref with default value -> not dirty
     53  do_check_throws(function () {
     54    userBranch.setCharPref("DirtyTest.existing.bool", "boo");
     55  }, Cr.NS_ERROR_UNEXPECTED);
     56  Assert.ok(!ps.dirty);
     57 
     58  // Set user value same as default, not dirty
     59  userBranch.setBoolPref("DirtyTest.existing.bool", true);
     60  Assert.ok(!ps.dirty);
     61  // User value different from default, dirty
     62  userBranch.setBoolPref("DirtyTest.existing.bool", false);
     63  Assert.ok(ps.dirty);
     64  ps.savePrefFile(null);
     65  // Back to default value, dirty again
     66  userBranch.setBoolPref("DirtyTest.existing.bool", true);
     67  Assert.ok(ps.dirty);
     68  ps.savePrefFile(null);
     69 }