Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Use Instrumentation.waitForIdleSync() after rotation requests. #51169

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +21,8 @@
@RunWith(AndroidJUnit4.class)
@LargeTest
public class PlatformTextureUiTests {
Intent intent;
private Instrumentation instrumentation;
private Intent intent;

@Rule @NonNull
public ActivityTestRule<PlatformViewsActivity> activityRule =
Expand All @@ -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 texture.
intent.putExtra("use_android_view", false);
Expand Down Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this be null?

I think what you actually want here is InstrumentationRegistry.getInstrumentation().waitForIdleSync()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this one is still missing)

ScreenshotUtil.capture(activity, goldName("testPlatformViewRotate"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +21,8 @@
@RunWith(AndroidJUnit4.class)
@LargeTest
public class PlatformViewUiTests {
Intent intent;
private Instrumentation instrumentation;
private Intent intent;

@Rule @NonNull
public ActivityTestRule<PlatformViewsActivity> activityRule =
Expand All @@ -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);
Expand Down Expand Up @@ -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"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +22,8 @@
@RunWith(AndroidJUnit4.class)
@LargeTest
public class PlatformViewWithSurfaceViewUiTest {
Intent intent;
private Instrumentation instrumentation;
private Intent intent;

@Rule @NonNull
public ActivityTestRule<PlatformViewsActivity> activityRule =
Expand All @@ -33,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);
Expand Down Expand Up @@ -100,6 +104,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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here - but if you'd rather add a setup method for setting this I guess that's fine too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah oops, thought I had all of them. I would have tried it locally first but uh:
https://discord.com/channels/608014603317936148/608021010377080866/1214272920382210049

ScreenshotUtil.capture(activity, goldName("testPlatformViewRotate"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +21,8 @@
@RunWith(AndroidJUnit4.class)
@LargeTest
public class PlatformViewWithTextureViewUiTest {
Intent intent;
private Instrumentation instrumentation;
private Intent intent;

@Rule @NonNull
public ActivityTestRule<PlatformViewsActivity> activityRule =
Expand All @@ -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);
}
Expand Down Expand Up @@ -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"));
}

Expand Down