1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/libpref/test/unit/test_bug790374.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/licenses/publicdomain/ */ 1.6 + 1.7 +function run_test() { 1.8 + const Cc = Components.classes; 1.9 + const Ci = Components.interfaces; 1.10 + const Cr = Components.results; 1.11 + const PREF_NAME = "testPref"; 1.12 + 1.13 + var ps = Cc["@mozilla.org/preferences-service;1"] 1.14 + .getService(Ci.nsIPrefService); 1.15 + var prefs = ps.getDefaultBranch(null); 1.16 + var userprefs = ps.getBranch(null); 1.17 + 1.18 + /* First, test to make sure we can parse a float from a string properly. */ 1.19 + prefs.setCharPref(PREF_NAME, "9.674"); 1.20 + prefs.lockPref(PREF_NAME); 1.21 + var myFloat = 9.674; 1.22 + var fudge = 0.001; 1.23 + var floatPref = userprefs.getFloatPref(PREF_NAME); 1.24 + do_check_true(myFloat+fudge >= floatPref); 1.25 + do_check_true(myFloat-fudge <= floatPref); 1.26 + 1.27 + /* Now test some failure conditions. */ 1.28 + prefs.unlockPref(PREF_NAME); 1.29 + prefs.setCharPref(PREF_NAME, ""); 1.30 + prefs.lockPref(PREF_NAME); 1.31 + do_check_throws(function() { 1.32 + userprefs.getFloatPref(PREF_NAME); 1.33 + }, Cr.NS_ERROR_ILLEGAL_VALUE); 1.34 + 1.35 + prefs.unlockPref(PREF_NAME); 1.36 + prefs.setCharPref(PREF_NAME, "18.0a1"); 1.37 + prefs.lockPref(PREF_NAME); 1.38 + 1.39 + do_check_throws(function() { 1.40 + userprefs.getFloatPref(PREF_NAME); 1.41 + }, Cr.NS_ERROR_ILLEGAL_VALUE); 1.42 + 1.43 + prefs.unlockPref(PREF_NAME); 1.44 + prefs.setCharPref(PREF_NAME, "09.25.2012"); 1.45 + prefs.lockPref(PREF_NAME); 1.46 + 1.47 + do_check_throws(function() { 1.48 + userprefs.getFloatPref(PREF_NAME); 1.49 + }, Cr.NS_ERROR_ILLEGAL_VALUE); 1.50 + 1.51 + prefs.unlockPref(PREF_NAME); 1.52 + prefs.setCharPref(PREF_NAME, "aString"); 1.53 + prefs.lockPref(PREF_NAME); 1.54 + 1.55 + do_check_throws(function() { 1.56 + userprefs.getFloatPref(PREF_NAME); 1.57 + }, Cr.NS_ERROR_ILLEGAL_VALUE); 1.58 +}