Loading packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationAnimationControllerTest.java +168 −120 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ import android.graphics.Rect; import android.os.Handler; import android.os.RemoteException; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; import android.view.SurfaceControl; import android.view.View; import android.view.WindowManager; Loading Loading @@ -68,7 +67,6 @@ import java.util.concurrent.atomic.AtomicReference; @LargeTest @RunWith(AndroidTestingRunner.class) @RunWithLooper(setAsMainLooper = true) public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { @Rule Loading Loading @@ -135,7 +133,9 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { @After public void tearDown() throws Exception { mInstrumentation.runOnMainSync(() -> { mController.deleteWindowMagnification(); }); } @Test Loading Loading @@ -170,8 +170,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterX = DEFAULT_CENTER_X + 100; final float targetCenterY = DEFAULT_CENTER_Y + 100; mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, null); enableWindowMagnificationWithoutAnimation(targetScale, targetCenterX, targetCenterY); verifyFinalSpec(targetScale, targetCenterX, targetCenterY); } Loading @@ -179,10 +178,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { @Test public void enableWindowMagnificationWithScaleOne_disabled_NoAnimationAndInvokeCallback() throws RemoteException { mWindowMagnificationAnimationController.enableWindowMagnification(1, enableWindowMagnificationAndWaitAnimating( mWaitAnimationDuration, /* targetScale= */ 1.0f, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, mAnimationCallback); verify(mSpyController).enableWindowMagnificationInternal(1, DEFAULT_CENTER_X, verify(mSpyController).enableWindowMagnificationInternal(1.0f, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, 0f, 0f); verify(mAnimationCallback).onResult(true); } Loading @@ -196,13 +196,15 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterX = DEFAULT_CENTER_X + 100; final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); resetMockObjects(); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback2); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); advanceTimeBy(mWaitAnimationDuration); }); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading @@ -224,9 +226,8 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { enableWindowMagnificationAndWaitAnimating(mWaitPartialAnimationDuration, mAnimationCallback); mWindowMagnificationAnimationController.enableWindowMagnification(Float.NaN, enableWindowMagnificationAndWaitAnimating(mWaitAnimationDuration, Float.NaN, Float.NaN, Float.NaN, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); // The callback in 2nd enableWindowMagnification will return true verify(mAnimationCallback2).onResult(true); Loading @@ -245,12 +246,14 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); advanceTimeBy(mWaitAnimationDuration); }); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading Loading @@ -279,12 +282,14 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); advanceTimeBy(mWaitAnimationDuration); }); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading Loading @@ -314,8 +319,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, null); enableWindowMagnificationWithoutAnimation(targetScale, targetCenterX, targetCenterY); verifyFinalSpec(Float.NaN, Float.NaN, Float.NaN); assertEquals(WindowMagnificationAnimationController.STATE_DISABLED, Loading @@ -333,8 +337,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, null); enableWindowMagnificationWithoutAnimation(targetScale, targetCenterX, targetCenterY); verifyFinalSpec(targetScale, targetCenterX, targetCenterY); verify(mAnimationCallback).onResult(false); Loading @@ -347,9 +350,8 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mAnimationCallback); Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(Float.NaN, Float.NaN, Float.NaN, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); enableWindowMagnificationAndWaitAnimating( mWaitAnimationDuration, Float.NaN, Float.NaN, Float.NaN, mAnimationCallback2); verify(mSpyController, never()).enableWindowMagnificationInternal(anyFloat(), anyFloat(), anyFloat()); Loading @@ -368,20 +370,25 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback2); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); }); // Current spec shouldn't match given spec. verify(mAnimationCallback2, never()).onResult(anyBoolean()); verify(mAnimationCallback).onResult(false); // ValueAnimator.reverse() could not work correctly with the AnimatorTestRule since it is // using SystemClock in reverse() (b/305731398). Therefore, we call end() on the animator // directly to verify the result of animation is correct instead of querying the animation // frame at a specific timing. mInstrumentation.runOnMainSync(() -> { // ValueAnimator.reverse() could not work correctly with the AnimatorTestRule since it // is using SystemClock in reverse() (b/305731398). Therefore, we call end() on the // animator directly to verify the result of animation is correct instead of querying // the animation frame at a specific timing. mValueAnimator.end(); }); verify(mSpyController).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading Loading @@ -410,8 +417,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, null); enableWindowMagnificationWithoutAnimation(targetScale, targetCenterX, targetCenterY); verify(mAnimationCallback).onResult(false); verifyFinalSpec(targetScale, targetCenterX, targetCenterY); Loading @@ -425,9 +431,8 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mAnimationCallback); Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(Float.NaN, enableWindowMagnificationAndWaitAnimating(mWaitAnimationDuration, Float.NaN, Float.NaN, Float.NaN, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); verify(mSpyController, never()).enableWindowMagnificationInternal(anyFloat(), anyFloat(), anyFloat()); Loading @@ -445,12 +450,14 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback2); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); advanceTimeBy(mWaitAnimationDuration); }); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading @@ -471,13 +478,15 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final Rect windowBounds = new Rect(mWindowManager.getCurrentWindowMetrics().getBounds()); Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(DEFAULT_SCALE, windowBounds.exactCenterX(), windowBounds.exactCenterY(), offsetRatio, offsetRatio, mAnimationCallback); advanceTimeBy(mWaitAnimationDuration); }); // We delay the time of verifying to wait for the measurement and layout of the view mHandler.postDelayed(() -> { // Wait for Rects update waitForIdleSync(); final View attachedView = mWindowManager.getAttachedView(); assertNotNull(attachedView); final Rect mirrorViewBound = new Rect(); Loading @@ -489,7 +498,6 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { (int) (mirrorViewBound.exactCenterX() - windowBounds.exactCenterX())); assertEquals((int) (offsetRatio * mirrorViewBound.height() / 2), (int) (mirrorViewBound.exactCenterY() - windowBounds.exactCenterY())); }, 100); } @Test Loading @@ -498,9 +506,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; enableWindowMagnificationWithoutAnimation(); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( targetCenterX, targetCenterY, mAnimationCallback); advanceTimeBy(mWaitAnimationDuration); }); verify(mAnimationCallback).onResult(true); verify(mAnimationCallback, never()).onResult(false); Loading @@ -512,6 +522,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { throws RemoteException { enableWindowMagnificationWithoutAnimation(); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( DEFAULT_CENTER_X + 10, DEFAULT_CENTER_Y + 10, mAnimationCallback); mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( Loading @@ -521,6 +532,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( DEFAULT_CENTER_X + 40, DEFAULT_CENTER_Y + 40, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); }); // only the last one callback will return true verify(mAnimationCallback2).onResult(true); Loading @@ -538,9 +550,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { enableWindowMagnificationAndWaitAnimating(mWaitPartialAnimationDuration, mAnimationCallback); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( targetCenterX, targetCenterY, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); }); // The callback in moveWindowMagnifierToPosition will return true verify(mAnimationCallback2).onResult(true); Loading @@ -556,9 +570,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { enableWindowMagnificationAndWaitAnimating(mWaitPartialAnimationDuration, mAnimationCallback); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( Float.NaN, Float.NaN, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); }); // The callback in moveWindowMagnifierToPosition will return true verify(mAnimationCallback2).onResult(true); Loading @@ -584,6 +600,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { throws RemoteException { enableWindowMagnificationWithoutAnimation(); resetMockObjects(); deleteWindowMagnificationAndWaitAnimating(mWaitAnimationDuration, mAnimationCallback); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( Loading Loading @@ -625,16 +642,18 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mAnimationCallback); Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.deleteWindowMagnification( mAnimationCallback2); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); // ValueAnimator.reverse() could not work correctly with the AnimatorTestRule since it is // using SystemClock in reverse() (b/305731398). Therefore, we call end() on the animator // directly to verify the result of animation is correct instead of querying the animation // frame at a specific timing. // ValueAnimator.reverse() could not work correctly with the AnimatorTestRule since it // is using SystemClock in reverse() (b/305731398). Therefore, we call end() on the // animator directly to verify the result of animation is correct instead of querying // the animation frame at a specific timing. mValueAnimator.end(); }); verify(mSpyController).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading @@ -661,7 +680,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mAnimationCallback); Mockito.reset(mSpyController); mWindowMagnificationAnimationController.deleteWindowMagnification(null); deleteWindowMagnificationWithoutAnimation(); verifyFinalSpec(Float.NaN, Float.NaN, Float.NaN); verify(mAnimationCallback).onResult(false); Loading @@ -673,6 +692,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { deleteWindowMagnificationAndWaitAnimating(mWaitPartialAnimationDuration, mAnimationCallback); resetMockObjects(); deleteWindowMagnificationAndWaitAnimating(mWaitAnimationDuration, mAnimationCallback2); verify(mSpyController).enableWindowMagnificationInternal( Loading Loading @@ -710,8 +730,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float offsetY = (float) Math.ceil(offsetX * WindowMagnificationController.HORIZONTAL_LOCK_BASE) + 1.0f; mController.moveWindowMagnifier(offsetX, offsetY); mInstrumentation.runOnMainSync(()-> mController.moveWindowMagnifier(offsetX, offsetY)); verify(mSpyController).moveWindowMagnifier(offsetX, offsetY); verifyFinalSpec(DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y + offsetY); Loading @@ -726,8 +745,8 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float offsetY = (float) Math.floor(offsetX * WindowMagnificationController.HORIZONTAL_LOCK_BASE) - 1.0f; mController.moveWindowMagnifier(offsetX, offsetY); mInstrumentation.runOnMainSync(() -> mController.moveWindowMagnifier(offsetX, offsetY)); verify(mSpyController).moveWindowMagnifier(offsetX, offsetY); verifyFinalSpec(DEFAULT_SCALE, DEFAULT_CENTER_X + offsetX, DEFAULT_CENTER_Y); Loading @@ -742,8 +761,10 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { (float) Math.ceil(offsetX * WindowMagnificationController.HORIZONTAL_LOCK_BASE); // while diagonal scrolling enabled, // should move with both offsetX and offsetY without regrading offsetY/offsetX mInstrumentation.runOnMainSync(() -> { mController.setDiagonalScrolling(true); mController.moveWindowMagnifier(offsetX, offsetY); }); verify(mSpyController).moveWindowMagnifier(offsetX, offsetY); verifyFinalSpec(DEFAULT_SCALE, DEFAULT_CENTER_X + offsetX, DEFAULT_CENTER_Y + offsetY); Loading @@ -755,9 +776,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; enableWindowMagnificationWithoutAnimation(); mInstrumentation.runOnMainSync(() -> { mController.moveWindowMagnifierToPosition(targetCenterX, targetCenterY, mAnimationCallback); advanceTimeBy(mWaitAnimationDuration); }); verifyFinalSpec(DEFAULT_SCALE, targetCenterX, targetCenterY); } Loading @@ -774,24 +797,49 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { } private void enableWindowMagnificationWithoutAnimation() { Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, null); enableWindowMagnificationWithoutAnimation( DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y); } private void enableWindowMagnificationWithoutAnimation( float targetScale, float targetCenterX, float targetCenterY) { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification( targetScale, targetCenterX, targetCenterY, null); }); } private void enableWindowMagnificationAndWaitAnimating(long duration, @Nullable IRemoteMagnificationAnimationCallback callback) { Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, callback); enableWindowMagnificationAndWaitAnimating( duration, DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, callback); } private void enableWindowMagnificationAndWaitAnimating( long duration, float targetScale, float targetCenterX, float targetCenterY, @Nullable IRemoteMagnificationAnimationCallback callback) { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification( targetScale, targetCenterX, targetCenterY, callback); advanceTimeBy(duration); }); } private void deleteWindowMagnificationWithoutAnimation() { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.deleteWindowMagnification(null); }); } private void deleteWindowMagnificationAndWaitAnimating(long duration, @Nullable IRemoteMagnificationAnimationCallback callback) { resetMockObjects(); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.deleteWindowMagnification(callback); advanceTimeBy(duration); }); } private void verifyStartValue(ArgumentCaptor<Float> captor, float startValue) { Loading Loading
packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationAnimationControllerTest.java +168 −120 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ import android.graphics.Rect; import android.os.Handler; import android.os.RemoteException; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; import android.view.SurfaceControl; import android.view.View; import android.view.WindowManager; Loading Loading @@ -68,7 +67,6 @@ import java.util.concurrent.atomic.AtomicReference; @LargeTest @RunWith(AndroidTestingRunner.class) @RunWithLooper(setAsMainLooper = true) public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { @Rule Loading Loading @@ -135,7 +133,9 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { @After public void tearDown() throws Exception { mInstrumentation.runOnMainSync(() -> { mController.deleteWindowMagnification(); }); } @Test Loading Loading @@ -170,8 +170,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterX = DEFAULT_CENTER_X + 100; final float targetCenterY = DEFAULT_CENTER_Y + 100; mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, null); enableWindowMagnificationWithoutAnimation(targetScale, targetCenterX, targetCenterY); verifyFinalSpec(targetScale, targetCenterX, targetCenterY); } Loading @@ -179,10 +178,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { @Test public void enableWindowMagnificationWithScaleOne_disabled_NoAnimationAndInvokeCallback() throws RemoteException { mWindowMagnificationAnimationController.enableWindowMagnification(1, enableWindowMagnificationAndWaitAnimating( mWaitAnimationDuration, /* targetScale= */ 1.0f, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, mAnimationCallback); verify(mSpyController).enableWindowMagnificationInternal(1, DEFAULT_CENTER_X, verify(mSpyController).enableWindowMagnificationInternal(1.0f, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, 0f, 0f); verify(mAnimationCallback).onResult(true); } Loading @@ -196,13 +196,15 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterX = DEFAULT_CENTER_X + 100; final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); resetMockObjects(); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback2); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); advanceTimeBy(mWaitAnimationDuration); }); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading @@ -224,9 +226,8 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { enableWindowMagnificationAndWaitAnimating(mWaitPartialAnimationDuration, mAnimationCallback); mWindowMagnificationAnimationController.enableWindowMagnification(Float.NaN, enableWindowMagnificationAndWaitAnimating(mWaitAnimationDuration, Float.NaN, Float.NaN, Float.NaN, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); // The callback in 2nd enableWindowMagnification will return true verify(mAnimationCallback2).onResult(true); Loading @@ -245,12 +246,14 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); advanceTimeBy(mWaitAnimationDuration); }); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading Loading @@ -279,12 +282,14 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); advanceTimeBy(mWaitAnimationDuration); }); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading Loading @@ -314,8 +319,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, null); enableWindowMagnificationWithoutAnimation(targetScale, targetCenterX, targetCenterY); verifyFinalSpec(Float.NaN, Float.NaN, Float.NaN); assertEquals(WindowMagnificationAnimationController.STATE_DISABLED, Loading @@ -333,8 +337,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, null); enableWindowMagnificationWithoutAnimation(targetScale, targetCenterX, targetCenterY); verifyFinalSpec(targetScale, targetCenterX, targetCenterY); verify(mAnimationCallback).onResult(false); Loading @@ -347,9 +350,8 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mAnimationCallback); Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(Float.NaN, Float.NaN, Float.NaN, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); enableWindowMagnificationAndWaitAnimating( mWaitAnimationDuration, Float.NaN, Float.NaN, Float.NaN, mAnimationCallback2); verify(mSpyController, never()).enableWindowMagnificationInternal(anyFloat(), anyFloat(), anyFloat()); Loading @@ -368,20 +370,25 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback2); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); }); // Current spec shouldn't match given spec. verify(mAnimationCallback2, never()).onResult(anyBoolean()); verify(mAnimationCallback).onResult(false); // ValueAnimator.reverse() could not work correctly with the AnimatorTestRule since it is // using SystemClock in reverse() (b/305731398). Therefore, we call end() on the animator // directly to verify the result of animation is correct instead of querying the animation // frame at a specific timing. mInstrumentation.runOnMainSync(() -> { // ValueAnimator.reverse() could not work correctly with the AnimatorTestRule since it // is using SystemClock in reverse() (b/305731398). Therefore, we call end() on the // animator directly to verify the result of animation is correct instead of querying // the animation frame at a specific timing. mValueAnimator.end(); }); verify(mSpyController).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading Loading @@ -410,8 +417,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, null); enableWindowMagnificationWithoutAnimation(targetScale, targetCenterX, targetCenterY); verify(mAnimationCallback).onResult(false); verifyFinalSpec(targetScale, targetCenterX, targetCenterY); Loading @@ -425,9 +431,8 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mAnimationCallback); Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(Float.NaN, enableWindowMagnificationAndWaitAnimating(mWaitAnimationDuration, Float.NaN, Float.NaN, Float.NaN, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); verify(mSpyController, never()).enableWindowMagnificationInternal(anyFloat(), anyFloat(), anyFloat()); Loading @@ -445,12 +450,14 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(targetScale, targetCenterX, targetCenterY, mAnimationCallback2); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); advanceTimeBy(mWaitAnimationDuration); }); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading @@ -471,13 +478,15 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final Rect windowBounds = new Rect(mWindowManager.getCurrentWindowMetrics().getBounds()); Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification(DEFAULT_SCALE, windowBounds.exactCenterX(), windowBounds.exactCenterY(), offsetRatio, offsetRatio, mAnimationCallback); advanceTimeBy(mWaitAnimationDuration); }); // We delay the time of verifying to wait for the measurement and layout of the view mHandler.postDelayed(() -> { // Wait for Rects update waitForIdleSync(); final View attachedView = mWindowManager.getAttachedView(); assertNotNull(attachedView); final Rect mirrorViewBound = new Rect(); Loading @@ -489,7 +498,6 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { (int) (mirrorViewBound.exactCenterX() - windowBounds.exactCenterX())); assertEquals((int) (offsetRatio * mirrorViewBound.height() / 2), (int) (mirrorViewBound.exactCenterY() - windowBounds.exactCenterY())); }, 100); } @Test Loading @@ -498,9 +506,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; enableWindowMagnificationWithoutAnimation(); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( targetCenterX, targetCenterY, mAnimationCallback); advanceTimeBy(mWaitAnimationDuration); }); verify(mAnimationCallback).onResult(true); verify(mAnimationCallback, never()).onResult(false); Loading @@ -512,6 +522,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { throws RemoteException { enableWindowMagnificationWithoutAnimation(); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( DEFAULT_CENTER_X + 10, DEFAULT_CENTER_Y + 10, mAnimationCallback); mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( Loading @@ -521,6 +532,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( DEFAULT_CENTER_X + 40, DEFAULT_CENTER_Y + 40, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); }); // only the last one callback will return true verify(mAnimationCallback2).onResult(true); Loading @@ -538,9 +550,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { enableWindowMagnificationAndWaitAnimating(mWaitPartialAnimationDuration, mAnimationCallback); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( targetCenterX, targetCenterY, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); }); // The callback in moveWindowMagnifierToPosition will return true verify(mAnimationCallback2).onResult(true); Loading @@ -556,9 +570,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { enableWindowMagnificationAndWaitAnimating(mWaitPartialAnimationDuration, mAnimationCallback); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.moveWindowMagnifierToPosition( Float.NaN, Float.NaN, mAnimationCallback2); advanceTimeBy(mWaitAnimationDuration); }); // The callback in moveWindowMagnifierToPosition will return true verify(mAnimationCallback2).onResult(true); Loading @@ -584,6 +600,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { throws RemoteException { enableWindowMagnificationWithoutAnimation(); resetMockObjects(); deleteWindowMagnificationAndWaitAnimating(mWaitAnimationDuration, mAnimationCallback); verify(mSpyController, atLeast(2)).enableWindowMagnificationInternal( Loading Loading @@ -625,16 +642,18 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mAnimationCallback); Mockito.reset(mSpyController); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.deleteWindowMagnification( mAnimationCallback2); mCurrentScale.set(mController.getScale()); mCurrentCenterX.set(mController.getCenterX()); mCurrentCenterY.set(mController.getCenterY()); // ValueAnimator.reverse() could not work correctly with the AnimatorTestRule since it is // using SystemClock in reverse() (b/305731398). Therefore, we call end() on the animator // directly to verify the result of animation is correct instead of querying the animation // frame at a specific timing. // ValueAnimator.reverse() could not work correctly with the AnimatorTestRule since it // is using SystemClock in reverse() (b/305731398). Therefore, we call end() on the // animator directly to verify the result of animation is correct instead of querying // the animation frame at a specific timing. mValueAnimator.end(); }); verify(mSpyController).enableWindowMagnificationInternal( mScaleCaptor.capture(), Loading @@ -661,7 +680,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { mAnimationCallback); Mockito.reset(mSpyController); mWindowMagnificationAnimationController.deleteWindowMagnification(null); deleteWindowMagnificationWithoutAnimation(); verifyFinalSpec(Float.NaN, Float.NaN, Float.NaN); verify(mAnimationCallback).onResult(false); Loading @@ -673,6 +692,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { deleteWindowMagnificationAndWaitAnimating(mWaitPartialAnimationDuration, mAnimationCallback); resetMockObjects(); deleteWindowMagnificationAndWaitAnimating(mWaitAnimationDuration, mAnimationCallback2); verify(mSpyController).enableWindowMagnificationInternal( Loading Loading @@ -710,8 +730,7 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float offsetY = (float) Math.ceil(offsetX * WindowMagnificationController.HORIZONTAL_LOCK_BASE) + 1.0f; mController.moveWindowMagnifier(offsetX, offsetY); mInstrumentation.runOnMainSync(()-> mController.moveWindowMagnifier(offsetX, offsetY)); verify(mSpyController).moveWindowMagnifier(offsetX, offsetY); verifyFinalSpec(DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y + offsetY); Loading @@ -726,8 +745,8 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float offsetY = (float) Math.floor(offsetX * WindowMagnificationController.HORIZONTAL_LOCK_BASE) - 1.0f; mController.moveWindowMagnifier(offsetX, offsetY); mInstrumentation.runOnMainSync(() -> mController.moveWindowMagnifier(offsetX, offsetY)); verify(mSpyController).moveWindowMagnifier(offsetX, offsetY); verifyFinalSpec(DEFAULT_SCALE, DEFAULT_CENTER_X + offsetX, DEFAULT_CENTER_Y); Loading @@ -742,8 +761,10 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { (float) Math.ceil(offsetX * WindowMagnificationController.HORIZONTAL_LOCK_BASE); // while diagonal scrolling enabled, // should move with both offsetX and offsetY without regrading offsetY/offsetX mInstrumentation.runOnMainSync(() -> { mController.setDiagonalScrolling(true); mController.moveWindowMagnifier(offsetX, offsetY); }); verify(mSpyController).moveWindowMagnifier(offsetX, offsetY); verifyFinalSpec(DEFAULT_SCALE, DEFAULT_CENTER_X + offsetX, DEFAULT_CENTER_Y + offsetY); Loading @@ -755,9 +776,11 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { final float targetCenterY = DEFAULT_CENTER_Y + 100; enableWindowMagnificationWithoutAnimation(); mInstrumentation.runOnMainSync(() -> { mController.moveWindowMagnifierToPosition(targetCenterX, targetCenterY, mAnimationCallback); advanceTimeBy(mWaitAnimationDuration); }); verifyFinalSpec(DEFAULT_SCALE, targetCenterX, targetCenterY); } Loading @@ -774,24 +797,49 @@ public class WindowMagnificationAnimationControllerTest extends SysuiTestCase { } private void enableWindowMagnificationWithoutAnimation() { Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, null); enableWindowMagnificationWithoutAnimation( DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y); } private void enableWindowMagnificationWithoutAnimation( float targetScale, float targetCenterX, float targetCenterY) { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification( targetScale, targetCenterX, targetCenterY, null); }); } private void enableWindowMagnificationAndWaitAnimating(long duration, @Nullable IRemoteMagnificationAnimationCallback callback) { Mockito.reset(mSpyController); mWindowMagnificationAnimationController.enableWindowMagnification(DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, callback); enableWindowMagnificationAndWaitAnimating( duration, DEFAULT_SCALE, DEFAULT_CENTER_X, DEFAULT_CENTER_Y, callback); } private void enableWindowMagnificationAndWaitAnimating( long duration, float targetScale, float targetCenterX, float targetCenterY, @Nullable IRemoteMagnificationAnimationCallback callback) { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.enableWindowMagnification( targetScale, targetCenterX, targetCenterY, callback); advanceTimeBy(duration); }); } private void deleteWindowMagnificationWithoutAnimation() { mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.deleteWindowMagnification(null); }); } private void deleteWindowMagnificationAndWaitAnimating(long duration, @Nullable IRemoteMagnificationAnimationCallback callback) { resetMockObjects(); mInstrumentation.runOnMainSync(() -> { mWindowMagnificationAnimationController.deleteWindowMagnification(callback); advanceTimeBy(duration); }); } private void verifyStartValue(ArgumentCaptor<Float> captor, float startValue) { Loading