mirror of
https://github.com/servo/servo.git
synced 2025-07-16 03:43:38 +01:00
69 lines
2.3 KiB
HTML
69 lines
2.3 KiB
HTML
<!DOCTYPE HTML>
|
|
<meta charset=utf-8>
|
|
<title>Element Timing: observe elements with the same resource</title>
|
|
<body>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
}
|
|
</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 numEntries = 0;
|
|
let responseEnd1;
|
|
let responseEnd2;
|
|
let img;
|
|
let img2;
|
|
const index = window.location.href.lastIndexOf('/');
|
|
const pathname = window.location.href.substring(0, index) +
|
|
'/resources/square100.png';
|
|
async_test(function (t) {
|
|
const observer = new PerformanceObserver(
|
|
t.step_func(function(entryList) {
|
|
entryList.getEntries().forEach(entry => {
|
|
// Easier to check the |element| attribute here since element ID is the same for both images.
|
|
checkElement(entry, pathname, entry.identifier, 'image_id', beforeRender, null);
|
|
checkNaturalSize(entry, 100, 100);
|
|
if (entry.identifier === 'my_image') {
|
|
++numEntries;
|
|
responseEnd1 = entry.responseEnd;
|
|
assert_equals(entry.element, img);
|
|
}
|
|
else if (entry.identifier === 'my_image2') {
|
|
++numEntries;
|
|
responseEnd2 = entry.responseEnd;
|
|
assert_equals(entry.element, img2);
|
|
}
|
|
});
|
|
if (numEntries == 2) {
|
|
assert_equals(responseEnd1, responseEnd2);
|
|
t.done();
|
|
}
|
|
})
|
|
);
|
|
observer.observe({entryTypes: ['element']});
|
|
// We add the images during onload to be sure that the observer is registered
|
|
// in time for it to observe the element timing.
|
|
window.onload = () => {
|
|
// Add image of width and height equal to 100.
|
|
img = document.createElement('img');
|
|
img.src = 'resources/square100.png';
|
|
img.setAttribute('elementtiming', 'my_image');
|
|
img.setAttribute('id', 'image_id');
|
|
document.body.appendChild(img);
|
|
|
|
img2 = document.createElement('img');
|
|
img2.src = 'resources/square100.png';
|
|
img2.setAttribute('elementtiming', 'my_image2');
|
|
img2.setAttribute('id', 'image_id');
|
|
document.body.appendChild(img2);
|
|
|
|
beforeRender = performance.now();
|
|
};
|
|
}, 'Element with elementtiming attribute is observable.');
|
|
</script>
|
|
|
|
</body>
|