| 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/display/window_tree_host_manager.h" |
| 8 #include "ash/public/cpp/config.h" | 9 #include "ash/public/cpp/config.h" |
| 9 #include "ash/rotator/screen_rotation_animator_observer.h" | 10 #include "ash/rotator/screen_rotation_animator_observer.h" |
| 10 #include "ash/rotator/test/screen_rotation_animator_test_api.h" | 11 #include "ash/rotator/test/screen_rotation_animator_test_api.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/shell_port.h" | 13 #include "ash/shell_port.h" |
| 13 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
| 14 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 53 } |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 bool notified_ = false; | 56 bool notified_ = false; |
| 56 | 57 |
| 57 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); | 58 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 class TestScreenRotationAnimator : public ScreenRotationAnimator { | 61 class TestScreenRotationAnimator : public ScreenRotationAnimator { |
| 61 public: | 62 public: |
| 62 TestScreenRotationAnimator(int64_t display_id, const base::Closure& callback); | 63 TestScreenRotationAnimator(int64_t display_id, |
| 64 const base::Closure& before_callback, |
| 65 const base::Closure& after_callback); |
| 63 ~TestScreenRotationAnimator() override {} | 66 ~TestScreenRotationAnimator() override {} |
| 64 | 67 |
| 65 private: | 68 private: |
| 66 CopyCallback CreateAfterCopyCallback( | 69 CopyCallback CreateAfterCopyCallbackBeforeRotation( |
| 70 std::unique_ptr<ScreenRotationRequest> rotation_request) override; |
| 71 CopyCallback CreateAfterCopyCallbackAfterRotation( |
| 67 std::unique_ptr<ScreenRotationRequest> rotation_request) override; | 72 std::unique_ptr<ScreenRotationRequest> rotation_request) override; |
| 68 | 73 |
| 69 void IntersectBefore(CopyCallback next_callback, | 74 void IntersectBefore(CopyCallback next_callback, |
| 70 std::unique_ptr<cc::CopyOutputResult> result); | 75 std::unique_ptr<cc::CopyOutputResult> result); |
| 76 void IntersectAfter(CopyCallback next_callback, |
| 77 std::unique_ptr<cc::CopyOutputResult> result); |
| 71 | 78 |
| 72 base::Closure intersect_callback_; | 79 base::Closure intersect_before_callback_; |
| 80 base::Closure intersect_after_callback_; |
| 73 | 81 |
| 74 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator); | 82 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator); |
| 75 }; | 83 }; |
| 76 | 84 |
| 77 TestScreenRotationAnimator::TestScreenRotationAnimator( | 85 TestScreenRotationAnimator::TestScreenRotationAnimator( |
| 78 int64_t display_id, | 86 int64_t display_id, |
| 79 const base::Closure& callback) | 87 const base::Closure& before_callback, |
| 80 : ScreenRotationAnimator(display_id), intersect_callback_(callback) {} | 88 const base::Closure& after_callback) |
| 89 : ScreenRotationAnimator(display_id), |
| 90 intersect_before_callback_(before_callback), |
| 91 intersect_after_callback_(after_callback) {} |
| 81 | 92 |
| 82 ScreenRotationAnimator::CopyCallback | 93 ScreenRotationAnimator::CopyCallback |
| 83 TestScreenRotationAnimator::CreateAfterCopyCallback( | 94 TestScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( |
| 84 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 95 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 85 CopyCallback next_callback = ScreenRotationAnimator::CreateAfterCopyCallback( | 96 CopyCallback next_callback = |
| 86 std::move(rotation_request)); | 97 ScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( |
| 98 std::move(rotation_request)); |
| 87 return base::Bind(&TestScreenRotationAnimator::IntersectBefore, | 99 return base::Bind(&TestScreenRotationAnimator::IntersectBefore, |
| 88 base::Unretained(this), next_callback); | 100 base::Unretained(this), next_callback); |
| 89 } | 101 } |
| 90 | 102 |
| 103 ScreenRotationAnimator::CopyCallback |
| 104 TestScreenRotationAnimator::CreateAfterCopyCallbackAfterRotation( |
| 105 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 106 CopyCallback next_callback = |
| 107 ScreenRotationAnimator::CreateAfterCopyCallbackAfterRotation( |
| 108 std::move(rotation_request)); |
| 109 return base::Bind(&TestScreenRotationAnimator::IntersectAfter, |
| 110 base::Unretained(this), next_callback); |
| 111 } |
| 112 |
| 91 void TestScreenRotationAnimator::IntersectBefore( | 113 void TestScreenRotationAnimator::IntersectBefore( |
| 92 CopyCallback next_callback, | 114 CopyCallback next_callback, |
| 93 std::unique_ptr<cc::CopyOutputResult> result) { | 115 std::unique_ptr<cc::CopyOutputResult> result) { |
| 94 intersect_callback_.Run(); | 116 intersect_before_callback_.Run(); |
| 117 next_callback.Run(std::move(result)); |
| 118 } |
| 119 |
| 120 void TestScreenRotationAnimator::IntersectAfter( |
| 121 CopyCallback next_callback, |
| 122 std::unique_ptr<cc::CopyOutputResult> result) { |
| 123 intersect_after_callback_.Run(); |
| 95 next_callback.Run(std::move(result)); | 124 next_callback.Run(std::move(result)); |
| 96 } | 125 } |
| 97 | 126 |
| 98 } // namespace | 127 } // namespace |
| 99 | 128 |
| 100 class ScreenRotationAnimatorTest : public test::AshTestBase { | 129 class ScreenRotationAnimatorSlowAnimationTest : public test::AshTestBase { |
| 101 public: | 130 public: |
| 102 ScreenRotationAnimatorTest() {} | 131 ScreenRotationAnimatorSlowAnimationTest() {} |
| 103 ~ScreenRotationAnimatorTest() override {} | 132 ~ScreenRotationAnimatorSlowAnimationTest() override {} |
| 133 |
| 134 // AshTestBase: |
| 135 void SetUp() override; |
| 136 |
| 137 protected: |
| 138 int64_t display_id() const { return display_.id(); } |
| 139 |
| 140 ScreenRotationAnimator* animator() { return animator_.get(); } |
| 141 |
| 142 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } |
| 143 |
| 144 private: |
| 145 display::Display display_; |
| 146 |
| 147 std::unique_ptr<ScreenRotationAnimator> animator_; |
| 148 |
| 149 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_; |
| 150 |
| 151 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; |
| 152 |
| 153 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorSlowAnimationTest); |
| 154 }; |
| 155 |
| 156 void ScreenRotationAnimatorSlowAnimationTest::SetUp() { |
| 157 AshTestBase::SetUp(); |
| 158 |
| 159 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 160 if (Shell::GetAshConfig() == Config::MASH) { |
| 161 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 162 display_id()); |
| 163 return; |
| 164 } |
| 165 |
| 166 animator_ = base::MakeUnique<ScreenRotationAnimator>(display_.id()); |
| 167 test_api_ = |
| 168 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); |
| 169 test_api()->DisableAnimationTimers(); |
| 170 non_zero_duration_mode_ = |
| 171 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( |
| 172 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 173 } |
| 174 |
| 175 class ScreenRotationAnimatorSmoothAnimationTest : public test::AshTestBase { |
| 176 public: |
| 177 ScreenRotationAnimatorSmoothAnimationTest() {} |
| 178 ~ScreenRotationAnimatorSmoothAnimationTest() override {} |
| 104 | 179 |
| 105 // AshTestBase: | 180 // AshTestBase: |
| 106 void SetUp() override; | 181 void SetUp() override; |
| 107 | 182 |
| 108 void RemoveSecondaryDisplay(const std::string& specs); | 183 void RemoveSecondaryDisplay(const std::string& specs); |
| 184 void QuitWaitForCopyCallback(); |
| 109 | 185 |
| 110 protected: | 186 protected: |
| 111 int64_t display_id() const { return display_.id(); } | 187 int64_t display_id() const { return display_.id(); } |
| 112 | 188 |
| 113 TestScreenRotationAnimator* animator() { return animator_.get(); } | 189 TestScreenRotationAnimator* animator() { return animator_.get(); } |
| 114 | 190 |
| 115 void SetScreenRotationAnimator(int64_t display_id, | 191 void SetScreenRotationAnimator(int64_t display_id, |
| 116 const base::Closure& callback); | 192 const base::Closure& before_callback, |
| 193 const base::Closure& after_callback); |
| 117 | 194 |
| 118 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } | 195 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } |
| 119 | 196 |
| 120 void WaitForCopyCallback(); | 197 void WaitForCopyCallback(); |
| 121 | 198 |
| 122 std::unique_ptr<base::RunLoop> run_loop_; | 199 std::unique_ptr<base::RunLoop> run_loop_; |
| 123 | 200 |
| 124 private: | 201 private: |
| 125 display::Display display_; | 202 display::Display display_; |
| 126 | 203 |
| 127 std::unique_ptr<TestScreenRotationAnimator> animator_; | 204 std::unique_ptr<TestScreenRotationAnimator> animator_; |
| 128 | 205 |
| 129 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_; | 206 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_; |
| 130 | 207 |
| 131 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; | 208 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; |
| 132 | 209 |
| 133 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest); | 210 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorSmoothAnimationTest); |
| 134 }; | 211 }; |
| 135 | 212 |
| 136 void ScreenRotationAnimatorTest::RemoveSecondaryDisplay( | 213 void ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay( |
| 137 const std::string& specs) { | 214 const std::string& specs) { |
| 138 UpdateDisplay(specs); | 215 UpdateDisplay(specs); |
| 216 QuitWaitForCopyCallback(); |
| 217 } |
| 218 |
| 219 void ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback() { |
| 139 run_loop_->QuitWhenIdle(); | 220 run_loop_->QuitWhenIdle(); |
| 140 } | 221 } |
| 141 | 222 |
| 142 void ScreenRotationAnimatorTest::SetUp() { | 223 void ScreenRotationAnimatorSmoothAnimationTest::SetUp() { |
| 143 AshTestBase::SetUp(); | 224 AshTestBase::SetUp(); |
| 144 | 225 |
| 145 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); | 226 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 227 if (Shell::GetAshConfig() == Config::MASH) { |
| 228 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 229 display_id()); |
| 230 return; |
| 231 } |
| 232 |
| 233 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 234 switches::kAshEnableSmoothScreenRotation); |
| 146 run_loop_ = base::MakeUnique<base::RunLoop>(); | 235 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 147 SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure()); | 236 SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure(), |
| 237 run_loop_->QuitWhenIdleClosure()); |
| 148 non_zero_duration_mode_ = | 238 non_zero_duration_mode_ = |
| 149 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( | 239 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( |
| 150 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); | 240 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 151 } | 241 } |
| 152 | 242 |
| 153 void ScreenRotationAnimatorTest::SetScreenRotationAnimator( | 243 void ScreenRotationAnimatorSmoothAnimationTest::SetScreenRotationAnimator( |
| 154 int64_t display_id, | 244 int64_t display_id, |
| 155 const base::Closure& callback) { | 245 const base::Closure& before_callback, |
| 156 animator_ = | 246 const base::Closure& after_callback) { |
| 157 base::MakeUnique<TestScreenRotationAnimator>(display_id, callback); | 247 animator_ = base::MakeUnique<TestScreenRotationAnimator>( |
| 248 display_id, before_callback, after_callback); |
| 158 test_api_ = | 249 test_api_ = |
| 159 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); | 250 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); |
| 160 test_api()->DisableAnimationTimers(); | 251 test_api()->DisableAnimationTimers(); |
| 161 } | 252 } |
| 162 | 253 |
| 163 void ScreenRotationAnimatorTest::WaitForCopyCallback() { | 254 void ScreenRotationAnimatorSmoothAnimationTest::WaitForCopyCallback() { |
| 255 run_loop_.reset(new base::RunLoop()); |
| 164 run_loop_->Run(); | 256 run_loop_->Run(); |
| 165 } | 257 } |
| 166 | 258 |
| 167 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) { | 259 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldNotifyObserver) { |
| 168 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 260 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 169 if (Shell::GetAshConfig() == Config::MASH) { | 261 if (Shell::GetAshConfig() == Config::MASH) { |
| 170 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 262 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 171 display_id()); | 263 display_id()); |
| 172 return; | 264 return; |
| 173 } | 265 } |
| 174 | 266 |
| 175 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 267 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
| 176 AnimationObserver observer; | 268 AnimationObserver observer; |
| 177 animator()->AddScreenRotationAnimatorObserver(&observer); | 269 animator()->AddScreenRotationAnimatorObserver(&observer); |
| 178 EXPECT_FALSE(observer.notified()); | 270 EXPECT_FALSE(observer.notified()); |
| 179 | 271 |
| 180 animator()->Rotate(display::Display::ROTATE_90, | 272 animator()->Rotate(display::Display::ROTATE_90, |
| 181 display::Display::RotationSource::ROTATION_SOURCE_USER); | 273 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 182 EXPECT_FALSE(observer.notified()); | 274 EXPECT_FALSE(observer.notified()); |
| 183 | 275 |
| 184 test_api()->CompleteAnimations(); | 276 test_api()->CompleteAnimations(); |
| 185 EXPECT_TRUE(observer.notified()); | 277 EXPECT_TRUE(observer.notified()); |
| 186 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 278 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 187 animator()->RemoveScreenRotationAnimatorObserver(&observer); | 279 animator()->RemoveScreenRotationAnimatorObserver(&observer); |
| 188 } | 280 } |
| 189 | 281 |
| 190 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserverOnce) { | 282 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldNotifyObserverOnce) { |
| 191 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 283 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 192 if (Shell::GetAshConfig() == Config::MASH) { | 284 if (Shell::GetAshConfig() == Config::MASH) { |
| 193 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 285 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 194 display_id()); | 286 display_id()); |
| 195 return; | 287 return; |
| 196 } | 288 } |
| 197 | 289 |
| 198 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 290 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
| 199 AnimationObserver observer; | 291 AnimationObserver observer; |
| 200 animator()->AddScreenRotationAnimatorObserver(&observer); | 292 animator()->AddScreenRotationAnimatorObserver(&observer); |
| 201 EXPECT_FALSE(observer.notified()); | 293 EXPECT_FALSE(observer.notified()); |
| 202 | 294 |
| 203 animator()->Rotate(display::Display::ROTATE_90, | 295 animator()->Rotate(display::Display::ROTATE_90, |
| 204 display::Display::RotationSource::ROTATION_SOURCE_USER); | 296 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 205 EXPECT_FALSE(observer.notified()); | 297 EXPECT_FALSE(observer.notified()); |
| 206 | 298 |
| 207 animator()->Rotate(display::Display::ROTATE_180, | 299 animator()->Rotate(display::Display::ROTATE_180, |
| 208 display::Display::RotationSource::ROTATION_SOURCE_USER); | 300 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 209 EXPECT_FALSE(observer.notified()); | 301 EXPECT_FALSE(observer.notified()); |
| 210 | 302 |
| 211 test_api()->CompleteAnimations(); | 303 test_api()->CompleteAnimations(); |
| 212 EXPECT_TRUE(observer.notified()); | 304 EXPECT_TRUE(observer.notified()); |
| 213 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 305 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 214 animator()->RemoveScreenRotationAnimatorObserver(&observer); | 306 animator()->RemoveScreenRotationAnimatorObserver(&observer); |
| 215 } | 307 } |
| 216 | 308 |
| 217 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotation) { | 309 TEST_F(ScreenRotationAnimatorSlowAnimationTest, RotatesToDifferentRotation) { |
| 218 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 310 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 219 if (Shell::GetAshConfig() == Config::MASH) { | 311 if (Shell::GetAshConfig() == Config::MASH) { |
| 220 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 312 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 221 display_id()); | 313 display_id()); |
| 222 return; | 314 return; |
| 223 } | 315 } |
| 224 | 316 |
| 225 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 317 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
| 226 animator()->Rotate(display::Display::ROTATE_90, | 318 animator()->Rotate(display::Display::ROTATE_90, |
| 227 display::Display::RotationSource::ROTATION_SOURCE_USER); | 319 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 228 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 320 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
| 229 | 321 |
| 230 test_api()->CompleteAnimations(); | 322 test_api()->CompleteAnimations(); |
| 231 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 323 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 232 } | 324 } |
| 233 | 325 |
| 234 TEST_F(ScreenRotationAnimatorTest, ShouldNotRotateTheSameRotation) { | 326 TEST_F(ScreenRotationAnimatorSlowAnimationTest, |
| 327 ShouldNotRotateTheSameRotation) { |
| 235 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 328 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 236 if (Shell::GetAshConfig() == Config::MASH) { | 329 if (Shell::GetAshConfig() == Config::MASH) { |
| 237 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 330 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 238 display_id()); | 331 display_id()); |
| 239 return; | 332 return; |
| 240 } | 333 } |
| 241 | 334 |
| 242 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 335 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
| 243 animator()->Rotate(display::Display::ROTATE_0, | 336 animator()->Rotate(display::Display::ROTATE_0, |
| 244 display::Display::RotationSource::ROTATION_SOURCE_USER); | 337 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 245 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 338 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 246 } | 339 } |
| 247 | 340 |
| 248 // Simulates the situation that if there is a new rotation request during | 341 // Simulates the situation that if there is a new rotation request during |
| 249 // animation, it should stop the animation immediately and add the new rotation | 342 // animation, it should stop the animation immediately and add the new rotation |
| 250 // request to the |last_pending_request_|. | 343 // request to the |last_pending_request_|. |
| 251 TEST_F(ScreenRotationAnimatorTest, RotatesDuringRotation) { | 344 TEST_F(ScreenRotationAnimatorSlowAnimationTest, RotatesDuringRotation) { |
| 252 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 345 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 253 if (Shell::GetAshConfig() == Config::MASH) { | 346 if (Shell::GetAshConfig() == Config::MASH) { |
| 254 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 347 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 255 display_id()); | 348 display_id()); |
| 256 return; | 349 return; |
| 257 } | 350 } |
| 258 | 351 |
| 259 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 352 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
| 260 animator()->Rotate(display::Display::ROTATE_90, | 353 animator()->Rotate(display::Display::ROTATE_90, |
| 261 display::Display::RotationSource::ROTATION_SOURCE_USER); | 354 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 262 animator()->Rotate(display::Display::ROTATE_180, | 355 animator()->Rotate(display::Display::ROTATE_180, |
| 263 display::Display::RotationSource::ROTATION_SOURCE_USER); | 356 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 264 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 357 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
| 265 | 358 |
| 266 test_api()->CompleteAnimations(); | 359 test_api()->CompleteAnimations(); |
| 267 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 360 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 268 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id())); | 361 EXPECT_EQ(display::Display::ROTATE_180, GetDisplayRotation(display_id())); |
| 269 } | 362 } |
| 270 | 363 |
| 271 // If there are multiple requests queued during animation, it should process the | 364 // If there are multiple requests queued during animation, it should process the |
| 272 // last request and finish the rotation animation. | 365 // last request and finish the rotation animation. |
| 273 TEST_F(ScreenRotationAnimatorTest, ShouldCompleteAnimations) { | 366 TEST_F(ScreenRotationAnimatorSlowAnimationTest, ShouldCompleteAnimations) { |
| 274 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 367 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 275 if (Shell::GetAshConfig() == Config::MASH) { | 368 if (Shell::GetAshConfig() == Config::MASH) { |
| 276 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 369 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 277 display_id()); | 370 display_id()); |
| 278 return; | 371 return; |
| 279 } | 372 } |
| 280 | 373 |
| 281 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 374 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
| 282 animator()->Rotate(display::Display::ROTATE_90, | 375 animator()->Rotate(display::Display::ROTATE_90, |
| 283 display::Display::RotationSource::ROTATION_SOURCE_USER); | 376 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 284 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 377 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
| 285 | 378 |
| 286 animator()->Rotate(display::Display::ROTATE_180, | 379 animator()->Rotate(display::Display::ROTATE_180, |
| 287 display::Display::RotationSource::ROTATION_SOURCE_USER); | 380 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 288 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 381 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
| 289 | 382 |
| 290 animator()->Rotate(display::Display::ROTATE_270, | 383 animator()->Rotate(display::Display::ROTATE_270, |
| 291 display::Display::RotationSource::ROTATION_SOURCE_USER); | 384 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 292 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 385 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
| 293 | 386 |
| 294 test_api()->CompleteAnimations(); | 387 test_api()->CompleteAnimations(); |
| 295 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 388 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 296 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); | 389 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); |
| 297 } | 390 } |
| 298 | 391 |
| 299 // Test enable smooth screen rotation code path. | 392 // Test enable smooth screen rotation code path. |
| 300 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) { | 393 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 394 RotatesToDifferentRotationWithCopyCallback) { |
| 301 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 395 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 302 if (Shell::GetAshConfig() == Config::MASH) { | 396 if (Shell::GetAshConfig() == Config::MASH) { |
| 303 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 397 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 304 display_id()); | 398 display_id()); |
| 305 return; | 399 return; |
| 306 } | 400 } |
| 307 | 401 |
| 402 SetScreenRotationAnimator( |
| 403 display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(), |
| 404 base::Bind( |
| 405 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback, |
| 406 base::Unretained(this))); |
| 308 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 407 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
| 309 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 310 switches::kAshEnableSmoothScreenRotation); | |
| 311 animator()->Rotate(display::Display::ROTATE_90, | 408 animator()->Rotate(display::Display::ROTATE_90, |
| 312 display::Display::RotationSource::ROTATION_SOURCE_USER); | 409 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 313 WaitForCopyCallback(); | 410 WaitForCopyCallback(); |
| 314 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 411 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
| 315 | 412 |
| 316 test_api()->CompleteAnimations(); | 413 test_api()->CompleteAnimations(); |
| 317 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 414 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 318 } | 415 } |
| 319 | 416 |
| 320 // If the external display is removed, it should not crash. | 417 // If the external secondary display is removed before the first copy request |
| 321 TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) { | 418 // callback called, it should not crash. |
| 419 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 420 RemoveExternalSecondaryDisplayBeforeFirstCopyCallback) { |
| 322 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 421 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 323 if (Shell::GetAshConfig() == Config::MASH) { | 422 if (Shell::GetAshConfig() == Config::MASH) { |
| 324 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 423 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 325 display_id()); | 424 display_id()); |
| 326 return; | 425 return; |
| 327 } | 426 } |
| 328 | 427 |
| 329 UpdateDisplay("640x480,800x600"); | 428 UpdateDisplay("640x480,800x600"); |
| 330 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 429 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 331 | 430 |
| 332 const unsigned int primary_display_id = | 431 const unsigned int primary_display_id = |
| 333 display_manager()->GetDisplayAt(0).id(); | 432 display_manager()->GetDisplayAt(0).id(); |
| 334 SetScreenRotationAnimator( | 433 SetScreenRotationAnimator( |
| 335 display_manager()->GetDisplayAt(1).id(), | 434 display_manager()->GetDisplayAt(1).id(), |
| 336 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay, | 435 base::Bind( |
| 337 base::Unretained(this), "640x480")); | 436 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 338 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 437 base::Unretained(this), "640x480"), |
| 339 switches::kAshEnableSmoothScreenRotation); | 438 run_loop_->QuitWhenIdleClosure()); |
| 340 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), | 439 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), |
| 341 display::Display::ROTATE_0); | 440 display::Display::ROTATE_0); |
| 342 animator()->Rotate(display::Display::ROTATE_90, | 441 animator()->Rotate(display::Display::ROTATE_90, |
| 343 display::Display::RotationSource::ROTATION_SOURCE_USER); | 442 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 344 WaitForCopyCallback(); | 443 WaitForCopyCallback(); |
| 345 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 444 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 346 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); | 445 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 347 } | 446 } |
| 348 | 447 |
| 448 // If the external primary display is removed before the first copy request |
| 449 // callback called, it should not crash. |
| 450 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 451 RemoveExternalPrimaryDisplayBeforeFirstCopyCallback) { |
| 452 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 453 if (Shell::GetAshConfig() == Config::MASH) { |
| 454 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 455 display_id()); |
| 456 return; |
| 457 } |
| 458 |
| 459 UpdateDisplay("640x480,800x600"); |
| 460 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 461 |
| 462 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
| 463 display_manager()->GetDisplayAt(1).id()); |
| 464 const unsigned int secondary_display_id = |
| 465 display_manager()->GetDisplayAt(0).id(); |
| 466 SetScreenRotationAnimator( |
| 467 display_manager()->GetDisplayAt(1).id(), |
| 468 base::Bind( |
| 469 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 470 base::Unretained(this), "640x480"), |
| 471 run_loop_->QuitWhenIdleClosure()); |
| 472 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), |
| 473 display::Display::ROTATE_0); |
| 474 animator()->Rotate(display::Display::ROTATE_90, |
| 475 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 476 WaitForCopyCallback(); |
| 477 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 478 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 479 } |
| 480 |
| 481 // If the external secondary display is removed before the second copy request |
| 482 // callback called, it should not crash. |
| 483 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 484 RemoveExternalSecondaryDisplayBeforeSecondCopyCallback) { |
| 485 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 486 if (Shell::GetAshConfig() == Config::MASH) { |
| 487 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 488 display_id()); |
| 489 return; |
| 490 } |
| 491 |
| 492 UpdateDisplay("640x480,800x600"); |
| 493 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 494 |
| 495 const unsigned int primary_display_id = |
| 496 display_manager()->GetDisplayAt(0).id(); |
| 497 SetScreenRotationAnimator( |
| 498 display_manager()->GetDisplayAt(1).id(), run_loop_->QuitWhenIdleClosure(), |
| 499 base::Bind( |
| 500 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 501 base::Unretained(this), "640x480")); |
| 502 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), |
| 503 display::Display::ROTATE_0); |
| 504 animator()->Rotate(display::Display::ROTATE_90, |
| 505 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 506 WaitForCopyCallback(); |
| 507 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 508 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 509 } |
| 510 |
| 511 // If the external primary display is removed before the second copy request |
| 512 // callback called, it should not crash. |
| 513 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 514 RemoveExternalPrimaryDisplayBeforeSecondCopyCallback) { |
| 515 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 516 if (Shell::GetAshConfig() == Config::MASH) { |
| 517 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 518 display_id()); |
| 519 return; |
| 520 } |
| 521 |
| 522 UpdateDisplay("640x480,800x600"); |
| 523 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 524 |
| 525 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
| 526 display_manager()->GetDisplayAt(1).id()); |
| 527 const unsigned int secondary_display_id = |
| 528 display_manager()->GetDisplayAt(0).id(); |
| 529 SetScreenRotationAnimator( |
| 530 display_manager()->GetDisplayAt(1).id(), run_loop_->QuitWhenIdleClosure(), |
| 531 base::Bind( |
| 532 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 533 base::Unretained(this), "640x480")); |
| 534 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), |
| 535 display::Display::ROTATE_0); |
| 536 animator()->Rotate(display::Display::ROTATE_90, |
| 537 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 538 WaitForCopyCallback(); |
| 539 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 540 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 541 } |
| 542 |
| 349 } // namespace ash | 543 } // namespace ash |
| OLD | NEW |