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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 loadURL("https://example.com/"); | 39 loadURL("https://example.com/"); |
40 mainResource.complete( | 40 mainResource.complete( |
41 "<div id=\"target\">Hello <strong>World</strong>!</div>"); | 41 "<div id=\"target\">Hello <strong>World</strong>!</div>"); |
42 | 42 |
43 compositor().beginFrame(); | 43 compositor().beginFrame(); |
44 ASSERT_FALSE(compositor().needsBeginFrame()); | 44 ASSERT_FALSE(compositor().needsBeginFrame()); |
45 | 45 |
46 Element* target = document().getElementById("target"); | 46 Element* target = document().getElementById("target"); |
47 LayoutNGBlockFlow* blockFlow = toLayoutNGBlockFlow(target->layoutObject()); | 47 LayoutNGBlockFlow* blockFlow = toLayoutNGBlockFlow(target->layoutObject()); |
48 NGConstraintSpace* constraintSpace = constraintSpaceForElement(blockFlow); | 48 NGConstraintSpace* constraintSpace = constraintSpaceForElement(blockFlow); |
| 49 NGBlockNode* node = new NGBlockNode(blockFlow); |
49 | 50 |
50 NGInlineNode* inlineBox = | |
51 new NGInlineNode(blockFlow->firstChild(), blockFlow->mutableStyle()); | |
52 RefPtr<NGPhysicalFragment> fragment = | 51 RefPtr<NGPhysicalFragment> fragment = |
53 NGBlockLayoutAlgorithm(blockFlow, blockFlow->style(), inlineBox, | 52 NGBlockLayoutAlgorithm(node, constraintSpace).Layout(); |
54 constraintSpace) | |
55 .Layout(); | |
56 EXPECT_TRUE(fragment); | 53 EXPECT_TRUE(fragment); |
57 | 54 |
58 String expectedText("Hello World!"); | 55 String expectedText("Hello World!"); |
59 EXPECT_EQ(expectedText, inlineBox->Text(0, 12)); | 56 EXPECT_EQ(expectedText, toNGInlineNode(node->FirstChild())->Text(0, 12)); |
60 } | 57 } |
61 | 58 |
62 TEST_F(NGInlineLayoutTest, BlockWithTextAndAtomicInline) { | 59 TEST_F(NGInlineLayoutTest, BlockWithTextAndAtomicInline) { |
63 RuntimeEnabledFeatures::setLayoutNGEnabled(true); | 60 RuntimeEnabledFeatures::setLayoutNGEnabled(true); |
64 RuntimeEnabledFeatures::setLayoutNGInlineEnabled(true); | 61 RuntimeEnabledFeatures::setLayoutNGInlineEnabled(true); |
65 | 62 |
66 SimRequest mainResource("https://example.com/", "text/html"); | 63 SimRequest mainResource("https://example.com/", "text/html"); |
67 loadURL("https://example.com/"); | 64 loadURL("https://example.com/"); |
68 mainResource.complete("<div id=\"target\">Hello <img>.</div>"); | 65 mainResource.complete("<div id=\"target\">Hello <img>.</div>"); |
69 | 66 |
70 compositor().beginFrame(); | 67 compositor().beginFrame(); |
71 ASSERT_FALSE(compositor().needsBeginFrame()); | 68 ASSERT_FALSE(compositor().needsBeginFrame()); |
72 | 69 |
73 Element* target = document().getElementById("target"); | 70 Element* target = document().getElementById("target"); |
74 LayoutNGBlockFlow* blockFlow = toLayoutNGBlockFlow(target->layoutObject()); | 71 LayoutNGBlockFlow* blockFlow = toLayoutNGBlockFlow(target->layoutObject()); |
75 NGConstraintSpace* constraintSpace = constraintSpaceForElement(blockFlow); | 72 NGConstraintSpace* constraintSpace = constraintSpaceForElement(blockFlow); |
| 73 NGBlockNode* node = new NGBlockNode(blockFlow); |
76 | 74 |
77 NGInlineNode* inlineBox = | |
78 new NGInlineNode(blockFlow->firstChild(), blockFlow->mutableStyle()); | |
79 RefPtr<NGPhysicalFragment> fragment = | 75 RefPtr<NGPhysicalFragment> fragment = |
80 NGBlockLayoutAlgorithm(blockFlow, blockFlow->style(), inlineBox, | 76 NGBlockLayoutAlgorithm(node, constraintSpace).Layout(); |
81 constraintSpace) | |
82 .Layout(); | |
83 EXPECT_TRUE(fragment); | 77 EXPECT_TRUE(fragment); |
84 | 78 |
85 String expectedText("Hello "); | 79 String expectedText("Hello "); |
86 expectedText.append(objectReplacementCharacter); | 80 expectedText.append(objectReplacementCharacter); |
87 expectedText.append("."); | 81 expectedText.append("."); |
88 EXPECT_EQ(expectedText, inlineBox->Text(0, 8)); | 82 EXPECT_EQ(expectedText, toNGInlineNode(node->FirstChild())->Text(0, 8)); |
89 | 83 |
90 // Delete the line box tree to avoid leaks in the test. | 84 // Delete the line box tree to avoid leaks in the test. |
91 blockFlow->deleteLineBoxTree(); | 85 blockFlow->deleteLineBoxTree(); |
92 } | 86 } |
93 | 87 |
94 } // namespace blink | 88 } // namespace blink |
OLD | NEW |