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 "core/dom/Document.h" | 5 #include "core/dom/Document.h" |
6 #include "core/dom/Element.h" | 6 #include "core/dom/Element.h" |
7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
8 #include "core/html/HTMLIFrameElement.h" | 8 #include "core/html/HTMLIFrameElement.h" |
9 #include "platform/testing/URLTestHelpers.h" | 9 #include "platform/testing/URLTestHelpers.h" |
10 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 // Move the frame offscreen to throttle it. | 205 // Move the frame offscreen to throttle it. |
206 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 206 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
207 compositeFrame(); | 207 compositeFrame(); |
208 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; | 208 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
209 | 209 |
210 // Mutating the throttled frame should not cause an animation to be schedule
d. | 210 // Mutating the throttled frame should not cause an animation to be schedule
d. |
211 frameElement->contentDocument()->documentElement()->setAttribute(styleAttr,
"background: green"); | 211 frameElement->contentDocument()->documentElement()->setAttribute(styleAttr,
"background: green"); |
212 EXPECT_FALSE(compositor().needsAnimate()); | 212 EXPECT_FALSE(compositor().needsAnimate()); |
213 | 213 |
214 // Moving the frame back on screen to unthrottle it. | 214 // Move the frame back on screen to unthrottle it. |
215 frameElement->setAttribute(styleAttr, ""); | 215 frameElement->setAttribute(styleAttr, ""); |
216 EXPECT_TRUE(compositor().needsAnimate()); | 216 EXPECT_TRUE(compositor().needsAnimate()); |
217 | 217 |
218 // The first frame we composite after unthrottling won't contain the | 218 // The first frame we composite after unthrottling won't contain the |
219 // frame's new contents because unthrottling happens at the end of the | 219 // frame's new contents because unthrottling happens at the end of the |
220 // lifecycle update. We need to do another composite to refresh the frame's | 220 // lifecycle update. We need to do another composite to refresh the frame's |
221 // contents. | 221 // contents. |
222 auto displayItems2 = compositeFrame(); | 222 auto displayItems2 = compositeFrame(); |
223 EXPECT_FALSE(displayItems2.contains(SimCanvas::Rect, "green")); | 223 EXPECT_FALSE(displayItems2.contains(SimCanvas::Rect, "green")); |
224 EXPECT_TRUE(compositor().needsAnimate()); | 224 EXPECT_TRUE(compositor().needsAnimate()); |
(...skipping 19 matching lines...) Expand all Loading... |
244 | 244 |
245 // Change the size of a div in the throttled frame. | 245 // Change the size of a div in the throttled frame. |
246 auto* divElement = frameElement->contentDocument()->getElementById("div"); | 246 auto* divElement = frameElement->contentDocument()->getElementById("div"); |
247 divElement->setAttribute(styleAttr, "width: 50px"); | 247 divElement->setAttribute(styleAttr, "width: 50px"); |
248 | 248 |
249 // Querying the width of the div should do a synchronous layout update even | 249 // Querying the width of the div should do a synchronous layout update even |
250 // though the frame is being throttled. | 250 // though the frame is being throttled. |
251 EXPECT_EQ(50, divElement->clientWidth()); | 251 EXPECT_EQ(50, divElement->clientWidth()); |
252 } | 252 } |
253 | 253 |
| 254 TEST_F(FrameThrottlingTest, UnthrottlingTriggersRepaint) |
| 255 { |
| 256 // Create a hidden frame which is throttled. |
| 257 SimRequest mainResource("https://example.com/", "text/html"); |
| 258 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 259 |
| 260 loadURL("https://example.com/"); |
| 261 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
| 262 frameResource.complete("<style> html { background: green; } </style>"); |
| 263 |
| 264 // Move the frame offscreen to throttle it. |
| 265 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 266 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 267 EXPECT_FALSE(frameElement->contentDocument()->view()->shouldThrottleRenderin
g()); |
| 268 compositeFrame(); |
| 269 EXPECT_TRUE(frameElement->contentDocument()->view()->shouldThrottleRendering
()); |
| 270 |
| 271 // Scroll down to unthrottle the frame. The first frame we composite after |
| 272 // scrolling won't contain the frame yet, but will schedule another repaint. |
| 273 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); |
| 274 auto displayItems = compositeFrame(); |
| 275 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 276 |
| 277 // Now the frame contents should be visible again. |
| 278 auto displayItems2 = compositeFrame(); |
| 279 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 280 } |
| 281 |
| 282 TEST_F(FrameThrottlingTest, ChangeStyleInThrottledFrame) |
| 283 { |
| 284 // Create a hidden frame which is throttled. |
| 285 SimRequest mainResource("https://example.com/", "text/html"); |
| 286 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 287 |
| 288 loadURL("https://example.com/"); |
| 289 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
| 290 frameResource.complete("<style> html { background: red; } </style>"); |
| 291 |
| 292 // Move the frame offscreen to throttle it. |
| 293 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 294 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 295 EXPECT_FALSE(frameElement->contentDocument()->view()->shouldThrottleRenderin
g()); |
| 296 compositeFrame(); |
| 297 EXPECT_TRUE(frameElement->contentDocument()->view()->shouldThrottleRendering
()); |
| 298 |
| 299 // Change the background color of the frame's contents from red to green. |
| 300 frameElement->contentDocument()->body()->setAttribute(styleAttr, "background
: green"); |
| 301 |
| 302 // Scroll down to unthrottle the frame. |
| 303 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); |
| 304 auto displayItems = compositeFrame(); |
| 305 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "red")); |
| 306 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 307 |
| 308 // Make sure the new style shows up instead of the old one. |
| 309 auto displayItems2 = compositeFrame(); |
| 310 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 311 } |
| 312 |
254 TEST(RemoteFrameThrottlingTest, ThrottledLocalRoot) | 313 TEST(RemoteFrameThrottlingTest, ThrottledLocalRoot) |
255 { | 314 { |
256 FrameTestHelpers::TestWebViewClient viewClient; | 315 FrameTestHelpers::TestWebViewClient viewClient; |
257 WebViewImpl* webView = WebViewImpl::create(&viewClient); | 316 WebViewImpl* webView = WebViewImpl::create(&viewClient); |
258 webView->resize(WebSize(640, 480)); | 317 webView->resize(WebSize(640, 480)); |
259 | 318 |
260 // Create a remote root frame with a local child frame. | 319 // Create a remote root frame with a local child frame. |
261 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; | 320 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; |
262 webView->setMainFrame(remoteClient.frame()); | 321 webView->setMainFrame(remoteClient.frame()); |
263 remoteClient.frame()->setReplicatedOrigin(WebSecurityOrigin::createUnique())
; | 322 remoteClient.frame()->setReplicatedOrigin(WebSecurityOrigin::createUnique())
; |
(...skipping 27 matching lines...) Expand all Loading... |
291 | 350 |
292 // Update the lifecycle again. The frame's lifecycle should not advance | 351 // Update the lifecycle again. The frame's lifecycle should not advance |
293 // because of throttling even though it is the local root. | 352 // because of throttling even though it is the local root. |
294 frameView->updateAllLifecyclePhases(); | 353 frameView->updateAllLifecyclePhases(); |
295 testing::runPendingTasks(); | 354 testing::runPendingTasks(); |
296 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); | 355 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); |
297 webView->close(); | 356 webView->close(); |
298 } | 357 } |
299 | 358 |
300 } // namespace blink | 359 } // namespace blink |
OLD | NEW |