1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_prefs-reload.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,233 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Tests if the prefs that should survive across tool reloads work. 1.9 + */ 1.10 + 1.11 +function test() { 1.12 + initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { 1.13 + info("Starting test... "); 1.14 + 1.15 + // This test reopens the network monitor a bunch of times, for different 1.16 + // hosts (bottom, side, window). This seems to be slow on debug builds. 1.17 + requestLongerTimeout(3); 1.18 + 1.19 + // Use these getters instead of caching instances inside the panel win, 1.20 + // since the tool is reopened a bunch of times during this test 1.21 + // and the instances will differ. 1.22 + let getView = () => aMonitor.panelWin.NetMonitorView; 1.23 + let getController = () => aMonitor.panelWin.NetMonitorController; 1.24 + 1.25 + let prefsToCheck = { 1.26 + filters: { 1.27 + // A custom new value to be used for the verified preference. 1.28 + newValue: ["html", "css"], 1.29 + // Getter used to retrieve the current value from the frontend, in order 1.30 + // to verify that the pref was applied properly. 1.31 + validateValue: ($) => getView().RequestsMenu._activeFilters, 1.32 + // Predicate used to modify the frontend when setting the new pref value, 1.33 + // before trying to validate the changes. 1.34 + modifyFrontend: ($, aValue) => aValue.forEach(e => getView().RequestsMenu.filterOn(e)) 1.35 + }, 1.36 + networkDetailsWidth: { 1.37 + newValue: ~~(Math.random() * 200 + 100), 1.38 + validateValue: ($) => ~~$("#details-pane").getAttribute("width"), 1.39 + modifyFrontend: ($, aValue) => $("#details-pane").setAttribute("width", aValue) 1.40 + }, 1.41 + networkDetailsHeight: { 1.42 + newValue: ~~(Math.random() * 300 + 100), 1.43 + validateValue: ($) => ~~$("#details-pane").getAttribute("height"), 1.44 + modifyFrontend: ($, aValue) => $("#details-pane").setAttribute("height", aValue) 1.45 + } 1.46 + /* add more prefs here... */ 1.47 + }; 1.48 + 1.49 + function storeFirstPrefValues() { 1.50 + info("Caching initial pref values."); 1.51 + 1.52 + for (let name in prefsToCheck) { 1.53 + let currentValue = aMonitor.panelWin.Prefs[name]; 1.54 + prefsToCheck[name].firstValue = currentValue; 1.55 + } 1.56 + } 1.57 + 1.58 + function validateFirstPrefValues() { 1.59 + info("Validating current pref values to the UI elements."); 1.60 + 1.61 + for (let name in prefsToCheck) { 1.62 + let currentValue = aMonitor.panelWin.Prefs[name]; 1.63 + let firstValue = prefsToCheck[name].firstValue; 1.64 + let validateValue = prefsToCheck[name].validateValue; 1.65 + 1.66 + is(currentValue.toSource(), firstValue.toSource(), 1.67 + "Pref " + name + " should be equal to first value: " + firstValue); 1.68 + is(currentValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), 1.69 + "Pref " + name + " should validate: " + currentValue); 1.70 + } 1.71 + } 1.72 + 1.73 + function modifyFrontend() { 1.74 + info("Modifying UI elements to the specified new values."); 1.75 + 1.76 + for (let name in prefsToCheck) { 1.77 + let currentValue = aMonitor.panelWin.Prefs[name]; 1.78 + let firstValue = prefsToCheck[name].firstValue; 1.79 + let newValue = prefsToCheck[name].newValue; 1.80 + let validateValue = prefsToCheck[name].validateValue; 1.81 + let modifyFrontend = prefsToCheck[name].modifyFrontend; 1.82 + 1.83 + modifyFrontend(aMonitor.panelWin.$, newValue); 1.84 + info("Modified UI element affecting " + name + " to: " + newValue); 1.85 + 1.86 + is(currentValue.toSource(), firstValue.toSource(), 1.87 + "Pref " + name + " should still be equal to first value: " + firstValue); 1.88 + isnot(currentValue.toSource(), newValue.toSource(), 1.89 + "Pref " + name + " should't yet be equal to second value: " + newValue); 1.90 + is(newValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), 1.91 + "The UI element affecting " + name + " should validate: " + newValue); 1.92 + } 1.93 + } 1.94 + 1.95 + function validateNewPrefValues() { 1.96 + info("Invalidating old pref values to the modified UI elements."); 1.97 + 1.98 + for (let name in prefsToCheck) { 1.99 + let currentValue = aMonitor.panelWin.Prefs[name]; 1.100 + let firstValue = prefsToCheck[name].firstValue; 1.101 + let newValue = prefsToCheck[name].newValue; 1.102 + let validateValue = prefsToCheck[name].validateValue; 1.103 + 1.104 + isnot(currentValue.toSource(), firstValue.toSource(), 1.105 + "Pref " + name + " should't be equal to first value: " + firstValue); 1.106 + is(currentValue.toSource(), newValue.toSource(), 1.107 + "Pref " + name + " should now be equal to second value: " + newValue); 1.108 + is(newValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), 1.109 + "The UI element affecting " + name + " should validate: " + newValue); 1.110 + } 1.111 + } 1.112 + 1.113 + function resetFrontend() { 1.114 + info("Resetting UI elements to the cached initial pref values."); 1.115 + 1.116 + for (let name in prefsToCheck) { 1.117 + let currentValue = aMonitor.panelWin.Prefs[name]; 1.118 + let firstValue = prefsToCheck[name].firstValue; 1.119 + let newValue = prefsToCheck[name].newValue; 1.120 + let validateValue = prefsToCheck[name].validateValue; 1.121 + let modifyFrontend = prefsToCheck[name].modifyFrontend; 1.122 + 1.123 + modifyFrontend(aMonitor.panelWin.$, firstValue); 1.124 + info("Modified UI element affecting " + name + " to: " + firstValue); 1.125 + 1.126 + isnot(currentValue.toSource(), firstValue.toSource(), 1.127 + "Pref " + name + " should't yet be equal to first value: " + firstValue); 1.128 + is(currentValue.toSource(), newValue.toSource(), 1.129 + "Pref " + name + " should still be equal to second value: " + newValue); 1.130 + is(firstValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), 1.131 + "The UI element affecting " + name + " should validate: " + firstValue); 1.132 + } 1.133 + } 1.134 + 1.135 + function testBottom() { 1.136 + info("Testing prefs reload for a bottom host."); 1.137 + storeFirstPrefValues(); 1.138 + 1.139 + // Validate and modify while toolbox is on the bottom. 1.140 + validateFirstPrefValues(); 1.141 + modifyFrontend(); 1.142 + 1.143 + return restartNetMonitor(aMonitor) 1.144 + .then(([,, aNewMonitor]) => { 1.145 + aMonitor = aNewMonitor; 1.146 + 1.147 + // Revalidate and reset frontend while toolbox is on the bottom. 1.148 + validateNewPrefValues(); 1.149 + resetFrontend(); 1.150 + 1.151 + return restartNetMonitor(aMonitor); 1.152 + }) 1.153 + .then(([,, aNewMonitor]) => { 1.154 + aMonitor = aNewMonitor; 1.155 + 1.156 + // Revalidate. 1.157 + validateFirstPrefValues(); 1.158 + }); 1.159 + } 1.160 + 1.161 + function testSide() { 1.162 + info("Moving toolbox to the side..."); 1.163 + 1.164 + return aMonitor._toolbox.switchHost(Toolbox.HostType.SIDE) 1.165 + .then(() => { 1.166 + info("Testing prefs reload for a side host."); 1.167 + storeFirstPrefValues(); 1.168 + 1.169 + // Validate and modify frontend while toolbox is on the side. 1.170 + validateFirstPrefValues(); 1.171 + modifyFrontend(); 1.172 + 1.173 + return restartNetMonitor(aMonitor); 1.174 + }) 1.175 + .then(([,, aNewMonitor]) => { 1.176 + aMonitor = aNewMonitor; 1.177 + 1.178 + // Revalidate and reset frontend while toolbox is on the side. 1.179 + validateNewPrefValues(); 1.180 + resetFrontend(); 1.181 + 1.182 + return restartNetMonitor(aMonitor); 1.183 + }) 1.184 + .then(([,, aNewMonitor]) => { 1.185 + aMonitor = aNewMonitor; 1.186 + 1.187 + // Revalidate. 1.188 + validateFirstPrefValues(); 1.189 + }); 1.190 + } 1.191 + 1.192 + function testWindow() { 1.193 + info("Moving toolbox into a window..."); 1.194 + 1.195 + return aMonitor._toolbox.switchHost(Toolbox.HostType.WINDOW) 1.196 + .then(() => { 1.197 + info("Testing prefs reload for a window host."); 1.198 + storeFirstPrefValues(); 1.199 + 1.200 + // Validate and modify frontend while toolbox is in a window. 1.201 + validateFirstPrefValues(); 1.202 + modifyFrontend(); 1.203 + 1.204 + return restartNetMonitor(aMonitor); 1.205 + }) 1.206 + .then(([,, aNewMonitor]) => { 1.207 + aMonitor = aNewMonitor; 1.208 + 1.209 + // Revalidate and reset frontend while toolbox is in a window. 1.210 + validateNewPrefValues(); 1.211 + resetFrontend(); 1.212 + 1.213 + return restartNetMonitor(aMonitor); 1.214 + }) 1.215 + .then(([,, aNewMonitor]) => { 1.216 + aMonitor = aNewMonitor; 1.217 + 1.218 + // Revalidate. 1.219 + validateFirstPrefValues(); 1.220 + }); 1.221 + } 1.222 + 1.223 + function cleanupAndFinish() { 1.224 + info("Moving toolbox back to the bottom..."); 1.225 + 1.226 + aMonitor._toolbox.switchHost(Toolbox.HostType.BOTTOM) 1.227 + .then(() => teardown(aMonitor)) 1.228 + .then(finish); 1.229 + } 1.230 + 1.231 + testBottom() 1.232 + .then(testSide) 1.233 + .then(testWindow) 1.234 + .then(cleanupAndFinish); 1.235 + }); 1.236 +}