Unverified Commit 7ba1d5ec authored by pdblasi-google's avatar pdblasi-google Committed by GitHub

Updates `flutter/test/widgets` to no longer reference `TestWindow` (#122354)

Updates `flutter/test/widgets` to no longer reference `TestWindow`
parent 47c0723f
......@@ -146,7 +146,7 @@ Future<void> _expectColors(WidgetTester tester, Finder finder, Set<Color> allowe
assert(position.dx.round() < image.width);
assert(position.dy.round() >= 0);
assert(position.dy.round() < image.height);
final Offset precisePosition = position * binding.window.devicePixelRatio;
final Offset precisePosition = position * tester.view.devicePixelRatio;
final Color actual = _getPixel(bytes, precisePosition.dx.round(), precisePosition.dy.round(), image.width);
expect(actual, expected, reason: 'Pixel at $position is $actual but expected $expected.');
});
......
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:convert' show jsonDecode;
import 'dart:ui' as ui;
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
......@@ -44,26 +43,6 @@ class _MatchesMethodCall extends Matcher {
}
}
// Used to set window.viewInsets since the real ui.WindowPadding has only a
// private constructor.
class _TestViewPadding implements ui.ViewPadding {
const _TestViewPadding({
required this.bottom,
});
@override
final double bottom;
@override
double get top => 0.0;
@override
double get left => 0.0;
@override
double get right => 0.0;
}
late TextEditingController controller;
final FocusNode focusNode = FocusNode(debugLabel: 'EditableText Node');
final FocusScopeNode focusScopeNode = FocusScopeNode(debugLabel: 'EditableText Scope Node');
......@@ -134,6 +113,8 @@ void main() {
testWidgets('Text with selection can be shown on the screen when the keyboard shown', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/119628
addTearDown(tester.view.reset);
final ScrollController scrollController = ScrollController();
final TextEditingController textController = TextEditingController.fromValue(
const TextEditingValue(text: 'I love flutter'),
......@@ -164,8 +145,7 @@ void main() {
await tester.pumpWidget(widget);
await tester.showKeyboard(find.byType(EditableText));
TestWidgetsFlutterBinding.instance.window.viewInsetsTestValue = const _TestViewPadding(bottom: 500);
addTearDown(TestWidgetsFlutterBinding.instance.window.clearViewInsetsTestValue);
tester.view.viewInsets = const FakeViewPadding(bottom: 500);
textController.selection = TextSelection(
baseOffset: 0,
extentOffset: textController.text.length,
......@@ -173,13 +153,15 @@ void main() {
await tester.pump();
// The offset of the scrollController should change immediately after window changes its metrics.
// The offset of the scrollController should change immediately after view changes its metrics.
final double offsetAfter = scrollController.offset;
expect(offsetAfter, isNot(0.0));
});
// Related issue: https://github.com/flutter/flutter/issues/98115
testWidgets('ScheduleShowCaretOnScreen with no animation when the window changes metrics', (WidgetTester tester) async {
testWidgets('ScheduleShowCaretOnScreen with no animation when the view changes metrics', (WidgetTester tester) async {
addTearDown(tester.view.reset);
final ScrollController scrollController = ScrollController();
final Widget widget = MaterialApp(
home: Scaffold(
......@@ -215,11 +197,10 @@ void main() {
);
await tester.pumpWidget(widget);
await tester.showKeyboard(find.byType(EditableText));
TestWidgetsFlutterBinding.instance.window.viewInsetsTestValue = const _TestViewPadding(bottom: 500);
addTearDown(TestWidgetsFlutterBinding.instance.window.clearViewInsetsTestValue);
tester.view.viewInsets = const FakeViewPadding(bottom: 500);
await tester.pump();
// The offset of the scrollController should change immediately after window changes its metrics.
// The offset of the scrollController should change immediately after view changes its metrics.
final double offsetAfter = scrollController.offset;
expect(offsetAfter, isNot(0.0));
});
......@@ -1841,7 +1822,7 @@ void main() {
});
testWidgets('toolbar hidden on mobile when orientation changes', (WidgetTester tester) async {
addTearDown(tester.binding.window.clearPhysicalSizeTestValue);
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
......@@ -1871,7 +1852,7 @@ void main() {
expect(find.text('Paste'), findsOneWidget);
// Hide the menu by changing orientation.
tester.binding.window.physicalSizeTestValue = const Size(1800.0, 2400.0);
tester.view.physicalSize = const Size(1800.0, 2400.0);
await tester.pumpAndSettle();
expect(find.text('Paste'), findsNothing);
......@@ -5176,9 +5157,9 @@ void main() {
});
testWidgets('selection rects are sent when they change', (WidgetTester tester) async {
addTearDown(tester.binding.window.clearPhysicalSizeTestValue);
addTearDown(tester.view.reset);
// Ensure selection rects are sent on iPhone (using SE 3rd gen size)
tester.binding.window.physicalSizeTestValue = const Size(750.0, 1334.0);
tester.view.physicalSize = const Size(750.0, 1334.0);
final List<List<SelectionRect>> log = <List<SelectionRect>>[];
SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async {
......
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:ui' as ui;
import 'dart:ui' show ViewPadding;
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
......@@ -184,25 +183,6 @@ class MyStatefulWidgetState extends State<MyStatefulWidget> {
Widget build(BuildContext context) => Text(widget.value);
}
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;
}
Future<void> main() async {
final ui.Image testImage = await createTestImage();
......@@ -3090,72 +3070,71 @@ Future<void> main() async {
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
testWidgets('smooth transition between different incoming data', (WidgetTester tester) async {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey();
const Key imageKey1 = Key('image1');
const Key imageKey2 = Key('image2');
final TestImageProvider imageProvider = TestImageProvider(testImage);
final TestWidgetsFlutterBinding testBinding = tester.binding;
addTearDown(tester.view.reset);
testBinding.window.paddingTestValue = const FakeViewPadding(top: 50);
final GlobalKey<NavigatorState> navigatorKey = GlobalKey();
const Key imageKey1 = Key('image1');
const Key imageKey2 = Key('image2');
final TestImageProvider imageProvider = TestImageProvider(testImage);
await tester.pumpWidget(
MaterialApp(
navigatorKey: navigatorKey,
home: Scaffold(
appBar: AppBar(title: const Text('test')),
body: Hero(
tag: 'imageHero',
child: GridView.count(
crossAxisCount: 3,
shrinkWrap: true,
children: <Widget>[
Image(image: imageProvider, key: imageKey1),
],
),
tester.view.padding = const FakeViewPadding(top: 50);
await tester.pumpWidget(
MaterialApp(
navigatorKey: navigatorKey,
home: Scaffold(
appBar: AppBar(title: const Text('test')),
body: Hero(
tag: 'imageHero',
child: GridView.count(
crossAxisCount: 3,
shrinkWrap: true,
children: <Widget>[
Image(image: imageProvider, key: imageKey1),
],
),
),
),
);
),
);
final MaterialPageRoute<void> route2 = MaterialPageRoute<void>(
builder: (BuildContext context) {
return Scaffold(
body: Hero(
tag: 'imageHero',
child: GridView.count(
crossAxisCount: 3,
shrinkWrap: true,
children: <Widget>[
Image(image: imageProvider, key: imageKey2),
],
),
final MaterialPageRoute<void> route2 = MaterialPageRoute<void>(
builder: (BuildContext context) {
return Scaffold(
body: Hero(
tag: 'imageHero',
child: GridView.count(
crossAxisCount: 3,
shrinkWrap: true,
children: <Widget>[
Image(image: imageProvider, key: imageKey2),
],
),
);
},
);
// Load images.
imageProvider.complete();
await tester.pump();
),
);
},
);
final double forwardRest = tester.getTopLeft(find.byType(Image)).dy;
navigatorKey.currentState!.push(route2);
await tester.pump();
await tester.pump(const Duration(milliseconds: 1));
expect(tester.getTopLeft(find.byType(Image)).dy, moreOrLessEquals(forwardRest, epsilon: 0.1));
await tester.pumpAndSettle();
// Load images.
imageProvider.complete();
await tester.pump();
navigatorKey.currentState!.pop(route2);
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
expect(tester.getTopLeft(find.byType(Image)).dy, moreOrLessEquals(forwardRest, epsilon: 0.1));
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.byType(Image)).dy, moreOrLessEquals(forwardRest, epsilon: 0.1));
final double forwardRest = tester.getTopLeft(find.byType(Image)).dy;
navigatorKey.currentState!.push(route2);
await tester.pump();
await tester.pump(const Duration(milliseconds: 1));
expect(tester.getTopLeft(find.byType(Image)).dy, moreOrLessEquals(forwardRest, epsilon: 0.1));
await tester.pumpAndSettle();
testBinding.window.clearAllTestValues();
},
);
navigatorKey.currentState!.pop(route2);
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
expect(tester.getTopLeft(find.byType(Image)).dy, moreOrLessEquals(forwardRest, epsilon: 0.1));
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.byType(Image)).dy, moreOrLessEquals(forwardRest, epsilon: 0.1));
});
}
class TestDependencies extends StatelessWidget {
......
......@@ -1190,6 +1190,8 @@ void main() {
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows }));
testWidgets('viewport changes size', (WidgetTester tester) async {
addTearDown(tester.view.reset);
final TransformationController transformationController = TransformationController();
await tester.pumpWidget(
MaterialApp(
......@@ -1222,8 +1224,7 @@ void main() {
expect(transformationController.value, equals(Matrix4.identity()));
// Shrink the size of the screen.
tester.binding.window.physicalSizeTestValue = const Size(100.0, 100.0);
addTearDown(tester.binding.window.clearPhysicalSizeTestValue);
tester.view.physicalSize = const Size(100.0, 100.0);
await tester.pump();
// Attempting to drag to pan still doesn't work, because the image has
......
......@@ -142,7 +142,7 @@ void main() {
// Set the starting viewportDimension to 0.0
await tester.binding.setSurfaceSize(Size.zero);
final MediaQueryData mediaQueryData = MediaQueryData.fromView(tester.binding.window);
final MediaQueryData mediaQueryData = MediaQueryData.fromView(tester.view);
Widget build(Size size) {
return MediaQuery(
......@@ -1048,7 +1048,7 @@ void main() {
viewportDimension: 25.0,
axisDirection: AxisDirection.right,
viewportFraction: 1.0,
devicePixelRatio: tester.binding.window.devicePixelRatio,
devicePixelRatio: tester.view.devicePixelRatio,
);
expect(page.page, 6);
final PageMetrics page2 = page.copyWith(
......
......@@ -2599,6 +2599,8 @@ void main() {
);
testWidgets('PlatformViewLink includes offset in create call when using texture layer', (WidgetTester tester) async {
addTearDown(tester.view.reset);
late FakeAndroidViewController controller;
final PlatformViewLink platformViewLink = PlatformViewLink(
......@@ -2622,8 +2624,8 @@ void main() {
},
);
TestWidgetsFlutterBinding.instance.window.physicalSizeTestValue = const Size(400, 200);
TestWidgetsFlutterBinding.instance.window.devicePixelRatioTestValue = 1.0;
tester.view.physicalSize= const Size(400, 200);
tester.view.devicePixelRatio = 1.0;
await tester.pumpWidget(
Container(
......@@ -2638,9 +2640,6 @@ void main() {
);
expect(controller.createPosition, const Offset(150, 75));
TestWidgetsFlutterBinding.instance.window.clearPhysicalSizeTestValue();
TestWidgetsFlutterBinding.instance.window.clearDevicePixelRatioTestValue();
});
testWidgets(
......
......@@ -2038,7 +2038,9 @@ void main() {
expect(find.byType(RawScrollbar), isNot(paints..rect())); // Hide the bar.
});
testWidgets('The bar can show or hide when the window size change', (WidgetTester tester) async {
testWidgets('The bar can show or hide when the view size change', (WidgetTester tester) async {
addTearDown(tester.view.reset);
final ScrollController scrollController = ScrollController();
Widget buildFrame() {
return Directionality(
......@@ -2061,21 +2063,19 @@ void main() {
),
);
}
tester.binding.window.physicalSizeTestValue = const Size(800.0, 600.0);
tester.binding.window.devicePixelRatioTestValue = 1;
addTearDown(tester.binding.window.clearPhysicalSizeTestValue);
addTearDown(tester.binding.window.clearDevicePixelRatioTestValue);
tester.view.physicalSize = const Size(800.0, 600.0);
tester.view.devicePixelRatio = 1;
await tester.pumpWidget(buildFrame());
await tester.pumpAndSettle();
expect(scrollController.offset, 0.0);
expect(find.byType(RawScrollbar), isNot(paints..rect())); // Not shown.
tester.binding.window.physicalSizeTestValue = const Size(800.0, 599.0);
tester.view.physicalSize = const Size(800.0, 599.0);
await tester.pumpAndSettle();
expect(find.byType(RawScrollbar), paints..rect()..rect()); // Show the bar.
tester.binding.window.physicalSizeTestValue = const Size(800.0, 600.0);
tester.view.physicalSize = const Size(800.0, 600.0);
await tester.pumpAndSettle();
expect(find.byType(RawScrollbar), isNot(paints..rect())); // Not shown.
});
......
......@@ -1668,6 +1668,8 @@ void main() {
});
testWidgets('toolbar is hidden on mobile when orientation changes', (WidgetTester tester) async {
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
home: SelectableRegion(
......@@ -1677,7 +1679,6 @@ void main() {
),
),
);
addTearDown(tester.binding.window.clearPhysicalSizeTestValue);
final RenderParagraph paragraph1 = tester.renderObject<RenderParagraph>(find.descendant(of: find.text('How are you?'), matching: find.byType(RichText)));
final TestGesture gesture = await tester.startGesture(textOffsetToPosition(paragraph1, 6)); // at the 'r'
......@@ -1690,7 +1691,7 @@ void main() {
expect(find.text('Copy'), findsOneWidget);
// Hide the toolbar by changing orientation.
tester.binding.window.physicalSizeTestValue = const Size(1800.0, 2400.0);
tester.view.physicalSize = const Size(1800.0, 2400.0);
await tester.pumpAndSettle();
expect(find.text('Copy'), findsNothing);
......
......@@ -264,12 +264,11 @@ void main() {
}, skip: kIsWeb); // TODO(jonahwilliams): https://github.com/flutter/flutter/issues/106689
testWidgets('SnapshotWidget should have same result when enabled', (WidgetTester tester) async {
tester.binding.window
..physicalSizeTestValue = const Size(10, 10)
..devicePixelRatioTestValue = 1;
addTearDown(() => tester.binding.window
..clearPhysicalSizeTestValue()
..clearDevicePixelRatioTestValue());
addTearDown(tester.view.reset);
tester.view
..physicalSize = const Size(10, 10)
..devicePixelRatio = 1;
const ValueKey<String> repaintBoundaryKey = ValueKey<String>('boundary');
final SnapshotController controller = SnapshotController();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment