OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2011, Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
abarth-chromium
2014/06/23 21:52:43
Please use new-style copyright blocks for new file
abarth-chromium
2014/06/23 21:52:43
Please use new-style copyright blocks for new file
| |
30 | |
31 #include "config.h" | |
32 | |
33 #include "platform/scroll/ScrollbarStateTransitionAnimator.h" | |
34 | |
35 #include "platform/Logging.h" | |
36 #include "platform/geometry/FloatPoint.h" | |
37 #include "platform/geometry/IntRect.h" | |
38 #include "platform/scroll/ScrollableArea.h" | |
39 #include "platform/scroll/ScrollbarThemeOverlayMock.h" | |
abarth-chromium
2014/06/23 21:52:43
If all the code you're testing is in blink_platfor
| |
40 #include <gmock/gmock.h> | |
41 #include <gtest/gtest.h> | |
42 | |
43 using namespace std; | |
44 using namespace WebCore; | |
45 | |
46 using testing::AtLeast; | |
47 using testing::Return; | |
48 using testing::_; | |
49 | |
50 class MockScrollbarStateTransitionAnimator; | |
51 class MockScrollableAreaForAnimator : public ScrollableArea { | |
52 public: | |
53 MockScrollableAreaForAnimator(bool enabled) | |
54 : m_scrollbarAnimatorEnabled(enabled) { } | |
55 void setAnimator(MockScrollbarStateTransitionAnimator* animator) | |
56 { | |
57 m_scrollbarStateTransitionAnimator = animator; | |
58 } | |
59 void setAnimatorEnabled(bool enabled) | |
60 { | |
61 m_scrollbarAnimatorEnabled = enabled; | |
62 } | |
63 virtual bool hasOverlayScrollbars() const OVERRIDE | |
64 { | |
65 return m_scrollbarAnimatorEnabled; | |
66 } | |
67 virtual bool scheduleAnimation() OVERRIDE | |
68 { | |
69 return true; | |
70 } | |
71 | |
72 MOCK_CONST_METHOD0(isActive, bool()); | |
73 MOCK_CONST_METHOD1(scrollSize, int(ScrollbarOrientation)); | |
74 MOCK_METHOD2(invalidateScrollbar, void(Scrollbar*, const IntRect&)); | |
75 MOCK_CONST_METHOD0(isScrollCornerVisible, bool()); | |
76 MOCK_CONST_METHOD0(scrollCornerRect, IntRect()); | |
77 MOCK_METHOD1(setScrollOffset, void(const IntPoint&)); | |
78 MOCK_METHOD2(invalidateScrollbarRect, void(Scrollbar*, const IntRect&)); | |
79 MOCK_METHOD1(invalidateScrollCornerRect, void(const IntRect&)); | |
80 MOCK_METHOD1(setScrollOffsetFromAnimation, void(const IntPoint&)); | |
81 MOCK_CONST_METHOD0(enclosingScrollableArea, ScrollableArea*()); | |
82 MOCK_CONST_METHOD0(minimumScrollPosition, IntPoint()); | |
83 MOCK_CONST_METHOD0(maximumScrollPosition, IntPoint()); | |
84 MOCK_CONST_METHOD1(visibleContentRect, IntRect(IncludeScrollbarsInRect)); | |
85 MOCK_CONST_METHOD0(contentsSize, IntSize()); | |
86 MOCK_CONST_METHOD0(overhangAmount, IntSize()); | |
87 MOCK_CONST_METHOD0(scrollbarsCanBeActive, bool()); | |
88 MOCK_CONST_METHOD0(scrollableAreaBoundingBox, IntRect()); | |
89 MOCK_CONST_METHOD0(scrollPosition, IntPoint()); | |
90 MOCK_CONST_METHOD0(shouldPlaceVerticalScrollbarOnLeft, bool()); | |
91 MOCK_CONST_METHOD1(userInputScrollable, bool(ScrollbarOrientation)); | |
92 MOCK_CONST_METHOD0(visibleHeight, int()); | |
93 MOCK_CONST_METHOD0(visibleWidth, int()); | |
94 | |
95 private: | |
96 MockScrollbarStateTransitionAnimator* m_scrollbarStateTransitionAnimator; | |
97 bool m_scrollbarAnimatorEnabled; | |
98 }; | |
99 | |
100 class MockScrollbarStateTransitionAnimator : public ScrollbarStateTransitionAnim ator { | |
101 public: | |
102 MockScrollbarStateTransitionAnimator(MockScrollableAreaForAnimator* scrollab leArea) | |
103 : ScrollbarStateTransitionAnimator(scrollableArea) { } | |
104 | |
105 void reset() | |
106 { | |
107 m_data.reset(); | |
108 m_mockCurrentTime = 0; | |
109 stopAnimationTimerIfNeeded(); | |
110 } | |
111 | |
112 void setCurrentTime(double time) | |
113 { | |
114 m_mockCurrentTime = time; | |
115 } | |
116 virtual double currentTime() const OVERRIDE | |
117 { | |
118 return m_mockCurrentTime; | |
119 } | |
120 | |
121 private: | |
122 double m_mockCurrentTime; | |
123 }; | |
124 | |
125 TEST(ScrollbarStateTransitionAnimatorEnabled, Enabled) | |
126 { | |
127 MockScrollableAreaForAnimator scrollableArea(true); | |
128 MockScrollbarStateTransitionAnimator scrollbarAnimator(&scrollableArea); | |
129 scrollableArea.setAnimator(&scrollbarAnimator); | |
130 | |
131 scrollbarAnimator.reset(); | |
132 scrollbarAnimator.setCurrentTime(1.0); | |
133 scrollbarAnimator.mouseEnteredScrollbar(0); | |
134 scrollbarAnimator.setCurrentTime(1.1); | |
135 scrollbarAnimator.serviceAnimations(); | |
136 EXPECT_TRUE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
137 EXPECT_NE(0.f, scrollbarAnimator.stateTransitionProgress()); | |
138 EXPECT_EQ(blink::WebThemeEngine::StateNormal, scrollbarAnimator.stateTransit ionStartState()); | |
139 EXPECT_EQ(blink::WebThemeEngine::StateHover, scrollbarAnimator.stateTransiti onEndState()); | |
140 scrollbarAnimator.setCurrentTime(2.0); | |
141 scrollbarAnimator.serviceAnimations(); | |
142 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
143 scrollbarAnimator.reset(); | |
144 scrollbarAnimator.setCurrentTime(1.0); | |
145 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
146 scrollbarAnimator.mouseExitedScrollbar(0); | |
147 scrollbarAnimator.setCurrentTime(1.1); | |
148 scrollbarAnimator.serviceAnimations(); | |
149 EXPECT_TRUE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
150 EXPECT_NE(0.f, scrollbarAnimator.stateTransitionProgress()); | |
151 EXPECT_EQ(blink::WebThemeEngine::StateHover, scrollbarAnimator.stateTransiti onStartState()); | |
152 EXPECT_EQ(blink::WebThemeEngine::StateNormal, scrollbarAnimator.stateTransit ionEndState()); | |
153 scrollbarAnimator.setCurrentTime(2.0); | |
154 scrollbarAnimator.serviceAnimations(); | |
155 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
156 scrollbarAnimator.reset(); | |
157 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
158 } | |
159 | |
160 TEST(ScrollbarStateTransitionAnimatorEnabled, Disabled) | |
161 { | |
162 MockScrollableAreaForAnimator scrollableArea(false); | |
163 MockScrollbarStateTransitionAnimator scrollbarAnimator(&scrollableArea); | |
164 scrollableArea.setAnimator(&scrollbarAnimator); | |
165 | |
166 scrollbarAnimator.reset(); | |
167 scrollbarAnimator.setCurrentTime(1.0); | |
168 scrollbarAnimator.mouseEnteredScrollbar(0); | |
169 scrollbarAnimator.setCurrentTime(1.1); | |
170 scrollbarAnimator.serviceAnimations(); | |
171 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
172 EXPECT_EQ(0.f, scrollbarAnimator.stateTransitionProgress()); | |
173 EXPECT_NE(blink::WebThemeEngine::StateNormal, scrollbarAnimator.stateTransit ionStartState()); | |
174 EXPECT_NE(blink::WebThemeEngine::StateHover, scrollbarAnimator.stateTransiti onEndState()); | |
175 scrollbarAnimator.setCurrentTime(2.0); | |
176 scrollbarAnimator.serviceAnimations(); | |
177 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
178 scrollbarAnimator.reset(); | |
179 scrollbarAnimator.setCurrentTime(1.0); | |
180 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
181 scrollbarAnimator.mouseExitedScrollbar(0); | |
182 scrollbarAnimator.setCurrentTime(1.1); | |
183 scrollbarAnimator.serviceAnimations(); | |
184 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
185 EXPECT_EQ(0.f, scrollbarAnimator.stateTransitionProgress()); | |
186 EXPECT_NE(blink::WebThemeEngine::StateHover, scrollbarAnimator.stateTransiti onStartState()); | |
187 EXPECT_NE(blink::WebThemeEngine::StateNormal, scrollbarAnimator.stateTransit ionEndState()); | |
188 scrollbarAnimator.setCurrentTime(2.0); | |
189 scrollbarAnimator.serviceAnimations(); | |
190 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
191 scrollbarAnimator.reset(); | |
192 EXPECT_FALSE(scrollbarAnimator.isDuringStateTransitionAnimation()); | |
193 } | |
OLD | NEW |