add_test(function test_set_null_pref() { try {
Preferences.set("test_set_null_pref", null); // We expect this to throw, so the test is designed to fail if it doesn't. Assert.ok(false);
} catch (ex) {}
run_next_test();
});
add_test(function test_set_undefined_pref() { try {
Preferences.set("test_set_undefined_pref"); // We expect this to throw, so the test is designed to fail if it doesn't. Assert.ok(false);
} catch (ex) {}
run_next_test();
});
add_test(function test_set_unsupported_pref() { try {
Preferences.set("test_set_unsupported_pref", []); // We expect this to throw, so the test is designed to fail if it doesn't. Assert.ok(false);
} catch (ex) {}
run_next_test();
});
// Make sure that we can get a string pref that we didn't set ourselves.
add_test(function test_get_string_pref() {
Services.prefs.setCharPref("test_get_string_pref", "a normal string"); Assert.equal(Preferences.get("test_get_string_pref"), "a normal string");
// Non-integer values get converted to integers.
Preferences.set("test_set_get_number_pref", 3.14159); Assert.equal(Preferences.get("test_set_get_number_pref"), 3);
// Values outside the range -(2^31-1) to 2^31-1 overflow. try {
Preferences.set("test_set_get_number_pref", Math.pow(2, 31)); // We expect this to throw, so the test is designed to fail if it doesn't. Assert.ok(false);
} catch (ex) {}
// Make sure the module doesn't throw an exception when asked to reset // a nonexistent pref.
add_test(function test_reset_nonexistent_pref() {
Preferences.reset("test_reset_nonexistent_pref");
run_next_test();
});
// Make sure the module doesn't throw an exception when asked to reset // a nonexistent pref branch.
add_test(function test_reset_nonexistent_pref_branch() {
Preferences.resetBranch("test_reset_nonexistent_pref_branch.");
run_next_test();
});
add_test(function test_observe_prefs_function() {
let observed = false;
let observer = function () {
observed = !observed;
};
// This should not need to be said, but *DO NOT DISABLE THIS TEST*. // // Existing consumers of the observer API depend on the observer only // being triggered for the exact preference they are observing. This is // expecially true for consumers of the function callback variant which // passes the preference's new value but not its name.
add_test(function test_observe_exact_pref() {
let observed = false;
let observer = function () {
observed = !observed;
};
add_test(function test_isSet_pref() { // Use a pref that we know has a default value but no user-set value. // This feels dangerous; perhaps we should create some other default prefs // that we can use for testing. Assert.ok(!Preferences.isSet("toolkit.defaultChromeURI"));
Preferences.set("toolkit.defaultChromeURI", "foo"); Assert.ok(Preferences.isSet("toolkit.defaultChromeURI"));
/* add_test(function test_lock_prefs() { // Use a pref that we know has a default value. // This feels dangerous; perhaps we should create some other default prefs // that we can use for testing. do_check_false(Preferences.locked("toolkit.defaultChromeURI")); Preferences.lock("toolkit.defaultChromeURI"); do_check_true(Preferences.locked("toolkit.defaultChromeURI")); Preferences.unlock("toolkit.defaultChromeURI"); do_check_false(Preferences.locked("toolkit.defaultChromeURI"));
let val = Preferences.get("toolkit.defaultChromeURI"); Preferences.set("toolkit.defaultChromeURI", "test_lock_prefs"); do_check_eq(Preferences.get("toolkit.defaultChromeURI"), "test_lock_prefs"); Preferences.lock("toolkit.defaultChromeURI"); do_check_eq(Preferences.get("toolkit.defaultChromeURI"), val); Preferences.unlock("toolkit.defaultChromeURI"); do_check_eq(Preferences.get("toolkit.defaultChromeURI"), "test_lock_prefs");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.