diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /dom/webtransport/test | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webtransport/test')
-rw-r--r-- | dom/webtransport/test/moz.build | 9 | ||||
-rw-r--r-- | dom/webtransport/test/xpcshell/moz.build | 9 | ||||
-rw-r--r-- | dom/webtransport/test/xpcshell/test_close.js | 65 | ||||
-rw-r--r-- | dom/webtransport/test/xpcshell/test_simple_conn.js | 129 | ||||
-rw-r--r-- | dom/webtransport/test/xpcshell/test_simple_stream.js | 168 | ||||
-rw-r--r-- | dom/webtransport/test/xpcshell/xpcshell.ini | 29 |
6 files changed, 409 insertions, 0 deletions
diff --git a/dom/webtransport/test/moz.build b/dom/webtransport/test/moz.build new file mode 100644 index 0000000000..ddf7e1f9a9 --- /dev/null +++ b/dom/webtransport/test/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +TEST_DIRS += [ + "xpcshell", +] diff --git a/dom/webtransport/test/xpcshell/moz.build b/dom/webtransport/test/xpcshell/moz.build new file mode 100644 index 0000000000..3d85532034 --- /dev/null +++ b/dom/webtransport/test/xpcshell/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +XPCSHELL_TESTS_MANIFESTS += [ + "xpcshell.ini", +] diff --git a/dom/webtransport/test/xpcshell/test_close.js b/dom/webtransport/test/xpcshell/test_close.js new file mode 100644 index 0000000000..5c0aa0017c --- /dev/null +++ b/dom/webtransport/test/xpcshell/test_close.js @@ -0,0 +1,65 @@ +// +// Simple WebTransport test +// +// keep eslint happy until it knows about WebTransport +/* global WebTransport:false */ + +"use strict"; + +var h3Port; +var host; + +registerCleanupFunction(async () => { + Services.prefs.clearUserPref("network.dns.localDomains"); +}); + +var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); + +function readFile(file) { + let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance( + Ci.nsIFileInputStream + ); + fstream.init(file, -1, 0, 0); + let data = NetUtil.readInputStreamToString(fstream, fstream.available()); + fstream.close(); + return data; +} + +function addCertFromFile(certdb, filename, trustString) { + let certFile = do_get_file(filename, false); + let pem = readFile(certFile) + .replace(/-----BEGIN CERTIFICATE-----/, "") + .replace(/-----END CERTIFICATE-----/, "") + .replace(/[\r\n]/g, ""); + certdb.addCertFromBase64(pem, trustString); +} + +add_task(async function setup() { + Services.prefs.setCharPref("network.dns.localDomains", "foo.example.com"); + + h3Port = Services.env.get("MOZHTTP3_PORT"); + Assert.notEqual(h3Port, null); + Assert.notEqual(h3Port, ""); + host = "foo.example.com:" + h3Port; + do_get_profile(); + + let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + // `../unit/` so that unit_ipc tests can use as well + addCertFromFile( + certdb, + "../../../../netwerk/test/unit/http2-ca.pem", + "CTu,u,u" + ); +}); + +add_task(async function test_webtransport_create() { + Services.prefs.setBoolPref("network.webtransport.enabled", true); + + const wt = new WebTransport("https://" + host + "/success"); + await wt.ready; + dump("**** ready\n"); + + wt.close(); +}); diff --git a/dom/webtransport/test/xpcshell/test_simple_conn.js b/dom/webtransport/test/xpcshell/test_simple_conn.js new file mode 100644 index 0000000000..e5711c0baf --- /dev/null +++ b/dom/webtransport/test/xpcshell/test_simple_conn.js @@ -0,0 +1,129 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Some basic WebTransport tests for: +// * session rejection and redirection +// * session and stream creation +// * reading from incoming streams (uni) +// +// keep eslint happy until it knows about WebTransport +/* global WebTransport:false */ + +"use strict"; + +var h3Port; +var host; + +registerCleanupFunction(async () => { + Services.prefs.clearUserPref("network.dns.localDomains"); + Services.prefs.clearUserPref("network.webtransport.enabled"); + Services.prefs.clearUserPref("network.webtransport.datagrams.enabled"); + Services.prefs.clearUserPref("network.webtransport.redirect.enabled"); +}); + +var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); + +function readFile(file) { + let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance( + Ci.nsIFileInputStream + ); + fstream.init(file, -1, 0, 0); + let data = NetUtil.readInputStreamToString(fstream, fstream.available()); + fstream.close(); + return data; +} + +function addCertFromFile(certdb, filename, trustString) { + let certFile = do_get_file(filename, false); + let pem = readFile(certFile) + .replace(/-----BEGIN CERTIFICATE-----/, "") + .replace(/-----END CERTIFICATE-----/, "") + .replace(/[\r\n]/g, ""); + certdb.addCertFromBase64(pem, trustString); +} + +add_setup(async function setup() { + Services.prefs.setCharPref("network.dns.localDomains", "foo.example.com"); + Services.prefs.setBoolPref("network.webtransport.enabled", true); + Services.prefs.setBoolPref("network.webtransport.datagrams.enabled", true); + Services.prefs.setBoolPref("network.webtransport.redirect.enabled", true); + + h3Port = Services.env.get("MOZHTTP3_PORT"); + Assert.notEqual(h3Port, null); + Assert.notEqual(h3Port, ""); + host = "foo.example.com:" + h3Port; + do_get_profile(); + + let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + // `../unit/` so that unit_ipc tests can use as well + addCertFromFile( + certdb, + "../../../../netwerk/test/unit/http2-ca.pem", + "CTu,u,u" + ); +}); + +add_task(async function test_webtransport_create() { + const wt = new WebTransport("https://" + host + "/success"); + await wt.ready; + wt.close(); +}); + +add_task(async function test_redirect_wt() { + let wt = new WebTransport("https://" + host + "/redirect"); + const e1 = await wt.ready.catch(e => e); + const e2 = await wt.closed.catch(e => e); + + Assert.equal(e1, "WebTransportError: WebTransport connection rejected"); + Assert.equal(e2, "WebTransportError: WebTransport connection rejected"); +}); + +add_task(async function test_reject_wt() { + let wt = new WebTransport("https://" + host + "/reject"); + const e1 = await wt.ready.catch(e => e); + const e2 = await wt.closed.catch(e => e); + Assert.equal(e1, "WebTransportError: WebTransport connection rejected"); + Assert.equal(e2, "WebTransportError: WebTransport connection rejected"); +}); + +add_task(async function test_immediate_server_close() { + let wt = new WebTransport("https://" + host + "/closeafter0ms"); + await wt.ready; + await wt.closed; + Assert.ok(true); +}); + +add_task(async function test_delayed_server_close() { + let wt = new WebTransport("https://" + host + "/closeafter100ms"); + await wt.ready; + await wt.closed; + Assert.ok(true); +}); + +add_task(async function test_wt_stream_create_bidi() { + let wt = new WebTransport("https://" + host + "/success"); + await wt.ready; + + let bds = await wt.createBidirectionalStream(); + await bds.writable.close(); + await bds.readable.cancel(); + Assert.notEqual(bds, null); + wt.close(); +}); + +add_task(async function test_wt_stream_create_uni() { + let wt = new WebTransport("https://" + host + "/success"); + await wt.ready; + + let uds = await wt.createUnidirectionalStream(); + Assert.notEqual(uds, null); + await uds.close(); + wt.close(); +}); + +// TODO: datagram test +// TODO: getStats tests +// TODO: fix the crash discussed in bug 1822154 diff --git a/dom/webtransport/test/xpcshell/test_simple_stream.js b/dom/webtransport/test/xpcshell/test_simple_stream.js new file mode 100644 index 0000000000..4efbfe2539 --- /dev/null +++ b/dom/webtransport/test/xpcshell/test_simple_stream.js @@ -0,0 +1,168 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// keep eslint happy until it knows about WebTransport +/* global WebTransport:false */ +/* global TextDecoderStream:false */ + +// Using multiple files to reduce racing +// This file tests reading/writing to incoming/outgoing streams (uni & bidi) +// +"use strict"; + +var h3Port; +var host; + +registerCleanupFunction(async () => { + Services.prefs.clearUserPref("network.dns.localDomains"); + Services.prefs.clearUserPref("network.webtransport.enabled"); + Services.prefs.clearUserPref("network.webtransport.datagrams.enabled"); + Services.prefs.clearUserPref("network.webtransport.redirect.enabled"); +}); + +var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); + +function readFile(file) { + let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance( + Ci.nsIFileInputStream + ); + fstream.init(file, -1, 0, 0); + let data = NetUtil.readInputStreamToString(fstream, fstream.available()); + fstream.close(); + return data; +} + +function addCertFromFile(certdb, filename, trustString) { + let certFile = do_get_file(filename, false); + let pem = readFile(certFile) + .replace(/-----BEGIN CERTIFICATE-----/, "") + .replace(/-----END CERTIFICATE-----/, "") + .replace(/[\r\n]/g, ""); + certdb.addCertFromBase64(pem, trustString); +} + +add_setup(async function setup() { + Services.prefs.setCharPref("network.dns.localDomains", "foo.example.com"); + Services.prefs.setBoolPref("network.webtransport.enabled", true); + Services.prefs.setBoolPref("network.webtransport.datagrams.enabled", true); + Services.prefs.setBoolPref("network.webtransport.redirect.enabled", true); + + h3Port = Services.env.get("MOZHTTP3_PORT"); + Assert.notEqual(h3Port, null); + Assert.notEqual(h3Port, ""); + host = "foo.example.com:" + h3Port; + do_get_profile(); + + let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + // `../unit/` so that unit_ipc tests can use as well + addCertFromFile( + certdb, + "../../../../netwerk/test/unit/http2-ca.pem", + "CTu,u,u" + ); +}); + +// Read all chunks from |readable_stream|, decode chunks to a utf-8 string, then +// return the string. (borrowed from wpt tests) +async function read_stream_as_string(readable_stream) { + const decoder = new TextDecoderStream(); + const decode_stream = readable_stream.pipeThrough(decoder); + const reader = decode_stream.getReader(); + + let chunks = ""; + while (true) { + const { value: chunk, done } = await reader.read(); + if (done) { + break; + } + chunks += chunk; + } + reader.releaseLock(); + return chunks; +} + +add_task(async function test_wt_incoming_unidi_stream() { + // trigger stream creation server side and default echo + let wt = new WebTransport( + "https://" + host + "/create_unidi_stream_and_hello" + ); + await wt.ready; + + const streams = await wt.incomingUnidirectionalStreams; + const stream_reader = streams.getReader(); + const { value: recv_stream } = await stream_reader.read(); + let str = await read_stream_as_string(recv_stream); + stream_reader.releaseLock(); + Assert.equal(str, "qwerty"); + + wt.close(); +}); + +add_task(async function test_wt_incoming_and_outgoing_unidi_stream() { + // create the client's incoming stream from the server side + // we need it to listen to the echo back + let wt = new WebTransport("https://" + host + "/create_unidi_stream"); + await wt.ready; + + // send hello to server + let expected = "uni_hello"; + let writableStream = await wt.createUnidirectionalStream(); // only triggers NewStream OnWrite + let wsDefaultWriter = writableStream.getWriter(); + await wsDefaultWriter.ready; + let data = new TextEncoder().encode(expected); + await wsDefaultWriter.write(data); // triggers Http3ServerEvent::Data + await wsDefaultWriter.close(); + wsDefaultWriter.releaseLock(); + + // read the echo + const streams = await wt.incomingUnidirectionalStreams; + const stream_reader = streams.getReader(); + const { value: recv_stream } = await stream_reader.read(); + let str = await read_stream_as_string(recv_stream); + Assert.equal(str, expected); + stream_reader.releaseLock(); + await recv_stream.closed; + + wt.close(); +}); + +add_task(async function test_wt_outgoing_bidi_stream() { + let wt = new WebTransport("https://" + host + "/success"); + await wt.ready; + + // write to server + let wtbds = await wt.createBidirectionalStream(); + let writableStream = wtbds.writable; + let wsDefaultWriter = writableStream.getWriter(); + await wsDefaultWriter.ready; + let expected = "xyzhello"; + let data = new TextEncoder().encode(expected); + await wsDefaultWriter.write(data); + await wsDefaultWriter.close(); + wsDefaultWriter.releaseLock(); + + // string goes through server and is echoed back here + const str = await read_stream_as_string(wtbds.readable); + Assert.equal(str, expected); + + wt.close(); +}); + +add_task(async function test_wt_incoming_bidi_stream() { + let wt = new WebTransport( + "https://" + host + "/create_bidi_stream_and_hello" + ); + // await wt.ready; // causes occasional hang on release --verify + + const stream_reader = wt.incomingBidirectionalStreams.getReader(); + const { value: bidi_stream } = await stream_reader.read(); + stream_reader.releaseLock(); + + const str = await read_stream_as_string(bidi_stream.readable); + Assert.equal(str, "asdfg"); + + wt.close(); +}); diff --git a/dom/webtransport/test/xpcshell/xpcshell.ini b/dom/webtransport/test/xpcshell/xpcshell.ini new file mode 100644 index 0000000000..97fe9a39e4 --- /dev/null +++ b/dom/webtransport/test/xpcshell/xpcshell.ini @@ -0,0 +1,29 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +[DEFAULT] + +# XXX figure out why android doesn't get MOZHTTP3_PORT +[test_close.js] +skip-if = + os == 'android' || socketprocess_networking + os == 'win' && msix # https://bugzilla.mozilla.org/show_bug.cgi?id=1807925 +[test_simple_conn.js] +skip-if = + (!fission && debug) + (verify && tsan) + (verify && debug) + os == 'android' + socketprocess_networking + os == 'win' && msix # https://bugzilla.mozilla.org/show_bug.cgi?id=1807925 +run-sequentially = http3server +[test_simple_stream.js] +skip-if = + (!fission && debug) + (verify && tsan) + (verify && debug) + os == 'android' + socketprocess_networking + os == 'win' && msix # https://bugzilla.mozilla.org/show_bug.cgi?id=1807925 +run-sequentially = http3server |