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

Commit 77324b04 authored by AI test gen's avatar AI test gen Committed by Kevin Liu
Browse files

Add test for onMaximizeButtonHoverExit with null view holder

Adds a unit test to verify that calling `onMaximizeButtonHoverExit()` after the window decoration has been closed does not result in a NullPointerException.

This test simulates an edge case where a hover exit event might be received after the decoration's view holder has been destroyed and nulled out, ensuring the added null check correctly prevents a crash.


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

Original Change: ag/35041164
Test: ATP tests passed http://go/forrest-run/L96900030017382731
Bug: 431235865
Flag: TEST_ONLY

Change-Id: Ia416fff098b8bf18aaf0f6d306f4b16acd9f5e4d
parent bdd2d660
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.argThat;
@@ -1944,7 +1943,28 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        try {
            decor.setAnimatingTaskResizeOrReposition(true /* animatingTaskResizeOrReposition */);
        } catch (NullPointerException e) {
            fail("Attempted to access view holder after window decor is closed");
            throw new AssertionError(
                    "Attempted to access view holder after window decor is closed", e);
        }
    }

    @Test
    public void onMaximizeButtonHoverExit_returnsWhenViewHolderIsNull() {
        // Create a freeform task so the decoration has an AppHeaderViewHolder
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
        final DesktopModeWindowDecoration decor =
                spy(createWindowDecoration(taskInfo, true /* relayout */));

        // Close the decor to close the view holder and set it to null
        decor.close();

        // Verify that calling onMaximizeButtonHoverExit does not cause a crash
        try {
            decor.onMaximizeButtonHoverExit();
        } catch (NullPointerException e) {
            throw new AssertionError(
                    "Attempted to access view holder after window decor is closed", e);
        }
    }