Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
io.flutter.embedding.android.FlutterSurfaceViewTest Class Reference

Public Member Functions

void itShouldCreateANewSurfaceWhenReattachedAfterDetachingFromRenderer ()
 

Detailed Description

Definition at line 26 of file FlutterSurfaceViewTest.java.

Member Function Documentation

◆ itShouldCreateANewSurfaceWhenReattachedAfterDetachingFromRenderer()

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

Definition at line 28 of file FlutterSurfaceViewTest.java.

28 {
29 // Consider this scenario: In an add-to-app context, where multiple Flutter activities share the
30 // same engine, a situation occurs. When navigating from FlutterActivity1 to FlutterActivity2,
31 // the Flutter view associated with FlutterActivity1 is detached from the engine. Then, the
32 // Flutter view of FlutterActivity2 is attached. Upon navigating back to FlutterActivity1, its
33 // Flutter view is re-attached to the shared engine.
34 //
35 // The expected behavior is: When a Flutter view detaches from the shared engine, the associated
36 // surface should be released. When the Flutter view re-attaches, a new surface should be
37 // created.
38
39 // Setup the test.
40 final FlutterSurfaceView surfaceView =
41 spy(new FlutterSurfaceView(ApplicationProvider.getApplicationContext()));
42
43 FlutterJNI fakeFlutterJNI = mock(FlutterJNI.class);
44 FlutterRenderer flutterRenderer = new FlutterRenderer(fakeFlutterJNI);
45
46 SurfaceHolder fakeSurfaceHolder = mock(SurfaceHolder.class);
47 Surface fakeSurface = mock(Surface.class);
48 when(surfaceView.getHolder()).thenReturn(fakeSurfaceHolder);
49 when(fakeSurfaceHolder.getSurface()).thenReturn(fakeSurface);
50 when(surfaceView.isSurfaceAvailableForRendering()).thenReturn(true);
51 when(surfaceView.getWindowToken()).thenReturn(mock(android.os.IBinder.class));
52
53 // Execute the behavior under test.
54 surfaceView.attachToRenderer(flutterRenderer);
55
56 // Verify the behavior under test.
57 verify(fakeFlutterJNI, times(1)).onSurfaceCreated(any(Surface.class));
58
59 // Execute the behavior under test.
60 surfaceView.detachFromRenderer();
61
62 // Verify the behavior under test.
63 verify(fakeFlutterJNI, times(1)).onSurfaceDestroyed();
64
65 // Execute the behavior under test.
66 surfaceView.attachToRenderer(flutterRenderer);
67
68 // Verify the behavior under test.
69 verify(fakeFlutterJNI, never()).onSurfaceWindowChanged(any(Surface.class));
70 verify(fakeFlutterJNI, times(2)).onSurfaceCreated(any(Surface.class));
71 }
static SkISize times(const SkISize &size, float factor)
SIT bool any(const Vec< 1, T > &x)
Definition SkVx.h:530

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