michael@0: // The various properties that we'll be testing michael@0: var testdata = { michael@0: missing: "fuel.fuel-test-missing", michael@0: dummy: "fuel.fuel-test", michael@0: string: "browser.active_color", michael@0: integer: "permissions.default.image", michael@0: boolean: "browser.underline_anchors" michael@0: }; michael@0: michael@0: function test() { michael@0: // test getting nonexistent values michael@0: var itemValue = Application.prefs.getValue(testdata.missing, "default"); michael@0: is(itemValue, "default", "Check 'Application.prefs.getValue' for nonexistent item"); michael@0: michael@0: is(Application.prefs.get(testdata.missing), null, "Check 'Application.prefs.get' for nonexistent item"); michael@0: michael@0: // test setting and getting a value michael@0: Application.prefs.setValue(testdata.dummy, "dummy"); michael@0: itemValue = Application.prefs.getValue(testdata.dummy, "default"); michael@0: is(itemValue, "dummy", "Check 'Application.prefs.getValue' for existing item"); michael@0: michael@0: // test for overwriting an existing value michael@0: Application.prefs.setValue(testdata.dummy, "smarty"); michael@0: itemValue = Application.prefs.getValue(testdata.dummy, "default"); michael@0: is(itemValue, "smarty", "Check 'Application.prefs.getValue' for overwritten item"); michael@0: michael@0: // test setting and getting a value michael@0: Application.prefs.get(testdata.dummy).value = "dummy2"; michael@0: itemValue = Application.prefs.get(testdata.dummy).value; michael@0: is(itemValue, "dummy2", "Check 'Application.prefs.get().value' for existing item"); michael@0: michael@0: // test resetting a pref [since there is no default value, the pref should disappear] michael@0: Application.prefs.get(testdata.dummy).reset(); michael@0: itemValue = Application.prefs.getValue(testdata.dummy, "default"); michael@0: is(itemValue, "default", "Check 'Application.prefs.getValue' for reset pref"); michael@0: michael@0: // test to see if a non-existant property exists michael@0: ok(!Application.prefs.has(testdata.dummy), "Check non-existant property for existence"); michael@0: michael@0: // PREF: string browser.active_color == #EE0000 michael@0: michael@0: // test to see if an existing string property exists michael@0: ok(Application.prefs.has(testdata.string), "Check existing string property for existence"); michael@0: michael@0: // test accessing a non-existant string property michael@0: var val = Application.prefs.getValue(testdata.dummy, "default"); michael@0: is(val, "default", "Check non-existant string property for expected value"); michael@0: michael@0: // test accessing an existing string property michael@0: var val = Application.prefs.getValue(testdata.string, "default"); michael@0: is(val, "#EE0000", "Check existing string property for expected value"); michael@0: michael@0: // test manipulating an existing string property michael@0: Application.prefs.setValue(testdata.string, "#EF0000"); michael@0: var val = Application.prefs.getValue(testdata.string, "default"); michael@0: is(val, "#EF0000", "Set existing string property"); michael@0: michael@0: // test getting the type of an existing string property michael@0: var type = Application.prefs.get(testdata.string).type; michael@0: is(type, "String", "Check 'Application.prefs.get().type' for string pref"); michael@0: michael@0: // test resetting an existing string property michael@0: Application.prefs.get(testdata.string).reset(); michael@0: var val = Application.prefs.getValue(testdata.string, "default"); michael@0: is(val, "#EE0000", "Reset existing string property"); michael@0: michael@0: // PREF: integer permissions.default.image == 1 michael@0: michael@0: // test to see if an existing integer property exists michael@0: ok(Application.prefs.has(testdata.integer), "Check existing integer property for existence"); michael@0: michael@0: // test accessing a non-existant integer property michael@0: var val = Application.prefs.getValue(testdata.dummy, 0); michael@0: is(val, 0, "Check non-existant integer property for expected value"); michael@0: michael@0: // test accessing an existing integer property michael@0: var val = Application.prefs.getValue(testdata.integer, 0); michael@0: is(val, 1, "Check existing integer property for expected value"); michael@0: michael@0: // test manipulating an existing integer property michael@0: Application.prefs.setValue(testdata.integer, 0); michael@0: var val = Application.prefs.getValue(testdata.integer, 1); michael@0: is(val, 0, "Set existing integer property"); michael@0: michael@0: // test getting the type of an existing integer property michael@0: var type = Application.prefs.get(testdata.integer).type; michael@0: is(type, "Number", "Check 'Application.prefs.get().type' for integer pref"); michael@0: michael@0: // test resetting an existing integer property michael@0: Application.prefs.get(testdata.integer).reset(); michael@0: var val = Application.prefs.getValue(testdata.integer, 0); michael@0: is(val, 1, "Reset existing integer property"); michael@0: michael@0: // PREF: boolean browser.underline_anchors == true michael@0: michael@0: // test to see if an existing boolean property exists michael@0: ok(Application.prefs.has(testdata.boolean), "Check existing boolean property for existence"); michael@0: michael@0: // test accessing a non-existant boolean property michael@0: var val = Application.prefs.getValue(testdata.dummy, true); michael@0: ok(val, "Check non-existant boolean property for expected value"); michael@0: michael@0: // test accessing an existing boolean property michael@0: var val = Application.prefs.getValue(testdata.boolean, false); michael@0: ok(val, "Check existing boolean property for expected value"); michael@0: michael@0: // test manipulating an existing boolean property michael@0: Application.prefs.setValue(testdata.boolean, false); michael@0: var val = Application.prefs.getValue(testdata.boolean, true); michael@0: ok(!val, "Set existing boolean property"); michael@0: michael@0: // test getting the type of an existing boolean property michael@0: var type = Application.prefs.get(testdata.boolean).type; michael@0: is(type, "Boolean", "Check 'Application.prefs.get().type' for boolean pref"); michael@0: michael@0: // test resetting an existing boolean property michael@0: Application.prefs.get(testdata.boolean).reset(); michael@0: var val = Application.prefs.getValue(testdata.boolean, false); michael@0: ok(val, "Reset existing string property for expected value"); michael@0: michael@0: // test getting all preferences michael@0: var allPrefs = Application.prefs.all; michael@0: ok(allPrefs.length >= 800, "Check 'Application.prefs.all' for the right number of preferences"); michael@0: ok(allPrefs[0].name.length > 0, "Check 'Application.prefs.all' for a valid name in the starting preference"); michael@0: michael@0: // test the value of the preference root michael@0: is(Application.prefs.root, "", "Check the Application preference root"); michael@0: michael@0: // test for user changed preferences michael@0: ok(Application.prefs.get("browser.shell.checkDefaultBrowser").modified, "A single preference is marked as modified."); michael@0: ok(!Application.prefs.get(testdata.string).modified, "A single preference is marked as not modified."); michael@0: michael@0: // test for a locked preference michael@0: var pref = Application.prefs.get(testdata.string); michael@0: ok(!pref.locked, "A single preference should not be locked."); michael@0: michael@0: pref.locked = true; michael@0: ok(pref.locked, "A single preference should be locked."); michael@0: michael@0: try { michael@0: prev.value = "test value"; michael@0: michael@0: ok(false, "A locked preference could be modified."); michael@0: } catch(e){ michael@0: ok(true, "A locked preference should not be able to be modified."); michael@0: } michael@0: michael@0: pref.locked = false; michael@0: ok(!pref.locked, "A single preference is unlocked."); michael@0: michael@0: // check for change event when setting a value michael@0: waitForExplicitFinish(); michael@0: Application.prefs.events.addListener("change", onPrefChange); michael@0: Application.prefs.setValue("fuel.fuel-test", "change event"); michael@0: } michael@0: michael@0: function onPrefChange(evt) { michael@0: is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event"); michael@0: Application.prefs.events.removeListener("change", onPrefChange); michael@0: michael@0: // We are removing the old listener after adding the new listener so we can test that michael@0: // removing a listener does not remove all listeners michael@0: Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChangeDummy); michael@0: Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2); michael@0: Application.prefs.get("fuel.fuel-test").events.removeListener("change", onPrefChangeDummy); michael@0: michael@0: Application.prefs.setValue("fuel.fuel-test", "change event2"); michael@0: } michael@0: michael@0: function onPrefChange2(evt) { michael@0: is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event for a single preference"); michael@0: Application.prefs.events.removeListener("change", onPrefChange2); michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: function onPrefChangeDummy(evt) { michael@0: ok(false, "onPrefChangeDummy shouldn't be invoked!"); michael@0: }