blob: a1b7eeec65c0502505fc99473c8e2774275a2ce0 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../vr/resources/fake-vr-displays.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/device/vr/vr_service.mojom.js"></script>
<script src="../vr/resources/mock-vr-service.js"></script>
<canvas id="webgl-canvas"></canvas>
<script src="../vr/resources/presentation-setup.js"></script>
<script>
let fakeDisplays = fakeVRDisplays();
xr_session_test( (t, session) => {
// Session must have a baseLayer or frame requests will be ignored.
session.baseLayer = new XRWebGLLayer(session, gl);
function onFrameBad(time, vrFrame) {
t.step( () => {
assert_unreached("Unregistered callback was called");
});
t.done();
}
let counter = 0;
let handle2 = 0;
function onFrameGood(time, vrFrame) {
counter++;
if (counter >= 4) {
t.done();
// Intentionally don't return immediately so that session.requestAnimationFrame
// gets called again to make sure it doesn't cause unexpected behavior
// like in crbug.com/679401
}
session.requestAnimationFrame(onFrameGood);
if (handle2 != 0) {
// The first time we enter this callback the callback associated with
// handle2 will have already been queued to execute immediately after
// this callback returns. Ensure that cancelAnimationFrame works even in that
// scenario.
session.cancelAnimationFrame(handle2);
handle2 = 0;
}
}
let handle = session.requestAnimationFrame(onFrameBad);
session.cancelAnimationFrame(handle);
session.requestAnimationFrame(onFrameGood);
handle2 = session.requestAnimationFrame(onFrameBad);
}, fakeDisplays["Pixel"], { exclusive: true },
"XRSession requestAnimationFrame callbacks can be unregistered with cancelAnimationFrame");
</script>