tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xrWebGLBinding_getReflectionCubeMap.https.html (4062B)


      1 <!DOCTYPE html>
      2 <body>
      3  <script src=/resources/testharness.js></script>
      4  <script src=/resources/testharnessreport.js></script>
      5  <script src="../resources/webxr_util.js"></script>
      6  <script src="../resources/webxr_test_constants.js"></script>
      7 
      8  <script>
      9    let testName = "Test that getReflectionCubeMap returns or throws appropriately without a reflection map.";
     10 
     11    let testFunction = (session, controller, t, sessionObjects) => new Promise((resolve) => {
     12      let halfFloatExt = sessionObjects.gl.getExtension('OES_texture_half_float');
     13      // The preferredReflectionFormat used below is set to "rgba16f" by default.
     14      // This means half float textures must be supported in order to run this test
     15      if (!halfFloatExt) {
     16        resolve(session.end());
     17      } else {
     18        let debug = xr_debug.bind(this, 'testFunction');
     19        let lightProbe1 = null;
     20        let binding1 = new XRWebGLBinding(session, sessionObjects.gl);
     21 
     22        // Request a default lightProbe
     23        session.requestLightProbe({reflectionFormat: session.preferredReflectionFormat }).then((probe) => {
     24          // Stash and end session.
     25          lightProbe1 = probe;
     26 
     27          debug("Querying first pair");
     28          t.step(() => {
     29            assert_equals(
     30              binding1.getReflectionCubeMap(lightProbe1),
     31              null,
     32              "Active binding and light probe shouldn't throw when requesting cube map");
     33          });
     34 
     35          return session.end();
     36        }).then(() => {
     37          // Need to request a new session.
     38          navigator.xr.test.simulateUserActivation( () => {
     39            navigator.xr.requestSession('immersive-ar', { 'requiredFeatures': ['light-estimation'] })
     40            .then((newSession) => {
     41              let newBinding = new XRWebGLBinding(newSession, sessionObjects.gl);
     42              newSession.requestLightProbe({ reflectionFormat: newSession.preferredReflectionFormat }).then((newProbe) => {
     43                t.step(() => {
     44                  debug("Querying second pair");
     45                  assert_equals(
     46                    newBinding.getReflectionCubeMap(newProbe),
     47                    null,
     48                    "Newly created binding and light probe shouldn't throw");
     49 
     50                  debug("Querying old pair");
     51                  assert_throws_dom(
     52                    "InvalidStateError",
     53                    () => binding1.getReflectionCubeMap(lightProbe1),
     54                    "Binding created with an ended session should throw InvalidStateError");
     55                  debug("Querying mismatched pair");
     56                  assert_throws_dom(
     57                    "InvalidStateError",
     58                    () => newBinding.getReflectionCubeMap(lightProbe1),
     59                    "Querying binding with a probe with a different backing session should throw InvalidStateError");
     60                });
     61                debug("losing context");
     62 
     63                // Trigger a context loss and verify that we are unable to get the reflectionCubeMap.
     64                let lose_context_ext = sessionObjects.gl.getExtension('WEBGL_lose_context');
     65 
     66                sessionObjects.gl.canvas.addEventListener('webglcontextlost', (ev) => {
     67                  ev.preventDefault();
     68 
     69                  t.step(() => {
     70                    assert_throws_dom(
     71                      "InvalidStateError",
     72                      () => newBinding.getReflectionCubeMap(newProbe),
     73                      "Querying for reflection cube map on a binding with context loss should throw InvalidStateError");
     74                  });
     75 
     76                  resolve(newSession.end());
     77                });
     78 
     79                lose_context_ext.loseContext();
     80              }); // Request second light probe
     81            }); // Request second session
     82          }); // SimulateUserActivation
     83        }); // .then on session end
     84      } // halfFloatExt
     85    }); // testFunction
     86 
     87    xr_session_promise_test(
     88      testName,
     89      testFunction,
     90      IMMERSIVE_AR_DEVICE,
     91      'immersive-ar',
     92      {'requiredFeatures': ['light-estimation']});
     93 
     94  </script>
     95 </body>