| 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 "platform/scroll/ScrollableArea.h" | 5 #include "platform/scroll/ScrollableArea.h" |
| 6 | 6 |
| 7 #include "platform/graphics/Color.h" | 7 #include "platform/graphics/Color.h" |
| 8 #include "platform/graphics/GraphicsLayer.h" | 8 #include "platform/graphics/GraphicsLayer.h" |
| 9 #include "platform/scroll/ScrollbarTestSuite.h" |
| 9 #include "platform/scroll/ScrollbarTheme.h" | 10 #include "platform/scroll/ScrollbarTheme.h" |
| 10 #include "platform/scroll/ScrollbarThemeMock.h" | 11 #include "platform/scroll/ScrollbarThemeMock.h" |
| 11 #include "platform/testing/FakeGraphicsLayer.h" | 12 #include "platform/testing/FakeGraphicsLayer.h" |
| 12 #include "platform/testing/FakeGraphicsLayerClient.h" | 13 #include "platform/testing/FakeGraphicsLayerClient.h" |
| 13 #include "platform/testing/TestingPlatformSupport.h" | 14 #include "platform/testing/TestingPlatformSupport.h" |
| 14 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 using testing::_; | 23 using testing::_; |
| 23 using testing::Return; | 24 using testing::Return; |
| 24 | 25 |
| 25 class MockScrollableArea : public GarbageCollectedFinalized<MockScrollableArea>,
public ScrollableArea { | 26 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock { |
| 26 USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); | |
| 27 public: | 27 public: |
| 28 static MockScrollableArea* create(const IntPoint& maximumScrollPosition) | 28 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool()); |
| 29 { | 29 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, ScrollbarPart(const Scro
llbarThemeClient&, float, float)); |
| 30 return new MockScrollableArea(maximumScrollPosition); | |
| 31 } | |
| 32 | |
| 33 MOCK_CONST_METHOD0(visualRectForScrollbarParts, LayoutRect()); | |
| 34 MOCK_CONST_METHOD0(isActive, bool()); | |
| 35 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); | |
| 36 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); | |
| 37 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); | |
| 38 MOCK_CONST_METHOD0(horizontalScrollbar, Scrollbar*()); | |
| 39 MOCK_CONST_METHOD0(verticalScrollbar, Scrollbar*()); | |
| 40 MOCK_METHOD0(scrollControlWasSetNeedsPaintInvalidation, void()); | |
| 41 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); | |
| 42 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); | |
| 43 MOCK_CONST_METHOD0(contentsSize, IntSize()); | |
| 44 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); | |
| 45 MOCK_CONST_METHOD0(layerForHorizontalScrollbar, GraphicsLayer*()); | |
| 46 MOCK_CONST_METHOD0(layerForVerticalScrollbar, GraphicsLayer*()); | |
| 47 | |
| 48 bool userInputScrollable(ScrollbarOrientation) const override { return true;
} | |
| 49 bool scrollbarsCanBeActive () const override { return true; } | |
| 50 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } | |
| 51 void setScrollOffset(const DoublePoint& offset, ScrollType) override { m_scr
ollPosition = flooredIntPoint(offset).shrunkTo(m_maximumScrollPosition); } | |
| 52 IntPoint scrollPosition() const override { return m_scrollPosition; } | |
| 53 IntPoint minimumScrollPosition() const override { return IntPoint(); } | |
| 54 IntPoint maximumScrollPosition() const override { return m_maximumScrollPosi
tion; } | |
| 55 int visibleHeight() const override { return 768; } | |
| 56 int visibleWidth() const override { return 1024; } | |
| 57 bool scrollAnimatorEnabled() const override { return false; } | |
| 58 int pageStep(ScrollbarOrientation) const override { return 0; } | |
| 59 | |
| 60 using ScrollableArea::horizontalScrollbarNeedsPaintInvalidation; | |
| 61 using ScrollableArea::verticalScrollbarNeedsPaintInvalidation; | |
| 62 using ScrollableArea::clearNeedsPaintInvalidationForScrollControls; | |
| 63 | |
| 64 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 65 { | |
| 66 ScrollableArea::trace(visitor); | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 explicit MockScrollableArea(const IntPoint& maximumScrollPosition) | |
| 71 : m_maximumScrollPosition(maximumScrollPosition) { } | |
| 72 | |
| 73 IntPoint m_scrollPosition; | |
| 74 IntPoint m_maximumScrollPosition; | |
| 75 }; | 30 }; |
| 76 | 31 |
| 77 } // namespace | 32 } // namespace |
| 78 | 33 |
| 79 class ScrollableAreaTest : public testing::Test { | 34 class ScrollableAreaTest : public ScrollbarTestSuite { |
| 80 public: | |
| 81 ScrollableAreaTest() { } | |
| 82 | |
| 83 void SetUp() override | |
| 84 { | |
| 85 TestingPlatformSupport::Config config; | |
| 86 config.compositorSupport = Platform::current()->compositorSupport(); | |
| 87 m_fakePlatform = adoptPtr(new TestingPlatformSupportWithMockScheduler(co
nfig)); | |
| 88 } | |
| 89 | |
| 90 void TearDown() override | |
| 91 { | |
| 92 m_fakePlatform = nullptr; | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 OwnPtr<TestingPlatformSupportWithMockScheduler> m_fakePlatform; | |
| 97 }; | 35 }; |
| 98 | 36 |
| 99 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) | 37 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) |
| 100 { | 38 { |
| 101 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0,
100)); | 39 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0,
100)); |
| 102 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll); | 40 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll); |
| 103 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y()); | 41 EXPECT_EQ(100.0, scrollableArea->scrollAnimator().currentPosition().y()); |
| 104 } | 42 } |
| 105 | 43 |
| 106 namespace { | |
| 107 | |
| 108 class ScrollbarThemeWithMockInvalidation : public ScrollbarThemeMock { | |
| 109 public: | |
| 110 MOCK_CONST_METHOD0(shouldRepaintAllPartsOnInvalidation, bool()); | |
| 111 MOCK_CONST_METHOD3(invalidateOnThumbPositionChange, ScrollbarPart(const Scro
llbarThemeClient&, float, float)); | |
| 112 }; | |
| 113 | |
| 114 } // namespace | |
| 115 | |
| 116 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) | 44 TEST_F(ScrollableAreaTest, ScrollbarTrackAndThumbRepaint) |
| 117 { | 45 { |
| 118 ScrollbarThemeWithMockInvalidation theme; | 46 ScrollbarThemeWithMockInvalidation theme; |
| 119 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0,
100)); | 47 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0,
100)); |
| 120 Scrollbar* scrollbar = Scrollbar::createForTesting(scrollableArea, Horizonta
lScrollbar, RegularScrollbar, &theme); | 48 Scrollbar* scrollbar = Scrollbar::createForTesting(scrollableArea, Horizonta
lScrollbar, RegularScrollbar, &theme); |
| 121 | 49 |
| 122 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret
urn(true)); | 50 EXPECT_CALL(theme, shouldRepaintAllPartsOnInvalidation()).WillRepeatedly(Ret
urn(true)); |
| 123 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); | 51 EXPECT_TRUE(scrollbar->trackNeedsRepaint()); |
| 124 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); | 52 EXPECT_TRUE(scrollbar->thumbNeedsRepaint()); |
| 125 scrollbar->setNeedsPaintInvalidation(NoPart); | 53 scrollbar->setNeedsPaintInvalidation(NoPart); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0,
100)); | 202 MockScrollableArea* scrollableArea = MockScrollableArea::create(IntPoint(0,
100)); |
| 275 | 203 |
| 276 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS
tyle()); | 204 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS
tyle()); |
| 277 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51)); | 205 scrollableArea->recalculateScrollbarOverlayStyle(Color(34, 85, 51)); |
| 278 EXPECT_EQ(ScrollbarOverlayStyleLight, scrollableArea->getScrollbarOverlaySty
le()); | 206 EXPECT_EQ(ScrollbarOverlayStyleLight, scrollableArea->getScrollbarOverlaySty
le()); |
| 279 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185)); | 207 scrollableArea->recalculateScrollbarOverlayStyle(Color(236, 143, 185)); |
| 280 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS
tyle()); | 208 EXPECT_EQ(ScrollbarOverlayStyleDefault, scrollableArea->getScrollbarOverlayS
tyle()); |
| 281 } | 209 } |
| 282 | 210 |
| 283 } // namespace blink | 211 } // namespace blink |
| OLD | NEW |