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 () => {
9 add_task(async
function setup() {
10 await
http3_setup_tests("h3-29");
13 let Http3Listener = function () {};
15 Http3Listener
.prototype = {
17 expectedStatus
: Cr
.NS_OK
,
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
) {
29 read_stream(stream
, cnt
);
32 onStopRequest
: function testOnStopRequest(request
) {
35 httpVersion
= request
.protocolVersion
;
37 Assert
.equal(httpVersion
, "h3-29");
38 Assert
.equal(this.amount
, this.expectedAmount
);
44 function chanPromise(chan
, listener
) {
45 return new Promise(resolve
=> {
46 function finish(result
) {
49 listener
.finish
= finish
;
50 chan
.asyncOpen(listener
);
54 function makeChan(uri
) {
55 let chan
= NetUtil
.newChannel({
57 loadUsingSystemPrincipal
: true,
58 }).QueryInterface(Ci
.nsIHttpChannel
);
59 chan
.loadFlags
= Ci
.nsIChannel
.LOAD_INITIAL_DOCUMENT_URI
;
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
);
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
);
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
);