Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTextTest.cpp

Issue 2369963005: Avoid creating consecutive whitespace renderers. (Closed)
Patch Set: Rebased and manually fixed expectations Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/Text.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/LayoutText.h" 5 #include "core/layout/LayoutText.h"
6 6
7 #include "core/layout/LayoutTestHelper.h" 7 #include "core/layout/LayoutTestHelper.h"
8 #include "core/layout/line/InlineTextBox.h" 8 #include "core/layout/line/InlineTextBox.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 TEST_F(LayoutTextTest, WidthLengthBeyondLength) 79 TEST_F(LayoutTextTest, WidthLengthBeyondLength)
80 { 80 {
81 setBasicBody("x"); 81 setBasicBody("x");
82 // Width may vary by platform and we just want to make sure it's something r oughly reasonable. 82 // Width may vary by platform and we just want to make sure it's something r oughly reasonable.
83 float width = getBasicText()->width(0u, 2u, LayoutUnit(), LTR, false); 83 float width = getBasicText()->width(0u, 2u, LayoutUnit(), LTR, false);
84 ASSERT_GE(width, 4.f); 84 ASSERT_GE(width, 4.f);
85 ASSERT_LE(width, 20.f); 85 ASSERT_LE(width, 20.f);
86 } 86 }
87 87
88 TEST_F(LayoutTextTest, ConsecutiveWhitespaceRenderersInsertAfterWS)
89 {
90 setBodyInnerHTML("<span></span> <span id='span'></span>");
91
92 Element* span = document().getElementById("span");
93 Node* whitespace1 = span->previousSibling();
94 EXPECT_TRUE(whitespace1->layoutObject());
95
96 Node* whitespace2 = Text::create(document(), " ");
97 document().body()->insertBefore(whitespace2, span, ASSERT_NO_EXCEPTION);
98 document().view()->updateAllLifecyclePhases();
99
100 EXPECT_TRUE(whitespace1->layoutObject());
101 EXPECT_FALSE(whitespace2->layoutObject());
102 }
103
104 TEST_F(LayoutTextTest, ConsecutiveWhitespaceRenderersInsertBeforeWS)
105 {
106 setBodyInnerHTML("<span id='span'></span> <span></span>");
107
108 Element* span = document().getElementById("span");
109 Node* whitespace2 = span->nextSibling();
110 EXPECT_TRUE(whitespace2->layoutObject());
111
112 Node* whitespace1 = Text::create(document(), " ");
113 document().body()->insertBefore(whitespace1, whitespace2, ASSERT_NO_EXCEPTIO N);
114 document().view()->updateAllLifecyclePhases();
115
116 EXPECT_TRUE(whitespace1->layoutObject());
117 EXPECT_FALSE(whitespace2->layoutObject());
118 }
119
120 TEST_F(LayoutTextTest, ConsecutiveWhitespaceRenderersDisplayNone)
121 {
122 setBodyInnerHTML("<span></span> <span style='display:none'></span> <span></s pan>");
123
124 // First <span>
125 Node* child = document().body()->firstChild();
126 ASSERT_TRUE(child);
127
128 // First whitespace node
129 child = child->nextSibling();
130 ASSERT_TRUE(child);
131 EXPECT_TRUE(child->isTextNode());
132 EXPECT_TRUE(child->layoutObject());
133
134 // <span display:none>
135 child = child->nextSibling();
136 ASSERT_TRUE(child);
137 EXPECT_FALSE(child->layoutObject());
138
139 // Second whitespace node
140 child = child->nextSibling();
141 ASSERT_TRUE(child);
142 EXPECT_TRUE(child->isTextNode());
143 EXPECT_FALSE(child->layoutObject());
144 }
145
146 TEST_F(LayoutTextTest, ConsecutiveWhitespaceRenderersComment)
147 {
148 setBodyInnerHTML("<span></span> <!-- --> <span></span>");
149
150 // First <span>
151 Node* child = document().body()->firstChild();
152 ASSERT_TRUE(child);
153
154 // First whitespace node
155 child = child->nextSibling();
156 ASSERT_TRUE(child);
157 EXPECT_TRUE(child->isTextNode());
158 EXPECT_TRUE(child->layoutObject());
159
160 // Comment node
161 child = child->nextSibling();
162 ASSERT_TRUE(child);
163 EXPECT_FALSE(child->layoutObject());
164
165 // Second whitespace node
166 child = child->nextSibling();
167 ASSERT_TRUE(child);
168 EXPECT_TRUE(child->isTextNode());
169 EXPECT_FALSE(child->layoutObject());
170 }
171
88 } // namespace blink 172 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Text.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698