| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/frame/FrameView.h" | 5 #include "core/frame/FrameView.h" |
| 6 #include "core/layout/LayoutTestHelper.h" | 6 #include "core/layout/LayoutTestHelper.h" |
| 7 #include "core/layout/LayoutView.h" | 7 #include "core/layout/LayoutView.h" |
| 8 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 namespace blink { | 11 namespace blink { |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 class PaintInvalidationTest : public RenderingTest { | 15 class PaintInvalidationTest : public ::testing::WithParamInterface<bool>, |
| 16 private ScopedRootLayerScrollingForTest, |
| 17 public RenderingTest { |
| 15 public: | 18 public: |
| 16 PaintInvalidationTest() | 19 PaintInvalidationTest() |
| 17 : RenderingTest(SingleChildLocalFrameClient::create()) {} | 20 : ScopedRootLayerScrollingForTest(GetParam()), |
| 21 RenderingTest(SingleChildLocalFrameClient::create()) {} |
| 18 }; | 22 }; |
| 19 | 23 |
| 24 INSTANTIATE_TEST_CASE_P(All, PaintInvalidationTest, ::testing::Bool()); |
| 25 |
| 20 // Changing style in a way that changes overflow without layout should cause | 26 // Changing style in a way that changes overflow without layout should cause |
| 21 // the layout view to possibly need a paint invalidation since we may have | 27 // the layout view to possibly need a paint invalidation since we may have |
| 22 // revealed additional background that can be scrolled into view. | 28 // revealed additional background that can be scrolled into view. |
| 23 TEST_F(PaintInvalidationTest, RecalcOverflowInvalidatesBackground) { | 29 TEST_P(PaintInvalidationTest, RecalcOverflowInvalidatesBackground) { |
| 24 document().page()->settings().setViewportEnabled(true); | 30 document().page()->settings().setViewportEnabled(true); |
| 25 setBodyInnerHTML( | 31 setBodyInnerHTML( |
| 26 "<!DOCTYPE html>" | 32 "<!DOCTYPE html>" |
| 27 "<style type='text/css'>" | 33 "<style type='text/css'>" |
| 28 " body, html {" | 34 " body, html {" |
| 29 " width: 100%;" | 35 " width: 100%;" |
| 30 " height: 100%;" | 36 " height: 100%;" |
| 31 " margin: 0px;" | 37 " margin: 0px;" |
| 32 " }" | 38 " }" |
| 33 " #container {" | 39 " #container {" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 45 | 51 |
| 46 Element* container = document().getElementById("container"); | 52 Element* container = document().getElementById("container"); |
| 47 container->setAttribute(HTMLNames::styleAttr, | 53 container->setAttribute(HTMLNames::styleAttr, |
| 48 "transform: translateY(1000px);"); | 54 "transform: translateY(1000px);"); |
| 49 document().updateStyleAndLayoutTree(); | 55 document().updateStyleAndLayoutTree(); |
| 50 | 56 |
| 51 EXPECT_EQ(scrollableArea->maximumScrollOffset().height(), 1000); | 57 EXPECT_EQ(scrollableArea->maximumScrollOffset().height(), 1000); |
| 52 EXPECT_TRUE(document().layoutView()->mayNeedPaintInvalidation()); | 58 EXPECT_TRUE(document().layoutView()->mayNeedPaintInvalidation()); |
| 53 } | 59 } |
| 54 | 60 |
| 61 TEST_P(PaintInvalidationTest, UpdateVisualRectOnFrameBorderWidthChange) { |
| 62 // TODO(wangxianzhu): enable for SPv2. |
| 63 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 64 return; |
| 65 |
| 66 setBodyInnerHTML( |
| 67 "<style>" |
| 68 " body { margin: 10px }" |
| 69 " iframe { width: 100px; height: 100px; border: none; }" |
| 70 "</style>" |
| 71 "<iframe id='iframe'></iframe>"); |
| 72 |
| 73 Element* iframe = document().getElementById("iframe"); |
| 74 LayoutView* childLayoutView = childDocument().layoutView(); |
| 75 EXPECT_EQ(document().layoutView(), |
| 76 &childLayoutView->containerForPaintInvalidation()); |
| 77 EXPECT_EQ(LayoutRect(10, 10, 100, 100), childLayoutView->visualRect()); |
| 78 |
| 79 iframe->setAttribute(HTMLNames::styleAttr, "border: 20px solid blue"); |
| 80 document().view()->updateAllLifecyclePhases(); |
| 81 EXPECT_EQ(document().layoutView(), |
| 82 &childLayoutView->containerForPaintInvalidation()); |
| 83 EXPECT_EQ(LayoutRect(30, 30, 100, 100), childLayoutView->visualRect()); |
| 84 }; |
| 85 |
| 55 } // namespace | 86 } // namespace |
| 56 | 87 |
| 57 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |