Use Default PasswordStore with Ozone.
[chromium-blink-merge.git] / cc / animation / scrollbar_animation_controller_linear_fade_unittest.cc
blobb4c1160b081bae8f1cc600f8c4335e0efed434fa
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/animation/scrollbar_animation_controller_linear_fade.h"
7 #include "cc/layers/painted_scrollbar_layer_impl.h"
8 #include "cc/test/fake_impl_proxy.h"
9 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace cc {
13 namespace {
15 class ScrollbarAnimationControllerLinearFadeTest : public testing::Test {
16 public:
17 ScrollbarAnimationControllerLinearFadeTest() : host_impl_(&proxy_) {}
19 protected:
20 virtual void SetUp() {
21 scroll_layer_ = LayerImpl::Create(host_impl_.active_tree(), 1);
22 scrollbar_layer_ = PaintedScrollbarLayerImpl::Create(
23 host_impl_.active_tree(), 2, HORIZONTAL);
25 scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(50, 50));
26 scroll_layer_->SetBounds(gfx::Size(50, 50));
27 scroll_layer_->SetHorizontalScrollbarLayer(scrollbar_layer_.get());
29 scrollbar_controller_ = ScrollbarAnimationControllerLinearFade::Create(
30 scroll_layer_.get(),
31 base::TimeDelta::FromSeconds(2),
32 base::TimeDelta::FromSeconds(3));
35 FakeImplProxy proxy_;
36 FakeLayerTreeHostImpl host_impl_;
37 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_;
38 scoped_ptr<LayerImpl> scroll_layer_;
39 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar_layer_;
42 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HiddenInBegin) {
43 scrollbar_controller_->Animate(base::TimeTicks());
44 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
47 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
48 HiddenAfterNonScrollingGesture) {
49 scrollbar_controller_->DidScrollGestureBegin();
50 EXPECT_FALSE(scrollbar_controller_->IsAnimating());
51 EXPECT_FALSE(scrollbar_controller_->Animate(base::TimeTicks()));
52 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
54 base::TimeTicks time;
55 time += base::TimeDelta::FromSeconds(100);
56 EXPECT_FALSE(scrollbar_controller_->Animate(time));
57 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
58 scrollbar_controller_->DidScrollGestureEnd(time);
60 time += base::TimeDelta::FromSeconds(100);
61 EXPECT_FALSE(scrollbar_controller_->IsAnimating());
62 EXPECT_FALSE(scrollbar_controller_->Animate(time));
63 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
66 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollingGesture) {
67 base::TimeTicks time;
68 time += base::TimeDelta::FromSeconds(1);
69 scrollbar_controller_->DidScrollGestureBegin();
70 scrollbar_controller_->Animate(time);
71 EXPECT_FALSE(scrollbar_controller_->IsAnimating());
72 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
74 EXPECT_FALSE(scrollbar_controller_->DidScrollUpdate(time));
75 EXPECT_FALSE(scrollbar_controller_->IsAnimating());
76 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
78 time += base::TimeDelta::FromSeconds(100);
79 scrollbar_controller_->Animate(time);
80 EXPECT_FALSE(scrollbar_controller_->IsAnimating());
81 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
82 scrollbar_controller_->DidScrollGestureEnd(time);
84 EXPECT_TRUE(scrollbar_controller_->IsAnimating());
85 EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
87 time += base::TimeDelta::FromSeconds(1);
88 scrollbar_controller_->Animate(time);
89 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
91 time += base::TimeDelta::FromSeconds(1);
92 scrollbar_controller_->Animate(time);
93 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
95 time += base::TimeDelta::FromSeconds(1);
96 scrollbar_controller_->Animate(time);
97 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity());
99 time += base::TimeDelta::FromSeconds(1);
100 scrollbar_controller_->Animate(time);
101 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity());
103 time += base::TimeDelta::FromSeconds(1);
105 scrollbar_controller_->DidScrollGestureBegin();
106 EXPECT_FALSE(scrollbar_controller_->DidScrollUpdate(time));
107 scrollbar_controller_->DidScrollGestureEnd(time);
109 time += base::TimeDelta::FromSeconds(1);
110 scrollbar_controller_->Animate(time);
111 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
113 time += base::TimeDelta::FromSeconds(1);
114 scrollbar_controller_->Animate(time);
115 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
117 time += base::TimeDelta::FromSeconds(1);
118 scrollbar_controller_->Animate(time);
119 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity());
121 time += base::TimeDelta::FromSeconds(1);
122 scrollbar_controller_->Animate(time);
123 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity());
125 time += base::TimeDelta::FromSeconds(1);
126 scrollbar_controller_->Animate(time);
127 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
130 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByProgrammaticScroll) {
131 base::TimeTicks time;
132 time += base::TimeDelta::FromSeconds(1);
133 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
134 EXPECT_TRUE(scrollbar_controller_->IsAnimating());
135 EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds());
136 scrollbar_controller_->Animate(time);
137 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
139 time += base::TimeDelta::FromSeconds(1);
140 scrollbar_controller_->Animate(time);
141 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
142 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
144 time += base::TimeDelta::FromSeconds(1);
145 scrollbar_controller_->Animate(time);
146 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
148 time += base::TimeDelta::FromSeconds(1);
149 scrollbar_controller_->Animate(time);
150 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
152 time += base::TimeDelta::FromSeconds(1);
153 scrollbar_controller_->Animate(time);
154 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity());
156 time += base::TimeDelta::FromSeconds(1);
157 scrollbar_controller_->Animate(time);
158 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity());
160 time += base::TimeDelta::FromSeconds(1);
161 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
162 time += base::TimeDelta::FromSeconds(1);
163 scrollbar_controller_->Animate(time);
164 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
166 time += base::TimeDelta::FromSeconds(1);
167 scrollbar_controller_->Animate(time);
168 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
170 time += base::TimeDelta::FromSeconds(1);
171 scrollbar_controller_->Animate(time);
172 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity());
174 time += base::TimeDelta::FromSeconds(1);
175 scrollbar_controller_->Animate(time);
176 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity());
178 time += base::TimeDelta::FromSeconds(1);
179 scrollbar_controller_->Animate(time);
180 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
183 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
184 AnimationPreservedByNonScrollingGesture) {
185 base::TimeTicks time;
186 time += base::TimeDelta::FromSeconds(1);
187 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
188 EXPECT_TRUE(scrollbar_controller_->IsAnimating());
189 scrollbar_controller_->Animate(time);
190 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
192 time += base::TimeDelta::FromSeconds(3);
193 scrollbar_controller_->Animate(time);
194 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity());
196 scrollbar_controller_->DidScrollGestureBegin();
197 EXPECT_TRUE(scrollbar_controller_->IsAnimating());
198 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity());
200 time += base::TimeDelta::FromSeconds(1);
201 scrollbar_controller_->Animate(time);
202 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity());
204 scrollbar_controller_->DidScrollGestureEnd(time);
205 EXPECT_TRUE(scrollbar_controller_->IsAnimating());
206 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity());
208 time += base::TimeDelta::FromSeconds(1);
209 EXPECT_FALSE(scrollbar_controller_->Animate(time));
210 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
213 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
214 AnimationOverriddenByScrollingGesture) {
215 base::TimeTicks time;
216 time += base::TimeDelta::FromSeconds(1);
217 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time));
218 EXPECT_TRUE(scrollbar_controller_->IsAnimating());
219 scrollbar_controller_->Animate(time);
220 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
222 time += base::TimeDelta::FromSeconds(3);
223 scrollbar_controller_->Animate(time);
224 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity());
226 scrollbar_controller_->DidScrollGestureBegin();
227 EXPECT_TRUE(scrollbar_controller_->IsAnimating());
228 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity());
230 time += base::TimeDelta::FromSeconds(1);
231 scrollbar_controller_->Animate(time);
232 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity());
234 time += base::TimeDelta::FromSeconds(1);
235 EXPECT_FALSE(scrollbar_controller_->DidScrollUpdate(time));
236 EXPECT_FALSE(scrollbar_controller_->IsAnimating());
237 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity());
239 time += base::TimeDelta::FromSeconds(1);
240 scrollbar_controller_->DidScrollGestureEnd(time);
241 EXPECT_TRUE(scrollbar_controller_->IsAnimating());
242 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity());
245 } // namespace
246 } // namespace cc