main_test.dart 5.42 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2014 The Flutter 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 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;

Future<void> main() async {
9
  late FlutterDriver driver;
10 11 12 13 14 15 16 17 18 19 20

  setUpAll(() async {
    driver = await FlutterDriver.connect();
  });

  tearDownAll(() {
    driver.close();
  });

  // Each test below must return back to the home page after finishing.
  test('MotionEvent recomposition', () async {
21
    final SerializableFinder motionEventsListTile = find.byValueKey('MotionEventsListTile');
22 23 24 25 26 27
    await driver.tap(motionEventsListTile);
    await driver.waitFor(find.byValueKey('PlatformView'));
    final String errorMessage = await driver.requestData('run test');
    expect(errorMessage, '');
    final SerializableFinder backButton = find.byValueKey('back');
    await driver.tap(backButton);
28
  }, timeout: Timeout.none);
29

30
  group('Nested View Event', () {
31 32 33 34 35 36 37 38 39 40 41 42
    setUpAll(() async {
      final SerializableFinder wmListTile =
      find.byValueKey('NestedViewEventTile');
      await driver.tap(wmListTile);
    });

    tearDownAll(() async {
      await driver.waitFor(find.pageBack());
      await driver.tap(find.pageBack());
    });

    test('AlertDialog from platform view context', () async {
43
      final SerializableFinder showAlertDialog = find.byValueKey('ShowAlertDialog');
44 45 46 47
      await driver.waitFor(showAlertDialog);
      await driver.tap(showAlertDialog);
      final String status = await driver.getText(find.byValueKey('Status'));
      expect(status, 'Success');
48
    }, timeout: Timeout.none);
49 50 51 52 53 54 55

    test('Child view can handle touches', () async {
      final SerializableFinder addChildView = find.byValueKey('AddChildView');
      await driver.waitFor(addChildView);
      await driver.tap(addChildView);
      final SerializableFinder tapChildView = find.byValueKey('TapChildView');
      await driver.tap(tapChildView);
56 57
      final String nestedViewClickCount =
        await driver.getText(find.byValueKey('NestedViewClickCount'));
58
      expect(nestedViewClickCount, 'Click count: 1');
59
    }, timeout: Timeout.none);
60
  });
61

62
  group('Flutter surface without hybrid composition', () {
63
    setUpAll(() async {
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
      await driver.tap(find.byValueKey('NestedViewEventTile'));
    });

    tearDownAll(() async {
      await driver.waitFor(find.pageBack());
      await driver.tap(find.pageBack());
    });

    test('Uses FlutterSurfaceView when Android view is on the screen', () async {
      await driver.waitFor(find.byValueKey('PlatformView'));

      expect(
        await driver.requestData('hierarchy'),
        '|-FlutterView\n'
        '  |-FlutterSurfaceView\n' // Flutter UI
        '  |-ViewGroup\n'  // Platform View
        '    |-ViewGroup\n'
      );

      // Hide platform view.
      final SerializableFinder togglePlatformView = find.byValueKey('TogglePlatformView');
      await driver.tap(togglePlatformView);
      await driver.waitForAbsent(find.byValueKey('PlatformView'));

      expect(
        await driver.requestData('hierarchy'),
        '|-FlutterView\n'
        '  |-FlutterSurfaceView\n' // Just the Flutter UI
      );

      // Show platform view again.
      await driver.tap(togglePlatformView);
      await driver.waitFor(find.byValueKey('PlatformView'));

      expect(
        await driver.requestData('hierarchy'),
        '|-FlutterView\n'
        '  |-FlutterSurfaceView\n' // Flutter UI
        '  |-ViewGroup\n' // Platform View
        '    |-ViewGroup\n'
      );
    }, timeout: Timeout.none);
  });

  group('Flutter surface with hybrid composition', () {
    setUpAll(() async {
      await driver.tap(find.byValueKey('NestedViewEventTile'));
      await driver.tap(find.byValueKey('ToggleHybridComposition'));
      await driver.tap(find.byValueKey('TogglePlatformView'));
      await driver.tap(find.byValueKey('TogglePlatformView'));
114 115 116 117 118 119 120 121 122 123 124 125 126
    });

    tearDownAll(() async {
      await driver.waitFor(find.pageBack());
      await driver.tap(find.pageBack());
    });

    test('Uses FlutterImageView when Android view is on the screen', () async {
      await driver.waitFor(find.byValueKey('PlatformView'));

      expect(
        await driver.requestData('hierarchy'),
        '|-FlutterView\n'
127 128
        '  |-FlutterSurfaceView\n'  // Flutter UI (hidden)
        '  |-FlutterImageView\n' // Flutter UI (background surface)
129 130
        '  |-ViewGroup\n'  // Platform View
        '    |-ViewGroup\n'
131
        '  |-FlutterImageView\n'  // Flutter UI (overlay surface)
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
      );

      // Hide platform view.
      final SerializableFinder togglePlatformView = find.byValueKey('TogglePlatformView');
      await driver.tap(togglePlatformView);
      await driver.waitForAbsent(find.byValueKey('PlatformView'));

      expect(
        await driver.requestData('hierarchy'),
        '|-FlutterView\n'
        '  |-FlutterSurfaceView\n' // Just the Flutter UI
      );

      // Show platform view again.
      await driver.tap(togglePlatformView);
      await driver.waitFor(find.byValueKey('PlatformView'));

      expect(
        await driver.requestData('hierarchy'),
        '|-FlutterView\n'
152 153
        '  |-FlutterSurfaceView\n' // Flutter UI (hidden)
        '  |-FlutterImageView\n' // Flutter UI (background surface)
154 155
        '  |-ViewGroup\n' // Platform View
        '    |-ViewGroup\n'
156
        '  |-FlutterImageView\n' // Flutter UI (overlay surface)
157
      );
158
    }, timeout: Timeout.none);
159
  });
160
}