diff options
5 files changed, 90 insertions, 63 deletions
diff --git a/third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp b/third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp index 97db2f3..518e7df 100644 --- a/third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp +++ b/third_party/WebKit/Source/core/layout/LayoutTestHelper.cpp @@ -6,6 +6,7 @@ #include "core/layout/LayoutTestHelper.h" #include "core/frame/FrameHost.h" +#include "core/html/HTMLIFrameElement.h" #include "platform/graphics/test/FakeGraphicsLayerFactory.h" namespace blink { @@ -42,10 +43,33 @@ void RenderingTest::SetUp() void RenderingTest::TearDown() { + if (m_subframe) { + m_subframe->detach(FrameDetachType::Remove); + static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(nullptr); + document().frame()->host()->decrementSubframeCount(); + } + // We need to destroy most of the Blink structure here because derived tests may restore // RuntimeEnabledFeatures setting during teardown, which happens before our destructor // getting invoked, breaking the assumption that REF can't change during Blink lifetime. m_pageHolder = nullptr; } +Document& RenderingTest::setupChildIframe(const AtomicString& iframeElementId, const String& htmlContentOfIframe) +{ + + HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById(iframeElementId)); + m_frameLoaderClient = FrameLoaderClientWithParent::create(document().frame()); + m_subframe = LocalFrame::create(m_frameLoaderClient.get(), document().frame()->host(), &iframe); + m_subframe->setView(FrameView::create(m_subframe.get(), IntSize(500, 500))); + m_subframe->init(); + static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(m_subframe.get()); + document().frame()->host()->incrementSubframeCount(); + Document& frameDocument = *iframe.contentDocument(); + + frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); + frameDocument.body()->setInnerHTML(htmlContentOfIframe, ASSERT_NO_EXCEPTION); + return frameDocument; +} + } // namespace blink diff --git a/third_party/WebKit/Source/core/layout/LayoutTestHelper.h b/third_party/WebKit/Source/core/layout/LayoutTestHelper.h index caaeddb..81eb4dc 100644 --- a/third_party/WebKit/Source/core/layout/LayoutTestHelper.h +++ b/third_party/WebKit/Source/core/layout/LayoutTestHelper.h @@ -38,6 +38,9 @@ protected: document().view()->updateAllLifecyclePhases(); } + // Returns the Document for the iframe. + Document& setupChildIframe(const AtomicString& iframeElementId, const String& htmlContentOfIframe); + // Both enables compositing and runs the document lifecycle. void enableCompositing() { @@ -46,6 +49,8 @@ protected: } private: + RefPtrWillBePersistent<LocalFrame> m_subframe; + OwnPtrWillBePersistent<FrameLoaderClient> m_frameLoaderClient; OwnPtr<DummyPageHolder> m_pageHolder; }; diff --git a/third_party/WebKit/Source/core/layout/LayoutView.cpp b/third_party/WebKit/Source/core/layout/LayoutView.cpp index 87c0348..e0f48c7 100644 --- a/third_party/WebKit/Source/core/layout/LayoutView.cpp +++ b/third_party/WebKit/Source/core/layout/LayoutView.cpp @@ -397,9 +397,8 @@ void LayoutView::mapAbsoluteToLocalPoint(MapCoordinatesFlags mode, TransformStat if (mode & TraverseDocumentBoundaries) { if (LayoutPart* parentDocLayoutObject = frame()->ownerLayoutObject()) { parentDocLayoutObject->mapAbsoluteToLocalPoint(mode, transformState); - - transformState.move(-parentDocLayoutObject->contentBoxOffset()); - transformState.move(frame()->view()->scrollOffset()); + transformState.move(parentDocLayoutObject->contentBoxOffset()); + transformState.move(-frame()->view()->scrollOffset()); } } } diff --git a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp index c6deda04..4fd748b 100644 --- a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp +++ b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMappingTest.cpp @@ -6,11 +6,9 @@ #include "core/layout/compositing/CompositedLayerMapping.h" #include "core/frame/FrameView.h" -#include "core/html/HTMLIFrameElement.h" #include "core/layout/LayoutBoxModelObject.h" #include "core/layout/LayoutTestHelper.h" #include "core/layout/LayoutView.h" -#include "core/loader/EmptyClients.h" #include "core/paint/PaintLayer.h" #include "testing/gtest/include/gtest/gtest.h" @@ -63,6 +61,8 @@ private: { GraphicsLayer::setDrawDebugRedFillForTesting(true); RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(m_originalSlimmingPaintSynchronizedPaintingEnabled); + + RenderingTest::TearDown(); } bool m_originalSlimmingPaintSynchronizedPaintingEnabled; @@ -70,10 +70,11 @@ private: #define EXPECT_RECT_EQ(expected, actual) \ do { \ - EXPECT_EQ(expected.x(), actual.x()); \ - EXPECT_EQ(expected.y(), actual.y()); \ - EXPECT_EQ(expected.width(), actual.width()); \ - EXPECT_EQ(expected.height(), actual.height()); \ + const IntRect& actualRect = actual; \ + EXPECT_EQ(expected.x(), actualRect.x()); \ + EXPECT_EQ(expected.y(), actualRect.y()); \ + EXPECT_EQ(expected.width(), actualRect.width()); \ + EXPECT_EQ(expected.height(), actualRect.height()); \ } while (false) TEST_F(CompositedLayerMappingTest, SimpleInterestRect) @@ -512,7 +513,7 @@ TEST_F(CompositedLayerMappingTest, InterestRectOfSquashingLayerWithAncestorClip) EXPECT_RECT_EQ(IntRect(5600, 0, 4400, 1000), groupedMapping->computeInterestRect(groupedMapping->squashingLayer(), IntRect())); } -TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) +TEST_F(CompositedLayerMappingTest, InterestRectOfIframeInScrolledDiv) { document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); setBodyInnerHTML( @@ -521,18 +522,7 @@ TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) "<iframe id=frame src='http://test.com' width='500' height='500' frameBorder='0'>" "</iframe>"); - HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("frame")); - OwnPtrWillBeRawPtr<FrameLoaderClient> frameLoaderClient = FrameLoaderClientWithParent::create(document().frame()); - RefPtrWillBePersistent<LocalFrame> subframe = LocalFrame::create(frameLoaderClient.get(), document().frame()->host(), &iframe); - subframe->setView(FrameView::create(subframe.get(), IntSize(500, 500))); - subframe->init(); - static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(subframe.get()); - document().frame()->host()->incrementSubframeCount(); - Document& frameDocument = *iframe.contentDocument(); - - frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); - frameDocument.body()->setInnerHTML("<style>body { margin: 0; } #target { width: 200px; height: 200px; will-change: transform}</style><div id=target></div>", - ASSERT_NO_EXCEPTION); + Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0; } #target { width: 200px; height: 200px; will-change: transform}</style><div id=target></div>"); // Scroll 8000 pixels down to move the iframe into view. document().view()->setScrollPosition(DoublePoint(0.0, 8000.0), ProgrammaticScroll); @@ -542,10 +532,51 @@ TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) ASSERT_TRUE(target); EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), recomputeInterestRect(target->layoutObject()->enclosingLayer()->graphicsLayerBacking())); +} + +TEST_F(CompositedLayerMappingTest, InterestRectOfScrolledIframe) +{ + document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); + document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); + setBodyInnerHTML( + "<style>body { margin: 0; }</style>" + "<iframe id=frame src='http://test.com' width='500' height='500' frameBorder='0'>" + "</iframe>"); + + Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0; } #target { width: 200px; height: 8000px;}</style><div id=target></div>"); + + document().view()->updateAllLifecyclePhases(); + + // Scroll 7500 pixels down to bring the scrollable area to the bottom. + frameDocument.view()->setScrollPosition(DoublePoint(0.0, 7500.0), ProgrammaticScroll); + document().view()->updateAllLifecyclePhases(); + + ASSERT_TRUE(frameDocument.view()->layoutView()->hasLayer()); + // The width is 485 pixels due to the size of the scrollbar. + EXPECT_RECT_EQ(IntRect(0, 3500, 485, 4500), recomputeInterestRect(frameDocument.view()->layoutView()->enclosingLayer()->graphicsLayerBacking())); +} + +TEST_F(CompositedLayerMappingTest, InterestRectOfIframeWithContentBoxOffset) +{ + document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); + document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); + // Set a 10px border in order to have a contentBoxOffset for the iframe element. + setBodyInnerHTML( + "<style>body { margin: 0; } #frame { border: 10px solid black; }</style>" + "<iframe id=frame src='http://test.com' width='500' height='500' frameBorder='0'>" + "</iframe>"); + + Document& frameDocument = setupChildIframe("frame", "<style>body { margin: 0; } #target { width: 200px; height: 8000px;}</style> <div id=target></div>"); + + document().view()->updateAllLifecyclePhases(); + + // Scroll 3000 pixels down to bring the scrollable area to somewhere in the middle. + frameDocument.view()->setScrollPosition(DoublePoint(0.0, 3000.0), ProgrammaticScroll); + document().view()->updateAllLifecyclePhases(); - subframe->detach(FrameDetachType::Remove); - static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(nullptr); - document().frame()->host()->decrementSubframeCount(); + ASSERT_TRUE(frameDocument.view()->layoutView()->hasLayer()); + // The width is 485 pixels due to the size of the scrollbar. + EXPECT_RECT_EQ(IntRect(0, 0, 485, 7500), recomputeInterestRect(frameDocument.view()->layoutView()->enclosingLayer()->graphicsLayerBacking())); } } // namespace blink diff --git a/third_party/WebKit/Source/core/page/PrintContextTest.cpp b/third_party/WebKit/Source/core/page/PrintContextTest.cpp index 04b70f4..b8328a7 100644 --- a/third_party/WebKit/Source/core/page/PrintContextTest.cpp +++ b/third_party/WebKit/Source/core/page/PrintContextTest.cpp @@ -9,10 +9,8 @@ #include "core/frame/FrameView.h" #include "core/html/HTMLElement.h" -#include "core/html/HTMLIFrameElement.h" #include "core/layout/LayoutTestHelper.h" #include "core/layout/LayoutView.h" -#include "core/loader/EmptyClients.h" #include "core/paint/PaintLayer.h" #include "core/paint/PaintLayerPainter.h" #include "core/testing/DummyPageHolder.h" @@ -275,20 +273,9 @@ TEST_F(PrintContextFrameTest, WithSubframe) "<iframe id='frame' src='http://b.com/' width='500' height='500'" " style='border-width: 5px; margin: 5px; position: absolute; top: 90px; left: 90px'></iframe>"); - HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("frame")); - OwnPtrWillBeRawPtr<FrameLoaderClient> frameLoaderClient = FrameLoaderClientWithParent::create(document().frame()); - RefPtrWillBePersistent<LocalFrame> subframe = LocalFrame::create(frameLoaderClient.get(), document().frame()->host(), &iframe); - subframe->setView(FrameView::create(subframe.get(), IntSize(500, 500))); - subframe->init(); - static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(subframe.get()); - document().frame()->host()->incrementSubframeCount(); - - Document& frameDocument = *iframe.contentDocument(); - frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://b.com/")); - frameDocument.body()->setInnerHTML(absoluteBlockHtmlForLink(50, 60, 70, 80, "#fragment") + setupChildIframe("frame", absoluteBlockHtmlForLink(50, 60, 70, 80, "#fragment") + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com") - + absoluteBlockHtmlForLink(250, 260, 270, 280, "http://www.google.com#fragment"), - ASSERT_NO_EXCEPTION); + + absoluteBlockHtmlForLink(250, 260, 270, 280, "http://www.google.com#fragment")); printSinglePage(canvas); @@ -298,10 +285,6 @@ TEST_F(PrintContextFrameTest, WithSubframe) EXPECT_SKRECT_EQ(250, 260, 170, 180, operations[0].rect); EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); EXPECT_SKRECT_EQ(350, 360, 270, 280, operations[1].rect); - - subframe->detach(FrameDetachType::Remove); - static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(nullptr); - document().frame()->host()->decrementSubframeCount(); } TEST_F(PrintContextFrameTest, WithScrolledSubframe) @@ -312,24 +295,13 @@ TEST_F(PrintContextFrameTest, WithScrolledSubframe) "<iframe id='frame' src='http://b.com/' width='500' height='500'" " style='border-width: 5px; margin: 5px; position: absolute; top: 90px; left: 90px'></iframe>"); - HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("frame")); - OwnPtrWillBeRawPtr<FrameLoaderClient> frameLoaderClient = FrameLoaderClientWithParent::create(document().frame()); - RefPtrWillBePersistent<LocalFrame> subframe = LocalFrame::create(frameLoaderClient.get(), document().frame()->host(), &iframe); - subframe->setView(FrameView::create(subframe.get(), IntSize(500, 500))); - subframe->init(); - static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(subframe.get()); - document().frame()->host()->incrementSubframeCount(); - - Document& frameDocument = *iframe.contentDocument(); - frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://b.com/")); - frameDocument.body()->setInnerHTML( - absoluteBlockHtmlForLink(10, 10, 20, 20, "http://invisible.com") + Document& frameDocument = setupChildIframe("frame", absoluteBlockHtmlForLink(10, 10, 20, 20, "http://invisible.com") + absoluteBlockHtmlForLink(50, 60, 70, 80, "http://partly.visible.com") + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com") + absoluteBlockHtmlForLink(250, 260, 270, 280, "http://www.google.com#fragment") - + absoluteBlockHtmlForLink(850, 860, 70, 80, "http://another.invisible.com"), - ASSERT_NO_EXCEPTION); - iframe.contentWindow()->scrollTo(100, 100); + + absoluteBlockHtmlForLink(850, 860, 70, 80, "http://another.invisible.com")); + + frameDocument.domWindow()->scrollTo(100, 100); printSinglePage(canvas); @@ -341,10 +313,6 @@ TEST_F(PrintContextFrameTest, WithScrolledSubframe) EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); - - subframe->detach(FrameDetachType::Remove); - static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(nullptr); - document().frame()->host()->decrementSubframeCount(); } } // namespace blink |