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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_layout_inline_items_builder_test.cc

Issue 2749013003: [LayoutNG] Fix whitespace collapsing when a node is a newline (Closed)
Patch Set: Created 3 years, 9 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/layout/ng/ng_layout_inline_items_builder.cc ('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/ng/ng_layout_inline_items_builder.h" 5 #include "core/layout/ng/ng_layout_inline_items_builder.h"
6 6
7 #include "core/layout/LayoutInline.h" 7 #include "core/layout/LayoutInline.h"
8 #include "core/layout/ng/ng_inline_node.h" 8 #include "core/layout/ng/ng_inline_node.h"
9 #include "core/style/ComputedStyle.h" 9 #include "core/style/ComputedStyle.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 String collapsed("text text text text"); 90 String collapsed("text text text text");
91 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNormal); 91 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNormal);
92 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNowrap); 92 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNowrap);
93 TestWhitespaceValue(collapsed, input, EWhiteSpace::kWebkitNowrap); 93 TestWhitespaceValue(collapsed, input, EWhiteSpace::kWebkitNowrap);
94 TestWhitespaceValue(collapsed, input, EWhiteSpace::kPreLine); 94 TestWhitespaceValue(collapsed, input, EWhiteSpace::kPreLine);
95 TestWhitespaceValue(input, input, EWhiteSpace::kPre); 95 TestWhitespaceValue(input, input, EWhiteSpace::kPre);
96 TestWhitespaceValue(input, input, EWhiteSpace::kPreWrap); 96 TestWhitespaceValue(input, input, EWhiteSpace::kPreWrap);
97 } 97 }
98 98
99 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseNewLines) { 99 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseNewLines) {
100 String input("text\ntext \n text"); 100 String input("text\ntext \n text\n\ntext");
101 String collapsed("text text text"); 101 String collapsed("text text text text");
102 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNormal); 102 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNormal);
103 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNowrap); 103 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNowrap);
104 TestWhitespaceValue("text\ntext\ntext", input, EWhiteSpace::kPreLine); 104 TestWhitespaceValue("text\ntext\ntext\n\ntext", input, EWhiteSpace::kPreLine);
105 TestWhitespaceValue(input, input, EWhiteSpace::kPre); 105 TestWhitespaceValue(input, input, EWhiteSpace::kPre);
106 TestWhitespaceValue(input, input, EWhiteSpace::kPreWrap); 106 TestWhitespaceValue(input, input, EWhiteSpace::kPreWrap);
107 } 107 }
108 108
109 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseNewlinesAsSpaces) {
110 EXPECT_EQ("text text", TestAppend("text\ntext"));
111 EXPECT_EQ("text text", TestAppend("text\n\ntext"));
112 EXPECT_EQ("text text", TestAppend("text \n\n text"));
113 EXPECT_EQ("text text", TestAppend("text \n \n text"));
114 }
115
109 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseAcrossElements) { 116 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseAcrossElements) {
110 EXPECT_EQ("text text", TestAppend("text ", " text")) 117 EXPECT_EQ("text text", TestAppend("text ", " text"))
111 << "Spaces are collapsed even when across elements."; 118 << "Spaces are collapsed even when across elements.";
112 } 119 }
113 120
114 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseLeadingSpaces) { 121 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseLeadingSpaces) {
115 EXPECT_EQ("text", TestAppend(" text")); 122 EXPECT_EQ("text", TestAppend(" text"));
116 EXPECT_EQ("text", TestAppend(" ", "text")); 123 EXPECT_EQ("text", TestAppend(" ", "text"));
117 EXPECT_EQ("text", TestAppend(" ", " text")); 124 EXPECT_EQ("text", TestAppend(" ", " text"));
118 } 125 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 NGLayoutInlineItemsBuilder builder(&items_); 175 NGLayoutInlineItemsBuilder builder(&items_);
169 RefPtr<ComputedStyle> pre_wrap(CreateWhitespaceStyle(EWhiteSpace::kPreWrap)); 176 RefPtr<ComputedStyle> pre_wrap(CreateWhitespaceStyle(EWhiteSpace::kPreWrap));
170 builder.Append("text ", pre_wrap.get()); 177 builder.Append("text ", pre_wrap.get());
171 builder.Append(" text", style_.get()); 178 builder.Append(" text", style_.get());
172 EXPECT_EQ("text text", builder.ToString()) 179 EXPECT_EQ("text text", builder.ToString())
173 << "The whitespace in constructions like '<span style=\"white-space: " 180 << "The whitespace in constructions like '<span style=\"white-space: "
174 "pre-wrap\">text <span><span> text</span>' does not collapse."; 181 "pre-wrap\">text <span><span> text</span>' does not collapse.";
175 } 182 }
176 183
177 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseZeroWidthSpaces) { 184 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseZeroWidthSpaces) {
178 EXPECT_EQ("text text", TestAppend("text\ntext"))
179 << "Newline is converted to a space.";
180
181 EXPECT_EQ(String(u"text\u200Btext"), TestAppend(u"text\u200B\ntext")) 185 EXPECT_EQ(String(u"text\u200Btext"), TestAppend(u"text\u200B\ntext"))
182 << "Newline is removed if the character before is ZWS."; 186 << "Newline is removed if the character before is ZWS.";
183 EXPECT_EQ(String(u"text\u200Btext"), TestAppend(u"text\n\u200Btext")) 187 EXPECT_EQ(String(u"text\u200Btext"), TestAppend(u"text\n\u200Btext"))
184 << "Newline is removed if the character after is ZWS."; 188 << "Newline is removed if the character after is ZWS.";
185 EXPECT_EQ(String(u"text\u200B\u200Btext"), 189 EXPECT_EQ(String(u"text\u200B\u200Btext"),
186 TestAppend(u"text\u200B\n\u200Btext")) 190 TestAppend(u"text\u200B\n\u200Btext"))
187 << "Newline is removed if the character before/after is ZWS."; 191 << "Newline is removed if the character before/after is ZWS.";
188 192
189 EXPECT_EQ(String(u"text\u200Btext"), TestAppend(u"text\n", u"\u200Btext")) 193 EXPECT_EQ(String(u"text\u200Btext"), TestAppend(u"text\n", u"\u200Btext"))
190 << "Newline is removed if the character after across elements is ZWS."; 194 << "Newline is removed if the character after across elements is ZWS.";
(...skipping 26 matching lines...) Expand all
217 } 221 }
218 222
219 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseAroundReplacedElement) { 223 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseAroundReplacedElement) {
220 NGLayoutInlineItemsBuilder builder(&items_); 224 NGLayoutInlineItemsBuilder builder(&items_);
221 builder.Append("Hello ", style_.get()); 225 builder.Append("Hello ", style_.get());
222 builder.Append(objectReplacementCharacter); 226 builder.Append(objectReplacementCharacter);
223 builder.Append(" World", style_.get()); 227 builder.Append(" World", style_.get());
224 EXPECT_EQ(String(u"Hello \uFFFC World"), builder.ToString()); 228 EXPECT_EQ(String(u"Hello \uFFFC World"), builder.ToString());
225 } 229 }
226 230
227 TEST_F(NGLayoutInlineItemsBuilderTest, AppendAsOpaqueToSpaceCollapsing) { 231 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseNewlineAfterObject) {
228 NGLayoutInlineItemsBuilder builder(&items_); 232 NGLayoutInlineItemsBuilder builder(&items_);
229 builder.Append("Hello ", style_.get()); 233 builder.Append(objectReplacementCharacter);
230 builder.AppendAsOpaqueToSpaceCollapsing(firstStrongIsolateCharacter); 234 builder.Append("\n", style_.get());
231 builder.Append(" World", style_.get()); 235 builder.Append(objectReplacementCharacter);
232 EXPECT_EQ(String(u"Hello \u2068World"), builder.ToString()); 236 EXPECT_EQ(String(u"\uFFFC \uFFFC"), builder.ToString());
237 EXPECT_EQ(3u, items_.size());
238 EXPECT_EQ(nullptr, items_[0].Style());
239 EXPECT_EQ(style_.get(), items_[1].Style());
240 EXPECT_EQ(nullptr, items_[2].Style());
233 } 241 }
234 242
235 TEST_F(NGLayoutInlineItemsBuilderTest, AppendEmptyString) { 243 TEST_F(NGLayoutInlineItemsBuilderTest, AppendEmptyString) {
236 EXPECT_EQ("", TestAppend("")); 244 EXPECT_EQ("", TestAppend(""));
237 EXPECT_EQ(0u, items_.size()); 245 EXPECT_EQ(0u, items_.size());
238 } 246 }
239 247
240 TEST_F(NGLayoutInlineItemsBuilderTest, Empty) { 248 TEST_F(NGLayoutInlineItemsBuilderTest, Empty) {
241 Vector<NGLayoutInlineItem> items; 249 Vector<NGLayoutInlineItem> items;
242 NGLayoutInlineItemsBuilder builder(&items); 250 NGLayoutInlineItemsBuilder builder(&items);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 u"\u2068\u202E" 326 u"\u2068\u202E"
319 u"\u05E2\u05D1\u05E8\u05D9\u05EA" 327 u"\u05E2\u05D1\u05E8\u05D9\u05EA"
320 u"\u202C\u2069" 328 u"\u202C\u2069"
321 u" World"), 329 u" World"),
322 builder.ToString()); 330 builder.ToString());
323 } 331 }
324 332
325 } // namespace 333 } // namespace
326 334
327 } // namespace blink 335 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_layout_inline_items_builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698