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

Commit af0e0914 authored by Charles Chen's avatar Charles Chen
Browse files

Verify multiple bubble launch

Test: atest LaunchMultipleBubbleTest
Bug: 396020056
Flag: TEST_ONLY

Change-Id: I78636325e6a9f66ae7145f065c5085eb5bd011f9
parent 942bca08
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -73,7 +73,8 @@ class DismissExpandedBubbleViaBubbleViewTest(navBar: NavBar) :
                setUpBeforeTransition(instrumentation, wmHelper)
                launchBubbleViaBubbleMenu(testApp, tapl, wmHelper)
            },
            transition = { dismissBubbleAppViaBubbleView(uiDevice, wmHelper) }
            transition = { dismissBubbleAppViaBubbleView(uiDevice, wmHelper) },
            tearDownAfterTransition = { testApp.exit() }
        )
    }

+105 −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.systemui_tapl.ui.Bubble
import android.platform.systemui_tapl.ui.Root
import android.platform.test.annotations.Presubmit
import android.platform.test.annotations.RequiresFlagsEnabled
import android.tools.NavBar
import androidx.test.filters.FlakyTest
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.BubbleAlwaysVisibleTestCases
import com.android.wm.shell.flicker.bubbles.testcase.BubbleAppBecomesExpandedTestCases
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.dismissMultipleBubbles
import com.android.wm.shell.flicker.bubbles.utils.launchBubbleViaBubbleMenu
import com.android.wm.shell.flicker.bubbles.utils.launchMultipleBubbleAppsViaBubbleMenuAndCollapse
import com.google.common.truth.Truth.assertWithMessage
import org.junit.FixMethodOrder
import org.junit.Rule
import org.junit.rules.TestRule
import org.junit.runners.MethodSorters

/**
 * Test launch multiple bubbles.
 *
 * To run this test: `atest WMShellExplicitFlickerTestsBubbles:LaunchMultipleBubbleTest`
 *
 * Pre-steps:
 * ```
 *   Launch five apps into bubble and collapse.
 * ```
 *
 * Actions:
 * ```
 *   Launch [testApp] into bubble
 *   The oldest bubble app will be removed from the bubble stack, or bubble bar.
 * ```
 * Verified tests:
 * - [BubbleFlickerTestBase]
 * - [BubbleAlwaysVisibleTestCases]
 * - [BubbleAppBecomesExpandedTestCases]
 */
@FlakyTest(bugId = 430273288)
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE)
@RequiresDevice
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Presubmit
class LaunchMultipleBubbleTest(navBar: NavBar) : BubbleFlickerTestBase(),
    BubbleAlwaysVisibleTestCases, BubbleAppBecomesExpandedTestCases {

    companion object : FlickerPropertyInitializer() {

        private lateinit var bubbleIconsBeforeTransition: List<Bubble>

        private val recordTraceWithTransitionRule = RecordTraceWithTransitionRule(
            setUpBeforeTransition = {
                bubbleIconsBeforeTransition =
                    launchMultipleBubbleAppsViaBubbleMenuAndCollapse(
                        tapl,
                        wmHelper
                    )
            },
            transition = {
                launchBubbleViaBubbleMenu(testApp, tapl, wmHelper)
                val bubbleIconsAfterTransition = Root.get().expandedBubbleStack.bubbles
                val oldestBubble = bubbleIconsBeforeTransition.first()
                assertWithMessage("The oldest bubble must be removed.")
                    .that(bubbleIconsAfterTransition)
                    .doesNotContain(oldestBubble)
            },
            tearDownAfterTransition = {
                testApp.exit()
                dismissMultipleBubbles()
            }
        )
    }

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

    override val traceDataReader
        get() = recordTraceWithTransitionRule.reader
}
 No newline at end of file
+106 −6
Original line number Diff line number Diff line
@@ -20,8 +20,14 @@ package com.android.wm.shell.flicker.bubbles.utils

import android.app.Instrumentation
import android.graphics.Point
import android.platform.systemui_tapl.ui.Bubble
import android.platform.systemui_tapl.ui.Root
import android.tools.Rotation
import android.tools.device.apphelpers.BrowserAppHelper
import android.tools.device.apphelpers.CalculatorAppHelper
import android.tools.device.apphelpers.ClockAppHelper
import android.tools.device.apphelpers.MapsAppHelper
import android.tools.device.apphelpers.MessagingAppHelper
import android.tools.device.apphelpers.StandardAppHelper
import android.tools.flicker.rules.ChangeDisplayOrientationRule
import android.tools.flicker.rules.RemoveAllTasksButHomeRule.Companion.removeAllTasksButHome
@@ -40,6 +46,8 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.wm.shell.Flags
import com.google.common.truth.Truth.assertWithMessage

// TODO(b/396020056): Verify bubble bar on the large screen devices.
/**
@@ -89,12 +97,9 @@ fun launchBubbleViaBubbleMenu(
    tapl: LauncherInstrumentation,
    wmHelper: WindowManagerStateHelper,
) {
    val allApps = tapl.goHome().switchToAllApps()
    val simpleAppIcon = allApps.getAppIcon(testApp.appName)
    // Open the bubble menu and click.
    simpleAppIcon.openMenu().bubbleMenuItem.click()

    waitAndAssertBubbleAppInExpandedState(testApp, wmHelper)
    // Go to all apps to launch app into a bubble.
    tapl.goHome().switchToAllApps()
    launchAndWaitForBubbleAppExpanded(testApp, tapl, wmHelper)
}

/**
@@ -116,6 +121,9 @@ fun launchBubbleViaDragToBubbleBar(
    taskBarAppIcon.dragToBubbleBarLocation(false /* isBubbleBarLeftDropTarget */)

    waitAndAssertBubbleAppInExpandedState(testApp, wmHelper)
    tapl.launchedAppState.assertTaskbarHidden()
    assertWithMessage("The education must not show for Application bubble")
        .that(Root.get().bubble.isEducationVisible).isFalse()
}

/**
@@ -211,6 +219,88 @@ fun dismissBubbleAppViaBubbleView(uiDevice: UiDevice, wmHelper: WindowManagerSta
        .waitForAndVerify()
}

/**
 * Launches as many bubble apps as a bubble stack or a bubble bar can contain and collapse.
 *
 * @param tapl the [LauncherInstrumentation]
 * @param wmHelper the [WindowManagerStateHelper]
 * @return the [Bubble] icon objects of the launched bubble apps
 */
fun launchMultipleBubbleAppsViaBubbleMenuAndCollapse(
    tapl: LauncherInstrumentation,
    wmHelper: WindowManagerStateHelper,
): List<Bubble> {
    // Go to all apps to launch app into a bubble.
    tapl.goHome().switchToAllApps()

    bubbleApps.forEach { testApp ->
        launchAndWaitForBubbleAppExpanded(testApp, tapl, wmHelper)
        if (testApp != bubbleApps.last()) {
            Root.get().expandedBubbleStack.closeByClickingOutside()
        }
    }

    assertBubbleIconsAligned(tapl)

    val expandedBubbleStack = Root.get().expandedBubbleStack
    val bubbles = expandedBubbleStack.bubbles
    expandedBubbleStack.closeByClickingOutside()

    return bubbles
}

/**
 * Dismisses all bubble apps launched by [launchMultipleBubbleAppsViaBubbleMenuAndCollapse].
 */
fun dismissMultipleBubbles() {
    bubbleApps.forEach { app -> app.exit() }
}

private fun assertBubbleIconsAligned(tapl: LauncherInstrumentation) {
    val isBubbleIconsAligned = Root.get().expandedBubbleStack.bubbles.stream()
        .mapToInt { bubbleIcon: Bubble ->
            if (tapl.isTablet && !Flags.enableBubbleBar()) {
                // For large screen devices without bubble bar, the bubble icons are aligned
                // vertically.
                bubbleIcon.visibleCenter.x
            } else {
                // Otherwise, the bubble icons are aligned horizontally.
                bubbleIcon.visibleCenter.y
            }
        }
        .distinct()
        .count() == 1L


    val bubblePositions = StringBuilder()
    if (!isBubbleIconsAligned) {
        Root.get().expandedBubbleStack.bubbles.forEach { bubble ->
            bubblePositions.append(
                "{${bubble.contentDescription()} center: ${bubble.visibleCenter}}, "
            )
        }
    }
    assertWithMessage("The bubble icons must be aligned, but was $bubblePositions")
        .that(isBubbleIconsAligned)
        .isTrue()
}

private fun launchAndWaitForBubbleAppExpanded(
    testApp: StandardAppHelper,
    tapl: LauncherInstrumentation,
    wmHelper: WindowManagerStateHelper,
) {
    val allApps = tapl.allApps
    val simpleAppIcon = allApps.getAppIcon(testApp.appName)
    // Open the bubble menu and click.
    simpleAppIcon.openMenu().bubbleMenuItem.click()

    waitAndAssertBubbleAppInExpandedState(testApp, wmHelper)

    assertWithMessage("The education must not show for Application bubble")
        .that(Root.get().bubble.isEducationVisible).isFalse()
}

private fun waitAndAssertBubbleAppInExpandedState(
    testApp: StandardAppHelper,
    wmHelper: WindowManagerStateHelper,
@@ -252,3 +342,13 @@ private const val FIND_OBJECT_TIMEOUT = 4000L
private const val SYSUI_PACKAGE = "com.android.systemui"
private const val RES_ID_BUBBLE_VIEW = "bubble_view"
private const val RES_ID_BUBBLE_BAR = "taskbar_bubbles"

// TODO(b/396020056): The max number of bubbles is 5. Make the test more flexible
//  if the max number could be overridden.
private val bubbleApps = listOf(
    CalculatorAppHelper(),
    BrowserAppHelper(),
    MapsAppHelper(),
    MessagingAppHelper(),
    ClockAppHelper(),
)
 No newline at end of file
+1 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

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

import android.tools.flicker.rules.RemoveAllTasksButHomeRule.Companion.removeAllTasksButHome
import android.tools.io.Reader
import android.util.Log
import org.junit.AssumptionViolatedException
@@ -56,7 +55,7 @@ class RecordTraceWithTransitionRule(
                    errors.add(e)
                } finally {
                    // In case the crash during transition and test App is not removed.
                    removeAllTasksButHome()
                    tearDownAfterTransition()
                }

                try {
@@ -82,7 +81,6 @@ class RecordTraceWithTransitionRule(
                Log.e(TAG, "Transition is aborted due to the exception:\n $e")
            }
        }
        tearDownAfterTransition()
    }

    companion object {