Merge "Fix StaleObjectException on bubble tests"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c5cbe40261
@@ -26,6 +26,7 @@ import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.UiObject2
|
||||
import androidx.test.uiautomator.Until
|
||||
import com.android.server.wm.flicker.Flicker
|
||||
import com.android.server.wm.flicker.FlickerBuilderProvider
|
||||
import com.android.server.wm.flicker.FlickerTestParameter
|
||||
import com.android.server.wm.flicker.FlickerTestParameterFactory
|
||||
@@ -47,13 +48,9 @@ abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {
|
||||
protected val notifyManager = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE))
|
||||
|
||||
protected val packageManager = context.getPackageManager()
|
||||
protected val uid = packageManager.getApplicationInfo(
|
||||
protected val uid = context.packageManager.getApplicationInfo(
|
||||
testApp.component.packageName, 0).uid
|
||||
|
||||
protected lateinit var addBubbleBtn: UiObject2
|
||||
protected lateinit var cancelAllBtn: UiObject2
|
||||
|
||||
protected abstract val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
|
||||
@JvmOverloads
|
||||
@@ -67,10 +64,8 @@ abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {
|
||||
notifyManager.setBubblesAllowed(testApp.component.packageName,
|
||||
uid, NotificationManager.BUBBLE_PREFERENCE_ALL)
|
||||
testApp.launchViaIntent(wmHelper)
|
||||
addBubbleBtn = device.wait(Until.findObject(
|
||||
By.text("Add Bubble")), FIND_OBJECT_TIMEOUT)
|
||||
cancelAllBtn = device.wait(Until.findObject(
|
||||
By.text("Cancel All Bubble")), FIND_OBJECT_TIMEOUT)
|
||||
waitAndGetAddBubbleBtn()
|
||||
waitAndGetCancelAllBtn()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +79,11 @@ abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun Flicker.waitAndGetAddBubbleBtn(): UiObject2? = device.wait(Until.findObject(
|
||||
By.text("Add Bubble")), FIND_OBJECT_TIMEOUT)
|
||||
protected fun Flicker.waitAndGetCancelAllBtn(): UiObject2? = device.wait(Until.findObject(
|
||||
By.text("Cancel All Bubble")), FIND_OBJECT_TIMEOUT)
|
||||
|
||||
@FlickerBuilderProvider
|
||||
fun buildFlicker(): FlickerBuilder {
|
||||
return FlickerBuilder(instrumentation).apply {
|
||||
@@ -102,7 +102,6 @@ abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {
|
||||
}
|
||||
|
||||
const val FIND_OBJECT_TIMEOUT = 2000L
|
||||
const val WINDOW_UPDAT_TIMEOUT = 2000L
|
||||
const val SYSTEM_UI_PACKAGE = SYSTEMUI_PACKAGE
|
||||
const val BUBBLE_RES_NAME = "bubble_view"
|
||||
}
|
||||
|
||||
@@ -46,18 +46,19 @@ import org.junit.runners.Parameterized
|
||||
@Group4
|
||||
class DismissBubbleScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {
|
||||
|
||||
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
val displaySize = DisplayMetrics()
|
||||
private val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
private val displaySize = DisplayMetrics()
|
||||
|
||||
override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
get() = buildTransition() {
|
||||
get() = buildTransition {
|
||||
setup {
|
||||
eachRun {
|
||||
addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Add Bubble not found")
|
||||
val addBubbleBtn = waitAndGetAddBubbleBtn()
|
||||
addBubbleBtn?.click() ?: error("Add Bubble not found")
|
||||
}
|
||||
}
|
||||
transitions {
|
||||
wm?.run { wm.getDefaultDisplay().getMetrics(displaySize) } ?: error("WM not found")
|
||||
wm.run { wm.getDefaultDisplay().getMetrics(displaySize) }
|
||||
val dist = Point((displaySize.widthPixels / 2), displaySize.heightPixels)
|
||||
val showBubble = device.wait(Until.findObject(
|
||||
By.res(SYSTEM_UI_PACKAGE, BUBBLE_RES_NAME)), FIND_OBJECT_TIMEOUT)
|
||||
|
||||
@@ -45,10 +45,11 @@ import org.junit.runners.Parameterized
|
||||
class ExpandBubbleScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {
|
||||
|
||||
override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
get() = buildTransition() {
|
||||
get() = buildTransition {
|
||||
setup {
|
||||
test {
|
||||
addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Bubble widget not found")
|
||||
val addBubbleBtn = waitAndGetAddBubbleBtn()
|
||||
addBubbleBtn?.click() ?: error("Add Bubble not found")
|
||||
}
|
||||
}
|
||||
transitions {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.wm.shell.flicker.bubble
|
||||
|
||||
import android.os.SystemClock
|
||||
import androidx.test.filters.FlakyTest
|
||||
import androidx.test.filters.RequiresDevice
|
||||
import androidx.test.uiautomator.By
|
||||
@@ -44,31 +43,33 @@ import org.junit.runners.Parameterized
|
||||
class LaunchBubbleFromLockScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {
|
||||
|
||||
override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
get() = buildTransition() {
|
||||
get() = buildTransition {
|
||||
setup {
|
||||
eachRun {
|
||||
val addBubbleBtn = waitAndGetAddBubbleBtn()
|
||||
addBubbleBtn?.click() ?: error("Bubble widget not found")
|
||||
device.sleep()
|
||||
SystemClock.sleep(2000)
|
||||
device.wakeUp()
|
||||
wmHelper.waitFor("noAppWindowsOnTop") {
|
||||
it.wmState.topVisibleAppWindow.isEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
transitions {
|
||||
val notification = device.wait(Until.findObject(
|
||||
By.text("BubbleChat")), FIND_OBJECT_TIMEOUT)
|
||||
notification?.click() ?: error("Notification not found")
|
||||
instrumentation.getUiAutomation().syncInputTransactions()
|
||||
instrumentation.uiAutomation.syncInputTransactions()
|
||||
val showBubble = device.wait(Until.findObject(
|
||||
By.res("com.android.systemui", "bubble_view")), FIND_OBJECT_TIMEOUT)
|
||||
showBubble?.click() ?: error("Bubble notify not found")
|
||||
instrumentation.getUiAutomation().syncInputTransactions()
|
||||
instrumentation.uiAutomation.syncInputTransactions()
|
||||
val cancelAllBtn = waitAndGetCancelAllBtn()
|
||||
cancelAllBtn?.click() ?: error("Cancel widget not found")
|
||||
}
|
||||
}
|
||||
|
||||
@FlakyTest
|
||||
@Test
|
||||
fun testAppisVisibleAtEnd() {
|
||||
fun testAppIsVisibleAtEnd() {
|
||||
testSpec.assertLayersEnd {
|
||||
this.isVisible(testApp.component)
|
||||
}
|
||||
|
||||
@@ -42,9 +42,10 @@ import org.junit.runners.Parameterized
|
||||
class LaunchBubbleScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {
|
||||
|
||||
override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
get() = buildTransition() {
|
||||
get() = buildTransition {
|
||||
transitions {
|
||||
addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Bubble widget not found")
|
||||
val addBubbleBtn = waitAndGetAddBubbleBtn()
|
||||
addBubbleBtn?.click() ?: error("Bubble widget not found")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,10 +44,11 @@ import org.junit.runners.Parameterized
|
||||
class MultiBubblesScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {
|
||||
|
||||
override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
get() = buildTransition() {
|
||||
get() = buildTransition {
|
||||
setup {
|
||||
test {
|
||||
for (i in 1..3) {
|
||||
val addBubbleBtn = waitAndGetAddBubbleBtn()
|
||||
addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Add Bubble not found")
|
||||
}
|
||||
val showBubble = device.wait(Until.findObject(
|
||||
|
||||
Reference in New Issue
Block a user