Ensure Chrome is closed on tab close (#43586)

This commit is contained in:
Jonah Williams
2019-10-28 10:26:18 -07:00
committed by GitHub
parent c31cd0717c
commit d983c1d1ae
3 changed files with 29 additions and 1 deletions

View File

@@ -113,9 +113,18 @@ class ResidentWebRunner extends ResidentRunner {
await _stdOutSub?.cancel();
await _webFs?.stop();
await device.stopApp(null);
if (ChromeLauncher.hasChromeInstance) {
final Chrome chrome = await ChromeLauncher.connectedInstance;
await chrome.close();
}
_exited = true;
}
Future<void> _cleanupAndExit() async {
await _cleanup();
appFinished();
}
@override
void printHelp({bool details = true}) {
if (details) {
@@ -201,7 +210,7 @@ class ResidentWebRunner extends ResidentRunner {
);
if (supportsServiceProtocol) {
_connectionResult = await _webFs.connect(debuggingOptions);
unawaited(_connectionResult.debugConnection.onDone.whenComplete(() => exit(0)));
unawaited(_connectionResult.debugConnection.onDone.whenComplete(_cleanupAndExit));
}
if (statusActive) {
buildStatus.stop();

View File

@@ -69,6 +69,8 @@ String findChromeExecutable() {
class ChromeLauncher {
const ChromeLauncher();
static bool get hasChromeInstance => _currentCompleter.isCompleted;
static final Completer<Chrome> _currentCompleter = Completer<Chrome>();
/// Whether we can locate the chrome executable.

View File

@@ -532,6 +532,23 @@ void main() {
verifyNever(mockDebugConnection.close());
}));
test('cleans up Chrome if tab is closed', () => testbed.run(() async {
_setupMocks();
final Completer<void> onDone = Completer<void>();
when(mockDebugConnection.onDone).thenAnswer((Invocation invocation) {
return onDone.future;
});
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
final Future<int> result = residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
);
await connectionInfoCompleter.future;
onDone.complete();
await result;
verify(mockWebFs.stop()).called(1);
}));
test('Prints target and device name on run', () => testbed.run(() async {
_setupMocks();
when(mockWebDevice.name).thenReturn('Chromez');