Fix surface-size state leak in material/paginated_data_table_test (framework shuffle-all 3/n) (#123842)

Fix surface-size state leak in material/paginated_data_table_test (framework shuffle-all 3/n)
This commit is contained in:
Greg Price
2023-04-06 16:34:12 -07:00
committed by GitHub
parent bf98fcf738
commit 846fcefd21
2 changed files with 13 additions and 7 deletions

View File

@@ -2,13 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(gspencergoog): Remove this tag once this test's state leaks/test
// dependencies have been fixed.
// https://github.com/flutter/flutter/issues/85160
// Fails with "flutter test --test-randomize-ordering-seed=1000"
@Tags(<String>['no-shuffle'])
library;
import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@@ -845,6 +838,7 @@ void main() {
testWidgets('PaginatedDataTable with optional column checkbox', (WidgetTester tester) async {
await binding.setSurfaceSize(const Size(800, 800));
addTearDown(() => binding.setSurfaceSize(null));
Widget buildTable(bool checkbox) => MaterialApp(
home: PaginatedDataTable(
@@ -1004,6 +998,7 @@ void main() {
testWidgets('PaginatedDataTable arrowHeadColor set properly', (WidgetTester tester) async {
await binding.setSurfaceSize(const Size(800, 800));
addTearDown(() => binding.setSurfaceSize(null));
const Color arrowHeadColor = Color(0xFFE53935);
await tester.pumpWidget(

View File

@@ -505,6 +505,17 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
/// then flushes microtasks.
///
/// Set to null to use the default surface size.
///
/// To avoid affecting other tests by leaking state, a test that
/// uses this method should always reset the surface size to the default.
/// For example, using `addTearDown`:
/// ```dart
/// await binding.setSurfaceSize(someSize);
/// addTearDown(() => binding.setSurfaceSize(null));
/// ```
///
/// See also [TestFlutterView.physicalSize], which has a similar effect.
// TODO(pdblasi-google): Deprecate this. https://github.com/flutter/flutter/issues/123881
Future<void> setSurfaceSize(Size? size) {
return TestAsyncUtils.guard<void>(() async {
assert(inTest);