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

Commit 3bb700e6 authored by Charles Chen's avatar Charles Chen
Browse files

Verify expand bubble via bubble stack

Also handles the crash during transition to prevent
the whole test process crashes.

Test: atest
WMShellExplicitFlickerTestsBubbles:ExpandBubbleViaBubbleStackTest
Flag: TEST_ONLY
Bug: 396020056

Change-Id: I9131871f03a15fde2ac3fb1ee419a3e1622a1d78
parent b1d9917f
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -51,12 +51,20 @@ test_module_config {
    name: "WMShellExplicitFlickerTestsBubbles-CatchAll",
    base: "WMShellExplicitFlickerTestsBubbles",
    exclude_filters: [
        "com.android.wm.shell.flicker.bubbles.EnterBubbleViaBubbleMenuTest",
        "com.android.wm.shell.flicker.bubbles.CollapseBubbleViaBackTest",
        "com.android.wm.shell.flicker.bubbles.EnterBubbleViaBubbleMenuTest",
        "com.android.wm.shell.flicker.bubbles.ExpandBubbleViaBubbleStackTest",
    ],
    test_suites: ["device-tests"],
}

test_module_config {
    name: "WMShellExplicitFlickerTestsBubbles-CollapseBubbleViaBackTest",
    base: "WMShellExplicitFlickerTestsBubbles",
    include_filters: ["com.android.wm.shell.flicker.bubbles.CollapseBubbleViaBackTest"],
    test_suites: ["device-tests"],
}

test_module_config {
    name: "WMShellExplicitFlickerTestsBubbles-EnterBubbleViaBubbleMenuTest",
    base: "WMShellExplicitFlickerTestsBubbles",
@@ -65,8 +73,8 @@ test_module_config {
}

test_module_config {
    name: "WMShellExplicitFlickerTestsBubbles-CollapseBubbleViaBackTest",
    name: "WMShellExplicitFlickerTestsBubbles-ExpandBubbleViaBubbleStackTest",
    base: "WMShellExplicitFlickerTestsBubbles",
    include_filters: ["com.android.wm.shell.flicker.bubbles.CollapseBubbleViaBackTest"],
    include_filters: ["com.android.wm.shell.flicker.bubbles.ExpandBubbleViaBubbleStackTest"],
    test_suites: ["device-tests"],
}
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
    },
    {
      "name": "WMShellExplicitFlickerTestsBubbles-CollapseBubbleViaBackTest"
    },
    {
      "name": "WMShellExplicitFlickerTestsBubbles-ExpandBubbleViaBubbleStackTest"
    }
  ]
}
 No newline at end of file
+89 −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.RequiresDevice
import android.platform.test.annotations.RequiresFlagsEnabled
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.wm.shell.Flags
import com.android.wm.shell.flicker.bubbles.testcase.BubbleAppBecomesExpandedTestCases
import com.android.wm.shell.flicker.bubbles.testcase.BubbleStackAlwaysVisibleTestCases
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.collapseBubbleViaBackKey
import com.android.wm.shell.flicker.bubbles.utils.expandBubbleViaTapOnBubbleStack
import com.android.wm.shell.flicker.bubbles.utils.launchBubbleViaBubbleMenu
import com.android.wm.shell.flicker.bubbles.utils.setUpBeforeTransition
import org.junit.Assume.assumeFalse
import org.junit.Before
import org.junit.ClassRule
import org.junit.FixMethodOrder
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters

/**
 * Test clicking bubble to expand a bubble that was in collapsed state.
 *
 * To run this test: `atest WMShellExplicitFlickerTestsBubbles:ExpandBubbleViaBubbleStackTest`
 *
 * Pre-steps:
 * ```
 *     Launch [testApp] into bubble and collapse the bubble
 * ```
 *
 * Actions:
 * ```
 *     Expand the [testApp] bubble via clicking floating bubble icon
 * ```
 * Verified tests:
 * - [BubbleFlickerTestBase]
 * - [BubbleStackAlwaysVisibleTestCases]
 * - [BubbleAppBecomesExpandedTestCases]
 */
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE)
@RunWith(AndroidJUnit4::class)
@RequiresDevice
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Presubmit
class ExpandBubbleViaBubbleStackTest :
    BubbleFlickerTestBase(), BubbleStackAlwaysVisibleTestCases, BubbleAppBecomesExpandedTestCases {

    override val traceDataReader
        get() = recordTraceWithTransitionRule.reader

    // TODO(b/396020056): Verify expand bubble with bubble bar.
    @Before
    fun setUp() {
        assumeFalse(tapl.isTablet)
    }

    companion object : FlickerPropertyInitializer() {

        @ClassRule
        @JvmField
        val recordTraceWithTransitionRule = RecordTraceWithTransitionRule(
            setUpBeforeTransition = {
                setUpBeforeTransition(instrumentation, wmHelper)
                launchBubbleViaBubbleMenu(testApp, tapl, wmHelper)
                collapseBubbleViaBackKey(testApp, tapl, wmHelper)
            },
            transition = { expandBubbleViaTapOnBubbleStack(uiDevice, testApp, wmHelper) },
            tearDownAfterTransition = { testApp.exit(wmHelper) }
        )
    }
}
 No newline at end of file
+47 −14
Original line number Diff line number Diff line
@@ -25,11 +25,15 @@ import android.tools.flicker.rules.ChangeDisplayOrientationRule
import android.tools.flicker.rules.RemoveAllTasksButHomeRule.Companion.removeAllTasksButHome
import android.tools.io.Reader
import android.tools.traces.ConditionsFactory
import android.tools.traces.component.ComponentNameMatcher
import android.tools.traces.component.ComponentNameMatcher.Companion.LAUNCHER
import android.tools.traces.monitors.PerfettoTraceMonitor
import android.tools.traces.monitors.events.EventLogMonitor
import android.tools.traces.monitors.withTracing
import android.tools.traces.parsers.WindowManagerStateHelper
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.launcher3.tapl.LauncherInstrumentation

// TODO(b/396020056): Verify bubble bar on the large screen devices.
@@ -84,13 +88,7 @@ fun launchBubbleViaBubbleMenu(
    // Open the bubble menu and click.
    simpleAppIcon.openMenu().bubbleMenuItem.click()

    // Wait for bubble shown.
    wmHelper
        .StateSyncBuilder()
        .add(ConditionsFactory.isWMStateComplete())
        .withAppTransitionIdle()
        .withTopVisibleApp(testApp)
        .waitForAndVerify()
    waitAndAssertBubbleInExpandedState(testApp, wmHelper)
}

/**
@@ -105,7 +103,33 @@ fun collapseBubbleViaBackKey(
    tapl: LauncherInstrumentation,
    wmHelper: WindowManagerStateHelper,
) {
    // Ensure Bubble is shown and in expanded state.
    // Ensure Bubble is in expanded state.
    waitAndAssertBubbleInExpandedState(testApp, wmHelper)

    // Press back key to collapse bubble
    tapl.pressBack()

    waitAndAssertBubbleInCollapseState(wmHelper)
}

fun expandBubbleViaTapOnBubbleStack(
    uiDevice: UiDevice,
    testApp: StandardAppHelper,
    wmHelper: WindowManagerStateHelper,
) {
    // Ensure Bubble is in collapse state.
    waitAndAssertBubbleInCollapseState(wmHelper)

    // Click bubble to expand
    uiDevice.bubble?.click() ?: error("Can't find bubble view")

    waitAndAssertBubbleInExpandedState(testApp, wmHelper)
}

private fun waitAndAssertBubbleInExpandedState(
    testApp: StandardAppHelper,
    wmHelper: WindowManagerStateHelper,
) {
    wmHelper
        .StateSyncBuilder()
        .add(ConditionsFactory.isWMStateComplete())
@@ -113,15 +137,24 @@ fun collapseBubbleViaBackKey(
        .withTopVisibleApp(testApp)
        .withBubbleShown()
        .waitForAndVerify()
}

    // Press back key to collapse bubble
    tapl.pressBack()

    // Ensure Bubble is in the collapse state.
private fun waitAndAssertBubbleInCollapseState(wmHelper: WindowManagerStateHelper) {
    wmHelper
        .StateSyncBuilder()
        .add(ConditionsFactory.isWMStateComplete())
        .withAppTransitionIdle()
        .withTopVisibleApp(ComponentNameMatcher.LAUNCHER)
        .withTopVisibleApp(LAUNCHER)
        .withBubbleShown()
        .waitForAndVerify()
}

private val UiDevice.bubble: UiObject2?
    get() = wait(
        Until.findObject(By.pkg(SYSUI_PACKAGE).res(SYSUI_PACKAGE, RES_ID_BUBBLE_VIEW)),
        FIND_OBJECT_TIMEOUT
    )

private const val FIND_OBJECT_TIMEOUT = 4000L
private const val SYSUI_PACKAGE = "com.android.systemui"
private const val RES_ID_BUBBLE_VIEW = "bubble_view"
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.tools.traces.parsers.WindowManagerStateHelper
import android.tools.traces.surfaceflinger.LayerTraceEntry
import android.tools.traces.wm.WindowManagerState
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.server.wm.flicker.helpers.SimpleAppHelper

@@ -32,6 +33,8 @@ open class FlickerPropertyInitializer {

    val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()

    val uiDevice: UiDevice = UiDevice.getInstance(instrumentation)

    /**
     * Helper class to wait on [WindowManagerState] or [LayerTraceEntry] conditions.
     *
Loading