OLD | NEW |
---|---|
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 193 |
194 // Scrollbar should fade out over kFadeDuration. | 194 // Scrollbar should fade out over kFadeDuration. |
195 scrollbar_controller_->Animate(time); | 195 scrollbar_controller_->Animate(time); |
196 time += kFadeDuration; | 196 time += kFadeDuration; |
197 scrollbar_controller_->Animate(time); | 197 scrollbar_controller_->Animate(time); |
198 | 198 |
199 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 199 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
200 } | 200 } |
201 | 201 |
202 // Scroll content. Move the mouse near the scrollbar and confirm it becomes | 202 // Scroll content. Move the mouse near the scrollbar and confirm it becomes |
203 // thick. Ensure it fades out after that. | 203 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. |
204 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndFadeOut) { | 204 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndDontFadeOut) { |
205 base::TimeTicks time; | 205 base::TimeTicks time; |
206 time += base::TimeDelta::FromSeconds(1); | 206 time += base::TimeDelta::FromSeconds(1); |
207 | 207 |
208 scrollbar_controller_->DidScrollBegin(); | 208 scrollbar_controller_->DidScrollBegin(); |
209 scrollbar_controller_->DidScrollUpdate(false); | 209 scrollbar_controller_->DidScrollUpdate(false); |
210 scrollbar_controller_->DidScrollEnd(); | 210 scrollbar_controller_->DidScrollEnd(); |
211 | 211 |
212 // An animation should have been enqueued. | 212 // An animation should have been enqueued. |
213 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 213 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
214 EXPECT_FALSE(client_.start_fade().is_null()); | 214 EXPECT_FALSE(client_.start_fade().is_null()); |
215 EXPECT_FALSE(client_.start_fade().IsCancelled()); | |
215 | 216 |
216 // Now move the mouse near the scrollbar. This should cancel the currently | 217 // Now move the mouse near the scrollbar. This should cancel the currently |
217 // queued fading animation and start animating thickness. | 218 // queued fading animation and start animating thickness. |
218 scrollbar_controller_->DidMouseMoveNear(1); | 219 scrollbar_controller_->DidMouseMoveNear(1); |
219 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 220 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
220 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 221 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
221 scrollbar_layer_->thumb_thickness_scale_factor()); | 222 scrollbar_layer_->thumb_thickness_scale_factor()); |
222 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 223 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
223 | 224 |
224 // Scrollbar should become thick. | 225 // Scrollbar should become thick. |
225 scrollbar_controller_->Animate(time); | 226 scrollbar_controller_->Animate(time); |
226 time += kThinningDuration; | 227 time += kThinningDuration; |
227 scrollbar_controller_->Animate(time); | 228 scrollbar_controller_->Animate(time); |
228 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 230 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
230 | 231 |
231 // Once the thickening animation is complete, it should enqueue the delayed | 232 // Mouse is still near the Scrollbar. Once the thickness animation is |
232 // fade animation. | 233 // complete, the queued delayed fade animation should be still cancelled. |
233 EXPECT_FALSE(client_.start_fade().is_null()); | 234 EXPECT_FALSE(client_.start_fade().is_null()); |
234 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 235 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
bokan
2016/12/06 17:22:28
Merge all occurances of this !is_null and IsCancel
sahel
2016/12/07 22:33:06
right, done.
| |
235 } | 236 } |
236 | 237 |
237 // Scroll content. Move the mouse over the scrollbar and confirm it becomes | 238 // Scroll content. Move the mouse over the scrollbar and confirm it becomes |
238 // thick. Ensure it fades out after that. | 239 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. |
239 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndFadeOut) { | 240 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndDontFadeOut) { |
240 base::TimeTicks time; | 241 base::TimeTicks time; |
241 time += base::TimeDelta::FromSeconds(1); | 242 time += base::TimeDelta::FromSeconds(1); |
242 | 243 |
243 scrollbar_controller_->DidScrollBegin(); | 244 scrollbar_controller_->DidScrollBegin(); |
244 scrollbar_controller_->DidScrollUpdate(false); | 245 scrollbar_controller_->DidScrollUpdate(false); |
245 scrollbar_controller_->DidScrollEnd(); | 246 scrollbar_controller_->DidScrollEnd(); |
246 | 247 |
247 // An animation should have been enqueued. | 248 // An animation should have been enqueued. |
248 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 249 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
249 EXPECT_FALSE(client_.start_fade().is_null()); | 250 EXPECT_FALSE(client_.start_fade().is_null()); |
251 EXPECT_FALSE(client_.start_fade().IsCancelled()); | |
250 | 252 |
251 // Now move the mouse over the scrollbar. This should cancel the currently | 253 // Now move the mouse over the scrollbar. This should cancel the currently |
252 // queued fading animation and start animating thickness. | 254 // queued fading animation and start animating thickness. |
253 scrollbar_controller_->DidMouseMoveNear(0); | 255 scrollbar_controller_->DidMouseMoveNear(0); |
254 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 256 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
255 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 257 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
256 scrollbar_layer_->thumb_thickness_scale_factor()); | 258 scrollbar_layer_->thumb_thickness_scale_factor()); |
257 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 259 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
258 | 260 |
259 // Scrollbar should become thick. | 261 // Scrollbar should become thick. |
260 scrollbar_controller_->Animate(time); | 262 scrollbar_controller_->Animate(time); |
261 time += kThinningDuration; | 263 time += kThinningDuration; |
262 scrollbar_controller_->Animate(time); | 264 scrollbar_controller_->Animate(time); |
263 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 265 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
264 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 266 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
265 | 267 |
266 // Once the thickening animation is complete, it should enqueue the delayed | 268 // Mouse is still over the Scrollbar. Once the thickness animation is |
267 // fade animation. | 269 // complete, the queued delayed fade animation should be still cancelled. |
268 EXPECT_FALSE(client_.start_fade().is_null()); | 270 EXPECT_FALSE(client_.start_fade().is_null()); |
269 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 271 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
270 } | 272 } |
271 | 273 |
272 // Make sure a scrollbar captured before the thickening animation doesn't try | 274 // Make sure a scrollbar captured before the thickening animation doesn't try |
273 // to fade out. | 275 // to fade out. |
274 TEST_F(ScrollbarAnimationControllerThinningTest, | 276 TEST_F(ScrollbarAnimationControllerThinningTest, |
275 DontFadeWhileCapturedBeforeThick) { | 277 DontFadeWhileCapturedBeforeThick) { |
276 base::TimeTicks time; | 278 base::TimeTicks time; |
277 time += base::TimeDelta::FromSeconds(1); | 279 time += base::TimeDelta::FromSeconds(1); |
278 | 280 |
279 scrollbar_controller_->DidScrollBegin(); | 281 scrollbar_controller_->DidScrollBegin(); |
(...skipping 22 matching lines...) Expand all Loading... | |
302 base::TimeTicks time; | 304 base::TimeTicks time; |
303 time += base::TimeDelta::FromSeconds(1); | 305 time += base::TimeDelta::FromSeconds(1); |
304 | 306 |
305 scrollbar_controller_->DidScrollBegin(); | 307 scrollbar_controller_->DidScrollBegin(); |
306 scrollbar_controller_->DidScrollUpdate(false); | 308 scrollbar_controller_->DidScrollUpdate(false); |
307 scrollbar_controller_->DidScrollEnd(); | 309 scrollbar_controller_->DidScrollEnd(); |
308 | 310 |
309 // An animation should have been enqueued. | 311 // An animation should have been enqueued. |
310 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 312 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
311 EXPECT_FALSE(client_.start_fade().is_null()); | 313 EXPECT_FALSE(client_.start_fade().is_null()); |
314 EXPECT_FALSE(client_.start_fade().IsCancelled()); | |
312 | 315 |
313 // Now move the mouse over the scrollbar and animate it until it's thick. | 316 // Now move the mouse over the scrollbar and animate it until it's thick. |
314 scrollbar_controller_->DidMouseMoveNear(0); | 317 scrollbar_controller_->DidMouseMoveNear(0); |
315 scrollbar_controller_->Animate(time); | 318 scrollbar_controller_->Animate(time); |
316 time += kThinningDuration; | 319 time += kThinningDuration; |
317 scrollbar_controller_->Animate(time); | 320 scrollbar_controller_->Animate(time); |
318 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 321 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
319 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 322 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
320 | 323 |
321 // Since the scrollbar became thick, it should have queued up a fade. | 324 // Since the mouse is over the scrollbar, it should cancel the queued fade. |
322 EXPECT_FALSE(client_.start_fade().is_null()); | 325 EXPECT_FALSE(client_.start_fade().is_null()); |
323 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 326 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
324 | 327 |
325 // Make sure capturing the scrollbar stops the fade. | 328 // Make sure the queued fade animation is still cancelled after capturing |
329 // the scrollbar. | |
326 scrollbar_controller_->DidMouseDown(); | 330 scrollbar_controller_->DidMouseDown(); |
327 EXPECT_FALSE(client_.start_fade().is_null()); | 331 EXPECT_FALSE(client_.start_fade().is_null()); |
328 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 332 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
329 } | 333 } |
330 | 334 |
331 // Make sure releasing a captured scrollbar causes it to fade out. | 335 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes |
332 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleased) { | 336 // the scrollbar to fade out. |
337 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleasedFar) { | |
333 base::TimeTicks time; | 338 base::TimeTicks time; |
334 time += base::TimeDelta::FromSeconds(1); | 339 time += base::TimeDelta::FromSeconds(1); |
335 | 340 |
336 scrollbar_controller_->DidScrollBegin(); | 341 scrollbar_controller_->DidScrollBegin(); |
337 scrollbar_controller_->DidScrollUpdate(false); | 342 scrollbar_controller_->DidScrollUpdate(false); |
338 scrollbar_controller_->DidScrollEnd(); | 343 scrollbar_controller_->DidScrollEnd(); |
339 | 344 |
340 // An animation should have been enqueued. | 345 // An animation should have been enqueued. |
341 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 346 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
342 EXPECT_FALSE(client_.start_fade().is_null()); | 347 EXPECT_FALSE(client_.start_fade().is_null()); |
348 EXPECT_FALSE(client_.start_fade().IsCancelled()); | |
343 | 349 |
344 // Now move the mouse over the scrollbar and capture it. | 350 // Now move the mouse over the scrollbar and capture it. |
345 scrollbar_controller_->DidMouseMoveNear(0); | 351 scrollbar_controller_->DidMouseMoveNear(0); |
346 scrollbar_controller_->DidMouseDown(); | 352 scrollbar_controller_->DidMouseDown(); |
347 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 353 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
348 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 354 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
349 | 355 |
350 // Since the scrollbar became thick, it should have queued up a fade. | 356 // Since the mouse is still near the scrollbar, the queued fade should be |
357 // cancelled. | |
351 EXPECT_FALSE(client_.start_fade().is_null()); | 358 EXPECT_FALSE(client_.start_fade().is_null()); |
352 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 359 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
353 | 360 |
361 // Now move the mouse away from the scrollbar and release it. | |
362 scrollbar_controller_->DidMouseMoveNear(26); | |
bokan
2016/12/06 17:22:28
Use kDefaultMouseMoveDistanceToTriggerAnimation +
sahel
2016/12/07 22:33:06
Done.
| |
354 scrollbar_controller_->DidMouseUp(); | 363 scrollbar_controller_->DidMouseUp(); |
364 | |
365 scrollbar_controller_->Animate(time); | |
366 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
367 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
368 time += kThinningDuration; | |
369 scrollbar_controller_->Animate(time); | |
370 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
371 EXPECT_FLOAT_EQ(kIdleThicknessScale, | |
372 scrollbar_layer_->thumb_thickness_scale_factor()); | |
373 | |
374 // The thickness animation is complete, a fade out must be queued. | |
355 EXPECT_FALSE(client_.start_fade().is_null()); | 375 EXPECT_FALSE(client_.start_fade().is_null()); |
356 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 376 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
357 } | 377 } |
358 | 378 |
359 // Make sure moving near a scrollbar while it's fading out causes it to reset | 379 // Make sure releasing a captured scrollbar when the mouse is near/over it, |
360 // the opacity and thicken. | 380 // doesn't cause the scrollbar to fade out. |
361 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { | 381 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeAfterReleasedNear) { |
362 base::TimeTicks time; | 382 base::TimeTicks time; |
363 time += base::TimeDelta::FromSeconds(1); | 383 time += base::TimeDelta::FromSeconds(1); |
364 | 384 |
365 scrollbar_controller_->DidScrollBegin(); | 385 scrollbar_controller_->DidScrollBegin(); |
366 scrollbar_controller_->DidScrollUpdate(false); | 386 scrollbar_controller_->DidScrollUpdate(false); |
367 scrollbar_controller_->DidScrollEnd(); | 387 scrollbar_controller_->DidScrollEnd(); |
368 | 388 |
369 // An animation should have been enqueued. Start it. | 389 // An animation should have been enqueued. |
370 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 390 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
371 EXPECT_FALSE(client_.start_fade().is_null()); | 391 EXPECT_FALSE(client_.start_fade().is_null()); |
372 client_.start_fade().Run(); | 392 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
373 | 393 |
374 scrollbar_controller_->Animate(time); | 394 // Now move the mouse over the scrollbar and capture it. |
395 scrollbar_controller_->DidMouseMoveNear(0); | |
396 scrollbar_controller_->DidMouseDown(); | |
375 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 397 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
398 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
376 | 399 |
377 // Proceed half way through the fade out animation. | 400 // Since the mouse is over the scrollbar, the queued fade must be cancelled. |
378 time += kFadeDuration / 2; | 401 EXPECT_FALSE(client_.start_fade().is_null()); |
379 scrollbar_controller_->Animate(time); | 402 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
380 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | |
381 | 403 |
382 // Now move the mouse near the scrollbar. It should reset opacity to 1 | 404 // Mouse is still near the scrollbar, releasing it shouldn't do anything. |
383 // instantly and start animating to thick. | 405 scrollbar_controller_->DidMouseUp(); |
384 scrollbar_controller_->DidMouseMoveNear(1); | 406 EXPECT_FALSE(client_.start_fade().is_null()); |
385 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 407 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
386 EXPECT_FLOAT_EQ(kIdleThicknessScale, | |
387 scrollbar_layer_->thumb_thickness_scale_factor()); | |
388 | |
389 scrollbar_controller_->Animate(time); | |
390 time += kThinningDuration; | |
391 scrollbar_controller_->Animate(time); | |
392 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 408 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
393 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 409 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
394 } | 410 } |
395 | 411 |
396 // Make sure capturing a scrollbar while it's fading out causes it to reset the | 412 // Make sure moving near a scrollbar while it's fading out causes it to reset |
397 // opacity and thicken instantly. | 413 // the opacity and thicken. |
398 TEST_F(ScrollbarAnimationControllerThinningTest, CaptureScrollbarWhileFading) { | 414 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { |
399 base::TimeTicks time; | 415 base::TimeTicks time; |
400 time += base::TimeDelta::FromSeconds(1); | 416 time += base::TimeDelta::FromSeconds(1); |
401 | 417 |
402 scrollbar_controller_->DidScrollBegin(); | 418 scrollbar_controller_->DidScrollBegin(); |
403 scrollbar_controller_->DidScrollUpdate(false); | 419 scrollbar_controller_->DidScrollUpdate(false); |
404 scrollbar_controller_->DidScrollEnd(); | 420 scrollbar_controller_->DidScrollEnd(); |
405 | 421 |
406 // Move mouse over the scrollbar. | |
407 scrollbar_controller_->DidMouseMoveNear(0); | |
408 scrollbar_controller_->Animate(time); | |
409 time += kThinningDuration; | |
410 scrollbar_controller_->Animate(time); | |
411 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
412 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
413 | |
414 // A fade animation should have been enqueued. Start it. | 422 // A fade animation should have been enqueued. Start it. |
415 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 423 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
416 EXPECT_FALSE(client_.start_fade().is_null()); | 424 EXPECT_FALSE(client_.start_fade().is_null()); |
417 client_.start_fade().Run(); | 425 client_.start_fade().Run(); |
418 | 426 |
419 scrollbar_controller_->Animate(time); | 427 scrollbar_controller_->Animate(time); |
420 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 428 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
421 | 429 |
422 // Proceed half way through the fade out animation. | 430 // Proceed half way through the fade out animation. |
423 time += kFadeDuration / 2; | 431 time += kFadeDuration / 2; |
424 scrollbar_controller_->Animate(time); | 432 scrollbar_controller_->Animate(time); |
425 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | 433 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
426 | 434 |
427 // Now capture the scrollbar. It should reset opacity to 1 instantly. | 435 // Now move the mouse near the scrollbar. It should reset opacity to 1 |
428 scrollbar_controller_->DidMouseDown(); | 436 // instantly and start animating to thick. |
437 scrollbar_controller_->DidMouseMoveNear(1); | |
438 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
439 EXPECT_FLOAT_EQ(kIdleThicknessScale, | |
440 scrollbar_layer_->thumb_thickness_scale_factor()); | |
441 | |
442 scrollbar_controller_->Animate(time); | |
443 time += kThinningDuration; | |
444 scrollbar_controller_->Animate(time); | |
429 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 445 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
430 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 446 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
431 } | 447 } |
432 | 448 |
433 // Make sure we can't capture scrollbar that's completely faded out | 449 // Make sure we can't capture scrollbar that's completely faded out. |
434 TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { | 450 TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { |
435 base::TimeTicks time; | 451 base::TimeTicks time; |
436 time += base::TimeDelta::FromSeconds(1); | 452 time += base::TimeDelta::FromSeconds(1); |
437 | 453 |
438 scrollbar_controller_->DidScrollBegin(); | 454 scrollbar_controller_->DidScrollBegin(); |
439 scrollbar_controller_->DidScrollUpdate(false); | 455 scrollbar_controller_->DidScrollUpdate(false); |
440 scrollbar_controller_->DidScrollEnd(); | 456 scrollbar_controller_->DidScrollEnd(); |
441 | 457 |
442 // Move mouse over the scrollbar. | |
443 scrollbar_controller_->DidMouseMoveNear(0); | |
444 scrollbar_controller_->Animate(time); | |
445 time += kThinningDuration; | |
446 scrollbar_controller_->Animate(time); | |
447 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
448 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
449 | |
450 // A fade animation should have been enqueued. Start it. | |
451 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 458 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
452 EXPECT_FALSE(client_.start_fade().is_null()); | 459 EXPECT_FALSE(client_.start_fade().is_null()); |
460 EXPECT_FALSE(client_.start_fade().IsCancelled()); | |
453 client_.start_fade().Run(); | 461 client_.start_fade().Run(); |
454 scrollbar_controller_->Animate(time); | 462 scrollbar_controller_->Animate(time); |
455 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 463 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
456 | 464 |
457 // Fade the scrollbar out completely. | 465 // Fade the scrollbar out completely. |
458 time += kFadeDuration; | 466 time += kFadeDuration; |
459 scrollbar_controller_->Animate(time); | 467 scrollbar_controller_->Animate(time); |
460 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 468 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
461 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 469 |
470 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since | |
471 // it's completely faded out. | |
472 scrollbar_controller_->DidMouseMoveNear(0); | |
473 scrollbar_controller_->Animate(time); | |
474 time += kThinningDuration; | |
475 scrollbar_controller_->Animate(time); | |
476 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | |
477 EXPECT_FLOAT_EQ(kIdleThicknessScale, | |
478 scrollbar_layer_->thumb_thickness_scale_factor()); | |
462 | 479 |
463 client_.start_fade().Reset(); | 480 client_.start_fade().Reset(); |
464 | 481 |
465 // Now try to capture the scrollbar. It shouldn't do anything since it's | 482 // Now try to capture the scrollbar. It shouldn't do anything since it's |
466 // completely faded out. | 483 // completely faded out. |
467 scrollbar_controller_->DidMouseDown(); | 484 scrollbar_controller_->DidMouseDown(); |
468 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 485 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
469 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 486 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
487 scrollbar_layer_->thumb_thickness_scale_factor()); | |
470 EXPECT_TRUE(client_.start_fade().is_null()); | 488 EXPECT_TRUE(client_.start_fade().is_null()); |
471 | 489 |
472 // Similarly, releasing the scrollbar should have no effect. | 490 // Similarly, releasing the scrollbar should have no effect. |
473 scrollbar_controller_->DidMouseUp(); | 491 scrollbar_controller_->DidMouseUp(); |
474 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 492 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
475 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 493 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
494 scrollbar_layer_->thumb_thickness_scale_factor()); | |
476 EXPECT_TRUE(client_.start_fade().is_null()); | 495 EXPECT_TRUE(client_.start_fade().is_null()); |
477 } | 496 } |
478 | 497 |
479 // Initiate a scroll when the pointer is already near the scrollbar. It should | 498 // Initiate a scroll when the pointer is already near the scrollbar. It should |
480 // appear thick and remain thick. | 499 // appear thick and remain thick. |
481 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { | 500 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { |
482 base::TimeTicks time; | 501 base::TimeTicks time; |
483 time += base::TimeDelta::FromSeconds(1); | 502 time += base::TimeDelta::FromSeconds(1); |
484 | 503 |
485 scrollbar_controller_->DidMouseMoveNear(1); | 504 scrollbar_controller_->DidMouseMoveNear(1); |
486 scrollbar_controller_->Animate(time); | 505 scrollbar_controller_->Animate(time); |
487 time += kThinningDuration; | 506 time += kThinningDuration; |
488 | 507 |
489 // Since the scrollbar isn't visible yet (because we haven't scrolled), we | 508 // Since the scrollbar isn't visible yet (because we haven't scrolled), we |
490 // shouldn't have applied the thickening. | 509 // shouldn't have applied the thickening. |
491 scrollbar_controller_->Animate(time); | 510 scrollbar_controller_->Animate(time); |
492 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 511 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
493 scrollbar_layer_->thumb_thickness_scale_factor()); | 512 scrollbar_layer_->thumb_thickness_scale_factor()); |
494 | 513 |
495 scrollbar_controller_->DidScrollBegin(); | 514 scrollbar_controller_->DidScrollBegin(); |
496 scrollbar_controller_->DidScrollUpdate(false); | 515 scrollbar_controller_->DidScrollUpdate(false); |
497 | 516 |
498 // Now that we've received a scroll, we should be thick without an animation. | 517 // Now that we've received a scroll, we should be thick without an animation. |
499 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 518 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
500 | 519 |
501 // An animation for the fade should have been enqueued. | 520 // An animation for the fade should have been enqueued and cancelled, since |
bokan
2016/12/06 17:22:28
We shouldn't test that's its enqueued anymore. Onl
sahel
2016/12/07 22:33:06
Done.
| |
521 // mouse is still near the scrollbar. | |
502 scrollbar_controller_->DidScrollEnd(); | 522 scrollbar_controller_->DidScrollEnd(); |
503 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 523 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
504 EXPECT_FALSE(client_.start_fade().is_null()); | 524 EXPECT_FALSE(client_.start_fade().is_null()); |
525 EXPECT_TRUE(client_.start_fade().IsCancelled()); | |
505 | 526 |
506 client_.start_fade().Run(); | |
507 scrollbar_controller_->Animate(time); | 527 scrollbar_controller_->Animate(time); |
508 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 528 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
509 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 529 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
510 | 530 |
511 // Scrollbar should still be thick, even though the scrollbar fades out. | 531 // Scrollbar should still be thick and visible. |
512 time += kFadeDuration; | 532 time += kFadeDuration; |
513 scrollbar_controller_->Animate(time); | 533 scrollbar_controller_->Animate(time); |
514 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 534 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
515 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 535 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
516 } | 536 } |
517 | 537 |
518 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when | 538 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when |
519 // moved away. | 539 // moved away. |
520 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) { | 540 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) { |
521 base::TimeTicks time; | 541 base::TimeTicks time; |
522 time += base::TimeDelta::FromSeconds(1); | 542 time += base::TimeDelta::FromSeconds(1); |
523 | 543 |
524 // Scroll to make the scrollbars visible. | 544 // Scroll to make the scrollbars visible. |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
984 // Calling DidScrollUpdate without a begin (i.e. update from commit) should | 1004 // Calling DidScrollUpdate without a begin (i.e. update from commit) should |
985 // also notify. | 1005 // also notify. |
986 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 1006 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
987 scrollbar_controller_->DidScrollUpdate(false); | 1007 scrollbar_controller_->DidScrollUpdate(false); |
988 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 1008 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
989 Mock::VerifyAndClearExpectations(&client_); | 1009 Mock::VerifyAndClearExpectations(&client_); |
990 } | 1010 } |
991 | 1011 |
992 } // namespace | 1012 } // namespace |
993 } // namespace cc | 1013 } // namespace cc |
OLD | NEW |