Bug 588730 - Adding text nodes to the Web Console causes warnings r=dietrich a=blocking2.0
authorPatrick Walton <pwalton@mozilla.com>
Fri, 27 Aug 2010 13:25:23 -0700
changeset 51599 0b09b81b1a608a33a861b46df5e22ab4536473c7
parent 51598 bc95b9869d3f593d0b4e6e938075c15cd8a5db9c
child 51600 c877b9e86e4d44fee5404d73efc1518500d1eb03
push idunknown
push userunknown
push dateunknown
reviewersdietrich, blocking2.0
bugs588730
milestone2.0b5pre
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 588730 - Adding text nodes to the Web Console causes warnings r=dietrich a=blocking2.0
toolkit/components/console/hudservice/HUDService.jsm
toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js
--- a/toolkit/components/console/hudservice/HUDService.jsm
+++ b/toolkit/components/console/hudservice/HUDService.jsm
@@ -1838,17 +1838,19 @@ HeadsUpDisplay.prototype = {
     this.outputNode.setAttribute("orient", "vertical");
     this.outputNode.setAttribute("context", this.hudId + "-output-contextmenu");
 
     this.outputNode.addEventListener("DOMNodeInserted", function(ev) {
       // DOMNodeInserted is also called when the output node is being *itself*
       // (re)inserted into the DOM (which happens during a search, for
       // example). For this reason, we need to ensure that we only check
       // message nodes.
-      if (ev.target.classList.contains("hud-msg-node")) {
+      let node = ev.target;
+      if (node.nodeType === node.ELEMENT_NODE &&
+          node.classList.contains("hud-msg-node")) {
         HUDService.adjustVisibilityForNewlyInsertedNode(self.hudId, ev.target);
       }
     }, false);
 
     this.filterSpacer = this.makeXULNode("spacer");
     this.filterSpacer.setAttribute("flex", "1");
 
     this.filterBox = this.makeXULNode("textbox");
--- a/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js
+++ b/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js
@@ -231,16 +231,19 @@ function testLogEntry(aOutputNode, aMatc
       ok(true, aSuccessErrObj.success);
       return;
     }
   }
   throw new Error(aSuccessErrObj.err);
 }
 
 // test network logging
+//
+// NB: After this test, the HUD (including its "jsterm" attribute) will be gone
+// forever due to bug 580618!
 function testNet()
 {
   HUDService.setFilterState(hudId, "network", true);
   setStringFilter("");
 
   let HUD = HUDService.hudWeakReferences[hudId].get();
   let jsterm = HUD.jsterm;
   let outputNode = jsterm.outputNode;
@@ -349,17 +352,17 @@ function testLiveFilteringForSearchStrin
     setStringFilter("'foo'");
     is(countNetworkNodes(), 0, "the network nodes are hidden when searching " +
       "for the string 'foo'");
 
     setStringFilter("foo\"bar'baz\"boo'");
     is(countNetworkNodes(), 0, "the network nodes are hidden when searching " +
       "for the string \"foo\"bar'baz\"boo'\"");
 
-    testPageReload();
+    testTextNodeInsertion();
   });
 }
 
 function testOutputOrder()
 {
   let HUD = HUDService.hudWeakReferences[hudId].get();
   let jsterm = HUD.jsterm;
   let outputNode = jsterm.outputNode;
@@ -766,16 +769,54 @@ function testHUDGetters()
   ok(klass == "jsterm-input-node", "We have the input node.");
 
   var hudconsole = HUD.console;
   is(typeof hudconsole, "object", "HUD.console is an object");
   is(typeof hudconsole.log, "function", "HUD.console.log is a function");
   is(typeof hudconsole.info, "function", "HUD.console.info is a function");
 }
 
+// Test for bug 588730: Adding a text node to an existing label element causes
+// warnings
+function testTextNodeInsertion() {
+  HUDService.clearDisplay(hudId);
+
+  let display = HUDService.getDisplayByURISpec(TEST_NETWORK_URI);
+  let outputNode = display.querySelector(".hud-output-node");
+
+  let label = document.createElementNS(
+    "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "label");
+  outputNode.appendChild(label);
+
+  let error = false;
+  let listener = {
+    observe: function(aMessage) {
+      let messageText = aMessage.message;
+      if (messageText.indexOf("JavaScript Warning") !== -1) {
+        error = true;
+      }
+    }
+  };
+
+  let nsIConsoleServiceClass = Cc["@mozilla.org/consoleservice;1"];
+  let nsIConsoleService = nsIConsoleServiceClass.getService(Ci.
+    nsIConsoleService);
+  nsIConsoleService.registerListener(listener);
+
+  // This shouldn't fail.
+  label.appendChild(document.createTextNode("foo"));
+
+  executeSoon(function() {
+    nsIConsoleService.unregisterListener(listener);
+    ok(!error, "no error when adding text nodes as children of labels");
+
+    testPageReload();
+  });
+}
+
 function testPageReload() {
   // see bug 578437 - The HUD console fails to re-attach the window.console
   // object after page reload.
 
   browser.addEventListener("DOMContentLoaded", function onDOMLoad () {
     browser.removeEventListener("DOMContentLoaded", onDOMLoad, false);
 
     var console = browser.contentWindow.wrappedJSObject.console;