"Fossies" - the Fresh Open Source Software Archive 
Member "flutter-3.7.0/dev/devicelab/test/adb_test.dart" (24 Jan 2023, 7271 Bytes) of package /linux/misc/flutter-3.7.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "adb_test.dart":
3.3.10_vs_3.7.0.
1 // Copyright 2014 The Flutter 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 'package:collection/collection.dart' show ListEquality, MapEquality;
6
7 import 'package:flutter_devicelab/framework/devices.dart';
8 import 'package:meta/meta.dart';
9
10 import 'common.dart';
11
12 void main() {
13 group('device', () {
14 late Device device;
15
16 setUp(() {
17 FakeDevice.resetLog();
18 device = FakeDevice(deviceId: 'fakeDeviceId');
19 });
20
21 tearDown(() {
22 });
23
24 group('cpu check', () {
25 test('arm64', () async {
26 FakeDevice.pretendArm64();
27 final AndroidDevice androidDevice = device as AndroidDevice;
28 expect(await androidDevice.isArm64(), isTrue);
29 expectLog(<CommandArgs>[
30 cmd(command: 'getprop', arguments: <String>['ro.bootimage.build.fingerprint', ';', 'getprop', 'ro.build.version.release', ';', 'getprop', 'ro.build.version.sdk']),
31 cmd(command: 'getprop', arguments: <String>['ro.product.cpu.abi']),
32 ]);
33 });
34 });
35
36 group('isAwake/isAsleep', () {
37 test('reads Awake', () async {
38 FakeDevice.pretendAwake();
39 expect(await device.isAwake(), isTrue);
40 expect(await device.isAsleep(), isFalse);
41 });
42
43 test('reads Awake - samsung devices', () async {
44 FakeDevice.pretendAwakeSamsung();
45 expect(await device.isAwake(), isTrue);
46 expect(await device.isAsleep(), isFalse);
47 });
48
49 test('reads Asleep', () async {
50 FakeDevice.pretendAsleep();
51 expect(await device.isAwake(), isFalse);
52 expect(await device.isAsleep(), isTrue);
53 });
54 });
55
56 group('togglePower', () {
57 test('sends power event', () async {
58 await device.togglePower();
59 expectLog(<CommandArgs>[
60 cmd(command: 'getprop', arguments: <String>['ro.bootimage.build.fingerprint', ';', 'getprop', 'ro.build.version.release', ';', 'getprop', 'ro.build.version.sdk']),
61 cmd(command: 'input', arguments: <String>['keyevent', '26']),
62 ]);
63 });
64 });
65
66 group('wakeUp', () {
67 test('when awake', () async {
68 FakeDevice.pretendAwake();
69 await device.wakeUp();
70 expectLog(<CommandArgs>[
71 cmd(command: 'getprop', arguments: <String>['ro.bootimage.build.fingerprint', ';', 'getprop', 'ro.build.version.release', ';', 'getprop', 'ro.build.version.sdk']),
72 cmd(command: 'dumpsys', arguments: <String>['power']),
73 ]);
74 });
75
76 test('when asleep', () async {
77 FakeDevice.pretendAsleep();
78 await device.wakeUp();
79 expectLog(<CommandArgs>[
80 cmd(command: 'getprop', arguments: <String>['ro.bootimage.build.fingerprint', ';', 'getprop', 'ro.build.version.release', ';', 'getprop', 'ro.build.version.sdk']),
81 cmd(command: 'dumpsys', arguments: <String>['power']),
82 cmd(command: 'input', arguments: <String>['keyevent', '26']),
83 ]);
84 });
85 });
86
87 group('sendToSleep', () {
88 test('when asleep', () async {
89 FakeDevice.pretendAsleep();
90 await device.sendToSleep();
91 expectLog(<CommandArgs>[
92 cmd(command: 'getprop', arguments: <String>['ro.bootimage.build.fingerprint', ';', 'getprop', 'ro.build.version.release', ';', 'getprop', 'ro.build.version.sdk']),
93 cmd(command: 'dumpsys', arguments: <String>['power']),
94 ]);
95 });
96
97 test('when awake', () async {
98 FakeDevice.pretendAwake();
99 await device.sendToSleep();
100 expectLog(<CommandArgs>[
101 cmd(command: 'getprop', arguments: <String>['ro.bootimage.build.fingerprint', ';', 'getprop', 'ro.build.version.release', ';', 'getprop', 'ro.build.version.sdk']),
102 cmd(command: 'dumpsys', arguments: <String>['power']),
103 cmd(command: 'input', arguments: <String>['keyevent', '26']),
104 ]);
105 });
106 });
107
108 group('unlock', () {
109 test('sends unlock event', () async {
110 FakeDevice.pretendAwake();
111 await device.unlock();
112 expectLog(<CommandArgs>[
113 cmd(command: 'getprop', arguments: <String>['ro.bootimage.build.fingerprint', ';', 'getprop', 'ro.build.version.release', ';', 'getprop', 'ro.build.version.sdk']),
114 cmd(command: 'dumpsys', arguments: <String>['power']),
115 cmd(command: 'input', arguments: <String>['keyevent', '82']),
116 ]);
117 });
118 });
119
120 group('adb', () {
121 test('tap', () async {
122 await device.tap(100, 200);
123 expectLog(<CommandArgs>[
124 cmd(command: 'getprop', arguments: <String>['ro.bootimage.build.fingerprint', ';', 'getprop', 'ro.build.version.release', ';', 'getprop', 'ro.build.version.sdk']),
125 cmd(command: 'input', arguments: <String>['tap', '100', '200']),
126 ]);
127 });
128 });
129 });
130 }
131
132 void expectLog(List<CommandArgs> log) {
133 expect(FakeDevice.commandLog, log);
134 }
135
136 CommandArgs cmd({
137 required String command,
138 List<String>? arguments,
139 Map<String, String>? environment,
140 }) {
141 return CommandArgs(
142 command: command,
143 arguments: arguments,
144 environment: environment,
145 );
146 }
147
148 @immutable
149 class CommandArgs {
150 const CommandArgs({ required this.command, this.arguments, this.environment });
151
152 final String command;
153 final List<String>? arguments;
154 final Map<String, String>? environment;
155
156 @override
157 String toString() => 'CommandArgs(command: $command, arguments: $arguments, environment: $environment)';
158
159 @override
160 bool operator==(Object other) {
161 if (other.runtimeType != CommandArgs) {
162 return false;
163 }
164 return other is CommandArgs
165 && other.command == command
166 && const ListEquality<String>().equals(other.arguments, arguments)
167 && const MapEquality<String, String>().equals(other.environment, environment);
168 }
169
170 @override
171 int get hashCode {
172 return Object.hash(
173 command,
174 Object.hashAll(arguments ?? const <String>[]),
175 Object.hashAllUnordered(environment?.keys ?? const <String>[]),
176 Object.hashAllUnordered(environment?.values ?? const <String>[]),
177 );
178 }
179 }
180
181 class FakeDevice extends AndroidDevice {
182 FakeDevice({required super.deviceId});
183
184 static String output = '';
185
186 static List<CommandArgs> commandLog = <CommandArgs>[];
187
188 static void resetLog() {
189 commandLog.clear();
190 }
191
192 static void pretendAwake() {
193 output = '''
194 mWakefulness=Awake
195 ''';
196 }
197
198 static void pretendAwakeSamsung() {
199 output = '''
200 getWakefulnessLocked()=Awake
201 ''';
202 }
203
204 static void pretendAsleep() {
205 output = '''
206 mWakefulness=Asleep
207 ''';
208 }
209
210 static void pretendArm64() {
211 output = '''
212 arm64
213 ''';
214 }
215
216 @override
217 Future<String> shellEval(String command, List<String> arguments, { Map<String, String>? environment, bool silent = false }) async {
218 commandLog.add(CommandArgs(
219 command: command,
220 arguments: arguments,
221 environment: environment,
222 ));
223 return output;
224 }
225
226 @override
227 Future<void> shellExec(String command, List<String> arguments, { Map<String, String>? environment, bool silent = false }) async {
228 commandLog.add(CommandArgs(
229 command: command,
230 arguments: arguments,
231 environment: environment,
232 ));
233 }
234 }