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

Commit 62f24f63 authored by vadimt's avatar vadimt
Browse files

Moving ViewCaptureRule to inside of FailureWatcher

Goal: ViewCaptureRule finishes recording before FailureWatcher starts saving
  artifacts, including view capture.

Also starting recoding without waiting for activity creation if there is
already a Launcher activity.

Test: local, presubmit
Flag: N/A
Bug: 286251603
Change-Id: I191d3cdde76e9f906453b20325862f2bcff9024c
parent 167ff731
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -117,12 +117,13 @@ public class FallbackRecentsTest {
            Utilities.enableRunningInTestHarnessForTests();
        }

        final ViewCaptureRule viewCaptureRule = new ViewCaptureRule();
        final ViewCaptureRule viewCaptureRule = new ViewCaptureRule(
                RecentsActivity.ACTIVITY_TRACKER::getCreatedActivity);
        mOrderSensitiveRules = RuleChain
                .outerRule(new SamplerRule())
                .around(new NavigationModeSwitchRule(mLauncher))
                .around(viewCaptureRule)
                .around(new FailureWatcher(mDevice, mLauncher, viewCaptureRule.getViewCapture()))
                .around(viewCaptureRule)
                .around(new ViewCaptureAnalysisRule(viewCaptureRule.getViewCapture()));

        mOtherLauncherActivity = context.getPackageManager().queryIntentActivities(
+2 −2
Original line number Diff line number Diff line
@@ -204,11 +204,11 @@ public abstract class AbstractLauncherUiTest {
    }

    protected TestRule getRulesInsideActivityMonitor() {
        final ViewCaptureRule viewCaptureRule = new ViewCaptureRule();
        final ViewCaptureRule viewCaptureRule = new ViewCaptureRule(mActivityMonitor::getActivity);
        final RuleChain inner = RuleChain
                .outerRule(new PortraitLandscapeRunner(this))
                .around(viewCaptureRule)
                .around(new FailureWatcher(mDevice, mLauncher, viewCaptureRule.getViewCapture()))
                .around(viewCaptureRule)
                .around(new ViewCaptureAnalysisRule(viewCaptureRule.getViewCapture()));

        return TestHelpers.isInLauncherProcess()
+20 −7
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import androidx.test.core.app.ApplicationProvider
import com.android.app.viewcapture.SimpleViewCapture
import com.android.app.viewcapture.ViewCapture.MAIN_EXECUTOR
import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter
import java.util.function.Supplier
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
@@ -33,7 +34,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.
 */
class ViewCaptureRule : TestRule {
class ViewCaptureRule(var alreadyOpenActivitySupplier: Supplier<Activity?>) : TestRule {
    val viewCapture = SimpleViewCapture("test-view-capture")

    override fun apply(base: Statement, description: Description): Statement {
@@ -41,16 +42,16 @@ class ViewCaptureRule : TestRule {
            override fun evaluate() {
                val windowListenerCloseables = mutableListOf<SafeCloseable>()

                val alreadyOpenActivity = alreadyOpenActivitySupplier.get()
                if (alreadyOpenActivity != null) {
                    startCapture(windowListenerCloseables, alreadyOpenActivity)
                }

                val lifecycleCallbacks =
                    object : ActivityLifecycleCallbacksAdapter {
                        override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
                            super.onActivityCreated(activity, bundle)
                            windowListenerCloseables.add(
                                viewCapture.startCapture(
                                    activity.window.decorView,
                                    "${description.testClass?.simpleName}.${description.methodName}"
                                )
                            )
                            startCapture(windowListenerCloseables, activity)
                        }

                        override fun onActivityDestroyed(activity: Activity) {
@@ -75,6 +76,18 @@ class ViewCaptureRule : TestRule {
                    MAIN_EXECUTOR.execute { windowListenerCloseables.onEach(SafeCloseable::close) }
                }
            }

            private fun startCapture(
                windowListenerCloseables: MutableCollection<SafeCloseable>,
                activity: Activity
            ) {
                windowListenerCloseables.add(
                    viewCapture.startCapture(
                        activity.window.decorView,
                        "${description.testClass?.simpleName}.${description.methodName}"
                    )
                )
            }
        }
    }
}