modules/libpref/test/unit_ipc/test_user_default_prefs.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/libpref/test/unit_ipc/test_user_default_prefs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +const Ci = Components.interfaces;
     1.5 +const Cc = Components.classes;
     1.6 +
     1.7 +let pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
     1.8 +
     1.9 +// This pref is chosen somewhat arbitrarily --- we just need one
    1.10 +// that's guaranteed to have a default value.
    1.11 +const kPrefName = 'intl.accept_languages'; // of type char, which we
    1.12 +                                           // assume below
    1.13 +let initialValue = null;
    1.14 +
    1.15 +function check_child_pref_info_eq(continuation) {
    1.16 +    sendCommand(
    1.17 +        'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n'+
    1.18 +        // Returns concatenation "[value],[isUser]"
    1.19 +        'pb.getCharPref("'+ kPrefName +'")+ "," +'+
    1.20 +        'pb.prefHasUserValue("'+ kPrefName +'");',
    1.21 +        function (info) {
    1.22 +            let [ value, isUser ] = info.split(',');
    1.23 +            do_check_eq(pb.getCharPref(kPrefName), value);
    1.24 +            do_check_eq(pb.prefHasUserValue(kPrefName), isUser == "true");
    1.25 +            continuation();
    1.26 +        });
    1.27 +}
    1.28 +
    1.29 +function run_test() {
    1.30 +    // We finish in clean_up()
    1.31 +    do_test_pending();
    1.32 +
    1.33 +    try {
    1.34 +        if (pb.getCharPref('dom.ipc.processPrelaunch.enabled')) {
    1.35 +            dump('WARNING: Content process may already have launched, so this test may not be meaningful.');
    1.36 +        }
    1.37 +    } catch(e) { }
    1.38 +
    1.39 +    initialValue = pb.getCharPref(kPrefName);
    1.40 +
    1.41 +    test_user_setting();
    1.42 +}
    1.43 +
    1.44 +function test_user_setting() {
    1.45 +    // We rely on setting this before the content process starts up.
    1.46 +    // When it starts up, it should recognize this as a user pref, not
    1.47 +    // a default pref.
    1.48 +    pb.setCharPref(kPrefName, 'i-imaginarylanguage');
    1.49 +    // NB: processing of the value-change notification in the child
    1.50 +    // process triggered by the above set happens-before the remaining
    1.51 +    // code here
    1.52 +    check_child_pref_info_eq(function () {
    1.53 +            do_check_eq(pb.prefHasUserValue(kPrefName), true);
    1.54 +
    1.55 +            test_cleared_is_default();
    1.56 +        });
    1.57 +}
    1.58 +
    1.59 +function test_cleared_is_default() {
    1.60 +    pb.clearUserPref(kPrefName);
    1.61 +    // NB: processing of the value-change notification in the child
    1.62 +    // process triggered by the above set happens-before the remaining
    1.63 +    // code here
    1.64 +    check_child_pref_info_eq(function () {
    1.65 +            do_check_eq(pb.prefHasUserValue(kPrefName), false);
    1.66 +
    1.67 +            clean_up();
    1.68 +        });
    1.69 +}
    1.70 +
    1.71 +function clean_up() {
    1.72 +    pb.setCharPref(kPrefName, initialValue);
    1.73 +    // NB: processing of the value-change notification in the child
    1.74 +    // process triggered by the above set happens-before the remaining
    1.75 +    // code here
    1.76 +    check_child_pref_info_eq(function () {
    1.77 +            do_test_finished();
    1.78 +        });
    1.79 +}
    1.80 \ No newline at end of file

mercurial