main_test.dart 3.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// 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 {
  FlutterDriver driver;

  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 28 29
    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);
  });

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 48 49 50 51 52 53 54 55
      await driver.waitFor(showAlertDialog);
      await driver.tap(showAlertDialog);
      final String status = await driver.getText(find.byValueKey('Status'));
      expect(status, 'Success');
    });

    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 59 60
      expect(nestedViewClickCount, 'Click count: 1');
    });
  });
61 62 63 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

  group('Flutter surface switch', () {
    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('Uses FlutterImageView 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 (hidden)
        '  |-FlutterImageView\n' // Flutter UI (background surface)
        '  |-ViewGroup\n'  // Platform View
        '    |-ViewGroup\n'
        '  |-FlutterImageView\n'  // Flutter UI (overlay surface)
      );

      // 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 (hidden)
        '  |-FlutterImageView\n' // Flutter UI (background surface)
        '  |-ViewGroup\n' // Platform View
        '    |-ViewGroup\n'
        '  |-FlutterImageView\n' // Flutter UI (overlay surface)
      );
    });
  });
112
}