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 5import 'find.dart'; 6import 'message.dart'; 7 8/// A Flutter Driver command that taps on a target widget located by [finder]. 9class Tap extends CommandWithTarget { 10 /// Creates a tap command to tap on a widget located by [finder]. 11 Tap(SerializableFinder finder, { Duration timeout }) : super(finder, timeout: timeout); 12 13 /// Deserializes this command from the value generated by [serialize]. 14 Tap.deserialize(Map<String, String> json) : super.deserialize(json); 15 16 @override 17 String get kind => 'tap'; 18} 19 20/// The result of a [Tap] command. 21class TapResult extends Result { 22 /// Creates a [TapResult]. 23 const TapResult(); 24 25 /// Deserializes this result from JSON. 26 static TapResult fromJson(Map<String, dynamic> json) { 27 return const TapResult(); 28 } 29 30 @override 31 Map<String, dynamic> toJson() => <String, dynamic>{}; 32} 33 34 35/// A Flutter Driver command that commands the driver to perform a scrolling action. 36class Scroll extends CommandWithTarget { 37 /// Creates a scroll command that will attempt to scroll a scrollable view by 38 /// dragging a widget located by the given [finder]. 39 Scroll( 40 SerializableFinder finder, 41 this.dx, 42 this.dy, 43 this.duration, 44 this.frequency, { 45 Duration timeout, 46 }) : super(finder, timeout: timeout); 47 48 /// Deserializes this command from the value generated by [serialize]. 49 Scroll.deserialize(Map<String, String> json) 50 : dx = double.parse(json['dx']), 51 dy = double.parse(json['dy']), 52 duration = Duration(microseconds: int.parse(json['duration'])), 53 frequency = int.parse(json['frequency']), 54 super.deserialize(json); 55 56 /// Delta X offset per move event. 57 final double dx; 58 59 /// Delta Y offset per move event. 60 final double dy; 61 62 /// The duration of the scrolling action 63 final Duration duration; 64 65 /// The frequency in Hz of the generated move events. 66 final int frequency; 67 68 @override 69 String get kind => 'scroll'; 70 71 @override 72 Map<String, String> serialize() => super.serialize()..addAll(<String, String>{ 73 'dx': '$dx', 74 'dy': '$dy', 75 'duration': '${duration.inMicroseconds}', 76 'frequency': '$frequency', 77 }); 78} 79 80/// The result of a [Scroll] command. 81class ScrollResult extends Result { 82 /// Creates a [ScrollResult]. 83 const ScrollResult(); 84 85 /// Deserializes this result from JSON. 86 static ScrollResult fromJson(Map<String, dynamic> json) { 87 return const ScrollResult(); 88 } 89 90 @override 91 Map<String, dynamic> toJson() => <String, dynamic>{}; 92} 93 94/// A Flutter Driver command that commands the driver to ensure that the element 95/// represented by [finder] has been scrolled completely into view. 96class ScrollIntoView extends CommandWithTarget { 97 /// Creates this command given a [finder] used to locate the widget to be 98 /// scrolled into view. 99 ScrollIntoView(SerializableFinder finder, { this.alignment = 0.0, Duration timeout }) : super(finder, timeout: timeout); 100 101 /// Deserializes this command from the value generated by [serialize]. 102 ScrollIntoView.deserialize(Map<String, String> json) 103 : alignment = double.parse(json['alignment']), 104 super.deserialize(json); 105 106 /// How the widget should be aligned. 107 /// 108 /// This value is passed to [Scrollable.ensureVisible] as the value of its 109 /// argument of the same name. 110 /// 111 /// Defaults to 0.0. 112 final double alignment; 113 114 @override 115 String get kind => 'scrollIntoView'; 116 117 @override 118 Map<String, String> serialize() => super.serialize()..addAll(<String, String>{ 119 'alignment': '$alignment', 120 }); 121} 122