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" |
6 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
7 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
8 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
9 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
10 #include "core/html/HTMLIFrameElement.h" | 11 #include "core/html/HTMLIFrameElement.h" |
11 #include "core/layout/api/LayoutViewItem.h" | 12 #include "core/layout/api/LayoutViewItem.h" |
12 #include "core/page/FocusController.h" | 13 #include "core/page/FocusController.h" |
13 #include "core/page/Page.h" | 14 #include "core/page/Page.h" |
14 #include "core/paint/PaintLayer.h" | 15 #include "core/paint/PaintLayer.h" |
15 #include "platform/testing/URLTestHelpers.h" | 16 #include "platform/testing/URLTestHelpers.h" |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); | 772 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); |
772 EXPECT_FALSE( | 773 EXPECT_FALSE( |
773 childFrameElement->contentDocument()->view()->canThrottleRendering()); | 774 childFrameElement->contentDocument()->view()->canThrottleRendering()); |
774 | 775 |
775 // Only run the intersection observer for the parent frame. Both frames | 776 // Only run the intersection observer for the parent frame. Both frames |
776 // should immediately become throttled. This simulates the case where a task | 777 // should immediately become throttled. This simulates the case where a task |
777 // such as BeginMainFrame runs in the middle of dispatching intersection | 778 // such as BeginMainFrame runs in the middle of dispatching intersection |
778 // observer notifications. | 779 // observer notifications. |
779 frameElement->contentDocument() | 780 frameElement->contentDocument() |
780 ->view() | 781 ->view() |
781 ->notifyRenderThrottlingObserversForTesting(); | 782 ->updateRenderThrottlingStatusForTesting(); |
782 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | 783 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); |
783 EXPECT_TRUE( | 784 EXPECT_TRUE( |
784 childFrameElement->contentDocument()->view()->canThrottleRendering()); | 785 childFrameElement->contentDocument()->view()->canThrottleRendering()); |
785 | 786 |
786 // Both frames should still be throttled after the second notification. | 787 // Both frames should still be throttled after the second notification. |
787 childFrameElement->contentDocument() | 788 childFrameElement->contentDocument() |
788 ->view() | 789 ->view() |
789 ->notifyRenderThrottlingObserversForTesting(); | 790 ->updateRenderThrottlingStatusForTesting(); |
790 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); | 791 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); |
791 EXPECT_TRUE( | 792 EXPECT_TRUE( |
792 childFrameElement->contentDocument()->view()->canThrottleRendering()); | 793 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()); |
793 } | 818 } |
794 | 819 |
795 TEST_F(FrameThrottlingTest, SkipPaintingLayersInThrottledFrames) { | 820 TEST_F(FrameThrottlingTest, SkipPaintingLayersInThrottledFrames) { |
796 webView().settings()->setAcceleratedCompositingEnabled(true); | 821 webView().settings()->setAcceleratedCompositingEnabled(true); |
797 webView().settings()->setPreferCompositingToLCDTextEnabled(true); | 822 webView().settings()->setPreferCompositingToLCDTextEnabled(true); |
798 | 823 |
799 SimRequest mainResource("https://example.com/", "text/html"); | 824 SimRequest mainResource("https://example.com/", "text/html"); |
800 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 825 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
801 | 826 |
802 loadURL("https://example.com/"); | 827 loadURL("https://example.com/"); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 LocalFrame* localFrame = toLocalFrame(secondFrameElement->contentFrame()); | 892 LocalFrame* localFrame = toLocalFrame(secondFrameElement->contentFrame()); |
868 localFrame->script().executeScriptInMainWorld( | 893 localFrame->script().executeScriptInMainWorld( |
869 "window.requestAnimationFrame(function() {\n" | 894 "window.requestAnimationFrame(function() {\n" |
870 " var throttledFrame = window.parent.frames.first;\n" | 895 " var throttledFrame = window.parent.frames.first;\n" |
871 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" | 896 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" |
872 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\n" | 897 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\n" |
873 "});\n"); | 898 "});\n"); |
874 compositeFrame(); | 899 compositeFrame(); |
875 } | 900 } |
876 | 901 |
| 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 |
877 } // namespace blink | 931 } // namespace blink |
OLD | NEW |