Flutter Engine
The Flutter Engine
PlatformViewWithSurfaceViewUiTest.java
Go to the documentation of this file.
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
5package dev.flutter.scenariosui;
6
7import android.app.Instrumentation;
8import android.content.Intent;
9import android.content.pm.ActivityInfo;
10import androidx.annotation.NonNull;
11import androidx.test.ext.junit.runners.AndroidJUnit4;
12import androidx.test.filters.LargeTest;
13import androidx.test.platform.app.InstrumentationRegistry;
14import androidx.test.rule.ActivityTestRule;
15import dev.flutter.scenarios.PlatformViewsActivity;
16import org.junit.Before;
17import org.junit.Ignore;
18import org.junit.Rule;
19import org.junit.Test;
20import org.junit.runner.RunWith;
21
22@RunWith(AndroidJUnit4.class)
23@LargeTest
25 private Instrumentation instrumentation;
26 private Intent intent;
27
28 @Rule @NonNull
29 public ActivityTestRule<PlatformViewsActivity> activityRule =
30 new ActivityTestRule<>(
31 PlatformViewsActivity.class, /*initialTouchMode=*/ false, /*launchActivity=*/ false);
32
33 private static String goldName(String suffix) {
34 return "PlatformViewWithSurfaceViewUiTest_" + suffix;
35 }
36
37 @Before
38 public void setUp() {
39 instrumentation = InstrumentationRegistry.getInstrumentation();
40 intent = new Intent(Intent.ACTION_MAIN);
41 // Render a texture.
42 intent.putExtra("use_android_view", false);
43 intent.putExtra("view_type", PlatformViewsActivity.SURFACE_VIEW_PV);
44 }
45
46 @Test
47 public void testPlatformView() throws Exception {
48 intent.putExtra("scenario_name", "platform_view");
49 ScreenshotUtil.capture(activityRule.launchActivity(intent), goldName("testPlatformView"));
50 }
51
52 @Test
53 public void testPlatformViewMultiple() throws Exception {
54 intent.putExtra("scenario_name", "platform_view_multiple");
56 activityRule.launchActivity(intent), goldName("testPlatformViewMultiple"));
57 }
58
59 @Test
60 public void testPlatformViewMultipleBackgroundForeground() throws Exception {
61 intent.putExtra("scenario_name", "platform_view_multiple_background_foreground");
63 activityRule.launchActivity(intent),
64 goldName("testPlatformViewMultipleBackgroundForeground"));
65 }
66
67 @Test
68 public void testPlatformViewCliprect() throws Exception {
69 intent.putExtra("scenario_name", "platform_view_cliprect");
71 activityRule.launchActivity(intent), goldName("testPlatformViewCliprect"));
72 }
73
74 @Test
75 public void testPlatformViewCliprrect() throws Exception {
76 intent.putExtra("scenario_name", "platform_view_cliprrect");
78 activityRule.launchActivity(intent), goldName("testPlatformViewCliprrect"));
79 }
80
81 @Test
82 public void testPlatformViewClippath() throws Exception {
83 intent.putExtra("scenario_name", "platform_view_clippath");
85 activityRule.launchActivity(intent), goldName("testPlatformViewClippath"));
86 }
87
88 @Test
89 public void testPlatformViewTransform() throws Exception {
90 intent.putExtra("scenario_name", "platform_view_transform");
92 activityRule.launchActivity(intent), goldName("testPlatformViewTransform"));
93 }
94
95 @Test
96 public void testPlatformViewOpacity() throws Exception {
97 intent.putExtra("scenario_name", "platform_view_opacity");
99 activityRule.launchActivity(intent), goldName("testPlatformViewOpacity"));
100 }
101
102 @Test
103 public void testPlatformViewRotate() throws Exception {
104 intent.putExtra("scenario_name", "platform_view_rotate");
105 PlatformViewsActivity activity = activityRule.launchActivity(intent);
106 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
107 instrumentation.waitForIdleSync();
108 ScreenshotUtil.capture(activity, goldName("testPlatformViewRotate"));
109 }
110
111 @Test
112 public void testPlatformViewMultipleWithoutOverlays() throws Exception {
113 intent.putExtra("scenario_name", "platform_view_multiple_without_overlays");
115 activityRule.launchActivity(intent), goldName("testPlatformViewMultipleWithoutOverlays"));
116 }
117
118 @Test
119 public void testPlatformViewTwoIntersectingOverlays() throws Exception {
120 intent.putExtra("scenario_name", "platform_view_two_intersecting_overlays");
122 activityRule.launchActivity(intent), goldName("testPlatformViewTwoIntersectingOverlays"));
123 }
124
125 @Test
126 public void testPlatformViewWithoutOverlayIntersection() throws Exception {
127 intent.putExtra("scenario_name", "platform_view_no_overlay_intersection");
129 activityRule.launchActivity(intent),
130 goldName("testPlatformViewWithoutOverlayIntersection"));
131 }
132
133 // TODO(dnfield): This is not safe until https://github.com/flutter/flutter/issues/31990
134 // is resolved.
135 @Ignore("not safe until https://github.com/flutter/flutter/issues/31990 is resolved")
136 @Test
137 public void testPlatformViewLargerThanDisplaySize() throws Exception {
138 // Regression test for https://github.com/flutter/flutter/issues/28978.
139 intent.putExtra("scenario_name", "platform_view_larger_than_display_size");
141 activityRule.launchActivity(intent), goldName("testPlatformViewLargerThanDisplaySize"));
142 }
143}
static void capture(@NonNull TestableFlutterActivity activity, @NonNull String captureName)