Unverified Commit 28b65e08 authored by pdblasi-google's avatar pdblasi-google Committed by GitHub

Updates `flutter/test/rendering` to no longer use `TestWindow` (#122347)

Updates `flutter/test/rendering` to no longer use `TestWindow`
parent de399511
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// 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';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -16,18 +14,18 @@ void main() { ...@@ -16,18 +14,18 @@ void main() {
const double deviceWidth = 480.0; const double deviceWidth = 480.0;
const double devicePixelRatio = 2.0; const double devicePixelRatio = 2.0;
void setupTestDevice() { void setupTestDevice(WidgetTester tester) {
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
const FakeViewPadding padding = FakeViewPadding( const FakeViewPadding padding = FakeViewPadding(
top: statusBarHeight * devicePixelRatio, top: statusBarHeight * devicePixelRatio,
bottom: navigationBarHeight * devicePixelRatio, bottom: navigationBarHeight * devicePixelRatio,
); );
binding.window addTearDown(tester.view.reset);
..viewPaddingTestValue = padding tester.view
..paddingTestValue = padding ..viewPadding = padding
..devicePixelRatioTestValue = devicePixelRatio ..padding = padding
..physicalSizeTestValue = const Size( ..devicePixelRatio = devicePixelRatio
..physicalSize = const Size(
deviceWidth * devicePixelRatio, deviceWidth * devicePixelRatio,
deviceHeight * devicePixelRatio, deviceHeight * devicePixelRatio,
); );
...@@ -52,7 +50,7 @@ void main() { ...@@ -52,7 +50,7 @@ void main() {
testWidgets( testWidgets(
'statusBarColor is set for annotated view', 'statusBarColor is set for annotated view',
(WidgetTester tester) async { (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>( await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle( value: SystemUiOverlayStyle(
statusBarColor: Colors.blue, statusBarColor: Colors.blue,
...@@ -72,7 +70,7 @@ void main() { ...@@ -72,7 +70,7 @@ void main() {
testWidgets( testWidgets(
"statusBarColor isn't set when view covers less than half of the system status bar", "statusBarColor isn't set when view covers less than half of the system status bar",
(WidgetTester tester) async { (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
const double lessThanHalfOfTheStatusBarHeight = const double lessThanHalfOfTheStatusBarHeight =
statusBarHeight / 2.0 - 1; statusBarHeight / 2.0 - 1;
await tester.pumpWidget(const Align( await tester.pumpWidget(const Align(
...@@ -97,7 +95,7 @@ void main() { ...@@ -97,7 +95,7 @@ void main() {
testWidgets( testWidgets(
'statusBarColor is set when view covers more than half of tye system status bar', 'statusBarColor is set when view covers more than half of tye system status bar',
(WidgetTester tester) async { (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
const double moreThanHalfOfTheStatusBarHeight = const double moreThanHalfOfTheStatusBarHeight =
statusBarHeight / 2.0 + 1; statusBarHeight / 2.0 + 1;
await tester.pumpWidget(const Align( await tester.pumpWidget(const Align(
...@@ -127,7 +125,7 @@ void main() { ...@@ -127,7 +125,7 @@ void main() {
testWidgets( testWidgets(
"systemNavigationBarColor isn't set for non Android device", "systemNavigationBarColor isn't set for non Android device",
(WidgetTester tester) async { (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>( await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle( value: SystemUiOverlayStyle(
systemNavigationBarColor: Colors.blue, systemNavigationBarColor: Colors.blue,
...@@ -158,7 +156,7 @@ void main() { ...@@ -158,7 +156,7 @@ void main() {
testWidgets( testWidgets(
'systemNavigationBarColor is set for annotated view', 'systemNavigationBarColor is set for annotated view',
(WidgetTester tester) async { (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>( await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle( value: SystemUiOverlayStyle(
systemNavigationBarColor: Colors.blue, systemNavigationBarColor: Colors.blue,
...@@ -178,7 +176,7 @@ void main() { ...@@ -178,7 +176,7 @@ void main() {
testWidgets( testWidgets(
"systemNavigationBarColor isn't set when view covers less than half of navigation bar", "systemNavigationBarColor isn't set when view covers less than half of navigation bar",
(WidgetTester tester) async { (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
const double lessThanHalfOfTheNavigationBarHeight = const double lessThanHalfOfTheNavigationBarHeight =
navigationBarHeight / 2.0 - 1; navigationBarHeight / 2.0 - 1;
await tester.pumpWidget(const Align( await tester.pumpWidget(const Align(
...@@ -203,7 +201,7 @@ void main() { ...@@ -203,7 +201,7 @@ void main() {
testWidgets( testWidgets(
'systemNavigationBarColor is set when view covers more than half of navigation bar', 'systemNavigationBarColor is set when view covers more than half of navigation bar',
(WidgetTester tester) async { (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
const double moreThanHalfOfTheNavigationBarHeight = const double moreThanHalfOfTheNavigationBarHeight =
navigationBarHeight / 2.0 + 1; navigationBarHeight / 2.0 + 1;
await tester.pumpWidget(const Align( await tester.pumpWidget(const Align(
...@@ -230,7 +228,7 @@ void main() { ...@@ -230,7 +228,7 @@ void main() {
}); });
testWidgets('Top AnnotatedRegion provides status bar overlay style and bottom AnnotatedRegion provides navigation bar overlay style', (WidgetTester tester) async { testWidgets('Top AnnotatedRegion provides status bar overlay style and bottom AnnotatedRegion provides navigation bar overlay style', (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
await tester.pumpWidget( await tester.pumpWidget(
const Column(children: <Widget>[ const Column(children: <Widget>[
Expanded(child: AnnotatedRegion<SystemUiOverlayStyle>( Expanded(child: AnnotatedRegion<SystemUiOverlayStyle>(
...@@ -256,7 +254,7 @@ void main() { ...@@ -256,7 +254,7 @@ void main() {
}, variant: TargetPlatformVariant.only(TargetPlatform.android)); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
testWidgets('Top only AnnotatedRegion provides status bar and navigation bar style properties', (WidgetTester tester) async { testWidgets('Top only AnnotatedRegion provides status bar and navigation bar style properties', (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
await tester.pumpWidget( await tester.pumpWidget(
const Column(children: <Widget>[ const Column(children: <Widget>[
Expanded(child: AnnotatedRegion<SystemUiOverlayStyle>( Expanded(child: AnnotatedRegion<SystemUiOverlayStyle>(
...@@ -276,7 +274,7 @@ void main() { ...@@ -276,7 +274,7 @@ void main() {
}, variant: TargetPlatformVariant.only(TargetPlatform.android)); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
testWidgets('Bottom only AnnotatedRegion provides status bar and navigation bar style properties', (WidgetTester tester) async { testWidgets('Bottom only AnnotatedRegion provides status bar and navigation bar style properties', (WidgetTester tester) async {
setupTestDevice(); setupTestDevice(tester);
await tester.pumpWidget( await tester.pumpWidget(
const Column(children: <Widget>[ const Column(children: <Widget>[
Expanded(child: SizedBox.expand()), Expanded(child: SizedBox.expand()),
...@@ -296,21 +294,3 @@ void main() { ...@@ -296,21 +294,3 @@ void main() {
}, variant: TargetPlatformVariant.only(TargetPlatform.android)); }, variant: TargetPlatformVariant.only(TargetPlatform.android));
}); });
} }
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;
}
...@@ -45,7 +45,7 @@ void main() { ...@@ -45,7 +45,7 @@ void main() {
expect(identical(view.debugLayer, firstLayer), false); expect(identical(view.debugLayer, firstLayer), false);
}); });
test('does not replace the root layer unnecessarily when window resize', () { test('does not replace the root layer unnecessarily when view resizes', () {
final RenderView view = RenderView( final RenderView view = RenderView(
configuration: createViewConfiguration(size: const Size(100.0, 100.0)), configuration: createViewConfiguration(size: const Size(100.0, 100.0)),
window: RendererBinding.instance.platformDispatcher.views.single, window: RendererBinding.instance.platformDispatcher.views.single,
......
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
@Tags(<String>['reduced-test-set']) @Tags(<String>['reduced-test-set'])
library; library;
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -782,19 +780,14 @@ void main() { ...@@ -782,19 +780,14 @@ void main() {
} }
testWidgets('Reverse List showOnScreen', (WidgetTester tester) async { testWidgets('Reverse List showOnScreen', (WidgetTester tester) async {
final ui.Size originalScreenSize = tester.binding.window.physicalSize; addTearDown(tester.view.reset);
final double originalDevicePixelRatio = tester.binding.window.devicePixelRatio;
addTearDown(() {
tester.binding.window.devicePixelRatioTestValue = originalDevicePixelRatio;
tester.binding.window.physicalSizeTestValue = originalScreenSize;
});
const double screenHeight = 400.0; const double screenHeight = 400.0;
const double screenWidth = 400.0; const double screenWidth = 400.0;
const double itemHeight = screenHeight / 10.0; const double itemHeight = screenHeight / 10.0;
const ValueKey<String> centerKey = ValueKey<String>('center'); const ValueKey<String> centerKey = ValueKey<String>('center');
tester.binding.window.devicePixelRatioTestValue = 1.0; tester.view.devicePixelRatio = 1.0;
tester.binding.window.physicalSizeTestValue = const Size(screenWidth, screenHeight); tester.view.physicalSize = const Size(screenWidth, screenHeight);
await tester.pumpWidget(Directionality( await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
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