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

Side by Side Diff: cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc

Issue 655783004: Hide scrollbars when their dimensions are not scrollable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed can_scroll_orientation() -> CanScrollOrientation() Created 6 years, 2 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 2012 The Chromium Authors. All rights reserved. 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 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/animation/scrollbar_animation_controller_linear_fade.h" 5 #include "cc/animation/scrollbar_animation_controller_linear_fade.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_proxy.h" 8 #include "cc/test/fake_impl_proxy.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/test_shared_bitmap_manager.h" 11 #include "cc/test/test_shared_bitmap_manager.h"
12 #include "cc/trees/layer_tree_impl.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 14
13 namespace cc { 15 namespace cc {
14 namespace { 16 namespace {
15 17
16 class ScrollbarAnimationControllerLinearFadeTest 18 class ScrollbarAnimationControllerLinearFadeTest
17 : public testing::Test, 19 : public testing::Test,
18 public ScrollbarAnimationControllerClient { 20 public ScrollbarAnimationControllerClient {
19 public: 21 public:
20 ScrollbarAnimationControllerLinearFadeTest() 22 ScrollbarAnimationControllerLinearFadeTest()
(...skipping 13 matching lines...) Expand all
34 const int kThumbThickness = 10; 36 const int kThumbThickness = 10;
35 const int kTrackStart = 0; 37 const int kTrackStart = 0;
36 const bool kIsLeftSideVerticalScrollbar = false; 38 const bool kIsLeftSideVerticalScrollbar = false;
37 const bool kIsOverlayScrollbar = true; // Allow opacity animations. 39 const bool kIsOverlayScrollbar = true; // Allow opacity animations.
38 40
39 scoped_ptr<LayerImpl> scroll_layer = 41 scoped_ptr<LayerImpl> scroll_layer =
40 LayerImpl::Create(host_impl_.active_tree(), 1); 42 LayerImpl::Create(host_impl_.active_tree(), 1);
41 scrollbar_layer_ = 43 scrollbar_layer_ =
42 SolidColorScrollbarLayerImpl::Create(host_impl_.active_tree(), 44 SolidColorScrollbarLayerImpl::Create(host_impl_.active_tree(),
43 2, 45 2,
44 HORIZONTAL, 46 orientation(),
45 kThumbThickness, 47 kThumbThickness,
46 kTrackStart, 48 kTrackStart,
47 kIsLeftSideVerticalScrollbar, 49 kIsLeftSideVerticalScrollbar,
48 kIsOverlayScrollbar); 50 kIsOverlayScrollbar);
49 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); 51 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3);
50 scroll_layer->SetScrollClipLayer(clip_layer_->id()); 52 scroll_layer->SetScrollClipLayer(clip_layer_->id());
51 LayerImpl* scroll_layer_ptr = scroll_layer.get(); 53 LayerImpl* scroll_layer_ptr = scroll_layer.get();
52 clip_layer_->AddChild(scroll_layer.Pass()); 54 clip_layer_->AddChild(scroll_layer.Pass());
53 55
54 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), 56 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(),
55 clip_layer_->id()); 57 clip_layer_->id());
56 clip_layer_->SetBounds(gfx::Size(100, 100)); 58 clip_layer_->SetBounds(gfx::Size(100, 100));
57 scroll_layer_ptr->SetBounds(gfx::Size(50, 50)); 59 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
58 60
59 scrollbar_controller_ = ScrollbarAnimationControllerLinearFade::Create( 61 scrollbar_controller_ = ScrollbarAnimationControllerLinearFade::Create(
60 scroll_layer_ptr, 62 scroll_layer_ptr,
61 this, 63 this,
62 base::TimeDelta::FromSeconds(2), 64 base::TimeDelta::FromSeconds(2),
63 base::TimeDelta::FromSeconds(5), 65 base::TimeDelta::FromSeconds(5),
64 base::TimeDelta::FromSeconds(3)); 66 base::TimeDelta::FromSeconds(3));
65 } 67 }
66 68
69 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; }
70
67 FakeImplProxy proxy_; 71 FakeImplProxy proxy_;
68 TestSharedBitmapManager shared_bitmap_manager_; 72 TestSharedBitmapManager shared_bitmap_manager_;
69 FakeLayerTreeHostImpl host_impl_; 73 FakeLayerTreeHostImpl host_impl_;
70 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_; 74 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_;
71 scoped_ptr<LayerImpl> clip_layer_; 75 scoped_ptr<LayerImpl> clip_layer_;
72 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; 76 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_;
73 77
74 base::Closure start_fade_; 78 base::Closure start_fade_;
75 base::TimeDelta delay_; 79 base::TimeDelta delay_;
76 int needs_frame_count_; 80 int needs_frame_count_;
77 }; 81 };
78 82
83 class VerticalScrollbarAnimationControllerLinearFadeTest
84 : public ScrollbarAnimationControllerLinearFadeTest {
85 protected:
86 virtual ScrollbarOrientation orientation() const override { return VERTICAL; }
87 };
88
79 TEST_F(ScrollbarAnimationControllerLinearFadeTest, DelayAnimationOnResize) { 89 TEST_F(ScrollbarAnimationControllerLinearFadeTest, DelayAnimationOnResize) {
80 scrollbar_layer_->SetOpacity(0.0f); 90 scrollbar_layer_->SetOpacity(0.0f);
81 scrollbar_controller_->DidScrollBegin(); 91 scrollbar_controller_->DidScrollBegin();
82 scrollbar_controller_->DidScrollUpdate(true); 92 scrollbar_controller_->DidScrollUpdate(true);
83 scrollbar_controller_->DidScrollEnd(); 93 scrollbar_controller_->DidScrollEnd();
84 // Normal Animation delay of 2 seconds. 94 // Normal Animation delay of 2 seconds.
85 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 95 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
86 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2)); 96 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2));
87 97
88 scrollbar_layer_->SetOpacity(0.0f); 98 scrollbar_layer_->SetOpacity(0.0f);
(...skipping 23 matching lines...) Expand all
112 122
113 EXPECT_TRUE(start_fade_.Equals(base::Closure())); 123 EXPECT_TRUE(start_fade_.Equals(base::Closure()));
114 124
115 time += base::TimeDelta::FromSeconds(100); 125 time += base::TimeDelta::FromSeconds(100);
116 scrollbar_controller_->Animate(time); 126 scrollbar_controller_->Animate(time);
117 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); 127 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
118 128
119 EXPECT_EQ(0, needs_frame_count_); 129 EXPECT_EQ(0, needs_frame_count_);
120 } 130 }
121 131
132 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HideOnResize) {
133 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
134 ASSERT_TRUE(scroll_layer);
135 EXPECT_SIZE_EQ(gfx::Size(200, 200), scroll_layer->bounds());
136
137 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());
138
139 // Shrink along X axis, horizontal scrollbar should appear.
140 clip_layer_->SetBounds(gfx::Size(100, 200));
141 EXPECT_SIZE_EQ(gfx::Size(100, 200), clip_layer_->bounds());
142
143 scrollbar_controller_->DidScrollBegin();
144
145 scrollbar_controller_->DidScrollUpdate(false);
146 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
147
148 scrollbar_controller_->DidScrollEnd();
149
150 // Shrink along Y axis and expand along X, horizontal scrollbar
151 // should disappear.
152 clip_layer_->SetBounds(gfx::Size(200, 100));
153 EXPECT_SIZE_EQ(gfx::Size(200, 100), clip_layer_->bounds());
154
155 scrollbar_controller_->DidScrollBegin();
156
157 scrollbar_controller_->DidScrollUpdate(false);
158 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
159
160 scrollbar_controller_->DidScrollEnd();
161 }
162
163 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest, HideOnResize) {
164 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
165 ASSERT_TRUE(scroll_layer);
166 EXPECT_SIZE_EQ(gfx::Size(200, 200), scroll_layer->bounds());
167
168 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation());
169
170 // Shrink along X axis, vertical scrollbar should remain invisible.
171 clip_layer_->SetBounds(gfx::Size(100, 200));
172 EXPECT_SIZE_EQ(gfx::Size(100, 200), clip_layer_->bounds());
173
174 scrollbar_controller_->DidScrollBegin();
175
176 scrollbar_controller_->DidScrollUpdate(false);
177 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
178
179 scrollbar_controller_->DidScrollEnd();
180
181 // Shrink along Y axis and expand along X, vertical scrollbar should appear.
182 clip_layer_->SetBounds(gfx::Size(200, 100));
183 EXPECT_SIZE_EQ(gfx::Size(200, 100), clip_layer_->bounds());
184
185 scrollbar_controller_->DidScrollBegin();
186
187 scrollbar_controller_->DidScrollUpdate(false);
188 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
189
190 scrollbar_controller_->DidScrollEnd();
191 }
192
193 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
194 HideOnUserNonScrollableHorz) {
195 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());
196
197 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
198 ASSERT_TRUE(scroll_layer);
199 scroll_layer->set_user_scrollable_horizontal(false);
200
201 scrollbar_controller_->DidScrollBegin();
202
203 scrollbar_controller_->DidScrollUpdate(false);
204 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
205
206 scrollbar_controller_->DidScrollEnd();
207 }
208
209 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
210 ShowOnUserNonScrollableVert) {
211 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());
212
213 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
214 ASSERT_TRUE(scroll_layer);
215 scroll_layer->set_user_scrollable_vertical(false);
216
217 scrollbar_controller_->DidScrollBegin();
218
219 scrollbar_controller_->DidScrollUpdate(false);
220 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
221
222 scrollbar_controller_->DidScrollEnd();
223 }
224
225 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest,
226 HideOnUserNonScrollableVert) {
227 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation());
228
229 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
230 ASSERT_TRUE(scroll_layer);
231 scroll_layer->set_user_scrollable_vertical(false);
232
233 scrollbar_controller_->DidScrollBegin();
234
235 scrollbar_controller_->DidScrollUpdate(false);
236 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity());
237
238 scrollbar_controller_->DidScrollEnd();
239 }
240
241 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest,
242 ShowOnUserNonScrollableHorz) {
243 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation());
244
245 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
246 ASSERT_TRUE(scroll_layer);
247 scroll_layer->set_user_scrollable_horizontal(false);
248
249 scrollbar_controller_->DidScrollBegin();
250
251 scrollbar_controller_->DidScrollUpdate(false);
252 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
253
254 scrollbar_controller_->DidScrollEnd();
255 }
256
122 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollingGesture) { 257 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollingGesture) {
123 base::TimeTicks time; 258 base::TimeTicks time;
124 time += base::TimeDelta::FromSeconds(1); 259 time += base::TimeDelta::FromSeconds(1);
125 scrollbar_controller_->DidScrollBegin(); 260 scrollbar_controller_->DidScrollBegin();
126 261
127 scrollbar_controller_->DidScrollUpdate(false); 262 scrollbar_controller_->DidScrollUpdate(false);
128 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 263 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity());
129 264
130 EXPECT_TRUE(start_fade_.Equals(base::Closure())); 265 EXPECT_TRUE(start_fade_.Equals(base::Closure()));
131 266
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 scrollbar_controller_->DidScrollUpdate(false); 412 scrollbar_controller_->DidScrollUpdate(false);
278 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); 413 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity());
279 414
280 time += base::TimeDelta::FromSeconds(1); 415 time += base::TimeDelta::FromSeconds(1);
281 scrollbar_controller_->DidScrollEnd(); 416 scrollbar_controller_->DidScrollEnd();
282 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); 417 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity());
283 } 418 }
284 419
285 } // namespace 420 } // namespace
286 } // namespace cc 421 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/scrollbar_animation_controller_linear_fade.cc ('k') | cc/animation/scrollbar_animation_controller_thinning.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698