Ian Hickson | 9adb4a7 | 2017-06-23 14:58:29 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
| 5 | import 'message.dart'; |
| 6 | |
Ian Hickson | 8f56f6f | 2017-07-21 16:39:04 -0700 | [diff] [blame] | 7 | /// A Flutter Driver command that sends a string to the application and expects a |
| 8 | /// string response. |
Ian Hickson | 9adb4a7 | 2017-06-23 14:58:29 -0700 | [diff] [blame] | 9 | class RequestData extends Command { |
Ian Hickson | 9adb4a7 | 2017-06-23 14:58:29 -0700 | [diff] [blame] | 10 | /// Create a command that sends a message. |
| 11 | RequestData(this.message, { Duration timeout }) : super(timeout: timeout); |
| 12 | |
Ian Hickson | 9adb4a7 | 2017-06-23 14:58:29 -0700 | [diff] [blame] | 13 | /// Deserializes this command from the value generated by [serialize]. |
| 14 | RequestData.deserialize(Map<String, String> params) |
Alexandre Ardhuin | 5de96bb | 2018-10-02 17:14:59 +0200 | [diff] [blame^] | 15 | : message = params['message'], |
Ian Hickson | 9adb4a7 | 2017-06-23 14:58:29 -0700 | [diff] [blame] | 16 | super.deserialize(params); |
| 17 | |
Ian Hickson | 8f56f6f | 2017-07-21 16:39:04 -0700 | [diff] [blame] | 18 | /// The message being sent from the test to the application. |
| 19 | final String message; |
| 20 | |
| 21 | @override |
| 22 | final String kind = 'request_data'; |
| 23 | |
Ian Hickson | 9adb4a7 | 2017-06-23 14:58:29 -0700 | [diff] [blame] | 24 | @override |
| 25 | Map<String, String> serialize() => super.serialize()..addAll(<String, String>{ |
| 26 | 'message': message, |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | /// The result of the [RequestData] command. |
| 31 | class RequestDataResult extends Result { |
| 32 | /// Creates a result with the given [message]. |
| 33 | RequestDataResult(this.message); |
| 34 | |
| 35 | /// The text extracted by the [RequestData] command. |
| 36 | final String message; |
| 37 | |
| 38 | /// Deserializes the result from JSON. |
| 39 | static RequestDataResult fromJson(Map<String, dynamic> json) { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 40 | return RequestDataResult(json['message']); |
Ian Hickson | 9adb4a7 | 2017-06-23 14:58:29 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | @override |
| 44 | Map<String, dynamic> toJson() => <String, String>{ |
| 45 | 'message': message, |
| 46 | }; |
| 47 | } |