| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 SimRequest mainResource("https://example.com/", "text/html"); | 257 SimRequest mainResource("https://example.com/", "text/html"); |
| 258 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 258 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 259 | 259 |
| 260 loadURL("https://example.com/"); | 260 loadURL("https://example.com/"); |
| 261 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); | 261 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
| 262 frameResource.complete("<style> html { background: green; } </style>"); | 262 frameResource.complete("<style> html { background: green; } </style>"); |
| 263 | 263 |
| 264 // Move the frame offscreen to throttle it. | 264 // Move the frame offscreen to throttle it. |
| 265 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; | 265 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 266 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 266 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 267 EXPECT_FALSE(frameElement->contentDocument()->view()->shouldThrottleRenderin
g()); | 267 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); |
| 268 compositeFrame(); | 268 compositeFrame(); |
| 269 EXPECT_TRUE(frameElement->contentDocument()->view()->shouldThrottleRendering
()); | 269 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
| 270 | 270 |
| 271 // Scroll down to unthrottle the frame. The first frame we composite after | 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. | 272 // scrolling won't contain the frame yet, but will schedule another repaint. |
| 273 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); | 273 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); |
| 274 auto displayItems = compositeFrame(); | 274 auto displayItems = compositeFrame(); |
| 275 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); | 275 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 276 | 276 |
| 277 // Now the frame contents should be visible again. | 277 // Now the frame contents should be visible again. |
| 278 auto displayItems2 = compositeFrame(); | 278 auto displayItems2 = compositeFrame(); |
| 279 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); | 279 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 280 } | 280 } |
| 281 | 281 |
| 282 TEST_F(FrameThrottlingTest, ChangeStyleInThrottledFrame) | 282 TEST_F(FrameThrottlingTest, ChangeStyleInThrottledFrame) |
| 283 { | 283 { |
| 284 // Create a hidden frame which is throttled. | 284 // Create a hidden frame which is throttled. |
| 285 SimRequest mainResource("https://example.com/", "text/html"); | 285 SimRequest mainResource("https://example.com/", "text/html"); |
| 286 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 286 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 287 | 287 |
| 288 loadURL("https://example.com/"); | 288 loadURL("https://example.com/"); |
| 289 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); | 289 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
| 290 frameResource.complete("<style> html { background: red; } </style>"); | 290 frameResource.complete("<style> html { background: red; } </style>"); |
| 291 | 291 |
| 292 // Move the frame offscreen to throttle it. | 292 // Move the frame offscreen to throttle it. |
| 293 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; | 293 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame"))
; |
| 294 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 294 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 295 EXPECT_FALSE(frameElement->contentDocument()->view()->shouldThrottleRenderin
g()); | 295 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()
); |
| 296 compositeFrame(); | 296 compositeFrame(); |
| 297 EXPECT_TRUE(frameElement->contentDocument()->view()->shouldThrottleRendering
()); | 297 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering())
; |
| 298 | 298 |
| 299 // Change the background color of the frame's contents from red to green. | 299 // Change the background color of the frame's contents from red to green. |
| 300 frameElement->contentDocument()->body()->setAttribute(styleAttr, "background
: green"); | 300 frameElement->contentDocument()->body()->setAttribute(styleAttr, "background
: green"); |
| 301 | 301 |
| 302 // Scroll down to unthrottle the frame. | 302 // Scroll down to unthrottle the frame. |
| 303 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); | 303 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480
), ProgrammaticScroll); |
| 304 auto displayItems = compositeFrame(); | 304 auto displayItems = compositeFrame(); |
| 305 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "red")); | 305 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "red")); |
| 306 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); | 306 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 307 | 307 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 331 FrameTestHelpers::loadFrame(localFrame, baseURL.utf8() + "simple_div.html"); | 331 FrameTestHelpers::loadFrame(localFrame, baseURL.utf8() + "simple_div.html"); |
| 332 | 332 |
| 333 FrameView* frameView = toWebLocalFrameImpl(localFrame)->frameView(); | 333 FrameView* frameView = toWebLocalFrameImpl(localFrame)->frameView(); |
| 334 EXPECT_TRUE(frameView->frame().isLocalRoot()); | 334 EXPECT_TRUE(frameView->frame().isLocalRoot()); |
| 335 | 335 |
| 336 // Enable throttling for the child frame. | 336 // Enable throttling for the child frame. |
| 337 frameView->setFrameRect(IntRect(0, 480, frameView->width(), frameView->heigh
t())); | 337 frameView->setFrameRect(IntRect(0, 480, frameView->width(), frameView->heigh
t())); |
| 338 frameView->frame().securityContext()->setSecurityOrigin(SecurityOrigin::crea
teUnique()); | 338 frameView->frame().securityContext()->setSecurityOrigin(SecurityOrigin::crea
teUnique()); |
| 339 frameView->updateAllLifecyclePhases(); | 339 frameView->updateAllLifecyclePhases(); |
| 340 testing::runPendingTasks(); | 340 testing::runPendingTasks(); |
| 341 EXPECT_TRUE(frameView->shouldThrottleRendering()); | 341 EXPECT_TRUE(frameView->canThrottleRendering()); |
| 342 | 342 |
| 343 Document* frameDocument = frameView->frame().document(); | 343 Document* frameDocument = frameView->frame().document(); |
| 344 EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().state())
; | 344 EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().state())
; |
| 345 | 345 |
| 346 // Mutate the local child frame contents. | 346 // Mutate the local child frame contents. |
| 347 auto* divElement = frameDocument->getElementById("div"); | 347 auto* divElement = frameDocument->getElementById("div"); |
| 348 divElement->setAttribute(styleAttr, "width: 50px"); | 348 divElement->setAttribute(styleAttr, "width: 50px"); |
| 349 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); | 349 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); |
| 350 | 350 |
| 351 // Update the lifecycle again. The frame's lifecycle should not advance | 351 // Update the lifecycle again. The frame's lifecycle should not advance |
| 352 // because of throttling even though it is the local root. | 352 // because of throttling even though it is the local root. |
| 353 DocumentLifecycle::AllowThrottlingScope throttlingScope(frameDocument->lifec
ycle()); |
| 353 frameView->updateAllLifecyclePhases(); | 354 frameView->updateAllLifecyclePhases(); |
| 354 testing::runPendingTasks(); | 355 testing::runPendingTasks(); |
| 355 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); | 356 EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle()
.state()); |
| 356 webView->close(); | 357 webView->close(); |
| 357 } | 358 } |
| 358 | 359 |
| 359 } // namespace blink | 360 } // namespace blink |
| OLD | NEW |