Files
tubestation/modules/libpref/test/unit/test_defaultValues.js
Nicholas Nethercote 2c805ac89f Bug 1414096 (attempt 2) - Remove support for nsISupportsString values in nsPrefBranch::{get,set}ComplexValue(). r=florian.
Bug 1345294 introduced nsPrefBranch::{get,set}StringPref(), which allowed the
getting of utf8 strings from prefs, which previously required using
nsISupportsString with {get,set}ComplexValue. That bug also converted most
uses.

This patch finishes the job.

- It removes the nsISupportsString support.

- It converts existing code that relied on the nsISupportsString.

- It removes the lint that was set up to detect such uses of nsISupportsString.
2017-11-10 09:07:48 +11:00

58 lines
2.4 KiB
JavaScript

/* 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.string";
do_check_throws(function() { ps.getCharPref(prefName); },
Cr.NS_ERROR_UNEXPECTED);
strictEqual(ps.getStringPref(prefName, ""), "");
strictEqual(ps.getStringPref(prefName, "éèçàê€"), "éèçàê€");
ps.setStringPref(prefName, "éèçàê€");
strictEqual(ps.getStringPref(prefName), "éèçàê€");
strictEqual(ps.getStringPref(prefName, "string"), "éèçàê€");
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);
}