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

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

Issue 2614883007: Change computed style enums to be prefixed with 'k'. (Closed)
Patch Set: Rebase on ToT. Created 3 years, 11 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
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 #include "core/layout/LayoutInline.h" 6 #include "core/layout/LayoutInline.h"
7 #include "core/layout/ng/ng_inline_node.h" 7 #include "core/layout/ng/ng_inline_node.h"
8 #include "core/style/ComputedStyle.h" 8 #include "core/style/ComputedStyle.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 RefPtr<ComputedStyle> style_; 50 RefPtr<ComputedStyle> style_;
51 }; 51 };
52 52
53 #define TestWhitespaceValue(expected, input, whitespace) \ 53 #define TestWhitespaceValue(expected, input, whitespace) \
54 SetWhiteSpace(whitespace); \ 54 SetWhiteSpace(whitespace); \
55 EXPECT_EQ(expected, TestAppend(input)) << "white-space: " #whitespace; 55 EXPECT_EQ(expected, TestAppend(input)) << "white-space: " #whitespace;
56 56
57 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseSpaces) { 57 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseSpaces) {
58 String input("text text text text"); 58 String input("text text text text");
59 String collapsed("text text text text"); 59 String collapsed("text text text text");
60 TestWhitespaceValue(collapsed, input, EWhiteSpace::Normal); 60 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNormal);
61 TestWhitespaceValue(collapsed, input, EWhiteSpace::Nowrap); 61 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNowrap);
62 TestWhitespaceValue(collapsed, input, EWhiteSpace::WebkitNowrap); 62 TestWhitespaceValue(collapsed, input, EWhiteSpace::kWebkitNowrap);
63 TestWhitespaceValue(collapsed, input, EWhiteSpace::PreLine); 63 TestWhitespaceValue(collapsed, input, EWhiteSpace::kPreLine);
64 TestWhitespaceValue(input, input, EWhiteSpace::Pre); 64 TestWhitespaceValue(input, input, EWhiteSpace::kPre);
65 TestWhitespaceValue(input, input, EWhiteSpace::PreWrap); 65 TestWhitespaceValue(input, input, EWhiteSpace::kPreWrap);
66 } 66 }
67 67
68 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseTabs) { 68 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseTabs) {
69 String input("text\ttext\t text \t text"); 69 String input("text\ttext\t text \t text");
70 String collapsed("text text text text"); 70 String collapsed("text text text text");
71 TestWhitespaceValue(collapsed, input, EWhiteSpace::Normal); 71 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNormal);
72 TestWhitespaceValue(collapsed, input, EWhiteSpace::Nowrap); 72 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNowrap);
73 TestWhitespaceValue(collapsed, input, EWhiteSpace::WebkitNowrap); 73 TestWhitespaceValue(collapsed, input, EWhiteSpace::kWebkitNowrap);
74 TestWhitespaceValue(collapsed, input, EWhiteSpace::PreLine); 74 TestWhitespaceValue(collapsed, input, EWhiteSpace::kPreLine);
75 TestWhitespaceValue(input, input, EWhiteSpace::Pre); 75 TestWhitespaceValue(input, input, EWhiteSpace::kPre);
76 TestWhitespaceValue(input, input, EWhiteSpace::PreWrap); 76 TestWhitespaceValue(input, input, EWhiteSpace::kPreWrap);
77 } 77 }
78 78
79 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseNewLines) { 79 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseNewLines) {
80 String input("text\ntext \n text"); 80 String input("text\ntext \n text");
81 String collapsed("text text text"); 81 String collapsed("text text text");
82 TestWhitespaceValue(collapsed, input, EWhiteSpace::Normal); 82 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNormal);
83 TestWhitespaceValue(collapsed, input, EWhiteSpace::Nowrap); 83 TestWhitespaceValue(collapsed, input, EWhiteSpace::kNowrap);
84 TestWhitespaceValue("text\ntext\ntext", input, EWhiteSpace::PreLine); 84 TestWhitespaceValue("text\ntext\ntext", input, EWhiteSpace::kPreLine);
85 TestWhitespaceValue(input, input, EWhiteSpace::Pre); 85 TestWhitespaceValue(input, input, EWhiteSpace::kPre);
86 TestWhitespaceValue(input, input, EWhiteSpace::PreWrap); 86 TestWhitespaceValue(input, input, EWhiteSpace::kPreWrap);
87 } 87 }
88 88
89 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseAcrossElements) { 89 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseAcrossElements) {
90 EXPECT_EQ("text text", TestAppend("text ", " text")) 90 EXPECT_EQ("text text", TestAppend("text ", " text"))
91 << "Spaces are collapsed even when across elements."; 91 << "Spaces are collapsed even when across elements.";
92 } 92 }
93 93
94 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseLeadingSpaces) { 94 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseLeadingSpaces) {
95 EXPECT_EQ("text", TestAppend(" text")) << "Leading spaces are removed."; 95 EXPECT_EQ("text", TestAppend(" text")) << "Leading spaces are removed.";
96 } 96 }
97 97
98 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseBeforeAndAfterNewline) { 98 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseBeforeAndAfterNewline) {
99 SetWhiteSpace(EWhiteSpace::PreLine); 99 SetWhiteSpace(EWhiteSpace::kPreLine);
100 EXPECT_EQ("text\ntext", TestAppend("text \n text")) 100 EXPECT_EQ("text\ntext", TestAppend("text \n text"))
101 << "Spaces before and after newline are removed."; 101 << "Spaces before and after newline are removed.";
102 } 102 }
103 103
104 TEST_F(NGLayoutInlineItemsBuilderTest, 104 TEST_F(NGLayoutInlineItemsBuilderTest,
105 CollapsibleSpaceAfterNonCollapsibleSpaceAcrossElements) { 105 CollapsibleSpaceAfterNonCollapsibleSpaceAcrossElements) {
106 NGLayoutInlineItemsBuilder builder(&items_); 106 NGLayoutInlineItemsBuilder builder(&items_);
107 RefPtr<ComputedStyle> pre_wrap(CreateWhitespaceStyle(EWhiteSpace::PreWrap)); 107 RefPtr<ComputedStyle> pre_wrap(CreateWhitespaceStyle(EWhiteSpace::kPreWrap));
108 builder.Append("text ", pre_wrap.get()); 108 builder.Append("text ", pre_wrap.get());
109 builder.Append(" text", style_.get()); 109 builder.Append(" text", style_.get());
110 EXPECT_EQ("text text", builder.ToString()) 110 EXPECT_EQ("text text", builder.ToString())
111 << "The whitespace in constructions like '<span style=\"white-space: " 111 << "The whitespace in constructions like '<span style=\"white-space: "
112 "pre-wrap\">text <span><span> text</span>' does not collapse."; 112 "pre-wrap\">text <span><span> text</span>' does not collapse.";
113 } 113 }
114 114
115 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseZeroWidthSpaces) { 115 TEST_F(NGLayoutInlineItemsBuilderTest, CollapseZeroWidthSpaces) {
116 EXPECT_EQ("text text", TestAppend("text\ntext")) 116 EXPECT_EQ("text text", TestAppend("text\ntext"))
117 << "Newline is converted to a space."; 117 << "Newline is converted to a space.";
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 builder.ExitBlock(); 180 builder.ExitBlock();
181 181
182 EXPECT_EQ("", builder.ToString()); 182 EXPECT_EQ("", builder.ToString());
183 } 183 }
184 184
185 TEST_F(NGLayoutInlineItemsBuilderTest, BidiBlockOverride) { 185 TEST_F(NGLayoutInlineItemsBuilderTest, BidiBlockOverride) {
186 Vector<NGLayoutInlineItem> items; 186 Vector<NGLayoutInlineItem> items;
187 NGLayoutInlineItemsBuilder builder(&items); 187 NGLayoutInlineItemsBuilder builder(&items);
188 RefPtr<ComputedStyle> block_style(ComputedStyle::create()); 188 RefPtr<ComputedStyle> block_style(ComputedStyle::create());
189 block_style->setUnicodeBidi(Override); 189 block_style->setUnicodeBidi(Override);
190 block_style->setDirection(TextDirection::Rtl); 190 block_style->setDirection(TextDirection::kRtl);
191 builder.EnterBlock(block_style.get()); 191 builder.EnterBlock(block_style.get());
192 builder.Append("Hello", style_.get()); 192 builder.Append("Hello", style_.get());
193 builder.ExitBlock(); 193 builder.ExitBlock();
194 194
195 // Expected control characters as defined in: 195 // Expected control characters as defined in:
196 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection- table 196 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection- table
197 EXPECT_EQ(String(u"\u202E" 197 EXPECT_EQ(String(u"\u202E"
198 u"Hello" 198 u"Hello"
199 u"\u202C"), 199 u"\u202C"),
200 builder.ToString()); 200 builder.ToString());
201 } 201 }
202 202
203 static std::unique_ptr<LayoutInline> createLayoutInline( 203 static std::unique_ptr<LayoutInline> createLayoutInline(
204 void (*initialize_style)(ComputedStyle*)) { 204 void (*initialize_style)(ComputedStyle*)) {
205 RefPtr<ComputedStyle> style(ComputedStyle::create()); 205 RefPtr<ComputedStyle> style(ComputedStyle::create());
206 initialize_style(style.get()); 206 initialize_style(style.get());
207 std::unique_ptr<LayoutInline> node = WTF::makeUnique<LayoutInline>(nullptr); 207 std::unique_ptr<LayoutInline> node = WTF::makeUnique<LayoutInline>(nullptr);
208 node->setStyleInternal(std::move(style)); 208 node->setStyleInternal(std::move(style));
209 return node; 209 return node;
210 } 210 }
211 211
212 TEST_F(NGLayoutInlineItemsBuilderTest, BidiIsolate) { 212 TEST_F(NGLayoutInlineItemsBuilderTest, BidiIsolate) {
213 Vector<NGLayoutInlineItem> items; 213 Vector<NGLayoutInlineItem> items;
214 NGLayoutInlineItemsBuilder builder(&items); 214 NGLayoutInlineItemsBuilder builder(&items);
215 builder.Append("Hello ", style_.get()); 215 builder.Append("Hello ", style_.get());
216 std::unique_ptr<LayoutInline> isolateRTL( 216 std::unique_ptr<LayoutInline> isolateRTL(
217 createLayoutInline([](ComputedStyle* style) { 217 createLayoutInline([](ComputedStyle* style) {
218 style->setUnicodeBidi(Isolate); 218 style->setUnicodeBidi(Isolate);
219 style->setDirection(TextDirection::Rtl); 219 style->setDirection(TextDirection::kRtl);
220 })); 220 }));
221 builder.EnterInline(isolateRTL.get()); 221 builder.EnterInline(isolateRTL.get());
222 builder.Append(u"\u05E2\u05D1\u05E8\u05D9\u05EA", style_.get()); 222 builder.Append(u"\u05E2\u05D1\u05E8\u05D9\u05EA", style_.get());
223 builder.ExitInline(isolateRTL.get()); 223 builder.ExitInline(isolateRTL.get());
224 builder.Append(" World", style_.get()); 224 builder.Append(" World", style_.get());
225 225
226 // Expected control characters as defined in: 226 // Expected control characters as defined in:
227 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection- table 227 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection- table
228 EXPECT_EQ(String(u"Hello " 228 EXPECT_EQ(String(u"Hello "
229 u"\u2067" 229 u"\u2067"
230 u"\u05E2\u05D1\u05E8\u05D9\u05EA" 230 u"\u05E2\u05D1\u05E8\u05D9\u05EA"
231 u"\u2069" 231 u"\u2069"
232 u" World"), 232 u" World"),
233 builder.ToString()); 233 builder.ToString());
234 } 234 }
235 235
236 TEST_F(NGLayoutInlineItemsBuilderTest, BidiIsolateOverride) { 236 TEST_F(NGLayoutInlineItemsBuilderTest, BidiIsolateOverride) {
237 Vector<NGLayoutInlineItem> items; 237 Vector<NGLayoutInlineItem> items;
238 NGLayoutInlineItemsBuilder builder(&items); 238 NGLayoutInlineItemsBuilder builder(&items);
239 builder.Append("Hello ", style_.get()); 239 builder.Append("Hello ", style_.get());
240 std::unique_ptr<LayoutInline> isolateOverrideRTL( 240 std::unique_ptr<LayoutInline> isolateOverrideRTL(
241 createLayoutInline([](ComputedStyle* style) { 241 createLayoutInline([](ComputedStyle* style) {
242 style->setUnicodeBidi(IsolateOverride); 242 style->setUnicodeBidi(IsolateOverride);
243 style->setDirection(TextDirection::Rtl); 243 style->setDirection(TextDirection::kRtl);
244 })); 244 }));
245 builder.EnterInline(isolateOverrideRTL.get()); 245 builder.EnterInline(isolateOverrideRTL.get());
246 builder.Append(u"\u05E2\u05D1\u05E8\u05D9\u05EA", style_.get()); 246 builder.Append(u"\u05E2\u05D1\u05E8\u05D9\u05EA", style_.get());
247 builder.ExitInline(isolateOverrideRTL.get()); 247 builder.ExitInline(isolateOverrideRTL.get());
248 builder.Append(" World", style_.get()); 248 builder.Append(" World", style_.get());
249 249
250 // Expected control characters as defined in: 250 // Expected control characters as defined in:
251 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection- table 251 // https://drafts.csswg.org/css-writing-modes-3/#bidi-control-codes-injection- table
252 EXPECT_EQ(String(u"Hello " 252 EXPECT_EQ(String(u"Hello "
253 u"\u2068\u202E" 253 u"\u2068\u202E"
254 u"\u05E2\u05D1\u05E8\u05D9\u05EA" 254 u"\u05E2\u05D1\u05E8\u05D9\u05EA"
255 u"\u202C\u2069" 255 u"\u202C\u2069"
256 u" World"), 256 u" World"),
257 builder.ToString()); 257 builder.ToString());
258 } 258 }
259 259
260 } // namespace 260 } // namespace
261 261
262 } // namespace blink 262 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698