From 3205736fcf09f52e6d5e97916f5eb314e6849c12 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 14 Feb 2019 22:49:49 -0800 Subject: [PATCH] add ui.Window fallback to TestViewConfiguration (#27987) --- packages/flutter_test/lib/src/binding.dart | 10 ++++++++-- packages/flutter_test/test/bindings_test.dart | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 packages/flutter_test/test/bindings_test.dart diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 35595eb5af..a7261b9153 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -1319,10 +1319,16 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { /// size onto the actual display using the [BoxFit.contain] algorithm. class TestViewConfiguration extends ViewConfiguration { /// Creates a [TestViewConfiguration] with the given size. Defaults to 800x600. - TestViewConfiguration({ + /// + /// If a [window] instance is not provided it defaults to [ui.window]. + factory TestViewConfiguration({ Size size = _kDefaultTestViewportSize, ui.Window window, - }) + }) { + return TestViewConfiguration._(size, window ?? ui.window); + } + + TestViewConfiguration._(Size size, ui.Window window) : _paintMatrix = _getMatrix(size, window.devicePixelRatio, window), _hitTestMatrix = _getMatrix(size, 1.0, window), super(size: size); diff --git a/packages/flutter_test/test/bindings_test.dart b/packages/flutter_test/test/bindings_test.dart new file mode 100644 index 0000000000..eef7e41560 --- /dev/null +++ b/packages/flutter_test/test/bindings_test.dart @@ -0,0 +1,17 @@ +// Copyright 2019 The Chromium 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 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; + + +void main() { + group(TestViewConfiguration, () { + test('is initialized with top-level window if one is not provided', () { + // The code below will throw without the default. + TestViewConfiguration(size: const Size(1280.0, 800.0)); + }); + }); +}