| 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 "config.h" | 5 #include "config.h" |
| 6 | |
| 7 #include "platform/scroll/ScrollableArea.h" | 6 #include "platform/scroll/ScrollableArea.h" |
| 8 | 7 |
| 9 #include "platform/TestingPlatformSupport.h" | 8 #include "platform/TestingPlatformSupport.h" |
| 10 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
| 11 #include "public/platform/WebScheduler.h" | 10 #include "public/platform/WebScheduler.h" |
| 12 #include "public/platform/WebThread.h" | 11 #include "public/platform/WebThread.h" |
| 13 #include <gmock/gmock.h> | 12 #include <gmock/gmock.h> |
| 14 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
| 15 | 14 |
| 16 using namespace blink; | 15 namespace blink { |
| 17 | |
| 18 namespace { | |
| 19 | 16 |
| 20 class MockScrollableArea : public ScrollableArea { | 17 class MockScrollableArea : public ScrollableArea { |
| 21 public: | 18 public: |
| 22 MockScrollableArea(const IntPoint& maximumScrollPosition) | 19 MockScrollableArea(const IntPoint& maximumScrollPosition) |
| 23 : m_maximumScrollPosition(maximumScrollPosition) { } | 20 : m_maximumScrollPosition(maximumScrollPosition) { } |
| 24 | 21 |
| 25 MOCK_CONST_METHOD0(isActive, bool()); | 22 MOCK_CONST_METHOD0(isActive, bool()); |
| 26 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); | 23 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); |
| 27 MOCK_METHOD2(invalidateScrollbar, void(Scrollbar*, const IntRect&)); | 24 MOCK_METHOD2(invalidateScrollbar, void(Scrollbar*, const IntRect&)); |
| 28 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); | 25 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); |
| 29 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); | 26 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); |
| 30 MOCK_METHOD2(invalidateScrollbarRect, void(Scrollbar*, const IntRect&)); | 27 MOCK_METHOD2(invalidateScrollbarRect, void(Scrollbar*, const IntRect&)); |
| 31 MOCK_METHOD1(invalidateScrollCornerRect, void(const IntRect&)); | 28 MOCK_METHOD1(invalidateScrollCornerRect, void(const IntRect&)); |
| 32 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); | 29 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); |
| 33 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint()); | 30 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint()); |
| 34 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); | 31 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); |
| 35 MOCK_CONST_METHOD0(contentsSize, IntSize()); | 32 MOCK_CONST_METHOD0(contentsSize, IntSize()); |
| 36 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); | 33 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); |
| 37 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); | 34 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); |
| 38 | 35 |
| 39 virtual bool userInputScrollable(ScrollbarOrientation) const override { retu
rn true; } | 36 bool userInputScrollable(ScrollbarOrientation) const override { return true;
} |
| 40 virtual bool shouldPlaceVerticalScrollbarOnLeft() const override { return fa
lse; } | 37 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } |
| 41 virtual void setScrollOffset(const IntPoint& offset, ScrollType) override {
m_scrollPosition = offset.shrunkTo(m_maximumScrollPosition); } | 38 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll
Position = offset.shrunkTo(m_maximumScrollPosition); } |
| 42 virtual IntPoint scrollPosition() const override { return m_scrollPosition;
} | 39 IntPoint scrollPosition() const override { return m_scrollPosition; } |
| 43 virtual IntPoint maximumScrollPosition() const override { return m_maximumSc
rollPosition; } | 40 IntPoint maximumScrollPosition() const override { return m_maximumScrollPosi
tion; } |
| 44 virtual int visibleHeight() const override { return 768; } | 41 int visibleHeight() const override { return 768; } |
| 45 virtual int visibleWidth() const override { return 1024; } | 42 int visibleWidth() const override { return 1024; } |
| 46 virtual bool scrollAnimatorEnabled() const override { return false; } | 43 bool scrollAnimatorEnabled() const override { return false; } |
| 47 virtual int pageStep(ScrollbarOrientation) const override { return 0; } | 44 int pageStep(ScrollbarOrientation) const override { return 0; } |
| 48 | 45 |
| 49 private: | 46 private: |
| 50 IntPoint m_scrollPosition; | 47 IntPoint m_scrollPosition; |
| 51 IntPoint m_maximumScrollPosition; | 48 IntPoint m_maximumScrollPosition; |
| 52 }; | 49 }; |
| 53 | 50 |
| 54 class FakeWebThread : public WebThread { | 51 class FakeWebThread : public WebThread { |
| 55 public: | 52 public: |
| 56 FakeWebThread() { } | 53 FakeWebThread() { } |
| 57 ~FakeWebThread() override { } | 54 ~FakeWebThread() override { } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 Platform* m_oldPlatform; // Not owned. | 111 Platform* m_oldPlatform; // Not owned. |
| 115 }; | 112 }; |
| 116 | 113 |
| 117 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) | 114 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) |
| 118 { | 115 { |
| 119 MockScrollableArea scrollableArea(IntPoint(0, 100)); | 116 MockScrollableArea scrollableArea(IntPoint(0, 100)); |
| 120 scrollableArea.notifyScrollPositionChanged(IntPoint(0, 10000)); | 117 scrollableArea.notifyScrollPositionChanged(IntPoint(0, 10000)); |
| 121 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y()); | 118 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y()); |
| 122 } | 119 } |
| 123 | 120 |
| 124 } // unnamed namespace | 121 } // namespace blink |
| OLD | NEW |