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 "bindings/core/v8/ScriptSourceCode.h" | |
7 #include "core/dom/Document.h" | 6 #include "core/dom/Document.h" |
8 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
9 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
10 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
11 #include "core/html/HTMLIFrameElement.h" | 10 #include "core/html/HTMLIFrameElement.h" |
12 #include "core/layout/api/LayoutViewItem.h" | 11 #include "core/layout/api/LayoutViewItem.h" |
13 #include "core/page/FocusController.h" | 12 #include "core/page/FocusController.h" |
14 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
15 #include "core/paint/PaintLayer.h" | 14 #include "core/paint/PaintLayer.h" |
16 #include "platform/testing/URLTestHelpers.h" | 15 #include "platform/testing/URLTestHelpers.h" |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); | 771 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); |
773 EXPECT_FALSE( | 772 EXPECT_FALSE( |
774 childFrameElement->contentDocument()->view()->canThrottleRendering()); | 773 childFrameElement->contentDocument()->view()->canThrottleRendering()); |
775 | 774 |
776 // Only run the intersection observer for the parent frame. Both frames | 775 // Only run the intersection observer for the parent frame. Both frames |
777 // should immediately become throttled. This simulates the case where a task | 776 // should immediately become throttled. This simulates the case where a task |
778 // such as BeginMainFrame runs in the middle of dispatching intersection | 777 // such as BeginMainFrame runs in the middle of dispatching intersection |
779 // observer notifications. | 778 // observer notifications. |
780 frameElement->contentDocument() | 779 frameElement->contentDocument() |
781 ->view() | 780 ->view() |
782 ->updateRenderThrottlingStatusForTesting(); | 781 ->notifyRenderThrottlingObserversForTesting(); |
783 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | 782 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); |
784 EXPECT_TRUE( | 783 EXPECT_TRUE( |
785 childFrameElement->contentDocument()->view()->canThrottleRendering()); | 784 childFrameElement->contentDocument()->view()->canThrottleRendering()); |
786 | 785 |
787 // Both frames should still be throttled after the second notification. | 786 // Both frames should still be throttled after the second notification. |
788 childFrameElement->contentDocument() | 787 childFrameElement->contentDocument() |
789 ->view() | 788 ->view() |
790 ->updateRenderThrottlingStatusForTesting(); | 789 ->notifyRenderThrottlingObserversForTesting(); |
791 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | 790 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); |
792 EXPECT_TRUE( | 791 EXPECT_TRUE( |
793 childFrameElement->contentDocument()->view()->canThrottleRendering()); | 792 childFrameElement->contentDocument()->view()->canThrottleRendering()); |
794 | |
795 // Move the frame back on screen but don't update throttling yet. | |
796 frameElement->setAttribute(styleAttr, "transform: translateY(0px)"); | |
797 compositor().beginFrame(); | |
798 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | |
799 EXPECT_TRUE( | |
800 childFrameElement->contentDocument()->view()->canThrottleRendering()); | |
801 | |
802 // Update throttling for the child. It should remain throttled because the | |
803 // parent is still throttled. | |
804 childFrameElement->contentDocument() | |
805 ->view() | |
806 ->updateRenderThrottlingStatusForTesting(); | |
807 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | |
808 EXPECT_TRUE( | |
809 childFrameElement->contentDocument()->view()->canThrottleRendering()); | |
810 | |
811 // Updating throttling on the parent should unthrottle both frames. | |
812 frameElement->contentDocument() | |
813 ->view() | |
814 ->updateRenderThrottlingStatusForTesting(); | |
815 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); | |
816 EXPECT_FALSE( | |
817 childFrameElement->contentDocument()->view()->canThrottleRendering()); | |
818 } | 793 } |
819 | 794 |
820 TEST_F(FrameThrottlingTest, SkipPaintingLayersInThrottledFrames) { | 795 TEST_F(FrameThrottlingTest, SkipPaintingLayersInThrottledFrames) { |
821 webView().settings()->setAcceleratedCompositingEnabled(true); | 796 webView().settings()->setAcceleratedCompositingEnabled(true); |
822 webView().settings()->setPreferCompositingToLCDTextEnabled(true); | 797 webView().settings()->setPreferCompositingToLCDTextEnabled(true); |
823 | 798 |
824 SimRequest mainResource("https://example.com/", "text/html"); | 799 SimRequest mainResource("https://example.com/", "text/html"); |
825 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 800 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
826 | 801 |
827 loadURL("https://example.com/"); | 802 loadURL("https://example.com/"); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 LocalFrame* localFrame = toLocalFrame(secondFrameElement->contentFrame()); | 867 LocalFrame* localFrame = toLocalFrame(secondFrameElement->contentFrame()); |
893 localFrame->script().executeScriptInMainWorld( | 868 localFrame->script().executeScriptInMainWorld( |
894 "window.requestAnimationFrame(function() {\n" | 869 "window.requestAnimationFrame(function() {\n" |
895 " var throttledFrame = window.parent.frames.first;\n" | 870 " var throttledFrame = window.parent.frames.first;\n" |
896 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" | 871 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" |
897 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\n" | 872 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\n" |
898 "});\n"); | 873 "});\n"); |
899 compositeFrame(); | 874 compositeFrame(); |
900 } | 875 } |
901 | 876 |
902 TEST_F(FrameThrottlingTest, AllowOneAnimationFrame) { | |
903 webView().settings()->setJavaScriptEnabled(true); | |
904 | |
905 // Prepare a page with two cross origin frames (from the same origin so they | |
906 // are able to access eachother). | |
907 SimRequest mainResource("https://example.com/", "text/html"); | |
908 SimRequest frameResource("https://thirdparty.com/frame.html", "text/html"); | |
909 loadURL("https://example.com/"); | |
910 mainResource.complete( | |
911 "<iframe id=frame style=\"position: fixed; top: -10000px\" " | |
912 "src='https://thirdparty.com/frame.html'></iframe>"); | |
913 | |
914 frameResource.complete( | |
915 "<script>" | |
916 "window.requestAnimationFrame(() => { window.didRaf = true; });" | |
917 "</script>"); | |
918 | |
919 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); | |
920 compositeFrame(); | |
921 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | |
922 | |
923 LocalFrame* localFrame = toLocalFrame(frameElement->contentFrame()); | |
924 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
925 v8::Local<v8::Value> result = | |
926 localFrame->script().executeScriptInMainWorldAndReturnValue( | |
927 ScriptSourceCode("window.didRaf;")); | |
928 EXPECT_TRUE(result->IsTrue()); | |
929 } | |
930 | |
931 } // namespace blink | 877 } // namespace blink |
OLD | NEW |