Kaido Kert | f309f9a | 2021-04-30 12:09:15 -0700 | [diff] [blame] | 1 | <!DOCTYPE HTML> |
| 2 | <meta charset=utf-8> |
| 3 | <title>PerformanceObservers: resource</title> |
| 4 | <script src="/resources/testharness.js"></script> |
| 5 | <script src="/resources/testharnessreport.js"></script> |
| 6 | <script src="performanceobservers.js"></script> |
| 7 | <h1>PerformanceObservers: resource</h1> |
| 8 | <p> |
| 9 | New resources will <a href="https://w3c.github.io/performance-timeline/#dfn-queue-a-performanceentry">queue a PerformanceEntry</a>. |
| 10 | </p> |
| 11 | <div id="log"></div> |
| 12 | <script> |
| 13 | async_test(function (t) { |
| 14 | function path(pathname) { |
| 15 | var filename = pathname.substring(pathname.lastIndexOf('/')+1); |
| 16 | return pathname.substring(0, pathname.length - filename.length); |
| 17 | } |
| 18 | var gUniqueCounter = 0; |
| 19 | function generateUniqueValues() { |
| 20 | return Date.now() + "-" + (++gUniqueCounter); |
| 21 | } |
| 22 | var stored_entries = []; |
| 23 | var img_location = document.location.origin + path(document.location.pathname) |
| 24 | + "resources/square.png?random="; |
| 25 | var img1 = img_location + generateUniqueValues(); |
| 26 | var img2 = img_location + generateUniqueValues(); |
| 27 | var observer = new PerformanceObserver( |
| 28 | t.step_func(function (entryList, obs) { |
| 29 | stored_entries = |
| 30 | stored_entries.concat(entryList.getEntriesByType("resource")); |
| 31 | if (stored_entries.length >= 2) { |
| 32 | checkEntries(stored_entries, |
| 33 | [{ entryType: "resource", name: img1}, |
| 34 | { entryType: "resource", name: img2}]); |
| 35 | observer.disconnect(); |
| 36 | t.done(); |
| 37 | } |
| 38 | }) |
| 39 | ); |
| 40 | observer.observe({entryTypes: ["resource"]}); |
| 41 | var img = document.createElement("img"); |
| 42 | img.src = img1; |
| 43 | document.body.appendChild(img); |
| 44 | img = document.createElement("img"); |
| 45 | img.src = img2; |
| 46 | document.body.appendChild(img); |
| 47 | }, "resource entries are observable"); |
| 48 | </script> |