browser_ApplicationPrefs.js
Go to the documentation of this file.
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 };
9 
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");
14 
15  is(Application.prefs.get(testdata.missing), null, "Check 'Application.prefs.get' for non-existing item");
16 
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");
21 
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");
26 
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");
31 
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");
36 
37  // test to see if a non-existant property exists
38  ok(!Application.prefs.has(testdata.dummy), "Check non-existant property for existance");
39 
40  // PREF: string browser.active_color == #EE0000
41 
42  // test to see if an existing string property exists
43  ok(Application.prefs.has(testdata.string), "Check existing string property for existance");
44 
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");
48 
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");
52 
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");
57 
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");
61 
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");
66 
67  // PREF: integer permissions.default.image == 1
68 
69  // test to see if an existing integer property exists
70  ok(Application.prefs.has(testdata.integer), "Check existing integer property for existance");
71 
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");
75 
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");
79 
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");
84 
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");
88 
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");
93 
94  // PREF: boolean browser.blink_allowed == true
95 
96  // test to see if an existing boolean property exists
97  ok(Application.prefs.has(testdata.boolean), "Check existing boolean property for existance");
98 
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");
102 
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");
106 
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");
111 
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");
115 
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");
120 
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");
125 
126  // test the value of the preference root
127  is(Application.prefs.root, "", "Check the Application preference root");
128 
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.");
132 
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.");
136 
137  pref.locked = true;
138  ok(pref.locked, "A single preference should be locked.");
139 
140  try {
141  prev.value = "test value";
142 
143  ok(false, "A locked preference could be modified.");
144  } catch(e){
145  ok(true, "A locked preference should not be able to be modified.");
146  }
147 
148  pref.locked = false;
149  ok(!pref.locked, "A single preference is unlocked.");
150 
151  // check for change event when setting a value
153  Application.prefs.events.addListener("change", onPrefChange);
154  Application.prefs.setValue("fuel.fuel-test", "change event");
155 }
156 
157 function onPrefChange(evt) {
158  is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event");
159  Application.prefs.events.removeListener("change", onPrefChange);
160 
161  // We are removing the old listener after adding the new listener so we can test that
162  // removing a listener does not remove all listeners
163  Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChangeDummy);
164  Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
165  Application.prefs.get("fuel.fuel-test").events.removeListener("change", onPrefChangeDummy);
166 
167  Application.prefs.setValue("fuel.fuel-test", "change event2");
168 }
169 
170 function onPrefChange2(evt) {
171  is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event for a single preference");
172  Application.prefs.events.removeListener("change", onPrefChange2);
173 
174  finish();
175 }
176 
177 function onPrefChangeDummy(evt) { }
var Application
Definition: sbAboutDRM.js:37
var pref
Definition: openLocation.js:44
function test()
waitForExplicitFinish()
this _dialogInput val(dateText)
return null
Definition: FeedWriter.js:1143
function onPrefChange2(evt)
function onPrefChangeDummy(evt)
function onPrefChange(evt)