summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/light-estimation/xrWebGLBinding_getReflectionCubeMap.https.html
blob: a68a0f2b5125459e6294a75a996a742ad996edde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<body>
  <script src=/resources/testharness.js></script>
  <script src=/resources/testharnessreport.js></script>
  <script src="../resources/webxr_util.js"></script>
  <script src="../resources/webxr_test_constants.js"></script>

  <script>
    let testName = "Test that getReflectionCubeMap returns or throws appropriately without a reflection map.";

    let testFunction = (session, controller, t, sessionObjects) => new Promise((resolve) => {
      let halfFloatExt = sessionObjects.gl.getExtension('OES_texture_half_float');
      // The preferredReflectionFormat used below is set to "rgba16f" by default.
      // This means half float textures must be supported in order to run this test
      if (!halfFloatExt) {
        resolve(session.end());
      } else {
        let debug = xr_debug.bind(this, 'testFunction');
        let lightProbe1 = null;
        let binding1 = new XRWebGLBinding(session, sessionObjects.gl);

        // Request a default lightProbe
        session.requestLightProbe({reflectionFormat: session.preferredReflectionFormat }).then((probe) => {
          // Stash and end session.
          lightProbe1 = probe;

          debug("Querying first pair");
          t.step(() => {
            assert_equals(
              binding1.getReflectionCubeMap(lightProbe1),
              null,
              "Active binding and light probe shouldn't throw when requesting cube map");
          });

          return session.end();
        }).then(() => {
          // Need to request a new session.
          navigator.xr.test.simulateUserActivation( () => {
            navigator.xr.requestSession('immersive-ar', { 'requiredFeatures': ['light-estimation'] })
            .then((newSession) => {
              let newBinding = new XRWebGLBinding(newSession, sessionObjects.gl);
              newSession.requestLightProbe({ reflectionFormat: newSession.preferredReflectionFormat }).then((newProbe) => {
                t.step(() => {
                  debug("Querying second pair");
                  assert_equals(
                    newBinding.getReflectionCubeMap(newProbe),
                    null,
                    "Newly created binding and light probe shouldn't throw");

                  debug("Querying old pair");
                  assert_throws_dom(
                    "InvalidStateError",
                    () => binding1.getReflectionCubeMap(lightProbe1),
                    "Binding created with an ended session should throw InvalidStateError");
                  debug("Querying mismatched pair");
                  assert_throws_dom(
                    "InvalidStateError",
                    () => newBinding.getReflectionCubeMap(lightProbe1),
                    "Querying binding with a probe with a different backing session should throw InvalidStateError");
                });
                debug("losing context");

                // Trigger a context loss and verify that we are unable to get the reflectionCubeMap.
                let lose_context_ext = sessionObjects.gl.getExtension('WEBGL_lose_context');

                sessionObjects.gl.canvas.addEventListener('webglcontextlost', (ev) => {
                  ev.preventDefault();

                  t.step(() => {
                    assert_throws_dom(
                      "InvalidStateError",
                      () => newBinding.getReflectionCubeMap(newProbe),
                      "Querying for reflection cube map on a binding with context loss should throw InvalidStateError");
                  });

                  resolve(newSession.end());
                });

                lose_context_ext.loseContext();
              }); // Request second light probe
            }); // Request second session
          }); // SimulateUserActivation
        }); // .then on session end
      } // halfFloatExt
    }); // testFunction

    xr_session_promise_test(
      testName,
      testFunction,
      IMMERSIVE_AR_DEVICE,
      'immersive-ar',
      {'requiredFeatures': ['light-estimation']});

  </script>
</body>