| 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/display/window_tree_host_manager.h" |
| 9 #include "ash/public/cpp/config.h" | 9 #include "ash/public/cpp/config.h" |
| 10 #include "ash/rotator/screen_rotation_animator_observer.h" | 10 #include "ash/rotator/screen_rotation_animator_observer.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 Shell::Get()->display_manager()->SetDisplayRotation( | 44 Shell::Get()->display_manager()->SetDisplayRotation( |
| 45 display_id, rotation, | 45 display_id, rotation, |
| 46 display::Display::RotationSource::ROTATION_SOURCE_USER); | 46 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 47 } | 47 } |
| 48 | 48 |
| 49 OverviewButtonTray* GetTray() { | 49 OverviewButtonTray* GetTray() { |
| 50 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() | 50 return StatusAreaWidgetTestHelper::GetStatusAreaWidget() |
| 51 ->overview_button_tray(); | 51 ->overview_button_tray(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 aura::Window* GetRootWindow(int64_t display_id) { |
| 55 return Shell::Get()->window_tree_host_manager()->GetRootWindowForDisplayId( |
| 56 display_id); |
| 57 } |
| 58 |
| 54 class AnimationObserver : public ScreenRotationAnimatorObserver { | 59 class AnimationObserver : public ScreenRotationAnimatorObserver { |
| 55 public: | 60 public: |
| 56 AnimationObserver() {} | 61 AnimationObserver() {} |
| 57 | 62 |
| 58 bool notified() const { return notified_; } | 63 bool notified() const { return notified_; } |
| 59 | 64 |
| 60 void OnScreenRotationAnimationFinished( | 65 void OnScreenRotationAnimationFinished( |
| 61 ScreenRotationAnimator* animator) override { | 66 ScreenRotationAnimator* animator) override { |
| 62 notified_ = true; | 67 notified_ = true; |
| 63 } | 68 } |
| 64 | 69 |
| 65 private: | 70 private: |
| 66 bool notified_ = false; | 71 bool notified_ = false; |
| 67 | 72 |
| 68 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); | 73 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); |
| 69 }; | 74 }; |
| 70 | 75 |
| 71 class TestScreenRotationAnimator : public ScreenRotationAnimator { | 76 class TestScreenRotationAnimator : public ScreenRotationAnimator { |
| 72 public: | 77 public: |
| 73 TestScreenRotationAnimator(int64_t display_id, | 78 TestScreenRotationAnimator(aura::Window* root_window, |
| 74 const base::Closure& before_callback, | 79 const base::Closure& before_callback, |
| 75 const base::Closure& after_callback); | 80 const base::Closure& after_callback); |
| 76 ~TestScreenRotationAnimator() override {} | 81 ~TestScreenRotationAnimator() override {} |
| 77 | 82 |
| 78 private: | 83 private: |
| 79 CopyCallback CreateAfterCopyCallbackBeforeRotation( | 84 CopyCallback CreateAfterCopyCallbackBeforeRotation( |
| 80 std::unique_ptr<ScreenRotationRequest> rotation_request) override; | 85 std::unique_ptr<ScreenRotationRequest> rotation_request) override; |
| 81 CopyCallback CreateAfterCopyCallbackAfterRotation( | 86 CopyCallback CreateAfterCopyCallbackAfterRotation( |
| 82 std::unique_ptr<ScreenRotationRequest> rotation_request) override; | 87 std::unique_ptr<ScreenRotationRequest> rotation_request) override; |
| 83 | 88 |
| 84 void IntersectBefore(CopyCallback next_callback, | 89 void IntersectBefore(CopyCallback next_callback, |
| 85 std::unique_ptr<cc::CopyOutputResult> result); | 90 std::unique_ptr<cc::CopyOutputResult> result); |
| 86 void IntersectAfter(CopyCallback next_callback, | 91 void IntersectAfter(CopyCallback next_callback, |
| 87 std::unique_ptr<cc::CopyOutputResult> result); | 92 std::unique_ptr<cc::CopyOutputResult> result); |
| 88 | 93 |
| 89 base::Closure intersect_before_callback_; | 94 base::Closure intersect_before_callback_; |
| 90 base::Closure intersect_after_callback_; | 95 base::Closure intersect_after_callback_; |
| 91 | 96 |
| 92 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator); | 97 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator); |
| 93 }; | 98 }; |
| 94 | 99 |
| 95 TestScreenRotationAnimator::TestScreenRotationAnimator( | 100 TestScreenRotationAnimator::TestScreenRotationAnimator( |
| 96 int64_t display_id, | 101 aura::Window* root_window, |
| 97 const base::Closure& before_callback, | 102 const base::Closure& before_callback, |
| 98 const base::Closure& after_callback) | 103 const base::Closure& after_callback) |
| 99 : ScreenRotationAnimator(display_id), | 104 : ScreenRotationAnimator(root_window), |
| 100 intersect_before_callback_(before_callback), | 105 intersect_before_callback_(before_callback), |
| 101 intersect_after_callback_(after_callback) {} | 106 intersect_after_callback_(after_callback) {} |
| 102 | 107 |
| 103 ScreenRotationAnimator::CopyCallback | 108 ScreenRotationAnimator::CopyCallback |
| 104 TestScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( | 109 TestScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( |
| 105 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 110 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 106 CopyCallback next_callback = | 111 CopyCallback next_callback = |
| 107 ScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( | 112 ScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( |
| 108 std::move(rotation_request)); | 113 std::move(rotation_request)); |
| 109 return base::Bind(&TestScreenRotationAnimator::IntersectBefore, | 114 return base::Bind(&TestScreenRotationAnimator::IntersectBefore, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 void ScreenRotationAnimatorSlowAnimationTest::SetUp() { | 171 void ScreenRotationAnimatorSlowAnimationTest::SetUp() { |
| 167 AshTestBase::SetUp(); | 172 AshTestBase::SetUp(); |
| 168 | 173 |
| 169 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); | 174 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 170 if (Shell::GetAshConfig() == Config::MASH) { | 175 if (Shell::GetAshConfig() == Config::MASH) { |
| 171 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 176 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 172 display_id()); | 177 display_id()); |
| 173 return; | 178 return; |
| 174 } | 179 } |
| 175 | 180 |
| 176 animator_ = base::MakeUnique<ScreenRotationAnimator>(display_.id()); | 181 animator_ = |
| 182 base::MakeUnique<ScreenRotationAnimator>(GetRootWindow(display_.id())); |
| 177 test_api_ = | 183 test_api_ = |
| 178 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); | 184 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); |
| 179 test_api()->DisableAnimationTimers(); | 185 test_api()->DisableAnimationTimers(); |
| 180 non_zero_duration_mode_ = | 186 non_zero_duration_mode_ = |
| 181 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( | 187 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( |
| 182 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); | 188 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 183 } | 189 } |
| 184 | 190 |
| 185 class ScreenRotationAnimatorSmoothAnimationTest : public test::AshTestBase { | 191 class ScreenRotationAnimatorSmoothAnimationTest : public test::AshTestBase { |
| 186 public: | 192 public: |
| 187 ScreenRotationAnimatorSmoothAnimationTest() {} | 193 ScreenRotationAnimatorSmoothAnimationTest() {} |
| 188 ~ScreenRotationAnimatorSmoothAnimationTest() override {} | 194 ~ScreenRotationAnimatorSmoothAnimationTest() override {} |
| 189 | 195 |
| 190 // AshTestBase: | 196 // AshTestBase: |
| 191 void SetUp() override; | 197 void SetUp() override; |
| 192 | 198 |
| 193 void RemoveSecondaryDisplay(const std::string& specs); | 199 void RemoveSecondaryDisplay(const std::string& specs); |
| 194 void QuitWaitForCopyCallback(); | 200 void QuitWaitForCopyCallback(); |
| 195 | 201 |
| 196 protected: | 202 protected: |
| 197 int64_t display_id() const { return display_.id(); } | 203 int64_t display_id() const { return display_.id(); } |
| 198 | 204 |
| 199 TestScreenRotationAnimator* animator() { return animator_.get(); } | 205 TestScreenRotationAnimator* animator() { return animator_.get(); } |
| 200 | 206 |
| 201 void SetScreenRotationAnimator(int64_t display_id, | 207 void SetScreenRotationAnimator(aura::Window* root_window, |
| 202 const base::Closure& before_callback, | 208 const base::Closure& before_callback, |
| 203 const base::Closure& after_callback); | 209 const base::Closure& after_callback); |
| 204 | 210 |
| 205 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } | 211 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } |
| 206 | 212 |
| 207 void WaitForCopyCallback(); | 213 void WaitForCopyCallback(); |
| 208 | 214 |
| 209 std::unique_ptr<base::RunLoop> run_loop_; | 215 std::unique_ptr<base::RunLoop> run_loop_; |
| 210 | 216 |
| 211 private: | 217 private: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 238 ash_test_helper()->reset_commandline(); | 244 ash_test_helper()->reset_commandline(); |
| 239 | 245 |
| 240 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); | 246 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 241 if (Shell::GetAshConfig() == Config::MASH) { | 247 if (Shell::GetAshConfig() == Config::MASH) { |
| 242 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 248 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 243 display_id()); | 249 display_id()); |
| 244 return; | 250 return; |
| 245 } | 251 } |
| 246 | 252 |
| 247 run_loop_ = base::MakeUnique<base::RunLoop>(); | 253 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 248 SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure(), | 254 SetScreenRotationAnimator(GetRootWindow(display_.id()), |
| 255 run_loop_->QuitWhenIdleClosure(), |
| 249 run_loop_->QuitWhenIdleClosure()); | 256 run_loop_->QuitWhenIdleClosure()); |
| 250 non_zero_duration_mode_ = | 257 non_zero_duration_mode_ = |
| 251 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( | 258 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( |
| 252 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); | 259 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 253 } | 260 } |
| 254 | 261 |
| 255 void ScreenRotationAnimatorSmoothAnimationTest::SetScreenRotationAnimator( | 262 void ScreenRotationAnimatorSmoothAnimationTest::SetScreenRotationAnimator( |
| 256 int64_t display_id, | 263 aura::Window* root_window, |
| 257 const base::Closure& before_callback, | 264 const base::Closure& before_callback, |
| 258 const base::Closure& after_callback) { | 265 const base::Closure& after_callback) { |
| 259 animator_ = base::MakeUnique<TestScreenRotationAnimator>( | 266 animator_ = base::MakeUnique<TestScreenRotationAnimator>( |
| 260 display_id, before_callback, after_callback); | 267 root_window, before_callback, after_callback); |
| 261 test_api_ = | 268 test_api_ = |
| 262 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); | 269 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); |
| 263 test_api()->DisableAnimationTimers(); | 270 test_api()->DisableAnimationTimers(); |
| 264 } | 271 } |
| 265 | 272 |
| 266 void ScreenRotationAnimatorSmoothAnimationTest::WaitForCopyCallback() { | 273 void ScreenRotationAnimatorSmoothAnimationTest::WaitForCopyCallback() { |
| 267 run_loop_.reset(new base::RunLoop()); | 274 run_loop_.reset(new base::RunLoop()); |
| 268 run_loop_->Run(); | 275 run_loop_->Run(); |
| 269 } | 276 } |
| 270 | 277 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 // Test enable smooth screen rotation code path. | 441 // Test enable smooth screen rotation code path. |
| 435 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, | 442 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 436 RotatesToDifferentRotationWithCopyCallback) { | 443 RotatesToDifferentRotationWithCopyCallback) { |
| 437 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 444 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 438 if (Shell::GetAshConfig() == Config::MASH) { | 445 if (Shell::GetAshConfig() == Config::MASH) { |
| 439 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 446 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 440 display_id()); | 447 display_id()); |
| 441 return; | 448 return; |
| 442 } | 449 } |
| 443 | 450 |
| 451 const int64_t display_id = display_manager()->GetDisplayAt(0).id(); |
| 444 SetScreenRotationAnimator( | 452 SetScreenRotationAnimator( |
| 445 display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(), | 453 GetRootWindow(display_id), run_loop_->QuitWhenIdleClosure(), |
| 446 base::Bind( | 454 base::Bind( |
| 447 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback, | 455 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback, |
| 448 base::Unretained(this))); | 456 base::Unretained(this))); |
| 449 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 457 SetDisplayRotation(display_id, display::Display::ROTATE_0); |
| 450 animator()->Rotate(display::Display::ROTATE_90, | 458 animator()->Rotate(display::Display::ROTATE_90, |
| 451 display::Display::RotationSource::ROTATION_SOURCE_USER); | 459 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 452 WaitForCopyCallback(); | 460 WaitForCopyCallback(); |
| 453 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 461 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
| 454 | 462 |
| 455 test_api()->CompleteAnimations(); | 463 test_api()->CompleteAnimations(); |
| 456 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 464 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 465 EXPECT_EQ(display::Display::ROTATE_90, GetDisplayRotation(display_id)); |
| 457 } | 466 } |
| 458 | 467 |
| 459 // If the external secondary display is removed before the first copy request | 468 // If the rotating external secondary display is removed before the first copy |
| 460 // callback called, it should not crash. | 469 // request callback called, it should stop rotating. |
| 461 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, | 470 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 462 RemoveExternalSecondaryDisplayBeforeFirstCopyCallback) { | 471 RemoveExternalSecondaryDisplayBeforeFirstCopyCallback) { |
| 463 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 472 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 464 if (Shell::GetAshConfig() == Config::MASH) { | 473 if (Shell::GetAshConfig() == Config::MASH) { |
| 465 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 474 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 466 display_id()); | 475 display_id()); |
| 467 return; | 476 return; |
| 468 } | 477 } |
| 469 | 478 |
| 470 UpdateDisplay("640x480,800x600"); | 479 UpdateDisplay("640x480,800x600"); |
| 471 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 480 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 472 | 481 |
| 473 const unsigned int primary_display_id = | 482 const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id(); |
| 474 display_manager()->GetDisplayAt(0).id(); | 483 const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id(); |
| 484 |
| 475 SetScreenRotationAnimator( | 485 SetScreenRotationAnimator( |
| 476 display_manager()->GetDisplayAt(1).id(), | 486 GetRootWindow(secondary_display_id), |
| 477 base::Bind( | 487 base::Bind( |
| 478 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, | 488 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 479 base::Unretained(this), "640x480"), | 489 base::Unretained(this), "640x480"), |
| 480 run_loop_->QuitWhenIdleClosure()); | 490 run_loop_->QuitWhenIdleClosure()); |
| 481 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), | 491 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0); |
| 482 display::Display::ROTATE_0); | |
| 483 animator()->Rotate(display::Display::ROTATE_90, | 492 animator()->Rotate(display::Display::ROTATE_90, |
| 484 display::Display::RotationSource::ROTATION_SOURCE_USER); | 493 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 485 WaitForCopyCallback(); | 494 WaitForCopyCallback(); |
| 486 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 495 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 487 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); | 496 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 488 } | 497 } |
| 489 | 498 |
| 490 // If the external primary display is removed before the first copy request | 499 // If the rotating external primary display is removed before the first copy |
| 491 // callback called, it should not crash. | 500 // request callback called, it should stop rotating. |
| 492 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, | 501 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 493 RemoveExternalPrimaryDisplayBeforeFirstCopyCallback) { | 502 RemoveExternalPrimaryDisplayBeforeFirstCopyCallback) { |
| 494 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 503 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 495 if (Shell::GetAshConfig() == Config::MASH) { | 504 if (Shell::GetAshConfig() == Config::MASH) { |
| 496 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 505 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 497 display_id()); | 506 display_id()); |
| 498 return; | 507 return; |
| 499 } | 508 } |
| 500 | 509 |
| 501 UpdateDisplay("640x480,800x600"); | 510 UpdateDisplay("640x480,800x600"); |
| 502 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 511 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 503 | 512 |
| 504 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( | 513 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
| 505 display_manager()->GetDisplayAt(1).id()); | 514 display_manager()->GetDisplayAt(1).id()); |
| 506 const unsigned int secondary_display_id = | 515 const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id(); |
| 507 display_manager()->GetDisplayAt(0).id(); | 516 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id(); |
| 508 SetScreenRotationAnimator( | 517 SetScreenRotationAnimator( |
| 509 display_manager()->GetDisplayAt(1).id(), | 518 GetRootWindow(primary_display_id), |
| 510 base::Bind( | 519 base::Bind( |
| 511 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, | 520 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 512 base::Unretained(this), "640x480"), | 521 base::Unretained(this), "640x480"), |
| 513 run_loop_->QuitWhenIdleClosure()); | 522 run_loop_->QuitWhenIdleClosure()); |
| 514 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), | 523 SetDisplayRotation(primary_display_id, display::Display::ROTATE_0); |
| 515 display::Display::ROTATE_0); | |
| 516 animator()->Rotate(display::Display::ROTATE_90, | 524 animator()->Rotate(display::Display::ROTATE_90, |
| 517 display::Display::RotationSource::ROTATION_SOURCE_USER); | 525 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 518 WaitForCopyCallback(); | 526 WaitForCopyCallback(); |
| 519 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 527 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 520 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); | 528 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 521 } | 529 } |
| 522 | 530 |
| 523 // If the external secondary display is removed before the second copy request | 531 // If the rotating external secondary display is removed before the second copy |
| 524 // callback called, it should not crash. | 532 // request callback called, it should stop rotating. |
| 525 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, | 533 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 526 RemoveExternalSecondaryDisplayBeforeSecondCopyCallback) { | 534 RemoveExternalSecondaryDisplayBeforeSecondCopyCallback) { |
| 527 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 535 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 528 if (Shell::GetAshConfig() == Config::MASH) { | 536 if (Shell::GetAshConfig() == Config::MASH) { |
| 529 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 537 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 530 display_id()); | 538 display_id()); |
| 531 return; | 539 return; |
| 532 } | 540 } |
| 533 | 541 |
| 534 UpdateDisplay("640x480,800x600"); | 542 UpdateDisplay("640x480,800x600"); |
| 535 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 543 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 536 | 544 |
| 537 const unsigned int primary_display_id = | 545 const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id(); |
| 538 display_manager()->GetDisplayAt(0).id(); | 546 const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id(); |
| 539 SetScreenRotationAnimator( | 547 SetScreenRotationAnimator( |
| 540 display_manager()->GetDisplayAt(1).id(), run_loop_->QuitWhenIdleClosure(), | 548 GetRootWindow(secondary_display_id), run_loop_->QuitWhenIdleClosure(), |
| 541 base::Bind( | 549 base::Bind( |
| 542 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, | 550 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 543 base::Unretained(this), "640x480")); | 551 base::Unretained(this), "640x480")); |
| 544 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), | 552 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0); |
| 545 display::Display::ROTATE_0); | |
| 546 animator()->Rotate(display::Display::ROTATE_90, | 553 animator()->Rotate(display::Display::ROTATE_90, |
| 547 display::Display::RotationSource::ROTATION_SOURCE_USER); | 554 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 548 WaitForCopyCallback(); | 555 WaitForCopyCallback(); |
| 549 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 556 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 550 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); | 557 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 551 } | 558 } |
| 552 | 559 |
| 553 // If the external primary display is removed before the second copy request | 560 // If the rotating external primary display is removed before the second copy |
| 554 // callback called, it should not crash. | 561 // request callback called, it should stop rotating. |
| 555 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, | 562 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 556 RemoveExternalPrimaryDisplayBeforeSecondCopyCallback) { | 563 RemoveExternalPrimaryDisplayBeforeSecondCopyCallback) { |
| 557 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 564 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 558 if (Shell::GetAshConfig() == Config::MASH) { | 565 if (Shell::GetAshConfig() == Config::MASH) { |
| 559 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 566 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 560 display_id()); | 567 display_id()); |
| 561 return; | 568 return; |
| 562 } | 569 } |
| 563 | 570 |
| 564 UpdateDisplay("640x480,800x600"); | 571 UpdateDisplay("640x480,800x600"); |
| 565 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 572 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 566 | 573 |
| 567 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( | 574 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
| 568 display_manager()->GetDisplayAt(1).id()); | 575 display_manager()->GetDisplayAt(1).id()); |
| 569 const unsigned int secondary_display_id = | 576 const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id(); |
| 570 display_manager()->GetDisplayAt(0).id(); | 577 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id(); |
| 571 SetScreenRotationAnimator( | 578 SetScreenRotationAnimator( |
| 572 display_manager()->GetDisplayAt(1).id(), run_loop_->QuitWhenIdleClosure(), | 579 GetRootWindow(primary_display_id), run_loop_->QuitWhenIdleClosure(), |
| 573 base::Bind( | 580 base::Bind( |
| 574 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, | 581 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 575 base::Unretained(this), "640x480")); | 582 base::Unretained(this), "640x480")); |
| 576 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), | 583 SetDisplayRotation(primary_display_id, display::Display::ROTATE_0); |
| 577 display::Display::ROTATE_0); | |
| 578 animator()->Rotate(display::Display::ROTATE_90, | 584 animator()->Rotate(display::Display::ROTATE_90, |
| 579 display::Display::RotationSource::ROTATION_SOURCE_USER); | 585 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 580 WaitForCopyCallback(); | 586 WaitForCopyCallback(); |
| 581 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 587 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 582 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); | 588 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 583 } | 589 } |
| 584 | 590 |
| 591 // If the external primary display is removed while rotating the secondary |
| 592 // display. It should stop rotating the secondary display because the |
| 593 // |root_window| changed. |
| 594 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 595 RemoveExternalPrimaryDisplayDuringAnimationChangedRootWindow) { |
| 596 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 597 if (Shell::GetAshConfig() == Config::MASH) { |
| 598 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 599 display_id()); |
| 600 return; |
| 601 } |
| 602 |
| 603 UpdateDisplay("640x480,800x600"); |
| 604 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 605 |
| 606 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
| 607 display_manager()->GetDisplayAt(1).id()); |
| 608 const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id(); |
| 609 SetScreenRotationAnimator( |
| 610 GetRootWindow(secondary_display_id), |
| 611 base::Bind( |
| 612 &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay, |
| 613 base::Unretained(this), "640x480"), |
| 614 run_loop_->QuitWhenIdleClosure()); |
| 615 SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0); |
| 616 animator()->Rotate(display::Display::ROTATE_90, |
| 617 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 618 WaitForCopyCallback(); |
| 619 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 620 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 621 EXPECT_EQ(display::Display::ROTATE_0, |
| 622 GetDisplayRotation(secondary_display_id)); |
| 623 } |
| 624 |
| 585 // Test that smooth screen rotation animation will not interrupt hide animation. | 625 // Test that smooth screen rotation animation will not interrupt hide animation. |
| 586 // The OverviewButton should be hidden. | 626 // The OverviewButton should be hidden. |
| 587 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, | 627 TEST_F(ScreenRotationAnimatorSmoothAnimationTest, |
| 588 OverviewButtonTrayHideAnimationAlwaysCompletes) { | 628 OverviewButtonTrayHideAnimationAlwaysCompletes) { |
| 589 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 629 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 590 if (Shell::GetAshConfig() == Config::MASH) { | 630 if (Shell::GetAshConfig() == Config::MASH) { |
| 591 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 631 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 592 display_id()); | 632 display_id()); |
| 593 return; | 633 return; |
| 594 } | 634 } |
| 595 | 635 |
| 596 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 636 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 597 true); | 637 true); |
| 598 | 638 |
| 599 // Long duration for hide animation, to allow it to be interrupted. | 639 // Long duration for hide animation, to allow it to be interrupted. |
| 600 ui::ScopedAnimationDurationScaleMode hide_duration( | 640 ui::ScopedAnimationDurationScaleMode hide_duration( |
| 601 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); | 641 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 602 GetTray()->SetVisible(false); | 642 GetTray()->SetVisible(false); |
| 603 | 643 |
| 604 // Allow ScreenRotationAnimator animation to complete first. | 644 // Allow ScreenRotationAnimator animation to complete first. |
| 605 ui::ScopedAnimationDurationScaleMode rotate_duration( | 645 ui::ScopedAnimationDurationScaleMode rotate_duration( |
| 606 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 646 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 647 int64_t display_id = display_manager()->GetDisplayAt(0).id(); |
| 607 SetScreenRotationAnimator( | 648 SetScreenRotationAnimator( |
| 608 display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(), | 649 GetRootWindow(display_id), run_loop_->QuitWhenIdleClosure(), |
| 609 base::Bind( | 650 base::Bind( |
| 610 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback, | 651 &ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback, |
| 611 base::Unretained(this))); | 652 base::Unretained(this))); |
| 612 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 653 SetDisplayRotation(display_id, display::Display::ROTATE_0); |
| 613 animator()->Rotate(display::Display::ROTATE_90, | 654 animator()->Rotate(display::Display::ROTATE_90, |
| 614 display::Display::RotationSource::ROTATION_SOURCE_USER); | 655 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 615 WaitForCopyCallback(); | 656 WaitForCopyCallback(); |
| 616 | 657 |
| 617 GetTray()->layer()->GetAnimator()->StopAnimating(); | 658 GetTray()->layer()->GetAnimator()->StopAnimating(); |
| 618 EXPECT_FALSE(GetTray()->visible()); | 659 EXPECT_FALSE(GetTray()->visible()); |
| 619 } | 660 } |
| 620 | 661 |
| 621 } // namespace ash | 662 } // namespace ash |
| OLD | NEW |