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 | 6 |
7 #include "platform/scroll/ScrollableArea.h" | 7 #include "platform/scroll/ScrollableArea.h" |
8 | 8 |
9 #include "platform/TestingPlatformSupport.h" | |
10 #include "public/platform/Platform.h" | |
11 #include "public/platform/WebScheduler.h" | |
12 #include "public/platform/WebThread.h" | |
13 #include <gmock/gmock.h> | 9 #include <gmock/gmock.h> |
14 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
15 | 11 |
16 using namespace blink; | 12 using namespace blink; |
17 | 13 |
18 namespace { | 14 namespace { |
19 | 15 |
20 class MockScrollableArea : public ScrollableArea { | 16 class MockScrollableArea : public ScrollableArea { |
21 public: | 17 public: |
22 MockScrollableArea(const IntPoint& maximumScrollPosition) | 18 MockScrollableArea(const IntPoint& maximumScrollPosition) |
(...skipping 21 matching lines...) Expand all Loading... |
44 virtual int visibleHeight() const override { return 768; } | 40 virtual int visibleHeight() const override { return 768; } |
45 virtual int visibleWidth() const override { return 1024; } | 41 virtual int visibleWidth() const override { return 1024; } |
46 virtual bool scrollAnimatorEnabled() const override { return false; } | 42 virtual bool scrollAnimatorEnabled() const override { return false; } |
47 virtual int pageStep(ScrollbarOrientation) const override { return 0; } | 43 virtual int pageStep(ScrollbarOrientation) const override { return 0; } |
48 | 44 |
49 private: | 45 private: |
50 IntPoint m_scrollPosition; | 46 IntPoint m_scrollPosition; |
51 IntPoint m_maximumScrollPosition; | 47 IntPoint m_maximumScrollPosition; |
52 }; | 48 }; |
53 | 49 |
54 class FakeWebThread : public WebThread { | 50 TEST(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) |
55 public: | |
56 FakeWebThread() { } | |
57 ~FakeWebThread() override { } | |
58 | |
59 void postTask(const WebTraceLocation&, Task*) override | |
60 { | |
61 ASSERT_NOT_REACHED(); | |
62 } | |
63 | |
64 void postDelayedTask(const WebTraceLocation&, Task*, long long) override | |
65 { | |
66 ASSERT_NOT_REACHED(); | |
67 } | |
68 | |
69 bool isCurrentThread() const override | |
70 { | |
71 ASSERT_NOT_REACHED(); | |
72 return true; | |
73 } | |
74 | |
75 WebScheduler* scheduler() const override | |
76 { | |
77 return nullptr; | |
78 } | |
79 }; | |
80 | |
81 // The FakePlatform is needed because ScrollAnimatorMac's constructor creates se
veral timers. | |
82 // We need just enough scaffolding for the Timer constructor to not segfault. | |
83 class FakePlatform : public TestingPlatformSupport { | |
84 public: | |
85 FakePlatform() : TestingPlatformSupport(TestingPlatformSupport::Config()) {
} | |
86 ~FakePlatform() override { } | |
87 | |
88 WebThread* currentThread() override | |
89 { | |
90 return &m_webThread; | |
91 } | |
92 | |
93 private: | |
94 FakeWebThread m_webThread; | |
95 }; | |
96 | |
97 class ScrollableAreaTest : public testing::Test { | |
98 public: | |
99 ScrollableAreaTest() : m_oldPlatform(nullptr) { } | |
100 | |
101 void SetUp() override | |
102 { | |
103 m_oldPlatform = Platform::current(); | |
104 Platform::initialize(&m_fakePlatform); | |
105 } | |
106 | |
107 void TearDown() override | |
108 { | |
109 Platform::initialize(m_oldPlatform); | |
110 } | |
111 | |
112 private: | |
113 FakePlatform m_fakePlatform; | |
114 Platform* m_oldPlatform; // Not owned. | |
115 }; | |
116 | |
117 TEST_F(ScrollableAreaTest, ScrollAnimatorCurrentPositionShouldBeSync) | |
118 { | 51 { |
119 MockScrollableArea scrollableArea(IntPoint(0, 100)); | 52 MockScrollableArea scrollableArea(IntPoint(0, 100)); |
120 scrollableArea.notifyScrollPositionChanged(IntPoint(0, 10000)); | 53 scrollableArea.notifyScrollPositionChanged(IntPoint(0, 10000)); |
121 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y()); | 54 EXPECT_EQ(100.0, scrollableArea.scrollAnimator()->currentPosition().y()); |
122 } | 55 } |
123 | 56 |
124 } // unnamed namespace | 57 } // unnamed namespace |
| 58 |
| 59 |
OLD | NEW |