Unverified Commit 86f9ab51 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

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
parent c6d4a6ef
......@@ -236,12 +236,12 @@ abstract class BindingBase {
}
_postExtensionStateChangedEvent(
brightnessOverrideExtensionName,
(debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(),
(debugBrightnessOverride ?? window.platformBrightness).toString(),
);
await reassembleApplication();
}
return <String, dynamic>{
'value': (debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(),
'value': (debugBrightnessOverride ?? window.platformBrightness).toString(),
};
},
);
......
......@@ -198,7 +198,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
void initInstances() {
super.initInstances();
_instance = this;
platformDispatcher.onPointerDataPacket = _handlePointerDataPacket;
window.onPointerDataPacket = _handlePointerDataPacket;
}
@override
......
......@@ -33,7 +33,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
onSemanticsOwnerCreated: _handleSemanticsOwnerCreated,
onSemanticsOwnerDisposed: _handleSemanticsOwnerDisposed,
);
platformDispatcher
window
..onMetricsChanged = handleMetricsChanged
..onTextScaleFactorChanged = handleTextScaleFactorChanged
..onPlatformBrightnessChanged = handlePlatformBrightnessChanged
......@@ -280,7 +280,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
}
void _handleSemanticsEnabledChanged() {
setSemanticsEnabled(platformDispatcher.semanticsEnabled);
setSemanticsEnabled(window.semanticsEnabled);
}
/// Whether the render tree associated with this binding should produce a tree
......
......@@ -265,10 +265,10 @@ mixin SchedulerBinding on BindingBase {
void addTimingsCallback(TimingsCallback callback) {
_timingsCallbacks.add(callback);
if (_timingsCallbacks.length == 1) {
assert(platformDispatcher.onReportTimings == null);
platformDispatcher.onReportTimings = _executeTimingsCallbacks;
assert(window.onReportTimings == null);
window.onReportTimings = _executeTimingsCallbacks;
}
assert(platformDispatcher.onReportTimings == _executeTimingsCallbacks);
assert(window.onReportTimings == _executeTimingsCallbacks);
}
/// Removes a callback that was earlier added by [addTimingsCallback].
......@@ -276,7 +276,7 @@ mixin SchedulerBinding on BindingBase {
assert(_timingsCallbacks.contains(callback));
_timingsCallbacks.remove(callback);
if (_timingsCallbacks.isEmpty) {
platformDispatcher.onReportTimings = null;
window.onReportTimings = null;
}
}
......@@ -724,8 +724,8 @@ mixin SchedulerBinding on BindingBase {
/// [PlatformDispatcher.onDrawFrame] are registered.
@protected
void ensureFrameCallbacksRegistered() {
platformDispatcher.onBeginFrame ??= _handleBeginFrame;
platformDispatcher.onDrawFrame ??= _handleDrawFrame;
window.onBeginFrame ??= _handleBeginFrame;
window.onDrawFrame ??= _handleDrawFrame;
}
/// Schedules a new frame using [scheduleFrame] if this object is not
......@@ -790,7 +790,7 @@ mixin SchedulerBinding on BindingBase {
return true;
}());
ensureFrameCallbacksRegistered();
platformDispatcher.scheduleFrame();
window.scheduleFrame();
_hasScheduledFrame = true;
}
......@@ -827,7 +827,7 @@ mixin SchedulerBinding on BindingBase {
debugPrintStack(label: 'scheduleForcedFrame() called. Current phase is $schedulerPhase.');
return true;
}());
platformDispatcher.scheduleFrame();
window.scheduleFrame();
_hasScheduledFrame = true;
}
......
......@@ -21,7 +21,7 @@ mixin SemanticsBinding on BindingBase {
void initInstances() {
super.initInstances();
_instance = this;
_accessibilityFeatures = platformDispatcher.accessibilityFeatures;
_accessibilityFeatures = window.accessibilityFeatures;
}
/// Called when the platform accessibility features change.
......@@ -29,7 +29,7 @@ mixin SemanticsBinding on BindingBase {
/// See [dart:ui.PlatformDispatcher.onAccessibilityFeaturesChanged].
@protected
void handleAccessibilityFeaturesChanged() {
_accessibilityFeatures = platformDispatcher.accessibilityFeatures;
_accessibilityFeatures = window.accessibilityFeatures;
}
/// Creates an empty semantics update builder.
......
......@@ -2658,7 +2658,7 @@ class SemanticsOwner extends ChangeNotifier {
final CustomSemanticsAction action = CustomSemanticsAction.getAction(actionId)!;
builder.updateCustomAction(id: actionId, label: action.label, hint: action.hint, overrideId: action.action?.index ?? -1);
}
SemanticsBinding.instance!.platformDispatcher.updateSemantics(builder.build());
SemanticsBinding.instance!.window.updateSemantics(builder.build());
notifyListeners();
}
......
......@@ -28,7 +28,7 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
_instance = this;
_defaultBinaryMessenger = createBinaryMessenger();
_restorationManager = createRestorationManager();
platformDispatcher.onPlatformMessage = defaultBinaryMessenger.handlePlatformMessage;
window.onPlatformMessage = defaultBinaryMessenger.handlePlatformMessage;
initLicenses();
SystemChannels.system.setMessageHandler((dynamic message) => handleSystemMessage(message as Object));
SystemChannels.lifecycle.setMessageHandler(_handleLifecycleMessage);
......
......@@ -1113,15 +1113,15 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
// If window.defaultRouteName isn't '/', we should assume it was set
// intentionally via `setInitialRoute`, and should override whatever is in
// [widget.initialRoute].
String get _initialRouteName => WidgetsBinding.instance!.platformDispatcher.defaultRouteName != Navigator.defaultRouteName
? WidgetsBinding.instance!.platformDispatcher.defaultRouteName
: widget.initialRoute ?? WidgetsBinding.instance!.platformDispatcher.defaultRouteName;
String get _initialRouteName => WidgetsBinding.instance!.window.defaultRouteName != Navigator.defaultRouteName
? WidgetsBinding.instance!.window.defaultRouteName
: widget.initialRoute ?? WidgetsBinding.instance!.window.defaultRouteName;
@override
void initState() {
super.initState();
_updateRouting();
_locale = _resolveLocales(WidgetsBinding.instance!.platformDispatcher.locales, widget.supportedLocales);
_locale = _resolveLocales(WidgetsBinding.instance!.window.locales, widget.supportedLocales);
WidgetsBinding.instance!.addObserver(this);
}
......
......@@ -245,7 +245,7 @@ abstract class WidgetsBindingObserver {
///
/// This method exposes notifications from
/// [dart:ui.PlatformDispatcher.onLocaleChanged].
void didChangeLocales(List<Locale>? locale) { }
void didChangeLocales(List<Locale>? locales) { }
/// Called when the system puts the app in the background or returns
/// the app to the foreground.
......@@ -287,8 +287,8 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
// properly setup the [defaultBinaryMessenger] instance.
_buildOwner = BuildOwner();
buildOwner!.onBuildScheduled = _handleBuildScheduled;
platformDispatcher.onLocaleChanged = handleLocaleChanged;
platformDispatcher.onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged;
window.onLocaleChanged = handleLocaleChanged;
window.onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged;
SystemChannels.navigation.setMethodCallHandler(_handleNavigationInvocation);
FlutterErrorDetails.propertiesTransformers.add(transformDebugCreator);
}
......@@ -586,7 +586,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
@protected
@mustCallSuper
void handleLocaleChanged() {
dispatchLocalesChanged(platformDispatcher.locales);
dispatchLocalesChanged(window.locales);
}
/// Notify all the observers that the locale has changed (using
......@@ -1016,7 +1016,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
/// method again with the matched locale of the first call omitted from
/// `supportedLocales`.
Locale? computePlatformResolvedLocale(List<Locale> supportedLocales) {
return platformDispatcher.computePlatformResolvedLocale(supportedLocales);
return window.computePlatformResolvedLocale(supportedLocales);
}
}
......
......@@ -19,14 +19,14 @@ void main() {
// Simulates the engine completing a frame render to trigger the
// appropriate callback setting [WidgetBinding.firstFrameRasterized].
binding.platformDispatcher.onReportTimings!(<FrameTiming>[]);
binding.window.onReportTimings!(<FrameTiming>[]);
expect(binding.firstFrameRasterized, isFalse);
binding.allowFirstFrame();
fakeAsync.flushTimers();
// Simulates the engine again.
binding.platformDispatcher.onReportTimings!(<FrameTiming>[]);
binding.window.onReportTimings!(<FrameTiming>[]);
expect(binding.firstFrameRasterized, isTrue);
});
});
......
......@@ -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
......
......@@ -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;
}
}
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