OLD | NEW |
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/layout_ng_block_flow.h" | 5 #include "core/layout/ng/layout_ng_block_flow.h" |
6 #include "core/layout/ng/ng_block_layout_algorithm.h" | 6 #include "core/layout/ng/ng_block_layout_algorithm.h" |
7 #include "core/layout/ng/ng_constraint_space_builder.h" | 7 #include "core/layout/ng/ng_constraint_space_builder.h" |
8 #include "core/layout/ng/ng_inline_node.h" | 8 #include "core/layout/ng/ng_inline_node.h" |
9 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 9 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
10 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
11 #include "web/WebViewImpl.h" | 11 #include "web/WebViewImpl.h" |
12 #include "web/tests/sim/SimCompositor.h" | 12 #include "web/tests/sim/SimCompositor.h" |
13 #include "web/tests/sim/SimDisplayItemList.h" | 13 #include "web/tests/sim/SimDisplayItemList.h" |
14 #include "web/tests/sim/SimRequest.h" | 14 #include "web/tests/sim/SimRequest.h" |
15 #include "web/tests/sim/SimTest.h" | 15 #include "web/tests/sim/SimTest.h" |
16 #include "wtf/CurrentTime.h" | 16 #include "wtf/CurrentTime.h" |
17 #include "wtf/text/CharacterNames.h" | 17 #include "wtf/text/CharacterNames.h" |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 | 20 |
21 class NGInlineLayoutTest : public SimTest { | 21 class NGInlineLayoutTest : public SimTest { |
22 public: | 22 public: |
23 NGConstraintSpace* constraintSpaceForElement(LayoutNGBlockFlow* blockFlow) { | 23 RefPtr<NGConstraintSpace> constraintSpaceForElement( |
| 24 LayoutNGBlockFlow* blockFlow) { |
24 return NGConstraintSpaceBuilder( | 25 return NGConstraintSpaceBuilder( |
25 FromPlatformWritingMode(blockFlow->style()->getWritingMode())) | 26 FromPlatformWritingMode(blockFlow->style()->getWritingMode())) |
26 .SetAvailableSize(NGLogicalSize(LayoutUnit(), LayoutUnit())) | 27 .SetAvailableSize(NGLogicalSize(LayoutUnit(), LayoutUnit())) |
27 .SetPercentageResolutionSize(NGLogicalSize(LayoutUnit(), LayoutUnit())) | 28 .SetPercentageResolutionSize(NGLogicalSize(LayoutUnit(), LayoutUnit())) |
28 .SetTextDirection(blockFlow->style()->direction()) | 29 .SetTextDirection(blockFlow->style()->direction()) |
29 .ToConstraintSpace( | 30 .ToConstraintSpace( |
30 FromPlatformWritingMode(blockFlow->style()->getWritingMode())); | 31 FromPlatformWritingMode(blockFlow->style()->getWritingMode())); |
31 } | 32 } |
32 }; | 33 }; |
33 | 34 |
34 TEST_F(NGInlineLayoutTest, BlockWithSingleTextNode) { | 35 TEST_F(NGInlineLayoutTest, BlockWithSingleTextNode) { |
35 RuntimeEnabledFeatures::setLayoutNGEnabled(true); | 36 RuntimeEnabledFeatures::setLayoutNGEnabled(true); |
36 RuntimeEnabledFeatures::setLayoutNGInlineEnabled(true); | 37 RuntimeEnabledFeatures::setLayoutNGInlineEnabled(true); |
37 | 38 |
38 SimRequest mainResource("https://example.com/", "text/html"); | 39 SimRequest mainResource("https://example.com/", "text/html"); |
39 loadURL("https://example.com/"); | 40 loadURL("https://example.com/"); |
40 mainResource.complete( | 41 mainResource.complete( |
41 "<div id=\"target\">Hello <strong>World</strong>!</div>"); | 42 "<div id=\"target\">Hello <strong>World</strong>!</div>"); |
42 | 43 |
43 compositor().beginFrame(); | 44 compositor().beginFrame(); |
44 ASSERT_FALSE(compositor().needsBeginFrame()); | 45 ASSERT_FALSE(compositor().needsBeginFrame()); |
45 | 46 |
46 Element* target = document().getElementById("target"); | 47 Element* target = document().getElementById("target"); |
47 LayoutNGBlockFlow* blockFlow = toLayoutNGBlockFlow(target->layoutObject()); | 48 LayoutNGBlockFlow* blockFlow = toLayoutNGBlockFlow(target->layoutObject()); |
48 NGConstraintSpace* constraintSpace = constraintSpaceForElement(blockFlow); | 49 RefPtr<NGConstraintSpace> constraintSpace = |
| 50 constraintSpaceForElement(blockFlow); |
49 NGBlockNode* node = new NGBlockNode(blockFlow); | 51 NGBlockNode* node = new NGBlockNode(blockFlow); |
50 | 52 |
51 RefPtr<NGLayoutResult> result = | 53 RefPtr<NGLayoutResult> result = |
52 NGBlockLayoutAlgorithm(node, constraintSpace).Layout(); | 54 NGBlockLayoutAlgorithm(node, constraintSpace.get()).Layout(); |
53 EXPECT_TRUE(result); | 55 EXPECT_TRUE(result); |
54 | 56 |
55 String expectedText("Hello World!"); | 57 String expectedText("Hello World!"); |
56 EXPECT_EQ(expectedText, toNGInlineNode(node->FirstChild())->Text(0, 12)); | 58 EXPECT_EQ(expectedText, toNGInlineNode(node->FirstChild())->Text(0, 12)); |
57 } | 59 } |
58 | 60 |
59 TEST_F(NGInlineLayoutTest, BlockWithTextAndAtomicInline) { | 61 TEST_F(NGInlineLayoutTest, BlockWithTextAndAtomicInline) { |
60 RuntimeEnabledFeatures::setLayoutNGEnabled(true); | 62 RuntimeEnabledFeatures::setLayoutNGEnabled(true); |
61 RuntimeEnabledFeatures::setLayoutNGInlineEnabled(true); | 63 RuntimeEnabledFeatures::setLayoutNGInlineEnabled(true); |
62 | 64 |
63 SimRequest mainResource("https://example.com/", "text/html"); | 65 SimRequest mainResource("https://example.com/", "text/html"); |
64 loadURL("https://example.com/"); | 66 loadURL("https://example.com/"); |
65 mainResource.complete("<div id=\"target\">Hello <img>.</div>"); | 67 mainResource.complete("<div id=\"target\">Hello <img>.</div>"); |
66 | 68 |
67 compositor().beginFrame(); | 69 compositor().beginFrame(); |
68 ASSERT_FALSE(compositor().needsBeginFrame()); | 70 ASSERT_FALSE(compositor().needsBeginFrame()); |
69 | 71 |
70 Element* target = document().getElementById("target"); | 72 Element* target = document().getElementById("target"); |
71 LayoutNGBlockFlow* blockFlow = toLayoutNGBlockFlow(target->layoutObject()); | 73 LayoutNGBlockFlow* blockFlow = toLayoutNGBlockFlow(target->layoutObject()); |
72 NGConstraintSpace* constraintSpace = constraintSpaceForElement(blockFlow); | 74 RefPtr<NGConstraintSpace> constraintSpace = |
| 75 constraintSpaceForElement(blockFlow); |
73 NGBlockNode* node = new NGBlockNode(blockFlow); | 76 NGBlockNode* node = new NGBlockNode(blockFlow); |
74 | 77 |
75 RefPtr<NGLayoutResult> result = | 78 RefPtr<NGLayoutResult> result = |
76 NGBlockLayoutAlgorithm(node, constraintSpace).Layout(); | 79 NGBlockLayoutAlgorithm(node, constraintSpace.get()).Layout(); |
77 EXPECT_TRUE(result); | 80 EXPECT_TRUE(result); |
78 | 81 |
79 String expectedText("Hello "); | 82 String expectedText("Hello "); |
80 expectedText.append(objectReplacementCharacter); | 83 expectedText.append(objectReplacementCharacter); |
81 expectedText.append("."); | 84 expectedText.append("."); |
82 EXPECT_EQ(expectedText, toNGInlineNode(node->FirstChild())->Text(0, 8)); | 85 EXPECT_EQ(expectedText, toNGInlineNode(node->FirstChild())->Text(0, 8)); |
83 | 86 |
84 // Delete the line box tree to avoid leaks in the test. | 87 // Delete the line box tree to avoid leaks in the test. |
85 blockFlow->deleteLineBoxTree(); | 88 blockFlow->deleteLineBoxTree(); |
86 } | 89 } |
87 | 90 |
88 } // namespace blink | 91 } // namespace blink |
OLD | NEW |