Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: third_party/WebKit/Source/web/tests/FrameThrottlingTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698