Repository: flutter
Issue: Inconsistent sizes reported when running a test with `flutter run` vs `flutter test`
Labels: a: tests,framework,P2,team-framework,triaged-framework

```dart
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('Foo', (widgetTester) async {
    print('View physical size: ${widgetTester.view.physicalSize}');
    print('View dpr: ${widgetTester.view.devicePixelRatio}');
    print('Config size: ${widgetTester.binding.renderView.configuration.size}');
    print('Config size: ${widgetTester.binding.renderView.configuration.devicePixelRatio}');
    await widgetTester.pumpWidget(Builder(
      builder: (BuildContext context) {
        print('MediaQuery size: ${MediaQuery.sizeOf(context)}');
        print('MediaQuery DPR: ${MediaQuery.devicePixelRatioOf(context)}');
        return const Placeholder();
      }
    ));
  });
}
```

Running the above code with `flutter test` prints:

```
View size: Size(2400.0, 1800.0)
View dpr: 3.0
Config size: Size(800.0, 600.0)
Config size: 3.0
MediaQuery size: Size(800.0, 600.0)
MediaQuery DPR: 3.0
```

That's the expected output. However, when the test is now run with `flutter run`, the output changes depending on the device used to run on. This is the output when running on an iPhone 13 simulator:

```
flutter: View physical size: Size(1170.0, 2532.0)
flutter: View dpr: 3.0
flutter: Config size: Size(800.0, 600.0)
flutter: Config size: 3.0
flutter: MediaQuery size: Size(390.0, 844.0)
flutter: MediaQuery DPR: 3.0
```

And this `flutter run` on macOS:

```
flutter: View physical size: Size(1600.0, 1200.0)
flutter: View dpr: 2.0
flutter: Config size: Size(800.0, 600.0)
flutter: Config size: 2.0
flutter: MediaQuery size: Size(800.0, 600.0)
flutter: MediaQuery DPR: 2.0
```

This is problematic as widget tests shouldn't change their behavior depending on how they were executed. `flutter run` should run the test just like `flutter test` does. However, it seems like `flutter run` is leaking some values from the test device into the test. This could alter the behavior of the test. For example, if the widget under test is adaptive, it may render a different UI when `MediaQuery.sizeOf` reports `Size(390.0, 844.0)` instead of the expected `Size(800.0, 600.0)`.

After further investigation it looks like there are two problems here:

1) The `LiveTestWidgetsFlutterBinding` used by `flutter run` doesn't configure the `TestFlutterView` to simulate the physical size (and DPR?) used by the `flutter test` environment.
2) `LiveTestWidgetsFlutterBinding.createViewConfiguration` needs to create a TestViewConfigruation with a matrix that properly translates between the simulated geometry of the TestFlutterView and the actual geometry of the underlying FlutterView. The current implementation is buggy because it assumes that TestFlutterView.physicalSize is the real geometry. However, users may have messed with this in a test.

For 2) one idea is to expose the wrapped view of the TestFlutterView somehow, so `LiveTestWidgetsFlutterBinding.createViewConfiguration` can read the real geometry from it.

Somewhat related: https://github.com/flutter/flutter/issues/123881