support disabling text entry emulation (#13410)
This commit is contained in:
parent
bf4409f1f3
commit
d1e918fa10
@ -21,6 +21,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('Ensure keyboard dismissal resizes the view to original size', () async {
|
||||
await driver.setTextEntryEmulation(enabled: false);
|
||||
final SerializableFinder heightText = find.byValueKey(keys.kHeightText);
|
||||
await driver.waitFor(heightText);
|
||||
|
||||
|
@ -71,3 +71,39 @@ class EnterTextResult extends Result {
|
||||
@override
|
||||
Map<String, dynamic> toJson() => const <String, String>{};
|
||||
}
|
||||
|
||||
/// A Flutter Driver command that enables and disables text entry emulation.
|
||||
class SetTextEntryEmulation extends Command {
|
||||
/// Creates a command that enables and disables text entry emulation.
|
||||
SetTextEntryEmulation(this.enabled, { Duration timeout }) : super(timeout: timeout);
|
||||
|
||||
/// Whether text entry emulation should be enabled.
|
||||
final bool enabled;
|
||||
|
||||
/// Deserializes this command from the value generated by [serialize].
|
||||
SetTextEntryEmulation.deserialize(Map<String, dynamic> json)
|
||||
: enabled = json['enabled'] == 'true',
|
||||
super.deserialize(json);
|
||||
|
||||
@override
|
||||
final String kind = 'set_text_entry_emulation';
|
||||
|
||||
@override
|
||||
Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
|
||||
'enabled': '$enabled',
|
||||
});
|
||||
}
|
||||
|
||||
/// The result of the [SetTextEntryEmulation] command.
|
||||
class SetTextEntryEmulationResult extends Result {
|
||||
/// Creates a successful result.
|
||||
SetTextEntryEmulationResult();
|
||||
|
||||
/// Deserializes the result from JSON.
|
||||
static SetTextEntryEmulationResult fromJson(Map<String, dynamic> json) {
|
||||
return new SetTextEntryEmulationResult();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => const <String, String>{};
|
||||
}
|
||||
|
@ -451,6 +451,15 @@ class FlutterDriver {
|
||||
await _sendCommand(new EnterText(text, timeout: timeout));
|
||||
}
|
||||
|
||||
/// If `enabled` is true, enables text entry emulation via [enterText]. If
|
||||
/// `enabled` is false, disables it.
|
||||
///
|
||||
/// By default text entry emulation is enabled.
|
||||
Future<Null> setTextEntryEmulation({ @required bool enabled, Duration timeout }) async {
|
||||
assert(enabled != null);
|
||||
await _sendCommand(new SetTextEntryEmulation(enabled, timeout: timeout));
|
||||
}
|
||||
|
||||
/// Sends a string and returns a string.
|
||||
///
|
||||
/// This enables generic communication between the driver and the application.
|
||||
|
@ -100,6 +100,7 @@ class FlutterDriverExtension {
|
||||
'scrollIntoView': _scrollIntoView,
|
||||
'set_frame_sync': _setFrameSync,
|
||||
'set_semantics': _setSemantics,
|
||||
'set_text_entry_emulation': _setTextEntryEmulation,
|
||||
'tap': _tap,
|
||||
'waitFor': _waitFor,
|
||||
'waitForAbsent': _waitForAbsent,
|
||||
@ -116,6 +117,7 @@ class FlutterDriverExtension {
|
||||
'scrollIntoView': (Map<String, String> params) => new ScrollIntoView.deserialize(params),
|
||||
'set_frame_sync': (Map<String, String> params) => new SetFrameSync.deserialize(params),
|
||||
'set_semantics': (Map<String, String> params) => new SetSemantics.deserialize(params),
|
||||
'set_text_entry_emulation': (Map<String, String> params) => new SetTextEntryEmulation.deserialize(params),
|
||||
'tap': (Map<String, String> params) => new Tap.deserialize(params),
|
||||
'waitFor': (Map<String, String> params) => new WaitFor.deserialize(params),
|
||||
'waitForAbsent': (Map<String, String> params) => new WaitForAbsent.deserialize(params),
|
||||
@ -332,6 +334,16 @@ class FlutterDriverExtension {
|
||||
return new GetTextResult(text.data);
|
||||
}
|
||||
|
||||
Future<SetTextEntryEmulationResult> _setTextEntryEmulation(Command command) async {
|
||||
final SetTextEntryEmulation setTextEntryEmulationCommand = command;
|
||||
if (setTextEntryEmulationCommand.enabled) {
|
||||
_testTextInput.register();
|
||||
} else {
|
||||
_testTextInput.unregister();
|
||||
}
|
||||
return new SetTextEntryEmulationResult();
|
||||
}
|
||||
|
||||
Future<EnterTextResult> _enterText(Command command) async {
|
||||
final EnterText enterTextCommand = command;
|
||||
_testTextInput.enterText(enterTextCommand.text);
|
||||
|
@ -24,6 +24,15 @@ class TestTextInput {
|
||||
SystemChannels.textInput.setMockMethodCallHandler(_handleTextInputCall);
|
||||
}
|
||||
|
||||
/// Removes this object as a mock handler for [SystemChannels.textInput].
|
||||
///
|
||||
/// After calling this method, the channel will exchange messages with the
|
||||
/// Flutter engine. Use this with [FlutterDriver] tests that need to display
|
||||
/// on-screen keyboard provided by the operating system.
|
||||
void unregister() {
|
||||
SystemChannels.textInput.setMockMethodCallHandler(null);
|
||||
}
|
||||
|
||||
int _client = 0;
|
||||
|
||||
/// Arguments supplied to the TextInput.setClient method call.
|
||||
|
Loading…
x
Reference in New Issue
Block a user