2015-08-17 22:13:20 +00:00
|
|
|
<!--
|
|
|
|
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';
|
|
|
|
[
|
2015-09-02 21:41:00 +00:00
|
|
|
"promise_test", "test", "setup",
|
2015-08-17 22:13:20 +00:00
|
|
|
"assert_true", "assert_equals", "assert_array_equals",
|
2015-09-02 21:41:00 +00:00
|
|
|
"assert_throws", "assert_unreached"
|
2015-08-17 22:13:20 +00:00
|
|
|
].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>
|
2015-09-02 21:41:00 +00:00
|
|
|
function makeXHR(aUrl) {
|
|
|
|
var xmlhttp = new XMLHttpRequest();
|
|
|
|
xmlhttp.open("get", aUrl, true);
|
|
|
|
xmlhttp.send();
|
2015-08-17 22:13:20 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 21:41:00 +00:00
|
|
|
promise_test(t => {
|
|
|
|
var promise = new Promise(resolve => {
|
|
|
|
performance.clearResourceTimings();
|
2015-08-17 22:13:20 +00:00
|
|
|
|
2015-09-02 21:41:00 +00:00
|
|
|
var observer = new PerformanceObserver(list => resolve(list));
|
|
|
|
observer.observe({entryTypes: ['resource']});
|
|
|
|
t.add_cleanup(() => observer.disconnect());
|
2015-08-17 22:13:20 +00:00
|
|
|
});
|
|
|
|
|
2015-09-02 21:41:00 +00:00
|
|
|
makeXHR("test-data.json");
|
2015-08-17 22:13:20 +00:00
|
|
|
|
2015-09-02 21:41:00 +00:00
|
|
|
return promise.then(list => {
|
|
|
|
assert_equals(list.getEntries().length, 1);
|
|
|
|
assert_array_equals(list.getEntries(),
|
2015-08-17 22:13:20 +00:00
|
|
|
performance.getEntriesByType("resource"),
|
|
|
|
"Observed 'resource' entries should equal to entries obtained by getEntriesByType.");
|
2015-08-17 22:13:26 +00:00
|
|
|
|
|
|
|
// getEntries filtering tests
|
2015-09-02 21:41:00 +00:00
|
|
|
assert_array_equals(list.getEntries({name: "http://mochi.test:8888/tests/dom/base/test/test-data.json"}),
|
2015-08-17 22:13:26 +00:00
|
|
|
performance.getEntriesByName("http://mochi.test:8888/tests/dom/base/test/test-data.json"),
|
|
|
|
"getEntries with name filter should return correct results.");
|
2015-09-02 21:41:00 +00:00
|
|
|
assert_array_equals(list.getEntries({entryType: "resource"}),
|
2015-08-17 22:13:26 +00:00
|
|
|
performance.getEntriesByType("resource"),
|
|
|
|
"getEntries with entryType filter should return correct results.");
|
2015-09-02 21:41:00 +00:00
|
|
|
assert_array_equals(list.getEntries({initiatorType: "xmlhttprequest"}),
|
2015-08-17 22:13:26 +00:00
|
|
|
performance.getEntriesByType("resource"),
|
|
|
|
"getEntries with initiatorType filter should return correct results.");
|
2015-09-02 21:41:00 +00:00
|
|
|
assert_array_equals(list.getEntries({initiatorType: "link"}),
|
2015-08-17 22:13:26 +00:00
|
|
|
[],
|
|
|
|
"getEntries with non-existent initiatorType filter should return an empty array.");
|
2015-09-02 21:41:00 +00:00
|
|
|
});
|
2015-08-17 22:13:20 +00:00
|
|
|
}, "resource-timing test");
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|