test_performance_observer.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 performance observer</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 src="test_performance_observer.js"></script>
  16. <script>
  17. function makeXHR(aUrl) {
  18. var xmlhttp = new XMLHttpRequest();
  19. xmlhttp.open("get", aUrl, true);
  20. xmlhttp.send();
  21. }
  22. promise_test(t => {
  23. var promise = new Promise(resolve => {
  24. performance.clearResourceTimings();
  25. var observer = new PerformanceObserver(list => resolve(list));
  26. observer.observe({entryTypes: ['resource']});
  27. t.add_cleanup(() => observer.disconnect());
  28. });
  29. makeXHR("test-data.json");
  30. return promise.then(list => {
  31. assert_equals(list.getEntries().length, 1);
  32. assert_array_equals(list.getEntries(),
  33. performance.getEntriesByType("resource"),
  34. "Observed 'resource' entries should equal to entries obtained by getEntriesByType.");
  35. // getEntries filtering tests
  36. assert_array_equals(list.getEntries({name: "http://mochi.test:8888/tests/dom/base/test/test-data.json"}),
  37. performance.getEntriesByName("http://mochi.test:8888/tests/dom/base/test/test-data.json"),
  38. "getEntries with name filter should return correct results.");
  39. assert_array_equals(list.getEntries({entryType: "resource"}),
  40. performance.getEntriesByType("resource"),
  41. "getEntries with entryType filter should return correct results.");
  42. assert_array_equals(list.getEntries({initiatorType: "xmlhttprequest"}),
  43. performance.getEntriesByType("resource"),
  44. "getEntries with initiatorType filter should return correct results.");
  45. assert_array_equals(list.getEntries({initiatorType: "link"}),
  46. [],
  47. "getEntries with non-existent initiatorType filter should return an empty array.");
  48. });
  49. }, "resource-timing test");
  50. </script>
  51. </body>