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

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

Issue 2554913002: Prevent overlay scrollbars expand or hover together (Closed)
Patch Set: bokan comment addressed. Created 3 years, 12 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_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);
534 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
482 EXPECT_FLOAT_EQ(kIdleThicknessScale, 535 EXPECT_FLOAT_EQ(kIdleThicknessScale,
483 scrollbar_layer_->thumb_thickness_scale_factor()); 536 h_scrollbar_layer_->thumb_thickness_scale_factor());
484 537
485 client_.start_fade().Reset(); 538 client_.start_fade().Reset();
486 539
487 // Now try to capture the scrollbar. It shouldn't do anything since it's 540 // Now try to capture the scrollbar. It shouldn't do anything since it's
488 // completely faded out. 541 // completely faded out.
489 scrollbar_controller_->DidMouseDown(); 542 scrollbar_controller_->DidMouseDown();
490 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); 543 ExpectScrollbarsOpacity(0);
544 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
491 EXPECT_FLOAT_EQ(kIdleThicknessScale, 545 EXPECT_FLOAT_EQ(kIdleThicknessScale,
492 scrollbar_layer_->thumb_thickness_scale_factor()); 546 h_scrollbar_layer_->thumb_thickness_scale_factor());
493 EXPECT_TRUE(client_.start_fade().is_null()); 547 EXPECT_TRUE(client_.start_fade().is_null());
494 548
495 // Similarly, releasing the scrollbar should have no effect. 549 // Similarly, releasing the scrollbar should have no effect.
496 scrollbar_controller_->DidMouseUp(); 550 scrollbar_controller_->DidMouseUp();
497 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); 551 ExpectScrollbarsOpacity(0);
552 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
498 EXPECT_FLOAT_EQ(kIdleThicknessScale, 553 EXPECT_FLOAT_EQ(kIdleThicknessScale,
499 scrollbar_layer_->thumb_thickness_scale_factor()); 554 h_scrollbar_layer_->thumb_thickness_scale_factor());
500 EXPECT_TRUE(client_.start_fade().is_null()); 555 EXPECT_TRUE(client_.start_fade().is_null());
501 } 556 }
502 557
503 // Initiate a scroll when the pointer is already near the scrollbar. It should 558 // Initiate a scroll when the pointer is already near the scrollbar. It should
504 // appear thick and remain thick. 559 // appear thick and remain thick.
505 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { 560 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) {
506 base::TimeTicks time; 561 base::TimeTicks time;
507 time += base::TimeDelta::FromSeconds(1); 562 time += base::TimeDelta::FromSeconds(1);
508 563
509 scrollbar_controller_->DidMouseMoveNear(1); 564 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
510 scrollbar_controller_->Animate(time); 565 scrollbar_controller_->Animate(time);
511 time += kThinningDuration; 566 time += kThinningDuration;
512 567
513 // Since the scrollbar isn't visible yet (because we haven't scrolled), we 568 // Since the scrollbar isn't visible yet (because we haven't scrolled), we
514 // shouldn't have applied the thickening. 569 // shouldn't have applied the thickening.
515 scrollbar_controller_->Animate(time); 570 scrollbar_controller_->Animate(time);
571 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
516 EXPECT_FLOAT_EQ(kIdleThicknessScale, 572 EXPECT_FLOAT_EQ(kIdleThicknessScale,
517 scrollbar_layer_->thumb_thickness_scale_factor()); 573 h_scrollbar_layer_->thumb_thickness_scale_factor());
518 574
519 scrollbar_controller_->DidScrollBegin(); 575 scrollbar_controller_->DidScrollBegin();
520 scrollbar_controller_->DidScrollUpdate(false); 576 scrollbar_controller_->DidScrollUpdate(false);
521 577
522 // Now that we've received a scroll, we should be thick without an animation. 578 // 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()); 579 ExpectScrollbarsOpacity(1);
524 580
525 // An animation for the fade should be either null or cancelled, since 581 // An animation for the fade should be either null or cancelled, since
526 // mouse is still near the scrollbar. 582 // mouse is still near the scrollbar.
527 scrollbar_controller_->DidScrollEnd(); 583 scrollbar_controller_->DidScrollEnd();
528 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); 584 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
529 EXPECT_TRUE(client_.start_fade().is_null() || 585 EXPECT_TRUE(client_.start_fade().is_null() ||
530 client_.start_fade().IsCancelled()); 586 client_.start_fade().IsCancelled());
531 587
532 scrollbar_controller_->Animate(time); 588 scrollbar_controller_->Animate(time);
533 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); 589 ExpectScrollbarsOpacity(1);
534 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 590 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
591 EXPECT_FLOAT_EQ(kIdleThicknessScale,
592 h_scrollbar_layer_->thumb_thickness_scale_factor());
535 593
536 // Scrollbar should still be thick and visible. 594 // Scrollbar should still be thick and visible.
537 time += kFadeDuration; 595 time += kFadeDuration;
538 scrollbar_controller_->Animate(time); 596 scrollbar_controller_->Animate(time);
539 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); 597 ExpectScrollbarsOpacity(1);
540 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 598 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, 599 EXPECT_FLOAT_EQ(kIdleThicknessScale,
558 scrollbar_layer_->thumb_thickness_scale_factor()); 600 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 } 601 }
892 602
893 // Tests that main thread scroll updates immediatley queue a fade animation 603 // Tests that main thread scroll updates immediatley queue a fade animation
894 // without requiring a ScrollEnd. 604 // without requiring a ScrollEnd.
895 TEST_F(ScrollbarAnimationControllerThinningTest, MainThreadScrollQueuesFade) { 605 TEST_F(ScrollbarAnimationControllerThinningTest, MainThreadScrollQueuesFade) {
896 ASSERT_TRUE(client_.start_fade().is_null()); 606 ASSERT_TRUE(client_.start_fade().is_null());
897 607
898 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update 608 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update
899 // so we should schedule a fade animation without waiting for a ScrollEnd 609 // so we should schedule a fade animation without waiting for a ScrollEnd
900 // (which will never come). 610 // (which will never come).
(...skipping 29 matching lines...) Expand all
930 scrollbar_controller_->DidScrollBegin(); 640 scrollbar_controller_->DidScrollBegin();
931 scrollbar_controller_->DidScrollUpdate(true); 641 scrollbar_controller_->DidScrollUpdate(true);
932 scrollbar_controller_->DidScrollEnd(); 642 scrollbar_controller_->DidScrollEnd();
933 643
934 EXPECT_FALSE(client_.start_fade().is_null()); 644 EXPECT_FALSE(client_.start_fade().is_null());
935 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); 645 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
936 } 646 }
937 647
938 // Tests that the fade effect is animated. 648 // Tests that the fade effect is animated.
939 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAnimated) { 649 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAnimated) {
650 base::TimeTicks time;
651 time += base::TimeDelta::FromSeconds(1);
652
940 // Scroll to make the scrollbars visible. 653 // Scroll to make the scrollbars visible.
941 scrollbar_controller_->DidScrollBegin(); 654 scrollbar_controller_->DidScrollBegin();
942 scrollbar_controller_->DidScrollUpdate(false); 655 scrollbar_controller_->DidScrollUpdate(false);
943 scrollbar_controller_->DidScrollEnd(); 656 scrollbar_controller_->DidScrollEnd();
944 657
945 // Appearance is instant. 658 // Appearance is instant.
946 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); 659 ExpectScrollbarsOpacity(1);
947 660
948 // An animation should have been enqueued. 661 // An animation should have been enqueued.
949 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); 662 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
950 EXPECT_FALSE(client_.start_fade().is_null()); 663 EXPECT_FALSE(client_.start_fade().is_null());
951 client_.start_fade().Run(); 664 client_.start_fade().Run();
952 665
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. 666 // Test that at half the fade duration time, the opacity is at half.
957 scrollbar_controller_->Animate(time); 667 scrollbar_controller_->Animate(time);
958 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); 668 ExpectScrollbarsOpacity(1);
959 669
960 time += kFadeDuration / 2; 670 time += kFadeDuration / 2;
961 scrollbar_controller_->Animate(time); 671 scrollbar_controller_->Animate(time);
962 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); 672 ExpectScrollbarsOpacity(.5f);
963 673
964 time += kFadeDuration / 2; 674 time += kFadeDuration / 2;
965 scrollbar_controller_->Animate(time); 675 scrollbar_controller_->Animate(time);
966 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); 676 ExpectScrollbarsOpacity(0);
967 } 677 }
968 678
969 // Tests that the controller tells the client when the scrollbars hide/show. 679 // Tests that the controller tells the client when the scrollbars hide/show.
970 TEST_F(ScrollbarAnimationControllerThinningTest, NotifyChangedVisibility) { 680 TEST_F(ScrollbarAnimationControllerThinningTest, NotifyChangedVisibility) {
971 base::TimeTicks time; 681 base::TimeTicks time;
972 time += base::TimeDelta::FromSeconds(1); 682 time += base::TimeDelta::FromSeconds(1);
973 683
974 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 684 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
975 // Scroll to make the scrollbars visible. 685 // Scroll to make the scrollbars visible.
976 scrollbar_controller_->DidScrollBegin(); 686 scrollbar_controller_->DidScrollBegin();
(...skipping 12 matching lines...) Expand all
989 scrollbar_controller_->Animate(time); 699 scrollbar_controller_->Animate(time);
990 time += kFadeDuration / 4; 700 time += kFadeDuration / 4;
991 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 701 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
992 scrollbar_controller_->Animate(time); 702 scrollbar_controller_->Animate(time);
993 time += kFadeDuration / 4; 703 time += kFadeDuration / 4;
994 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 704 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
995 scrollbar_controller_->Animate(time); 705 scrollbar_controller_->Animate(time);
996 time += kFadeDuration / 4; 706 time += kFadeDuration / 4;
997 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 707 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
998 scrollbar_controller_->Animate(time); 708 scrollbar_controller_->Animate(time);
999 EXPECT_FLOAT_EQ(0.25f, scrollbar_layer_->Opacity()); 709 ExpectScrollbarsOpacity(.25f);
1000 Mock::VerifyAndClearExpectations(&client_); 710 Mock::VerifyAndClearExpectations(&client_);
1001 711
1002 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 712 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
1003 time += kFadeDuration / 4; 713 time += kFadeDuration / 4;
1004 scrollbar_controller_->Animate(time); 714 scrollbar_controller_->Animate(time);
1005 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 715 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
1006 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); 716 ExpectScrollbarsOpacity(0);
1007 Mock::VerifyAndClearExpectations(&client_); 717 Mock::VerifyAndClearExpectations(&client_);
1008 718
1009 // Calling DidScrollUpdate without a begin (i.e. update from commit) should 719 // Calling DidScrollUpdate without a begin (i.e. update from commit) should
1010 // also notify. 720 // also notify.
1011 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 721 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
1012 scrollbar_controller_->DidScrollUpdate(false); 722 scrollbar_controller_->DidScrollUpdate(false);
1013 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 723 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1014 Mock::VerifyAndClearExpectations(&client_); 724 Mock::VerifyAndClearExpectations(&client_);
1015 } 725 }
1016 726
727 // Move the pointer near each scrollbar. Confirm it gets thick and narrow when
728 // moved away.
729 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearEach) {
730 base::TimeTicks time;
731 time += base::TimeDelta::FromSeconds(1);
732
733 // Scroll to make the scrollbars visible.
734 scrollbar_controller_->DidScrollBegin();
735 scrollbar_controller_->DidScrollUpdate(false);
736 scrollbar_controller_->DidScrollEnd();
737
738 // Near Vertical Scrollbar
739 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
740 scrollbar_controller_->Animate(time);
741 ExpectScrollbarsOpacity(1);
742 EXPECT_FLOAT_EQ(kIdleThicknessScale,
743 v_scrollbar_layer_->thumb_thickness_scale_factor());
744 EXPECT_FLOAT_EQ(kIdleThicknessScale,
745 h_scrollbar_layer_->thumb_thickness_scale_factor());
746
747 // Should animate to thickened.
748 time += kThinningDuration;
749 scrollbar_controller_->Animate(time);
750 ExpectScrollbarsOpacity(1);
751 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
752 EXPECT_FLOAT_EQ(kIdleThicknessScale,
753 h_scrollbar_layer_->thumb_thickness_scale_factor());
754
755 // Subsequent moves within the nearness threshold should not change anything.
756 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 2);
757 scrollbar_controller_->Animate(time);
758 time += base::TimeDelta::FromSeconds(10);
759 scrollbar_controller_->Animate(time);
760 ExpectScrollbarsOpacity(1);
761 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
762 EXPECT_FLOAT_EQ(kIdleThicknessScale,
763 h_scrollbar_layer_->thumb_thickness_scale_factor());
764
765 // Now move away from bar.
766 scrollbar_controller_->DidMouseMoveNear(
767 VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation);
768 scrollbar_controller_->Animate(time);
769 time += kThinningDuration;
770 scrollbar_controller_->Animate(time);
771 ExpectScrollbarsOpacity(1);
772 EXPECT_FLOAT_EQ(kIdleThicknessScale,
773 v_scrollbar_layer_->thumb_thickness_scale_factor());
774 EXPECT_FLOAT_EQ(kIdleThicknessScale,
775 h_scrollbar_layer_->thumb_thickness_scale_factor());
776
777 // Near Horizontal Scrollbar
778 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 2);
779 scrollbar_controller_->Animate(time);
780 ExpectScrollbarsOpacity(1);
781 EXPECT_FLOAT_EQ(kIdleThicknessScale,
782 v_scrollbar_layer_->thumb_thickness_scale_factor());
783 EXPECT_FLOAT_EQ(kIdleThicknessScale,
784 h_scrollbar_layer_->thumb_thickness_scale_factor());
785
786 // Should animate to thickened.
787 time += kThinningDuration;
788 scrollbar_controller_->Animate(time);
789 ExpectScrollbarsOpacity(1);
790 EXPECT_FLOAT_EQ(kIdleThicknessScale,
791 v_scrollbar_layer_->thumb_thickness_scale_factor());
792 EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
793
794 // Subsequent moves within the nearness threshold should not change anything.
795 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1);
796 scrollbar_controller_->Animate(time);
797 time += base::TimeDelta::FromSeconds(10);
798 scrollbar_controller_->Animate(time);
799 ExpectScrollbarsOpacity(1);
800 EXPECT_FLOAT_EQ(kIdleThicknessScale,
801 v_scrollbar_layer_->thumb_thickness_scale_factor());
802 EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
803
804 // Now move away from bar.
805 scrollbar_controller_->DidMouseMoveNear(
806 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation);
807 scrollbar_controller_->Animate(time);
808 time += kThinningDuration;
809 scrollbar_controller_->Animate(time);
810 ExpectScrollbarsOpacity(1);
811 EXPECT_FLOAT_EQ(kIdleThicknessScale,
812 v_scrollbar_layer_->thumb_thickness_scale_factor());
813 EXPECT_FLOAT_EQ(kIdleThicknessScale,
814 h_scrollbar_layer_->thumb_thickness_scale_factor());
815
816 // An animation should have been enqueued.
817 EXPECT_FALSE(client_.start_fade().is_null());
818 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
819 }
820
821 // Move mouse near both scrollbars at the same time.
822 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearBoth) {
823 base::TimeTicks time;
824 time += base::TimeDelta::FromSeconds(1);
825
826 // Scroll to make the scrollbars visible.
827 scrollbar_controller_->DidScrollBegin();
828 scrollbar_controller_->DidScrollUpdate(false);
829 scrollbar_controller_->DidScrollEnd();
830
831 // Near both Scrollbar
832 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
833 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1);
834 scrollbar_controller_->Animate(time);
835 ExpectScrollbarsOpacity(1);
836 EXPECT_FLOAT_EQ(kIdleThicknessScale,
837 v_scrollbar_layer_->thumb_thickness_scale_factor());
838 EXPECT_FLOAT_EQ(kIdleThicknessScale,
839 h_scrollbar_layer_->thumb_thickness_scale_factor());
840
841 // Should animate to thickened.
842 time += kThinningDuration;
843 scrollbar_controller_->Animate(time);
844 ExpectScrollbarsOpacity(1);
845 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
846 EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
847 }
848
849 // Move mouse from one to the other scrollbar before animation is finished, then
850 // away before animation finished.
851 TEST_F(ScrollbarAnimationControllerThinningTest,
852 MouseNearOtherBeforeAnimationFinished) {
853 base::TimeTicks time;
854 time += base::TimeDelta::FromSeconds(1);
855
856 // Scroll to make the scrollbars visible.
857 scrollbar_controller_->DidScrollBegin();
858 scrollbar_controller_->DidScrollUpdate(false);
859 scrollbar_controller_->DidScrollEnd();
860
861 // Near Vertical Scrollbar.
862 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
863 scrollbar_controller_->Animate(time);
864 ExpectScrollbarsOpacity(1);
865 EXPECT_FLOAT_EQ(kIdleThicknessScale,
866 v_scrollbar_layer_->thumb_thickness_scale_factor());
867 EXPECT_FLOAT_EQ(kIdleThicknessScale,
868 h_scrollbar_layer_->thumb_thickness_scale_factor());
869
870 // Vertical Scrollbar animate to half thickened.
871 time += kThinningDuration / 2;
872 scrollbar_controller_->Animate(time);
873 ExpectScrollbarsOpacity(1);
874 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2,
875 v_scrollbar_layer_->thumb_thickness_scale_factor());
876 EXPECT_FLOAT_EQ(kIdleThicknessScale,
877 h_scrollbar_layer_->thumb_thickness_scale_factor());
878
879 // Away Vertical Scrollbar and near Horizontal Scrollbar.
880 scrollbar_controller_->DidMouseMoveNear(
881 VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation);
882 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1);
883 scrollbar_controller_->Animate(time);
884
885 // Vertical Scrollbar animate to thin. Horizontal Scrollbar animate to
886 // thickened.
887 time += kThinningDuration;
888 scrollbar_controller_->Animate(time);
889 ExpectScrollbarsOpacity(1);
890 EXPECT_FLOAT_EQ(kIdleThicknessScale,
891 v_scrollbar_layer_->thumb_thickness_scale_factor());
892 EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
893
894 // Away Horizontal Scrollbar.
895 scrollbar_controller_->DidMouseMoveNear(
896 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation);
897 scrollbar_controller_->Animate(time);
898
899 // Horizontal Scrollbar animate to thin.
900 time += kThinningDuration;
901 scrollbar_controller_->Animate(time);
902 ExpectScrollbarsOpacity(1);
903 EXPECT_FLOAT_EQ(kIdleThicknessScale,
904 v_scrollbar_layer_->thumb_thickness_scale_factor());
905 EXPECT_FLOAT_EQ(kIdleThicknessScale,
906 h_scrollbar_layer_->thumb_thickness_scale_factor());
907
908 // An animation should have been enqueued.
909 EXPECT_FALSE(client_.start_fade().is_null());
910 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
911 }
912
1017 } // namespace 913 } // namespace
1018 } // namespace cc 914 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698