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

Unified Diff: ash/rotator/screen_rotation_animator_unittest.cc

Issue 2780823002: Uses copy request to flatten the layers to do screen rotation animation. (Closed)
Patch Set: Resolve merge conflicts. 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
« no previous file with comments | « ash/rotator/screen_rotation_animator.cc ('k') | chrome/browser/about_flags.cc » ('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 9a84d05cae456e29bdac0dabb21ce6dd35ac008e..ec03db5a54162820456ae57d7db196a89ca5d9ac 100644
--- a/ash/rotator/screen_rotation_animator_unittest.cc
+++ b/ash/rotator/screen_rotation_animator_unittest.cc
@@ -3,12 +3,18 @@
// found in the LICENSE file.
#include "ash/rotator/screen_rotation_animator.h"
+#include "ash/common/ash_switches.h"
#include "ash/common/wm_shell.h"
#include "ash/rotator/screen_rotation_animator_observer.h"
#include "ash/rotator/test/screen_rotation_animator_test_api.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
+#include "base/callback_forward.h"
+#include "base/command_line.h"
#include "base/memory/ptr_util.h"
+#include "base/run_loop.h"
+#include "cc/output/copy_output_request.h"
+#include "cc/output/copy_output_result.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/display.h"
#include "ui/display/manager/display_manager.h"
@@ -49,6 +55,44 @@ class AnimationObserver : public ScreenRotationAnimatorObserver {
DISALLOW_COPY_AND_ASSIGN(AnimationObserver);
};
+class TestScreenRotationAnimator : public ScreenRotationAnimator {
+ public:
+ TestScreenRotationAnimator(int64_t display_id, const base::Closure& callback);
+ ~TestScreenRotationAnimator() override {}
+
+ private:
+ CopyCallback CreateAfterCopyCallback(
+ std::unique_ptr<ScreenRotationRequest> rotation_request) override;
+
+ void IntersectBefore(CopyCallback next_callback,
+ std::unique_ptr<cc::CopyOutputResult> result);
+
+ base::Closure intersect_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator);
+};
+
+TestScreenRotationAnimator::TestScreenRotationAnimator(
+ int64_t display_id,
+ const base::Closure& callback)
+ : ScreenRotationAnimator(display_id), intersect_callback_(callback) {}
+
+ScreenRotationAnimator::CopyCallback
+TestScreenRotationAnimator::CreateAfterCopyCallback(
+ std::unique_ptr<ScreenRotationRequest> rotation_request) {
+ CopyCallback next_callback = ScreenRotationAnimator::CreateAfterCopyCallback(
+ std::move(rotation_request));
+ return base::Bind(&TestScreenRotationAnimator::IntersectBefore,
+ base::Unretained(this), next_callback);
+}
+
+void TestScreenRotationAnimator::IntersectBefore(
+ CopyCallback next_callback,
+ std::unique_ptr<cc::CopyOutputResult> result) {
+ intersect_callback_.Run();
+ next_callback.Run(std::move(result));
+}
+
} // namespace
class ScreenRotationAnimatorTest : public test::AshTestBase {
@@ -59,38 +103,65 @@ class ScreenRotationAnimatorTest : public test::AshTestBase {
// AshTestBase:
void SetUp() override;
+ void RemoveSecondaryDisplay(const std::string& specs);
+
protected:
int64_t display_id() const { return display_.id(); }
- ScreenRotationAnimator* animator() { return animator_.get(); }
+ TestScreenRotationAnimator* animator() { return animator_.get(); }
+
+ void SetScreenRotationAnimator(int64_t display_id,
+ const base::Closure& callback);
test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); }
- std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_;
+ void WaitForCopyCallback();
+
+ std::unique_ptr<base::RunLoop> run_loop_;
private:
display::Display display_;
- std::unique_ptr<ScreenRotationAnimator> animator_;
+ std::unique_ptr<TestScreenRotationAnimator> animator_;
std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_;
+ std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_;
+
DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest);
};
+void ScreenRotationAnimatorTest::RemoveSecondaryDisplay(
+ const std::string& specs) {
+ UpdateDisplay(specs);
+ run_loop_->QuitWhenIdle();
+}
+
void ScreenRotationAnimatorTest::SetUp() {
AshTestBase::SetUp();
display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
- animator_ = base::MakeUnique<ScreenRotationAnimator>(display_.id());
- test_api_ =
- base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
- test_api()->DisableAnimationTimers();
+ run_loop_ = base::MakeUnique<base::RunLoop>();
+ SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure());
non_zero_duration_mode_ =
base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
}
+void ScreenRotationAnimatorTest::SetScreenRotationAnimator(
+ int64_t display_id,
+ const base::Closure& callback) {
+ animator_ =
+ base::MakeUnique<TestScreenRotationAnimator>(display_id, callback);
+ test_api_ =
+ base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
+ test_api()->DisableAnimationTimers();
+}
+
+void ScreenRotationAnimatorTest::WaitForCopyCallback() {
+ run_loop_->Run();
+}
+
TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) {
// TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
if (WmShell::Get()->IsRunningInMash()) {
@@ -223,4 +294,54 @@ TEST_F(ScreenRotationAnimatorTest, ShouldCompleteAnimations) {
EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id()));
}
+// Test enable smooth screen rotation code path.
+TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) {
+ // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
+ if (WmShell::Get()->IsRunningInMash()) {
+ ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() !=
+ display_id());
+ return;
+ }
+
+ 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();
+ EXPECT_TRUE(test_api()->HasActiveAnimations());
+
+ test_api()->CompleteAnimations();
+ EXPECT_FALSE(test_api()->HasActiveAnimations());
+}
+
+// If the external display is removed, it should not crash.
+TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) {
+ // 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());
+
+ const unsigned int primary_display_id =
+ display_manager()->GetDisplayAt(0).id();
+ SetScreenRotationAnimator(
+ display_manager()->GetDisplayAt(1).id(),
+ base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay,
+ base::Unretained(this), "640x480"));
+ 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(primary_display_id, display_manager()->GetDisplayAt(0).id());
+}
+
} // namespace ash
« no previous file with comments | « ash/rotator/screen_rotation_animator.cc ('k') | chrome/browser/about_flags.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698