summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webtransport/constructor.https.any.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/webtransport/constructor.https.any.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webtransport/constructor.https.any.js')
-rw-r--r--testing/web-platform/tests/webtransport/constructor.https.any.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webtransport/constructor.https.any.js b/testing/web-platform/tests/webtransport/constructor.https.any.js
new file mode 100644
index 0000000000..0f39c4993b
--- /dev/null
+++ b/testing/web-platform/tests/webtransport/constructor.https.any.js
@@ -0,0 +1,57 @@
+// META: global=window,worker
+// META: script=/common/get-host-info.sub.js
+// META: script=resources/webtransport-test-helpers.sub.js
+// META: script=/common/utils.js
+
+const BAD_URLS = [
+ null,
+ '',
+ 'no-scheme',
+ 'http://example.com/' /* scheme is wrong */,
+ 'quic-transport://example.com/' /* scheme is wrong */,
+ 'https:///' /* no host specified */,
+ 'https://example.com/#failing' /* has fragment */,
+ `https://${HOST}:999999/` /* invalid port */,
+];
+
+for (const url of BAD_URLS) {
+ test(() => {
+ assert_throws_dom('SyntaxError', () => new WebTransport(url),
+ 'constructor should throw');
+ }, `WebTransport constructor should reject URL '${url}'`);
+}
+
+const OPTIONS = [
+ { allowPooling: true },
+ { requireUnreliable: true },
+ { allowPooling: true, requireUnreliable: true },
+ { congestionControl: "default" },
+ { congestionControl: "throughput" },
+ { congestionControl: "low-latency" },
+ { allowPooling: true, requireUnreliable: true, congestionControl: "low-latency" },
+ // XXX Need to test serverCertificateHashes
+];
+
+for (const options of OPTIONS) {
+ promise_test(async t => {
+ const id = token();
+ const wt = new WebTransport(webtransport_url(`client-close.py?token=${id}`), options );
+ await wt.ready;
+ wt.close();
+ }, "WebTransport constructor should allow options " + JSON.stringify(options));
+}
+
+promise_test(async t => {
+ const wt = new WebTransport(`https://${HOST}:0/`);
+
+ // Sadly we cannot use promise_rejects_dom as the error constructor is
+ // WebTransportError rather than DOMException.
+ // We get a possible error, and then make sure wt.ready is rejected with it.
+ const e = await wt.ready.catch(e => e);
+
+ await promise_rejects_exactly(t, e, wt.ready, 'ready should be rejected');
+ await promise_rejects_exactly(t, e, wt.closed, 'closed should be rejected');
+ assert_true(e instanceof WebTransportError);
+ assert_equals(e.source, 'session', 'source');
+ assert_equals(e.streamErrorCode, null, 'streamErrorCode');
+}, 'Connection to port 0 should fail');