Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_prio_header_override_forbid.js
blob9889f5725157f71d694052a4d1a250ddb2867f18
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/. */
5 add_setup(() => {
6 Services.prefs.setBoolPref("network.http.priority_header.enabled", true);
7 });
9 registerCleanupFunction(() => {
10 Services.prefs.clearUserPref("network.http.priority_header.enabled");
11 });
13 function channelOpenPromise(chan, flags) {
14 return new Promise(resolve => {
15 function finish(req, buffer) {
16 resolve([req, buffer]);
18 chan.asyncOpen(new ChannelListener(finish, null, flags));
19 });
22 async function test_flag_override_priority(
23 prioHeaderValue,
24 listenerPriorityValue,
25 flag
26 ) {
27 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
28 Ci.nsIX509CertDB
30 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
32 let server = new NodeHTTPSServer();
33 await server.start();
35 await server.registerPathHandler("/test", (req, resp) => {
36 resp.writeHead(200);
37 resp.end(req.headers.priority);
38 });
40 let request = NetUtil.newChannel({
41 uri: `https://localhost:${server.port()}/test`,
42 loadUsingSystemPrincipal: true,
43 });
44 let chan = request.QueryInterface(Ci.nsIHttpChannel);
46 if (prioHeaderValue !== null) {
47 request.setRequestHeader("Priority", prioHeaderValue, false);
50 // Setting flags should not override if priority is already set
51 let cos = chan.QueryInterface(Ci.nsIClassOfService);
52 cos.addClassFlags(flag);
54 let [req, buff] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
55 Assert.equal(req.status, Cr.NS_OK);
56 Assert.equal(buff, listenerPriorityValue); // Check buffer
57 Assert.equal(req.getRequestHeader("Priority"), listenerPriorityValue);
58 await server.stop();
61 add_task(async function test_prio_header_no_override() {
62 await test_flag_override_priority(null, "u=2", Ci.nsIClassOfService.Leader);
63 });
65 add_task(async function test_prio_header_no_override2() {
66 await test_flag_override_priority(null, "u=4", Ci.nsIClassOfService.Follower);
67 });
69 add_task(async function test_prio_header_override() {
70 await test_flag_override_priority("foo", "foo", Ci.nsIClassOfService.Leader);
71 });
73 add_task(async function test_prio_header_override2() {
74 await test_flag_override_priority(
75 "foo",
76 "foo",
77 Ci.nsIClassOfService.Follower
79 });