Loading quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -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( Loading tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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() Loading tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt +20 −7 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 { Loading @@ -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) { Loading @@ -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}" ) ) } } } } Loading
quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -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( Loading
tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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() Loading
tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt +20 −7 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 { Loading @@ -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) { Loading @@ -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}" ) ) } } } }