| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/paint/PaintLayerScrollableArea.h" | 5 #include "core/paint/PaintLayerScrollableArea.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/layout/LayoutBoxModelObject.h" | 8 #include "core/layout/LayoutBoxModelObject.h" |
| 9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include "core/paint/PaintLayer.h" | 10 #include "core/paint/PaintLayer.h" |
| 11 #include "platform/graphics/GraphicsLayer.h" | 11 #include "platform/graphics/GraphicsLayer.h" |
| 12 #include "platform/scroll/ScrollTypes.h" | 12 #include "platform/scroll/ScrollTypes.h" |
| 13 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 13 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 |
| 16 using testing::_; |
| 14 | 17 |
| 15 namespace blink { | 18 namespace blink { |
| 19 namespace { |
| 20 |
| 21 class MockChromeClient : public EmptyChromeClient { |
| 22 public: |
| 23 MOCK_METHOD3(mockSetToolTip, void(LocalFrame*, const String&, TextDirection)); |
| 24 void setToolTip(LocalFrame& frame, |
| 25 const String& tooltipText, |
| 26 TextDirection dir) override { |
| 27 mockSetToolTip(&frame, tooltipText, dir); |
| 28 } |
| 29 }; |
| 30 |
| 31 } // namespace { |
| 16 | 32 |
| 17 class PaintLayerScrollableAreaTest : public RenderingTest { | 33 class PaintLayerScrollableAreaTest : public RenderingTest { |
| 18 public: | 34 public: |
| 19 PaintLayerScrollableAreaTest() | 35 PaintLayerScrollableAreaTest() |
| 20 : RenderingTest(EmptyFrameLoaderClient::create()) {} | 36 : RenderingTest(EmptyFrameLoaderClient::create()), |
| 37 m_chromeClient(new MockChromeClient) {} |
| 38 |
| 39 ~PaintLayerScrollableAreaTest() { |
| 40 testing::Mock::VerifyAndClearExpectations(&chromeClient()); |
| 41 } |
| 42 |
| 43 MockChromeClient& chromeClient() const override { return *m_chromeClient; } |
| 21 | 44 |
| 22 BackgroundPaintLocation backgroundPaintLocation(const char* elementId) { | 45 BackgroundPaintLocation backgroundPaintLocation(const char* elementId) { |
| 23 PaintLayer* paintLayer = | 46 PaintLayer* paintLayer = |
| 24 toLayoutBoxModelObject(getLayoutObjectByElementId(elementId))->layer(); | 47 toLayoutBoxModelObject(getLayoutObjectByElementId(elementId))->layer(); |
| 25 return paintLayer->backgroundPaintLocation(); | 48 return paintLayer->backgroundPaintLocation(); |
| 26 } | 49 } |
| 27 | 50 |
| 28 private: | 51 private: |
| 29 void SetUp() override { | 52 void SetUp() override { |
| 30 RenderingTest::SetUp(); | 53 RenderingTest::SetUp(); |
| 31 enableCompositing(); | 54 enableCompositing(); |
| 32 } | 55 } |
| 56 |
| 57 Persistent<MockChromeClient> m_chromeClient; |
| 33 }; | 58 }; |
| 34 | 59 |
| 35 TEST_F(PaintLayerScrollableAreaTest, | 60 TEST_F(PaintLayerScrollableAreaTest, |
| 36 CanPaintBackgroundOntoScrollingContentsLayer) { | 61 CanPaintBackgroundOntoScrollingContentsLayer) { |
| 37 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); | 62 document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); |
| 38 setBodyInnerHTML( | 63 setBodyInnerHTML( |
| 39 "<style>" | 64 "<style>" |
| 40 ".scroller { overflow: scroll; will-change: transform; width: 300px; " | 65 ".scroller { overflow: scroll; will-change: transform; width: 300px; " |
| 41 "height: 300px;} .spacer { height: 1000px; }" | 66 "height: 300px;} .spacer { height: 1000px; }" |
| 42 "#scroller13::-webkit-scrollbar { width: 13px; height: 13px;}" | 67 "#scroller13::-webkit-scrollbar { width: 13px; height: 13px;}" |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 ASSERT_TRUE(paintLayer); | 516 ASSERT_TRUE(paintLayer); |
| 492 EXPECT_FALSE(paintLayer->needsCompositedScrolling()); | 517 EXPECT_FALSE(paintLayer->needsCompositedScrolling()); |
| 493 | 518 |
| 494 // Change the scroller to be auto clipped again. | 519 // Change the scroller to be auto clipped again. |
| 495 scroller->removeAttribute("class"); | 520 scroller->removeAttribute("class"); |
| 496 document().view()->updateAllLifecyclePhases(); | 521 document().view()->updateAllLifecyclePhases(); |
| 497 paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->layer(); | 522 paintLayer = toLayoutBoxModelObject(scroller->layoutObject())->layer(); |
| 498 ASSERT_TRUE(paintLayer); | 523 ASSERT_TRUE(paintLayer); |
| 499 EXPECT_TRUE(paintLayer->needsCompositedScrolling()); | 524 EXPECT_TRUE(paintLayer->needsCompositedScrolling()); |
| 500 } | 525 } |
| 526 |
| 527 TEST_F(PaintLayerScrollableAreaTest, HideTooltipWhenScrollPositionChanges) { |
| 528 setBodyInnerHTML( |
| 529 "<style>" |
| 530 "#scroller { width: 100px; height: 100px; overflow: scroll; }" |
| 531 "#scrolled { height: 300px; }" |
| 532 "</style>" |
| 533 "<div id=\"scroller\"><div id=\"scrolled\"></div></div>"); |
| 534 document().view()->updateAllLifecyclePhases(); |
| 535 |
| 536 Element* scroller = document().getElementById("scroller"); |
| 537 PaintLayerScrollableArea* scrollableArea = |
| 538 toLayoutBoxModelObject(scroller->layoutObject())->getScrollableArea(); |
| 539 ASSERT_TRUE(scrollableArea); |
| 540 |
| 541 EXPECT_CALL(chromeClient(), mockSetToolTip(document().frame(), String(), _)) |
| 542 .Times(1); |
| 543 scrollableArea->setScrollOffset(ScrollOffset(1, 1), UserScroll); |
| 544 |
| 545 // Programmatic scrolling should not dismiss the tooltip, so setToolTip |
| 546 // should not be called for this invocation. |
| 547 EXPECT_CALL(chromeClient(), mockSetToolTip(document().frame(), String(), _)) |
| 548 .Times(0); |
| 549 scrollableArea->setScrollOffset(ScrollOffset(2, 2), ProgrammaticScroll); |
| 501 } | 550 } |
| 551 } |
| OLD | NEW |