Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: ash/rotator/screen_rotation_animator_unittest.cc

Issue 2790583004: Add second copy request after screen rotation to flatten the layers in animation. (Closed)
Patch Set: Move some functions to ash/utility/transformer_util. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 ec03db5a54162820456ae57d7db196a89ca5d9ac..6e239029a82ca21d0b9bbfbf1190406060b0dcc5 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/common/ash_switches.h"
#include "ash/common/wm_shell.h"
+#include "ash/display/window_tree_host_manager.h"
#include "ash/rotator/screen_rotation_animator_observer.h"
#include "ash/rotator/test/screen_rotation_animator_test_api.h"
#include "ash/shell.h"
@@ -57,39 +58,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));
}
@@ -104,6 +133,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(); }
@@ -111,7 +141,9 @@ 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(); }
@@ -134,6 +166,10 @@ class ScreenRotationAnimatorTest : public test::AshTestBase {
void ScreenRotationAnimatorTest::RemoveSecondaryDisplay(
const std::string& specs) {
UpdateDisplay(specs);
+ QuitWaitForCopyCallback();
+}
+
+void ScreenRotationAnimatorTest::QuitWaitForCopyCallback() {
run_loop_->QuitWhenIdle();
}
@@ -142,7 +178,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);
@@ -150,15 +187,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();
}
@@ -303,6 +342,10 @@ TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) {
return;
}
+ SetScreenRotationAnimator(
+ display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(),
+ base::Bind(&ScreenRotationAnimatorTest::QuitWaitForCopyCallback,
+ base::Unretained(this)));
SetDisplayRotation(display_id(), display::Display::ROTATE_0);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableSmoothScreenRotation);
@@ -315,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 (WmShell::Get()->IsRunningInMash()) {
ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() !=
@@ -332,7 +376,8 @@ TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) {
SetScreenRotationAnimator(
display_manager()->GetDisplayAt(1).id(),
base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay,
- base::Unretained(this), "640x480"));
+ base::Unretained(this), "640x480"),
+ run_loop_->QuitWhenIdleClosure());
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableSmoothScreenRotation);
SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
@@ -344,4 +389,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 (WmShell::Get()->IsRunningInMash()) {
+ ASSERT_TRUE(WmShell::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());
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kAshEnableSmoothScreenRotation);
+ 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

Powered by Google App Engine
This is Rietveld 408576698