Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // The various properties that we'll be testing |
michael@0 | 2 | var testdata = { |
michael@0 | 3 | missing: "fuel.fuel-test-missing", |
michael@0 | 4 | dummy: "fuel.fuel-test", |
michael@0 | 5 | string: "browser.active_color", |
michael@0 | 6 | integer: "permissions.default.image", |
michael@0 | 7 | boolean: "browser.underline_anchors" |
michael@0 | 8 | }; |
michael@0 | 9 | |
michael@0 | 10 | function test() { |
michael@0 | 11 | // test getting nonexistent values |
michael@0 | 12 | var itemValue = Application.prefs.getValue(testdata.missing, "default"); |
michael@0 | 13 | is(itemValue, "default", "Check 'Application.prefs.getValue' for nonexistent item"); |
michael@0 | 14 | |
michael@0 | 15 | is(Application.prefs.get(testdata.missing), null, "Check 'Application.prefs.get' for nonexistent item"); |
michael@0 | 16 | |
michael@0 | 17 | // test setting and getting a value |
michael@0 | 18 | Application.prefs.setValue(testdata.dummy, "dummy"); |
michael@0 | 19 | itemValue = Application.prefs.getValue(testdata.dummy, "default"); |
michael@0 | 20 | is(itemValue, "dummy", "Check 'Application.prefs.getValue' for existing item"); |
michael@0 | 21 | |
michael@0 | 22 | // test for overwriting an existing value |
michael@0 | 23 | Application.prefs.setValue(testdata.dummy, "smarty"); |
michael@0 | 24 | itemValue = Application.prefs.getValue(testdata.dummy, "default"); |
michael@0 | 25 | is(itemValue, "smarty", "Check 'Application.prefs.getValue' for overwritten item"); |
michael@0 | 26 | |
michael@0 | 27 | // test setting and getting a value |
michael@0 | 28 | Application.prefs.get(testdata.dummy).value = "dummy2"; |
michael@0 | 29 | itemValue = Application.prefs.get(testdata.dummy).value; |
michael@0 | 30 | is(itemValue, "dummy2", "Check 'Application.prefs.get().value' for existing item"); |
michael@0 | 31 | |
michael@0 | 32 | // test resetting a pref [since there is no default value, the pref should disappear] |
michael@0 | 33 | Application.prefs.get(testdata.dummy).reset(); |
michael@0 | 34 | itemValue = Application.prefs.getValue(testdata.dummy, "default"); |
michael@0 | 35 | is(itemValue, "default", "Check 'Application.prefs.getValue' for reset pref"); |
michael@0 | 36 | |
michael@0 | 37 | // test to see if a non-existant property exists |
michael@0 | 38 | ok(!Application.prefs.has(testdata.dummy), "Check non-existant property for existence"); |
michael@0 | 39 | |
michael@0 | 40 | // PREF: string browser.active_color == #EE0000 |
michael@0 | 41 | |
michael@0 | 42 | // test to see if an existing string property exists |
michael@0 | 43 | ok(Application.prefs.has(testdata.string), "Check existing string property for existence"); |
michael@0 | 44 | |
michael@0 | 45 | // test accessing a non-existant string property |
michael@0 | 46 | var val = Application.prefs.getValue(testdata.dummy, "default"); |
michael@0 | 47 | is(val, "default", "Check non-existant string property for expected value"); |
michael@0 | 48 | |
michael@0 | 49 | // test accessing an existing string property |
michael@0 | 50 | var val = Application.prefs.getValue(testdata.string, "default"); |
michael@0 | 51 | is(val, "#EE0000", "Check existing string property for expected value"); |
michael@0 | 52 | |
michael@0 | 53 | // test manipulating an existing string property |
michael@0 | 54 | Application.prefs.setValue(testdata.string, "#EF0000"); |
michael@0 | 55 | var val = Application.prefs.getValue(testdata.string, "default"); |
michael@0 | 56 | is(val, "#EF0000", "Set existing string property"); |
michael@0 | 57 | |
michael@0 | 58 | // test getting the type of an existing string property |
michael@0 | 59 | var type = Application.prefs.get(testdata.string).type; |
michael@0 | 60 | is(type, "String", "Check 'Application.prefs.get().type' for string pref"); |
michael@0 | 61 | |
michael@0 | 62 | // test resetting an existing string property |
michael@0 | 63 | Application.prefs.get(testdata.string).reset(); |
michael@0 | 64 | var val = Application.prefs.getValue(testdata.string, "default"); |
michael@0 | 65 | is(val, "#EE0000", "Reset existing string property"); |
michael@0 | 66 | |
michael@0 | 67 | // PREF: integer permissions.default.image == 1 |
michael@0 | 68 | |
michael@0 | 69 | // test to see if an existing integer property exists |
michael@0 | 70 | ok(Application.prefs.has(testdata.integer), "Check existing integer property for existence"); |
michael@0 | 71 | |
michael@0 | 72 | // test accessing a non-existant integer property |
michael@0 | 73 | var val = Application.prefs.getValue(testdata.dummy, 0); |
michael@0 | 74 | is(val, 0, "Check non-existant integer property for expected value"); |
michael@0 | 75 | |
michael@0 | 76 | // test accessing an existing integer property |
michael@0 | 77 | var val = Application.prefs.getValue(testdata.integer, 0); |
michael@0 | 78 | is(val, 1, "Check existing integer property for expected value"); |
michael@0 | 79 | |
michael@0 | 80 | // test manipulating an existing integer property |
michael@0 | 81 | Application.prefs.setValue(testdata.integer, 0); |
michael@0 | 82 | var val = Application.prefs.getValue(testdata.integer, 1); |
michael@0 | 83 | is(val, 0, "Set existing integer property"); |
michael@0 | 84 | |
michael@0 | 85 | // test getting the type of an existing integer property |
michael@0 | 86 | var type = Application.prefs.get(testdata.integer).type; |
michael@0 | 87 | is(type, "Number", "Check 'Application.prefs.get().type' for integer pref"); |
michael@0 | 88 | |
michael@0 | 89 | // test resetting an existing integer property |
michael@0 | 90 | Application.prefs.get(testdata.integer).reset(); |
michael@0 | 91 | var val = Application.prefs.getValue(testdata.integer, 0); |
michael@0 | 92 | is(val, 1, "Reset existing integer property"); |
michael@0 | 93 | |
michael@0 | 94 | // PREF: boolean browser.underline_anchors == true |
michael@0 | 95 | |
michael@0 | 96 | // test to see if an existing boolean property exists |
michael@0 | 97 | ok(Application.prefs.has(testdata.boolean), "Check existing boolean property for existence"); |
michael@0 | 98 | |
michael@0 | 99 | // test accessing a non-existant boolean property |
michael@0 | 100 | var val = Application.prefs.getValue(testdata.dummy, true); |
michael@0 | 101 | ok(val, "Check non-existant boolean property for expected value"); |
michael@0 | 102 | |
michael@0 | 103 | // test accessing an existing boolean property |
michael@0 | 104 | var val = Application.prefs.getValue(testdata.boolean, false); |
michael@0 | 105 | ok(val, "Check existing boolean property for expected value"); |
michael@0 | 106 | |
michael@0 | 107 | // test manipulating an existing boolean property |
michael@0 | 108 | Application.prefs.setValue(testdata.boolean, false); |
michael@0 | 109 | var val = Application.prefs.getValue(testdata.boolean, true); |
michael@0 | 110 | ok(!val, "Set existing boolean property"); |
michael@0 | 111 | |
michael@0 | 112 | // test getting the type of an existing boolean property |
michael@0 | 113 | var type = Application.prefs.get(testdata.boolean).type; |
michael@0 | 114 | is(type, "Boolean", "Check 'Application.prefs.get().type' for boolean pref"); |
michael@0 | 115 | |
michael@0 | 116 | // test resetting an existing boolean property |
michael@0 | 117 | Application.prefs.get(testdata.boolean).reset(); |
michael@0 | 118 | var val = Application.prefs.getValue(testdata.boolean, false); |
michael@0 | 119 | ok(val, "Reset existing string property for expected value"); |
michael@0 | 120 | |
michael@0 | 121 | // test getting all preferences |
michael@0 | 122 | var allPrefs = Application.prefs.all; |
michael@0 | 123 | ok(allPrefs.length >= 800, "Check 'Application.prefs.all' for the right number of preferences"); |
michael@0 | 124 | ok(allPrefs[0].name.length > 0, "Check 'Application.prefs.all' for a valid name in the starting preference"); |
michael@0 | 125 | |
michael@0 | 126 | // test the value of the preference root |
michael@0 | 127 | is(Application.prefs.root, "", "Check the Application preference root"); |
michael@0 | 128 | |
michael@0 | 129 | // test for user changed preferences |
michael@0 | 130 | ok(Application.prefs.get("browser.shell.checkDefaultBrowser").modified, "A single preference is marked as modified."); |
michael@0 | 131 | ok(!Application.prefs.get(testdata.string).modified, "A single preference is marked as not modified."); |
michael@0 | 132 | |
michael@0 | 133 | // test for a locked preference |
michael@0 | 134 | var pref = Application.prefs.get(testdata.string); |
michael@0 | 135 | ok(!pref.locked, "A single preference should not be locked."); |
michael@0 | 136 | |
michael@0 | 137 | pref.locked = true; |
michael@0 | 138 | ok(pref.locked, "A single preference should be locked."); |
michael@0 | 139 | |
michael@0 | 140 | try { |
michael@0 | 141 | prev.value = "test value"; |
michael@0 | 142 | |
michael@0 | 143 | ok(false, "A locked preference could be modified."); |
michael@0 | 144 | } catch(e){ |
michael@0 | 145 | ok(true, "A locked preference should not be able to be modified."); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | pref.locked = false; |
michael@0 | 149 | ok(!pref.locked, "A single preference is unlocked."); |
michael@0 | 150 | |
michael@0 | 151 | // check for change event when setting a value |
michael@0 | 152 | waitForExplicitFinish(); |
michael@0 | 153 | Application.prefs.events.addListener("change", onPrefChange); |
michael@0 | 154 | Application.prefs.setValue("fuel.fuel-test", "change event"); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | function onPrefChange(evt) { |
michael@0 | 158 | is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event"); |
michael@0 | 159 | Application.prefs.events.removeListener("change", onPrefChange); |
michael@0 | 160 | |
michael@0 | 161 | // We are removing the old listener after adding the new listener so we can test that |
michael@0 | 162 | // removing a listener does not remove all listeners |
michael@0 | 163 | Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChangeDummy); |
michael@0 | 164 | Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2); |
michael@0 | 165 | Application.prefs.get("fuel.fuel-test").events.removeListener("change", onPrefChangeDummy); |
michael@0 | 166 | |
michael@0 | 167 | Application.prefs.setValue("fuel.fuel-test", "change event2"); |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | function onPrefChange2(evt) { |
michael@0 | 171 | is(evt.data, testdata.dummy, "Check 'Application.prefs.setValue' fired a change event for a single preference"); |
michael@0 | 172 | Application.prefs.events.removeListener("change", onPrefChange2); |
michael@0 | 173 | |
michael@0 | 174 | finish(); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | function onPrefChangeDummy(evt) { |
michael@0 | 178 | ok(false, "onPrefChangeDummy shouldn't be invoked!"); |
michael@0 | 179 | } |