From ec0f7b165a97141a8a7953c0d543609b96e34a7b Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 25 Nov 2024 09:39:24 -0800 Subject: [PATCH] more test cleanups and fixes. --- .../embedding/android/FlutterView.java | 5 +- .../plugin/editing/TextInputPlugin.java | 8 +- .../platform/PlatformViewsController2.java | 6 +- ...lutterActivityAndFragmentDelegateTest.java | 2 + .../plugin/editing/TextInputPluginTest.java | 223 +++++++++++++++--- .../PlatformViewsController2Test.java | 11 +- .../platform/PlatformViewsControllerTest.java | 3 + 7 files changed, 213 insertions(+), 45 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterView.java b/shell/platform/android/io/flutter/embedding/android/FlutterView.java index a1eaed6da7f03..404eee696d09b 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterView.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterView.java @@ -1129,7 +1129,8 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) { this, this.flutterEngine.getTextInputChannel(), this.flutterEngine.getScribeChannel(), - this.flutterEngine.getPlatformViewsController()); + this.flutterEngine.getPlatformViewsController(), + this.flutterEngine.getPlatformViewsController2()); try { textServicesManager = @@ -1226,9 +1227,11 @@ public void detachFromFlutterEngine() { getContext().getContentResolver().unregisterContentObserver(systemSettingsObserver); flutterEngine.getPlatformViewsController().detachFromView(); + flutterEngine.getPlatformViewsController2().detachFromView(); // Disconnect the FlutterEngine's PlatformViewsController from the AccessibilityBridge. flutterEngine.getPlatformViewsController().detachAccessibilityBridge(); + flutterEngine.getPlatformViewsController2().detachAccessibilityBridge(); // Disconnect and clean up the AccessibilityBridge. accessibilityBridge.release(); diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 4f3adcec4d8a4..d6d6160786312 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -33,6 +33,7 @@ import io.flutter.embedding.engine.systemchannels.TextInputChannel; import io.flutter.embedding.engine.systemchannels.TextInputChannel.TextEditState; import io.flutter.plugin.platform.PlatformViewsController; +import io.flutter.plugin.platform.PlatformViewsController2; import java.util.ArrayList; import java.util.HashMap; @@ -52,6 +53,7 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch private boolean mRestartInputPending; @Nullable private InputConnection lastInputConnection; @NonNull private PlatformViewsController platformViewsController; + @NonNull private PlatformViewsController2 platformViewsController2; @Nullable private Rect lastClientRect; private ImeSyncDeferringInsetsCallback imeSyncCallback; @@ -69,7 +71,8 @@ public TextInputPlugin( @NonNull View view, @NonNull TextInputChannel textInputChannel, @NonNull ScribeChannel scribeChannel, - @NonNull PlatformViewsController platformViewsController) { + @NonNull PlatformViewsController platformViewsController, + @NonNull PlatformViewsController2 platformViewsController2) { mView = view; // Create a default object. mEditable = new ListenableEditingState(null, mView); @@ -160,6 +163,8 @@ public void sendAppPrivateCommand(String action, Bundle data) { this.platformViewsController = platformViewsController; this.platformViewsController.attachTextInputPlugin(this); + this.platformViewsController2 = platformViewsController2; + this.platformViewsController2.attachTextInputPlugin(this); } @NonNull @@ -215,6 +220,7 @@ public void unlockPlatformViewInputConnection() { @SuppressLint("NewApi") public void destroy() { platformViewsController.detachTextInputPlugin(); + platformViewsController2.detachTextInputPlugin(); textInputChannel.setTextInputMethodHandler(null); notifyViewExited(); mEditable.removeEditingStateListener(this); diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java index 0629c181e6bdf..5c667f218bd1a 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java @@ -573,8 +573,10 @@ public FlutterOverlaySurface createOverlaySurface() { } public void destroyOverlaySurface() { - overlayerSurface.release(); - overlayerSurface = null; + if (overlayerSurface != null) { + overlayerSurface.release(); + overlayerSurface = null; + } } //// Message Handler /////// 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 ae1e371a48d6a..9cc1f115d8c81 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -55,6 +55,7 @@ import io.flutter.embedding.engine.systemchannels.TextInputChannel; import io.flutter.plugin.localization.LocalizationPlugin; import io.flutter.plugin.platform.PlatformViewsController; +import io.flutter.plugin.platform.PlatformViewsController2; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -1475,6 +1476,7 @@ private FlutterEngine mockFlutterEngine() { when(engine.getNavigationChannel()).thenReturn(mock(NavigationChannel.class)); when(engine.getBackGestureChannel()).thenReturn(mock(BackGestureChannel.class)); when(engine.getPlatformViewsController()).thenReturn(mock(PlatformViewsController.class)); + when(engine.getPlatformViewsController2()).thenReturn(mock(PlatformViewsController2.class)); FlutterRenderer renderer = mock(FlutterRenderer.class); when(engine.getRenderer()).thenReturn(renderer); 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 d10df7bf1aee2..d879a4abf68ce 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -63,6 +63,7 @@ import io.flutter.plugin.common.JSONMethodCodec; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.platform.PlatformViewsController; +import io.flutter.plugin.platform.PlatformViewsController2; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.HashMap; @@ -139,7 +140,11 @@ public void textInputPlugin_RequestsReattachOnCreation() throws JSONException { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); ArgumentCaptor channelCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor bufferCaptor = ArgumentCaptor.forClass(ByteBuffer.class); @@ -160,7 +165,11 @@ public void setTextInputEditingState_doesNotInvokeUpdateEditingState() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -204,7 +213,11 @@ public void setTextInputEditingState_willNotThrowWithoutSetTextInputClient() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); // Here's no textInputPlugin.setTextInputClient() textInputPlugin.setTextInputEditingState( @@ -223,7 +236,11 @@ public void setTextInputEditingState_doesNotInvokeUpdateEditingStateWithDeltas() ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -275,7 +292,11 @@ public void textEditingDelta_TestUpdateEditingValueWithDeltasIsNotInvokedWhenDel ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); CharSequence newText = "I do not fear computers. I fear the lack of them."; // Change InputTarget to FRAMEWORK_CLIENT. @@ -390,7 +411,11 @@ public void textEditingDelta_TestUpdateEditingValueIsNotInvokedWhenDeltaModelEna ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); CharSequence newText = "I do not fear computers. I fear the lack of them."; final TextEditingDelta expectedDelta = new TextEditingDelta("", 0, 0, newText, newText.length(), newText.length(), 0, 49); @@ -521,7 +546,11 @@ public void textEditingDelta_TestDeltaIsCreatedWhenComposingTextSetIsInserting() ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); CharSequence newText = "I do not fear computers. I fear the lack of them."; final TextEditingDelta expectedDelta = new TextEditingDelta("", 0, 0, newText, newText.length(), newText.length(), 0, 49); @@ -632,7 +661,11 @@ public void textEditingDelta_TestDeltaIsCreatedWhenComposingTextSetIsDeleting() ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); CharSequence newText = "I do not fear computers. I fear the lack of them."; final TextEditingDelta expectedDelta = new TextEditingDelta( @@ -744,7 +777,11 @@ public void textEditingDelta_TestDeltaIsCreatedWhenComposingTextSetIsReplacing() ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); CharSequence newText = "helfo"; final TextEditingDelta expectedDelta = new TextEditingDelta(newText, 0, 5, "hello", 5, 5, 0, 5); @@ -853,7 +890,11 @@ public void inputConnectionAdaptor_RepeatFilter() throws NullPointerException { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); // Change InputTarget to FRAMEWORK_CLIENT. textInputPlugin.setTextInputClient( @@ -946,7 +987,11 @@ public void setTextInputEditingState_doesNotRestartWhenTextIsIdentical() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -986,7 +1031,11 @@ public void setTextInputEditingState_alwaysSetEditableWhenDifferent() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1036,7 +1085,11 @@ public void setTextInputEditingState_restartsIMEOnlyWhenFrameworkChangesComposin ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1139,7 +1192,11 @@ public void setTextInputEditingState_nullInputMethodSubtype() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1168,7 +1225,11 @@ public void destroy_clearTextInputMethodHandler() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); verify(textInputChannel, times(1)).setTextInputMethodHandler(isNotNull()); textInputPlugin.destroy(); verify(textInputChannel, times(1)).setTextInputMethodHandler(isNull()); @@ -1186,7 +1247,11 @@ private void verifyInputConnection(TextInputChannel.TextInputType textInputType) ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1263,7 +1328,11 @@ public void inputConnection_finishComposingTextUpdatesIMM() throws JSONException ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1303,7 +1372,11 @@ public void inputConnection_textInputTypeNone() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1335,7 +1408,11 @@ public void showTextInput_textInputTypeNone() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1365,7 +1442,11 @@ public void showTextInput_textInputTypeWebSearch() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1399,7 +1480,11 @@ public void inputConnection_textInputTypeMultilineAndSuggestionsDisabled() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1438,7 +1523,11 @@ public void inputConnection_setsStylusHandwritingAvailable() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1472,7 +1561,11 @@ public void inputConnection_doesNotcallSetsStylusHandwritingAvailableWhenAPILeve ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); textInputPlugin.setTextInputClient( 0, new TextInputChannel.Configuration( @@ -1507,7 +1600,11 @@ public void autofill_enabledByDefault() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); final TextInputChannel.Configuration.Autofill autofill = new TextInputChannel.Configuration.Autofill( "1", new String[] {}, null, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); @@ -1569,7 +1666,11 @@ public void autofill_canBeDisabled() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); final TextInputChannel.Configuration.Autofill autofill = new TextInputChannel.Configuration.Autofill( "1", new String[] {}, null, new TextInputChannel.TextEditState("", 0, 0, -1, -1)); @@ -1608,7 +1709,11 @@ public void autofill_hintText() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); final TextInputChannel.Configuration.Autofill autofill = new TextInputChannel.Configuration.Autofill( "1", @@ -1655,7 +1760,11 @@ public void autofill_onProvideVirtualViewStructure() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); final TextInputChannel.Configuration.Autofill autofill1 = new TextInputChannel.Configuration.Autofill( "1", @@ -1749,7 +1858,11 @@ public void autofill_onProvideVirtualViewStructure_singular_textfield() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); final TextInputChannel.Configuration.Autofill autofill = new TextInputChannel.Configuration.Autofill( "1", @@ -1804,7 +1917,11 @@ public void autofill_testLifeCycle() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); // Set up an autofill scenario with 2 fields. final TextInputChannel.Configuration.Autofill autofill1 = @@ -1943,7 +2060,11 @@ public void autofill_testAutofillUpdatesTheFramework() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); // Set up an autofill scenario with 2 fields. final TextInputChannel.Configuration.Autofill autofill1 = @@ -2040,7 +2161,11 @@ public void autofill_doesNotCrashAfterClearClientCall() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); // Set up an autofill scenario with 2 fields. final TextInputChannel.Configuration.Autofill autofillConfig = new TextInputChannel.Configuration.Autofill( @@ -2093,7 +2218,11 @@ public void autofill_testSetTextIpnutClientUpdatesSideFields() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); // Set up an autofill scenario with 2 fields. final TextInputChannel.Configuration.Autofill autofill1 = @@ -2214,7 +2343,11 @@ public void sendAppPrivateCommand_dataIsEmpty() throws JSONException { View testView = new View(ctx); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); verify(mockBinaryMessenger, times(1)) .setMessageHandler(any(String.class), binaryMessageHandlerCaptor.capture()); @@ -2247,7 +2380,11 @@ public void sendAppPrivateCommand_hasData() throws JSONException { View testView = new View(ctx); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); verify(mockBinaryMessenger, times(1)) .setMessageHandler(any(String.class), binaryMessageHandlerCaptor.capture()); @@ -2279,7 +2416,11 @@ public void ime_windowInsetsSync_notLaidOutBehindNavigation_excludesNavigationBa ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); ImeSyncDeferringInsetsCallback imeSyncCallback = textInputPlugin.getImeSyncCallback(); FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni)); FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni)); @@ -2362,7 +2503,11 @@ public void ime_windowInsetsSync_laidOutBehindNavigation_includesNavigationBars( ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); ImeSyncDeferringInsetsCallback imeSyncCallback = textInputPlugin.getImeSyncCallback(); FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni)); FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni)); @@ -2443,7 +2588,11 @@ public void lastWindowInsets_updatedOnSecondOnProgressCall() { ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class)); TextInputPlugin textInputPlugin = new TextInputPlugin( - testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class)); + testView, + textInputChannel, + scribeChannel, + mock(PlatformViewsController.class), + mock(PlatformViewsController2.class)); ImeSyncDeferringInsetsCallback imeSyncCallback = textInputPlugin.getImeSyncCallback(); FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni)); FlutterRenderer flutterRenderer = spy(new FlutterRenderer(mockFlutterJni)); diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java index cc81b62292194..5edb4318998cd 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java @@ -621,7 +621,7 @@ private static void createPlatformView( final MethodCall platformCreateMethodCall = new MethodCall("create", args); jni.handlePlatformMessage( - "flutter/platform_views", + "flutter/platform_views_2", encodeMethodCall(platformCreateMethodCall), /*replyId=*/ 0, /*messageData=*/ 0); @@ -639,7 +639,7 @@ private static void setLayoutDirection( final MethodCall platformSetDirectionMethodCall = new MethodCall("setDirection", args); jni.handlePlatformMessage( - "flutter/platform_views", + "flutter/platform_views_2", encodeMethodCall(platformSetDirectionMethodCall), /*replyId=*/ 0, /*messageData=*/ 0); @@ -654,7 +654,7 @@ private static void disposePlatformView( final MethodCall platformDisposeMethodCall = new MethodCall("dispose", args); jni.handlePlatformMessage( - "flutter/platform_views", + "flutter/platform_views_2", encodeMethodCall(platformDisposeMethodCall), /*replyId=*/ 0, /*messageData=*/ 0); @@ -666,7 +666,7 @@ private static void synchronizeToNativeViewHierarchy( final MethodCall convertMethodCall = new MethodCall("synchronizeToNativeViewHierarchy", yes); jni.handlePlatformMessage( - "flutter/platform_views", + "flutter/platform_views_2", encodeMethodCall(convertMethodCall), /*replyId=*/ 0, /*messageData=*/ 0); @@ -696,6 +696,8 @@ private static void attachToFlutterView( final Context context = ApplicationProvider.getApplicationContext(); PlatformViewsController2.attach(context, executor); + PlatformViewsController oldController = new PlatformViewsController(); + final FlutterEngine engine = mock(FlutterEngine.class); when(engine.getRenderer()).thenReturn(new FlutterRenderer(jni)); when(engine.getMouseCursorChannel()).thenReturn(mock(MouseCursorChannel.class)); @@ -703,6 +705,7 @@ private static void attachToFlutterView( when(engine.getSettingsChannel()).thenReturn(new SettingsChannel(executor)); when(engine.getScribeChannel()).thenReturn(mock(ScribeChannel.class)); when(engine.getPlatformViewsController2()).thenReturn(PlatformViewsController2); + when(engine.getPlatformViewsController()).thenReturn(oldController); when(engine.getLocalizationPlugin()).thenReturn(mock(LocalizationPlugin.class)); when(engine.getAccessibilityChannel()).thenReturn(mock(AccessibilityChannel.class)); when(engine.getDartExecutor()).thenReturn(executor); 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 4b36393b71924..0b3e3aaa0ae5b 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -1664,6 +1664,8 @@ public void scheduleFrame() {} platformViewsController.attach(context, registry, executor); + PlatformViewsController2 secondController = new PlatformViewsController2(); + final FlutterEngine engine = mock(FlutterEngine.class); when(engine.getRenderer()).thenReturn(new FlutterRenderer(jni)); when(engine.getMouseCursorChannel()).thenReturn(mock(MouseCursorChannel.class)); @@ -1671,6 +1673,7 @@ public void scheduleFrame() {} when(engine.getSettingsChannel()).thenReturn(new SettingsChannel(executor)); when(engine.getScribeChannel()).thenReturn(mock(ScribeChannel.class)); when(engine.getPlatformViewsController()).thenReturn(platformViewsController); + when(engine.getPlatformViewsController2()).thenReturn(secondController); when(engine.getLocalizationPlugin()).thenReturn(mock(LocalizationPlugin.class)); when(engine.getAccessibilityChannel()).thenReturn(mock(AccessibilityChannel.class)); when(engine.getDartExecutor()).thenReturn(executor);