OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="../resources/mojo-helpers.js"></script> |
| 5 <script src="resources/fake-vr-displays.js"></script> |
| 6 <script src="resources/mock-vr-service.js"></script> |
| 7 <canvas id="webgl-canvas"></canvas> |
| 8 <script src="resources/presentation-setup.js"></script> |
| 9 <script> |
| 10 let fakeDisplays = fakeVRDisplays(); |
| 11 |
| 12 vr_test( (t) => { |
| 13 return navigator.getVRDisplays().then( (displays) => { |
| 14 let display = displays[0]; |
| 15 |
| 16 let prePresentFrameCount = 0; |
| 17 |
| 18 function onFrameStartup() { |
| 19 // Wait until presentation starts, then proceed |
| 20 // with the remaining tests. |
| 21 if (display.isPresenting) { |
| 22 t.step( () => { |
| 23 assert_unreached(err); |
| 24 }, "unexpectedly presenting"); |
| 25 } else { |
| 26 // Run a few frames in "magic mirror" mode, then start presentation. |
| 27 if (++prePresentFrameCount == 3) { |
| 28 runWithUserGesture(startPresentation); |
| 29 } else { |
| 30 display.requestAnimationFrame(onFrameStartup); |
| 31 } |
| 32 } |
| 33 } |
| 34 |
| 35 function onFrame1() { |
| 36 // case (b): submit frame first, then rAF |
| 37 display.submitFrame(); |
| 38 display.requestAnimationFrame(onFrame2); |
| 39 } |
| 40 |
| 41 function onFrame2() { |
| 42 // case (c): rAF first, then submit frame |
| 43 display.requestAnimationFrame(onFrame3); |
| 44 display.submitFrame(); |
| 45 } |
| 46 |
| 47 function onFrame3(time) { |
| 48 // case (d): don't submit a frame. |
| 49 display.requestAnimationFrame(onFrame4); |
| 50 } |
| 51 |
| 52 function onFrame4(time) { |
| 53 // If we get here, we're done. |
| 54 t.done(); |
| 55 } |
| 56 |
| 57 function startPresentation() { |
| 58 display.requestPresent([{ source : webglCanvas }]).then( () => { |
| 59 t.step( () => { |
| 60 // case (a): in requestPresent promise, outside animating context. |
| 61 assert_true(display.isPresenting); |
| 62 display.requestAnimationFrame(onFrame1); |
| 63 }, "Display should be presenting"); |
| 64 }, (err) => { |
| 65 t.step( () => { |
| 66 assert_unreached(err); |
| 67 }, "requestPresent rejected"); |
| 68 }); |
| 69 } |
| 70 |
| 71 // Start: case (a) outside animating context. |
| 72 display.requestAnimationFrame(onFrameStartup); |
| 73 }, (err) => { |
| 74 t.step( () => { |
| 75 assert_unreached("getVRDisplays rejected"); |
| 76 }); |
| 77 t.done(); |
| 78 }); |
| 79 }, [fakeDisplays["Pixel"]], |
| 80 "multiple requestAnimationFrame requests call the correct callbacks"); |
| 81 |
| 82 </script> |
OLD | NEW |