text.dart 3.45 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 62 63 64

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

/// The result of the [EnterText] command.
class EnterTextResult extends Result {
  /// Creates a successful result of entering the text.
65
  const EnterTextResult();
66 67 68

  /// Deserializes the result from JSON.
  static EnterTextResult fromJson(Map<String, dynamic> json) {
69
    return const EnterTextResult();
70 71 72 73 74
  }

  @override
  Map<String, dynamic> toJson() => const <String, String>{};
}
75 76 77 78

/// 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.
79
  const SetTextEntryEmulation(this.enabled, { Duration? timeout }) : super(timeout: timeout);
80 81

  /// Deserializes this command from the value generated by [serialize].
82
  SetTextEntryEmulation.deserialize(Map<String, String> json)
83 84
    : enabled = json['enabled'] == 'true',
      super.deserialize(json);
85

86 87 88
  /// Whether text entry emulation should be enabled.
  final bool enabled;

89
  @override
90
  String get kind => 'set_text_entry_emulation';
91 92 93 94 95 96 97 98 99 100

  @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.
101
  const SetTextEntryEmulationResult();
102 103 104

  /// Deserializes the result from JSON.
  static SetTextEntryEmulationResult fromJson(Map<String, dynamic> json) {
105
    return const SetTextEntryEmulationResult();
106 107 108 109 110
  }

  @override
  Map<String, dynamic> toJson() => const <String, String>{};
}