2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
9 <title>Test for performance observer
</title>
10 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
11 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
16 SimpleTest
.requestFlakyTimeout("For testing when observer callbacks should not be called.");
17 SimpleTest
.waitForExplicitFinish();
21 let test
= promise_test
= fn
=> {
23 _tests
.push(async () => {
26 add_cleanup
: f
=> { cleanups
.push(f
); },
27 step_timeout(f
, timeout
) {
29 var args
= Array
.prototype.slice
.call(arguments
, 2);
30 return setTimeout(() => {
31 return f
.apply(test_this
, args
);
36 ok(false, `got unexpected exception ${e}`);
39 for (const f
of cleanups
) {
44 ok(false, `got unexpected exception during cleanup ${e}`);
49 function runNextTest() {
57 function assert_equals(actual
, expected
, description
) {
58 ok(typeof actual
== typeof expected
,
59 `${description} expected (${typeof expected}) ${expected} but got (${typeof actual}) ${actual}`);
60 ok(Object
.is(actual
, expected
),
61 `${description} expected ${expected} but got ${actual}`);
64 function assert_array_equals(actual
, expected
, description
) {
65 ok(actual
.length
=== expected
.length
,
66 `${description} lengths differ, expected ${expected.length} but got ${actual.length}`);
67 for (var i
= 0; i
< actual
.length
; i
++) {
68 ok(actual
.hasOwnProperty(i
) === expected
.hasOwnProperty(i
),
69 `${description} property expected to be ${expected[i]} but got ${actual[i]}`);
73 function assert_throws(expected_exc
, func
, desc
) {
77 var actual
= e
.name
|| e
.type
;
78 var expected
= expected_exc
.name
|| expected_exc
.type
;
79 ok(actual
== expected
,
80 `Expected '${expected}', got '${actual}'.`);
83 ok(false, "Expected exception, but none was thrown");
86 function assert_unreached(description
) {
87 ok(false, `${description} reached unreachable code`);
90 <script src=
"test_performance_observer.js"></script>
92 function makeXHR(aUrl
) {
93 var xmlhttp
= new XMLHttpRequest();
94 xmlhttp
.open("get", aUrl
, true);
98 let waitForConsole
= new Promise(resolve
=> {
99 SimpleTest
.monitorConsole(resolve
, [{
100 message
: /JavaScript Warning: "Ignoring unsupported entryTypes: invalid."/,
105 var promise
= new Promise(resolve
=> {
106 performance
.clearResourceTimings();
108 var observer
= new PerformanceObserver(list
=> resolve(list
));
109 observer
.observe({entryTypes
: ['resource']});
110 t
.add_cleanup(() => observer
.disconnect());
113 makeXHR("test-data.json");
115 return promise
.then(async list
=> {
116 assert_equals(list
.getEntries().length
, 1);
117 assert_array_equals(list
.getEntries(),
118 performance
.getEntriesByType("resource"),
119 "Observed 'resource' entries should equal to entries obtained by getEntriesByType.");
121 // getEntries filtering tests
122 assert_array_equals(list
.getEntries({name
: "http://mochi.test:8888/tests/dom/base/test/test-data.json"}),
123 performance
.getEntriesByName("http://mochi.test:8888/tests/dom/base/test/test-data.json"),
124 "getEntries with name filter should return correct results.");
125 assert_array_equals(list
.getEntries({entryType
: "resource"}),
126 performance
.getEntriesByType("resource"),
127 "getEntries with entryType filter should return correct results.");
128 assert_array_equals(list
.getEntries({initiatorType
: "xmlhttprequest"}),
129 performance
.getEntriesByType("resource"),
130 "getEntries with initiatorType filter should return correct results.");
131 assert_array_equals(list
.getEntries({initiatorType
: "link"}),
133 "getEntries with non-existent initiatorType filter should return an empty array.");
135 SimpleTest
.endMonitorConsole();
136 await waitForConsole
;
138 }, "resource-timing test");