From d04870eb063f6615ef4b05fceb3b8ef048eaff1b Mon Sep 17 00:00:00 2001 From: Adrien-Marie Enault Date: Thu, 23 Feb 2017 17:53:27 +0100 Subject: [PATCH] Bug 1341278 - Fix loss of filters in netmon when clicking on back from the perf tabs. r=Honza --HG-- extra : rebase_source : 3887ae935ee07be289c13b11c57e3cd753d58ebd --- .../client/netmonitor/components/toolbar.js | 4 --- .../client/netmonitor/reducers/filters.js | 6 ++++- devtools/client/netmonitor/reducers/index.js | 14 +++++------ .../client/netmonitor/reducers/requests.js | 5 +++- devtools/client/netmonitor/reducers/sort.js | 5 +++- .../netmonitor/reducers/timing-markers.js | 5 +++- devtools/client/netmonitor/reducers/ui.js | 5 +++- devtools/client/netmonitor/store.js | 21 ++++++++++++++++ .../netmonitor/test/browser_net_filter-04.js | 25 +++++++++++++------ 9 files changed, 66 insertions(+), 24 deletions(-) diff --git a/devtools/client/netmonitor/components/toolbar.js b/devtools/client/netmonitor/components/toolbar.js index 71111b8ee369..826ed46f7555 100644 --- a/devtools/client/netmonitor/components/toolbar.js +++ b/devtools/client/netmonitor/components/toolbar.js @@ -56,10 +56,6 @@ const Toolbar = createClass({ toggleRequestFilterType: PropTypes.func.isRequired, }, - componentDidMount() { - Prefs.filters.forEach(this.props.toggleRequestFilterType); - }, - toggleRequestFilterType(evt) { if (evt.type === "keydown" && (evt.key !== "" || evt.key !== "Enter")) { return; diff --git a/devtools/client/netmonitor/reducers/filters.js b/devtools/client/netmonitor/reducers/filters.js index ad29c23a7f24..909bc542baae 100644 --- a/devtools/client/netmonitor/reducers/filters.js +++ b/devtools/client/netmonitor/reducers/filters.js @@ -80,4 +80,8 @@ function filters(state = new Filters(), action) { } } -module.exports = filters; +module.exports = { + FilterTypes, + Filters, + filters +}; diff --git a/devtools/client/netmonitor/reducers/index.js b/devtools/client/netmonitor/reducers/index.js index 479490c3c9e3..247fdcce7410 100644 --- a/devtools/client/netmonitor/reducers/index.js +++ b/devtools/client/netmonitor/reducers/index.js @@ -6,16 +6,16 @@ const { combineReducers } = require("devtools/client/shared/vendor/redux"); const batchingReducer = require("./batching"); -const requests = require("./requests"); -const sort = require("./sort"); -const filters = require("./filters"); -const timingMarkers = require("./timing-markers"); -const ui = require("./ui"); +const { requestsReducer } = require("./requests"); +const { sortReducer } = require("./sort"); +const { filters } = require("./filters"); +const { timingMarkers } = require("./timing-markers"); +const { ui } = require("./ui"); module.exports = batchingReducer( combineReducers({ - requests, - sort, + requests: requestsReducer, + sort: sortReducer, filters, timingMarkers, ui, diff --git a/devtools/client/netmonitor/reducers/requests.js b/devtools/client/netmonitor/reducers/requests.js index bceab1133cd4..a337d06adba3 100644 --- a/devtools/client/netmonitor/reducers/requests.js +++ b/devtools/client/netmonitor/reducers/requests.js @@ -245,4 +245,7 @@ function requestsReducer(state = new Requests(), action) { } } -module.exports = requestsReducer; +module.exports = { + Requests, + requestsReducer, +} diff --git a/devtools/client/netmonitor/reducers/sort.js b/devtools/client/netmonitor/reducers/sort.js index 33cbb64c5e2b..6e3756611bfb 100644 --- a/devtools/client/netmonitor/reducers/sort.js +++ b/devtools/client/netmonitor/reducers/sort.js @@ -30,4 +30,7 @@ function sortReducer(state = new Sort(), action) { } } -module.exports = sortReducer; +module.exports = { + Sort, + sortReducer +} diff --git a/devtools/client/netmonitor/reducers/timing-markers.js b/devtools/client/netmonitor/reducers/timing-markers.js index 4b0e92bcfd96..03915037ab28 100644 --- a/devtools/client/netmonitor/reducers/timing-markers.js +++ b/devtools/client/netmonitor/reducers/timing-markers.js @@ -51,4 +51,7 @@ function timingMarkers(state = new TimingMarkers(), action) { } } -module.exports = timingMarkers; +module.exports = { + TimingMarkers, + timingMarkers +} diff --git a/devtools/client/netmonitor/reducers/ui.js b/devtools/client/netmonitor/reducers/ui.js index 79bb9a6a7929..12e2548c9e6d 100644 --- a/devtools/client/netmonitor/reducers/ui.js +++ b/devtools/client/netmonitor/reducers/ui.js @@ -64,4 +64,7 @@ function ui(state = new UI(), action) { } } -module.exports = ui; +module.exports = { + UI, + ui +} diff --git a/devtools/client/netmonitor/store.js b/devtools/client/netmonitor/store.js index 48a94aebf33e..a15f0bb47a73 100644 --- a/devtools/client/netmonitor/store.js +++ b/devtools/client/netmonitor/store.js @@ -9,10 +9,31 @@ const { thunk } = require("devtools/client/shared/redux/middleware/thunk"); const batching = require("./middleware/batching"); const prefs = require("./middleware/prefs"); const rootReducer = require("./reducers/index"); +const { Prefs } = require("./utils/prefs"); +const { FilterTypes, Filters } = require("./reducers/filters"); +const { Requests } = require("./reducers/requests"); +const { Sort } = require("./reducers/sort"); +const { TimingMarkers } = require("./reducers/timing-markers"); +const { UI } = require("./reducers/ui"); function configureStore() { + let activeFilters = {}; + Prefs.filters.forEach((filter) => { + activeFilters[filter] = true; + }); + const initialState = { + filters: new Filters({ + requestFilterTypes: new FilterTypes(activeFilters) + }), + requests: new Requests(), + sort: new Sort(), + timingMarkers: new TimingMarkers(), + ui: new UI() + } + return createStore( rootReducer, + initialState, applyMiddleware( thunk, prefs, diff --git a/devtools/client/netmonitor/test/browser_net_filter-04.js b/devtools/client/netmonitor/test/browser_net_filter-04.js index 418a50dd66c2..590af012ae8a 100644 --- a/devtools/client/netmonitor/test/browser_net_filter-04.js +++ b/devtools/client/netmonitor/test/browser_net_filter-04.js @@ -35,16 +35,16 @@ add_task(function* () { let { monitor } = yield initNetMonitor(FILTERING_URL); info("Starting test... "); - let { gStore, windowRequire } = monitor.panelWin; + let { document, gStore, windowRequire } = monitor.panelWin; let Actions = windowRequire("devtools/client/netmonitor/actions/index"); let { Prefs } = windowRequire("devtools/client/netmonitor/utils/prefs"); gStore.dispatch(Actions.batchEnable(false)); - is(Prefs.filters.length, 1, - "Only the valid filter types should be loaded, the others should be ignored"); - is(Prefs.filters[0], "js", - "The only filter type is correct."); + is(Prefs.filters.length, 3, + "All the filter types should be loaded."); + is(Prefs.filters[0], "bogus", + "The first filter type is invalid, but loaded anyway."); let wait = waitForNetworkEvents(monitor, 9); loadCommonFrameScript(); @@ -54,9 +54,18 @@ add_task(function* () { testFilterButtons(monitor, "js"); ok(true, "Only the correct filter type was taken into consideration."); - yield teardown(monitor); + EventUtils.sendMouseEvent({ type: "click" }, + document.querySelector(".requests-list-filter-html-button")); let filters = Services.prefs.getCharPref("devtools.netmonitor.filters"); - is(filters, '["js"]', - "The bogus filter type was ignored and removed from the preferences."); + is(filters, '["html","js"]', + "The filters preferences were saved directly after the click and only with the valid."); + + EventUtils.sendMouseEvent({ type: "click" }, + document.querySelector(".requests-list-network-summary-button")); + yield wait; + + + + yield teardown(monitor); });