diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /testing/web-platform/tests/css/css-scroll-snap-2/resources | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/css-scroll-snap-2/resources')
3 files changed, 32 insertions, 79 deletions
diff --git a/testing/web-platform/tests/css/css-scroll-snap-2/resources/common.js b/testing/web-platform/tests/css/css-scroll-snap-2/resources/common.js index a3591d48ed..8dce29474d 100644 --- a/testing/web-platform/tests/css/css-scroll-snap-2/resources/common.js +++ b/testing/web-platform/tests/css/css-scroll-snap-2/resources/common.js @@ -26,13 +26,15 @@ async function snap_test_setup(test, scroller, event_type) { }); } -async function test_snap_event(test, test_data, event_type) { +async function test_snap_event(test, test_data, event_type, + use_onsnap_member = false) { await snap_test_setup(test, test_data.scroller, event_type); let listener = test_data.scroller == document.scrollingElement ? document : test_data.scroller; - const event_promise = waitForSnapEvent(listener, event_type); + const event_promise = waitForSnapEvent(listener, event_type, true, + use_onsnap_member); await test_data.scrolling_function(); let evt = await event_promise; @@ -45,19 +47,36 @@ async function test_snap_event(test, test_data, event_type) { "horizontal scroll offset mismatch."); } -async function test_snapchanged(test, test_data) { - await test_snap_event(test, test_data, "snapchanged"); +async function test_snapchanged(test, test_data, use_onsnap_member = false) { + await test_snap_event(test, test_data, "snapchanged", use_onsnap_member); } -function waitForEventUntil(event_target, event_type, wait_until) { +function waitForEventUntil(event_target, event_type, wait_until, + use_onsnap_member = false) { return new Promise(resolve => { let result = null; const listener = (evt) => { result = evt; }; - event_target.addEventListener(event_type, listener); + if (use_onsnap_member) { + if (event_type === "snapchanging") { + event_target.onsnapchanging = listener; + } else { + event_target.onsnapchanged = listener; + } + } else { + event_target.addEventListener(event_type, listener); + } wait_until.then(() => { - event_target.removeEventListener(event_type, listener); + if (use_onsnap_member) { + if (event_type === "snapchanging") { + event_target.onsnapchanging = null; + } else { + event_target.onsnapchanged = null; + } + } else { + event_target.removeEventListener(event_type, listener); + } resolve(result); }); }); @@ -77,30 +96,19 @@ function waitForEventsUntil(event_target, event_type, wait_until) { }); } -function waitForOnSnapchanging(event_target) { - return new Promise(resolve => { - let result = null; - const listener = (evt) => { - result = evt; - }; - event_target.onsnapchanging = listener; - waitForScrollendEventNoTimeout(event_target).then(() => { - event_target.onsnapchanging = null; - resolve(result); - }); - }); -} - // Proxy a wait for a snap event. We want to avoid having a test // timeout in the event of an expected snap event not firing in a particular // test case as that would cause the entire file to fail. // Snap events should fire before scrollend, so if a scroll should happen, wait // for a scrollend event. Otherwise, just do a rAF-based wait. -function waitForSnapEvent(event_target, event_type, scroll_happens = true) { +function waitForSnapEvent(event_target, event_type, scroll_happens = true, + use_onsnap_member = false) { return scroll_happens ? waitForEventUntil(event_target, event_type, - waitForScrollendEventNoTimeout(event_target)) + waitForScrollendEventNoTimeout(event_target), + use_onsnap_member) : waitForEventUntil(event_target, event_type, - waitForAnimationFrames(2)); + waitForAnimationFrames(2), + use_onsnap_member); } function waitForSnapChangedEvent(event_target, scroll_happens = true) { diff --git a/testing/web-platform/tests/css/css-scroll-snap-2/resources/programmatic-scroll-common.js b/testing/web-platform/tests/css/css-scroll-snap-2/resources/programmatic-scroll-common.js deleted file mode 100644 index 8257b98fe3..0000000000 --- a/testing/web-platform/tests/css/css-scroll-snap-2/resources/programmatic-scroll-common.js +++ /dev/null @@ -1,26 +0,0 @@ -// Helper functions for snapchanged-on-programmatic-* tests. - -// Utility function to test that onsnapchanging is triggered for -// snapchanging-on-programmatic-* tests which set up a similar layout in which -// the |scroller| has 3 snap targets that form a vertical column along -// |scroller|'s middle. onsnapchanging should be triggered by conducting a -// programmatic scroll to the top of snap_target. -async function test_programmatic_scroll_onsnapchanging(test, - scroller, - event_target, - snap_target) { - await snap_test_setup(test, scroller, "snapchanging"); - const expected_snap_targets = { block: snap_target, inline: null }; - - // Scroll and wait for a snapchanging event. - const snapchanging_promise = waitForOnSnapchanging(event_target); - scroller.scrollTo(0, snap_target.offsetTop); - const snapchanging_event = await snapchanging_promise; - - // Assert that snapchanging fired and indicated that snap_target would - // be snapped to. - assertSnapEvent(snapchanging_event, expected_snap_targets); - assert_equals(scroller.scrollLeft, 0, "scrollLeft is zero"); - assert_equals(scroller.scrollTop, snap_target.offsetTop, - "snapped to snap_target"); -} diff --git a/testing/web-platform/tests/css/css-scroll-snap-2/resources/user-scroll-common.js b/testing/web-platform/tests/css/css-scroll-snap-2/resources/user-scroll-common.js index 820f143816..07c1428633 100644 --- a/testing/web-platform/tests/css/css-scroll-snap-2/resources/user-scroll-common.js +++ b/testing/web-platform/tests/css/css-scroll-snap-2/resources/user-scroll-common.js @@ -69,32 +69,3 @@ async function test_no_snapchanged(t, scroller, delta) { async function test_no_snapchanging(t, scroller, delta) { await test_no_snap_event(t, scroller, delta, "snapchanging"); } - -// Utility function to test that onsnapchanging is triggered for -// snapchanging-on-user-* tests which set up a similar layout in which -// the |scroller| has 3 snap targets that form a vertical column along -// |scroller|'s middle. onsnapchanging should be triggered by touch-dragging -// |scroller|'s content so that |snap_target|'s top aligns to |snap_target|. -async function test_user_scroll_onsnapchanging(test, scroller, event_target, - snap_target) { - await snap_test_setup(test, scroller, "snapchanging"); - - // Compute touch positions to drag the top of snap_target to the top of - // the scroller. - const scroller_middle = Math.round(scroller.clientWidth / 2); - const start_pos = { x: scroller_middle, y: snap_target.offsetTop }; - const end_pos = { x: scroller_middle, y: 0 }; - const expected_snap_targets = { block: snap_target, inline: null }; - - // Scroll and wait for a snapchanging event. - const snapchanging_promise = waitForOnSnapchanging(event_target); - await snap_event_touch_scroll_helper(start_pos, end_pos); - const snapchanging_event = await snapchanging_promise; - - // Assert that snapchanging fired and indicated that snap_target would - // be snapped to. - assertSnapEvent(snapchanging_event, expected_snap_targets); - assert_equals(scroller.scrollLeft, 0, "scrollLeft is zero"); - assert_equals(scroller.scrollTop, snap_target.offsetTop, - "snapped to snap_target"); -} |