michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if the prefs that should survive across tool reloads work. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: // This test reopens the network monitor a bunch of times, for different michael@0: // hosts (bottom, side, window). This seems to be slow on debug builds. michael@0: requestLongerTimeout(3); michael@0: michael@0: // Use these getters instead of caching instances inside the panel win, michael@0: // since the tool is reopened a bunch of times during this test michael@0: // and the instances will differ. michael@0: let getView = () => aMonitor.panelWin.NetMonitorView; michael@0: let getController = () => aMonitor.panelWin.NetMonitorController; michael@0: michael@0: let prefsToCheck = { michael@0: filters: { michael@0: // A custom new value to be used for the verified preference. michael@0: newValue: ["html", "css"], michael@0: // Getter used to retrieve the current value from the frontend, in order michael@0: // to verify that the pref was applied properly. michael@0: validateValue: ($) => getView().RequestsMenu._activeFilters, michael@0: // Predicate used to modify the frontend when setting the new pref value, michael@0: // before trying to validate the changes. michael@0: modifyFrontend: ($, aValue) => aValue.forEach(e => getView().RequestsMenu.filterOn(e)) michael@0: }, michael@0: networkDetailsWidth: { michael@0: newValue: ~~(Math.random() * 200 + 100), michael@0: validateValue: ($) => ~~$("#details-pane").getAttribute("width"), michael@0: modifyFrontend: ($, aValue) => $("#details-pane").setAttribute("width", aValue) michael@0: }, michael@0: networkDetailsHeight: { michael@0: newValue: ~~(Math.random() * 300 + 100), michael@0: validateValue: ($) => ~~$("#details-pane").getAttribute("height"), michael@0: modifyFrontend: ($, aValue) => $("#details-pane").setAttribute("height", aValue) michael@0: } michael@0: /* add more prefs here... */ michael@0: }; michael@0: michael@0: function storeFirstPrefValues() { michael@0: info("Caching initial pref values."); michael@0: michael@0: for (let name in prefsToCheck) { michael@0: let currentValue = aMonitor.panelWin.Prefs[name]; michael@0: prefsToCheck[name].firstValue = currentValue; michael@0: } michael@0: } michael@0: michael@0: function validateFirstPrefValues() { michael@0: info("Validating current pref values to the UI elements."); michael@0: michael@0: for (let name in prefsToCheck) { michael@0: let currentValue = aMonitor.panelWin.Prefs[name]; michael@0: let firstValue = prefsToCheck[name].firstValue; michael@0: let validateValue = prefsToCheck[name].validateValue; michael@0: michael@0: is(currentValue.toSource(), firstValue.toSource(), michael@0: "Pref " + name + " should be equal to first value: " + firstValue); michael@0: is(currentValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), michael@0: "Pref " + name + " should validate: " + currentValue); michael@0: } michael@0: } michael@0: michael@0: function modifyFrontend() { michael@0: info("Modifying UI elements to the specified new values."); michael@0: michael@0: for (let name in prefsToCheck) { michael@0: let currentValue = aMonitor.panelWin.Prefs[name]; michael@0: let firstValue = prefsToCheck[name].firstValue; michael@0: let newValue = prefsToCheck[name].newValue; michael@0: let validateValue = prefsToCheck[name].validateValue; michael@0: let modifyFrontend = prefsToCheck[name].modifyFrontend; michael@0: michael@0: modifyFrontend(aMonitor.panelWin.$, newValue); michael@0: info("Modified UI element affecting " + name + " to: " + newValue); michael@0: michael@0: is(currentValue.toSource(), firstValue.toSource(), michael@0: "Pref " + name + " should still be equal to first value: " + firstValue); michael@0: isnot(currentValue.toSource(), newValue.toSource(), michael@0: "Pref " + name + " should't yet be equal to second value: " + newValue); michael@0: is(newValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), michael@0: "The UI element affecting " + name + " should validate: " + newValue); michael@0: } michael@0: } michael@0: michael@0: function validateNewPrefValues() { michael@0: info("Invalidating old pref values to the modified UI elements."); michael@0: michael@0: for (let name in prefsToCheck) { michael@0: let currentValue = aMonitor.panelWin.Prefs[name]; michael@0: let firstValue = prefsToCheck[name].firstValue; michael@0: let newValue = prefsToCheck[name].newValue; michael@0: let validateValue = prefsToCheck[name].validateValue; michael@0: michael@0: isnot(currentValue.toSource(), firstValue.toSource(), michael@0: "Pref " + name + " should't be equal to first value: " + firstValue); michael@0: is(currentValue.toSource(), newValue.toSource(), michael@0: "Pref " + name + " should now be equal to second value: " + newValue); michael@0: is(newValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), michael@0: "The UI element affecting " + name + " should validate: " + newValue); michael@0: } michael@0: } michael@0: michael@0: function resetFrontend() { michael@0: info("Resetting UI elements to the cached initial pref values."); michael@0: michael@0: for (let name in prefsToCheck) { michael@0: let currentValue = aMonitor.panelWin.Prefs[name]; michael@0: let firstValue = prefsToCheck[name].firstValue; michael@0: let newValue = prefsToCheck[name].newValue; michael@0: let validateValue = prefsToCheck[name].validateValue; michael@0: let modifyFrontend = prefsToCheck[name].modifyFrontend; michael@0: michael@0: modifyFrontend(aMonitor.panelWin.$, firstValue); michael@0: info("Modified UI element affecting " + name + " to: " + firstValue); michael@0: michael@0: isnot(currentValue.toSource(), firstValue.toSource(), michael@0: "Pref " + name + " should't yet be equal to first value: " + firstValue); michael@0: is(currentValue.toSource(), newValue.toSource(), michael@0: "Pref " + name + " should still be equal to second value: " + newValue); michael@0: is(firstValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), michael@0: "The UI element affecting " + name + " should validate: " + firstValue); michael@0: } michael@0: } michael@0: michael@0: function testBottom() { michael@0: info("Testing prefs reload for a bottom host."); michael@0: storeFirstPrefValues(); michael@0: michael@0: // Validate and modify while toolbox is on the bottom. michael@0: validateFirstPrefValues(); michael@0: modifyFrontend(); michael@0: michael@0: return restartNetMonitor(aMonitor) michael@0: .then(([,, aNewMonitor]) => { michael@0: aMonitor = aNewMonitor; michael@0: michael@0: // Revalidate and reset frontend while toolbox is on the bottom. michael@0: validateNewPrefValues(); michael@0: resetFrontend(); michael@0: michael@0: return restartNetMonitor(aMonitor); michael@0: }) michael@0: .then(([,, aNewMonitor]) => { michael@0: aMonitor = aNewMonitor; michael@0: michael@0: // Revalidate. michael@0: validateFirstPrefValues(); michael@0: }); michael@0: } michael@0: michael@0: function testSide() { michael@0: info("Moving toolbox to the side..."); michael@0: michael@0: return aMonitor._toolbox.switchHost(Toolbox.HostType.SIDE) michael@0: .then(() => { michael@0: info("Testing prefs reload for a side host."); michael@0: storeFirstPrefValues(); michael@0: michael@0: // Validate and modify frontend while toolbox is on the side. michael@0: validateFirstPrefValues(); michael@0: modifyFrontend(); michael@0: michael@0: return restartNetMonitor(aMonitor); michael@0: }) michael@0: .then(([,, aNewMonitor]) => { michael@0: aMonitor = aNewMonitor; michael@0: michael@0: // Revalidate and reset frontend while toolbox is on the side. michael@0: validateNewPrefValues(); michael@0: resetFrontend(); michael@0: michael@0: return restartNetMonitor(aMonitor); michael@0: }) michael@0: .then(([,, aNewMonitor]) => { michael@0: aMonitor = aNewMonitor; michael@0: michael@0: // Revalidate. michael@0: validateFirstPrefValues(); michael@0: }); michael@0: } michael@0: michael@0: function testWindow() { michael@0: info("Moving toolbox into a window..."); michael@0: michael@0: return aMonitor._toolbox.switchHost(Toolbox.HostType.WINDOW) michael@0: .then(() => { michael@0: info("Testing prefs reload for a window host."); michael@0: storeFirstPrefValues(); michael@0: michael@0: // Validate and modify frontend while toolbox is in a window. michael@0: validateFirstPrefValues(); michael@0: modifyFrontend(); michael@0: michael@0: return restartNetMonitor(aMonitor); michael@0: }) michael@0: .then(([,, aNewMonitor]) => { michael@0: aMonitor = aNewMonitor; michael@0: michael@0: // Revalidate and reset frontend while toolbox is in a window. michael@0: validateNewPrefValues(); michael@0: resetFrontend(); michael@0: michael@0: return restartNetMonitor(aMonitor); michael@0: }) michael@0: .then(([,, aNewMonitor]) => { michael@0: aMonitor = aNewMonitor; michael@0: michael@0: // Revalidate. michael@0: validateFirstPrefValues(); michael@0: }); michael@0: } michael@0: michael@0: function cleanupAndFinish() { michael@0: info("Moving toolbox back to the bottom..."); michael@0: michael@0: aMonitor._toolbox.switchHost(Toolbox.HostType.BOTTOM) michael@0: .then(() => teardown(aMonitor)) michael@0: .then(finish); michael@0: } michael@0: michael@0: testBottom() michael@0: .then(testSide) michael@0: .then(testWindow) michael@0: .then(cleanupAndFinish); michael@0: }); michael@0: }