Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: cc/input/scrollbar_animation_controller_thinning_unittest.cc

Issue 2554913002: Prevent overlay scrollbars expand or hover together (Closed)
Patch Set: fix for fade in/out together Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/input/scrollbar_animation_controller_thinning.h" 5 #include "cc/input/scrollbar_animation_controller_thinning.h"
6 6
7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h"
8 #include "cc/test/fake_impl_task_runner_provider.h" 8 #include "cc/test/fake_impl_task_runner_provider.h"
9 #include "cc/test/fake_layer_tree_host_impl.h" 9 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "cc/test/geometry_test_utils.h" 10 #include "cc/test/geometry_test_utils.h"
11 #include "cc/test/test_task_graph_runner.h" 11 #include "cc/test/test_task_graph_runner.h"
12 #include "cc/trees/layer_tree_impl.h" 12 #include "cc/trees/layer_tree_impl.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using testing::AtLeast; 16 using testing::AtLeast;
17 using testing::Mock; 17 using testing::Mock;
18 using testing::NiceMock; 18 using testing::NiceMock;
19 using testing::_; 19 using testing::_;
20 20
21 namespace cc { 21 namespace cc {
22 namespace { 22 namespace {
23 23
24 // These constants are hard-coded and should match the values in 24 // These constants are hard-coded and should match the values in
25 // scrollbar_animation_controller_thinning.cc. 25 // scrollbar_animation_controller_thinning.cc.
26 const float kIdleThicknessScale = 0.4f; 26 const float kIdleThicknessScale = 0.4f;
27 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f;
28 27
29 class MockScrollbarAnimationControllerClient 28 class MockScrollbarAnimationControllerClient
30 : public ScrollbarAnimationControllerClient { 29 : public ScrollbarAnimationControllerClient {
31 public: 30 public:
32 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) 31 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl)
33 : host_impl_(host_impl) {} 32 : host_impl_(host_impl) {}
34 virtual ~MockScrollbarAnimationControllerClient() {} 33 virtual ~MockScrollbarAnimationControllerClient() {}
35 34
36 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, 35 void PostDelayedScrollbarAnimationTask(const base::Closure&,
37 base::TimeDelta delay) override { 36 base::TimeDelta) override {}
38 start_fade_ = start_fade;
39 delay_ = delay;
40 }
41 void SetNeedsRedrawForScrollbarAnimation() override {} 37 void SetNeedsRedrawForScrollbarAnimation() override {}
42 void SetNeedsAnimateForScrollbarAnimation() override {} 38 void SetNeedsAnimateForScrollbarAnimation() override {}
43 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { 39 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override {
44 return host_impl_->ScrollbarsFor(scroll_layer_id); 40 return host_impl_->ScrollbarsFor(scroll_layer_id);
45 } 41 }
46 MOCK_METHOD0(DidChangeScrollbarVisibility, void()); 42 MOCK_METHOD0(DidChangeScrollbarVisibility, void());
47 43
48 base::Closure& start_fade() { return start_fade_; }
49 base::TimeDelta& delay() { return delay_; }
50
51 private: 44 private:
52 base::Closure start_fade_;
53 base::TimeDelta delay_;
54 LayerTreeHostImpl* host_impl_; 45 LayerTreeHostImpl* host_impl_;
55 }; 46 };
56 47
57 class ScrollbarAnimationControllerThinningTest : public testing::Test { 48 class ScrollbarAnimationControllerThinningTest : public testing::Test {
58 public: 49 public:
59 ScrollbarAnimationControllerThinningTest() 50 ScrollbarAnimationControllerThinningTest()
60 : host_impl_(&task_runner_provider_, &task_graph_runner_), 51 : host_impl_(&task_runner_provider_, &task_graph_runner_),
61 client_(&host_impl_) {} 52 client_(&host_impl_) {}
62 53
63 protected: 54 protected:
64 const base::TimeDelta kDelayBeforeStarting = base::TimeDelta::FromSeconds(2); 55 const base::TimeDelta kDelayBeforeStarting = base::TimeDelta::FromSeconds(2);
65 const base::TimeDelta kResizeDelayBeforeStarting = 56 const base::TimeDelta kResizeDelayBeforeStarting =
66 base::TimeDelta::FromSeconds(5); 57 base::TimeDelta::FromSeconds(5);
67 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3); 58 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3);
68 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); 59 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2);
69 60
70 void SetUp() override { 61 void SetUp() override {
71 std::unique_ptr<LayerImpl> scroll_layer = 62 std::unique_ptr<LayerImpl> scroll_layer =
72 LayerImpl::Create(host_impl_.active_tree(), 1); 63 LayerImpl::Create(host_impl_.active_tree(), 1);
73 std::unique_ptr<LayerImpl> clip = 64 std::unique_ptr<LayerImpl> clip =
74 LayerImpl::Create(host_impl_.active_tree(), 3); 65 LayerImpl::Create(host_impl_.active_tree(), 2);
75 clip_layer_ = clip.get(); 66 clip_layer_ = clip.get();
76 scroll_layer->SetScrollClipLayer(clip_layer_->id()); 67 scroll_layer->SetScrollClipLayer(clip_layer_->id());
77 LayerImpl* scroll_layer_ptr = scroll_layer.get(); 68 LayerImpl* scroll_layer_ptr = scroll_layer.get();
78 69
79 const int kId = 2;
80 const int kThumbThickness = 10; 70 const int kThumbThickness = 10;
81 const int kTrackStart = 0; 71 const int kTrackStart = 0;
82 const bool kIsLeftSideVerticalScrollbar = false; 72 const bool kIsLeftSideVerticalScrollbar = false;
83 const bool kIsOverlayScrollbar = true; 73 const bool kIsOverlayScrollbar = true;
84 74
85 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 75 std::unique_ptr<SolidColorScrollbarLayerImpl> h_scrollbar =
86 SolidColorScrollbarLayerImpl::Create( 76 SolidColorScrollbarLayerImpl::Create(
87 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, 77 host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness,
88 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); 78 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
89 scrollbar_layer_ = scrollbar.get(); 79 std::unique_ptr<SolidColorScrollbarLayerImpl> v_scrollbar =
80 SolidColorScrollbarLayerImpl::Create(
81 host_impl_.active_tree(), 4, VERTICAL, kThumbThickness, kTrackStart,
82 kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
83 v_scrollbar_layer_ = v_scrollbar.get();
84 h_scrollbar_layer_ = h_scrollbar.get();
90 85
91 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); 86 scroll_layer->test_properties()->AddChild(std::move(v_scrollbar));
87 scroll_layer->test_properties()->AddChild(std::move(h_scrollbar));
92 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); 88 clip_layer_->test_properties()->AddChild(std::move(scroll_layer));
93 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); 89 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip));
94 90
95 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); 91 v_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
96 scrollbar_layer_->test_properties()->opacity_can_animate = true; 92 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
93 v_scrollbar_layer_->test_properties()->opacity_can_animate = true;
94 h_scrollbar_layer_->test_properties()->opacity_can_animate = true;
97 clip_layer_->SetBounds(gfx::Size(100, 100)); 95 clip_layer_->SetBounds(gfx::Size(100, 100));
98 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); 96 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
99 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); 97 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
100 98
101 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( 99 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create(
102 scroll_layer_ptr->id(), &client_, kDelayBeforeStarting, 100 scroll_layer_ptr->id(), &client_, kDelayBeforeStarting,
103 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration); 101 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration);
104 } 102 }
105 103
106 FakeImplTaskRunnerProvider task_runner_provider_; 104 FakeImplTaskRunnerProvider task_runner_provider_;
107 TestTaskGraphRunner task_graph_runner_; 105 TestTaskGraphRunner task_graph_runner_;
108 FakeLayerTreeHostImpl host_impl_; 106 FakeLayerTreeHostImpl host_impl_;
109 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; 107 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_;
110 LayerImpl* clip_layer_; 108 LayerImpl* clip_layer_;
111 SolidColorScrollbarLayerImpl* scrollbar_layer_; 109 SolidColorScrollbarLayerImpl* v_scrollbar_layer_;
110 SolidColorScrollbarLayerImpl* h_scrollbar_layer_;
112 NiceMock<MockScrollbarAnimationControllerClient> client_; 111 NiceMock<MockScrollbarAnimationControllerClient> client_;
113 }; 112 };
114 113
115 // Check initialization of scrollbar. Should start off invisible and thin. 114 // Check initialization of scrollbars. Should start off invisible and thin.
116 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { 115 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) {
117 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); 116 EXPECT_FLOAT_EQ(0.0f, v_scrollbar_layer_->Opacity());
118 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 117 EXPECT_FLOAT_EQ(kIdleThicknessScale,
118 v_scrollbar_layer_->thumb_thickness_scale_factor());
119 EXPECT_FLOAT_EQ(0.0f, h_scrollbar_layer_->Opacity());
120 EXPECT_FLOAT_EQ(kIdleThicknessScale,
121 h_scrollbar_layer_->thumb_thickness_scale_factor());
119 } 122 }
120 123
121 // Check that scrollbar appears again when the layer becomes scrollable. 124 // Scroll content. Move the mouse near the scrollbar and confirm it becomes
122 TEST_F(ScrollbarAnimationControllerThinningTest, AppearOnResize) { 125 // thick.
123 scrollbar_controller_->DidScrollBegin(); 126 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNear) {
124 scrollbar_controller_->DidScrollUpdate(false);
125 scrollbar_controller_->DidScrollEnd();
126 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
127
128 // Make the Layer non-scrollable, scrollbar disappears.
129 clip_layer_->SetBounds(gfx::Size(200, 200));
130 scrollbar_controller_->DidScrollUpdate(false);
131 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
132
133 // Make the layer scrollable, scrollbar appears again.
134 clip_layer_->SetBounds(gfx::Size(100, 100));
135 scrollbar_controller_->DidScrollUpdate(false);
136 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
137 }
138
139 // Check that scrollbar disappears when the layer becomes non-scrollable.
140 TEST_F(ScrollbarAnimationControllerThinningTest, HideOnResize) {
141 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
142 ASSERT_TRUE(scroll_layer);
143 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds());
144
145 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());
146
147 // Shrink along X axis, horizontal scrollbar should appear.
148 clip_layer_->SetBounds(gfx::Size(100, 200));
149 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds());
150
151 scrollbar_controller_->DidScrollBegin();
152
153 scrollbar_controller_->DidScrollUpdate(false);
154 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
155
156 scrollbar_controller_->DidScrollEnd();
157
158 // Shrink along Y axis and expand along X, horizontal scrollbar
159 // should disappear.
160 clip_layer_->SetBounds(gfx::Size(200, 100));
161 EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds());
162
163 scrollbar_controller_->DidScrollBegin();
164
165 scrollbar_controller_->DidScrollUpdate(false);
166 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
167
168 scrollbar_controller_->DidScrollEnd();
169 }
170
171 // Scroll content. Confirm the scrollbar appears and fades out.
172 TEST_F(ScrollbarAnimationControllerThinningTest, BasicAppearAndFadeOut) {
173 base::TimeTicks time; 127 base::TimeTicks time;
174 time += base::TimeDelta::FromSeconds(1); 128 time += base::TimeDelta::FromSeconds(1);
175 129
176 // Scrollbar should be invisible by default.
177 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
178
179 // Scrollbar should appear only on scroll update.
180 scrollbar_controller_->DidScrollBegin();
181 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
182
183 scrollbar_controller_->DidScrollUpdate(false);
184 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
185
186 scrollbar_controller_->DidScrollEnd();
187 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
188
189 // An animation should have been enqueued.
190 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
191 EXPECT_FALSE(client_.start_fade().is_null());
192 client_.start_fade().Run();
193
194 // Scrollbar should fade out over kFadeDuration.
195 scrollbar_controller_->Animate(time);
196 time += kFadeDuration;
197 scrollbar_controller_->Animate(time);
198
199 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
200 }
201
202 // Scroll content. Move the mouse near the scrollbar and confirm it becomes
203 // thick. Ensure it remains visible as long as the mouse is near the scrollbar.
204 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndDontFadeOut) {
205 base::TimeTicks time;
206 time += base::TimeDelta::FromSeconds(1);
207
208 scrollbar_controller_->DidScrollBegin(); 130 scrollbar_controller_->DidScrollBegin();
209 scrollbar_controller_->DidScrollUpdate(false); 131 scrollbar_controller_->DidScrollUpdate(false);
210 scrollbar_controller_->DidScrollEnd(); 132 scrollbar_controller_->DidScrollEnd();
211 133
212 // An animation should have been enqueued. 134 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->Opacity());
213 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); 135 EXPECT_FLOAT_EQ(1.0f, h_scrollbar_layer_->Opacity());
214 EXPECT_FALSE(client_.start_fade().is_null());
215 EXPECT_FALSE(client_.start_fade().IsCancelled());
216 136
217 // Now move the mouse near the scrollbar. This should cancel the currently 137 // Now move the mouse near the v scrollbar. This should start animating
218 // queued fading animation and start animating thickness. 138 // thickness.
219 scrollbar_controller_->DidMouseMoveNear(1); 139 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
220 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
221 EXPECT_FLOAT_EQ(kIdleThicknessScale, 140 EXPECT_FLOAT_EQ(kIdleThicknessScale,
222 scrollbar_layer_->thumb_thickness_scale_factor()); 141 v_scrollbar_layer_->thumb_thickness_scale_factor());
223 EXPECT_TRUE(client_.start_fade().IsCancelled());
224 142
225 // Scrollbar should become thick. 143 // Scrollbar should become thick.
226 scrollbar_controller_->Animate(time); 144 scrollbar_controller_->Animate(time);
227 time += kThinningDuration; 145 time += kThinningDuration;
228 scrollbar_controller_->Animate(time); 146 scrollbar_controller_->Animate(time);
229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); 147 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->Opacity());
230 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 148 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->thumb_thickness_scale_factor());
231 149
232 // Mouse is still near the Scrollbar. Once the thickness animation is 150 // move the mouse near the h scrollbar. This should start animating thickness.
233 // complete, the queued delayed fade animation should be either cancelled or 151 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1);
234 // null. 152 EXPECT_FLOAT_EQ(kIdleThicknessScale,
235 EXPECT_TRUE(client_.start_fade().is_null() || 153 h_scrollbar_layer_->thumb_thickness_scale_factor());
236 client_.start_fade().IsCancelled()); 154
155 // Scrollbar should become thick.
156 scrollbar_controller_->Animate(time);
157 time += kThinningDuration;
158 scrollbar_controller_->Animate(time);
159 EXPECT_FLOAT_EQ(1.0f, h_scrollbar_layer_->Opacity());
160 EXPECT_FLOAT_EQ(1.0f, h_scrollbar_layer_->thumb_thickness_scale_factor());
237 } 161 }
238 162
239 // Scroll content. Move the mouse over the scrollbar and confirm it becomes 163 // Scroll content. Move the mouse over the scrollbar and confirm it becomes
240 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. 164 // thick.
241 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndDontFadeOut) { 165 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOver) {
242 base::TimeTicks time; 166 base::TimeTicks time;
243 time += base::TimeDelta::FromSeconds(1); 167 time += base::TimeDelta::FromSeconds(1);
244 168
245 scrollbar_controller_->DidScrollBegin(); 169 scrollbar_controller_->DidScrollBegin();
246 scrollbar_controller_->DidScrollUpdate(false); 170 scrollbar_controller_->DidScrollUpdate(false);
247 scrollbar_controller_->DidScrollEnd(); 171 scrollbar_controller_->DidScrollEnd();
248 172
249 // An animation should have been enqueued. 173 // Now move the mouse over the v scrollbar.
250 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); 174 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
251 EXPECT_FALSE(client_.start_fade().is_null()); 175 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 100);
252 EXPECT_FALSE(client_.start_fade().IsCancelled()); 176 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->Opacity());
253
254 // Now move the mouse over the scrollbar. This should cancel the currently
255 // queued fading animation and start animating thickness.
256 scrollbar_controller_->DidMouseMoveNear(0);
257 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
258 EXPECT_FLOAT_EQ(kIdleThicknessScale, 177 EXPECT_FLOAT_EQ(kIdleThicknessScale,
259 scrollbar_layer_->thumb_thickness_scale_factor()); 178 v_scrollbar_layer_->thumb_thickness_scale_factor());
260 EXPECT_TRUE(client_.start_fade().IsCancelled()); 179 EXPECT_FLOAT_EQ(1.0f, h_scrollbar_layer_->Opacity());
180 EXPECT_FLOAT_EQ(kIdleThicknessScale,
181 h_scrollbar_layer_->thumb_thickness_scale_factor());
261 182
262 // Scrollbar should become thick. 183 // Scrollbar should become thick.
263 scrollbar_controller_->Animate(time); 184 scrollbar_controller_->Animate(time);
264 time += kThinningDuration; 185 time += kThinningDuration;
265 scrollbar_controller_->Animate(time); 186 scrollbar_controller_->Animate(time);
266 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); 187 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->Opacity());
267 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 188 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->thumb_thickness_scale_factor());
189 EXPECT_FLOAT_EQ(1.0f, h_scrollbar_layer_->Opacity());
190 EXPECT_FLOAT_EQ(kIdleThicknessScale,
191 h_scrollbar_layer_->thumb_thickness_scale_factor());
268 192
269 // Mouse is still over the Scrollbar. Once the thickness animation is 193 // Now move the mouse over the h scrollbar.
270 // complete, the queued delayed fade animation should be either null or 194 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 100);
271 // cancelled. 195 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0);
272 EXPECT_TRUE(client_.start_fade().is_null() ||
273 client_.start_fade().IsCancelled());
274 }
275 196
276 // Make sure a scrollbar captured before the thickening animation doesn't try 197 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->Opacity());
277 // to fade out. 198 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->thumb_thickness_scale_factor());
278 TEST_F(ScrollbarAnimationControllerThinningTest, 199 EXPECT_FLOAT_EQ(1.0f, h_scrollbar_layer_->Opacity());
279 DontFadeWhileCapturedBeforeThick) { 200 EXPECT_FLOAT_EQ(kIdleThicknessScale,
280 base::TimeTicks time; 201 h_scrollbar_layer_->thumb_thickness_scale_factor());
281 time += base::TimeDelta::FromSeconds(1);
282 202
283 scrollbar_controller_->DidScrollBegin(); 203 // Scrollbar should become thick.
284 scrollbar_controller_->DidScrollUpdate(false);
285 scrollbar_controller_->DidScrollEnd();
286
287 // An animation should have been enqueued.
288 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
289 EXPECT_FALSE(client_.start_fade().is_null());
290
291 // Now move the mouse over the scrollbar and capture it. It should become
292 // thick without need for an animation.
293 scrollbar_controller_->DidMouseMoveNear(0);
294 scrollbar_controller_->DidMouseDown();
295 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
296 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
297
298 // The fade animation should have been cleared or cancelled.
299 EXPECT_TRUE(client_.start_fade().is_null() ||
300 client_.start_fade().IsCancelled());
301 }
302
303 // Make sure a scrollbar captured after a thickening animation doesn't try to
304 // fade out.
305 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) {
306 base::TimeTicks time;
307 time += base::TimeDelta::FromSeconds(1);
308
309 scrollbar_controller_->DidScrollBegin();
310 scrollbar_controller_->DidScrollUpdate(false);
311 scrollbar_controller_->DidScrollEnd();
312
313 // An animation should have been enqueued.
314 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
315 EXPECT_FALSE(client_.start_fade().is_null());
316 EXPECT_FALSE(client_.start_fade().IsCancelled());
317
318 // Now move the mouse over the scrollbar and animate it until it's thick.
319 scrollbar_controller_->DidMouseMoveNear(0);
320 scrollbar_controller_->Animate(time); 204 scrollbar_controller_->Animate(time);
321 time += kThinningDuration; 205 time += kThinningDuration;
322 scrollbar_controller_->Animate(time); 206 scrollbar_controller_->Animate(time);
323 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); 207 EXPECT_FLOAT_EQ(1.0f, v_scrollbar_layer_->Opacity());
324 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
325
326 // Since the mouse is over the scrollbar, it should either clear or cancel the
327 // queued fade.
328 EXPECT_TRUE(client_.start_fade().is_null() ||
329 client_.start_fade().IsCancelled());
330
331 // Make sure the queued fade animation is still null or cancelled after
332 // capturing the scrollbar.
333 scrollbar_controller_->DidMouseDown();
334 EXPECT_TRUE(client_.start_fade().is_null() ||
335 client_.start_fade().IsCancelled());
336 }
337
338 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes
339 // the scrollbar to fade out.
340 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleasedFar) {
341 base::TimeTicks time;
342 time += base::TimeDelta::FromSeconds(1);
343
344 scrollbar_controller_->DidScrollBegin();
345 scrollbar_controller_->DidScrollUpdate(false);
346 scrollbar_controller_->DidScrollEnd();
347
348 // An animation should have been enqueued.
349 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
350 EXPECT_FALSE(client_.start_fade().is_null());
351 EXPECT_FALSE(client_.start_fade().IsCancelled());
352
353 // Now move the mouse over the scrollbar and capture it.
354 scrollbar_controller_->DidMouseMoveNear(0);
355 scrollbar_controller_->DidMouseDown();
356 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
357 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
358
359 // Since the mouse is still near the scrollbar, the queued fade should be
360 // either null or cancelled.
361 EXPECT_TRUE(client_.start_fade().is_null() ||
362 client_.start_fade().IsCancelled());
363
364 // Now move the mouse away from the scrollbar and release it.
365 scrollbar_controller_->DidMouseMoveNear(
366 kDefaultMouseMoveDistanceToTriggerAnimation + 1);
367 scrollbar_controller_->DidMouseUp();
368
369 scrollbar_controller_->Animate(time);
370 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
371 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
372 time += kThinningDuration;
373 scrollbar_controller_->Animate(time);
374 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
375 EXPECT_FLOAT_EQ(kIdleThicknessScale, 208 EXPECT_FLOAT_EQ(kIdleThicknessScale,
376 scrollbar_layer_->thumb_thickness_scale_factor()); 209 v_scrollbar_layer_->thumb_thickness_scale_factor());
377 210 EXPECT_FLOAT_EQ(1.0f, h_scrollbar_layer_->Opacity());
378 // The thickness animation is complete, a fade out must be queued. 211 EXPECT_FLOAT_EQ(1.0f, h_scrollbar_layer_->thumb_thickness_scale_factor());
379 EXPECT_FALSE(client_.start_fade().is_null());
380 EXPECT_FALSE(client_.start_fade().IsCancelled());
381 }
382
383 // Make sure releasing a captured scrollbar when the mouse is near/over it,
384 // doesn't cause the scrollbar to fade out.
385 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeAfterReleasedNear) {
386 base::TimeTicks time;
387 time += base::TimeDelta::FromSeconds(1);
388
389 scrollbar_controller_->DidScrollBegin();
390 scrollbar_controller_->DidScrollUpdate(false);
391 scrollbar_controller_->DidScrollEnd();
392
393 // An animation should have been enqueued.
394 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
395 EXPECT_FALSE(client_.start_fade().is_null());
396 EXPECT_FALSE(client_.start_fade().IsCancelled());
397
398 // Now move the mouse over the scrollbar and capture it.
399 scrollbar_controller_->DidMouseMoveNear(0);
400 scrollbar_controller_->DidMouseDown();
401 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
402 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
403
404 // Since the mouse is over the scrollbar, the queued fade must be either
405 // null or cancelled.
406 EXPECT_TRUE(client_.start_fade().is_null() ||
407 client_.start_fade().IsCancelled());
408
409 // Mouse is still near the scrollbar, releasing it shouldn't do anything.
410 scrollbar_controller_->DidMouseUp();
411 EXPECT_TRUE(client_.start_fade().is_null() ||
412 client_.start_fade().IsCancelled());
413 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
414 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
415 }
416
417 // Make sure moving near a scrollbar while it's fading out causes it to reset
418 // the opacity and thicken.
419 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) {
420 base::TimeTicks time;
421 time += base::TimeDelta::FromSeconds(1);
422
423 scrollbar_controller_->DidScrollBegin();
424 scrollbar_controller_->DidScrollUpdate(false);
425 scrollbar_controller_->DidScrollEnd();
426
427 // A fade animation should have been enqueued. Start it.
428 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
429 EXPECT_FALSE(client_.start_fade().is_null());
430 client_.start_fade().Run();
431
432 scrollbar_controller_->Animate(time);
433 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
434
435 // Proceed half way through the fade out animation.
436 time += kFadeDuration / 2;
437 scrollbar_controller_->Animate(time);
438 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity());
439
440 // Now move the mouse near the scrollbar. It should reset opacity to 1
441 // instantly and start animating to thick.
442 scrollbar_controller_->DidMouseMoveNear(1);
443 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
444 EXPECT_FLOAT_EQ(kIdleThicknessScale,
445 scrollbar_layer_->thumb_thickness_scale_factor());
446
447 scrollbar_controller_->Animate(time);
448 time += kThinningDuration;
449 scrollbar_controller_->Animate(time);
450 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
451 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
452 }
453
454 // Make sure we can't capture scrollbar that's completely faded out.
455 TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) {
456 base::TimeTicks time;
457 time += base::TimeDelta::FromSeconds(1);
458
459 scrollbar_controller_->DidScrollBegin();
460 scrollbar_controller_->DidScrollUpdate(false);
461 scrollbar_controller_->DidScrollEnd();
462
463 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
464 EXPECT_FALSE(client_.start_fade().is_null());
465 EXPECT_FALSE(client_.start_fade().IsCancelled());
466 client_.start_fade().Run();
467 scrollbar_controller_->Animate(time);
468 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
469
470 // Fade the scrollbar out completely.
471 time += kFadeDuration;
472 scrollbar_controller_->Animate(time);
473 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
474
475 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since
476 // it's completely faded out.
477 scrollbar_controller_->DidMouseMoveNear(0);
478 scrollbar_controller_->Animate(time);
479 time += kThinningDuration;
480 scrollbar_controller_->Animate(time);
481 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
482 EXPECT_FLOAT_EQ(kIdleThicknessScale,
483 scrollbar_layer_->thumb_thickness_scale_factor());
484
485 client_.start_fade().Reset();
486
487 // Now try to capture the scrollbar. It shouldn't do anything since it's
488 // completely faded out.
489 scrollbar_controller_->DidMouseDown();
490 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
491 EXPECT_FLOAT_EQ(kIdleThicknessScale,
492 scrollbar_layer_->thumb_thickness_scale_factor());
493 EXPECT_TRUE(client_.start_fade().is_null());
494
495 // Similarly, releasing the scrollbar should have no effect.
496 scrollbar_controller_->DidMouseUp();
497 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
498 EXPECT_FLOAT_EQ(kIdleThicknessScale,
499 scrollbar_layer_->thumb_thickness_scale_factor());
500 EXPECT_TRUE(client_.start_fade().is_null());
501 }
502
503 // Initiate a scroll when the pointer is already near the scrollbar. It should
504 // appear thick and remain thick.
505 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) {
506 base::TimeTicks time;
507 time += base::TimeDelta::FromSeconds(1);
508
509 scrollbar_controller_->DidMouseMoveNear(1);
510 scrollbar_controller_->Animate(time);
511 time += kThinningDuration;
512
513 // Since the scrollbar isn't visible yet (because we haven't scrolled), we
514 // shouldn't have applied the thickening.
515 scrollbar_controller_->Animate(time);
516 EXPECT_FLOAT_EQ(kIdleThicknessScale,
517 scrollbar_layer_->thumb_thickness_scale_factor());
518
519 scrollbar_controller_->DidScrollBegin();
520 scrollbar_controller_->DidScrollUpdate(false);
521
522 // Now that we've received a scroll, we should be thick without an animation.
523 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
524
525 // An animation for the fade should be either null or cancelled, since
526 // mouse is still near the scrollbar.
527 scrollbar_controller_->DidScrollEnd();
528 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
529 EXPECT_TRUE(client_.start_fade().is_null() ||
530 client_.start_fade().IsCancelled());
531
532 scrollbar_controller_->Animate(time);
533 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
534 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
535
536 // Scrollbar should still be thick and visible.
537 time += kFadeDuration;
538 scrollbar_controller_->Animate(time);
539 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
540 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
541 }
542
543 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when
544 // moved away.
545 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) {
546 base::TimeTicks time;
547 time += base::TimeDelta::FromSeconds(1);
548
549 // Scroll to make the scrollbars visible.
550 scrollbar_controller_->DidScrollBegin();
551 scrollbar_controller_->DidScrollUpdate(false);
552 scrollbar_controller_->DidScrollEnd();
553
554 scrollbar_controller_->DidMouseMoveNear(1);
555 scrollbar_controller_->Animate(time);
556 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
557 EXPECT_FLOAT_EQ(kIdleThicknessScale,
558 scrollbar_layer_->thumb_thickness_scale_factor());
559
560 // Should animate to thickened.
561 time += kThinningDuration;
562 scrollbar_controller_->Animate(time);
563 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
564 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
565
566 // Subsequent moves within the nearness threshold should not change anything.
567 scrollbar_controller_->DidMouseMoveNear(2);
568 scrollbar_controller_->Animate(time);
569 time += base::TimeDelta::FromSeconds(10);
570 scrollbar_controller_->Animate(time);
571 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
572 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
573
574 // Now move away from bar.
575 scrollbar_controller_->DidMouseMoveNear(
576 kDefaultMouseMoveDistanceToTriggerAnimation);
577 scrollbar_controller_->Animate(time);
578 time += kThinningDuration;
579 scrollbar_controller_->Animate(time);
580 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
581 EXPECT_FLOAT_EQ(kIdleThicknessScale,
582 scrollbar_layer_->thumb_thickness_scale_factor());
583 }
584
585 // Move the pointer over the scrollbar. Make sure it gets thick that it gets
586 // thin when moved away.
587 TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) {
588 // Scroll to make the scrollbars visible.
589 scrollbar_controller_->DidScrollBegin();
590 scrollbar_controller_->DidScrollUpdate(false);
591 scrollbar_controller_->DidScrollEnd();
592
593 base::TimeTicks time;
594 time += base::TimeDelta::FromSeconds(1);
595
596 scrollbar_controller_->DidMouseMoveNear(0);
597 scrollbar_controller_->Animate(time);
598 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
599 EXPECT_FLOAT_EQ(kIdleThicknessScale,
600 scrollbar_layer_->thumb_thickness_scale_factor());
601
602 // Should animate to thickened.
603 time += kThinningDuration;
604 scrollbar_controller_->Animate(time);
605 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
606 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
607
608 // Subsequent moves should not change anything.
609 scrollbar_controller_->DidMouseMoveNear(0);
610 scrollbar_controller_->Animate(time);
611 time += base::TimeDelta::FromSeconds(10);
612 scrollbar_controller_->Animate(time);
613 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
614 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
615
616 // Moving off the scrollbar but still withing the "near" threshold should do
617 // nothing.
618 scrollbar_controller_->DidMouseMoveNear(
619 kDefaultMouseMoveDistanceToTriggerAnimation - 1.f);
620 scrollbar_controller_->Animate(time);
621 time += base::TimeDelta::FromSeconds(10);
622 scrollbar_controller_->Animate(time);
623 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
624 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
625
626 // Now move away from bar.
627 scrollbar_controller_->DidMouseMoveNear(
628 kDefaultMouseMoveDistanceToTriggerAnimation);
629 scrollbar_controller_->Animate(time);
630 time += kThinningDuration;
631 scrollbar_controller_->Animate(time);
632 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
633 EXPECT_FLOAT_EQ(kIdleThicknessScale,
634 scrollbar_layer_->thumb_thickness_scale_factor());
635 }
636
637 // First move the pointer over the scrollbar off of it. Make sure the thinning
638 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the
639 // thickening animation in the DidMouseMoveNear call.
640 TEST_F(ScrollbarAnimationControllerThinningTest,
641 MouseNearThenAwayWhileAnimating) {
642 // Scroll to make the scrollbars visible.
643 scrollbar_controller_->DidScrollBegin();
644 scrollbar_controller_->DidScrollUpdate(false);
645 scrollbar_controller_->DidScrollEnd();
646
647 base::TimeTicks time;
648 time += base::TimeDelta::FromSeconds(1);
649
650 scrollbar_controller_->DidMouseMoveNear(0);
651 scrollbar_controller_->Animate(time);
652 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
653 EXPECT_FLOAT_EQ(kIdleThicknessScale,
654 scrollbar_layer_->thumb_thickness_scale_factor());
655
656 // Should animate to thickened.
657 time += kThinningDuration;
658 scrollbar_controller_->Animate(time);
659 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
660 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
661
662 // This is tricky. The DidMouseLeave() is sent before the
663 // subsequent DidMouseMoveNear(), if the mouse moves in that direction.
664 // This results in the thumb thinning. We want to make sure that when the
665 // thumb starts expanding it doesn't first narrow to the idle thinness.
666 time += base::TimeDelta::FromSeconds(1);
667 scrollbar_controller_->DidMouseLeave();
668 scrollbar_controller_->Animate(time);
669 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
670
671 // Let the animation run half of the way through the thinning animation.
672 time += kThinningDuration / 2;
673 scrollbar_controller_->Animate(time);
674 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f,
675 scrollbar_layer_->thumb_thickness_scale_factor());
676
677 // Now we get a notification for the mouse moving over the scroller. The
678 // animation is reset to the thickening direction but we won't start
679 // thickening until the new animation catches up to the current thickness.
680 scrollbar_controller_->DidMouseMoveNear(1);
681 scrollbar_controller_->Animate(time);
682 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f,
683 scrollbar_layer_->thumb_thickness_scale_factor());
684
685 // Until we reach the half way point, the animation will have no effect.
686 time += kThinningDuration / 4;
687 scrollbar_controller_->Animate(time);
688 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f,
689 scrollbar_layer_->thumb_thickness_scale_factor());
690
691 time += kThinningDuration / 4;
692 scrollbar_controller_->Animate(time);
693 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f,
694 scrollbar_layer_->thumb_thickness_scale_factor());
695
696 // We're now at three quarters of the way through so it should now started
697 // thickening again.
698 time += kThinningDuration / 4;
699 scrollbar_controller_->Animate(time);
700 EXPECT_FLOAT_EQ(kIdleThicknessScale + 3 * (1.0f - kIdleThicknessScale) / 4.0f,
701 scrollbar_layer_->thumb_thickness_scale_factor());
702
703 // And all the way to the end.
704 time += kThinningDuration / 4;
705 scrollbar_controller_->Animate(time);
706 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
707 }
708
709 // First move the pointer on the scrollbar, then press it, then away.
710 // Confirm that the bar gets thick. Then mouse up. Confirm that
711 // the bar gets thin.
712 TEST_F(ScrollbarAnimationControllerThinningTest,
713 MouseCaptureAndReleaseOutOfBar) {
714 // Scroll to make the scrollbars visible.
715 scrollbar_controller_->DidScrollBegin();
716 scrollbar_controller_->DidScrollUpdate(false);
717 scrollbar_controller_->DidScrollEnd();
718
719 base::TimeTicks time;
720 time += base::TimeDelta::FromSeconds(1);
721
722 // Move over the scrollbar.
723 scrollbar_controller_->DidMouseMoveNear(0);
724 scrollbar_controller_->Animate(time);
725 time += kFadeDuration;
726 scrollbar_controller_->Animate(time);
727 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
728 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
729
730 // Capture
731 scrollbar_controller_->DidMouseDown();
732 time += base::TimeDelta::FromSeconds(1);
733 scrollbar_controller_->Animate(time);
734 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
735 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
736
737 // Should stay thick for a while.
738 time += base::TimeDelta::FromSeconds(10);
739 scrollbar_controller_->Animate(time);
740
741 // Move outside the "near" threshold. Because the scrollbar is captured it
742 // should remain thick.
743 scrollbar_controller_->DidMouseMoveNear(
744 kDefaultMouseMoveDistanceToTriggerAnimation);
745 time += kThinningDuration;
746 scrollbar_controller_->Animate(time);
747 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
748 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
749
750 // Release.
751 scrollbar_controller_->DidMouseUp();
752
753 // Should become thin.
754 time += base::TimeDelta::FromSeconds(1);
755 scrollbar_controller_->Animate(time);
756 time += kThinningDuration;
757 scrollbar_controller_->Animate(time);
758 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
759 EXPECT_FLOAT_EQ(kIdleThicknessScale,
760 scrollbar_layer_->thumb_thickness_scale_factor());
761 }
762
763 // First move the pointer on the scrollbar, then press it, then away. Confirm
764 // that the bar gets thick. Then move point on the scrollbar and mouse up.
765 // Confirm that the bar stays thick.
766 TEST_F(ScrollbarAnimationControllerThinningTest, MouseCaptureAndReleaseOnBar) {
767 // Scroll to make the scrollbars visible.
768 scrollbar_controller_->DidScrollBegin();
769 scrollbar_controller_->DidScrollUpdate(false);
770 scrollbar_controller_->DidScrollEnd();
771
772 base::TimeTicks time;
773 time += base::TimeDelta::FromSeconds(1);
774
775 // Move over scrollbar.
776 scrollbar_controller_->DidMouseMoveNear(0);
777 scrollbar_controller_->Animate(time);
778 time += kThinningDuration;
779 scrollbar_controller_->Animate(time);
780 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
781 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
782
783 // Capture. Nothing should change.
784 scrollbar_controller_->DidMouseDown();
785 time += base::TimeDelta::FromSeconds(1);
786 scrollbar_controller_->Animate(time);
787 time += base::TimeDelta::FromSeconds(10);
788 scrollbar_controller_->Animate(time);
789 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
790 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
791
792 // Move away from scrollbar. Nothing should change.
793 scrollbar_controller_->DidMouseMoveNear(
794 kDefaultMouseMoveDistanceToTriggerAnimation);
795 time += base::TimeDelta::FromSeconds(1);
796 scrollbar_controller_->Animate(time);
797 time += base::TimeDelta::FromSeconds(10);
798 scrollbar_controller_->Animate(time);
799 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
800 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
801
802 // Move over scrollbar and release. Since we're near the scrollbar, it should
803 // remain thick.
804 scrollbar_controller_->DidMouseMoveNear(0);
805 scrollbar_controller_->DidMouseUp();
806 time += base::TimeDelta::FromSeconds(1);
807 scrollbar_controller_->Animate(time);
808 time += base::TimeDelta::FromSeconds(10);
809 scrollbar_controller_->Animate(time);
810 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
811 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
812 }
813
814 // Move mouse on scrollbar and capture then move out of window. Confirm that
815 // the bar stays thick.
816 TEST_F(ScrollbarAnimationControllerThinningTest,
817 MouseCapturedAndExitWindowFromScrollbar) {
818 // Scroll to make the scrollbars visible.
819 scrollbar_controller_->DidScrollBegin();
820 scrollbar_controller_->DidScrollUpdate(false);
821 scrollbar_controller_->DidScrollEnd();
822
823 base::TimeTicks time;
824 time += base::TimeDelta::FromSeconds(1);
825
826 // Move mouse over scrollbar.
827 scrollbar_controller_->DidMouseMoveNear(0);
828 scrollbar_controller_->Animate(time);
829 time += kThinningDuration;
830 scrollbar_controller_->Animate(time);
831 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
832 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
833
834 // Capture.
835 scrollbar_controller_->DidMouseDown();
836 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
837 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
838
839 // Move out of window. Since the scrollbar is capture, it shouldn't change in
840 // any way.
841 scrollbar_controller_->DidMouseLeave();
842 scrollbar_controller_->Animate(time);
843 time += kThinningDuration;
844 scrollbar_controller_->Animate(time);
845 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
846 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
847 }
848
849 // Tests that the thickening/thinning effects are animated.
850 TEST_F(ScrollbarAnimationControllerThinningTest, ThicknessAnimated) {
851 // Scroll to make the scrollbars visible.
852 scrollbar_controller_->DidScrollBegin();
853 scrollbar_controller_->DidScrollUpdate(false);
854 scrollbar_controller_->DidScrollEnd();
855
856 base::TimeTicks time;
857 time += base::TimeDelta::FromSeconds(1);
858
859 // Move mouse near scrollbar. Test that at half the duration time, the
860 // thickness is half way through its animation.
861 scrollbar_controller_->DidMouseMoveNear(1);
862 scrollbar_controller_->Animate(time);
863 EXPECT_FLOAT_EQ(kIdleThicknessScale,
864 scrollbar_layer_->thumb_thickness_scale_factor());
865
866 time += kThinningDuration / 2;
867 scrollbar_controller_->Animate(time);
868 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f,
869 scrollbar_layer_->thumb_thickness_scale_factor());
870
871 time += kThinningDuration / 2;
872 scrollbar_controller_->Animate(time);
873 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
874
875 // Move mouse away from scrollbar. Same check.
876 time += base::TimeDelta::FromSeconds(1);
877 scrollbar_controller_->DidMouseMoveNear(
878 kDefaultMouseMoveDistanceToTriggerAnimation);
879 scrollbar_controller_->Animate(time);
880 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
881
882 time += kThinningDuration / 2;
883 scrollbar_controller_->Animate(time);
884 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f,
885 scrollbar_layer_->thumb_thickness_scale_factor());
886
887 time += kThinningDuration / 2;
888 scrollbar_controller_->Animate(time);
889 EXPECT_FLOAT_EQ(kIdleThicknessScale,
890 scrollbar_layer_->thumb_thickness_scale_factor());
891 }
892
893 // Tests that main thread scroll updates immediatley queue a fade animation
894 // without requiring a ScrollEnd.
895 TEST_F(ScrollbarAnimationControllerThinningTest, MainThreadScrollQueuesFade) {
896 ASSERT_TRUE(client_.start_fade().is_null());
897
898 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update
899 // so we should schedule a fade animation without waiting for a ScrollEnd
900 // (which will never come).
901 scrollbar_controller_->DidScrollUpdate(false);
902 EXPECT_FALSE(client_.start_fade().is_null());
903 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
904
905 client_.start_fade().Reset();
906
907 // If we got a ScrollBegin, we shouldn't schedule the fade animation until we
908 // get a corresponding ScrollEnd.
909 scrollbar_controller_->DidScrollBegin();
910 scrollbar_controller_->DidScrollUpdate(false);
911 EXPECT_TRUE(client_.start_fade().is_null());
912 scrollbar_controller_->DidScrollEnd();
913 EXPECT_FALSE(client_.start_fade().is_null());
914 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
915 }
916
917 // Make sure that if the scroll update is as a result of a resize, we use the
918 // resize delay time instead of the default one.
919 TEST_F(ScrollbarAnimationControllerThinningTest, ResizeFadeDuration) {
920 ASSERT_TRUE(client_.delay().is_zero());
921
922 scrollbar_controller_->DidScrollUpdate(true);
923 EXPECT_FALSE(client_.start_fade().is_null());
924 EXPECT_EQ(kResizeDelayBeforeStarting, client_.delay());
925
926 client_.delay() = base::TimeDelta();
927
928 // We should use the gesture delay rather than the resize delay if we're in a
929 // gesture scroll, even if the resize param is set.
930 scrollbar_controller_->DidScrollBegin();
931 scrollbar_controller_->DidScrollUpdate(true);
932 scrollbar_controller_->DidScrollEnd();
933
934 EXPECT_FALSE(client_.start_fade().is_null());
935 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
936 }
937
938 // Tests that the fade effect is animated.
939 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAnimated) {
940 // Scroll to make the scrollbars visible.
941 scrollbar_controller_->DidScrollBegin();
942 scrollbar_controller_->DidScrollUpdate(false);
943 scrollbar_controller_->DidScrollEnd();
944
945 // Appearance is instant.
946 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
947
948 // An animation should have been enqueued.
949 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
950 EXPECT_FALSE(client_.start_fade().is_null());
951 client_.start_fade().Run();
952
953 base::TimeTicks time;
954 time += base::TimeDelta::FromSeconds(1);
955
956 // Test that at half the fade duration time, the opacity is at half.
957 scrollbar_controller_->Animate(time);
958 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
959
960 time += kFadeDuration / 2;
961 scrollbar_controller_->Animate(time);
962 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity());
963
964 time += kFadeDuration / 2;
965 scrollbar_controller_->Animate(time);
966 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
967 }
968
969 // Tests that the controller tells the client when the scrollbars hide/show.
970 TEST_F(ScrollbarAnimationControllerThinningTest, NotifyChangedVisibility) {
971 base::TimeTicks time;
972 time += base::TimeDelta::FromSeconds(1);
973
974 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
975 // Scroll to make the scrollbars visible.
976 scrollbar_controller_->DidScrollBegin();
977 scrollbar_controller_->DidScrollUpdate(false);
978 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
979 Mock::VerifyAndClearExpectations(&client_);
980
981 scrollbar_controller_->DidScrollEnd();
982
983 // Play out the fade animation. We shouldn't notify that the scrollbars are
984 // hidden until the animation is completly over. We can (but don't have to)
985 // notify during the animation that the scrollbars are still visible.
986 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(0);
987 ASSERT_FALSE(client_.start_fade().is_null());
988 client_.start_fade().Run();
989 scrollbar_controller_->Animate(time);
990 time += kFadeDuration / 4;
991 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
992 scrollbar_controller_->Animate(time);
993 time += kFadeDuration / 4;
994 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
995 scrollbar_controller_->Animate(time);
996 time += kFadeDuration / 4;
997 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
998 scrollbar_controller_->Animate(time);
999 EXPECT_FLOAT_EQ(0.25f, scrollbar_layer_->Opacity());
1000 Mock::VerifyAndClearExpectations(&client_);
1001
1002 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
1003 time += kFadeDuration / 4;
1004 scrollbar_controller_->Animate(time);
1005 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
1006 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1007 Mock::VerifyAndClearExpectations(&client_);
1008
1009 // Calling DidScrollUpdate without a begin (i.e. update from commit) should
1010 // also notify.
1011 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
1012 scrollbar_controller_->DidScrollUpdate(false);
1013 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1014 Mock::VerifyAndClearExpectations(&client_);
1015 } 212 }
1016 213
1017 } // namespace 214 } // namespace
1018 } // namespace cc 215 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698