Bug 865288 - Do not count console.log messages with different objects as repeats; r=past
authorMihai Sucan <mihai.sucan@gmail.com>
Thu, 02 May 2013 18:21:45 +0300
changeset 141857 ac3547a7ed84eda24dbdad0c0e2cc84b901a6c03
parent 141856 253e46507c5773cbdf7c73249a17007c0ad7bd6c
child 141858 13475fab0883f541b2080607849339b9ef3b0c1b
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs865288
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 865288 - Do not count console.log messages with different objects as repeats; r=past
browser/devtools/webconsole/test/Makefile.in
browser/devtools/webconsole/test/browser_bug_865288_repeat_different_objects.js
browser/devtools/webconsole/test/head.js
browser/devtools/webconsole/test/test-repeated-messages.html
browser/devtools/webconsole/webconsole.js
--- a/browser/devtools/webconsole/test/Makefile.in
+++ b/browser/devtools/webconsole/test/Makefile.in
@@ -119,16 +119,17 @@ MOCHITEST_BROWSER_FILES = \
 	browser_eval_in_debugger_stackframe.js \
 	browser_console_variables_view.js \
 	browser_console_variables_view_while_debugging.js \
 	browser_console.js \
 	browser_longstring_hang.js \
 	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)
 
 ifeq ($(OS_ARCH), Darwin)
 MOCHITEST_BROWSER_FILES += \
 	browser_webconsole_bug_804845_ctrl_key_nav.js \
         $(NULL)
 endif
new file mode 100644
--- /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);
+  }
+}
--- a/browser/devtools/webconsole/test/head.js
+++ b/browser/devtools/webconsole/test/head.js
@@ -864,26 +864,51 @@ function getMessageElementText(aElement)
  *
  * @param object aOptions
  *        Options for what you want to wait for:
  *        - webconsole: the webconsole instance you work with.
  *        - messages: an array of objects that tells which messages to wait for.
  *        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
  *            the top of this file.
  *            - severity: match message severity. See SEVERITY_* constants at
  *            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)
 {
   gPendingOutputTest++;
   let webconsole = aOptions.webconsole;
   let rules = WebConsoleUtils.cloneObject(aOptions.messages, true);
   let rulesMatched = 0;
   let listenerAdded = false;
--- a/browser/devtools/webconsole/test/test-repeated-messages.html
+++ b/browser/devtools/webconsole/test/test-repeated-messages.html
@@ -1,18 +1,24 @@
 <!DOCTYPE HTML>
 <html dir="ltr" xml:lang="en-US" lang="en-US">
   <head>
     <meta charset="utf8">
-    <title>Test for bugs 720180 and 800510</title>
+    <title>Test for bugs 720180, 800510 and 865288</title>
     <script>
       function testConsole() {
         console.log("foo repeat"); console.log("foo repeat");
         console.log("foo repeat"); console.error("foo repeat");
       }
+      function testConsoleObjects() {
+        for (var i = 0; i < 3; i++) {
+          var o = { id: "abba" + i };
+          console.log("abba", o);
+        }
+      }
     </script>
     <style>
       body {
         background-image: foobarz;
       }
       p {
         background-image: foobarz;
       }
--- a/browser/devtools/webconsole/webconsole.js
+++ b/browser/devtools/webconsole/webconsole.js
@@ -1093,16 +1093,19 @@ WebConsoleFrame.prototype = {
     }
 
     let node = this.createMessageNode(CATEGORY_WEBDEV, LEVELS[level], body,
                                       sourceURL, sourceLine, clipboardText,
                                       level, aMessage.timeStamp);
 
     if (objectActors.size > 0) {
       node._objectActors = objectActors;
+
+      let repeatNode = node.querySelector(".webconsole-msg-repeat");
+      repeatNode._uid += [...objectActors].join("-");
     }
 
     // Make the node bring up the variables view, to allow the user to inspect
     // the stack trace.
     if (level == "trace") {
       node._stacktrace = aMessage.stacktrace;
 
       this.makeOutputMessageLink(node, () =>