haikuwebkit/LayoutTests/gamepad/gamepad-timestamp.html

94 lines
2.4 KiB
HTML
Raw Permalink Normal View History

<head>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
function log(msg)
{
document.getElementById("logger").innerHTML += msg + "<br>";
}
function finishTest()
{
if (testRunner)
testRunner.notifyDone();
}
var rafCount = 0;
var increasingTimestampsSeen = 0;
var timestamp = 0;
var gamepad2Timestamp = -1;
function rafCallback()
{
var gamepad = navigator.getGamepads()[0];
var gamepad2 = navigator.getGamepads()[1];
if (gamepad2Timestamp == -1)
gamepad2Timestamp = gamepad2.timestamp;
if (gamepad2Timestamp != gamepad2.timestamp) {
log("Timestamp of gamepad 2 should never change throughout this test, but it did!");
finishTest();
}
if (gamepad.timestamp < timestamp) {
log("Timestamp on gamepad is " + gamepad.timestamp + " which is less than " + timestamp);
finishTest();
}
if (gamepad.timestamp > timestamp)
++increasingTimestampsSeen;
if (increasingTimestampsSeen == 10) {
log("Increasing timestamp values seen for 10 RAF cycles");
finishTest();
}
if (++rafCount == 120) {
log("Went 120 RAF cycles without seeing 10 increasing timestamp values... yikes!");
log("Number of actual timestamp increases seen: " + increasingTimestampsSeen);
finishTest();
}
timestamp = gamepad.timestamp;
if (gamepad.buttons[0] == 1.0)
testRunner.setMockGamepadButtonValue(0, 0, 0.0);
else
testRunner.setMockGamepadButtonValue(0, 0, 1.0);
requestAnimationFrame(rafCallback);
}
function handleGamepadConnect()
{
requestAnimationFrame(rafCallback);
}
function runTest() {
addEventListener("gamepadconnected", handleGamepadConnect);
Standard gamepad mapping for GameControllerGamepads https://bugs.webkit.org/show_bug.cgi?id=206033 Patch by James Howard <jameshoward@mac.com> on 2020-02-10 Reviewed by Dean Jackson. Source/WebCore: Extend PlatformGamepad to add a field for the gamepad mapping. The mapping defines the order and interpretation of the axes and buttons vectors, and is passed along to users of the Gamepad API[1]. Letting PlatformGamepad subclassers define their mapping is the natural place for this functionality. The PlatformGamepad already defines the order of the axes and buttons and PlatformGamepad subclassers may know something about the physical layout of the gamepad they represent. This change modifies the GameControllerGamepad subclass of PlatformGamepad to set the mapping to "standard" when a GCExtendedGamepad is detected, and to bind the axes and buttons appropriately. Previously, the buttons and axes were bound arbitrarily, and in some cases incompletely. While that wasn't a bug per se, because with the mapping set to the empty string an implementation is free to provide any interpretation of the gamepad elements it likes, it was certainly less useful than the "standard" mapping. [1] https://www.w3.org/TR/gamepad/#remapping * Modules/gamepad/Gamepad.cpp: (WebCore::Gamepad::Gamepad): * platform/gamepad/PlatformGamepad.h: (WebCore::PlatformGamepad::mapping const): * platform/gamepad/cocoa/GameControllerGamepad.mm: (WebCore::GameControllerGamepad::setupAsExtendedGamepad): * testing/MockGamepad.cpp: (WebCore::MockGamepad::MockGamepad): (WebCore::MockGamepad::updateDetails): * testing/MockGamepad.h: * testing/MockGamepadProvider.cpp: (WebCore::MockGamepadProvider::setMockGamepadDetails): * testing/MockGamepadProvider.h: * testing/js/WebCoreTestSupport.cpp: (WebCoreTestSupport::setMockGamepadDetails): * testing/js/WebCoreTestSupport.h: Source/WebKit: Make the mapping as provided by PlatformGamepad available in UIGamepad, and pass it along to GamepadData so it can be correctly reflected in the Gamepad API. * Shared/Gamepad/GamepadData.cpp: (WebKit::GamepadData::GamepadData): (WebKit::GamepadData::encode const): (WebKit::GamepadData::decode): * Shared/Gamepad/GamepadData.h: (WebKit::GamepadData::mapping const): * UIProcess/Gamepad/UIGamepad.cpp: (WebKit::UIGamepad::UIGamepad): (WebKit::UIGamepad::fullGamepadData const): * UIProcess/Gamepad/UIGamepad.h: * WebProcess/Gamepad/WebGamepad.cpp: (WebKit::WebGamepad::WebGamepad): Tools: * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setMockGamepadDetails): * WebKitTestRunner/InjectedBundle/TestRunner.h: * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): LayoutTests: * gamepad/gamepad-polling-access-expected.txt: * gamepad/gamepad-polling-access.html: * gamepad/gamepad-timestamp.html: * gamepad/gamepad-visibility-1.html: Canonical link: https://commits.webkit.org/220496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256215 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-02-10 22:38:22 +00:00
testRunner.setMockGamepadDetails(0, "Test Joystick", "", 2, 2);
testRunner.setMockGamepadAxisValue(0, 0, 0.7);
testRunner.setMockGamepadAxisValue(0, 1, -1.0);
testRunner.setMockGamepadButtonValue(0, 0, 1.0);
testRunner.setMockGamepadButtonValue(0, 1, 1.0);
testRunner.connectMockGamepad(0);
Standard gamepad mapping for GameControllerGamepads https://bugs.webkit.org/show_bug.cgi?id=206033 Patch by James Howard <jameshoward@mac.com> on 2020-02-10 Reviewed by Dean Jackson. Source/WebCore: Extend PlatformGamepad to add a field for the gamepad mapping. The mapping defines the order and interpretation of the axes and buttons vectors, and is passed along to users of the Gamepad API[1]. Letting PlatformGamepad subclassers define their mapping is the natural place for this functionality. The PlatformGamepad already defines the order of the axes and buttons and PlatformGamepad subclassers may know something about the physical layout of the gamepad they represent. This change modifies the GameControllerGamepad subclass of PlatformGamepad to set the mapping to "standard" when a GCExtendedGamepad is detected, and to bind the axes and buttons appropriately. Previously, the buttons and axes were bound arbitrarily, and in some cases incompletely. While that wasn't a bug per se, because with the mapping set to the empty string an implementation is free to provide any interpretation of the gamepad elements it likes, it was certainly less useful than the "standard" mapping. [1] https://www.w3.org/TR/gamepad/#remapping * Modules/gamepad/Gamepad.cpp: (WebCore::Gamepad::Gamepad): * platform/gamepad/PlatformGamepad.h: (WebCore::PlatformGamepad::mapping const): * platform/gamepad/cocoa/GameControllerGamepad.mm: (WebCore::GameControllerGamepad::setupAsExtendedGamepad): * testing/MockGamepad.cpp: (WebCore::MockGamepad::MockGamepad): (WebCore::MockGamepad::updateDetails): * testing/MockGamepad.h: * testing/MockGamepadProvider.cpp: (WebCore::MockGamepadProvider::setMockGamepadDetails): * testing/MockGamepadProvider.h: * testing/js/WebCoreTestSupport.cpp: (WebCoreTestSupport::setMockGamepadDetails): * testing/js/WebCoreTestSupport.h: Source/WebKit: Make the mapping as provided by PlatformGamepad available in UIGamepad, and pass it along to GamepadData so it can be correctly reflected in the Gamepad API. * Shared/Gamepad/GamepadData.cpp: (WebKit::GamepadData::GamepadData): (WebKit::GamepadData::encode const): (WebKit::GamepadData::decode): * Shared/Gamepad/GamepadData.h: (WebKit::GamepadData::mapping const): * UIProcess/Gamepad/UIGamepad.cpp: (WebKit::UIGamepad::UIGamepad): (WebKit::UIGamepad::fullGamepadData const): * UIProcess/Gamepad/UIGamepad.h: * WebProcess/Gamepad/WebGamepad.cpp: (WebKit::WebGamepad::WebGamepad): Tools: * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setMockGamepadDetails): * WebKitTestRunner/InjectedBundle/TestRunner.h: * WebKitTestRunner/TestInvocation.cpp: (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): LayoutTests: * gamepad/gamepad-polling-access-expected.txt: * gamepad/gamepad-polling-access.html: * gamepad/gamepad-timestamp.html: * gamepad/gamepad-visibility-1.html: Canonical link: https://commits.webkit.org/220496@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256215 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-02-10 22:38:22 +00:00
testRunner.setMockGamepadDetails(1, "Test Joystick 2", "", 2, 2);
testRunner.setMockGamepadAxisValue(1, 0, 0.7);
testRunner.setMockGamepadAxisValue(1, 1, -1.0);
testRunner.setMockGamepadButtonValue(1, 0, 1.0);
testRunner.setMockGamepadButtonValue(1, 1, 1.0);
testRunner.connectMockGamepad(1);
}
</script>
</head>
<body onload="runTest();">
<div id="logger"></div>
</body>