add ui.Window fallback to TestViewConfiguration (#27987)

This commit is contained in:
Jonah Williams
2019-02-14 22:49:49 -08:00
committed by GitHub
parent 9bc5656637
commit 3205736fcf
2 changed files with 25 additions and 2 deletions

View File

@@ -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);

View File

@@ -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));
});
});
}