summaryrefslogtreecommitdiffstats
path: root/modules/libpref/test/unit/test_defaultValues.js
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-03-29 16:04:01 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-03-29 16:04:01 +0100
commit88083f8c683c18f4de68a20c863a82a9da65db8f (patch)
tree926656892d9d80260da02ea8ea71031b140c51df /modules/libpref/test/unit/test_defaultValues.js
parentf999f544aad04069b03704d994a99352263f600b (diff)
parent843e4ceffd6ce21a6e6db37419335eafdc543e18 (diff)
downloadUXP-88083f8c683c18f4de68a20c863a82a9da65db8f.tar
UXP-88083f8c683c18f4de68a20c863a82a9da65db8f.tar.gz
UXP-88083f8c683c18f4de68a20c863a82a9da65db8f.tar.lz
UXP-88083f8c683c18f4de68a20c863a82a9da65db8f.tar.xz
UXP-88083f8c683c18f4de68a20c863a82a9da65db8f.zip
Merge branch 'master' into Sync-weave
Diffstat (limited to 'modules/libpref/test/unit/test_defaultValues.js')
-rw-r--r--modules/libpref/test/unit/test_defaultValues.js48
1 files changed, 48 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);
+}