Skip to content

Commit

Permalink
Updates flutter/test/rendering to no longer use TestWindow (#122347)
Browse files Browse the repository at this point in the history
Updates `flutter/test/rendering` to no longer use `TestWindow`
  • Loading branch information
pdblasi-google authored Mar 10, 2023
1 parent de39951 commit 28b65e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 48 deletions.
54 changes: 17 additions & 37 deletions packages/flutter/test/rendering/view_chrome_style_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -16,18 +14,18 @@ void main() {
const double deviceWidth = 480.0;
const double devicePixelRatio = 2.0;

void setupTestDevice() {
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
void setupTestDevice(WidgetTester tester) {
const FakeViewPadding padding = FakeViewPadding(
top: statusBarHeight * devicePixelRatio,
bottom: navigationBarHeight * devicePixelRatio,
);

binding.window
..viewPaddingTestValue = padding
..paddingTestValue = padding
..devicePixelRatioTestValue = devicePixelRatio
..physicalSizeTestValue = const Size(
addTearDown(tester.view.reset);
tester.view
..viewPadding = padding
..padding = padding
..devicePixelRatio = devicePixelRatio
..physicalSize = const Size(
deviceWidth * devicePixelRatio,
deviceHeight * devicePixelRatio,
);
Expand All @@ -52,7 +50,7 @@ void main() {
testWidgets(
'statusBarColor is set for annotated view',
(WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarColor: Colors.blue,
Expand All @@ -72,7 +70,7 @@ void main() {
testWidgets(
"statusBarColor isn't set when view covers less than half of the system status bar",
(WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
const double lessThanHalfOfTheStatusBarHeight =
statusBarHeight / 2.0 - 1;
await tester.pumpWidget(const Align(
Expand All @@ -97,7 +95,7 @@ void main() {
testWidgets(
'statusBarColor is set when view covers more than half of tye system status bar',
(WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
const double moreThanHalfOfTheStatusBarHeight =
statusBarHeight / 2.0 + 1;
await tester.pumpWidget(const Align(
Expand Down Expand Up @@ -127,7 +125,7 @@ void main() {
testWidgets(
"systemNavigationBarColor isn't set for non Android device",
(WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
systemNavigationBarColor: Colors.blue,
Expand Down Expand Up @@ -158,7 +156,7 @@ void main() {
testWidgets(
'systemNavigationBarColor is set for annotated view',
(WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
await tester.pumpWidget(const AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
systemNavigationBarColor: Colors.blue,
Expand All @@ -178,7 +176,7 @@ void main() {
testWidgets(
"systemNavigationBarColor isn't set when view covers less than half of navigation bar",
(WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
const double lessThanHalfOfTheNavigationBarHeight =
navigationBarHeight / 2.0 - 1;
await tester.pumpWidget(const Align(
Expand All @@ -203,7 +201,7 @@ void main() {
testWidgets(
'systemNavigationBarColor is set when view covers more than half of navigation bar',
(WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
const double moreThanHalfOfTheNavigationBarHeight =
navigationBarHeight / 2.0 + 1;
await tester.pumpWidget(const Align(
Expand All @@ -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 {
setupTestDevice();
setupTestDevice(tester);
await tester.pumpWidget(
const Column(children: <Widget>[
Expanded(child: AnnotatedRegion<SystemUiOverlayStyle>(
Expand All @@ -256,7 +254,7 @@ void main() {
}, variant: TargetPlatformVariant.only(TargetPlatform.android));

testWidgets('Top only AnnotatedRegion provides status bar and navigation bar style properties', (WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
await tester.pumpWidget(
const Column(children: <Widget>[
Expanded(child: AnnotatedRegion<SystemUiOverlayStyle>(
Expand All @@ -276,7 +274,7 @@ void main() {
}, variant: TargetPlatformVariant.only(TargetPlatform.android));

testWidgets('Bottom only AnnotatedRegion provides status bar and navigation bar style properties', (WidgetTester tester) async {
setupTestDevice();
setupTestDevice(tester);
await tester.pumpWidget(
const Column(children: <Widget>[
Expanded(child: SizedBox.expand()),
Expand All @@ -296,21 +294,3 @@ void main() {
}, 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;
}
2 changes: 1 addition & 1 deletion packages/flutter/test/rendering/view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void main() {
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(
configuration: createViewConfiguration(size: const Size(100.0, 100.0)),
window: RendererBinding.instance.platformDispatcher.views.single,
Expand Down
13 changes: 3 additions & 10 deletions packages/flutter/test/rendering/viewport_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
@Tags(<String>['reduced-test-set'])
library;

import 'dart:ui' as ui;

import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
Expand Down Expand Up @@ -782,19 +780,14 @@ void main() {
}

testWidgets('Reverse List showOnScreen', (WidgetTester tester) async {
final ui.Size originalScreenSize = tester.binding.window.physicalSize;
final double originalDevicePixelRatio = tester.binding.window.devicePixelRatio;
addTearDown(() {
tester.binding.window.devicePixelRatioTestValue = originalDevicePixelRatio;
tester.binding.window.physicalSizeTestValue = originalScreenSize;
});
addTearDown(tester.view.reset);
const double screenHeight = 400.0;
const double screenWidth = 400.0;
const double itemHeight = screenHeight / 10.0;
const ValueKey<String> centerKey = ValueKey<String>('center');

tester.binding.window.devicePixelRatioTestValue = 1.0;
tester.binding.window.physicalSizeTestValue = const Size(screenWidth, screenHeight);
tester.view.devicePixelRatio = 1.0;
tester.view.physicalSize = const Size(screenWidth, screenHeight);

await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
Expand Down

0 comments on commit 28b65e0

Please sign in to comment.