ar_hittest_subscription_unlocalizable.https.html (3845B)
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_math_utils.js"></script> 6 <script src="../resources/webxr_test_asserts.js"></script> 7 <script src="../resources/webxr_test_constants.js"></script> 8 <script src="../resources/webxr_test_constants_fake_world.js"></script> 9 10 <script> 11 12 // 1m above world origin. 13 const VIEWER_ORIGIN_TRANSFORM = { 14 position: [0, 1, 0], 15 orientation: [0, 0, 0, 1], 16 }; 17 18 // 0.25m above world origin. 19 const FLOOR_ORIGIN_TRANSFORM = { 20 position: [0, 0.25, 0], 21 orientation: [0, 0, 0, 1], 22 }; 23 24 const fakeDeviceInitParams = { 25 supportedModes: ["immersive-ar"], 26 views: VALID_VIEWS, 27 floorOrigin: FLOOR_ORIGIN_TRANSFORM, // aka mojo_from_floor 28 viewerOrigin: VIEWER_ORIGIN_TRANSFORM, // aka mojo_from_viewer 29 supportedFeatures: ALL_FEATURES, 30 world: createFakeWorld(5.0, 2.0, 5.0), // webxr_test_constants_fake_world.js has detailed description of the fake world 31 }; 32 33 // Generates a test function given the parameters for the hit test. It will subscribe 34 // to a hit test using |refSpaceName| and |ray|, and attempt to obtain poses from returned hit 35 // test results using a space that is known to be unlocalizable, with the expectation of 36 // obtaining a null pose for each hit test result. 37 // |ray| - ray that will be used to subscribe to hit test. 38 // |refSpaceName| - XRReferenceSpaceType - either 'local', 'local-floor' or 'viewer'. 39 let testFunctionGenerator = function(ray, refSpaceName) { 40 const testFunction = function(session, fakeDeviceController, t) { 41 42 const input_source_controller = fakeDeviceController.simulateInputSourceConnection({ 43 handedness: "right", 44 targetRayMode: "tracked-pointer", 45 pointerOrigin: IDENTITY_TRANSFORM, 46 profiles: [] 47 }); 48 49 return Promise.all([ 50 session.requestReferenceSpace('local'), 51 session.requestReferenceSpace('viewer'), 52 session.requestReferenceSpace('local-floor'), 53 ]).then(([localRefSpace, viewerRefSpace, localFloorRefSpace]) => { 54 55 const refSpaceNameToSpace = { 56 'local' : localRefSpace, 57 'viewer' : viewerRefSpace, 58 'local-floor' : localFloorRefSpace 59 }; 60 61 const hitTestOptionsInit = { 62 space: refSpaceNameToSpace[refSpaceName], 63 offsetRay: ray, 64 }; 65 66 return session.requestHitTestSource(hitTestOptionsInit).then( 67 (hitTestSource) => new Promise((resolve, reject) => { 68 69 const requestAnimationFrameCallback = function(time, frame) { 70 71 const hitTestResults = frame.getHitTestResults(hitTestSource); 72 73 t.step(() => { 74 assert_true(session.inputSources.length > 0, "session.inputSources should not be empty!"); 75 assert_true(hitTestResults.length > 0, "Results should not be empty!"); 76 77 const input_source = session.inputSources[0]; 78 79 for(const [index, hitTestResult] of hitTestResults.entries()) { 80 const pose = hitTestResult.getPose(input_source.targetRaySpace); 81 assert_true(pose == null, "Pose should be null since input source is not localizable"); 82 } 83 }); 84 85 resolve(); 86 }; 87 88 t.step(() => { 89 assert_true(hitTestSource != null, "Hit test source should not be null"); 90 }); 91 92 session.requestAnimationFrame(requestAnimationFrameCallback); 93 })); 94 }); 95 }; 96 97 return testFunction; 98 }; 99 100 // All test cases require local-floor and hit-test. 101 const sessionInit = { 'requiredFeatures': ['local-floor', 'hit-test'] }; 102 103 xr_session_promise_test( 104 "Ensures hit test result returns null pose w/unlocalizable space - viewer space", 105 testFunctionGenerator(new XRRay(), 'viewer'), 106 fakeDeviceInitParams, 'immersive-ar', sessionInit); 107 108 </script>