summaryrefslogtreecommitdiffstats
path: root/dom/vr/test/mochitest/test_vrController_displayId.html
blob: e69e3920d22666614e6bc64c0077831a5ba90177 (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
<!DOCTYPE html>
<html>
  <head>
    <title>VRController DisplayId</title>
    <meta name="timeout" content="long"/>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="VRSimulationDriver.js"></script>
    <script src="runVRTest.js"></script>
  </head>
  <body>
    <script>
      "use strict";
      var vrDisplay;
      var controllerCount = 0;

      function addController() {
        promise_test((test) => {
          return VRSimulationDriver.AttachVRController().then((controller) => {
            controller.newButtonEvent(0, true);
          });
        }, "Finish to add VRController.");
      }

      function listenControllerEvents() {
        async_test(function(t) {
          window.addEventListener("gamepadbuttondown", function(e) {
              assert_equals(e.gamepad.displayId, vrDisplay.displayId, "gamepad.displayId should be equal to vrDisplay.");
              assert_equals(e.gamepad.id, "Puppet Gamepad", "gamepad.id must be equal to 'Puppet Gamepad'.");
              ++controllerCount;
              if (controllerCount == 2) {
                t.done();
              }
          });
        }, "Finish to verify VRController.displayId.");
      }

      function startTest() {
        promise_test((test) => {
          listenControllerEvents();
          return VRSimulationDriver.AttachWebVRDisplay().then(() => {
            return navigator.getVRDisplays().then((displays) => {
              vrDisplay = displays[0];
              assert_equals(displays.length, 1, "displays.length must be one after attach.");
              assert_equals(vrDisplay.displayName, "Puppet HMD", "display.displayName must be equal to 'Puppet HMD'.");
              addController();
              addController();
            });
          });
        }, "Finish to add VRDisplay.");
      }

      runVRTest(startTest);
    </script>
  </body>
</html>