Bug 1341278 - Fix loss of filters in netmon when clicking on back from the perf tabs. r=Honza
☠☠ backed out by a8cbc9a26039 ☠ ☠
authorAdrien-Marie Enault <schwartzmorn+bugzilla@gmail.com>
Thu, 23 Feb 2017 17:53:27 +0100
changeset 373657 cd395be353188b5e4ff953502ac7ed951a5ade29
parent 373656 3a585de719c2d165c5f8f9e888b87cf058380f23
child 373658 9857d5421648084cc0fa32fc0e7154f6beb82b44
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1341278
milestone54.0a1
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
@@ -51,20 +51,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
@@ -30,33 +30,42 @@ 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.");
+
+  EventUtils.sendMouseEvent({ type: "click" },
+    document.querySelector(".requests-list-network-summary-button"));
+  yield wait;
+
+  
+
+  yield teardown(monitor);
 });