From b01c8bf47bc2e0b36aa4787ed7c30217410d0fa6 Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Tue, 11 Feb 2014 09:25:21 -0500 Subject: [PATCH] Bug 969448 - Netmonitor selected filter reset to "All" upon every new page request, r=rcampbell --- browser/app/profile/firefox.js | 1 + .../netmonitor/netmonitor-controller.js | 3 +- .../devtools/netmonitor/netmonitor-view.js | 8 ++- .../netmonitor/test/browser_net_filter-02.js | 6 +++ .../test/browser_net_prefs-reload.js | 52 ++++++++++++------- browser/devtools/netmonitor/test/head.js | 6 ++- .../devtools/shared/widgets/ViewHelpers.jsm | 14 +++-- .../themes/shared/devtools/netmonitor.inc.css | 8 +++ 8 files changed, 73 insertions(+), 25 deletions(-) diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 62833a94dcb4..cb949b078fda 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -1152,6 +1152,7 @@ pref("devtools.netmonitor.enabled", true); pref("devtools.netmonitor.panes-network-details-width", 450); pref("devtools.netmonitor.panes-network-details-height", 450); pref("devtools.netmonitor.statistics", true); +pref("devtools.netmonitor.filters", "[\"all\"]"); // Enable the Tilt inspector pref("devtools.tilt.enabled", true); diff --git a/browser/devtools/netmonitor/netmonitor-controller.js b/browser/devtools/netmonitor/netmonitor-controller.js index c57b1eb2dfe0..998c0331b9c9 100644 --- a/browser/devtools/netmonitor/netmonitor-controller.js +++ b/browser/devtools/netmonitor/netmonitor-controller.js @@ -691,7 +691,8 @@ let L10N = new ViewHelpers.L10N(NET_STRINGS_URI); let Prefs = new ViewHelpers.Prefs("devtools.netmonitor", { networkDetailsWidth: ["Int", "panes-network-details-width"], networkDetailsHeight: ["Int", "panes-network-details-height"], - statistics: ["Bool", "statistics"] + statistics: ["Bool", "statistics"], + filters: ["Json", "filters"] }); /** diff --git a/browser/devtools/netmonitor/netmonitor-view.js b/browser/devtools/netmonitor/netmonitor-view.js index 8810da3dca93..bb03e076bc2c 100644 --- a/browser/devtools/netmonitor/netmonitor-view.js +++ b/browser/devtools/netmonitor/netmonitor-view.js @@ -338,7 +338,9 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, { this._summary = $("#requests-menu-network-summary-label"); this._summary.setAttribute("value", L10N.getStr("networkMenu.empty")); + Prefs.filters.forEach(type => this.filterOn(type)); this.sortContents(this._byTiming); + this.allowFocusOnRightClick = true; this.maintainSelectionVisible = true; this.widget.autoscrollWithAppendedItems = true; @@ -386,6 +388,8 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, { destroy: function() { dumpn("Destroying the SourcesView"); + Prefs.filters = this._activeFilters; + this.widget.removeEventListener("select", this._onSelect, false); this._splitter.removeEventListener("mousemove", this._onResize, false); window.removeEventListener("resize", this._onResize, false); @@ -414,7 +418,6 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, { */ reset: function() { this.empty(); - this.filterOn("all"); this._firstRequestStartedMillis = -1; this._lastRequestEndedMillis = -1; }, @@ -604,8 +607,9 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, { target.removeAttribute("checked"); // Check if the filter disabled was the last one. If so, toggle all on. - if (this._activeFilters.length === 0) + if (this._activeFilters.length === 0) { this._enableFilter("all"); + } }, /** diff --git a/browser/devtools/netmonitor/test/browser_net_filter-02.js b/browser/devtools/netmonitor/test/browser_net_filter-02.js index 8e172e570563..795edfa54a66 100644 --- a/browser/devtools/netmonitor/test/browser_net_filter-02.js +++ b/browser/devtools/netmonitor/test/browser_net_filter-02.js @@ -52,6 +52,12 @@ function test() { testButtons("html"); return testContents([1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]); }) + .then(() => { + info("Resetting filters."); + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-all-button")); + testButtons("all"); + return testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + }) .then(() => { return teardown(aMonitor); }) diff --git a/browser/devtools/netmonitor/test/browser_net_prefs-reload.js b/browser/devtools/netmonitor/test/browser_net_prefs-reload.js index d5fd61c43dc9..669ec31f2aec 100644 --- a/browser/devtools/netmonitor/test/browser_net_prefs-reload.js +++ b/browser/devtools/netmonitor/test/browser_net_prefs-reload.js @@ -13,17 +13,33 @@ function test() { // hosts (bottom, side, window). This seems to be slow on debug builds. requestLongerTimeout(3); + // Use these getters instead of caching instances inside the panel win, + // since the tool is reopened a bunch of times during this test + // and the instances will differ. + let getView = () => aMonitor.panelWin.NetMonitorView; + let getController = () => aMonitor.panelWin.NetMonitorController; + let prefsToCheck = { + filters: { + // A custom new value to be used for the verified preference. + newValue: ["html", "css"], + // Getter used to retrieve the current value from the frontend, in order + // to verify that the pref was applied properly. + validateValue: ($) => getView().RequestsMenu._activeFilters, + // Predicate used to modify the frontend when setting the new pref value, + // before trying to validate the changes. + modifyFrontend: ($, aValue) => aValue.forEach(e => getView().RequestsMenu.filterOn(e)) + }, networkDetailsWidth: { newValue: ~~(Math.random() * 200 + 100), - validate: ($) => ~~$("#details-pane").getAttribute("width"), + validateValue: ($) => ~~$("#details-pane").getAttribute("width"), modifyFrontend: ($, aValue) => $("#details-pane").setAttribute("width", aValue) }, networkDetailsHeight: { newValue: ~~(Math.random() * 300 + 100), - validate: ($) => ~~$("#details-pane").getAttribute("height"), + validateValue: ($) => ~~$("#details-pane").getAttribute("height"), modifyFrontend: ($, aValue) => $("#details-pane").setAttribute("height", aValue) - }, + } /* add more prefs here... */ }; @@ -42,11 +58,11 @@ function test() { for (let name in prefsToCheck) { let currentValue = aMonitor.panelWin.Prefs[name]; let firstValue = prefsToCheck[name].firstValue; - let validate = prefsToCheck[name].validate; + let validateValue = prefsToCheck[name].validateValue; - is(currentValue, firstValue, + is(currentValue.toSource(), firstValue.toSource(), "Pref " + name + " should be equal to first value: " + firstValue); - is(currentValue, validate(aMonitor.panelWin.$), + is(currentValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), "Pref " + name + " should validate: " + currentValue); } } @@ -58,17 +74,17 @@ function test() { let currentValue = aMonitor.panelWin.Prefs[name]; let firstValue = prefsToCheck[name].firstValue; let newValue = prefsToCheck[name].newValue; - let validate = prefsToCheck[name].validate; + let validateValue = prefsToCheck[name].validateValue; let modifyFrontend = prefsToCheck[name].modifyFrontend; modifyFrontend(aMonitor.panelWin.$, newValue); info("Modified UI element affecting " + name + " to: " + newValue); - is(currentValue, firstValue, + is(currentValue.toSource(), firstValue.toSource(), "Pref " + name + " should still be equal to first value: " + firstValue); - isnot(currentValue, newValue, + isnot(currentValue.toSource(), newValue.toSource(), "Pref " + name + " should't yet be equal to second value: " + newValue); - is(newValue, validate(aMonitor.panelWin.$), + is(newValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), "The UI element affecting " + name + " should validate: " + newValue); } } @@ -80,13 +96,13 @@ function test() { let currentValue = aMonitor.panelWin.Prefs[name]; let firstValue = prefsToCheck[name].firstValue; let newValue = prefsToCheck[name].newValue; - let validate = prefsToCheck[name].validate; + let validateValue = prefsToCheck[name].validateValue; - isnot(currentValue, firstValue, + isnot(currentValue.toSource(), firstValue.toSource(), "Pref " + name + " should't be equal to first value: " + firstValue); - is(currentValue, newValue, + is(currentValue.toSource(), newValue.toSource(), "Pref " + name + " should now be equal to second value: " + newValue); - is(newValue, validate(aMonitor.panelWin.$), + is(newValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), "The UI element affecting " + name + " should validate: " + newValue); } } @@ -98,17 +114,17 @@ function test() { let currentValue = aMonitor.panelWin.Prefs[name]; let firstValue = prefsToCheck[name].firstValue; let newValue = prefsToCheck[name].newValue; - let validate = prefsToCheck[name].validate; + let validateValue = prefsToCheck[name].validateValue; let modifyFrontend = prefsToCheck[name].modifyFrontend; modifyFrontend(aMonitor.panelWin.$, firstValue); info("Modified UI element affecting " + name + " to: " + firstValue); - isnot(currentValue, firstValue, + isnot(currentValue.toSource(), firstValue.toSource(), "Pref " + name + " should't yet be equal to first value: " + firstValue); - is(currentValue, newValue, + is(currentValue.toSource(), newValue.toSource(), "Pref " + name + " should still be equal to second value: " + newValue); - is(firstValue, validate(aMonitor.panelWin.$), + is(firstValue.toSource(), validateValue(aMonitor.panelWin.$).toSource(), "The UI element affecting " + name + " should validate: " + firstValue); } } diff --git a/browser/devtools/netmonitor/test/head.js b/browser/devtools/netmonitor/test/head.js index dedd9713bf94..40c97c4b3138 100644 --- a/browser/devtools/netmonitor/test/head.js +++ b/browser/devtools/netmonitor/test/head.js @@ -44,12 +44,16 @@ const TEST_IMAGE = EXAMPLE_URL + "test-image.png"; waitForExplicitFinish(); // Enable logging for all the relevant tests. -let gEnableLogging = Services.prefs.getBoolPref("devtools.debugger.log"); +const gEnableLogging = Services.prefs.getBoolPref("devtools.debugger.log"); Services.prefs.setBoolPref("devtools.debugger.log", true); +// Always reset some prefs to their original values after the test finishes. +const gDefaultFilters = Services.prefs.getCharPref("devtools.netmonitor.filters"); + registerCleanupFunction(() => { info("finish() was called, cleaning up..."); Services.prefs.setBoolPref("devtools.debugger.log", gEnableLogging); + Services.prefs.setCharPref("devtools.netmonitor.filters", gDefaultFilters); }); function addTab(aUrl, aWindow) { diff --git a/browser/devtools/shared/widgets/ViewHelpers.jsm b/browser/devtools/shared/widgets/ViewHelpers.jsm index 6e0732c7cea2..7d651ba98f83 100644 --- a/browser/devtools/shared/widgets/ViewHelpers.jsm +++ b/browser/devtools/shared/widgets/ViewHelpers.jsm @@ -395,15 +395,23 @@ ViewHelpers.Prefs.prototype = { /** * Maps a property name to a pref, defining lazy getters and setters. + * Supported types are "Bool", "Char", "Int" and "Json" (which is basically + * just sugar for "Char" using the standard JSON serializer). * * @param string aAccessorName * @param string aType * @param string aPrefName + * @param array aSerializer */ - map: function(aAccessorName, aType, aPrefName) { + map: function(aAccessorName, aType, aPrefName, aSerializer = { in: e => e, out: e => e }) { + if (aType == "Json") { + this.map(aAccessorName, "Char", aPrefName, { in: JSON.parse, out: JSON.stringify }); + return; + } + Object.defineProperty(this, aAccessorName, { - get: () => this._get(aType, [this.root, aPrefName].join(".")), - set: (aValue) => this._set(aType, [this.root, aPrefName].join("."), aValue) + get: () => aSerializer.in(this._get(aType, [this.root, aPrefName].join("."))), + set: (e) => this._set(aType, [this.root, aPrefName].join("."), aSerializer.out(e)) }); } }; diff --git a/browser/themes/shared/devtools/netmonitor.inc.css b/browser/themes/shared/devtools/netmonitor.inc.css index 2c7e32a9ae75..37907adb7308 100644 --- a/browser/themes/shared/devtools/netmonitor.inc.css +++ b/browser/themes/shared/devtools/netmonitor.inc.css @@ -502,6 +502,14 @@ box.requests-menu-status { border-top: solid 1px hsla(210,5%,5%,.3); } +.theme-dark #requests-menu-footer { + background: url(background-noise-toolbar.png), #343c45; /* Toolbars */ +} + +.theme-light #requests-menu-footer { + background: url(background-noise-toolbar.png), #f0f1f2; /* Toolbars */ +} + .requests-menu-footer-button, .requests-menu-footer-label { min-width: 1em;