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

Unified Diff: ash/rotator/screen_rotation_animator_unittest.cc

Issue 2919393002: [merge to m60] cros: Do not cache |root_window| in ScreenRotationAnimator. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « ash/rotator/screen_rotation_animator.cc ('k') | ash/test/display_configuration_controller_test_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fa65898242594e67f52b59f6cf3f61ae3dfd0dc4..0736263afb77d8678220290e7952b2ac8cc0df0f 100644
--- a/ash/rotator/screen_rotation_animator_unittest.cc
+++ b/ash/rotator/screen_rotation_animator_unittest.cc
@@ -42,6 +42,11 @@ void SetDisplayRotation(int64_t display_id,
display::Display::RotationSource::ROTATION_SOURCE_USER);
}
+aura::Window* GetRootWindow(int64_t display_id) {
+ return Shell::Get()->window_tree_host_manager()->GetRootWindowForDisplayId(
+ display_id);
+}
+
class AnimationObserver : public ScreenRotationAnimatorObserver {
public:
AnimationObserver() {}
@@ -61,7 +66,7 @@ class AnimationObserver : public ScreenRotationAnimatorObserver {
class TestScreenRotationAnimator : public ScreenRotationAnimator {
public:
- TestScreenRotationAnimator(int64_t display_id,
+ TestScreenRotationAnimator(aura::Window* root_window,
const base::Closure& before_callback,
const base::Closure& after_callback);
~TestScreenRotationAnimator() override {}
@@ -84,10 +89,10 @@ class TestScreenRotationAnimator : public ScreenRotationAnimator {
};
TestScreenRotationAnimator::TestScreenRotationAnimator(
- int64_t display_id,
+ aura::Window* root_window,
const base::Closure& before_callback,
const base::Closure& after_callback)
- : ScreenRotationAnimator(display_id),
+ : ScreenRotationAnimator(root_window),
intersect_before_callback_(before_callback),
intersect_after_callback_(after_callback) {}
@@ -164,7 +169,8 @@ void ScreenRotationAnimatorSlowAnimationTest::SetUp() {
return;
}
- animator_ = base::MakeUnique<ScreenRotationAnimator>(display_.id());
+ animator_ =
+ base::MakeUnique<ScreenRotationAnimator>(GetRootWindow(display_.id()));
test_api_ =
base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
test_api()->DisableAnimationTimers();
@@ -189,7 +195,7 @@ class ScreenRotationAnimatorSmoothAnimationTest : public test::AshTestBase {
TestScreenRotationAnimator* animator() { return animator_.get(); }
- void SetScreenRotationAnimator(int64_t display_id,
+ void SetScreenRotationAnimator(aura::Window* root_window,
const base::Closure& before_callback,
const base::Closure& after_callback);
@@ -236,7 +242,8 @@ void ScreenRotationAnimatorSmoothAnimationTest::SetUp() {
}
run_loop_ = base::MakeUnique<base::RunLoop>();
- SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure(),
+ SetScreenRotationAnimator(GetRootWindow(display_.id()),
+ run_loop_->QuitWhenIdleClosure(),
run_loop_->QuitWhenIdleClosure());
non_zero_duration_mode_ =
base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
@@ -244,11 +251,11 @@ void ScreenRotationAnimatorSmoothAnimationTest::SetUp() {
}
void ScreenRotationAnimatorSmoothAnimationTest::SetScreenRotationAnimator(
- int64_t display_id,
+ aura::Window* root_window,
const base::Closure& before_callback,
const base::Closure& after_callback) {
animator_ = base::MakeUnique<TestScreenRotationAnimator>(
- display_id, before_callback, after_callback);
+ root_window, before_callback, after_callback);
test_api_ =
base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
test_api()->DisableAnimationTimers();
@@ -402,12 +409,13 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
return;
}
+ const int64_t display_id = display_manager()->GetDisplayAt(0).id();
SetScreenRotationAnimator(
- display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(),
+ GetRootWindow(display_id), run_loop_->QuitWhenIdleClosure(),
base::Bind(
&ScreenRotationAnimatorSmoothAnimationTest::QuitWaitForCopyCallback,
base::Unretained(this)));
- SetDisplayRotation(display_id(), display::Display::ROTATE_0);
+ SetDisplayRotation(display_id, display::Display::ROTATE_0);
animator()->Rotate(display::Display::ROTATE_90,
display::Display::RotationSource::ROTATION_SOURCE_USER);
WaitForCopyCallback();
@@ -415,10 +423,11 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
test_api()->CompleteAnimations();
EXPECT_FALSE(test_api()->HasActiveAnimations());
+ EXPECT_EQ(display::Display::ROTATE_90, GetDisplayRotation(display_id));
}
-// If the external secondary display is removed before the first copy request
-// callback called, it should not crash.
+// If the rotating external secondary display is removed before the first copy
+// request callback called, it should stop rotating.
TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
RemoveExternalSecondaryDisplayBeforeFirstCopyCallback) {
// TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
@@ -431,16 +440,16 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
UpdateDisplay("640x480,800x600");
EXPECT_EQ(2U, display_manager()->GetNumDisplays());
- const unsigned int primary_display_id =
- display_manager()->GetDisplayAt(0).id();
+ const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id();
+ const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id();
+
SetScreenRotationAnimator(
- display_manager()->GetDisplayAt(1).id(),
+ GetRootWindow(secondary_display_id),
base::Bind(
&ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
base::Unretained(this), "640x480"),
run_loop_->QuitWhenIdleClosure());
- SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
- display::Display::ROTATE_0);
+ SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0);
animator()->Rotate(display::Display::ROTATE_90,
display::Display::RotationSource::ROTATION_SOURCE_USER);
WaitForCopyCallback();
@@ -448,8 +457,8 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
}
-// If the external primary display is removed before the first copy request
-// callback called, it should not crash.
+// If the rotating external primary display is removed before the first copy
+// request callback called, it should stop rotating.
TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
RemoveExternalPrimaryDisplayBeforeFirstCopyCallback) {
// TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
@@ -464,16 +473,15 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
display_manager()->GetDisplayAt(1).id());
- const unsigned int secondary_display_id =
- display_manager()->GetDisplayAt(0).id();
+ const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id();
+ const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
SetScreenRotationAnimator(
- display_manager()->GetDisplayAt(1).id(),
+ GetRootWindow(primary_display_id),
base::Bind(
&ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
base::Unretained(this), "640x480"),
run_loop_->QuitWhenIdleClosure());
- SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
- display::Display::ROTATE_0);
+ SetDisplayRotation(primary_display_id, display::Display::ROTATE_0);
animator()->Rotate(display::Display::ROTATE_90,
display::Display::RotationSource::ROTATION_SOURCE_USER);
WaitForCopyCallback();
@@ -481,8 +489,8 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id());
}
-// If the external secondary display is removed before the second copy request
-// callback called, it should not crash.
+// If the rotating external secondary display is removed before the second copy
+// request callback called, it should stop rotating.
TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
RemoveExternalSecondaryDisplayBeforeSecondCopyCallback) {
// TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
@@ -495,15 +503,14 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
UpdateDisplay("640x480,800x600");
EXPECT_EQ(2U, display_manager()->GetNumDisplays());
- const unsigned int primary_display_id =
- display_manager()->GetDisplayAt(0).id();
+ const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id();
+ const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id();
SetScreenRotationAnimator(
- display_manager()->GetDisplayAt(1).id(), run_loop_->QuitWhenIdleClosure(),
+ GetRootWindow(secondary_display_id), run_loop_->QuitWhenIdleClosure(),
base::Bind(
&ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
base::Unretained(this), "640x480"));
- SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
- display::Display::ROTATE_0);
+ SetDisplayRotation(secondary_display_id, display::Display::ROTATE_0);
animator()->Rotate(display::Display::ROTATE_90,
display::Display::RotationSource::ROTATION_SOURCE_USER);
WaitForCopyCallback();
@@ -511,8 +518,8 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
}
-// If the external primary display is removed before the second copy request
-// callback called, it should not crash.
+// If the rotating external primary display is removed before the second copy
+// request callback called, it should stop rotating.
TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
RemoveExternalPrimaryDisplayBeforeSecondCopyCallback) {
// TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
@@ -527,20 +534,53 @@ TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId(
display_manager()->GetDisplayAt(1).id());
- const unsigned int secondary_display_id =
- display_manager()->GetDisplayAt(0).id();
+ const int64_t primary_display_id = display_manager()->GetDisplayAt(1).id();
+ const int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
SetScreenRotationAnimator(
- display_manager()->GetDisplayAt(1).id(), run_loop_->QuitWhenIdleClosure(),
+ GetRootWindow(primary_display_id), run_loop_->QuitWhenIdleClosure(),
base::Bind(
&ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
base::Unretained(this), "640x480"));
- SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
- display::Display::ROTATE_0);
+ SetDisplayRotation(primary_display_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());
+}
+
+// If the external primary display is removed while rotating the secondary
+// display. It should stop rotating the secondary display because the
+// |root_window| changed.
+TEST_F(ScreenRotationAnimatorSmoothAnimationTest,
+ RemoveExternalPrimaryDisplayDuringAnimationChangedRootWindow) {
+ // 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 int64_t secondary_display_id = display_manager()->GetDisplayAt(0).id();
+ SetScreenRotationAnimator(
+ GetRootWindow(secondary_display_id),
+ base::Bind(
+ &ScreenRotationAnimatorSmoothAnimationTest::RemoveSecondaryDisplay,
+ base::Unretained(this), "640x480"),
+ run_loop_->QuitWhenIdleClosure());
+ SetDisplayRotation(secondary_display_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());
+ EXPECT_EQ(display::Display::ROTATE_0,
+ GetDisplayRotation(secondary_display_id));
}
} // namespace ash
« no previous file with comments | « ash/rotator/screen_rotation_animator.cc ('k') | ash/test/display_configuration_controller_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698