From 6f236d655886a22142bcd33c4fc38cd02b3bcd7d Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 8 Jun 2023 13:01:04 -0700 Subject: [PATCH] Run common URLSessionTask tests on URLSessionWebSocketTask --- .../url_session_task_test.dart | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkgs/cupertino_http/example/integration_test/url_session_task_test.dart b/pkgs/cupertino_http/example/integration_test/url_session_task_test.dart index 35e411b84a..beb447abee 100644 --- a/pkgs/cupertino_http/example/integration_test/url_session_task_test.dart +++ b/pkgs/cupertino_http/example/integration_test/url_session_task_test.dart @@ -142,8 +142,9 @@ void testWebSocketTask() { }); } -void testURLSessionTask( - URLSessionTask Function(URLSession session, Uri url) f) { +void testURLSessionTaskCommon( + URLSessionTask Function(URLSession session, Uri url) f, + {bool suspendedAfterCancel = false}) { group('task states', () { late HttpServer server; late URLSessionTask task; @@ -177,7 +178,11 @@ void testURLSessionTask( test('cancel', () { task.cancel(); - expect(task.state, URLSessionTaskState.urlSessionTaskStateCanceling); + if (suspendedAfterCancel) { + expect(task.state, URLSessionTaskState.urlSessionTaskStateSuspended); + } else { + expect(task.state, URLSessionTaskState.urlSessionTaskStateCanceling); + } expect(task.response, null); task.toString(); // Just verify that there is no crash. }); @@ -356,14 +361,21 @@ void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); group('data task', () { - testURLSessionTask( + testURLSessionTaskCommon( (session, uri) => session.dataTaskWithRequest(URLRequest.fromUrl(uri))); }); group('download task', () { - testURLSessionTask((session, uri) => + testURLSessionTaskCommon((session, uri) => session.downloadTaskWithRequest(URLRequest.fromUrl(uri))); }); + group('websocket task', () { + testURLSessionTaskCommon( + (session, uri) => + session.webSocketTaskWithRequest(URLRequest.fromUrl(uri)), + suspendedAfterCancel: true); + }); + testWebSocketTask(); }