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

Commit 66704bca authored by AI test gen's avatar AI test gen Committed by Ang Li
Browse files

Add tests for split button visibility on external displays

Adds unit tests to verify the visibility of the split-screen button in the handle menu when a task is on an external (non-default) display.

The tests cover the behavior with the `enable_non_default_display_split_bugfix` flag both enabled and disabled, ensuring the button is shown or hidden correctly according to the flag's state.

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

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/34622022 (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/L90900030017612015
Bug: 431235865
Flag: TEST_ONLY

Change-Id: I7a7d0db246973b6e5177fcfa13efac7f0bc43d94
parent 89fb94fa
Loading
Loading
Loading
Loading
+59 −2
Original line number Diff line number Diff line
@@ -25,10 +25,12 @@ import android.graphics.Color
import android.graphics.Point
import android.graphics.Rect
import android.graphics.drawable.BitmapDrawable
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.view.Display
import android.view.Display.DEFAULT_DISPLAY
import android.view.LayoutInflater
import android.view.SurfaceControl
import android.view.SurfaceControlViewHost
@@ -240,7 +242,59 @@ class HandleMenuTest : ShellTestCase() {
        assertThat(drawable.bitmap).isEqualTo(mockAppIcon)
    }

    private suspend fun createTaskInfo(windowingMode: Int, splitPosition: Int? = null) {
    @Test
    @DisableFlags(FLAG_ENABLE_NON_DEFAULT_DISPLAY_SPLIT_BUGFIX)
    fun splitButton_onDefaultDisplay_flagOff_isVisible() = runTest {
        createTaskInfo(windowingMode = WINDOWING_MODE_FULLSCREEN, displayId = DEFAULT_DISPLAY)
        val handleMenu = createAndShowHandleMenu()

        val handleMenuView =
            checkNotNull(handleMenu.handleMenuView) { "Expected non-null handle menu view" }
        val splitButton = handleMenuView.rootView.findViewById<View>(R.id.split_screen_button)
        assertThat(splitButton.visibility).isEqualTo(View.VISIBLE)
    }

    @Test
    @DisableFlags(FLAG_ENABLE_NON_DEFAULT_DISPLAY_SPLIT_BUGFIX)
    fun splitButton_onExternalDisplay_flagOff_isGone() = runTest {
        createTaskInfo(windowingMode = WINDOWING_MODE_FULLSCREEN, displayId = EXTERNAL_DISPLAY_ID)
        val handleMenu = createAndShowHandleMenu()

        val handleMenuView =
            checkNotNull(handleMenu.handleMenuView) { "Expected non-null handle menu view" }
        val splitButton = handleMenuView.rootView.findViewById<View>(R.id.split_screen_button)
        assertThat(splitButton.visibility).isEqualTo(View.GONE)
    }

    @Test
    @EnableFlags(FLAG_ENABLE_NON_DEFAULT_DISPLAY_SPLIT_BUGFIX)
    fun splitButton_onExternalDisplay_flagOn_isVisible() = runTest {
        createTaskInfo(windowingMode = WINDOWING_MODE_FULLSCREEN, displayId = EXTERNAL_DISPLAY_ID)
        val handleMenu = createAndShowHandleMenu()

        val handleMenuView =
            checkNotNull(handleMenu.handleMenuView) { "Expected non-null handle menu view" }
        val splitButton = handleMenuView.rootView.findViewById<View>(R.id.split_screen_button)
        assertThat(splitButton.visibility).isEqualTo(View.VISIBLE)
    }

    @Test
    @EnableFlags(FLAG_ENABLE_NON_DEFAULT_DISPLAY_SPLIT_BUGFIX)
    fun splitButton_onDefaultDisplay_flagOn_isVisible() = runTest {
        createTaskInfo(windowingMode = WINDOWING_MODE_FULLSCREEN, displayId = DEFAULT_DISPLAY)
        val handleMenu = createAndShowHandleMenu()

        val handleMenuView =
            checkNotNull(handleMenu.handleMenuView) { "Expected non-null handle menu view" }
        val splitButton = handleMenuView.rootView.findViewById<View>(R.id.split_screen_button)
        assertThat(splitButton.visibility).isEqualTo(View.VISIBLE)
    }

    private suspend fun createTaskInfo(
        windowingMode: Int,
        splitPosition: Int? = null,
        displayId: Int = DEFAULT_DISPLAY
    ) {
        val taskDescriptionBuilder =
            ActivityManager.TaskDescription.Builder().setBackgroundColor(Color.YELLOW)
        val bounds =
@@ -259,7 +313,7 @@ class HandleMenuTest : ShellTestCase() {
            }
        mockDesktopWindowDecoration.mTaskInfo =
            TestRunningTaskInfoBuilder()
                .setDisplayId(Display.DEFAULT_DISPLAY)
                .setDisplayId(displayId)
                .setTaskDescriptionBuilder(taskDescriptionBuilder)
                .setWindowingMode(windowingMode)
                .setBounds(bounds)
@@ -382,5 +436,8 @@ class HandleMenuTest : ShellTestCase() {
        private const val MENU_PILL_SPACING_MARGIN = 4
        private const val HANDLE_WIDTH = 80
        private const val APP_NAME = "Test App"
        private const val EXTERNAL_DISPLAY_ID = 1
        private const val FLAG_ENABLE_NON_DEFAULT_DISPLAY_SPLIT_BUGFIX =
            "com.android.window.flags.enable_non_default_display_split_bugfix"
    }
}