2007-07-14 14:13:51 -07:00
|
|
|
// The various properties that we'll be testing
|
|
|
|
var testdata = {
|
|
|
|
missing: "fuel.fuel-test-missing",
|
|
|
|
dummy: "fuel.fuel-test",
|
|
|
|
string: "browser.active_color",
|
|
|
|
integer: "permissions.default.image",
|
|
|
|
boolean: "browser.blink_allowed"
|
|
|
|
};
|
|
|
|
|
|
|
|
function test() {
|
2010-05-23 12:26:15 -07:00
|
|
|
// test getting nonexistent values
|
2007-07-14 14:13:51 -07:00
|
|
|
var itemValue = Application.prefs.getValue(testdata.missing, "default");
|
2010-05-23 12:26:15 -07:00
|
|
|
is(itemValue, "default", "Check 'Application.prefs.getValue' for nonexistent item");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2010-05-23 12:26:15 -07:00
|
|
|
is(Application.prefs.get(testdata.missing), null, "Check 'Application.prefs.get' for nonexistent item");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test setting and getting a value
|
|
|
|
Application.prefs.setValue(testdata.dummy, "dummy");
|
|
|
|
itemValue = Application.prefs.getValue(testdata.dummy, "default");
|
|
|
|
is(itemValue, "dummy", "Check 'Application.prefs.getValue' for existing item");
|
|
|
|
|
|
|
|
// test for overwriting an existing value
|
|
|
|
Application.prefs.setValue(testdata.dummy, "smarty");
|
|
|
|
itemValue = Application.prefs.getValue(testdata.dummy, "default");
|
|
|
|
is(itemValue, "smarty", "Check 'Application.prefs.getValue' for overwritten item");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test setting and getting a value
|
|
|
|
Application.prefs.get(testdata.dummy).value = "dummy2";
|
|
|
|
itemValue = Application.prefs.get(testdata.dummy).value;
|
|
|
|
is(itemValue, "dummy2", "Check 'Application.prefs.get().value' for existing item");
|
|
|
|
|
|
|
|
// test resetting a pref [since there is no default value, the pref should disappear]
|
|
|
|
Application.prefs.get(testdata.dummy).reset();
|
2008-03-05 18:27:59 -08:00
|
|
|
itemValue = Application.prefs.getValue(testdata.dummy, "default");
|
2007-07-14 14:13:51 -07:00
|
|
|
is(itemValue, "default", "Check 'Application.prefs.getValue' for reset pref");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test to see if a non-existant property exists
|
2010-04-08 20:58:17 -07:00
|
|
|
ok(!Application.prefs.has(testdata.dummy), "Check non-existant property for existence");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// PREF: string browser.active_color == #EE0000
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test to see if an existing string property exists
|
2010-04-08 20:58:17 -07:00
|
|
|
ok(Application.prefs.has(testdata.string), "Check existing string property for existence");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test accessing a non-existant string property
|
|
|
|
var val = Application.prefs.getValue(testdata.dummy, "default");
|
|
|
|
is(val, "default", "Check non-existant string property for expected value");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test accessing an existing string property
|
|
|
|
var val = Application.prefs.getValue(testdata.string, "default");
|
|
|
|
is(val, "#EE0000", "Check existing string property for expected value");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test manipulating an existing string property
|
|
|
|
Application.prefs.setValue(testdata.string, "#EF0000");
|
|
|
|
var val = Application.prefs.getValue(testdata.string, "default");
|
|
|
|
is(val, "#EF0000", "Set existing string property");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
|
|
|
// test getting the type of an existing string property
|
|
|
|
var type = Application.prefs.get(testdata.string).type;
|
|
|
|
is(type, "String", "Check 'Application.prefs.get().type' for string pref");
|
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test resetting an existing string property
|
|
|
|
Application.prefs.get(testdata.string).reset();
|
|
|
|
var val = Application.prefs.getValue(testdata.string, "default");
|
|
|
|
is(val, "#EE0000", "Reset existing string property");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// PREF: integer permissions.default.image == 1
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test to see if an existing integer property exists
|
2010-04-08 20:58:17 -07:00
|
|
|
ok(Application.prefs.has(testdata.integer), "Check existing integer property for existence");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test accessing a non-existant integer property
|
|
|
|
var val = Application.prefs.getValue(testdata.dummy, 0);
|
|
|
|
is(val, 0, "Check non-existant integer property for expected value");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test accessing an existing integer property
|
|
|
|
var val = Application.prefs.getValue(testdata.integer, 0);
|
|
|
|
is(val, 1, "Check existing integer property for expected value");
|
|
|
|
|
|
|
|
// test manipulating an existing integer property
|
|
|
|
Application.prefs.setValue(testdata.integer, 0);
|
|
|
|
var val = Application.prefs.getValue(testdata.integer, 1);
|
|
|
|
is(val, 0, "Set existing integer property");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
|
|
|
// test getting the type of an existing integer property
|
|
|
|
var type = Application.prefs.get(testdata.integer).type;
|
|
|
|
is(type, "Number", "Check 'Application.prefs.get().type' for integer pref");
|
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test resetting an existing integer property
|
|
|
|
Application.prefs.get(testdata.integer).reset();
|
|
|
|
var val = Application.prefs.getValue(testdata.integer, 0);
|
|
|
|
is(val, 1, "Reset existing integer property");
|
|
|
|
|
|
|
|
// PREF: boolean browser.blink_allowed == true
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test to see if an existing boolean property exists
|
2010-04-08 20:58:17 -07:00
|
|
|
ok(Application.prefs.has(testdata.boolean), "Check existing boolean property for existence");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test accessing a non-existant boolean property
|
|
|
|
var val = Application.prefs.getValue(testdata.dummy, true);
|
|
|
|
ok(val, "Check non-existant boolean property for expected value");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test accessing an existing boolean property
|
|
|
|
var val = Application.prefs.getValue(testdata.boolean, false);
|
|
|
|
ok(val, "Check existing boolean property for expected value");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test manipulating an existing boolean property
|
|
|
|
Application.prefs.setValue(testdata.boolean, false);
|
|
|
|
var val = Application.prefs.getValue(testdata.boolean, true);
|
|
|
|
ok(!val, "Set existing boolean property");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
|
|
|
// test getting the type of an existing boolean property
|
|
|
|
var type = Application.prefs.get(testdata.boolean).type;
|
|
|
|
is(type, "Boolean", "Check 'Application.prefs.get().type' for boolean pref");
|
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test resetting an existing boolean property
|
|
|
|
Application.prefs.get(testdata.boolean).reset();
|
|
|
|
var val = Application.prefs.getValue(testdata.boolean, false);
|
|
|
|
ok(val, "Reset existing string property for expected value");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test getting all preferences
|
|
|
|
var allPrefs = Application.prefs.all;
|
|
|
|
ok(allPrefs.length >= 800, "Check 'Application.prefs.all' for the right number of preferences");
|
2007-08-03 12:44:17 -07:00
|
|
|
ok(allPrefs[0].name.length > 0, "Check 'Application.prefs.all' for a valid name in the starting preference");
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
// test the value of the preference root
|
|
|
|
is(Application.prefs.root, "", "Check the Application preference root");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test for user changed preferences
|
|
|
|
ok(Application.prefs.get("browser.shell.checkDefaultBrowser").modified, "A single preference is marked as modified.");
|
|
|
|
ok(!Application.prefs.get(testdata.string).modified, "A single preference is marked as not modified.");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// test for a locked preference
|
|
|
|
var pref = Application.prefs.get(testdata.string);
|
|
|
|
ok(!pref.locked, "A single preference should not be locked.");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
pref.locked = true;
|
|
|
|
ok(pref.locked, "A single preference should be locked.");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
try {
|
|
|
|
prev.value = "test value";
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2010-01-24 05:58:31 -08:00
|
|
|
ok(false, "A locked preference could be modified.");
|
2007-07-14 14:13:51 -07:00
|
|
|
} catch(e){
|
|
|
|
ok(true, "A locked preference should not be able to be modified.");
|
|
|
|
}
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
pref.locked = false;
|
2010-01-24 05:58:31 -08:00
|
|
|
ok(!pref.locked, "A single preference is unlocked.");
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2010-06-24 15:01:27 -07:00
|
|
|
// Preference events tests disabled until bug 533290 is fixed
|
|
|
|
return;
|
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
// check for change event when setting a value
|
|
|
|
waitForExplicitFinish();
|
|
|
|
Application.prefs.events.addListener("change", onPrefChange);
|
|
|
|
Application.prefs.setValue("fuel.fuel-test", "change event");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onPrefChange(evt) {
|
2010-01-24 05:58:31 -08:00
|
|
|
is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event");
|
2007-07-14 14:13:51 -07:00
|
|
|
Application.prefs.events.removeListener("change", onPrefChange);
|
|
|
|
|
2009-01-15 10:47:55 -08:00
|
|
|
// We are removing the old listener after adding the new listener so we can test that
|
|
|
|
// removing a listener does not remove all listeners
|
|
|
|
Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChangeDummy);
|
2007-07-14 14:13:51 -07:00
|
|
|
Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
|
2009-01-15 10:47:55 -08:00
|
|
|
Application.prefs.get("fuel.fuel-test").events.removeListener("change", onPrefChangeDummy);
|
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
Application.prefs.setValue("fuel.fuel-test", "change event2");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onPrefChange2(evt) {
|
2010-01-24 05:58:31 -08:00
|
|
|
is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event for a single preference");
|
2007-07-14 14:13:51 -07:00
|
|
|
Application.prefs.events.removeListener("change", onPrefChange2);
|
2008-03-05 18:27:59 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
finish();
|
|
|
|
}
|
2009-01-15 10:47:55 -08:00
|
|
|
|
|
|
|
function onPrefChangeDummy(evt) { }
|