Last Comment Bug 664131 - Expand console object with group methods that indent future console messages in order to create separate blocks of visually combined output
: Expand console object with group methods that indent future console messages ...
Status: RESOLVED FIXED
: dev-doc-complete
Product: Firefox
Classification: Client Software
Component: Developer Tools (show other bugs)
: Trunk
: All All
: -- normal (vote)
: Firefox 9
Assigned To: Panos Astithas [:past]
:
Mentors:
Depends on:
Blocks: 644596
  Show dependency treegraph
 
Reported: 2011-06-14 07:14 PDT by Panos Astithas [:past]
Modified: 2011-11-16 12:39 PST (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Patch v1 (12.19 KB, patch)
2011-06-14 08:56 PDT, Panos Astithas [:past]
no flags Details | Diff | Review
Patch v2 (16.07 KB, patch)
2011-06-15 03:00 PDT, Panos Astithas [:past]
mihai.sucan: review+
Details | Diff | Review
Patch v3 (15.58 KB, patch)
2011-06-16 07:51 PDT, Panos Astithas [:past]
no flags Details | Diff | Review
Patch v4 (10.98 KB, patch)
2011-07-20 03:05 PDT, Panos Astithas [:past]
no flags Details | Diff | Review
Patch v5 (10.82 KB, patch)
2011-07-27 06:41 PDT, Panos Astithas [:past]
no flags Details | Diff | Review
Patch v6 (16.58 KB, patch)
2011-08-04 08:52 PDT, Panos Astithas [:past]
gavin.sharp: review+
Details | Diff | Review
[in-fx-team] Patch v7 (24.57 KB, patch)
2011-09-26 02:32 PDT, Panos Astithas [:past]
no flags Details | Diff | Review

Description Panos Astithas [:past] 2011-06-14 07:14:16 PDT
As described in bug 644596, we have to implement the rest of the de-facto standard methods in the console object. This bug will track the work for the group, groupCollapsed and groupEnd methods.
Comment 1 Panos Astithas [:past] 2011-06-14 08:56:13 PDT
Created attachment 539220 [details] [diff] [review]
Patch v1

A simple implementation for group/groupEnd that does not allow collapsing the grouped messages.
Comment 2 Panos Astithas [:past] 2011-06-15 03:00:34 PDT
Created attachment 539467 [details] [diff] [review]
Patch v2

The simplest implementation possible. Proper group labels are displayed, new messages are indented as expected, but you can't collapse the groups, like you can in Firebug and WebKit Inspector. Group collapsing will be implemented in a followup bug. Here is a screencast showing this in action:

http://vimeo.com/25082943
Comment 3 Mihai Sucan [:msucan] 2011-06-15 04:26:19 PDT
Comment on attachment 539467 [details] [diff] [review]
Patch v2

Review of attachment 539467 [details] [diff] [review]:
-----------------------------------------------------------------

Good work!

Giving the patch r+, but please address the comments. Thank you!

::: dom/base/ConsoleAPI.js
@@ +186,5 @@
> +  /**
> +   * Begin a new group for logging output together.
> +   **/
> +  beginGroup: function CA_beginGroup() {
> +    this.groupDepth++;

This is unused.

Do we want to track this here? It's also tracked in HUDService.

@@ +187,5 @@
> +   * Begin a new group for logging output together.
> +   **/
> +  beginGroup: function CA_beginGroup() {
> +    this.groupDepth++;
> +    return Array.prototype.slice.call(arguments[0]).join(" ");

Why slice() then join()?

return Array.prototype.join.call(arguments[0], " ");

::: toolkit/components/console/hudservice/HUDService.jsm
@@ +5540,5 @@
>      // long multi-line messages.
>      let iconContainer = aDocument.createElementNS(XUL_NS, "xul:vbox");
>      iconContainer.classList.add("webconsole-msg-icon-container");
> +    // Apply the curent group by indenting appropriately.
> +    iconContainer.style.margin = "0 0 0 " + HUDService.groupDepth * GROUP_INDENT + "px";

You can change only iconContainer.style.marginLeft.

What happens when console.group() is called many times? I think you should limit how much marginLeft can grow, based on the richlistbox width. I was able to overflow the Web Console output with sufficient numerous calls to group().

::: toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_664131_console_group.js
@@ +24,5 @@
> +  content.console.group("a");
> +  findLogEntry("a");
> +  let msg = outputNode.querySelectorAll(".webconsole-msg-icon-container");
> +  is(msg.length, 1, "one message node displayed");
> +  is(msg[0].style.margin, "0pt 0pt 0pt " + GROUP_INDENT + "px", "correct group indent found");

Please only check style.marginLeft.
Comment 4 Panos Astithas [:past] 2011-06-16 07:51:16 PDT
Created attachment 539795 [details] [diff] [review]
Patch v3

(In reply to comment #3)
> Comment on attachment 539467 [details] [diff] [review] [review]
> Patch v2
> 
> Review of attachment 539467 [details] [diff] [review] [review]:
> -----------------------------------------------------------------
> 
> Good work!
> 
> Giving the patch r+, but please address the comments. Thank you!
> 
> ::: dom/base/ConsoleAPI.js
> @@ +186,5 @@
> > +  /**
> > +   * Begin a new group for logging output together.
> > +   **/
> > +  beginGroup: function CA_beginGroup() {
> > +    this.groupDepth++;
> 
> This is unused.
> 
> Do we want to track this here? It's also tracked in HUDService.

You are absolutely right. After the latest refactoring this is no longer needed. Removed.

> @@ +187,5 @@
> > +   * Begin a new group for logging output together.
> > +   **/
> > +  beginGroup: function CA_beginGroup() {
> > +    this.groupDepth++;
> > +    return Array.prototype.slice.call(arguments[0]).join(" ");
> 
> Why slice() then join()?
> 
> return Array.prototype.join.call(arguments[0], " ");

No reason. Fixed.

> ::: toolkit/components/console/hudservice/HUDService.jsm
> @@ +5540,5 @@
> >      // long multi-line messages.
> >      let iconContainer = aDocument.createElementNS(XUL_NS, "xul:vbox");
> >      iconContainer.classList.add("webconsole-msg-icon-container");
> > +    // Apply the curent group by indenting appropriately.
> > +    iconContainer.style.margin = "0 0 0 " + HUDService.groupDepth * GROUP_INDENT + "px";
> 
> You can change only iconContainer.style.marginLeft.

Ah yes, that simplifies things a bit.

> What happens when console.group() is called many times? I think you should
> limit how much marginLeft can grow, based on the richlistbox width. I was
> able to overflow the Web Console output with sufficient numerous calls to
> group().

The behavior is identical to what webkit and firebug do: when too many nested groups have been started, the console output grows larger and we get a horizontal scrollbar.

> :::
> toolkit/components/console/hudservice/tests/browser/
> browser_webconsole_bug_664131_console_group.js
> @@ +24,5 @@
> > +  content.console.group("a");
> > +  findLogEntry("a");
> > +  let msg = outputNode.querySelectorAll(".webconsole-msg-icon-container");
> > +  is(msg.length, 1, "one message node displayed");
> > +  is(msg[0].style.margin, "0pt 0pt 0pt " + GROUP_INDENT + "px", "correct group indent found");
> 
> Please only check style.marginLeft.

Done.

Thanks for the review!
Comment 5 Panos Astithas [:past] 2011-07-20 03:05:44 PDT
Created attachment 547021 [details] [diff] [review]
Patch v4

Rebased against latest fx-team repo.
Comment 6 Panos Astithas [:past] 2011-07-27 06:41:35 PDT
Created attachment 548761 [details] [diff] [review]
Patch v5

Rebased due to the creation of the new devtools module. This patch has already received an r+ from Mihai who is a devtools module peer, so Gavin, I think you only need to look at the dom/ bits, and perhaps more importantly, with your sr hat on.
Comment 7 :Gavin Sharp [email: gavin@gavinsharp.com] 2011-08-02 14:18:13 PDT
Comment on attachment 548761 [details] [diff] [review]
Patch v5

>diff --git a/browser/devtools/webconsole/HUDService.jsm b/browser/devtools/webconsole/HUDService.jsm

>   /**
>+   * The nesting depth of the currently active console group.
>+   */
>+  groupDepth: 0,

Won't tracking this globally mean that e.g. two tabs that are both calling group()/groupEnd() concurrently will interfere with each other? That doesn't seem desirable.
Comment 8 Panos Astithas [:past] 2011-08-04 08:52:47 PDT
Created attachment 550706 [details] [diff] [review]
Patch v6

(In reply to comment #7)
> Comment on attachment 548761 [details] [diff] [review] [diff] [details] [review]
> Patch v5
> 
> >diff --git a/browser/devtools/webconsole/HUDService.jsm b/browser/devtools/webconsole/HUDService.jsm
> 
> >   /**
> >+   * The nesting depth of the currently active console group.
> >+   */
> >+  groupDepth: 0,
> 
> Won't tracking this globally mean that e.g. two tabs that are both calling
> group()/groupEnd() concurrently will interfere with each other? That doesn't
> seem desirable.

You are absolutely right! This version stores the current depth in the HeadsUpDisplay object which is unique per tab. I also rebased the patch on top of the latest fx-team.
Comment 9 :Gavin Sharp [email: gavin@gavinsharp.com] 2011-08-10 18:21:12 PDT
Just a note for future reference - it would be ideal to generate patches with at least 8 lines of context. This patch in particular is rather sucky to review with the default 3 lines :) https://developer.mozilla.org/en/Installing_Mercurial#Configuration has some config examples.
Comment 10 :Gavin Sharp [email: gavin@gavinsharp.com] 2011-08-10 19:05:24 PDT
Comment on attachment 550706 [details] [diff] [review]
Patch v6

I don't think this is suitable either, since a HUD object is still shared amongst a top-level window and all of its child frames, so frames from different contexts can still interfere with each other. I think you'll need a solution similar to the one for bug 658368 (perhaps code can even be shared for storing per-window state like this).
Comment 11 Panos Astithas [:past] 2011-08-11 01:31:19 PDT
(In reply to Gavin Sharp from comment #9)
> Just a note for future reference - it would be ideal to generate patches
> with at least 8 lines of context. This patch in particular is rather sucky
> to review with the default 3 lines :)
> https://developer.mozilla.org/en/Installing_Mercurial#Configuration has some
> config examples.

Sorry about that, I'm using 3 lines of context (per jorendorff's suggestion) to reduce the merge conflicts with mq. I was just being lazy and uploaded the mq patch file as-is, instead of using hg diff to get 8 lines of context.

This is the relevant part of my configuration:

[defaults]
commit = -v
diff=-U 8 -p
qdiff=-U 8
qnew = -U

[diff]
git = 1
showfunc = 1
Comment 12 Rob Campbell [:rc] (:robcee) 2011-08-11 06:26:30 PDT
Panos, I suggested in bug 669658 that we do a manual qdiff -U 8 (looks like you've already got that set, goody!) for producing patches for review.
Comment 13 Panos Astithas [:past] 2011-08-14 02:08:22 PDT
(In reply to Gavin Sharp from comment #10)
> Comment on attachment 550706 [details] [diff] [review]
> Patch v6
> 
> I don't think this is suitable either, since a HUD object is still shared
> amongst a top-level window and all of its child frames, so frames from
> different contexts can still interfere with each other. I think you'll need
> a solution similar to the one for bug 658368 (perhaps code can even be
> shared for storing per-window state like this).

Let me see if I understand the failure scenario. Pointing two different tabs at http://htmlpad.org/group with consoles opened does not seem to cause interference in the grouping, after the fix in v6. That is, if you only click the outer button. On the other hand, clicking on the button in the iframe causes the log message grouping in the iframe to be dependent on the grouping level of the outer frame.

This however is consistent with what the other browsers are doing (tested on Chrome, Safari, Opera and Firebug). In my mind this makes sense, because the web console is visually connected to the tab, so I would expect console operations from anywhere in the tab's contents to be interfering with each other. I can see some benefits in treating iframes differently, but I'm not sure if this is worth the deviation from what the rest of the web is doing?
Comment 14 :Gavin Sharp [email: gavin@gavinsharp.com] 2011-08-16 17:19:43 PDT
Hmm, perhaps you're right. Seems odd that different frames can share that same state, but I guess that's never really a problem in practice (and only an annoyance even if it does somehow come up).
Comment 15 Panos Astithas [:past] 2011-09-16 09:38:23 PDT
(In reply to Gavin Sharp from comment #14)
> Hmm, perhaps you're right. Seems odd that different frames can share that
> same state, but I guess that's never really a problem in practice (and only
> an annoyance even if it does somehow come up).

Did you get a chance to think about this some more? Can we land this?
Comment 16 :Gavin Sharp [email: gavin@gavinsharp.com] 2011-09-23 17:46:56 PDT
Comment on attachment 550706 [details] [diff] [review]
Patch v6

Sure - you should feel free to poke me directly when I'm not responding to bugmail (I only just saw your question now).
Comment 17 Panos Astithas [:past] 2011-09-24 00:22:45 PDT
(In reply to Gavin Sharp from comment #16)
> Comment on attachment 550706 [details] [diff] [review] [diff] [details] [review]
> Patch v6
> 
> Sure - you should feel free to poke me directly when I'm not responding to
> bugmail (I only just saw your question now).

Will do, thanks!
Comment 18 Panos Astithas [:past] 2011-09-26 02:32:09 PDT
Created attachment 562386 [details] [diff] [review]
[in-fx-team] Patch v7

Rebased patch on top of latest fx-team.
Try submission results at:

https://tbpl.mozilla.org/?tree=Try&usebuildbot=1&rev=421c5376c30f
Comment 19 Rob Campbell [:rc] (:robcee) 2011-09-26 12:18:43 PDT
Comment on attachment 562386 [details] [diff] [review]
[in-fx-team] Patch v7

https://hg.mozilla.org/integration/fx-team/rev/e7facdd9040b
Comment 20 Tim Taubert [:ttaubert] 2011-09-27 04:35:23 PDT
https://hg.mozilla.org/mozilla-central/rev/e7facdd9040b
Comment 21 Eric Shepherd [:sheppy] 2011-11-16 12:39:31 PST
Documentation updated:

https://developer.mozilla.org/en/Using_the_Web_Console#The_console_object

Also mentioned on Firefox 9 for developers

Note You need to log in before you can comment on or make changes to this bug.