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

Commit aa7801da authored by Grace Cheng's avatar Grace Cheng Committed by Automerger Merge Worker
Browse files

Merge "Adding optional block to run before screenshot" into udc-dev am: a6550a83

parents 17d3c0c4 a6550a83
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -78,6 +78,7 @@ open class ViewScreenshotTestRule(
    protected fun takeScreenshot(
    protected fun takeScreenshot(
        mode: Mode = Mode.WrapContent,
        mode: Mode = Mode.WrapContent,
        viewProvider: (ComponentActivity) -> View,
        viewProvider: (ComponentActivity) -> View,
        beforeScreenshot: (ComponentActivity) -> Unit = {}
    ): Bitmap {
    ): Bitmap {
        activityRule.scenario.onActivity { activity ->
        activityRule.scenario.onActivity { activity ->
            // Make sure that the activity draws full screen and fits the whole display instead of
            // Make sure that the activity draws full screen and fits the whole display instead of
@@ -103,6 +104,7 @@ open class ViewScreenshotTestRule(
            val content = activity.requireViewById<ViewGroup>(android.R.id.content)
            val content = activity.requireViewById<ViewGroup>(android.R.id.content)
            assertEquals(1, content.childCount)
            assertEquals(1, content.childCount)
            contentView = content.getChildAt(0)
            contentView = content.getChildAt(0)
            beforeScreenshot(activity)
        }
        }


        return if (isRobolectric) {
        return if (isRobolectric) {
@@ -120,9 +122,10 @@ open class ViewScreenshotTestRule(
    fun screenshotTest(
    fun screenshotTest(
        goldenIdentifier: String,
        goldenIdentifier: String,
        mode: Mode = Mode.WrapContent,
        mode: Mode = Mode.WrapContent,
        viewProvider: (ComponentActivity) -> View,
        beforeScreenshot: (ComponentActivity) -> Unit = {},
        viewProvider: (ComponentActivity) -> View
    ) {
    ) {
        val bitmap = takeScreenshot(mode, viewProvider)
        val bitmap = takeScreenshot(mode, viewProvider, beforeScreenshot)
        screenshotRule.assertBitmapAgainstGolden(
        screenshotRule.assertBitmapAgainstGolden(
            bitmap,
            bitmap,
            goldenIdentifier,
            goldenIdentifier,