|
| 1 | +import 'package:flutter/foundation.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:flutter_test_runners/flutter_test_runners.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + group("Runners simulate platforms >", () { |
| 7 | + group("all platforms >", () { |
| 8 | + final expectedPlatforms = [ |
| 9 | + TargetPlatform.iOS, |
| 10 | + TargetPlatform.android, |
| 11 | + TargetPlatform.macOS, |
| 12 | + TargetPlatform.windows, |
| 13 | + TargetPlatform.linux, |
| 14 | + ]; |
| 15 | + |
| 16 | + testWidgetsOnAllPlatforms("all platforms runner", (tester) async { |
| 17 | + expect(expectedPlatforms, contains(defaultTargetPlatform)); |
| 18 | + expectedPlatforms.remove(defaultTargetPlatform); |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + group("mobile >", () { |
| 23 | + final expectedPlatforms = [TargetPlatform.iOS, TargetPlatform.android]; |
| 24 | + |
| 25 | + testWidgetsOnMobile("mobile runner", (tester) async { |
| 26 | + expect(expectedPlatforms, contains(defaultTargetPlatform)); |
| 27 | + expectedPlatforms.remove(defaultTargetPlatform); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + testWidgetsOnIos("iOS runner", (tester) async { |
| 32 | + expect(defaultTargetPlatform, TargetPlatform.iOS); |
| 33 | + |
| 34 | + // We leave mobile pixel ratios alone because the default Flutter value |
| 35 | + // approximates real mobile pixel ratios. |
| 36 | + expect(tester.view.devicePixelRatio, 3.0); |
| 37 | + }); |
| 38 | + |
| 39 | + testWidgetsOnAndroid("Android runner", (tester) async { |
| 40 | + expect(defaultTargetPlatform, TargetPlatform.android); |
| 41 | + |
| 42 | + // We leave mobile pixel ratios alone because the default Flutter value |
| 43 | + // approximates real mobile pixel ratios. |
| 44 | + expect(tester.view.devicePixelRatio, 3.0); |
| 45 | + }); |
| 46 | + |
| 47 | + group("desktop >", () { |
| 48 | + final expectedPlatforms = [TargetPlatform.macOS, TargetPlatform.windows, TargetPlatform.linux]; |
| 49 | + |
| 50 | + testWidgetsOnDesktop("desktop runner", (tester) async { |
| 51 | + expect(expectedPlatforms, contains(defaultTargetPlatform)); |
| 52 | + expectedPlatforms.remove(defaultTargetPlatform); |
| 53 | + |
| 54 | + // We configure desktop for a 1:1 pixel density to match real desktops. |
| 55 | + expect(tester.view.devicePixelRatio, 1.0); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + testWidgetsOnMac("Mac runner", (tester) async { |
| 60 | + expect(defaultTargetPlatform, TargetPlatform.macOS); |
| 61 | + |
| 62 | + // We configure desktop for a 1:1 pixel density to match real desktops. |
| 63 | + expect(tester.view.devicePixelRatio, 1.0); |
| 64 | + }); |
| 65 | + |
| 66 | + testWidgetsOnWindows("Windows runner", (tester) async { |
| 67 | + expect(defaultTargetPlatform, TargetPlatform.windows); |
| 68 | + |
| 69 | + // We configure desktop for a 1:1 pixel density to match real desktops. |
| 70 | + expect(tester.view.devicePixelRatio, 1.0); |
| 71 | + }); |
| 72 | + |
| 73 | + testWidgetsOnLinux("Linux runner", (tester) async { |
| 74 | + expect(defaultTargetPlatform, TargetPlatform.linux); |
| 75 | + |
| 76 | + // We configure desktop for a 1:1 pixel density to match real desktops. |
| 77 | + expect(tester.view.devicePixelRatio, 1.0); |
| 78 | + }); |
| 79 | + }); |
| 80 | +} |
0 commit comments