Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 const Ci = Components.interfaces;
2 const Cc = Components.classes;
4 let pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
6 // This pref is chosen somewhat arbitrarily --- we just need one
7 // that's guaranteed to have a default value.
8 const kPrefName = 'intl.accept_languages'; // of type char, which we
9 // assume below
10 let initialValue = null;
12 function check_child_pref_info_eq(continuation) {
13 sendCommand(
14 'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n'+
15 // Returns concatenation "[value],[isUser]"
16 'pb.getCharPref("'+ kPrefName +'")+ "," +'+
17 'pb.prefHasUserValue("'+ kPrefName +'");',
18 function (info) {
19 let [ value, isUser ] = info.split(',');
20 do_check_eq(pb.getCharPref(kPrefName), value);
21 do_check_eq(pb.prefHasUserValue(kPrefName), isUser == "true");
22 continuation();
23 });
24 }
26 function run_test() {
27 // We finish in clean_up()
28 do_test_pending();
30 try {
31 if (pb.getCharPref('dom.ipc.processPrelaunch.enabled')) {
32 dump('WARNING: Content process may already have launched, so this test may not be meaningful.');
33 }
34 } catch(e) { }
36 initialValue = pb.getCharPref(kPrefName);
38 test_user_setting();
39 }
41 function test_user_setting() {
42 // We rely on setting this before the content process starts up.
43 // When it starts up, it should recognize this as a user pref, not
44 // a default pref.
45 pb.setCharPref(kPrefName, 'i-imaginarylanguage');
46 // NB: processing of the value-change notification in the child
47 // process triggered by the above set happens-before the remaining
48 // code here
49 check_child_pref_info_eq(function () {
50 do_check_eq(pb.prefHasUserValue(kPrefName), true);
52 test_cleared_is_default();
53 });
54 }
56 function test_cleared_is_default() {
57 pb.clearUserPref(kPrefName);
58 // NB: processing of the value-change notification in the child
59 // process triggered by the above set happens-before the remaining
60 // code here
61 check_child_pref_info_eq(function () {
62 do_check_eq(pb.prefHasUserValue(kPrefName), false);
64 clean_up();
65 });
66 }
68 function clean_up() {
69 pb.setCharPref(kPrefName, initialValue);
70 // NB: processing of the value-change notification in the child
71 // process triggered by the above set happens-before the remaining
72 // code here
73 check_child_pref_info_eq(function () {
74 do_test_finished();
75 });
76 }