@@ -838,6 +838,23 @@ void main() {
838838 chromeConnection.throwSocketExceptions = true ;
839839 await chrome.close ();
840840 });
841+
842+ test ('Chromium close handles a WebSocketException when closing the WipConnection' , () async {
843+ final BufferLogger logger = BufferLogger .test ();
844+ final FakeChromeConnectionWithTab chromeConnection = FakeChromeConnectionWithTab (throwWebSocketException: true );
845+ final ChromiumLauncher chromiumLauncher = ChromiumLauncher (
846+ fileSystem: fileSystem,
847+ platform: platform,
848+ processManager: processManager,
849+ operatingSystemUtils: operatingSystemUtils,
850+ browserFinder: findChromeExecutable,
851+ logger: logger,
852+ );
853+ final FakeProcess process = FakeProcess ();
854+ final Chromium chrome = Chromium (0 , chromeConnection, chromiumLauncher: chromiumLauncher, process: process, logger: logger);
855+ expect (await chromiumLauncher.connect (chrome, false ), equals (chrome));
856+ await chrome.close ();
857+ });
841858}
842859
843860/// Fake chrome connection that fails to get tabs a few times.
@@ -877,8 +894,8 @@ typedef OnSendCommand = void Function(String);
877894
878895/// Fake chrome connection that returns a tab.
879896class FakeChromeConnectionWithTab extends Fake implements ChromeConnection {
880- FakeChromeConnectionWithTab ({OnSendCommand ? onSendCommand})
881- : _tab = FakeChromeTab (onSendCommand);
897+ FakeChromeConnectionWithTab ({OnSendCommand ? onSendCommand, bool throwWebSocketException = false })
898+ : _tab = FakeChromeTab (onSendCommand, throwWebSocketException );
882899
883900 final FakeChromeTab _tab;
884901 bool throwSocketExceptions = false ;
@@ -904,20 +921,22 @@ class FakeChromeConnectionWithTab extends Fake implements ChromeConnection {
904921}
905922
906923class FakeChromeTab extends Fake implements ChromeTab {
907- FakeChromeTab (this .onSendCommand);
924+ FakeChromeTab (this .onSendCommand, this .throwWebSocketException );
908925
909- OnSendCommand ? onSendCommand;
926+ final OnSendCommand ? onSendCommand;
927+ final bool throwWebSocketException;
910928
911929 @override
912930 Future <WipConnection > connect ({Function ? onError}) async {
913- return FakeWipConnection (onSendCommand);
931+ return FakeWipConnection (onSendCommand, throwWebSocketException );
914932 }
915933}
916934
917935class FakeWipConnection extends Fake implements WipConnection {
918- FakeWipConnection (this .onSendCommand);
936+ FakeWipConnection (this .onSendCommand, this .throwWebSocketException );
919937
920- OnSendCommand ? onSendCommand;
938+ final OnSendCommand ? onSendCommand;
939+ final bool throwWebSocketException;
921940
922941 @override
923942 Future <WipResponse > sendCommand (String method, [Map <String , dynamic >? params]) async {
@@ -926,5 +945,9 @@ class FakeWipConnection extends Fake implements WipConnection {
926945 }
927946
928947 @override
929- Future <void > close () async {}
948+ Future <void > close () async {
949+ if (throwWebSocketException) {
950+ throw const io.WebSocketException ('test' );
951+ }
952+ }
930953}
0 commit comments