summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-11-01 15:11:01 -0600
committerGitHub <noreply@github.com>2023-11-01 21:11:01 +0000
commit42c426e7695a0037032d1ac5237830800eeaaed4 (patch)
tree242f9aa30187464f1b6314387654a76d8dc76fc0 /cli/tests
parent587f2e0800a55e58b2579758d4278a4129b609c0 (diff)
feat(ext/websocket): websockets over http2 (#21040)
Implements `WebSocket` over http/2. This requires a conformant http/2 server supporting the extended connect protocol. Passes approximately 100 new WPT tests (mostly `?wpt_flags=h2` versions of existing websockets APIs). This is implemented as a fallback when http/1.1 fails, so a server that supports both h1 and h2 WebSockets will still end up on the http/1.1 upgrade path. The patch also cleas up the websockets handshake to split it up into http, https+http1 and https+http2, making it a little less intertwined. This uncovered a likely bug in the WPT test server: https://github.com/web-platform-tests/wpt/issues/42896
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/testdata/run/websocket_test.ts2
-rw-r--r--cli/tests/unit/websocket_test.ts54
2 files changed, 51 insertions, 5 deletions
diff --git a/cli/tests/testdata/run/websocket_test.ts b/cli/tests/testdata/run/websocket_test.ts
index 43db15cce..b759d042d 100644
--- a/cli/tests/testdata/run/websocket_test.ts
+++ b/cli/tests/testdata/run/websocket_test.ts
@@ -163,7 +163,7 @@ Deno.test("websocket error", async () => {
// Error message got changed because we don't use warp in test_util
assertEquals(
err.message,
- "InvalidData: invalid data",
+ "NetworkError: failed to connect to WebSocket: invalid data",
);
promise1.resolve();
};
diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts
index 8ae729d42..697f524d0 100644
--- a/cli/tests/unit/websocket_test.ts
+++ b/cli/tests/unit/websocket_test.ts
@@ -29,6 +29,50 @@ Deno.test(async function websocketConstructorTakeURLObjectAsParameter() {
await promise;
});
+Deno.test(async function websocketH2SendSmallPacket() {
+ const promise = deferred();
+ const ws = new WebSocket(new URL("wss://localhost:4248/"));
+ assertEquals(ws.url, "wss://localhost:4248/");
+ let messageCount = 0;
+ ws.onerror = (e) => promise.reject(e);
+ ws.onopen = () => {
+ ws.send("a".repeat(16));
+ ws.send("a".repeat(16));
+ ws.send("a".repeat(16));
+ };
+ ws.onmessage = () => {
+ if (++messageCount == 3) {
+ ws.close();
+ }
+ };
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await promise;
+});
+
+Deno.test(async function websocketH2SendLargePacket() {
+ const promise = deferred();
+ const ws = new WebSocket(new URL("wss://localhost:4248/"));
+ assertEquals(ws.url, "wss://localhost:4248/");
+ let messageCount = 0;
+ ws.onerror = (e) => promise.reject(e);
+ ws.onopen = () => {
+ ws.send("a".repeat(65000));
+ ws.send("a".repeat(65000));
+ ws.send("a".repeat(65000));
+ };
+ ws.onmessage = () => {
+ if (++messageCount == 3) {
+ ws.close();
+ }
+ };
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await promise;
+});
+
Deno.test(async function websocketSendLargePacket() {
const promise = deferred();
const ws = new WebSocket(new URL("wss://localhost:4243/"));
@@ -49,13 +93,14 @@ Deno.test(async function websocketSendLargePacket() {
Deno.test(async function websocketSendLargeBinaryPacket() {
const promise = deferred();
const ws = new WebSocket(new URL("wss://localhost:4243/"));
+ ws.binaryType = "arraybuffer";
assertEquals(ws.url, "wss://localhost:4243/");
ws.onerror = (e) => promise.reject(e);
ws.onopen = () => {
ws.send(new Uint8Array(65000));
};
- ws.onmessage = (msg) => {
- console.log(msg);
+ ws.onmessage = (msg: MessageEvent) => {
+ assertEquals(msg.data.byteLength, 65000);
ws.close();
};
ws.onclose = () => {
@@ -67,13 +112,14 @@ Deno.test(async function websocketSendLargeBinaryPacket() {
Deno.test(async function websocketSendLargeBlobPacket() {
const promise = deferred();
const ws = new WebSocket(new URL("wss://localhost:4243/"));
+ ws.binaryType = "arraybuffer";
assertEquals(ws.url, "wss://localhost:4243/");
ws.onerror = (e) => promise.reject(e);
ws.onopen = () => {
ws.send(new Blob(["a".repeat(65000)]));
};
- ws.onmessage = (msg) => {
- console.log(msg);
+ ws.onmessage = (msg: MessageEvent) => {
+ assertEquals(msg.data.byteLength, 65000);
ws.close();
};
ws.onclose = () => {