integration_tests.dart 4.1 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// 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
import '../framework/adb.dart';
import '../framework/framework.dart';
import '../framework/utils.dart';

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

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

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

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

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

49 50 51 52 53 54 55
TaskFunction createPlatformChannelSwiftSampleTest() {
  return DriverTest(
    '${flutterDirectory.path}/examples/platform_channel_swift',
    'test_driver/button_tap.dart',
  );
}

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

63
TaskFunction createAndroidSemanticsIntegrationTest() {
64
  return DriverTest(
65 66 67 68 69
    '${flutterDirectory.path}/dev/integration_tests/android_semantics_testing',
    'lib/main.dart',
  );
}

70 71 72 73 74
TaskFunction createCodegenerationIntegrationTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/codegen',
    'lib/main.dart',
    environment: <String, String>{
75
      'FLUTTER_EXPERIMENTAL_BUILD': 'true',
76 77 78 79
    },
  );
}

80 81 82 83 84 85 86
TaskFunction createImageLoadingIntegrationTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/image_loading',
    'lib/main.dart',
  );
}

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
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);
  };
}

103 104 105 106 107 108 109
TaskFunction createAndroidSplashScreenKitchenSinkTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/android_splash_screens/splash_screen_kitchen_sink',
    'test_driver/main.dart',
  );
}

110 111 112 113 114 115 116
TaskFunction createFlutterDriverScreenshotTest() {
  return DriverTest(
    '${flutterDirectory.path}/dev/integration_tests/flutter_driver_screenshot_test',
    'lib/main.dart',
  );
}

117 118
class DriverTest {

119 120 121 122
  DriverTest(
    this.testDirectory,
    this.testTarget, {
      this.extraOptions = const <String>[],
123
      this.environment =  const <String, String>{},
124 125
    }
  );
126 127 128

  final String testDirectory;
  final String testTarget;
129
  final List<String> extraOptions;
130
  final Map<String, String> environment;
131 132

  Future<TaskResult> call() {
133
    return inDirectory<TaskResult>(testDirectory, () async {
134 135 136 137 138
      final Device device = await devices.workingDevice;
      await device.unlock();
      final String deviceId = device.deviceId;
      await flutter('packages', options: <String>['get']);

139
      final List<String> options = <String>[
140 141 142 143 144
        '-v',
        '-t',
        testTarget,
        '-d',
        deviceId,
145
        ...extraOptions,
146
      ];
147
      await flutter('drive', options: options, environment: Map<String, String>.from(environment));
148

149
      return TaskResult.success(null);
150 151 152
    });
  }
}