Factor our common Paint-building code used with BoxShadow (#17363)
This commit is contained in:
committed by
Todd Volkert
parent
5732219500
commit
ca94bfdfc6
@@ -96,6 +96,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
/// [debugPrintOverride], which can be overridden by subclasses.
|
||||
TestWidgetsFlutterBinding() {
|
||||
debugPrint = debugPrintOverride;
|
||||
debugDisableShadows = disableShadows;
|
||||
debugCheckIntrinsicSizes = checkIntrinsicSizes;
|
||||
}
|
||||
|
||||
@@ -108,6 +109,15 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
@protected
|
||||
DebugPrintCallback get debugPrintOverride => debugPrint;
|
||||
|
||||
/// The value to set [debugDisableShadows] to while tests are running.
|
||||
///
|
||||
/// This can be used to reduce the likelihood of golden file tests being
|
||||
/// flaky, because shadow rendering is not always deterministic. The
|
||||
/// [AutomatedTestWidgetsFlutterBinding] sets this to true, so that all tests
|
||||
/// always run with shadows disabled.
|
||||
@protected
|
||||
bool get disableShadows => false;
|
||||
|
||||
/// The value to set [debugCheckIntrinsicSizes] to while tests are running.
|
||||
///
|
||||
/// This can be used to enable additional checks. For example,
|
||||
@@ -525,6 +535,10 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
assert(debugAssertAllGesturesVarsUnset(
|
||||
'The value of a gestures debug variable was changed by the test.',
|
||||
));
|
||||
assert(debugAssertAllPaintingVarsUnset(
|
||||
'The value of a painting debug variable was changed by the test.',
|
||||
debugDisableShadowsOverride: disableShadows,
|
||||
));
|
||||
assert(debugAssertAllRenderVarsUnset(
|
||||
'The value of a rendering debug variable was changed by the test.',
|
||||
debugCheckIntrinsicSizesOverride: checkIntrinsicSizes,
|
||||
@@ -588,6 +602,9 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
@override
|
||||
DebugPrintCallback get debugPrintOverride => debugPrintSynchronously;
|
||||
|
||||
@override
|
||||
bool get disableShadows => true;
|
||||
|
||||
@override
|
||||
bool get checkIntrinsicSizes => true;
|
||||
|
||||
|
||||
@@ -51,11 +51,19 @@ abstract class GoldenFileComparator {
|
||||
///
|
||||
/// This comparator is used as the backend for [matchesGoldenFile].
|
||||
///
|
||||
/// The default comparator, [LocalFileComparator], will treat the golden key as
|
||||
/// When using `flutter test`, a comparator implemented by [LocalFileComparator]
|
||||
/// is used if no other comparator is specified. It treats the golden key as
|
||||
/// a relative path from the test file's directory. It will then load the
|
||||
/// golden file's bytes from disk and perform a byte-for-byte comparison of the
|
||||
/// encoded PNGs, returning true only if there's an exact match.
|
||||
///
|
||||
/// When using `flutter test --update-goldens`, the [LocalFileComparator]
|
||||
/// updates the files on disk to match the rendering.
|
||||
///
|
||||
/// When using `flutter run`, the default comparator (null) is used. It prints
|
||||
/// a message to the console but otherwise does nothing. This allows tests to
|
||||
/// be developed visually on a real device.
|
||||
///
|
||||
/// Callers may choose to override the default comparator by setting this to a
|
||||
/// custom comparator during test set-up (or using directory-level test
|
||||
/// configuration). For example, some projects may wish to install a more
|
||||
@@ -119,7 +127,7 @@ class _UninitializedComparator implements GoldenFileComparator {
|
||||
}
|
||||
}
|
||||
|
||||
/// The default [GoldenFileComparator] implementation.
|
||||
/// The default [GoldenFileComparator] implementation for `flutter test`.
|
||||
///
|
||||
/// This comparator loads golden files from the local file system, treating the
|
||||
/// golden key as a relative path from the test file's directory.
|
||||
@@ -128,13 +136,16 @@ class _UninitializedComparator implements GoldenFileComparator {
|
||||
/// comparison of the encoded PNGs, returning true only if there's an exact
|
||||
/// match. This means it will fail the test if two PNGs represent the same
|
||||
/// pixels but are encoded differently.
|
||||
///
|
||||
/// When using `flutter test --update-goldens`, [LocalFileComparator]
|
||||
/// updates the files on disk to match the rendering.
|
||||
class LocalFileComparator implements GoldenFileComparator {
|
||||
/// Creates a new [LocalFileComparator] for the specified [testFile].
|
||||
///
|
||||
/// Golden file keys will be interpreted as file paths relative to the
|
||||
/// directory in which [testFile] resides.
|
||||
///
|
||||
/// The [testFile] URI must represent a file.
|
||||
/// The [testFile] URL must represent a file.
|
||||
LocalFileComparator(Uri testFile, {path.Style pathStyle})
|
||||
: basedir = _getBasedir(testFile, pathStyle),
|
||||
_path = _getPath(pathStyle);
|
||||
|
||||
@@ -177,7 +177,8 @@ Future<void> expectLater(dynamic actual, dynamic matcher, {
|
||||
// We can't wrap the delegate in a guard, or we'll hit async barriers in
|
||||
// [TestWidgetsFlutterBinding] while we're waiting for the matcher to complete
|
||||
TestAsyncUtils.guardSync();
|
||||
return test_package.expectLater(actual, matcher, reason: reason, skip: skip);
|
||||
return test_package.expectLater(actual, matcher, reason: reason, skip: skip)
|
||||
.then<void>((dynamic value) => null);
|
||||
}
|
||||
|
||||
/// Class that programmatically interacts with widgets and the test environment.
|
||||
|
||||
Reference in New Issue
Block a user