@@ -758,7 +758,7 @@ void main() {
758
758
expect (logger.errorText, contains ('SocketException' ));
759
759
});
760
760
761
- test ('can recover if getTabs throws a connection exception' , () async {
761
+ testWithoutContext ('can recover if getTabs throws a connection exception' , () async {
762
762
final BufferLogger logger = BufferLogger .test ();
763
763
final FakeChromeConnection chromeConnection = FakeChromeConnection (maxRetries: 4 );
764
764
final ChromiumLauncher chromiumLauncher = ChromiumLauncher (
@@ -775,11 +775,11 @@ void main() {
775
775
expect (logger.errorText, isEmpty);
776
776
});
777
777
778
- test ('can recover if getTabs throws an HttpException' , () async {
778
+ testWithoutContext ('can recover if getTabs throws an HttpException' , () async {
779
779
final BufferLogger logger = BufferLogger .test ();
780
780
final FakeChromeConnection chromeConnection = FakeChromeConnection (
781
781
maxRetries: 4 ,
782
- exception : io.HttpException (
782
+ error : io.HttpException (
783
783
'Connection closed before full header was received' ,
784
784
uri: Uri .parse ('http://localhost:52097/json' ),
785
785
),
@@ -798,7 +798,27 @@ void main() {
798
798
expect (logger.errorText, isEmpty);
799
799
});
800
800
801
- test ('exits if getTabs throws a connection exception consistently' , () async {
801
+ testWithoutContext ('chrome.close can recover if getTab throws a StateError' , () async {
802
+ final BufferLogger logger = BufferLogger .test ();
803
+ final FakeChromeConnection chromeConnection = FakeChromeConnection (
804
+ maxRetries: 4 ,
805
+ error: StateError ('Client is closed.' ),
806
+ );
807
+ final ChromiumLauncher chromiumLauncher = ChromiumLauncher (
808
+ fileSystem: fileSystem,
809
+ platform: platform,
810
+ processManager: processManager,
811
+ operatingSystemUtils: operatingSystemUtils,
812
+ browserFinder: findChromeExecutable,
813
+ logger: logger,
814
+ );
815
+ final FakeProcess process = FakeProcess ();
816
+ final Chromium chrome = Chromium (0 , chromeConnection, chromiumLauncher: chromiumLauncher, process: process, logger: logger,);
817
+ await chrome.close ();
818
+ expect (logger.errorText, isEmpty);
819
+ });
820
+
821
+ testWithoutContext ('exits if getTabs throws a connection exception consistently' , () async {
802
822
final BufferLogger logger = BufferLogger .test ();
803
823
final FakeChromeConnection chromeConnection = FakeChromeConnection ();
804
824
final ChromiumLauncher chromiumLauncher = ChromiumLauncher (
@@ -825,7 +845,7 @@ void main() {
825
845
));
826
846
});
827
847
828
- test ('Chromium close sends browser close command' , () async {
848
+ testWithoutContext ('Chromium close sends browser close command' , () async {
829
849
final BufferLogger logger = BufferLogger .test ();
830
850
final List <String > commands = < String > [];
831
851
void onSendCommand (String cmd) { commands.add (cmd); }
@@ -845,7 +865,7 @@ void main() {
845
865
expect (commands, contains ('Browser.close' ));
846
866
});
847
867
848
- test ('Chromium close handles a SocketException when connecting to Chrome' , () async {
868
+ testWithoutContext ('Chromium close handles a SocketException when connecting to Chrome' , () async {
849
869
final BufferLogger logger = BufferLogger .test ();
850
870
final FakeChromeConnectionWithTab chromeConnection = FakeChromeConnectionWithTab ();
851
871
final ChromiumLauncher chromiumLauncher = ChromiumLauncher (
@@ -863,7 +883,7 @@ void main() {
863
883
await chrome.close ();
864
884
});
865
885
866
- test ('Chromium close handles a WebSocketException when closing the WipConnection' , () async {
886
+ testWithoutContext ('Chromium close handles a WebSocketException when closing the WipConnection' , () async {
867
887
final BufferLogger logger = BufferLogger .test ();
868
888
final FakeChromeConnectionWithTab chromeConnection = FakeChromeConnectionWithTab (throwWebSocketException: true );
869
889
final ChromiumLauncher chromiumLauncher = ChromiumLauncher (
@@ -887,8 +907,8 @@ class FakeChromeConnection extends Fake implements ChromeConnection {
887
907
/// Create a connection that throws a connection exception on first
888
908
/// [maxRetries] calls to [getTabs] .
889
909
/// If [maxRetries] is `null` , [getTabs] calls never succeed.
890
- FakeChromeConnection ({this .maxRetries, Exception ? exception }) : _retries = 0 {
891
- this .exception = exception ??
910
+ FakeChromeConnection ({this .maxRetries, Object ? error }) : _retries = 0 {
911
+ this .error = error ??
892
912
ConnectionException (
893
913
formatException: const FormatException ('incorrect format' ),
894
914
responseStatus: 'OK,' ,
@@ -899,7 +919,7 @@ class FakeChromeConnection extends Fake implements ChromeConnection {
899
919
final List <ChromeTab > tabs = < ChromeTab > [];
900
920
final int ? maxRetries;
901
921
int _retries;
902
- late final Exception exception ;
922
+ late final Object error ;
903
923
904
924
@override
905
925
Future <ChromeTab ?> getTab (bool Function (ChromeTab tab) accept, {Duration ? retryFor}) async {
@@ -910,7 +930,8 @@ class FakeChromeConnection extends Fake implements ChromeConnection {
910
930
Future <List <ChromeTab >> getTabs ({Duration ? retryFor}) async {
911
931
_retries ++ ;
912
932
if (maxRetries == null || _retries < maxRetries! ) {
913
- throw exception;
933
+ // ignore: only_throw_errors -- This is fine for an ad-hoc test.
934
+ throw error;
914
935
}
915
936
return tabs;
916
937
}
0 commit comments