Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
io.flutter.embedding.android.FlutterTextureViewTest Class Reference

Public Member Functions

void surfaceTextureListenerReleasesRenderer ()
 
void itShouldCreateANewSurfaceWhenReattachedAfterDetachingFromRenderer ()
 

Detailed Description

Definition at line 27 of file FlutterTextureViewTest.java.

Member Function Documentation

◆ itShouldCreateANewSurfaceWhenReattachedAfterDetachingFromRenderer()

void io.flutter.embedding.android.FlutterTextureViewTest.itShouldCreateANewSurfaceWhenReattachedAfterDetachingFromRenderer ( )
inline

Definition at line 43 of file FlutterTextureViewTest.java.

43 {
44 // Consider this scenario: In an add-to-app context, where multiple Flutter activities share the
45 // same engine, a situation occurs. When navigating from FlutterActivity1 to FlutterActivity2,
46 // the Flutter view associated with FlutterActivity1 is detached from the engine. Then, the
47 // Flutter view of FlutterActivity2 is attached. Upon navigating back to FlutterActivity1, its
48 // Flutter view is re-attached to the shared engine.
49 //
50 // The expected behavior is: When a Flutter view detaches from the shared engine, the associated
51 // surface should be released. When the Flutter view re-attaches, a new surface should be
52 // created.
53
54 // Setup the test.
55 final FlutterTextureView textureView =
56 spy(new FlutterTextureView(ApplicationProvider.getApplicationContext()));
57
58 FlutterJNI fakeFlutterJNI = mock(FlutterJNI.class);
59 FlutterRenderer flutterRenderer = new FlutterRenderer(fakeFlutterJNI);
60
61 when(textureView.isSurfaceAvailableForRendering()).thenReturn(true);
62 when(textureView.getSurfaceTexture()).thenReturn(mock(SurfaceTexture.class));
63 when(textureView.getWindowToken()).thenReturn(mock(android.os.IBinder.class));
64
65 // Execute the behavior under test.
66 textureView.attachToRenderer(flutterRenderer);
67
68 // Verify the behavior under test.
69 verify(fakeFlutterJNI, times(1)).onSurfaceCreated(any(Surface.class));
70
71 // Execute the behavior under test.
72 textureView.detachFromRenderer();
73
74 // Verify the behavior under test.
75 verify(fakeFlutterJNI, times(1)).onSurfaceDestroyed();
76
77 // Execute the behavior under test.
78 textureView.attachToRenderer(flutterRenderer);
79
80 // Verify the behavior under test.
81 verify(fakeFlutterJNI, never()).onSurfaceWindowChanged(any(Surface.class));
82 verify(fakeFlutterJNI, times(2)).onSurfaceCreated(any(Surface.class));
83 }
static SkISize times(const SkISize &size, float factor)
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530

◆ surfaceTextureListenerReleasesRenderer()

void io.flutter.embedding.android.FlutterTextureViewTest.surfaceTextureListenerReleasesRenderer ( )
inline

Definition at line 29 of file FlutterTextureViewTest.java.

29 {
30 final FlutterTextureView textureView =
31 new FlutterTextureView(ApplicationProvider.getApplicationContext());
32 final Surface mockRenderSurface = mock(Surface.class);
33
34 textureView.setRenderSurface(mockRenderSurface);
35
36 final TextureView.SurfaceTextureListener listener = textureView.getSurfaceTextureListener();
37 listener.onSurfaceTextureDestroyed(mock(SurfaceTexture.class));
38
39 verify(mockRenderSurface).release();
40 }

The documentation for this class was generated from the following file: