Skip to content

Commit

Permalink
test: update dom/events wpt
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Sep 30, 2024
1 parent 317d245 commit e9a5c8a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Last update:
- compression: https://github.com/web-platform-tests/wpt/tree/5aa50dd415/compression
- console: https://github.com/web-platform-tests/wpt/tree/767ae35464/console
- dom/abort: https://github.com/web-platform-tests/wpt/tree/0143fe244b/dom/abort
- dom/events: https://github.com/web-platform-tests/wpt/tree/0a811c5161/dom/events
- dom/events: https://github.com/web-platform-tests/wpt/tree/922a7fe9a4/dom/events
- encoding: https://github.com/web-platform-tests/wpt/tree/1ac8deee08/encoding
- fetch/data-urls/resources: https://github.com/web-platform-tests/wpt/tree/7c79d998ff/fetch/data-urls/resources
- FileAPI: https://github.com/web-platform-tests/wpt/tree/cceaf3628d/FileAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

function onOverscroll(event) {
assert_false(event.cancelable);
// overscroll events targeting document are bubbled to the window.
// overscroll events targetting document are bubbled to the window.
assert_true(event.bubbles);
window_received_overscroll = true;
}
Expand Down
37 changes: 36 additions & 1 deletion test/fixtures/wpt/dom/events/scrolling/scroll_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,41 @@ async function waitForScrollendEventNoTimeout(target) {
});
}

// Waits until a rAF callback with no "scroll" event in the last 200ms.
function waitForDelayWithoutScrollEvent(eventTarget) {
const TIMEOUT_IN_MS = 200;

return new Promise(resolve => {
let lastScrollEventTime = performance.now();

const scrollListener = () => {
lastScrollEventTime = performance.now();
};
eventTarget.addEventListener('scroll', scrollListener);

const tick = () => {
if (performance.now() - lastScrollEventTime > TIMEOUT_IN_MS) {
eventTarget.removeEventListener('scroll', scrollListener);
resolve();
return;
}
requestAnimationFrame(tick); // wait another frame
}
requestAnimationFrame(tick);
});
}

// Waits for the end of scrolling. Uses the "scrollend" event if available.
// Otherwise, fall backs to waitForDelayWithoutScrollEvent().
function waitForScrollEndFallbackToDelayWithoutScrollEvent(eventTarget) {
if (window.onscrollend !== undefined) {
return waitForScrollendEventNoTimeout(eventTarget);
}
return waitForScrollEvent(eventTarget).then(() => {
return waitForDelayWithoutScrollEvent(eventTarget);
});
}

async function waitForPointercancelEvent(test, target, timeoutMs = 500) {
return waitForEvent("pointercancel", test, target, timeoutMs);
}
Expand Down Expand Up @@ -88,7 +123,7 @@ const MAX_UNCHANGED_FRAMES = 20;
function waitFor(condition, error_message = 'Reaches the maximum frames.') {
return new Promise((resolve, reject) => {
function tick(frames) {
// We requestAnimationFrame either for MAX_FRAME frames or until condition
// We requestAnimationFrame either for MAX_FRAM frames or until condition
// is met.
if (frames >= MAX_FRAME)
reject(error_message);
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"path": "dom/abort"
},
"dom/events": {
"commit": "0a811c51619b14f78fec60ba7dd1603795ca6a21",
"commit": "922a7fe9a4f5bffd0161e11b38bac8f76ef03efd",
"path": "dom/events"
},
"encoding": {
Expand Down

0 comments on commit e9a5c8a

Please sign in to comment.