| 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 "bindings/core/v8/ScriptController.h" | 5 #include "bindings/core/v8/ScriptController.h" |
| 6 #include "core/dom/Document.h" | 6 #include "core/dom/Document.h" |
| 7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/html/HTMLIFrameElement.h" | 10 #include "core/html/HTMLIFrameElement.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 { | 66 { |
| 67 SimDisplayItemList displayItems = compositor().beginFrame(); | 67 SimDisplayItemList displayItems = compositor().beginFrame(); |
| 68 // Ensure intersection observer notifications get delivered. | 68 // Ensure intersection observer notifications get delivered. |
| 69 testing::runPendingTasks(); | 69 testing::runPendingTasks(); |
| 70 return displayItems; | 70 return displayItems; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Number of rectangles that make up the root layer's touch handler region. | 73 // Number of rectangles that make up the root layer's touch handler region. |
| 74 size_t touchHandlerRegionSize() | 74 size_t touchHandlerRegionSize() |
| 75 { | 75 { |
| 76 return webView().mainFrameImpl()->frame()->contentLayoutItem().layer()->
graphicsLayerBacking()->platformLayer()->touchEventHandlerRegion().size(); | 76 return webView().mainFrameImpl()->frame()->contentLayoutItem().layer()->
graphicsLayerBackingForScrolling()->platformLayer()->touchEventHandlerRegion().s
ize(); |
| 77 } | 77 } |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 TEST_F(FrameThrottlingTest, ThrottleInvisibleFrames) | 80 TEST_F(FrameThrottlingTest, ThrottleInvisibleFrames) |
| 81 { | 81 { |
| 82 SimRequest mainResource("https://example.com/", "text/html"); | 82 SimRequest mainResource("https://example.com/", "text/html"); |
| 83 | 83 |
| 84 loadURL("https://example.com/"); | 84 loadURL("https://example.com/"); |
| 85 mainResource.complete("<iframe sandbox id=frame></iframe>"); | 85 mainResource.complete("<iframe sandbox id=frame></iframe>"); |
| 86 | 86 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 304 |
| 305 // Move the frame offscreen to throttle it. | 305 // Move the frame offscreen to throttle it. |
| 306 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; | 306 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 307 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 307 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 308 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); | 308 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); |
| 309 compositeFrame(); | 309 compositeFrame(); |
| 310 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; | 310 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
| 311 | 311 |
| 312 // Scroll down to unthrottle the frame. The first frame we composite after | 312 // Scroll down to unthrottle the frame. The first frame we composite after |
| 313 // scrolling won't contain the frame yet, but will schedule another repaint. | 313 // scrolling won't contain the frame yet, but will schedule another repaint. |
| 314 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); | 314 webView().mainFrameImpl()->frameView()->layoutViewportScrollableArea()->setS
crollPosition(DoublePoint(0, 480), ProgrammaticScroll); |
| 315 auto displayItems = compositeFrame(); | 315 auto displayItems = compositeFrame(); |
| 316 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); | 316 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 317 | 317 |
| 318 // Now the frame contents should be visible again. | 318 // Now the frame contents should be visible again. |
| 319 auto displayItems2 = compositeFrame(); | 319 auto displayItems2 = compositeFrame(); |
| 320 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); | 320 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 321 } | 321 } |
| 322 | 322 |
| 323 TEST_F(FrameThrottlingTest, UnthrottlingTriggersRepaintInCompositedChild) | 323 TEST_F(FrameThrottlingTest, UnthrottlingTriggersRepaintInCompositedChild) |
| 324 { | 324 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 340 | 340 |
| 341 // Move the frame offscreen to throttle it. | 341 // Move the frame offscreen to throttle it. |
| 342 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; | 342 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 343 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 343 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 344 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); | 344 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); |
| 345 compositeFrame(); | 345 compositeFrame(); |
| 346 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; | 346 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
| 347 | 347 |
| 348 // Scroll down to unthrottle the frame. The first frame we composite after | 348 // Scroll down to unthrottle the frame. The first frame we composite after |
| 349 // scrolling won't contain the frame yet, but will schedule another repaint. | 349 // scrolling won't contain the frame yet, but will schedule another repaint. |
| 350 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); | 350 webView().mainFrameImpl()->frameView()->layoutViewportScrollableArea()->setS
crollPosition(DoublePoint(0, 480), ProgrammaticScroll); |
| 351 auto displayItems = compositeFrame(); | 351 auto displayItems = compositeFrame(); |
| 352 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); | 352 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 353 | 353 |
| 354 // Now the composited child contents should be visible again. | 354 // Now the composited child contents should be visible again. |
| 355 auto displayItems2 = compositeFrame(); | 355 auto displayItems2 = compositeFrame(); |
| 356 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); | 356 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 357 } | 357 } |
| 358 | 358 |
| 359 TEST_F(FrameThrottlingTest, ChangeStyleInThrottledFrame) | 359 TEST_F(FrameThrottlingTest, ChangeStyleInThrottledFrame) |
| 360 { | 360 { |
| 361 // Create a hidden frame which is throttled. | 361 // Create a hidden frame which is throttled. |
| 362 SimRequest mainResource("https://example.com/", "text/html"); | 362 SimRequest mainResource("https://example.com/", "text/html"); |
| 363 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 363 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 364 | 364 |
| 365 loadURL("https://example.com/"); | 365 loadURL("https://example.com/"); |
| 366 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); | 366 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
| 367 frameResource.complete("<style> html { background: red; } </style>"); | 367 frameResource.complete("<style> html { background: red; } </style>"); |
| 368 | 368 |
| 369 // Move the frame offscreen to throttle it. | 369 // Move the frame offscreen to throttle it. |
| 370 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; | 370 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 371 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 371 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 372 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); | 372 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); |
| 373 compositeFrame(); | 373 compositeFrame(); |
| 374 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; | 374 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
| 375 | 375 |
| 376 // Change the background color of the frame's contents from red to green. | 376 // Change the background color of the frame's contents from red to green. |
| 377 frameElement->contentDocument()->body()->setAttribute(styleAttr, "background
: green"); | 377 frameElement->contentDocument()->body()->setAttribute(styleAttr, "background
: green"); |
| 378 | 378 |
| 379 // Scroll down to unthrottle the frame. | 379 // Scroll down to unthrottle the frame. |
| 380 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); | 380 webView().mainFrameImpl()->frameView()->layoutViewportScrollableArea()->setS
crollPosition(DoublePoint(0, 480), ProgrammaticScroll); |
| 381 auto displayItems = compositeFrame(); | 381 auto displayItems = compositeFrame(); |
| 382 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "red")); | 382 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "red")); |
| 383 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); | 383 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 384 | 384 |
| 385 // Make sure the new style shows up instead of the old one. | 385 // Make sure the new style shows up instead of the old one. |
| 386 auto displayItems2 = compositeFrame(); | 386 auto displayItems2 = compositeFrame(); |
| 387 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); | 387 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 388 } | 388 } |
| 389 | 389 |
| 390 TEST_F(FrameThrottlingTest, ThrottledFrameWithFocus) | 390 TEST_F(FrameThrottlingTest, ThrottledFrameWithFocus) |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 localFrame->script().executeScriptInMainWorld( | 845 localFrame->script().executeScriptInMainWorld( |
| 846 "window.requestAnimationFrame(function() {\n" | 846 "window.requestAnimationFrame(function() {\n" |
| 847 " var throttledFrame = window.parent.frames.first;\n" | 847 " var throttledFrame = window.parent.frames.first;\n" |
| 848 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" | 848 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" |
| 849 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\
n" | 849 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\
n" |
| 850 "});\n"); | 850 "});\n"); |
| 851 compositeFrame(); | 851 compositeFrame(); |
| 852 } | 852 } |
| 853 | 853 |
| 854 } // namespace blink | 854 } // namespace blink |
| OLD | NEW |