Move most of the dart:ui tests to package:test. (flutter/engine#55090)

Work towards https://github.com/flutter/flutter/issues/133569.

There are a couple with custom matchers I'd like to migrate in a follow-up PR.
This commit is contained in:
Matan Lurey
2024-09-11 16:46:07 -07:00
committed by GitHub
parent 647e6f004f
commit bc84a70c7f
39 changed files with 86 additions and 76 deletions

View File

@@ -7,7 +7,7 @@ import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('Loading an asset that does not exist returns null', () async {
@@ -81,7 +81,7 @@ void main() {
final List<int> bundledFontImage = await _createPictureFromFont('Roboto2');
// Bundling fonts is disabled, so the font selected in both cases should be ahem.
// Therefore each buffer will contain identical contents.
expect(ahemImage, notEquals(bundledFontImage));
expect(ahemImage, isNot(bundledFontImage));
});
}

View File

@@ -9,7 +9,7 @@ import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
ByteData _makeByteData(String str) {
final Uint8List list = utf8.encode(str);

View File

@@ -6,8 +6,8 @@ import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'impeller_enabled.dart';

View File

@@ -5,7 +5,7 @@
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
import 'impeller_enabled.dart';

View File

@@ -5,7 +5,7 @@
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('Scene.toImageSync succeeds', () async {
@@ -76,7 +76,7 @@ void main() {
if (assertsEnabled) {
expect(
() => builder.addPicture(Offset.zero, picture),
throwsA(isInstanceOf<AssertionError>()),
throwsA(const isInstanceOf<AssertionError>()),
);
} else {
builder.addPicture(Offset.zero, picture);
@@ -105,7 +105,7 @@ void main() {
assert(() {
expect(
() => builder.pushTransform(matrix4WrongLength),
expectAssertion,
throwsA(isA<AssertionError>()),
);
return true;
}());
@@ -119,7 +119,7 @@ void main() {
assert(() {
expect(
() => builder.pushTransform(matrix4NaN),
expectAssertion,
throwsA(isA<AssertionError>()),
);
return true;
}());
@@ -133,7 +133,7 @@ void main() {
assert(() {
expect(
() => builder.pushTransform(matrix4Infinity),
expectAssertion,
throwsA(isA<AssertionError>()),
);
return true;
}());

View File

@@ -4,7 +4,7 @@
import 'dart:async';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
/// Verifies Dart semantics governed by flags set by Flutter tooling.
void main() {

View File

@@ -7,8 +7,8 @@ import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'impeller_enabled.dart';

View File

@@ -9,7 +9,7 @@ import 'dart:math' as math show sqrt;
import 'dart:math' show pi;
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('OffsetBase.>=', () {
@@ -47,8 +47,8 @@ void main() {
test('OffsetBase.==', () {
expect(const Offset(0, 0), equals(const Offset(0, 0)));
expect(const Offset(0, 0), notEquals(const Offset(1, 0)));
expect(const Offset(0, 0), notEquals(const Offset(0, 1)));
expect(const Offset(0, 0), isNot(const Offset(1, 0)));
expect(const Offset(0, 0), isNot(const Offset(0, 1)));
});
test('Offset.direction', () {
@@ -392,28 +392,28 @@ void main() {
const Rect.fromLTRB(10.0, 20.0, 30.0, 40.0),
topLeft: const Radius.circular(-1),
);
}, throwsA(isInstanceOf<AssertionError>()));
}, throwsA(const isInstanceOf<AssertionError>()));
expect(() {
RRect.fromRectAndCorners(
const Rect.fromLTRB(10.0, 20.0, 30.0, 40.0),
topRight: const Radius.circular(-2),
);
}, throwsA(isInstanceOf<AssertionError>()));
}, throwsA(const isInstanceOf<AssertionError>()));
expect(() {
RRect.fromRectAndCorners(
const Rect.fromLTRB(10.0, 20.0, 30.0, 40.0),
bottomLeft: const Radius.circular(-3),
);
}, throwsA(isInstanceOf<AssertionError>()));
}, throwsA(const isInstanceOf<AssertionError>()));
expect(() {
RRect.fromRectAndCorners(
const Rect.fromLTRB(10.0, 20.0, 30.0, 40.0),
bottomRight: const Radius.circular(-4),
);
}, throwsA(isInstanceOf<AssertionError>()));
}, throwsA(const isInstanceOf<AssertionError>()));
});
test('RRect.inflate clamps when deflating past zero', () {

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('GestureSettings has a reasonable toString', () {
@@ -23,11 +23,11 @@ void main() {
expect(settingsA, equals(settingsC));
expect(settingsC, equals(settingsA));
expect(settingsA, notEquals(settingsB));
expect(settingsC, notEquals(settingsB));
expect(settingsA, isNot(settingsB));
expect(settingsC, isNot(settingsB));
expect(settingsB, notEquals(settingsA));
expect(settingsB, notEquals(settingsC));
expect(settingsB, isNot(settingsA));
expect(settingsB, isNot(settingsC));
});
test('GestureSettings copyWith preserves already set values', () {

View File

@@ -7,7 +7,7 @@
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
import '../../lib/gpu/lib/gpu.dart' as gpu;
import 'impeller_enabled.dart';

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('Gradient.radial with no focal point', () {
@@ -64,7 +64,7 @@ void main() {
Offset.zero,
1.0,
),
expectAssertion,
throwsA(isA<AssertionError>()),
);
return true;
}());

View File

@@ -5,7 +5,7 @@
import 'dart:async';
import 'dart:io';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
import 'http_disallow_http_connections_test.dart';

View File

@@ -7,7 +7,7 @@
import 'dart:async';
import 'dart:io';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
typedef FutureFunction = Future<Object?> Function();

View File

@@ -7,8 +7,8 @@ import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
void main() {
test('basic image descriptor - encoded - greyscale', () async {

View File

@@ -6,8 +6,8 @@ import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
void main() {
bool assertsEnabled = false;

View File

@@ -5,7 +5,7 @@
import 'dart:async';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('Image constructor and dispose invokes onCreate once', () async {

View File

@@ -7,8 +7,8 @@ import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
void main() {
bool assertsEnabled = false;

View File

@@ -5,7 +5,7 @@
import 'dart:async';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('toImage succeeds', () async {

View File

@@ -6,7 +6,7 @@ import 'dart:async';
import 'dart:isolate';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
const int kErrorCode = -1;
const int kStartCode = 0;

View File

@@ -5,7 +5,7 @@
import 'dart:isolate';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('Invalid isolate URI', () async {

View File

@@ -4,7 +4,9 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
const precisionErrorTolerance = 1e-4;
// These tests should be kept in sync with the web tests in
// lib/web_ui/test/lerp_test.dart.
@@ -103,23 +105,23 @@ void main() {
});
test('lerpDouble should throw AssertionError if interpolation value is NaN and a != b', () {
expectAssertion(() => lerpDouble(0.0, 10.0, double.nan));
expect(() => lerpDouble(0.0, 10.0, double.nan), throwsA(isA<AssertionError>()));
});
test('lerpDouble should throw AssertionError if interpolation value is +/- infinity and a != b', () {
expectAssertion(() => lerpDouble(0.0, 10.0, double.infinity));
expectAssertion(() => lerpDouble(0.0, 10.0, -double.infinity));
expect(() => lerpDouble(0.0, 10.0, double.infinity), throwsA(isA<AssertionError>()));
expect(() => lerpDouble(0.0, 10.0, -double.infinity), throwsA(isA<AssertionError>()));
});
test('lerpDouble should throw AssertionError if either start or end are NaN', () {
expectAssertion(() => lerpDouble(double.nan, 10.0, 5.0));
expectAssertion(() => lerpDouble(0.0, double.nan, 5.0));
expect(() => lerpDouble(double.nan, 10.0, 5.0), throwsA(isA<AssertionError>()));
expect(() => lerpDouble(0.0, double.nan, 5.0), throwsA(isA<AssertionError>()));
});
test('lerpDouble should throw AssertionError if either start or end are +/- infinity', () {
expectAssertion(() => lerpDouble(double.infinity, 10.0, 5.0));
expectAssertion(() => lerpDouble(-double.infinity, 10.0, 5.0));
expectAssertion(() => lerpDouble(0.0, double.infinity, 5.0));
expectAssertion(() => lerpDouble(0.0, -double.infinity, 5.0));
expect(() => lerpDouble(double.infinity, 10.0, 5.0), throwsA(isA<AssertionError>()));
expect(() => lerpDouble(-double.infinity, 10.0, 5.0), throwsA(isA<AssertionError>()));
expect(() => lerpDouble(0.0, double.infinity, 5.0), throwsA(isA<AssertionError>()));
expect(() => lerpDouble(0.0, -double.infinity, 5.0), throwsA(isA<AssertionError>()));
});
}

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('Locale', () {
@@ -45,19 +45,19 @@ void main() {
test('Locale equality', () {
expect(const Locale.fromSubtags(languageCode: 'en'),
notEquals(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn')));
isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn')));
expect(const Locale.fromSubtags(languageCode: 'en').hashCode,
notEquals(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode));
isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode));
expect(const Locale('en', ''), const Locale('en'));
expect(const Locale('en'), const Locale('en', ''));
expect(const Locale('en'), const Locale('en'));
expect(const Locale('en', ''), const Locale('en', ''));
expect(const Locale('en', ''), notEquals(const Locale('en', 'GB')));
expect(const Locale('en'), notEquals(const Locale('en', 'GB')));
expect(const Locale('en', 'GB'), notEquals(const Locale('en', '')));
expect(const Locale('en', 'GB'), notEquals(const Locale('en')));
expect(const Locale('en', ''), isNot(const Locale('en', 'GB')));
expect(const Locale('en'), isNot(const Locale('en', 'GB')));
expect(const Locale('en', 'GB'), isNot(const Locale('en', '')));
expect(const Locale('en', 'GB'), isNot(const Locale('en')));
});
test("Locale toString does not include separator for ''", () {

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('MaskFilter - NOP blur does not crash', () async {

View File

@@ -5,7 +5,7 @@
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
import 'package:vector_math/vector_math_64.dart';
typedef CanvasCallback = void Function(Canvas canvas);

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('Should be able to build and layout a paragraph', () {

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
// Ahem font uses a constant ideographic/alphabetic baseline ratio.
@@ -311,7 +311,7 @@ void main() {
final GlyphInfo? bottomRight = paragraph.getClosestGlyphInfoForOffset(const Offset(99.0, 99.0));
final GlyphInfo? last = paragraph.getGlyphInfoAt(8);
expect(bottomRight, equals(last));
expect(bottomRight, notEquals(paragraph.getGlyphInfoAt(0)));
expect(bottomRight, isNot(paragraph.getGlyphInfoAt(0)));
expect(bottomRight?.graphemeClusterLayoutBounds, const Rect.fromLTWH(30, 10, 10, 10));
expect(bottomRight?.graphemeClusterCodeUnitRange, const TextRange(start: 8, end: 9));
@@ -326,11 +326,8 @@ void main() {
final Canvas canvas = Canvas(recorder);
void callback() { canvas.drawParagraph(paragraph, Offset.zero); }
if (assertStatementsEnabled) {
expectAssertion(callback);
} else {
expect(callback, throwsStateError);
}
expect(callback, throwsA(isA<AssertionError>()));
});
test('rounding hack disabled', () {

View File

@@ -5,7 +5,7 @@
import 'dart:typed_data' show Float64List;
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('path getBounds', () {

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('Picture construction invokes onCreate once', () async {

View File

@@ -5,7 +5,7 @@
import 'dart:async';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('ViewConstraints.tight', () {

View File

@@ -7,7 +7,7 @@ import 'dart:ffi';
import 'dart:isolate';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('PlatformIsolate runOnPlatformThread, cancels pending jobs if shutdown', () async {

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('PlatformView layers do not emit errors from tester', () async {

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
typedef StringFunction = String Function();
typedef IntFunction = int Function();
@@ -21,14 +21,14 @@ void main() {
test('PluginUtilities Callback Handles', () {
// Top level callback.
final CallbackHandle hTop = PluginUtilities.getCallbackHandle(top)!;
expect(hTop, notEquals(0));
expect(hTop, isNot(0));
expect(PluginUtilities.getCallbackHandle(top), hTop);
final StringFunction topClosure = PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction;
expect(topClosure(), 'top');
// Static method callback.
final CallbackHandle hGetInt = PluginUtilities.getCallbackHandle(Foo.getInt)!;
expect(hGetInt, notEquals(0));
expect(hGetInt, isNot(0));
expect(PluginUtilities.getCallbackHandle(Foo.getInt), hGetInt);
final IntFunction getIntClosure = PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction;
expect(getIntClosure(), 1);

View File

@@ -18,6 +18,7 @@ dependencies:
path: any
skia_gold_client: any
sky_engine: any
test: any
vector_math: any
vm_service: any
vm_service_protos: any

View File

@@ -0,0 +1,10 @@
#!/bin/bash
set -e
FILE=$1
COMPILE_TARGET=compile_$FILE.dart
DART_FILTER=$FILE.dart
ninja -C ../out/host_debug_unopt_arm64 $COMPILE_TARGET
./testing/run_tests.py --type=dart --dart-filter=$DART_FILTER --variant=host_debug_unopt_arm64

View File

@@ -4,7 +4,7 @@
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
// The body of this file is the same as ../../lib/web_ui/test/engine/semantics/semantics_api_test.dart
// Please keep them in sync.

View File

@@ -4,7 +4,7 @@
// FlutterTesterOptions=--enable-serial-gc
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
int use(List<int> a) {
return a[0];

View File

@@ -5,7 +5,7 @@
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
final Uint8List imageData = Uint8List.fromList(<int>[ // Small WebP file
0x52, 0x49, 0x46, 0x46, 0x12, 0x00, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50, 0x56, 0x50, 0x38, 0x4c, // |RIFF....WEBPVP8L|

View File

@@ -11,8 +11,8 @@ import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
Future<Uint8List> readFile(String fileName) async {
final File file = File(path.join('flutter', 'testing', 'resources', fileName));

View File

@@ -6,7 +6,7 @@ import 'dart:async';
import 'dart:typed_data';
import 'dart:ui';
import 'package:litetest/litetest.dart';
import 'package:test/test.dart';
void main() {
test('window.sendPlatformMessage preserves callback zone', () {