diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-03-25 17:47:59 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-03-25 17:47:59 +0100 |
commit | 917a2c450f08ab4c934c9938319f10a1114272b4 (patch) | |
tree | 79394bdbef8c5bc90734918a9f862efaf6ec2e1a /modules/libpref/test/unit | |
parent | eb77e289bbe056b58051db0fa868e95da803aa0a (diff) | |
parent | a1ad1d835b66e9300cc011244a23aea5d660baf1 (diff) | |
download | UXP-917a2c450f08ab4c934c9938319f10a1114272b4.tar UXP-917a2c450f08ab4c934c9938319f10a1114272b4.tar.gz UXP-917a2c450f08ab4c934c9938319f10a1114272b4.tar.lz UXP-917a2c450f08ab4c934c9938319f10a1114272b4.tar.xz UXP-917a2c450f08ab4c934c9938319f10a1114272b4.zip |
Merge branch 'master' of https://github.com/MoonchildProductions/UXP
Diffstat (limited to 'modules/libpref/test/unit')
-rw-r--r-- | modules/libpref/test/unit/test_defaultValues.js | 48 | ||||
-rw-r--r-- | modules/libpref/test/unit/xpcshell.ini | 1 |
2 files changed, 49 insertions, 0 deletions
diff --git a/modules/libpref/test/unit/test_defaultValues.js b/modules/libpref/test/unit/test_defaultValues.js new file mode 100644 index 000000000..d04bcc04a --- /dev/null +++ b/modules/libpref/test/unit/test_defaultValues.js @@ -0,0 +1,48 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* Tests for providing a default value to get{Bool,Char,Float,Int}Pref */ + +function run_test() { + var ps = Cc["@mozilla.org/preferences-service;1"] + .getService(Ci.nsIPrefService) + .QueryInterface(Ci.nsIPrefBranch); + + let prefName = "test.default.values.bool"; + do_check_throws(function() { ps.getBoolPref(prefName); }, + Cr.NS_ERROR_UNEXPECTED); + strictEqual(ps.getBoolPref(prefName, false), false); + strictEqual(ps.getBoolPref(prefName, true), true); + ps.setBoolPref(prefName, true); + strictEqual(ps.getBoolPref(prefName), true); + strictEqual(ps.getBoolPref(prefName, false), true); + strictEqual(ps.getBoolPref(prefName, true), true); + + prefName = "test.default.values.char"; + do_check_throws(function() { ps.getCharPref(prefName); }, + Cr.NS_ERROR_UNEXPECTED); + strictEqual(ps.getCharPref(prefName, ""), ""); + strictEqual(ps.getCharPref(prefName, "string"), "string"); + ps.setCharPref(prefName, "foo"); + strictEqual(ps.getCharPref(prefName), "foo"); + strictEqual(ps.getCharPref(prefName, "string"), "foo"); + + prefName = "test.default.values.float"; + do_check_throws(function() { ps.getFloatPref(prefName); }, + Cr.NS_ERROR_UNEXPECTED); + strictEqual(ps.getFloatPref(prefName, 3.5), 3.5); + strictEqual(ps.getFloatPref(prefName, 0), 0); + ps.setCharPref(prefName, 1.75); + strictEqual(ps.getFloatPref(prefName), 1.75); + strictEqual(ps.getFloatPref(prefName, 3.5), 1.75); + + prefName = "test.default.values.int"; + do_check_throws(function() { ps.getIntPref(prefName); }, + Cr.NS_ERROR_UNEXPECTED); + strictEqual(ps.getIntPref(prefName, 3), 3); + strictEqual(ps.getIntPref(prefName, 0), 0); + ps.setIntPref(prefName, 42); + strictEqual(ps.getIntPref(prefName), 42); + strictEqual(ps.getIntPref(prefName, 3), 42); +} diff --git a/modules/libpref/test/unit/xpcshell.ini b/modules/libpref/test/unit/xpcshell.ini index 74c56907a..66458863f 100644 --- a/modules/libpref/test/unit/xpcshell.ini +++ b/modules/libpref/test/unit/xpcshell.ini @@ -13,6 +13,7 @@ support-files = [test_stickyprefs.js] support-files = data/testPrefSticky.js data/testPrefStickyUser.js [test_changeType.js] +[test_defaultValues.js] [test_dirtyPrefs.js] [test_extprefs.js] [test_libPrefs.js] |