text.dart 3.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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.
  GetText(SerializableFinder finder, { Duration timeout }) : super(finder, timeout: timeout);

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

  @override
  final String kind = 'get_text';
}

/// The result of the [GetText] command.
class GetTextResult extends Result {
  /// Creates a result with the given [text].
  GetTextResult(this.text);

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

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

  @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.
  EnterText(this.text, { Duration timeout }) : super(timeout: timeout);

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

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

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  @override
  final String kind = 'enter_text';

  @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.
  EnterTextResult();

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

  @override
  Map<String, dynamic> toJson() => const <String, String>{};
}
74 75 76 77 78 79 80 81 82 83 84

/// 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);

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

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

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  @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) {
104
    return SetTextEntryEmulationResult();
105 106 107 108 109
  }

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