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