Bug 1928997: Update tabs icon in Unified Search popup r=desktop-theme-reviewers,daleh...
[gecko.git] / dom / performance / tests / test_performance_server_timing.html
blobcba11a5fddbb75387f08f3a347995f223bf7d25e
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <!DOCTYPE html>
6 <html>
7 <head>
8 <meta charset=utf-8>
9 <title>Test for PerformanceServerTiming</title>
10 <script src="/resources/testharness.js"></script>
11 <script src="/resources/testharnessreport.js"></script>
12 </head>
13 <body>
14 <div id="log"></div>
15 <script>
16 function makeXHR(aUrl) {
17 var xmlhttp = new XMLHttpRequest();
18 xmlhttp.open("get", aUrl, true);
19 xmlhttp.send();
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));
40 promise_test(t => {
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());
47 });
49 makeXHR("serverTiming.sjs");
51 return promise.then(list => {
52 assert_equals(list.getEntries().length, 1);
53 checkServerTimingContent(list.getEntries()[0].serverTiming);
54 });
55 }, "server-timing test");
57 </script>
58 </body>