events_session_select.https.html (3844B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="resources/webxr_util.js"></script> 5 <script src="resources/webxr_test_constants.js"></script> 6 7 <script> 8 let testName = "XRInputSources primary input presses properly fires off the " 9 + "right events"; 10 11 let watcherDone = new Event("watcherdone"); 12 13 let fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE; 14 15 let xrViewerSpace = null; 16 17 let testFunction = function(session, fakeDeviceController, t) { 18 let eventWatcher = new EventWatcher( 19 t, session, ["selectstart", "select", "selectend", "watcherdone"]); 20 let eventPromise = eventWatcher.wait_for( 21 ["selectstart", "select", "selectend", "watcherdone"]); 22 23 function tryCallingFrameMethods(frame) { 24 t.step(() => { 25 // Frame is active but not an animation frame, so calling getPose is 26 // allowed while getViewerPose is not. 27 assert_throws_dom('InvalidStateError', () => frame.getViewerPose(currentReferenceSpace)); 28 let pose = frame.getPose(xrViewerSpace, currentReferenceSpace); 29 assert_not_equals(pose, null); 30 assert_true(pose instanceof XRPose); 31 assert_false(pose instanceof XRViewerPose); 32 }); 33 } 34 35 function onSessionSelectStart(event) { 36 t.step( () => { 37 let input_sources = session.inputSources; 38 assert_equals(event.frame.session, session); 39 assert_equals(event.inputSource, input_sources[0]); 40 validateSameObject(event); 41 tryCallingFrameMethods(event.frame); 42 }); 43 } 44 45 function onSessionSelectEnd(event) { 46 t.step( () => { 47 let input_sources = session.inputSources; 48 assert_equals(event.frame.session, session); 49 assert_equals(event.inputSource, input_sources[0]); 50 validateSameObject(event); 51 tryCallingFrameMethods(event.frame); 52 }); 53 session.dispatchEvent(watcherDone); 54 } 55 56 function onSessionSelect(event) { 57 t.step( () => { 58 let input_sources = session.inputSources; 59 assert_equals(event.frame.session, session); 60 assert_equals(event.inputSource, input_sources[0]); 61 validateSameObject(event); 62 tryCallingFrameMethods(event.frame); 63 }); 64 } 65 66 // Verifies that the same object is returned each time attributes are accessed 67 // on an XRInputSourceEvent, as required by the spec. 68 function validateSameObject(event) { 69 let frame = event.frame; 70 let source = event.inputSource; 71 t.step(() => { 72 assert_equals(frame, event.frame, 73 "XRInputSourceEvent.frame returns the same object."); 74 assert_equals(source, event.inputSource, 75 "XRInputSourceEvent.inputSource returns the same object."); 76 }); 77 } 78 79 session.addEventListener("selectstart", onSessionSelectStart, false); 80 session.addEventListener("selectend", onSessionSelectEnd, false); 81 session.addEventListener("select", onSessionSelect, false); 82 83 let input_source = 84 fakeDeviceController.simulateInputSourceConnection(VALID_CONTROLLER); 85 let currentReferenceSpace = null; 86 87 session.requestReferenceSpace('viewer').then(function(viewerSpace) { 88 xrViewerSpace = viewerSpace; 89 90 session.requestReferenceSpace('local').then((referenceSpace) => { 91 currentReferenceSpace = referenceSpace; 92 93 // Press the primary input button and then release it a short time later. 94 requestSkipAnimationFrame(session, (time, xrFrame) => { 95 input_source.startSelection(); 96 97 session.requestAnimationFrame((time, xrFrame) => { 98 input_source.endSelection(); 99 100 session.requestAnimationFrame((time, xrFrame) => { 101 // Need to process one more frame to allow select to propegate. 102 }); 103 }); 104 }); 105 }); 106 }); 107 108 return eventPromise; 109 }; 110 111 xr_session_promise_test( 112 testName, testFunction, fakeDeviceInitParams, 'immersive-vr'); 113 114 </script>