Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-scroll-snap-2] Add shadow DOM test for scroll-initial-target #50101

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<!DOCTYPE html>
<html>
<head>
<title> CSS Scroll Snap 2 Test: scroll-initial-target for scroller in shadow DOM</title>
<link rel="help" href="https://drafts.csswg.org/css-scroll-snap-2/#scroll-initial-target">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<style>
.space {
width: 50px;
height: 500px;
}
.scroller {
width: 100px;
height: 100px;
overflow: scroll;
border: solid 2px;
}
.purpleborder {
border: solid 2px purple;
}
.target {
scroll-initial-target: nearest;
width: 50px;
height: 50px;
background-color: green
}
#wrapper {
/* Hide everything initially to ensure that the test sees the scroll */
/* events from the scrolls to the scroll-initial-targets. */
display: none;
}
</style>
<div id="wrapper">
<div id="scroller_before" class="scroller">
<div class="space"></div>
<div class="target"></div>
</div>
<div id="shadowDomHost">
<template shadowrootmode="open">
<style>
.space {
width: 50px;
height: 500px;
}
.scroller {
width: 100px;
height: 100px;
overflow: scroll;
border: solid 2px red;
}
.target {
scroll-initial-target: nearest;
width: 50px;
height: 50px;
background-color: green
}
</style>
<slot name="slot1"></slot>
<div id="shadow_scroller" class="scroller">
<div id="space" class="space"></div>
<div id="target" class="target"></div>
</div>
<slot name="slot2"></slot>
</template>
<div id="slot1scroller" slot="slot1" class="purpleborder scroller">
<div id="space" class="space"></div>
<div class="target"></div>
</div>
<div id="slot2scroller" slot="slot2" class="purpleborder scroller">
<div id="space" class="space"></div>
<div class="target"></div>
</div>
</div>
<div id="scroller_after" class="scroller">
<div class="space"></div>
<div class="target"></div>
</div>
</div>
<script>
const scroller_before = document.getElementById("scroller_before");
const slot1scroller = document.getElementById("slot1scroller");
const shadow_scroller =
shadowDomHost.shadowRoot.querySelector(".scroller");
const slot2scroller = document.getElementById("slot2scroller");
const scroller_after = document.getElementById("scroller_after");

const scrollers = [scroller_before, slot1scroller, shadow_scroller,
slot2scroller, scroller_after];
const scroll_log = [];

function setUpLogging() {
let promises = [];
for (const scroller of scrollers) {
promises.push(new Promise((resolve) => {
scroller.addEventListener("scroll", () => {
scroll_log.push(scroller.id);
resolve();
}, { once: true });
}));
}
return Promise.all(promises);
}

function verifyScrollPositions() {
for (const scroller of scrollers) {
// Each scroller's target is at the scroller's very bottom so the
// scroller should be scrolled all the way down.
assert_equals(scroller.scrollTop,
scroller.scrollHeight - scroller.clientHeight,
`${scroller.id} is scrolled to its target`);
}
}

promise_test(async (t) => {
// Arm the promises that should be resolved due to scrolling to the
// scroll-initial-targets.
const scroll_promises = setUpLogging();

const wrapper = document.getElementById("wrapper");
wrapper.style.display = "initial";

await scroll_promises;

// Verify that the order in which the scroll containers were scrolled
// matches flat tree order.
assert_array_equals(scroll_log, ["scroller_before", "slot1scroller",
"shadow_scroller", "slot2scroller", "scroller_after"]);

verifyScrollPositions();
}, "scroll-initial-target in shadow DOM is scrolled to initially.");
</script>
</body>
</html>
Loading