Files
sousa-gecko/testing/web-platform/tests/container-timing/resources/container-timing-helpers.js
T
Jose Dapena Paz 5ab97ff174 Bug 2013049 [wpt PR 57386] - ContainerTiming: decouple web platform tests from ElementTiming, a=testonly
Automatic update from web-platform-tests
ContainerTiming: decouple web platform tests from ElementTiming

It should be possible to implement ContainerTiming without implementing
ElementTiming. So it should be also possible to test it.

To achieve this, these changes are introduced:
- Element Timing helpers are not used anymore.
- Avoided requiring ElementTiming to wait for checking. When it is not
  available the tests fall back to use a timeout.
- Added internal methods for using ElementTiming and its fallback.
- Simplified the helper API, so now we pass the handler directly when
  we start the wait.

Bug: 477829714
Change-Id: I5b4f90501fdbe10bb42bffef1ecaafa49c270234
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7510867
Reviewed-by: Michal Mocny <mmocny@chromium.org>
Commit-Queue: José Dapena Paz <jdapena@igalia.com>
Cr-Commit-Position: refs/heads/main@{#1576422}

--

wpt-commits: da84729256f7b4f7c7b867f84c962b2983c49520
wpt-pr: 57386
2026-02-03 10:09:14 +00:00

88 lines
2.7 KiB
JavaScript

function checkContainerEntry(entry, identifier, last_element_id, beforeRender) {
assert_equals(entry.entryType, 'container');
assert_equals(entry.name, 'container-paints');
assert_equals(entry.identifier, identifier, 'identifier does not match');
if (last_element_id != null) {
assert_equals(entry.lastPaintedElement.id, last_element_id);
}
assert_equals(entry.duration, 0, 'duration should be 0');
assert_greater_than_equal(
entry.firstRenderTime, beforeRender,
'firstRenderTime greater than beforeRender');
assert_greater_than_equal(
entry.startTime, entry.firstRenderTime,
'startTime greater than beforeRender');
assert_greater_than_equal(
performance.now(), entry.startTime, 'startTime bound by now()')
// PaintTimingMixin
if ("presentationTime" in entry && entry.presentationTime !== null) {
assert_greater_than(entry.presentationTime, entry.paintTime);
assert_equals(entry.presentationTime, entry.startTime);
} else {
assert_equals(entry.startTime, entry.paintTime);
}
}
function checkContainerSize(entry, size) {
assert_equals(entry.size, size);
}
function checkContainerIntersectionRect(entry, expected, description = '') {
assert_equals(
entry.intersectionRect.left, expected[0], 'left of rect ' + description);
assert_equals(
entry.intersectionRect.right, expected[1],
'right of rect ' + description);
assert_equals(
entry.intersectionRect.top, expected[2], 'top of rect ' + description);
assert_equals(
entry.intersectionRect.bottom, expected[3],
'bottom of rect ' + description);
}
// The test wait methods use ElementTiming if available (that should finish
// the tests faster), or use a 2 seconds timeout as a fallback.
// To try the non ElementTiming fallback just set this variable to false.
const is_element_timing_available = !!window.PerformanceElementTiming;
function setupElementTimingWait(func, parent) {
const finish_observer = new PerformanceObserver((entryList) => {
finish_observer.disconnect();
requestAnimationFrame(() => {
func();
});
});
finish_observer.observe({entryTypes: ['element']});
const finish_img = document.createElement('img');
finish_img.src = '/container-timing/resources/square100.png';
finish_img.setAttribute('elementtiming', '');
parent.appendChild(finish_img);
}
function setupTimeoutWait(t, func) {
t.step_timeout(() => {
func();
}, 2000);
}
function setupWait(t, parent, func) {
if (is_element_timing_available) {
setupElementTimingWait(func, parent);
} else {
setupTimeoutWait(t, func);
}
}
function waitAfterTest(t, parent, func) {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
setupWait(t, parent, func);
});
});
}