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

Add test for external textures on Android #26109

Closed
wants to merge 4 commits into from
Closed
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
@@ -0,0 +1,110 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package dev.flutter.scenariosui;

import android.content.Intent;
import android.graphics.Rect;
import android.os.Build.VERSION_CODES;
import androidx.test.filters.LargeTest;
import androidx.test.filters.SdkSuppress;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import dev.flutter.scenarios.ExternalTextureFlutterActivity;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ExternalTextureTests {
private static final int SURFACE_WIDTH = 192;
private static final int SURFACE_HEIGHT = 256;

Intent intent;

@Rule
public ActivityTestRule<ExternalTextureFlutterActivity> activityRule =
new ActivityTestRule<>(
ExternalTextureFlutterActivity.class,
/*initialTouchMode=*/ false,
/*launchActivity=*/ false);

@Before
public void setUp() {
intent = new Intent(Intent.ACTION_MAIN);
}

@Test
public void testCanvasSurface() throws Exception {
intent.putExtra("scenario", "display_texture");
intent.putExtra("surface_renderer", "canvas");
ScreenshotUtil.capture(activityRule.launchActivity(intent));
}

@Test
@SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP)
public void testMediaSurface() throws Exception {
intent.putExtra("scenario", "display_texture");
intent.putExtra("surface_renderer", "media");
ScreenshotUtil.capture(activityRule.launchActivity(intent));
}

@Test
@SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP)
public void testRotatedMediaSurface_90() throws Exception {
intent.putExtra("scenario", "display_texture");
intent.putExtra("surface_renderer", "media");
intent.putExtra("rotation", 90);
ScreenshotUtil.capture(activityRule.launchActivity(intent));
}

@Test
@SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP)
public void testRotatedMediaSurface_180() throws Exception {
intent.putExtra("scenario", "display_texture");
intent.putExtra("surface_renderer", "media");
intent.putExtra("rotation", 180);
ScreenshotUtil.capture(activityRule.launchActivity(intent));
}

@Test
@SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP)
public void testRotatedMediaSurface_270() throws Exception {
intent.putExtra("scenario", "display_texture");
intent.putExtra("surface_renderer", "media");
intent.putExtra("rotation", 270);
ScreenshotUtil.capture(activityRule.launchActivity(intent));
}

@Test
@SdkSuppress(minSdkVersion = VERSION_CODES.M)
public void testCroppedMediaSurface_bottomLeft() throws Exception {
intent.putExtra("scenario", "display_texture");
intent.putExtra("surface_renderer", "image");
intent.putExtra("crop", new Rect(0, 0, SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2));
ScreenshotUtil.capture(activityRule.launchActivity(intent));
}

@Test
@SdkSuppress(minSdkVersion = VERSION_CODES.M)
public void testCroppedMediaSurface_topRight() throws Exception {
intent.putExtra("scenario", "display_texture");
intent.putExtra("surface_renderer", "image");
intent.putExtra(
"crop", new Rect(SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2, SURFACE_WIDTH, SURFACE_HEIGHT));
ScreenshotUtil.capture(activityRule.launchActivity(intent));
}

@Test
@SdkSuppress(minSdkVersion = VERSION_CODES.M)
public void testCroppedRotatedMediaSurface_bottomLeft_90() throws Exception {
intent.putExtra("scenario", "display_texture");
intent.putExtra("surface_renderer", "image");
intent.putExtra("crop", new Rect(0, 0, SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2));
intent.putExtra("rotation", 90);
ScreenshotUtil.capture(activityRule.launchActivity(intent));
}
}
17 changes: 17 additions & 0 deletions testing/scenario_app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ExternalTextureFlutterActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize"
android:theme="@style/FullScreenScreenshot">
<intent-filter>
<action android:name="com.google.intent.action.TEST_LOOP" />
Copy link

Choose a reason for hiding this comment

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

this seems correct. I wonder if the issue is that only one activity can have this action. What happens if you remove the content of the outer <intent-filter>?

<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/javascript" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".StrictModeFlutterActivity"
android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down
Binary file not shown.
Loading