From ba7eb6023c89ffc5cbfe15a6cba2f8006e6f6dac Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Fri, 9 Jun 2023 08:30:29 -0700 Subject: [PATCH] Run common URLSessionTask tests on URLSessionWebSocketTask (#959) --- .../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 c15f1a86d2..8ea2d86828 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 @@ -151,8 +151,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; @@ -186,7 +187,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. }); @@ -365,14 +370,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(); }