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

[anchor-position] Support testing of polyfill #47156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions css/css-anchor-position/pseudo-element-anchor.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<title>CSS Anchor Positioning: Pseudo elements as anchors</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-1/#position-anchor">
<script src="/resources/testharness.js"></script>
<script src="support/test-common.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.cb {
Expand Down Expand Up @@ -45,11 +46,11 @@
<div id="anchored2" class="anchored"></div>
</div>
<script>
test(() => {
testForAnchorPos(() => {
assert_equals(anchored1.offsetLeft, 100);
assert_equals(anchored1.offsetTop, 100);
}, "::before as anchor");
test(() => {
testForAnchorPos(() => {
assert_equals(anchored2.offsetLeft, 100);
assert_equals(anchored2.offsetTop, 100);
}, "::after as anchor");
Expand Down
16 changes: 16 additions & 0 deletions css/css-anchor-position/support/test-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@ window.checkLayoutForAnchorPos = async function(selectorList, callDone = true) {
}
return window.checkLayout(selectorList, callDone);
}

// This function is a thin wrapper around `promise_test` (from
// resources/testharness.js). It also replaces `test`, but must be a
// promise_test due to potential for awaits. See the description of
// `checkLayoutForAnchorPos` for caveats and intended usage.
window.testForAnchorPos = async function(func, name, properties){
promise_test(async ()=>{
if (window.CHECK_LAYOUT_DELAY) {
assert_equals(window.INJECTED_SCRIPT,undefined,'CHECK_LAYOUT_DELAY is only allowed when serving WPT with --injected-script.');
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
await waitUntilNextAnimationFrame();
}
await func();
}, name, properties)
}