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 // This test can be merged with test_progress.js once HTTP/3 tests are
7 // enabled on all plaforms.
11 var using_proxy
= false;
13 const RESPONSE_LENGTH
= 3000000;
14 const STATUS_RECEIVING_FROM
= 0x4b0006;
16 const TYPE_ONSTATUS
= 1;
17 const TYPE_ONPROGRESS
= 2;
18 const TYPE_ONSTARTREQUEST
= 3;
19 const TYPE_ONDATAAVAILABLE
= 4;
20 const TYPE_ONSTOPREQUEST
= 5;
22 var ProgressCallback = function () {};
24 ProgressCallback
.prototype = {
26 _got_onstartrequest
: false,
27 _got_onstatus_after_onstartrequest
: false,
28 _last_callback_handled
: null,
32 QueryInterface
: ChromeUtils
.generateQI([
33 "nsIProgressEventSink",
40 iid
.equals(Ci
.nsIProgressEventSink
) ||
41 iid
.equals(Ci
.nsIStreamListener
) ||
42 iid
.equals(Ci
.nsIRequestObserver
)
46 throw Components
.Exception("", Cr
.NS_ERROR_NO_INTERFACE
);
49 onStartRequest(request
) {
50 Assert
.equal(this._last_callback_handled
, TYPE_ONSTATUS
);
51 this._got_onstartrequest
= true;
52 this._last_callback_handled
= TYPE_ONSTARTREQUEST
;
54 this._listener
= new ChannelListener(checkRequest
, request
);
55 this._listener
.onStartRequest(request
);
58 onDataAvailable(request
, data
, offset
, count
) {
59 Assert
.equal(this._last_callback_handled
, TYPE_ONPROGRESS
);
60 this._last_callback_handled
= TYPE_ONDATAAVAILABLE
;
62 this._listener
.onDataAvailable(request
, data
, offset
, count
);
65 onStopRequest(request
, status
) {
66 Assert
.equal(this._last_callback_handled
, TYPE_ONDATAAVAILABLE
);
67 Assert
.ok(this._got_onstatus_after_onstartrequest
);
68 this._last_callback_handled
= TYPE_ONSTOPREQUEST
;
70 this._listener
.onStopRequest(request
, status
);
71 delete this._listener
;
73 check_http_info(request
, this.expected_httpVersion
, using_proxy
);
78 onProgress(request
, progress
, progressMax
) {
79 Assert
.equal(this._last_callback_handled
, TYPE_ONSTATUS
);
80 this._last_callback_handled
= TYPE_ONPROGRESS
;
82 Assert
.equal(this.mStatus
, STATUS_RECEIVING_FROM
);
87 onStatus(request
, status
, statusArg
) {
88 if (!this._got_onstartrequest
) {
89 // Ensure that all messages before onStartRequest are onStatus
90 if (this._last_callback_handled
) {
91 Assert
.equal(this._last_callback_handled
, TYPE_ONSTATUS
);
93 } else if (this._last_callback_handled
== TYPE_ONSTARTREQUEST
) {
94 this._got_onstatus_after_onstartrequest
= true;
96 Assert
.equal(this._last_callback_handled
, TYPE_ONDATAAVAILABLE
);
98 this._last_callback_handled
= TYPE_ONSTATUS
;
100 Assert
.equal(statusArg
, this.statusArg
);
101 this.mStatus
= status
;
107 function chanPromise(uri
, statusArg
, version
) {
108 return new Promise(resolve
=> {
109 var chan
= makeHTTPChannel(uri
, using_proxy
);
110 chan
.requestMethod
= "GET";
111 let listener
= new ProgressCallback();
112 listener
.statusArg
= statusArg
;
113 chan
.notificationCallbacks
= listener
;
114 listener
.expected_httpVersion
= version
;
115 listener
.finish
= resolve
;
116 chan
.asyncOpen(listener
);
120 function checkRequest() {
121 Assert
.equal(last
, RESPONSE_LENGTH
);
122 Assert
.equal(max
, RESPONSE_LENGTH
);
125 async
function check_progress(server
) {
126 info(`Testing ${server.constructor.name}`);
127 await server
.registerPathHandler("/test", (req
, resp
) => {
129 function generateContent(size
) {
130 return "0".repeat(size
);
133 resp
.writeHead(200, {
134 "content-type": "application/json",
135 "content-length": "3000000",
137 resp
.end(generateContent(3000000));
140 `${server.origin()}/test`,
141 `${server.domain()}`,
146 add_task(async
function setup() {
147 let certdb
= Cc
["@mozilla.org/security/x509certdb;1"].getService(
150 addCertFromFile(certdb
, "http2-ca.pem", "CTu,u,u");
151 addCertFromFile(certdb
, "proxy-ca.pem", "CTu,u,u");
154 add_task(async
function test_http_1_and_2() {
155 await
with_node_servers(
156 [NodeHTTPServer
, NodeHTTPSServer
, NodeHTTP2Server
],
161 add_task(async
function test_http_proxy() {
163 let proxy
= new NodeHTTPProxyServer();
165 await
with_node_servers(
166 [NodeHTTPServer
, NodeHTTPSServer
, NodeHTTP2Server
],
173 add_task(async
function test_https_proxy() {
175 let proxy
= new NodeHTTPSProxyServer();
177 await
with_node_servers(
178 [NodeHTTPServer
, NodeHTTPSServer
, NodeHTTP2Server
],
185 add_task(async
function test_http2_proxy() {
187 let proxy
= new NodeHTTP2ProxyServer();
189 await
with_node_servers(
190 [NodeHTTPServer
, NodeHTTPSServer
, NodeHTTP2Server
],
197 add_task(async
function test_http3() {
198 await
http3_setup_tests("h3-29");
200 "https://foo.example.com/" + RESPONSE_LENGTH
,