Sync BackAnimationControllerTest on master to the version on tm-dev.

The file has diverged quite a bit and is causing merge headaches for ag/18961750.

The updated version is copied verbatim from ToT tm-dev libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java.

Test: atest BackAnimationControllerTest
Bug: 236431156

Change-Id: Ia6fdbef2236c0f49ff66b5e9d48de0db0599f8db
This commit is contained in:
Shan Huang
2022-06-17 17:57:48 -07:00
parent 2e69667e57
commit 73a525b646

View File

@@ -77,7 +77,6 @@ import org.mockito.MockitoAnnotations;
public class BackAnimationControllerTest {
private static final String ANIMATION_ENABLED = "1";
private final TestShellExecutor mShellExecutor = new TestShellExecutor();
@Rule
@@ -184,7 +183,8 @@ public class BackAnimationControllerTest {
// b/207481538, we check that the surface is not moved for now, we can re-enable this once
// we implement the animation
verify(mTransaction, never()).setScale(eq(screenshotSurface), anyInt(), anyInt());
verify(mTransaction, never()).setPosition(animationTarget.leash, 100, 100);
verify(mTransaction, never()).setPosition(
animationTarget.leash, 100, 100);
verify(mTransaction, atLeastOnce()).apply();
}
@@ -218,11 +218,8 @@ public class BackAnimationControllerTest {
// Check that back start and progress is dispatched when first move.
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
verify(mIOnBackInvokedCallback).onBackStarted();
// Check that back progress is dispatched.
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
ArgumentCaptor<BackEvent> backEventCaptor = ArgumentCaptor.forClass(BackEvent.class);
verify(mIOnBackInvokedCallback, atLeastOnce()).onBackProgressed(backEventCaptor.capture());
verify(mIOnBackInvokedCallback).onBackProgressed(backEventCaptor.capture());
assertEquals(animationTarget, backEventCaptor.getValue().getDepartingAnimationTarget());
// Check that back invocation is dispatched.
@@ -231,62 +228,6 @@ public class BackAnimationControllerTest {
verify(mIOnBackInvokedCallback).onBackInvoked();
}
@Test
public void ignoresGesture_transitionInProgress() throws RemoteException {
mController.setBackToLauncherCallback(mIOnBackInvokedCallback);
RemoteAnimationTarget animationTarget = createAnimationTarget();
createNavigationInfo(animationTarget, null, null,
BackNavigationInfo.TYPE_RETURN_TO_HOME, null);
triggerBackGesture();
// Check that back invocation is dispatched.
verify(mIOnBackInvokedCallback).onBackInvoked();
reset(mIOnBackInvokedCallback);
// Verify that we prevent animation from restarting if another gestures happens before
// the previous transition is finished.
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
MotionEvent.ACTION_DOWN,
BackEvent.EDGE_LEFT);
verifyNoMoreInteractions(mIOnBackInvokedCallback);
// Verify that we start accepting gestures again once transition finishes.
mController.onBackToLauncherAnimationFinished();
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
MotionEvent.ACTION_DOWN,
BackEvent.EDGE_LEFT);
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 100, 100, 0),
MotionEvent.ACTION_MOVE,
BackEvent.EDGE_LEFT);
verify(mIOnBackInvokedCallback).onBackStarted();
}
@Test
public void acceptsGesture_transitionTimeout() throws RemoteException {
mController.setBackToLauncherCallback(mIOnBackInvokedCallback);
RemoteAnimationTarget animationTarget = createAnimationTarget();
createNavigationInfo(animationTarget, null, null,
BackNavigationInfo.TYPE_RETURN_TO_HOME, null);
triggerBackGesture();
reset(mIOnBackInvokedCallback);
// Simulate transition timeout.
mShellExecutor.flushAll();
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0),
MotionEvent.ACTION_DOWN,
BackEvent.EDGE_LEFT);
mController.onMotionEvent(
MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 100, 100, 0),
MotionEvent.ACTION_MOVE,
BackEvent.EDGE_LEFT);
verify(mIOnBackInvokedCallback).onBackStarted();
}
@Test
public void animationDisabledFromSettings() throws RemoteException {
// Toggle the setting off
@@ -314,6 +255,47 @@ public class BackAnimationControllerTest {
verify(mIOnBackInvokedCallback, never()).onBackInvoked();
}
@Test
public void ignoresGesture_transitionInProgress() throws RemoteException {
mController.setBackToLauncherCallback(mIOnBackInvokedCallback);
RemoteAnimationTarget animationTarget = createAnimationTarget();
createNavigationInfo(animationTarget, null, null,
BackNavigationInfo.TYPE_RETURN_TO_HOME, null);
triggerBackGesture();
// Check that back invocation is dispatched.
verify(mIOnBackInvokedCallback).onBackInvoked();
reset(mIOnBackInvokedCallback);
// Verify that we prevent animation from restarting if another gestures happens before
// the previous transition is finished.
doMotionEvent(MotionEvent.ACTION_DOWN, 0);
verifyNoMoreInteractions(mIOnBackInvokedCallback);
// Verify that we start accepting gestures again once transition finishes.
mController.onBackToLauncherAnimationFinished();
doMotionEvent(MotionEvent.ACTION_DOWN, 0);
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
verify(mIOnBackInvokedCallback).onBackStarted();
}
@Test
public void acceptsGesture_transitionTimeout() throws RemoteException {
mController.setBackToLauncherCallback(mIOnBackInvokedCallback);
RemoteAnimationTarget animationTarget = createAnimationTarget();
createNavigationInfo(animationTarget, null, null,
BackNavigationInfo.TYPE_RETURN_TO_HOME, null);
triggerBackGesture();
reset(mIOnBackInvokedCallback);
// Simulate transition timeout.
mShellExecutor.flushAll();
doMotionEvent(MotionEvent.ACTION_DOWN, 0);
doMotionEvent(MotionEvent.ACTION_MOVE, 100);
verify(mIOnBackInvokedCallback).onBackStarted();
}
private void doMotionEvent(int actionDown, int coordinate) {
mController.onMotionEvent(
MotionEvent.obtain(0, mEventTime, actionDown, coordinate, coordinate, 0),