blob: 504d17592f2de93177dd20949d31f14ed51503f7 [file] [log] [blame]
Nicolas Pena6e9d51e2019-01-30 15:25:001<!DOCTYPE HTML>
2<meta charset=utf-8>
3<title>Element Timing: intersectionRect when image overflows</title>
4<body>
5<style>
6body {
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 Moreno66bb6b42019-05-01 17:40:5815 let img;
Nicolas Pena6e9d51e2019-01-30 15:25:0016 async_test(function (t) {
Stephen McGruerdcfc14d2020-04-16 13:23:0317 assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
Nicolas Pena6e9d51e2019-01-30 15:25:0018 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 Morenoe42570f2019-10-21 21:23:0922 const pathname = window.location.origin + '/element-timing/resources/square20.png';
Nicolás Peña Moreno66bb6b42019-05-01 17:40:5823 checkElement(entry, pathname, 'not_fully_visible', '', beforeRender, img);
Nicolas Pena6e9d51e2019-01-30 15:25:0024 // 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 Morenocf8e8812019-04-01 17:12:0228 checkNaturalSize(entry, 20, 20);
Nicolas Pena6e9d51e2019-01-30 15:25:0029 })
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 Moreno66bb6b42019-05-01 17:40:5836 img = document.createElement('img');
Nicolas Pena6e9d51e2019-01-30 15:25:0037 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>