mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Add basic XR tests
This commit is contained in:
parent
7d029d5a36
commit
01665fe94a
5 changed files with 124 additions and 1 deletions
|
@ -11222,7 +11222,10 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"mozilla/xmlhttprequest_url.html": []
|
"mozilla/xmlhttprequest_url.html": [],
|
||||||
|
"webxr/resources/webxr-util.js": [
|
||||||
|
[]
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"testharness": {
|
"testharness": {
|
||||||
"bluetooth/advertisingEvent/watchAdvertisements-succeeds.html": [
|
"bluetooth/advertisingEvent/watchAdvertisements-succeeds.html": [
|
||||||
|
@ -13927,6 +13930,18 @@
|
||||||
"mozilla/xmlhttprequest_url.html",
|
"mozilla/xmlhttprequest_url.html",
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
|
],
|
||||||
|
"webxr/create_session.html": [
|
||||||
|
[
|
||||||
|
"webxr/create_session.html",
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"webxr/obtain_frame.html": [
|
||||||
|
[
|
||||||
|
"webxr/obtain_frame.html",
|
||||||
|
{}
|
||||||
|
]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"visual": {
|
"visual": {
|
||||||
|
@ -21112,6 +21127,18 @@
|
||||||
"mozilla/xmlhttprequest_url.html": [
|
"mozilla/xmlhttprequest_url.html": [
|
||||||
"e5d10f27c06e1febd3bb70f8f128194fc3f63861",
|
"e5d10f27c06e1febd3bb70f8f128194fc3f63861",
|
||||||
"testharness"
|
"testharness"
|
||||||
|
],
|
||||||
|
"webxr/create_session.html": [
|
||||||
|
"306ab85d3b1b914d2dd7c11a3b03dccd990148ae",
|
||||||
|
"testharness"
|
||||||
|
],
|
||||||
|
"webxr/obtain_frame.html": [
|
||||||
|
"1089bb25c2f6b26db4e21b6bf07c28add3fee5ec",
|
||||||
|
"testharness"
|
||||||
|
],
|
||||||
|
"webxr/resources/webxr-util.js": [
|
||||||
|
"505173c82998a80b1e543f1a18aefaf1891f8269",
|
||||||
|
"support"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"url_base": "/_mozilla/",
|
"url_base": "/_mozilla/",
|
||||||
|
|
2
tests/wpt/mozilla/meta/webxr/__dir__.ini
Normal file
2
tests/wpt/mozilla/meta/webxr/__dir__.ini
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
prefs: [dom.webxr.enabled:true, dom.webxr.test:true]
|
||||||
|
|
15
tests/wpt/mozilla/tests/webxr/create_session.html
Normal file
15
tests/wpt/mozilla/tests/webxr/create_session.html
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
async_test(function(t) {
|
||||||
|
navigator.xr.test.simulateDeviceConnection({supportsImmersive: true}).then((m) => {
|
||||||
|
return navigator.xr.requestSession({mode: "immersive-vr"})
|
||||||
|
}).then(() => t.done());
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
62
tests/wpt/mozilla/tests/webxr/obtain_frame.html
Normal file
62
tests/wpt/mozilla/tests/webxr/obtain_frame.html
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<script src="./resources/webxr-util.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="canvas" width="640" height="480"></canvas>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
let session;
|
||||||
|
let mock;
|
||||||
|
let canvas = document.getElementById("canvas");
|
||||||
|
let gl = canvas.getContext('webgl');
|
||||||
|
|
||||||
|
promise_test(function() {
|
||||||
|
return navigator.xr.test.simulateDeviceConnection({supportsImmersive: true}).then((m) => {
|
||||||
|
mock = m;
|
||||||
|
mock.setViewerOrigin({position: [0.5, 0, 0, 1], orientation: [0, 0, 0, 1] });
|
||||||
|
mock.setViews(TEST_VIEWS);
|
||||||
|
return navigator.xr.requestSession({mode: "immersive-vr"});
|
||||||
|
})
|
||||||
|
.then((s) => {
|
||||||
|
session = s;
|
||||||
|
return session.updateRenderState({"baseLayer": new XRWebGLLayer(session, gl, {})})
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
session.requestAnimationFrame(function(time, frame) {
|
||||||
|
session.requestReferenceSpace("local").then((space) => {
|
||||||
|
let pose = frame.getViewerPose(space);
|
||||||
|
for (view of pose.views) {
|
||||||
|
assert_matrix_approx_equals(view.projectionMatrix, VALID_PROJECTION_MATRIX, 0.001, "left projection matrix");
|
||||||
|
|
||||||
|
if (view.eye == "left") {
|
||||||
|
assert_matrix_approx_equals(view.transform.matrix, [1,0,0,0, 0,1,0,0, 0,0,1,0, 0.4,0,0,1], 0.001, "left transform");
|
||||||
|
let position = view.transform.position;
|
||||||
|
assert_approx_equals(position.x, 0.4, 0.001, "left x value");
|
||||||
|
assert_approx_equals(position.y, 0, 0.001, "left y value");
|
||||||
|
assert_approx_equals(position.z, 0, 0.001, "left z value");
|
||||||
|
assert_approx_equals(position.w, 1, 0.001, "left w value");
|
||||||
|
} else if (view.eye == "right") {
|
||||||
|
assert_matrix_approx_equals(view.transform.matrix, [1,0,0,0, 0,1,0,0, 0,0,1,0, 0.6,0,0,1], 0.001, "right transform");
|
||||||
|
let position = view.transform.position;
|
||||||
|
assert_approx_equals(position.x, 0.6, 0.001, "left x value");
|
||||||
|
assert_approx_equals(position.y, 0, 0.001, "left y value");
|
||||||
|
assert_approx_equals(position.z, 0, 0.001, "left z value");
|
||||||
|
assert_approx_equals(position.w, 1, 0.001, "left w value");
|
||||||
|
} else {
|
||||||
|
reject("got unknown view");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
}).catch((e) => reject(e));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
17
tests/wpt/mozilla/tests/webxr/resources/webxr-util.js
Normal file
17
tests/wpt/mozilla/tests/webxr/resources/webxr-util.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// pieced together from various things in wpt/webxr/resources
|
||||||
|
|
||||||
|
const VALID_PROJECTION_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 3, 2, -1, -1, 0, 0, -0.2, 0];
|
||||||
|
const LEFT_OFFSET = {position: [-0.1, 0, 0], orientation: [0,0,0,0]};
|
||||||
|
const RIGHT_OFFSET = {position: [0.1, 0, 0], orientation: [0,0,0,0]};
|
||||||
|
|
||||||
|
let assert_matrix_approx_equals = function(m1, m2, epsilon, prefix = "") {
|
||||||
|
assert_equals(m1.length, m2.length, prefix + "Matrix lengths should match");
|
||||||
|
for(var i = 0; i < m1.length; ++i) {
|
||||||
|
assert_approx_equals(m1[i], m2[i], epsilon, m1 + prefix + "Component number " + i + " should match");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const TEST_VIEWS = [
|
||||||
|
{eye: "left", projectionMatrix: VALID_PROJECTION_MATRIX, viewOffset: LEFT_OFFSET},
|
||||||
|
{eye: "right", projectionMatrix: VALID_PROJECTION_MATRIX, viewOffset: RIGHT_OFFSET}
|
||||||
|
];
|
Loading…
Add table
Add a link
Reference in a new issue