test_defaultValues.js (2310B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* Tests for providing a default value to get{Bool,Char,Float,Int}Pref */ 6 7 function run_test() { 8 const ps = Services.prefs; 9 let prefName = "test.default.values.bool"; 10 do_check_throws(function () { 11 ps.getBoolPref(prefName); 12 }, Cr.NS_ERROR_UNEXPECTED); 13 strictEqual(ps.getBoolPref(prefName, false), false); 14 strictEqual(ps.getBoolPref(prefName, true), true); 15 ps.setBoolPref(prefName, true); 16 strictEqual(ps.getBoolPref(prefName), true); 17 strictEqual(ps.getBoolPref(prefName, false), true); 18 strictEqual(ps.getBoolPref(prefName, true), true); 19 20 prefName = "test.default.values.char"; 21 do_check_throws(function () { 22 ps.getCharPref(prefName); 23 }, Cr.NS_ERROR_UNEXPECTED); 24 strictEqual(ps.getCharPref(prefName, ""), ""); 25 strictEqual(ps.getCharPref(prefName, "string"), "string"); 26 ps.setCharPref(prefName, "foo"); 27 strictEqual(ps.getCharPref(prefName), "foo"); 28 strictEqual(ps.getCharPref(prefName, "string"), "foo"); 29 30 prefName = "test.default.values.string"; 31 do_check_throws(function () { 32 ps.getCharPref(prefName); 33 }, Cr.NS_ERROR_UNEXPECTED); 34 strictEqual(ps.getStringPref(prefName, ""), ""); 35 strictEqual(ps.getStringPref(prefName, "éèçàê€"), "éèçàê€"); 36 ps.setStringPref(prefName, "éèçàê€"); 37 strictEqual(ps.getStringPref(prefName), "éèçàê€"); 38 strictEqual(ps.getStringPref(prefName, "string"), "éèçàê€"); 39 40 prefName = "test.default.values.float"; 41 do_check_throws(function () { 42 ps.getFloatPref(prefName); 43 }, Cr.NS_ERROR_UNEXPECTED); 44 strictEqual(ps.getFloatPref(prefName, 3.5), 3.5); 45 strictEqual(ps.getFloatPref(prefName, 0), 0); 46 ps.setCharPref(prefName, 1.75); 47 strictEqual(ps.getFloatPref(prefName), 1.75); 48 strictEqual(ps.getFloatPref(prefName, 3.5), 1.75); 49 50 prefName = "test.default.values.int"; 51 do_check_throws(function () { 52 ps.getIntPref(prefName); 53 }, Cr.NS_ERROR_UNEXPECTED); 54 strictEqual(ps.getIntPref(prefName, 3), 3); 55 strictEqual(ps.getIntPref(prefName, 0), 0); 56 ps.setIntPref(prefName, 42); 57 strictEqual(ps.getIntPref(prefName), 42); 58 strictEqual(ps.getIntPref(prefName, 3), 42); 59 }