summaryrefslogtreecommitdiffstats
path: root/modules/libpref/test/unit/test_locked_file_prefs.js
blob: 29b5270df5891bd2a172408491a3b6669154a02c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/  */

// This file tests the `locked` attribute in default pref files.

const ps = Services.prefs;

// It is necessary to manually disable `xpc::IsInAutomation` since
// `resetPrefs` will flip the preference to re-enable `once`-synced
// preference change assertions, and also change the value of those
// preferences.
Services.prefs.setBoolPref(
  "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer",
  false
);

add_test(function notChangedFromAPI() {
  ps.resetPrefs();
  ps.readDefaultPrefsFromFile(do_get_file("data/testPrefLocked.js"));
  Assert.strictEqual(ps.getIntPref("testPref.unlocked.int"), 333);
  Assert.strictEqual(ps.getIntPref("testPref.locked.int"), 444);

  // Unlocked pref: can set the user value, which is used upon reading.
  ps.setIntPref("testPref.unlocked.int", 334);
  Assert.ok(ps.prefHasUserValue("testPref.unlocked.int"), "has a user value");
  Assert.strictEqual(ps.getIntPref("testPref.unlocked.int"), 334);

  // Locked pref: can set the user value, but the default value is used upon
  // reading.
  ps.setIntPref("testPref.locked.int", 445);
  Assert.ok(ps.prefHasUserValue("testPref.locked.int"), "has a user value");
  Assert.strictEqual(ps.getIntPref("testPref.locked.int"), 444);

  // After unlocking, the user value is used.
  ps.unlockPref("testPref.locked.int");
  Assert.ok(ps.prefHasUserValue("testPref.locked.int"), "has a user value");
  Assert.strictEqual(ps.getIntPref("testPref.locked.int"), 445);

  run_next_test();
});

add_test(function notChangedFromUserPrefs() {
  ps.resetPrefs();
  ps.readDefaultPrefsFromFile(do_get_file("data/testPrefLocked.js"));
  ps.readUserPrefsFromFile(do_get_file("data/testPrefLockedUser.js"));

  Assert.strictEqual(ps.getIntPref("testPref.unlocked.int"), 333);
  Assert.strictEqual(ps.getIntPref("testPref.locked.int"), 444);

  run_next_test();
});