From 29bfb11c04f9ee0e01627969e4754bbc81a1279c Mon Sep 17 00:00:00 2001 From: Michael Klimushyn Date: Thu, 10 Oct 2019 10:36:24 -0700 Subject: [PATCH] Partial deflaking of abstract_method_smoke_test (#42379) 1. The platform code to show the keyboard wasn't working on certain devices. From my testing it appears to be related to when the code was firing. IMM won't show the soft input (or shows and then immediately hides it, it's hard to tell) if it's called before the Flutter UI is loaded. Change this to instead show the soft keyboard after a message from Flutter that main() has been started. 2. A text field was visible in the UI, and the test was run under a fuzzer that random tapped portions of the screen. Remove the text field so that the fuzzer can't accidentally open the keyboard on its own at a random time. 3. The keyboard was left open even after the app was closed. Also toggle the input off when the app was closed, so that this test can be ran multiple times in succession relatively hermetically. --- .../MainActivity.kt | 20 +++++++++++++++++-- .../abstract_method_smoke_test/lib/main.dart | 11 ++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/dev/integration_tests/abstract_method_smoke_test/android/app/src/main/kotlin/com/example/abstract_method_smoke_test/MainActivity.kt b/dev/integration_tests/abstract_method_smoke_test/android/app/src/main/kotlin/com/example/abstract_method_smoke_test/MainActivity.kt index 4b7eeb7b1f..acb8afcc6d 100644 --- a/dev/integration_tests/abstract_method_smoke_test/android/app/src/main/kotlin/com/example/abstract_method_smoke_test/MainActivity.kt +++ b/dev/integration_tests/abstract_method_smoke_test/android/app/src/main/kotlin/com/example/abstract_method_smoke_test/MainActivity.kt @@ -4,6 +4,8 @@ import android.content.Context import android.os.Bundle import android.view.inputmethod.InputMethodManager import io.flutter.app.FlutterActivity +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugins.GeneratedPluginRegistrant class MainActivity: FlutterActivity() { @@ -12,8 +14,22 @@ class MainActivity: FlutterActivity() { GeneratedPluginRegistrant.registerWith(this) // Triggers the Android keyboard, which causes the resize of the Flutter view. - // https://github.com/flutter/flutter/issues/40126 + // We need to wait for the app to complete. + MethodChannel(getFlutterView(), "com.example.abstract_method_smoke_test") + .setMethodCallHandler({ call, result -> + toggleInput() + result.success(null) + }) + } + + override fun onPause() { + // Hide the input when the app is closed. + toggleInput() + super.onPause() + } + + fun toggleInput() { val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) + imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0) } } diff --git a/dev/integration_tests/abstract_method_smoke_test/lib/main.dart b/dev/integration_tests/abstract_method_smoke_test/lib/main.dart index 97638939dc..26ad2158b6 100644 --- a/dev/integration_tests/abstract_method_smoke_test/lib/main.dart +++ b/dev/integration_tests/abstract_method_smoke_test/lib/main.dart @@ -1,7 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; -void main() { +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + const MethodChannel channel = MethodChannel('com.example.abstract_method_smoke_test'); + await channel.invokeMethod('show_keyboard'); runApp(MyApp()); print('Test suceeded'); } @@ -48,9 +52,8 @@ class SecondPage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( body: Column( - children: [ - TextFormField(), - const Expanded( + children: const [ + Expanded( child: GoogleMap( initialCameraPosition: CameraPosition( target: LatLng(0, 0)