Unit Test for Issue #328: Added testSetInnerText() test. This test checks to see that no child nodes of a DOM element exist after calling element.setInnerText(null). A helper method, getDenormalizedChildCount(), is a JSNI method that allows us to get the 'true' child count for an element. DOM.getChildCount() excludes text nodes from the count, and this is not sufficient for asserting that there are no child nodes left in the DOM structure.

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@493 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/test/com/google/gwt/user/client/ui/DOMTest.java b/user/test/com/google/gwt/user/client/ui/DOMTest.java
index 4bcbcd9..2d7d2c0 100644
--- a/user/test/com/google/gwt/user/client/ui/DOMTest.java
+++ b/user/test/com/google/gwt/user/client/ui/DOMTest.java
@@ -6,6 +6,19 @@
 
 public class DOMTest extends GWTTestCase {
 
+  /**
+   * Helper method to return the denormalized child count of a DOM Element. For example,
+   * child nodes which have a nodeType of Text are included in the count, whereas
+   * <code>DOM.getChildCount(Element parent)</code> only counts the child nodes which have a nodeType
+   * of Element.
+   *
+   * @param elem the DOM element to check the child count for
+   * @return The number of child nodes
+   */
+  public static native int getDenormalizedChildCount(Element elem) /*-{
+    return (elem.childNodes.length);
+  }-*/;
+
   public String getModuleName() {
     return "com.google.gwt.user.User";
   }
@@ -24,7 +37,33 @@
     // If we get here, we pass, because we encountered no errors going to the 
     // top of the parent hierarchy.
   }
-  
+
+  public void testSetInnerText() {
+    Element tableElem = DOM.createTable();
+
+    Element trElem = DOM.createTR();
+
+    Element tdElem = DOM.createTD();
+    DOM.setInnerText(tdElem, "Some Table Heading Data");
+
+    // Add a <em> element as a child to the td element
+    Element emElem = DOM.createElement("em");
+    DOM.setInnerText(emElem, "Some emphasized text");
+    DOM.appendChild(tdElem, emElem);
+
+    DOM.appendChild(trElem, tdElem);
+
+    DOM.appendChild(tableElem, trElem);
+
+    DOM.appendChild(RootPanel.getBodyElement(), tableElem);
+
+    DOM.setInnerText(tdElem, null);
+
+    // Once we set the inner text on an element to null, all of the element's child nodes
+    // should be deleted, including any text nodes, for all supported browsers.
+    assertTrue(getDenormalizedChildCount(tdElem) == 0);
+  }
+
   public void testToString() {
     Button b = new Button("abcdef");
     assertTrue(b.toString().indexOf("abcdef")!=-1);