michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: michael@0: let pb = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); michael@0: michael@0: // This pref is chosen somewhat arbitrarily --- we just need one michael@0: // that's guaranteed to have a default value. michael@0: const kPrefName = 'intl.accept_languages'; // of type char, which we michael@0: // assume below michael@0: let initialValue = null; michael@0: michael@0: function check_child_pref_info_eq(continuation) { michael@0: sendCommand( michael@0: 'var pb = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);\n'+ michael@0: // Returns concatenation "[value],[isUser]" michael@0: 'pb.getCharPref("'+ kPrefName +'")+ "," +'+ michael@0: 'pb.prefHasUserValue("'+ kPrefName +'");', michael@0: function (info) { michael@0: let [ value, isUser ] = info.split(','); michael@0: do_check_eq(pb.getCharPref(kPrefName), value); michael@0: do_check_eq(pb.prefHasUserValue(kPrefName), isUser == "true"); michael@0: continuation(); michael@0: }); michael@0: } michael@0: michael@0: function run_test() { michael@0: // We finish in clean_up() michael@0: do_test_pending(); michael@0: michael@0: try { michael@0: if (pb.getCharPref('dom.ipc.processPrelaunch.enabled')) { michael@0: dump('WARNING: Content process may already have launched, so this test may not be meaningful.'); michael@0: } michael@0: } catch(e) { } michael@0: michael@0: initialValue = pb.getCharPref(kPrefName); michael@0: michael@0: test_user_setting(); michael@0: } michael@0: michael@0: function test_user_setting() { michael@0: // We rely on setting this before the content process starts up. michael@0: // When it starts up, it should recognize this as a user pref, not michael@0: // a default pref. michael@0: pb.setCharPref(kPrefName, 'i-imaginarylanguage'); michael@0: // NB: processing of the value-change notification in the child michael@0: // process triggered by the above set happens-before the remaining michael@0: // code here michael@0: check_child_pref_info_eq(function () { michael@0: do_check_eq(pb.prefHasUserValue(kPrefName), true); michael@0: michael@0: test_cleared_is_default(); michael@0: }); michael@0: } michael@0: michael@0: function test_cleared_is_default() { michael@0: pb.clearUserPref(kPrefName); michael@0: // NB: processing of the value-change notification in the child michael@0: // process triggered by the above set happens-before the remaining michael@0: // code here michael@0: check_child_pref_info_eq(function () { michael@0: do_check_eq(pb.prefHasUserValue(kPrefName), false); michael@0: michael@0: clean_up(); michael@0: }); michael@0: } michael@0: michael@0: function clean_up() { michael@0: pb.setCharPref(kPrefName, initialValue); michael@0: // NB: processing of the value-change notification in the child michael@0: // process triggered by the above set happens-before the remaining michael@0: // code here michael@0: check_child_pref_info_eq(function () { michael@0: do_test_finished(); michael@0: }); michael@0: }