Bug 987310 - Sanitize the filter predicates loaded from the preferences, r=rcampbell

This commit is contained in:
Victor Porof 2014-03-24 15:39:18 -04:00
parent 153d382b05
commit c03a50ef4f
3 changed files with 61 additions and 12 deletions

View File

@ -699,6 +699,11 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
* "flash" or "other".
*/
_enableFilter: function (aType) {
// Make sure this is a valid filter type.
if (Object.keys(this._allFilterPredicates).indexOf(aType) == -1) {
return;
}
// Add the filter to the list of active filters.
this._activeFilters.push(aType);
@ -717,18 +722,7 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
* the active filters.
*/
get _filterPredicate() {
let filterPredicates = {
"all": () => true,
"html": this.isHtml,
"css": this.isCss,
"js": this.isJs,
"xhr": this.isXHR,
"fonts": this.isFont,
"images": this.isImage,
"media": this.isMedia,
"flash": this.isFlash,
"other": this.isOther
};
let filterPredicates = this._allFilterPredicates;
if (this._activeFilters.length === 1) {
// The simplest case: only one filter active.
@ -743,6 +737,22 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
}
},
/**
* Returns an object with all the filter predicates as [key: function] pairs.
*/
get _allFilterPredicates() ({
all: () => true,
html: this.isHtml,
css: this.isCss,
js: this.isJs,
xhr: this.isXHR,
fonts: this.isFont,
images: this.isImage,
media: this.isMedia,
flash: this.isFlash,
other: this.isOther
}),
/**
* Sorts all network requests in this container by a specified detail.
*

View File

@ -50,6 +50,7 @@ support-files =
[browser_net_filter-01.js]
[browser_net_filter-02.js]
[browser_net_filter-03.js]
[browser_net_filter-04.js]
[browser_net_footer-summary.js]
[browser_net_html-preview.js]
[browser_net_icon-preview.js]

View File

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if invalid filter types are sanitized when loaded from the preferences.
*/
function test() {
Services.prefs.setCharPref("devtools.netmonitor.filters", '["js", "bogus"]');
initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => {
info("Starting test... ");
let { Prefs } = aMonitor.panelWin;
is(Prefs.filters.length, 2,
"All filter types were loaded as an array from the preferences.");
is(Prefs.filters[0], "js",
"The first filter type is correct.");
is(Prefs.filters[1], "bogus",
"The second filter type is invalid, but loaded anyway.");
waitForNetworkEvents(aMonitor, 7).then(() => {
testFilterButtons(aMonitor, "js");
ok(true, "Only the correct filter type was taken into consideration.");
teardown(aMonitor).then(() => {
let filters = Services.prefs.getCharPref("devtools.netmonitor.filters");
is(filters, '["js"]',
"The bogus filter type was ignored and removed from the preferences.");
finish();
});
});
aDebuggee.performRequests('{ "getMedia": true, "getFlash": true }');
});
}