Fixes issue #446 "DOM.insertChild fails on IE6 when the index parameter is greater than the num of children".

Patch by: sandymac, tobyr
Review by: bruce


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@984 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/impl/DOMImplIE6.java b/user/src/com/google/gwt/user/client/impl/DOMImplIE6.java
index 59b5046..792117a 100644
--- a/user/src/com/google/gwt/user/client/impl/DOMImplIE6.java
+++ b/user/src/com/google/gwt/user/client/impl/DOMImplIE6.java
@@ -154,7 +154,7 @@
   }-*/;
 
   public native void insertChild(Element parent, Element child, int index) /*-{
-    if (index == parent.children.length)
+    if (index >= parent.children.length)
       parent.appendChild(child);
     else
       parent.insertBefore(child, parent.children[index]);
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 7f6cc37..865d0d1 100644
--- a/user/test/com/google/gwt/user/client/ui/DOMTest.java
+++ b/user/test/com/google/gwt/user/client/ui/DOMTest.java
@@ -53,7 +53,7 @@
     cssClass = DOM.getElementAttribute(div, "class");
     assertNull(cssClass);
   }
-  
+
   /**
    * Tests the ability to do a parent-ward walk in the DOM.
    */
@@ -73,6 +73,18 @@
   }
 
   /**
+   * Tests {@link DOM#insertChild(Element, Element, int)}.
+   *
+   */
+  public void testInsertChild() {
+    Element parent = RootPanel.get().getElement();
+    Element div = DOM.createDiv();
+    DOM.insertChild(parent, div, Integer.MAX_VALUE);
+    Element child = DOM.getChild(RootPanel.get().getElement(), DOM.getChildCount(parent) - 1);
+    assertEquals(div, child);
+  }
+
+  /**
    * Tests that {@link DOM#isOrHasChild(Element, Element)} works consistently
    * across browsers.
    */