test_http3_trans_close.js (2368B)
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/. */ 4 5 registerCleanupFunction(async () => { 6 http3_clear_prefs(); 7 }); 8 9 add_task(async function setup() { 10 await http3_setup_tests("h3"); 11 }); 12 13 let Http3Listener = function () {}; 14 15 Http3Listener.prototype = { 16 expectedAmount: 0, 17 expectedStatus: Cr.NS_OK, 18 amount: 0, 19 20 onStartRequest: function testOnStartRequest(request) { 21 Assert.equal(request.status, this.expectedStatus); 22 if (Components.isSuccessCode(this.expectedStatus)) { 23 Assert.equal(request.responseStatus, 200); 24 } 25 }, 26 27 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) { 28 this.amount += cnt; 29 read_stream(stream, cnt); 30 }, 31 32 onStopRequest: function testOnStopRequest(request) { 33 let httpVersion = ""; 34 try { 35 httpVersion = request.protocolVersion; 36 } catch (e) {} 37 Assert.equal(httpVersion, "h3"); 38 Assert.equal(this.amount, this.expectedAmount); 39 40 this.finish(); 41 }, 42 }; 43 44 function chanPromise(chan, listener) { 45 return new Promise(resolve => { 46 function finish(result) { 47 resolve(result); 48 } 49 listener.finish = finish; 50 chan.asyncOpen(listener); 51 }); 52 } 53 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; 61 } 62 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 }); 69 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 }); 76 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 });