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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/licenses/publicdomain/ */ |
michael@0 | 3 | |
michael@0 | 4 | function run_test() { |
michael@0 | 5 | const Cc = Components.classes; |
michael@0 | 6 | const Ci = Components.interfaces; |
michael@0 | 7 | const Cr = Components.results; |
michael@0 | 8 | const PREF_NAME = "testPref"; |
michael@0 | 9 | |
michael@0 | 10 | var ps = Cc["@mozilla.org/preferences-service;1"] |
michael@0 | 11 | .getService(Ci.nsIPrefService); |
michael@0 | 12 | var prefs = ps.getDefaultBranch(null); |
michael@0 | 13 | var userprefs = ps.getBranch(null); |
michael@0 | 14 | |
michael@0 | 15 | /* First, test to make sure we can parse a float from a string properly. */ |
michael@0 | 16 | prefs.setCharPref(PREF_NAME, "9.674"); |
michael@0 | 17 | prefs.lockPref(PREF_NAME); |
michael@0 | 18 | var myFloat = 9.674; |
michael@0 | 19 | var fudge = 0.001; |
michael@0 | 20 | var floatPref = userprefs.getFloatPref(PREF_NAME); |
michael@0 | 21 | do_check_true(myFloat+fudge >= floatPref); |
michael@0 | 22 | do_check_true(myFloat-fudge <= floatPref); |
michael@0 | 23 | |
michael@0 | 24 | /* Now test some failure conditions. */ |
michael@0 | 25 | prefs.unlockPref(PREF_NAME); |
michael@0 | 26 | prefs.setCharPref(PREF_NAME, ""); |
michael@0 | 27 | prefs.lockPref(PREF_NAME); |
michael@0 | 28 | do_check_throws(function() { |
michael@0 | 29 | userprefs.getFloatPref(PREF_NAME); |
michael@0 | 30 | }, Cr.NS_ERROR_ILLEGAL_VALUE); |
michael@0 | 31 | |
michael@0 | 32 | prefs.unlockPref(PREF_NAME); |
michael@0 | 33 | prefs.setCharPref(PREF_NAME, "18.0a1"); |
michael@0 | 34 | prefs.lockPref(PREF_NAME); |
michael@0 | 35 | |
michael@0 | 36 | do_check_throws(function() { |
michael@0 | 37 | userprefs.getFloatPref(PREF_NAME); |
michael@0 | 38 | }, Cr.NS_ERROR_ILLEGAL_VALUE); |
michael@0 | 39 | |
michael@0 | 40 | prefs.unlockPref(PREF_NAME); |
michael@0 | 41 | prefs.setCharPref(PREF_NAME, "09.25.2012"); |
michael@0 | 42 | prefs.lockPref(PREF_NAME); |
michael@0 | 43 | |
michael@0 | 44 | do_check_throws(function() { |
michael@0 | 45 | userprefs.getFloatPref(PREF_NAME); |
michael@0 | 46 | }, Cr.NS_ERROR_ILLEGAL_VALUE); |
michael@0 | 47 | |
michael@0 | 48 | prefs.unlockPref(PREF_NAME); |
michael@0 | 49 | prefs.setCharPref(PREF_NAME, "aString"); |
michael@0 | 50 | prefs.lockPref(PREF_NAME); |
michael@0 | 51 | |
michael@0 | 52 | do_check_throws(function() { |
michael@0 | 53 | userprefs.getFloatPref(PREF_NAME); |
michael@0 | 54 | }, Cr.NS_ERROR_ILLEGAL_VALUE); |
michael@0 | 55 | } |