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

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

Issue 2018833002: cc : Delete LayerImpl::opacity (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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
« no previous file with comments | « cc/input/scrollbar_animation_controller_thinning.cc ('k') | cc/layers/layer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 26 matching lines...) Expand all
37 did_request_animate_ = true; 37 did_request_animate_ = true;
38 } 38 }
39 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { 39 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override {
40 return host_impl_.ScrollbarsFor(scroll_layer_id); 40 return host_impl_.ScrollbarsFor(scroll_layer_id);
41 } 41 }
42 42
43 protected: 43 protected:
44 void SetUp() override { 44 void SetUp() override {
45 std::unique_ptr<LayerImpl> scroll_layer = 45 std::unique_ptr<LayerImpl> scroll_layer =
46 LayerImpl::Create(host_impl_.active_tree(), 1); 46 LayerImpl::Create(host_impl_.active_tree(), 1);
47 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); 47 std::unique_ptr<LayerImpl> clip =
48 LayerImpl::Create(host_impl_.active_tree(), 3);
49 clip_layer_ = clip.get();
48 scroll_layer->SetScrollClipLayer(clip_layer_->id()); 50 scroll_layer->SetScrollClipLayer(clip_layer_->id());
49 LayerImpl* scroll_layer_ptr = scroll_layer.get(); 51 LayerImpl* scroll_layer_ptr = scroll_layer.get();
50 clip_layer_->AddChild(std::move(scroll_layer));
51 52
52 const int kId = 2; 53 const int kId = 2;
53 const int kThumbThickness = 10; 54 const int kThumbThickness = 10;
54 const int kTrackStart = 0; 55 const int kTrackStart = 0;
55 const bool kIsLeftSideVerticalScrollbar = false; 56 const bool kIsLeftSideVerticalScrollbar = false;
56 const bool kIsOverlayScrollbar = true; 57 const bool kIsOverlayScrollbar = true;
57 scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( 58 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
58 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, kTrackStart, 59 SolidColorScrollbarLayerImpl::Create(
59 kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); 60 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness,
61 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
62 scrollbar_layer_ = scrollbar.get();
63
64 scroll_layer->AddChild(std::move(scrollbar));
65 clip_layer_->AddChild(std::move(scroll_layer));
66 host_impl_.active_tree()->SetRootLayer(std::move(clip));
60 67
61 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); 68 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
69 scrollbar_layer_->test_properties()->opacity_can_animate = true;
62 clip_layer_->SetBounds(gfx::Size(100, 100)); 70 clip_layer_->SetBounds(gfx::Size(100, 100));
63 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); 71 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
72 host_impl_.active_tree()->BuildPropertyTreesForTesting();
64 73
65 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( 74 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create(
66 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2), 75 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2),
67 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); 76 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3));
68 } 77 }
69 78
70 FakeImplTaskRunnerProvider task_runner_provider_; 79 FakeImplTaskRunnerProvider task_runner_provider_;
71 TestSharedBitmapManager shared_bitmap_manager_; 80 TestSharedBitmapManager shared_bitmap_manager_;
72 TestTaskGraphRunner task_graph_runner_; 81 TestTaskGraphRunner task_graph_runner_;
73 FakeLayerTreeHostImpl host_impl_; 82 FakeLayerTreeHostImpl host_impl_;
74 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; 83 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_;
75 std::unique_ptr<LayerImpl> clip_layer_; 84 LayerImpl* clip_layer_;
76 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; 85 SolidColorScrollbarLayerImpl* scrollbar_layer_;
77 86
78 base::Closure start_fade_; 87 base::Closure start_fade_;
79 base::TimeDelta delay_; 88 base::TimeDelta delay_;
80 bool did_request_redraw_; 89 bool did_request_redraw_;
81 bool did_request_animate_; 90 bool did_request_animate_;
82 }; 91 };
83 92
84 // Check initialization of scrollbar. 93 // Check initialization of scrollbar.
85 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { 94 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) {
86 scrollbar_controller_->Animate(base::TimeTicks()); 95 scrollbar_controller_->Animate(base::TimeTicks());
87 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 96 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
88 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 97 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
89 } 98 }
90 99
91 // Check that scrollbar disappears when the layer becomes non-scrollable. 100 // Check that scrollbar disappears when the layer becomes non-scrollable.
92 TEST_F(ScrollbarAnimationControllerThinningTest, HideOnResize) { 101 TEST_F(ScrollbarAnimationControllerThinningTest, HideOnResize) {
93 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); 102 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
94 ASSERT_TRUE(scroll_layer); 103 ASSERT_TRUE(scroll_layer);
95 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); 104 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds());
96 105
97 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); 106 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());
98 107
99 // Shrink along X axis, horizontal scrollbar should appear. 108 // Shrink along X axis, horizontal scrollbar should appear.
100 clip_layer_->SetBounds(gfx::Size(100, 200)); 109 clip_layer_->SetBounds(gfx::Size(100, 200));
101 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds()); 110 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds());
102 111
103 scrollbar_controller_->DidScrollBegin(); 112 scrollbar_controller_->DidScrollBegin();
104 113
105 scrollbar_controller_->DidScrollUpdate(false); 114 scrollbar_controller_->DidScrollUpdate(false);
106 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 115 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
107 116
108 scrollbar_controller_->DidScrollEnd(); 117 scrollbar_controller_->DidScrollEnd();
109 118
110 // Shrink along Y axis and expand along X, horizontal scrollbar 119 // Shrink along Y axis and expand along X, horizontal scrollbar
111 // should disappear. 120 // should disappear.
112 clip_layer_->SetBounds(gfx::Size(200, 100)); 121 clip_layer_->SetBounds(gfx::Size(200, 100));
113 EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds()); 122 EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds());
114 123
115 scrollbar_controller_->DidScrollBegin(); 124 scrollbar_controller_->DidScrollBegin();
116 125
117 scrollbar_controller_->DidScrollUpdate(false); 126 scrollbar_controller_->DidScrollUpdate(false);
118 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); 127 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
119 128
120 scrollbar_controller_->DidScrollEnd(); 129 scrollbar_controller_->DidScrollEnd();
121 } 130 }
122 131
123 // Scroll content. Confirm the scrollbar gets dark and then becomes light 132 // Scroll content. Confirm the scrollbar gets dark and then becomes light
124 // after stopping. 133 // after stopping.
125 TEST_F(ScrollbarAnimationControllerThinningTest, AwakenByProgrammaticScroll) { 134 TEST_F(ScrollbarAnimationControllerThinningTest, AwakenByProgrammaticScroll) {
126 base::TimeTicks time; 135 base::TimeTicks time;
127 time += base::TimeDelta::FromSeconds(1); 136 time += base::TimeDelta::FromSeconds(1);
128 scrollbar_controller_->DidScrollUpdate(false); 137 scrollbar_controller_->DidScrollUpdate(false);
129 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 138 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
130 // Scrollbar doesn't change size if triggered by scroll. 139 // Scrollbar doesn't change size if triggered by scroll.
131 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 140 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
132 141
133 start_fade_.Run(); 142 start_fade_.Run();
134 143
135 time += base::TimeDelta::FromSeconds(1); 144 time += base::TimeDelta::FromSeconds(1);
136 scrollbar_controller_->Animate(time); 145 scrollbar_controller_->Animate(time);
137 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 146 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
138 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 147 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
139 148
140 // Subsequent scroll restarts animation. 149 // Subsequent scroll restarts animation.
141 scrollbar_controller_->DidScrollUpdate(false); 150 scrollbar_controller_->DidScrollUpdate(false);
142 151
143 start_fade_.Run(); 152 start_fade_.Run();
144 153
145 time += base::TimeDelta::FromSeconds(2); 154 time += base::TimeDelta::FromSeconds(2);
146 scrollbar_controller_->Animate(time); 155 scrollbar_controller_->Animate(time);
147 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 156 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
148 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 157 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
149 158
150 time += base::TimeDelta::FromSeconds(1); 159 time += base::TimeDelta::FromSeconds(1);
151 scrollbar_controller_->Animate(time); 160 scrollbar_controller_->Animate(time);
152 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity()); 161 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity());
153 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 162 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
154 163
155 time += base::TimeDelta::FromSeconds(1); 164 time += base::TimeDelta::FromSeconds(1);
156 scrollbar_controller_->Animate(time); 165 scrollbar_controller_->Animate(time);
157 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity()); 166 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->Opacity());
158 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 167 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
159 168
160 time += base::TimeDelta::FromSeconds(1); 169 time += base::TimeDelta::FromSeconds(1);
161 scrollbar_controller_->Animate(time); 170 scrollbar_controller_->Animate(time);
162 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 171 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
163 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 172 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
164 } 173 }
165 174
166 // Initiate a scroll when the pointer is already near the scrollbar. It should 175 // Initiate a scroll when the pointer is already near the scrollbar. It should
167 // remain thick. 176 // remain thick.
168 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { 177 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) {
169 base::TimeTicks time; 178 base::TimeTicks time;
170 time += base::TimeDelta::FromSeconds(1); 179 time += base::TimeDelta::FromSeconds(1);
171 180
172 scrollbar_controller_->DidMouseMoveNear(1); 181 scrollbar_controller_->DidMouseMoveNear(1);
173 scrollbar_controller_->Animate(time); 182 scrollbar_controller_->Animate(time);
174 time += base::TimeDelta::FromSeconds(3); 183 time += base::TimeDelta::FromSeconds(3);
175 184
176 scrollbar_controller_->Animate(time); 185 scrollbar_controller_->Animate(time);
177 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 186 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
178 187
179 scrollbar_controller_->DidScrollUpdate(false); 188 scrollbar_controller_->DidScrollUpdate(false);
180 start_fade_.Run(); 189 start_fade_.Run();
181 scrollbar_controller_->Animate(time); 190 scrollbar_controller_->Animate(time);
182 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 191 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
183 // Scrollbar should still be thick. 192 // Scrollbar should still be thick.
184 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 193 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
185 194
186 time += base::TimeDelta::FromSeconds(5); 195 time += base::TimeDelta::FromSeconds(5);
187 scrollbar_controller_->Animate(time); 196 scrollbar_controller_->Animate(time);
188 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 197 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
189 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 198 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
190 } 199 }
191 200
192 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when 201 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when
193 // moved away. 202 // moved away.
194 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) { 203 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) {
195 base::TimeTicks time; 204 base::TimeTicks time;
196 time += base::TimeDelta::FromSeconds(1); 205 time += base::TimeDelta::FromSeconds(1);
197 scrollbar_controller_->DidMouseMoveNear(1); 206 scrollbar_controller_->DidMouseMoveNear(1);
198 scrollbar_controller_->Animate(time); 207 scrollbar_controller_->Animate(time);
199 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 208 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
200 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 209 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
201 210
202 // Should animate to thickened but not darken. 211 // Should animate to thickened but not darken.
203 time += base::TimeDelta::FromSeconds(1); 212 time += base::TimeDelta::FromSeconds(1);
204 scrollbar_controller_->Animate(time); 213 scrollbar_controller_->Animate(time);
205 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 214 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
206 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); 215 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor());
207 216
208 time += base::TimeDelta::FromSeconds(1); 217 time += base::TimeDelta::FromSeconds(1);
209 scrollbar_controller_->Animate(time); 218 scrollbar_controller_->Animate(time);
210 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 219 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
211 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); 220 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
212 221
213 time += base::TimeDelta::FromSeconds(1); 222 time += base::TimeDelta::FromSeconds(1);
214 scrollbar_controller_->Animate(time); 223 scrollbar_controller_->Animate(time);
215 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 224 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
216 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 225 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
217 226
218 // Subsequent moves should not change anything. 227 // Subsequent moves should not change anything.
219 scrollbar_controller_->DidMouseMoveNear(1); 228 scrollbar_controller_->DidMouseMoveNear(1);
220 scrollbar_controller_->Animate(time); 229 scrollbar_controller_->Animate(time);
221 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 230 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
222 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 231 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
223 232
224 // Now move away from bar. 233 // Now move away from bar.
225 time += base::TimeDelta::FromSeconds(1); 234 time += base::TimeDelta::FromSeconds(1);
226 scrollbar_controller_->DidMouseMoveNear(26); 235 scrollbar_controller_->DidMouseMoveNear(26);
227 scrollbar_controller_->Animate(time); 236 scrollbar_controller_->Animate(time);
228 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 237 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 238 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
230 239
231 // Animate to narrow. 240 // Animate to narrow.
232 time += base::TimeDelta::FromSeconds(1); 241 time += base::TimeDelta::FromSeconds(1);
233 scrollbar_controller_->Animate(time); 242 scrollbar_controller_->Animate(time);
234 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 243 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
235 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); 244 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
236 245
237 time += base::TimeDelta::FromSeconds(1); 246 time += base::TimeDelta::FromSeconds(1);
238 scrollbar_controller_->Animate(time); 247 scrollbar_controller_->Animate(time);
239 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 248 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
240 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); 249 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor());
241 250
242 time += base::TimeDelta::FromSeconds(1); 251 time += base::TimeDelta::FromSeconds(1);
243 scrollbar_controller_->Animate(time); 252 scrollbar_controller_->Animate(time);
244 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 253 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
245 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 254 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
246 } 255 }
247 256
248 // Move the pointer over the scrollbar. Make sure it gets thick and dark 257 // Move the pointer over the scrollbar. Make sure it gets thick and dark
249 // and that it gets thin and light when moved away. 258 // and that it gets thin and light when moved away.
250 TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) { 259 TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) {
251 base::TimeTicks time; 260 base::TimeTicks time;
252 time += base::TimeDelta::FromSeconds(1); 261 time += base::TimeDelta::FromSeconds(1);
253 scrollbar_controller_->DidMouseMoveNear(0); 262 scrollbar_controller_->DidMouseMoveNear(0);
254 scrollbar_controller_->Animate(time); 263 scrollbar_controller_->Animate(time);
255 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 264 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
256 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 265 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
257 266
258 // Should animate to thickened and darkened. 267 // Should animate to thickened and darkened.
259 time += base::TimeDelta::FromSeconds(1); 268 time += base::TimeDelta::FromSeconds(1);
260 scrollbar_controller_->Animate(time); 269 scrollbar_controller_->Animate(time);
261 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity()); 270 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->Opacity());
262 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); 271 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor());
263 272
264 time += base::TimeDelta::FromSeconds(1); 273 time += base::TimeDelta::FromSeconds(1);
265 scrollbar_controller_->Animate(time); 274 scrollbar_controller_->Animate(time);
266 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity()); 275 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity());
267 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); 276 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
268 277
269 time += base::TimeDelta::FromSeconds(1); 278 time += base::TimeDelta::FromSeconds(1);
270 scrollbar_controller_->Animate(time); 279 scrollbar_controller_->Animate(time);
271 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 280 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
272 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 281 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
273 282
274 // Subsequent moves should not change anything. 283 // Subsequent moves should not change anything.
275 scrollbar_controller_->DidMouseMoveNear(0); 284 scrollbar_controller_->DidMouseMoveNear(0);
276 scrollbar_controller_->Animate(time); 285 scrollbar_controller_->Animate(time);
277 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 286 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
278 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 287 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
279 288
280 // Now move away from bar. 289 // Now move away from bar.
281 time += base::TimeDelta::FromSeconds(1); 290 time += base::TimeDelta::FromSeconds(1);
282 scrollbar_controller_->DidMouseMoveNear(26); 291 scrollbar_controller_->DidMouseMoveNear(26);
283 scrollbar_controller_->Animate(time); 292 scrollbar_controller_->Animate(time);
284 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 293 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
285 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 294 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
286 295
287 // Animate to narrow. 296 // Animate to narrow.
288 time += base::TimeDelta::FromSeconds(1); 297 time += base::TimeDelta::FromSeconds(1);
289 scrollbar_controller_->Animate(time); 298 scrollbar_controller_->Animate(time);
290 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity()); 299 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity());
291 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); 300 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
292 301
293 time += base::TimeDelta::FromSeconds(1); 302 time += base::TimeDelta::FromSeconds(1);
294 scrollbar_controller_->Animate(time); 303 scrollbar_controller_->Animate(time);
295 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity()); 304 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->Opacity());
296 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); 305 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor());
297 306
298 time += base::TimeDelta::FromSeconds(1); 307 time += base::TimeDelta::FromSeconds(1);
299 scrollbar_controller_->Animate(time); 308 scrollbar_controller_->Animate(time);
300 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 309 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
301 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 310 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
302 } 311 }
303 312
304 // First move the pointer near the scrollbar, then over it, then back near 313 // First move the pointer near the scrollbar, then over it, then back near
305 // then far away. Confirm that first the bar gets thick, then dark, then light, 314 // then far away. Confirm that first the bar gets thick, then dark, then light,
306 // then narrow. 315 // then narrow.
307 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearThenOver) { 316 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearThenOver) {
308 base::TimeTicks time; 317 base::TimeTicks time;
309 time += base::TimeDelta::FromSeconds(1); 318 time += base::TimeDelta::FromSeconds(1);
310 scrollbar_controller_->DidMouseMoveNear(1); 319 scrollbar_controller_->DidMouseMoveNear(1);
311 scrollbar_controller_->Animate(time); 320 scrollbar_controller_->Animate(time);
312 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 321 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
313 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); 322 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor());
314 323
315 // Should animate to thickened but not darken. 324 // Should animate to thickened but not darken.
316 time += base::TimeDelta::FromSeconds(3); 325 time += base::TimeDelta::FromSeconds(3);
317 scrollbar_controller_->Animate(time); 326 scrollbar_controller_->Animate(time);
318 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 327 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
319 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 328 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
320 329
321 // Now move over. 330 // Now move over.
322 scrollbar_controller_->DidMouseMoveNear(0); 331 scrollbar_controller_->DidMouseMoveNear(0);
323 scrollbar_controller_->Animate(time); 332 scrollbar_controller_->Animate(time);
324 333
325 // Should animate to darkened. 334 // Should animate to darkened.
326 time += base::TimeDelta::FromSeconds(1); 335 time += base::TimeDelta::FromSeconds(1);
327 scrollbar_controller_->Animate(time); 336 scrollbar_controller_->Animate(time);
328 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity()); 337 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->Opacity());
329 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 338 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
330 339
331 time += base::TimeDelta::FromSeconds(1); 340 time += base::TimeDelta::FromSeconds(1);
332 scrollbar_controller_->Animate(time); 341 scrollbar_controller_->Animate(time);
333 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity()); 342 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity());
334 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 343 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
335 344
336 time += base::TimeDelta::FromSeconds(1); 345 time += base::TimeDelta::FromSeconds(1);
337 scrollbar_controller_->Animate(time); 346 scrollbar_controller_->Animate(time);
338 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); 347 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
339 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 348 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
340 349
341 // This is tricky. The DidMouseMoveOffScrollbar() is sent before the 350 // This is tricky. The DidMouseMoveOffScrollbar() is sent before the
342 // subsequent DidMouseMoveNear(), if the mouse moves in that direction. 351 // subsequent DidMouseMoveNear(), if the mouse moves in that direction.
343 // This results in the thumb thinning. We want to make sure that when the 352 // This results in the thumb thinning. We want to make sure that when the
344 // thumb starts expanding it doesn't first narrow to the idle thinness. 353 // thumb starts expanding it doesn't first narrow to the idle thinness.
345 time += base::TimeDelta::FromSeconds(1); 354 time += base::TimeDelta::FromSeconds(1);
346 scrollbar_controller_->DidMouseMoveOffScrollbar(); 355 scrollbar_controller_->DidMouseMoveOffScrollbar();
347 scrollbar_controller_->Animate(time); 356 scrollbar_controller_->Animate(time);
348 357
349 time += base::TimeDelta::FromSeconds(1); 358 time += base::TimeDelta::FromSeconds(1);
350 scrollbar_controller_->Animate(time); 359 scrollbar_controller_->Animate(time);
351 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity()); 360 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity());
352 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); 361 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
353 362
354 scrollbar_controller_->DidMouseMoveNear(1); 363 scrollbar_controller_->DidMouseMoveNear(1);
355 scrollbar_controller_->Animate(time); 364 scrollbar_controller_->Animate(time);
356 // A new animation is kicked off. 365 // A new animation is kicked off.
357 366
358 time += base::TimeDelta::FromSeconds(1); 367 time += base::TimeDelta::FromSeconds(1);
359 scrollbar_controller_->Animate(time); 368 scrollbar_controller_->Animate(time);
360 // We will initiate the narrowing again, but it won't get decremented until 369 // We will initiate the narrowing again, but it won't get decremented until
361 // the new animation catches up to it. 370 // the new animation catches up to it.
362 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->opacity()); 371 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity());
363 // Now the thickness should be increasing, but it shouldn't happen until the 372 // Now the thickness should be increasing, but it shouldn't happen until the
364 // animation catches up. 373 // animation catches up.
365 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); 374 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
366 375
367 time += base::TimeDelta::FromSeconds(1); 376 time += base::TimeDelta::FromSeconds(1);
368 scrollbar_controller_->Animate(time); 377 scrollbar_controller_->Animate(time);
369 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->opacity()); 378 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->Opacity());
370 // The thickness now gets big again. 379 // The thickness now gets big again.
371 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); 380 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor());
372 381
373 time += base::TimeDelta::FromSeconds(1); 382 time += base::TimeDelta::FromSeconds(1);
374 scrollbar_controller_->Animate(time); 383 scrollbar_controller_->Animate(time);
375 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); 384 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity());
376 // The thickness now gets big again. 385 // The thickness now gets big again.
377 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); 386 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor());
378 } 387 }
379 388
380 } // namespace 389 } // namespace
381 } // namespace cc 390 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scrollbar_animation_controller_thinning.cc ('k') | cc/layers/layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698