Skip to content

Commit

Permalink
Revert "Removes single window assumptions from flutter_test (#121549)"
Browse files Browse the repository at this point in the history
This reverts commit f2dd19d.
  • Loading branch information
pdblasi-google committed Mar 6, 2023
1 parent f5ddece commit 3e67b5e
Show file tree
Hide file tree
Showing 16 changed files with 1,310 additions and 2,269 deletions.
6 changes: 4 additions & 2 deletions packages/flutter/lib/src/widgets/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -901,13 +901,15 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
/// Used by [runApp] to wrap the provided `rootWidget` in the default [View].
///
/// The [View] determines into what [FlutterView] the app is rendered into.
/// This is currently [PlatformDispatcher.implicitView] from [platformDispatcher].
/// For backwards-compatibility reasons, this method currently chooses
/// [window] (which is a [FlutterView]) as the rendering target. This will
/// change in a future version of Flutter.
///
/// The `rootWidget` widget provided to this method must not already be
/// wrapped in a [View].
Widget wrapWithDefaultView(Widget rootWidget) {
return View(
view: platformDispatcher.implicitView!,
view: window,
child: rootWidget,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/material/debug_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void main() {
' MediaQuery\n'
' _MediaQueryFromView\n'
' _ViewScope\n'
' View-[GlobalObjectKey TestFlutterView#00000]\n'
' View-[GlobalObjectKey TestWindow#00000]\n'
' [root]\n'
' Typically, the Scaffold widget is introduced by the MaterialApp\n'
' or WidgetsApp widget at the top of your application widget tree.\n'
Expand Down Expand Up @@ -376,7 +376,7 @@ void main() {
' MediaQuery\n'
' _MediaQueryFromView\n'
' _ViewScope\n'
' View-[GlobalObjectKey TestFlutterView#00000]\n'
' View-[GlobalObjectKey TestWindow#00000]\n'
' [root]\n'
' Typically, the ScaffoldMessenger widget is introduced by the\n'
' MaterialApp at the top of your application widget tree.\n'
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/material/scaffold_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,7 @@ void main() {
' MediaQuery\n'
' _MediaQueryFromView\n'
' _ViewScope\n'
' View-[GlobalObjectKey TestFlutterView#e6136]\n'
' View-[GlobalObjectKey TestWindow#e6136]\n'
' [root]\n'
' Typically, the ScaffoldMessenger widget is introduced by the\n'
' MaterialApp at the top of your application widget tree.\n',
Expand Down
953 changes: 444 additions & 509 deletions packages/flutter/test/widgets/container_test.dart

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void main() {
' creator: ConstrainedBox ← Container ← LayoutWithMissingId ←\n'
' CustomMultiChildLayout ← Center ← MediaQuery ←\n'
' _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
' TestFlutterView#00000] ← [root]\n'
' TestWindow#00000] ← [root]\n'
' parentData: offset=Offset(0.0, 0.0); id=null\n'
' constraints: MISSING\n'
' size: MISSING\n'
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/widgets/focus_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ void main() {
' │ primaryFocus: FocusNode#00000(Child 4 [PRIMARY FOCUS])\n'
' │ primaryFocusCreator: Container-[GlobalKey#00000] ← MediaQuery ←\n'
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
' │ TestFlutterView#00000] ← [root]\n'
' │ TestWindow#00000] ← [root]\n'
' │\n'
' └─rootScope: FocusScopeNode#00000(Root Focus Scope [IN FOCUS PATH])\n'
' │ IN FOCUS PATH\n'
Expand Down
259 changes: 173 additions & 86 deletions packages/flutter/test/widgets/media_query_test.dart

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ void main() {
'_RenderDiagonal#00000 relayoutBoundary=up1\n'
' │ creator: _Diagonal ← Align ← Directionality ← MediaQuery ←\n'
' │ _MediaQueryFromView ← _ViewScope ← View-[GlobalObjectKey\n'
' │ TestFlutterView#00000] ← [root]\n'
' │ TestWindow#00000] ← [root]\n'
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
' │ size: Size(190.0, 220.0)\n'
' │\n'
' ├─topLeft: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
' │ creator: SizedBox ← _Diagonal ← Align ← Directionality ←\n'
' │ MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
' │ View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
' │ View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
' │ constraints: BoxConstraints(unconstrained)\n'
' │ size: Size(80.0, 100.0)\n'
Expand All @@ -240,7 +240,7 @@ void main() {
' └─bottomRight: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
' creator: SizedBox ← _Diagonal ← Align ← Directionality ←\n'
' MediaQuery ← _MediaQueryFromView ← _ViewScope ←\n'
' View-[GlobalObjectKey TestFlutterView#00000] ← [root]\n'
' View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
' parentData: offset=Offset(80.0, 100.0) (can use size)\n'
' constraints: BoxConstraints(unconstrained)\n'
' size: Size(110.0, 120.0)\n'
Expand Down
15 changes: 4 additions & 11 deletions packages/flutter_test/lib/src/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
52 changes: 0 additions & 52 deletions packages/flutter_test/lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
///
Expand All @@ -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();
Expand Down

0 comments on commit 3e67b5e

Please sign in to comment.