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 // HTTP Server-Timing header test
11 function make_and_open_channel(url
, callback
) {
12 let chan
= NetUtil
.newChannel({ uri
: url
, loadUsingSystemPrincipal
: true });
13 chan
.asyncOpen(new ChannelListener(callback
, null, CL_ALLOW_UNKNOWN_CL
));
16 var responseServerTiming
= [
17 { metric
: "metric", duration
: "123.4", description
: "description" },
18 { metric
: "metric2", duration
: "456.78", description
: "description1" },
20 var trailerServerTiming
= [
21 { metric
: "metric3", duration
: "789.11", description
: "description2" },
22 { metric
: "metric4", duration
: "1112.13", description
: "description3" },
28 // Set up to allow the cert presented by the server
30 let certdb
= Cc
["@mozilla.org/security/x509certdb;1"].getService(
33 addCertFromFile(certdb
, "http2-ca.pem", "CTu,u,u");
35 Services
.prefs
.setCharPref("network.dns.localDomains", "foo.example.com");
36 registerCleanupFunction(() => {
37 Services
.prefs
.clearUserPref("network.dns.localDomains");
40 var serverPort
= Services
.env
.get("MOZHTTP2_PORT");
41 make_and_open_channel(
42 "https://foo.example.com:" + serverPort
+ "/server-timing",
47 function checkServerTimingContent(headers
) {
48 var expectedResult
= responseServerTiming
.concat(trailerServerTiming
);
49 Assert
.equal(headers
.length
, expectedResult
.length
);
51 for (var i
= 0; i
< expectedResult
.length
; i
++) {
52 let header
= headers
.queryElementAt(i
, Ci
.nsIServerTiming
);
53 Assert
.equal(header
.name
, expectedResult
[i
].metric
);
54 Assert
.equal(header
.description
, expectedResult
[i
].description
);
55 Assert
.equal(header
.duration
, parseFloat(expectedResult
[i
].duration
));
59 function readServerContent(request
) {
60 let channel
= request
.QueryInterface(Ci
.nsITimedChannel
);
61 let headers
= channel
.serverTiming
.QueryInterface(Ci
.nsIArray
);
62 checkServerTimingContent(headers
);