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