mirror of
https://github.com/servo/servo.git
synced 2025-08-14 18:05:36 +01:00
Update web-platform-tests to revision ac12b3e9488edb436f063b11213e954ae62d5a5e
This commit is contained in:
parent
65370f17c9
commit
b56a3b8e69
111 changed files with 3122 additions and 68 deletions
|
@ -0,0 +1,110 @@
|
|||
<!DOCTYPE HTML>
|
||||
<meta charset=utf-8>
|
||||
<title>Element Timing: multiple images</title>
|
||||
<body>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
#img1 {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
#img2 {
|
||||
margin-top:150px;
|
||||
margin-left:50px;
|
||||
}
|
||||
</style>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/element-timing-helpers.js"></script>
|
||||
<script>
|
||||
let beforeRender, image1Observed=0, image2Observed=0, image3Observed=0;
|
||||
async_test(function (t) {
|
||||
const observer = new PerformanceObserver(
|
||||
t.step_func(function(entryList) {
|
||||
entryList.getEntries().forEach( entry => {
|
||||
if (entry.name === 'image1') {
|
||||
if (image1Observed) {
|
||||
assert_unreached("Observer received image1 more than once");
|
||||
t.done();
|
||||
}
|
||||
image1Observed = 1;
|
||||
checkElement(entry, 'image1', beforeRender);
|
||||
// This image is horizontally centered.
|
||||
// Using abs and comparing to 1 because the viewport sizes could be odd.
|
||||
// If a size is odd, then image cannot be in the pure center, but left
|
||||
// and right should still be very close to their estimated coordinates.
|
||||
assert_less_than_equal(Math.abs(entry.intersectionRect.left -
|
||||
(document.documentElement.clientWidth / 2 - 50)), 1,
|
||||
'left of rect for image1');
|
||||
assert_less_than_equal(Math.abs(entry.intersectionRect.right -
|
||||
(document.documentElement.clientWidth / 2 + 50)), 1,
|
||||
'right of rect for image1');
|
||||
assert_equals(entry.intersectionRect.top, 0, 'top of rect for image1');
|
||||
assert_equals(entry.intersectionRect.bottom,
|
||||
100, 'bottom of rect for image1');
|
||||
}
|
||||
else if (entry.name === 'image2') {
|
||||
if (image2Observed) {
|
||||
assert_unreached("Observer received image2 more than once");
|
||||
t.done();
|
||||
}
|
||||
image2Observed = 1;
|
||||
checkElement(entry, 'image2', beforeRender);
|
||||
// This image should be below image 1, and should respect the margin.
|
||||
checkRect(entry, [50, 250, 250, 450], "of image2");
|
||||
}
|
||||
else if (entry.name === 'image3') {
|
||||
if (image3Observed) {
|
||||
assert_unreached("Observer received image3 more than once");
|
||||
t.done();
|
||||
}
|
||||
image3Observed = 1;
|
||||
checkElement(entry, 'image3', beforeRender);
|
||||
// This image is just to the right of image2.
|
||||
checkRect(entry, [250, 450, 250, 450], "of image3");
|
||||
}
|
||||
else {
|
||||
assert_unreached("Received an unexpected name.");
|
||||
t.done();
|
||||
}
|
||||
if (image1Observed && image2Observed && image3Observed) {
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
observer.observe({entryTypes: ['element']});
|
||||
function addImage(number, source, width=0) {
|
||||
const img = document.createElement('img');
|
||||
img.src = source;
|
||||
img.id = 'img' + number;
|
||||
img.setAttribute('elementtiming', 'image' + number);
|
||||
if (width !== 0)
|
||||
img.width = width;
|
||||
document.body.appendChild(img);
|
||||
}
|
||||
// Add the images during onload to be sure that the observer is registered in
|
||||
// time to observe the element timing.
|
||||
window.onload = () => {
|
||||
addImage(1, 'resources/square100.png');
|
||||
// Use requestAnimationFrame and a timeout to ensure that the images are
|
||||
// processed in the order we want.
|
||||
requestAnimationFrame( () => {
|
||||
t.step_timeout( () => {
|
||||
// Set the size equal to that of image3 to make positioning easier.
|
||||
addImage(2, 'resources/square20.png', 200);
|
||||
requestAnimationFrame( () => {
|
||||
t.step_timeout( () => {
|
||||
addImage(3, 'resources/circle.svg');
|
||||
}, 0);
|
||||
});
|
||||
}, 0);
|
||||
});
|
||||
beforeRender = performance.now();
|
||||
};
|
||||
}, 'PerformanceObserver can observe multiple image elements.');
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue