summaryrefslogtreecommitdiffstats
path: root/dom/performance/tests/performance_observer.html
blob: b8ced9296c40237f2561de01ade30e5a843a132e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE html>
<meta charset=utf-8>
<html>
<head>
<title>Test for performance observer</title>
<script>
'use strict';
[
 "promise_test", "test", "setup",
 "assert_true", "assert_equals", "assert_array_equals",
 "assert_throws", "assert_unreached"
].forEach(func => {
  window[func] = opener[func].bind(opener);
});
function done() {
  opener.add_completion_callback(() => {
    self.close();
  });
  opener.done();
}

</script>
<script src="test_performance_observer.js"></script>
</head>
<body>
<div id="log"></div>
<script>
function makeXHR(aUrl) {
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.open("get", aUrl, true);
  xmlhttp.send();
}

promise_test(t => {
  var promise = new Promise(resolve => {
    performance.clearResourceTimings();

    var observer = new PerformanceObserver(list => resolve(list));
    observer.observe({entryTypes: ['resource']});
    t.add_cleanup(() => observer.disconnect());
  });

  makeXHR("test-data.json");

  return promise.then(list => {
    assert_equals(list.getEntries().length, 1);
    assert_array_equals(list.getEntries(),
                        performance.getEntriesByType("resource"),
                        "Observed 'resource' entries should equal to entries obtained by getEntriesByType.");

    // getEntries filtering tests
    assert_array_equals(list.getEntries({name: "http://mochi.test:8888/tests/dom/base/test/test-data.json"}),
                        performance.getEntriesByName("http://mochi.test:8888/tests/dom/base/test/test-data.json"),
                        "getEntries with name filter should return correct results.");
    assert_array_equals(list.getEntries({entryType: "resource"}),
                        performance.getEntriesByType("resource"),
                        "getEntries with entryType filter should return correct results.");
    assert_array_equals(list.getEntries({initiatorType: "xmlhttprequest"}),
                        performance.getEntriesByType("resource"),
                        "getEntries with initiatorType filter should return correct results.");
    assert_array_equals(list.getEntries({initiatorType: "link"}),
                        [],
                        "getEntries with non-existent initiatorType filter should return an empty array.");
  });
}, "resource-timing test");

done();

</script>
</body>