Verifying that ViewCapture data is not empty

Flag: N/A
Test: presubmit
Bug: 286251603
Change-Id: I45b6f858cfa13a12203a61ee80ac2e7988360d58
diff --git a/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt b/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt
index ab2410a..b4ad1f3 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 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 @@
                     MAIN_EXECUTOR.execute { windowListenerCloseables.onEach(SafeCloseable::close) }
                 }
 
-                ViewCaptureAnalyzer.assertNoAnomalies(viewCaptureData)
+                analyzeViewCapture()
             }
 
             private fun startCapturingExistingActivity(
@@ -104,4 +106,17 @@
             }
         }
     }
+
+    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)
+    }
 }