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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 FrameTestHelpers::loadFrame(localFrame, baseURL.utf8() + "simple_div.html"); | 443 FrameTestHelpers::loadFrame(localFrame, baseURL.utf8() + "simple_div.html"); |
444 | 444 |
445 FrameView* frameView = toWebLocalFrameImpl(localFrame)->frameView(); | 445 FrameView* frameView = toWebLocalFrameImpl(localFrame)->frameView(); |
446 EXPECT_TRUE(frameView->frame().isLocalRoot()); | 446 EXPECT_TRUE(frameView->frame().isLocalRoot()); |
447 | 447 |
448 // Enable throttling for the child frame. | 448 // Enable throttling for the child frame. |
449 frameView->setFrameRect(IntRect(0, 480, frameView->width(), frameView->heigh
t())); | 449 frameView->setFrameRect(IntRect(0, 480, frameView->width(), frameView->heigh
t())); |
450 frameView->frame().securityContext()->setSecurityOrigin(SecurityOrigin::crea
teUnique()); | 450 frameView->frame().securityContext()->setSecurityOrigin(SecurityOrigin::crea
teUnique()); |
451 frameView->updateAllLifecyclePhases(); | 451 frameView->updateAllLifecyclePhases(); |
452 testing::runPendingTasks(); | 452 testing::runPendingTasks(); |
453 EXPECT_TRUE(frameView->canThrottleRendering()); | 453 // TODO(skyostil): Intersection observers don't work for remote frames (crbu
g.com/615156). |
| 454 EXPECT_FALSE(frameView->canThrottleRendering()); |
454 | 455 |
455 Document* frameDocument = frameView->frame().document(); | 456 Document* frameDocument = frameView->frame().document(); |
456 EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().state())
; | 457 EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().state())
; |
457 | 458 |
458 // Mutate the local child frame contents. | 459 // Mutate the local child frame contents. |
459 auto* divElement = frameDocument->getElementById("div"); | 460 auto* divElement = frameDocument->getElementById("div"); |
460 divElement->setAttribute(styleAttr, "width: 50px"); | 461 divElement->setAttribute(styleAttr, "width: 50px"); |
461 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); | 462 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); |
462 | 463 |
463 // Update the lifecycle again. The frame's lifecycle should not advance | 464 // Update the lifecycle again. The frame's lifecycle should not advance |
464 // because of throttling even though it is the local root. | 465 // because of throttling even though it is the local root. |
| 466 // TODO(skyostil): Intersection observers don't work for remote frames (crbu
g.com/615156). |
465 DocumentLifecycle::AllowThrottlingScope throttlingScope(frameDocument->lifec
ycle()); | 467 DocumentLifecycle::AllowThrottlingScope throttlingScope(frameDocument->lifec
ycle()); |
466 frameView->updateAllLifecyclePhases(); | 468 frameView->updateAllLifecyclePhases(); |
467 testing::runPendingTasks(); | 469 testing::runPendingTasks(); |
468 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); | 470 EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().state())
; |
469 webView->close(); | 471 webView->close(); |
470 } | 472 } |
471 | 473 |
472 TEST_F(FrameThrottlingTest, ScrollingCoordinatorShouldSkipThrottledFrame) | 474 TEST_F(FrameThrottlingTest, ScrollingCoordinatorShouldSkipThrottledFrame) |
473 { | 475 { |
474 webView().settings()->setAcceleratedCompositingEnabled(true); | 476 webView().settings()->setAcceleratedCompositingEnabled(true); |
475 | 477 |
476 // Create a hidden frame which is throttled. | 478 // Create a hidden frame which is throttled. |
477 SimRequest mainResource("https://example.com/", "text/html"); | 479 SimRequest mainResource("https://example.com/", "text/html"); |
478 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 480 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 auto* childFrameElement = toHTMLIFrameElement(frameElement->contentDocument(
)->getElementById("child-frame")); | 763 auto* childFrameElement = toHTMLIFrameElement(frameElement->contentDocument(
)->getElementById("child-frame")); |
762 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 764 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
763 compositor().beginFrame(); | 765 compositor().beginFrame(); |
764 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); | 766 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); |
765 EXPECT_FALSE(childFrameElement->contentDocument()->view()->canThrottleRender
ing()); | 767 EXPECT_FALSE(childFrameElement->contentDocument()->view()->canThrottleRender
ing()); |
766 | 768 |
767 // Only run the intersection observer for the parent frame. Both frames | 769 // Only run the intersection observer for the parent frame. Both frames |
768 // should immediately become throttled. This simulates the case where a task | 770 // should immediately become throttled. This simulates the case where a task |
769 // such as BeginMainFrame runs in the middle of dispatching intersection | 771 // such as BeginMainFrame runs in the middle of dispatching intersection |
770 // observer notifications. | 772 // observer notifications. |
771 frameElement->contentDocument()->view()->notifyRenderThrottlingObserversForT
esting(); | 773 frameElement->contentDocument()->view()->updateRenderThrottlingStatusForTest
ing(); |
772 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; | 774 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
773 EXPECT_TRUE(childFrameElement->contentDocument()->view()->canThrottleRenderi
ng()); | 775 EXPECT_TRUE(childFrameElement->contentDocument()->view()->canThrottleRenderi
ng()); |
774 | 776 |
775 // Both frames should still be throttled after the second notification. | 777 // Both frames should still be throttled after the second notification. |
776 childFrameElement->contentDocument()->view()->notifyRenderThrottlingObserver
sForTesting(); | 778 childFrameElement->contentDocument()->view()->updateRenderThrottlingStatusFo
rTesting(); |
777 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; | 779 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
778 EXPECT_TRUE(childFrameElement->contentDocument()->view()->canThrottleRenderi
ng()); | 780 EXPECT_TRUE(childFrameElement->contentDocument()->view()->canThrottleRenderi
ng()); |
| 781 |
| 782 // Move the frame back on screen but don't update throttling yet. |
| 783 frameElement->setAttribute(styleAttr, "transform: translateY(0px)"); |
| 784 compositor().beginFrame(); |
| 785 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
| 786 EXPECT_TRUE(childFrameElement->contentDocument()->view()->canThrottleRenderi
ng()); |
| 787 |
| 788 // Update throttling for the child. It should remain throttled because the |
| 789 // parent is still throttled. |
| 790 childFrameElement->contentDocument()->view()->updateRenderThrottlingStatusFo
rTesting(); |
| 791 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
| 792 EXPECT_TRUE(childFrameElement->contentDocument()->view()->canThrottleRenderi
ng()); |
| 793 |
| 794 // Updating throttling on the parent should unthrottle both frames. |
| 795 frameElement->contentDocument()->view()->updateRenderThrottlingStatusForTest
ing(); |
| 796 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); |
| 797 EXPECT_FALSE(childFrameElement->contentDocument()->view()->canThrottleRender
ing()); |
779 } | 798 } |
780 | 799 |
781 TEST_F(FrameThrottlingTest, SkipPaintingLayersInThrottledFrames) | 800 TEST_F(FrameThrottlingTest, SkipPaintingLayersInThrottledFrames) |
782 { | 801 { |
783 webView().settings()->setAcceleratedCompositingEnabled(true); | 802 webView().settings()->setAcceleratedCompositingEnabled(true); |
784 webView().settings()->setPreferCompositingToLCDTextEnabled(true); | 803 webView().settings()->setPreferCompositingToLCDTextEnabled(true); |
785 | 804 |
786 SimRequest mainResource("https://example.com/", "text/html"); | 805 SimRequest mainResource("https://example.com/", "text/html"); |
787 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 806 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
788 | 807 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 localFrame->script().executeScriptInMainWorld( | 864 localFrame->script().executeScriptInMainWorld( |
846 "window.requestAnimationFrame(function() {\n" | 865 "window.requestAnimationFrame(function() {\n" |
847 " var throttledFrame = window.parent.frames.first;\n" | 866 " var throttledFrame = window.parent.frames.first;\n" |
848 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" | 867 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" |
849 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\
n" | 868 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\
n" |
850 "});\n"); | 869 "});\n"); |
851 compositeFrame(); | 870 compositeFrame(); |
852 } | 871 } |
853 | 872 |
854 } // namespace blink | 873 } // namespace blink |
OLD | NEW |