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 #include "platform/scroll/ScrollableArea.h" | 6 #include "platform/scroll/ScrollableArea.h" |
7 | 7 |
8 #include "platform/TestingPlatformSupport.h" | 8 #include "platform/TestingPlatformSupport.h" |
9 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
10 #include "public/platform/WebScheduler.h" | 10 #include "public/platform/WebScheduler.h" |
11 #include "public/platform/WebThread.h" | 11 #include "public/platform/WebThread.h" |
12 #include <gmock/gmock.h> | 12 #include <gmock/gmock.h> |
13 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 class MockScrollableArea : public ScrollableArea { | 17 class MockScrollableArea : public NoBaseWillBeGarbageCollectedFinalized<MockScro
llableArea>, public ScrollableArea { |
| 18 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MockScrollableArea); |
18 public: | 19 public: |
19 MockScrollableArea(const IntPoint& maximumScrollPosition) | 20 static PassOwnPtrWillBeRawPtr<MockScrollableArea> create(const IntPoint& max
imumScrollPosition) |
20 : m_maximumScrollPosition(maximumScrollPosition) { } | 21 { |
| 22 return adoptPtrWillBeNoop(new MockScrollableArea(maximumScrollPosition))
; |
| 23 } |
21 | 24 |
22 MOCK_CONST_METHOD0(isActive, bool()); | 25 MOCK_CONST_METHOD0(isActive, bool()); |
23 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); | 26 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); |
24 MOCK_METHOD2(invalidateScrollbar, void(Scrollbar*, const IntRect&)); | 27 MOCK_METHOD2(invalidateScrollbar, void(Scrollbar*, const IntRect&)); |
25 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); | 28 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); |
26 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); | 29 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); |
27 MOCK_METHOD2(invalidateScrollbarRect, void(Scrollbar*, const IntRect&)); | 30 MOCK_METHOD2(invalidateScrollbarRect, void(Scrollbar*, const IntRect&)); |
28 MOCK_METHOD1(invalidateScrollCornerRect, void(const IntRect&)); | 31 MOCK_METHOD1(invalidateScrollCornerRect, void(const IntRect&)); |
29 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); | 32 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); |
30 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); | 33 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); |
31 MOCK_CONST_METHOD0(contentsSize, IntSize()); | 34 MOCK_CONST_METHOD0(contentsSize, IntSize()); |
32 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); | 35 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); |
33 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); | 36 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); |
34 | 37 |
35 bool userInputScrollable(ScrollbarOrientation) const override { return true;
} | 38 bool userInputScrollable(ScrollbarOrientation) const override { return true;
} |
36 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } | 39 bool shouldPlaceVerticalScrollbarOnLeft() const override { return false; } |
37 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll
Position = offset.shrunkTo(m_maximumScrollPosition); } | 40 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll
Position = offset.shrunkTo(m_maximumScrollPosition); } |
38 IntPoint scrollPosition() const override { return m_scrollPosition; } | 41 IntPoint scrollPosition() const override { return m_scrollPosition; } |
39 IntPoint minimumScrollPosition() const override { return IntPoint(); } | 42 IntPoint minimumScrollPosition() const override { return IntPoint(); } |
40 IntPoint maximumScrollPosition() const override { return m_maximumScrollPosi
tion; } | 43 IntPoint maximumScrollPosition() const override { return m_maximumScrollPosi
tion; } |
41 int visibleHeight() const override { return 768; } | 44 int visibleHeight() const override { return 768; } |
42 int visibleWidth() const override { return 1024; } | 45 int visibleWidth() const override { return 1024; } |
43 bool scrollAnimatorEnabled() const override { return false; } | 46 bool scrollAnimatorEnabled() const override { return false; } |
44 int pageStep(ScrollbarOrientation) const override { return 0; } | 47 int pageStep(ScrollbarOrientation) const override { return 0; } |
45 | 48 |
| 49 DEFINE_INLINE_VIRTUAL_TRACE() |
| 50 { |
| 51 ScrollableArea::trace(visitor); |
| 52 } |
| 53 |
46 private: | 54 private: |
| 55 explicit MockScrollableArea(const IntPoint& maximumScrollPosition) |
| 56 : m_maximumScrollPosition(maximumScrollPosition) { } |
| 57 |
47 IntPoint m_scrollPosition; | 58 IntPoint m_scrollPosition; |
48 IntPoint m_maximumScrollPosition; | 59 IntPoint m_maximumScrollPosition; |
49 }; | 60 }; |
50 | 61 |
51 class FakeWebThread : public WebThread { | 62 class FakeWebThread : public WebThread { |
52 public: | 63 public: |
53 FakeWebThread() { } | 64 FakeWebThread() { } |
54 ~FakeWebThread() override { } | 65 ~FakeWebThread() override { } |
55 | 66 |
56 void postTask(const WebTraceLocation&, Task*) override | 67 void postTask(const WebTraceLocation&, Task*) override |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 Platform::initialize(m_oldPlatform); | 117 Platform::initialize(m_oldPlatform); |
107 } | 118 } |
108 | 119 |
109 private: | 120 private: |
110 FakePlatform m_fakePlatform; | 121 FakePlatform m_fakePlatform; |
111 Platform* m_oldPlatform; // Not owned. | 122 Platform* m_oldPlatform; // Not owned. |
112 }; | 123 }; |
113 | 124 |
114 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) | 125 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) |
115 { | 126 { |
116 MockScrollableArea scrollableArea(IntPoint(0, 100)); | 127 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = MockScrollableArea::
create(IntPoint(0, 100)); |
117 scrollableArea.setScrollPosition(IntPoint(0, 10000), CompositorScroll); | 128 scrollableArea->setScrollPosition(IntPoint(0, 10000), CompositorScroll); |
118 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y()); | 129 EXPECT_EQ(100.0, scrollableArea->scrollAnimator()->currentPosition().y()); |
119 } | 130 } |
120 | 131 |
121 } // namespace blink | 132 } // namespace blink |
OLD | NEW |