Merge "Add tests for PIP exclusion bounds updates" into sc-dev

This commit is contained in:
Jorge Gil
2021-04-20 14:28:33 +00:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 0 deletions

View File

@@ -38,6 +38,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.function.Consumer;
/**
* Tests for {@link PipBoundsState}.
*/
@@ -178,4 +180,20 @@ public class PipBoundsStateTest extends ShellTestCase {
mPipBoundsState.setOverrideMinSize(new Size(15, 10));
assertEquals(10, mPipBoundsState.getOverrideMinEdgeSize());
}
@Test
public void testSetBounds_updatesPipExclusionBounds() {
final Consumer<Rect> callback = mock(Consumer.class);
final Rect currentBounds = new Rect(10, 10, 20, 15);
final Rect newBounds = new Rect(50, 50, 100, 75);
mPipBoundsState.setBounds(currentBounds);
mPipBoundsState.setPipExclusionBoundsChangeCallback(callback);
// Setting the listener immediately calls back with the current bounds.
verify(callback).accept(currentBounds);
mPipBoundsState.setBounds(newBounds);
// Updating the bounds makes the listener call back back with the new rect.
verify(callback).accept(newBounds);
}
}

View File

@@ -19,6 +19,7 @@ package com.android.wm.shell.pip;
import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_TO_PIP;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -31,6 +32,7 @@ import android.app.ActivityManager;
import android.app.PictureInPictureParams;
import android.content.ComponentName;
import android.content.pm.ActivityInfo;
import android.graphics.Rect;
import android.os.RemoteException;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
@@ -222,6 +224,16 @@ public class PipTaskOrganizerTest extends ShellTestCase {
assertEquals(minSize, mPipBoundsState.getOverrideMinSize());
}
@Test
public void onTaskVanished_clearsPipBounds() {
mSpiedPipTaskOrganizer.onTaskAppeared(createTaskInfo(mComponent1,
createPipParams(null)), null /* leash */);
mPipBoundsState.setBounds(new Rect(100, 100, 200, 150));
mSpiedPipTaskOrganizer.onTaskVanished(createTaskInfo(mComponent1, createPipParams(null)));
assertTrue(mPipBoundsState.getBounds().isEmpty());
}
private void preparePipTaskOrg() {
final DisplayInfo info = new DisplayInfo();
mPipBoundsState.setDisplayLayout(new DisplayLayout(info,