| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 EXPECT_FALSE(document().view()->isHiddenForThrottling()); | 97 EXPECT_FALSE(document().view()->isHiddenForThrottling()); |
| 98 EXPECT_TRUE(frameDocument->view()->isHiddenForThrottling()); | 98 EXPECT_TRUE(frameDocument->view()->isHiddenForThrottling()); |
| 99 | 99 |
| 100 // A partially visible child is considered visible. | 100 // A partially visible child is considered visible. |
| 101 frameElement->setAttribute(styleAttr, "transform: translate(-50px, 0px, 0px)
"); | 101 frameElement->setAttribute(styleAttr, "transform: translate(-50px, 0px, 0px)
"); |
| 102 compositeFrame(); | 102 compositeFrame(); |
| 103 EXPECT_FALSE(document().view()->isHiddenForThrottling()); | 103 EXPECT_FALSE(document().view()->isHiddenForThrottling()); |
| 104 EXPECT_FALSE(frameDocument->view()->isHiddenForThrottling()); | 104 EXPECT_FALSE(frameDocument->view()->isHiddenForThrottling()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 TEST_F(FrameThrottlingTest, ViewportVisibilityFullyClipped) | |
| 108 { | |
| 109 SimRequest mainResource("https://example.com/", "text/html"); | |
| 110 | |
| 111 loadURL("https://example.com/"); | |
| 112 mainResource.complete("<iframe sandbox id=frame></iframe>"); | |
| 113 | |
| 114 // A child which is fully clipped away by its ancestor should become invisib
le. | |
| 115 webView().resize(WebSize(0, 0)); | |
| 116 compositeFrame(); | |
| 117 | |
| 118 EXPECT_TRUE(document().view()->isHiddenForThrottling()); | |
| 119 | |
| 120 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; | |
| 121 auto* frameDocument = frameElement->contentDocument(); | |
| 122 EXPECT_TRUE(frameDocument->view()->isHiddenForThrottling()); | |
| 123 } | |
| 124 | |
| 125 TEST_F(FrameThrottlingTest, HiddenSameOriginFramesAreNotThrottled) | 107 TEST_F(FrameThrottlingTest, HiddenSameOriginFramesAreNotThrottled) |
| 126 { | 108 { |
| 127 SimRequest mainResource("https://example.com/", "text/html"); | 109 SimRequest mainResource("https://example.com/", "text/html"); |
| 128 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 110 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 129 | 111 |
| 130 loadURL("https://example.com/"); | 112 loadURL("https://example.com/"); |
| 131 mainResource.complete("<iframe id=frame src=iframe.html></iframe>"); | 113 mainResource.complete("<iframe id=frame src=iframe.html></iframe>"); |
| 132 frameResource.complete("<iframe id=innerFrame></iframe>"); | 114 frameResource.complete("<iframe id=innerFrame></iframe>"); |
| 133 | 115 |
| 134 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; | 116 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 EXPECT_FALSE(innerFrameDocument->view()->canThrottleRendering()); | 152 EXPECT_FALSE(innerFrameDocument->view()->canThrottleRendering()); |
| 171 | 153 |
| 172 // Hidden cross origin frames are throttled. | 154 // Hidden cross origin frames are throttled. |
| 173 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 155 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 174 compositeFrame(); | 156 compositeFrame(); |
| 175 EXPECT_FALSE(document().view()->canThrottleRendering()); | 157 EXPECT_FALSE(document().view()->canThrottleRendering()); |
| 176 EXPECT_FALSE(frameDocument->view()->canThrottleRendering()); | 158 EXPECT_FALSE(frameDocument->view()->canThrottleRendering()); |
| 177 EXPECT_TRUE(innerFrameDocument->view()->canThrottleRendering()); | 159 EXPECT_TRUE(innerFrameDocument->view()->canThrottleRendering()); |
| 178 } | 160 } |
| 179 | 161 |
| 162 TEST_F(FrameThrottlingTest, HiddenCrossOriginZeroByZeroFramesAreNotThrottled) |
| 163 { |
| 164 // Create a document with doubly nested iframes. |
| 165 SimRequest mainResource("https://example.com/", "text/html"); |
| 166 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 167 |
| 168 loadURL("https://example.com/"); |
| 169 mainResource.complete("<iframe id=frame src=iframe.html></iframe>"); |
| 170 frameResource.complete("<iframe id=innerFrame width=0 height=0 sandbox></ifr
ame>"); |
| 171 |
| 172 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 173 auto* frameDocument = frameElement->contentDocument(); |
| 174 |
| 175 auto* innerFrameElement = toHTMLIFrameElement(frameDocument->getElementById(
"innerFrame")); |
| 176 auto* innerFrameDocument = innerFrameElement->contentDocument(); |
| 177 |
| 178 EXPECT_FALSE(document().view()->canThrottleRendering()); |
| 179 EXPECT_FALSE(frameDocument->view()->canThrottleRendering()); |
| 180 EXPECT_FALSE(innerFrameDocument->view()->canThrottleRendering()); |
| 181 |
| 182 // The frame is not throttled because its dimensions are 0x0. |
| 183 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 184 compositeFrame(); |
| 185 EXPECT_FALSE(document().view()->canThrottleRendering()); |
| 186 EXPECT_FALSE(frameDocument->view()->canThrottleRendering()); |
| 187 EXPECT_FALSE(innerFrameDocument->view()->canThrottleRendering()); |
| 188 } |
| 189 |
| 180 TEST_F(FrameThrottlingTest, ThrottledLifecycleUpdate) | 190 TEST_F(FrameThrottlingTest, ThrottledLifecycleUpdate) |
| 181 { | 191 { |
| 182 SimRequest mainResource("https://example.com/", "text/html"); | 192 SimRequest mainResource("https://example.com/", "text/html"); |
| 183 | 193 |
| 184 loadURL("https://example.com/"); | 194 loadURL("https://example.com/"); |
| 185 mainResource.complete("<iframe sandbox id=frame></iframe>"); | 195 mainResource.complete("<iframe sandbox id=frame></iframe>"); |
| 186 | 196 |
| 187 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; | 197 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 188 auto* frameDocument = frameElement->contentDocument(); | 198 auto* frameDocument = frameElement->contentDocument(); |
| 189 | 199 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 426 |
| 417 // Give the frame focus and do another composite. The selection in the | 427 // Give the frame focus and do another composite. The selection in the |
| 418 // compositor should be cleared because the frame is throttled. | 428 // compositor should be cleared because the frame is throttled. |
| 419 EXPECT_FALSE(compositor().hasSelection()); | 429 EXPECT_FALSE(compositor().hasSelection()); |
| 420 document().page()->focusController().setFocusedFrame(frameElement->contentDo
cument()->frame()); | 430 document().page()->focusController().setFocusedFrame(frameElement->contentDo
cument()->frame()); |
| 421 document().body()->setAttribute(styleAttr, "background: green"); | 431 document().body()->setAttribute(styleAttr, "background: green"); |
| 422 compositeFrame(); | 432 compositeFrame(); |
| 423 EXPECT_FALSE(compositor().hasSelection()); | 433 EXPECT_FALSE(compositor().hasSelection()); |
| 424 } | 434 } |
| 425 | 435 |
| 426 TEST(RemoteFrameThrottlingTest, ThrottledLocalRoot) | |
| 427 { | |
| 428 FrameTestHelpers::TestWebViewClient viewClient; | |
| 429 WebViewImpl* webView = WebViewImpl::create(&viewClient, WebPageVisibilitySta
teVisible); | |
| 430 webView->resize(WebSize(640, 480)); | |
| 431 | |
| 432 // Create a remote root frame with a local child frame. | |
| 433 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; | |
| 434 webView->setMainFrame(remoteClient.frame()); | |
| 435 remoteClient.frame()->setReplicatedOrigin(WebSecurityOrigin::createUnique())
; | |
| 436 | |
| 437 WebFrameOwnerProperties properties; | |
| 438 WebRemoteFrame* rootFrame = webView->mainFrame()->toWebRemoteFrame(); | |
| 439 WebLocalFrame* localFrame = FrameTestHelpers::createLocalChild(rootFrame); | |
| 440 | |
| 441 WebString baseURL("http://internal.test/"); | |
| 442 URLTestHelpers::registerMockedURLFromBaseURL(baseURL, "simple_div.html"); | |
| 443 FrameTestHelpers::loadFrame(localFrame, baseURL.utf8() + "simple_div.html"); | |
| 444 | |
| 445 FrameView* frameView = toWebLocalFrameImpl(localFrame)->frameView(); | |
| 446 EXPECT_TRUE(frameView->frame().isLocalRoot()); | |
| 447 | |
| 448 // Enable throttling for the child frame. | |
| 449 frameView->setFrameRect(IntRect(0, 480, frameView->width(), frameView->heigh
t())); | |
| 450 frameView->frame().securityContext()->setSecurityOrigin(SecurityOrigin::crea
teUnique()); | |
| 451 frameView->updateAllLifecyclePhases(); | |
| 452 testing::runPendingTasks(); | |
| 453 EXPECT_TRUE(frameView->canThrottleRendering()); | |
| 454 | |
| 455 Document* frameDocument = frameView->frame().document(); | |
| 456 EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().state())
; | |
| 457 | |
| 458 // Mutate the local child frame contents. | |
| 459 auto* divElement = frameDocument->getElementById("div"); | |
| 460 divElement->setAttribute(styleAttr, "width: 50px"); | |
| 461 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); | |
| 462 | |
| 463 // Update the lifecycle again. The frame's lifecycle should not advance | |
| 464 // because of throttling even though it is the local root. | |
| 465 DocumentLifecycle::AllowThrottlingScope throttlingScope(frameDocument->lifec
ycle()); | |
| 466 frameView->updateAllLifecyclePhases(); | |
| 467 testing::runPendingTasks(); | |
| 468 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); | |
| 469 webView->close(); | |
| 470 } | |
| 471 | |
| 472 TEST_F(FrameThrottlingTest, ScrollingCoordinatorShouldSkipThrottledFrame) | 436 TEST_F(FrameThrottlingTest, ScrollingCoordinatorShouldSkipThrottledFrame) |
| 473 { | 437 { |
| 474 webView().settings()->setAcceleratedCompositingEnabled(true); | 438 webView().settings()->setAcceleratedCompositingEnabled(true); |
| 475 | 439 |
| 476 // Create a hidden frame which is throttled. | 440 // Create a hidden frame which is throttled. |
| 477 SimRequest mainResource("https://example.com/", "text/html"); | 441 SimRequest mainResource("https://example.com/", "text/html"); |
| 478 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 442 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 479 | 443 |
| 480 loadURL("https://example.com/"); | 444 loadURL("https://example.com/"); |
| 481 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); | 445 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 localFrame->script().executeScriptInMainWorld( | 809 localFrame->script().executeScriptInMainWorld( |
| 846 "window.requestAnimationFrame(function() {\n" | 810 "window.requestAnimationFrame(function() {\n" |
| 847 " var throttledFrame = window.parent.frames.first;\n" | 811 " var throttledFrame = window.parent.frames.first;\n" |
| 848 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" | 812 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" |
| 849 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\
n" | 813 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\
n" |
| 850 "});\n"); | 814 "});\n"); |
| 851 compositeFrame(); | 815 compositeFrame(); |
| 852 } | 816 } |
| 853 | 817 |
| 854 } // namespace blink | 818 } // namespace blink |
| OLD | NEW |