| <!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-internal-device-mocking.js"></script> |
| <script src="resources/vr-test-utils.js "></script> |
| |
| <canvas id="webgl-canvas"></canvas> |
| <script src="resources/presentation-setup.js"></script> |
| <script> |
| let fakeDisplays = fakeVRDisplays(); |
| |
| vr_test( (t, device_controller) => { |
| return navigator.getVRDisplays().then( (displays) => { |
| let display = displays[0]; |
| |
| let prePresentFrameCount = 0; |
| |
| function onFrameStartup() { |
| // Wait until presentation starts, then proceed |
| // with the remaining tests. |
| if (display.isPresenting) { |
| t.step( () => { |
| assert_unreached(err); |
| }, "unexpectedly presenting"); |
| } else { |
| // Run a few frames in "magic mirror" mode, then start presentation. |
| if (++prePresentFrameCount == 3) { |
| runWithUserGesture(startPresentation); |
| } else { |
| display.requestAnimationFrame(onFrameStartup); |
| } |
| } |
| } |
| |
| function getSubmitFrameCount() { |
| return device_controller.getSubmitFrameCount(); |
| } |
| |
| function getMissingFrameCount() { |
| return device_controller.getMissingFrameCount(); |
| } |
| |
| function onFrame1() { |
| assert_equals(getSubmitFrameCount(), 0); |
| assert_equals(getMissingFrameCount(), 0); |
| // case (b): submit frame first, then rAF |
| display.submitFrame(); |
| display.requestAnimationFrame(onFrame2); |
| } |
| |
| function onFrame2() { |
| assert_equals(getSubmitFrameCount(), 1); |
| assert_equals(getMissingFrameCount(), 0); |
| // case (c): rAF first, then submit frame |
| display.requestAnimationFrame(onFrame3); |
| display.submitFrame(); |
| } |
| |
| function onFrame3(time) { |
| assert_equals(getSubmitFrameCount(), 2); |
| assert_equals(getMissingFrameCount(), 0); |
| // case (d): don't submit a frame. |
| display.requestAnimationFrame(onFrame4); |
| } |
| |
| function onFrame4(time) { |
| // If we get here, we're done. |
| assert_equals(getSubmitFrameCount(), 2); |
| assert_equals(getMissingFrameCount(), 1); |
| t.done(); |
| } |
| |
| function startPresentation() { |
| assert_equals(getSubmitFrameCount(), 0); |
| assert_equals(getMissingFrameCount(), 0); |
| display.requestPresent([{ source : webglCanvas }]).then( () => { |
| t.step( () => { |
| assert_equals(getSubmitFrameCount(), 0); |
| assert_equals(getMissingFrameCount(), 0); |
| // case (a): in requestPresent promise, outside animating context. |
| assert_true(display.isPresenting); |
| display.requestAnimationFrame(onFrame1); |
| }, "Display should be presenting"); |
| }, (err) => { |
| t.step( () => { |
| assert_unreached(err); |
| }, "requestPresent rejected"); |
| }); |
| } |
| |
| // Start: case (a) outside animating context. |
| display.requestAnimationFrame(onFrameStartup); |
| }, (err) => { |
| t.step( () => { |
| assert_unreached("getVRDisplays rejected"); |
| }); |
| t.done(); |
| }); |
| }, [fakeDisplays["Pixel"]], |
| "multiple requestAnimationFrame requests call the correct callbacks"); |
| |
| </script> |