Chromium Code Reviews| Index: third_party/WebKit/Source/web/tests/FrameThrottlingTest.cpp |
| diff --git a/third_party/WebKit/Source/web/tests/FrameThrottlingTest.cpp b/third_party/WebKit/Source/web/tests/FrameThrottlingTest.cpp |
| index 60faa0b895dc7efc0cd86d439d21682d141153f4..355b06b78cab3b15d5354e3f22a4824b1da5ecd5 100644 |
| --- a/third_party/WebKit/Source/web/tests/FrameThrottlingTest.cpp |
| +++ b/third_party/WebKit/Source/web/tests/FrameThrottlingTest.cpp |
| @@ -11,6 +11,7 @@ |
| #include "core/paint/PaintLayer.h" |
| #include "platform/testing/URLTestHelpers.h" |
| #include "platform/testing/UnitTestHelpers.h" |
| +#include "public/platform/WebDisplayItemList.h" |
| #include "public/platform/WebLayer.h" |
| #include "public/web/WebHitTestResult.h" |
| #include "public/web/WebSettings.h" |
| @@ -22,12 +23,35 @@ |
| #include "web/tests/sim/SimRequest.h" |
| #include "web/tests/sim/SimTest.h" |
| +using testing::_; |
| + |
| namespace blink { |
| using namespace HTMLNames; |
| // NOTE: This test uses <iframe sandbox> to create cross origin iframes. |
| +namespace { |
| + |
| +class MockWebDisplayItemList : public WebDisplayItemList { |
| +public: |
| + ~MockWebDisplayItemList() override {} |
| + |
| + MOCK_METHOD2(appendDrawingItem, void(const WebRect&, sk_sp<const SkPicture>)); |
| +}; |
| + |
| +void paintRecursively(GraphicsLayer* layer, WebDisplayItemList* displayItems) |
| +{ |
| + if (layer->drawsContent()) { |
| + layer->setNeedsDisplay(); |
| + layer->contentLayerDelegateForTesting()->paintContents(displayItems, ContentLayerDelegate::PaintDefaultBehaviorForTest); |
| + } |
| + for (const auto& child : layer->children()) |
| + paintRecursively(child, displayItems); |
| +} |
| + |
| +} // namespace |
| + |
| class FrameThrottlingTest : public SimTest { |
| protected: |
| FrameThrottlingTest() |
| @@ -621,4 +645,36 @@ TEST_F(FrameThrottlingTest, ThrottledEventHandlerIgnored) |
| EXPECT_EQ(1u, touchHandlerRegionSize()); |
| } |
| +TEST_F(FrameThrottlingTest, PaintingViaContentLayerDelegateIsThrottled) |
| +{ |
| + webView().settings()->setAcceleratedCompositingEnabled(true); |
| + webView().settings()->setPreferCompositingToLCDTextEnabled(true); |
| + |
| + // Create a hidden frame which is throttled. |
| + SimRequest mainResource("https://example.com/", "text/html"); |
| + SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| + |
| + loadURL("https://example.com/"); |
| + mainResource.complete("<iframe id=frame sandbox src=iframe.html></iframe>"); |
| + frameResource.complete("throttled"); |
| + compositeFrame(); |
| + |
| + // Move the frame offscreen to throttle it and make sure it is backed by a |
| + // graphics layer. |
| + auto* frameElement = toHTMLIFrameElement(document().getElementById("frame")); |
| + frameElement->setAttribute(styleAttr, "transform: translateY(480px) translateZ(0px)"); |
| + EXPECT_FALSE(frameElement->contentDocument()->view()->canThrottleRendering()); |
| + compositeFrame(); |
| + EXPECT_TRUE(frameElement->contentDocument()->view()->canThrottleRendering()); |
| + |
| + // If painting of the iframe is throttled, we should only receive two |
| + // drawing items. |
| + MockWebDisplayItemList displayItems; |
| + EXPECT_CALL(displayItems, appendDrawingItem(_, _)) |
| + .Times(2); |
| + |
| + GraphicsLayer* layer = webView().rootGraphicsLayer(); |
| + paintRecursively(layer, &displayItems); |
|
ojan
2016/04/28 21:47:27
Specifically, this is not a thing that can happen
Xianzhu
2016/04/28 21:56:32
Right.
However, I think this is why we call raste
|
| +} |
| + |
| } // namespace blink |