| 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 "bindings/core/v8/ScriptSourceCode.h" |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 main_resource.Complete( | 798 main_resource.Complete( |
| 799 "main <iframe id=frame sandbox=allow-scripts src=iframe.html></iframe>"); | 799 "main <iframe id=frame sandbox=allow-scripts src=iframe.html></iframe>"); |
| 800 frame_resource.Complete(""); | 800 frame_resource.Complete(""); |
| 801 auto* frame_element = | 801 auto* frame_element = |
| 802 toHTMLIFrameElement(GetDocument().GetElementById("frame")); | 802 toHTMLIFrameElement(GetDocument().GetElementById("frame")); |
| 803 frame_element->setAttribute(styleAttr, "transform: translateY(480px)"); | 803 frame_element->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 804 CompositeFrame(); | 804 CompositeFrame(); |
| 805 EXPECT_TRUE(frame_element->contentDocument()->View()->CanThrottleRendering()); | 805 EXPECT_TRUE(frame_element->contentDocument()->View()->CanThrottleRendering()); |
| 806 | 806 |
| 807 LocalFrame* local_frame = ToLocalFrame(frame_element->ContentFrame()); | 807 LocalFrame* local_frame = ToLocalFrame(frame_element->ContentFrame()); |
| 808 local_frame->Script().ExecuteScriptInMainWorld( | 808 local_frame->GetScriptController().ExecuteScriptInMainWorld( |
| 809 "document.body.innerHTML = 'throttled'"); | 809 "document.body.innerHTML = 'throttled'"); |
| 810 EXPECT_FALSE(Compositor().NeedsBeginFrame()); | 810 EXPECT_FALSE(Compositor().NeedsBeginFrame()); |
| 811 | 811 |
| 812 // The dumped contents should not include the throttled frame. | 812 // The dumped contents should not include the throttled frame. |
| 813 DocumentLifecycle::AllowThrottlingScope throttling_scope( | 813 DocumentLifecycle::AllowThrottlingScope throttling_scope( |
| 814 GetDocument().Lifecycle()); | 814 GetDocument().Lifecycle()); |
| 815 WebString result = WebFrameContentDumper::DeprecatedDumpFrameTreeAsText( | 815 WebString result = WebFrameContentDumper::DeprecatedDumpFrameTreeAsText( |
| 816 WebView().MainFrameImpl(), 1024); | 816 WebView().MainFrameImpl(), 1024); |
| 817 EXPECT_NE(std::string::npos, result.Utf8().find("main")); | 817 EXPECT_NE(std::string::npos, result.Utf8().find("main")); |
| 818 EXPECT_EQ(std::string::npos, result.Utf8().find("throttled")); | 818 EXPECT_EQ(std::string::npos, result.Utf8().find("throttled")); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 EXPECT_TRUE( | 989 EXPECT_TRUE( |
| 990 first_frame_element->contentDocument()->View()->CanThrottleRendering()); | 990 first_frame_element->contentDocument()->View()->CanThrottleRendering()); |
| 991 | 991 |
| 992 // Run a animation frame callback in the second frame which mutates the | 992 // Run a animation frame callback in the second frame which mutates the |
| 993 // contents of the first frame and causes a synchronous style update. This | 993 // contents of the first frame and causes a synchronous style update. This |
| 994 // should not result in an unexpected lifecycle state even if the first | 994 // should not result in an unexpected lifecycle state even if the first |
| 995 // frame is throttled during the animation frame callback. | 995 // frame is throttled during the animation frame callback. |
| 996 auto* second_frame_element = | 996 auto* second_frame_element = |
| 997 toHTMLIFrameElement(GetDocument().GetElementById("second")); | 997 toHTMLIFrameElement(GetDocument().GetElementById("second")); |
| 998 LocalFrame* local_frame = ToLocalFrame(second_frame_element->ContentFrame()); | 998 LocalFrame* local_frame = ToLocalFrame(second_frame_element->ContentFrame()); |
| 999 local_frame->Script().ExecuteScriptInMainWorld( | 999 local_frame->GetScriptController().ExecuteScriptInMainWorld( |
| 1000 "window.requestAnimationFrame(function() {\n" | 1000 "window.requestAnimationFrame(function() {\n" |
| 1001 " var throttledFrame = window.parent.frames.first;\n" | 1001 " var throttledFrame = window.parent.frames.first;\n" |
| 1002 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" | 1002 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" |
| 1003 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\n" | 1003 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\n" |
| 1004 "});\n"); | 1004 "});\n"); |
| 1005 CompositeFrame(); | 1005 CompositeFrame(); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 TEST_P(FrameThrottlingTest, AllowOneAnimationFrame) { | 1008 TEST_P(FrameThrottlingTest, AllowOneAnimationFrame) { |
| 1009 WebView().GetSettings()->SetJavaScriptEnabled(true); | 1009 WebView().GetSettings()->SetJavaScriptEnabled(true); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1023 "</script>"); | 1023 "</script>"); |
| 1024 | 1024 |
| 1025 auto* frame_element = | 1025 auto* frame_element = |
| 1026 toHTMLIFrameElement(GetDocument().GetElementById("frame")); | 1026 toHTMLIFrameElement(GetDocument().GetElementById("frame")); |
| 1027 CompositeFrame(); | 1027 CompositeFrame(); |
| 1028 EXPECT_TRUE(frame_element->contentDocument()->View()->CanThrottleRendering()); | 1028 EXPECT_TRUE(frame_element->contentDocument()->View()->CanThrottleRendering()); |
| 1029 | 1029 |
| 1030 LocalFrame* local_frame = ToLocalFrame(frame_element->ContentFrame()); | 1030 LocalFrame* local_frame = ToLocalFrame(frame_element->ContentFrame()); |
| 1031 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 1031 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 1032 v8::Local<v8::Value> result = | 1032 v8::Local<v8::Value> result = |
| 1033 local_frame->Script().ExecuteScriptInMainWorldAndReturnValue( | 1033 local_frame->GetScriptController().ExecuteScriptInMainWorldAndReturnValue( |
| 1034 ScriptSourceCode("window.didRaf;")); | 1034 ScriptSourceCode("window.didRaf;")); |
| 1035 EXPECT_TRUE(result->IsTrue()); | 1035 EXPECT_TRUE(result->IsTrue()); |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 TEST_P(FrameThrottlingTest, UpdatePaintPropertiesOnUnthrottling) { | 1038 TEST_P(FrameThrottlingTest, UpdatePaintPropertiesOnUnthrottling) { |
| 1039 if (!RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) | 1039 if (!RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 1040 return; | 1040 return; |
| 1041 | 1041 |
| 1042 SimRequest main_resource("https://example.com/", "text/html"); | 1042 SimRequest main_resource("https://example.com/", "text/html"); |
| 1043 SimRequest frame_resource("https://example.com/iframe.html", "text/html"); | 1043 SimRequest frame_resource("https://example.com/iframe.html", "text/html"); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 // the child. This behavior matches Safari. | 1133 // the child. This behavior matches Safari. |
| 1134 frame_element->setAttribute(styleAttr, "display: none"); | 1134 frame_element->setAttribute(styleAttr, "display: none"); |
| 1135 CompositeFrame(); | 1135 CompositeFrame(); |
| 1136 EXPECT_FALSE( | 1136 EXPECT_FALSE( |
| 1137 frame_element->contentDocument()->View()->CanThrottleRendering()); | 1137 frame_element->contentDocument()->View()->CanThrottleRendering()); |
| 1138 EXPECT_TRUE( | 1138 EXPECT_TRUE( |
| 1139 child_frame_element->contentDocument()->View()->CanThrottleRendering()); | 1139 child_frame_element->contentDocument()->View()->CanThrottleRendering()); |
| 1140 } | 1140 } |
| 1141 | 1141 |
| 1142 } // namespace blink | 1142 } // namespace blink |
| OLD | NEW |