Bug 632817 - Cannot filter search for NET events in the Web console;

f=pwalton,mihai.sucan r=sdwilsh approval2.0=beltzner - Backed out
changeset e949d8f936f9, a=#developers
This commit is contained in:
Rob Campbell 2011-02-22 13:45:25 -04:00
parent f5134f8541
commit a5f6869993
3 changed files with 56 additions and 236 deletions

View File

@ -1606,25 +1606,36 @@ HUD_SERVICE.prototype =
},
/**
* Check that the passed string matches the filter arguments.
* Returns the source code of the XPath contains() function necessary to
* match the given query string.
*
* @param String aString
* to search for filter words in.
* @param String aFilter
* is a string containing all of the words to filter on.
* @returns boolean
* @param string The query string to convert.
* @returns string
*/
stringMatchesFilters: function stringMatchesFilters(aString, aFilter)
buildXPathFunctionForString: function HS_buildXPathFunctionForString(aStr)
{
if (!aFilter || !aString) {
return true;
let words = aStr.split(/\s+/), results = [];
for (let i = 0; i < words.length; i++) {
let word = words[i];
if (word === "") {
continue;
}
let result;
if (word.indexOf('"') === -1) {
result = '"' + word + '"';
}
else if (word.indexOf("'") === -1) {
result = "'" + word + "'";
}
else {
result = 'concat("' + word.replace(/"/g, "\", '\"', \"") + '")';
}
results.push("contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), " + result.toLowerCase() + ")");
}
let searchStr = aString.toLowerCase();
let filterStrings = aFilter.toLowerCase().split(/\s+/);
return !filterStrings.some(function (f) {
return searchStr.indexOf(f) == -1;
});
return (results.length === 0) ? "true()" : results.join(" and ");
},
/**
@ -1640,25 +1651,31 @@ HUD_SERVICE.prototype =
adjustVisibilityOnSearchStringChange:
function HS_adjustVisibilityOnSearchStringChange(aHUDId, aSearchString)
{
let fn = this.buildXPathFunctionForString(aSearchString);
let displayNode = this.getOutputNodeById(aHUDId);
let outputNode = displayNode.querySelector(".hud-output-node");
let doc = outputNode.ownerDocument;
let nodes = outputNode.querySelectorAll(".hud-msg-node");
// Look for message nodes ("hud-msg-node") that *aren't* filtered and
// that don't contain the string, and hide them.
let xpath = './/*[contains(@class, "hud-msg-node") and ' +
'not(contains(@class, "hud-filtered-by-string")) and not(' + fn + ')]';
let result = doc.evaluate(xpath, outputNode, null,
Ci.nsIDOMXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0; i < result.snapshotLength; i++) {
let node = result.snapshotItem(i);
node.classList.add("hud-filtered-by-string");
}
for (let i = 0; i < nodes.length; ++i) {
let node = nodes[i];
// hide nodes that match the strings
let text = node.clipboardText;
// if the text matches the words in aSearchString...
if (this.stringMatchesFilters(text, aSearchString)) {
node.classList.remove("hud-filtered-by-string");
}
else {
node.classList.add("hud-filtered-by-string");
}
// Look for message nodes ("hud-msg-node") that *are* filtered and that
// *do* contain the string, and unhide them.
xpath = './/*[contains(@class, "hud-msg-node") and contains(@class, ' +
'"hud-filtered-by-string") and ' + fn + ']';
result = doc.evaluate(xpath, outputNode, null,
Ci.nsIDOMXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0; i < result.snapshotLength; i++) {
let node = result.snapshotItem(i);
node.classList.remove("hud-filtered-by-string");
}
this.regroupOutput(outputNode);
@ -5066,21 +5083,23 @@ ConsoleUtils = {
* The ID of the HUD which this node is to be inserted into.
*/
filterMessageNode: function(aNode, aHUDId) {
// Filter on the search string.
let search = HUDService.getFilterStringByHUDId(aHUDId);
let xpath = ".[" + HUDService.buildXPathFunctionForString(search) + "]";
let doc = aNode.ownerDocument;
let result = doc.evaluate(xpath, aNode, null,
Ci.nsIDOMXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
if (result.snapshotLength == 0) {
// The string filter didn't match, so the node is filtered.
aNode.classList.add("hud-filtered-by-string");
}
// Filter by the message type.
let prefKey = MESSAGE_PREFERENCE_KEYS[aNode.category][aNode.severity];
if (prefKey && !HUDService.getFilterState(aHUDId, prefKey)) {
// The node is filtered by type.
aNode.classList.add("hud-filtered-by-type");
}
// Filter on the search string.
let search = HUDService.getFilterStringByHUDId(aHUDId);
let text = aNode.clipboardText;
// if string matches the filter text
if (!HUDService.stringMatchesFilters(text, search)) {
aNode.classList.add("hud-filtered-by-string");
}
},
/**

View File

@ -122,7 +122,6 @@ _BROWSER_TEST_FILES = \
browser_webconsole_bug_613280_jsterm_copy.js \
browser_webconsole_bug_630733_response_redirect_headers.js \
browser_webconsole_bug_621644_jsterm_dollar.js \
browser_webconsole_bug_632817.js \
head.js \
$(NULL)

View File

@ -1,198 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that network log messages bring up the network panel.
const TEST_NETWORK_REQUEST_URI = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-network-request.html";
const TEST_IMG = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-image.png";
const TEST_DATA_JSON_CONTENT =
'{ id: "test JSON data", myArray: [ "foo", "bar", "baz", "biff" ] }';
let lastRequest = null;
let requestCallback = null;
function test()
{
addTab("data:text/html,Web Console network logging tests");
browser.addEventListener("load", function() {
browser.removeEventListener("load", arguments.callee, true);
openConsole();
is(HUDService.displaysIndex().length, 1, "Web Console was opened");
hudId = HUDService.displaysIndex()[0];
hud = HUDService.getHeadsUpDisplay(hudId);
HUDService.lastFinishedRequestCallback = function(aRequest) {
lastRequest = aRequest;
if (requestCallback) {
requestCallback();
}
};
executeSoon(testPageLoad);
}, true);
}
function testPageLoad()
{
browser.addEventListener("load", function(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
// Check if page load was logged correctly.
ok(lastRequest, "Page load was logged");
is(lastRequest.url, TEST_NETWORK_REQUEST_URI,
"Logged network entry is page load");
is(lastRequest.method, "GET", "Method is correct");
lastRequest = null;
executeSoon(testPageLoadBody);
}, true);
content.location = TEST_NETWORK_REQUEST_URI;
}
function testPageLoadBody()
{
// Turn on logging of request bodies and check again.
HUDService.saveRequestAndResponseBodies = true;
browser.addEventListener("load", function(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
ok(lastRequest, "Page load was logged again");
is(lastRequest.response.body.indexOf("<!DOCTYPE HTML>"), 0,
"Response body's beginning is okay");
lastRequest = null;
executeSoon(testXhrGet);
}, true);
content.location.reload();
}
function testXhrGet()
{
requestCallback = function() {
ok(lastRequest, "testXhrGet() was logged");
is(lastRequest.method, "GET", "Method is correct");
is(lastRequest.request.body, null, "No request body was sent");
is(lastRequest.response.body, TEST_DATA_JSON_CONTENT,
"Response is correct");
lastRequest = null;
requestCallback = null;
executeSoon(testXhrPost);
};
// Start the XMLHttpRequest() GET test.
content.wrappedJSObject.testXhrGet();
}
function testXhrPost()
{
requestCallback = function() {
ok(lastRequest, "testXhrPost() was logged");
is(lastRequest.method, "POST", "Method is correct");
is(lastRequest.request.body, "Hello world!",
"Request body was logged");
is(lastRequest.response.body, TEST_DATA_JSON_CONTENT,
"Response is correct");
lastRequest = null;
requestCallback = null;
executeSoon(testFormSubmission);
};
// Start the XMLHttpRequest() POST test.
content.wrappedJSObject.testXhrPost();
}
function testFormSubmission()
{
// Start the form submission test. As the form is submitted, the page is
// loaded again. Bind to the load event to catch when this is done.
browser.addEventListener("load", function(aEvent) {
browser.removeEventListener(aEvent.type, arguments.callee, true);
ok(lastRequest, "testFormSubmission() was logged");
is(lastRequest.method, "POST", "Method is correct");
isnot(lastRequest.request.body.
indexOf("Content-Type: application/x-www-form-urlencoded"), -1,
"Content-Type is correct");
isnot(lastRequest.request.body.
indexOf("Content-Length: 20"), -1, "Content-length is correct");
isnot(lastRequest.request.body.
indexOf("name=foo+bar&age=144"), -1, "Form data is correct");
ok(lastRequest.response.body.indexOf("<!DOCTYPE HTML>") == 0,
"Response body's beginning is okay");
executeSoon(testLiveFilteringOnSearchStrings);
}, true);
let form = content.document.querySelector("form");
ok(form, "we have the HTML form");
form.submit();
}
function testLiveFilteringOnSearchStrings() {
browser.removeEventListener("DOMContentLoaded",
testLiveFilteringOnSearchStrings, false);
setStringFilter("http");
isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
"search string is set to \"http\"");
setStringFilter("HTTP");
isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
"search string is set to \"HTTP\"");
setStringFilter("hxxp");
is(countMessageNodes(), 0, "the log nodes are hidden when the search " +
"string is set to \"hxxp\"");
setStringFilter("ht tp");
isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
"search string is set to \"ht tp\"");
setStringFilter("");
isnot(countMessageNodes(), 0, "the log nodes are not hidden when the " +
"search string is removed");
setStringFilter("json");
is(countMessageNodes(), 2, "the log nodes show only the nodes with \"json\"");
setStringFilter("'foo'");
is(countMessageNodes(), 0, "the log nodes are hidden when searching for " +
"the string 'foo'");
setStringFilter("foo\"bar'baz\"boo'");
is(countMessageNodes(), 0, "the log nodes are hidden when searching for " +
"the string \"foo\"bar'baz\"boo'\"");
finishTest();
}
function countMessageNodes() {
let outputNode = hud.querySelector(".hud-output-node");
let messageNodes = outputNode.querySelectorAll(".hud-msg-node");
let displayedMessageNodes = 0;
let view = outputNode.ownerDocument.defaultView;
for (let i = 0; i < messageNodes.length; i++) {
let computedStyle = view.getComputedStyle(messageNodes[i], null);
if (computedStyle.display !== "none")
displayedMessageNodes++;
}
return displayedMessageNodes;
}
function setStringFilter(aValue)
{
hud.querySelector(".hud-filter-box").value = aValue;
HUDService.adjustVisibilityOnSearchStringChange(hudId, aValue);
}