summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_http3_version1.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 /netwerk/test/unit/test_http3_version1.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_http3_version1.js')
-rw-r--r--netwerk/test/unit/test_http3_version1.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_http3_version1.js b/netwerk/test/unit/test_http3_version1.js
new file mode 100644
index 0000000000..65f4eef906
--- /dev/null
+++ b/netwerk/test/unit/test_http3_version1.js
@@ -0,0 +1,93 @@
+/* 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/. */
+"use strict";
+
+registerCleanupFunction(async () => {
+ http3_clear_prefs();
+});
+
+let httpsUri;
+
+add_task(async function pre_setup() {
+ let h2Port = Services.env.get("MOZHTTP2_PORT");
+ Assert.notEqual(h2Port, null);
+ Assert.notEqual(h2Port, "");
+ httpsUri = "https://foo.example.com:" + h2Port + "/";
+ Services.prefs.setBoolPref("network.http.http3.support_version1", true);
+});
+
+add_task(async function setup() {
+ await http3_setup_tests("h3");
+});
+
+function chanPromise(chan, listener) {
+ return new Promise(resolve => {
+ function finish() {
+ resolve();
+ }
+ listener.finish = finish;
+ chan.asyncOpen(listener);
+ });
+}
+
+function makeH2Chan() {
+ let chan = NetUtil.newChannel({
+ uri: httpsUri,
+ loadUsingSystemPrincipal: true,
+ }).QueryInterface(Ci.nsIHttpChannel);
+ chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
+ return chan;
+}
+
+let Http3Listener = function () {};
+
+Http3Listener.prototype = {
+ version1enabled: "",
+
+ onStartRequest: function testOnStartRequest(request) {},
+
+ onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
+ read_stream(stream, cnt);
+ },
+
+ onStopRequest: function testOnStopRequest(request, status) {
+ let httpVersion = "";
+ try {
+ httpVersion = request.protocolVersion;
+ } catch (e) {}
+ if (this.version1enabled) {
+ Assert.equal(httpVersion, "h3");
+ } else {
+ Assert.equal(httpVersion, "h2");
+ }
+
+ this.finish();
+ },
+};
+
+add_task(async function test_version1_enabled_1() {
+ Services.prefs.setBoolPref("network.http.http3.support_version1", true);
+ let listener = new Http3Listener();
+ listener.version1enabled = true;
+ let chan = makeH2Chan("https://foo.example.com/");
+ await chanPromise(chan, listener);
+});
+
+add_task(async function test_version1_disabled() {
+ Services.obs.notifyObservers(null, "net:cancel-all-connections");
+ Services.prefs.setBoolPref("network.http.http3.support_version1", false);
+ let listener = new Http3Listener();
+ listener.version1enabled = false;
+ let chan = makeH2Chan("https://foo.example.com/");
+ await chanPromise(chan, listener);
+});
+
+add_task(async function test_version1_enabled_2() {
+ Services.obs.notifyObservers(null, "net:cancel-all-connections");
+ Services.prefs.setBoolPref("network.http.http3.support_version1", true);
+ let listener = new Http3Listener();
+ listener.version1enabled = true;
+ let chan = makeH2Chan("https://foo.example.com/");
+ await chanPromise(chan, listener);
+});