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