mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +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.os.Bundle;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.ClipData;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
@ -66,6 +68,16 @@ public class MainActivity extends FlutterActivity {
|
|||||||
result.success(convertSemantics(node, id));
|
result.success(convertSemantics(node, id));
|
||||||
return;
|
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();
|
result.notImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,21 @@ Future<String> dataHandler(String message) async {
|
|||||||
completeSemantics();
|
completeSemantics();
|
||||||
return completer.future;
|
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();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,29 +120,7 @@ void main() {
|
|||||||
// Ideally this should test the case where there is nothing on the
|
// 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 as well, but there is no reliable way to clear the
|
||||||
// clipboard on Android devices.
|
// clipboard on Android devices.
|
||||||
final SerializableFinder normalTextField = find.descendant(
|
await driver.requestData('setClipboard#Hello World');
|
||||||
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 Future<void>.delayed(const Duration(milliseconds: 500));
|
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user