Emulate text entry in FlutterDriver (#13373)
* Emulate text entry in FlutterDriver * document enterText behavior * remove the unnecessary composint TextRange
This commit is contained in:
@@ -23,8 +23,8 @@ final CommonFinders find = const CommonFinders._();
|
||||
class CommonFinders {
|
||||
const CommonFinders._();
|
||||
|
||||
/// Finds [Text] widgets containing string equal to the `text`
|
||||
/// argument.
|
||||
/// Finds [Text] and [EditableText] widgets containing string equal to the
|
||||
/// `text` argument.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
@@ -410,10 +410,14 @@ class _TextFinder extends MatchFinder {
|
||||
|
||||
@override
|
||||
bool matches(Element candidate) {
|
||||
if (candidate.widget is! Text)
|
||||
return false;
|
||||
final Text textWidget = candidate.widget;
|
||||
return textWidget.data == text;
|
||||
if (candidate.widget is Text) {
|
||||
final Text textWidget = candidate.widget;
|
||||
return textWidget.data == text;
|
||||
} else if (candidate.widget is EditableText) {
|
||||
final EditableText editable = candidate.widget;
|
||||
return editable.controller.text == text;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,11 @@ class TestTextInput {
|
||||
|
||||
/// Simulates the user changing the [TextEditingValue] to the given value.
|
||||
void updateEditingValue(TextEditingValue value) {
|
||||
expect(_client, isNonZero);
|
||||
// Not using the `expect` function because in the case of a FlutterDriver
|
||||
// test this code does not run in a package:test test zone.
|
||||
if (_client == 0) {
|
||||
throw new TestFailure('_client must be non-zero');
|
||||
}
|
||||
BinaryMessages.handlePlatformMessage(
|
||||
SystemChannels.textInput.name,
|
||||
SystemChannels.textInput.codec.encodeMethodCall(
|
||||
@@ -82,7 +86,6 @@ class TestTextInput {
|
||||
void enterText(String text) {
|
||||
updateEditingValue(new TextEditingValue(
|
||||
text: text,
|
||||
composing: new TextRange(start: 0, end: text.length),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user