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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
<!DOCTYPE html>
<html>
<head>
<title>VRDisplay RequestPresent</title>
<meta name="timeout" content="long"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="VRSimulationDriver.js"></script>
<script src="WebVRHelpers.js"></script>
<script src="requestPresent.js"></script>
<script src="runVRTest.js"></script>
</head>
<body id="body">
<canvas id="webglCanvas"></canvas>
<div id="testDiv"></div>
<script>
"use strict";
var vrDisplay;
var canvas = document.getElementById('webglCanvas');
var div = document.getElementById('testDiv');
function startTest() {
promise_test((test) => {
return setupVRDisplay(test).then(() => {
return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{}]));
}).then(() => {
return validateDisplayNotPresenting(test, vrDisplay);
});
}, "WebVR requestPresent rejected with empty frames");
promise_test((test) => {
return setupVRDisplay(test).then(() => {
return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas, leftBounds: [0.0, 0.0] }]));
}).then(() => {
return validateDisplayNotPresenting(test, vrDisplay);
});
}, "WebVR requestPresent rejected with incorrect bounds (bounds arrays must be 0 or 4 long)");
promise_test((test) => {
return setupVRDisplay(test).then(() => {
return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: div }]));
}).then(() => {
return validateDisplayNotPresenting(test, vrDisplay);
});
}, "WebVR requestPresent rejected with invalid source (must be canvas element)");
promise_test((test) => {
return setupVRDisplay(test).then(() => {
return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas, leftBounds: [div] }]));
}).then(() => {
return validateDisplayNotPresenting(test, vrDisplay);
});
}, "WebVR requestPresent rejected with invalid bounds data type (must be able to convert to float)");
const invalidBounds = [
[2.0, 0.0, 0.0, 0.0],
[0.0, 2.0, 0.0, 0.0],
[0.0, 0.0, 2.0, 0.0],
[0.0, 0.0, 0.0, 2.0],
[-1.0, 0.0, 0.0, 0.0],
[0.0, -1.0, 0.0, 0.0],
[0.0, 0.0, -1.0, 0.0],
[0.0, 0.0, 0.0, -1.0]];
invalidBounds.forEach((bound) => {
promise_test((test) => {
return setupVRDisplay(test).then(() => {
return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas, leftBounds: bound }]));
}).then(() => {
return validateDisplayNotPresenting(test, vrDisplay);
});
}, "WebVR requestPresent rejected with bounds in invalid range: [" + bound + "]");
});
promise_test((test) => {
return setupVRDisplay(test).then(() => {
var promise = vrDisplay.requestPresent({ source: canvas });
return promise_rejects(test, null, promise);
}).then(() => {
return validateDisplayNotPresenting(test, vrDisplay);
});
}, "WebVR requestPresent rejected without user initiated action");
promise_test((test) => {
return setupVRDisplay(test).then(() => {
return promise_rejects(test, null, WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas }, { source: canvas }]));
}).then(() => {
return validateDisplayNotPresenting(test, vrDisplay);
});
}, "WebVR requestPresent rejected with more frames than max layers");
promise_test((test) => {
return setupVRDisplay(test).then(() => {
function requestAgain() {
// Callback for immediate requestPresent call for further testing.
// Cache this promise on global object since it seems to be the only object
// in scope across calls.
window.promiseSecond = vrDisplay.requestPresent([{ source: canvas }]);
}
return WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas }], requestAgain);
}).then(() => {
// First promise succeeded
assert_true(vrDisplay.isPresenting, "First promise should successfully fulfill");
// Now, validate that the subsequent requestPresent was rejected
return promise_rejects(test, null, window.promiseSecond);
}).then(() => {
delete window.promiseSecond;
assert_true(vrDisplay.isPresenting, "Should still be presenting after rejected second promise");
return vrDisplay.exitPresent();
});
}, "WebVR requestPresent fails while another one is in progress");
promise_test((test) => {
return setupVRDisplay(test).then(() => {
return WebVRHelpers.RequestPresentOnVRDisplay(vrDisplay, [{ source: canvas }]);
}).then(() => {
assert_true(vrDisplay.isPresenting, "vrDisplay.isPresenting must be true if requestPresent is fulfilled.");
assert_equals(vrDisplay.getLayers().length, 1, "vrDisplay.getLayers() should return one layer.");
return vrDisplay.exitPresent();
}).then(() => {
assert_false(vrDisplay.isPresenting, "vrDisplay.isPresenting must be false if exitPresent is fulfilled.");
// exitPresent() should reject since we are no longer presenting.
return promise_rejects(test, null, vrDisplay.exitPresent());
});
}, "WebVR requestPresent fulfilled");
}
runVRTest(startTest);
</script>
</body>
</html>
|