From af87cdc51e2c3431f5257321ff30f3d348c37123 Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Tue, 12 Oct 2010 12:13:21 -0700 Subject: [PATCH] Bug 589162 - CSS filtering on the console does not work r=sdwilsh a=betaN+ --- .../console/hudservice/HUDService.jsm | 8 ++- .../hudservice/tests/browser/Makefile.in | 1 + ...rowser_webconsole_bug_589162_css_filter.js | 57 +++++++++++++++++++ .../console/hudservice/tests/browser/head.js | 45 +++++++++++++-- 4 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_589162_css_filter.js diff --git a/toolkit/components/console/hudservice/HUDService.jsm b/toolkit/components/console/hudservice/HUDService.jsm index d93937bf8aa..e65a77817ad 100644 --- a/toolkit/components/console/hudservice/HUDService.jsm +++ b/toolkit/components/console/hudservice/HUDService.jsm @@ -4688,8 +4688,12 @@ LogMessage.prototype = { this.messageNode.appendChild(messageTxtNode); - var klass = "hud-msg-node hud-" + this.level; - this.messageNode.setAttribute("class", klass); + this.messageNode.classList.add("hud-msg-node"); + this.messageNode.classList.add("hud-" + this.level); + + if (this.activityObject.category == "CSS Parser") { + this.messageNode.classList.add("hud-cssparser"); + } var self = this; diff --git a/toolkit/components/console/hudservice/tests/browser/Makefile.in b/toolkit/components/console/hudservice/tests/browser/Makefile.in index caef2ecc3b8..dad429ff475 100644 --- a/toolkit/components/console/hudservice/tests/browser/Makefile.in +++ b/toolkit/components/console/hudservice/tests/browser/Makefile.in @@ -91,6 +91,7 @@ _BROWSER_TEST_FILES = \ browser_webconsole_netlogging.js \ browser_webconsole_bug_583816_tab_focus.js \ browser_webconsole_bug_594477_clickable_output.js \ + browser_webconsole_bug_589162_css_filter.js \ head.js \ $(NULL) diff --git a/toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_589162_css_filter.js b/toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_589162_css_filter.js new file mode 100644 index 00000000000..b1fa44b0ecb --- /dev/null +++ b/toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_589162_css_filter.js @@ -0,0 +1,57 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/* ***** BEGIN LICENSE BLOCK ***** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + * + * Contributor(s): + * Mihai Șucan + * + * ***** END LICENSE BLOCK ***** */ + +const TEST_URI = "data:text/html,
test CSS parser filter
" + +function onContentLoaded() +{ + browser.removeEventListener("load", arguments.callee, true); + + let HUD = HUDService.getDisplayByURISpec(content.location.href); + let hudId = HUD.getAttribute("id"); + let filterBox = HUD.querySelector(".hud-filter-box"); + let outputNode = HUD.querySelector(".hud-output-node"); + + let warningFound = "the unknown CSS property warning is displayed"; + let warningNotFound = "could not find the unknown CSS property warning"; + + testLogEntry(outputNode, "foobarCssParser", + { success: warningFound, err: warningNotFound }, true); + + HUDService.setFilterState(hudId, "cssparser", false); + + warningNotFound = "the unknown CSS property warning is not displayed, " + + "after filtering"; + warningFound = "the unknown CSS property warning is still displayed, " + + "after filtering"; + + testLogEntry(outputNode, "foobarCssParser", + { success: warningNotFound, err: warningFound }, true, true); + + finishTest(); +} + +/** + * Unit test for bug 589162: + * CSS filtering on the console does not work + */ +function test() +{ + addTab(TEST_URI); + browser.addEventListener("load", function() { + browser.removeEventListener("load", arguments.callee, true); + + openConsole(); + browser.addEventListener("load", onContentLoaded, true); + content.location.reload(); + }, true); +} + diff --git a/toolkit/components/console/hudservice/tests/browser/head.js b/toolkit/components/console/hudservice/tests/browser/head.js index 5980f9d8deb..ab206fd19a1 100644 --- a/toolkit/components/console/hudservice/tests/browser/head.js +++ b/toolkit/components/console/hudservice/tests/browser/head.js @@ -20,6 +20,7 @@ * * Contributor(s): * David Dahl + * Mihai Șucan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -69,14 +70,50 @@ function addTab(aURL) browser = gBrowser.getBrowserForTab(tab); } -function testLogEntry(aOutputNode, aMatchString, aSuccessErrObj) +/** + * Check if a log entry exists in the HUD output node. + * + * @param {Element} aOutputNode + * the HUD output node. + * @param {string} aMatchString + * the string you want to check if it exists in the output node. + * @param {boolean} [aOnlyVisible=false] + * find only messages that are visible, not hidden by the filter. + * @param {boolean} [aFailIfFound=false] + * fail the test if the string is found in the output node. + */ +function testLogEntry(aOutputNode, aMatchString, aSuccessErrObj, aOnlyVisible, + aFailIfFound) { - var message = aOutputNode.textContent.indexOf(aMatchString); + let found = true; + let notfound = false; + let foundMsg = aSuccessErrObj.success; + let notfoundMsg = aSuccessErrObj.err; + + if (aFailIfFound) { + found = false; + notfound = true; + foundMsg = aSuccessErrObj.err; + notfoundMsg = aSuccessErrObj.success; + } + + let selector = ".hud-group > *"; + + // Skip entries that are hidden by the filter. + if (aOnlyVisible) { + selector += ":not(.hud-filtered-by-type)"; + } + + let msgs = aOutputNode.querySelectorAll(selector); + for (let i = 0, n = msgs.length; i < n; i++) { + let message = msgs[i].textContent.indexOf(aMatchString); if (message > -1) { - ok(true, aSuccessErrObj.success); + ok(found, foundMsg); return; } - ok(false, aSuccessErrObj.err); + } + + ok(notfound, notfoundMsg); } function openConsole()