Migrate RuntimeEnvironment#sytemContext to ApplicatoinProvider#getApplicationContext (flutter/engine#32725)
This commit is contained in:
@@ -60,7 +60,6 @@ import org.mockito.Spy;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
@@ -500,12 +499,12 @@ public class FlutterViewTest {
|
||||
@Test
|
||||
@Config(minSdk = 23, maxSdk = 29, qualifiers = "land")
|
||||
public void systemInsetHandlesFullscreenNavbarRight() {
|
||||
FlutterView flutterView = spy(new FlutterView(RuntimeEnvironment.systemContext));
|
||||
FlutterView flutterView = spy(new FlutterView(ctx));
|
||||
setExpectedDisplayRotation(Surface.ROTATION_90);
|
||||
assertEquals(0, flutterView.getSystemUiVisibility());
|
||||
when(flutterView.getWindowSystemUiVisibility())
|
||||
.thenReturn(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
when(flutterView.getContext()).thenReturn(RuntimeEnvironment.systemContext);
|
||||
when(flutterView.getContext()).thenReturn(ctx);
|
||||
|
||||
FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni));
|
||||
FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni));
|
||||
@@ -536,12 +535,12 @@ public class FlutterViewTest {
|
||||
@Test
|
||||
@Config(minSdk = 20, maxSdk = 22, qualifiers = "land")
|
||||
public void systemInsetHandlesFullscreenNavbarRightBelowSDK23() {
|
||||
FlutterView flutterView = spy(new FlutterView(RuntimeEnvironment.systemContext));
|
||||
FlutterView flutterView = spy(new FlutterView(ctx));
|
||||
setExpectedDisplayRotation(Surface.ROTATION_270);
|
||||
assertEquals(0, flutterView.getSystemUiVisibility());
|
||||
when(flutterView.getWindowSystemUiVisibility())
|
||||
.thenReturn(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
when(flutterView.getContext()).thenReturn(RuntimeEnvironment.systemContext);
|
||||
when(flutterView.getContext()).thenReturn(ctx);
|
||||
|
||||
FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni));
|
||||
FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni));
|
||||
@@ -572,12 +571,12 @@ public class FlutterViewTest {
|
||||
@Test
|
||||
@Config(minSdk = 23, maxSdk = 29, qualifiers = "land")
|
||||
public void systemInsetHandlesFullscreenNavbarLeft() {
|
||||
FlutterView flutterView = spy(new FlutterView(RuntimeEnvironment.systemContext));
|
||||
FlutterView flutterView = spy(new FlutterView(ctx));
|
||||
setExpectedDisplayRotation(Surface.ROTATION_270);
|
||||
assertEquals(0, flutterView.getSystemUiVisibility());
|
||||
when(flutterView.getWindowSystemUiVisibility())
|
||||
.thenReturn(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
when(flutterView.getContext()).thenReturn(RuntimeEnvironment.systemContext);
|
||||
when(flutterView.getContext()).thenReturn(ctx);
|
||||
|
||||
FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni));
|
||||
FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni));
|
||||
@@ -611,12 +610,12 @@ public class FlutterViewTest {
|
||||
@TargetApi(30)
|
||||
@Config(sdk = 30, qualifiers = "land")
|
||||
public void systemInsetGetInsetsFullscreen() {
|
||||
FlutterView flutterView = spy(new FlutterView(RuntimeEnvironment.systemContext));
|
||||
FlutterView flutterView = spy(new FlutterView(ctx));
|
||||
setExpectedDisplayRotation(Surface.ROTATION_270);
|
||||
assertEquals(0, flutterView.getSystemUiVisibility());
|
||||
when(flutterView.getWindowSystemUiVisibility())
|
||||
.thenReturn(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
when(flutterView.getContext()).thenReturn(RuntimeEnvironment.systemContext);
|
||||
when(flutterView.getContext()).thenReturn(ctx);
|
||||
|
||||
FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni));
|
||||
FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni));
|
||||
@@ -647,12 +646,12 @@ public class FlutterViewTest {
|
||||
@TargetApi(28)
|
||||
@Config(sdk = 28, qualifiers = "land")
|
||||
public void systemInsetGetInsetsFullscreenLegacy() {
|
||||
FlutterView flutterView = spy(new FlutterView(RuntimeEnvironment.systemContext));
|
||||
FlutterView flutterView = spy(new FlutterView(ctx));
|
||||
setExpectedDisplayRotation(Surface.ROTATION_270);
|
||||
assertEquals(0, flutterView.getSystemUiVisibility());
|
||||
when(flutterView.getWindowSystemUiVisibility())
|
||||
.thenReturn(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
when(flutterView.getContext()).thenReturn(RuntimeEnvironment.systemContext);
|
||||
when(flutterView.getContext()).thenReturn(ctx);
|
||||
|
||||
FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni));
|
||||
FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni));
|
||||
@@ -685,10 +684,10 @@ public class FlutterViewTest {
|
||||
@TargetApi(30)
|
||||
@Config(sdk = 30, qualifiers = "land")
|
||||
public void systemInsetDisplayCutoutSimple() {
|
||||
FlutterView flutterView = spy(new FlutterView(RuntimeEnvironment.systemContext));
|
||||
FlutterView flutterView = spy(new FlutterView(ctx));
|
||||
assertEquals(0, flutterView.getSystemUiVisibility());
|
||||
when(flutterView.getWindowSystemUiVisibility()).thenReturn(0);
|
||||
when(flutterView.getContext()).thenReturn(RuntimeEnvironment.systemContext);
|
||||
when(flutterView.getContext()).thenReturn(ctx);
|
||||
|
||||
FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni));
|
||||
FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni));
|
||||
@@ -733,9 +732,7 @@ public class FlutterViewTest {
|
||||
FlutterView flutterView = spy(new FlutterView(context));
|
||||
ShadowDisplay display =
|
||||
Shadows.shadowOf(
|
||||
((WindowManager)
|
||||
RuntimeEnvironment.systemContext.getSystemService(Context.WINDOW_SERVICE))
|
||||
.getDefaultDisplay());
|
||||
((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay());
|
||||
WindowInfoRepositoryCallbackAdapterWrapper windowInfoRepo =
|
||||
mock(WindowInfoRepositoryCallbackAdapterWrapper.class);
|
||||
// For reasoning behing using doReturn instead of when, read "Important gotcha" at
|
||||
@@ -761,9 +758,7 @@ public class FlutterViewTest {
|
||||
FlutterView flutterView = spy(new FlutterView(context));
|
||||
ShadowDisplay display =
|
||||
Shadows.shadowOf(
|
||||
((WindowManager)
|
||||
RuntimeEnvironment.systemContext.getSystemService(Context.WINDOW_SERVICE))
|
||||
.getDefaultDisplay());
|
||||
((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay());
|
||||
when(flutterView.getContext()).thenReturn(context);
|
||||
WindowInfoRepositoryCallbackAdapterWrapper windowInfoRepo =
|
||||
mock(WindowInfoRepositoryCallbackAdapterWrapper.class);
|
||||
@@ -1006,9 +1001,7 @@ public class FlutterViewTest {
|
||||
private void setExpectedDisplayRotation(int rotation) {
|
||||
ShadowDisplay display =
|
||||
Shadows.shadowOf(
|
||||
((WindowManager)
|
||||
RuntimeEnvironment.systemContext.getSystemService(Context.WINDOW_SERVICE))
|
||||
.getDefaultDisplay());
|
||||
((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay());
|
||||
display.setRotation(rotation);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,26 +4,27 @@ import static android.view.View.OnFocusChangeListener;
|
||||
import static junit.framework.TestCase.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Matrix;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewTreeObserver;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import io.flutter.embedding.android.AndroidTouchProcessor;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@Config(manifest = Config.NONE)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FlutterMutatorViewTest {
|
||||
private final Context ctx = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Test
|
||||
public void canDragViews() {
|
||||
final AndroidTouchProcessor touchProcessor = mock(AndroidTouchProcessor.class);
|
||||
final FlutterMutatorView view =
|
||||
new FlutterMutatorView(RuntimeEnvironment.systemContext, 1.0f, touchProcessor);
|
||||
final FlutterMutatorView view = new FlutterMutatorView(ctx, 1.0f, touchProcessor);
|
||||
final FlutterMutatorsStack mutatorStack = mock(FlutterMutatorsStack.class);
|
||||
|
||||
assertTrue(view.onInterceptTouchEvent(mock(MotionEvent.class)));
|
||||
@@ -85,7 +86,7 @@ public class FlutterMutatorViewTest {
|
||||
when(viewTreeObserver.isAlive()).thenReturn(true);
|
||||
|
||||
final FlutterMutatorView view =
|
||||
new FlutterMutatorView(RuntimeEnvironment.systemContext) {
|
||||
new FlutterMutatorView(ctx) {
|
||||
@Override
|
||||
public ViewTreeObserver getViewTreeObserver() {
|
||||
return viewTreeObserver;
|
||||
@@ -114,7 +115,7 @@ public class FlutterMutatorViewTest {
|
||||
when(viewTreeObserver.isAlive()).thenReturn(true);
|
||||
|
||||
final FlutterMutatorView view =
|
||||
new FlutterMutatorView(RuntimeEnvironment.systemContext) {
|
||||
new FlutterMutatorView(ctx) {
|
||||
@Override
|
||||
public ViewTreeObserver getViewTreeObserver() {
|
||||
return viewTreeObserver;
|
||||
@@ -140,7 +141,7 @@ public class FlutterMutatorViewTest {
|
||||
@Test
|
||||
public void focusChangeListener_viewTreeObserverIsAliveFalseDoesNotThrow() {
|
||||
final FlutterMutatorView view =
|
||||
new FlutterMutatorView(RuntimeEnvironment.systemContext) {
|
||||
new FlutterMutatorView(ctx) {
|
||||
@Override
|
||||
public ViewTreeObserver getViewTreeObserver() {
|
||||
final ViewTreeObserver viewTreeObserver = mock(ViewTreeObserver.class);
|
||||
@@ -157,7 +158,7 @@ public class FlutterMutatorViewTest {
|
||||
when(viewTreeObserver.isAlive()).thenReturn(true);
|
||||
|
||||
final FlutterMutatorView view =
|
||||
new FlutterMutatorView(RuntimeEnvironment.systemContext) {
|
||||
new FlutterMutatorView(ctx) {
|
||||
@Override
|
||||
public ViewTreeObserver getViewTreeObserver() {
|
||||
return viewTreeObserver;
|
||||
@@ -184,7 +185,7 @@ public class FlutterMutatorViewTest {
|
||||
when(viewTreeObserver.isAlive()).thenReturn(true);
|
||||
|
||||
final FlutterMutatorView view =
|
||||
new FlutterMutatorView(RuntimeEnvironment.systemContext) {
|
||||
new FlutterMutatorView(ctx) {
|
||||
@Override
|
||||
public ViewTreeObserver getViewTreeObserver() {
|
||||
return viewTreeObserver;
|
||||
|
||||
Reference in New Issue
Block a user