Add a test of an Android platform view that draws a gradient (#153878)

Closes https://github.com/flutter/flutter/issues/152376.

The gradient, for posterity, looks like this:

<img src="https://github.com/user-attachments/assets/bed9599a-4e16-499c-af79-b51980095e89" width="150">

Let's see if CI agrees!

/cc @johnmccutchan
This commit is contained in:
Matan Lurey
2024-08-23 11:25:40 -07:00
committed by GitHub
parent 327193af9a
commit 5e194383af
8 changed files with 189 additions and 17 deletions

View File

@@ -0,0 +1,47 @@
// 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:flutter_driver/src/native_driver.dart';
import 'package:test/test.dart';
import '_flutter_goldens_fork.dart';
// TODO(matanlurey): This is done automatically by 'flutter test' but not by
// 'flutter drive'. If we get closer to shipping the native 'flutter drive'
// command, we should look into if 'flutter_test_config.dart', or a similar
// mechanism, can be used to configure this automatically.
void main() async {
await testExecutable(_main);
}
Future<void> _main() async {
// To generate golden files locally, uncomment the following line.
// autoUpdateGoldenFiles = true;
late FlutterDriver flutterDriver;
late NativeDriver nativeDriver;
setUpAll(() async {
flutterDriver = await FlutterDriver.connect();
nativeDriver = await AndroidNativeDriver.connect();
});
tearDownAll(() async {
await nativeDriver.close();
await flutterDriver.close();
});
test(
'should screenshot and match a blue (top left) -> orange (bottom right) gradient',
() async {
await flutterDriver.waitFor(find.byType('AndroidView'));
await expectLater(
nativeDriver.screenshot(),
matchesGoldenFile('android_driver_test.BlueOrangeGradient.png'),
);
},
timeout: Timeout.none,
);
}

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io' as io;
import 'package:flutter_driver/flutter_driver.dart';
import 'package:flutter_driver/src/native_driver.dart';
import 'package:test/test.dart';
@@ -18,34 +16,27 @@ void main() async {
await testExecutable(_main);
}
final bool _isLuciCi = io.Platform.environment['LUCI_CI'] == 'True';
Future<void> _main() async {
// To generate golden files locally, uncomment the following line.
// autoUpdateGoldenFiles = true;
FlutterDriver? flutterDriver;
NativeDriver? nativeDriver;
late FlutterDriver flutterDriver;
late NativeDriver nativeDriver;
setUpAll(() async {
flutterDriver = await FlutterDriver.connect(
// TODO(matanlurey): Workaround log uploading in LUCI not being enabled.
// Default to true on CI because log uploading doesn't work.
// See <https://github.com/flutter/flutter/issues/152775>.
printCommunication: _isLuciCi,
);
flutterDriver = await FlutterDriver.connect();
nativeDriver = await AndroidNativeDriver.connect();
});
tearDownAll(() async {
await nativeDriver?.close();
await flutterDriver?.close();
await nativeDriver.close();
await flutterDriver.close();
});
test('should screenshot and match a full-screen blue rectangle', () async {
await flutterDriver?.waitFor(find.byType('DecoratedBox'));
await flutterDriver.waitFor(find.byType('DecoratedBox'));
await expectLater(
nativeDriver?.screenshot(),
nativeDriver.screenshot(),
matchesGoldenFile('android_driver_test.BlueRectangle.png'),
);
}, timeout: Timeout.none);