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

<!doctype html>
<!--
Tests that it is always possible to create an inline session and access the
identity reference space
-->
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="../resources/webxr_e2e.css">
  </head>
  <body>
    <script src="../../../../../../third_party/blink/web_tests/resources/testharness.js"></script>
    <script src="../resources/webxr_e2e.js"></script>
    <script>
      let session = null;
      let testFrames = 5;
      let numFramesReceived = 0;
      function onRequestAnimationFrame() {
        if (session === null) {
          assert_unreached("Session should not be null");
        }

        numFramesReceived++;
        console.log('Received frame ' + numFramesReceived);
        if (numFramesReceived < testFrames) {
          session.requestAnimationFrame(onRequestAnimationFrame);
        } else {
          done();
        }
      }

      // TODO (crbug.com/934912): Consider improving flow once methods are
      // updated.
      let step = "supportsInline";
      console.log('Checking inline support');
      navigator.xr.isSessionSupported('inline')
      .then((supported)=> {
        assert_true(supported);
        step = "requestSession";
        console.log(
            'Inline support found, requesting inline session');
        return navigator.xr.requestSession('inline');
      })
      .then((xrSession) => {
        session = xrSession;

        step = "requestReferenceSpace";
        console.log('Got inline session, requesting viewer reference space');
        return xrSession.requestReferenceSpace('viewer');
      })
      .then((referenceSpace) => {
        assert_not_equals(referenceSpace, null);
        step = "Request Animation Frames";

        // Create an offscreen canvas and get its context
        let offscreenCanvas = document.createElement('canvas');
        let gl = offscreenCanvas.getContext('webgl', { xrCompatible: true });
        if (!gl) {
          throw 'Failed to get WebGL context';
        }

        console.log('Got reference space, updating render state base layer');
        session.updateRenderState({
            baseLayer: new XRWebGLLayer(session, gl)
        });
        console.log('Starting rAF loop');
        session.requestAnimationFrame(onRequestAnimationFrame);
      })
      .catch((err) => {
        assert_unreached("Failed with " + err + " at step " + step);
      });
    </script>
  </body>
</html>