From 69dfefb9e17bbc8ce468a3e4a3d6ecb28553254d Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 15:11:44 -0400 Subject: [PATCH 01/25] Remove usages of deprecated junit.framework and replace with org.junit in KeyboardManagerTest, PlatformViewsControllerTest and SinglePresentationViewTest --- .../android/KeyboardManagerTest.java | 35 +++++++++---------- .../platform/PlatformViewsControllerTest.java | 2 -- .../platform/SingleViewPresentationTest.java | 2 +- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java b/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java index 850196e6f2077..80aaf225edee5 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java @@ -29,7 +29,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.stream.Collectors; -import junit.framework.Assert; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; @@ -489,25 +488,25 @@ public void serializeAndDeserializeKeyData() { @Test public void basicCombingCharactersTest() { final KeyboardManager.CharacterCombiner combiner = new KeyboardManager.CharacterCombiner(); - Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); - Assert.assertEquals('A', (int) combiner.applyCombiningCharacterToBaseCharacter('A')); - Assert.assertEquals('B', (int) combiner.applyCombiningCharacterToBaseCharacter('B')); - Assert.assertEquals('B', (int) combiner.applyCombiningCharacterToBaseCharacter('B')); - Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); - Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); - - Assert.assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY)); - Assert.assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY)); - Assert.assertEquals('À', (int) combiner.applyCombiningCharacterToBaseCharacter('A')); - - Assert.assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY)); - Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); + assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); + assertEquals('B', (int) combiner.applyCombiningCharacterToBaseCharacter('B')); + assertEquals('B', (int) combiner.applyCombiningCharacterToBaseCharacter('B')); + assertEquals('A', (int) combiner.applyCombiningCharacterToBaseCharacter('A')); + assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); + assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); + + assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY)); + assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY)); + assertEquals('À', (int) combiner.applyCombiningCharacterToBaseCharacter('A')); + + assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY)); + assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); // The 0 input should remove the combining state. - Assert.assertEquals('A', (int) combiner.applyCombiningCharacterToBaseCharacter('A')); + assertEquals('A', (int) combiner.applyCombiningCharacterToBaseCharacter('A')); - Assert.assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); - Assert.assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY)); - Assert.assertEquals('À', (int) combiner.applyCombiningCharacterToBaseCharacter('A')); + assertEquals(0, (int) combiner.applyCombiningCharacterToBaseCharacter(0)); + assertEquals('`', (int) combiner.applyCombiningCharacterToBaseCharacter(DEAD_KEY)); + assertEquals('À', (int) combiner.applyCombiningCharacterToBaseCharacter('A')); } @Test diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index 9dfd58ddeaa4f..54ff2cf334372 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -2,8 +2,6 @@ import static android.os.Looper.getMainLooper; import static io.flutter.embedding.engine.systemchannels.PlatformViewsChannel.PlatformViewTouch; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; diff --git a/shell/platform/android/test/io/flutter/plugin/platform/SingleViewPresentationTest.java b/shell/platform/android/test/io/flutter/plugin/platform/SingleViewPresentationTest.java index 2cc177fd86648..fdeab2bc39229 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/SingleViewPresentationTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/SingleViewPresentationTest.java @@ -3,7 +3,7 @@ import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; import static android.os.Build.VERSION_CODES.P; import static android.os.Build.VERSION_CODES.R; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; From 5925883ee7809b131d1c24da5c255f3584ef1559 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 15:47:24 -0400 Subject: [PATCH 02/25] Annotate deprecated usages of Registrar --- .../plugins/shim/ShimPluginRegistryTest.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java b/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java index 18c9b5ae206a7..89c9c3729d8bf 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java @@ -15,7 +15,6 @@ import io.flutter.embedding.engine.plugins.PluginRegistry; import io.flutter.embedding.engine.plugins.activity.ActivityAware; import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; -import io.flutter.plugin.common.PluginRegistry.Registrar; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,11 +42,14 @@ public void setup() { when(mockActivityPluginBinding.getActivity()).thenReturn(mockActivity); } + @SuppressWarnings("deprecation") + // Test is intentionally verifying deprecated behavior. @Test public void itSuppliesOldAPIsViaTheNewFlutterPluginBinding() { ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine); + // Fully qualifed name because imports can not have deprecation supression. // This is the consumption side of the old plugins. - Registrar registrarUnderTest = registryUnderTest.registrarFor("test"); + io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest = registryUnderTest.registrarFor("test"); ArgumentCaptor shimAggregateCaptor = ArgumentCaptor.forClass(FlutterPlugin.class); @@ -65,11 +67,14 @@ public void itSuppliesOldAPIsViaTheNewFlutterPluginBinding() { verify(mockFlutterPluginBinding).getApplicationContext(); } + @SuppressWarnings("deprecation") + // Test is intentionally verifying deprecated behavior. @Test public void itSuppliesMultipleOldPlugins() { ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine); - Registrar registrarUnderTest1 = registryUnderTest.registrarFor("test1"); - Registrar registrarUnderTest2 = registryUnderTest.registrarFor("test2"); + // Fully qualifed name because imports can not have deprecation supression. + io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest1 = registryUnderTest.registrarFor("test1"); + io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest2 = registryUnderTest.registrarFor("test2"); ArgumentCaptor shimAggregateCaptor = ArgumentCaptor.forClass(FlutterPlugin.class); @@ -86,10 +91,12 @@ public void itSuppliesMultipleOldPlugins() { verify(mockFlutterPluginBinding, times(2)).getApplicationContext(); } + @SuppressWarnings("deprecation") + // Test is intentionally verifying deprecated behavior. @Test public void itCanOnlySupplyActivityBindingWhenUpstreamActivityIsAttached() { ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine); - Registrar registrarUnderTest = registryUnderTest.registrarFor("test"); + io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest = registryUnderTest.registrarFor("test"); ArgumentCaptor shimAggregateCaptor = ArgumentCaptor.forClass(FlutterPlugin.class); From b3ada3773a2e8554355c76161f65be1f74ea7a41 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 16:06:31 -0400 Subject: [PATCH 03/25] Suppress warnings for getSystemWindowInsets and ensure roboletric config consistant with targetApi lint annotation, bump itDescribesTextFieldsWithTextAndHint to 28 because test actually fails on api 26 --- .../flutter/view/AccessibilityBridgeTest.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java b/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java index 256ba35bc702a..28077a2c6877e 100644 --- a/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java +++ b/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java @@ -81,7 +81,8 @@ public void itDescribesNonTextFieldsWithAContentDescription() { assertEquals(nodeInfo.getText(), null); } - @TargetApi(26) + @Config(sdk = 28) + @TargetApi(28) @Test public void itDescribesTextFieldsWithTextAndHint() { AccessibilityBridge accessibilityBridge = setUpBridge(); @@ -322,6 +323,7 @@ public void itSetsTraversalAfter() { verify(mockNodeInfo2, times(1)).setTraversalAfter(eq(mockRootView), eq(1)); } + @Config(sdk = 24) @TargetApi(24) @Test public void itSetsRootViewNotImportantForAccessibility() { @@ -350,6 +352,7 @@ public void itSetsRootViewNotImportantForAccessibility() { verify(mockNodeInfo, times(1)).setImportantForAccessibility(eq(false)); } + @Config(sdk = 24) @TargetApi(24) @Test public void itSetsNodeImportantForAccessibilityIfItHasContent() { @@ -380,6 +383,7 @@ public void itSetsNodeImportantForAccessibilityIfItHasContent() { verify(mockNodeInfo, times(1)).setImportantForAccessibility(eq(true)); } + @Config(sdk = 24) @TargetApi(24) @Test public void itSetsNodeImportantForAccessibilityIfItHasActions() { @@ -410,6 +414,7 @@ public void itSetsNodeImportantForAccessibilityIfItHasActions() { verify(mockNodeInfo, times(1)).setImportantForAccessibility(eq(true)); } + @Config(sdk = 24) @TargetApi(24) @Test public void itSetsNodeUnImportantForAccessibilityIfItIsEmpty() { @@ -449,6 +454,9 @@ public void itSetsNodeUnImportantForAccessibilityIfItIsEmpty() { verify(mockNodeInfo1, times(1)).setImportantForAccessibility(eq(false)); } + @SuppressWarnings("deprecation") + // getSystemWindowInset* methods deprecated. + @Config(sdk = 28) @TargetApi(28) @Test public void itSetCutoutInsetBasedonLayoutModeNever() { @@ -498,6 +506,9 @@ public void itSetCutoutInsetBasedonLayoutModeNever() { new Rect(left + expectedInsetLeft, top, right + expectedInsetLeft, bottom)); } + @SuppressWarnings("deprecation") + // getSystemWindowInset* methods deprecated. + @Config(sdk = 28) @TargetApi(28) @Test public void itSetCutoutInsetBasedonLayoutModeDefault() { @@ -547,6 +558,9 @@ public void itSetCutoutInsetBasedonLayoutModeDefault() { new Rect(left + expectedInsetLeft, top, right + expectedInsetLeft, bottom)); } + @SuppressWarnings("deprecation") + // getSystemWindowInset* methods deprecated. + @Config(sdk = 28) @TargetApi(28) @Test public void itSetCutoutInsetBasedonLayoutModeShortEdges() { @@ -595,6 +609,10 @@ public void itSetCutoutInsetBasedonLayoutModeShortEdges() { verify(mockNodeInfo, times(1)).setBoundsInScreen(new Rect(left, top, right, bottom)); } + @SuppressWarnings("deprecation") + // getSystemWindowInset* methods deprecated. + // fluter#133074 tracks post deprecation work. + @Config(sdk = 30) @TargetApi(30) @Test public void itSetCutoutInsetBasedonLayoutModeAlways() { @@ -840,6 +858,7 @@ public void itAnnouncesRouteNameWhenRemoveARoute() { verify(mockRootView, times(1)).setAccessibilityPaneTitle(eq("new_node2")); } + @Config(sdk = 21) @TargetApi(21) @Test public void itCanPerformSetText() { @@ -879,6 +898,7 @@ public void itCanPerformSetText() { .dispatchSemanticsAction(1, AccessibilityBridge.Action.SET_TEXT, expectedText); } + @Config(sdk = 21) @TargetApi(21) @Test public void itCanPredictSetText() { @@ -918,6 +938,7 @@ public void itCanPredictSetText() { assertEquals(nodeInfo.getText().toString(), expectedText); } + @Config(sdk = 21) @TargetApi(21) @Test public void itBuildsAttributedString() { @@ -984,6 +1005,7 @@ public void itBuildsAttributedString() { assertEquals(actual.getSpanEnd(spellOutSpan), 9); } + @Config(sdk = 21) @TargetApi(21) @Test public void itSetsTextCorrectly() { @@ -1043,6 +1065,7 @@ public void itSetsTextCorrectly() { assertEquals(objectSpans.length, 0); } + @Config(sdk = 28) @TargetApi(28) @Test public void itSetsTooltipCorrectly() { @@ -1080,6 +1103,7 @@ public void itSetsTooltipCorrectly() { assertEquals(actual.toString(), root.tooltip); } + @Config(sdk = 21) @TargetApi(21) @Test public void itCanCreateAccessibilityNodeInfoWithSetText() { @@ -1255,6 +1279,7 @@ public void itSetsFocusabilityBasedOnFlagsCorrectly() { assertTrue(node2Info.isFocusable()); } + @Config(sdk = 31) @TargetApi(31) @Test public void itSetsBoldTextFlagCorrectly() { From 1f2bc15a96ec033898fb2296bc26177ab1fac935 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 16:15:19 -0400 Subject: [PATCH 04/25] Suppress warnings for DartExecutor.send --- .../editing/InputConnectionAdaptorTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java index 93f92c182e0c2..3972f2521bdbe 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java @@ -185,6 +185,8 @@ public void testPerformContextMenuAction_paste() { assertTrue(editable.toString().startsWith(textToBePasted)); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testCommitContent() throws JSONException { View testView = new View(ctx); @@ -244,6 +246,8 @@ public void testCommitContent() throws JSONException { }); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsNull() throws JSONException { View testView = new View(ctx); @@ -273,6 +277,8 @@ public void testPerformPrivateCommand_dataIsNull() throws JSONException { new String[] {"0", "{\"action\":\"actionCommand\"}"}); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsByteArray() throws JSONException { View testView = new View(ctx); @@ -308,6 +314,8 @@ public void testPerformPrivateCommand_dataIsByteArray() throws JSONException { }); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsByte() throws JSONException { View testView = new View(ctx); @@ -341,6 +349,8 @@ public void testPerformPrivateCommand_dataIsByte() throws JSONException { new String[] {"0", "{\"data\":{\"keyboard_layout\":3},\"action\":\"actionCommand\"}"}); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsCharArray() throws JSONException { View testView = new View(ctx); @@ -377,6 +387,8 @@ public void testPerformPrivateCommand_dataIsCharArray() throws JSONException { }); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsChar() throws JSONException { View testView = new View(ctx); @@ -410,6 +422,8 @@ public void testPerformPrivateCommand_dataIsChar() throws JSONException { new String[] {"0", "{\"data\":{\"keyboard_layout\":\"a\"},\"action\":\"actionCommand\"}"}); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsCharSequenceArray() throws JSONException { View testView = new View(ctx); @@ -447,6 +461,8 @@ public void testPerformPrivateCommand_dataIsCharSequenceArray() throws JSONExcep }); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsCharSequence() throws JSONException { View testView = new View(ctx); @@ -482,6 +498,8 @@ public void testPerformPrivateCommand_dataIsCharSequence() throws JSONException }); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsFloat() throws JSONException { View testView = new View(ctx); @@ -515,6 +533,8 @@ public void testPerformPrivateCommand_dataIsFloat() throws JSONException { new String[] {"0", "{\"data\":{\"keyboard_layout\":0.5},\"action\":\"actionCommand\"}"}); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void testPerformPrivateCommand_dataIsFloatArray() throws JSONException { View testView = new View(ctx); From 0d3b2b0a7b77eac91852476f740ada5d5dc38ade Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 16:21:18 -0400 Subject: [PATCH 05/25] Suppress warnings for ClipboardManager.set/hasText --- .../flutter/plugin/editing/InputConnectionAdaptorTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java index 3972f2521bdbe..9d93a2acd573d 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java @@ -135,6 +135,8 @@ public void testPerformContextMenuAction_selectAll() { assertEquals(editable.length(), Selection.getSelectionEnd(editable)); } + @SuppressWarnings("deprecation") + // ClipboardManager.hasText is deprecated. @Test public void testPerformContextMenuAction_cut() { ClipboardManager clipboardManager = ctx.getSystemService(ClipboardManager.class); @@ -152,6 +154,8 @@ public void testPerformContextMenuAction_cut() { assertFalse(editable.toString().contains(textToBeCut)); } + @SuppressWarnings("deprecation") + // ClipboardManager.hasText is deprecated. @Test public void testPerformContextMenuAction_copy() { ClipboardManager clipboardManager = ctx.getSystemService(ClipboardManager.class); @@ -171,6 +175,8 @@ public void testPerformContextMenuAction_copy() { clipboardManager.getPrimaryClip().getItemAt(0).getText()); } + @SuppressWarnings("deprecation") + // ClipboardManager.setText is deprecated. @Test public void testPerformContextMenuAction_paste() { ClipboardManager clipboardManager = ctx.getSystemService(ClipboardManager.class); From 9f2b58809922108ce41d6c69946b9513d660b03d Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 16:40:00 -0400 Subject: [PATCH 06/25] Suppress warnings for getWindowSystemUiVisibility, setMessageHandler, DartExecutor.send, InputMethodSubtype, and proof of concept migration from Roboletric.setupActivity --- .../plugin/editing/TextInputPluginTest.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index d049f171a3dfb..7dd0be1da5720 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -43,6 +43,7 @@ import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; +import androidx.test.core.app.ActivityScenario; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import io.flutter.embedding.android.FlutterView; @@ -118,6 +119,8 @@ private static void sendToBinaryMessageHandler( (ByteBuffer) encodedMethodCall.flip(), mock(BinaryMessenger.BinaryReply.class)); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void textInputPlugin_RequestsReattachOnCreation() throws JSONException { // Initialize a general TextInputPlugin. @@ -992,6 +995,7 @@ public void setTextInputEditingState_alwaysSetEditableWhenDifferent() { // need the restart. // Update: many other keyboards need this too: // https://github.com/flutter/flutter/issues/78827 + @SuppressWarnings("deprecation") // InputMethodSubtype @Test public void setTextInputEditingState_restartsIMEOnlyWhenFrameworkChangesComposingRegion() { // Initialize a TextInputPlugin that needs to be always restarted. @@ -1136,6 +1140,8 @@ public void destroy_clearTextInputMethodHandler() { verify(textInputChannel, times(1)).setTextInputMethodHandler(isNull()); } + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. @Test public void inputConnection_createsActionFromEnter() throws JSONException { TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE)); @@ -1192,6 +1198,7 @@ public void inputConnection_createsActionFromEnter() throws JSONException { new String[] {"0", "TextInputAction.done"}); } + @SuppressWarnings("deprecation") // InputMethodSubtype @Test public void inputConnection_finishComposingTextUpdatesIMM() throws JSONException { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { @@ -1446,8 +1453,10 @@ public void autofill_onProvideVirtualViewStructure() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; } + try(ActivityScenario scenario = ActivityScenario.launch(Activity.class)) { + scenario.onActivity(activity -> { - FlutterView testView = new FlutterView(Robolectric.setupActivity(Activity.class)); + FlutterView testView = new FlutterView(activity); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); @@ -1529,6 +1538,9 @@ public void autofill_onProvideVirtualViewStructure() { verify(children[1]).setAutofillHints(aryEq(new String[] {"HINT2", "EXTRA"})); verify(children[1]).setDimens(anyInt(), anyInt(), anyInt(), anyInt(), gt(0), gt(0)); verify(children[1], times(0)).setHint(any()); + + }); + } } @Test @@ -1939,6 +1951,8 @@ public void autofill_testSetTextIpnutClientUpdatesSideFields() { } // -------- End: Autofill Tests ------- + @SuppressWarnings("deprecation") + // setMessageHandler is deprecated. @Test public void respondsToInputChannelMessages() { ArgumentCaptor binaryMessageHandlerCaptor = @@ -1966,6 +1980,8 @@ public void respondsToInputChannelMessages() { verify(mockHandler, times(1)).finishAutofillContext(false); } + @SuppressWarnings("deprecation") + // setMessageHandler is deprecated. @Test public void sendAppPrivateCommand_dataIsEmpty() throws JSONException { ArgumentCaptor binaryMessageHandlerCaptor = @@ -1995,6 +2011,8 @@ public void sendAppPrivateCommand_dataIsEmpty() throws JSONException { .sendAppPrivateCommand(any(View.class), eq("actionCommand"), eq(null)); } + @SuppressWarnings("deprecation") + // setMessageHandler is deprecated. @Test public void sendAppPrivateCommand_hasData() throws JSONException { ArgumentCaptor binaryMessageHandlerCaptor = @@ -2029,6 +2047,9 @@ public void sendAppPrivateCommand_hasData() throws JSONException { @Test @TargetApi(30) @Config(sdk = 30) + @SuppressWarnings("deprecation") + // getWindowSystemUiVisibility and SYSTEM_UI_FLAG_LAYOUT_STABLE are deprecated + // flutter#133074 tracks migration work. public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBars() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); when(testView.getWindowSystemUiVisibility()).thenReturn(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); @@ -2105,6 +2126,8 @@ public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBa @Test @TargetApi(30) @Config(sdk = 30) + @SuppressWarnings("deprecation") + // getWindowSystemUiVisibility is deprecated flutter#133074 tracks migration work. public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); when(testView.getWindowSystemUiVisibility()) @@ -2183,6 +2206,9 @@ public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars( @Test @TargetApi(30) @Config(sdk = 30) + @SuppressWarnings("deprecation") + // getWindowSystemUiVisibility and SYSTEM_UI_FLAG_LAYOUT_STABLE are deprecated + // flutter#133074 tracks migration work. public void lastWindowInsets_updatedOnSecondOnProgressCall() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); when(testView.getWindowSystemUiVisibility()).thenReturn(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); From 86eb9553a0b7a13c408eac2016fa3b12865c179b Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:17:54 -0400 Subject: [PATCH 07/25] Suppress deprecation warnings, set minsdk on tests that were checking for sdk version --- .../plugin/editing/TextInputPluginTest.java | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 7dd0be1da5720..95dccf030ed45 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -1448,15 +1448,16 @@ public void autofill_hintText() { verify(children[0]).setHint("placeholder"); } + @Config(minSdk = Build.VERSION_CODES.O) + @SuppressWarnings("deprecation") + // Robolectric.setupActivity. @Test public void autofill_onProvideVirtualViewStructure() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; } - try(ActivityScenario scenario = ActivityScenario.launch(Activity.class)) { - scenario.onActivity(activity -> { - - FlutterView testView = new FlutterView(activity); + // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 + FlutterView testView = new FlutterView(Robolectric.setupActivity(Activity.class)); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); @@ -1538,17 +1539,17 @@ public void autofill_onProvideVirtualViewStructure() { verify(children[1]).setAutofillHints(aryEq(new String[] {"HINT2", "EXTRA"})); verify(children[1]).setDimens(anyInt(), anyInt(), anyInt(), anyInt(), gt(0), gt(0)); verify(children[1], times(0)).setHint(any()); - - }); - } } + @SuppressWarnings("deprecation") + // Robolectric.setupActivity. + @Config(minSdk = Build.VERSION_CODES.O) @Test public void autofill_onProvideVirtualViewStructure_singular_textfield() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; } - + // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 FlutterView testView = new FlutterView(Robolectric.setupActivity(Activity.class)); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = @@ -1594,6 +1595,9 @@ public void autofill_onProvideVirtualViewStructure_singular_textfield() { verify(children[0]).setDimens(anyInt(), anyInt(), anyInt(), anyInt(), gt(0), gt(0)); } + @Config(minSdk = Build.VERSION_CODES.O) + @SuppressWarnings("deprecation") + // Robolectric.setupActivity. @Test public void autofill_testLifeCycle() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1728,6 +1732,9 @@ public void autofill_testLifeCycle() { assertEquals("1".hashCode(), testAfm.exitId); } + @Config(minSdk = Build.VERSION_CODES.O) + @SuppressWarnings("deprecation") + // Robolectric.setupActivity. @Test public void autofill_testAutofillUpdatesTheFramework() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1824,6 +1831,7 @@ public void autofill_testAutofillUpdatesTheFramework() { assertEquals(editState.text, "unfocused field"); } + @Config(minSdk = Build.VERSION_CODES.O) @Test public void autofill_doesNotCrashAfterClearClientCall() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1872,6 +1880,9 @@ public void autofill_doesNotCrashAfterClearClientCall() { .updateEditingState(anyInt(), any(), anyInt(), anyInt(), anyInt(), anyInt()); } + @Config(minSdk = Build.VERSION_CODES.O) + @SuppressWarnings("deprecation") + // Robolectric.setupActivity. @Test public void autofill_testSetTextIpnutClientUpdatesSideFields() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -2048,7 +2059,7 @@ public void sendAppPrivateCommand_hasData() throws JSONException { @TargetApi(30) @Config(sdk = 30) @SuppressWarnings("deprecation") - // getWindowSystemUiVisibility and SYSTEM_UI_FLAG_LAYOUT_STABLE are deprecated + // getWindowSystemUiVisibility, SYSTEM_UI_FLAG_LAYOUT_STABLE, Robolectric.setupActivity. // flutter#133074 tracks migration work. public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBars() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); @@ -2127,7 +2138,8 @@ public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBa @TargetApi(30) @Config(sdk = 30) @SuppressWarnings("deprecation") - // getWindowSystemUiVisibility is deprecated flutter#133074 tracks migration work. + // getWindowSystemUiVisibility, Robolectric.setupActivity. + // flutter#133074 tracks migration work. public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); when(testView.getWindowSystemUiVisibility()) @@ -2207,7 +2219,7 @@ public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars( @TargetApi(30) @Config(sdk = 30) @SuppressWarnings("deprecation") - // getWindowSystemUiVisibility and SYSTEM_UI_FLAG_LAYOUT_STABLE are deprecated + // getWindowSystemUiVisibility, SYSTEM_UI_FLAG_LAYOUT_STABLE, Robolectric.setupActivity. // flutter#133074 tracks migration work. public void lastWindowInsets_updatedOnSecondOnProgressCall() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); From 8a482fca4c5d008323a6a8c0f3488ea4a3b5c2d2 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:20:07 -0400 Subject: [PATCH 08/25] Suppress deprecation warnings in SpellCheckPluginTest --- .../test/io/flutter/plugin/editing/SpellCheckPluginTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java index f5c1a6fb6ee23..fd291b291ada0 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/SpellCheckPluginTest.java @@ -44,6 +44,8 @@ private static void sendToBinaryMessageHandler( (ByteBuffer) encodedMethodCall.flip(), mock(BinaryMessenger.BinaryReply.class)); } + @SuppressWarnings("deprecation") + // setMessageHandler is deprecated. @Test public void respondsToSpellCheckChannelMessage() { ArgumentCaptor binaryMessageHandlerCaptor = From fb7272deb776b38a22d42c51b274b60f5160db46 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:23:42 -0400 Subject: [PATCH 09/25] Suppress deprecation warnings in MouseCursorPluginTest, set minsdk config to match target api --- .../test/io/flutter/plugin/mouse/MouseCursorPluginTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shell/platform/android/test/io/flutter/plugin/mouse/MouseCursorPluginTest.java b/shell/platform/android/test/io/flutter/plugin/mouse/MouseCursorPluginTest.java index 26db240c88180..17b659c2ebd8d 100644 --- a/shell/platform/android/test/io/flutter/plugin/mouse/MouseCursorPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/mouse/MouseCursorPluginTest.java @@ -25,12 +25,17 @@ @Config( manifest = Config.NONE, + minSdk = 24, shadows = {}) @RunWith(AndroidJUnit4.class) @TargetApi(24) public class MouseCursorPluginTest { + + @SuppressWarnings("deprecation") + // Robolectric.setupActivity. @Test public void mouseCursorPlugin_SetsSystemCursorOnRequest() throws JSONException { + // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 // Initialize a general MouseCursorPlugin. FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); MouseCursorChannel mouseCursorChannel = new MouseCursorChannel(mock(DartExecutor.class)); From 90f6ce04b90564bea95cceea8410c9489f63e973 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:29:16 -0400 Subject: [PATCH 10/25] Stop calling RuntimeEnvrionment.application and insted a call ApplicationProvider.getApplicationContext() in SingleViewPresentationTest --- .../flutter/plugin/platform/SingleViewPresentationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/test/io/flutter/plugin/platform/SingleViewPresentationTest.java b/shell/platform/android/test/io/flutter/plugin/platform/SingleViewPresentationTest.java index fdeab2bc39229..20e6bb3b4731c 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/SingleViewPresentationTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/SingleViewPresentationTest.java @@ -13,10 +13,10 @@ import android.hardware.display.DisplayManager; import android.view.Display; import android.view.inputmethod.InputMethodManager; +import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @Config(manifest = Config.NONE) @@ -38,7 +38,7 @@ public void returnsOuterContextInputMethodManager() { // system service instead of the spy's and fails. // Create an SVP under test with a Context that returns a local IMM mock. - Context context = spy(RuntimeEnvironment.application); + Context context = spy(ApplicationProvider.getApplicationContext()); InputMethodManager expected = mock(InputMethodManager.class); when(context.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(expected); DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); @@ -60,7 +60,7 @@ public void returnsOuterContextInputMethodManager_createDisplayContext() { // The IMM should also persist across display contexts created from the base context. // Create an SVP under test with a Context that returns a local IMM mock. - Context context = spy(RuntimeEnvironment.application); + Context context = spy(ApplicationProvider.getApplicationContext()); InputMethodManager expected = mock(InputMethodManager.class); when(context.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(expected); Display display = From d32d874fe070c6827758b3b4a1417531deae15b6 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:33:25 -0400 Subject: [PATCH 11/25] Start calling FlutterView(Context, FlutterSurfaceView) --- .../flutter/plugin/platform/PlatformViewsControllerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index 54ff2cf334372..880f2a707833b 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -25,6 +25,7 @@ import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import io.flutter.embedding.android.FlutterImageView; +import io.flutter.embedding.android.FlutterSurfaceView; import io.flutter.embedding.android.FlutterView; import io.flutter.embedding.android.MotionEventTracker; import io.flutter.embedding.android.RenderMode; @@ -1521,7 +1522,7 @@ private static FlutterView attach( FlutterJNI jni, PlatformViewsController platformViewsController) { final Context context = ApplicationProvider.getApplicationContext(); final FlutterView flutterView = - new FlutterView(context, RenderMode.surface) { + new FlutterView(context, new FlutterSurfaceView(context)) { @Override public FlutterImageView createImageView() { final FlutterImageView view = mock(FlutterImageView.class); From 7c656227783f2b74afd571f11a77ce7069ace3cc Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:42:33 -0400 Subject: [PATCH 12/25] Suppress deprecation warnings in PlatformPluginTest, getText, Robolectric.setup/buildActivity, system ui flags --- .../plugin/platform/PlatformPluginTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java index 8b27e80fd4264..89b232aa0e9f7 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -94,6 +94,8 @@ public void platformPlugin_getClipboardData() throws IOException { assertNull(platformPlugin.mPlatformMessageHandler.getClipboardData(clipboardFormat)); } + @SuppressWarnings("deprecation") + // ClipboardManager.getText @Config(sdk = 28) @Test public void platformPlugin_hasStrings() { @@ -315,6 +317,8 @@ public void setStatusBarIconBrightness() { } } + @SuppressWarnings("deprecation") + // SYSTEM_UI_FLAG_*, setSystemUiVisibility @Config(sdk = 29) @Test public void setSystemUiMode() { @@ -371,8 +375,11 @@ public void setSystemUiMode() { } } + @SuppressWarnings("deprecation") + // Robolectric.buildActivity. @Test public void setSystemUiModeListener_overlaysAreHidden() { + // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 ActivityController controller = Robolectric.buildActivity(Activity.class); controller.setup(); Activity fakeActivity = controller.get(); @@ -400,8 +407,11 @@ public void setSystemUiModeListener_overlaysAreHidden() { verify(fakePlatformChannel).systemChromeChanged(false); } + @SuppressWarnings("deprecation") + // Robolectric.buildActivity. @Test public void setSystemUiModeListener_overlaysAreVisible() { + // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 ActivityController controller = Robolectric.buildActivity(Activity.class); controller.setup(); Activity fakeActivity = controller.get(); @@ -426,6 +436,8 @@ public void setSystemUiModeListener_overlaysAreVisible() { verify(fakePlatformChannel).systemChromeChanged(true); } + @SuppressWarnings("deprecation") + // SYSTEM_UI_FLAG_*, setSystemUiVisibility @Config(sdk = 28) @Test public void doNotEnableEdgeToEdgeOnOlderSdk() { @@ -446,6 +458,8 @@ public void doNotEnableEdgeToEdgeOnOlderSdk() { | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } + @SuppressWarnings("deprecation") + // FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_NAVIGATION @Config(sdk = 29) @Test public void verifyWindowFlagsSetToStyleOverlays() { @@ -513,8 +527,12 @@ public void doesNotDoAnythingByDefaultIfPopSystemNavigatorOverridden() { verify(mockActivity, never()).finish(); } + + @SuppressWarnings("deprecation") + // Robolectric.setupActivity. @Test public void popSystemNavigatorFlutterFragment() { + // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 FragmentActivity activity = spy(Robolectric.setupActivity(FragmentActivity.class)); final AtomicBoolean onBackPressedCalled = new AtomicBoolean(false); OnBackPressedCallback backCallback = @@ -539,8 +557,11 @@ public void handleOnBackPressed() { assertTrue(onBackPressedCalled.get()); } + @SuppressWarnings("deprecation") + // Robolectric.setupActivity. @Test public void doesNotDoAnythingByDefaultIfFragmentPopSystemNavigatorOverridden() { + // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 FragmentActivity activity = spy(Robolectric.setupActivity(FragmentActivity.class)); PlatformChannel mockPlatformChannel = mock(PlatformChannel.class); PlatformPluginDelegate mockPlatformPluginDelegate = mock(PlatformPluginDelegate.class); From 3ba9a9838fdafd20cd7500ff0834eba39f436a53 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:46:25 -0400 Subject: [PATCH 13/25] Suppress deprecation warnings in PlayStoreDeferredComponentManagerTest --- .../PlayStoreDeferredComponentManagerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java b/shell/platform/android/test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java index d1af9fb59fd83..7bfb7e4d4888c 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java @@ -82,7 +82,8 @@ public void installDeferredComponent(int loadingUnitId, String componentName) { loadDartLibrary(loadingUnitId, componentName); } } - + @SuppressWarnings("deprecation") + // getApplicationInfo private Context createSpyContext(Bundle metadata) throws NameNotFoundException { Context spyContext = spy(ApplicationProvider.getApplicationContext()); doReturn(spyContext).when(spyContext).createPackageContext(any(), anyInt()); From 488c707ec1b126c31956f34a2f2783db31e99a68 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:50:21 -0400 Subject: [PATCH 14/25] Suppress deprecation warnings in KeyboardChannelTest --- .../embedding/engine/systemchannels/KeyboardChannelTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/KeyboardChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/KeyboardChannelTest.java index 96766a31b11c8..d0c436011e14d 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/KeyboardChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/KeyboardChannelTest.java @@ -32,6 +32,8 @@ private static BinaryMessenger.BinaryReply sendToBinaryMessageHandler( return reply; } + @SuppressWarnings("deprecation") + // setMessageHandler is deprecated. @Test public void respondsToGetKeyboardStateChannelMessage() { ArgumentCaptor binaryMessageHandlerCaptor = From 78d6b79a84b5593511c5b23e7a0d7aa23f02f14f Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:52:36 -0400 Subject: [PATCH 15/25] Suppress deprecation warnings in SettingsChannelTest --- .../embedding/engine/systemchannels/SettingsChannelTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/SettingsChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/SettingsChannelTest.java index a4a25ec597dfd..50c40e609ed06 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/SettingsChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/SettingsChannelTest.java @@ -23,6 +23,8 @@ public class SettingsChannelTest { @Test @TargetApi(33) @Config(sdk = 33) + @SuppressWarnings("deprecation") + // DartExecutor.send is deprecated. public void setDisplayMetricsDoesNothingOnAPILevel33() { final DartExecutor executor = mock(DartExecutor.class); executor.onAttachedToJNI(); From 0c14a63276177f1cfa81fae98d630660b410882a Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:54:04 -0400 Subject: [PATCH 16/25] Suppress deprecation warnings in ApplicationInfoLoaderTest --- .../embedding/engine/loader/ApplicationInfoLoaderTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/loader/ApplicationInfoLoaderTest.java b/shell/platform/android/test/io/flutter/embedding/engine/loader/ApplicationInfoLoaderTest.java index e616eb627f6ac..6a9e4424f3182 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/loader/ApplicationInfoLoaderTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/loader/ApplicationInfoLoaderTest.java @@ -48,6 +48,8 @@ public void itGeneratesCorrectApplicationInfoWithDefaultManifest() { assertNull(info.nativeLibraryDir); } + @SuppressWarnings("deprecation") + // getApplicationInfo private Context generateMockContext(Bundle metadata, String networkPolicyXml) throws Exception { Context context = mock(Context.class); PackageManager packageManager = mock(PackageManager.class); From 7eb6b0181e466add2c9678fa01cd22410d9f712d Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 17:57:39 -0400 Subject: [PATCH 17/25] Stop calling RuntimeEnvrionment.application and insted a call ApplicationProvider.getApplicationContext() in FlutterEngineGroupCacheTest --- .../embedding/engine/FlutterEngineGroupCacheTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupCacheTest.java b/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupCacheTest.java index 55802f6cecd74..80325695900bd 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupCacheTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupCacheTest.java @@ -7,13 +7,13 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import androidx.test.core.app.ApplicationProvider; import io.flutter.FlutterInjector; import io.flutter.embedding.engine.loader.FlutterLoader; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @Config(manifest = Config.NONE) @@ -75,8 +75,8 @@ public void itRemovesFlutterEngineGroups() { @Test public void itRemovesAllFlutterEngineGroups() { // --- Test Setup --- - FlutterEngineGroup flutterEngineGroup1 = new FlutterEngineGroup(RuntimeEnvironment.application); - FlutterEngineGroup flutterEngineGroup2 = new FlutterEngineGroup(RuntimeEnvironment.application); + FlutterEngineGroup flutterEngineGroup1 = new FlutterEngineGroup(ApplicationProvider.getApplicationContext()); + FlutterEngineGroup flutterEngineGroup2 = new FlutterEngineGroup(ApplicationProvider.getApplicationContext()); FlutterEngineGroupCache cache = new FlutterEngineGroupCache(); // --- Execute Test --- From e58f957d47c0a175a463a5169077126397198e00 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 18:00:09 -0400 Subject: [PATCH 18/25] Suppress deprecation warnings in FlutterAndroidComponentTest --- .../embedding/android/FlutterAndroidComponentTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java index 64cf15d0404d2..e49e73f13e62d 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java @@ -207,6 +207,8 @@ public void normalLifecycleStepsDoNotTriggerADetachFromFlutterEngine() { verify(delegate, never()).detachFromFlutterEngine(); } + @SuppressWarnings("deprecation") + // Robolectric.buildActivity @Test public void twoOverlappingFlutterActivitiesDoNotCrosstalk() { // ---- Test setup ---- @@ -265,6 +267,9 @@ public Context getContext() { return ApplicationProvider.getApplicationContext(); } + + @SuppressWarnings("deprecation") + // Robolectric.setupActivity @Nullable @Override public Activity getActivity() { From fb86f96fbd48bcf52baa91bc7ffd79583f3e3757 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 18:02:46 -0400 Subject: [PATCH 19/25] Suppress deprecation warnings in FlutterFragmentTest, more robolectric setup activity calls --- .../io/flutter/embedding/android/FlutterFragmentTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java index 3fb89f9376e72..af9b2f6829b5f 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java @@ -283,6 +283,8 @@ public void itReturnsExclusiveAppComponent() { assertEquals(fragment.getExclusiveAppComponent(), delegate); } + @SuppressWarnings("deprecation") + // Robolectric.setupActivity @Test public void itDelegatesOnBackPressedAutomaticallyWhenEnabled() { // We need to mock FlutterJNI to avoid triggering native code. @@ -317,6 +319,8 @@ public void itDelegatesOnBackPressedAutomaticallyWhenEnabled() { verify(mockDelegate, times(1)).onBackPressed(); } + @SuppressWarnings("deprecation") + // Robolectric.setupActivity @Test public void itHandlesPopSystemNavigationAutomaticallyWhenEnabled() { // We need to mock FlutterJNI to avoid triggering native code. From e987bc2fd9ffe4b14f816decc462e6263c5bb513 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 18:04:50 -0400 Subject: [PATCH 20/25] Suppress deprecation warnings in FlutterActivityAndFragmentDelegateTest --- .../android/FlutterActivityAndFragmentDelegateTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index 9ce5f8c91331f..dda31e6fe2428 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -66,6 +66,8 @@ public class FlutterActivityAndFragmentDelegateTest { private FlutterEngine mockFlutterEngine; private FlutterActivityAndFragmentDelegate.Host mockHost; + @SuppressWarnings("deprecation") + // Robolectric.setupActivity @Before public void setup() { FlutterInjector.reset(); @@ -402,6 +404,8 @@ public void itGivesHostAnOpportunityToConfigureFlutterSurfaceView() { verify(mockHost, times(1)).onFlutterSurfaceViewCreated(isNotNull()); } + @SuppressWarnings("deprecation") + // Robolectric.setupActivity @Test public void itGivesHostAnOpportunityToConfigureFlutterTextureView() { // ---- Test setup ---- From 86d08f5f75e7867e15419b2c82f64a1679f6a896 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 18:22:36 -0400 Subject: [PATCH 21/25] Shadow.directlyOn is incompatible with java 17+, refactor to use reflectors and direct following https://github.com/robolectric/robolectric/pull/6598/files as an example Unsure if SplashShadowResources is used anywhere --- .../embedding/android/SplashShadowResources.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java b/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java index f02646c8ed768..0faaa999d970f 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java +++ b/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java @@ -1,5 +1,7 @@ package io.flutter.embedding.android; +import static org.robolectric.util.reflector.Reflector.reflector; + import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; @@ -10,6 +12,8 @@ import org.robolectric.annotation.RealObject; import org.robolectric.shadow.api.Shadow; import org.robolectric.shadows.ShadowResources; +import org.robolectric.util.reflector.Direct; +import org.robolectric.util.reflector.ForType; @Implements(Resources.class) public class SplashShadowResources extends ShadowResources { @@ -17,13 +21,21 @@ public class SplashShadowResources extends ShadowResources { public static final int SPLASH_DRAWABLE_ID = 191919; public static final int THEMED_SPLASH_DRAWABLE_ID = 212121; + @ForType(Resources.class) + interface ResourcesReflector { + @Direct + Drawable getDrawable(int id, Resources.Theme theme); + + @Direct + Drawable getDrawable(int id); + } @Implementation protected Drawable getDrawable(int id) { if (id == SPLASH_DRAWABLE_ID) { return new ColorDrawable(Color.BLUE); } - return Shadow.directlyOn(resources, Resources.class).getDrawable(id); + return reflector(Resources.class, resources).getDrawable(id); } @Implementation @@ -37,6 +49,6 @@ protected Drawable getDrawable(int id, @Nullable Resources.Theme theme) { } return new ColorDrawable(Color.GRAY); } - return Shadow.directlyOn(resources, Resources.class).getDrawable(id, theme); + return reflector(Resources.class, resources).getDrawable(id, theme); } } From 81cd095679366dcffc8312425606142df53353d0 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 18:28:46 -0400 Subject: [PATCH 22/25] Enable warnings as errors --- .../io/flutter/embedding/android/SplashShadowResources.java | 2 ++ shell/platform/android/test_runner/build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java b/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java index 0faaa999d970f..5007453badc0e 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java +++ b/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java @@ -15,6 +15,8 @@ import org.robolectric.util.reflector.Direct; import org.robolectric.util.reflector.ForType; +@SuppressWarnings("deprecation") +// getDrawableInt @Implements(Resources.class) public class SplashShadowResources extends ShadowResources { @RealObject private Resources resources; diff --git a/shell/platform/android/test_runner/build.gradle b/shell/platform/android/test_runner/build.gradle index 5fd37ad3edb6f..97a5af893f3d1 100644 --- a/shell/platform/android/test_runner/build.gradle +++ b/shell/platform/android/test_runner/build.gradle @@ -22,7 +22,7 @@ rootProject.buildDir = project.property("build_dir") // 434 (at the time of this comment) deprecations are fixed. gradle.projectsEvaluated { tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:deprecation" << "-Xmaxwarns" << "434" + options.compilerArgs << "-Xlint:deprecation" << "-Werror" << "-Xmaxwarns" << "434" } } From 6142bf2eee3b29ca077fe6dddeabeeac7a2f1a1b Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Tue, 22 Aug 2023 18:32:43 -0400 Subject: [PATCH 23/25] Formatting --- .../android/FlutterAndroidComponentTest.java | 1 - .../embedding/android/SplashShadowResources.java | 2 +- .../engine/FlutterEngineGroupCacheTest.java | 6 ++++-- .../PlayStoreDeferredComponentManagerTest.java | 1 + .../engine/plugins/shim/ShimPluginRegistryTest.java | 12 ++++++++---- .../flutter/plugin/editing/TextInputPluginTest.java | 1 - .../flutter/plugin/platform/PlatformPluginTest.java | 1 - .../plugin/platform/PlatformViewsControllerTest.java | 1 - 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java index e49e73f13e62d..70190c31ef751 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java @@ -267,7 +267,6 @@ public Context getContext() { return ApplicationProvider.getApplicationContext(); } - @SuppressWarnings("deprecation") // Robolectric.setupActivity @Nullable diff --git a/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java b/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java index 5007453badc0e..7c0bd96fec856 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java +++ b/shell/platform/android/test/io/flutter/embedding/android/SplashShadowResources.java @@ -10,7 +10,6 @@ import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.annotation.RealObject; -import org.robolectric.shadow.api.Shadow; import org.robolectric.shadows.ShadowResources; import org.robolectric.util.reflector.Direct; import org.robolectric.util.reflector.ForType; @@ -23,6 +22,7 @@ public class SplashShadowResources extends ShadowResources { public static final int SPLASH_DRAWABLE_ID = 191919; public static final int THEMED_SPLASH_DRAWABLE_ID = 212121; + @ForType(Resources.class) interface ResourcesReflector { @Direct diff --git a/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupCacheTest.java b/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupCacheTest.java index 80325695900bd..efd8edc81649d 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupCacheTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/FlutterEngineGroupCacheTest.java @@ -75,8 +75,10 @@ public void itRemovesFlutterEngineGroups() { @Test public void itRemovesAllFlutterEngineGroups() { // --- Test Setup --- - FlutterEngineGroup flutterEngineGroup1 = new FlutterEngineGroup(ApplicationProvider.getApplicationContext()); - FlutterEngineGroup flutterEngineGroup2 = new FlutterEngineGroup(ApplicationProvider.getApplicationContext()); + FlutterEngineGroup flutterEngineGroup1 = + new FlutterEngineGroup(ApplicationProvider.getApplicationContext()); + FlutterEngineGroup flutterEngineGroup2 = + new FlutterEngineGroup(ApplicationProvider.getApplicationContext()); FlutterEngineGroupCache cache = new FlutterEngineGroupCache(); // --- Execute Test --- diff --git a/shell/platform/android/test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java b/shell/platform/android/test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java index 7bfb7e4d4888c..e221afbe011d7 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java @@ -82,6 +82,7 @@ public void installDeferredComponent(int loadingUnitId, String componentName) { loadDartLibrary(loadingUnitId, componentName); } } + @SuppressWarnings("deprecation") // getApplicationInfo private Context createSpyContext(Bundle metadata) throws NameNotFoundException { diff --git a/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java b/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java index 89c9c3729d8bf..95aad07402f12 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java @@ -49,7 +49,8 @@ public void itSuppliesOldAPIsViaTheNewFlutterPluginBinding() { ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine); // Fully qualifed name because imports can not have deprecation supression. // This is the consumption side of the old plugins. - io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest = registryUnderTest.registrarFor("test"); + io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest = + registryUnderTest.registrarFor("test"); ArgumentCaptor shimAggregateCaptor = ArgumentCaptor.forClass(FlutterPlugin.class); @@ -73,8 +74,10 @@ public void itSuppliesOldAPIsViaTheNewFlutterPluginBinding() { public void itSuppliesMultipleOldPlugins() { ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine); // Fully qualifed name because imports can not have deprecation supression. - io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest1 = registryUnderTest.registrarFor("test1"); - io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest2 = registryUnderTest.registrarFor("test2"); + io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest1 = + registryUnderTest.registrarFor("test1"); + io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest2 = + registryUnderTest.registrarFor("test2"); ArgumentCaptor shimAggregateCaptor = ArgumentCaptor.forClass(FlutterPlugin.class); @@ -96,7 +99,8 @@ public void itSuppliesMultipleOldPlugins() { @Test public void itCanOnlySupplyActivityBindingWhenUpstreamActivityIsAttached() { ShimPluginRegistry registryUnderTest = new ShimPluginRegistry(mockFlutterEngine); - io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest = registryUnderTest.registrarFor("test"); + io.flutter.plugin.common.PluginRegistry.Registrar registrarUnderTest = + registryUnderTest.registrarFor("test"); ArgumentCaptor shimAggregateCaptor = ArgumentCaptor.forClass(FlutterPlugin.class); diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 95dccf030ed45..0d251df390b6f 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -43,7 +43,6 @@ import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; -import androidx.test.core.app.ActivityScenario; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import io.flutter.embedding.android.FlutterView; diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java index 89b232aa0e9f7..3a5f0e1016803 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -527,7 +527,6 @@ public void doesNotDoAnythingByDefaultIfPopSystemNavigatorOverridden() { verify(mockActivity, never()).finish(); } - @SuppressWarnings("deprecation") // Robolectric.setupActivity. @Test diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index 880f2a707833b..13ec6823f1301 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -28,7 +28,6 @@ import io.flutter.embedding.android.FlutterSurfaceView; import io.flutter.embedding.android.FlutterView; import io.flutter.embedding.android.MotionEventTracker; -import io.flutter.embedding.android.RenderMode; import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterJNI; import io.flutter.embedding.engine.FlutterOverlaySurface; From 1ea2739bc07cc7f7912c1b6e1743e884ef294844 Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Wed, 23 Aug 2023 11:18:09 -0400 Subject: [PATCH 24/25] Add todo for roboletric setupActivity method and remove supression from buildActivity methods --- .../android/FlutterActivityAndFragmentDelegateTest.java | 2 ++ .../embedding/android/FlutterAndroidComponentTest.java | 3 +-- .../flutter/embedding/android/FlutterFragmentTest.java | 2 ++ .../io/flutter/plugin/editing/TextInputPluginTest.java | 8 ++++++++ .../io/flutter/plugin/mouse/MouseCursorPluginTest.java | 1 + .../io/flutter/plugin/platform/PlatformPluginTest.java | 9 ++++----- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index dda31e6fe2428..7b37b4b54451c 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -68,6 +68,7 @@ public class FlutterActivityAndFragmentDelegateTest { @SuppressWarnings("deprecation") // Robolectric.setupActivity + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Before public void setup() { FlutterInjector.reset(); @@ -406,6 +407,7 @@ public void itGivesHostAnOpportunityToConfigureFlutterSurfaceView() { @SuppressWarnings("deprecation") // Robolectric.setupActivity + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void itGivesHostAnOpportunityToConfigureFlutterTextureView() { // ---- Test setup ---- diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java index 70190c31ef751..9641739adbee8 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterAndroidComponentTest.java @@ -207,8 +207,6 @@ public void normalLifecycleStepsDoNotTriggerADetachFromFlutterEngine() { verify(delegate, never()).detachFromFlutterEngine(); } - @SuppressWarnings("deprecation") - // Robolectric.buildActivity @Test public void twoOverlappingFlutterActivitiesDoNotCrosstalk() { // ---- Test setup ---- @@ -269,6 +267,7 @@ public Context getContext() { @SuppressWarnings("deprecation") // Robolectric.setupActivity + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Nullable @Override public Activity getActivity() { diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java index af9b2f6829b5f..4b6c223530d30 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java @@ -285,6 +285,7 @@ public void itReturnsExclusiveAppComponent() { @SuppressWarnings("deprecation") // Robolectric.setupActivity + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void itDelegatesOnBackPressedAutomaticallyWhenEnabled() { // We need to mock FlutterJNI to avoid triggering native code. @@ -321,6 +322,7 @@ public void itDelegatesOnBackPressedAutomaticallyWhenEnabled() { @SuppressWarnings("deprecation") // Robolectric.setupActivity + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void itHandlesPopSystemNavigationAutomaticallyWhenEnabled() { // We need to mock FlutterJNI to avoid triggering native code. diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 0d251df390b6f..368e0a71d98c0 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -1450,6 +1450,7 @@ public void autofill_hintText() { @Config(minSdk = Build.VERSION_CODES.O) @SuppressWarnings("deprecation") // Robolectric.setupActivity. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void autofill_onProvideVirtualViewStructure() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1542,6 +1543,7 @@ public void autofill_onProvideVirtualViewStructure() { @SuppressWarnings("deprecation") // Robolectric.setupActivity. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Config(minSdk = Build.VERSION_CODES.O) @Test public void autofill_onProvideVirtualViewStructure_singular_textfield() { @@ -1597,6 +1599,7 @@ public void autofill_onProvideVirtualViewStructure_singular_textfield() { @Config(minSdk = Build.VERSION_CODES.O) @SuppressWarnings("deprecation") // Robolectric.setupActivity. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void autofill_testLifeCycle() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1734,6 +1737,7 @@ public void autofill_testLifeCycle() { @Config(minSdk = Build.VERSION_CODES.O) @SuppressWarnings("deprecation") // Robolectric.setupActivity. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void autofill_testAutofillUpdatesTheFramework() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1882,6 +1886,7 @@ public void autofill_doesNotCrashAfterClearClientCall() { @Config(minSdk = Build.VERSION_CODES.O) @SuppressWarnings("deprecation") // Robolectric.setupActivity. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void autofill_testSetTextIpnutClientUpdatesSideFields() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -2060,6 +2065,7 @@ public void sendAppPrivateCommand_hasData() throws JSONException { @SuppressWarnings("deprecation") // getWindowSystemUiVisibility, SYSTEM_UI_FLAG_LAYOUT_STABLE, Robolectric.setupActivity. // flutter#133074 tracks migration work. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBars() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); when(testView.getWindowSystemUiVisibility()).thenReturn(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); @@ -2139,6 +2145,7 @@ public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBa @SuppressWarnings("deprecation") // getWindowSystemUiVisibility, Robolectric.setupActivity. // flutter#133074 tracks migration work. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); when(testView.getWindowSystemUiVisibility()) @@ -2220,6 +2227,7 @@ public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars( @SuppressWarnings("deprecation") // getWindowSystemUiVisibility, SYSTEM_UI_FLAG_LAYOUT_STABLE, Robolectric.setupActivity. // flutter#133074 tracks migration work. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 public void lastWindowInsets_updatedOnSecondOnProgressCall() { FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); when(testView.getWindowSystemUiVisibility()).thenReturn(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); diff --git a/shell/platform/android/test/io/flutter/plugin/mouse/MouseCursorPluginTest.java b/shell/platform/android/test/io/flutter/plugin/mouse/MouseCursorPluginTest.java index 17b659c2ebd8d..5ab0f07f65d02 100644 --- a/shell/platform/android/test/io/flutter/plugin/mouse/MouseCursorPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/mouse/MouseCursorPluginTest.java @@ -33,6 +33,7 @@ public class MouseCursorPluginTest { @SuppressWarnings("deprecation") // Robolectric.setupActivity. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void mouseCursorPlugin_SetsSystemCursorOnRequest() throws JSONException { // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java index 3a5f0e1016803..fe8c7e46967d7 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -376,10 +376,9 @@ public void setSystemUiMode() { } @SuppressWarnings("deprecation") - // Robolectric.buildActivity. + // SYSTEM_UI_FLAG_FULLSCREEN @Test public void setSystemUiModeListener_overlaysAreHidden() { - // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 ActivityController controller = Robolectric.buildActivity(Activity.class); controller.setup(); Activity fakeActivity = controller.get(); @@ -408,10 +407,9 @@ public void setSystemUiModeListener_overlaysAreHidden() { } @SuppressWarnings("deprecation") - // Robolectric.buildActivity. + // dispatchSystemUiVisibilityChanged @Test public void setSystemUiModeListener_overlaysAreVisible() { - // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 ActivityController controller = Robolectric.buildActivity(Activity.class); controller.setup(); Activity fakeActivity = controller.get(); @@ -529,6 +527,7 @@ public void doesNotDoAnythingByDefaultIfPopSystemNavigatorOverridden() { @SuppressWarnings("deprecation") // Robolectric.setupActivity. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void popSystemNavigatorFlutterFragment() { // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 @@ -558,9 +557,9 @@ public void handleOnBackPressed() { @SuppressWarnings("deprecation") // Robolectric.setupActivity. + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void doesNotDoAnythingByDefaultIfFragmentPopSystemNavigatorOverridden() { - // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 FragmentActivity activity = spy(Robolectric.setupActivity(FragmentActivity.class)); PlatformChannel mockPlatformChannel = mock(PlatformChannel.class); PlatformPluginDelegate mockPlatformPluginDelegate = mock(PlatformPluginDelegate.class); From e281c259508e6cddd3ed3fc3ff6440d4da2e401a Mon Sep 17 00:00:00 2001 From: Reid Baker Date: Wed, 23 Aug 2023 11:36:34 -0400 Subject: [PATCH 25/25] Add todo for expanding linter coverage and refactor method to reduce number of supressed warnings --- .../plugin/editing/TextInputPluginTest.java | 44 +++++++------------ .../platform/android/test_runner/build.gradle | 5 +-- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index 368e0a71d98c0..881dffc18882c 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -1449,15 +1449,12 @@ public void autofill_hintText() { @Config(minSdk = Build.VERSION_CODES.O) @SuppressWarnings("deprecation") - // Robolectric.setupActivity. - // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void autofill_onProvideVirtualViewStructure() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; } - // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 - FlutterView testView = new FlutterView(Robolectric.setupActivity(Activity.class)); + FlutterView testView = getTestView(); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); @@ -1542,8 +1539,6 @@ public void autofill_onProvideVirtualViewStructure() { } @SuppressWarnings("deprecation") - // Robolectric.setupActivity. - // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Config(minSdk = Build.VERSION_CODES.O) @Test public void autofill_onProvideVirtualViewStructure_singular_textfield() { @@ -1551,7 +1546,7 @@ public void autofill_onProvideVirtualViewStructure_singular_textfield() { return; } // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736 - FlutterView testView = new FlutterView(Robolectric.setupActivity(Activity.class)); + FlutterView testView = getTestView(); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); @@ -1597,9 +1592,6 @@ public void autofill_onProvideVirtualViewStructure_singular_textfield() { } @Config(minSdk = Build.VERSION_CODES.O) - @SuppressWarnings("deprecation") - // Robolectric.setupActivity. - // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void autofill_testLifeCycle() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1607,7 +1599,7 @@ public void autofill_testLifeCycle() { } TestAfm testAfm = Shadow.extract(ctx.getSystemService(AutofillManager.class)); - FlutterView testView = new FlutterView(Robolectric.setupActivity(Activity.class)); + FlutterView testView = getTestView(); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); @@ -1736,8 +1728,6 @@ public void autofill_testLifeCycle() { @Config(minSdk = Build.VERSION_CODES.O) @SuppressWarnings("deprecation") - // Robolectric.setupActivity. - // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void autofill_testAutofillUpdatesTheFramework() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1745,7 +1735,7 @@ public void autofill_testAutofillUpdatesTheFramework() { } TestAfm testAfm = Shadow.extract(ctx.getSystemService(AutofillManager.class)); - FlutterView testView = new FlutterView(Robolectric.setupActivity(Activity.class)); + FlutterView testView = getTestView(); TextInputChannel textInputChannel = spy(new TextInputChannel(mock(DartExecutor.class))); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); @@ -1884,9 +1874,6 @@ public void autofill_doesNotCrashAfterClearClientCall() { } @Config(minSdk = Build.VERSION_CODES.O) - @SuppressWarnings("deprecation") - // Robolectric.setupActivity. - // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 @Test public void autofill_testSetTextIpnutClientUpdatesSideFields() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -1894,7 +1881,7 @@ public void autofill_testSetTextIpnutClientUpdatesSideFields() { } TestAfm testAfm = Shadow.extract(ctx.getSystemService(AutofillManager.class)); - FlutterView testView = new FlutterView(Robolectric.setupActivity(Activity.class)); + FlutterView testView = getTestView(); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class)); @@ -1966,6 +1953,12 @@ public void autofill_testSetTextIpnutClientUpdatesSideFields() { } // -------- End: Autofill Tests ------- + @SuppressWarnings("deprecation") + private FlutterView getTestView() { + // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 + return new FlutterView(Robolectric.setupActivity(Activity.class)); + } + @SuppressWarnings("deprecation") // setMessageHandler is deprecated. @Test @@ -2063,11 +2056,10 @@ public void sendAppPrivateCommand_hasData() throws JSONException { @TargetApi(30) @Config(sdk = 30) @SuppressWarnings("deprecation") - // getWindowSystemUiVisibility, SYSTEM_UI_FLAG_LAYOUT_STABLE, Robolectric.setupActivity. + // getWindowSystemUiVisibility, SYSTEM_UI_FLAG_LAYOUT_STABLE. // flutter#133074 tracks migration work. - // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBars() { - FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); + FlutterView testView = spy(getTestView()); when(testView.getWindowSystemUiVisibility()).thenReturn(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); @@ -2143,11 +2135,10 @@ public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBa @TargetApi(30) @Config(sdk = 30) @SuppressWarnings("deprecation") - // getWindowSystemUiVisibility, Robolectric.setupActivity. + // getWindowSystemUiVisibility // flutter#133074 tracks migration work. - // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars() { - FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); + FlutterView testView = spy(getTestView()); when(testView.getWindowSystemUiVisibility()) .thenReturn( View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); @@ -2225,11 +2216,10 @@ public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars( @TargetApi(30) @Config(sdk = 30) @SuppressWarnings("deprecation") - // getWindowSystemUiVisibility, SYSTEM_UI_FLAG_LAYOUT_STABLE, Robolectric.setupActivity. + // getWindowSystemUiVisibility, SYSTEM_UI_FLAG_LAYOUT_STABLE // flutter#133074 tracks migration work. - // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151 public void lastWindowInsets_updatedOnSecondOnProgressCall() { - FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class))); + FlutterView testView = spy(getTestView()); when(testView.getWindowSystemUiVisibility()).thenReturn(View.SYSTEM_UI_FLAG_LAYOUT_STABLE); TextInputChannel textInputChannel = new TextInputChannel(mock(DartExecutor.class)); diff --git a/shell/platform/android/test_runner/build.gradle b/shell/platform/android/test_runner/build.gradle index 97a5af893f3d1..53a537f874c15 100644 --- a/shell/platform/android/test_runner/build.gradle +++ b/shell/platform/android/test_runner/build.gradle @@ -18,11 +18,10 @@ apply plugin: "com.android.library" rootProject.buildDir = project.property("build_dir") // Shows warnings for usage of deprecated API usages. -// TODO(camsim99): Make deprecation warnings fatal and remove limit when all -// 434 (at the time of this comment) deprecations are fixed. +// TODO(reidbaker): Expand linter coverage https://github.com/flutter/flutter/issues/133154 gradle.projectsEvaluated { tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:deprecation" << "-Werror" << "-Xmaxwarns" << "434" + options.compilerArgs << "-Xlint:deprecation" << "-Werror" } }