2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
9 <title>Test for PerformanceServerTiming
</title>
10 <script src=
"/resources/testharness.js"></script>
11 <script src=
"/resources/testharnessreport.js"></script>
16 function makeXHR(aUrl
) {
17 var xmlhttp
= new XMLHttpRequest();
18 xmlhttp
.open("get", aUrl
, true);
22 // Note that |responseServerTiming| and |trailerServerTiming| SHOULD be synced with
23 // the ones in serverTiming.sjs.
24 var responseServerTiming
= [{metric
:"metric1", duration
:"123.4", description
:"description1"},
25 {metric
:"metric2", duration
:"456.78", description
:"description2"}];
26 var trailerServerTiming
= [{metric
:"metric3", duration
:"789.11", description
:"description3"},
27 {metric
:"metric4", duration
:"1112.13", description
:"description4"}];
29 function checkServerTimingContent(serverTiming
) {
30 var expectedResult
= responseServerTiming
.concat(trailerServerTiming
);
31 assert_equals(serverTiming
.length
, expectedResult
.length
);
33 for (var i
= 0; i
< expectedResult
.length
; i
++) {
34 assert_equals(serverTiming
[i
].name
, expectedResult
[i
].metric
);
35 assert_equals(serverTiming
[i
].description
, expectedResult
[i
].description
);
36 assert_equals(serverTiming
[i
].duration
, parseFloat(expectedResult
[i
].duration
));
41 var promise
= new Promise(resolve
=> {
42 performance
.clearResourceTimings();
44 var observer
= new PerformanceObserver(list
=> resolve(list
));
45 observer
.observe({entryTypes
: ['resource']});
46 t
.add_cleanup(() => observer
.disconnect());
49 makeXHR("serverTiming.sjs");
51 return promise
.then(list
=> {
52 assert_equals(list
.getEntries().length
, 1);
53 checkServerTimingContent(list
.getEntries()[0].serverTiming
);
55 }, "server-timing test");