Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/LayoutObject.h" | 5 #include "core/layout/LayoutObject.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
| 8 #include "core/layout/LayoutView.h" | 8 #include "core/layout/LayoutView.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class LayoutObjectTest : public RenderingTest { | 13 class LayoutObjectTest : public RenderingTest { |
| 14 public: | |
| 15 LayoutObjectTest() | |
| 16 : RenderingTest(SingleChildFrameLoaderClient::create()) {} | |
| 14 protected: | 17 protected: |
| 15 LayoutView& layoutView() const { return *document().layoutView(); } | 18 LayoutView& layoutView() const { return *document().layoutView(); } |
| 16 }; | 19 }; |
| 17 | 20 |
| 18 TEST_F(LayoutObjectTest, LayoutDecoratedNameCalledWithPositionedObject) | 21 TEST_F(LayoutObjectTest, LayoutDecoratedNameCalledWithPositionedObject) |
| 19 { | 22 { |
| 20 setBodyInnerHTML("<div id='div' style='position: fixed'>test</div>"); | 23 setBodyInnerHTML("<div id='div' style='position: fixed'>test</div>"); |
| 21 Element* div = document().getElementById(AtomicString("div")); | 24 Element* div = document().getElementById(AtomicString("div")); |
| 22 ASSERT(div); | 25 ASSERT(div); |
| 23 LayoutObject* obj = div->layoutObject(); | 26 LayoutObject* obj = div->layoutObject(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // Sanity check: Make sure we don't generate anonymous objects. | 104 // Sanity check: Make sure we don't generate anonymous objects. |
| 102 EXPECT_EQ(nullptr, bodyLayoutObject->slowFirstChild()->nextSibling()); | 105 EXPECT_EQ(nullptr, bodyLayoutObject->slowFirstChild()->nextSibling()); |
| 103 EXPECT_EQ(nullptr, layoutObject->slowFirstChild()); | 106 EXPECT_EQ(nullptr, layoutObject->slowFirstChild()); |
| 104 EXPECT_EQ(nullptr, layoutObject->nextSibling()); | 107 EXPECT_EQ(nullptr, layoutObject->nextSibling()); |
| 105 | 108 |
| 106 EXPECT_EQ(layoutObject->containingBlock(), bodyLayoutObject); | 109 EXPECT_EQ(layoutObject->containingBlock(), bodyLayoutObject); |
| 107 } | 110 } |
| 108 | 111 |
| 109 TEST_F(LayoutObjectTest, MapToVisibleRectInAncestorSpace) | 112 TEST_F(LayoutObjectTest, MapToVisibleRectInAncestorSpace) |
| 110 { | 113 { |
| 114 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | |
| 111 setBodyInnerHTML( | 115 setBodyInnerHTML( |
| 116 "<style>body { margin: 0; }</style>" | |
| 112 "<div id='container' style='overflow: scroll; will-change: transform; wi dth: 50px; height: 50px'>" | 117 "<div id='container' style='overflow: scroll; will-change: transform; wi dth: 50px; height: 50px'>" |
|
chrishtr
2016/03/24 21:18:43
will-change: transform; seems irrelevant
szager1
2016/03/24 21:52:28
Done.
| |
| 113 " <span><img style='width: 20px; height: 100px'></span>" | 118 " <span><img style='width: 20px; height: 100px'></span>" |
| 114 " text text text text text text text" | 119 " text text text text text text text" |
| 120 "</div>" | |
| 121 "<div id=frameContainer>" | |
| 122 " <iframe id=frame src='http://test.com' width='50' height='50' frameBo rder='0'></iframe>" | |
| 115 "</div>"); | 123 "</div>"); |
| 124 | |
| 125 Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0 ; }</style><span><img style='width: 20px; height: 100px'></span>text text text") ; | |
| 126 frameDocument.updateLayout(); | |
| 127 | |
| 116 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container ")); | 128 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container ")); |
| 117 LayoutText* text = toLayoutText(container->lastChild()); | 129 LayoutText* text = toLayoutText(container->lastChild()); |
| 130 LayoutBlock* frameContainer = toLayoutBlock(getLayoutObjectByElementId("fram eContainer")); | |
| 131 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()) ; | |
| 132 LayoutText* frameText = toLayoutText(frameBody->lastChild()); | |
|
chrishtr
2016/03/24 21:18:43
Separate these two test types into two unittests (
szager1
2016/03/24 21:52:28
Done.
| |
| 118 | 133 |
| 119 container->setScrollTop(LayoutUnit(50)); | 134 container->setScrollTop(LayoutUnit(50)); |
| 120 LayoutRect rect(0, 60, 20, 20); | 135 LayoutRect rect(0, 60, 20, 80); |
| 121 text->mapToVisibleRectInAncestorSpace(container, rect, nullptr); | 136 EXPECT_TRUE(text->mapToVisibleRectInAncestorSpace(container, rect, nullptr)) ; |
| 122 EXPECT_TRUE(rect == LayoutRect(0, 10, 20, 20)); | 137 EXPECT_EQ(rect, LayoutRect(0, 10, 20, 80)); |
| 138 | |
| 139 rect = LayoutRect(0, 60, 80, 0); | |
| 140 EXPECT_TRUE(text->mapToVisibleRectInAncestorSpace(container, rect, nullptr, EdgeInclusive)); | |
| 141 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); | |
| 142 | |
| 143 // This case involves clipping: frame height is 50, y-coordinate of result r ect is 13, | |
| 144 // so height should be clipped to (50 - 13) == 37. | |
| 145 frameDocument.view()->setScrollPosition(DoublePoint(0, 47), ProgrammaticScro ll); | |
|
chrishtr
2016/03/24 21:18:43
Make one test for LayoutInline, one for LayoutText
szager1
2016/03/24 21:52:28
Done.
| |
| 146 rect = LayoutRect(4, 60, 20, 80); | |
| 147 EXPECT_TRUE(frameText->mapToVisibleRectInAncestorSpace(frameContainer, rect, nullptr)); | |
| 148 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); | |
| 149 | |
| 150 rect = LayoutRect(4, 60, 0, 80); | |
| 151 EXPECT_TRUE(frameText->mapToVisibleRectInAncestorSpace(frameContainer, rect, nullptr, EdgeInclusive)); | |
| 152 EXPECT_EQ(rect, LayoutRect(4, 13, 0, 37)); | |
| 123 } | 153 } |
| 124 | 154 |
| 125 } // namespace blink | 155 } // namespace blink |
| OLD | NEW |