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