• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'find.dart';
6import 'message.dart';
7
8/// A Flutter Driver command that reads the text from a given element.
9class GetText extends CommandWithTarget {
10  /// [finder] looks for an element that contains a piece of text.
11  GetText(SerializableFinder finder, { Duration timeout }) : super(finder, timeout: timeout);
12
13  /// Deserializes this command from the value generated by [serialize].
14  GetText.deserialize(Map<String, dynamic> json) : super.deserialize(json);
15
16  @override
17  String get kind => 'get_text';
18}
19
20/// The result of the [GetText] command.
21class GetTextResult extends Result {
22  /// Creates a result with the given [text].
23  const GetTextResult(this.text);
24
25  /// The text extracted by the [GetText] command.
26  final String text;
27
28  /// Deserializes the result from JSON.
29  static GetTextResult fromJson(Map<String, dynamic> json) {
30    return GetTextResult(json['text']);
31  }
32
33  @override
34  Map<String, dynamic> toJson() => <String, String>{
35    'text': text,
36  };
37}
38
39/// A Flutter Driver command that enters text into the currently focused widget.
40class EnterText extends Command {
41  /// Creates a command that enters text into the currently focused widget.
42  const EnterText(this.text, { Duration timeout }) : super(timeout: timeout);
43
44  /// Deserializes this command from the value generated by [serialize].
45  EnterText.deserialize(Map<String, dynamic> json)
46    : text = json['text'],
47      super.deserialize(json);
48
49  /// The text extracted by the [GetText] command.
50  final String text;
51
52  @override
53  String get kind => 'enter_text';
54
55  @override
56  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
57    'text': text,
58  });
59}
60
61/// The result of the [EnterText] command.
62class EnterTextResult extends Result {
63  /// Creates a successful result of entering the text.
64  const EnterTextResult();
65
66  /// Deserializes the result from JSON.
67  static EnterTextResult fromJson(Map<String, dynamic> json) {
68    return const EnterTextResult();
69  }
70
71  @override
72  Map<String, dynamic> toJson() => const <String, String>{};
73}
74
75/// A Flutter Driver command that enables and disables text entry emulation.
76class SetTextEntryEmulation extends Command {
77  /// Creates a command that enables and disables text entry emulation.
78  const SetTextEntryEmulation(this.enabled, { Duration timeout }) : super(timeout: timeout);
79
80  /// Deserializes this command from the value generated by [serialize].
81  SetTextEntryEmulation.deserialize(Map<String, dynamic> json)
82    : enabled = json['enabled'] == 'true',
83      super.deserialize(json);
84
85  /// Whether text entry emulation should be enabled.
86  final bool enabled;
87
88  @override
89  String get kind => 'set_text_entry_emulation';
90
91  @override
92  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
93    'enabled': '$enabled',
94  });
95}
96
97/// The result of the [SetTextEntryEmulation] command.
98class SetTextEntryEmulationResult extends Result {
99  /// Creates a successful result.
100  const SetTextEntryEmulationResult();
101
102  /// Deserializes the result from JSON.
103  static SetTextEntryEmulationResult fromJson(Map<String, dynamic> json) {
104    return const SetTextEntryEmulationResult();
105  }
106
107  @override
108  Map<String, dynamic> toJson() => const <String, String>{};
109}
110