1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 registerCleanupFunction(async () => {
13 add_task(async
function pre_setup() {
14 let h2Port
= Services
.env
.get("MOZHTTP2_PORT");
15 Assert
.notEqual(h2Port
, null);
16 Assert
.notEqual(h2Port
, "");
18 wssUri
= "wss://foo.example.com:" + h2Port
+ "/websocket";
19 httpsUri
= "https://foo.example.com:" + h2Port
+ "/";
20 Services
.prefs
.setBoolPref("network.http.http3.support_version1", true);
23 add_task(async
function setup() {
24 await
http3_setup_tests("h3", true);
27 WebSocketListener
.prototype = {
29 onBinaryMessageAvailable() {},
30 onMessageAvailable() {},
38 function makeH2Chan() {
39 let chan
= NetUtil
.newChannel({
41 loadUsingSystemPrincipal
: true,
42 }).QueryInterface(Ci
.nsIHttpChannel
);
43 chan
.loadFlags
= Ci
.nsIChannel
.LOAD_INITIAL_DOCUMENT_URI
;
47 add_task(async
function open_wss_when_h3_is_active() {
48 // Make an active connection using HTTP/3
49 let chanHttp1
= makeH2Chan(httpsUri
);
50 await
new Promise(resolve
=> {
52 new ChannelListener(request
=> {
55 httpVersion
= request
.protocolVersion
;
57 Assert
.equal(httpVersion
, "h3");
63 // Now try to connect ot a WebSocket on the same port -> this should not loop
65 let chan
= Cc
["@mozilla.org/network/protocol;1?name=wss"].createInstance(
66 Ci
.nsIWebSocketChannel
70 Services
.scriptSecurityManager
.getSystemPrincipal(),
71 null, // aTriggeringPrincipal
72 Ci
.nsILoadInfo
.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL
,
73 Ci
.nsIContentPolicy
.TYPE_WEBSOCKET
76 var uri
= Services
.io
.newURI(wssUri
);
77 var wsListener
= new WebSocketListener();
78 await
new Promise(resolve
=> {
79 wsListener
.finish
= resolve
;
80 chan
.asyncOpen(uri
, wssUri
, {}, 0, wsListener
, null);
83 // Try to use https protocol, it should sttill use HTTP/3
84 let chanHttp2
= makeH2Chan(httpsUri
);
85 await
new Promise(resolve
=> {
87 new ChannelListener(request
=> {
90 httpVersion
= request
.protocolVersion
;
92 Assert
.equal(httpVersion
, "h3");