OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/layout/LayoutTable.h" |
| 6 |
| 7 #include "core/layout/LayoutTestHelper.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 namespace { |
| 12 |
| 13 class LayoutTableTest : public RenderingTest { |
| 14 protected: |
| 15 LayoutTable* GetTableByElementId(const char* id) { |
| 16 return ToLayoutTable(GetLayoutObjectByElementId(id)); |
| 17 } |
| 18 }; |
| 19 |
| 20 TEST_F(LayoutTableTest, OverflowWithCollapsedBorders) { |
| 21 SetBodyInnerHTML( |
| 22 "<style>" |
| 23 " table { border-collapse: collapse }" |
| 24 " td { border: 0px solid blue; padding: 0 }" |
| 25 " div { width: 100px; height: 100px }" |
| 26 "</style>" |
| 27 "<table id='table'>" |
| 28 " <tr>" |
| 29 " <td style='border-bottom-width: 10px;" |
| 30 " outline: 3px solid blue'><div></div></td>" |
| 31 " <td style='border-width: 3px 15px'><div></div></td>" |
| 32 " </tr>" |
| 33 " <tr style='outline: 8px solid green'><td><div></div></td></tr>" |
| 34 "</table>"); |
| 35 |
| 36 auto* table = GetTableByElementId("table"); |
| 37 |
| 38 // The table's self visual overflow covers the collapsed borders. |
| 39 LayoutRect expected_self_visual_overflow = table->BorderBoxRect(); |
| 40 expected_self_visual_overflow.ExpandEdges(LayoutUnit(1), LayoutUnit(8), |
| 41 LayoutUnit(0), LayoutUnit(0)); |
| 42 EXPECT_EQ(expected_self_visual_overflow, table->SelfVisualOverflowRect()); |
| 43 |
| 44 // The table's visual overflow covers self visual overflow and visual |
| 45 // overflows rows. |
| 46 LayoutRect expected_visual_overflow = table->BorderBoxRect(); |
| 47 expected_visual_overflow.ExpandEdges(LayoutUnit(3), LayoutUnit(8), |
| 48 LayoutUnit(8), LayoutUnit(8)); |
| 49 EXPECT_EQ(expected_visual_overflow, table->VisualOverflowRect()); |
| 50 } |
| 51 |
| 52 TEST_F(LayoutTableTest, CollapsedBorders) { |
| 53 SetBodyInnerHTML( |
| 54 "<style>table { border-collapse: collapse }</style>" |
| 55 "<table id='table1'" |
| 56 " style='border-top: hidden; border-bottom: 8px solid;" |
| 57 " border-left: hidden; border-right: 10px solid'>" |
| 58 " <tr><td>A</td><td>B</td></tr>" |
| 59 "</table>" |
| 60 "<table id='table2' style='border: 10px solid'>" |
| 61 " <tr>" |
| 62 " <td style='border: hidden'>C</td>" |
| 63 " <td style='border: hidden'>D</td>" |
| 64 " </tr>" |
| 65 "</table>" |
| 66 "<table id='table3' style='border: 10px solid'>" |
| 67 " <tr>" |
| 68 " <td style='border-top: 15px solid;" |
| 69 " border-left: 21px solid'>E</td>" |
| 70 " <td style='border-bottom: 19px solid;" |
| 71 " border-right: 25px solid'>F</td>" |
| 72 " </tr>" |
| 73 "</table>"); |
| 74 |
| 75 auto* table1 = GetTableByElementId("table1"); |
| 76 EXPECT_EQ(0, table1->BorderBefore()); |
| 77 EXPECT_EQ(4, table1->BorderAfter()); |
| 78 EXPECT_EQ(0, table1->BorderStart()); |
| 79 EXPECT_EQ(5, table1->BorderEnd()); |
| 80 |
| 81 // All cells have hidden border. |
| 82 auto* table2 = GetTableByElementId("table2"); |
| 83 EXPECT_EQ(0, table2->BorderBefore()); |
| 84 EXPECT_EQ(0, table2->BorderAfter()); |
| 85 EXPECT_EQ(0, table2->BorderStart()); |
| 86 EXPECT_EQ(0, table2->BorderEnd()); |
| 87 |
| 88 // Cells have wider borders. |
| 89 auto* table3 = GetTableByElementId("table3"); |
| 90 // Cell E's border-top won. |
| 91 EXPECT_EQ(7, table3->BorderBefore()); |
| 92 // Cell F's border-bottom won. |
| 93 EXPECT_EQ(10, table3->BorderAfter()); |
| 94 // Cell E's border-left won. |
| 95 EXPECT_EQ(10, table3->BorderStart()); |
| 96 // Cell F's border-bottom won. |
| 97 EXPECT_EQ(13, table3->BorderEnd()); |
| 98 } |
| 99 |
| 100 TEST_F(LayoutTableTest, CollapsedBordersWithCol) { |
| 101 SetBodyInnerHTML( |
| 102 "<style>table { border-collapse: collapse }</style>" |
| 103 "<table id='table1' style='border: hidden'>" |
| 104 " <colgroup>" |
| 105 " <col colspan='2000' style='border: 10px solid'>" |
| 106 " <col colspan='2000' style='border: 20px solid'>" |
| 107 " </colgroup>" |
| 108 " <tr>" |
| 109 " <td colspan='2000'>A</td>" |
| 110 " <td colspan='2000'>B</td>" |
| 111 " </tr>" |
| 112 "</table>" |
| 113 "<table id='table2' style='border: 10px solid'>" |
| 114 " <colgroup>" |
| 115 " <col colspan='2000' style='border: 10px solid'>" |
| 116 " <col colspan='2000' style='border: 20px solid'>" |
| 117 " </colgroup>" |
| 118 " <tr>" |
| 119 " <td colspan='2000' style='border: hidden'>C</td>" |
| 120 " <td colspan='2000' style='border: hidden'>D</td>" |
| 121 " </tr>" |
| 122 "</table>" |
| 123 "<table id='table3'>" |
| 124 " <colgroup>" |
| 125 " <col colspan='2000' style='border: 10px solid'>" |
| 126 " <col colspan='2000' style='border: 20px solid'>" |
| 127 " </colgroup>" |
| 128 " <tr>" |
| 129 " <td colspan='2000' style='border: 12px solid'>E</td>" |
| 130 " <td colspan='2000' style='border: 16px solid'>F</td>" |
| 131 " </tr>" |
| 132 "</table>"); |
| 133 |
| 134 // Table has hidden border. |
| 135 auto* table1 = GetTableByElementId("table1"); |
| 136 EXPECT_EQ(0, table1->BorderBefore()); |
| 137 EXPECT_EQ(0, table1->BorderAfter()); |
| 138 EXPECT_EQ(0, table1->BorderStart()); |
| 139 EXPECT_EQ(0, table1->BorderEnd()); |
| 140 |
| 141 // All cells have hidden border. |
| 142 auto* table2 = GetTableByElementId("table2"); |
| 143 EXPECT_EQ(0, table2->BorderBefore()); |
| 144 EXPECT_EQ(0, table2->BorderAfter()); |
| 145 EXPECT_EQ(0, table2->BorderStart()); |
| 146 EXPECT_EQ(0, table2->BorderEnd()); |
| 147 |
| 148 // Combined cell and col borders. |
| 149 auto* table3 = GetTableByElementId("table3"); |
| 150 // Col 2's border-top won. |
| 151 EXPECT_EQ(10, table3->BorderBefore()); |
| 152 // Col 2's border-bottom won. |
| 153 EXPECT_EQ(10, table3->BorderAfter()); |
| 154 // Cell E's border-left won. |
| 155 EXPECT_EQ(6, table3->BorderStart()); |
| 156 // Col 2's border-right won. |
| 157 EXPECT_EQ(10, table3->BorderEnd()); |
| 158 } |
| 159 |
| 160 } // anonymous namespace |
| 161 |
| 162 } // namespace blink |
OLD | NEW |