Bug 1463057 - Fix expanding object in console.error message; r=Honza. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Mon, 21 May 2018 12:02:12 +0200
changeset 798088 be63fb2764ed97864bfe4cccf03d336df46de4db
parent 797960 a23b4e769ce042895cd9d743384b9603041fd612
push id110673
push userbmo:nchevobbe@mozilla.com
push dateTue, 22 May 2018 12:12:57 +0000
reviewersHonza
bugs1463057
milestone62.0a1
Bug 1463057 - Fix expanding object in console.error message; r=Honza. There was a race between the fetching of the object properties and the expansion of the stacktrace of the console.error message. In the end, the message was re-rendered, without the object being expanded. To prevent such thing, we stop the propagation of the click on the Tree node. Here the fix is done directly in the Reps bundle so it can be applied on beta, without unrelated code changes we'd have if doing a full bundle release. The fix will be backported to the Tree components so it's included in the bundle on the next reps release. A test is added to make sure we don't regress this. MozReview-Commit-ID: Di8YxJ7P1Wl
devtools/client/shared/components/reps/reps.js
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_webconsole_console_error_expand_object.js
--- a/devtools/client/shared/components/reps/reps.js
+++ b/devtools/client/shared/components/reps/reps.js
@@ -4412,16 +4412,17 @@ class Tree extends Component {
           // Since the user just clicked the node, there's no need to check if
           // it should be scrolled into view.
           this._focus(item, { preventAutoScroll: true });
           if (this.props.isExpanded(item)) {
             this.props.onCollapse(item);
           } else {
             this.props.onExpand(item, e.altKey);
           }
+          e.stopPropagation();
         }
       });
     });
 
     const style = Object.assign({}, this.props.style || {}, {
       padding: 0,
       margin: 0
     });
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -240,16 +240,17 @@ tags = mcb
 [browser_webconsole_close_unfocused_window.js]
 [browser_webconsole_closing_after_completion.js]
 [browser_webconsole_close_sidebar.js]
 [browser_webconsole_closure_inspection.js]
 skip-if = true # Bug 1405250
 [browser_webconsole_console_api_iframe.js]
 [browser_webconsole_console_dir.js]
 [browser_webconsole_console_dir_uninspectable.js]
+[browser_webconsole_console_error_expand_object.js]
 [browser_webconsole_console_group.js]
 [browser_webconsole_console_logging_workers_api.js]
 [browser_webconsole_console_table.js]
 [browser_webconsole_console_trace_duplicates.js]
 [browser_webconsole_context_menu_copy_entire_message.js]
 subsuite = clipboard
 skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
 [browser_webconsole_context_menu_copy_link_location.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_console_error_expand_object.js
@@ -0,0 +1,27 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Check console.error calls with expandable object.
+const TEST_URI = "data:text/html;charset=utf8,<h1>test console.error with objects</h1>";
+
+add_task(async function() {
+  let toolbox = await openNewTabAndToolbox(TEST_URI, "webconsole");
+  let hud = toolbox.getCurrentPanel().hud;
+
+  const onMessagesLogged = waitForMessage(hud, "myError");
+  ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+    content.wrappedJSObject.console.error("myError", {a: "a", b: "b"});
+  });
+  const {node} = await onMessagesLogged;
+
+  let objectInspectors = [...node.querySelectorAll(".tree")];
+  is(objectInspectors.length, 1, "There is the expected number of object inspectors");
+  const [oi] = objectInspectors;
+  oi.querySelector(".node .arrow").click();
+  await waitFor(() => oi.querySelectorAll(".node").length > 1);
+  ok(true, "The object can be expanded");
+});