mirror of
https://github.com/flutter/flutter
synced 2024-09-13 13:21:36 +00:00
Set the Clipboard more reliably in android semantics integration test. (#101851)
This commit is contained in:
parent
65a826728d
commit
adda8e9388
|
@ -15,6 +15,8 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
@ -66,6 +68,16 @@ public class MainActivity extends FlutterActivity {
|
|||
result.success(convertSemantics(node, id));
|
||||
return;
|
||||
}
|
||||
if (methodCall.method.equals("setClipboard")) {
|
||||
Map<String, Object> data = methodCall.arguments();
|
||||
@SuppressWarnings("unchecked")
|
||||
String message = (String) data.get("message");
|
||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("message", message);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
result.notImplemented();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,21 @@ Future<String> dataHandler(String message) async {
|
|||
completeSemantics();
|
||||
return completer.future;
|
||||
}
|
||||
if (message.contains('setClipboard')) {
|
||||
final Completer<String> completer = Completer<String>();
|
||||
final String str = message.split('#')[1];
|
||||
Future<void> completeSetClipboard([Object _]) async {
|
||||
await kSemanticsChannel.invokeMethod<dynamic>('setClipboard', <String, dynamic>{
|
||||
'message': str,
|
||||
});
|
||||
completer.complete('');
|
||||
}
|
||||
if (SchedulerBinding.instance.hasScheduledFrame)
|
||||
SchedulerBinding.instance.addPostFrameCallback(completeSetClipboard);
|
||||
else
|
||||
completeSetClipboard();
|
||||
return completer.future;
|
||||
}
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
|
|
@ -120,29 +120,7 @@ void main() {
|
|||
// Ideally this should test the case where there is nothing on the
|
||||
// clipboard as well, but there is no reliable way to clear the
|
||||
// clipboard on Android devices.
|
||||
final SerializableFinder normalTextField = find.descendant(
|
||||
of: find.byValueKey(normalTextFieldKeyValue),
|
||||
matching: find.byType('Semantics'),
|
||||
firstMatchOnly: true,
|
||||
);
|
||||
await driver.tap(normalTextField);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
await driver.enterText('hello world');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
await driver.tap(normalTextField);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
await driver.tap(normalTextField);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
await driver.tap(find.text('Select all'));
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
await driver.tap(find.text('Copy'));
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
await driver.enterText('');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
// Go back to previous page and forward again to unfocus the field.
|
||||
await driver.tap(find.byValueKey(backButtonKeyValue));
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
await driver.tap(find.text(textFieldRoute));
|
||||
await driver.requestData('setClipboard#Hello World');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue