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