Unverified Commit d983c1d1 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Ensure Chrome is closed on tab close (#43586)

parent c31cd071
...@@ -113,9 +113,18 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -113,9 +113,18 @@ class ResidentWebRunner extends ResidentRunner {
await _stdOutSub?.cancel(); await _stdOutSub?.cancel();
await _webFs?.stop(); await _webFs?.stop();
await device.stopApp(null); await device.stopApp(null);
if (ChromeLauncher.hasChromeInstance) {
final Chrome chrome = await ChromeLauncher.connectedInstance;
await chrome.close();
}
_exited = true; _exited = true;
} }
Future<void> _cleanupAndExit() async {
await _cleanup();
appFinished();
}
@override @override
void printHelp({bool details = true}) { void printHelp({bool details = true}) {
if (details) { if (details) {
...@@ -201,7 +210,7 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -201,7 +210,7 @@ class ResidentWebRunner extends ResidentRunner {
); );
if (supportsServiceProtocol) { if (supportsServiceProtocol) {
_connectionResult = await _webFs.connect(debuggingOptions); _connectionResult = await _webFs.connect(debuggingOptions);
unawaited(_connectionResult.debugConnection.onDone.whenComplete(() => exit(0))); unawaited(_connectionResult.debugConnection.onDone.whenComplete(_cleanupAndExit));
} }
if (statusActive) { if (statusActive) {
buildStatus.stop(); buildStatus.stop();
......
...@@ -69,6 +69,8 @@ String findChromeExecutable() { ...@@ -69,6 +69,8 @@ String findChromeExecutable() {
class ChromeLauncher { class ChromeLauncher {
const ChromeLauncher(); const ChromeLauncher();
static bool get hasChromeInstance => _currentCompleter.isCompleted;
static final Completer<Chrome> _currentCompleter = Completer<Chrome>(); static final Completer<Chrome> _currentCompleter = Completer<Chrome>();
/// Whether we can locate the chrome executable. /// Whether we can locate the chrome executable.
......
...@@ -532,6 +532,23 @@ void main() { ...@@ -532,6 +532,23 @@ void main() {
verifyNever(mockDebugConnection.close()); 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 { test('Prints target and device name on run', () => testbed.run(() async {
_setupMocks(); _setupMocks();
when(mockWebDevice.name).thenReturn('Chromez'); when(mockWebDevice.name).thenReturn('Chromez');
......
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