Chromium Code Reviews| 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 "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" |
| 11 #include "core/page/FocusController.h" | 11 #include "core/page/FocusController.h" |
| 12 #include "core/page/Page.h" | 12 #include "core/page/Page.h" |
| 13 #include "core/paint/PaintLayer.h" | 13 #include "core/paint/PaintLayer.h" |
| 14 #include "platform/testing/URLTestHelpers.h" | 14 #include "platform/testing/URLTestHelpers.h" |
| 15 #include "platform/testing/UnitTestHelpers.h" | 15 #include "platform/testing/UnitTestHelpers.h" |
| 16 #include "public/platform/WebDisplayItemList.h" | 16 #include "public/platform/WebDisplayItemList.h" |
| 17 #include "public/platform/WebLayer.h" | 17 #include "public/platform/WebLayer.h" |
| 18 #include "public/web/WebFrameContentDumper.h" | 18 #include "public/web/WebFrameContentDumper.h" |
| 19 #include "public/web/WebHitTestResult.h" | 19 #include "public/web/WebHitTestResult.h" |
| 20 #include "public/web/WebRuntimeFeatures.h" | |
| 20 #include "public/web/WebSettings.h" | 21 #include "public/web/WebSettings.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "web/WebLocalFrameImpl.h" | 23 #include "web/WebLocalFrameImpl.h" |
| 23 #include "web/WebRemoteFrameImpl.h" | 24 #include "web/WebRemoteFrameImpl.h" |
| 24 #include "web/tests/sim/SimCompositor.h" | 25 #include "web/tests/sim/SimCompositor.h" |
| 25 #include "web/tests/sim/SimDisplayItemList.h" | 26 #include "web/tests/sim/SimDisplayItemList.h" |
| 26 #include "web/tests/sim/SimRequest.h" | 27 #include "web/tests/sim/SimRequest.h" |
| 27 #include "web/tests/sim/SimTest.h" | 28 #include "web/tests/sim/SimTest.h" |
| 28 | 29 |
| 29 using testing::_; | 30 using testing::_; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 { | 67 { |
| 67 SimDisplayItemList displayItems = compositor().beginFrame(); | 68 SimDisplayItemList displayItems = compositor().beginFrame(); |
| 68 // Ensure intersection observer notifications get delivered. | 69 // Ensure intersection observer notifications get delivered. |
| 69 testing::runPendingTasks(); | 70 testing::runPendingTasks(); |
| 70 return displayItems; | 71 return displayItems; |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Number of rectangles that make up the root layer's touch handler region. | 74 // Number of rectangles that make up the root layer's touch handler region. |
| 74 size_t touchHandlerRegionSize() | 75 size_t touchHandlerRegionSize() |
| 75 { | 76 { |
| 76 return webView().mainFrameImpl()->frame()->contentLayoutItem().layer()-> graphicsLayerBacking()->platformLayer()->touchEventHandlerRegion().size(); | 77 return webView().mainFrameImpl()->frame()->contentLayoutItem().layer()-> graphicsLayerBackingForScrolling()->platformLayer()->touchEventHandlerRegion().s ize(); |
| 77 } | 78 } |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 TEST_F(FrameThrottlingTest, ThrottleInvisibleFrames) | 81 TEST_F(FrameThrottlingTest, ThrottleInvisibleFrames) |
| 81 { | 82 { |
| 82 SimRequest mainResource("https://example.com/", "text/html"); | 83 SimRequest mainResource("https://example.com/", "text/html"); |
| 83 | 84 |
| 84 loadURL("https://example.com/"); | 85 loadURL("https://example.com/"); |
| 85 mainResource.complete("<iframe sandbox id=frame></iframe>"); | 86 mainResource.complete("<iframe sandbox id=frame></iframe>"); |
| 86 | 87 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 | 305 |
| 305 // Move the frame offscreen to throttle it. | 306 // Move the frame offscreen to throttle it. |
| 306 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ; | 307 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ; |
| 307 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 308 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 308 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering() ); | 309 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering() ); |
| 309 compositeFrame(); | 310 compositeFrame(); |
| 310 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()) ; | 311 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()) ; |
| 311 | 312 |
| 312 // Scroll down to unthrottle the frame. The first frame we composite after | 313 // Scroll down to unthrottle the frame. The first frame we composite after |
| 313 // scrolling won't contain the frame yet, but will schedule another repaint. | 314 // scrolling won't contain the frame yet, but will schedule another repaint. |
| 314 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480 ), ProgrammaticScroll); | 315 webView().mainFrameImpl()->frameView()->layoutViewportScrollableArea()->setS crollPosition(DoublePoint(0, 480), ProgrammaticScroll); |
| 315 auto displayItems = compositeFrame(); | 316 auto displayItems = compositeFrame(); |
| 316 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); | 317 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 317 | 318 |
| 318 // Now the frame contents should be visible again. | 319 // Now the frame contents should be visible again. |
| 319 auto displayItems2 = compositeFrame(); | 320 auto displayItems2 = compositeFrame(); |
| 320 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); | 321 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 321 } | 322 } |
| 322 | 323 |
| 323 TEST_F(FrameThrottlingTest, UnthrottlingTriggersRepaintInCompositedChild) | 324 TEST_F(FrameThrottlingTest, UnthrottlingTriggersRepaintInCompositedChild) |
| 324 { | 325 { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 340 | 341 |
| 341 // Move the frame offscreen to throttle it. | 342 // Move the frame offscreen to throttle it. |
| 342 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ; | 343 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ; |
| 343 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 344 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 344 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering() ); | 345 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering() ); |
| 345 compositeFrame(); | 346 compositeFrame(); |
| 346 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()) ; | 347 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()) ; |
| 347 | 348 |
| 348 // Scroll down to unthrottle the frame. The first frame we composite after | 349 // Scroll down to unthrottle the frame. The first frame we composite after |
| 349 // scrolling won't contain the frame yet, but will schedule another repaint. | 350 // scrolling won't contain the frame yet, but will schedule another repaint. |
| 350 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480 ), ProgrammaticScroll); | 351 webView().mainFrameImpl()->frameView()->layoutViewportScrollableArea()->setS crollPosition(DoublePoint(0, 480), ProgrammaticScroll); |
| 351 auto displayItems = compositeFrame(); | 352 auto displayItems = compositeFrame(); |
| 352 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); | 353 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 353 | 354 |
| 354 // Now the composited child contents should be visible again. | 355 // Now the composited child contents should be visible again. |
| 355 auto displayItems2 = compositeFrame(); | 356 auto displayItems2 = compositeFrame(); |
| 356 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); | 357 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 357 } | 358 } |
| 358 | 359 |
| 360 | |
|
Sami
2016/09/07 14:48:43
Unintended whitespace?
szager1
2016/09/07 16:53:01
Fixed.
| |
| 359 TEST_F(FrameThrottlingTest, ChangeStyleInThrottledFrame) | 361 TEST_F(FrameThrottlingTest, ChangeStyleInThrottledFrame) |
| 360 { | 362 { |
| 361 // Create a hidden frame which is throttled. | 363 // Create a hidden frame which is throttled. |
| 362 SimRequest mainResource("https://example.com/", "text/html"); | 364 SimRequest mainResource("https://example.com/", "text/html"); |
| 363 SimRequest frameResource("https://example.com/iframe.html", "text/html"); | 365 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 364 | 366 |
| 365 loadURL("https://example.com/"); | 367 loadURL("https://example.com/"); |
| 366 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); | 368 mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
| 367 frameResource.complete("<style> html { background: red; } </style>"); | 369 frameResource.complete("<style> html { background: red; } </style>"); |
| 368 | 370 |
| 369 // Move the frame offscreen to throttle it. | 371 // Move the frame offscreen to throttle it. |
| 370 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ; | 372 auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")) ; |
| 371 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); | 373 frameElement->setAttribute(styleAttr, "transform: translateY(480px)"); |
| 372 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering() ); | 374 EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering() ); |
| 373 compositeFrame(); | 375 compositeFrame(); |
| 374 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()) ; | 376 EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()) ; |
| 375 | 377 |
| 376 // Change the background color of the frame's contents from red to green. | 378 // Change the background color of the frame's contents from red to green. |
| 377 frameElement->contentDocument()->body()->setAttribute(styleAttr, "background : green"); | 379 frameElement->contentDocument()->body()->setAttribute(styleAttr, "background : green"); |
| 378 | 380 |
| 379 // Scroll down to unthrottle the frame. | 381 // Scroll down to unthrottle the frame. |
| 380 webView().mainFrameImpl()->frameView()->setScrollPosition(DoublePoint(0, 480 ), ProgrammaticScroll); | 382 webView().mainFrameImpl()->frameView()->layoutViewportScrollableArea()->setS crollPosition(DoublePoint(0, 480), ProgrammaticScroll); |
| 381 auto displayItems = compositeFrame(); | 383 auto displayItems = compositeFrame(); |
| 382 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "red")); | 384 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "red")); |
| 383 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); | 385 EXPECT_FALSE(displayItems.contains(SimCanvas::Rect, "green")); |
| 384 | 386 |
| 385 // Make sure the new style shows up instead of the old one. | 387 // Make sure the new style shows up instead of the old one. |
| 386 auto displayItems2 = compositeFrame(); | 388 auto displayItems2 = compositeFrame(); |
| 387 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); | 389 EXPECT_TRUE(displayItems2.contains(SimCanvas::Rect, "green")); |
| 388 } | 390 } |
| 389 | 391 |
| 390 TEST_F(FrameThrottlingTest, ThrottledFrameWithFocus) | 392 TEST_F(FrameThrottlingTest, ThrottledFrameWithFocus) |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 localFrame->script().executeScriptInMainWorld( | 847 localFrame->script().executeScriptInMainWorld( |
| 846 "window.requestAnimationFrame(function() {\n" | 848 "window.requestAnimationFrame(function() {\n" |
| 847 " var throttledFrame = window.parent.frames.first;\n" | 849 " var throttledFrame = window.parent.frames.first;\n" |
| 848 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" | 850 " throttledFrame.document.documentElement.style = 'margin: 50px';\n" |
| 849 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\ n" | 851 " throttledFrame.document.querySelector('#d').getBoundingClientRect();\ n" |
| 850 "});\n"); | 852 "});\n"); |
| 851 compositeFrame(); | 853 compositeFrame(); |
| 852 } | 854 } |
| 853 | 855 |
| 854 } // namespace blink | 856 } // namespace blink |
| OLD | NEW |