blob: b02808456a3de05fb2ac1ede3af33c056bfd77ad [file] [log] [blame]
Nicolás Peña Morenocf8e8812019-04-01 17:12:021<!DOCTYPE HTML>
2<meta charset=utf-8>
3<title>Element Timing: observe a rectangular image</title>
4<body>
5<style>
6body {
7 margin: 20px;
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;
15 async_test(function (t) {
16 const observer = new PerformanceObserver(
17 t.step_func_done(function(entryList) {
18 assert_equals(entryList.getEntries().length, 1);
19 const entry = entryList.getEntries()[0];
20 const index = window.location.href.lastIndexOf('/');
21 // Subtracting 14 to remove 'element-timing'.
22 const pathname = window.location.href.substring(0, index - 14) +
23 'images/black-rectangle.png';
Nicolás Peña Moreno15d28552019-04-01 19:03:0824 checkElement(entry, pathname, 'my_image', 'rectangle', beforeRender);
Nicolás Peña Morenocf8e8812019-04-01 17:12:0225 // Assume viewport has size at least 100, so the element is fully visible.
26 checkRect(entry, [20, 120, 20, 70]);
27 checkNaturalSize(entry, 100, 50);
28 })
29 );
30 observer.observe({entryTypes: ['element']});
31 // We add the image during onload to be sure that the observer is registered
32 // in time for it to observe the element timing.
33 window.onload = () => {
34 // Add image of width equal to 100 and height equal to 50.
35 const img = document.createElement('img');
36 img.src = '/images/black-rectangle.png';
Nicolás Peña Moreno15d28552019-04-01 19:03:0837 img.id = 'rectangle';
Nicolás Peña Morenocf8e8812019-04-01 17:12:0238 img.setAttribute('elementtiming', 'my_image');
39 document.body.appendChild(img);
40 beforeRender = performance.now();
41 };
42 }, 'Element with rectangular image has correct rect and instrinsic size.');
43</script>
44</body>