Unverified Commit 473fa38f authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Reland "Remove references to BindingBase.window (#122119 & #122341)" (#122412)

Reland "Remove references to BindingBase.window (#122119 & #122341)"
parent d8a72110
......@@ -33,11 +33,11 @@ Future<void> main() async {
final TestViewConfiguration big = TestViewConfiguration.fromView(
size: const Size(360.0, 640.0),
view: RendererBinding.instance.window,
view: tester.view,
);
final TestViewConfiguration small = TestViewConfiguration.fromView(
size: const Size(355.0, 635.0),
view: RendererBinding.instance.window,
view: tester.view,
);
final RenderView renderView = WidgetsBinding.instance.renderView;
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmark;
......
......@@ -58,8 +58,8 @@ void main() {
expect(find.text('Account Balance'), findsNothing);
// drag the drawer out
final Offset left = Offset(0.0, (WidgetsBinding.instance.window.physicalSize / WidgetsBinding.instance.window.devicePixelRatio).height / 2.0);
final Offset right = Offset((WidgetsBinding.instance.window.physicalSize / WidgetsBinding.instance.window.devicePixelRatio).width, left.dy);
final Offset left = Offset(0.0, (tester.view.physicalSize / tester.view.devicePixelRatio).height / 2.0);
final Offset right = Offset((tester.view.physicalSize / tester.view.devicePixelRatio).width, left.dy);
final TestGesture gesture = await tester.startGesture(left);
await tester.pump();
await gesture.moveTo(right);
......
......@@ -1702,6 +1702,7 @@ void main() {
];
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test shouldn't call this.
......@@ -1728,6 +1729,7 @@ void main() {
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test shouldn't call this.
......@@ -1756,6 +1758,7 @@ void main() {
];
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test shouldn't call this.
......@@ -1777,6 +1780,7 @@ void main() {
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test shouldn't call this.
......@@ -2213,12 +2217,13 @@ class TransitionDetector extends DefaultTransitionDelegate<void> {
Widget buildNavigator({
required List<Page<dynamic>> pages,
required FlutterView view,
PopPageCallback? onPopPage,
GlobalKey<NavigatorState>? key,
TransitionDelegate<dynamic>? transitionDelegate,
}) {
return MediaQuery(
data: MediaQueryData.fromView(WidgetsBinding.instance.window),
data: MediaQueryData.fromView(view),
child: Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
......
......@@ -101,7 +101,7 @@ void main() {
expect(events.length, 1);
expect(events[0], isA<PointerDownEvent>());
expect(events[0].timeStamp, currentTestFrameTime() + kSamplingOffset);
expect(events[0].position, Offset(7.5 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[0].position, Offset(7.5 / tester.view.devicePixelRatio, 0.0));
// Now the system time is epoch + 20ms
requestFrame();
......@@ -109,8 +109,8 @@ void main() {
expect(events.length, 2);
expect(events[1].timeStamp, currentTestFrameTime() + kSamplingOffset);
expect(events[1], isA<PointerMoveEvent>());
expect(events[1].position, Offset(22.5 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[1].delta, Offset(15.0 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[1].position, Offset(22.5 / tester.view.devicePixelRatio, 0.0));
expect(events[1].delta, Offset(15.0 / tester.view.devicePixelRatio, 0.0));
// Now the system time is epoch + 30ms
requestFrame();
......@@ -118,8 +118,8 @@ void main() {
expect(events.length, 4);
expect(events[2].timeStamp, currentTestFrameTime() + kSamplingOffset);
expect(events[2], isA<PointerMoveEvent>());
expect(events[2].position, Offset(37.5 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[2].delta, Offset(15.0 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[2].position, Offset(37.5 / tester.view.devicePixelRatio, 0.0));
expect(events[2].delta, Offset(15.0 / tester.view.devicePixelRatio, 0.0));
expect(events[3].timeStamp, currentTestFrameTime() + kSamplingOffset);
expect(events[3], isA<PointerUpEvent>());
});
......
......@@ -162,6 +162,8 @@ void main() {
expect(events[1], isA<PointerCancelEvent>());
});
const double devicePixelRatio = 2.5;
test('Can expand add and hover pointers', () {
const ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
......@@ -173,7 +175,7 @@ void main() {
],
);
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
......@@ -189,7 +191,7 @@ void main() {
ui.PointerData(change: ui.PointerChange.add, device: 24),
],
);
List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 1);
expect(events[0], isA<PointerAddedEvent>());
......@@ -205,7 +207,7 @@ void main() {
ui.PointerData(signalKind: ui.PointerSignalKind.scroll, device: 24, scrollDeltaY: double.negativeInfinity, scrollDeltaX: 10),
],
);
events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 0);
// Send packet with a valid scroll event.
......@@ -215,7 +217,7 @@ void main() {
],
);
// Make sure PointerEventConverter can expand when device pixel ratio is valid.
events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 1);
expect(events[0], isA<PointerScrollEvent>());
......@@ -232,7 +234,7 @@ void main() {
],
);
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 2);
expect(events[0], isA<PointerAddedEvent>());
......@@ -240,7 +242,7 @@ void main() {
});
test('Should synthesize kPrimaryButton for touch when no button is set', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
ui.PointerData(change: ui.PointerChange.add, physicalX: location.dx, physicalY: location.dy),
......@@ -251,7 +253,7 @@ void main() {
],
);
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
......@@ -267,7 +269,7 @@ void main() {
});
test('Should not synthesize kPrimaryButton for touch when a button is set', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
ui.PointerData(change: ui.PointerChange.add, physicalX: location.dx, physicalY: location.dy),
......@@ -278,7 +280,7 @@ void main() {
],
);
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
......@@ -294,7 +296,7 @@ void main() {
});
test('Should synthesize kPrimaryButton for stylus when no button is set', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
for (final PointerDeviceKind kind in <PointerDeviceKind>[
PointerDeviceKind.stylus,
PointerDeviceKind.invertedStylus,
......@@ -310,7 +312,7 @@ void main() {
],
);
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
......@@ -327,7 +329,7 @@ void main() {
});
test('Should synthesize kPrimaryButton for unknown devices when no button is set', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
const PointerDeviceKind kind = PointerDeviceKind.unknown;
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
......@@ -339,7 +341,7 @@ void main() {
],
);
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
......@@ -355,7 +357,7 @@ void main() {
});
test('Should not synthesize kPrimaryButton for mouse', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
for (final PointerDeviceKind kind in <PointerDeviceKind>[
PointerDeviceKind.mouse,
]) {
......@@ -369,7 +371,7 @@ void main() {
],
);
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
......
......@@ -1042,6 +1042,7 @@ void main() {
];
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test should never execute this.
......@@ -1060,6 +1061,7 @@ void main() {
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test should never execute this.
......@@ -1085,6 +1087,7 @@ void main() {
];
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test should never execute this.
......@@ -1106,6 +1109,7 @@ void main() {
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test should never execute this.
......@@ -1214,11 +1218,12 @@ class TransitionDetector extends DefaultTransitionDelegate<void> {
Widget buildNavigator({
required List<Page<dynamic>> pages,
required PopPageCallback onPopPage,
required ui.FlutterView view,
GlobalKey<NavigatorState>? key,
TransitionDelegate<dynamic>? transitionDelegate,
}) {
return MediaQuery(
data: MediaQueryData.fromView(WidgetsBinding.instance.window),
data: MediaQueryData.fromView(view),
child: Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
......
......@@ -52,7 +52,7 @@ void main() {
test('debugInvertOversizedImages', () async {
debugInvertOversizedImages = true;
expect(PaintingBinding.instance.window.devicePixelRatio != 1.0, true);
expect(PaintingBinding.instance.platformDispatcher.views.any((ui. FlutterView view) => view.devicePixelRatio > 1.0), isTrue);
final FlutterExceptionHandler? oldFlutterError = FlutterError.onError;
final List<String> messages = <String>[];
......@@ -180,7 +180,7 @@ void main() {
expect(imageSizeInfo, isNotNull);
expect(imageSizeInfo.source, 'test.png');
expect(imageSizeInfo.imageSize, const Size(300, 300));
expect(imageSizeInfo.displaySize, const Size(200, 100) * PaintingBinding.instance.window.devicePixelRatio);
expect(imageSizeInfo.displaySize, const Size(200, 100) * tester.view.devicePixelRatio);
// Make sure that we don't report an identical image size info if we
// redraw in the next frame.
......@@ -219,7 +219,7 @@ void main() {
expect(imageSizeInfo, isNotNull);
expect(imageSizeInfo.source, 'test.png');
expect(imageSizeInfo.imageSize, const Size(300, 300));
expect(imageSizeInfo.displaySize, const Size(200, 100) * PaintingBinding.instance.window.devicePixelRatio);
expect(imageSizeInfo.displaySize, const Size(200, 100) * tester.view.devicePixelRatio);
// Make sure that we don't report an identical image size info if we
// redraw in the next frame.
......@@ -237,7 +237,7 @@ void main() {
expect(imageSizeInfo, isNotNull);
expect(imageSizeInfo.source, 'test.png');
expect(imageSizeInfo.imageSize, const Size(300, 300));
expect(imageSizeInfo.displaySize, const Size(200, 150) * PaintingBinding.instance.window.devicePixelRatio);
expect(imageSizeInfo.displaySize, const Size(200, 150) * tester.view.devicePixelRatio);
debugOnPaintImage = null;
});
......@@ -261,7 +261,7 @@ void main() {
expect(imageSizeInfo, isNotNull);
expect(imageSizeInfo.source, '<Unknown Image(300×200)>');
expect(imageSizeInfo.imageSize, const Size(300, 200));
expect(imageSizeInfo.displaySize, const Size(200, 100) * PaintingBinding.instance.window.devicePixelRatio);
expect(imageSizeInfo.displaySize, const Size(200, 100) * tester.view.devicePixelRatio);
debugOnPaintImage = null;
});
......
......@@ -44,7 +44,7 @@ void main() {
expect(offscreen.child.hasSize, isFalse);
expect(offscreen.painted, isFalse);
// Attach the offscreen to a custom render view and owner
final RenderView renderView = RenderView(configuration: testConfiguration, window: RendererBinding.instance.window);
final RenderView renderView = RenderView(configuration: testConfiguration, window: RendererBinding.instance.platformDispatcher.views.single);
final PipelineOwner pipelineOwner = PipelineOwner();
renderView.attach(pipelineOwner);
renderView.child = offscreen.root;
......@@ -66,6 +66,7 @@ void main() {
pipelineOwner.flushPaint();
expect(offscreen.painted, isTrue);
});
test('offscreen layout does not affect onscreen', () {
final TestLayout onscreen = TestLayout();
final TestLayout offscreen = TestLayout();
......@@ -74,7 +75,7 @@ void main() {
expect(offscreen.child.hasSize, isFalse);
expect(offscreen.painted, isFalse);
// Attach the offscreen to a custom render view and owner
final RenderView renderView = RenderView(configuration: testConfiguration, window: RendererBinding.instance.window);
final RenderView renderView = RenderView(configuration: testConfiguration, window: RendererBinding.instance.platformDispatcher.views.single);
final PipelineOwner pipelineOwner = PipelineOwner();
renderView.attach(pipelineOwner);
renderView.child = offscreen.root;
......
......@@ -169,7 +169,7 @@ void main() {
test('switching layer link of an attached leader layer should not crash', () {
final LayerLink link = LayerLink();
final LeaderLayer leaderLayer = LeaderLayer(link: link);
final RenderView view = RenderView(configuration: const ViewConfiguration(), window: RendererBinding.instance.window);
final RenderView view = RenderView(configuration: const ViewConfiguration(), window: RendererBinding.instance.platformDispatcher.views.single);
leaderLayer.attach(view);
final LayerLink link2 = LayerLink();
leaderLayer.link = link2;
......@@ -182,7 +182,7 @@ void main() {
final LayerLink link = LayerLink();
final LeaderLayer leaderLayer1 = LeaderLayer(link: link);
final LeaderLayer leaderLayer2 = LeaderLayer(link: link);
final RenderView view = RenderView(configuration: const ViewConfiguration(), window: RendererBinding.instance.window);
final RenderView view = RenderView(configuration: const ViewConfiguration(), window: RendererBinding.instance.platformDispatcher.views.single);
leaderLayer1.attach(view);
leaderLayer2.attach(view);
leaderLayer2.detach();
......
......@@ -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:ui' as ui;
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -32,10 +30,9 @@ void main() {
});
test('does not replace the root layer unnecessarily', () {
final ui.FlutterView window = TestWindow(window: RendererBinding.instance.window);
final RenderView view = RenderView(
configuration: createViewConfiguration(),
window: window,
window: RendererBinding.instance.platformDispatcher.views.single,
);
final PipelineOwner owner = PipelineOwner();
view.attach(owner);
......@@ -49,10 +46,9 @@ void main() {
});
test('does not replace the root layer unnecessarily when window resize', () {
final ui.FlutterView window = TestWindow(window: RendererBinding.instance.window);
final RenderView view = RenderView(
configuration: createViewConfiguration(size: const Size(100.0, 100.0)),
window: window,
window: RendererBinding.instance.platformDispatcher.views.single,
);
final PipelineOwner owner = PipelineOwner();
view.attach(owner);
......
......@@ -29,13 +29,13 @@ void main() {
),
);
int? result = RendererBinding.instance.renderView.debugLayer!.find<int>(Offset(
10.0 * RendererBinding.instance.window.devicePixelRatio,
10.0 * RendererBinding.instance.window.devicePixelRatio,
10.0 * tester.view.devicePixelRatio,
10.0 * tester.view.devicePixelRatio,
));
expect(result, null);
result = RendererBinding.instance.renderView.debugLayer!.find<int>(Offset(
50.0 * RendererBinding.instance.window.devicePixelRatio,
50.0 * RendererBinding.instance.window.devicePixelRatio,
50.0 * tester.view.devicePixelRatio,
50.0 * tester.view.devicePixelRatio,
));
expect(result, 1);
});
......
......@@ -11,7 +11,7 @@ void main() {
group('DisplayFeatureSubScreen', () {
testWidgets('without Directionality or anchor', (WidgetTester tester) async {
const Key childKey = Key('childKey');
final MediaQueryData mediaQuery = MediaQueryData.fromView(WidgetsBinding.instance.window).copyWith(
final MediaQueryData mediaQuery = MediaQueryData.fromView(tester.view).copyWith(
displayFeatures: <DisplayFeature>[
const DisplayFeature(
bounds: Rect.fromLTRB(390, 0, 410, 600),
......@@ -39,7 +39,7 @@ void main() {
testWidgets('with anchorPoint', (WidgetTester tester) async {
const Key childKey = Key('childKey');
final MediaQueryData mediaQuery = MediaQueryData.fromView(WidgetsBinding.instance.window).copyWith(
final MediaQueryData mediaQuery = MediaQueryData.fromView(tester.view).copyWith(
displayFeatures: <DisplayFeature>[
const DisplayFeature(
bounds: Rect.fromLTRB(390, 0, 410, 600),
......@@ -70,7 +70,7 @@ void main() {
testWidgets('with infinity anchorpoint', (WidgetTester tester) async {
const Key childKey = Key('childKey');
final MediaQueryData mediaQuery = MediaQueryData.fromView(WidgetsBinding.instance.window).copyWith(
final MediaQueryData mediaQuery = MediaQueryData.fromView(tester.view).copyWith(
displayFeatures: <DisplayFeature>[
const DisplayFeature(
bounds: Rect.fromLTRB(390, 0, 410, 600),
......@@ -101,7 +101,7 @@ void main() {
testWidgets('with horizontal hinge and anchorPoint', (WidgetTester tester) async {
const Key childKey = Key('childKey');
final MediaQueryData mediaQuery = MediaQueryData.fromView(WidgetsBinding.instance.window).copyWith(
final MediaQueryData mediaQuery = MediaQueryData.fromView(tester.view).copyWith(
displayFeatures: <DisplayFeature>[
const DisplayFeature(
bounds: Rect.fromLTRB(0, 290, 800, 310),
......@@ -131,7 +131,7 @@ void main() {
testWidgets('with multiple display features and anchorPoint', (WidgetTester tester) async {
const Key childKey = Key('childKey');
final MediaQueryData mediaQuery = MediaQueryData.fromView(WidgetsBinding.instance.window).copyWith(
final MediaQueryData mediaQuery = MediaQueryData.fromView(tester.view).copyWith(
displayFeatures: <DisplayFeature>[
const DisplayFeature(
bounds: Rect.fromLTRB(0, 290, 800, 310),
......@@ -166,7 +166,7 @@ void main() {
testWidgets('with non-splitting display features and anchorPoint', (WidgetTester tester) async {
const Key childKey = Key('childKey');
final MediaQueryData mediaQuery = MediaQueryData.fromView(WidgetsBinding.instance.window).copyWith(
final MediaQueryData mediaQuery = MediaQueryData.fromView(tester.view).copyWith(
displayFeatures: <DisplayFeature>[
// Top notch
const DisplayFeature(
......@@ -211,7 +211,7 @@ void main() {
testWidgets('with size 0 display feature in half-opened posture and anchorPoint', (WidgetTester tester) async {
const Key childKey = Key('childKey');
final MediaQueryData mediaQuery = MediaQueryData.fromView(WidgetsBinding.instance.window).copyWith(
final MediaQueryData mediaQuery = MediaQueryData.fromView(tester.view).copyWith(
displayFeatures: <DisplayFeature>[
const DisplayFeature(
bounds: Rect.fromLTRB(0, 300, 800, 300),
......
......@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' show FlutterView;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
const Size _kTestViewSize = Size(800.0, 600.0);
class ScheduledFrameTrackingWindow extends TestWindow {
ScheduledFrameTrackingWindow({ required super.window });
class ScheduledFrameTrackingPlatformDispatcher extends TestPlatformDispatcher {
ScheduledFrameTrackingPlatformDispatcher({ required super.platformDispatcher });
int _scheduledFrameCount = 0;
int get scheduledFrameCount => _scheduledFrameCount;
......@@ -26,16 +28,16 @@ class ScheduledFrameTrackingWindow extends TestWindow {
}
class ScheduledFrameTrackingBindings extends AutomatedTestWidgetsFlutterBinding {
late final ScheduledFrameTrackingWindow _window = ScheduledFrameTrackingWindow(window: super.window);
late final ScheduledFrameTrackingPlatformDispatcher _platformDispatcher = ScheduledFrameTrackingPlatformDispatcher(platformDispatcher: super.platformDispatcher);
@override
ScheduledFrameTrackingWindow get window => _window;
ScheduledFrameTrackingPlatformDispatcher get platformDispatcher => _platformDispatcher;
}
class OffscreenRenderView extends RenderView {
OffscreenRenderView() : super(
OffscreenRenderView({required FlutterView view}) : super(
configuration: const ViewConfiguration(size: _kTestViewSize),
window: WidgetsBinding.instance.window,
window: view,
);
@override
......@@ -45,13 +47,14 @@ class OffscreenRenderView extends RenderView {
}
class OffscreenWidgetTree {
OffscreenWidgetTree() {
OffscreenWidgetTree(this.view) {
renderView.attach(pipelineOwner);
renderView.prepareInitialFrame();
pipelineOwner.requestVisualUpdate();
}
final RenderView renderView = OffscreenRenderView();
final FlutterView view;
late final RenderView renderView = OffscreenRenderView(view: view);
final BuildOwner buildOwner = BuildOwner(focusManager: FocusManager());
final PipelineOwner pipelineOwner = PipelineOwner();
RenderObjectToWidgetElement<RenderBox>? root;
......@@ -168,12 +171,12 @@ void main() {
testWidgets('RenderObjectToWidgetAdapter.attachToRenderTree does not schedule frame', (WidgetTester tester) async {
expect(WidgetsBinding.instance, isA<ScheduledFrameTrackingBindings>());
final ScheduledFrameTrackingWindow window = WidgetsBinding.instance.window as ScheduledFrameTrackingWindow;
window.resetScheduledFrameCount();
expect(window.scheduledFrameCount, isZero);
final OffscreenWidgetTree tree = OffscreenWidgetTree();
final ScheduledFrameTrackingPlatformDispatcher platformDispatcher = tester.platformDispatcher as ScheduledFrameTrackingPlatformDispatcher;
platformDispatcher.resetScheduledFrameCount();
expect(platformDispatcher.scheduledFrameCount, isZero);
final OffscreenWidgetTree tree = OffscreenWidgetTree(tester.view);
tree.pumpWidget(const SizedBox.shrink());
expect(window.scheduledFrameCount, isZero);
expect(platformDispatcher.scheduledFrameCount, isZero);
});
testWidgets('no crosstalk between widget build owners', (WidgetTester tester) async {
......@@ -181,7 +184,7 @@ void main() {
final Counter counter1 = Counter();
final Trigger trigger2 = Trigger();
final Counter counter2 = Counter();
final OffscreenWidgetTree tree = OffscreenWidgetTree();
final OffscreenWidgetTree tree = OffscreenWidgetTree(tester.view);
// Both counts should start at zero
expect(counter1.count, equals(0));
expect(counter2.count, equals(0));
......@@ -227,7 +230,7 @@ void main() {
});
testWidgets('no crosstalk between focus nodes', (WidgetTester tester) async {
final OffscreenWidgetTree tree = OffscreenWidgetTree();
final OffscreenWidgetTree tree = OffscreenWidgetTree(tester.view);
final FocusNode onscreenFocus = FocusNode();
final FocusNode offscreenFocus = FocusNode();
await tester.pumpWidget(
......@@ -250,7 +253,7 @@ void main() {
});
testWidgets('able to tear down offscreen tree', (WidgetTester tester) async {
final OffscreenWidgetTree tree = OffscreenWidgetTree();
final OffscreenWidgetTree tree = OffscreenWidgetTree(tester.view);
final List<WidgetState> states = <WidgetState>[];
tree.pumpWidget(SizedBox(child: TestStates(states: states)));
expect(states, <WidgetState>[WidgetState.initialized]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment