From 0427e04da4496add340037f6ceb6aa4615ffe2b9 Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Thu, 2 May 2013 18:21:45 +0300 Subject: [PATCH] Bug 865288 - Do not count console.log messages with different objects as repeats; r=past --- browser/devtools/webconsole/test/Makefile.in | 1 + ...ser_bug_865288_repeat_different_objects.js | 82 +++++++++++++++++++ browser/devtools/webconsole/test/head.js | 25 ++++++ .../test/test-repeated-messages.html | 8 +- browser/devtools/webconsole/webconsole.js | 3 + 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 browser/devtools/webconsole/test/browser_bug_865288_repeat_different_objects.js diff --git a/browser/devtools/webconsole/test/Makefile.in b/browser/devtools/webconsole/test/Makefile.in index 823c5bff2210..c5e0de8f79f6 100644 --- a/browser/devtools/webconsole/test/Makefile.in +++ b/browser/devtools/webconsole/test/Makefile.in @@ -124,6 +124,7 @@ MOCHITEST_BROWSER_FILES = \ browser_console_consolejsm_output.js \ browser_webconsole_bug_837351_securityerrors.js \ browser_bug_865871_variables_view_close_on_esc_key.js \ + browser_bug_865288_repeat_different_objects.js \ head.js \ $(NULL) diff --git a/browser/devtools/webconsole/test/browser_bug_865288_repeat_different_objects.js b/browser/devtools/webconsole/test/browser_bug_865288_repeat_different_objects.js new file mode 100644 index 000000000000..df3335082396 --- /dev/null +++ b/browser/devtools/webconsole/test/browser_bug_865288_repeat_different_objects.js @@ -0,0 +1,82 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Tests that makes sure messages are not considered repeated when console.log() +// is invoked with different objects, see bug 865288. + +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-repeated-messages.html"; + +let hud = null; + +function test() { + addTab(TEST_URI); + browser.addEventListener("load", function onLoad() { + browser.removeEventListener("load", onLoad, true); + openConsole(null, consoleOpened); + }, true); +} + +function consoleOpened(aHud) { + hud = aHud; + + // Check that css warnings are not coalesced if they come from different lines. + info("waiting for 3 console.log objects"); + + hud.jsterm.clearOutput(true); + content.wrappedJSObject.testConsoleObjects(); + + waitForMessages({ + webconsole: hud, + messages: [{ + name: "3 console.log messages", + text: "abba", + category: CATEGORY_WEBDEV, + severity: SEVERITY_LOG, + count: 3, + repeats: 1, + objects: true, + }], + }).then(checkMessages); +} + +function checkMessages(aResults) +{ + let result = aResults[0]; + let msgs = [...result.matched]; + is(msgs.length, 3, "3 message elements"); + let m = -1; + + function nextMessage() + { + let msg = msgs[++m]; + if (msg) { + ok(msg, "message element #" + m); + + let clickable = msg.querySelector(".hud-clickable"); + ok(clickable, "clickable object #" + m); + + scrollOutputToNode(msg); + clickObject(clickable); + } + else { + finishTest(); + } + } + + nextMessage(); + + function clickObject(aObject) + { + hud.jsterm.once("variablesview-fetched", onObjectFetch); + EventUtils.synthesizeMouse(aObject, 2, 2, {}, hud.iframeWindow); + } + + function onObjectFetch(aEvent, aVar) + { + findVariableViewProperties(aVar, [ + { name: "id", value: "abba" + m }, + ], { webconsole: hud }).then(nextMessage); + } +} diff --git a/browser/devtools/webconsole/test/head.js b/browser/devtools/webconsole/test/head.js index 29cb89843fb2..a379387f2b30 100644 --- a/browser/devtools/webconsole/test/head.js +++ b/browser/devtools/webconsole/test/head.js @@ -869,6 +869,8 @@ function getMessageElementText(aElement) * Properties: * - text: string or RegExp to match the textContent of each new * message. + * - noText: string or RegExp that must not match in the message + * textContent. * - repeats: the number of message repeats, as displayed by the Web * Console. * - category: match message category. See CATEGORY_* constants at @@ -877,8 +879,31 @@ function getMessageElementText(aElement) * the top of this file. * - count: how many unique web console messages should be matched by * this rule. + * - consoleTrace: boolean, set to |true| to match a console.trace() + * message. Optionally this can be an object of the form + * { file, fn, line } that can match the specified file, function + * and/or line number in the trace message. + * - consoleTime: string that matches a console.time() timer name. + * Provide this if you want to match a console.time() message. + * - consoleTimeEnd: same as above, but for console.timeEnd(). + * - consoleDir: boolean, set to |true| to match a console.dir() + * message. + * - longString: boolean, set to |true} to match long strings in the + * message. + * - objects: boolean, set to |true| if you expect inspectable + * objects in the message. * @return object * A Promise object is returned once the messages you want are found. + * The promise is resolved with the array of rule objects you give in + * the |messages| property. Each objects is the same as provided, with + * additional properties: + * - matched: a Set of web console messages that matched the rule. + * - clickableElements: a list of inspectable objects. This is available + * if any of the following properties are present in the rule: + * |consoleTrace| or |objects|. + * - longStrings: a list of long string ellipsis elements you can click + * in the message element, to expand a long string. This is available + * only if |longString| is present in the matching rule. */ function waitForMessages(aOptions) { diff --git a/browser/devtools/webconsole/test/test-repeated-messages.html b/browser/devtools/webconsole/test/test-repeated-messages.html index 4e21a69d6c09..5bbc8fd5abc2 100644 --- a/browser/devtools/webconsole/test/test-repeated-messages.html +++ b/browser/devtools/webconsole/test/test-repeated-messages.html @@ -2,12 +2,18 @@ - Test for bugs 720180 and 800510 + Test for bugs 720180, 800510 and 865288