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

Commit e7a9e274 authored by Ram Peri's avatar Ram Peri Committed by Automerger Merge Worker
Browse files

Merge "Test: atest -c MyRoboTests Bug: 266743080 Add support for Robolectric...

Merge "Test: atest -c MyRoboTests Bug: 266743080 Add support for Robolectric based RNG screenshot diffing" into udc-dev am: 7b53dca2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22110699



Change-Id: I444267ed66f67ab5fdbadb9af88f874ced6467fd
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a2f5eb56 7b53dca2
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import kotlinx.coroutines.runBlocking
fun View.captureToBitmap(window: Window? = null): ListenableFuture<Bitmap> {
    val bitmapFuture: ResolvableFuture<Bitmap> = ResolvableFuture.create()
    val mainExecutor = HandlerExecutor(Handler(Looper.getMainLooper()))
    val isRobolectric = if (Build.FINGERPRINT.contains("robolectric")) true else false

    // disable drawing again if necessary once work is complete
    if (!HardwareRendererCompat.isDrawingEnabled()) {
@@ -61,9 +62,13 @@ fun View.captureToBitmap(window: Window? = null): ListenableFuture<Bitmap> {
    }

    mainExecutor.execute {
        if (isRobolectric) {
            generateBitmap(bitmapFuture)
        } else {
            val forceRedrawFuture = forceRedraw()
            forceRedrawFuture.addListener({ generateBitmap(bitmapFuture, window) }, mainExecutor)
        }
    }

    return bitmapFuture
}
+14 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.testing.screenshot
import android.app.Activity
import android.app.Dialog
import android.graphics.Bitmap
import android.os.Build
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams
@@ -26,6 +27,7 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.activity.ComponentActivity
import androidx.test.ext.junit.rules.ActivityScenarioRule
import java.util.concurrent.TimeUnit
import org.junit.Assert.assertEquals
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
@@ -54,14 +56,14 @@ open class ViewScreenshotTestRule(
            )
        )
    private val activityRule = ActivityScenarioRule(ScreenshotActivity::class.java)
    private val delegateRule =
        RuleChain.outerRule(colorsRule)
            .around(deviceEmulationRule)
            .around(screenshotRule)
            .around(activityRule)
    private val roboRule =
        RuleChain.outerRule(deviceEmulationRule).around(screenshotRule).around(activityRule)
    private val delegateRule = RuleChain.outerRule(colorsRule).around(roboRule)
    private val isRobolectric = if (Build.FINGERPRINT.contains("robolectric")) true else false

    override fun apply(base: Statement, description: Description): Statement {
        return delegateRule.apply(base, description)
        val ruleToApply = if (isRobolectric) roboRule else delegateRule
        return ruleToApply.apply(base, description)
    }

    protected fun takeScreenshot(
@@ -94,7 +96,12 @@ open class ViewScreenshotTestRule(
            contentView = content.getChildAt(0)
        }

        return contentView?.toBitmap() ?: error("contentView is null")
        return if (isRobolectric) {
            contentView?.captureToBitmap()?.get(10, TimeUnit.SECONDS)
                ?: error("timeout while trying to capture view to bitmap")
        } else {
            contentView?.toBitmap() ?: error("contentView is null")
        }
    }

    /**