routing_test.dart 3.34 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as path;

import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart';

void main() {
  task(() async {
17 18
    int vmServicePort;

19 20 21 22 23 24 25 26 27 28 29 30 31
    final Device device = await devices.workingDevice;
    await device.unlock();
    final Directory appDir = dir(path.join(flutterDirectory.path, 'dev/integration_tests/ui'));
    section('TEST WHETHER `flutter drive --route` WORKS');
    await inDirectory(appDir, () async {
      return await flutter(
        'drive',
        options: <String>['--verbose', '-d', device.deviceId, '--route', '/smuggle-it', 'lib/route.dart'],
        canFail: false,
      );
    });
    section('TEST WHETHER `flutter run --route` WORKS');
    await inDirectory(appDir, () async {
32
      final Completer<void> ready = Completer<void>();
33 34 35 36
      bool ok;
      print('run: starting...');
      final Process run = await startProcess(
        path.join(flutterDirectory.path, 'bin', 'flutter'),
37 38
        // --fast-start does not support routes.
        <String>['run', '--verbose', '--disable-service-auth-codes', '--no-fast-start', '-d', device.deviceId, '--route', '/smuggle-it', 'lib/route.dart'],
39 40
      );
      run.stdout
41 42
        .transform<String>(utf8.decoder)
        .transform<String>(const LineSplitter())
43 44
        .listen((String line) {
          print('run:stdout: $line');
45
          if (vmServicePort == null) {
46
            vmServicePort = parseServicePort(line);
47 48 49 50 51 52
            if (vmServicePort != null) {
              print('service protocol connection available at port $vmServicePort');
              print('run: ready!');
              ready.complete();
              ok ??= true;
            }
53 54 55
          }
        });
      run.stderr
56 57
        .transform<String>(utf8.decoder)
        .transform<String>(const LineSplitter())
58 59 60
        .listen((String line) {
          stderr.writeln('run:stderr: $line');
        });
61
      run.exitCode.then<void>((int exitCode) { ok = false; });
62 63 64 65 66 67
      await Future.any<dynamic>(<Future<dynamic>>[ ready.future, run.exitCode ]);
      if (!ok)
        throw 'Failed to run test app.';
      print('drive: starting...');
      final Process drive = await startProcess(
        path.join(flutterDirectory.path, 'bin', 'flutter'),
68
        <String>['drive', '--use-existing-app', 'http://127.0.0.1:$vmServicePort/', '--no-keep-app-running', 'lib/route.dart'],
69 70
      );
      drive.stdout
71 72
        .transform<String>(utf8.decoder)
        .transform<String>(const LineSplitter())
73 74 75 76
        .listen((String line) {
          print('drive:stdout: $line');
        });
      drive.stderr
77 78
        .transform<String>(utf8.decoder)
        .transform<String>(const LineSplitter())
79 80 81 82 83 84 85 86 87 88 89
        .listen((String line) {
          stderr.writeln('drive:stderr: $line');
        });
      int result;
      result = await drive.exitCode;
      if (result != 0)
        throw 'Failed to drive test app (exit code $result).';
      result = await run.exitCode;
      if (result != 0)
        throw 'Received unexpected exit code $result from run process.';
    });
90
    return TaskResult.success(null);
91 92
  });
}