|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +package dev.flutter.scenariosui; |
| 6 | + |
| 7 | +import android.content.Intent; |
| 8 | +import android.graphics.Rect; |
| 9 | +import android.os.Build.VERSION_CODES; |
| 10 | +import androidx.annotation.NonNull; |
| 11 | +import androidx.test.filters.LargeTest; |
| 12 | +import androidx.test.filters.SdkSuppress; |
| 13 | +import androidx.test.rule.ActivityTestRule; |
| 14 | +import androidx.test.runner.AndroidJUnit4; |
| 15 | +import dev.flutter.scenarios.ExternalTextureFlutterActivity; |
| 16 | +import org.junit.Before; |
| 17 | +import org.junit.Rule; |
| 18 | +import org.junit.Test; |
| 19 | +import org.junit.runner.RunWith; |
| 20 | + |
| 21 | +@RunWith(AndroidJUnit4.class) |
| 22 | +@LargeTest |
| 23 | +public class ExternalTextureTests { |
| 24 | + private static final int SURFACE_WIDTH = 192; |
| 25 | + private static final int SURFACE_HEIGHT = 256; |
| 26 | + |
| 27 | + Intent intent; |
| 28 | + |
| 29 | + @Rule @NonNull |
| 30 | + public ActivityTestRule<ExternalTextureFlutterActivity> activityRule = |
| 31 | + new ActivityTestRule<>( |
| 32 | + ExternalTextureFlutterActivity.class, |
| 33 | + /*initialTouchMode=*/ false, |
| 34 | + /*launchActivity=*/ false); |
| 35 | + |
| 36 | + @Before |
| 37 | + public void setUp() { |
| 38 | + intent = new Intent(Intent.ACTION_MAIN); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testCanvasSurface() throws Exception { |
| 43 | + intent.putExtra("scenario", "display_texture"); |
| 44 | + intent.putExtra("surface_renderer", "canvas"); |
| 45 | + ScreenshotUtil.capture(activityRule.launchActivity(intent)); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + @SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP) |
| 50 | + public void testMediaSurface() throws Exception { |
| 51 | + intent.putExtra("scenario", "display_texture"); |
| 52 | + intent.putExtra("surface_renderer", "media"); |
| 53 | + ScreenshotUtil.capture(activityRule.launchActivity(intent)); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + @SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP) |
| 58 | + public void testRotatedMediaSurface_90() throws Exception { |
| 59 | + intent.putExtra("scenario", "display_texture"); |
| 60 | + intent.putExtra("surface_renderer", "media"); |
| 61 | + intent.putExtra("rotation", 90); |
| 62 | + ScreenshotUtil.capture(activityRule.launchActivity(intent)); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + @SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP) |
| 67 | + public void testRotatedMediaSurface_180() throws Exception { |
| 68 | + intent.putExtra("scenario", "display_texture"); |
| 69 | + intent.putExtra("surface_renderer", "media"); |
| 70 | + intent.putExtra("rotation", 180); |
| 71 | + ScreenshotUtil.capture(activityRule.launchActivity(intent)); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + @SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP) |
| 76 | + public void testRotatedMediaSurface_270() throws Exception { |
| 77 | + intent.putExtra("scenario", "display_texture"); |
| 78 | + intent.putExtra("surface_renderer", "media"); |
| 79 | + intent.putExtra("rotation", 270); |
| 80 | + ScreenshotUtil.capture(activityRule.launchActivity(intent)); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + @SdkSuppress(minSdkVersion = VERSION_CODES.M) |
| 85 | + public void testCroppedMediaSurface_bottomLeft() throws Exception { |
| 86 | + intent.putExtra("scenario", "display_texture"); |
| 87 | + intent.putExtra("surface_renderer", "image"); |
| 88 | + intent.putExtra("crop", new Rect(0, 0, SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2)); |
| 89 | + ScreenshotUtil.capture(activityRule.launchActivity(intent)); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + @SdkSuppress(minSdkVersion = VERSION_CODES.M) |
| 94 | + public void testCroppedMediaSurface_topRight() throws Exception { |
| 95 | + intent.putExtra("scenario", "display_texture"); |
| 96 | + intent.putExtra("surface_renderer", "image"); |
| 97 | + intent.putExtra( |
| 98 | + "crop", new Rect(SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2, SURFACE_WIDTH, SURFACE_HEIGHT)); |
| 99 | + ScreenshotUtil.capture(activityRule.launchActivity(intent)); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + @SdkSuppress(minSdkVersion = VERSION_CODES.M) |
| 104 | + public void testCroppedRotatedMediaSurface_bottomLeft_90() throws Exception { |
| 105 | + intent.putExtra("scenario", "display_texture"); |
| 106 | + intent.putExtra("surface_renderer", "image"); |
| 107 | + intent.putExtra("crop", new Rect(0, 0, SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2)); |
| 108 | + intent.putExtra("rotation", 90); |
| 109 | + ScreenshotUtil.capture(activityRule.launchActivity(intent)); |
| 110 | + } |
| 111 | +} |
0 commit comments