This reverts commit f2dd19d5b6.
This commit is contained in:
@@ -182,18 +182,17 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
///
|
||||
/// This constructor overrides the [debugPrint] global hook to point to
|
||||
/// [debugPrintOverride], which can be overridden by subclasses.
|
||||
TestWidgetsFlutterBinding() : platformDispatcher = TestPlatformDispatcher(
|
||||
platformDispatcher: PlatformDispatcher.instance,
|
||||
) {
|
||||
TestWidgetsFlutterBinding() : _window = TestWindow(window: ui.window) {
|
||||
debugPrint = debugPrintOverride;
|
||||
debugDisableShadows = disableShadows;
|
||||
}
|
||||
|
||||
@override
|
||||
late final TestWindow window;
|
||||
TestWindow get window => _window;
|
||||
final TestWindow _window;
|
||||
|
||||
@override
|
||||
final TestPlatformDispatcher platformDispatcher;
|
||||
TestPlatformDispatcher get platformDispatcher => _window.platformDispatcher;
|
||||
|
||||
@override
|
||||
TestRestorationManager get restorationManager {
|
||||
@@ -347,12 +346,6 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
|
||||
@override
|
||||
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();
|
||||
_instance = this;
|
||||
timeDilation = 1.0; // just in case the developer has artificially changed it for development
|
||||
|
||||
@@ -14,7 +14,6 @@ import 'event_simulation.dart';
|
||||
import 'finders.dart';
|
||||
import 'test_async_utils.dart';
|
||||
import 'test_pointer.dart';
|
||||
import 'window.dart';
|
||||
|
||||
/// The default drag touch slop used to break up a large drag into multiple
|
||||
/// smaller moves.
|
||||
@@ -235,37 +234,6 @@ abstract class WidgetController {
|
||||
/// A reference to the current instance of the 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
|
||||
/// the [Semantics] tree.
|
||||
///
|
||||
@@ -289,26 +257,6 @@ abstract class WidgetController {
|
||||
// TODO(ianh): verify that the return values are of type T and throw
|
||||
// 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.
|
||||
bool any(Finder finder) {
|
||||
TestAsyncUtils.guardSync();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -711,25 +711,6 @@ 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('find', () {
|
||||
testWidgets('throws when there are no semantics', (WidgetTester tester) async {
|
||||
|
||||
@@ -7,17 +7,15 @@ import 'dart:ui' show AccessibilityFeatures, Brightness, Locale, PlatformDispatc
|
||||
import 'package:flutter/widgets.dart' show WidgetsBinding, WidgetsBindingObserver;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'utils/fake_and_mock_utils.dart';
|
||||
|
||||
void main() {
|
||||
test('TestPlatformDispatcher can handle new methods without breaking', () {
|
||||
test('TestWindow can handle new methods without breaking', () {
|
||||
final dynamic testPlatformDispatcher = TestPlatformDispatcher(platformDispatcher: PlatformDispatcher.instance);
|
||||
// ignore: avoid_dynamic_calls
|
||||
expect(testPlatformDispatcher.someNewProperty, null);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can fake locale', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<Locale>(
|
||||
testWidgets('TestWindow can fake locale', (WidgetTester tester) async {
|
||||
verifyThatTestPlatformDispatcherCanFakeProperty<Locale>(
|
||||
tester: tester,
|
||||
realValue: PlatformDispatcher.instance.locale,
|
||||
fakeValue: const Locale('fake_language_code'),
|
||||
@@ -30,8 +28,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can fake locales', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<List<Locale>>(
|
||||
testWidgets('TestWindow can fake locales', (WidgetTester tester) async {
|
||||
verifyThatTestPlatformDispatcherCanFakeProperty<List<Locale>>(
|
||||
tester: tester,
|
||||
realValue: PlatformDispatcher.instance.locales,
|
||||
fakeValue: <Locale>[const Locale('fake_language_code')],
|
||||
@@ -44,8 +42,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can fake text scale factor', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<double>(
|
||||
testWidgets('TestWindow can fake text scale factor', (WidgetTester tester) async {
|
||||
verifyThatTestPlatformDispatcherCanFakeProperty<double>(
|
||||
tester: tester,
|
||||
realValue: PlatformDispatcher.instance.textScaleFactor,
|
||||
fakeValue: 2.5,
|
||||
@@ -58,8 +56,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can fake clock format', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<bool>(
|
||||
testWidgets('TestWindow can fake clock format', (WidgetTester tester) async {
|
||||
verifyThatTestPlatformDispatcherCanFakeProperty<bool>(
|
||||
tester: tester,
|
||||
realValue: PlatformDispatcher.instance.alwaysUse24HourFormat,
|
||||
fakeValue: !PlatformDispatcher.instance.alwaysUse24HourFormat,
|
||||
@@ -72,8 +70,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can fake brieflyShowPassword', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<bool>(
|
||||
testWidgets('TestWindow can fake brieflyShowPassword', (WidgetTester tester) async {
|
||||
verifyThatTestPlatformDispatcherCanFakeProperty<bool>(
|
||||
tester: tester,
|
||||
realValue: PlatformDispatcher.instance.brieflyShowPassword,
|
||||
fakeValue: !PlatformDispatcher.instance.brieflyShowPassword,
|
||||
@@ -84,8 +82,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can fake default route name', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<String>(
|
||||
testWidgets('TestWindow can fake default route name', (WidgetTester tester) async {
|
||||
verifyThatTestPlatformDispatcherCanFakeProperty<String>(
|
||||
tester: tester,
|
||||
realValue: PlatformDispatcher.instance.defaultRouteName,
|
||||
fakeValue: 'fake_route',
|
||||
@@ -98,8 +96,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can fake accessibility features', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<AccessibilityFeatures>(
|
||||
testWidgets('TestWindow can fake accessibility features', (WidgetTester tester) async {
|
||||
verifyThatTestPlatformDispatcherCanFakeProperty<AccessibilityFeatures>(
|
||||
tester: tester,
|
||||
realValue: PlatformDispatcher.instance.accessibilityFeatures,
|
||||
fakeValue: const FakeAccessibilityFeatures(),
|
||||
@@ -112,8 +110,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can fake platform brightness', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<Brightness>(
|
||||
testWidgets('TestWindow can fake platform brightness', (WidgetTester tester) async {
|
||||
verifyThatTestPlatformDispatcherCanFakeProperty<Brightness>(
|
||||
tester: tester,
|
||||
realValue: Brightness.light,
|
||||
fakeValue: Brightness.dark,
|
||||
@@ -126,7 +124,7 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher can clear out fake properties all at once', (WidgetTester tester) async {
|
||||
testWidgets('TestWindow can clear out fake properties all at once', (WidgetTester tester) async {
|
||||
final Locale originalLocale = PlatformDispatcher.instance.locale;
|
||||
final double originalTextScaleFactor = PlatformDispatcher.instance.textScaleFactor;
|
||||
final TestPlatformDispatcher testPlatformDispatcher = retrieveTestBinding(tester).platformDispatcher;
|
||||
@@ -143,7 +141,7 @@ void main() {
|
||||
expect(WidgetsBinding.instance.platformDispatcher.textScaleFactor, originalTextScaleFactor);
|
||||
});
|
||||
|
||||
testWidgets('TestPlatformDispatcher sends fake locales when WidgetsBindingObserver notifiers are called', (WidgetTester tester) async {
|
||||
testWidgets('TestWindow sends fake locales when WidgetsBindingObserver notifiers are called', (WidgetTester tester) async {
|
||||
final List<Locale> defaultLocales = WidgetsBinding.instance.platformDispatcher.locales;
|
||||
final TestObserver observer = TestObserver();
|
||||
retrieveTestBinding(tester).addObserver(observer);
|
||||
@@ -154,8 +152,36 @@ 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 {
|
||||
List<Locale>? locales;
|
||||
Locale? locale;
|
||||
|
||||
@override
|
||||
void didChangeLocales(List<Locale>? locales) {
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -1,445 +0,0 @@
|
||||
// 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,19 +3,13 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui show window;
|
||||
import 'dart:ui';
|
||||
import 'dart:ui' show AccessibilityFeatures, Brightness, Locale, PlatformDispatcher, SemanticsUpdate, SingletonFlutterWindow, Size, ViewPadding;
|
||||
|
||||
import 'package:flutter/semantics.dart' show SemanticsUpdateBuilder;
|
||||
import 'package:flutter/widgets.dart' show WidgetsBinding, WidgetsBindingObserver;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'utils/fake_and_mock_utils.dart';
|
||||
|
||||
void main() {
|
||||
tearDown(() {
|
||||
final TestWindow window = WidgetsBinding.instance.window as TestWindow;
|
||||
window.clearAllTestValues();
|
||||
});
|
||||
|
||||
test('TestWindow can handle new methods without breaking', () {
|
||||
final dynamic testWindow = TestWindow(window: ui.window);
|
||||
// ignore: avoid_dynamic_calls
|
||||
@@ -23,7 +17,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake device pixel ratio', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<double>(
|
||||
verifyThatTestWindowCanFakeProperty<double>(
|
||||
tester: tester,
|
||||
realValue: ui.window.devicePixelRatio,
|
||||
fakeValue: 2.5,
|
||||
@@ -37,7 +31,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake physical size', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<Size>(
|
||||
verifyThatTestWindowCanFakeProperty<Size>(
|
||||
tester: tester,
|
||||
realValue: ui.window.physicalSize,
|
||||
fakeValue: const Size(50, 50),
|
||||
@@ -51,7 +45,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake view insets', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<ViewPadding>(
|
||||
verifyThatTestWindowCanFakeProperty<ViewPadding>(
|
||||
tester: tester,
|
||||
realValue: ui.window.viewInsets,
|
||||
fakeValue: const FakeViewPadding(),
|
||||
@@ -61,12 +55,11 @@ void main() {
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, ViewPadding fakeValue) {
|
||||
binding.window.viewInsetsTestValue = fakeValue;
|
||||
},
|
||||
matcher: matchesViewPadding,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake padding', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<ViewPadding>(
|
||||
verifyThatTestWindowCanFakeProperty<ViewPadding>(
|
||||
tester: tester,
|
||||
realValue: ui.window.padding,
|
||||
fakeValue: const FakeViewPadding(),
|
||||
@@ -76,12 +69,11 @@ void main() {
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, ViewPadding fakeValue) {
|
||||
binding.window.paddingTestValue = fakeValue;
|
||||
},
|
||||
matcher: matchesViewPadding
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake locale', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<Locale>(
|
||||
verifyThatTestWindowCanFakeProperty<Locale>(
|
||||
tester: tester,
|
||||
realValue: ui.window.locale,
|
||||
fakeValue: const Locale('fake_language_code'),
|
||||
@@ -95,7 +87,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake locales', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<List<Locale>>(
|
||||
verifyThatTestWindowCanFakeProperty<List<Locale>>(
|
||||
tester: tester,
|
||||
realValue: ui.window.locales,
|
||||
fakeValue: <Locale>[const Locale('fake_language_code')],
|
||||
@@ -109,7 +101,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake text scale factor', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<double>(
|
||||
verifyThatTestWindowCanFakeProperty<double>(
|
||||
tester: tester,
|
||||
realValue: ui.window.textScaleFactor,
|
||||
fakeValue: 2.5,
|
||||
@@ -123,7 +115,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake clock format', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<bool>(
|
||||
verifyThatTestWindowCanFakeProperty<bool>(
|
||||
tester: tester,
|
||||
realValue: ui.window.alwaysUse24HourFormat,
|
||||
fakeValue: !ui.window.alwaysUse24HourFormat,
|
||||
@@ -137,7 +129,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake brieflyShowPassword', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<bool>(
|
||||
verifyThatTestWindowCanFakeProperty<bool>(
|
||||
tester: tester,
|
||||
realValue: ui.window.brieflyShowPassword,
|
||||
fakeValue: !ui.window.brieflyShowPassword,
|
||||
@@ -149,7 +141,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake default route name', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<String>(
|
||||
verifyThatTestWindowCanFakeProperty<String>(
|
||||
tester: tester,
|
||||
realValue: ui.window.defaultRouteName,
|
||||
fakeValue: 'fake_route',
|
||||
@@ -163,7 +155,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake accessibility features', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<AccessibilityFeatures>(
|
||||
verifyThatTestWindowCanFakeProperty<AccessibilityFeatures>(
|
||||
tester: tester,
|
||||
realValue: ui.window.accessibilityFeatures,
|
||||
fakeValue: const FakeAccessibilityFeatures(),
|
||||
@@ -177,7 +169,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestWindow can fake platform brightness', (WidgetTester tester) async {
|
||||
verifyPropertyFaked<Brightness>(
|
||||
verifyThatTestWindowCanFakeProperty<Brightness>(
|
||||
tester: tester,
|
||||
realValue: Brightness.light,
|
||||
fakeValue: Brightness.dark,
|
||||
@@ -217,27 +209,63 @@ void main() {
|
||||
retrieveTestBinding(tester).window.localesTestValue = defaultLocales;
|
||||
});
|
||||
|
||||
testWidgets('Updates to window also update tester.view', (WidgetTester tester) async {
|
||||
tester.binding.window.devicePixelRatioTestValue = 7;
|
||||
tester.binding.window.displayFeaturesTestValue = <DisplayFeature>[const DisplayFeature(bounds: Rect.fromLTWH(0, 0, 20, 300), type: DisplayFeatureType.unknown, state: DisplayFeatureState.unknown)];
|
||||
tester.binding.window.paddingTestValue = const FakeViewPadding();
|
||||
tester.binding.window.physicalSizeTestValue = const Size(505, 805);
|
||||
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);
|
||||
test('Window test', () {
|
||||
final FakeSingletonWindow fakeWindow = FakeSingletonWindow();
|
||||
final TestWindow testWindow = TestWindow(window: fakeWindow);
|
||||
final SemanticsUpdate update = SemanticsUpdateBuilder().build();
|
||||
testWindow.updateSemantics(update);
|
||||
expect(fakeWindow.lastUpdate, update);
|
||||
});
|
||||
}
|
||||
|
||||
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 {
|
||||
List<Locale>? locales;
|
||||
Locale? locale;
|
||||
@@ -247,3 +275,15 @@ class TestObserver with WidgetsBindingObserver {
|
||||
this.locales = locales;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeSingletonWindow extends Fake implements SingletonFlutterWindow {
|
||||
SemanticsUpdate? lastUpdate;
|
||||
|
||||
@override
|
||||
PlatformDispatcher get platformDispatcher => PlatformDispatcher.instance;
|
||||
|
||||
@override
|
||||
void updateSemantics(SemanticsUpdate update) {
|
||||
lastUpdate = update;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user