From d1ec1be037f339c1e153748d6f4e9602675f19fc Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Tue, 14 Mar 2023 02:34:54 +0000 Subject: [PATCH] Add test mapping for back animation Add the TEST_MAPPING for back animation. Add unit tests for CrossTaskBackAnimation and CrossActivityAnimation. Test: atest --test-mapping Bug: 262322161 Bug: 262322082 Bug: 262322245 Change-Id: I35c195cfbc1aaeca4989d705e39bdcc0ef9fb5ea --- .../wm/shell/back/BackAnimationRunner.java | 2 +- .../com/android/wm/shell/back/TEST_MAPPING | 32 +++++++++++++ .../Shell/tests/unittest/Android.bp | 2 + .../back/BackAnimationControllerTest.java | 47 +++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 libs/WindowManager/Shell/src/com/android/wm/shell/back/TEST_MAPPING diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationRunner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationRunner.java index 22b841a338c18..913239f74bf2f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationRunner.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationRunner.java @@ -75,7 +75,7 @@ class BackAnimationRunner { }; mWaitingAnimation = false; try { - mRunner.onAnimationStart(TRANSIT_OLD_UNSET, apps, wallpapers, + getRunner().onAnimationStart(TRANSIT_OLD_UNSET, apps, wallpapers, nonApps, callback); } catch (RemoteException e) { Log.w(TAG, "Failed call onAnimationStart", e); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/TEST_MAPPING b/libs/WindowManager/Shell/src/com/android/wm/shell/back/TEST_MAPPING new file mode 100644 index 0000000000000..837d5ff3b073c --- /dev/null +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/TEST_MAPPING @@ -0,0 +1,32 @@ +{ + "presubmit": [ + { + "name": "WMShellUnitTests", + "options": [ + { + "exclude-annotation": "androidx.test.filters.FlakyTest" + }, + { + "include-filter": "com.android.wm.shell.back" + } + ] + }, + { + "name": "CtsWindowManagerDeviceTestCases", + "options": [ + { + "exclude-annotation": "androidx.test.filters.FlakyTest" + }, + { + "include-filter": "android.server.wm.BackGestureInvokedTest" + }, + { + "include-filter": "android.server.wm.BackNavigationTests" + }, + { + "include-filter": "android.server.wm.OnBackInvokedCallbackGestureTest" + } + ] + } + ] +} diff --git a/libs/WindowManager/Shell/tests/unittest/Android.bp b/libs/WindowManager/Shell/tests/unittest/Android.bp index 2ac1dc0c4838c..57a698128d773 100644 --- a/libs/WindowManager/Shell/tests/unittest/Android.bp +++ b/libs/WindowManager/Shell/tests/unittest/Android.bp @@ -69,6 +69,8 @@ android_test { enabled: false, }, + test_suites: ["device-tests"], + platform_apis: true, certificate: "platform", diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java index 6dae479ae7a78..169b9bd4dea72 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java @@ -411,6 +411,53 @@ public class BackAnimationControllerTest extends ShellTestCase { verify(mAnimatorCallback, never()).onBackInvoked(); } + @Test + public void testBackToActivity() throws RemoteException { + final CrossActivityAnimation animation = new CrossActivityAnimation(mContext, + mAnimationBackground); + verifySystemBackBehavior( + BackNavigationInfo.TYPE_CROSS_ACTIVITY, animation.mBackAnimationRunner); + } + + @Test + public void testBackToTask() throws RemoteException { + final CrossTaskBackAnimation animation = new CrossTaskBackAnimation(mContext, + mAnimationBackground); + verifySystemBackBehavior( + BackNavigationInfo.TYPE_CROSS_TASK, animation.mBackAnimationRunner); + } + + private void verifySystemBackBehavior(int type, BackAnimationRunner animation) + throws RemoteException { + final BackAnimationRunner animationRunner = spy(animation); + final IRemoteAnimationRunner runner = spy(animationRunner.getRunner()); + final IOnBackInvokedCallback callback = spy(animationRunner.getCallback()); + + // Set up the monitoring objects. + doNothing().when(runner).onAnimationStart(anyInt(), any(), any(), any(), any()); + doReturn(runner).when(animationRunner).getRunner(); + doReturn(callback).when(animationRunner).getCallback(); + + mController.registerAnimation(type, animationRunner); + + createNavigationInfo(type, true); + + doMotionEvent(MotionEvent.ACTION_DOWN, 0); + + // Check that back start and progress is dispatched when first move. + doMotionEvent(MotionEvent.ACTION_MOVE, 100); + + simulateRemoteAnimationStart(type); + + verify(callback).onBackStarted(any(BackMotionEvent.class)); + verify(animationRunner).startAnimation(any(), any(), any(), any()); + + // Check that back invocation is dispatched. + mController.setTriggerBack(true); // Fake trigger back + doMotionEvent(MotionEvent.ACTION_UP, 0); + verify(callback).onBackInvoked(); + } + private void doMotionEvent(int actionDown, int coordinate) { mController.onMotionEvent( coordinate, coordinate,