summaryrefslogtreecommitdiffstats
path: root/dom/vr/test/mochitest/requestPresent.js
blob: a2f9dd4d1143236f2734a7faa21ff0d0d9328c06 (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
// requestPresent.js
//
// This file provides helpers for testing VRDisplay requestPresent.

function attachVRDisplay(test) {
  assert_equals(
    typeof navigator.getVRDisplays,
    "function",
    "'navigator.getVRDisplays()' must be defined."
  );
  return VRSimulationDriver.AttachWebVRDisplay();
}

function setupVRDisplay(test) {
  assert_equals(
    typeof navigator.getVRDisplays,
    "function",
    "'navigator.getVRDisplays()' must be defined."
  );
  return VRSimulationDriver.AttachWebVRDisplay()
    .then(() => {
      return navigator.getVRDisplays();
    })
    .then(displays => {
      assert_equals(
        displays.length,
        1,
        "displays.length must be one after attach."
      );
      vrDisplay = displays[0];
      return validateNewVRDisplay(test, vrDisplay);
    });
}

// Validate the settings off a freshly created VRDisplay (prior to calling
// requestPresent).
function validateNewVRDisplay(test, display) {
  assert_true(
    display.capabilities.canPresent,
    "display.capabilities.canPresent must always be true for HMDs."
  );
  assert_equals(
    display.capabilities.maxLayers,
    1,
    "display.capabilities.maxLayers must always be 1 when display.capabilities.canPresent is true for current spec revision."
  );
  assert_false(
    display.isPresenting,
    "display.isPresenting must be false before calling requestPresent."
  );
  assert_equals(
    display.getLayers().length,
    0,
    "display.getLayers() should have no layers if not presenting."
  );
  var promise = display.exitPresent();
  return promise_rejects(test, null, promise);
}

// Validate the settings off a VRDisplay after requestPresent promise is
// rejected or after exitPresent is fulfilled.
function validateDisplayNotPresenting(test, display) {
  assert_false(
    display.isPresenting,
    "display.isPresenting must be false if requestPresent is rejected or after exitPresent is fulfilled."
  );
  assert_equals(
    display.getLayers().length,
    0,
    "display.getLayers() should have no layers if requestPresent is rejected  or after exitPresent is fulfilled."
  );
  var promise = display.exitPresent();
  return promise_rejects(test, null, promise);
}