5package io.flutter.view;
7import static org.mockito.ArgumentMatchers.any;
8import static org.mockito.ArgumentMatchers.anyLong;
9import static org.mockito.ArgumentMatchers.eq;
10import static org.mockito.ArgumentMatchers.isNull;
11import static org.mockito.Mockito.mock;
12import static org.mockito.Mockito.times;
13import static org.mockito.Mockito.verify;
14import static org.mockito.Mockito.when;
15import static org.robolectric.Shadows.shadowOf;
17import android.hardware.display.DisplayManager;
20import androidx.test.ext.junit.runners.AndroidJUnit4;
21import io.flutter.embedding.engine.FlutterJNI;
22import org.junit.Before;
24import org.junit.runner.RunWith;
25import org.mockito.ArgumentCaptor;
26import org.robolectric.annotation.Config;
29@RunWith(AndroidJUnit4.class)
40 verify(mockFlutterJNI,
times(1)).setRefreshRateFPS(10.0
f);
46 verify(mockFlutterJNI,
times(1)).setAsyncWaitForVsyncDelegate(delegateCaptor.capture());
48 shadowOf(Looper.getMainLooper()).idle();
49 verify(mockFlutterJNI,
times(1)).onVsync(anyLong(),
eq(1000000000l / 10l),
eq(1l));
55 DisplayManager mockDisplayManager = mock(DisplayManager.class);
56 Display mockDisplay = mock(Display.class);
59 when(mockDisplayManager.getDisplay(Display.DEFAULT_DISPLAY)).thenReturn(mockDisplay);
62 verify(mockDisplayManager,
times(1))
63 .registerDisplayListener(displayListenerCaptor.capture(), isNull());
65 when(mockDisplay.getRefreshRate()).thenReturn(90.0
f);
66 displayListenerCaptor.getValue().onDisplayChanged(Display.DEFAULT_DISPLAY);
67 verify(mockFlutterJNI,
times(1)).setRefreshRateFPS(90.0
f);
73 verify(mockFlutterJNI,
times(1)).setAsyncWaitForVsyncDelegate(delegateCaptor.capture());
75 shadowOf(Looper.getMainLooper()).idle();
76 verify(mockFlutterJNI,
times(1)).onVsync(anyLong(),
eq(1000000000l / 90l),
eq(1l));
78 when(mockDisplay.getRefreshRate()).thenReturn(60.0
f);
79 displayListenerCaptor.getValue().onDisplayChanged(Display.DEFAULT_DISPLAY);
80 verify(mockFlutterJNI,
times(1)).setRefreshRateFPS(60.0
f);
82 delegateCaptor.getValue().asyncWaitForVsync(1);
83 shadowOf(Looper.getMainLooper()).idle();
84 verify(mockFlutterJNI,
times(1)).onVsync(anyLong(),
eq(1000000000l / 60l),
eq(1l));
90 DisplayManager mockDisplayManager = mock(DisplayManager.class);
91 Display mockDisplay = mock(Display.class);
92 when(mockDisplayManager.getDisplay(Display.DEFAULT_DISPLAY)).thenReturn(mockDisplay);
93 when(mockDisplay.getRefreshRate()).thenReturn(90.0
f);
96 verify(mockDisplayManager,
times(1)).registerDisplayListener(
any(), isNull());
98 verify(mockFlutterJNI,
times(1)).setRefreshRateFPS(90.0
f);
static SkISize times(const SkISize &size, float factor)
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
void itSetsFpsWhenDisplayManagerUpdates()
void itSetsFpsWhenDisplayManagerDoesNotUpdate()
void itSetsFpsBelowApi17()
static VsyncWaiter getInstance(float fps, @NonNull FlutterJNI flutterJNI)
void asyncWaitForVsync(final long cookie)
SIT bool any(const Vec< 1, T > &x)