From d3b4945e1ad2b3ccf29511fe3521e81b13591a58 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 4 Mar 2024 09:58:51 -0800 Subject: [PATCH 1/3] Use Instrumentation.waitForIdleSync() after rotation requests. --- .../dev/flutter/scenariosui/PlatformTextureUiTests.java | 5 ++++- .../java/dev/flutter/scenariosui/PlatformViewUiTests.java | 7 ++++++- .../scenariosui/PlatformViewWithSurfaceViewUiTest.java | 5 ++++- .../scenariosui/PlatformViewWithTextureViewUiTest.java | 7 ++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java index a4aa061f2a82c..9451a751111c1 100644 --- a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java +++ b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java @@ -4,6 +4,7 @@ package dev.flutter.scenariosui; +import android.app.Instrumentation; import android.content.Intent; import android.content.pm.ActivityInfo; import androidx.annotation.NonNull; @@ -19,7 +20,8 @@ @RunWith(AndroidJUnit4.class) @LargeTest public class PlatformTextureUiTests { - Intent intent; + private Instrumentation instrumentation; + private Intent intent; @Rule @NonNull public ActivityTestRule activityRule = @@ -99,6 +101,7 @@ public void testPlatformViewRotate() throws Exception { 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/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java index 50dc5dfef600b..12cb44044361f 100644 --- a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewUiTests.java +++ b/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 @@ @RunWith(AndroidJUnit4.class) @LargeTest public class PlatformViewUiTests { - Intent intent; + private Instrumentation instrumentation; + private Intent intent; @Rule @NonNull public ActivityTestRule activityRule = @@ -32,6 +35,7 @@ private static String goldName(String suffix) { @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 void testPlatformViewRotate() throws Exception { 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/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java index b445a3d8407a5..dcedf79cc7276 100644 --- a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java +++ b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java @@ -4,6 +4,7 @@ package dev.flutter.scenariosui; +import android.app.Instrumentation; import android.content.Intent; import android.content.pm.ActivityInfo; import androidx.annotation.NonNull; @@ -20,7 +21,8 @@ @RunWith(AndroidJUnit4.class) @LargeTest public class PlatformViewWithSurfaceViewUiTest { - Intent intent; + private Instrumentation instrumentation; + private Intent intent; @Rule @NonNull public ActivityTestRule activityRule = @@ -100,6 +102,7 @@ public void testPlatformViewRotate() throws Exception { 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/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithTextureViewUiTest.java b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithTextureViewUiTest.java index 9a8dfd99878ee..c2039b59f4508 100644 --- a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithTextureViewUiTest.java +++ b/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 @@ @RunWith(AndroidJUnit4.class) @LargeTest public class PlatformViewWithTextureViewUiTest { - Intent intent; + private Instrumentation instrumentation; + private Intent intent; @Rule @NonNull public ActivityTestRule activityRule = @@ -32,6 +35,7 @@ private static String goldName(String suffix) { @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 void testPlatformViewRotate() throws Exception { 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")); } From 05f1f59837cb1a483cadc1a123bedc8fd6d015f8 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 4 Mar 2024 10:10:00 -0800 Subject: [PATCH 2/3] ++ --- .../flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java index dcedf79cc7276..b5d62993bd456 100644 --- a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java +++ b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformViewWithSurfaceViewUiTest.java @@ -9,6 +9,7 @@ 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; @@ -35,6 +36,7 @@ private static String goldName(String suffix) { @Before public void setUp() { + instrumentation = InstrumentationRegistry.getInstrumentation(); intent = new Intent(Intent.ACTION_MAIN); // Render a texture. intent.putExtra("use_android_view", false); From 7893c820694c2574d2e7fd73e16d9f812f3bdf6a Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 4 Mar 2024 10:27:45 -0800 Subject: [PATCH 3/3] ++ --- .../java/dev/flutter/scenariosui/PlatformTextureUiTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java index 9451a751111c1..bb09a981247f7 100644 --- a/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java +++ b/testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenariosui/PlatformTextureUiTests.java @@ -9,6 +9,7 @@ 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; @@ -34,6 +35,7 @@ private static String goldName(String suffix) { @Before public void setUp() { + instrumentation = InstrumentationRegistry.getInstrumentation(); intent = new Intent(Intent.ACTION_MAIN); // Render a texture. intent.putExtra("use_android_view", false);