2018-01-03 19:59:00 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
//
|
|
|
|
// HTTP Server-Timing header test
|
|
|
|
//
|
|
|
|
|
2020-04-07 19:00:03 +03:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-03 19:59:00 +03:00
|
|
|
function make_and_open_channel(url, callback) {
|
|
|
|
let chan = NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
|
2019-02-12 19:08:25 +03:00
|
|
|
chan.asyncOpen(new ChannelListener(callback, null, CL_ALLOW_UNKNOWN_CL));
|
2018-01-03 19:59:00 +03:00
|
|
|
}
|
|
|
|
|
2018-02-15 21:11:37 +03:00
|
|
|
var responseServerTiming = [
|
|
|
|
{ metric: "metric", duration: "123.4", description: "description" },
|
|
|
|
{ metric: "metric2", duration: "456.78", description: "description1" },
|
|
|
|
];
|
2018-01-03 19:59:00 +03:00
|
|
|
var trailerServerTiming = [
|
|
|
|
{ metric: "metric3", duration: "789.11", description: "description2" },
|
|
|
|
{ metric: "metric4", duration: "1112.13", description: "description3" },
|
|
|
|
];
|
|
|
|
|
|
|
|
function run_test() {
|
2018-02-15 21:11:37 +03:00
|
|
|
do_test_pending();
|
|
|
|
|
|
|
|
// Set up to allow the cert presented by the server
|
|
|
|
do_get_profile();
|
|
|
|
let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
|
|
|
|
Ci.nsIX509CertDB
|
|
|
|
);
|
2019-03-04 18:42:07 +03:00
|
|
|
addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
|
2018-02-15 21:11:37 +03:00
|
|
|
|
|
|
|
Services.prefs.setCharPref("network.dns.localDomains", "foo.example.com");
|
2018-02-08 03:05:38 +03:00
|
|
|
registerCleanupFunction(() => {
|
2018-02-15 21:11:37 +03:00
|
|
|
Services.prefs.clearUserPref("network.dns.localDomains");
|
2018-02-08 03:05:38 +03:00
|
|
|
});
|
|
|
|
|
2018-02-15 21:11:37 +03:00
|
|
|
var env = Cc["@mozilla.org/process/environment;1"].getService(
|
|
|
|
Ci.nsIEnvironment
|
|
|
|
);
|
|
|
|
var serverPort = env.get("MOZHTTP2_PORT");
|
|
|
|
make_and_open_channel(
|
|
|
|
"https://foo.example.com:" + serverPort + "/server-timing",
|
|
|
|
readServerContent
|
|
|
|
);
|
2018-01-03 19:59:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkServerTimingContent(headers) {
|
2018-02-15 21:11:37 +03:00
|
|
|
var expectedResult = responseServerTiming.concat(trailerServerTiming);
|
2018-01-03 19:59:00 +03:00
|
|
|
Assert.equal(headers.length, expectedResult.length);
|
|
|
|
|
|
|
|
for (var i = 0; i < expectedResult.length; i++) {
|
|
|
|
let header = headers.queryElementAt(i, Ci.nsIServerTiming);
|
|
|
|
Assert.equal(header.name, expectedResult[i].metric);
|
|
|
|
Assert.equal(header.description, expectedResult[i].description);
|
|
|
|
Assert.equal(header.duration, parseFloat(expectedResult[i].duration));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function readServerContent(request, buffer) {
|
|
|
|
let channel = request.QueryInterface(Ci.nsITimedChannel);
|
|
|
|
let headers = channel.serverTiming.QueryInterface(Ci.nsIArray);
|
|
|
|
checkServerTimingContent(headers);
|
2018-02-15 21:11:37 +03:00
|
|
|
do_test_finished();
|
2018-01-03 19:59:00 +03:00
|
|
|
}
|