From 5632f4b1bd82a40190cbd5747f76967f8ac25a00 Mon Sep 17 00:00:00 2001 From: ryanlwlin Date: Wed, 25 Aug 2021 14:37:54 +0800 Subject: [PATCH] Fix rotation test faiulre on foldable devices In our test, we assume the device is under portrait mode, which is not true for foldables. To fix it, we caclue the rotation degree based on the current rotation. Bug: 197623044 Test: run WindowMagnificationControllerTest with the device under the landscape mode. Change-Id: I4c27a193af05f402246aa8b3b490e8bde9d93fc7 --- .../accessibility/WindowMagnificationControllerTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java index 77941366b4d3b..323b5fe4636ff 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationControllerTest.java @@ -252,7 +252,9 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { @Test public void onOrientationChanged_enabled_updateDisplayRotationAndCenterStayAtSamePosition() { final Display display = Mockito.spy(mContext.getDisplay()); - when(display.getRotation()).thenReturn(Surface.ROTATION_90); + final int currentRotation = display.getRotation(); + final int newRotation = (currentRotation + 1) % 4; + when(display.getRotation()).thenReturn(newRotation); when(mContext.getDisplay()).thenReturn(display); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationController.enableWindowMagnification(Float.NaN, Float.NaN, @@ -261,7 +263,7 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { final PointF expectedCenter = new PointF(mWindowMagnificationController.getCenterY(), mWindowMagnificationController.getCenterX()); final Rect windowBounds = new Rect(mWindowManager.getCurrentWindowMetrics().getBounds()); - // Rotate the window 90 degrees. + // Rotate the window clockwise 90 degree. windowBounds.set(windowBounds.top, windowBounds.left, windowBounds.bottom, windowBounds.right); mWindowManager.setWindowBounds(windowBounds); @@ -270,7 +272,7 @@ public class WindowMagnificationControllerTest extends SysuiTestCase { mWindowMagnificationController.onConfigurationChanged(ActivityInfo.CONFIG_ORIENTATION); }); - assertEquals(Surface.ROTATION_90, mWindowMagnificationController.mRotation); + assertEquals(newRotation, mWindowMagnificationController.mRotation); final PointF actualCenter = new PointF(mWindowMagnificationController.getCenterX(), mWindowMagnificationController.getCenterY()); assertEquals(expectedCenter, actualCenter);