Allow the SceneBuilder, PictureRecord, and Canvas constructor calls from the rendering layer to be hooked (#147271)

This also includes some minor cleanup of documentation, asserts, and tests.
This commit is contained in:
Ian Hickson
2024-04-24 17:19:24 -07:00
committed by GitHub
parent c22ed980d0
commit 9751d4d002
7 changed files with 213 additions and 25 deletions

View File

@@ -2098,7 +2098,11 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
///
/// The resulting ViewConfiguration maps the given size onto the actual display
/// using the [BoxFit.contain] algorithm.
class TestViewConfiguration extends ViewConfiguration {
///
/// If the underlying [FlutterView] changes, a new [TestViewConfiguration] should
/// be created. See [RendererBinding.handleMetricsChanged] and
/// [RendererBinding.createViewConfigurationFor].
class TestViewConfiguration implements ViewConfiguration {
/// Deprecated. Will be removed in a future version of Flutter.
///
/// This property has been deprecated to prepare for Flutter's upcoming
@@ -2120,14 +2124,29 @@ class TestViewConfiguration extends ViewConfiguration {
/// Creates a [TestViewConfiguration] with the given size and view.
///
/// The [size] defaults to 800x600.
TestViewConfiguration.fromView({required ui.FlutterView view, Size size = _kDefaultTestViewportSize})
: _paintMatrix = _getMatrix(size, view.devicePixelRatio, view),
_physicalSize = view.physicalSize,
super(
devicePixelRatio: view.devicePixelRatio,
logicalConstraints: BoxConstraints.tight(size),
physicalConstraints: BoxConstraints.tight(size) * view.devicePixelRatio,
);
///
/// The settings of the given [FlutterView] are captured when the constructor
/// is called, and subsequent changes are ignored. A new
/// [TestViewConfiguration] should be created if the underlying [FlutterView]
/// changes. See [RendererBinding.handleMetricsChanged] and
/// [RendererBinding.createViewConfigurationFor].
TestViewConfiguration.fromView({
required ui.FlutterView view,
Size size = _kDefaultTestViewportSize,
}) : devicePixelRatio = view.devicePixelRatio,
logicalConstraints = BoxConstraints.tight(size),
physicalConstraints = BoxConstraints.tight(size) * view.devicePixelRatio,
_paintMatrix = _getMatrix(size, view.devicePixelRatio, view),
_physicalSize = view.physicalSize;
@override
final double devicePixelRatio;
@override
final BoxConstraints logicalConstraints;
@override
final BoxConstraints physicalConstraints;
static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) {
final double inverseRatio = devicePixelRatio / window.devicePixelRatio;
@@ -2158,6 +2177,18 @@ class TestViewConfiguration extends ViewConfiguration {
@override
Matrix4 toMatrix() => _paintMatrix.clone();
@override
bool shouldUpdateMatrix(ViewConfiguration oldConfiguration) {
if (oldConfiguration.runtimeType != runtimeType) {
// New configuration could have different logic, so we don't know
// whether it will need a new transform. Return a conservative result.
return true;
}
oldConfiguration as TestViewConfiguration;
// Compare the matrices directly since they are cached.
return oldConfiguration._paintMatrix != _paintMatrix;
}
final Size _physicalSize;
@override

View File

@@ -53,6 +53,9 @@ void main() {
group('the group with retry flag', () {
testWidgets('the test inside it', (WidgetTester tester) async {
addTearDown(() => retried = true);
if (!retried) {
debugPrint('DISREGARD NEXT FAILURE, IT IS EXPECTED');
}
expect(retried, isTrue);
});
}, retry: 1);
@@ -62,6 +65,9 @@ void main() {
bool retried = false;
testWidgets('the test with retry flag', (WidgetTester tester) async {
addTearDown(() => retried = true);
if (!retried) {
debugPrint('DISREGARD NEXT FAILURE, IT IS EXPECTED');
}
expect(retried, isTrue);
}, retry: 1);
});
@@ -557,6 +563,7 @@ void main() {
};
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
debugPrint('DISREGARD NEXT PENDING TIMER LIST, IT IS EXPECTED');
await binding.runTest(() async {
final Timer timer = Timer(const Duration(seconds: 1), () {});
expect(timer.isActive, true);