Merge "Add tests to verify last pip component name updates"

This commit is contained in:
Jorge Gil
2020-10-28 20:34:17 +00:00
committed by Android (Google) Code Review
5 changed files with 108 additions and 32 deletions

View File

@@ -69,11 +69,13 @@ public class PipTaskOrganizerTest extends PipTestCase {
private PipBoundsState mPipBoundsState;
private ComponentName mComponent1;
private ComponentName mComponent2;
@Before
public void setUp() throws RemoteException {
MockitoAnnotations.initMocks(this);
mComponent1 = new ComponentName(mContext, "component1");
mComponent2 = new ComponentName(mContext, "component2");
mPipBoundsState = new PipBoundsState();
mSpiedPipTaskOrganizer = spy(new PipTaskOrganizer(mContext, mPipBoundsState,
mMockPipBoundsHandler, mMockPipSurfaceTransactionHelper, mMockOptionalSplitScreen,
@@ -100,30 +102,58 @@ public class PipTaskOrganizerTest extends PipTestCase {
assertEquals(aspectRatio.floatValue(), mPipBoundsState.getAspectRatio(), 0.01f);
}
@Test
public void startSwipePipToHome_updatesLastPipComponentName() {
mSpiedPipTaskOrganizer.startSwipePipToHome(mComponent1, null, null);
assertEquals(mComponent1, mPipBoundsState.getLastPipComponentName());
}
@Test
public void onTaskAppeared_updatesAspectRatio() {
final Rational aspectRatio = new Rational(2, 1);
mSpiedPipTaskOrganizer.onTaskAppeared(createTaskInfo(
mSpiedPipTaskOrganizer.onTaskAppeared(createTaskInfo(mComponent1,
createPipParams(aspectRatio)), null /* leash */);
assertEquals(aspectRatio.floatValue(), mPipBoundsState.getAspectRatio(), 0.01f);
}
@Test
public void onTaskAppeared_updatesLastPipComponentName() {
mSpiedPipTaskOrganizer.onTaskAppeared(createTaskInfo(mComponent1, createPipParams(null)),
null /* leash */);
assertEquals(mComponent1, mPipBoundsState.getLastPipComponentName());
}
@Test
public void onTaskInfoChanged_updatesAspectRatioIfChanged() {
final Rational startAspectRatio = new Rational(2, 1);
final Rational newAspectRatio = new Rational(1, 2);
mSpiedPipTaskOrganizer.onTaskAppeared(createTaskInfo(
mSpiedPipTaskOrganizer.onTaskAppeared(createTaskInfo(mComponent1,
createPipParams(startAspectRatio)), null /* leash */);
mSpiedPipTaskOrganizer.onTaskInfoChanged(createTaskInfo(createPipParams(newAspectRatio)));
mSpiedPipTaskOrganizer.onTaskInfoChanged(createTaskInfo(mComponent1,
createPipParams(newAspectRatio)));
assertEquals(newAspectRatio.floatValue(), mPipBoundsState.getAspectRatio(), 0.01f);
}
@Test
public void onTaskInfoChanged_updatesLastPipComponentName() {
mSpiedPipTaskOrganizer.onTaskAppeared(createTaskInfo(mComponent1,
createPipParams(null)), null /* leash */);
mSpiedPipTaskOrganizer.onTaskInfoChanged(createTaskInfo(mComponent2,
createPipParams(null)));
assertEquals(mComponent2, mPipBoundsState.getLastPipComponentName());
}
private void preparePipTaskOrg() {
final DisplayInfo info = new DisplayInfo();
mPipBoundsState.setDisplayInfo(info);
when(mMockPipBoundsHandler.getDestinationBounds(any(), any())).thenReturn(new Rect());
when(mMockPipBoundsHandler.getDestinationBounds(any(), any(), anyBoolean()))
.thenReturn(new Rect());
@@ -133,10 +163,12 @@ public class PipTaskOrganizerTest extends PipTestCase {
doNothing().when(mSpiedPipTaskOrganizer).scheduleAnimateResizePip(any(), anyInt(), any());
}
private static ActivityManager.RunningTaskInfo createTaskInfo(PictureInPictureParams params) {
private static ActivityManager.RunningTaskInfo createTaskInfo(
ComponentName componentName, PictureInPictureParams params) {
final ActivityManager.RunningTaskInfo info = new ActivityManager.RunningTaskInfo();
info.token = mock(WindowContainerToken.class);
info.pictureInPictureParams = params;
info.topActivity = componentName;
return info;
}

View File

@@ -20,11 +20,14 @@ import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.RemoteException;
@@ -34,6 +37,7 @@ import android.testing.TestableLooper;
import com.android.wm.shell.WindowManagerShellWrapper;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.pip.PipBoundsHandler;
import com.android.wm.shell.pip.PipBoundsState;
import com.android.wm.shell.pip.PipMediaController;
@@ -64,6 +68,7 @@ public class PipControllerTest extends PipTestCase {
@Mock private PipTouchHandler mMockPipTouchHandler;
@Mock private WindowManagerShellWrapper mMockWindowManagerShellWrapper;
@Mock private PipBoundsState mMockPipBoundsState;
@Mock private ShellExecutor mMockExecutor;
@Before
public void setUp() throws RemoteException {
@@ -71,7 +76,11 @@ public class PipControllerTest extends PipTestCase {
mPipController = new PipController(mContext, mMockDisplayController,
mMockPipAppOpsListener, mMockPipBoundsHandler, mMockPipBoundsState,
mMockPipMediaController, mMockPipMenuActivityController, mMockPipTaskOrganizer,
mMockPipTouchHandler, mMockWindowManagerShellWrapper);
mMockPipTouchHandler, mMockWindowManagerShellWrapper, mMockExecutor);
doAnswer(invocation -> {
((Runnable) invocation.getArgument(0)).run();
return null;
}).when(mMockExecutor).execute(any());
}
@Test
@@ -99,6 +108,27 @@ public class PipControllerTest extends PipTestCase {
assertNull(PipController.create(spyContext, mMockDisplayController,
mMockPipAppOpsListener, mMockPipBoundsHandler, mMockPipBoundsState,
mMockPipMediaController, mMockPipMenuActivityController, mMockPipTaskOrganizer,
mMockPipTouchHandler, mMockWindowManagerShellWrapper));
mMockPipTouchHandler, mMockWindowManagerShellWrapper, mMockExecutor));
}
@Test
public void onActivityHidden_isLastPipComponentName_clearLastPipComponent() {
final ComponentName component1 = new ComponentName(mContext, "component1");
when(mMockPipBoundsState.getLastPipComponentName()).thenReturn(component1);
mPipController.mPinnedStackListener.onActivityHidden(component1);
verify(mMockPipBoundsState).setLastPipComponentName(null);
}
@Test
public void onActivityHidden_isNotLastPipComponentName_lastPipComponentNotCleared() {
final ComponentName component1 = new ComponentName(mContext, "component1");
final ComponentName component2 = new ComponentName(mContext, "component2");
when(mMockPipBoundsState.getLastPipComponentName()).thenReturn(component1);
mPipController.mPinnedStackListener.onActivityHidden(component2);
verify(mMockPipBoundsState, never()).setLastPipComponentName(null);
}
}