diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
commit | fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch) | |
tree | 4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /testing/web-platform/tests/websockets/stream | |
parent | Releasing progress-linux version 124.0.1-1~progress7.99u1. (diff) | |
download | firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/websockets/stream')
-rw-r--r-- | testing/web-platform/tests/websockets/stream/tentative/close.any.js | 10 | ||||
-rw-r--r-- | testing/web-platform/tests/websockets/stream/tentative/remote-close.any.js | 74 |
2 files changed, 84 insertions, 0 deletions
diff --git a/testing/web-platform/tests/websockets/stream/tentative/close.any.js b/testing/web-platform/tests/websockets/stream/tentative/close.any.js index 098caf31c8..ad41dc6e2e 100644 --- a/testing/web-platform/tests/websockets/stream/tentative/close.any.js +++ b/testing/web-platform/tests/websockets/stream/tentative/close.any.js @@ -1,6 +1,7 @@ // META: script=../../constants.sub.js // META: script=resources/url-constants.js // META: global=window,worker +// META: variant=?default // META: variant=?wss // META: variant=?wpt_flags=h2 @@ -108,6 +109,15 @@ promise_test(async () => { 'one second should have elapsed'); }, 'writer close() promise should not resolve until handshake completes'); +promise_test(async t => { + const wss = new WebSocketStream(`${BASEURL}/passive-close-abort`); + await wss.opened; + wss.close({closeCode: 4000, reason: 'because'}); + const error = await wss.closed.then(t.unreached_func('closed should reject'), e => e); + assert_equals(error.constructor, WebSocketError, 'error should be WebSocketError'); + assert_equals(error.closeCode, 1006, 'close code should be Abnormal Closure'); +}, 'incomplete closing handshake should be considered unclean close'); + const abortOrCancel = [ { method: 'abort', diff --git a/testing/web-platform/tests/websockets/stream/tentative/remote-close.any.js b/testing/web-platform/tests/websockets/stream/tentative/remote-close.any.js new file mode 100644 index 0000000000..b7fd321914 --- /dev/null +++ b/testing/web-platform/tests/websockets/stream/tentative/remote-close.any.js @@ -0,0 +1,74 @@ +// META: script=../../constants.sub.js +// META: script=resources/url-constants.js +// META: global=window,worker +// META: variant=?default +// META: variant=?wss +// META: variant=?wpt_flags=h2 + +'use strict'; + +promise_test(async t => { + const wss = new WebSocketStream(`${BASEURL}/remote-close?code=1000`); + const { readable, writable } = await wss.opened; + const { closeCode, reason } = await wss.closed; + assert_equals(closeCode, 1000, 'code should be 1000'); + assert_equals(reason, '', 'reason should be empty'); + const { value, done } = await readable.getReader().read(); + assert_true(done, 'readable should be closed'); + await promise_rejects_dom(t, 'InvalidStateError', writable.getWriter().ready, + 'writable should be errored'); +}, 'clean close should be clean'); + +promise_test(async () => { + const wss = new WebSocketStream(`${BASEURL}/remote-close`); + const { closeCode, reason } = await wss.closed; + assert_equals(closeCode, 1005, 'code should be No Status Rcvd'); + assert_equals(reason, '', 'reason should be empty'); +}, 'close frame with no body should result in status code 1005'); + +promise_test(async () => { + const wss = new WebSocketStream(`${BASEURL}/remote-close?code=4000&reason=robot`); + const { closeCode, reason } = await wss.closed; + assert_equals(closeCode, 4000, 'code should be 4000'); + assert_equals(reason, 'robot', 'reason should be set'); +}, 'reason should be passed through'); + +promise_test(async () => { + const wss = new WebSocketStream(`${BASEURL}/remote-close?code=4000&` + + 'reason=%E3%83%AD%E3%83%9C%E3%83%83%E3%83%88'); + const { reason } = await wss.closed; + assert_equals(reason, 'ロボット', 'reason should be set'); +}, 'UTF-8 reason should work'); + +promise_test(async t => { + const wss = new WebSocketStream(`${BASEURL}/remote-close?code=4567`); + const { writable } = await wss.opened; + const veryLargeMessage = new Uint8Array(20 * 1024 * 1024); // 20MB. + const writePromise = writable.getWriter().write(veryLargeMessage); + const closedError = await wss.closed.then(t.unreached_func('closed should reject'), e => e); + assert_equals(closedError.constructor, WebSocketError, 'error should be WebSocketError'); + assert_equals(closedError.closeCode, 4567, 'closeCode should be set'); + promise_rejects_js(t, WebSocketError, writePromise, 'write() should reject'); +}, 'close with unwritten data should not be considered clean'); + +promise_test(async t => { + const wss = new WebSocketStream(`${BASEURL}/remote-close?code=4222&reason=remote`); + await wss.opened; + wss.close({closeCode: 4111, reason: 'local'}); + const { closeCode, reason } = await wss.closed; + assert_equals(closeCode, 4222, 'remote code should be used'); + assert_equals(reason, 'remote', 'remote reason should be used'); +}, 'remote code and reason should be used'); + +promise_test(async t => { + const wss = new WebSocketStream(`${BASEURL}/remote-close?abrupt=1`); + const { readable, writable } = await wss.opened; + const closedError = await wss.closed.then(t.unreached_func('closed should reject'), e => e); + assert_equals(closedError.constructor, WebSocketError, 'error should be a WebSocketError'); + assert_equals(closedError.name, 'WebSocketError', 'error name should be WebSocketError'); + assert_equals(closedError.closeCode, 1006, 'code should be Abnormal Closure'); + await promise_rejects_exactly(t, closedError, readable.getReader().read(), + 'readable should be errored with the same object'); + await promise_rejects_exactly(t, closedError, writable.getWriter().ready, + 'writable should be errored with the same object'); +}, 'abrupt close should give an error'); |