Unverified Commit 6efe8e91 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove most usage of MockDevice (#74999)

parent fb9ff62c
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/dds.dart'; import 'package:flutter_tools/src/base/dds.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/features.dart';
...@@ -136,14 +137,15 @@ const FakeVmServiceRequest listenToExtensionStream = FakeVmServiceRequest( ...@@ -136,14 +137,15 @@ const FakeVmServiceRequest listenToExtensionStream = FakeVmServiceRequest(
args: <String, Object>{'streamId': 'Extension'}, args: <String, Object>{'streamId': 'Extension'},
); );
final Uri testUri = Uri.parse('foo://bar');
void main() { void main() {
final Uri testUri = Uri.parse('foo://bar');
Testbed testbed; Testbed testbed;
MockFlutterDevice mockFlutterDevice; MockFlutterDevice mockFlutterDevice;
MockVMService mockVMService; MockVMService mockVMService;
MockDevFS mockDevFS; MockDevFS mockDevFS;
ResidentRunner residentRunner; ResidentRunner residentRunner;
MockDevice mockDevice; FakeDevice mockDevice;
FakeVmServiceHost fakeVmServiceHost; FakeVmServiceHost fakeVmServiceHost;
MockDevtoolsLauncher mockDevtoolsLauncher; MockDevtoolsLauncher mockDevtoolsLauncher;
...@@ -164,7 +166,7 @@ void main() { ...@@ -164,7 +166,7 @@ void main() {
); );
}); });
mockFlutterDevice = MockFlutterDevice(); mockFlutterDevice = MockFlutterDevice();
mockDevice = MockDevice(); mockDevice = FakeDevice();
mockVMService = MockVMService(); mockVMService = MockVMService();
mockDevFS = MockDevFS(); mockDevFS = MockDevFS();
mockDevtoolsLauncher = MockDevtoolsLauncher(); mockDevtoolsLauncher = MockDevtoolsLauncher();
...@@ -463,16 +465,6 @@ void main() { ...@@ -463,16 +465,6 @@ void main() {
) )
), ),
]); ]);
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
residentRunner = HotRunner( residentRunner = HotRunner(
<FlutterDevice>[ <FlutterDevice>[
mockFlutterDevice, mockFlutterDevice,
...@@ -512,15 +504,6 @@ void main() { ...@@ -512,15 +504,6 @@ void main() {
setAssetBundlePath, setAssetBundlePath,
listViews, listViews,
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -550,7 +533,7 @@ void main() { ...@@ -550,7 +533,7 @@ void main() {
TestUsageEvent('hot', 'exception', parameters: <String, String>{ TestUsageEvent('hot', 'exception', parameters: <String, String>{
cdKey(CustomDimensions.hotEventTargetPlatform): cdKey(CustomDimensions.hotEventTargetPlatform):
getNameForTargetPlatform(TargetPlatform.android_arm), getNameForTargetPlatform(TargetPlatform.android_arm),
cdKey(CustomDimensions.hotEventSdkName): 'Example', cdKey(CustomDimensions.hotEventSdkName): 'Android',
cdKey(CustomDimensions.hotEventEmulator): 'false', cdKey(CustomDimensions.hotEventEmulator): 'false',
cdKey(CustomDimensions.hotEventFullRestart): 'false', cdKey(CustomDimensions.hotEventFullRestart): 'false',
}), }),
...@@ -568,15 +551,6 @@ void main() { ...@@ -568,15 +551,6 @@ void main() {
listViews, listViews,
setAssetBundlePath, setAssetBundlePath,
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -600,15 +574,6 @@ void main() { ...@@ -600,15 +574,6 @@ void main() {
setAssetBundlePath, setAssetBundlePath,
listViews, listViews,
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -640,7 +605,7 @@ void main() { ...@@ -640,7 +605,7 @@ void main() {
TestUsageEvent('hot', 'reload-barred', parameters: <String, String>{ TestUsageEvent('hot', 'reload-barred', parameters: <String, String>{
cdKey(CustomDimensions.hotEventTargetPlatform): cdKey(CustomDimensions.hotEventTargetPlatform):
getNameForTargetPlatform(TargetPlatform.android_arm), getNameForTargetPlatform(TargetPlatform.android_arm),
cdKey(CustomDimensions.hotEventSdkName): 'Example', cdKey(CustomDimensions.hotEventSdkName): 'Android',
cdKey(CustomDimensions.hotEventEmulator): 'false', cdKey(CustomDimensions.hotEventEmulator): 'false',
cdKey(CustomDimensions.hotEventFullRestart): 'false', cdKey(CustomDimensions.hotEventFullRestart): 'false',
}), }),
...@@ -671,15 +636,6 @@ void main() { ...@@ -671,15 +636,6 @@ void main() {
], ],
)), )),
); );
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -710,7 +666,7 @@ void main() { ...@@ -710,7 +666,7 @@ void main() {
TestUsageEvent('hot', 'exception', parameters: <String, String>{ TestUsageEvent('hot', 'exception', parameters: <String, String>{
cdKey(CustomDimensions.hotEventTargetPlatform): cdKey(CustomDimensions.hotEventTargetPlatform):
getNameForTargetPlatform(TargetPlatform.android_arm), getNameForTargetPlatform(TargetPlatform.android_arm),
cdKey(CustomDimensions.hotEventSdkName): 'Example', cdKey(CustomDimensions.hotEventSdkName): 'Android',
cdKey(CustomDimensions.hotEventEmulator): 'false', cdKey(CustomDimensions.hotEventEmulator): 'false',
cdKey(CustomDimensions.hotEventFullRestart): 'false', cdKey(CustomDimensions.hotEventFullRestart): 'false',
}), }),
...@@ -749,15 +705,6 @@ void main() { ...@@ -749,15 +705,6 @@ void main() {
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart', target: 'main.dart',
); );
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -833,15 +780,6 @@ void main() { ...@@ -833,15 +780,6 @@ void main() {
}, },
), ),
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -923,15 +861,6 @@ void main() { ...@@ -923,15 +861,6 @@ void main() {
}, },
), ),
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -1009,15 +938,6 @@ void main() { ...@@ -1009,15 +938,6 @@ void main() {
}, },
), ),
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -1101,16 +1021,6 @@ void main() { ...@@ -1101,16 +1021,6 @@ void main() {
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart', target: 'main.dart',
); );
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(NoOpDeviceLogReader('test'));
when(mockDevFS.update( when(mockDevFS.update(
mainUri: anyNamed('mainUri'), mainUri: anyNamed('mainUri'),
target: anyNamed('target'), target: anyNamed('target'),
...@@ -1202,16 +1112,6 @@ void main() { ...@@ -1202,16 +1112,6 @@ void main() {
) )
) )
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
when(mockDevice.supportsHotRestart).thenReturn(true);
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -1289,16 +1189,6 @@ void main() { ...@@ -1289,16 +1189,6 @@ void main() {
) )
) )
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
when(mockDevice.supportsHotRestart).thenReturn(true);
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -1422,16 +1312,6 @@ void main() { ...@@ -1422,16 +1312,6 @@ void main() {
), ),
) )
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
when(mockDevice.supportsHotRestart).thenReturn(true);
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -1454,16 +1334,6 @@ void main() { ...@@ -1454,16 +1334,6 @@ void main() {
listViews, listViews,
setAssetBundlePath, setAssetBundlePath,
]); ]);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example';
});
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) async {
return false;
});
when(mockDevice.supportsHotRestart).thenReturn(true);
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
unawaited(residentRunner.attach( unawaited(residentRunner.attach(
...@@ -1494,7 +1364,7 @@ void main() { ...@@ -1494,7 +1364,7 @@ void main() {
TestUsageEvent('hot', 'exception', parameters: <String, String>{ TestUsageEvent('hot', 'exception', parameters: <String, String>{
cdKey(CustomDimensions.hotEventTargetPlatform): cdKey(CustomDimensions.hotEventTargetPlatform):
getNameForTargetPlatform(TargetPlatform.android_arm), getNameForTargetPlatform(TargetPlatform.android_arm),
cdKey(CustomDimensions.hotEventSdkName): 'Example', cdKey(CustomDimensions.hotEventSdkName): 'Android',
cdKey(CustomDimensions.hotEventEmulator): 'false', cdKey(CustomDimensions.hotEventEmulator): 'false',
cdKey(CustomDimensions.hotEventFullRestart): 'true', cdKey(CustomDimensions.hotEventFullRestart): 'true',
}), }),
...@@ -1572,8 +1442,6 @@ void main() { ...@@ -1572,8 +1442,6 @@ void main() {
testUsingContext('ResidentRunner printHelpDetails', () => testbed.run(() { testUsingContext('ResidentRunner printHelpDetails', () => testbed.run(() {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.supportsScreenshot).thenReturn(true);
residentRunner.printHelp(details: true); residentRunner.printHelp(details: true);
...@@ -1611,7 +1479,7 @@ void main() { ...@@ -1611,7 +1479,7 @@ void main() {
commandHelp.v, commandHelp.v,
commandHelp.P, commandHelp.P,
commandHelp.a, commandHelp.a,
'An Observatory debugger and profiler on null is available at: null', 'An Observatory debugger and profiler on FakeDevice is available at: null',
'\n💪 Running with sound null safety 💪', '\n💪 Running with sound null safety 💪',
'' ''
].join('\n') ].join('\n')
...@@ -1619,8 +1487,6 @@ void main() { ...@@ -1619,8 +1487,6 @@ void main() {
})); }));
testUsingContext('ResidentRunner printHelpDetails cold runner', () => testbed.run(() { testUsingContext('ResidentRunner printHelpDetails cold runner', () => testbed.run(() {
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.supportsScreenshot).thenReturn(true);
fakeVmServiceHost = null; fakeVmServiceHost = null;
residentRunner = ColdRunner( residentRunner = ColdRunner(
<FlutterDevice>[ <FlutterDevice>[
...@@ -1687,17 +1553,13 @@ void main() { ...@@ -1687,17 +1553,13 @@ void main() {
} }
) )
]); ]);
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
when(mockDevice.name).thenReturn('test device');
await residentRunner.writeSkSL(); await residentRunner.writeSkSL();
expect(testLogger.statusText, contains('flutter_01.sksl.json')); expect(testLogger.statusText, contains('flutter_01.sksl.json'));
expect(globals.fs.file('flutter_01.sksl.json'), exists); expect(globals.fs.file('flutter_01.sksl.json'), exists);
expect(json.decode(globals.fs.file('flutter_01.sksl.json').readAsStringSync()), <String, Object>{ expect(json.decode(globals.fs.file('flutter_01.sksl.json').readAsStringSync()), <String, Object>{
'platform': 'android', 'platform': 'android',
'name': 'test device', 'name': 'FakeDevice',
'engineRevision': '42.2', // From FakeFlutterVersion 'engineRevision': '42.2', // From FakeFlutterVersion
'data': <String, Object>{'A': 'B'} 'data': <String, Object>{'A': 'B'}
}); });
...@@ -1814,13 +1676,6 @@ void main() { ...@@ -1814,13 +1676,6 @@ void main() {
}, },
) )
]); ]);
when(mockDevice.supportsScreenshot).thenReturn(true);
when(mockDevice.takeScreenshot(any))
.thenAnswer((Invocation invocation) async {
final File file = invocation.positionalArguments.first as File;
file.writeAsBytesSync(List<int>.generate(1024, (int i) => i));
});
await residentRunner.screenshot(mockFlutterDevice); await residentRunner.screenshot(mockFlutterDevice);
expect(testLogger.statusText, contains('1kB')); expect(testLogger.statusText, contains('1kB'));
...@@ -1828,13 +1683,6 @@ void main() { ...@@ -1828,13 +1683,6 @@ void main() {
})); }));
testUsingContext('ResidentRunner can take screenshot on release device', () => testbed.run(() async { testUsingContext('ResidentRunner can take screenshot on release device', () => testbed.run(() async {
when(mockDevice.supportsScreenshot).thenReturn(true);
when(mockDevice.takeScreenshot(any))
.thenAnswer((Invocation invocation) async {
final File file = invocation.positionalArguments.first as File;
file.writeAsBytesSync(List<int>.generate(1024, (int i) => i));
});
residentRunner = ColdRunner( residentRunner = ColdRunner(
<FlutterDevice>[ <FlutterDevice>[
mockFlutterDevice, mockFlutterDevice,
...@@ -1871,7 +1719,6 @@ void main() { ...@@ -1871,7 +1719,6 @@ void main() {
errorCode: RPCErrorCodes.kInternalError, errorCode: RPCErrorCodes.kInternalError,
) )
]); ]);
when(mockDevice.supportsScreenshot).thenReturn(true);
await residentRunner.screenshot(mockFlutterDevice); await residentRunner.screenshot(mockFlutterDevice);
expect(testLogger.errorText, contains('Error')); expect(testLogger.errorText, contains('Error'));
...@@ -1898,7 +1745,6 @@ void main() { ...@@ -1898,7 +1745,6 @@ void main() {
errorCode: RPCErrorCodes.kInternalError, errorCode: RPCErrorCodes.kInternalError,
) )
]); ]);
when(mockDevice.supportsScreenshot).thenReturn(true);
await residentRunner.screenshot(mockFlutterDevice); await residentRunner.screenshot(mockFlutterDevice);
expect(testLogger.errorText, contains('Error')); expect(testLogger.errorText, contains('Error'));
...@@ -1923,8 +1769,8 @@ void main() { ...@@ -1923,8 +1769,8 @@ void main() {
}, },
), ),
]); ]);
when(mockDevice.supportsScreenshot).thenReturn(true); // Ensure that takeScreenshot will throw an exception.
when(mockDevice.takeScreenshot(any)).thenThrow(Exception()); mockDevice.failScreenshot = true;
await residentRunner.screenshot(mockFlutterDevice); await residentRunner.screenshot(mockFlutterDevice);
...@@ -1933,7 +1779,7 @@ void main() { ...@@ -1933,7 +1779,7 @@ void main() {
testUsingContext("ResidentRunner can't take screenshot on device without support", () => testbed.run(() { testUsingContext("ResidentRunner can't take screenshot on device without support", () => testbed.run(() {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
when(mockDevice.supportsScreenshot).thenReturn(false); mockDevice.supportsScreenshot = false;
expect(() => residentRunner.screenshot(mockFlutterDevice), expect(() => residentRunner.screenshot(mockFlutterDevice),
throwsAssertionError); throwsAssertionError);
...@@ -1950,12 +1796,6 @@ void main() { ...@@ -1950,12 +1796,6 @@ void main() {
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart', target: 'main.dart',
); );
when(mockDevice.supportsScreenshot).thenReturn(true);
when(mockDevice.takeScreenshot(any))
.thenAnswer((Invocation invocation) async {
final File file = invocation.positionalArguments.first as File;
file.writeAsBytesSync(List<int>.generate(1024, (int i) => i));
});
await residentRunner.screenshot(mockFlutterDevice); await residentRunner.screenshot(mockFlutterDevice);
...@@ -1985,11 +1825,10 @@ void main() { ...@@ -1985,11 +1825,10 @@ void main() {
mockDevice, mockDevice,
); );
flutterDevice.vmService = fakeVmServiceHost.vmService; flutterDevice.vmService = fakeVmServiceHost.vmService;
when(mockDevice.supportsFlutterExit).thenReturn(true);
await flutterDevice.exitApps(); await flutterDevice.exitApps();
verify(mockDevice.stopApp(any, userIdentifier: anyNamed('userIdentifier'))).called(1); expect(mockDevice.appStopped, true);
expect(fakeVmServiceHost.hasRemainingExpectations, false); expect(fakeVmServiceHost.hasRemainingExpectations, false);
})); }));
...@@ -1997,11 +1836,10 @@ void main() { ...@@ -1997,11 +1836,10 @@ void main() {
final TestFlutterDevice flutterDevice = TestFlutterDevice( final TestFlutterDevice flutterDevice = TestFlutterDevice(
mockDevice, mockDevice,
); );
when(mockDevice.supportsFlutterExit).thenReturn(true);
await flutterDevice.exitApps(); await flutterDevice.exitApps();
verify(mockDevice.stopApp(any, userIdentifier: anyNamed('userIdentifier'))).called(1); expect(mockDevice.appStopped, true);
})); }));
testUsingContext('FlutterDevice will call stopApp if the exit request times out', () => testbed.run(() async { testUsingContext('FlutterDevice will call stopApp if the exit request times out', () => testbed.run(() async {
...@@ -2034,13 +1872,12 @@ void main() { ...@@ -2034,13 +1872,12 @@ void main() {
mockDevice, mockDevice,
); );
flutterDevice.vmService = fakeVmServiceHost.vmService; flutterDevice.vmService = fakeVmServiceHost.vmService;
when(mockDevice.supportsFlutterExit).thenReturn(true);
await flutterDevice.exitApps( await flutterDevice.exitApps(
timeoutDelay: Duration.zero, timeoutDelay: Duration.zero,
); );
verify(mockDevice.stopApp(any, userIdentifier: anyNamed('userIdentifier'))).called(1); expect(mockDevice.appStopped, true);
expect(fakeVmServiceHost.hasRemainingExpectations, false); expect(fakeVmServiceHost.hasRemainingExpectations, false);
})); }));
...@@ -2074,8 +1911,6 @@ void main() { ...@@ -2074,8 +1911,6 @@ void main() {
); );
flutterDevice.vmService = fakeVmServiceHost.vmService; flutterDevice.vmService = fakeVmServiceHost.vmService;
when(mockDevice.supportsFlutterExit).thenReturn(true);
final Future<void> exitFuture = flutterDevice.exitApps(); final Future<void> exitFuture = flutterDevice.exitApps();
await expectLater(exitFuture, completes); await expectLater(exitFuture, completes);
...@@ -2249,13 +2084,13 @@ void main() { ...@@ -2249,13 +2084,13 @@ void main() {
}, },
), ),
]); ]);
final FlutterDevice device = FlutterDevice( final FlutterDevice flutterDevice = FlutterDevice(
mockDevice, mockDevice,
buildInfo: BuildInfo.debug, buildInfo: BuildInfo.debug,
); );
device.vmService = fakeVmServiceHost.vmService; flutterDevice.vmService = fakeVmServiceHost.vmService;
expect(await device.toggleBrightness(), Brightness.dark); expect(await flutterDevice.toggleBrightness(), Brightness.dark);
expect(fakeVmServiceHost.hasRemainingExpectations, false); expect(fakeVmServiceHost.hasRemainingExpectations, false);
})); }));
...@@ -2309,13 +2144,13 @@ void main() { ...@@ -2309,13 +2144,13 @@ void main() {
}, },
), ),
]); ]);
final FlutterDevice device = FlutterDevice( final FlutterDevice flutterDevice = FlutterDevice(
mockDevice, mockDevice,
buildInfo: BuildInfo.debug, buildInfo: BuildInfo.debug,
); );
device.vmService = fakeVmServiceHost.vmService; flutterDevice.vmService = fakeVmServiceHost.vmService;
await device.toggleInvertOversizedImages(); await flutterDevice.toggleInvertOversizedImages();
expect(fakeVmServiceHost.hasRemainingExpectations, false); expect(fakeVmServiceHost.hasRemainingExpectations, false);
})); }));
...@@ -2681,14 +2516,12 @@ void main() { ...@@ -2681,14 +2516,12 @@ void main() {
DevtoolsLauncher: () => mockDevtoolsLauncher, DevtoolsLauncher: () => mockDevtoolsLauncher,
}); });
testUsingContext('HotRunner unforwards device ports', () => testbed.run(() async { testUsingContext('HotRunner calls device dispose', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews, listViews,
listViews, listViews,
setAssetBundlePath, setAssetBundlePath,
]); ]);
final MockDevicePortForwarder mockPortForwarder = MockDevicePortForwarder();
when(mockDevice.portForwarder).thenReturn(mockPortForwarder);
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
residentRunner = HotRunner( residentRunner = HotRunner(
<FlutterDevice>[ <FlutterDevice>[
...@@ -2705,13 +2538,8 @@ void main() { ...@@ -2705,13 +2538,8 @@ void main() {
return 0; return 0;
}); });
when(mockDevice.dispose()).thenAnswer((Invocation invocation) async {
await mockDevice.portForwarder.dispose();
});
await residentRunner.run(); await residentRunner.run();
expect(mockDevice.disposed, true);
verify(mockPortForwarder.dispose()).called(1);
}), overrides: <Type, Generator>{ }), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher, DevtoolsLauncher: () => mockDevtoolsLauncher,
}); });
...@@ -2793,11 +2621,7 @@ void main() { ...@@ -2793,11 +2621,7 @@ void main() {
testUsingContext('FlutterDevice uses dartdevc configuration when targeting web', () async { testUsingContext('FlutterDevice uses dartdevc configuration when targeting web', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final MockDevice mockDevice = MockDevice(); final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.web_javascript);
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.web_javascript;
});
final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
mockDevice, mockDevice,
buildInfo: const BuildInfo( buildInfo: const BuildInfo(
...@@ -2827,10 +2651,7 @@ void main() { ...@@ -2827,10 +2651,7 @@ void main() {
testUsingContext('FlutterDevice uses dartdevc configuration when targeting web with null-safety autodetected', () async { testUsingContext('FlutterDevice uses dartdevc configuration when targeting web with null-safety autodetected', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final MockDevice mockDevice = MockDevice(); final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.web_javascript);
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.web_javascript;
});
final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
mockDevice, mockDevice,
...@@ -2861,10 +2682,7 @@ void main() { ...@@ -2861,10 +2682,7 @@ void main() {
testUsingContext('FlutterDevice passes flutter-widget-cache flag when feature is enabled', () async { testUsingContext('FlutterDevice passes flutter-widget-cache flag when feature is enabled', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final MockDevice mockDevice = MockDevice(); final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.android_arm);
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
mockDevice, mockDevice,
...@@ -2888,10 +2706,8 @@ void main() { ...@@ -2888,10 +2706,8 @@ void main() {
testUsingContext('FlutterDevice passes alternative-invalidation-strategy flag when feature is enabled', () async { testUsingContext('FlutterDevice passes alternative-invalidation-strategy flag when feature is enabled', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final MockDevice mockDevice = MockDevice(); final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.android_arm);
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
mockDevice, mockDevice,
...@@ -2976,8 +2792,8 @@ void main() { ...@@ -2976,8 +2792,8 @@ void main() {
testUsingContext('Handle existing VM service clients DDS error', () => testbed.run(() async { testUsingContext('Handle existing VM service clients DDS error', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final MockDevice mockDevice = MockDevice(); final FakeDevice mockDevice = FakeDevice()
when(mockDevice.dds).thenReturn(DartDevelopmentService(logger: testLogger)); ..dds = DartDevelopmentService(logger: testLogger);
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) { ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) {
throw FakeDartDevelopmentServiceException(message: throw FakeDartDevelopmentServiceException(message:
'Existing VM service clients prevent DDS from taking control.', 'Existing VM service clients prevent DDS from taking control.',
...@@ -3018,8 +2834,8 @@ void main() { ...@@ -3018,8 +2834,8 @@ void main() {
testUsingContext('Failed DDS start outputs error message', () => testbed.run(() async { testUsingContext('Failed DDS start outputs error message', () => testbed.run(() async {
// See https://github.com/flutter/flutter/issues/72385 for context. // See https://github.com/flutter/flutter/issues/72385 for context.
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final MockDevice mockDevice = MockDevice(); final FakeDevice mockDevice = FakeDevice()
when(mockDevice.dds).thenReturn(DartDevelopmentService(logger: testLogger)); ..dds = DartDevelopmentService(logger: testLogger);
ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) { ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) {
throw FakeDartDevelopmentServiceException(message: 'No URI'); throw FakeDartDevelopmentServiceException(message: 'No URI');
}; };
...@@ -3149,12 +2965,12 @@ class MockFlutterDevice extends Mock implements FlutterDevice {} ...@@ -3149,12 +2965,12 @@ class MockFlutterDevice extends Mock implements FlutterDevice {}
class MockDartDevelopmentService extends Mock implements DartDevelopmentService {} class MockDartDevelopmentService extends Mock implements DartDevelopmentService {}
class MockVMService extends Mock implements vm_service.VmService {} class MockVMService extends Mock implements vm_service.VmService {}
class MockDevFS extends Mock implements DevFS {} class MockDevFS extends Mock implements DevFS {}
class MockDevice extends Mock implements Device {}
class MockDeviceLogReader extends Mock implements DeviceLogReader {} class MockDeviceLogReader extends Mock implements DeviceLogReader {}
class MockDevicePortForwarder extends Mock implements DevicePortForwarder {} class MockDevicePortForwarder extends Mock implements DevicePortForwarder {}
class MockDevtoolsLauncher extends Mock implements DevtoolsLauncher {} class MockDevtoolsLauncher extends Mock implements DevtoolsLauncher {}
class MockProcessManager extends Mock implements ProcessManager {} class MockProcessManager extends Mock implements ProcessManager {}
class MockResidentCompiler extends Mock implements ResidentCompiler {} class MockResidentCompiler extends Mock implements ResidentCompiler {}
class MockDevice extends Mock implements Device {}
class FakeDartDevelopmentServiceException implements dds.DartDevelopmentServiceException { class FakeDartDevelopmentServiceException implements dds.DartDevelopmentServiceException {
FakeDartDevelopmentServiceException({this.message = defaultMessage}); FakeDartDevelopmentServiceException({this.message = defaultMessage});
...@@ -3264,6 +3080,8 @@ class FakeDevice extends Fake implements Device { ...@@ -3264,6 +3080,8 @@ class FakeDevice extends Fake implements Device {
TargetPlatform targetPlatform = TargetPlatform.android_arm, TargetPlatform targetPlatform = TargetPlatform.android_arm,
bool isLocalEmulator = false, bool isLocalEmulator = false,
this.supportsHotRestart = true, this.supportsHotRestart = true,
this.supportsScreenshot = true,
this.supportsFlutterExit = true,
}) : _isLocalEmulator = isLocalEmulator, }) : _isLocalEmulator = isLocalEmulator,
_targetPlatform = targetPlatform, _targetPlatform = targetPlatform,
_sdkNameAndVersion = sdkNameAndVersion; _sdkNameAndVersion = sdkNameAndVersion;
...@@ -3272,8 +3090,23 @@ class FakeDevice extends Fake implements Device { ...@@ -3272,8 +3090,23 @@ class FakeDevice extends Fake implements Device {
final TargetPlatform _targetPlatform; final TargetPlatform _targetPlatform;
final String _sdkNameAndVersion; final String _sdkNameAndVersion;
bool disposed = false;
bool appStopped = false;
bool failScreenshot = false;
@override
bool supportsHotRestart;
@override
bool supportsScreenshot;
@override
bool supportsFlutterExit;
@override @override
final bool supportsHotRestart; PlatformType get platformType => _targetPlatform == TargetPlatform.web_javascript
? PlatformType.web
: PlatformType.android;
@override @override
Future<String> get sdkNameAndVersion async => _sdkNameAndVersion; Future<String> get sdkNameAndVersion async => _sdkNameAndVersion;
...@@ -3288,5 +3121,33 @@ class FakeDevice extends Fake implements Device { ...@@ -3288,5 +3121,33 @@ class FakeDevice extends Fake implements Device {
String get name => 'FakeDevice'; String get name => 'FakeDevice';
@override @override
Future<void> dispose() async { } DartDevelopmentService dds;
@override
Future<void> dispose() async {
disposed = true;
}
@override
Future<bool> stopApp(covariant ApplicationPackage app, {String userIdentifier}) async {
appStopped = true;
return true;
}
@override
Future<void> takeScreenshot(File outputFile) async {
if (failScreenshot) {
throw Exception();
}
outputFile.writeAsBytesSync(List<int>.generate(1024, (int i) => i));
}
@override
FutureOr<DeviceLogReader> getLogReader({
covariant ApplicationPackage app,
bool includePastLogs = false,
}) => NoOpDeviceLogReader(name);
@override
DevicePortForwarder portForwarder = const NoOpDevicePortForwarder();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment