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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Tests if the prefs that should survive across tool reloads work. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { |
michael@0 | 10 | info("Starting test... "); |
michael@0 | 11 | |
michael@0 | 12 | // This test reopens the network monitor a bunch of times, for different |
michael@0 | 13 | // hosts (bottom, side, window). This seems to be slow on debug builds. |
michael@0 | 14 | requestLongerTimeout(3); |
michael@0 | 15 | |
michael@0 | 16 | // Use these getters instead of caching instances inside the panel win, |
michael@0 | 17 | // since the tool is reopened a bunch of times during this test |
michael@0 | 18 | // and the instances will differ. |
michael@0 | 19 | let getView = () => aMonitor.panelWin.NetMonitorView; |
michael@0 | 20 | let getController = () => aMonitor.panelWin.NetMonitorController; |
michael@0 | 21 | |
michael@0 | 22 | let prefsToCheck = { |
michael@0 | 23 | filters: { |
michael@0 | 24 | // A custom new value to be used for the verified preference. |
michael@0 | 25 | newValue: ["html", "css"], |
michael@0 | 26 | // Getter used to retrieve the current value from the frontend, in order |
michael@0 | 27 | // to verify that the pref was applied properly. |
michael@0 | 28 | validateValue: ($) => getView().RequestsMenu._activeFilters, |
michael@0 | 29 | // Predicate used to modify the frontend when setting the new pref value, |
michael@0 | 30 | // before trying to validate the changes. |
michael@0 | 31 | modifyFrontend: ($, aValue) => aValue.forEach(e => getView().RequestsMenu.filterOn(e)) |
michael@0 | 32 | }, |
michael@0 | 33 | networkDetailsWidth: { |
michael@0 | 34 | newValue: ~~(Math.random() * 200 + 100), |
michael@0 | 35 | validateValue: ($) => ~~$("#details-pane").getAttribute("width"), |
michael@0 | 36 | modifyFrontend: ($, aValue) => $("#details-pane").setAttribute("width", aValue) |
michael@0 | 37 | }, |
michael@0 | 38 | networkDetailsHeight: { |
michael@0 | 39 | newValue: ~~(Math.random() * 300 + 100), |
michael@0 | 40 | validateValue: ($) => ~~$("#details-pane").getAttribute("height"), |
michael@0 | 41 | modifyFrontend: ($, aValue) => $("#details-pane").setAttribute("height", aValue) |
michael@0 | 42 | } |
michael@0 | 43 | /* add more prefs here... */ |
michael@0 | 44 | }; |
michael@0 | 45 | |
michael@0 | 46 | function storeFirstPrefValues() { |
michael@0 | 47 | info("Caching initial pref values."); |
michael@0 | 48 | |
michael@0 | 49 | for (let name in prefsToCheck) { |
michael@0 | 50 | let currentValue = aMonitor.panelWin.Prefs[name]; |
michael@0 | 51 | prefsToCheck[name].firstValue = currentValue; |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function validateFirstPrefValues() { |
michael@0 | 56 | info("Validating current pref values to the UI elements."); |
michael@0 | 57 | |
michael@0 | 58 | for (let name in prefsToCheck) { |
michael@0 | 59 | let currentValue = aMonitor.panelWin.Prefs[name]; |
michael@0 | 60 | let firstValue = prefsToCheck[name].firstValue; |
michael@0 | 61 | let validateValue = prefsToCheck[name].validateValue; |
michael@0 | 62 | |
michael@0 | 63 | is(currentValue.toSource(), firstValue.toSource(), |
michael@0 | 64 | "Pref " + name + " should be equal to first value: " + firstValue); |
michael@0 | 65 | is(currentValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), |
michael@0 | 66 | "Pref " + name + " should validate: " + currentValue); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function modifyFrontend() { |
michael@0 | 71 | info("Modifying UI elements to the specified new values."); |
michael@0 | 72 | |
michael@0 | 73 | for (let name in prefsToCheck) { |
michael@0 | 74 | let currentValue = aMonitor.panelWin.Prefs[name]; |
michael@0 | 75 | let firstValue = prefsToCheck[name].firstValue; |
michael@0 | 76 | let newValue = prefsToCheck[name].newValue; |
michael@0 | 77 | let validateValue = prefsToCheck[name].validateValue; |
michael@0 | 78 | let modifyFrontend = prefsToCheck[name].modifyFrontend; |
michael@0 | 79 | |
michael@0 | 80 | modifyFrontend(aMonitor.panelWin.$, newValue); |
michael@0 | 81 | info("Modified UI element affecting " + name + " to: " + newValue); |
michael@0 | 82 | |
michael@0 | 83 | is(currentValue.toSource(), firstValue.toSource(), |
michael@0 | 84 | "Pref " + name + " should still be equal to first value: " + firstValue); |
michael@0 | 85 | isnot(currentValue.toSource(), newValue.toSource(), |
michael@0 | 86 | "Pref " + name + " should't yet be equal to second value: " + newValue); |
michael@0 | 87 | is(newValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), |
michael@0 | 88 | "The UI element affecting " + name + " should validate: " + newValue); |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function validateNewPrefValues() { |
michael@0 | 93 | info("Invalidating old pref values to the modified UI elements."); |
michael@0 | 94 | |
michael@0 | 95 | for (let name in prefsToCheck) { |
michael@0 | 96 | let currentValue = aMonitor.panelWin.Prefs[name]; |
michael@0 | 97 | let firstValue = prefsToCheck[name].firstValue; |
michael@0 | 98 | let newValue = prefsToCheck[name].newValue; |
michael@0 | 99 | let validateValue = prefsToCheck[name].validateValue; |
michael@0 | 100 | |
michael@0 | 101 | isnot(currentValue.toSource(), firstValue.toSource(), |
michael@0 | 102 | "Pref " + name + " should't be equal to first value: " + firstValue); |
michael@0 | 103 | is(currentValue.toSource(), newValue.toSource(), |
michael@0 | 104 | "Pref " + name + " should now be equal to second value: " + newValue); |
michael@0 | 105 | is(newValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), |
michael@0 | 106 | "The UI element affecting " + name + " should validate: " + newValue); |
michael@0 | 107 | } |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function resetFrontend() { |
michael@0 | 111 | info("Resetting UI elements to the cached initial pref values."); |
michael@0 | 112 | |
michael@0 | 113 | for (let name in prefsToCheck) { |
michael@0 | 114 | let currentValue = aMonitor.panelWin.Prefs[name]; |
michael@0 | 115 | let firstValue = prefsToCheck[name].firstValue; |
michael@0 | 116 | let newValue = prefsToCheck[name].newValue; |
michael@0 | 117 | let validateValue = prefsToCheck[name].validateValue; |
michael@0 | 118 | let modifyFrontend = prefsToCheck[name].modifyFrontend; |
michael@0 | 119 | |
michael@0 | 120 | modifyFrontend(aMonitor.panelWin.$, firstValue); |
michael@0 | 121 | info("Modified UI element affecting " + name + " to: " + firstValue); |
michael@0 | 122 | |
michael@0 | 123 | isnot(currentValue.toSource(), firstValue.toSource(), |
michael@0 | 124 | "Pref " + name + " should't yet be equal to first value: " + firstValue); |
michael@0 | 125 | is(currentValue.toSource(), newValue.toSource(), |
michael@0 | 126 | "Pref " + name + " should still be equal to second value: " + newValue); |
michael@0 | 127 | is(firstValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), |
michael@0 | 128 | "The UI element affecting " + name + " should validate: " + firstValue); |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | function testBottom() { |
michael@0 | 133 | info("Testing prefs reload for a bottom host."); |
michael@0 | 134 | storeFirstPrefValues(); |
michael@0 | 135 | |
michael@0 | 136 | // Validate and modify while toolbox is on the bottom. |
michael@0 | 137 | validateFirstPrefValues(); |
michael@0 | 138 | modifyFrontend(); |
michael@0 | 139 | |
michael@0 | 140 | return restartNetMonitor(aMonitor) |
michael@0 | 141 | .then(([,, aNewMonitor]) => { |
michael@0 | 142 | aMonitor = aNewMonitor; |
michael@0 | 143 | |
michael@0 | 144 | // Revalidate and reset frontend while toolbox is on the bottom. |
michael@0 | 145 | validateNewPrefValues(); |
michael@0 | 146 | resetFrontend(); |
michael@0 | 147 | |
michael@0 | 148 | return restartNetMonitor(aMonitor); |
michael@0 | 149 | }) |
michael@0 | 150 | .then(([,, aNewMonitor]) => { |
michael@0 | 151 | aMonitor = aNewMonitor; |
michael@0 | 152 | |
michael@0 | 153 | // Revalidate. |
michael@0 | 154 | validateFirstPrefValues(); |
michael@0 | 155 | }); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | function testSide() { |
michael@0 | 159 | info("Moving toolbox to the side..."); |
michael@0 | 160 | |
michael@0 | 161 | return aMonitor._toolbox.switchHost(Toolbox.HostType.SIDE) |
michael@0 | 162 | .then(() => { |
michael@0 | 163 | info("Testing prefs reload for a side host."); |
michael@0 | 164 | storeFirstPrefValues(); |
michael@0 | 165 | |
michael@0 | 166 | // Validate and modify frontend while toolbox is on the side. |
michael@0 | 167 | validateFirstPrefValues(); |
michael@0 | 168 | modifyFrontend(); |
michael@0 | 169 | |
michael@0 | 170 | return restartNetMonitor(aMonitor); |
michael@0 | 171 | }) |
michael@0 | 172 | .then(([,, aNewMonitor]) => { |
michael@0 | 173 | aMonitor = aNewMonitor; |
michael@0 | 174 | |
michael@0 | 175 | // Revalidate and reset frontend while toolbox is on the side. |
michael@0 | 176 | validateNewPrefValues(); |
michael@0 | 177 | resetFrontend(); |
michael@0 | 178 | |
michael@0 | 179 | return restartNetMonitor(aMonitor); |
michael@0 | 180 | }) |
michael@0 | 181 | .then(([,, aNewMonitor]) => { |
michael@0 | 182 | aMonitor = aNewMonitor; |
michael@0 | 183 | |
michael@0 | 184 | // Revalidate. |
michael@0 | 185 | validateFirstPrefValues(); |
michael@0 | 186 | }); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | function testWindow() { |
michael@0 | 190 | info("Moving toolbox into a window..."); |
michael@0 | 191 | |
michael@0 | 192 | return aMonitor._toolbox.switchHost(Toolbox.HostType.WINDOW) |
michael@0 | 193 | .then(() => { |
michael@0 | 194 | info("Testing prefs reload for a window host."); |
michael@0 | 195 | storeFirstPrefValues(); |
michael@0 | 196 | |
michael@0 | 197 | // Validate and modify frontend while toolbox is in a window. |
michael@0 | 198 | validateFirstPrefValues(); |
michael@0 | 199 | modifyFrontend(); |
michael@0 | 200 | |
michael@0 | 201 | return restartNetMonitor(aMonitor); |
michael@0 | 202 | }) |
michael@0 | 203 | .then(([,, aNewMonitor]) => { |
michael@0 | 204 | aMonitor = aNewMonitor; |
michael@0 | 205 | |
michael@0 | 206 | // Revalidate and reset frontend while toolbox is in a window. |
michael@0 | 207 | validateNewPrefValues(); |
michael@0 | 208 | resetFrontend(); |
michael@0 | 209 | |
michael@0 | 210 | return restartNetMonitor(aMonitor); |
michael@0 | 211 | }) |
michael@0 | 212 | .then(([,, aNewMonitor]) => { |
michael@0 | 213 | aMonitor = aNewMonitor; |
michael@0 | 214 | |
michael@0 | 215 | // Revalidate. |
michael@0 | 216 | validateFirstPrefValues(); |
michael@0 | 217 | }); |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | function cleanupAndFinish() { |
michael@0 | 221 | info("Moving toolbox back to the bottom..."); |
michael@0 | 222 | |
michael@0 | 223 | aMonitor._toolbox.switchHost(Toolbox.HostType.BOTTOM) |
michael@0 | 224 | .then(() => teardown(aMonitor)) |
michael@0 | 225 | .then(finish); |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | testBottom() |
michael@0 | 229 | .then(testSide) |
michael@0 | 230 | .then(testWindow) |
michael@0 | 231 | .then(cleanupAndFinish); |
michael@0 | 232 | }); |
michael@0 | 233 | } |