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

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

Powered by Google App Engine
This is Rietveld 408576698