From aa79bd9a072e7bb2acfe28b0876100dfa80c9a4c Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Mon, 24 Jul 2023 10:32:53 -0700 Subject: [PATCH] Verifying that ViewCapture data is not empty Flag: N/A Test: presubmit Bug: 286251603 Change-Id: I45b6f858cfa13a12203a61ee80ac2e7988360d58 --- .../launcher3/util/rule/ViewCaptureRule.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt b/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt index ab2410a531..b4ad1f3542 100644 --- a/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt +++ b/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt @@ -23,8 +23,10 @@ import androidx.test.core.app.ApplicationProvider import com.android.app.viewcapture.SimpleViewCapture import com.android.app.viewcapture.ViewCapture.MAIN_EXECUTOR import com.android.app.viewcapture.data.ExportedData +import com.android.launcher3.tapl.TestHelpers import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter import com.android.launcher3.util.viewcapture_analysis.ViewCaptureAnalyzer +import org.junit.Assert.assertTrue import java.util.function.Supplier import org.junit.rules.TestRule import org.junit.runner.Description @@ -79,7 +81,7 @@ class ViewCaptureRule(var alreadyOpenActivitySupplier: Supplier) : Te MAIN_EXECUTOR.execute { windowListenerCloseables.onEach(SafeCloseable::close) } } - ViewCaptureAnalyzer.assertNoAnomalies(viewCaptureData) + analyzeViewCapture() } private fun startCapturingExistingActivity( @@ -104,4 +106,17 @@ class ViewCaptureRule(var alreadyOpenActivitySupplier: Supplier) : Te } } } + + private fun analyzeViewCapture() { + // OOP tests don't produce ViewCapture data + if (!TestHelpers.isInLauncherProcess()) return + + ViewCaptureAnalyzer.assertNoAnomalies(viewCaptureData) + + var frameCount = 0 + for (i in 0 until viewCaptureData!!.windowDataCount) { + frameCount += viewCaptureData!!.getWindowData(i).frameDataCount + } + assertTrue("Empty ViewCapture data", frameCount > 0) + } }