From 46d58cb8f85cda19c6b0579d5347b8175e9d95dc Mon Sep 17 00:00:00 2001 From: Jan Odvarko Date: Tue, 2 May 2017 17:27:15 +0200 Subject: [PATCH] Bug 1361270 - Search also within net logs; r=nchevobbe MozReview-Commit-ID: FTs2tJicTXC --HG-- extra : rebase_source : de14051242a9ed44b763e653d1b9a15b69a8c79a --- .../new-console-output/selectors/messages.js | 96 +++++++++++++------ 1 file changed, 68 insertions(+), 28 deletions(-) diff --git a/devtools/client/webconsole/new-console-output/selectors/messages.js b/devtools/client/webconsole/new-console-output/selectors/messages.js index 47a5e611529f..c522ec3a04d1 100644 --- a/devtools/client/webconsole/new-console-output/selectors/messages.js +++ b/devtools/client/webconsole/new-console-output/selectors/messages.js @@ -113,36 +113,14 @@ function matchSearchFilters(message, filters) { || isTextInParameters(text, message.parameters) // Look for a match in location. || isTextInFrame(text, message.frame) - // Look for a match in stacktrace. - || ( - Array.isArray(message.stacktrace) && - message.stacktrace.some(frame => isTextInFrame(text, - // isTextInFrame expect the properties of the frame object to be in the same - // order they are rendered in the Frame component. - { - functionName: frame.functionName || - l10n.getStr("stacktrace.anonymousFunction"), - filename: frame.filename, - lineNumber: frame.lineNumber, - columnNumber: frame.columnNumber - })) - ) + // Look for a match in net events. + || isTextInNetEvent(text, message.request) + // Look for a match in stack-trace. + || isTextInStackTrace(text, message.stacktrace) // Look for a match in messageText. - || (message.messageText && - message.messageText.toLocaleLowerCase().includes(text.toLocaleLowerCase())) - // Look for a match in parameters. Currently only checks value grips. - || (message.parameters && - message.parameters.join("").toLocaleLowerCase() - .includes(text.toLocaleLowerCase())) + || isTextInMessageText(text, message.messageText) // Look for a match in notes. - || (Array.isArray(message.notes) && message.notes.some(note => - // Look for a match in location. - isTextInFrame(text, note.frame) - // Look for a match in messageBody. - || (note.messageBody && - note.messageBody.toLocaleLowerCase() - .includes(text.toLocaleLowerCase())) - )) + || isTextInNotes(text, message.notes) ); } @@ -173,6 +151,68 @@ function isTextInParameters(text, parameters) { ); } +/** + * Returns true if given text is included in provided net event grip. + */ +function isTextInNetEvent(text, request) { + if (!request) { + return false; + } + + text = text.toLocaleLowerCase(); + + let method = request.method.toLocaleLowerCase(); + let url = request.url.toLocaleLowerCase(); + return method.includes(text) || url.includes(text); +} + +/** + * Returns true if given text is included in provided stack trace. + */ +function isTextInStackTrace(text, stacktrace) { + if (!Array.isArray(stacktrace)) { + return false; + } + + // isTextInFrame expect the properties of the frame object to be in the same + // order they are rendered in the Frame component. + return stacktrace.some(frame => isTextInFrame(text, { + functionName: frame.functionName || l10n.getStr("stacktrace.anonymousFunction"), + filename: frame.filename, + lineNumber: frame.lineNumber, + columnNumber: frame.columnNumber + })); +} + +/** + * Returns true if given text is included in `messageText` field. + */ +function isTextInMessageText(text, messageText) { + if (!messageText) { + return false; + } + + return messageText.toLocaleLowerCase().includes(text.toLocaleLowerCase()); +} + +/** + * Returns true if given text is included in notes. + */ +function isTextInNotes(text, notes) { + if (!Array.isArray(notes)) { + return false; + } + + return notes.some(note => + // Look for a match in location. + isTextInFrame(text, note.frame) || + // Look for a match in messageBody. + (note.messageBody && + note.messageBody.toLocaleLowerCase() + .includes(text.toLocaleLowerCase())) + ); +} + /** * Get a flat array of all the grips and their properties. *