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

Commit 17988825 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I45b6f858,I28120248 into udc-qpr-dev

* changes:
  Verifying that ViewCapture data is not empty
  Restoring starting capturing existing activity.
parents 38a7faf0 aa79bd9a
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -116,7 +116,8 @@ public class FallbackRecentsTest {
            Utilities.enableRunningInTestHarnessForTests();
            Utilities.enableRunningInTestHarnessForTests();
        }
        }


        final ViewCaptureRule viewCaptureRule = new ViewCaptureRule();
        final ViewCaptureRule viewCaptureRule = new ViewCaptureRule(
                RecentsActivity.ACTIVITY_TRACKER::getCreatedActivity);
        mOrderSensitiveRules = RuleChain
        mOrderSensitiveRules = RuleChain
                .outerRule(new SamplerRule())
                .outerRule(new SamplerRule())
                .around(new NavigationModeSwitchRule(mLauncher))
                .around(new NavigationModeSwitchRule(mLauncher))
+2 −1
Original line number Original line Diff line number Diff line
@@ -201,7 +201,8 @@ public abstract class AbstractLauncherUiTest {
    }
    }


    protected TestRule getRulesInsideActivityMonitor() {
    protected TestRule getRulesInsideActivityMonitor() {
        final ViewCaptureRule viewCaptureRule = new ViewCaptureRule();
        final ViewCaptureRule viewCaptureRule = new ViewCaptureRule(
                Launcher.ACTIVITY_TRACKER::getCreatedActivity);
        final RuleChain inner = RuleChain
        final RuleChain inner = RuleChain
                .outerRule(new PortraitLandscapeRunner(this))
                .outerRule(new PortraitLandscapeRunner(this))
                .around(new FailureWatcher(mLauncher, viewCaptureRule::getViewCaptureData))
                .around(new FailureWatcher(mLauncher, viewCaptureRule::getViewCaptureData))
+29 −2
Original line number Original line Diff line number Diff line
@@ -23,8 +23,11 @@ import androidx.test.core.app.ApplicationProvider
import com.android.app.viewcapture.SimpleViewCapture
import com.android.app.viewcapture.SimpleViewCapture
import com.android.app.viewcapture.ViewCapture.MAIN_EXECUTOR
import com.android.app.viewcapture.ViewCapture.MAIN_EXECUTOR
import com.android.app.viewcapture.data.ExportedData
import com.android.app.viewcapture.data.ExportedData
import com.android.launcher3.tapl.TestHelpers
import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter
import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter
import com.android.launcher3.util.viewcapture_analysis.ViewCaptureAnalyzer
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.rules.TestRule
import org.junit.runner.Description
import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.junit.runners.model.Statement
@@ -35,7 +38,7 @@ import org.junit.runners.model.Statement
 *
 *
 * This rule will not work in OOP tests that don't have access to the activity under test.
 * This rule will not work in OOP tests that don't have access to the activity under test.
 */
 */
class ViewCaptureRule : TestRule {
class ViewCaptureRule(var alreadyOpenActivitySupplier: Supplier<Activity?>) : TestRule {
    private val viewCapture = SimpleViewCapture("test-view-capture")
    private val viewCapture = SimpleViewCapture("test-view-capture")
    var viewCaptureData: ExportedData? = null
    var viewCaptureData: ExportedData? = null
        private set
        private set
@@ -46,6 +49,8 @@ class ViewCaptureRule : TestRule {
                viewCaptureData = null
                viewCaptureData = null
                val windowListenerCloseables = mutableListOf<SafeCloseable>()
                val windowListenerCloseables = mutableListOf<SafeCloseable>()


                startCapturingExistingActivity(windowListenerCloseables)

                val lifecycleCallbacks =
                val lifecycleCallbacks =
                    object : ActivityLifecycleCallbacksAdapter {
                    object : ActivityLifecycleCallbacksAdapter {
                        override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
                        override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
@@ -76,7 +81,16 @@ class ViewCaptureRule : TestRule {
                    MAIN_EXECUTOR.execute { windowListenerCloseables.onEach(SafeCloseable::close) }
                    MAIN_EXECUTOR.execute { windowListenerCloseables.onEach(SafeCloseable::close) }
                }
                }


                ViewCaptureAnalyzer.assertNoAnomalies(viewCaptureData)
                analyzeViewCapture()
            }

            private fun startCapturingExistingActivity(
                windowListenerCloseables: MutableCollection<SafeCloseable>
            ) {
                val alreadyOpenActivity = alreadyOpenActivitySupplier.get()
                if (alreadyOpenActivity != null) {
                    startCapture(windowListenerCloseables, alreadyOpenActivity)
                }
            }
            }


            private fun startCapture(
            private fun startCapture(
@@ -92,4 +106,17 @@ class ViewCaptureRule : TestRule {
            }
            }
        }
        }
    }
    }

    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)
    }
}
}