pauseResumeTests.js (4197B)
1 'use strict'; 2 3 const TestStates = Object.freeze({ 4 "ShouldSucceedPauseScheduleRAF": 1, 5 "ShouldFailResumeScheduleRAF": 2, 6 "ShouldSucceedTestDone": 3, 7 }); 8 9 const framesToWait = 10; 10 const pauseResumeTestFunction = function(session, controller, t, sessionObjects) { 11 const isCpuOptimized = session.depthUsage === 'cpu-optimized'; 12 let state = TestStates.ShouldSucceedPauseScheduleRAF; 13 14 return session.requestReferenceSpace('viewer').then((viewerSpace) => { 15 let done = false; 16 17 const glBinding = new XRWebGLBinding(session, sessionObjects.gl); 18 19 let stepFrameCount = 0; 20 let advanceState = false; 21 22 const rafCb = function(time, frame) { 23 const pose = frame.getViewerPose(viewerSpace); 24 stepFrameCount++; 25 for(const view of pose.views) { 26 const depthInformation = isCpuOptimized ? frame.getDepthInformation(view) 27 : glBinding.getDepthInformation(view); 28 29 if (state == TestStates.ShouldSucceedPauseScheduleRAF 30 || state == TestStates.ShouldSucceedTestDone) { 31 t.step(() => { 32 assert_true(session.depthActive); 33 }); 34 // We have no guarantees about when data should start returning, 35 // so we need to potentially wait a few frames. 36 37 // Final chance. If we haven't advanced the state by now, fail the 38 // test if it doesn't pass this time. 39 if (stepFrameCount >= framesToWait) { 40 t.step(() => { 41 assert_not_equals(depthInformation, null); 42 }); 43 } 44 45 // Either we have data, or we've waited long enough to keep moving. 46 if (depthInformation != null || stepFrameCount >= framesToWait) { 47 advanceState = true; 48 } 49 } else { 50 // Depth should stop being available immediately. 51 t.step(() => { 52 assert_false(session.depthActive); 53 assert_equals(depthInformation, null); 54 }); 55 advanceState = true; 56 } 57 } 58 59 switch(state) { 60 case TestStates.ShouldSucceedPauseScheduleRAF: 61 if (advanceState) { 62 session.pauseDepthSensing(); 63 for(const view of pose.views) { 64 const newDepthInformation = isCpuOptimized ? frame.getDepthInformation(view) 65 : glBinding.getDepthInformation(view); 66 t.step(()=> { 67 // depthActive state should update and stop returning depth info 68 // immediately. 69 assert_false(session.depthActive); 70 assert_equals(newDepthInformation, null); 71 }); 72 } 73 state = TestStates.ShouldFailResumeScheduleRAF; 74 stepFrameCount = 0; 75 advanceState = false; 76 } 77 session.requestAnimationFrame(rafCb); 78 break; 79 case TestStates.ShouldFailResumeScheduleRAF: 80 if (advanceState) { 81 session.resumeDepthSensing(); 82 // In pausing depth sensing, any controller data may have been 83 // thrown away since the UA can "tear down" any depth controller. 84 // So attempt to repopulate the data once we've resumed it. 85 controller.setDepthSensingData(DEPTH_SENSING_DATA); 86 t.step(()=> { 87 // While depth data may not return for a few frames, depthActive 88 // should be updated immediately. 89 assert_true(session.depthActive); 90 }); 91 state = TestStates.ShouldSucceedTestDone; 92 stepFrameCount = 0; 93 advanceState = false; 94 } 95 session.requestAnimationFrame(rafCb); 96 break; 97 case TestStates.ShouldSucceedTestDone: 98 // If we are advancing the state, we can stop pumping the rAF, but 99 // if we're still waiting for data to come back we need to keep it 100 // going. 101 if (advanceState) { 102 done = true; 103 } else { 104 session.requestAnimationFrame(rafCb); 105 } 106 break; 107 } 108 }; 109 110 session.requestAnimationFrame(rafCb); 111 112 return t.step_wait(() => done); 113 }); 114 };