From 43f24a8c1f65e0e95d2d4589e7a0fc087c33adc9 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 4 Mar 2024 11:05:51 -0800 Subject: [PATCH] Use Instrumentation.waitForIdleSync() after rotation requests. (flutter/engine#51169) Fixes https://github.com/flutter/flutter/issues/144553. Looking roughly at: - - ... and given the fact it's only the rotation tests that seem especially flaky, let's give it a shot? /cc @reidbaker @johnmccutchan if you have other advice. --- .../dev/flutter/scenariosui/PlatformTextureUiTests.java | 7 ++++++- .../java/dev/flutter/scenariosui/PlatformViewUiTests.java | 7 ++++++- .../scenariosui/PlatformViewWithSurfaceViewUiTest.java | 7 ++++++- .../scenariosui/PlatformViewWithTextureViewUiTest.java | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java index a4aa061f2a..bb09a98124 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java +++ b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java @@ -4,10 +4,12 @@ package dev.flutter.scenariosui; +import android.app.Instrumentation; import android.content.Intent; import android.content.pm.ActivityInfo; import androidx.annotation.NonNull; import androidx.test.filters.LargeTest; +import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import dev.flutter.scenarios.PlatformViewsActivity; @@ -19,7 +21,8 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @LargeTest public class PlatformTextureUiTests { - Intent intent; + private Instrumentation instrumentation; + private Intent intent; @Rule @NonNull public ActivityTestRule activityRule = @@ -32,6 +35,7 @@ public class PlatformTextureUiTests { @Before public void setUp() { + instrumentation = InstrumentationRegistry.getInstrumentation(); intent = new Intent(Intent.ACTION_MAIN); // Render a texture. intent.putExtra("use_android_view", false); @@ -99,6 +103,7 @@ public class PlatformTextureUiTests { intent.putExtra("scenario_name", "platform_view_rotate"); PlatformViewsActivity activity = activityRule.launchActivity(intent); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + instrumentation.waitForIdleSync(); ScreenshotUtil.capture(activity, goldName("testPlatformViewRotate")); } diff --git a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java index 50dc5dfef6..12cb440443 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java +++ b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java @@ -4,10 +4,12 @@ package dev.flutter.scenariosui; +import android.app.Instrumentation; import android.content.Intent; import android.content.pm.ActivityInfo; import androidx.annotation.NonNull; import androidx.test.filters.LargeTest; +import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import dev.flutter.scenarios.PlatformViewsActivity; @@ -19,7 +21,8 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @LargeTest public class PlatformViewUiTests { - Intent intent; + private Instrumentation instrumentation; + private Intent intent; @Rule @NonNull public ActivityTestRule activityRule = @@ -32,6 +35,7 @@ public class PlatformViewUiTests { @Before public void setUp() { + instrumentation = InstrumentationRegistry.getInstrumentation(); intent = new Intent(Intent.ACTION_MAIN); // Render a native android view. intent.putExtra("use_android_view", true); @@ -99,6 +103,7 @@ public class PlatformViewUiTests { intent.putExtra("scenario_name", "platform_view_rotate"); PlatformViewsActivity activity = activityRule.launchActivity(intent); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + instrumentation.waitForIdleSync(); ScreenshotUtil.capture(activity, goldName("testPlatformViewRotate")); } diff --git a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java index b445a3d840..b5d62993bd 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java +++ b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java @@ -4,10 +4,12 @@ package dev.flutter.scenariosui; +import android.app.Instrumentation; import android.content.Intent; import android.content.pm.ActivityInfo; import androidx.annotation.NonNull; import androidx.test.filters.LargeTest; +import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import dev.flutter.scenarios.PlatformViewsActivity; @@ -20,7 +22,8 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @LargeTest public class PlatformViewWithSurfaceViewUiTest { - Intent intent; + private Instrumentation instrumentation; + private Intent intent; @Rule @NonNull public ActivityTestRule activityRule = @@ -33,6 +36,7 @@ public class PlatformViewWithSurfaceViewUiTest { @Before public void setUp() { + instrumentation = InstrumentationRegistry.getInstrumentation(); intent = new Intent(Intent.ACTION_MAIN); // Render a texture. intent.putExtra("use_android_view", false); @@ -100,6 +104,7 @@ public class PlatformViewWithSurfaceViewUiTest { intent.putExtra("scenario_name", "platform_view_rotate"); PlatformViewsActivity activity = activityRule.launchActivity(intent); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + instrumentation.waitForIdleSync(); ScreenshotUtil.capture(activity, goldName("testPlatformViewRotate")); } diff --git a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithTextureViewUiTest.java b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithTextureViewUiTest.java index 9a8dfd9987..c2039b59f4 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithTextureViewUiTest.java +++ b/engine/src/flutter/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithTextureViewUiTest.java @@ -4,10 +4,12 @@ package dev.flutter.scenariosui; +import android.app.Instrumentation; import android.content.Intent; import android.content.pm.ActivityInfo; import androidx.annotation.NonNull; import androidx.test.filters.LargeTest; +import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import dev.flutter.scenarios.PlatformViewsActivity; @@ -19,7 +21,8 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @LargeTest public class PlatformViewWithTextureViewUiTest { - Intent intent; + private Instrumentation instrumentation; + private Intent intent; @Rule @NonNull public ActivityTestRule activityRule = @@ -32,6 +35,7 @@ public class PlatformViewWithTextureViewUiTest { @Before public void setUp() { + instrumentation = InstrumentationRegistry.getInstrumentation(); intent = new Intent(Intent.ACTION_MAIN); intent.putExtra("view_type", PlatformViewsActivity.TEXTURE_VIEW_PV); } @@ -97,6 +101,7 @@ public class PlatformViewWithTextureViewUiTest { intent.putExtra("scenario_name", "platform_view_rotate"); PlatformViewsActivity activity = activityRule.launchActivity(intent); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + instrumentation.waitForIdleSync(); ScreenshotUtil.capture(activity, goldName("testPlatformViewRotate")); }