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 3e1c7005eb..4fdbbc6bbf 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 @@ -67,24 +67,32 @@ void testWebSocketTask() { session.finishTasksAndInvalidate(); }); - test('client code and reason', () async { - final session = URLSession.sharedSession(); - final task = session.webSocketTaskWithRequest( - URLRequest.fromUrl(Uri.parse('ws://localhost:${server.port}/?noclose')), - )..resume(); - await task.sendMessage( - URLSessionWebSocketMessage.fromString('Hello World!'), - ); - await task.receiveMessage(); - task.cancelWithCloseCode(4998, 'Bye'.codeUnits.toNSData()); - - // Allow the server to run and save the close code. - while (lastCloseCode == null) { - await Future.delayed(const Duration(milliseconds: 10)); - } - expect(lastCloseCode, 4998); - expect(lastCloseReason, 'Bye'); - }); + test( + 'client code and reason', + () async { + final session = URLSession.sharedSession(); + final task = session.webSocketTaskWithRequest( + URLRequest.fromUrl( + Uri.parse('ws://localhost:${server.port}/?noclose'), + ), + )..resume(); + await task.sendMessage( + URLSessionWebSocketMessage.fromString('Hello World!'), + ); + await task.receiveMessage(); + task.cancelWithCloseCode(4998, 'Bye'.codeUnits.toNSData()); + + // Allow the server to run and save the close code. + while (lastCloseCode == null) { + await Future.delayed(const Duration(milliseconds: 10)); + } + expect(lastCloseCode, 4998); + expect(lastCloseReason, 'Bye'); + }, + skip: Platform.isMacOS + ? 'https://github.com/dart-lang/http/issues/1814' + : false, + ); test('server code and reason', () async { final session = URLSession.sharedSession(); 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 28059e2257..fc3315def9 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 @@ -2,19 +2,39 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:io'; + import 'package:cupertino_http/cupertino_http.dart'; import 'package:test/test.dart'; +import 'package:web_socket/web_socket.dart'; import 'package:web_socket_conformance_tests/web_socket_conformance_tests.dart'; -void main() { - testAll(CupertinoWebSocket.connect); +void runTests( + Future Function(Uri uri, {Iterable? protocols}) + webSocketFactory, +) { + if (Platform.isMacOS) { + // TODO(https://github.com/dart-lang/http/issues/1814): Fix web socket tests + // on macOS. + testCloseRemote(webSocketFactory); + testConnectUri(webSocketFactory); + testDisconnectAfterUpgrade(webSocketFactory); + testNoUpgrade(webSocketFactory); + testPayloadTransfer(webSocketFactory); + testPeerProtocolErrors(webSocketFactory); + testProtocols(webSocketFactory); + } else { + testAll(webSocketFactory); + } +} +void main() { group('defaultSessionConfiguration', () { - testAll(CupertinoWebSocket.connect); + runTests(CupertinoWebSocket.connect); }); group('fromSessionConfiguration', () { final config = URLSessionConfiguration.ephemeralSessionConfiguration(); - testAll( + runTests( (uri, {protocols}) => CupertinoWebSocket.connect(uri, protocols: protocols, config: config), ); diff --git a/pkgs/cupertino_http/example/pubspec.yaml b/pkgs/cupertino_http/example/pubspec.yaml index cdf54da738..c54e37422e 100644 --- a/pkgs/cupertino_http/example/pubspec.yaml +++ b/pkgs/cupertino_http/example/pubspec.yaml @@ -33,6 +33,7 @@ dev_dependencies: sdk: flutter objective_c: ^8.1.0 test: ^1.21.1 + web_socket: '^1.0.0' web_socket_conformance_tests: path: ../../web_socket_conformance_tests/ diff --git a/pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart b/pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart index 9e6e011628..a43a3d8c56 100644 --- a/pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart +++ b/pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart @@ -12,6 +12,15 @@ import 'src/payload_transfer_tests.dart'; import 'src/peer_protocol_errors_tests.dart'; import 'src/protocol_tests.dart'; +export 'src/close_local_tests.dart'; +export 'src/close_remote_tests.dart'; +export 'src/connect_uri_tests.dart'; +export 'src/disconnect_after_upgrade_tests.dart'; +export 'src/no_upgrade_tests.dart'; +export 'src/payload_transfer_tests.dart'; +export 'src/peer_protocol_errors_tests.dart'; +export 'src/protocol_tests.dart'; + /// Runs the entire test suite against the given [WebSocket]. void testAll( Future Function(Uri uri, {Iterable? protocols})