Update web-platform-tests to revision 50d6ee076e94273080d9f3b69be0bf4eeae156d3

This commit is contained in:
WPT Sync Bot 2018-08-22 21:45:47 -04:00
parent 3b9055510a
commit 280c87822d
331 changed files with 4209 additions and 866 deletions

View file

@ -11,11 +11,7 @@ idl_test(
async idl_array => {
idl_array.add_objects({
Navigator: ['navigator'],
XR: ['navigator.XR'],
XRDevice: ['device'],
XRSession: ['session'],
XR: ['navigator.xr'],
});
self.device = await navigator.XR.requestDevice();
self.session = await device.requestSession();
}
);

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script>
xr_promise_test("navigator.xr.requestDevice returns a device", (t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive: true })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => {
t.step(() => {
assert_true(device != null);
assert_true(device instanceof XRDevice);
});
});
});
</script>
</body>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script>
promise_test( (t) => {
return promise_rejects(t, 'NotFoundError', navigator.xr.requestDevice());
}, "navigator.xr.requestDevice properly rejects when there are 0 devices");
</script>
</body>

View file

@ -7,7 +7,7 @@
//
// --enable-blink-features=MojoJS,MojoJSTest
function xr_promise_test(func, name, properties) {
function xr_promise_test(name, func, properties) {
promise_test(async (t) => {
// Perform any required test setup:
@ -20,6 +20,74 @@ function xr_promise_test(func, name, properties) {
}, name, properties);
}
// A test function which runs through the common steps of requesting a session.
// Calls the passed in test function with the session, the controller for the
// device, and the test object.
// Requires a webglCanvas on the page.
function xr_session_promise_test(
name, func, fakeDeviceInit, sessionOptions, properties) {
let testDevice;
let testDeviceController;
let testSession;
const webglCanvas = document.getElementsByTagName('canvas')[0];
if (!webglCanvas) {
promise_test(async (t) => {
Promise.reject('xr_session_promise_test requires a canvas on the page!');
}, name, properties);
}
let gl = webglCanvas.getContext('webgl', {alpha: false, antialias: false});
xr_promise_test(
name,
(t) =>
XRTest.simulateDeviceConnection(fakeDeviceInit)
.then((controller) => {
testDeviceController = controller;
return navigator.xr.requestDevice();
})
.then((device) => {
testDevice = device;
return gl.setCompatibleXRDevice(device);
})
.then(() => new Promise((resolve, reject) => {
// Perform the session request in a user gesture.
XRTest.simulateUserActivation(() => {
testDevice.requestSession(sessionOptions)
.then((session) => {
testSession = session;
// Session must have a baseLayer or frame requests
// will be ignored.
session.baseLayer = new XRWebGLLayer(session, gl);
resolve(func(session, testDeviceController, t));
})
.catch((err) => {
reject(
'Session with params ' +
JSON.stringify(sessionOptions) +
' was rejected on device ' +
JSON.stringify(fakeDeviceInit) +
' with error: ' + err);
});
});
}))
.then(() => {
// Cleanup system state.
testSession.end().catch(() => {});
XRTest.simulateDeviceDisconnection(testDevice);
}),
properties);
}
// A utility function to create an output context as required by non-immersive
// sessions.
// https://immersive-web.github.io/webxr/#xrsessioncreationoptions-interface
function getOutputContext() {
let outputCanvas = document.createElement('canvas');
document.body.appendChild(outputCanvas);
return outputCanvas.getContext('xrpresent');
}
// This functions calls a callback with each API object as specified
// by https://immersive-web.github.io/webxr/spec/latest/, allowing
// checks to be made on all ojects.
@ -59,8 +127,13 @@ let loadChromiumResources = Promise.resolve().then(() => {
let chain = Promise.resolve();
['/gen/layout_test_data/mojo/public/js/mojo_bindings.js',
'/gen/ui/gfx/geometry/mojo/geometry.mojom.js',
'/gen/mojo/public/mojom/base/time.mojom.js',
'/gen/gpu/ipc/common/mailbox_holder.mojom.js',
'/gen/gpu/ipc/common/sync_token.mojom.js',
'/gen/ui/display/mojo/display.mojom.js',
'/gen/ui/gfx/geometry/mojo/geometry.mojom.js',
'/gen/ui/gfx/mojo/gpu_fence_handle.mojom.js',
'/gen/ui/gfx/mojo/transform.mojom.js',
'/gen/device/vr/public/mojom/vr_service.mojom.js',
'/resources/chromium/webxr-test.js', '/resources/testdriver.js',
'/resources/testdriver-vendor.js',

View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
xr_promise_test("webglCanvasContext can be created with an XRDevice",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:true })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => {
webglCanvas = document.getElementById('webgl-canvas');
gl = webglCanvas.getContext('webgl', {compatibleXRDevice: device});
assert_equals(gl.getContextAttributes().compatibleXRDevice, device);
// Check that an offscreen context behaves no different.
let offscreenCanvas = document.createElement('canvas');
let offscreenGl = webglCanvas.getContext(
'webgl', {compatibleXRDevice: device});
assert_equals(
offscreenGl.getContextAttributes().compatibleXRDevice, device);
});
});
</script>
</body>

View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
xr_promise_test(
"A lost webglCanvasContext should not be able to set device",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:true })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => {
webglCanvas = document.getElementById('webgl-canvas');
gl = webglCanvas.getContext('webgl', {compatibleXRDevice: device});
gl.getExtension('WEBGL_lose_context').loseContext();
return promise_rejects(t, 'InvalidStateError',
gl.setCompatibleXRDevice(device));
});
});
</script>
</body>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
xr_session_promise_test(
"Tests requestSession resolves when supported",
(session) => {
assert_not_equals(session, null);
}, { supportsImmersive:true }, { immersive: true });
</script>
</body>

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script>
xr_promise_test(
"Requesting immersive session outside of a user gesture rejects",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:true })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => promise_rejects(
t, 'SecurityError', device.requestSession({ immersive: true })));
});
</script>
</body>

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script>
xr_promise_test(
"Requesting an immersive session when unsupported rejects",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:false })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (magicWindowOnlyDevice) => new Promise((resolve) => {
XRTest.simulateUserActivation( () => {
resolve(promise_rejects(
t,
"NotSupportedError",
magicWindowOnlyDevice.requestSession({ immersive: true })
))
});
}));
});
</script>
</body>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script>
xr_promise_test(
"Requesting non-immersive session outside of a user gesture succeeds",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:false })
.then( (controller) => { return navigator.xr.requestDevice(); })
.then( (device) => device.requestSession({
immersive: false,
outputContext: getOutputContext()
}))
.then( (session) => { assert_not_equals(session, null); });
});
</script>
</body>

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script>
xr_promise_test(
"supportsSession resolves when immersive options supported",
() => {
return XRTest.simulateDeviceConnection({ supportsImmersive:true })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => device.supportsSession({ immersive: true }));
});
</script>
</body>

View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script>
xr_promise_test(
"supportsSession rejects when options not supported",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:false })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => {
return promise_rejects(
t,
"NotSupportedError",
device.supportsSession({ immersive: true })
);
});
});
</script>
</body>

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<script>
xr_promise_test(
"supportsSession resolves when non-immersive options supported",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:true })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => {
// Non-immersive sessions without a outputContext should not be supported.
promise_rejects(t, 'NotSupportedError', device.supportsSession());
// Non-immersive sessions with an outputContext should be supported.
return device.supportsSession({
outputContext: getOutputContext()
});
});
});
</script>
</body>

View file

@ -0,0 +1,58 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
let immersiveTestName = "XRSession requestAnimationFrame callbacks can be "
+ "unregistered with cancelAnimationFrame for immersive sessions";
let nonImmersiveTestName = "XRSession requestAnimationFrame callbacks can be "
+ "unregistered with cancelAnimationFrame for non-immersive sessions";
let fakeDeviceInitParams = { supportsImmersive:true };
let immersiveSessionOptions = { immersive: true };
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
let testFunction = (session) => new Promise((resolve, reject) => {
// Schedule and immediately cancel animation frame
session.cancelAnimationFrame(session.requestAnimationFrame(
(time, vrFrame) => { reject("Cancelled frame callback was called"); }));
let counter = 0;
let handle;
function onFrame(time, vrFrame) {
// Cancel the second animation frame.
if (handle != 0) {
session.cancelAnimationFrame(handle);
handle = 0;
}
// Run a few more animation frames to be sure that the cancelled frame isn't
// going to call.
counter++;
if (counter >= 4) {
// Ok, we're done here.
resolve();
} else {
session.requestAnimationFrame(onFrame);
}
}
// Schedule two animation frame and cancel one during on animation frame.
session.requestAnimationFrame(onFrame);
handle = session.requestAnimationFrame(
(time, vrFrame) => { reject("Cancelled frame callback was called"); });
});
xr_session_promise_test(immersiveTestName, testFunction,
fakeDeviceInitParams, immersiveSessionOptions);
xr_session_promise_test(nonImmersiveTestName, testFunction,
fakeDeviceInitParams, nonImmersiveSessionOptions);
</script>
</body>

View file

@ -0,0 +1,45 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
let immersiveTestName = "XRSession cancelAnimationFrame does not have unexpected "
+ "behavior when given invalid handles on immersive testSession";
let nonImmersiveTestName = "XRSession cancelAnimationFrame does not have unexpected "
+ "behavior when given invalid handles on non-immersive testSession";
let fakeDeviceInitParams = { supportsImmersive:true };
let immersiveSessionOptions = { immersive: true };
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
let testFunction = (testSession) => new Promise((resolve) => {
let counter = 0;
function onFrame(time, vrFrame) {
if(counter <= 10) {
testSession.requestAnimationFrame(onFrame);
} else {
resolve();
}
counter++;
}
let handle = testSession.requestAnimationFrame(onFrame);
testSession.cancelAnimationFrame(0);
testSession.cancelAnimationFrame(-1);
testSession.cancelAnimationFrame(handle + 1);
testSession.cancelAnimationFrame(handle - 1);
testSession.cancelAnimationFrame(0.5);
testSession.cancelAnimationFrame(null);
});
xr_session_promise_test(
immersiveTestName, testFunction, fakeDeviceInitParams, immersiveSessionOptions);
xr_session_promise_test(
nonImmersiveTestName, testFunction, fakeDeviceInitParams, nonImmersiveSessionOptions);
</script>
</body>

View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
xr_promise_test("Requested session has device set",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:true })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => new Promise((resolve) => {
XRTest.simulateUserActivation( () => {
resolve(device.requestSession({ immersive: true }).then( (session) => {
assert_true(session.immersive);
assert_equals(session.device, device);
}));
});
}));
});
</script>
</body>

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
const immersivetestName = "end event fires when immersive session ends";
const nonimmersiveTestName = "end event fires when non-immersive session ends";
let watcherDone = new Event("watcherdone");
const fakeDeviceInitParams = { supportsImmersive:true };
const immersiveSessionOptions = { immersive: true };
const nonImmersiveSessionOptions = { outputContext: getOutputContext() };
let testFunction = function(session, testDeviceController, t) {
let eventWatcher = new EventWatcher(t, session, ["end", "watcherdone"]);
let eventPromise = eventWatcher.wait_for(["end", "watcherdone"]);
function onSessionEnd(event) {
t.step( () => {
assert_equals(event.session, session);
session.dispatchEvent(watcherDone);
});
}
session.addEventListener("end", onSessionEnd, false);
session.end();
return eventPromise;
};
xr_session_promise_test(immersivetestName, testFunction,
fakeDeviceInitParams, immersiveSessionOptions);
xr_session_promise_test(nonimmersiveTestName, testFunction,
fakeDeviceInitParams, nonImmersiveSessionOptions);
</script>
</body>

View file

@ -1,91 +0,0 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
const identityMatrix = new Float32Array([
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
]);
const rightFakeXRViewInit =
{eye:"right", projectionMatrix: identityMatrix, viewMatrix: identityMatrix};
const leftFakeXRViewInit =
{eye:"left", projectionMatrix: identityMatrix, viewMatrix: identityMatrix};
const immersiveFakeXRDeviceInit = { supportsImmersive:true };
const webglCanvas = document.getElementById('webgl-canvas');
let gl = webglCanvas.getContext('webgl', { alpha: false, antialias: false });
let testDevice;
let testDeviceController;
let testSession;
xr_promise_test(
(t) => XRTest.simulateDeviceConnection(immersiveFakeXRDeviceInit)
.then((controller) => {
testDeviceController = controller;
return navigator.xr.requestDevice();
})
.then((device) => {
testDevice = device;
return gl.setCompatibleXRDevice(device);
})
.then(() => new Promise((resolve, reject) => {
// Perform the session request in a user gesture.
XRTest.simulateUserActivation(() => {
testDevice.requestSession({ immersive: true })
.then((session) => {
testSession = session;
return session.requestFrameOfReference('eye-level');
})
.then((frameOfRef) => {
// Session must have a baseLayer or frame requests will be ignored.
testSession.baseLayer = new XRWebGLLayer(testSession, gl);
function onFrame(time, xrFrame) {
assert_true(xrFrame instanceof XRFrame);
assert_not_equals(xrFrame.views, null);
assert_equals(xrFrame.views.length, 2);
let devicePose = xrFrame.getDevicePose(frameOfRef);
assert_not_equals(devicePose, null);
for(let i = 0; i < identityMatrix.length; i++) {
assert_equals(devicePose.poseModelMatrix[i], identityMatrix[i]);
}
assert_not_equals(devicePose.getViewMatrix(xrFrame.views[0]), null);
assert_equals(devicePose.getViewMatrix(xrFrame.views[0]).length, 16);
assert_not_equals(devicePose.getViewMatrix(xrFrame.views[1]), null);
assert_equals(devicePose.getViewMatrix(xrFrame.views[1]).length, 16);
// Test does not complete until the returned promise resolves.
resolve();
}
testDeviceController.setXRPresentationFrameData(
identityMatrix,
[rightFakeXRViewInit, leftFakeXRViewInit]
);
testSession.requestAnimationFrame(onFrame);
}).catch((err) => {
reject("Session was rejected with error: "+err);
});
});
})
),
"RequestAnimationFrame resolves with good data"
);
</script>
</body>

View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
xr_promise_test(
"Test prevention of multiple simultaneous immersive sessions",
(t) => {
return XRTest.simulateDeviceConnection({ supportsImmersive:true })
.then( (controller) => { return navigator.xr.requestDevice() })
.then( (device) => new Promise((resolve) => {
XRTest.simulateUserActivation( () => {
resolve(device.requestSession({ immersive: true })
.then( (session) => new Promise((resolve) => {
XRTest.simulateUserActivation( () => {
// Requesting a second immersive session from a device that already
// has an active immersive session should fail. Immersive sessions
// should take up the users entire view, and therefore it should
// be impossible for a user to be engaged with more than one.
resolve(promise_rejects(
t,
"InvalidStateError",
device.requestSession({ immersive: true })
).then( () => {
// End the immersive session and try again. Now the immersive
// session creation should succeed.
return session.end().then( () => new Promise((resolve) => {
XRTest.simulateUserActivation( () => {
resolve(device.requestSession({ immersive: true }));
});
}));
}));
});
})));
});
}));
});
</script>
</body>

View file

@ -0,0 +1,35 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
let immersiveTestName = "XRSession requestAnimationFrame calls the " +
"provided callback for an immersive session";
let nonImmersiveTestName = "XRSession requestAnimationFrame calls the " +
"provided callback a non-immersive session";
let fakeDeviceInitParams = { supportsImmersive:true };
let immersiveSessionOptions = { immersive: true };
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
let testFunction = (testSession) => new Promise((resolve) => {
function onFrame(time, xrFrame) {
assert_true(xrFrame instanceof XRFrame);
// Test does not complete until the returned promise resolves.
resolve();
}
testSession.requestAnimationFrame(onFrame);
});
xr_session_promise_test(immersiveTestName, testFunction,
fakeDeviceInitParams, immersiveSessionOptions);
xr_session_promise_test(nonImmersiveTestName, testFunction,
fakeDeviceInitParams, nonImmersiveSessionOptions);
</script>
</body>

View file

@ -0,0 +1,75 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
const testName = "RequestAnimationFrame resolves with good data";
const identityMatrix = new Float32Array([
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
]);
const rightFakeXRViewInit = {
eye:"right",
projectionMatrix: identityMatrix,
viewMatrix: identityMatrix
};
const leftFakeXRViewInit = {
eye:"left",
projectionMatrix: identityMatrix,
viewMatrix: identityMatrix
};
const fakeDeviceInitOptions = { supportsImmersive:true };
const sessionOptions = { immersive:true };
let testSession;
let testFunction = function(session, testDeviceController) {
testSession = session;
return session.requestFrameOfReference('eye-level')
.then((frameOfRef) => new Promise((resolve) => {
function onFrame(time, xrFrame) {
assert_true(xrFrame instanceof XRFrame);
assert_not_equals(xrFrame.views, null);
assert_equals(xrFrame.views.length, 2);
let devicePose = xrFrame.getDevicePose(frameOfRef);
assert_not_equals(devicePose, null);
for(let i = 0; i < identityMatrix.length; i++) {
assert_equals(devicePose.poseModelMatrix[i], identityMatrix[i]);
}
assert_not_equals(devicePose.getViewMatrix(xrFrame.views[0]), null);
assert_equals(devicePose.getViewMatrix(xrFrame.views[0]).length, 16);
assert_not_equals(devicePose.getViewMatrix(xrFrame.views[1]), null);
assert_equals(devicePose.getViewMatrix(xrFrame.views[1]).length, 16);
// Test does not complete until the returned promise resolves.
resolve();
}
testDeviceController.setXRPresentationFrameData(
identityMatrix,
[rightFakeXRViewInit, leftFakeXRViewInit]
);
testSession.requestAnimationFrame(onFrame);
})
);
}
xr_session_promise_test(
testName, testFunction, fakeDeviceInitOptions, sessionOptions);
</script>
</body>

View file

@ -0,0 +1,79 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
let immersiveTestName =
"XRFrame getDevicePose updates on the next frame for immersive sessions";
let nonImmersiveTestName =
"XRFrame getDevicePose updates on the next frame for non-immersive sessions";
let fakeDeviceInitParams = { supportsImmersive: true };
let immersiveSessionOptions = { immersive: true };
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
// Valid matrices for when we don't care about specific values
const validPoseMatrix = [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1];
const validProjectionMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 3, 2, -1, -1, 0, 0, -0.2, 0];
const validViewMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4, 3, 2, 1];
let testFunction = function(session, fakeDeviceController, t) {
return session.requestFrameOfReference("eye-level")
.then((frameOfRef) => new Promise((resolve, reject) => {
let counter = 0;
function onFrame(time, vrFrame) {
session.requestAnimationFrame(onFrame);
if (counter == 0) {
t.step( () => {
// Expecting to not get a pose since none has been supplied
assert_equals(vrFrame.getDevicePose(frameOfRef), null);
fakeDeviceController.setXRPresentationFrameData(
validPoseMatrix, [{
eye:"left",
projectionMatrix: validProjectionMatrix,
viewMatrix: validViewMatrix
}, {
eye:"right",
projectionMatrix: validProjectionMatrix,
viewMatrix: validViewMatrix
}]);
// Check that pose does not update pose within the same frame.
assert_equals(vrFrame.getDevicePose(frameOfRef), null);
});
} else {
t.step( () => {
let pose = vrFrame.getDevicePose(frameOfRef);
assert_not_equals(pose, null);
let poseMatrix = pose.poseModelMatrix;
assert_not_equals(poseMatrix, null);
for(let i = 0; i < poseMatrix.length; i++) {
assert_equals(poseMatrix[i], validPoseMatrix[i]);
}
});
// Finished.
resolve();
}
counter++;
}
session.requestAnimationFrame(onFrame);
}));
};
xr_session_promise_test(nonImmersiveTestName, testFunction,
fakeDeviceInitParams, nonImmersiveSessionOptions);
xr_session_promise_test(immersiveTestName, testFunction,
fakeDeviceInitParams, immersiveSessionOptions);
</script>
</body>

View file

@ -0,0 +1,49 @@
<!DOCTYPE html>
<body>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="resources/webxr_util.js"></script>
<canvas></canvas>
<script>
let immersiveTestName =
"Immersive XRSession requestFrameOfReference returns expected objects";
let nonImmersiveTestName =
"Non-immersive XRSession requestFrameOfReference returns expected objects";
let fakeDeviceInitParams = { supportsImmersive: true };
let immersiveSessionOptions = { immersive: true };
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
let testFunction = function(session, fakeDeviceController, t) {
return promise_rejects(t, new TypeError(), session.requestFrameOfReference("foo"))
.then(() => Promise.all([
session.requestFrameOfReference("head-model").then( (frameOfRef) => {
assert_true(frameOfRef instanceof XRCoordinateSystem,
"head-model frameOfRef is not correct type.");
assert_true(frameOfRef instanceof XRFrameOfReference,
"head-model frameOfRef is not correct type.");
}),
session.requestFrameOfReference("eye-level").then( (frameOfRef) => {
assert_true(frameOfRef instanceof XRCoordinateSystem,
"eye-level frameOfRef is not correct type.");
assert_true(frameOfRef instanceof XRFrameOfReference,
"eye-level frameOfRef is not correct type.");
}),
session.requestFrameOfReference("stage").then( (frameOfRef) => {
assert_true(frameOfRef instanceof XRCoordinateSystem,
"stage frameOfRef is not correct type.");
assert_true(frameOfRef instanceof XRFrameOfReference,
"stage frameOfRef is not correct type.");
})
]));
};
xr_session_promise_test(
immersiveTestName, testFunction, fakeDeviceInitParams, immersiveSessionOptions);
xr_session_promise_test(
nonImmersiveTestName, testFunction, fakeDeviceInitParams, nonImmersiveSessionOptions);
</script>
</body>