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

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

Issue 2836293004: [LayoutNG] Move NGInlineNode data to NGInlineNodeData. (Closed)
Patch Set: rebase. Created 3 years, 7 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/inline/ng_inline_node.h" 5 #include "core/layout/ng/inline/ng_inline_node.h"
6 6
7 #include "core/layout/LayoutTestHelper.h" 7 #include "core/layout/LayoutTestHelper.h"
8 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" 8 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h"
9 #include "core/layout/ng/inline/ng_physical_line_box_fragment.h" 9 #include "core/layout/ng/inline/ng_physical_line_box_fragment.h"
10 #include "core/layout/ng/inline/ng_physical_text_fragment.h" 10 #include "core/layout/ng/inline/ng_physical_text_fragment.h"
11 #include "core/layout/ng/inline/ng_text_fragment.h" 11 #include "core/layout/ng/inline/ng_text_fragment.h"
12 #include "core/layout/ng/ng_constraint_space.h" 12 #include "core/layout/ng/ng_constraint_space.h"
13 #include "core/layout/ng/ng_constraint_space_builder.h" 13 #include "core/layout/ng/ng_constraint_space_builder.h"
14 #include "core/layout/ng/ng_fragment_builder.h" 14 #include "core/layout/ng/ng_fragment_builder.h"
15 #include "core/layout/ng/ng_physical_box_fragment.h" 15 #include "core/layout/ng/ng_physical_box_fragment.h"
16 #include "core/style/ComputedStyle.h" 16 #include "core/style/ComputedStyle.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 class NGInlineNodeForTest : public NGInlineNode { 21 class NGInlineNodeForTest : public NGInlineNode {
22 public: 22 public:
23 using NGInlineNode::NGInlineNode; 23 using NGInlineNode::NGInlineNode;
24 24
25 String& Text() { return text_content_; } 25 String& Text() { return MutableData().text_content_; }
26 Vector<NGInlineItem>& Items() { return items_; } 26 Vector<NGInlineItem>& Items() { return MutableData().items_; }
27 27
28 void Append(const String& text, 28 void Append(const String& text,
29 const ComputedStyle* style = nullptr, 29 const ComputedStyle* style = nullptr,
30 LayoutObject* layout_object = nullptr) { 30 LayoutObject* layout_object = nullptr) {
31 unsigned start = text_content_.length(); 31 unsigned start = Data().text_content_.length();
32 text_content_.append(text); 32 MutableData().text_content_.append(text);
33 items_.push_back(NGInlineItem(NGInlineItem::kText, start, 33 MutableData().items_.push_back(NGInlineItem(NGInlineItem::kText, start,
34 start + text.length(), style, layout_object)); 34 start + text.length(), style,
35 layout_object));
35 } 36 }
36 37
37 void Append(UChar character) { 38 void Append(UChar character) {
38 text_content_.append(character); 39 MutableData().text_content_.append(character);
39 unsigned end = text_content_.length(); 40 unsigned end = Data().text_content_.length();
40 items_.push_back( 41 MutableData().items_.push_back(
41 NGInlineItem(NGInlineItem::kBidiControl, end - 1, end, nullptr)); 42 NGInlineItem(NGInlineItem::kBidiControl, end - 1, end, nullptr));
42 is_bidi_enabled_ = true; 43 MutableData().is_bidi_enabled_ = true;
43 } 44 }
44 45
45 void ClearText() { 46 void ClearText() {
46 text_content_ = String(); 47 MutableData().text_content_ = String();
47 items_.clear(); 48 MutableData().items_.clear();
48 } 49 }
49 50
50 void SegmentText() { 51 void SegmentText() {
51 is_bidi_enabled_ = true; 52 MutableData().is_bidi_enabled_ = true;
52 NGInlineNode::SegmentText(); 53 NGInlineNode::SegmentText();
53 } 54 }
54 55
55 using NGInlineNode::CollectInlines; 56 using NGInlineNode::CollectInlines;
56 using NGInlineNode::ShapeText; 57 using NGInlineNode::ShapeText;
57 }; 58 };
58 59
59 class NGInlineNodeTest : public RenderingTest { 60 class NGInlineNodeTest : public RenderingTest {
60 protected: 61 protected:
61 void SetUp() override { 62 void SetUp() override {
62 RenderingTest::SetUp(); 63 RenderingTest::SetUp();
64 RuntimeEnabledFeatures::setLayoutNGEnabled(true);
63 style_ = ComputedStyle::Create(); 65 style_ = ComputedStyle::Create();
64 style_->GetFont().Update(nullptr); 66 style_->GetFont().Update(nullptr);
65 } 67 }
66 68
69 void TearDown() override {
70 RuntimeEnabledFeatures::setLayoutNGEnabled(false);
71 RenderingTest::TearDown();
72 }
73
67 void SetupHtml(const char* id, String html) { 74 void SetupHtml(const char* id, String html) {
68 SetBodyInnerHTML(html); 75 SetBodyInnerHTML(html);
69 layout_block_flow_ = ToLayoutBlockFlow(GetLayoutObjectByElementId(id)); 76 layout_block_flow_ = ToLayoutNGBlockFlow(GetLayoutObjectByElementId(id));
70 layout_object_ = layout_block_flow_->FirstChild(); 77 layout_object_ = layout_block_flow_->FirstChild();
71 style_ = layout_object_->Style(); 78 style_ = layout_object_->Style();
72 } 79 }
73 80
74 void UseLayoutObjectAndAhem() { 81 void UseLayoutObjectAndAhem() {
75 // Get Ahem from document. Loading "Ahem.woff" using |createTestFont| fails 82 // Get Ahem from document. Loading "Ahem.woff" using |createTestFont| fails
76 // on linux_chromium_asan_rel_ng. 83 // on linux_chromium_asan_rel_ng.
77 LoadAhem(); 84 LoadAhem();
78 SetupHtml("t", "<div id=t style='font:10px Ahem'>test</div>"); 85 SetupHtml("t", "<div id=t style='font:10px Ahem'>test</div>");
79 } 86 }
(...skipping 16 matching lines...) Expand all
96 ToNGPhysicalBoxFragment(result->PhysicalFragment().Get()); 103 ToNGPhysicalBoxFragment(result->PhysicalFragment().Get());
97 EXPECT_EQ(container->Children().size(), 1u); 104 EXPECT_EQ(container->Children().size(), 1u);
98 const NGPhysicalLineBoxFragment* line = 105 const NGPhysicalLineBoxFragment* line =
99 ToNGPhysicalLineBoxFragment(container->Children()[0].Get()); 106 ToNGPhysicalLineBoxFragment(container->Children()[0].Get());
100 for (const auto& child : line->Children()) { 107 for (const auto& child : line->Children()) {
101 fragments_out->push_back(ToNGPhysicalTextFragment(child.Get())); 108 fragments_out->push_back(ToNGPhysicalTextFragment(child.Get()));
102 } 109 }
103 } 110 }
104 111
105 RefPtr<const ComputedStyle> style_; 112 RefPtr<const ComputedStyle> style_;
106 LayoutBlockFlow* layout_block_flow_ = nullptr; 113 LayoutNGBlockFlow* layout_block_flow_ = nullptr;
107 LayoutObject* layout_object_ = nullptr; 114 LayoutObject* layout_object_ = nullptr;
108 FontCachePurgePreventer purge_preventer_; 115 FontCachePurgePreventer purge_preventer_;
109 }; 116 };
110 117
111 #define TEST_ITEM_TYPE_OFFSET(item, type, start, end) \ 118 #define TEST_ITEM_TYPE_OFFSET(item, type, start, end) \
112 EXPECT_EQ(NGInlineItem::type, item.Type()); \ 119 EXPECT_EQ(NGInlineItem::type, item.Type()); \
113 EXPECT_EQ(start, item.StartOffset()); \ 120 EXPECT_EQ(start, item.StartOffset()); \
114 EXPECT_EQ(end, item.EndOffset()) 121 EXPECT_EQ(end, item.EndOffset())
115 122
116 #define TEST_ITEM_TYPE_OFFSET_LEVEL(item, type, start, end, level) \ 123 #define TEST_ITEM_TYPE_OFFSET_LEVEL(item, type, start, end, level) \
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 MinMaxContentSize sizes = node->ComputeMinMaxContentSize(); 331 MinMaxContentSize sizes = node->ComputeMinMaxContentSize();
325 // |min_content| should be the width of "BC" because there is an element 332 // |min_content| should be the width of "BC" because there is an element
326 // boundary between "B" and "C" but no break opportunities. 333 // boundary between "B" and "C" but no break opportunities.
327 // TODO(kojii): min_content should be 20, but is 30 until 334 // TODO(kojii): min_content should be 20, but is 30 until
328 // NGInlineLayoutAlgorithm implements trailing spaces correctly. 335 // NGInlineLayoutAlgorithm implements trailing spaces correctly.
329 EXPECT_EQ(30, sizes.min_content); 336 EXPECT_EQ(30, sizes.min_content);
330 EXPECT_EQ(60, sizes.max_content); 337 EXPECT_EQ(60, sizes.max_content);
331 } 338 }
332 339
333 } // namespace blink 340 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698