mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
Failing to disconnect the gamepad would cause subsequent gamepad tests to fail if they ran in the same WebView.
58 lines
2.0 KiB
HTML
58 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script src="gamepad-helper.js"></script>
|
|
<script>
|
|
asyncTest(async (done) => {
|
|
const gamepad = internals.connectVirtualGamepad();
|
|
await handleSDLInputEvents();
|
|
listenForGamepadConnected();
|
|
|
|
println(`Before pressing button in top level: ${getStringifiedGamepads()}`);
|
|
gamepad.setButton(gamepad.buttons[0], true);
|
|
await handleSDLInputEvents();
|
|
println(`After pressing button in top level: ${getStringifiedGamepads()}`);
|
|
gamepad.setButton(gamepad.buttons[0], false);
|
|
await handleSDLInputEvents();
|
|
|
|
const iframe = document.createElement("iframe");
|
|
iframe.onload = async () => {
|
|
const sendMessageAndWait = (message) => {
|
|
return new Promise((resolve) => {
|
|
window.onmessage = ({ data }) => {
|
|
resolve(data);
|
|
};
|
|
|
|
iframe.contentWindow.postMessage(message, "*");
|
|
});
|
|
};
|
|
|
|
println(`Gamepad should not be immediately exposed in the new navigable: ${await sendMessageAndWait("getGamepads")}`);
|
|
|
|
// New navigables will automatically connect to available gamepads, otherwise this wouldn't do anything.
|
|
gamepad.setButton(gamepad.buttons[0], true);
|
|
await handleSDLInputEvents();
|
|
|
|
println(`Gamepad is now exposed in the new navigable: ${await sendMessageAndWait("getGamepads")}`);
|
|
|
|
gamepad.disconnect();
|
|
done();
|
|
};
|
|
|
|
iframe.srcdoc = `
|
|
\u003cscript src="gamepad-helper.js"\u003e\u003c/script\u003e
|
|
\u003cscript\u003e
|
|
window.onmessage = async ({ data }) => {
|
|
switch (data) {
|
|
case 'getGamepads':
|
|
window.parent.postMessage(getStringifiedGamepads(), '*');
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
};
|
|
\u003c/script\u003e`;
|
|
|
|
document.body.appendChild(iframe);
|
|
});
|
|
</script>
|