summaryrefslogtreecommitdiffstats
path: root/modules/libpref/test/unit_ipc/test_user_default_prefs.js
blob: 3307522513b4fac5f039635518dffb37c8d126be (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const pb = Services.prefs;

// This pref is chosen somewhat arbitrarily --- we just need one
// that's guaranteed to have a default value.
const kPrefName = "intl.accept_languages"; // of type char, which we
// assume below
var initialValue = null;

function check_child_pref_info_eq(continuation) {
  sendCommand(
    'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n' +
      // Returns concatenation "[value],[isUser]"
      'pb.getCharPref("' +
      kPrefName +
      '")+ "," +' +
      'pb.prefHasUserValue("' +
      kPrefName +
      '");',
    function (info) {
      let [value, isUser] = info.split(",");
      Assert.equal(pb.getCharPref(kPrefName), value);
      Assert.equal(pb.prefHasUserValue(kPrefName), isUser == "true");
      continuation();
    }
  );
}

function run_test() {
  // We finish in clean_up()
  do_test_pending();

  initialValue = pb.getCharPref(kPrefName);

  test_user_setting();
}

function test_user_setting() {
  // We rely on setting this before the content process starts up.
  // When it starts up, it should recognize this as a user pref, not
  // a default pref.
  pb.setCharPref(kPrefName, "i-imaginarylanguage");
  // NB: processing of the value-change notification in the child
  // process triggered by the above set happens-before the remaining
  // code here
  check_child_pref_info_eq(function () {
    Assert.equal(pb.prefHasUserValue(kPrefName), true);

    test_cleared_is_default();
  });
}

function test_cleared_is_default() {
  pb.clearUserPref(kPrefName);
  // NB: processing of the value-change notification in the child
  // process triggered by the above set happens-before the remaining
  // code here
  check_child_pref_info_eq(function () {
    Assert.equal(pb.prefHasUserValue(kPrefName), false);

    clean_up();
  });
}

function clean_up() {
  pb.setCharPref(kPrefName, initialValue);
  // NB: processing of the value-change notification in the child
  // process triggered by the above set happens-before the remaining
  // code here
  check_child_pref_info_eq(function () {
    do_test_finished();
  });
}