Bug 1590219 [wpt PR 19813] - [ElementTiming] Cleanup window.location.href usage in...
[gecko.git] / testing / web-platform / tests / element-timing / observe-elementtiming.html
blob164cc4f580afd46ce8a2c5425db7f72841eba441
1 <!DOCTYPE HTML>
2 <meta charset=utf-8>
3 <title>Element Timing: observe elements with elementtiming attribute</title>
4 <body>
5 <style>
6 body {
7 margin: 0;
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;
15 let img;
16 async_test(function (t) {
17 if (!window.PerformanceElementTiming) {
18 assert_unreached("PerformanceElementTiming is not implemented");
20 const observer = new PerformanceObserver(
21 t.step_func_done(function(entryList) {
22 assert_equals(entryList.getEntries().length, 1);
23 const entry = entryList.getEntries()[0];
24 const pathname = window.location.origin + '/element-timing/resources/square100.png';
25 checkElement(entry, pathname, 'my_image', 'my_id', beforeRender, img);
26 // Assume viewport has size at least 100, so the element is fully visible.
27 checkRect(entry, [0, 100, 0, 100]);
28 checkNaturalSize(entry, 100, 100);
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 image of width equal to 100 and height equal to 100.
36 img = document.createElement('img');
37 img.src = 'resources/square100.png';
38 img.setAttribute('elementtiming', 'my_image');
39 img.setAttribute('id', 'my_id');
40 document.body.appendChild(img);
41 beforeRender = performance.now();
43 }, 'Element with elementtiming attribute is observable.');
44 </script>
46 </body>