blob: bd6080107370cf1beafbec7a1926fd55bc270ac4 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/device/vr/public/mojom/vr_service.mojom.js"></script>
<script src="../external/wpt/resources/chromium/webxr-test.js"></script>
<script src="../xr/resources/xr-test-utils.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let testName =
"Ensure a WebGL layer's framebuffer can only be drawn to inside a XR frame";
let fakeDeviceInitParams = { supportsImmersive: true };
let requestSessionOptions = [{ mode: 'immersive-vr' }];
let testFunction =
(session, t, fakeDeviceController) => new Promise((resolve, reject) => {
try {
let webglLayerGood = new XRWebGLLayer(session, gl);
} catch (err) {
reject("XRWebGLLayer should not fail with valid arguments");
}
let lose_context_ext = gl.getExtension('WEBGL_lose_context');
webglCanvas.addEventListener('webglcontextlost', (ev) => {
ev.preventDefault();
try {
let webglLayerBadContext = new XRWebGLLayer(session, gl);
reject("XRWebGLLayer should fail when created with a lost context");
} catch (err) {
assert_equals(err.name, 'InvalidStateError');
setTimeout(() => { lose_context_ext.restoreContext(); }, 100);
}
});
webglCanvas.addEventListener('webglcontextrestored', (ev) => {
resolve(session.end().then(() => {
try {
let webglLayerBadSession = new XRWebGLLayer(session, gl);
assert_unreached("XRWebGLLayer should fail when created with an ended session");
} catch (err) {
assert_equals(err.name, 'InvalidStateError');
}
}));
});
lose_context_ext.loseContext();
});
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>