Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 81c20075 authored by Jorge Gil's avatar Jorge Gil Committed by Android (Google) Code Review
Browse files

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

parents 9646f663 a50e0e79
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -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,