1+ // Copyright (c) 2017 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 'dart:async' ;
6+ import 'dart:convert' ;
7+ import 'dart:io' ;
8+
9+ import 'package:path/path.dart' as path;
10+
11+ import 'package:flutter_devicelab/framework/adb.dart' ;
12+ import 'package:flutter_devicelab/framework/framework.dart' ;
13+ import 'package:flutter_devicelab/framework/utils.dart' ;
14+
15+ void main () {
16+ task (() async {
17+ final Device device = await devices.workingDevice;
18+ await device.unlock ();
19+ final Directory appDir = dir (path.join (flutterDirectory.path, 'dev/integration_tests/ui' ));
20+ await inDirectory (appDir, () async {
21+ final Completer <Null > ready = new Completer <Null >();
22+ bool ok;
23+ print ('run: starting...' );
24+ final Process run = await startProcess (
25+ path.join (flutterDirectory.path, 'bin' , 'flutter' ),
26+ < String > ['run' , '--verbose' , '--observatory-port=8888' , '-d' , device.deviceId, 'lib/commands.dart' ],
27+ );
28+ run.stdout
29+ .transform (UTF8 .decoder)
30+ .transform (const LineSplitter ())
31+ .listen ((String line) {
32+ print ('run:stdout: $line ' );
33+ if (line.contains (new RegExp (r'^\[\s+\] For a more detailed help message, press "h"\. To quit, press "q"\.' ))) {
34+ print ('run: ready!' );
35+ ready.complete ();
36+ ok ?? = true ;
37+ }
38+ });
39+ run.stderr
40+ .transform (UTF8 .decoder)
41+ .transform (const LineSplitter ())
42+ .listen ((String line) {
43+ stderr.writeln ('run:stderr: $line ' );
44+ });
45+ run.exitCode.then ((int exitCode) { ok = false ; });
46+ await Future .any <dynamic >(< Future <dynamic >> [ ready.future, run.exitCode ]);
47+ if (! ok)
48+ throw 'Failed to run test app.' ;
49+ await drive ('none' );
50+ print ('test: pressing "p" to enable debugPaintSize...' );
51+ run.stdin.write ('p' );
52+ await drive ('debug_paint' );
53+ print ('test: pressing "p" again...' );
54+ run.stdin.write ('p' );
55+ await drive ('none' );
56+ print ('test: pressing "P" to enable performance overlay...' );
57+ run.stdin.write ('P' );
58+ await drive ('performance_overlay' );
59+ print ('test: pressing "P" again...' );
60+ run.stdin.write ('P' );
61+ await drive ('none' );
62+ run.stdin.write ('q' );
63+ final int result = await run.exitCode;
64+ if (result != 0 )
65+ throw 'Received unexpected exit code $result from run process.' ;
66+ });
67+ return new TaskResult .success (null );
68+ });
69+ }
70+
71+ Future <Null > drive (String name) async {
72+ print ('drive: running commands_$name check...' );
73+ final Process drive = await startProcess (
74+ path.join (flutterDirectory.path, 'bin' , 'flutter' ),
75+ < String > ['drive' , '--use-existing-app' , 'http://127.0.0.1:8888/' , '--keep-app-running' , '--driver' , 'test_driver/commands_${name }_test.dart' ],
76+ );
77+ drive.stdout
78+ .transform (UTF8 .decoder)
79+ .transform (const LineSplitter ())
80+ .listen ((String line) {
81+ print ('drive:stdout: $line ' );
82+ });
83+ drive.stderr
84+ .transform (UTF8 .decoder)
85+ .transform (const LineSplitter ())
86+ .listen ((String line) {
87+ stderr.writeln ('drive:stderr: $line ' );
88+ });
89+ final int result = await drive.exitCode;
90+ if (result != 0 )
91+ throw 'Failed to drive test app (exit code $result ).' ;
92+ print ('drive: finished commands_$name check successfully.' );
93+ }
0 commit comments