chromium/chrome/test/data/xr/e2e_test_files/html/webxr_test_basic_depth_test.html

<!--
Tests that depth API returns non-zero results.
-->
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="../resources/webxr_e2e.css">
  </head>
  <body>
    <canvas id="webgl-canvas"></canvas>
    <script src="../../../../../../third_party/blink/web_tests/resources/testharness.js"></script>
    <script src="../resources/webxr_e2e.js"></script>
    <script>var shouldAutoCreateNonImmersiveSession = false;</script>
    <script src="../resources/webxr_boilerplate.js"></script>
    <script>
      immersiveArSessionInit.requiredFeatures.push('depth-sensing');
      immersiveArSessionInit.depthSensing = {
        usagePreference: ['cpu-optimized'],
        dataFormatPreference: ['luminance-alpha'],
      };

      function stepStartDepthTest() {
        const sessionInfo = sessionInfos[sessionTypes.AR];
        const session = sessionInfo.currentSession;
        const referenceSpace = sessionInfo.currentRefSpace;

        assert_true(session.depthUsage == 'cpu-optimized');
        assert_true(session.depthDataFormat == 'luminance-alpha');

        let lessThan2mSeen = false;
        let moreThan2mSeen = false;

        onARFrameCallback = (session, frame) => {
          console.log('Got AR frame. Seen <2m: ' + lessThan2mSeen +
                      ' Seen >2m: ' + moreThan2mSeen);
          const pose = frame.getViewerPose(referenceSpace);
          if (pose) {
            for (const view of pose.views) {
              const depthInfo = frame.getDepthInformation(view);
              if (depthInfo != null) {
                // Try to grab depth in the middle of the view:
                const depth = depthInfo.getDepthInMeters(0.5, 0.5);
                if (depth != 0) {
                  lessThan2mSeen |= depth < 2.0;
                  moreThan2mSeen |= depth > 2.0;
                }
              }
            }
          }

          if (lessThan2mSeen && moreThan2mSeen) {
            // Finish the test once we saw depths that are less than 2m
            // and more than 2m in some of the frames - the recording that we
            // use is guaranteed to have them.
            done();
          }
        };
      }
    </script>
  </body>
</html>