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

Commit fd18163b authored by Nataniel Borges's avatar Nataniel Borges
Browse files

Simplify flicker assertions

1. Generalize assertions:

Some older flicker assertions were very specific, e.g., `appLayerReplacesWallpaper` or `navBarWindowIsVisible`.

Instead of having many highly specialized assertions, generalize them. E.g., instead of `appLayerReplacesWallpaper` use `replacesVisibleLayer(oldLayer, newLayer)` and `navBarWindowIsVisible` use `aboveAppWindowVisible(windowName)`

2. Unify on ComponentName

Some assertions used String arguments, and others ComponentName, now all assertions receive ComponentName

3. Remove old code

When integrating CTS waitFor functionality into flicke,r several new methods were added for future compatibility. Since CTS will continue to use their own parse mechanism in the near future, remove those unnecessary methods to simplify the flicker codebase

4. Introduce optional assertions

Some behaviors may or may not occur, and the tests are not able to determine it a priori (e.g., if a Splash screen or Snapshot layer will appear or not) to work in these scenarios, support optional assertions, which may pass or fail, but change the sequence of events when analysing traces

Test: atest FlickerLibTest FlickerTests WMShellFlickerTests
Bug: 167521849
Change-Id: I332230ca1c1bfdf6b4ba4280c9d70c375e6ff442
parent c426433a
Loading
Loading
Loading
Loading
+33 −30
Original line number Diff line number Diff line
@@ -16,97 +16,100 @@

package com.android.wm.shell.flicker

import android.content.ComponentName
import android.graphics.Region
import android.view.Surface
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.helpers.WindowUtils
import com.android.server.wm.flicker.traces.layers.getVisibleBounds

fun FlickerTestParameter.appPairsDividerIsVisible() {
fun FlickerTestParameter.appPairsDividerIsVisibleAtEnd() {
    assertLayersEnd {
        this.isVisible(APP_PAIR_SPLIT_DIVIDER)
        this.isVisible(APP_PAIR_SPLIT_DIVIDER_COMPONENT)
    }
}

fun FlickerTestParameter.appPairsDividerIsInvisible() {
fun FlickerTestParameter.appPairsDividerIsInvisibleAtEnd() {
    assertLayersEnd {
        this.notContains(APP_PAIR_SPLIT_DIVIDER)
        this.notContains(APP_PAIR_SPLIT_DIVIDER_COMPONENT)
    }
}

fun FlickerTestParameter.appPairsDividerBecomesVisible() {
    assertLayers {
        this.isInvisible(DOCKED_STACK_DIVIDER)
        this.isInvisible(DOCKED_STACK_DIVIDER_COMPONENT)
            .then()
            .isVisible(DOCKED_STACK_DIVIDER)
            .isVisible(DOCKED_STACK_DIVIDER_COMPONENT)
    }
}

fun FlickerTestParameter.dockedStackDividerIsVisible() {
fun FlickerTestParameter.dockedStackDividerIsVisibleAtEnd() {
    assertLayersEnd {
        this.isVisible(DOCKED_STACK_DIVIDER)
        this.isVisible(DOCKED_STACK_DIVIDER_COMPONENT)
    }
}

fun FlickerTestParameter.dockedStackDividerBecomesVisible() {
    assertLayers {
        this.isInvisible(DOCKED_STACK_DIVIDER)
        this.isInvisible(DOCKED_STACK_DIVIDER_COMPONENT)
            .then()
            .isVisible(DOCKED_STACK_DIVIDER)
            .isVisible(DOCKED_STACK_DIVIDER_COMPONENT)
    }
}

fun FlickerTestParameter.dockedStackDividerBecomesInvisible() {
    assertLayers {
        this.isVisible(DOCKED_STACK_DIVIDER)
        this.isVisible(DOCKED_STACK_DIVIDER_COMPONENT)
            .then()
            .isInvisible(DOCKED_STACK_DIVIDER)
            .isInvisible(DOCKED_STACK_DIVIDER_COMPONENT)
    }
}

fun FlickerTestParameter.dockedStackDividerIsInvisible() {
fun FlickerTestParameter.dockedStackDividerNotExistsAtEnd() {
    assertLayersEnd {
        this.notContains(DOCKED_STACK_DIVIDER)
        this.notContains(DOCKED_STACK_DIVIDER_COMPONENT)
    }
}

fun FlickerTestParameter.appPairsPrimaryBoundsIsVisible(rotation: Int, primaryLayerName: String) {
fun FlickerTestParameter.appPairsPrimaryBoundsIsVisibleAtEnd(
    rotation: Int,
    primaryComponent: ComponentName
) {
    assertLayersEnd {
        val dividerRegion = entry.getVisibleBounds(APP_PAIR_SPLIT_DIVIDER)
        visibleRegion(primaryLayerName)
        val dividerRegion = layer(APP_PAIR_SPLIT_DIVIDER_COMPONENT).visibleRegion.region
        visibleRegion(primaryComponent)
            .coversExactly(getPrimaryRegion(dividerRegion, rotation))
    }
}

fun FlickerTestParameter.dockedStackPrimaryBoundsIsVisible(
fun FlickerTestParameter.dockedStackPrimaryBoundsIsVisibleAtEnd(
    rotation: Int,
    primaryLayerName: String
    primaryComponent: ComponentName
) {
    assertLayersEnd {
        val dividerRegion = entry.getVisibleBounds(DOCKED_STACK_DIVIDER)
        visibleRegion(primaryLayerName)
        val dividerRegion = layer(DOCKED_STACK_DIVIDER_COMPONENT).visibleRegion.region
        visibleRegion(primaryComponent)
            .coversExactly(getPrimaryRegion(dividerRegion, rotation))
    }
}

fun FlickerTestParameter.appPairsSecondaryBoundsIsVisible(
fun FlickerTestParameter.appPairsSecondaryBoundsIsVisibleAtEnd(
    rotation: Int,
    secondaryLayerName: String
    secondaryComponent: ComponentName
) {
    assertLayersEnd {
        val dividerRegion = entry.getVisibleBounds(APP_PAIR_SPLIT_DIVIDER)
        visibleRegion(secondaryLayerName)
        val dividerRegion = layer(APP_PAIR_SPLIT_DIVIDER_COMPONENT).visibleRegion.region
        visibleRegion(secondaryComponent)
            .coversExactly(getSecondaryRegion(dividerRegion, rotation))
    }
}

fun FlickerTestParameter.dockedStackSecondaryBoundsIsVisible(
fun FlickerTestParameter.dockedStackSecondaryBoundsIsVisibleAtEnd(
    rotation: Int,
    secondaryLayerName: String
    secondaryComponent: ComponentName
) {
    assertLayersEnd {
        val dividerRegion = entry.getVisibleBounds(DOCKED_STACK_DIVIDER)
        visibleRegion(secondaryLayerName)
        val dividerRegion = layer(DOCKED_STACK_DIVIDER_COMPONENT).visibleRegion.region
        visibleRegion(secondaryComponent)
            .coversExactly(getSecondaryRegion(dividerRegion, rotation))
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -14,9 +14,11 @@
 * limitations under the License.
 */

@file:JvmName("CommonConstants")
package com.android.wm.shell.flicker

const val IME_WINDOW_NAME = "InputMethod"
import android.content.ComponentName

const val SYSTEM_UI_PACKAGE_NAME = "com.android.systemui"
const val APP_PAIR_SPLIT_DIVIDER = "AppPairSplitDivider"
const val DOCKED_STACK_DIVIDER = "DockedStackDivider"
 No newline at end of file
val APP_PAIR_SPLIT_DIVIDER_COMPONENT = ComponentName("", "AppPairSplitDivider#")
val DOCKED_STACK_DIVIDER_COMPONENT = ComponentName("", "DockedStackDivider#")
 No newline at end of file
+4 −4
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.annotation.Group1
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.wm.shell.flicker.appPairsDividerIsInvisible
import com.android.wm.shell.flicker.appPairsDividerIsInvisibleAtEnd
import com.android.wm.shell.flicker.helpers.AppPairsHelper
import com.android.wm.shell.flicker.helpers.MultiWindowHelper.Companion.resetMultiWindowConfig
import com.android.wm.shell.flicker.helpers.MultiWindowHelper.Companion.setSupportsNonResizableMultiWindow
@@ -91,7 +91,7 @@ class AppPairsTestCannotPairNonResizeableApps(

    @Presubmit
    @Test
    fun appPairsDividerIsInvisible() = testSpec.appPairsDividerIsInvisible()
    fun appPairsDividerIsInvisibleAtEnd() = testSpec.appPairsDividerIsInvisibleAtEnd()

    @Presubmit
    @Test
@@ -101,8 +101,8 @@ class AppPairsTestCannotPairNonResizeableApps(
            "Non resizeable app not initialized"
        }
        testSpec.assertWmEnd {
            isVisible(nonResizeableApp.defaultWindowName)
            isInvisible(primaryApp.defaultWindowName)
            isVisible(nonResizeableApp.component)
            isInvisible(primaryApp.component)
        }
    }

+8 −9
Original line number Diff line number Diff line
@@ -25,9 +25,8 @@ import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.annotation.Group1
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.traces.layers.getVisibleBounds
import com.android.wm.shell.flicker.APP_PAIR_SPLIT_DIVIDER
import com.android.wm.shell.flicker.appPairsDividerIsVisible
import com.android.wm.shell.flicker.APP_PAIR_SPLIT_DIVIDER_COMPONENT
import com.android.wm.shell.flicker.appPairsDividerIsVisibleAtEnd
import com.android.wm.shell.flicker.helpers.AppPairsHelper
import com.android.wm.shell.flicker.helpers.AppPairsHelper.Companion.waitAppsShown
import org.junit.FixMethodOrder
@@ -73,14 +72,14 @@ class AppPairsTestPairPrimaryAndSecondaryApps(

    @Presubmit
    @Test
    fun appPairsDividerIsVisible() = testSpec.appPairsDividerIsVisible()
    fun appPairsDividerIsVisibleAtEnd() = testSpec.appPairsDividerIsVisibleAtEnd()

    @Presubmit
    @Test
    fun bothAppWindowsVisible() {
        testSpec.assertWmEnd {
            isVisible(primaryApp.defaultWindowName)
            isVisible(secondaryApp.defaultWindowName)
            isVisible(primaryApp.component)
            isVisible(secondaryApp.component)
        }
    }

@@ -88,10 +87,10 @@ class AppPairsTestPairPrimaryAndSecondaryApps(
    @Test
    fun appsEndingBounds() {
        testSpec.assertLayersEnd {
            val dividerRegion = entry.getVisibleBounds(APP_PAIR_SPLIT_DIVIDER)
            visibleRegion(primaryApp.defaultWindowName)
            val dividerRegion = layer(APP_PAIR_SPLIT_DIVIDER_COMPONENT).visibleRegion.region
            visibleRegion(primaryApp.component)
                .coversExactly(appPairsHelper.getPrimaryBounds(dividerRegion))
            visibleRegion(secondaryApp.defaultWindowName)
            visibleRegion(secondaryApp.component)
                .coversExactly(appPairsHelper.getSecondaryBounds(dividerRegion))
        }
    }
+4 −4
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.annotation.Group1
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.wm.shell.flicker.appPairsDividerIsVisible
import com.android.wm.shell.flicker.appPairsDividerIsVisibleAtEnd
import com.android.wm.shell.flicker.helpers.AppPairsHelper
import com.android.wm.shell.flicker.helpers.MultiWindowHelper.Companion.resetMultiWindowConfig
import com.android.wm.shell.flicker.helpers.MultiWindowHelper.Companion.setSupportsNonResizableMultiWindow
@@ -91,7 +91,7 @@ class AppPairsTestSupportPairNonResizeableApps(

    @Presubmit
    @Test
    fun appPairsDividerIsVisible() = testSpec.appPairsDividerIsVisible()
    fun appPairsDividerIsVisibleAtEnd() = testSpec.appPairsDividerIsVisibleAtEnd()

    @Presubmit
    @Test
@@ -101,8 +101,8 @@ class AppPairsTestSupportPairNonResizeableApps(
            "Non resizeable app not initialized"
        }
        testSpec.assertWmEnd {
            isVisible(nonResizeableApp.defaultWindowName)
            isVisible(primaryApp.defaultWindowName)
            isVisible(nonResizeableApp.component)
            isVisible(primaryApp.component)
        }
    }

Loading