Skip to content

Commit

Permalink
Bug 1305788 - Part 1: Sync changed filter prefs back to system. r=bgrins
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: C9CMgjiXGSl
  • Loading branch information
linclark committed Oct 2, 2016
1 parent cc4fd28 commit 071543f
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 38 deletions.
18 changes: 12 additions & 6 deletions devtools/client/preferences/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,24 @@ sticky_pref("devtools.theme", "dark");
sticky_pref("devtools.theme", "light");
#endif

// Remember the Web Console filters
// Web console filters
pref("devtools.webconsole.filter.error", true);
pref("devtools.webconsole.filter.warn", true);
pref("devtools.webconsole.filter.info", true);
pref("devtools.webconsole.filter.log", true);
pref("devtools.webconsole.filter.debug", true);
pref("devtools.webconsole.filter.net", false);
pref("devtools.webconsole.filter.netxhr", false);
// Deprecated - old console frontend
pref("devtools.webconsole.filter.network", true);
pref("devtools.webconsole.filter.networkinfo", false);
pref("devtools.webconsole.filter.netwarn", true);
pref("devtools.webconsole.filter.netxhr", false);
pref("devtools.webconsole.filter.csserror", true);
pref("devtools.webconsole.filter.cssparser", false);
pref("devtools.webconsole.filter.csslog", false);
pref("devtools.webconsole.filter.exception", true);
pref("devtools.webconsole.filter.jswarn", true);
pref("devtools.webconsole.filter.jslog", false);
pref("devtools.webconsole.filter.error", true);
pref("devtools.webconsole.filter.warn", true);
pref("devtools.webconsole.filter.info", true);
pref("devtools.webconsole.filter.log", true);
pref("devtools.webconsole.filter.secerror", true);
pref("devtools.webconsole.filter.secwarn", true);
pref("devtools.webconsole.filter.serviceworkers", true);
Expand Down Expand Up @@ -282,6 +285,9 @@ pref("devtools.browserconsole.filter.serverwarn", false);
pref("devtools.browserconsole.filter.serverinfo", false);
pref("devtools.browserconsole.filter.serverlog", false);

// Web console filter settings bar
pref("devtools.webconsole.ui.filterbar", false);

// Max number of inputs to store in web console history.
pref("devtools.webconsole.inputHistoryCount", 50);

Expand Down
30 changes: 23 additions & 7 deletions devtools/client/webconsole/new-console-output/actions/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

"use strict";

const { getAllFilters } = require("devtools/client/webconsole/new-console-output/selectors/filters");
const Services = require("Services");

const {
FILTER_TEXT_SET,
FILTER_TOGGLE,
FILTERS_CLEAR
} = require("../constants");
FILTERS_CLEAR,
PREFS,
} = require("devtools/client/webconsole/new-console-output/constants");

function filterTextSet(text) {
return {
Expand All @@ -20,15 +24,27 @@ function filterTextSet(text) {
}

function filterToggle(filter) {
return {
type: FILTER_TOGGLE,
filter,
return (dispatch, getState) => {
dispatch({
type: FILTER_TOGGLE,
filter,
});
const filterState = getAllFilters(getState());
Services.prefs.setBoolPref(PREFS.FILTER[filter.toUpperCase()],
filterState.get(filter));
};
}

function filtersClear() {
return {
type: FILTERS_CLEAR
return (dispatch, getState) => {
dispatch({
type: FILTERS_CLEAR,
});

const filterState = getAllFilters(getState());
for (let filter in filterState) {
Services.prefs.clearUserPref(PREFS.FILTER[filter.toUpperCase()]);
}
};
}

Expand Down
14 changes: 11 additions & 3 deletions devtools/client/webconsole/new-console-output/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@

"use strict";

const { getAllUi } = require("devtools/client/webconsole/new-console-output/selectors/ui");
const Services = require("Services");

const {
FILTER_BAR_TOGGLE,
} = require("../constants");
PREFS,
} = require("devtools/client/webconsole/new-console-output/constants");

function filterBarToggle(show) {
return {
type: FILTER_BAR_TOGGLE
return (dispatch, getState) => {
dispatch({
type: FILTER_BAR_TOGGLE
});
const uiState = getAllUi(getState());
Services.prefs.setBoolPref(PREFS.UI.FILTER_BAR, uiState.get("filterBarVisible"));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const FilterBar = createClass({

if (filterBarVisible) {
children.push(
dom.div({className: "devtools-toolbar"},
dom.div({className: "devtools-toolbar webconsole-filterbar-secondary"},
FilterButton({
active: filter.error,
label: "Errors",
Expand Down Expand Up @@ -114,9 +114,9 @@ const FilterBar = createClass({
dispatch
}),
FilterButton({
active: filter.network,
active: filter.net,
label: "Requests",
filterKey: "network",
filterKey: "net",
dispatch
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ const FilterButton = createClass({
},

render() {
const {label, active} = this.props;
const {active, label, filterKey} = this.props;

let classList = ["menu-filter-button"];
let classList = [
"menu-filter-button",
filterKey,
];
if (active) {
classList.push("checked");
}
Expand Down
19 changes: 18 additions & 1 deletion devtools/client/webconsole/new-console-output/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ const actionTypes = {
FILTER_BAR_TOGGLE: "FILTER_BAR_TOGGLE",
};

const prefs = {
PREFS: {
FILTER: {
ERROR: "devtools.webconsole.filter.error",
WARN: "devtools.webconsole.filter.warn",
INFO: "devtools.webconsole.filter.info",
LOG: "devtools.webconsole.filter.log",
DEBUG: "devtools.webconsole.filter.debug",
NET: "devtools.webconsole.filter.net",
NETXHR: "devtools.webconsole.filter.netxhr",
},
UI: {
FILTER_BAR: "devtools.webconsole.ui.filterbar"
}
}
};

const chromeRDPEnums = {
MESSAGE_SOURCE: {
XML: "xml",
Expand Down Expand Up @@ -61,4 +78,4 @@ const chromeRDPEnums = {
};

// Combine into a single constants object
module.exports = Object.assign({}, actionTypes, chromeRDPEnums);
module.exports = Object.assign({}, actionTypes, prefs, chromeRDPEnums);
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const FilterState = Immutable.Record({
error: true,
info: true,
log: true,
network: true,
netxhr: true,
net: false,
netxhr: false,
text: "",
warn: true,
});
Expand Down
9 changes: 6 additions & 3 deletions devtools/client/webconsole/new-console-output/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
const constants = require("devtools/client/webconsole/new-console-output/constants");
const Immutable = require("devtools/client/shared/vendor/immutable");

const Ui = Immutable.Record({
const UiState = Immutable.Record({
filterBarVisible: false,
filteredMessageVisible: false,
});

function ui(state = new Ui(), action) {
function ui(state = new UiState(), action) {
switch (action.type) {
case constants.FILTER_BAR_TOGGLE:
return state.set("filterBarVisible", !state.filterBarVisible);
Expand All @@ -22,4 +22,7 @@ function ui(state = new Ui(), action) {
return state;
}

exports.ui = ui;
module.exports = {
UiState,
ui,
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function filterNetwork(messages, filters) {
return messages.filter((message) => {
return (
message.source !== MESSAGE_SOURCE.NETWORK
|| (filters.get("network") === true && message.isXHR === false)
|| (filters.get("net") === true && message.isXHR === false)
|| (filters.get("netxhr") === true && message.isXHR === true)
|| [MESSAGE_TYPE.COMMAND, MESSAGE_TYPE.RESULT].includes(message.type)
);
Expand Down
23 changes: 15 additions & 8 deletions devtools/client/webconsole/new-console-output/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

const {FilterState} = require("devtools/client/webconsole/new-console-output/reducers/filters");
const {PrefState} = require("devtools/client/webconsole/new-console-output/reducers/prefs");
const {UiState} = require("devtools/client/webconsole/new-console-output/reducers/ui");
const {
applyMiddleware,
combineReducers,
compose,
createStore
} = require("devtools/client/shared/vendor/redux");
const { thunk } = require("devtools/client/shared/redux/middleware/thunk");
const constants = require("devtools/client/webconsole/new-console-output/constants");
const {
BATCH_ACTIONS,
PREFS,
} = require("devtools/client/webconsole/new-console-output/constants");
const { reducers } = require("./reducers/index");
const Services = require("Services");

Expand All @@ -22,12 +26,15 @@ function configureStore() {
logLimit: Math.max(Services.prefs.getIntPref("devtools.hud.loglimit"), 1),
}),
filters: new FilterState({
error: Services.prefs.getBoolPref("devtools.webconsole.filter.error"),
warn: Services.prefs.getBoolPref("devtools.webconsole.filter.warn"),
info: Services.prefs.getBoolPref("devtools.webconsole.filter.info"),
log: Services.prefs.getBoolPref("devtools.webconsole.filter.log"),
network: Services.prefs.getBoolPref("devtools.webconsole.filter.network"),
netxhr: Services.prefs.getBoolPref("devtools.webconsole.filter.netxhr"),
error: Services.prefs.getBoolPref(PREFS.FILTER.ERROR),
warn: Services.prefs.getBoolPref(PREFS.FILTER.WARN),
info: Services.prefs.getBoolPref(PREFS.FILTER.INFO),
log: Services.prefs.getBoolPref(PREFS.FILTER.LOG),
net: Services.prefs.getBoolPref(PREFS.FILTER.NET),
netxhr: Services.prefs.getBoolPref(PREFS.FILTER.NETXHR),
}),
ui: new UiState({
filterBarVisible: Services.prefs.getBoolPref(PREFS.UI.FILTER_BAR),
})
};

Expand All @@ -45,7 +52,7 @@ function enableBatching() {
return next => (reducer, initialState, enhancer) => {
function batchingReducer(state, action) {
switch (action.type) {
case constants.BATCH_ACTIONS:
case BATCH_ACTIONS:
return action.actions.reduce(batchingReducer, state);
default:
return reducer(state, action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ support-files =
!/devtools/client/framework/test/shared-head.js
test-console-table.html
test-console.html
test-console-filters.html

[browser_webconsole_console_table.js]
[browser_webconsole_filters.js]
[browser_webconsole_init.js]
[browser_webconsole_input_focus.js]
[browser_webconsole_observer_notifications.js]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests filters.

"use strict";

const { MESSAGE_LEVEL } = require("devtools/client/webconsole/new-console-output/constants");

const TEST_URI = "http://example.com/browser/devtools/client/webconsole/new-console-output/test/mochitest/test-console-filters.html";

add_task(function* () {
let hud = yield openNewTabAndConsole(TEST_URI);
const outputNode = hud.ui.experimentalOutputNode;

const toolbar = yield waitFor(() => {
return outputNode.querySelector(".webconsole-filterbar-primary");
});
ok(toolbar, "Toolbar found");

// Show the filter bar
toolbar.querySelector(".devtools-filter-icon").click();
const filterBar = yield waitFor(() => {
return outputNode.querySelector(".webconsole-filterbar-secondary");
});
ok(filterBar, "Filter bar is shown when filter icon is clicked.");

// Check defaults.
Object.values(MESSAGE_LEVEL).forEach(level => {
ok(filterIsEnabled(filterBar.querySelector(`.${level}`)),
`Filter button for ${level} is on by default`);
});
["net", "netxhr"].forEach(category => {
ok(!filterIsEnabled(filterBar.querySelector(`.${category}`)),
`Filter button for ${category} is off by default`);
});

// Check that messages are shown as expected. This depends on cached messages being
// shown.
ok(findMessages(hud, "").length == 5,
"Messages of all levels shown when filters are on.");

// Check that messages are not shown when their filter is turned off.
filterBar.querySelector(".error").click();
yield waitFor(() => findMessages(hud, "").length == 4);
ok(true, "When a filter is turned off, its messages are not shown.");

// Check that the ui settings were persisted.
yield closeTabAndToolbox();
yield testFilterPersistence();
});

function filterIsEnabled(button) {
return button.classList.contains("checked");
}

function* testFilterPersistence() {
let hud = yield openNewTabAndConsole(TEST_URI);
const outputNode = hud.ui.experimentalOutputNode;
const filterBar = yield waitFor(() => {
return outputNode.querySelector(".webconsole-filterbar-secondary");
});
ok(filterBar, "Filter bar ui setting is persisted.");

// Check that the filter settings were persisted.
ok(!filterIsEnabled(filterBar.querySelector(".error")),
"Filter button setting is persisted");
ok(findMessages(hud, "").length == 4,
"Messages of all levels shown when filters are on.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,25 @@ function* waitFor(condition, message = "waitFor", interval = 100, maxTries = 50)
* The selector to use in finding the message.
*/
function findMessage(hud, text, selector = ".message") {
const elements = findMessages(hud, text, selector);
return elements.pop();
}

/**
* Find multiple messages in the output.
*
* @param object hud
* The web console.
* @param string text
* A substring that can be found in the message.
* @param selector [optional]
* The selector to use in finding the message.
*/
function findMessages(hud, text, selector = ".message") {
const messages = hud.ui.experimentalOutputNode.querySelectorAll(selector);
const elements = Array.prototype.filter.call(
hud.ui.experimentalOutputNode.querySelectorAll(selector),
messages,
(el) => el.textContent.includes(text)
);
return elements.length > 0 ? elements.pop() : false;
return elements;
}
Loading

0 comments on commit 071543f

Please sign in to comment.