Bug 1341278 - Fix loss of filters in netmon when clicking on back from the perf tabs. r=Honza
authorAdrien-Marie Enault <schwartzmorn+bugzilla@gmail.com>
Thu, 23 Feb 2017 22:20:38 +0100
changeset 345796 30c1e64495a9930f3b69b9dbdf6b43d24509c886
parent 345795 4daed4761e8d02845bc657bef016be99b358e55e
child 345797 c6ffd6d73ab820c2e8a00874e08b3d524878b63a
push id87672
push userryanvm@gmail.com
push dateFri, 03 Mar 2017 18:39:29 +0000
treeherdermozilla-inbound@e818ea427a08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1341278
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1341278 - Fix loss of filters in netmon when clicking on back from the perf tabs. r=Honza
devtools/client/netmonitor/components/toolbar.js
devtools/client/netmonitor/reducers/filters.js
devtools/client/netmonitor/reducers/index.js
devtools/client/netmonitor/reducers/requests.js
devtools/client/netmonitor/reducers/sort.js
devtools/client/netmonitor/reducers/timing-markers.js
devtools/client/netmonitor/reducers/ui.js
devtools/client/netmonitor/store.js
devtools/client/netmonitor/test/browser_net_filter-04.js
--- a/devtools/client/netmonitor/components/toolbar.js
+++ b/devtools/client/netmonitor/components/toolbar.js
@@ -9,17 +9,16 @@ const {
   createFactory,
   DOM,
   PropTypes,
 } = require("devtools/client/shared/vendor/react");
 const { connect } = require("devtools/client/shared/vendor/react-redux");
 const { PluralForm } = require("devtools/shared/plural-form");
 const Actions = require("../actions/index");
 const { L10N } = require("../utils/l10n");
-const { Prefs } = require("../utils/prefs");
 const {
   getDisplayedRequestsSummary,
   getRequestFilterTypes,
   isNetworkDetailsToggleButtonDisabled,
 } = require("../selectors/index");
 const {
   getFormattedSize,
   getFormattedTime
@@ -51,20 +50,16 @@ const Toolbar = createClass({
     setRequestFilterText: PropTypes.func.isRequired,
     networkDetailsToggleDisabled: PropTypes.bool.isRequired,
     networkDetailsOpen: PropTypes.bool.isRequired,
     summary: PropTypes.object.isRequired,
     toggleNetworkDetails: PropTypes.func.isRequired,
     toggleRequestFilterType: PropTypes.func.isRequired,
   },
 
-  componentDidMount() {
-    Prefs.filters.forEach(this.props.toggleRequestFilterType);
-  },
-
   toggleRequestFilterType(evt) {
     if (evt.type === "keydown" && (evt.key !== "" || evt.key !== "Enter")) {
       return;
     }
     this.props.toggleRequestFilterType(evt.target.dataset.key);
   },
 
   render() {
--- a/devtools/client/netmonitor/reducers/filters.js
+++ b/devtools/client/netmonitor/reducers/filters.js
@@ -75,9 +75,13 @@ function filters(state = new Filters(), 
         toggleRequestFilterType(state.requestFilterTypes, action));
     case SET_REQUEST_FILTER_TEXT:
       return state.set("requestFilterText", action.text);
     default:
       return state;
   }
 }
 
-module.exports = filters;
+module.exports = {
+  FilterTypes,
+  Filters,
+  filters
+};
--- a/devtools/client/netmonitor/reducers/index.js
+++ b/devtools/client/netmonitor/reducers/index.js
@@ -1,23 +1,23 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 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,
   })
 );
--- a/devtools/client/netmonitor/reducers/requests.js
+++ b/devtools/client/netmonitor/reducers/requests.js
@@ -240,9 +240,12 @@ function requestsReducer(state = new Req
       return state;
     }
 
     default:
       return state;
   }
 }
 
-module.exports = requestsReducer;
+module.exports = {
+  Requests,
+  requestsReducer,
+};
--- a/devtools/client/netmonitor/reducers/sort.js
+++ b/devtools/client/netmonitor/reducers/sort.js
@@ -25,9 +25,12 @@ function sortReducer(state = new Sort(),
         }
       });
     }
     default:
       return state;
   }
 }
 
-module.exports = sortReducer;
+module.exports = {
+  Sort,
+  sortReducer
+};
--- a/devtools/client/netmonitor/reducers/timing-markers.js
+++ b/devtools/client/netmonitor/reducers/timing-markers.js
@@ -46,9 +46,12 @@ function timingMarkers(state = new Timin
     case CLEAR_TIMING_MARKERS:
       return clearTimingMarkers(state);
 
     default:
       return state;
   }
 }
 
-module.exports = timingMarkers;
+module.exports = {
+  TimingMarkers,
+  timingMarkers
+};
--- a/devtools/client/netmonitor/reducers/ui.js
+++ b/devtools/client/netmonitor/reducers/ui.js
@@ -59,9 +59,12 @@ function ui(state = new UI(), action) {
       return openNetworkDetails(state, { open: true });
     case WATERFALL_RESIZE:
       return resizeWaterfall(state, action);
     default:
       return state;
   }
 }
 
-module.exports = ui;
+module.exports = {
+  UI,
+  ui
+};
--- a/devtools/client/netmonitor/store.js
+++ b/devtools/client/netmonitor/store.js
@@ -4,20 +4,41 @@
 
 "use strict";
 
 const { createStore, applyMiddleware } = require("devtools/client/shared/vendor/redux");
 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,
       batching
     )
   );
 }
 
--- a/devtools/client/netmonitor/test/browser_net_filter-04.js
+++ b/devtools/client/netmonitor/test/browser_net_filter-04.js
@@ -31,33 +31,36 @@ const REQUESTS_WITH_MEDIA_AND_FLASH_AND_
 
 add_task(function* () {
   Services.prefs.setCharPref("devtools.netmonitor.filters",
                              '["bogus", "js", "alsobogus"]');
 
   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();
   yield performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
   yield wait;
 
   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.");
+
+  yield teardown(monitor);
 });