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

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

Issue 2333653002: scheduler: Don't throttle 0x0 frames (Closed)
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 EXPECT_FALSE(document().view()->isHiddenForThrottling()); 98 EXPECT_FALSE(document().view()->isHiddenForThrottling());
99 EXPECT_TRUE(frameDocument->view()->isHiddenForThrottling()); 99 EXPECT_TRUE(frameDocument->view()->isHiddenForThrottling());
100 100
101 // A partially visible child is considered visible. 101 // A partially visible child is considered visible.
102 frameElement->setAttribute(styleAttr, "transform: translate(-50px, 0px, 0px) "); 102 frameElement->setAttribute(styleAttr, "transform: translate(-50px, 0px, 0px) ");
103 compositeFrame(); 103 compositeFrame();
104 EXPECT_FALSE(document().view()->isHiddenForThrottling()); 104 EXPECT_FALSE(document().view()->isHiddenForThrottling());
105 EXPECT_FALSE(frameDocument->view()->isHiddenForThrottling()); 105 EXPECT_FALSE(frameDocument->view()->isHiddenForThrottling());
106 } 106 }
107 107
108 TEST_F(FrameThrottlingTest, ViewportVisibilityFullyClipped)
109 {
110 SimRequest mainResource("https://example.com/", "text/html");
111
112 loadURL("https://example.com/");
113 mainResource.complete("<iframe sandbox id=frame></iframe>");
114
115 // A child which is fully clipped away by its ancestor should become invisib le.
116 webView().resize(WebSize(0, 0));
117 compositeFrame();
118
119 EXPECT_TRUE(document().view()->isHiddenForThrottling());
120
121 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ;
122 auto* frameDocument = frameElement->contentDocument();
123 EXPECT_TRUE(frameDocument->view()->isHiddenForThrottling());
124 }
125
126 TEST_F(FrameThrottlingTest, HiddenSameOriginFramesAreNotThrottled) 108 TEST_F(FrameThrottlingTest, HiddenSameOriginFramesAreNotThrottled)
127 { 109 {
128 SimRequest mainResource("https://example.com/", "text/html"); 110 SimRequest mainResource("https://example.com/", "text/html");
129 SimRequest frameResource("https://example.com/iframe.html", "text/html"); 111 SimRequest frameResource("https://example.com/iframe.html", "text/html");
130 112
131 loadURL("https://example.com/"); 113 loadURL("https://example.com/");
132 mainResource.complete("<iframe id=frame src=iframe.html></iframe>"); 114 mainResource.complete("<iframe id=frame src=iframe.html></iframe>");
133 frameResource.complete("<iframe id=innerFrame></iframe>"); 115 frameResource.complete("<iframe id=innerFrame></iframe>");
134 116
135 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ; 117 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 EXPECT_FALSE(innerFrameDocument->view()->canThrottleRendering()); 153 EXPECT_FALSE(innerFrameDocument->view()->canThrottleRendering());
172 154
173 // Hidden cross origin frames are throttled. 155 // Hidden cross origin frames are throttled.
174 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); 156 frameElement->setAttribute(styleAttr, "transform: translateY(480px)");
175 compositeFrame(); 157 compositeFrame();
176 EXPECT_FALSE(document().view()->canThrottleRendering()); 158 EXPECT_FALSE(document().view()->canThrottleRendering());
177 EXPECT_FALSE(frameDocument->view()->canThrottleRendering()); 159 EXPECT_FALSE(frameDocument->view()->canThrottleRendering());
178 EXPECT_TRUE(innerFrameDocument->view()->canThrottleRendering()); 160 EXPECT_TRUE(innerFrameDocument->view()->canThrottleRendering());
179 } 161 }
180 162
163 TEST_F(FrameThrottlingTest, HiddenCrossOriginZeroByZeroFramesAreNotThrottled)
164 {
165 // Create a document with doubly nested iframes.
166 SimRequest mainResource("https://example.com/", "text/html");
167 SimRequest frameResource("https://example.com/iframe.html", "text/html");
168
169 loadURL("https://example.com/");
170 mainResource.complete("<iframe id=frame src=iframe.html></iframe>");
171 frameResource.complete("<iframe id=innerFrame width=0 height=0 sandbox></ifr ame>");
172
173 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ;
174 auto* frameDocument = frameElement->contentDocument();
175
176 auto* innerFrameElement = toHTMLIFrameElement(frameDocument->getElementById( "innerFrame"));
177 auto* innerFrameDocument = innerFrameElement->contentDocument();
178
179 EXPECT_FALSE(document().view()->canThrottleRendering());
180 EXPECT_FALSE(frameDocument->view()->canThrottleRendering());
181 EXPECT_FALSE(innerFrameDocument->view()->canThrottleRendering());
182
183 // The frame is not throttled because its dimensions are 0x0.
184 frameElement->setAttribute(styleAttr, "transform: translateY(480px)");
185 compositeFrame();
186 EXPECT_FALSE(document().view()->canThrottleRendering());
187 EXPECT_FALSE(frameDocument->view()->canThrottleRendering());
188 EXPECT_FALSE(innerFrameDocument->view()->canThrottleRendering());
189 }
190
181 TEST_F(FrameThrottlingTest, ThrottledLifecycleUpdate) 191 TEST_F(FrameThrottlingTest, ThrottledLifecycleUpdate)
182 { 192 {
183 SimRequest mainResource("https://example.com/", "text/html"); 193 SimRequest mainResource("https://example.com/", "text/html");
184 194
185 loadURL("https://example.com/"); 195 loadURL("https://example.com/");
186 mainResource.complete("<iframe sandbox id=frame></iframe>"); 196 mainResource.complete("<iframe sandbox id=frame></iframe>");
187 197
188 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ; 198 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ;
189 auto* frameDocument = frameElement->contentDocument(); 199 auto* frameDocument = frameElement->contentDocument();
190 200
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 427
418 // Give the frame focus and do another composite. The selection in the 428 // Give the frame focus and do another composite. The selection in the
419 // compositor should be cleared because the frame is throttled. 429 // compositor should be cleared because the frame is throttled.
420 EXPECT_FALSE(compositor().hasSelection()); 430 EXPECT_FALSE(compositor().hasSelection());
421 document().page()->focusController().setFocusedFrame(frameElement->contentDo cument()->frame()); 431 document().page()->focusController().setFocusedFrame(frameElement->contentDo cument()->frame());
422 document().body()->setAttribute(styleAttr, "background: green"); 432 document().body()->setAttribute(styleAttr, "background: green");
423 compositeFrame(); 433 compositeFrame();
424 EXPECT_FALSE(compositor().hasSelection()); 434 EXPECT_FALSE(compositor().hasSelection());
425 } 435 }
426 436
427 TEST(RemoteFrameThrottlingTest, ThrottledLocalRoot)
428 {
429 FrameTestHelpers::TestWebViewClient viewClient;
430 WebViewImpl* webView = WebViewImpl::create(&viewClient, WebPageVisibilitySta teVisible);
431 webView->resize(WebSize(640, 480));
432
433 // Create a remote root frame with a local child frame.
434 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
435 webView->setMainFrame(remoteClient.frame());
436 remoteClient.frame()->setReplicatedOrigin(WebSecurityOrigin::createUnique()) ;
437
438 WebFrameOwnerProperties properties;
439 WebRemoteFrame* rootFrame = webView->mainFrame()->toWebRemoteFrame();
440 WebLocalFrame* localFrame = FrameTestHelpers::createLocalChild(rootFrame);
441
442 WebString baseURL("http://internal.test/");
443 URLTestHelpers::registerMockedURLFromBaseURL(baseURL, "simple_div.html");
444 FrameTestHelpers::loadFrame(localFrame, baseURL.utf8() + "simple_div.html");
445
446 FrameView* frameView = toWebLocalFrameImpl(localFrame)->frameView();
447 EXPECT_TRUE(frameView->frame().isLocalRoot());
448
449 // Enable throttling for the child frame.
450 frameView->setFrameRect(IntRect(0, 480, frameView->width(), frameView->heigh t()));
451 frameView->frame().securityContext()->setSecurityOrigin(SecurityOrigin::crea teUnique());
452 frameView->updateAllLifecyclePhases();
453 testing::runPendingTasks();
454 EXPECT_TRUE(frameView->canThrottleRendering());
455
456 Document* frameDocument = frameView->frame().document();
457 EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().state()) ;
458
459 // Mutate the local child frame contents.
460 auto* divElement = frameDocument->getElementById("div");
461 divElement->setAttribute(styleAttr, "width: 50px");
462 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle() .state());
463
464 // Update the lifecycle again. The frame's lifecycle should not advance
465 // because of throttling even though it is the local root.
466 DocumentLifecycle::AllowThrottlingScope throttlingScope(frameDocument->lifec ycle());
467 frameView->updateAllLifecyclePhases();
468 testing::runPendingTasks();
469 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle() .state());
470 webView->close();
471 }
472
473 TEST_F(FrameThrottlingTest, ScrollingCoordinatorShouldSkipThrottledFrame) 437 TEST_F(FrameThrottlingTest, ScrollingCoordinatorShouldSkipThrottledFrame)
474 { 438 {
475 webView().settings()->setAcceleratedCompositingEnabled(true); 439 webView().settings()->setAcceleratedCompositingEnabled(true);
476 440
477 // Create a hidden frame which is throttled. 441 // Create a hidden frame which is throttled.
478 SimRequest mainResource("https://example.com/", "text/html"); 442 SimRequest mainResource("https://example.com/", "text/html");
479 SimRequest frameResource("https://example.com/iframe.html", "text/html"); 443 SimRequest frameResource("https://example.com/iframe.html", "text/html");
480 444
481 loadURL("https://example.com/"); 445 loadURL("https://example.com/");
482 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); 446 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>");
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 localFrame->script().executeScriptInMainWorld( 810 localFrame->script().executeScriptInMainWorld(
847 "window.requestAnimationFrame(function() {\n" 811 "window.requestAnimationFrame(function() {\n"
848 " var throttledFrame = window.parent.frames.first;\n" 812 " var throttledFrame = window.parent.frames.first;\n"
849 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" 813 " throttledFrame.document.documentElement.style = 'margin: 50px';\n"
850 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\ n" 814 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\ n"
851 "});\n"); 815 "});\n");
852 compositeFrame(); 816 compositeFrame();
853 } 817 }
854 818
855 } // namespace blink 819 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698