message.dart 1.42 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5 6
import 'package:meta/meta.dart';

7 8 9
/// An object sent from the Flutter Driver to a Flutter application to instruct
/// the application to perform a task.
abstract class Command {
10 11 12
  /// Abstract const constructor. This constructor enables subclasses to provide
  /// const constructors so that they can be used in const expressions.
  const Command({ Duration timeout })
13 14
      : this.timeout = timeout ?? const Duration(seconds: 5);

15
  /// Deserializes this command from the value generated by [serialize].
16 17 18 19 20 21 22 23
  Command.deserialize(Map<String, String> json)
      : timeout = new Duration(milliseconds: int.parse(json['timeout']));

  /// The maximum amount of time to wait for the command to complete.
  ///
  /// Defaults to 5 seconds.
  final Duration timeout;

24 25
  /// Identifies the type of the command object and of the handler.
  String get kind;
26 27

  /// Serializes this command to parameter name/value pairs.
28
  @mustCallSuper
29 30 31 32
  Map<String, String> serialize() => <String, String>{
    'command': kind,
    'timeout': '${timeout.inMilliseconds}',
  };
33 34
}

35
/// An object sent from a Flutter application back to the Flutter Driver in
36
/// response to a command.
Ian Hickson's avatar
Ian Hickson committed
37
abstract class Result { // ignore: one_member_abstracts
38 39 40
  /// Serializes this message to a JSON map.
  Map<String, dynamic> toJson();
}