Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_header_Server_Timing.js
blobdbf05177e237d331d2b410867fbda792c078d0c8
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 //
6 // HTTP Server-Timing header test
7 //
9 "use strict";
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" },
25 function run_test() {
26 do_test_pending();
28 // Set up to allow the cert presented by the server
29 do_get_profile();
30 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
31 Ci.nsIX509CertDB
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");
38 });
40 var serverPort = Services.env.get("MOZHTTP2_PORT");
41 make_and_open_channel(
42 "https://foo.example.com:" + serverPort + "/server-timing",
43 readServerContent
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);
63 do_test_finished();