OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "ash/rotator/screen_rotation_animator.h" | |
James Cook
2017/04/10 22:00:41
nit: blank line below
sky
2017/04/10 22:16:25
Done.
| |
5 #include "ash/ash_switches.h" | 6 #include "ash/ash_switches.h" |
6 #include "ash/rotator/screen_rotation_animator.h" | |
7 #include "ash/rotator/screen_rotation_animator_observer.h" | 7 #include "ash/rotator/screen_rotation_animator_observer.h" |
8 #include "ash/rotator/test/screen_rotation_animator_test_api.h" | 8 #include "ash/rotator/test/screen_rotation_animator_test_api.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_port.h" | |
10 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
11 #include "ash/wm_shell.h" | |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "cc/output/copy_output_request.h" | 16 #include "cc/output/copy_output_request.h" |
17 #include "cc/output/copy_output_result.h" | 17 #include "cc/output/copy_output_result.h" |
18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
19 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
20 #include "ui/display/manager/display_manager.h" | 20 #include "ui/display/manager/display_manager.h" |
21 #include "ui/display/screen.h" | 21 #include "ui/display/screen.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); | 157 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); |
158 test_api()->DisableAnimationTimers(); | 158 test_api()->DisableAnimationTimers(); |
159 } | 159 } |
160 | 160 |
161 void ScreenRotationAnimatorTest::WaitForCopyCallback() { | 161 void ScreenRotationAnimatorTest::WaitForCopyCallback() { |
162 run_loop_->Run(); | 162 run_loop_->Run(); |
163 } | 163 } |
164 | 164 |
165 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) { | 165 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) { |
166 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 166 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
167 if (WmShell::Get()->IsRunningInMash()) { | 167 if (ShellPort::Get()->IsRunningInMash()) { |
168 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != | 168 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
169 display_id()); | 169 display_id()); |
170 return; | 170 return; |
171 } | 171 } |
172 | 172 |
173 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 173 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
174 AnimationObserver observer; | 174 AnimationObserver observer; |
175 animator()->AddScreenRotationAnimatorObserver(&observer); | 175 animator()->AddScreenRotationAnimatorObserver(&observer); |
176 EXPECT_FALSE(observer.notified()); | 176 EXPECT_FALSE(observer.notified()); |
177 | 177 |
178 animator()->Rotate(display::Display::ROTATE_90, | 178 animator()->Rotate(display::Display::ROTATE_90, |
179 display::Display::RotationSource::ROTATION_SOURCE_USER); | 179 display::Display::RotationSource::ROTATION_SOURCE_USER); |
180 EXPECT_FALSE(observer.notified()); | 180 EXPECT_FALSE(observer.notified()); |
181 | 181 |
182 test_api()->CompleteAnimations(); | 182 test_api()->CompleteAnimations(); |
183 EXPECT_TRUE(observer.notified()); | 183 EXPECT_TRUE(observer.notified()); |
184 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 184 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
185 animator()->RemoveScreenRotationAnimatorObserver(&observer); | 185 animator()->RemoveScreenRotationAnimatorObserver(&observer); |
186 } | 186 } |
187 | 187 |
188 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserverOnce) { | 188 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserverOnce) { |
189 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 189 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
190 if (WmShell::Get()->IsRunningInMash()) { | 190 if (ShellPort::Get()->IsRunningInMash()) { |
191 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != | 191 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
192 display_id()); | 192 display_id()); |
193 return; | 193 return; |
194 } | 194 } |
195 | 195 |
196 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 196 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
197 AnimationObserver observer; | 197 AnimationObserver observer; |
198 animator()->AddScreenRotationAnimatorObserver(&observer); | 198 animator()->AddScreenRotationAnimatorObserver(&observer); |
199 EXPECT_FALSE(observer.notified()); | 199 EXPECT_FALSE(observer.notified()); |
200 | 200 |
201 animator()->Rotate(display::Display::ROTATE_90, | 201 animator()->Rotate(display::Display::ROTATE_90, |
202 display::Display::RotationSource::ROTATION_SOURCE_USER); | 202 display::Display::RotationSource::ROTATION_SOURCE_USER); |
203 EXPECT_FALSE(observer.notified()); | 203 EXPECT_FALSE(observer.notified()); |
204 | 204 |
205 animator()->Rotate(display::Display::ROTATE_180, | 205 animator()->Rotate(display::Display::ROTATE_180, |
206 display::Display::RotationSource::ROTATION_SOURCE_USER); | 206 display::Display::RotationSource::ROTATION_SOURCE_USER); |
207 EXPECT_FALSE(observer.notified()); | 207 EXPECT_FALSE(observer.notified()); |
208 | 208 |
209 test_api()->CompleteAnimations(); | 209 test_api()->CompleteAnimations(); |
210 EXPECT_TRUE(observer.notified()); | 210 EXPECT_TRUE(observer.notified()); |
211 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 211 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
212 animator()->RemoveScreenRotationAnimatorObserver(&observer); | 212 animator()->RemoveScreenRotationAnimatorObserver(&observer); |
213 } | 213 } |
214 | 214 |
215 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) { | 215 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) { |
216 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 216 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
217 if (WmShell::Get()->IsRunningInMash()) { | 217 if (ShellPort::Get()->IsRunningInMash()) { |
218 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != | 218 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
219 display_id()); | 219 display_id()); |
220 return; | 220 return; |
221 } | 221 } |
222 | 222 |
223 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 223 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
224 animator()->Rotate(display::Display::ROTATE_90, | 224 animator()->Rotate(display::Display::ROTATE_90, |
225 display::Display::RotationSource::ROTATION_SOURCE_USER); | 225 display::Display::RotationSource::ROTATION_SOURCE_USER); |
226 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 226 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
227 | 227 |
228 test_api()->CompleteAnimations(); | 228 test_api()->CompleteAnimations(); |
229 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 229 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
230 } | 230 } |
231 | 231 |
232 TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) { | 232 TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) { |
233 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 233 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
234 if (WmShell::Get()->IsRunningInMash()) { | 234 if (ShellPort::Get()->IsRunningInMash()) { |
235 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != | 235 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
236 display_id()); | 236 display_id()); |
237 return; | 237 return; |
238 } | 238 } |
239 | 239 |
240 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 240 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
241 animator()->Rotate(display::Display::ROTATE_0, | 241 animator()->Rotate(display::Display::ROTATE_0, |
242 display::Display::RotationSource::ROTATION_SOURCE_USER); | 242 display::Display::RotationSource::ROTATION_SOURCE_USER); |
243 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 243 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
244 } | 244 } |
245 | 245 |
246 // Simulates the situation that if there is a new rotation request during | 246 // Simulates the situation that if there is a new rotation request during |
247 // animation, it should stop the animation immediately and add the new rotation | 247 // animation, it should stop the animation immediately and add the new rotation |
248 // request to the |last_pending_request_|. | 248 // request to the |last_pending_request_|. |
249 TEST_F(ScreenRotationAnimatorTest, RotatesDuringRotation) { | 249 TEST_F(ScreenRotationAnimatorTest, RotatesDuringRotation) { |
250 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 250 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
251 if (WmShell::Get()->IsRunningInMash()) { | 251 if (ShellPort::Get()->IsRunningInMash()) { |
252 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != | 252 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
253 display_id()); | 253 display_id()); |
254 return; | 254 return; |
255 } | 255 } |
256 | 256 |
257 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 257 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
258 animator()->Rotate(display::Display::ROTATE_90, | 258 animator()->Rotate(display::Display::ROTATE_90, |
259 display::Display::RotationSource::ROTATION_SOURCE_USER); | 259 display::Display::RotationSource::ROTATION_SOURCE_USER); |
260 animator()->Rotate(display::Display::ROTATE_180, | 260 animator()->Rotate(display::Display::ROTATE_180, |
261 display::Display::RotationSource::ROTATION_SOURCE_USER); | 261 display::Display::RotationSource::ROTATION_SOURCE_USER); |
262 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 262 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
263 | 263 |
264 test_api()->CompleteAnimations(); | 264 test_api()->CompleteAnimations(); |
265 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 265 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
266 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id())); | 266 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id())); |
267 } | 267 } |
268 | 268 |
269 // If there are multiple requests queued during animation, it should process the | 269 // If there are multiple requests queued during animation, it should process the |
270 // last request and finish the rotation animation. | 270 // last request and finish the rotation animation. |
271 TEST_F(ScreenRotationAnimatorTest, ShouldCompleteAnimations) { | 271 TEST_F(ScreenRotationAnimatorTest, ShouldCompleteAnimations) { |
272 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 272 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
273 if (WmShell::Get()->IsRunningInMash()) { | 273 if (ShellPort::Get()->IsRunningInMash()) { |
274 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != | 274 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
275 display_id()); | 275 display_id()); |
276 return; | 276 return; |
277 } | 277 } |
278 | 278 |
279 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 279 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
280 animator()->Rotate(display::Display::ROTATE_90, | 280 animator()->Rotate(display::Display::ROTATE_90, |
281 display::Display::RotationSource::ROTATION_SOURCE_USER); | 281 display::Display::RotationSource::ROTATION_SOURCE_USER); |
282 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 282 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
283 | 283 |
284 animator()->Rotate(display::Display::ROTATE_180, | 284 animator()->Rotate(display::Display::ROTATE_180, |
285 display::Display::RotationSource::ROTATION_SOURCE_USER); | 285 display::Display::RotationSource::ROTATION_SOURCE_USER); |
286 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 286 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
287 | 287 |
288 animator()->Rotate(display::Display::ROTATE_270, | 288 animator()->Rotate(display::Display::ROTATE_270, |
289 display::Display::RotationSource::ROTATION_SOURCE_USER); | 289 display::Display::RotationSource::ROTATION_SOURCE_USER); |
290 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 290 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
291 | 291 |
292 test_api()->CompleteAnimations(); | 292 test_api()->CompleteAnimations(); |
293 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 293 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
294 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); | 294 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); |
295 } | 295 } |
296 | 296 |
297 // Test enable smooth screen rotation code path. | 297 // Test enable smooth screen rotation code path. |
298 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) { | 298 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) { |
299 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 299 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
300 if (WmShell::Get()->IsRunningInMash()) { | 300 if (ShellPort::Get()->IsRunningInMash()) { |
301 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != | 301 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
302 display_id()); | 302 display_id()); |
303 return; | 303 return; |
304 } | 304 } |
305 | 305 |
306 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 306 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
307 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 307 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
308 switches::kAshEnableSmoothScreenRotation); | 308 switches::kAshEnableSmoothScreenRotation); |
309 animator()->Rotate(display::Display::ROTATE_90, | 309 animator()->Rotate(display::Display::ROTATE_90, |
310 display::Display::RotationSource::ROTATION_SOURCE_USER); | 310 display::Display::RotationSource::ROTATION_SOURCE_USER); |
311 WaitForCopyCallback(); | 311 WaitForCopyCallback(); |
312 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 312 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
313 | 313 |
314 test_api()->CompleteAnimations(); | 314 test_api()->CompleteAnimations(); |
315 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 315 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
316 } | 316 } |
317 | 317 |
318 // If the external display is removed, it should not crash. | 318 // If the external display is removed, it should not crash. |
319 TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) { | 319 TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) { |
320 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 320 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
321 if (WmShell::Get()->IsRunningInMash()) { | 321 if (ShellPort::Get()->IsRunningInMash()) { |
322 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != | 322 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
323 display_id()); | 323 display_id()); |
324 return; | 324 return; |
325 } | 325 } |
326 | 326 |
327 UpdateDisplay("640x480,800x600"); | 327 UpdateDisplay("640x480,800x600"); |
328 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 328 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
329 | 329 |
330 const unsigned int primary_display_id = | 330 const unsigned int primary_display_id = |
331 display_manager()->GetDisplayAt(0).id(); | 331 display_manager()->GetDisplayAt(0).id(); |
332 SetScreenRotationAnimator( | 332 SetScreenRotationAnimator( |
333 display_manager()->GetDisplayAt(1).id(), | 333 display_manager()->GetDisplayAt(1).id(), |
334 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay, | 334 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay, |
335 base::Unretained(this), "640x480")); | 335 base::Unretained(this), "640x480")); |
336 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 336 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
337 switches::kAshEnableSmoothScreenRotation); | 337 switches::kAshEnableSmoothScreenRotation); |
338 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), | 338 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), |
339 display::Display::ROTATE_0); | 339 display::Display::ROTATE_0); |
340 animator()->Rotate(display::Display::ROTATE_90, | 340 animator()->Rotate(display::Display::ROTATE_90, |
341 display::Display::RotationSource::ROTATION_SOURCE_USER); | 341 display::Display::RotationSource::ROTATION_SOURCE_USER); |
342 WaitForCopyCallback(); | 342 WaitForCopyCallback(); |
343 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 343 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
344 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); | 344 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); |
345 } | 345 } |
346 | 346 |
347 } // namespace ash | 347 } // namespace ash |
OLD | NEW |