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

Commit 4958630c authored by AI test gen's avatar AI test gen Committed by Ang Li
Browse files

Add test for providing IME insets to freeform windows

Adds a unit test for `InsetsPolicy#enforceInsetsPolicyForTarget` to
verify that IME insets are correctly provided to floating windows.

The test covers the following scenarios:
- A window in the same task as the IME target receives IME insets.
- The IME target window itself receives IME insets.
- A window in a different task does not receive IME insets.
- No window receives IME insets if the IME is not requested to be
  visible.
- Pinned (Picture-in-Picture) windows do not receive IME insets.

Please help fill out the survey for feedback: https://docs.google.com/forms/d/e/1FAIpQLSeKFKpHImCAqZIa_OR801cw72HQUreM2oGM25C3mKKT2tBFnw/viewform?usp=pp_url&entry.1586624956=ag/35495073

Please feel free to make changes to the generated tests based on your domain knowledge. More context about the project please see go/ai-testgen

Original Change: ag/35419508 (Note tests are based on the original CL but may add coverage beyond the specific changes to improve overall code health)

Test: ATP tests passed http://go/forrest-run/L34900030017616815
Bug: 431235865
Flag: TEST_ONLY

Change-Id: Ia93cf86c77444a366e52292c4d54b0e9646aba37
parent e5734fd9
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ package com.android.server.wm;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.view.InsetsSource.ID_IME;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.navigationBars;
import static android.view.WindowInsets.Type.statusBars;
@@ -907,6 +909,69 @@ public class InsetsPolicyTest extends WindowTestsBase {
        assertEquals(Insets.NONE, imeInsetsHidden);
    }

    @Test
    public void testEnforceInsetsPolicyForTarget_imeInsetsForFreeform() {
        final InsetsPolicy policy = mDisplayContent.getInsetsPolicy();
        final InsetsState originalState = new InsetsState();
        final int captionBarId = InsetsSource.createId(null, 0, captionBar());
        final InsetsSource captionBarSource = new InsetsSource(captionBarId, captionBar());
        final InsetsSource imeSource = new InsetsSource(ID_IME, ime());
        imeSource.setVisible(true);
        originalState.addSource(imeSource);
        originalState.addSource(captionBarSource);

        // Create two windows in the same freeform task.
        final Task freeformTask = createTask(mDisplayContent, WINDOWING_MODE_FREEFORM,
                ACTIVITY_TYPE_STANDARD);
        final WindowState imeTargetWindow = createAppWindow(freeformTask, TYPE_APPLICATION,
                "imeTarget");
        final WindowState anotherWindowInSameTask = createAppWindow(freeformTask, TYPE_APPLICATION,
                "anotherWindow");

        // Create a window in a different freeform task.
        final Task anotherFreeformTask = createTask(mDisplayContent, WINDOWING_MODE_FREEFORM,
                ACTIVITY_TYPE_STANDARD);
        final WindowState windowInDifferentTask = createAppWindow(
                anotherFreeformTask, TYPE_APPLICATION, "windowInDifferentTask");

        // Set the IME target and request IME visibility.
        mDisplayContent.setImeInputTarget(imeTargetWindow);
        imeTargetWindow.setRequestedVisibleTypes(ime(), ime());

        // Case 1: A window in the same task as the IME target should receive IME insets.
        InsetsState resultState = policy.enforceInsetsPolicyForTarget(
                anotherWindowInSameTask, originalState);
        assertEquals(
                "Window in same task should get IME insets",
                imeSource, resultState.peekSource(ID_IME));
        // It should also keep other insets like caption bar for floating windows.
        resultState = policy.enforceInsetsPolicyForTarget(
                anotherWindowInSameTask, originalState);
        assertEquals("Window in same task should still get IME insets",
                imeSource, resultState.peekSource(ID_IME));
        assertEquals("Floating window should keep caption bar insets",
                captionBarSource, resultState.peekSource(captionBarId));

        // Case 2: The IME target window itself should receive IME insets.
        resultState = policy.enforceInsetsPolicyForTarget(imeTargetWindow, originalState);
        assertEquals("IME target window should get IME insets",
                imeSource, resultState.peekSource(ID_IME));

        // Case 3: A window in a different task should NOT receive IME insets.
        resultState = policy.enforceInsetsPolicyForTarget(windowInDifferentTask, originalState);
        assertNull("Window in different task should not get IME insets",
                resultState.peekSource(ID_IME));

        // Case 4: Pinned (PIP) window should not receive IME insets.
        final Task pinnedTask = createTask(mDisplayContent, WINDOWING_MODE_PINNED,
                ACTIVITY_TYPE_STANDARD);
        final WindowState pinnedWindow = createAppWindow(pinnedTask, TYPE_APPLICATION,
                "pinnedWindow");
        mDisplayContent.setImeInputTarget(pinnedWindow);
        resultState = policy.enforceInsetsPolicyForTarget(pinnedWindow, originalState);
        assertNull("Pinned window should not get IME insets", resultState.peekSource(ID_IME));
    }


    private WindowState addNavigationBar() {
        final Binder owner = new Binder();