text.dart 2.65 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'deserialization_factory.dart';
6 7 8 9 10 11
import 'find.dart';
import 'message.dart';

/// A Flutter Driver command that reads the text from a given element.
class GetText extends CommandWithTarget {
  /// [finder] looks for an element that contains a piece of text.
12
  GetText(SerializableFinder finder, { Duration? timeout }) : super(finder, timeout: timeout);
13 14

  /// Deserializes this command from the value generated by [serialize].
15
  GetText.deserialize(Map<String, String> json, DeserializeFinderFactory finderFactory) : super.deserialize(json, finderFactory);
16 17

  @override
18
  String get kind => 'get_text';
19 20 21 22 23
}

/// The result of the [GetText] command.
class GetTextResult extends Result {
  /// Creates a result with the given [text].
24
  const GetTextResult(this.text);
25 26 27 28 29 30

  /// The text extracted by the [GetText] command.
  final String text;

  /// Deserializes the result from JSON.
  static GetTextResult fromJson(Map<String, dynamic> json) {
31
    return GetTextResult(json['text'] as String);
32 33 34 35 36 37 38 39 40 41 42
  }

  @override
  Map<String, dynamic> toJson() => <String, String>{
    'text': text,
  };
}

/// A Flutter Driver command that enters text into the currently focused widget.
class EnterText extends Command {
  /// Creates a command that enters text into the currently focused widget.
43
  const EnterText(this.text, { Duration? timeout }) : super(timeout: timeout);
44 45

  /// Deserializes this command from the value generated by [serialize].
46
  EnterText.deserialize(Map<String, String> json)
47
    : text = json['text']!,
48
      super.deserialize(json);
49

50 51 52
  /// The text extracted by the [GetText] command.
  final String text;

53
  @override
54
  String get kind => 'enter_text';
55 56 57 58 59 60 61

  @override
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'text': text,
  });
}

62 63 64
/// 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.
65
  const SetTextEntryEmulation(this.enabled, { Duration? timeout }) : super(timeout: timeout);
66 67

  /// Deserializes this command from the value generated by [serialize].
68
  SetTextEntryEmulation.deserialize(Map<String, String> json)
69 70
    : enabled = json['enabled'] == 'true',
      super.deserialize(json);
71

72 73 74
  /// Whether text entry emulation should be enabled.
  final bool enabled;

75
  @override
76
  String get kind => 'set_text_entry_emulation';
77 78 79 80 81 82

  @override
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'enabled': '$enabled',
  });
}