| Nicolas Pena | 6e9d51e | 2019-01-30 15:25:00 | [diff] [blame] | 1 | <!DOCTYPE HTML> |
| 2 | <meta charset=utf-8> |
| 3 | <title>Element Timing: intersectionRect when image overflows</title> |
| 4 | <body> |
| 5 | <style> |
| 6 | body { |
| 7 | margin: 200px 100px; |
| 8 | } |
| 9 | </style> |
| 10 | <script src="/resources/testharness.js"></script> |
| 11 | <script src="/resources/testharnessreport.js"></script> |
| 12 | <script src="resources/element-timing-helpers.js"></script> |
| 13 | <script> |
| 14 | let beforeRender; |
| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 15 | let img; |
| Nicolas Pena | 6e9d51e | 2019-01-30 15:25:00 | [diff] [blame] | 16 | async_test(function (t) { |
| Stephen McGruer | dcfc14d | 2020-04-16 13:23:03 | [diff] [blame] | 17 | assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented"); |
| Nicolas Pena | 6e9d51e | 2019-01-30 15:25:00 | [diff] [blame] | 18 | const observer = new PerformanceObserver( |
| 19 | t.step_func_done(function(entryList) { |
| 20 | assert_equals(entryList.getEntries().length, 1); |
| 21 | const entry = entryList.getEntries()[0]; |
| Nicolás Peña Moreno | e42570f | 2019-10-21 21:23:09 | [diff] [blame] | 22 | const pathname = window.location.origin + '/element-timing/resources/square20.png'; |
| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 23 | checkElement(entry, pathname, 'not_fully_visible', '', beforeRender, img); |
| Nicolas Pena | 6e9d51e | 2019-01-30 15:25:00 | [diff] [blame] | 24 | // Image will not be fully visible. It should start from the top left part |
| 25 | // of the document, excluding the margin, and then overflow. |
| 26 | checkRect(entry, |
| 27 | [100, document.documentElement.clientWidth, 200, document.documentElement.clientHeight]); |
| Nicolás Peña Moreno | cf8e881 | 2019-04-01 17:12:02 | [diff] [blame] | 28 | checkNaturalSize(entry, 20, 20); |
| Nicolas Pena | 6e9d51e | 2019-01-30 15:25:00 | [diff] [blame] | 29 | }) |
| 30 | ); |
| 31 | observer.observe({entryTypes: ['element']}); |
| 32 | // We add the image during onload to be sure that the observer is registered |
| 33 | // in time for it to observe the element timing. |
| 34 | window.onload = () => { |
| 35 | // Add an image setting width and height equal to viewport. |
| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 36 | img = document.createElement('img'); |
| Nicolas Pena | 6e9d51e | 2019-01-30 15:25:00 | [diff] [blame] | 37 | img.src = 'resources/square20.png'; |
| 38 | img.setAttribute('elementtiming', 'not_fully_visible'); |
| 39 | img.width = document.documentElement.clientWidth; |
| 40 | img.height = document.documentElement.clientHeight; |
| 41 | document.body.appendChild(img); |
| 42 | beforeRender = performance.now(); |
| 43 | }; |
| 44 | }, 'The intersectionRect of an img element overflowing is computed correctly'); |
| 45 | </script> |
| 46 | |
| 47 | </body> |