Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_http3_trans_close.js
blob7fc57873cfb54f0884446dc27d47e0132ffefdb8
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 registerCleanupFunction(async () => {
6 http3_clear_prefs();
7 });
9 add_task(async function setup() {
10 await http3_setup_tests("h3-29");
11 });
13 let Http3Listener = function () {};
15 Http3Listener.prototype = {
16 expectedAmount: 0,
17 expectedStatus: Cr.NS_OK,
18 amount: 0,
20 onStartRequest: function testOnStartRequest(request) {
21 Assert.equal(request.status, this.expectedStatus);
22 if (Components.isSuccessCode(this.expectedStatus)) {
23 Assert.equal(request.responseStatus, 200);
27 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
28 this.amount += cnt;
29 read_stream(stream, cnt);
32 onStopRequest: function testOnStopRequest(request) {
33 let httpVersion = "";
34 try {
35 httpVersion = request.protocolVersion;
36 } catch (e) {}
37 Assert.equal(httpVersion, "h3-29");
38 Assert.equal(this.amount, this.expectedAmount);
40 this.finish();
44 function chanPromise(chan, listener) {
45 return new Promise(resolve => {
46 function finish(result) {
47 resolve(result);
49 listener.finish = finish;
50 chan.asyncOpen(listener);
51 });
54 function makeChan(uri) {
55 let chan = NetUtil.newChannel({
56 uri,
57 loadUsingSystemPrincipal: true,
58 }).QueryInterface(Ci.nsIHttpChannel);
59 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
60 return chan;
63 add_task(async function test_response_without_body() {
64 let chan = makeChan("https://foo.example.com/no_body");
65 let listener = new Http3Listener();
66 listener.expectedAmount = 0;
67 await chanPromise(chan, listener);
68 });
70 add_task(async function test_response_without_content_length() {
71 let chan = makeChan("https://foo.example.com/no_content_length");
72 let listener = new Http3Listener();
73 listener.expectedAmount = 4000;
74 await chanPromise(chan, listener);
75 });
77 add_task(async function test_content_length_smaller_than_data_len() {
78 let chan = makeChan("https://foo.example.com/content_length_smaller");
79 let listener = new Http3Listener();
80 // content-lentgth is 4000, but data length is 8000.
81 // We should return an error here - bug 1670086.
82 listener.expectedAmount = 4000;
83 await chanPromise(chan, listener);
84 });