Bug 626484 - Incorrect order of lines when copying from web console; f=rcampbell,mihai.sucan r=mihai.sucan,gavin.sharp
authorAdam <unusualtears@gmail.com>
Tue, 19 Apr 2011 12:40:36 -0500
changeset 69177 b30aa967de2e407f6d3e28e3ef1207d815b8402e
parent 69176 61fc20a05e322b856946474d2398fc5b1e6130c7
child 69178 8227473480f5bde06cca23bc331d9c59b36f7def
push idunknown
push userunknown
push dateunknown
reviewersmihai.sucan, gavin.sharp
bugs626484
milestone6.0a1
Bug 626484 - Incorrect order of lines when copying from web console; f=rcampbell,mihai.sucan r=mihai.sucan,gavin.sharp
toolkit/components/console/hudservice/HUDService.jsm
toolkit/components/console/hudservice/tests/browser/Makefile.in
toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_626484_output_copy_order.js
--- a/toolkit/components/console/hudservice/HUDService.jsm
+++ b/toolkit/components/console/hudservice/HUDService.jsm
@@ -2976,18 +2976,24 @@ HUD_SERVICE.prototype =
    * @returns void
    */
   copySelectedItems: function HS_copySelectedItems(aOutputNode)
   {
     // Gather up the selected items and concatenate their clipboard text.
 
     let strings = [];
     let newGroup = false;
-    for (let i = 0; i < aOutputNode.selectedCount; i++) {
-      let item = aOutputNode.selectedItems[i];
+
+    let children = aOutputNode.children;
+
+    for (let i = 0; i < children.length; i++) {
+      let item = children[i];
+      if (!item.selected) {
+        continue;
+      }
 
       // Add dashes between groups so that group boundaries show up in the
       // copied output.
       if (i > 0 && item.classList.contains("webconsole-new-group")) {
         newGroup = true;
       }
 
       // Ensure the selected item hasn't been filtered by type or string.
--- a/toolkit/components/console/hudservice/tests/browser/Makefile.in
+++ b/toolkit/components/console/hudservice/tests/browser/Makefile.in
@@ -123,16 +123,17 @@ include $(topsrcdir)/config/rules.mk
 	browser_webconsole_bug_618078_network_exceptions.js \
 	browser_webconsole_bug_613280_jsterm_copy.js \
 	browser_webconsole_bug_630733_response_redirect_headers.js \
 	browser_webconsole_bug_621644_jsterm_dollar.js \
 	browser_webconsole_bug_632817.js \
 	browser_webconsole_bug_611795.js \
 	browser_webconsole_bug_618311_close_panels.js \
 	browser_webconsole_bug_618311_private_browsing.js \
+	browser_webconsole_bug_626484_output_copy_order.js \
 	browser_webconsole_bug_632347_iterators_generators.js \
 	browser_webconsole_bug_642108_refForOutputNode.js \
 	browser_webconsole_bug_642108_pruneTest.js \
 	browser_webconsole_bug_585956_console_trace.js \
 	browser_webconsole_bug_595223_file_uri.js \
 	browser_webconsole_bug_632275_getters_document_width.js \
 	head.js \
 	$(NULL)
new file mode 100644
--- /dev/null
+++ b/toolkit/components/console/hudservice/tests/browser/browser_webconsole_bug_626484_output_copy_order.js
@@ -0,0 +1,61 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+let itemsSet;
+
+function test() {
+  addTab("data:text/html,Web Console test for bug 626484");
+  browser.addEventListener("load", tabLoaded, true);
+}
+
+function tabLoaded(aEvent) {
+  browser.removeEventListener(aEvent.type, arguments.callee, true);
+  openConsole();
+
+  let console = browser.contentWindow.wrappedJSObject.console;
+  console.log("The first line.");
+  console.log("The second line.");
+  console.log("The last line.");
+
+  let hudId = HUDService.getHudIdByWindow(content);
+  HUD = HUDService.hudReferences[hudId];
+  outputNode = HUD.outputNode;
+
+  itemsSet = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1],
+    [2, 1, 0]];
+
+  nextTest();
+}
+
+function nextTest() {
+  if (itemsSet.length === 0) {
+    outputNode.clearSelection();
+    HUD.jsterm.clearOutput();
+    finish();
+  }
+  else {
+    outputNode.clearSelection();
+    let items = itemsSet.shift();
+    items.forEach(function (index) {
+      outputNode.addItemToSelection(outputNode.getItemAtIndex(index));
+    });
+    outputNode.focus();
+    waitForClipboard(getExpectedClipboardText(items.length),
+      clipboardSetup, nextTest, nextTest);
+  }
+}
+
+function getExpectedClipboardText(aItemCount) {
+  let expectedClipboardText = [];
+  for (let i = 0; i < aItemCount; i++) {
+    let item = outputNode.getItemAtIndex(i);
+    expectedClipboardText.push("[" +
+      ConsoleUtils.timestampString(item.timestamp) + "] " +
+      item.clipboardText);
+  }
+  return expectedClipboardText.join("\n");
+}
+
+function clipboardSetup() {
+  goDoCommand("cmd_copy");
+}
+