Index: Source/core/page/PrintContextTest.cpp |
=================================================================== |
--- Source/core/page/PrintContextTest.cpp (revision 191009) |
+++ Source/core/page/PrintContextTest.cpp (working copy) |
@@ -6,7 +6,11 @@ |
#include "core/page/PrintContext.h" |
#include "core/dom/Document.h" |
+#include "core/frame/FrameHost.h" |
+#include "core/frame/FrameView.h" |
#include "core/html/HTMLElement.h" |
+#include "core/html/HTMLIFrameElement.h" |
+#include "core/loader/EmptyClients.h" |
#include "core/testing/DummyPageHolder.h" |
#include "platform/graphics/GraphicsContext.h" |
#include "platform/testing/SkiaForCoreTesting.h" |
@@ -22,9 +26,9 @@ |
public: |
MockPrintContext(LocalFrame* frame) : PrintContext(frame) { } |
- void outputLinkAndLinkedDestinations(GraphicsContext& context, Node* node, const IntRect& pageRect) |
+ void outputLinkAndLinkedDestinations(GraphicsContext& context, const IntRect& pageRect) |
{ |
- PrintContext::outputLinkAndLinkedDestinations(context, node, pageRect); |
+ PrintContext::outputLinkAndLinkedDestinations(context, pageRect); |
} |
}; |
@@ -65,8 +69,8 @@ |
class PrintContextTest : public testing::Test { |
protected: |
- PrintContextTest() |
- : m_pageHolder(DummyPageHolder::create(IntSize(kPageWidth, kPageHeight))) |
+ PrintContextTest(PassOwnPtr<FrameLoaderClient> frameLoaderClient = PassOwnPtr<FrameLoaderClient>()) |
+ : m_pageHolder(DummyPageHolder::create(IntSize(kPageWidth, kPageHeight), nullptr, frameLoaderClient)) |
, m_printContext(adoptPtrWillBeNoop(new MockPrintContext(document().frame()))) { } |
Document& document() const { return m_pageHolder->document(); } |
@@ -82,7 +86,7 @@ |
IntRect pageRect(0, 0, kPageWidth, kPageHeight); |
GraphicsContext context(&canvas, nullptr); |
printContext().begin(kPageWidth, kPageHeight); |
- printContext().outputLinkAndLinkedDestinations(context, &document(), pageRect); |
+ printContext().outputLinkAndLinkedDestinations(context, pageRect); |
printContext().end(); |
} |
@@ -106,6 +110,34 @@ |
OwnPtrWillBePersistent<MockPrintContext> m_printContext; |
}; |
+class SingleChildFrameLoaderClient : public EmptyFrameLoaderClient { |
+public: |
+ SingleChildFrameLoaderClient() : m_child(nullptr) { } |
+ |
+ virtual Frame* firstChild() const override { return m_child; } |
+ virtual Frame* lastChild() const override { return m_child; } |
+ |
+ void setChild(Frame* child) { m_child = child; } |
+ |
+private: |
+ Frame* m_child; |
+}; |
+ |
+class FrameLoaderClientWithParent : public EmptyFrameLoaderClient { |
+public: |
+ FrameLoaderClientWithParent(Frame* parent) : m_parent(parent) { } |
+ |
+ virtual Frame* parent() const override { return m_parent; } |
+ |
+private: |
+ Frame* m_parent; |
+}; |
+ |
+class PrintContextFrameTest : public PrintContextTest { |
+public: |
+ PrintContextFrameTest() : PrintContextTest(adoptPtr(new SingleChildFrameLoaderClient())) { } |
+}; |
+ |
#define EXPECT_SKRECT_EQ(expectedX, expectedY, expectedWidth, expectedHeight, actualRect) \ |
EXPECT_EQ(expectedX, actualRect.x()); \ |
EXPECT_EQ(expectedY, actualRect.y()); \ |
@@ -156,4 +188,42 @@ |
EXPECT_SKRECT_EQ(250, 260, 0, 0, operations[secondIndex].rect); |
} |
+TEST_F(PrintContextFrameTest, WithSubframe) |
+{ |
+ MockCanvas canvas; |
+ document().setBaseURLOverride(KURL(ParsedURLString, "http://a.com/")); |
+ setBodyInnerHTML("<iframe id='frame' src='http://b.com/' width='500' height='500'></iframe>"); |
+ |
+ HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("frame")); |
+ OwnPtr<FrameLoaderClient> frameLoaderClient = adoptPtr(new FrameLoaderClientWithParent(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(htmlForLink(50, 60, 70, 80, "#fragment") |
+ + htmlForLink(150, 160, 170, 180, "http://www.google.com") |
+ + htmlForLink(250, 260, 270, 280, "http://www.google.com#fragment"), |
+ ASSERT_NO_EXCEPTION); |
+ printSinglePage(canvas); |
+ |
+ const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations(); |
+ ASSERT_EQ(2u, operations.size()); |
+ |
+ size_t firstIndex = operations[0].rect.x() == 150 ? 0 : 1; |
+ EXPECT_EQ(MockCanvas::DrawRect, operations[firstIndex].type); |
+ EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[firstIndex].rect); |
+ |
+ size_t secondIndex = firstIndex == 0 ? 1 : 0; |
+ EXPECT_EQ(MockCanvas::DrawRect, operations[secondIndex].type); |
+ EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[secondIndex].rect); |
+ |
+ subframe->detach(); |
+ static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->setChild(nullptr); |
+ document().frame()->host()->decrementSubframeCount(); |
+} |
+ |
} // namespace blink |