2011-04-29  Abhishek Arya  <inferno@chromium.org>

        Reviewed by Dave Hyatt.

        Allow only first table caption and destroy the remaining ones.
        https://bugs.webkit.org/show_bug.cgi?id=58249

        Previously, we were only laying out the first table caption.
        However Table::layout didn't mark the other ones as not needing
        layout. So after table layout completes, table is marked as not
        needing layout with its other table caption still needing layout.
        This causes incorrect layout root calculations and set it to a
        node which is already getting deleted.

        Tests: fast/table/dynamic-caption-add-before-child.xhtml
               fast/table/dynamic-caption-add-remove-before-child.xhtml
               fast/table/multiple-captions-crash.xhtml
               fast/table/multiple-captions-crash2.xhtml
               fast/table/multiple-captions-display.xhtml

        * rendering/RenderTable.cpp:
        (WebCore::RenderTable::addChild): when new caption or a before
        child caption is added, we need to explicitly trigger section
        recalc or otherwise layout won't catch it.
        (WebCore::RenderTable::removeChild): when child to be removed is
        m_caption, make sure to trigger style recalc on the table.
        (WebCore::RenderTable::recalcCaption): code to destroy captions
        other than the first one.
        (WebCore::RenderTable::recalcSections): call recalcCaption
        helper. Store the next sibling early since child can get destroyed
        in recalcCaption.
        * rendering/RenderTable.h:
2011-04-21  Abhishek Arya  <inferno@chromium.org>

        Reviewed by Dave Hyatt.

        Tests that we do not crash on
        ASSERT(!m_layoutRoot->container() || !m_layoutRoot->container()->needsLayout())
        when a table has two or more captions.
        https://bugs.webkit.org/show_bug.cgi?id=58249

        * fast/table/dynamic-caption-add-before-child.xhtml: Added. Tests that
        before child caption becomes the first caption.
        * fast/table/dynamic-caption-add-remove-before-child.xhtml: Added. Tests
        that when we remove the before child caption, the original caption becomes
        the first caption and is drawn.
        * fast/table/multiple-captions-crash-expected.txt: Added.
        * fast/table/multiple-captions-crash.xhtml: Added. Tests that we
        do not crash when table has multiple captions and captions (other
        than the first one) have input elements added as their child.
        * fast/table/multiple-captions-crash2-expected.txt: Added.
        * fast/table/multiple-captions-crash2.xhtml: Added. Same as
        multiple-captions-crash.xhtml but this testcase does not have
        enclosing table tags for the captions.
        * fast/table/multiple-captions-display.xhtml: Added. Tests that only
        the first caption and captions with position fixed (display=BLOCK) are
        shown. Other captions are not added to table.
        * platform/mac/fast/table/dynamic-caption-add-before-child-expected.checksum: Added.
        * platform/mac/fast/table/dynamic-caption-add-before-child-expected.png: Added.
        * platform/mac/fast/table/dynamic-caption-add-before-child-expected.txt: Added.
        * platform/mac/fast/table/dynamic-caption-add-remove-before-child-expected.checksum: Added.
        * platform/mac/fast/table/dynamic-caption-add-remove-before-child-expected.png: Added.
        * platform/mac/fast/table/dynamic-caption-add-remove-before-child-expected.txt: Added.
        * platform/mac/fast/table/multiple-captions-display-expected.checksum: Added.
        * platform/mac/fast/table/multiple-captions-display-expected.png: Added.
        * platform/mac/fast/table/multiple-captions-display-expected.txt: Added.
        * platform/mac/fast/table/prepend-in-anonymous-table-expected.png:
        * platform/mac/fast/table/prepend-in-anonymous-table-expected.txt: Rebaseline
        test because we do not allow captions other than the first one.
        * platform/mac/tables/mozilla_expected_failures/other/test4-expected.txt: Rebaseline
        test because we do not allow captions other than the first one.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@85355 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/fast/table/dynamic-caption-add-remove-before-child.xhtml b/LayoutTests/fast/table/dynamic-caption-add-remove-before-child.xhtml
new file mode 100644
index 0000000..f5be967
--- /dev/null
+++ b/LayoutTests/fast/table/dynamic-caption-add-remove-before-child.xhtml
@@ -0,0 +1,18 @@
+<html xmlns="http://www.w3.org/1999/xhtml">

+    <body>

+        <table id="table">

+        <caption id="c1">PASS: Text in caption 1</caption>

+        </table>

+        <script>

+           document.body.offsetLeft;           

+           var caption = document.createElement('caption');

+           caption.appendChild(document.createTextNode('FAIL: Dynamically added caption'));

+

+           var table = document.getElementById('table');

+           var c1 = document.getElementById('c1');

+           table.insertBefore(caption, c1);

+           document.body.offsetTop;

+           table.removeChild(caption);

+        </script>

+    </body>

+</html>