integration_tests.dart 3.7 KB
Newer Older
1 2 3 4 5
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
6
import 'dart:io';
7

8
import 'package:path/path.dart' as path;
9 10 11 12 13 14
import '../framework/adb.dart';
import '../framework/framework.dart';
import '../framework/ios.dart';
import '../framework/utils.dart';

TaskFunction createChannelsIntegrationTest() {
15
  return DriverTest(
16 17 18 19 20
    '${flutterDirectory.path}/dev/integration_tests/channels',
    'lib/main.dart',
  );
}

21
TaskFunction createPlatformInteractionTest() {
22
  return DriverTest(
23 24 25 26 27
    '${flutterDirectory.path}/dev/integration_tests/platform_interaction',
    'lib/main.dart',
  );
}

28
TaskFunction createFlavorsTest() {
29
  return DriverTest(
30 31
    '${flutterDirectory.path}/dev/integration_tests/flavors',
    'lib/main.dart',
32
    extraOptions: <String>['--flavor', 'paid'],
33 34 35
  );
}

36
TaskFunction createExternalUiIntegrationTest() {
37
  return DriverTest(
38 39 40 41 42
    '${flutterDirectory.path}/dev/integration_tests/external_ui',
    'lib/main.dart',
  );
}

43
TaskFunction createPlatformChannelSampleTest() {
44
  return DriverTest(
45 46 47 48 49
    '${flutterDirectory.path}/examples/platform_channel',
    'test_driver/button_tap.dart',
  );
}

50
TaskFunction createEmbeddedAndroidViewsIntegrationTest() {
51
  return DriverTest(
52 53 54 55 56
    '${flutterDirectory.path}/dev/integration_tests/android_views',
    'lib/main.dart',
  );
}

57
TaskFunction createAndroidSemanticsIntegrationTest() {
58
  return DriverTest(
59 60 61 62 63
    '${flutterDirectory.path}/dev/integration_tests/android_semantics_testing',
    'lib/main.dart',
  );
}

64 65 66 67 68
TaskFunction createCodegenerationIntegrationTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/codegen',
    'lib/main.dart',
    environment: <String, String>{
69
      'FLUTTER_EXPERIMENTAL_BUILD': 'true',
70 71 72 73
    },
  );
}

74 75 76 77 78 79 80
TaskFunction createImageLoadingIntegrationTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/image_loading',
    'lib/main.dart',
  );
}

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
TaskFunction createFlutterCreateOfflineTest() {
  return () async {
    final Directory tempDir = Directory.systemTemp.createTempSync('flutter_create_test.');
    String output;
    await inDirectory(tempDir, () async {
      output = await eval(path.join(flutterDirectory.path, 'bin', 'flutter'), <String>['create', '--offline', 'flutter_create_test']);
    });
    if (output.contains(RegExp('building flutter tool', caseSensitive: false))) {
      return TaskResult.failure('`flutter create --offline` should not rebuild flutter tool');
    } else if (!output.contains('All done!')) {
      return TaskResult.failure('`flutter create` failed');
    }
    return TaskResult.success(null);
  };
}

97 98
class DriverTest {

99 100 101 102
  DriverTest(
    this.testDirectory,
    this.testTarget, {
      this.extraOptions = const <String>[],
103
      this.environment =  const <String, String>{},
104 105
    }
  );
106 107 108

  final String testDirectory;
  final String testTarget;
109
  final List<String> extraOptions;
110
  final Map<String, String> environment;
111 112

  Future<TaskResult> call() {
113
    return inDirectory<TaskResult>(testDirectory, () async {
114 115 116 117 118
      final Device device = await devices.workingDevice;
      await device.unlock();
      final String deviceId = device.deviceId;
      await flutter('packages', options: <String>['get']);

119
      if (deviceOperatingSystem == DeviceOperatingSystem.ios)
120
        await prepareProvisioningCertificates(testDirectory);
121
      final List<String> options = <String>[
122 123 124 125 126
        '-v',
        '-t',
        testTarget,
        '-d',
        deviceId,
127 128
      ];
      options.addAll(extraOptions);
129
      await flutter('drive', options: options, environment: Map<String, String>.from(environment));
130

131
      return TaskResult.success(null);
132 133 134
    });
  }
}