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

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

Issue 2816923002: change overlay scrollbar hover show to hover fade in (Closed)
Patch Set: merge FadeInDuration and FadeOutDuration to FadeDuration Created 3 years, 8 months 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.h" 5 #include "cc/input/scrollbar_animation_controller.h"
6 6
7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h"
8 #include "cc/test/fake_impl_task_runner_provider.h" 8 #include "cc/test/fake_impl_task_runner_provider.h"
9 #include "cc/test/fake_layer_tree_host_impl.h" 9 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "cc/test/geometry_test_utils.h" 10 #include "cc/test/geometry_test_utils.h"
11 #include "cc/test/test_task_graph_runner.h" 11 #include "cc/test/test_task_graph_runner.h"
12 #include "cc/trees/layer_tree_impl.h" 12 #include "cc/trees/layer_tree_impl.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using testing::AtLeast; 16 using testing::AtLeast;
17 using testing::Mock; 17 using testing::Mock;
18 using testing::NiceMock; 18 using testing::NiceMock;
19 using testing::_; 19 using testing::_;
20 20
21 namespace cc { 21 namespace cc {
22 namespace { 22 namespace {
23 23
24 const float kIdleThicknessScale = 24 const float kIdleThicknessScale =
25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; 25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale;
26 const float kDefaultMouseMoveDistanceToTriggerAnimation = 26 const float kDefaultMouseMoveDistanceToTriggerAnimation =
27 SingleScrollbarAnimationControllerThinning:: 27 SingleScrollbarAnimationControllerThinning::
28 kDefaultMouseMoveDistanceToTriggerAnimation; 28 kDefaultMouseMoveDistanceToTriggerAnimation;
29 const float kMouseMoveDistanceToTriggerShow = 29 const float kMouseMoveDistanceToTriggerFadeIn =
30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerShow; 30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn;
31 const int kThumbThickness = 10; 31 const int kThumbThickness = 10;
32 32
33 class MockScrollbarAnimationControllerClient 33 class MockScrollbarAnimationControllerClient
34 : public ScrollbarAnimationControllerClient { 34 : public ScrollbarAnimationControllerClient {
35 public: 35 public:
36 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) 36 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl)
37 : host_impl_(host_impl) {} 37 : host_impl_(host_impl) {}
38 virtual ~MockScrollbarAnimationControllerClient() {} 38 virtual ~MockScrollbarAnimationControllerClient() {}
39 39
40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, 40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade,
(...skipping 22 matching lines...) Expand all
63 ScrollbarAnimationControllerAuraOverlayTest() 63 ScrollbarAnimationControllerAuraOverlayTest()
64 : host_impl_(&task_runner_provider_, &task_graph_runner_), 64 : host_impl_(&task_runner_provider_, &task_graph_runner_),
65 client_(&host_impl_) {} 65 client_(&host_impl_) {}
66 66
67 void ExpectScrollbarsOpacity(float opacity) { 67 void ExpectScrollbarsOpacity(float opacity) {
68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); 68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity());
69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); 69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity());
70 } 70 }
71 71
72 protected: 72 protected:
73 const base::TimeDelta kShowDelay = base::TimeDelta::FromSeconds(4); 73 const base::TimeDelta kFadeInDelay = base::TimeDelta::FromSeconds(4);
74 const base::TimeDelta kFadeOutDelay = base::TimeDelta::FromSeconds(2); 74 const base::TimeDelta kFadeOutDelay = base::TimeDelta::FromSeconds(2);
75 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5); 75 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5);
76 const base::TimeDelta kFadeOutDuration = base::TimeDelta::FromSeconds(3); 76 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3);
77 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); 77 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2);
78 78
79 void SetUp() override { 79 void SetUp() override {
80 std::unique_ptr<LayerImpl> scroll_layer = 80 std::unique_ptr<LayerImpl> scroll_layer =
81 LayerImpl::Create(host_impl_.active_tree(), 1); 81 LayerImpl::Create(host_impl_.active_tree(), 1);
82 std::unique_ptr<LayerImpl> clip = 82 std::unique_ptr<LayerImpl> clip =
83 LayerImpl::Create(host_impl_.active_tree(), 2); 83 LayerImpl::Create(host_impl_.active_tree(), 2);
84 clip_layer_ = clip.get(); 84 clip_layer_ = clip.get();
85 scroll_layer->SetScrollClipLayer(clip_layer_->id()); 85 scroll_layer->SetScrollClipLayer(clip_layer_->id());
86 LayerImpl* scroll_layer_ptr = scroll_layer.get(); 86 LayerImpl* scroll_layer_ptr = scroll_layer.get();
(...skipping 23 matching lines...) Expand all
110 h_scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(), 110 h_scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(),
111 scroll_layer_ptr->element_id()); 111 scroll_layer_ptr->element_id());
112 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; 112 v_scrollbar_layer_->test_properties()->opacity_can_animate = true;
113 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; 113 h_scrollbar_layer_->test_properties()->opacity_can_animate = true;
114 clip_layer_->SetBounds(gfx::Size(100, 100)); 114 clip_layer_->SetBounds(gfx::Size(100, 100));
115 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); 115 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
116 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); 116 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
117 117
118 scrollbar_controller_ = ScrollbarAnimationController:: 118 scrollbar_controller_ = ScrollbarAnimationController::
119 CreateScrollbarAnimationControllerAuraOverlay( 119 CreateScrollbarAnimationControllerAuraOverlay(
120 scroll_layer_ptr->id(), &client_, kShowDelay, kFadeOutDelay, 120 scroll_layer_ptr->id(), &client_, kFadeInDelay, kFadeOutDelay,
121 kResizeFadeOutDelay, kFadeOutDuration, kThinningDuration); 121 kResizeFadeOutDelay, kFadeDuration, kThinningDuration);
122 } 122 }
123 123
124 FakeImplTaskRunnerProvider task_runner_provider_; 124 FakeImplTaskRunnerProvider task_runner_provider_;
125 TestTaskGraphRunner task_graph_runner_; 125 TestTaskGraphRunner task_graph_runner_;
126 FakeLayerTreeHostImpl host_impl_; 126 FakeLayerTreeHostImpl host_impl_;
127 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; 127 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
128 LayerImpl* clip_layer_; 128 LayerImpl* clip_layer_;
129 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; 129 SolidColorScrollbarLayerImpl* v_scrollbar_layer_;
130 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; 130 SolidColorScrollbarLayerImpl* h_scrollbar_layer_;
131 NiceMock<MockScrollbarAnimationControllerClient> client_; 131 NiceMock<MockScrollbarAnimationControllerClient> client_;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 scrollbar_controller_->DidScrollEnd(); 216 scrollbar_controller_->DidScrollEnd();
217 ExpectScrollbarsOpacity(1); 217 ExpectScrollbarsOpacity(1);
218 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 218 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
219 219
220 // An fade out animation should have been enqueued. 220 // An fade out animation should have been enqueued.
221 EXPECT_EQ(kFadeOutDelay, client_.delay()); 221 EXPECT_EQ(kFadeOutDelay, client_.delay());
222 EXPECT_FALSE(client_.start_fade().is_null()); 222 EXPECT_FALSE(client_.start_fade().is_null());
223 client_.start_fade().Run(); 223 client_.start_fade().Run();
224 224
225 // Scrollbar should fade out over kFadeOutDuration. 225 // Scrollbar should fade out over kFadeDuration.
226 scrollbar_controller_->Animate(time); 226 scrollbar_controller_->Animate(time);
227 time += kFadeOutDuration; 227 time += kFadeDuration;
228 scrollbar_controller_->Animate(time); 228 scrollbar_controller_->Animate(time);
229 229
230 ExpectScrollbarsOpacity(0); 230 ExpectScrollbarsOpacity(0);
231 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 231 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
232 } 232 }
233 233
234 // Confirm the scrollbar appears by WillUpdateScroll and fade out. 234 // Confirm the scrollbar appears by WillUpdateScroll and fade out.
235 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 235 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
236 BasicAppearByWillUpdateScrollThenFadeOut) { 236 BasicAppearByWillUpdateScrollThenFadeOut) {
237 base::TimeTicks time; 237 base::TimeTicks time;
238 time += base::TimeDelta::FromSeconds(1); 238 time += base::TimeDelta::FromSeconds(1);
239 239
240 // Scrollbar should be invisible. 240 // Scrollbar should be invisible.
241 ExpectScrollbarsOpacity(0); 241 ExpectScrollbarsOpacity(0);
242 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 242 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
243 243
244 // Scrollbar should appear when scroll will update. 244 // Scrollbar should appear when scroll will update.
245 scrollbar_controller_->WillUpdateScroll(); 245 scrollbar_controller_->WillUpdateScroll();
246 ExpectScrollbarsOpacity(1); 246 ExpectScrollbarsOpacity(1);
247 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 247 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
248 248
249 // An fade out animation should have been enqueued. 249 // An fade out animation should have been enqueued.
250 EXPECT_EQ(kFadeOutDelay, client_.delay()); 250 EXPECT_EQ(kFadeOutDelay, client_.delay());
251 EXPECT_FALSE(client_.start_fade().is_null()); 251 EXPECT_FALSE(client_.start_fade().is_null());
252 client_.start_fade().Run(); 252 client_.start_fade().Run();
253 253
254 // Scrollbar should fade out over kFadeOutDuration. 254 // Scrollbar should fade out over kFadeDuration.
255 scrollbar_controller_->Animate(time); 255 scrollbar_controller_->Animate(time);
256 time += kFadeOutDuration; 256 time += kFadeDuration;
257 scrollbar_controller_->Animate(time); 257 scrollbar_controller_->Animate(time);
258 258
259 ExpectScrollbarsOpacity(0); 259 ExpectScrollbarsOpacity(0);
260 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 260 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
261 } 261 }
262 262
263 // Scroll content. Move the mouse near the scrollbar and confirm it becomes 263 // Scroll content. Move the mouse near the scrollbar and confirm it becomes
264 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. 264 // thick. Ensure it remains visible as long as the mouse is near the scrollbar.
265 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) { 265 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) {
266 base::TimeTicks time; 266 base::TimeTicks time;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 546
547 // A fade out animation should have been enqueued. Start it. 547 // A fade out animation should have been enqueued. Start it.
548 EXPECT_EQ(kFadeOutDelay, client_.delay()); 548 EXPECT_EQ(kFadeOutDelay, client_.delay());
549 EXPECT_FALSE(client_.start_fade().is_null()); 549 EXPECT_FALSE(client_.start_fade().is_null());
550 client_.start_fade().Run(); 550 client_.start_fade().Run();
551 551
552 scrollbar_controller_->Animate(time); 552 scrollbar_controller_->Animate(time);
553 ExpectScrollbarsOpacity(1); 553 ExpectScrollbarsOpacity(1);
554 554
555 // Proceed half way through the fade out animation. 555 // Proceed half way through the fade out animation.
556 time += kFadeOutDuration / 2; 556 time += kFadeDuration / 2;
557 scrollbar_controller_->Animate(time); 557 scrollbar_controller_->Animate(time);
558 ExpectScrollbarsOpacity(.5f); 558 ExpectScrollbarsOpacity(.5f);
559 559
560 // Now move the mouse near the scrollbar. It should reset opacity to 1 560 // Now move the mouse near the scrollbar. It should reset opacity to 1
561 // instantly and start animating to thick. 561 // instantly and start animating to thick.
562 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); 562 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
563 ExpectScrollbarsOpacity(1); 563 ExpectScrollbarsOpacity(1);
564 EXPECT_FLOAT_EQ(kIdleThicknessScale, 564 EXPECT_FLOAT_EQ(kIdleThicknessScale,
565 v_scrollbar_layer_->thumb_thickness_scale_factor()); 565 v_scrollbar_layer_->thumb_thickness_scale_factor());
566 EXPECT_FLOAT_EQ(kIdleThicknessScale, 566 EXPECT_FLOAT_EQ(kIdleThicknessScale,
(...skipping 18 matching lines...) Expand all
585 scrollbar_controller_->DidScrollEnd(); 585 scrollbar_controller_->DidScrollEnd();
586 586
587 EXPECT_EQ(kFadeOutDelay, client_.delay()); 587 EXPECT_EQ(kFadeOutDelay, client_.delay());
588 EXPECT_FALSE(client_.start_fade().is_null()); 588 EXPECT_FALSE(client_.start_fade().is_null());
589 EXPECT_FALSE(client_.start_fade().IsCancelled()); 589 EXPECT_FALSE(client_.start_fade().IsCancelled());
590 client_.start_fade().Run(); 590 client_.start_fade().Run();
591 scrollbar_controller_->Animate(time); 591 scrollbar_controller_->Animate(time);
592 ExpectScrollbarsOpacity(1); 592 ExpectScrollbarsOpacity(1);
593 593
594 // Fade the scrollbar out completely. 594 // Fade the scrollbar out completely.
595 time += kFadeOutDuration; 595 time += kFadeDuration;
596 scrollbar_controller_->Animate(time); 596 scrollbar_controller_->Animate(time);
597 ExpectScrollbarsOpacity(0); 597 ExpectScrollbarsOpacity(0);
598 598
599 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since 599 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since
600 // it's completely faded out. 600 // it's completely faded out.
601 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); 601 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
602 scrollbar_controller_->Animate(time); 602 scrollbar_controller_->Animate(time);
603 time += kThinningDuration; 603 time += kThinningDuration;
604 scrollbar_controller_->Animate(time); 604 scrollbar_controller_->Animate(time);
605 ExpectScrollbarsOpacity(0); 605 ExpectScrollbarsOpacity(0);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 EXPECT_TRUE(client_.start_fade().is_null() || 656 EXPECT_TRUE(client_.start_fade().is_null() ||
657 client_.start_fade().IsCancelled()); 657 client_.start_fade().IsCancelled());
658 658
659 scrollbar_controller_->Animate(time); 659 scrollbar_controller_->Animate(time);
660 ExpectScrollbarsOpacity(1); 660 ExpectScrollbarsOpacity(1);
661 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 661 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
662 EXPECT_FLOAT_EQ(kIdleThicknessScale, 662 EXPECT_FLOAT_EQ(kIdleThicknessScale,
663 h_scrollbar_layer_->thumb_thickness_scale_factor()); 663 h_scrollbar_layer_->thumb_thickness_scale_factor());
664 664
665 // Scrollbar should still be thick and visible. 665 // Scrollbar should still be thick and visible.
666 time += kFadeOutDuration; 666 time += kFadeDuration;
667 scrollbar_controller_->Animate(time); 667 scrollbar_controller_->Animate(time);
668 ExpectScrollbarsOpacity(1); 668 ExpectScrollbarsOpacity(1);
669 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 669 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
670 EXPECT_FLOAT_EQ(kIdleThicknessScale, 670 EXPECT_FLOAT_EQ(kIdleThicknessScale,
671 h_scrollbar_layer_->thumb_thickness_scale_factor()); 671 h_scrollbar_layer_->thumb_thickness_scale_factor());
672 } 672 }
673 673
674 // Tests that main thread scroll updates immediatley queue a fade out animation 674 // Tests that main thread scroll updates immediatley queue a fade out animation
675 // without requiring a ScrollEnd. 675 // without requiring a ScrollEnd.
676 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 676 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 732
733 // An fade out animation should have been enqueued. 733 // An fade out animation should have been enqueued.
734 EXPECT_EQ(kFadeOutDelay, client_.delay()); 734 EXPECT_EQ(kFadeOutDelay, client_.delay());
735 EXPECT_FALSE(client_.start_fade().is_null()); 735 EXPECT_FALSE(client_.start_fade().is_null());
736 client_.start_fade().Run(); 736 client_.start_fade().Run();
737 737
738 // Test that at half the fade duration time, the opacity is at half. 738 // Test that at half the fade duration time, the opacity is at half.
739 scrollbar_controller_->Animate(time); 739 scrollbar_controller_->Animate(time);
740 ExpectScrollbarsOpacity(1); 740 ExpectScrollbarsOpacity(1);
741 741
742 time += kFadeOutDuration / 2; 742 time += kFadeDuration / 2;
743 scrollbar_controller_->Animate(time); 743 scrollbar_controller_->Animate(time);
744 ExpectScrollbarsOpacity(.5f); 744 ExpectScrollbarsOpacity(.5f);
745 745
746 time += kFadeOutDuration / 2; 746 time += kFadeDuration / 2;
747 scrollbar_controller_->Animate(time); 747 scrollbar_controller_->Animate(time);
748 ExpectScrollbarsOpacity(0); 748 ExpectScrollbarsOpacity(0);
749 } 749 }
750 750
751 // Tests that the controller tells the client when the scrollbars hide/show. 751 // Tests that the controller tells the client when the scrollbars hide/show.
752 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) { 752 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) {
753 base::TimeTicks time; 753 base::TimeTicks time;
754 time += base::TimeDelta::FromSeconds(1); 754 time += base::TimeDelta::FromSeconds(1);
755 755
756 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 756 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
757 // Scroll to make the scrollbars visible. 757 // Scroll to make the scrollbars visible.
758 scrollbar_controller_->DidScrollBegin(); 758 scrollbar_controller_->DidScrollBegin();
759 scrollbar_controller_->DidScrollUpdate(); 759 scrollbar_controller_->DidScrollUpdate();
760 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 760 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
761 Mock::VerifyAndClearExpectations(&client_); 761 Mock::VerifyAndClearExpectations(&client_);
762 762
763 scrollbar_controller_->DidScrollEnd(); 763 scrollbar_controller_->DidScrollEnd();
764 764
765 // Play out the fade out animation. We shouldn't notify that the scrollbars 765 // Play out the fade out animation. We shouldn't notify that the scrollbars
766 // are hidden until the animation is completly over. We can (but don't have 766 // are hidden until the animation is completly over. We can (but don't have
767 // to) notify during the animation that the scrollbars are still visible. 767 // to) notify during the animation that the scrollbars are still visible.
768 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(0); 768 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(0);
769 ASSERT_FALSE(client_.start_fade().is_null()); 769 ASSERT_FALSE(client_.start_fade().is_null());
770 client_.start_fade().Run(); 770 client_.start_fade().Run();
771 scrollbar_controller_->Animate(time); 771 scrollbar_controller_->Animate(time);
772 time += kFadeOutDuration / 4; 772 time += kFadeDuration / 4;
773 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 773 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
774 scrollbar_controller_->Animate(time); 774 scrollbar_controller_->Animate(time);
775 time += kFadeOutDuration / 4; 775 time += kFadeDuration / 4;
776 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 776 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
777 scrollbar_controller_->Animate(time); 777 scrollbar_controller_->Animate(time);
778 time += kFadeOutDuration / 4; 778 time += kFadeDuration / 4;
779 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 779 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
780 scrollbar_controller_->Animate(time); 780 scrollbar_controller_->Animate(time);
781 ExpectScrollbarsOpacity(.25f); 781 ExpectScrollbarsOpacity(.25f);
782 Mock::VerifyAndClearExpectations(&client_); 782 Mock::VerifyAndClearExpectations(&client_);
783 783
784 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 784 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
785 time += kFadeOutDuration / 4; 785 time += kFadeDuration / 4;
786 scrollbar_controller_->Animate(time); 786 scrollbar_controller_->Animate(time);
787 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 787 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
788 ExpectScrollbarsOpacity(0); 788 ExpectScrollbarsOpacity(0);
789 Mock::VerifyAndClearExpectations(&client_); 789 Mock::VerifyAndClearExpectations(&client_);
790 790
791 // Calling DidScrollUpdate without a begin (i.e. update from commit) should 791 // Calling DidScrollUpdate without a begin (i.e. update from commit) should
792 // also notify. 792 // also notify.
793 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 793 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
794 scrollbar_controller_->DidScrollUpdate(); 794 scrollbar_controller_->DidScrollUpdate();
795 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 795 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 client_.start_fade().IsCancelled()); 1001 client_.start_fade().IsCancelled());
1002 1002
1003 // Mouse leave. 1003 // Mouse leave.
1004 scrollbar_controller_->DidMouseLeave(); 1004 scrollbar_controller_->DidMouseLeave();
1005 1005
1006 // An fade out animation should have been enqueued. 1006 // An fade out animation should have been enqueued.
1007 EXPECT_FALSE(client_.start_fade().is_null()); 1007 EXPECT_FALSE(client_.start_fade().is_null());
1008 EXPECT_EQ(kFadeOutDelay, client_.delay()); 1008 EXPECT_EQ(kFadeOutDelay, client_.delay());
1009 } 1009 }
1010 1010
1011 // Scrollbars should schedule a delay show when mouse hover the show scrollbar 1011 // Scrollbars should schedule a delay fade in when mouse hover the show
1012 // region of a hidden scrollbar. 1012 // scrollbar region of a hidden scrollbar.
1013 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverShow) { 1013 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverFadeIn) {
1014 base::TimeTicks time; 1014 base::TimeTicks time;
1015 time += base::TimeDelta::FromSeconds(1); 1015 time += base::TimeDelta::FromSeconds(1);
1016 1016
1017 // Move mouse hover the show scrollbar region of scrollbar. 1017 // Move mouse hover the fade in scrollbar region of scrollbar.
1018 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1018 scrollbar_controller_->DidMouseMoveNear(
1019 kMouseMoveDistanceToTriggerShow - 1); 1019 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1020 1020
1021 // An show animation should have been enqueued. 1021 // An fade in animation should have been enqueued.
1022 EXPECT_FALSE(client_.start_fade().is_null()); 1022 EXPECT_FALSE(client_.start_fade().is_null());
1023 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1023 EXPECT_FALSE(client_.start_fade().IsCancelled());
1024 EXPECT_EQ(kShowDelay, client_.delay()); 1024 EXPECT_EQ(kFadeInDelay, client_.delay());
1025 1025
1026 // Play the delay animation. 1026 // Play the delay animation.
1027 client_.start_fade().Run(); 1027 client_.start_fade().Run();
1028 EXPECT_TRUE(client_.start_fade().IsCancelled()); 1028 EXPECT_TRUE(client_.start_fade().IsCancelled());
1029
1030 scrollbar_controller_->Animate(time);
1031 time += kFadeDuration / 2;
1032 scrollbar_controller_->Animate(time);
1033
1034 ExpectScrollbarsOpacity(0.5);
1035 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1036
1037 time += kFadeDuration / 2;
1038 scrollbar_controller_->Animate(time);
1039
1040 ExpectScrollbarsOpacity(1);
1029 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 1041 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1030 } 1042 }
1031 1043
1032 // Scrollbars should not schedule a new delay show when the mouse hovers inside 1044 // Scrollbars should not schedule a new delay fade in when the mouse hovers
1033 // a scrollbar already scheduled a delay show. 1045 // inside a scrollbar already scheduled a delay fade in.
1034 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1046 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1035 MouseHoverScrollbarAndMoveInside) { 1047 MouseHoverScrollbarAndMoveInside) {
1036 base::TimeTicks time; 1048 base::TimeTicks time;
1037 time += base::TimeDelta::FromSeconds(1); 1049 time += base::TimeDelta::FromSeconds(1);
1038 1050
1039 // Move mouse hover the show scrollbar region of scrollbar. 1051 // Move mouse hover the fade in scrollbar region of scrollbar.
1040 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1052 scrollbar_controller_->DidMouseMoveNear(
1041 kMouseMoveDistanceToTriggerShow - 1); 1053 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1042 1054
1043 // An show animation should have been enqueued. 1055 // An fade in animation should have been enqueued.
1044 EXPECT_FALSE(client_.start_fade().is_null()); 1056 EXPECT_FALSE(client_.start_fade().is_null());
1045 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1057 EXPECT_FALSE(client_.start_fade().IsCancelled());
1046 EXPECT_EQ(kShowDelay, client_.delay()); 1058 EXPECT_EQ(kFadeInDelay, client_.delay());
1047 1059
1048 base::Closure& fade = client_.start_fade(); 1060 base::Closure& fade = client_.start_fade();
1049 // Move mouse still hover the show scrollbar region of scrollbar should not 1061 // Move mouse still hover the fade in scrollbar region of scrollbar should not
1050 // post a new show. 1062 // post a new fade in.
1051 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1063 scrollbar_controller_->DidMouseMoveNear(
1052 kMouseMoveDistanceToTriggerShow - 2); 1064 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 2);
1053 1065
1054 EXPECT_TRUE(fade.Equals(client_.start_fade())); 1066 EXPECT_TRUE(fade.Equals(client_.start_fade()));
1055 } 1067 }
1056 1068
1057 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then 1069 // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then
1058 // move far away. 1070 // move far away.
1059 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1071 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1060 MouseHoverThenOutShouldCancelShow) { 1072 MouseHoverThenOutShouldCancelFadeIn) {
1061 base::TimeTicks time; 1073 base::TimeTicks time;
1062 time += base::TimeDelta::FromSeconds(1); 1074 time += base::TimeDelta::FromSeconds(1);
1063 1075
1064 // Move mouse hover the show scrollbar region of scrollbar. 1076 // Move mouse hover the fade in scrollbar region of scrollbar.
1065 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1077 scrollbar_controller_->DidMouseMoveNear(
1066 kMouseMoveDistanceToTriggerShow - 1); 1078 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1067 1079
1068 // An show animation should have been enqueued. 1080 // An fade in animation should have been enqueued.
1069 EXPECT_FALSE(client_.start_fade().is_null()); 1081 EXPECT_FALSE(client_.start_fade().is_null());
1070 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1082 EXPECT_FALSE(client_.start_fade().IsCancelled());
1071 EXPECT_EQ(kShowDelay, client_.delay()); 1083 EXPECT_EQ(kFadeInDelay, client_.delay());
1072 1084
1073 // Move mouse far away,delay show should be canceled. 1085 // Move mouse far away,delay fade in should be canceled.
1074 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1086 scrollbar_controller_->DidMouseMoveNear(VERTICAL,
1075 kMouseMoveDistanceToTriggerShow); 1087 kMouseMoveDistanceToTriggerFadeIn);
1076 EXPECT_TRUE(client_.start_fade().is_null() || 1088 EXPECT_TRUE(client_.start_fade().is_null() ||
1077 client_.start_fade().IsCancelled()); 1089 client_.start_fade().IsCancelled());
1078 } 1090 }
1079 1091
1080 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then 1092 // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then
1081 // move out of window. 1093 // move out of window.
1082 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1094 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1083 MouseHoverThenLeaveShouldCancelShowThenEnterShouldShow) { 1095 MouseHoverThenLeaveShouldCancelShowThenEnterShouldFadeIn) {
1084 base::TimeTicks time; 1096 base::TimeTicks time;
1085 time += base::TimeDelta::FromSeconds(1); 1097 time += base::TimeDelta::FromSeconds(1);
1086 1098
1087 // Move mouse hover the show scrollbar region of scrollbar. 1099 // Move mouse hover the fade in scrollbar region of scrollbar.
1088 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1100 scrollbar_controller_->DidMouseMoveNear(
1089 kMouseMoveDistanceToTriggerShow - 1); 1101 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1090 1102
1091 // An show animation should have been enqueued. 1103 // An fade in animation should have been enqueued.
1092 EXPECT_FALSE(client_.start_fade().is_null()); 1104 EXPECT_FALSE(client_.start_fade().is_null());
1093 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1105 EXPECT_FALSE(client_.start_fade().IsCancelled());
1094 EXPECT_EQ(kShowDelay, client_.delay()); 1106 EXPECT_EQ(kFadeInDelay, client_.delay());
1095 1107
1096 // Move mouse out of window,delay show should be canceled. 1108 // Move mouse out of window,delay fade in should be canceled.
1097 scrollbar_controller_->DidMouseLeave(); 1109 scrollbar_controller_->DidMouseLeave();
1098 EXPECT_TRUE(client_.start_fade().is_null() || 1110 EXPECT_TRUE(client_.start_fade().is_null() ||
1099 client_.start_fade().IsCancelled()); 1111 client_.start_fade().IsCancelled());
1100 1112
1101 // Move mouse hover the show scrollbar region of scrollbar. 1113 // Move mouse hover the fade in scrollbar region of scrollbar.
1102 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1114 scrollbar_controller_->DidMouseMoveNear(
1103 kMouseMoveDistanceToTriggerShow - 1); 1115 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1104 1116
1105 // An show animation should have been enqueued. 1117 // An fade in animation should have been enqueued.
1106 EXPECT_FALSE(client_.start_fade().is_null()); 1118 EXPECT_FALSE(client_.start_fade().is_null());
1107 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1119 EXPECT_FALSE(client_.start_fade().IsCancelled());
1108 EXPECT_EQ(kShowDelay, client_.delay()); 1120 EXPECT_EQ(kFadeInDelay, client_.delay());
1109 1121
1110 // Play the delay animation. 1122 // Play the delay animation.
1111 client_.start_fade().Run(); 1123 client_.start_fade().Run();
1112 EXPECT_TRUE(client_.start_fade().IsCancelled()); 1124 EXPECT_TRUE(client_.start_fade().IsCancelled());
1125
1126 scrollbar_controller_->Animate(time);
1127 time += kFadeDuration;
1128 scrollbar_controller_->Animate(time);
1129
1113 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 1130 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1114 } 1131 }
1115 1132
1116 class ScrollbarAnimationControllerAndroidTest 1133 class ScrollbarAnimationControllerAndroidTest
1117 : public testing::Test, 1134 : public testing::Test,
1118 public ScrollbarAnimationControllerClient { 1135 public ScrollbarAnimationControllerClient {
1119 public: 1136 public:
1120 ScrollbarAnimationControllerAndroidTest() 1137 ScrollbarAnimationControllerAndroidTest()
1121 : host_impl_(&task_runner_provider_, &task_graph_runner_), 1138 : host_impl_(&task_runner_provider_, &task_graph_runner_),
1122 did_request_redraw_(false), 1139 did_request_redraw_(false),
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1614 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1598 1615
1599 time += base::TimeDelta::FromSeconds(1); 1616 time += base::TimeDelta::FromSeconds(1);
1600 scrollbar_controller_->DidScrollEnd(); 1617 scrollbar_controller_->DidScrollEnd();
1601 EXPECT_FALSE(did_request_animate_); 1618 EXPECT_FALSE(did_request_animate_);
1602 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1619 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1603 } 1620 }
1604 1621
1605 } // namespace 1622 } // namespace
1606 } // namespace cc 1623 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698