From 34d390808fce67061a42a7a67df11cd2e37408d9 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Mon, 11 Mar 2024 10:34:19 -0700 Subject: [PATCH] Fix --- .github/workflows/cupertino.yml | 2 +- .../example/integration_test/main.dart | 2 ++ .../web_socket_conformance_test.dart | 12 ++++++++++++ .../cupertino_http/lib/src/cupertino_web_socket.dart | 7 ++++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cupertino.yml b/.github/workflows/cupertino.yml index 9b470e1fea..1110e60e08 100644 --- a/.github/workflows/cupertino.yml +++ b/.github/workflows/cupertino.yml @@ -61,4 +61,4 @@ jobs: run: | cd example flutter pub get - flutter test --timeout=1200s integration_test/ + flutter test --timeout=1200s integration_test/main.dart diff --git a/pkgs/cupertino_http/example/integration_test/main.dart b/pkgs/cupertino_http/example/integration_test/main.dart index 12128b5b9a..0d4d5e16d9 100644 --- a/pkgs/cupertino_http/example/integration_test/main.dart +++ b/pkgs/cupertino_http/example/integration_test/main.dart @@ -19,6 +19,7 @@ import 'url_session_delegate_test.dart' as url_session_delegate_test; import 'url_session_task_test.dart' as url_session_task_test; import 'url_session_test.dart' as url_session_test; import 'utils_test.dart' as utils_test; +import 'web_socket_conformance_test.dart' as web_socket_conformance_test; /// Execute all the tests in this directory. /// @@ -43,4 +44,5 @@ void main() { url_session_task_test.main(); url_session_test.main(); utils_test.main(); + web_socket_conformance_test.main(); } diff --git a/pkgs/cupertino_http/example/integration_test/web_socket_conformance_test.dart b/pkgs/cupertino_http/example/integration_test/web_socket_conformance_test.dart index 68e5f80322..8dff3a2626 100644 --- a/pkgs/cupertino_http/example/integration_test/web_socket_conformance_test.dart +++ b/pkgs/cupertino_http/example/integration_test/web_socket_conformance_test.dart @@ -3,8 +3,20 @@ // BSD-style license that can be found in the LICENSE file. import 'package:cupertino_http/cupertino_http.dart'; +import 'package:test/test.dart'; import 'package:web_socket_conformance_tests/web_socket_conformance_tests.dart'; void main() { testAll(CupertinoWebSocket.connect); + + group('defaultSessionConfiguration', () { + testAll( + CupertinoWebSocket.connect, + ); + }); + group('fromSessionConfiguration', () { + final config = URLSessionConfiguration.ephemeralSessionConfiguration(); + testAll((uri, {protocols}) => + CupertinoWebSocket.connect(uri, protocols: protocols, config: config)); + }); } diff --git a/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart b/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart index dbd0195d4c..14fa40ed14 100644 --- a/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart +++ b/pkgs/cupertino_http/lib/src/cupertino_web_socket.dart @@ -20,7 +20,7 @@ class ConnectionException extends WebSocketException { String toString() => 'CupertinoErrorWebSocketException: $message $error'; } -/// A [WebSocket] using the +/// A [WebSocket] implemented using the /// [NSURLSessionWebSocketTask API](https://developer.apple.com/documentation/foundation/nsurlsessionwebsockettask). class CupertinoWebSocket implements WebSocket { /// Create a new WebSocket connection using the @@ -32,7 +32,8 @@ class CupertinoWebSocket implements WebSocket { /// the peer is able to select. See /// [RFC-6455 1.9](https://datatracker.ietf.org/doc/html/rfc6455#section-1.9). static Future connect(Uri url, - {Iterable? protocols}) async { + {Iterable? protocols, + URLSessionConfiguration? config}) async { if (!url.isScheme('ws') && !url.isScheme('wss')) { throw ArgumentError.value( url, 'url', 'only ws: and wss: schemes are supported'); @@ -42,7 +43,7 @@ class CupertinoWebSocket implements WebSocket { late CupertinoWebSocket webSocket; final session = URLSession.sessionWithConfiguration( - URLSessionConfiguration.defaultSessionConfiguration(), + config ?? URLSessionConfiguration.defaultSessionConfiguration(), onComplete: (session, task, error) { if (!readyCompleter.isCompleted) { if (error != null) {