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

Commit 789d8950 authored by Charles Chen's avatar Charles Chen
Browse files

Verify dismissing with bubble bar handle

Test: atest DismissExpandedBubbleViaBubbleBarHandleTest
Bug: 396020056
Flag: TEST_ONLY

Change-Id: Iffa0d4b0e8dcf42206a3bc98c2790ddfd68ebaac
parent 0d5adbee
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ class BubbleBarMovesTest(navBar: NavBar) : BubbleFlickerTestBase(), ExpandBubble
                Root.get().bubbleBar.dragToTheOtherSide()
                val bubbleBarAfterTransition = Root.get().bubbleBar.visibleCenter
                bubbleBarPosChanges = (bubbleBarBeforeTransition != bubbleBarAfterTransition)
                expandBubbleAppViaBubbleBar(uiDevice, testApp, wmHelper)
                expandBubbleAppViaBubbleBar(testApp, uiDevice, wmHelper)
            },
            tearDownAfterTransition = { testApp.exit(wmHelper) }
        )
+86 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.flicker.bubbles

import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresFlagsEnabled
import android.tools.NavBar
import androidx.test.filters.RequiresDevice
import com.android.wm.shell.Flags
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.bubbles.testcase.DismissExpandedBubbleTestCases
import com.android.wm.shell.flicker.bubbles.utils.ApplyPerParameterRule
import com.android.wm.shell.flicker.bubbles.utils.FlickerPropertyInitializer
import com.android.wm.shell.flicker.bubbles.utils.RecordTraceWithTransitionRule
import com.android.wm.shell.flicker.bubbles.utils.dismissBubbleAppViaBubbleBarHandle
import com.android.wm.shell.flicker.bubbles.utils.launchBubbleViaBubbleMenu
import org.junit.Assume.assumeTrue
import org.junit.Before
import org.junit.FixMethodOrder
import org.junit.Rule
import org.junit.runners.MethodSorters

/**
 * Test dismiss bubble app via dragging bubble bar handle to the dismiss view when the bubble is in
 * expanded state.
 *
 * To run this test:
 *     `atest WMShellExplicitFlickerTestsBubbles:DismissExpandedBubbleViaBubbleBarHandleTest`
 *
 * Pre-steps:
 * ```
 *     Launch [testApp] into bubble
 * ```
 *
 * Actions:
 * ```
 *     Dismiss bubble app via dragging bubble bar handle to the dismiss view
 * ```
 * Verified tests:
 * - [BubbleFlickerTestBase]
 * - [DismissExpandedBubbleTestCases]
 */
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE)
@RequiresDevice
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Presubmit
class DismissExpandedBubbleViaBubbleBarHandleTest(navBar: NavBar) : BubbleFlickerTestBase(),
    DismissExpandedBubbleTestCases {
    companion object : FlickerPropertyInitializer() {
        private val recordTraceWithTransitionRule = RecordTraceWithTransitionRule(
            setUpBeforeTransition = { launchBubbleViaBubbleMenu(testApp, tapl, wmHelper) },
            transition = { dismissBubbleAppViaBubbleBarHandle(testApp, wmHelper) },
            tearDownAfterTransition = { testApp.exit() }
        )
    }

    @get:Rule
    val setUpRule = ApplyPerParameterRule(
        Utils.testSetupRule(navBar).around(recordTraceWithTransitionRule),
        params = arrayOf(navBar)
    )

    override val traceDataReader
        get() = recordTraceWithTransitionRule.reader

    @Before
    override fun setUp() {
        // Bubble bar is only enabled on large screen device.
        assumeTrue(tapl.isTablet)
        super.setUp()
    }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ class ExpandBubbleViaBubbleStackTest(navBar: NavBar) : BubbleFlickerTestBase(),
                launchBubbleViaBubbleMenu(testApp, tapl, wmHelper)
                collapseBubbleAppViaBackKey(testApp, tapl, wmHelper)
            },
            transition = { expandBubbleAppViaTapOnBubbleStack(uiDevice, testApp, wmHelper) },
            transition = { expandBubbleAppViaTapOnBubbleStack(testApp, uiDevice, wmHelper) },
            tearDownAfterTransition = { testApp.exit(wmHelper) }
        )
    }
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ class ExpandBubbleWithImeViaBubbleBarTest(navBar: NavBar) : BubbleFlickerTestBas
                    .waitForAndVerify()
            },
            transition = {
                expandBubbleAppViaBubbleBar(uiDevice, testApp, wmHelper)
                expandBubbleAppViaBubbleBar(testApp, uiDevice, wmHelper)
                testApp.waitIMEShown(wmHelper)
                bitmapAtEnd = instrumentation.uiAutomation.takeScreenshot()
                imeInset = testApp.retrieveImeBottomInset()
+40 −9
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ fun collapseBubbleAppViaBackKey(
    // Press back key to collapse bubble
    tapl.pressBack()

    waitAndAssertBubbleAppInCollapseState(wmHelper)
    waitAndAssertBubbleAppInCollapseState(testApp, wmHelper)
}

/**
@@ -161,7 +161,7 @@ fun collapseBubbleAppViaTouchOutside(

    Root.get().expandedBubbleStack.closeByClickingOutside()

    waitAndAssertBubbleAppInCollapseState(wmHelper)
    waitAndAssertBubbleAppInCollapseState(testApp, wmHelper)
}

/**
@@ -172,12 +172,12 @@ fun collapseBubbleAppViaTouchOutside(
 * @param wmHelper the [WindowManagerStateHelper]
 */
fun expandBubbleAppViaTapOnBubbleStack(
    uiDevice: UiDevice,
    testApp: StandardAppHelper,
    uiDevice: UiDevice,
    wmHelper: WindowManagerStateHelper,
) {
    // Ensure Bubble is in collapse state.
    waitAndAssertBubbleAppInCollapseState(wmHelper)
    waitAndAssertBubbleAppInCollapseState(testApp, wmHelper)

    // Click bubble to expand
    uiDevice.bubbleIcon?.click() ?: error("Can't find bubble view")
@@ -189,17 +189,17 @@ fun expandBubbleAppViaTapOnBubbleStack(
 * Expands the bubble app [testApp], which is previously collapsed via tapping on bubble bar.
 * Note that this method only works on device with bubble bar.
 *
 * @param uiDevice the UI automator to get the bubble bar [UiObject2]
 * @param testApp the bubble app to expand
 * @param uiDevice the UI automator to get the bubble bar [UiObject2]
 * @param wmHelper the [WindowManagerStateHelper]
 */
fun expandBubbleAppViaBubbleBar(
    uiDevice: UiDevice,
    testApp: StandardAppHelper,
    uiDevice: UiDevice,
    wmHelper: WindowManagerStateHelper,
) {
    // Ensure Bubble is in collapse state.
    waitAndAssertBubbleAppInCollapseState(wmHelper)
    waitAndAssertBubbleAppInCollapseState(testApp, wmHelper)

    // Click bubble bar to expand
    uiDevice.bubbleBar?.click() ?: error("Can't find bubble bar")
@@ -226,6 +226,25 @@ fun dismissBubbleAppViaBubbleView(uiDevice: UiDevice, wmHelper: WindowManagerSta
    uiDevice.bubbleIcon?.run {
        drag(Point(uiDevice.displayWidth / 2, uiDevice.displayHeight), 1000)
    }

    waitAndAssertBubbleAppDismissed(wmHelper)
}

/**
 * Dismisses the bubble app via dragging the bubble bar handle to dismiss view.
 *
 * @param testApp the bubble app to dismiss
 * @param wmHelper the [WindowManagerStateHelper]
 */
fun dismissBubbleAppViaBubbleBarHandle(
    testApp: StandardAppHelper,
    wmHelper: WindowManagerStateHelper,
) {
    waitAndAssertBubbleAppInExpandedState(testApp, wmHelper)

    Root.get().expandedBubbleStack.bubbleBarHandle.dragToDismiss()

    waitAndAssertBubbleAppDismissed(wmHelper)
}

/**
@@ -343,16 +362,28 @@ private fun waitAndAssertBubbleAppInExpandedState(
    }
}

private fun waitAndAssertBubbleAppInCollapseState(wmHelper: WindowManagerStateHelper) {
private fun waitAndAssertBubbleAppInCollapseState(
    testApp: StandardAppHelper,
    wmHelper: WindowManagerStateHelper,
) {
    wmHelper
        .StateSyncBuilder()
        .add(ConditionsFactory.isWMStateComplete())
        .withAppTransitionIdle()
        .withTopVisibleApp(LAUNCHER)
        .withWindowSurfaceDisappeared(testApp)
        .withBubbleShown()
        .waitForAndVerify()
}

private fun waitAndAssertBubbleAppDismissed(wmHelper: WindowManagerStateHelper) {
    wmHelper
        .StateSyncBuilder()
        .add(ConditionsFactory.isWMStateComplete())
        .withAppTransitionIdle()
        .withBubbleGone()
        .waitForAndVerify()
}

private val UiDevice.bubbleIcon: UiObject2?
    get() = wait(Until.findObject(sysUiSelector(RES_ID_BUBBLE_VIEW)), FIND_OBJECT_TIMEOUT)