OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 11 matching lines...) Expand all Loading... |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "core/layout/LayoutTableCell.h" | 26 #include "core/layout/LayoutTableCell.h" |
27 | 27 |
28 #include "core/layout/LayoutTestHelper.h" | 28 #include "core/layout/LayoutTestHelper.h" |
29 | 29 |
30 namespace blink { | 30 namespace blink { |
31 | 31 |
32 namespace { | |
33 | |
34 class LayoutTableCellDeathTest : public RenderingTest { | 32 class LayoutTableCellDeathTest : public RenderingTest { |
35 protected: | 33 protected: |
36 virtual void SetUp() { | 34 virtual void SetUp() { |
37 RenderingTest::SetUp(); | 35 RenderingTest::SetUp(); |
38 cell_ = LayoutTableCell::CreateAnonymous(&GetDocument()); | 36 cell_ = LayoutTableCell::CreateAnonymous(&GetDocument()); |
39 } | 37 } |
40 | 38 |
41 virtual void TearDown() { | 39 virtual void TearDown() { |
42 cell_->Destroy(); | 40 cell_->Destroy(); |
43 RenderingTest::TearDown(); | 41 RenderingTest::TearDown(); |
(...skipping 22 matching lines...) Expand all Loading... |
66 TEST_F(LayoutTableCellDeathTest, CrashIfColumnOverflowOnSetting) { | 64 TEST_F(LayoutTableCellDeathTest, CrashIfColumnOverflowOnSetting) { |
67 ASSERT_DEATH(cell_->SetAbsoluteColumnIndex(kMaxColumnIndex + 1), ""); | 65 ASSERT_DEATH(cell_->SetAbsoluteColumnIndex(kMaxColumnIndex + 1), ""); |
68 } | 66 } |
69 | 67 |
70 TEST_F(LayoutTableCellDeathTest, CrashIfSettingUnsetColumnIndex) { | 68 TEST_F(LayoutTableCellDeathTest, CrashIfSettingUnsetColumnIndex) { |
71 ASSERT_DEATH(cell_->SetAbsoluteColumnIndex(kUnsetColumnIndex), ""); | 69 ASSERT_DEATH(cell_->SetAbsoluteColumnIndex(kUnsetColumnIndex), ""); |
72 } | 70 } |
73 | 71 |
74 #endif | 72 #endif |
75 | 73 |
76 using LayoutTableCellTest = RenderingTest; | 74 class LayoutTableCellTest : public RenderingTest { |
| 75 protected: |
| 76 bool HasStartBorderAdjoiningTable(const LayoutTableCell* cell) { |
| 77 return cell->HasStartBorderAdjoiningTable(); |
| 78 } |
| 79 bool HasEndBorderAdjoiningTable(const LayoutTableCell* cell) { |
| 80 return cell->HasEndBorderAdjoiningTable(); |
| 81 } |
| 82 |
| 83 LayoutTableCell* GetCellByElementId(const char* id) { |
| 84 return ToLayoutTableCell(GetLayoutObjectByElementId(id)); |
| 85 } |
| 86 }; |
77 | 87 |
78 TEST_F(LayoutTableCellTest, ResetColspanIfTooBig) { | 88 TEST_F(LayoutTableCellTest, ResetColspanIfTooBig) { |
79 SetBodyInnerHTML("<table><td colspan='14000'></td></table>"); | 89 SetBodyInnerHTML("<table><td id='cell' colspan='14000'></td></table>"); |
80 | 90 ASSERT_EQ(GetCellByElementId("cell")->ColSpan(), 8190U); |
81 LayoutTableCell* cell = ToLayoutTableCell(GetDocument() | |
82 .body() | |
83 ->firstChild() | |
84 ->firstChild() | |
85 ->firstChild() | |
86 ->firstChild() | |
87 ->GetLayoutObject()); | |
88 ASSERT_EQ(cell->ColSpan(), 8190U); | |
89 } | 91 } |
90 | 92 |
91 TEST_F(LayoutTableCellTest, DoNotResetColspanJustBelowBoundary) { | 93 TEST_F(LayoutTableCellTest, DoNotResetColspanJustBelowBoundary) { |
92 SetBodyInnerHTML("<table><td colspan='8190'></td></table>"); | 94 SetBodyInnerHTML("<table><td id='cell' colspan='8190'></td></table>"); |
93 | 95 ASSERT_EQ(GetCellByElementId("cell")->ColSpan(), 8190U); |
94 LayoutTableCell* cell = ToLayoutTableCell(GetDocument() | |
95 .body() | |
96 ->firstChild() | |
97 ->firstChild() | |
98 ->firstChild() | |
99 ->firstChild() | |
100 ->GetLayoutObject()); | |
101 ASSERT_EQ(cell->ColSpan(), 8190U); | |
102 } | 96 } |
103 | 97 |
104 TEST_F(LayoutTableCellTest, ResetRowspanIfTooBig) { | 98 TEST_F(LayoutTableCellTest, ResetRowspanIfTooBig) { |
105 SetBodyInnerHTML("<table><td rowspan='70000'></td></table>"); | 99 SetBodyInnerHTML("<table><td id='cell' rowspan='70000'></td></table>"); |
106 | 100 ASSERT_EQ(GetCellByElementId("cell")->RowSpan(), 65534U); |
107 LayoutTableCell* cell = ToLayoutTableCell(GetDocument() | |
108 .body() | |
109 ->firstChild() | |
110 ->firstChild() | |
111 ->firstChild() | |
112 ->firstChild() | |
113 ->GetLayoutObject()); | |
114 ASSERT_EQ(cell->RowSpan(), 65534U); | |
115 } | 101 } |
116 | 102 |
117 TEST_F(LayoutTableCellTest, DoNotResetRowspanJustBelowBoundary) { | 103 TEST_F(LayoutTableCellTest, DoNotResetRowspanJustBelowBoundary) { |
118 SetBodyInnerHTML("<table><td rowspan='65534'></td></table>"); | 104 SetBodyInnerHTML("<table><td id='cell' rowspan='65534'></td></table>"); |
119 | 105 ASSERT_EQ(GetCellByElementId("cell")->RowSpan(), 65534U); |
120 LayoutTableCell* cell = ToLayoutTableCell(GetDocument() | |
121 .body() | |
122 ->firstChild() | |
123 ->firstChild() | |
124 ->firstChild() | |
125 ->firstChild() | |
126 ->GetLayoutObject()); | |
127 ASSERT_EQ(cell->RowSpan(), 65534U); | |
128 } | 106 } |
129 | 107 |
130 TEST_F(LayoutTableCellTest, | 108 TEST_F(LayoutTableCellTest, |
131 BackgroundIsKnownToBeOpaqueWithLayerAndCollapsedBorder) { | 109 BackgroundIsKnownToBeOpaqueWithLayerAndCollapsedBorder) { |
132 SetBodyInnerHTML( | 110 SetBodyInnerHTML( |
133 "<table style='border-collapse: collapse'>" | 111 "<table style='border-collapse: collapse'>" |
134 "<td style='will-change: transform; background-color: blue'>Cell></td>" | 112 " <td id='cell' style='will-change: transform; background-color: blue'>" |
| 113 " Cell" |
| 114 " </td>" |
135 "</table>"); | 115 "</table>"); |
136 | 116 EXPECT_FALSE(GetCellByElementId("cell")->BackgroundIsKnownToBeOpaqueInRect( |
137 LayoutTableCell* cell = ToLayoutTableCell(GetDocument() | 117 LayoutRect(0, 0, 1, 1))); |
138 .body() | |
139 ->firstChild() | |
140 ->firstChild() | |
141 ->firstChild() | |
142 ->firstChild() | |
143 ->GetLayoutObject()); | |
144 EXPECT_FALSE(cell->BackgroundIsKnownToBeOpaqueInRect(LayoutRect(0, 0, 1, 1))); | |
145 } | 118 } |
146 | 119 |
147 TEST_F(LayoutTableCellTest, RepaintContentInTableCell) { | 120 TEST_F(LayoutTableCellTest, RepaintContentInTableCell) { |
148 const char* body_content = | 121 const char* body_content = |
149 "<table id='table' style='position: absolute; left: 1px;'>" | 122 "<table id='table' style='position: absolute; left: 1px;'>" |
150 "<tr>" | 123 " <tr>" |
151 "<td id='cell'>" | 124 " <td id='cell'>" |
152 "<div style='display: inline-block; height: 20px; width: 20px'>" | 125 " <div style='display: inline-block; height: 20px; width: 20px'>" |
153 "</td>" | 126 " </td>" |
154 "</tr>" | 127 " </tr>" |
155 "</table>"; | 128 "</table>"; |
156 SetBodyInnerHTML(body_content); | 129 SetBodyInnerHTML(body_content); |
157 | 130 |
158 // Create an overflow recalc. | 131 // Create an overflow recalc. |
159 Element* cell = GetDocument().getElementById(AtomicString("cell")); | 132 Element* cell = GetDocument().getElementById("cell"); |
160 cell->setAttribute(HTMLNames::styleAttr, "outline: 1px solid black;"); | 133 cell->setAttribute(HTMLNames::styleAttr, "outline: 1px solid black;"); |
161 // Trigger a layout on the table that doesn't require cell layout. | 134 // Trigger a layout on the table that doesn't require cell layout. |
162 Element* table = GetDocument().getElementById(AtomicString("table")); | 135 Element* table = GetDocument().getElementById("table"); |
163 table->setAttribute(HTMLNames::styleAttr, "position: absolute; left: 2px;"); | 136 table->setAttribute(HTMLNames::styleAttr, "position: absolute; left: 2px;"); |
164 GetDocument().View()->UpdateAllLifecyclePhases(); | 137 GetDocument().View()->UpdateAllLifecyclePhases(); |
165 | 138 |
166 // Check that overflow was calculated on the cell. | 139 // Check that overflow was calculated on the cell. |
167 LayoutBlock* input_block = ToLayoutBlock(GetLayoutObjectByElementId("cell")); | 140 auto* input_block = ToLayoutBlock(cell->GetLayoutObject()); |
168 LayoutRect rect = input_block->LocalVisualRect(); | 141 LayoutRect rect = input_block->LocalVisualRect(); |
169 EXPECT_EQ(LayoutRect(-1, -1, 24, 24), rect); | 142 EXPECT_EQ(LayoutRect(-1, -1, 24, 24), rect); |
170 } | 143 } |
171 } // namespace | 144 |
| 145 TEST_F(LayoutTableCellTest, HasBorderAdjoiningTable) { |
| 146 SetBodyInnerHTML( |
| 147 "<table id='table'>" |
| 148 " <tr>" |
| 149 " <td id='cell11' colspan='2000'></td>" |
| 150 " <td id='cell12'></td>" |
| 151 " <td id='cell13'></td>" |
| 152 " </tr>" |
| 153 " <tr>" |
| 154 " <td id='cell21' rowspan='2'></td>" |
| 155 " <td id='cell22'></td>" |
| 156 " <td id='cell23' colspan='2000'></td>" |
| 157 " </tr>" |
| 158 " <tr>" |
| 159 " <td id='cell31'></td>" |
| 160 " <td id='cell32'></td>" |
| 161 " </tr>" |
| 162 "</table>"); |
| 163 |
| 164 const auto* cell11 = GetCellByElementId("cell11"); |
| 165 const auto* cell12 = GetCellByElementId("cell12"); |
| 166 const auto* cell13 = GetCellByElementId("cell13"); |
| 167 const auto* cell21 = GetCellByElementId("cell21"); |
| 168 const auto* cell22 = GetCellByElementId("cell22"); |
| 169 const auto* cell23 = GetCellByElementId("cell23"); |
| 170 const auto* cell31 = GetCellByElementId("cell31"); |
| 171 const auto* cell32 = GetCellByElementId("cell32"); |
| 172 |
| 173 EXPECT_TRUE(HasStartBorderAdjoiningTable(cell11)); |
| 174 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell11)); |
| 175 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell12)); |
| 176 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell12)); |
| 177 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell13)); |
| 178 EXPECT_TRUE(HasEndBorderAdjoiningTable(cell13)); |
| 179 |
| 180 EXPECT_TRUE(HasStartBorderAdjoiningTable(cell21)); |
| 181 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell21)); |
| 182 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell22)); |
| 183 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell22)); |
| 184 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell23)); |
| 185 EXPECT_TRUE(HasEndBorderAdjoiningTable(cell23)); |
| 186 |
| 187 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell31)); |
| 188 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell31)); |
| 189 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell32)); |
| 190 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell32)); |
| 191 } |
| 192 |
| 193 TEST_F(LayoutTableCellTest, HasBorderAdjoiningTableRTL) { |
| 194 SetBodyInnerHTML( |
| 195 "<style>" |
| 196 " table { direction: rtl }" |
| 197 " td { direction: ltr }" |
| 198 "</style>" |
| 199 "<table id='table'>" |
| 200 " <tr>" |
| 201 " <td id='cell11' colspan='2000'></td>" |
| 202 " <td id='cell12'></td>" |
| 203 " <td id='cell13'></td>" |
| 204 " </tr>" |
| 205 " <tr>" |
| 206 " <td id='cell21' rowspan='2'></td>" |
| 207 " <td id='cell22'></td>" |
| 208 " <td id='cell23' colspan='2000'></td>" |
| 209 " </tr>" |
| 210 " <tr>" |
| 211 " <td id='cell31'></td>" |
| 212 " <td id='cell32'></td>" |
| 213 " </tr>" |
| 214 "</table>"); |
| 215 |
| 216 const auto* cell11 = GetCellByElementId("cell11"); |
| 217 const auto* cell12 = GetCellByElementId("cell12"); |
| 218 const auto* cell13 = GetCellByElementId("cell13"); |
| 219 const auto* cell21 = GetCellByElementId("cell21"); |
| 220 const auto* cell22 = GetCellByElementId("cell22"); |
| 221 const auto* cell23 = GetCellByElementId("cell23"); |
| 222 const auto* cell31 = GetCellByElementId("cell31"); |
| 223 const auto* cell32 = GetCellByElementId("cell32"); |
| 224 |
| 225 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell11)); |
| 226 EXPECT_TRUE(HasEndBorderAdjoiningTable(cell11)); |
| 227 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell12)); |
| 228 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell12)); |
| 229 EXPECT_TRUE(HasStartBorderAdjoiningTable(cell13)); |
| 230 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell13)); |
| 231 |
| 232 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell21)); |
| 233 EXPECT_TRUE(HasEndBorderAdjoiningTable(cell21)); |
| 234 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell22)); |
| 235 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell22)); |
| 236 EXPECT_TRUE(HasStartBorderAdjoiningTable(cell23)); |
| 237 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell23)); |
| 238 |
| 239 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell31)); |
| 240 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell31)); |
| 241 EXPECT_FALSE(HasStartBorderAdjoiningTable(cell32)); |
| 242 EXPECT_FALSE(HasEndBorderAdjoiningTable(cell32)); |
| 243 } |
172 | 244 |
173 } // namespace blink | 245 } // namespace blink |
OLD | NEW |