| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/page/PrintContext.h" | 6 #include "core/page/PrintContext.h" |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 | 9 |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 11 #include "core/html/HTMLElement.h" | 11 #include "core/html/HTMLElement.h" |
| 12 #include "core/html/HTMLIFrameElement.h" |
| 12 #include "core/layout/LayoutTestHelper.h" | 13 #include "core/layout/LayoutTestHelper.h" |
| 13 #include "core/layout/LayoutView.h" | 14 #include "core/layout/LayoutView.h" |
| 15 #include "core/loader/EmptyClients.h" |
| 14 #include "core/paint/PaintLayer.h" | 16 #include "core/paint/PaintLayer.h" |
| 15 #include "core/paint/PaintLayerPainter.h" | 17 #include "core/paint/PaintLayerPainter.h" |
| 16 #include "core/testing/DummyPageHolder.h" | 18 #include "core/testing/DummyPageHolder.h" |
| 17 #include "platform/graphics/GraphicsContext.h" | 19 #include "platform/graphics/GraphicsContext.h" |
| 18 #include "platform/graphics/paint/DrawingRecorder.h" | 20 #include "platform/graphics/paint/DrawingRecorder.h" |
| 19 #include "platform/graphics/paint/SkPictureBuilder.h" | 21 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 20 #include "platform/scroll/ScrollbarTheme.h" | 22 #include "platform/scroll/ScrollbarTheme.h" |
| 21 #include "platform/testing/SkiaForCoreTesting.h" | 23 #include "platform/testing/SkiaForCoreTesting.h" |
| 22 #include "platform/text/TextStream.h" | 24 #include "platform/text/TextStream.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 268 } |
| 267 | 269 |
| 268 TEST_F(PrintContextFrameTest, WithSubframe) | 270 TEST_F(PrintContextFrameTest, WithSubframe) |
| 269 { | 271 { |
| 270 MockCanvas canvas; | 272 MockCanvas canvas; |
| 271 document().setBaseURLOverride(KURL(ParsedURLString, "http://a.com/")); | 273 document().setBaseURLOverride(KURL(ParsedURLString, "http://a.com/")); |
| 272 setBodyInnerHTML("<style>::-webkit-scrollbar { display: none }</style>" | 274 setBodyInnerHTML("<style>::-webkit-scrollbar { display: none }</style>" |
| 273 "<iframe id='frame' src='http://b.com/' width='500' height='500'" | 275 "<iframe id='frame' src='http://b.com/' width='500' height='500'" |
| 274 " style='border-width: 5px; margin: 5px; position: absolute; top: 90px;
left: 90px'></iframe>"); | 276 " style='border-width: 5px; margin: 5px; position: absolute; top: 90px;
left: 90px'></iframe>"); |
| 275 | 277 |
| 276 setupChildIframe("frame", absoluteBlockHtmlForLink(50, 60, 70, 80, "#fragmen
t") | 278 HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("
frame")); |
| 279 OwnPtrWillBeRawPtr<FrameLoaderClient> frameLoaderClient = FrameLoaderClientW
ithParent::create(document().frame()); |
| 280 RefPtrWillBePersistent<LocalFrame> subframe = LocalFrame::create(frameLoader
Client.get(), document().frame()->host(), &iframe); |
| 281 subframe->setView(FrameView::create(subframe.get(), IntSize(500, 500))); |
| 282 subframe->init(); |
| 283 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(subframe.get()); |
| 284 document().frame()->host()->incrementSubframeCount(); |
| 285 |
| 286 Document& frameDocument = *iframe.contentDocument(); |
| 287 frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://b.com/")); |
| 288 frameDocument.body()->setInnerHTML(absoluteBlockHtmlForLink(50, 60, 70, 80,
"#fragment") |
| 277 + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com") | 289 + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com") |
| 278 + absoluteBlockHtmlForLink(250, 260, 270, 280, "http://www.google.com#fr
agment")); | 290 + absoluteBlockHtmlForLink(250, 260, 270, 280, "http://www.google.com#fr
agment"), |
| 291 ASSERT_NO_EXCEPTION); |
| 279 | 292 |
| 280 printSinglePage(canvas); | 293 printSinglePage(canvas); |
| 281 | 294 |
| 282 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations(
); | 295 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations(
); |
| 283 ASSERT_EQ(2u, operations.size()); | 296 ASSERT_EQ(2u, operations.size()); |
| 284 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); | 297 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); |
| 285 EXPECT_SKRECT_EQ(250, 260, 170, 180, operations[0].rect); | 298 EXPECT_SKRECT_EQ(250, 260, 170, 180, operations[0].rect); |
| 286 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); | 299 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); |
| 287 EXPECT_SKRECT_EQ(350, 360, 270, 280, operations[1].rect); | 300 EXPECT_SKRECT_EQ(350, 360, 270, 280, operations[1].rect); |
| 301 |
| 302 subframe->detach(FrameDetachType::Remove); |
| 303 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(nullptr); |
| 304 document().frame()->host()->decrementSubframeCount(); |
| 288 } | 305 } |
| 289 | 306 |
| 290 TEST_F(PrintContextFrameTest, WithScrolledSubframe) | 307 TEST_F(PrintContextFrameTest, WithScrolledSubframe) |
| 291 { | 308 { |
| 292 MockCanvas canvas; | 309 MockCanvas canvas; |
| 293 document().setBaseURLOverride(KURL(ParsedURLString, "http://a.com/")); | 310 document().setBaseURLOverride(KURL(ParsedURLString, "http://a.com/")); |
| 294 setBodyInnerHTML("<style>::-webkit-scrollbar { display: none }</style>" | 311 setBodyInnerHTML("<style>::-webkit-scrollbar { display: none }</style>" |
| 295 "<iframe id='frame' src='http://b.com/' width='500' height='500'" | 312 "<iframe id='frame' src='http://b.com/' width='500' height='500'" |
| 296 " style='border-width: 5px; margin: 5px; position: absolute; top: 90px;
left: 90px'></iframe>"); | 313 " style='border-width: 5px; margin: 5px; position: absolute; top: 90px;
left: 90px'></iframe>"); |
| 297 | 314 |
| 298 Document& frameDocument = setupChildIframe("frame", absoluteBlockHtmlForLink
(10, 10, 20, 20, "http://invisible.com") | 315 HTMLIFrameElement& iframe = *toHTMLIFrameElement(document().getElementById("
frame")); |
| 316 OwnPtrWillBeRawPtr<FrameLoaderClient> frameLoaderClient = FrameLoaderClientW
ithParent::create(document().frame()); |
| 317 RefPtrWillBePersistent<LocalFrame> subframe = LocalFrame::create(frameLoader
Client.get(), document().frame()->host(), &iframe); |
| 318 subframe->setView(FrameView::create(subframe.get(), IntSize(500, 500))); |
| 319 subframe->init(); |
| 320 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(subframe.get()); |
| 321 document().frame()->host()->incrementSubframeCount(); |
| 322 |
| 323 Document& frameDocument = *iframe.contentDocument(); |
| 324 frameDocument.setBaseURLOverride(KURL(ParsedURLString, "http://b.com/")); |
| 325 frameDocument.body()->setInnerHTML( |
| 326 absoluteBlockHtmlForLink(10, 10, 20, 20, "http://invisible.com") |
| 299 + absoluteBlockHtmlForLink(50, 60, 70, 80, "http://partly.visible.com") | 327 + absoluteBlockHtmlForLink(50, 60, 70, 80, "http://partly.visible.com") |
| 300 + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com") | 328 + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com") |
| 301 + absoluteBlockHtmlForLink(250, 260, 270, 280, "http://www.google.com#fr
agment") | 329 + absoluteBlockHtmlForLink(250, 260, 270, 280, "http://www.google.com#fr
agment") |
| 302 + absoluteBlockHtmlForLink(850, 860, 70, 80, "http://another.invisible.c
om")); | 330 + absoluteBlockHtmlForLink(850, 860, 70, 80, "http://another.invisible.c
om"), |
| 303 | 331 ASSERT_NO_EXCEPTION); |
| 304 frameDocument.domWindow()->scrollTo(100, 100); | 332 iframe.contentWindow()->scrollTo(100, 100); |
| 305 | 333 |
| 306 printSinglePage(canvas); | 334 printSinglePage(canvas); |
| 307 | 335 |
| 308 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations(
); | 336 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations(
); |
| 309 ASSERT_EQ(3u, operations.size()); | 337 ASSERT_EQ(3u, operations.size()); |
| 310 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); | 338 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); |
| 311 EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); // FIXME: the rect sho
uld be clipped. | 339 EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); // FIXME: the rect sho
uld be clipped. |
| 312 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); | 340 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); |
| 313 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); | 341 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); |
| 314 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); | 342 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); |
| 315 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); | 343 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); |
| 344 |
| 345 subframe->detach(FrameDetachType::Remove); |
| 346 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(nullptr); |
| 347 document().frame()->host()->decrementSubframeCount(); |
| 316 } | 348 } |
| 317 | 349 |
| 318 } // namespace blink | 350 } // namespace blink |
| OLD | NEW |