Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>.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<void>.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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocket> Function(Uri uri, {Iterable<String>? 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),
);
Expand Down
1 change: 1 addition & 0 deletions pkgs/cupertino_http/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocket> Function(Uri uri, {Iterable<String>? protocols})
Expand Down
Loading