mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Reland (3): Removes single window assumptions from flutter_test
(#122422)
Reland (3): Removes single window assumptions from `flutter_test`
This commit is contained in:
parent
37fc9ed260
commit
7dd53fefe9
@ -901,15 +901,13 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
|
|||||||
/// Used by [runApp] to wrap the provided `rootWidget` in the default [View].
|
/// Used by [runApp] to wrap the provided `rootWidget` in the default [View].
|
||||||
///
|
///
|
||||||
/// The [View] determines into what [FlutterView] the app is rendered into.
|
/// The [View] determines into what [FlutterView] the app is rendered into.
|
||||||
/// For backwards-compatibility reasons, this method currently chooses
|
/// This is currently [PlatformDispatcher.implicitView] from [platformDispatcher].
|
||||||
/// [window] (which is a [FlutterView]) as the rendering target. This will
|
|
||||||
/// change in a future version of Flutter.
|
|
||||||
///
|
///
|
||||||
/// The `rootWidget` widget provided to this method must not already be
|
/// The `rootWidget` widget provided to this method must not already be
|
||||||
/// wrapped in a [View].
|
/// wrapped in a [View].
|
||||||
Widget wrapWithDefaultView(Widget rootWidget) {
|
Widget wrapWithDefaultView(Widget rootWidget) {
|
||||||
return View(
|
return View(
|
||||||
view: window,
|
view: platformDispatcher.implicitView!,
|
||||||
child: rootWidget,
|
child: rootWidget,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ void main() {
|
|||||||
' MediaQuery\n'
|
' MediaQuery\n'
|
||||||
' _MediaQueryFromView\n'
|
' _MediaQueryFromView\n'
|
||||||
' _ViewScope\n'
|
' _ViewScope\n'
|
||||||
' View-[GlobalObjectKey TestWindow#00000]\n'
|
' View-[GlobalObjectKey TestFlutterView#00000]\n'
|
||||||
' [root]\n'
|
' [root]\n'
|
||||||
' Typically, the Scaffold widget is introduced by the MaterialApp\n'
|
' Typically, the Scaffold widget is introduced by the MaterialApp\n'
|
||||||
' or WidgetsApp widget at the top of your application widget tree.\n'
|
' or WidgetsApp widget at the top of your application widget tree.\n'
|
||||||
@ -376,7 +376,7 @@ void main() {
|
|||||||
' MediaQuery\n'
|
' MediaQuery\n'
|
||||||
' _MediaQueryFromView\n'
|
' _MediaQueryFromView\n'
|
||||||
' _ViewScope\n'
|
' _ViewScope\n'
|
||||||
' View-[GlobalObjectKey TestWindow#00000]\n'
|
' View-[GlobalObjectKey TestFlutterView#00000]\n'
|
||||||
' [root]\n'
|
' [root]\n'
|
||||||
' Typically, the ScaffoldMessenger widget is introduced by the\n'
|
' Typically, the ScaffoldMessenger widget is introduced by the\n'
|
||||||
' MaterialApp at the top of your application widget tree.\n'
|
' MaterialApp at the top of your application widget tree.\n'
|
||||||
|
@ -2454,7 +2454,7 @@ void main() {
|
|||||||
' MediaQuery\n'
|
' MediaQuery\n'
|
||||||
' _MediaQueryFromView\n'
|
' _MediaQueryFromView\n'
|
||||||
' _ViewScope\n'
|
' _ViewScope\n'
|
||||||
' View-[GlobalObjectKey TestWindow#e6136]\n'
|
' View-[GlobalObjectKey TestFlutterView#e6136]\n'
|
||||||
' [root]\n'
|
' [root]\n'
|
||||||
' Typically, the ScaffoldMessenger widget is introduced by the\n'
|
' Typically, the ScaffoldMessenger widget is introduced by the\n'
|
||||||
' MaterialApp at the top of your application widget tree.\n',
|
' MaterialApp at the top of your application widget tree.\n',
|
||||||
|
@ -13,7 +13,7 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import '../rendering/mock_canvas.dart';
|
import '../rendering/mock_canvas.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Container control test', (WidgetTester tester) async {
|
group('Container control tests:', () {
|
||||||
final Container container = Container(
|
final Container container = Container(
|
||||||
alignment: Alignment.bottomRight,
|
alignment: Alignment.bottomRight,
|
||||||
padding: const EdgeInsets.all(7.0),
|
padding: const EdgeInsets.all(7.0),
|
||||||
@ -39,8 +39,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(container, hasOneLineDescription);
|
testWidgets('paints as expected', (WidgetTester tester) async {
|
||||||
|
|
||||||
await tester.pumpWidget(Align(
|
await tester.pumpWidget(Align(
|
||||||
alignment: Alignment.topLeft,
|
alignment: Alignment.topLeft,
|
||||||
child: container,
|
child: container,
|
||||||
@ -54,8 +53,29 @@ void main() {
|
|||||||
..rect(rect: const Rect.fromLTWH(26.0, 43.0, 25.0, 33.0), color: const Color(0xFFFFFF00))
|
..rect(rect: const Rect.fromLTWH(26.0, 43.0, 25.0, 33.0), color: const Color(0xFFFFFF00))
|
||||||
..rect(rect: const Rect.fromLTWH(5.0, 5.0, 53.0, 78.0), color: const Color(0x7F0000FF)),
|
..rect(rect: const Rect.fromLTWH(5.0, 5.0, 53.0, 78.0), color: const Color(0x7F0000FF)),
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('diagnostics', () {
|
||||||
|
testWidgets('has reasonable default diagnostics', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: container,
|
||||||
|
));
|
||||||
|
|
||||||
|
final RenderBox box = tester.renderObject(find.byType(Container));
|
||||||
|
|
||||||
|
expect(container, hasOneLineDescription);
|
||||||
expect(box, hasAGoodToStringDeep);
|
expect(box, hasAGoodToStringDeep);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('has expected info diagnostics', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: container,
|
||||||
|
));
|
||||||
|
|
||||||
|
final RenderBox box = tester.renderObject(find.byType(Container));
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
box.toStringDeep(minLevel: DiagnosticLevel.info),
|
box.toStringDeep(minLevel: DiagnosticLevel.info),
|
||||||
equalsIgnoringHashCodes(
|
equalsIgnoringHashCodes(
|
||||||
@ -118,14 +138,26 @@ void main() {
|
|||||||
' android)\n',
|
' android)\n',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('has expected debug diagnostics', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: container,
|
||||||
|
));
|
||||||
|
|
||||||
|
final RenderBox box = tester.renderObject(find.byType(Container));
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
box.toStringDeep(),
|
// Using the redundant value to ensure the test is explicitly for
|
||||||
|
// debug diagnostics, regardless of any changes to the default value.
|
||||||
|
// ignore: avoid_redundant_argument_values
|
||||||
|
box.toStringDeep(minLevel: DiagnosticLevel.debug),
|
||||||
equalsIgnoringHashCodes(
|
equalsIgnoringHashCodes(
|
||||||
'RenderPadding#00000 relayoutBoundary=up1\n'
|
'RenderPadding#00000 relayoutBoundary=up1\n'
|
||||||
' │ creator: Padding ← Container ← Align ← MediaQuery ←\n'
|
' │ creator: Padding ← Container ← Align ← MediaQuery ←\n'
|
||||||
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' │ TestWindow#00000] ← [root]\n'
|
' │ TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
|
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
|
||||||
' │ size: Size(63.0, 88.0)\n'
|
' │ size: Size(63.0, 88.0)\n'
|
||||||
@ -134,7 +166,7 @@ void main() {
|
|||||||
' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
|
' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
|
||||||
' │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
|
' │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
|
||||||
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
||||||
' │ View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
|
' │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
|
' │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
|
||||||
' │ size: Size(53.0, 78.0)\n'
|
' │ size: Size(53.0, 78.0)\n'
|
||||||
@ -143,7 +175,7 @@ void main() {
|
|||||||
' └─child: RenderDecoratedBox#00000\n'
|
' └─child: RenderDecoratedBox#00000\n'
|
||||||
' │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
|
' │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
|
||||||
' │ Align ← MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
' │ Align ← MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
||||||
' │ View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ size: Size(53.0, 78.0)\n'
|
' │ size: Size(53.0, 78.0)\n'
|
||||||
@ -156,7 +188,8 @@ void main() {
|
|||||||
' └─child: _RenderColoredBox#00000\n'
|
' └─child: _RenderColoredBox#00000\n'
|
||||||
' │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
|
' │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
|
||||||
' │ Container ← Align ← MediaQuery ← _MediaQueryFromView ←\n'
|
' │ Container ← Align ← MediaQuery ← _MediaQueryFromView ←\n'
|
||||||
' │ _ViewScope ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ _ViewScope ← View-[GlobalObjectKey TestFlutterView#00000] ←\n'
|
||||||
|
' │ [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ size: Size(53.0, 78.0)\n'
|
' │ size: Size(53.0, 78.0)\n'
|
||||||
@ -165,7 +198,8 @@ void main() {
|
|||||||
' └─child: RenderPadding#00000\n'
|
' └─child: RenderPadding#00000\n'
|
||||||
' │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
|
' │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
|
||||||
' │ Padding ← Container ← Align ← MediaQuery ← _MediaQueryFromView\n'
|
' │ Padding ← Container ← Align ← MediaQuery ← _MediaQueryFromView\n'
|
||||||
' │ ← _ViewScope ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ ← _ViewScope ← View-[GlobalObjectKey TestFlutterView#00000] ←\n'
|
||||||
|
' │ [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ size: Size(53.0, 78.0)\n'
|
' │ size: Size(53.0, 78.0)\n'
|
||||||
@ -175,7 +209,7 @@ void main() {
|
|||||||
' │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
|
' │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
|
||||||
' │ ConstrainedBox ← Padding ← Container ← Align ← MediaQuery ←\n'
|
' │ ConstrainedBox ← Padding ← Container ← Align ← MediaQuery ←\n'
|
||||||
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' │ TestWindow#00000] ← ⋯\n'
|
' │ TestFlutterView#00000] ← ⋯\n'
|
||||||
' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
|
' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
|
' │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
|
||||||
' │ size: Size(39.0, 64.0)\n'
|
' │ size: Size(39.0, 64.0)\n'
|
||||||
@ -206,6 +240,15 @@ void main() {
|
|||||||
' android)\n',
|
' android)\n',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('has expected fine diagnostics', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: container,
|
||||||
|
));
|
||||||
|
|
||||||
|
final RenderBox box = tester.renderObject(find.byType(Container));
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
box.toStringDeep(minLevel: DiagnosticLevel.fine),
|
box.toStringDeep(minLevel: DiagnosticLevel.fine),
|
||||||
@ -213,7 +256,7 @@ void main() {
|
|||||||
'RenderPadding#00000 relayoutBoundary=up1\n'
|
'RenderPadding#00000 relayoutBoundary=up1\n'
|
||||||
' │ creator: Padding ← Container ← Align ← MediaQuery ←\n'
|
' │ creator: Padding ← Container ← Align ← MediaQuery ←\n'
|
||||||
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' │ TestWindow#00000] ← [root]\n'
|
' │ TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
|
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -225,7 +268,7 @@ void main() {
|
|||||||
' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
|
' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
|
||||||
' │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
|
' │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
|
||||||
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
||||||
' │ View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
|
' │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
|
' │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -236,7 +279,7 @@ void main() {
|
|||||||
' └─child: RenderDecoratedBox#00000\n'
|
' └─child: RenderDecoratedBox#00000\n'
|
||||||
' │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
|
' │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
|
||||||
' │ Align ← MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
' │ Align ← MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
||||||
' │ View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -257,7 +300,8 @@ void main() {
|
|||||||
' └─child: _RenderColoredBox#00000\n'
|
' └─child: _RenderColoredBox#00000\n'
|
||||||
' │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
|
' │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
|
||||||
' │ Container ← Align ← MediaQuery ← _MediaQueryFromView ←\n'
|
' │ Container ← Align ← MediaQuery ← _MediaQueryFromView ←\n'
|
||||||
' │ _ViewScope ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ _ViewScope ← View-[GlobalObjectKey TestFlutterView#00000] ←\n'
|
||||||
|
' │ [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -268,7 +312,8 @@ void main() {
|
|||||||
' └─child: RenderPadding#00000\n'
|
' └─child: RenderPadding#00000\n'
|
||||||
' │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
|
' │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
|
||||||
' │ Padding ← Container ← Align ← MediaQuery ← _MediaQueryFromView\n'
|
' │ Padding ← Container ← Align ← MediaQuery ← _MediaQueryFromView\n'
|
||||||
' │ ← _ViewScope ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ ← _ViewScope ← View-[GlobalObjectKey TestFlutterView#00000] ←\n'
|
||||||
|
' │ [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -281,7 +326,7 @@ void main() {
|
|||||||
' │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
|
' │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
|
||||||
' │ ConstrainedBox ← Padding ← Container ← Align ← MediaQuery ←\n'
|
' │ ConstrainedBox ← Padding ← Container ← Align ← MediaQuery ←\n'
|
||||||
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' │ TestWindow#00000] ← ⋯\n'
|
' │ TestFlutterView#00000] ← ⋯\n'
|
||||||
' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
|
' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
|
' │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -325,6 +370,15 @@ void main() {
|
|||||||
' android)\n',
|
' android)\n',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('has expected hidden diagnostics', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: container,
|
||||||
|
));
|
||||||
|
|
||||||
|
final RenderBox box = tester.renderObject(find.byType(Container));
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
box.toStringDeep(minLevel: DiagnosticLevel.hidden),
|
box.toStringDeep(minLevel: DiagnosticLevel.hidden),
|
||||||
@ -333,7 +387,7 @@ void main() {
|
|||||||
' │ needsCompositing: false\n'
|
' │ needsCompositing: false\n'
|
||||||
' │ creator: Padding ← Container ← Align ← MediaQuery ←\n'
|
' │ creator: Padding ← Container ← Align ← MediaQuery ←\n'
|
||||||
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' │ TestWindow#00000] ← [root]\n'
|
' │ TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
|
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -348,7 +402,7 @@ void main() {
|
|||||||
' │ needsCompositing: false\n'
|
' │ needsCompositing: false\n'
|
||||||
' │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
|
' │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
|
||||||
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
||||||
' │ View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
|
' │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
|
' │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -362,7 +416,7 @@ void main() {
|
|||||||
' │ needsCompositing: false\n'
|
' │ needsCompositing: false\n'
|
||||||
' │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
|
' │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
|
||||||
' │ Align ← MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
' │ Align ← MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
||||||
' │ View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -386,7 +440,8 @@ void main() {
|
|||||||
' │ needsCompositing: false\n'
|
' │ needsCompositing: false\n'
|
||||||
' │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
|
' │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
|
||||||
' │ Container ← Align ← MediaQuery ← _MediaQueryFromView ←\n'
|
' │ Container ← Align ← MediaQuery ← _MediaQueryFromView ←\n'
|
||||||
' │ _ViewScope ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ _ViewScope ← View-[GlobalObjectKey TestFlutterView#00000] ←\n'
|
||||||
|
' │ [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -400,7 +455,8 @@ void main() {
|
|||||||
' │ needsCompositing: false\n'
|
' │ needsCompositing: false\n'
|
||||||
' │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
|
' │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
|
||||||
' │ Padding ← Container ← Align ← MediaQuery ← _MediaQueryFromView\n'
|
' │ Padding ← Container ← Align ← MediaQuery ← _MediaQueryFromView\n'
|
||||||
' │ ← _ViewScope ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ ← _ViewScope ← View-[GlobalObjectKey TestFlutterView#00000] ←\n'
|
||||||
|
' │ [root]\n'
|
||||||
' │ parentData: <none> (can use size)\n'
|
' │ parentData: <none> (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
' │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -416,7 +472,7 @@ void main() {
|
|||||||
' │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
|
' │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
|
||||||
' │ ConstrainedBox ← Padding ← Container ← Align ← MediaQuery ←\n'
|
' │ ConstrainedBox ← Padding ← Container ← Align ← MediaQuery ←\n'
|
||||||
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' │ TestWindow#00000] ← ⋯\n'
|
' │ TestFlutterView#00000] ← ⋯\n'
|
||||||
' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
|
' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
|
' │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
|
||||||
' │ layer: null\n'
|
' │ layer: null\n'
|
||||||
@ -468,6 +524,13 @@ void main() {
|
|||||||
' android)\n',
|
' android)\n',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('painting error has expected diagnostics', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: container,
|
||||||
|
));
|
||||||
|
|
||||||
final RenderBox decoratedBox = tester.renderObject(find.byType(DecoratedBox).last);
|
final RenderBox decoratedBox = tester.renderObject(find.byType(DecoratedBox).last);
|
||||||
final PaintingContext context = _MockPaintingContext();
|
final PaintingContext context = _MockPaintingContext();
|
||||||
@ -491,6 +554,8 @@ void main() {
|
|||||||
' BoxPainter for BoxDecoration(color: Color(0xffffff00))\n',
|
' BoxPainter for BoxDecoration(color: Color(0xffffff00))\n',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
|
testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
|
@ -374,7 +374,7 @@ void main() {
|
|||||||
' creator: ConstrainedBox ← Container ← LayoutWithMissingId ←\n'
|
' creator: ConstrainedBox ← Container ← LayoutWithMissingId ←\n'
|
||||||
' CustomMultiChildLayout ← Center ← MediaQuery ←\n'
|
' CustomMultiChildLayout ← Center ← MediaQuery ←\n'
|
||||||
' _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' TestWindow#00000] ← [root]\n'
|
' TestFlutterView#00000] ← [root]\n'
|
||||||
' parentData: offset=Offset(0.0, 0.0); id=null\n'
|
' parentData: offset=Offset(0.0, 0.0); id=null\n'
|
||||||
' constraints: MISSING\n'
|
' constraints: MISSING\n'
|
||||||
' size: MISSING\n'
|
' size: MISSING\n'
|
||||||
|
@ -1230,7 +1230,7 @@ void main() {
|
|||||||
' │ primaryFocus: FocusNode#00000(Child 4 [PRIMARY FOCUS])\n'
|
' │ primaryFocus: FocusNode#00000(Child 4 [PRIMARY FOCUS])\n'
|
||||||
' │ primaryFocusCreator: Container-[GlobalKey#00000] ← MediaQuery ←\n'
|
' │ primaryFocusCreator: Container-[GlobalKey#00000] ← MediaQuery ←\n'
|
||||||
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' │ TestWindow#00000] ← [root]\n'
|
' │ TestFlutterView#00000] ← [root]\n'
|
||||||
' │\n'
|
' │\n'
|
||||||
' └─rootScope: FocusScopeNode#00000(Root Focus Scope [IN FOCUS PATH])\n'
|
' └─rootScope: FocusScopeNode#00000(Root Focus Scope [IN FOCUS PATH])\n'
|
||||||
' │ IN FOCUS PATH\n'
|
' │ IN FOCUS PATH\n'
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:ui' show Brightness, DisplayFeature, DisplayFeatureState, DisplayFeatureType, GestureSettings, PlatformDispatcher, ViewPadding;
|
import 'dart:ui' show Brightness, DisplayFeature, DisplayFeatureState, DisplayFeatureType, GestureSettings;
|
||||||
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -146,10 +146,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQueryData.fromView is sane', (WidgetTester tester) async {
|
testWidgets('MediaQueryData.fromView is sane', (WidgetTester tester) async {
|
||||||
final MediaQueryData data = MediaQueryData.fromView(tester.binding.window);
|
final MediaQueryData data = MediaQueryData.fromView(tester.view);
|
||||||
expect(data, hasOneLineDescription);
|
expect(data, hasOneLineDescription);
|
||||||
expect(data.hashCode, equals(data.copyWith().hashCode));
|
expect(data.hashCode, equals(data.copyWith().hashCode));
|
||||||
expect(data.size, equals(tester.binding.window.physicalSize / tester.binding.window.devicePixelRatio));
|
expect(data.size, equals(tester.view.physicalSize / tester.view.devicePixelRatio));
|
||||||
expect(data.accessibleNavigation, false);
|
expect(data.accessibleNavigation, false);
|
||||||
expect(data.invertColors, false);
|
expect(data.invertColors, false);
|
||||||
expect(data.disableAnimations, false);
|
expect(data.disableAnimations, false);
|
||||||
@ -173,26 +173,17 @@ void main() {
|
|||||||
navigationMode: NavigationMode.directional,
|
navigationMode: NavigationMode.directional,
|
||||||
);
|
);
|
||||||
|
|
||||||
final TestView view = TestView(
|
final MediaQueryData data = MediaQueryData.fromView(tester.view, platformData: platformData);
|
||||||
physicalSize: const Size(300, 600),
|
|
||||||
devicePixelRatio: 3.0,
|
|
||||||
padding: const TestViewPadding(15),
|
|
||||||
viewPadding: const TestViewPadding(75),
|
|
||||||
viewInsets: const TestViewPadding(45),
|
|
||||||
systemGestureInsets: const TestViewPadding(9),
|
|
||||||
);
|
|
||||||
|
|
||||||
final MediaQueryData data = MediaQueryData.fromView(view, platformData: platformData);
|
|
||||||
expect(data, hasOneLineDescription);
|
expect(data, hasOneLineDescription);
|
||||||
expect(data.hashCode, data.copyWith().hashCode);
|
expect(data.hashCode, data.copyWith().hashCode);
|
||||||
expect(data.size, view.physicalSize / view.devicePixelRatio);
|
expect(data.size, tester.view.physicalSize / tester.view.devicePixelRatio);
|
||||||
expect(data.devicePixelRatio, view.devicePixelRatio);
|
expect(data.devicePixelRatio, tester.view.devicePixelRatio);
|
||||||
expect(data.textScaleFactor, platformData.textScaleFactor);
|
expect(data.textScaleFactor, platformData.textScaleFactor);
|
||||||
expect(data.platformBrightness, platformData.platformBrightness);
|
expect(data.platformBrightness, platformData.platformBrightness);
|
||||||
expect(data.padding, EdgeInsets.fromViewPadding(view.padding, view.devicePixelRatio));
|
expect(data.padding, EdgeInsets.fromViewPadding(tester.view.padding, tester.view.devicePixelRatio));
|
||||||
expect(data.viewPadding, EdgeInsets.fromViewPadding(view.viewPadding, view.devicePixelRatio));
|
expect(data.viewPadding, EdgeInsets.fromViewPadding(tester.view.viewPadding, tester.view.devicePixelRatio));
|
||||||
expect(data.viewInsets, EdgeInsets.fromViewPadding(view.viewInsets, view.devicePixelRatio));
|
expect(data.viewInsets, EdgeInsets.fromViewPadding(tester.view.viewInsets, tester.view.devicePixelRatio));
|
||||||
expect(data.systemGestureInsets, EdgeInsets.fromViewPadding(view.systemGestureInsets, view.devicePixelRatio));
|
expect(data.systemGestureInsets, EdgeInsets.fromViewPadding(tester.view.systemGestureInsets, tester.view.devicePixelRatio));
|
||||||
expect(data.accessibleNavigation, platformData.accessibleNavigation);
|
expect(data.accessibleNavigation, platformData.accessibleNavigation);
|
||||||
expect(data.invertColors, platformData.invertColors);
|
expect(data.invertColors, platformData.invertColors);
|
||||||
expect(data.disableAnimations, platformData.disableAnimations);
|
expect(data.disableAnimations, platformData.disableAnimations);
|
||||||
@ -200,48 +191,37 @@ void main() {
|
|||||||
expect(data.highContrast, platformData.highContrast);
|
expect(data.highContrast, platformData.highContrast);
|
||||||
expect(data.alwaysUse24HourFormat, platformData.alwaysUse24HourFormat);
|
expect(data.alwaysUse24HourFormat, platformData.alwaysUse24HourFormat);
|
||||||
expect(data.navigationMode, platformData.navigationMode);
|
expect(data.navigationMode, platformData.navigationMode);
|
||||||
expect(data.gestureSettings, DeviceGestureSettings.fromView(view));
|
expect(data.gestureSettings, DeviceGestureSettings.fromView(tester.view));
|
||||||
expect(data.displayFeatures, view.displayFeatures);
|
expect(data.displayFeatures, tester.view.displayFeatures);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQueryData.fromView uses data from platformDispatcher if no platformData is provided', (WidgetTester tester) async {
|
testWidgets('MediaQueryData.fromView uses data from platformDispatcher if no platformData is provided', (WidgetTester tester) async {
|
||||||
final TestPlatformDispatcher platformDispatcher = TestPlatformDispatcher(platformDispatcher: tester.binding.platformDispatcher);
|
tester.platformDispatcher
|
||||||
platformDispatcher
|
|
||||||
..textScaleFactorTestValue = 123
|
..textScaleFactorTestValue = 123
|
||||||
..platformBrightnessTestValue = Brightness.dark
|
..platformBrightnessTestValue = Brightness.dark
|
||||||
..accessibilityFeaturesTestValue = FakeAccessibilityFeatures.allOn;
|
..accessibilityFeaturesTestValue = FakeAccessibilityFeatures.allOn;
|
||||||
addTearDown(() => platformDispatcher.clearAllTestValues());
|
addTearDown(() => tester.platformDispatcher.clearAllTestValues());
|
||||||
|
|
||||||
final TestView view = TestView(
|
final MediaQueryData data = MediaQueryData.fromView(tester.view);
|
||||||
platformDispatcher: platformDispatcher,
|
|
||||||
physicalSize: const Size(300, 600),
|
|
||||||
devicePixelRatio: 3.0,
|
|
||||||
padding: const TestViewPadding(15),
|
|
||||||
viewPadding: const TestViewPadding(75),
|
|
||||||
viewInsets: const TestViewPadding(45),
|
|
||||||
systemGestureInsets: const TestViewPadding(9),
|
|
||||||
);
|
|
||||||
|
|
||||||
final MediaQueryData data = MediaQueryData.fromView(view);
|
|
||||||
expect(data, hasOneLineDescription);
|
expect(data, hasOneLineDescription);
|
||||||
expect(data.hashCode, data.copyWith().hashCode);
|
expect(data.hashCode, data.copyWith().hashCode);
|
||||||
expect(data.size, view.physicalSize / view.devicePixelRatio);
|
expect(data.size, tester.view.physicalSize / tester.view.devicePixelRatio);
|
||||||
expect(data.devicePixelRatio, view.devicePixelRatio);
|
expect(data.devicePixelRatio, tester.view.devicePixelRatio);
|
||||||
expect(data.textScaleFactor, platformDispatcher.textScaleFactor);
|
expect(data.textScaleFactor, tester.platformDispatcher.textScaleFactor);
|
||||||
expect(data.platformBrightness, platformDispatcher.platformBrightness);
|
expect(data.platformBrightness, tester.platformDispatcher.platformBrightness);
|
||||||
expect(data.padding, EdgeInsets.fromViewPadding(view.padding, view.devicePixelRatio));
|
expect(data.padding, EdgeInsets.fromViewPadding(tester.view.padding, tester.view.devicePixelRatio));
|
||||||
expect(data.viewPadding, EdgeInsets.fromViewPadding(view.viewPadding, view.devicePixelRatio));
|
expect(data.viewPadding, EdgeInsets.fromViewPadding(tester.view.viewPadding, tester.view.devicePixelRatio));
|
||||||
expect(data.viewInsets, EdgeInsets.fromViewPadding(view.viewInsets, view.devicePixelRatio));
|
expect(data.viewInsets, EdgeInsets.fromViewPadding(tester.view.viewInsets, tester.view.devicePixelRatio));
|
||||||
expect(data.systemGestureInsets, EdgeInsets.fromViewPadding(view.systemGestureInsets, view.devicePixelRatio));
|
expect(data.systemGestureInsets, EdgeInsets.fromViewPadding(tester.view.systemGestureInsets, tester.view.devicePixelRatio));
|
||||||
expect(data.accessibleNavigation, platformDispatcher.accessibilityFeatures.accessibleNavigation);
|
expect(data.accessibleNavigation, tester.platformDispatcher.accessibilityFeatures.accessibleNavigation);
|
||||||
expect(data.invertColors, platformDispatcher.accessibilityFeatures.invertColors);
|
expect(data.invertColors, tester.platformDispatcher.accessibilityFeatures.invertColors);
|
||||||
expect(data.disableAnimations, platformDispatcher.accessibilityFeatures.disableAnimations);
|
expect(data.disableAnimations, tester.platformDispatcher.accessibilityFeatures.disableAnimations);
|
||||||
expect(data.boldText, platformDispatcher.accessibilityFeatures.boldText);
|
expect(data.boldText, tester.platformDispatcher.accessibilityFeatures.boldText);
|
||||||
expect(data.highContrast, platformDispatcher.accessibilityFeatures.highContrast);
|
expect(data.highContrast, tester.platformDispatcher.accessibilityFeatures.highContrast);
|
||||||
expect(data.alwaysUse24HourFormat, platformDispatcher.alwaysUse24HourFormat);
|
expect(data.alwaysUse24HourFormat, tester.platformDispatcher.alwaysUse24HourFormat);
|
||||||
expect(data.navigationMode, NavigationMode.traditional);
|
expect(data.navigationMode, NavigationMode.traditional);
|
||||||
expect(data.gestureSettings, DeviceGestureSettings.fromView(view));
|
expect(data.gestureSettings, DeviceGestureSettings.fromView(tester.view));
|
||||||
expect(data.displayFeatures, view.displayFeatures);
|
expect(data.displayFeatures, tester.view.displayFeatures);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQuery.fromView injects a new MediaQuery with data from view, preserving platform-specific data', (WidgetTester tester) async {
|
testWidgets('MediaQuery.fromView injects a new MediaQuery with data from view, preserving platform-specific data', (WidgetTester tester) async {
|
||||||
@ -257,20 +237,11 @@ void main() {
|
|||||||
navigationMode: NavigationMode.directional,
|
navigationMode: NavigationMode.directional,
|
||||||
);
|
);
|
||||||
|
|
||||||
final TestView view = TestView(
|
|
||||||
physicalSize: const Size(300, 600),
|
|
||||||
devicePixelRatio: 3.0,
|
|
||||||
padding: const TestViewPadding(15),
|
|
||||||
viewPadding: const TestViewPadding(75),
|
|
||||||
viewInsets: const TestViewPadding(45),
|
|
||||||
systemGestureInsets: const TestViewPadding(9),
|
|
||||||
);
|
|
||||||
|
|
||||||
late MediaQueryData data;
|
late MediaQueryData data;
|
||||||
await tester.pumpWidget(MediaQuery(
|
await tester.pumpWidget(MediaQuery(
|
||||||
data: platformData,
|
data: platformData,
|
||||||
child: MediaQuery.fromView(
|
child: MediaQuery.fromView(
|
||||||
view: view,
|
view: tester.view,
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
data = MediaQuery.of(context);
|
data = MediaQuery.of(context);
|
||||||
@ -281,14 +252,14 @@ void main() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
expect(data, isNot(platformData));
|
expect(data, isNot(platformData));
|
||||||
expect(data.size, view.physicalSize / view.devicePixelRatio);
|
expect(data.size, tester.view.physicalSize / tester.view.devicePixelRatio);
|
||||||
expect(data.devicePixelRatio, view.devicePixelRatio);
|
expect(data.devicePixelRatio, tester.view.devicePixelRatio);
|
||||||
expect(data.textScaleFactor, platformData.textScaleFactor);
|
expect(data.textScaleFactor, platformData.textScaleFactor);
|
||||||
expect(data.platformBrightness, platformData.platformBrightness);
|
expect(data.platformBrightness, platformData.platformBrightness);
|
||||||
expect(data.padding, EdgeInsets.fromViewPadding(view.padding, view.devicePixelRatio));
|
expect(data.padding, EdgeInsets.fromViewPadding(tester.view.padding, tester.view.devicePixelRatio));
|
||||||
expect(data.viewPadding, EdgeInsets.fromViewPadding(view.viewPadding, view.devicePixelRatio));
|
expect(data.viewPadding, EdgeInsets.fromViewPadding(tester.view.viewPadding, tester.view.devicePixelRatio));
|
||||||
expect(data.viewInsets, EdgeInsets.fromViewPadding(view.viewInsets, view.devicePixelRatio));
|
expect(data.viewInsets, EdgeInsets.fromViewPadding(tester.view.viewInsets, tester.view.devicePixelRatio));
|
||||||
expect(data.systemGestureInsets, EdgeInsets.fromViewPadding(view.systemGestureInsets, view.devicePixelRatio));
|
expect(data.systemGestureInsets, EdgeInsets.fromViewPadding(tester.view.systemGestureInsets, tester.view.devicePixelRatio));
|
||||||
expect(data.accessibleNavigation, platformData.accessibleNavigation);
|
expect(data.accessibleNavigation, platformData.accessibleNavigation);
|
||||||
expect(data.invertColors, platformData.invertColors);
|
expect(data.invertColors, platformData.invertColors);
|
||||||
expect(data.disableAnimations, platformData.disableAnimations);
|
expect(data.disableAnimations, platformData.disableAnimations);
|
||||||
@ -296,27 +267,16 @@ void main() {
|
|||||||
expect(data.highContrast, platformData.highContrast);
|
expect(data.highContrast, platformData.highContrast);
|
||||||
expect(data.alwaysUse24HourFormat, platformData.alwaysUse24HourFormat);
|
expect(data.alwaysUse24HourFormat, platformData.alwaysUse24HourFormat);
|
||||||
expect(data.navigationMode, platformData.navigationMode);
|
expect(data.navigationMode, platformData.navigationMode);
|
||||||
expect(data.gestureSettings, DeviceGestureSettings.fromView(view));
|
expect(data.gestureSettings, DeviceGestureSettings.fromView(tester.view));
|
||||||
expect(data.displayFeatures, view.displayFeatures);
|
expect(data.displayFeatures, tester.view.displayFeatures);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQuery.fromView injects a new MediaQuery with data from view when no surrounding MediaQuery exists', (WidgetTester tester) async {
|
testWidgets('MediaQuery.fromView injects a new MediaQuery with data from view when no surrounding MediaQuery exists', (WidgetTester tester) async {
|
||||||
final TestPlatformDispatcher platformDispatcher = TestPlatformDispatcher(platformDispatcher: tester.binding.platformDispatcher);
|
tester.platformDispatcher
|
||||||
platformDispatcher
|
|
||||||
..textScaleFactorTestValue = 123
|
..textScaleFactorTestValue = 123
|
||||||
..platformBrightnessTestValue = Brightness.dark
|
..platformBrightnessTestValue = Brightness.dark
|
||||||
..accessibilityFeaturesTestValue = FakeAccessibilityFeatures.allOn;
|
..accessibilityFeaturesTestValue = FakeAccessibilityFeatures.allOn;
|
||||||
addTearDown(() => platformDispatcher.clearAllTestValues());
|
addTearDown(() => tester.platformDispatcher.clearAllTestValues());
|
||||||
|
|
||||||
final TestView view = TestView(
|
|
||||||
platformDispatcher: platformDispatcher,
|
|
||||||
physicalSize: const Size(300, 600),
|
|
||||||
devicePixelRatio: 3.0,
|
|
||||||
padding: const TestViewPadding(15),
|
|
||||||
viewPadding: const TestViewPadding(75),
|
|
||||||
viewInsets: const TestViewPadding(45),
|
|
||||||
systemGestureInsets: const TestViewPadding(9),
|
|
||||||
);
|
|
||||||
|
|
||||||
late MediaQueryData data;
|
late MediaQueryData data;
|
||||||
MediaQueryData? outerData;
|
MediaQueryData? outerData;
|
||||||
@ -326,7 +286,7 @@ void main() {
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
outerData = MediaQuery.maybeOf(context);
|
outerData = MediaQuery.maybeOf(context);
|
||||||
return MediaQuery.fromView(
|
return MediaQuery.fromView(
|
||||||
view: view,
|
view: tester.view,
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
data = MediaQuery.of(context);
|
data = MediaQuery.of(context);
|
||||||
@ -339,33 +299,34 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(outerData, isNull);
|
expect(outerData, isNull);
|
||||||
expect(data.size, view.physicalSize / view.devicePixelRatio);
|
expect(data.size, tester.view.physicalSize / tester.view.devicePixelRatio);
|
||||||
expect(data.devicePixelRatio, view.devicePixelRatio);
|
expect(data.devicePixelRatio, tester.view.devicePixelRatio);
|
||||||
expect(data.textScaleFactor, platformDispatcher.textScaleFactor);
|
expect(data.textScaleFactor, tester.platformDispatcher.textScaleFactor);
|
||||||
expect(data.platformBrightness, platformDispatcher.platformBrightness);
|
expect(data.platformBrightness, tester.platformDispatcher.platformBrightness);
|
||||||
expect(data.padding, EdgeInsets.fromViewPadding(view.padding, view.devicePixelRatio));
|
expect(data.padding, EdgeInsets.fromViewPadding(tester.view.padding, tester.view.devicePixelRatio));
|
||||||
expect(data.viewPadding, EdgeInsets.fromViewPadding(view.viewPadding, view.devicePixelRatio));
|
expect(data.viewPadding, EdgeInsets.fromViewPadding(tester.view.viewPadding, tester.view.devicePixelRatio));
|
||||||
expect(data.viewInsets, EdgeInsets.fromViewPadding(view.viewInsets, view.devicePixelRatio));
|
expect(data.viewInsets, EdgeInsets.fromViewPadding(tester.view.viewInsets, tester.view.devicePixelRatio));
|
||||||
expect(data.systemGestureInsets, EdgeInsets.fromViewPadding(view.systemGestureInsets, view.devicePixelRatio));
|
expect(data.systemGestureInsets, EdgeInsets.fromViewPadding(tester.view.systemGestureInsets, tester.view.devicePixelRatio));
|
||||||
expect(data.accessibleNavigation, platformDispatcher.accessibilityFeatures.accessibleNavigation);
|
expect(data.accessibleNavigation, tester.platformDispatcher.accessibilityFeatures.accessibleNavigation);
|
||||||
expect(data.invertColors, platformDispatcher.accessibilityFeatures.invertColors);
|
expect(data.invertColors, tester.platformDispatcher.accessibilityFeatures.invertColors);
|
||||||
expect(data.disableAnimations, platformDispatcher.accessibilityFeatures.disableAnimations);
|
expect(data.disableAnimations, tester.platformDispatcher.accessibilityFeatures.disableAnimations);
|
||||||
expect(data.boldText, platformDispatcher.accessibilityFeatures.boldText);
|
expect(data.boldText, tester.platformDispatcher.accessibilityFeatures.boldText);
|
||||||
expect(data.highContrast, platformDispatcher.accessibilityFeatures.highContrast);
|
expect(data.highContrast, tester.platformDispatcher.accessibilityFeatures.highContrast);
|
||||||
expect(data.alwaysUse24HourFormat, platformDispatcher.alwaysUse24HourFormat);
|
expect(data.alwaysUse24HourFormat, tester.platformDispatcher.alwaysUse24HourFormat);
|
||||||
expect(data.navigationMode, NavigationMode.traditional);
|
expect(data.navigationMode, NavigationMode.traditional);
|
||||||
expect(data.gestureSettings, DeviceGestureSettings.fromView(view));
|
expect(data.gestureSettings, DeviceGestureSettings.fromView(tester.view));
|
||||||
expect(data.displayFeatures, view.displayFeatures);
|
expect(data.displayFeatures, tester.view.displayFeatures);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQuery.fromView updates on notifications (no parent data)', (WidgetTester tester) async {
|
testWidgets('MediaQuery.fromView updates on notifications (no parent data)', (WidgetTester tester) async {
|
||||||
tester.binding.platformDispatcher
|
addTearDown(() => tester.platformDispatcher.clearAllTestValues());
|
||||||
|
addTearDown(() => tester.view.reset());
|
||||||
|
|
||||||
|
tester.platformDispatcher
|
||||||
..textScaleFactorTestValue = 123
|
..textScaleFactorTestValue = 123
|
||||||
..platformBrightnessTestValue = Brightness.dark
|
..platformBrightnessTestValue = Brightness.dark
|
||||||
..accessibilityFeaturesTestValue = FakeAccessibilityFeatures.allOn;
|
..accessibilityFeaturesTestValue = FakeAccessibilityFeatures.allOn;
|
||||||
addTearDown(() => tester.binding.platformDispatcher.clearAllTestValues());
|
tester.view.devicePixelRatio = 44;
|
||||||
tester.binding.window.devicePixelRatioTestValue = 44;
|
|
||||||
addTearDown(() => tester.binding.window.clearAllTestValues());
|
|
||||||
|
|
||||||
late MediaQueryData data;
|
late MediaQueryData data;
|
||||||
MediaQueryData? outerData;
|
MediaQueryData? outerData;
|
||||||
@ -376,7 +337,7 @@ void main() {
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
outerData = MediaQuery.maybeOf(context);
|
outerData = MediaQuery.maybeOf(context);
|
||||||
return MediaQuery.fromView(
|
return MediaQuery.fromView(
|
||||||
view: tester.binding.window,
|
view: tester.view,
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
rebuildCount++;
|
rebuildCount++;
|
||||||
@ -393,38 +354,39 @@ void main() {
|
|||||||
expect(rebuildCount, 1);
|
expect(rebuildCount, 1);
|
||||||
|
|
||||||
expect(data.textScaleFactor, 123);
|
expect(data.textScaleFactor, 123);
|
||||||
tester.binding.platformDispatcher.textScaleFactorTestValue = 456;
|
tester.platformDispatcher.textScaleFactorTestValue = 456;
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(data.textScaleFactor, 456);
|
expect(data.textScaleFactor, 456);
|
||||||
expect(rebuildCount, 2);
|
expect(rebuildCount, 2);
|
||||||
|
|
||||||
expect(data.platformBrightness, Brightness.dark);
|
expect(data.platformBrightness, Brightness.dark);
|
||||||
tester.binding.platformDispatcher.platformBrightnessTestValue = Brightness.light;
|
tester.platformDispatcher.platformBrightnessTestValue = Brightness.light;
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(data.platformBrightness, Brightness.light);
|
expect(data.platformBrightness, Brightness.light);
|
||||||
expect(rebuildCount, 3);
|
expect(rebuildCount, 3);
|
||||||
|
|
||||||
expect(data.accessibleNavigation, true);
|
expect(data.accessibleNavigation, true);
|
||||||
tester.binding.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures();
|
tester.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(data.accessibleNavigation, false);
|
expect(data.accessibleNavigation, false);
|
||||||
expect(rebuildCount, 4);
|
expect(rebuildCount, 4);
|
||||||
|
|
||||||
expect(data.devicePixelRatio, 44);
|
expect(data.devicePixelRatio, 44);
|
||||||
tester.binding.window.devicePixelRatioTestValue = 55;
|
tester.view.devicePixelRatio = 55;
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(data.devicePixelRatio, 55);
|
expect(data.devicePixelRatio, 55);
|
||||||
expect(rebuildCount, 5);
|
expect(rebuildCount, 5);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQuery.fromView updates on notifications (with parent data)', (WidgetTester tester) async {
|
testWidgets('MediaQuery.fromView updates on notifications (with parent data)', (WidgetTester tester) async {
|
||||||
tester.binding.platformDispatcher
|
addTearDown(() => tester.platformDispatcher.clearAllTestValues());
|
||||||
|
addTearDown(() => tester.view.reset());
|
||||||
|
|
||||||
|
tester.platformDispatcher
|
||||||
..textScaleFactorTestValue = 123
|
..textScaleFactorTestValue = 123
|
||||||
..platformBrightnessTestValue = Brightness.dark
|
..platformBrightnessTestValue = Brightness.dark
|
||||||
..accessibilityFeaturesTestValue = FakeAccessibilityFeatures.allOn;
|
..accessibilityFeaturesTestValue = FakeAccessibilityFeatures.allOn;
|
||||||
addTearDown(() => tester.binding.platformDispatcher.clearAllTestValues());
|
tester.view.devicePixelRatio = 44;
|
||||||
tester.binding.window.devicePixelRatioTestValue = 44;
|
|
||||||
addTearDown(() => tester.binding.window.clearAllTestValues());
|
|
||||||
|
|
||||||
late MediaQueryData data;
|
late MediaQueryData data;
|
||||||
int rebuildCount = 0;
|
int rebuildCount = 0;
|
||||||
@ -436,7 +398,7 @@ void main() {
|
|||||||
accessibleNavigation: true,
|
accessibleNavigation: true,
|
||||||
),
|
),
|
||||||
child: MediaQuery.fromView(
|
child: MediaQuery.fromView(
|
||||||
view: tester.binding.window,
|
view: tester.view,
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
rebuildCount++;
|
rebuildCount++;
|
||||||
@ -451,25 +413,25 @@ void main() {
|
|||||||
expect(rebuildCount, 1);
|
expect(rebuildCount, 1);
|
||||||
|
|
||||||
expect(data.textScaleFactor, 44);
|
expect(data.textScaleFactor, 44);
|
||||||
tester.binding.platformDispatcher.textScaleFactorTestValue = 456;
|
tester.platformDispatcher.textScaleFactorTestValue = 456;
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(data.textScaleFactor, 44);
|
expect(data.textScaleFactor, 44);
|
||||||
expect(rebuildCount, 1);
|
expect(rebuildCount, 1);
|
||||||
|
|
||||||
expect(data.platformBrightness, Brightness.dark);
|
expect(data.platformBrightness, Brightness.dark);
|
||||||
tester.binding.platformDispatcher.platformBrightnessTestValue = Brightness.light;
|
tester.platformDispatcher.platformBrightnessTestValue = Brightness.light;
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(data.platformBrightness, Brightness.dark);
|
expect(data.platformBrightness, Brightness.dark);
|
||||||
expect(rebuildCount, 1);
|
expect(rebuildCount, 1);
|
||||||
|
|
||||||
expect(data.accessibleNavigation, true);
|
expect(data.accessibleNavigation, true);
|
||||||
tester.binding.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures();
|
tester.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(data.accessibleNavigation, true);
|
expect(data.accessibleNavigation, true);
|
||||||
expect(rebuildCount, 1);
|
expect(rebuildCount, 1);
|
||||||
|
|
||||||
expect(data.devicePixelRatio, 44);
|
expect(data.devicePixelRatio, 44);
|
||||||
tester.binding.window.devicePixelRatioTestValue = 55;
|
tester.view.devicePixelRatio = 55;
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(data.devicePixelRatio, 55);
|
expect(data.devicePixelRatio, 55);
|
||||||
expect(rebuildCount, 2);
|
expect(rebuildCount, 2);
|
||||||
@ -487,7 +449,7 @@ void main() {
|
|||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
data: MediaQueryData(textScaleFactor: textScaleFactor),
|
data: MediaQueryData(textScaleFactor: textScaleFactor),
|
||||||
child: MediaQuery.fromView(
|
child: MediaQuery.fromView(
|
||||||
view: tester.binding.window,
|
view: tester.view,
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
rebuildCount++;
|
rebuildCount++;
|
||||||
@ -513,7 +475,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQueryData.copyWith defaults to source', (WidgetTester tester) async {
|
testWidgets('MediaQueryData.copyWith defaults to source', (WidgetTester tester) async {
|
||||||
final MediaQueryData data = MediaQueryData.fromView(tester.binding.window);
|
final MediaQueryData data = MediaQueryData.fromView(tester.view);
|
||||||
final MediaQueryData copied = data.copyWith();
|
final MediaQueryData copied = data.copyWith();
|
||||||
expect(copied.size, data.size);
|
expect(copied.size, data.size);
|
||||||
expect(copied.devicePixelRatio, data.devicePixelRatio);
|
expect(copied.devicePixelRatio, data.devicePixelRatio);
|
||||||
@ -552,7 +514,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
final MediaQueryData data = MediaQueryData.fromView(tester.binding.window);
|
final MediaQueryData data = MediaQueryData.fromView(tester.view);
|
||||||
final MediaQueryData copied = data.copyWith(
|
final MediaQueryData copied = data.copyWith(
|
||||||
size: customSize,
|
size: customSize,
|
||||||
devicePixelRatio: customDevicePixelRatio,
|
devicePixelRatio: customDevicePixelRatio,
|
||||||
@ -1325,11 +1287,11 @@ void main() {
|
|||||||
expect(subScreenMediaQuery.displayFeatures, <DisplayFeature>[cutoutDisplayFeature]);
|
expect(subScreenMediaQuery.displayFeatures, <DisplayFeature>[cutoutDisplayFeature]);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQueryData.gestureSettings is set from window.viewConfiguration', (WidgetTester tester) async {
|
testWidgets('MediaQueryData.gestureSettings is set from view.gestureSettings', (WidgetTester tester) async {
|
||||||
tester.binding.window.gestureSettingsTestValue = const GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100);
|
tester.view.gestureSettings = const GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100);
|
||||||
|
addTearDown(() => tester.view.resetGestureSettings());
|
||||||
|
|
||||||
expect(MediaQueryData.fromView(tester.binding.window).gestureSettings.touchSlop, closeTo(33.33, 0.1)); // Repeating, of course
|
expect(MediaQueryData.fromView(tester.view).gestureSettings.touchSlop, closeTo(33.33, 0.1)); // Repeating, of course
|
||||||
tester.binding.window.clearGestureSettingsTestValue();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('MediaQuery can be partially depended-on', (WidgetTester tester) async {
|
testWidgets('MediaQuery can be partially depended-on', (WidgetTester tester) async {
|
||||||
@ -1511,52 +1473,3 @@ Future<void> pumpWidgetWithoutViewWrapper({required WidgetTester tester, require
|
|||||||
tester.binding.scheduleFrame();
|
tester.binding.scheduleFrame();
|
||||||
return tester.binding.pump();
|
return tester.binding.pump();
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestView implements FlutterView {
|
|
||||||
TestView({
|
|
||||||
PlatformDispatcher? platformDispatcher,
|
|
||||||
required this.physicalSize,
|
|
||||||
required this.devicePixelRatio,
|
|
||||||
required this.padding,
|
|
||||||
required this.viewPadding,
|
|
||||||
required this.viewInsets,
|
|
||||||
required this.systemGestureInsets,
|
|
||||||
}) : _platformDispatcher = platformDispatcher;
|
|
||||||
|
|
||||||
@override
|
|
||||||
PlatformDispatcher get platformDispatcher => _platformDispatcher!;
|
|
||||||
final PlatformDispatcher? _platformDispatcher;
|
|
||||||
@override
|
|
||||||
final Size physicalSize;
|
|
||||||
@override
|
|
||||||
final double devicePixelRatio;
|
|
||||||
@override
|
|
||||||
final ViewPadding padding;
|
|
||||||
@override
|
|
||||||
final ViewPadding viewPadding;
|
|
||||||
@override
|
|
||||||
final ViewPadding viewInsets;
|
|
||||||
@override
|
|
||||||
final ViewPadding systemGestureInsets;
|
|
||||||
@override
|
|
||||||
final List<DisplayFeature> displayFeatures = <DisplayFeature>[];
|
|
||||||
@override
|
|
||||||
final GestureSettings gestureSettings = const GestureSettings();
|
|
||||||
|
|
||||||
@override
|
|
||||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestViewPadding implements ViewPadding {
|
|
||||||
const TestViewPadding(this.value);
|
|
||||||
final double value;
|
|
||||||
|
|
||||||
@override
|
|
||||||
double get bottom => value;
|
|
||||||
@override
|
|
||||||
double get left => value;
|
|
||||||
@override
|
|
||||||
double get right => value;
|
|
||||||
@override
|
|
||||||
double get top => value;
|
|
||||||
}
|
|
||||||
|
@ -223,7 +223,7 @@ void main() {
|
|||||||
'_RenderDiagonal#00000 relayoutBoundary=up1\n'
|
'_RenderDiagonal#00000 relayoutBoundary=up1\n'
|
||||||
' │ creator: _Diagonal ← Align ← Directionality ← MediaQuery ←\n'
|
' │ creator: _Diagonal ← Align ← Directionality ← MediaQuery ←\n'
|
||||||
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
|
||||||
' │ TestWindow#00000] ← [root]\n'
|
' │ TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
|
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
|
||||||
' │ size: Size(190.0, 220.0)\n'
|
' │ size: Size(190.0, 220.0)\n'
|
||||||
@ -231,7 +231,7 @@ void main() {
|
|||||||
' ├─topLeft: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
|
' ├─topLeft: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
|
||||||
' │ creator: SizedBox ← _Diagonal ← Align ← Directionality ←\n'
|
' │ creator: SizedBox ← _Diagonal ← Align ← Directionality ←\n'
|
||||||
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
||||||
' │ View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' │ View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
|
||||||
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
|
||||||
' │ constraints: BoxConstraints(unconstrained)\n'
|
' │ constraints: BoxConstraints(unconstrained)\n'
|
||||||
' │ size: Size(80.0, 100.0)\n'
|
' │ size: Size(80.0, 100.0)\n'
|
||||||
@ -240,7 +240,7 @@ void main() {
|
|||||||
' └─bottomRight: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
|
' └─bottomRight: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
|
||||||
' creator: SizedBox ← _Diagonal ← Align ← Directionality ←\n'
|
' creator: SizedBox ← _Diagonal ← Align ← Directionality ←\n'
|
||||||
' MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
' MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
|
||||||
' View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
|
' View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
|
||||||
' parentData: offset=Offset(80.0, 100.0) (can use size)\n'
|
' parentData: offset=Offset(80.0, 100.0) (can use size)\n'
|
||||||
' constraints: BoxConstraints(unconstrained)\n'
|
' constraints: BoxConstraints(unconstrained)\n'
|
||||||
' size: Size(110.0, 120.0)\n'
|
' size: Size(110.0, 120.0)\n'
|
||||||
|
@ -182,17 +182,18 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||||||
///
|
///
|
||||||
/// This constructor overrides the [debugPrint] global hook to point to
|
/// This constructor overrides the [debugPrint] global hook to point to
|
||||||
/// [debugPrintOverride], which can be overridden by subclasses.
|
/// [debugPrintOverride], which can be overridden by subclasses.
|
||||||
TestWidgetsFlutterBinding() : _window = TestWindow(window: ui.window) {
|
TestWidgetsFlutterBinding() : platformDispatcher = TestPlatformDispatcher(
|
||||||
|
platformDispatcher: PlatformDispatcher.instance,
|
||||||
|
) {
|
||||||
debugPrint = debugPrintOverride;
|
debugPrint = debugPrintOverride;
|
||||||
debugDisableShadows = disableShadows;
|
debugDisableShadows = disableShadows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TestWindow get window => _window;
|
late final TestWindow window;
|
||||||
final TestWindow _window;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TestPlatformDispatcher get platformDispatcher => _window.platformDispatcher;
|
final TestPlatformDispatcher platformDispatcher;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TestRestorationManager get restorationManager {
|
TestRestorationManager get restorationManager {
|
||||||
@ -346,6 +347,12 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initInstances() {
|
void initInstances() {
|
||||||
|
// This is intialized here because it's needed for the `super.initInstances`
|
||||||
|
// call. It can't be handled as a ctor initializer because it's dependent
|
||||||
|
// on `platformDispatcher`. It can't be handled in the ctor itself because
|
||||||
|
// the base class ctor is called first and calls `initInstances`.
|
||||||
|
window = TestWindow.fromPlatformDispatcher(platformDispatcher: platformDispatcher);
|
||||||
|
|
||||||
super.initInstances();
|
super.initInstances();
|
||||||
_instance = this;
|
_instance = this;
|
||||||
timeDilation = 1.0; // just in case the developer has artificially changed it for development
|
timeDilation = 1.0; // just in case the developer has artificially changed it for development
|
||||||
|
@ -14,6 +14,7 @@ import 'event_simulation.dart';
|
|||||||
import 'finders.dart';
|
import 'finders.dart';
|
||||||
import 'test_async_utils.dart';
|
import 'test_async_utils.dart';
|
||||||
import 'test_pointer.dart';
|
import 'test_pointer.dart';
|
||||||
|
import 'window.dart';
|
||||||
|
|
||||||
/// The default drag touch slop used to break up a large drag into multiple
|
/// The default drag touch slop used to break up a large drag into multiple
|
||||||
/// smaller moves.
|
/// smaller moves.
|
||||||
@ -234,6 +235,37 @@ abstract class WidgetController {
|
|||||||
/// A reference to the current instance of the binding.
|
/// A reference to the current instance of the binding.
|
||||||
final WidgetsBinding binding;
|
final WidgetsBinding binding;
|
||||||
|
|
||||||
|
/// The [TestPlatformDispatcher] that is being used in this test.
|
||||||
|
///
|
||||||
|
/// This will be injected into the framework such that calls to
|
||||||
|
/// [WidgetsBinding.platformDispatcher] will use this. This allows
|
||||||
|
/// users to change platform specific properties for testing.
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [TestFlutterView] which allows changing view specific properties
|
||||||
|
/// for testing
|
||||||
|
/// * [view] and [viewOf] which are used to find
|
||||||
|
/// [TestFlutterView]s from the widget tree
|
||||||
|
TestPlatformDispatcher get platformDispatcher => binding.platformDispatcher as TestPlatformDispatcher;
|
||||||
|
|
||||||
|
/// The [TestFlutterView] provided by default when testing with
|
||||||
|
/// [WidgetTester.pumpWidget].
|
||||||
|
///
|
||||||
|
/// If the test requires multiple views, it will need to use [viewOf] instead
|
||||||
|
/// to ensure that the view related to the widget being evaluated is the one
|
||||||
|
/// that gets updated.
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [viewOf], which can find a [TestFlutterView] related to a given finder.
|
||||||
|
/// This is how to modify view properties for testing when dealing with
|
||||||
|
/// multiple views.
|
||||||
|
TestFlutterView get view {
|
||||||
|
assert(platformDispatcher.views.length == 1, 'When testing with multiple views, use `viewOf` instead.');
|
||||||
|
return platformDispatcher.views.single;
|
||||||
|
}
|
||||||
|
|
||||||
/// Provides access to a [SemanticsController] for testing anything related to
|
/// Provides access to a [SemanticsController] for testing anything related to
|
||||||
/// the [Semantics] tree.
|
/// the [Semantics] tree.
|
||||||
///
|
///
|
||||||
@ -257,6 +289,26 @@ abstract class WidgetController {
|
|||||||
// TODO(ianh): verify that the return values are of type T and throw
|
// TODO(ianh): verify that the return values are of type T and throw
|
||||||
// a good message otherwise, in all the generic methods below
|
// a good message otherwise, in all the generic methods below
|
||||||
|
|
||||||
|
/// Finds the [TestFlutterView] that is the closest ancestor of the widget
|
||||||
|
/// found by [finder].
|
||||||
|
///
|
||||||
|
/// [TestFlutterView] can be used to modify view specific properties for testing.
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [view] which returns the [TestFlutterView] used when only a single
|
||||||
|
/// view is being used.
|
||||||
|
TestFlutterView viewOf(Finder finder) {
|
||||||
|
final View view = firstWidget<View>(
|
||||||
|
find.ancestor(
|
||||||
|
of: finder,
|
||||||
|
matching: find.byType(View),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return view.view as TestFlutterView;
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks if `finder` exists in the tree.
|
/// Checks if `finder` exists in the tree.
|
||||||
bool any(Finder finder) {
|
bool any(Finder finder) {
|
||||||
TestAsyncUtils.guardSync();
|
TestAsyncUtils.guardSync();
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -711,6 +711,25 @@ void main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('platformDispatcher exposes the platformDispatcher from binding', (WidgetTester tester) async {
|
||||||
|
expect(tester.platformDispatcher, tester.binding.platformDispatcher);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('view exposes the implicitView from platformDispatcher', (WidgetTester tester) async {
|
||||||
|
expect(tester.view, tester.platformDispatcher.implicitView);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('viewOf finds a view when the view is implicit', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(const MaterialApp(
|
||||||
|
home: Center(
|
||||||
|
child: Text('Test'),
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(() => tester.viewOf(find.text('Test')), isNot(throwsA(anything)));
|
||||||
|
expect(tester.viewOf(find.text('Test')), isA<TestFlutterView>());
|
||||||
|
});
|
||||||
|
|
||||||
group('SemanticsController', () {
|
group('SemanticsController', () {
|
||||||
group('find', () {
|
group('find', () {
|
||||||
testWidgets('throws when there are no semantics', (WidgetTester tester) async {
|
testWidgets('throws when there are no semantics', (WidgetTester tester) async {
|
||||||
|
@ -7,15 +7,17 @@ import 'dart:ui' show AccessibilityFeatures, Brightness, Locale, PlatformDispatc
|
|||||||
import 'package:flutter/widgets.dart' show WidgetsBinding, WidgetsBindingObserver;
|
import 'package:flutter/widgets.dart' show WidgetsBinding, WidgetsBindingObserver;
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import 'utils/fake_and_mock_utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('TestWindow can handle new methods without breaking', () {
|
test('TestPlatformDispatcher can handle new methods without breaking', () {
|
||||||
final dynamic testPlatformDispatcher = TestPlatformDispatcher(platformDispatcher: PlatformDispatcher.instance);
|
final dynamic testPlatformDispatcher = TestPlatformDispatcher(platformDispatcher: PlatformDispatcher.instance);
|
||||||
// ignore: avoid_dynamic_calls
|
// ignore: avoid_dynamic_calls
|
||||||
expect(testPlatformDispatcher.someNewProperty, null);
|
expect(testPlatformDispatcher.someNewProperty, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake locale', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can fake locale', (WidgetTester tester) async {
|
||||||
verifyThatTestPlatformDispatcherCanFakeProperty<Locale>(
|
verifyPropertyFaked<Locale>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: PlatformDispatcher.instance.locale,
|
realValue: PlatformDispatcher.instance.locale,
|
||||||
fakeValue: const Locale('fake_language_code'),
|
fakeValue: const Locale('fake_language_code'),
|
||||||
@ -28,8 +30,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake locales', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can fake locales', (WidgetTester tester) async {
|
||||||
verifyThatTestPlatformDispatcherCanFakeProperty<List<Locale>>(
|
verifyPropertyFaked<List<Locale>>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: PlatformDispatcher.instance.locales,
|
realValue: PlatformDispatcher.instance.locales,
|
||||||
fakeValue: <Locale>[const Locale('fake_language_code')],
|
fakeValue: <Locale>[const Locale('fake_language_code')],
|
||||||
@ -42,8 +44,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake text scale factor', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can fake text scale factor', (WidgetTester tester) async {
|
||||||
verifyThatTestPlatformDispatcherCanFakeProperty<double>(
|
verifyPropertyFaked<double>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: PlatformDispatcher.instance.textScaleFactor,
|
realValue: PlatformDispatcher.instance.textScaleFactor,
|
||||||
fakeValue: 2.5,
|
fakeValue: 2.5,
|
||||||
@ -56,8 +58,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake clock format', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can fake clock format', (WidgetTester tester) async {
|
||||||
verifyThatTestPlatformDispatcherCanFakeProperty<bool>(
|
verifyPropertyFaked<bool>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: PlatformDispatcher.instance.alwaysUse24HourFormat,
|
realValue: PlatformDispatcher.instance.alwaysUse24HourFormat,
|
||||||
fakeValue: !PlatformDispatcher.instance.alwaysUse24HourFormat,
|
fakeValue: !PlatformDispatcher.instance.alwaysUse24HourFormat,
|
||||||
@ -70,8 +72,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake brieflyShowPassword', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can fake brieflyShowPassword', (WidgetTester tester) async {
|
||||||
verifyThatTestPlatformDispatcherCanFakeProperty<bool>(
|
verifyPropertyFaked<bool>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: PlatformDispatcher.instance.brieflyShowPassword,
|
realValue: PlatformDispatcher.instance.brieflyShowPassword,
|
||||||
fakeValue: !PlatformDispatcher.instance.brieflyShowPassword,
|
fakeValue: !PlatformDispatcher.instance.brieflyShowPassword,
|
||||||
@ -82,8 +84,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake default route name', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can fake default route name', (WidgetTester tester) async {
|
||||||
verifyThatTestPlatformDispatcherCanFakeProperty<String>(
|
verifyPropertyFaked<String>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: PlatformDispatcher.instance.defaultRouteName,
|
realValue: PlatformDispatcher.instance.defaultRouteName,
|
||||||
fakeValue: 'fake_route',
|
fakeValue: 'fake_route',
|
||||||
@ -96,8 +98,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake accessibility features', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can fake accessibility features', (WidgetTester tester) async {
|
||||||
verifyThatTestPlatformDispatcherCanFakeProperty<AccessibilityFeatures>(
|
verifyPropertyFaked<AccessibilityFeatures>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: PlatformDispatcher.instance.accessibilityFeatures,
|
realValue: PlatformDispatcher.instance.accessibilityFeatures,
|
||||||
fakeValue: const FakeAccessibilityFeatures(),
|
fakeValue: const FakeAccessibilityFeatures(),
|
||||||
@ -110,8 +112,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake platform brightness', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can fake platform brightness', (WidgetTester tester) async {
|
||||||
verifyThatTestPlatformDispatcherCanFakeProperty<Brightness>(
|
verifyPropertyFaked<Brightness>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: Brightness.light,
|
realValue: Brightness.light,
|
||||||
fakeValue: Brightness.dark,
|
fakeValue: Brightness.dark,
|
||||||
@ -124,7 +126,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can clear out fake properties all at once', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher can clear out fake properties all at once', (WidgetTester tester) async {
|
||||||
final Locale originalLocale = PlatformDispatcher.instance.locale;
|
final Locale originalLocale = PlatformDispatcher.instance.locale;
|
||||||
final double originalTextScaleFactor = PlatformDispatcher.instance.textScaleFactor;
|
final double originalTextScaleFactor = PlatformDispatcher.instance.textScaleFactor;
|
||||||
final TestPlatformDispatcher testPlatformDispatcher = retrieveTestBinding(tester).platformDispatcher;
|
final TestPlatformDispatcher testPlatformDispatcher = retrieveTestBinding(tester).platformDispatcher;
|
||||||
@ -141,7 +143,7 @@ void main() {
|
|||||||
expect(WidgetsBinding.instance.platformDispatcher.textScaleFactor, originalTextScaleFactor);
|
expect(WidgetsBinding.instance.platformDispatcher.textScaleFactor, originalTextScaleFactor);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow sends fake locales when WidgetsBindingObserver notifiers are called', (WidgetTester tester) async {
|
testWidgets('TestPlatformDispatcher sends fake locales when WidgetsBindingObserver notifiers are called', (WidgetTester tester) async {
|
||||||
final List<Locale> defaultLocales = WidgetsBinding.instance.platformDispatcher.locales;
|
final List<Locale> defaultLocales = WidgetsBinding.instance.platformDispatcher.locales;
|
||||||
final TestObserver observer = TestObserver();
|
final TestObserver observer = TestObserver();
|
||||||
retrieveTestBinding(tester).addObserver(observer);
|
retrieveTestBinding(tester).addObserver(observer);
|
||||||
@ -152,36 +154,8 @@ void main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifyThatTestPlatformDispatcherCanFakeProperty<PlatformDispatcherPropertyType>({
|
|
||||||
required WidgetTester tester,
|
|
||||||
required PlatformDispatcherPropertyType? realValue,
|
|
||||||
required PlatformDispatcherPropertyType fakeValue,
|
|
||||||
required PlatformDispatcherPropertyType? Function() propertyRetriever,
|
|
||||||
required Function(TestWidgetsFlutterBinding, PlatformDispatcherPropertyType fakeValue) propertyFaker,
|
|
||||||
}) {
|
|
||||||
PlatformDispatcherPropertyType? propertyBeforeFaking;
|
|
||||||
PlatformDispatcherPropertyType? propertyAfterFaking;
|
|
||||||
|
|
||||||
propertyBeforeFaking = propertyRetriever();
|
|
||||||
|
|
||||||
propertyFaker(retrieveTestBinding(tester), fakeValue);
|
|
||||||
|
|
||||||
propertyAfterFaking = propertyRetriever();
|
|
||||||
|
|
||||||
expect(propertyBeforeFaking, realValue);
|
|
||||||
expect(propertyAfterFaking, fakeValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
TestWidgetsFlutterBinding retrieveTestBinding(WidgetTester tester) {
|
|
||||||
final WidgetsBinding binding = tester.binding;
|
|
||||||
assert(binding is TestWidgetsFlutterBinding);
|
|
||||||
final TestWidgetsFlutterBinding testBinding = binding as TestWidgetsFlutterBinding;
|
|
||||||
return testBinding;
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestObserver with WidgetsBindingObserver {
|
class TestObserver with WidgetsBindingObserver {
|
||||||
List<Locale>? locales;
|
List<Locale>? locales;
|
||||||
Locale? locale;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeLocales(List<Locale>? locales) {
|
void didChangeLocales(List<Locale>? locales) {
|
||||||
|
114
packages/flutter_test/test/utils/fake_and_mock_utils.dart
Normal file
114
packages/flutter_test/test/utils/fake_and_mock_utils.dart
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
// 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 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
TestWidgetsFlutterBinding retrieveTestBinding(WidgetTester tester) {
|
||||||
|
final WidgetsBinding binding = tester.binding;
|
||||||
|
assert(binding is TestWidgetsFlutterBinding);
|
||||||
|
final TestWidgetsFlutterBinding testBinding = binding as TestWidgetsFlutterBinding;
|
||||||
|
return testBinding;
|
||||||
|
}
|
||||||
|
|
||||||
|
void verifyPropertyFaked<TProperty>({
|
||||||
|
required WidgetTester tester,
|
||||||
|
required TProperty realValue,
|
||||||
|
required TProperty fakeValue,
|
||||||
|
required TProperty Function() propertyRetriever,
|
||||||
|
required Function(TestWidgetsFlutterBinding, TProperty fakeValue) propertyFaker,
|
||||||
|
Matcher Function(TProperty) matcher = equals,
|
||||||
|
}) {
|
||||||
|
TProperty propertyBeforeFaking;
|
||||||
|
TProperty propertyAfterFaking;
|
||||||
|
|
||||||
|
propertyBeforeFaking = propertyRetriever();
|
||||||
|
|
||||||
|
propertyFaker(retrieveTestBinding(tester), fakeValue);
|
||||||
|
|
||||||
|
propertyAfterFaking = propertyRetriever();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
realValue == fakeValue,
|
||||||
|
isFalse,
|
||||||
|
reason: 'Since the real value and fake value are equal, we cannot validate '
|
||||||
|
'that a property has been faked. Choose a different fake value to test.',
|
||||||
|
);
|
||||||
|
expect(propertyBeforeFaking, matcher(realValue));
|
||||||
|
expect(propertyAfterFaking, matcher(fakeValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
void verifyPropertyReset<TProperty>({
|
||||||
|
required WidgetTester tester,
|
||||||
|
required TProperty fakeValue,
|
||||||
|
required TProperty Function() propertyRetriever,
|
||||||
|
required Function() propertyResetter,
|
||||||
|
required Function(TProperty fakeValue) propertyFaker,
|
||||||
|
Matcher Function(TProperty) matcher = equals,
|
||||||
|
}) {
|
||||||
|
TProperty propertyBeforeFaking;
|
||||||
|
TProperty propertyAfterFaking;
|
||||||
|
TProperty propertyAfterReset;
|
||||||
|
|
||||||
|
propertyBeforeFaking = propertyRetriever();
|
||||||
|
|
||||||
|
propertyFaker(fakeValue);
|
||||||
|
|
||||||
|
propertyAfterFaking = propertyRetriever();
|
||||||
|
|
||||||
|
propertyResetter();
|
||||||
|
|
||||||
|
propertyAfterReset = propertyRetriever();
|
||||||
|
|
||||||
|
expect(propertyAfterFaking, matcher(fakeValue));
|
||||||
|
expect(propertyAfterReset, matcher(propertyBeforeFaking));
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher matchesViewPadding(ViewPadding expected) => _FakeViewPaddingMatcher(expected);
|
||||||
|
|
||||||
|
class _FakeViewPaddingMatcher extends Matcher {
|
||||||
|
_FakeViewPaddingMatcher(this.expected);
|
||||||
|
|
||||||
|
final ViewPadding expected;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Description describe(Description description) {
|
||||||
|
description.add('two ViewPadding instances match');
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Description describeMismatch(dynamic item, Description mismatchDescription, Map<dynamic, dynamic> matchState, bool verbose) {
|
||||||
|
assert(item is ViewPadding, 'Can only match against implementations of ViewPadding.');
|
||||||
|
final ViewPadding actual = item as ViewPadding;
|
||||||
|
|
||||||
|
if (actual.left != expected.left) {
|
||||||
|
mismatchDescription.add('actual.left (${actual.left}) did not match expected.left (${expected.left})');
|
||||||
|
}
|
||||||
|
if (actual.top != expected.top) {
|
||||||
|
mismatchDescription.add('actual.top (${actual.top}) did not match expected.top (${expected.top})');
|
||||||
|
}
|
||||||
|
if (actual.right != expected.right) {
|
||||||
|
mismatchDescription.add('actual.right (${actual.right}) did not match expected.right (${expected.right})');
|
||||||
|
}
|
||||||
|
if (actual.bottom != expected.bottom) {
|
||||||
|
mismatchDescription.add('actual.bottom (${actual.bottom}) did not match expected.bottom (${expected.bottom})');
|
||||||
|
}
|
||||||
|
|
||||||
|
return mismatchDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
|
||||||
|
assert(item is ViewPadding, 'Can only match against implementations of ViewPadding.');
|
||||||
|
final ViewPadding actual = item as ViewPadding;
|
||||||
|
|
||||||
|
return actual.left == expected.left &&
|
||||||
|
actual.top == expected.top &&
|
||||||
|
actual.right == expected.right &&
|
||||||
|
actual.bottom == expected.bottom;
|
||||||
|
}
|
||||||
|
}
|
445
packages/flutter_test/test/view_test.dart
Normal file
445
packages/flutter_test/test/view_test.dart
Normal file
@ -0,0 +1,445 @@
|
|||||||
|
// 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 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import 'utils/fake_and_mock_utils.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('TestFlutterView', () {
|
||||||
|
FlutterView trueImplicitView() => PlatformDispatcher.instance.implicitView!;
|
||||||
|
FlutterView boundImplicitView() => WidgetsBinding.instance.platformDispatcher.implicitView!;
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
final TestFlutterView view = (WidgetsBinding.instance as TestWidgetsFlutterBinding).platformDispatcher.views.single;
|
||||||
|
view.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can handle new methods without breaking', (WidgetTester tester) async {
|
||||||
|
final dynamic testView = tester.view;
|
||||||
|
// ignore: avoid_dynamic_calls
|
||||||
|
expect(testView.someNewProperty, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can fake devicePixelRatio', (WidgetTester tester) async {
|
||||||
|
verifyPropertyFaked<double>(
|
||||||
|
tester: tester,
|
||||||
|
realValue: trueImplicitView().devicePixelRatio,
|
||||||
|
fakeValue: 2.5,
|
||||||
|
propertyRetriever: () => boundImplicitView().devicePixelRatio,
|
||||||
|
propertyFaker: (_, double fakeValue) {
|
||||||
|
tester.view.devicePixelRatio = fakeValue;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can reset devicePixelRatio', (WidgetTester tester) async {
|
||||||
|
verifyPropertyReset<double>(
|
||||||
|
tester: tester,
|
||||||
|
fakeValue: 2.5,
|
||||||
|
propertyRetriever: () => boundImplicitView().devicePixelRatio,
|
||||||
|
propertyResetter: () {
|
||||||
|
tester.view.resetDevicePixelRatio();
|
||||||
|
},
|
||||||
|
propertyFaker: (double fakeValue) {
|
||||||
|
tester.view.devicePixelRatio = fakeValue;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can fake displayFeatures', (WidgetTester tester) async {
|
||||||
|
verifyPropertyFaked<List<DisplayFeature>>(
|
||||||
|
tester: tester,
|
||||||
|
realValue: trueImplicitView().displayFeatures,
|
||||||
|
fakeValue: <DisplayFeature>[const DisplayFeature(bounds: Rect.fromLTWH(0, 0, 500, 30), type: DisplayFeatureType.unknown, state: DisplayFeatureState.unknown)],
|
||||||
|
propertyRetriever: () => boundImplicitView().displayFeatures,
|
||||||
|
propertyFaker: (_, List<DisplayFeature> fakeValue) {
|
||||||
|
tester.view.displayFeatures = fakeValue;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can reset displayFeatures', (WidgetTester tester) async {
|
||||||
|
verifyPropertyReset<List<DisplayFeature>>(
|
||||||
|
tester: tester,
|
||||||
|
fakeValue: <DisplayFeature>[const DisplayFeature(bounds: Rect.fromLTWH(0, 0, 500, 30), type: DisplayFeatureType.unknown, state: DisplayFeatureState.unknown)],
|
||||||
|
propertyRetriever: () => boundImplicitView().displayFeatures,
|
||||||
|
propertyResetter: () {
|
||||||
|
tester.view.resetDisplayFeatures();
|
||||||
|
},
|
||||||
|
propertyFaker: (List<DisplayFeature> fakeValue) {
|
||||||
|
tester.view.displayFeatures = fakeValue;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can fake padding', (WidgetTester tester) async {
|
||||||
|
verifyPropertyFaked<ViewPadding>(
|
||||||
|
tester: tester,
|
||||||
|
realValue: trueImplicitView().padding,
|
||||||
|
fakeValue: const FakeViewPadding(),
|
||||||
|
propertyRetriever: () => boundImplicitView().padding,
|
||||||
|
propertyFaker: (_, ViewPadding fakeValue) {
|
||||||
|
tester.view.padding = fakeValue as FakeViewPadding;
|
||||||
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can reset padding', (WidgetTester tester) async {
|
||||||
|
verifyPropertyReset<ViewPadding>(
|
||||||
|
tester: tester,
|
||||||
|
fakeValue: const FakeViewPadding(),
|
||||||
|
propertyRetriever: () => boundImplicitView().padding,
|
||||||
|
propertyResetter: () {
|
||||||
|
tester.view.resetPadding();
|
||||||
|
},
|
||||||
|
propertyFaker: (ViewPadding fakeValue) {
|
||||||
|
tester.view.padding = fakeValue as FakeViewPadding;
|
||||||
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can fake physicalGeometry', (WidgetTester tester) async {
|
||||||
|
verifyPropertyFaked<Rect>(
|
||||||
|
tester: tester,
|
||||||
|
realValue: trueImplicitView().physicalGeometry,
|
||||||
|
fakeValue: const Rect.fromLTWH(0, 0, 550, 850),
|
||||||
|
propertyRetriever: () => boundImplicitView().physicalGeometry,
|
||||||
|
propertyFaker: (_, Rect fakeValue) {
|
||||||
|
tester.view.physicalGeometry = fakeValue;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can reset physicalGeometry', (WidgetTester tester) async {
|
||||||
|
verifyPropertyReset<Rect>(
|
||||||
|
tester: tester,
|
||||||
|
fakeValue: const Rect.fromLTWH(0, 0, 35, 475),
|
||||||
|
propertyRetriever: () => boundImplicitView().physicalGeometry,
|
||||||
|
propertyResetter: () {
|
||||||
|
tester.view.resetPhysicalGeometry();
|
||||||
|
},
|
||||||
|
propertyFaker: (Rect fakeValue) {
|
||||||
|
tester.view.physicalGeometry = fakeValue;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('updating physicalGeometry also updates physicalSize', (WidgetTester tester) async {
|
||||||
|
const Rect testGeometry = Rect.fromLTWH(0, 0, 450, 575);
|
||||||
|
tester.view.physicalGeometry = testGeometry;
|
||||||
|
|
||||||
|
expect(tester.view.physicalSize, testGeometry.size);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can fake physicalSize', (WidgetTester tester) async {
|
||||||
|
verifyPropertyFaked<Size>(
|
||||||
|
tester: tester,
|
||||||
|
realValue: trueImplicitView().physicalSize,
|
||||||
|
fakeValue: const Size(50, 50),
|
||||||
|
propertyRetriever: () => boundImplicitView().physicalSize,
|
||||||
|
propertyFaker: (_, Size fakeValue) {
|
||||||
|
tester.view.physicalSize = fakeValue;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can reset physicalSize', (WidgetTester tester) async {
|
||||||
|
verifyPropertyReset<Size>(
|
||||||
|
tester: tester,
|
||||||
|
fakeValue: const Size(50, 50),
|
||||||
|
propertyRetriever: () => boundImplicitView().physicalSize,
|
||||||
|
propertyResetter: () {
|
||||||
|
tester.view.resetPhysicalSize();
|
||||||
|
},
|
||||||
|
propertyFaker: (Size fakeValue) {
|
||||||
|
tester.view.physicalSize = fakeValue;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('updating physicalSize also updates physicalGeometry', (WidgetTester tester) async {
|
||||||
|
const Rect testGeometry = Rect.fromLTWH(0, 0, 450, 575);
|
||||||
|
const Size testSize = Size(50, 50);
|
||||||
|
const Rect expectedGeometry = Rect.fromLTWH(0, 0, 50, 50);
|
||||||
|
|
||||||
|
tester.view.physicalGeometry = testGeometry;
|
||||||
|
tester.view.physicalSize = testSize;
|
||||||
|
|
||||||
|
expect(tester.view.physicalGeometry, expectedGeometry);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can fake systemGestureInsets', (WidgetTester tester) async {
|
||||||
|
verifyPropertyFaked<ViewPadding>(
|
||||||
|
tester: tester,
|
||||||
|
realValue: trueImplicitView().systemGestureInsets,
|
||||||
|
fakeValue: const FakeViewPadding(),
|
||||||
|
propertyRetriever: () => boundImplicitView().systemGestureInsets,
|
||||||
|
propertyFaker: (_, ViewPadding fakeValue) {
|
||||||
|
tester.view.systemGestureInsets = fakeValue as FakeViewPadding;
|
||||||
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can reset systemGestureInsets', (WidgetTester tester) async {
|
||||||
|
verifyPropertyReset<ViewPadding>(
|
||||||
|
tester: tester,
|
||||||
|
fakeValue: const FakeViewPadding(),
|
||||||
|
propertyRetriever: () => boundImplicitView().systemGestureInsets,
|
||||||
|
propertyResetter: () {
|
||||||
|
tester.view.resetSystemGestureInsets();
|
||||||
|
},
|
||||||
|
propertyFaker: (ViewPadding fakeValue) {
|
||||||
|
tester.view.systemGestureInsets = fakeValue as FakeViewPadding;
|
||||||
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can fake viewInsets', (WidgetTester tester) async {
|
||||||
|
verifyPropertyFaked<ViewPadding>(
|
||||||
|
tester: tester,
|
||||||
|
realValue: trueImplicitView().viewInsets,
|
||||||
|
fakeValue: const FakeViewPadding(),
|
||||||
|
propertyRetriever: () => boundImplicitView().viewInsets,
|
||||||
|
propertyFaker: (_, ViewPadding fakeValue) {
|
||||||
|
tester.view.viewInsets = fakeValue as FakeViewPadding;
|
||||||
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can reset viewInsets', (WidgetTester tester) async {
|
||||||
|
verifyPropertyReset<ViewPadding>(
|
||||||
|
tester: tester,
|
||||||
|
fakeValue: const FakeViewPadding(),
|
||||||
|
propertyRetriever: () => boundImplicitView().viewInsets,
|
||||||
|
propertyResetter: () {
|
||||||
|
tester.view.resetViewInsets();
|
||||||
|
},
|
||||||
|
propertyFaker: (ViewPadding fakeValue) {
|
||||||
|
tester.view.viewInsets = fakeValue as FakeViewPadding;
|
||||||
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can fake viewPadding', (WidgetTester tester) async {
|
||||||
|
verifyPropertyFaked<ViewPadding>(
|
||||||
|
tester: tester,
|
||||||
|
realValue: trueImplicitView().viewPadding,
|
||||||
|
fakeValue: const FakeViewPadding(),
|
||||||
|
propertyRetriever: () => boundImplicitView().viewPadding,
|
||||||
|
propertyFaker: (_, ViewPadding fakeValue) {
|
||||||
|
tester.view.viewPadding = fakeValue as FakeViewPadding;
|
||||||
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can reset viewPadding', (WidgetTester tester) async {
|
||||||
|
verifyPropertyReset<ViewPadding>(
|
||||||
|
tester: tester,
|
||||||
|
fakeValue: const FakeViewPadding(),
|
||||||
|
propertyRetriever: () => boundImplicitView().viewPadding,
|
||||||
|
propertyResetter: () {
|
||||||
|
tester.view.resetViewPadding();
|
||||||
|
},
|
||||||
|
propertyFaker: (ViewPadding fakeValue) {
|
||||||
|
tester.view.viewPadding = fakeValue as FakeViewPadding;
|
||||||
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('can clear out fake properties all at once', (WidgetTester tester) async {
|
||||||
|
final FlutterViewSnapshot initial = FlutterViewSnapshot(tester.view);
|
||||||
|
|
||||||
|
tester.view.devicePixelRatio = 7;
|
||||||
|
tester.view.displayFeatures = <DisplayFeature>[const DisplayFeature(bounds: Rect.fromLTWH(0, 0, 20, 300), type: DisplayFeatureType.unknown, state: DisplayFeatureState.unknown)];
|
||||||
|
tester.view.padding = const FakeViewPadding();
|
||||||
|
tester.view.physicalGeometry = const Rect.fromLTWH(0, 0, 505, 805);
|
||||||
|
tester.view.systemGestureInsets = const FakeViewPadding();
|
||||||
|
tester.view.viewInsets = const FakeViewPadding();
|
||||||
|
tester.view.viewPadding = const FakeViewPadding();
|
||||||
|
tester.view.gestureSettings = const GestureSettings(physicalTouchSlop: 4, physicalDoubleTapSlop: 5);
|
||||||
|
|
||||||
|
final FlutterViewSnapshot faked = FlutterViewSnapshot(tester.view);
|
||||||
|
|
||||||
|
tester.view.reset();
|
||||||
|
|
||||||
|
final FlutterViewSnapshot reset = FlutterViewSnapshot(tester.view);
|
||||||
|
|
||||||
|
expect(initial, isNot(matchesSnapshot(faked)));
|
||||||
|
expect(initial, matchesSnapshot(reset));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('render is passed through to backing FlutterView', (WidgetTester tester) async {
|
||||||
|
final Scene expectedScene = SceneBuilder().build();
|
||||||
|
final _FakeFlutterView backingView = _FakeFlutterView();
|
||||||
|
final TestFlutterView view = TestFlutterView(
|
||||||
|
view: backingView,
|
||||||
|
platformDispatcher: tester.binding.platformDispatcher,
|
||||||
|
);
|
||||||
|
|
||||||
|
view.render(expectedScene);
|
||||||
|
|
||||||
|
expect(backingView.lastRenderedScene, isNotNull);
|
||||||
|
expect(backingView.lastRenderedScene, expectedScene);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('updateSemantics is passed through to backing FlutterView', (WidgetTester tester) async {
|
||||||
|
final SemanticsUpdate expectedUpdate = SemanticsUpdateBuilder().build();
|
||||||
|
final _FakeFlutterView backingView = _FakeFlutterView();
|
||||||
|
final TestFlutterView view = TestFlutterView(
|
||||||
|
view: backingView,
|
||||||
|
platformDispatcher: tester.binding.platformDispatcher,
|
||||||
|
);
|
||||||
|
|
||||||
|
view.updateSemantics(expectedUpdate);
|
||||||
|
|
||||||
|
expect(backingView.lastSemanticsUpdate, isNotNull);
|
||||||
|
expect(backingView.lastSemanticsUpdate, expectedUpdate);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Matcher matchesSnapshot(FlutterViewSnapshot expected) => _FlutterViewSnapshotMatcher(expected);
|
||||||
|
|
||||||
|
class _FlutterViewSnapshotMatcher extends Matcher {
|
||||||
|
_FlutterViewSnapshotMatcher(this.expected);
|
||||||
|
|
||||||
|
final FlutterViewSnapshot expected;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Description describe(Description description) {
|
||||||
|
description.add('snapshot of a FlutterView matches');
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Description describeMismatch(dynamic item, Description mismatchDescription, Map<dynamic, dynamic> matchState, bool verbose) {
|
||||||
|
assert(item is FlutterViewSnapshot, 'Can only match against snapshots of FlutterView.');
|
||||||
|
final FlutterViewSnapshot actual = item as FlutterViewSnapshot;
|
||||||
|
|
||||||
|
if (actual.devicePixelRatio != expected.devicePixelRatio) {
|
||||||
|
mismatchDescription.add('actual.devicePixelRatio (${actual.devicePixelRatio}) did not match expected.devicePixelRatio (${expected.devicePixelRatio})');
|
||||||
|
}
|
||||||
|
if (!actual.displayFeatures.equals(expected.displayFeatures)) {
|
||||||
|
mismatchDescription.add('actual.displayFeatures did not match expected.devicePixelRatio');
|
||||||
|
mismatchDescription.addAll('Actual: [', ',', ']', actual.displayFeatures);
|
||||||
|
mismatchDescription.addAll('Expected: [', ',', ']', expected.displayFeatures);
|
||||||
|
}
|
||||||
|
if (actual.gestureSettings != expected.gestureSettings) {
|
||||||
|
mismatchDescription.add('actual.gestureSettings (${actual.gestureSettings}) did not match expected.gestureSettings (${expected.gestureSettings})');
|
||||||
|
}
|
||||||
|
|
||||||
|
final Matcher paddingMatcher = matchesViewPadding(expected.padding);
|
||||||
|
if (!paddingMatcher.matches(actual.padding, matchState)) {
|
||||||
|
mismatchDescription.add('actual.padding (${actual.padding}) did not match expected.padding (${expected.padding})');
|
||||||
|
paddingMatcher.describeMismatch(actual.padding, mismatchDescription, matchState, verbose);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actual.physicalGeometry != expected.physicalGeometry) {
|
||||||
|
mismatchDescription.add('actual.physicalGeometry (${actual.physicalGeometry}) did not match expected.physicalGeometry (${expected.physicalGeometry})');
|
||||||
|
}
|
||||||
|
if (actual.physicalSize != expected.physicalSize) {
|
||||||
|
mismatchDescription.add('actual.physicalSize (${actual.physicalSize}) did not match expected.physicalSize (${expected.physicalSize})');
|
||||||
|
}
|
||||||
|
|
||||||
|
final Matcher systemGestureInsetsMatcher = matchesViewPadding(expected.systemGestureInsets);
|
||||||
|
if (!systemGestureInsetsMatcher.matches(actual.systemGestureInsets, matchState)) {
|
||||||
|
mismatchDescription.add('actual.systemGestureInsets (${actual.systemGestureInsets}) did not match expected.systemGestureInsets (${expected.systemGestureInsets})');
|
||||||
|
systemGestureInsetsMatcher.describeMismatch(actual.systemGestureInsets, mismatchDescription, matchState, verbose);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actual.viewId != expected.viewId) {
|
||||||
|
mismatchDescription.add('actual.viewId (${actual.viewId}) did not match expected.viewId (${expected.viewId})');
|
||||||
|
}
|
||||||
|
|
||||||
|
final Matcher viewInsetsMatcher = matchesViewPadding(expected.viewInsets);
|
||||||
|
if (!viewInsetsMatcher.matches(actual.viewInsets, matchState)) {
|
||||||
|
mismatchDescription.add('actual.viewInsets (${actual.viewInsets}) did not match expected.viewInsets (${expected.viewInsets})');
|
||||||
|
viewInsetsMatcher.describeMismatch(actual.viewInsets, mismatchDescription, matchState, verbose);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Matcher viewPaddingMatcher = matchesViewPadding(expected.viewPadding);
|
||||||
|
if (!viewPaddingMatcher.matches(actual.viewPadding, matchState)) {
|
||||||
|
mismatchDescription.add('actual.viewPadding (${actual.viewPadding}) did not match expected.devicePixelRatio (${expected.viewPadding})');
|
||||||
|
viewPaddingMatcher.describeMismatch(actual.viewPadding, mismatchDescription, matchState, verbose);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mismatchDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
|
||||||
|
assert(item is FlutterViewSnapshot, 'Can only match against snapshots of FlutterView.');
|
||||||
|
final FlutterViewSnapshot actual = item as FlutterViewSnapshot;
|
||||||
|
|
||||||
|
return actual.devicePixelRatio == expected.devicePixelRatio &&
|
||||||
|
actual.displayFeatures.equals(expected.displayFeatures) &&
|
||||||
|
actual.gestureSettings == expected.gestureSettings &&
|
||||||
|
matchesViewPadding(expected.padding).matches(actual.padding, matchState) &&
|
||||||
|
actual.physicalGeometry == expected.physicalGeometry &&
|
||||||
|
actual.physicalSize == expected.physicalSize &&
|
||||||
|
matchesViewPadding(expected.systemGestureInsets).matches(actual.padding, matchState) &&
|
||||||
|
actual.viewId == expected.viewId &&
|
||||||
|
matchesViewPadding(expected.viewInsets).matches(actual.viewInsets, matchState) &&
|
||||||
|
matchesViewPadding(expected.viewPadding).matches(actual.viewPadding, matchState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FlutterViewSnapshot {
|
||||||
|
FlutterViewSnapshot(FlutterView view) :
|
||||||
|
devicePixelRatio = view.devicePixelRatio,
|
||||||
|
displayFeatures = <DisplayFeature>[...view.displayFeatures],
|
||||||
|
gestureSettings = view.gestureSettings,
|
||||||
|
padding = view.padding,
|
||||||
|
physicalGeometry = view.physicalGeometry,
|
||||||
|
physicalSize = view.physicalSize,
|
||||||
|
systemGestureInsets = view.systemGestureInsets,
|
||||||
|
viewId = view.viewId,
|
||||||
|
viewInsets = view.viewInsets,
|
||||||
|
viewPadding = view.viewPadding;
|
||||||
|
|
||||||
|
final double devicePixelRatio;
|
||||||
|
final List<DisplayFeature> displayFeatures;
|
||||||
|
final GestureSettings gestureSettings;
|
||||||
|
final ViewPadding padding;
|
||||||
|
final Rect physicalGeometry;
|
||||||
|
final Size physicalSize;
|
||||||
|
final ViewPadding systemGestureInsets;
|
||||||
|
final Object viewId;
|
||||||
|
final ViewPadding viewInsets;
|
||||||
|
final ViewPadding viewPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FakeFlutterView implements FlutterView {
|
||||||
|
SemanticsUpdate? lastSemanticsUpdate;
|
||||||
|
Scene? lastRenderedScene;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void updateSemantics(SemanticsUpdate update) {
|
||||||
|
lastSemanticsUpdate = update;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void render(Scene scene) {
|
||||||
|
lastRenderedScene = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
dynamic noSuchMethod(Invocation invocation) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -3,13 +3,19 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:ui' as ui show window;
|
import 'dart:ui' as ui show window;
|
||||||
import 'dart:ui' show AccessibilityFeatures, Brightness, Locale, PlatformDispatcher, SemanticsUpdate, SingletonFlutterWindow, Size, ViewPadding;
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/semantics.dart' show SemanticsUpdateBuilder;
|
|
||||||
import 'package:flutter/widgets.dart' show WidgetsBinding, WidgetsBindingObserver;
|
import 'package:flutter/widgets.dart' show WidgetsBinding, WidgetsBindingObserver;
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import 'utils/fake_and_mock_utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
tearDown(() {
|
||||||
|
final TestWindow window = WidgetsBinding.instance.window as TestWindow;
|
||||||
|
window.clearAllTestValues();
|
||||||
|
});
|
||||||
|
|
||||||
test('TestWindow can handle new methods without breaking', () {
|
test('TestWindow can handle new methods without breaking', () {
|
||||||
final dynamic testWindow = TestWindow(window: ui.window);
|
final dynamic testWindow = TestWindow(window: ui.window);
|
||||||
// ignore: avoid_dynamic_calls
|
// ignore: avoid_dynamic_calls
|
||||||
@ -17,7 +23,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake device pixel ratio', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake device pixel ratio', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<double>(
|
verifyPropertyFaked<double>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.devicePixelRatio,
|
realValue: ui.window.devicePixelRatio,
|
||||||
fakeValue: 2.5,
|
fakeValue: 2.5,
|
||||||
@ -31,7 +37,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake physical size', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake physical size', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<Size>(
|
verifyPropertyFaked<Size>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.physicalSize,
|
realValue: ui.window.physicalSize,
|
||||||
fakeValue: const Size(50, 50),
|
fakeValue: const Size(50, 50),
|
||||||
@ -45,7 +51,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake view insets', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake view insets', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<ViewPadding>(
|
verifyPropertyFaked<ViewPadding>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.viewInsets,
|
realValue: ui.window.viewInsets,
|
||||||
fakeValue: const FakeViewPadding(),
|
fakeValue: const FakeViewPadding(),
|
||||||
@ -55,11 +61,12 @@ void main() {
|
|||||||
propertyFaker: (TestWidgetsFlutterBinding binding, ViewPadding fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, ViewPadding fakeValue) {
|
||||||
binding.window.viewInsetsTestValue = fakeValue;
|
binding.window.viewInsetsTestValue = fakeValue;
|
||||||
},
|
},
|
||||||
|
matcher: matchesViewPadding,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake padding', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake padding', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<ViewPadding>(
|
verifyPropertyFaked<ViewPadding>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.padding,
|
realValue: ui.window.padding,
|
||||||
fakeValue: const FakeViewPadding(),
|
fakeValue: const FakeViewPadding(),
|
||||||
@ -69,11 +76,12 @@ void main() {
|
|||||||
propertyFaker: (TestWidgetsFlutterBinding binding, ViewPadding fakeValue) {
|
propertyFaker: (TestWidgetsFlutterBinding binding, ViewPadding fakeValue) {
|
||||||
binding.window.paddingTestValue = fakeValue;
|
binding.window.paddingTestValue = fakeValue;
|
||||||
},
|
},
|
||||||
|
matcher: matchesViewPadding
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake locale', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake locale', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<Locale>(
|
verifyPropertyFaked<Locale>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.locale,
|
realValue: ui.window.locale,
|
||||||
fakeValue: const Locale('fake_language_code'),
|
fakeValue: const Locale('fake_language_code'),
|
||||||
@ -87,7 +95,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake locales', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake locales', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<List<Locale>>(
|
verifyPropertyFaked<List<Locale>>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.locales,
|
realValue: ui.window.locales,
|
||||||
fakeValue: <Locale>[const Locale('fake_language_code')],
|
fakeValue: <Locale>[const Locale('fake_language_code')],
|
||||||
@ -101,7 +109,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake text scale factor', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake text scale factor', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<double>(
|
verifyPropertyFaked<double>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.textScaleFactor,
|
realValue: ui.window.textScaleFactor,
|
||||||
fakeValue: 2.5,
|
fakeValue: 2.5,
|
||||||
@ -115,7 +123,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake clock format', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake clock format', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<bool>(
|
verifyPropertyFaked<bool>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.alwaysUse24HourFormat,
|
realValue: ui.window.alwaysUse24HourFormat,
|
||||||
fakeValue: !ui.window.alwaysUse24HourFormat,
|
fakeValue: !ui.window.alwaysUse24HourFormat,
|
||||||
@ -129,7 +137,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake brieflyShowPassword', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake brieflyShowPassword', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<bool>(
|
verifyPropertyFaked<bool>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.brieflyShowPassword,
|
realValue: ui.window.brieflyShowPassword,
|
||||||
fakeValue: !ui.window.brieflyShowPassword,
|
fakeValue: !ui.window.brieflyShowPassword,
|
||||||
@ -141,7 +149,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake default route name', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake default route name', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<String>(
|
verifyPropertyFaked<String>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.defaultRouteName,
|
realValue: ui.window.defaultRouteName,
|
||||||
fakeValue: 'fake_route',
|
fakeValue: 'fake_route',
|
||||||
@ -155,7 +163,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake accessibility features', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake accessibility features', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<AccessibilityFeatures>(
|
verifyPropertyFaked<AccessibilityFeatures>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: ui.window.accessibilityFeatures,
|
realValue: ui.window.accessibilityFeatures,
|
||||||
fakeValue: const FakeAccessibilityFeatures(),
|
fakeValue: const FakeAccessibilityFeatures(),
|
||||||
@ -169,7 +177,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TestWindow can fake platform brightness', (WidgetTester tester) async {
|
testWidgets('TestWindow can fake platform brightness', (WidgetTester tester) async {
|
||||||
verifyThatTestWindowCanFakeProperty<Brightness>(
|
verifyPropertyFaked<Brightness>(
|
||||||
tester: tester,
|
tester: tester,
|
||||||
realValue: Brightness.light,
|
realValue: Brightness.light,
|
||||||
fakeValue: Brightness.dark,
|
fakeValue: Brightness.dark,
|
||||||
@ -209,63 +217,27 @@ void main() {
|
|||||||
retrieveTestBinding(tester).window.localesTestValue = defaultLocales;
|
retrieveTestBinding(tester).window.localesTestValue = defaultLocales;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Window test', () {
|
testWidgets('Updates to window also update tester.view', (WidgetTester tester) async {
|
||||||
final FakeSingletonWindow fakeWindow = FakeSingletonWindow();
|
tester.binding.window.devicePixelRatioTestValue = 7;
|
||||||
final TestWindow testWindow = TestWindow(window: fakeWindow);
|
tester.binding.window.displayFeaturesTestValue = <DisplayFeature>[const DisplayFeature(bounds: Rect.fromLTWH(0, 0, 20, 300), type: DisplayFeatureType.unknown, state: DisplayFeatureState.unknown)];
|
||||||
final SemanticsUpdate update = SemanticsUpdateBuilder().build();
|
tester.binding.window.paddingTestValue = const FakeViewPadding();
|
||||||
testWindow.updateSemantics(update);
|
tester.binding.window.physicalSizeTestValue = const Size(505, 805);
|
||||||
expect(fakeWindow.lastUpdate, update);
|
tester.binding.window.systemGestureInsetsTestValue = const FakeViewPadding();
|
||||||
|
tester.binding.window.viewInsetsTestValue = const FakeViewPadding();
|
||||||
|
tester.binding.window.viewPaddingTestValue = const FakeViewPadding();
|
||||||
|
tester.binding.window.gestureSettingsTestValue = const GestureSettings(physicalTouchSlop: 4, physicalDoubleTapSlop: 5);
|
||||||
|
|
||||||
|
expect(tester.binding.window.devicePixelRatio, tester.view.devicePixelRatio);
|
||||||
|
expect(tester.binding.window.displayFeatures, tester.view.displayFeatures);
|
||||||
|
expect(tester.binding.window.padding, tester.view.padding);
|
||||||
|
expect(tester.binding.window.physicalSize, tester.view.physicalSize);
|
||||||
|
expect(tester.binding.window.systemGestureInsets, tester.view.systemGestureInsets);
|
||||||
|
expect(tester.binding.window.viewInsets, tester.view.viewInsets);
|
||||||
|
expect(tester.binding.window.viewPadding, tester.view.viewPadding);
|
||||||
|
expect(tester.binding.window.gestureSettings, tester.view.gestureSettings);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifyThatTestWindowCanFakeProperty<WindowPropertyType>({
|
|
||||||
required WidgetTester tester,
|
|
||||||
required WindowPropertyType? realValue,
|
|
||||||
required WindowPropertyType fakeValue,
|
|
||||||
required WindowPropertyType? Function() propertyRetriever,
|
|
||||||
required Function(TestWidgetsFlutterBinding, WindowPropertyType fakeValue) propertyFaker,
|
|
||||||
}) {
|
|
||||||
WindowPropertyType? propertyBeforeFaking;
|
|
||||||
WindowPropertyType? propertyAfterFaking;
|
|
||||||
|
|
||||||
propertyBeforeFaking = propertyRetriever();
|
|
||||||
|
|
||||||
propertyFaker(retrieveTestBinding(tester), fakeValue);
|
|
||||||
|
|
||||||
propertyAfterFaking = propertyRetriever();
|
|
||||||
|
|
||||||
expect(propertyBeforeFaking, realValue);
|
|
||||||
expect(propertyAfterFaking, fakeValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
TestWidgetsFlutterBinding retrieveTestBinding(WidgetTester tester) {
|
|
||||||
final WidgetsBinding binding = tester.binding;
|
|
||||||
assert(binding is TestWidgetsFlutterBinding);
|
|
||||||
final TestWidgetsFlutterBinding testBinding = binding as TestWidgetsFlutterBinding;
|
|
||||||
return testBinding;
|
|
||||||
}
|
|
||||||
|
|
||||||
class FakeViewPadding implements ViewPadding {
|
|
||||||
const FakeViewPadding({
|
|
||||||
this.left = 0.0,
|
|
||||||
this.top = 0.0,
|
|
||||||
this.right = 0.0,
|
|
||||||
this.bottom = 0.0,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
final double left;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final double top;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final double right;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final double bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestObserver with WidgetsBindingObserver {
|
class TestObserver with WidgetsBindingObserver {
|
||||||
List<Locale>? locales;
|
List<Locale>? locales;
|
||||||
Locale? locale;
|
Locale? locale;
|
||||||
@ -275,15 +247,3 @@ class TestObserver with WidgetsBindingObserver {
|
|||||||
this.locales = locales;
|
this.locales = locales;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeSingletonWindow extends Fake implements SingletonFlutterWindow {
|
|
||||||
SemanticsUpdate? lastUpdate;
|
|
||||||
|
|
||||||
@override
|
|
||||||
PlatformDispatcher get platformDispatcher => PlatformDispatcher.instance;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void updateSemantics(SemanticsUpdate update) {
|
|
||||||
lastUpdate = update;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user