SF.net SVN: htmlunit: [1237] trunk/htmlunit/src

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

SF.net SVN: htmlunit: [1237] trunk/htmlunit/src

mguillem
Revision: 1237
          http://svn.sourceforge.net/htmlunit/?rev=1237&view=rev
Author:   mguillem
Date:     2006-09-21 09:45:37 -0700 (Thu, 21 Sep 2006)

Log Message:
-----------
JavaScript: fixed bug in table.insertRow with empty tbody. (#1562461)

Modified Paths:
--------------
    trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Table.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TableTest.java
    trunk/htmlunit/src/xdocs/changes.xml

Modified: trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Table.java
===================================================================
--- trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Table.java 2006-09-20 19:29:08 UTC (rev 1236)
+++ trunk/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Table.java 2006-09-21 16:45:37 UTC (rev 1237)
@@ -220,7 +220,8 @@
     protected Object insertRow(final int index) {
         // check if a tbody should be created
         final List tagNames = Arrays.asList(new String[] {"tbody", "thead", "tfoot"} );
-        if (getHtmlElementOrDie().getHtmlElementsByTagNames(tagNames).isEmpty()) {
+        final List rowContainers = getHtmlElementOrDie().getHtmlElementsByTagNames(tagNames);
+        if (rowContainers.isEmpty() || index == 0) {
             final HtmlElement tBody = getHtmlElementOrDie().appendChildIfNoneExists("tbody");
             return ((RowContainer) getScriptableFor(tBody)).insertRow(0);
         }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TableTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TableTest.java 2006-09-20 19:29:08 UTC (rev 1236)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TableTest.java 2006-09-21 16:45:37 UTC (rev 1237)
@@ -460,7 +460,7 @@
             + "</body>"
             + "</html>";
 
-        final List expectedAlerts = Arrays.asList(new String[] { "TBODY", "TABLE" });
+        final String[] expectedAlerts = { "TBODY", "TABLE" };
         createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
 
         final List collectedAlerts = new ArrayList();
@@ -469,7 +469,40 @@
         assertEquals(expectedAlerts, collectedAlerts);
     }
 
+    /**
+     * Test that a tbody is created
+     * @throws Exception if the test fails
+     */
+    public void testInsertRowInTableWithEmtpyTbody() throws Exception {
 
+        final String content =
+            "<html><head>"
+            + "<script>"
+            + "function test()"
+            + "{"
+            + "  var oTable = document.getElementById('mytable');"
+            + "  alert(oTable.lastChild.tagName);"
+            + "  var tableRow = oTable.insertRow(0);"
+            + "  alert(oTable.lastChild.tagName);"
+            + "  alert(tableRow.parentNode.tagName);"
+            + "}"
+            + "</script>"
+            + "</head>"
+            + "<body onload='test()'>"
+            + "<table id='mytable'><tbody></tbody>"
+            + "</table>"
+            + "</body>"
+            + "</html>";
+
+        final String[] expectedAlerts = { "TBODY", "TBODY", "TBODY" };
+        createTestPageForRealBrowserIfNeeded(content, expectedAlerts);
+
+        final List collectedAlerts = new ArrayList();
+        loadPage(content, collectedAlerts);
+
+        assertEquals(expectedAlerts, collectedAlerts);
+    }
+
     /**
      * Tests length, tBodies on nested rows
      * @throws Exception if the test fails

Modified: trunk/htmlunit/src/xdocs/changes.xml
===================================================================
--- trunk/htmlunit/src/xdocs/changes.xml 2006-09-20 19:29:08 UTC (rev 1236)
+++ trunk/htmlunit/src/xdocs/changes.xml 2006-09-21 16:45:37 UTC (rev 1237)
@@ -7,6 +7,9 @@
 
     <body>
         <release version="1.10-prerelease">
+            <action type="update" dev="mguillem" id="1562461">
+                JavaScript: fixed bug in table.insertRow with empty tbody.
+            </action>
             <action type="update" dev="mguillem" id="1531821">
                 Follow redirection to the same Url if original method was a POST. Handle redirections
                 like browsers do rather than according to the RFC.


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop