test_hide_gamepad_info_iframe.html (1223B)
1 <!DOCTYPE html> 2 <meta charset="utf8"> 3 <!--<script src="/tests/SimpleTest/SimpleTest.js"></script>--> 4 <script> 5 var SimpleTest = window.parent.SimpleTest; 6 7 function forceFail() { 8 SimpleTest.ok( 9 false, 10 "privacy.resistFingerprinting is true, should not receive any gamepad events" 11 ); 12 } 13 14 window.addEventListener("gamepadconnected", forceFail); 15 window.addEventListener("gamepaddisconnected", forceFail); 16 window.addEventListener("gamepadbuttondown", forceFail); 17 18 window.addEventListener("load", async () => { 19 const service = navigator.requestGamepadServiceTest(); 20 const buttonIndex = await service.addGamepad( 21 "test gamepad", // id 22 service.standardMapping, 23 service.noHand, 24 4, // buttons 25 2, 26 0, 27 0, 28 0 29 ); 30 31 // Press a button to make the gamepad visible to the page. 32 await service.newButtonEvent(buttonIndex, 0, true, true); 33 34 const { length } = navigator.getGamepads(); 35 SimpleTest.is( 36 length, 37 0, 38 "privacy.resistFingerprinting is true, navigator.getGamepads() should always return an empty array" 39 ); 40 41 // Attempt to force gamepad events to be fired, by simulating gamepad disconnect 42 await service.removeGamepad(buttonIndex); 43 SimpleTest.finish(); 44 }); 45 </script>