Bug 463982 - Drop configure support for cairo-mac widget toolkit, r=ted
[wine-gecko.git] / browser / fuel / test / browser_ApplicationPrefs.js
blob42d5e7a72f4035e565f179fa1f22fec8387b2652
1 // The various properties that we'll be testing
2 var testdata = {
3 missing: "fuel.fuel-test-missing",
4 dummy: "fuel.fuel-test",
5 string: "browser.active_color",
6 integer: "permissions.default.image",
7 boolean: "browser.blink_allowed"
8 };
10 function test() {
11 // test getting non-existing values
12 var itemValue = Application.prefs.getValue(testdata.missing, "default");
13 is(itemValue, "default", "Check 'Application.prefs.getValue' for non-existing item");
15 is(Application.prefs.get(testdata.missing), null, "Check 'Application.prefs.get' for non-existing item");
17 // test setting and getting a value
18 Application.prefs.setValue(testdata.dummy, "dummy");
19 itemValue = Application.prefs.getValue(testdata.dummy, "default");
20 is(itemValue, "dummy", "Check 'Application.prefs.getValue' for existing item");
22 // test for overwriting an existing value
23 Application.prefs.setValue(testdata.dummy, "smarty");
24 itemValue = Application.prefs.getValue(testdata.dummy, "default");
25 is(itemValue, "smarty", "Check 'Application.prefs.getValue' for overwritten item");
27 // test setting and getting a value
28 Application.prefs.get(testdata.dummy).value = "dummy2";
29 itemValue = Application.prefs.get(testdata.dummy).value;
30 is(itemValue, "dummy2", "Check 'Application.prefs.get().value' for existing item");
32 // test resetting a pref [since there is no default value, the pref should disappear]
33 Application.prefs.get(testdata.dummy).reset();
34 itemValue = Application.prefs.getValue(testdata.dummy, "default");
35 is(itemValue, "default", "Check 'Application.prefs.getValue' for reset pref");
37 // test to see if a non-existant property exists
38 ok(!Application.prefs.has(testdata.dummy), "Check non-existant property for existance");
40 // PREF: string browser.active_color == #EE0000
42 // test to see if an existing string property exists
43 ok(Application.prefs.has(testdata.string), "Check existing string property for existance");
45 // test accessing a non-existant string property
46 var val = Application.prefs.getValue(testdata.dummy, "default");
47 is(val, "default", "Check non-existant string property for expected value");
49 // test accessing an existing string property
50 var val = Application.prefs.getValue(testdata.string, "default");
51 is(val, "#EE0000", "Check existing string property for expected value");
53 // test manipulating an existing string property
54 Application.prefs.setValue(testdata.string, "#EF0000");
55 var val = Application.prefs.getValue(testdata.string, "default");
56 is(val, "#EF0000", "Set existing string property");
58 // test getting the type of an existing string property
59 var type = Application.prefs.get(testdata.string).type;
60 is(type, "String", "Check 'Application.prefs.get().type' for string pref");
62 // test resetting an existing string property
63 Application.prefs.get(testdata.string).reset();
64 var val = Application.prefs.getValue(testdata.string, "default");
65 is(val, "#EE0000", "Reset existing string property");
67 // PREF: integer permissions.default.image == 1
69 // test to see if an existing integer property exists
70 ok(Application.prefs.has(testdata.integer), "Check existing integer property for existance");
72 // test accessing a non-existant integer property
73 var val = Application.prefs.getValue(testdata.dummy, 0);
74 is(val, 0, "Check non-existant integer property for expected value");
76 // test accessing an existing integer property
77 var val = Application.prefs.getValue(testdata.integer, 0);
78 is(val, 1, "Check existing integer property for expected value");
80 // test manipulating an existing integer property
81 Application.prefs.setValue(testdata.integer, 0);
82 var val = Application.prefs.getValue(testdata.integer, 1);
83 is(val, 0, "Set existing integer property");
85 // test getting the type of an existing integer property
86 var type = Application.prefs.get(testdata.integer).type;
87 is(type, "Number", "Check 'Application.prefs.get().type' for integer pref");
89 // test resetting an existing integer property
90 Application.prefs.get(testdata.integer).reset();
91 var val = Application.prefs.getValue(testdata.integer, 0);
92 is(val, 1, "Reset existing integer property");
94 // PREF: boolean browser.blink_allowed == true
96 // test to see if an existing boolean property exists
97 ok(Application.prefs.has(testdata.boolean), "Check existing boolean property for existance");
99 // test accessing a non-existant boolean property
100 var val = Application.prefs.getValue(testdata.dummy, true);
101 ok(val, "Check non-existant boolean property for expected value");
103 // test accessing an existing boolean property
104 var val = Application.prefs.getValue(testdata.boolean, false);
105 ok(val, "Check existing boolean property for expected value");
107 // test manipulating an existing boolean property
108 Application.prefs.setValue(testdata.boolean, false);
109 var val = Application.prefs.getValue(testdata.boolean, true);
110 ok(!val, "Set existing boolean property");
112 // test getting the type of an existing boolean property
113 var type = Application.prefs.get(testdata.boolean).type;
114 is(type, "Boolean", "Check 'Application.prefs.get().type' for boolean pref");
116 // test resetting an existing boolean property
117 Application.prefs.get(testdata.boolean).reset();
118 var val = Application.prefs.getValue(testdata.boolean, false);
119 ok(val, "Reset existing string property for expected value");
121 // test getting all preferences
122 var allPrefs = Application.prefs.all;
123 ok(allPrefs.length >= 800, "Check 'Application.prefs.all' for the right number of preferences");
124 ok(allPrefs[0].name.length > 0, "Check 'Application.prefs.all' for a valid name in the starting preference");
126 // test the value of the preference root
127 is(Application.prefs.root, "", "Check the Application preference root");
129 // test for user changed preferences
130 ok(Application.prefs.get("browser.shell.checkDefaultBrowser").modified, "A single preference is marked as modified.");
131 ok(!Application.prefs.get(testdata.string).modified, "A single preference is marked as not modified.");
133 // test for a locked preference
134 var pref = Application.prefs.get(testdata.string);
135 ok(!pref.locked, "A single preference should not be locked.");
137 pref.locked = true;
138 ok(pref.locked, "A single preference should be locked.");
140 try {
141 prev.value = "test value";
143 ok(false, "A locked preference should not be able to be modified.");
144 } catch(e){
145 ok(true, "A locked preference should not be able to be modified.");
148 pref.locked = false;
149 ok(!pref.locked, "A single preference should not be locked.");
151 // check for change event when setting a value
152 waitForExplicitFinish();
153 Application.prefs.events.addListener("change", onPrefChange);
154 Application.prefs.setValue("fuel.fuel-test", "change event");
157 function onPrefChange(evt) {
158 is(evt.data, testdata.dummy, "Check 'Application.prefs.set' fired a change event");
159 Application.prefs.events.removeListener("change", onPrefChange);
161 Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
162 Application.prefs.setValue("fuel.fuel-test", "change event2");
165 function onPrefChange2(evt) {
166 is(evt.data, testdata.dummy, "Check 'Application.prefs.set' fired a change event for a single preference");
167 Application.prefs.events.removeListener("change", onPrefChange2);
169 finish();