Revert usages of the binding's platformDispatcher to use window instead (#70319)

This reverts usages of the binding's platformDispatcher to use window again temporarily, because there isn't a TestPlatformDispatcher yet, and so some tests were failing because they mocked the TestWindow to return certain things (locales) that were returning the real values instead of the test values.

Once I've created a TestPlatformDispatcher to allow fake data to be passed to it, we can go back to using the platformDispatcher in all of these places
This commit is contained in:
Greg Spencer
2020-11-12 11:17:00 -08:00
committed by GitHub
parent c6d4a6ef5c
commit 86f9ab511e
12 changed files with 49 additions and 31 deletions

View File

@@ -1039,8 +1039,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override
void ensureFrameCallbacksRegistered() {
// Leave PlatformDispatcher alone, do nothing.
assert(platformDispatcher.onDrawFrame == null);
assert(platformDispatcher.onBeginFrame == null);
assert(window.onDrawFrame == null);
assert(window.onBeginFrame == null);
}
@override

View File

@@ -5,7 +5,7 @@
import 'dart:ui' as ui show window;
import 'dart:ui' show Size, Locale, WindowPadding, AccessibilityFeatures, Brightness;
import 'package:flutter/widgets.dart' show WidgetsBinding;
import 'package:flutter/widgets.dart' show WidgetsBinding, WidgetsBindingObserver;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -184,6 +184,14 @@ void main() {
expect(WidgetsBinding.instance!.window.devicePixelRatio, originalDevicePixelRatio);
expect(WidgetsBinding.instance!.window.textScaleFactor, originalTextScaleFactor);
});
testWidgets('TestWindow sends fake locales when WidgetsBindingObserver notifiers are called', (WidgetTester tester) async {
final TestObserver observer = TestObserver();
retrieveTestBinding(tester).addObserver(observer);
final List<Locale> expectedValue = <Locale>[const Locale('fake_language_code')];
retrieveTestBinding(tester).window.localesTestValue = expectedValue;
expect(observer.locales, equals(expectedValue));
});
}
void verifyThatTestWindowCanFakeProperty<WindowPropertyType>({
@@ -273,3 +281,13 @@ class FakeAccessibilityFeatures implements AccessibilityFeatures {
return null;
}
}
class TestObserver with WidgetsBindingObserver {
List<Locale>? locales;
Locale? locale;
@override
void didChangeLocales(List<Locale>? locales) {
this.locales = locales;
}
}