| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 1 | <!DOCTYPE HTML> |
| 2 | <meta charset=utf-8> |
| 3 | <title>Element Timing: element attribute returns null when element is disconnected</title> |
| 4 | <body> |
| 5 | <script src="/resources/testharness.js"></script> |
| 6 | <script src="/resources/testharnessreport.js"></script> |
| 7 | <script src="resources/element-timing-helpers.js"></script> |
| 8 | <script> |
| 9 | let beforeRender; |
| 10 | let img; |
| 11 | async_test(function (t) { |
| James Graham | 163424c | 2019-05-17 16:47:03 | [diff] [blame] | 12 | if (!window.PerformanceElementTiming) { |
| 13 | assert_unreached("PerformanceElementTiming is not implemented"); |
| 14 | } |
| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 15 | const observer = new PerformanceObserver( |
| 16 | t.step_func_done(function(entryList) { |
| 17 | assert_equals(entryList.getEntries().length, 1); |
| 18 | const entry = entryList.getEntries()[0]; |
| Nicolás Peña Moreno | e42570f | 2019-10-21 21:23:09 | [diff] [blame] | 19 | const pathname = window.location.origin + '/element-timing/resources/square100.png'; |
| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 20 | // This method will check that entry.element is |img|. |
| 21 | checkElement(entry, pathname, 'my_image', 'my_id', beforeRender, img); |
| 22 | |
| 23 | img.parentNode.removeChild(img); |
| 24 | // After removing image, entry.element should return null. |
| 25 | assert_equals(entry.element, null); |
| 26 | }) |
| 27 | ); |
| 28 | observer.observe({entryTypes: ['element']}); |
| 29 | // We add the image during onload to be sure that the observer is registered |
| 30 | // in time for it to observe the element timing. |
| 31 | window.onload = () => { |
| 32 | // Add image of width equal to 100 and height equal to 100. |
| 33 | img = document.createElement('img'); |
| 34 | img.src = 'resources/square100.png'; |
| 35 | img.setAttribute('elementtiming', 'my_image'); |
| 36 | img.setAttribute('id', 'my_id'); |
| 37 | document.body.appendChild(img); |
| 38 | beforeRender = performance.now(); |
| 39 | }; |
| 40 | }, 'Disconnected elements have null as their |element| attribute.'); |
| 41 | </script> |
| 42 | |
| 43 | </body> |