| Index: ash/rotator/screen_rotation_animator_unittest.cc
|
| diff --git a/ash/rotator/screen_rotation_animator_unittest.cc b/ash/rotator/screen_rotation_animator_unittest.cc
|
| index 09e64d3a7457df980bb18b3d9e67ff3f3168b45f..917271c91cc251bfab2eb74a00f03abb2bbcd212 100644
|
| --- a/ash/rotator/screen_rotation_animator_unittest.cc
|
| +++ b/ash/rotator/screen_rotation_animator_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include "ash/rotator/screen_rotation_animator.h"
|
|
|
| #include "ash/ash_switches.h"
|
| +#include "ash/display/window_tree_host_manager.h"
|
| #include "ash/public/cpp/config.h"
|
| #include "ash/rotator/screen_rotation_animator_observer.h"
|
| #include "ash/rotator/test/screen_rotation_animator_test_api.h"
|
| @@ -59,39 +60,67 @@ class AnimationObserver : public ScreenRotationAnimatorObserver {
|
|
|
| class TestScreenRotationAnimator : public ScreenRotationAnimator {
|
| public:
|
| - TestScreenRotationAnimator(int64_t display_id, const base::Closure& callback);
|
| + TestScreenRotationAnimator(int64_t display_id,
|
| + const base::Closure& before_callback,
|
| + const base::Closure& after_callback);
|
| ~TestScreenRotationAnimator() override {}
|
|
|
| private:
|
| - CopyCallback CreateAfterCopyCallback(
|
| + CopyCallback CreateAfterCopyCallbackBeforeRotation(
|
| + std::unique_ptr<ScreenRotationRequest> rotation_request) override;
|
| + CopyCallback CreateAfterCopyCallbackAfterRotation(
|
| std::unique_ptr<ScreenRotationRequest> rotation_request) override;
|
|
|
| void IntersectBefore(CopyCallback next_callback,
|
| std::unique_ptr<cc::CopyOutputResult> result);
|
| + void IntersectAfter(CopyCallback next_callback,
|
| + std::unique_ptr<cc::CopyOutputResult> result);
|
|
|
| - base::Closure intersect_callback_;
|
| + base::Closure intersect_before_callback_;
|
| + base::Closure intersect_after_callback_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator);
|
| };
|
|
|
| TestScreenRotationAnimator::TestScreenRotationAnimator(
|
| int64_t display_id,
|
| - const base::Closure& callback)
|
| - : ScreenRotationAnimator(display_id), intersect_callback_(callback) {}
|
| + const base::Closure& before_callback,
|
| + const base::Closure& after_callback)
|
| + : ScreenRotationAnimator(display_id),
|
| + intersect_before_callback_(before_callback),
|
| + intersect_after_callback_(after_callback) {}
|
|
|
| ScreenRotationAnimator::CopyCallback
|
| -TestScreenRotationAnimator::CreateAfterCopyCallback(
|
| +TestScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation(
|
| std::unique_ptr<ScreenRotationRequest> rotation_request) {
|
| - CopyCallback next_callback = ScreenRotationAnimator::CreateAfterCopyCallback(
|
| - std::move(rotation_request));
|
| + CopyCallback next_callback =
|
| + ScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation(
|
| + std::move(rotation_request));
|
| return base::Bind(&TestScreenRotationAnimator::IntersectBefore,
|
| base::Unretained(this), next_callback);
|
| }
|
|
|
| +ScreenRotationAnimator::CopyCallback
|
| +TestScreenRotationAnimator::CreateAfterCopyCallbackAfterRotation(
|
| + std::unique_ptr<ScreenRotationRequest> rotation_request) {
|
| + CopyCallback next_callback =
|
| + ScreenRotationAnimator::CreateAfterCopyCallbackAfterRotation(
|
| + std::move(rotation_request));
|
| + return base::Bind(&TestScreenRotationAnimator::IntersectAfter,
|
| + base::Unretained(this), next_callback);
|
| +}
|
| +
|
| void TestScreenRotationAnimator::IntersectBefore(
|
| CopyCallback next_callback,
|
| std::unique_ptr<cc::CopyOutputResult> result) {
|
| - intersect_callback_.Run();
|
| + intersect_before_callback_.Run();
|
| + next_callback.Run(std::move(result));
|
| +}
|
| +
|
| +void TestScreenRotationAnimator::IntersectAfter(
|
| + CopyCallback next_callback,
|
| + std::unique_ptr<cc::CopyOutputResult> result) {
|
| + intersect_after_callback_.Run();
|
| next_callback.Run(std::move(result));
|
| }
|
|
|
| @@ -106,6 +135,7 @@ class ScreenRotationAnimatorTest : public test::AshTestBase {
|
| void SetUp() override;
|
|
|
| void RemoveSecondaryDisplay(const std::string& specs);
|
| + void QuitWaitForCopyCallback();
|
|
|
| protected:
|
| int64_t display_id() const { return display_.id(); }
|
| @@ -113,7 +143,8 @@ class ScreenRotationAnimatorTest : public test::AshTestBase {
|
| TestScreenRotationAnimator* animator() { return animator_.get(); }
|
|
|
| void SetScreenRotationAnimator(int64_t display_id,
|
| - const base::Closure& callback);
|
| + const base::Closure& before_callback,
|
| + const base::Closure& after_callback);
|
|
|
| test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); }
|
|
|
| @@ -136,6 +167,10 @@ class ScreenRotationAnimatorTest : public test::AshTestBase {
|
| void ScreenRotationAnimatorTest::RemoveSecondaryDisplay(
|
| const std::string& specs) {
|
| UpdateDisplay(specs);
|
| + QuitWaitForCopyCallback();
|
| +}
|
| +
|
| +void ScreenRotationAnimatorTest::QuitWaitForCopyCallback() {
|
| run_loop_->QuitWhenIdle();
|
| }
|
|
|
| @@ -144,7 +179,8 @@ void ScreenRotationAnimatorTest::SetUp() {
|
|
|
| display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
|
| run_loop_ = base::MakeUnique<base::RunLoop>();
|
| - SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure());
|
| + SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure(),
|
| + run_loop_->QuitWhenIdleClosure());
|
| non_zero_duration_mode_ =
|
| base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
|
| ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
|
| @@ -152,15 +188,17 @@ void ScreenRotationAnimatorTest::SetUp() {
|
|
|
| void ScreenRotationAnimatorTest::SetScreenRotationAnimator(
|
| int64_t display_id,
|
| - const base::Closure& callback) {
|
| - animator_ =
|
| - base::MakeUnique<TestScreenRotationAnimator>(display_id, callback);
|
| + const base::Closure& before_callback,
|
| + const base::Closure& after_callback) {
|
| + animator_ = base::MakeUnique<TestScreenRotationAnimator>(
|
| + display_id, before_callback, after_callback);
|
| test_api_ =
|
| base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
|
| test_api()->DisableAnimationTimers();
|
| }
|
|
|
| void ScreenRotationAnimatorTest::WaitForCopyCallback() {
|
| + run_loop_.reset(new base::RunLoop());
|
| run_loop_->Run();
|
| }
|
|
|
| @@ -305,9 +343,12 @@ TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) {
|
| return;
|
| }
|
|
|
| + SetScreenRotationAnimator(
|
| + display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(),
|
| + base::Bind(&ScreenRotationAnimatorTest::QuitWaitForCopyCallback,
|
| + base::Unretained(this)));
|
| + test_api()->EnableSmoothRotation();
|
| SetDisplayRotation(display_id(), display::Display::ROTATE_0);
|
| - base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kAshEnableSmoothScreenRotation);
|
| animator()->Rotate(display::Display::ROTATE_90,
|
| display::Display::RotationSource::ROTATION_SOURCE_USER);
|
| WaitForCopyCallback();
|
| @@ -317,8 +358,9 @@ TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) {
|
| EXPECT_FALSE(test_api()->HasActiveAnimations());
|
| }
|
|
|
| -// If the external display is removed, it should not crash.
|
| -TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) {
|
| +// If the external secondary display is removed, it should not crash.
|
| +TEST_F(ScreenRotationAnimatorTest,
|
| + RemoveExternalSecondaryDisplayAfterCopyCallback) {
|
| // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
|
| if (Shell::GetAshConfig() == Config::MASH) {
|
| ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
|
| @@ -334,9 +376,9 @@ TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) {
|
| SetScreenRotationAnimator(
|
| display_manager()->GetDisplayAt(1).id(),
|
| base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay,
|
| - base::Unretained(this), "640x480"));
|
| - base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kAshEnableSmoothScreenRotation);
|
| + base::Unretained(this), "640x480"),
|
| + run_loop_->QuitWhenIdleClosure());
|
| + test_api()->EnableSmoothRotation();
|
| SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
|
| display::Display::ROTATE_0);
|
| animator()->Rotate(display::Display::ROTATE_90,
|
| @@ -346,4 +388,36 @@ TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) {
|
| EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
|
| }
|
|
|
| +// If the external primary display is removed, it should not crash.
|
| +TEST_F(ScreenRotationAnimatorTest,
|
| + RemoveExternalPrimaryDisplayAfterCopyCallback) {
|
| + // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
|
| + if (Shell::GetAshConfig() == Config::MASH) {
|
| + ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() !=
|
| + display_id());
|
| + return;
|
| + }
|
| +
|
| + UpdateDisplay("640x480,800x600");
|
| + EXPECT_EQ(2U, display_manager()->GetNumDisplays());
|
| +
|
| + Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
|
| + display_manager()->GetDisplayAt(1).id());
|
| + const unsigned int secondary_display_id =
|
| + display_manager()->GetDisplayAt(0).id();
|
| + SetScreenRotationAnimator(
|
| + display_manager()->GetDisplayAt(1).id(),
|
| + base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay,
|
| + base::Unretained(this), "640x480"),
|
| + run_loop_->QuitWhenIdleClosure());
|
| + test_api()->EnableSmoothRotation();
|
| + SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
|
| + display::Display::ROTATE_0);
|
| + animator()->Rotate(display::Display::ROTATE_90,
|
| + display::Display::RotationSource::ROTATION_SOURCE_USER);
|
| + WaitForCopyCallback();
|
| + EXPECT_EQ(1U, display_manager()->GetNumDisplays());
|
| + EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
|
| +}
|
| +
|
| } // namespace ash
|
|
|