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

WebKit export of https://bugs.webkit.org/show_bug.cgi?id=218054 #49536

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
37 changes: 37 additions & 0 deletions pointerlock/pointerlock_promise.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<body>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
</head>
<body>
<h2>Description</h2>
<p>This test validates that pointer lock returns a Promise.</p>
<hr/>

<button id="Button">lockTarget</button>

<div id="target">Target</div>

<script type="text/javascript" >
const button = document.getElementById('Button');
const target = document.getElementById('target');

async_test(t => {
button.addEventListener('mousedown', t.step_func(async () => {
const promise = target.requestPointerLock();
assert_true(promise instanceof Promise, "Test that requestPointerLock() returns Promise.");
await promise;
t.done();
}));
});

// Automated testing
test_driver.click(button);
</script>
</body>
</html>
42 changes: 42 additions & 0 deletions pointerlock/pointerlock_unadjustedMovement.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
</head>
<body>
<h2>Description</h2>
<p>This test validates that pointer lock accepts the unadjustedMovement option.</p>
<hr/>

<button id="Button">lockTarget</button>
<div id="target">Target</div>

<script type="text/javascript" >
const button = document.getElementById('Button');
const target = document.getElementById('target');

async_test(t => {
button.addEventListener('mousedown', t.step_func(() => {
const p = target.requestPointerLock({unadjustedMovement: true});
p.then(t.step_func(() => {
assert_equals(document.pointerLockElement, target);
t.done();
})).catch(t.step_func((error) => {
// requestPointerLock may throw NotSupportedError to say unadjustedMovement isn't supported.
assert_throws_dom("NotSupportedError", () => { throw error; });
// but to pass this test fully, it unadjustedMovement must be supported.
assert_unreached("unadjustedMovement must be implemented.");
t.done();
}));
}));
});

// Automated testing
test_driver.click(button);
</script>
</body>
</html>
34 changes: 34 additions & 0 deletions pointerlock/pointerlock_without_gesture.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<body>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
</head>
<body>
<h2>Description</h2>
<p>This test validates that pointer lock does not work without user activation.</p>
<hr/>

<div id="target">Target</div>

<script type="text/javascript" >
promise_test(async t => {
const target = document.getElementById('target');

document.addEventListener('pointerlockchange', t.unreached_func("Must not acquire pointer lock."));

// Request pointer lock twice to ensure two failing promises are returned and both are rejected.
const p1 = target.requestPointerLock();
const p2 = target.requestPointerLock();

// ensure that both promises are rejected
await promise_rejects_dom(t, "NotAllowedError", p1);
await promise_rejects_dom(t, "NotAllowedError", p2);
});
</script>
</body>
</html>