RTCPeerConnection-remote-track-currentTime.https.html (4146B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <meta name="timeout" content="long"> 4 <title>RTCPeerConnection-remote-track-currentTime.https.html</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="RTCPeerConnection-helper.js"></script> 8 <script> 9 'use strict'; 10 11 /* 12 * This test is checking the below spec text for MediaStreamTracks received 13 * through an RTCPeerConnection. 14 * 15 * ยง 6. MediaStreams in Media Elements 16 * 17 * A MediaStream (...) represents a simple, potentially infinite, linear media 18 * timeline. The timeline starts at 0 and increments linearly in real time as 19 * long as the media element is potentially playing. The timeline does not 20 * increment when the playout of the MediaStream is paused. 21 */ 22 23 async function setupPeerConnectionAndWaitForTrack(t, kind) { 24 const pc1 = createPeerConnectionWithCleanup(t); 25 pc1.addTrack(... await createTrackAndStreamWithCleanup(t, "video")); 26 const pc2 = createPeerConnectionWithCleanup(t); 27 exchangeIceCandidates(pc1, pc2); 28 29 const haveTrack = waitUntilEvent(pc2, "track"); 30 await exchangeOfferAnswer(pc1, pc2); 31 const {track} = await haveTrack; 32 return {pc1, pc2, track}; 33 } 34 35 async function setupMediaElementAndCheckInitialCurrentTime(t, track) { 36 const elem = document.createElement(track.kind); 37 elem.srcObject = new MediaStream([track]); 38 assert_equals(elem.currentTime, 0, "currentTime starts at 0"); 39 elem.play(); 40 await new Promise(r => elem.ontimeupdate = r); 41 assert_between_exclusive(elem.currentTime, 0, 0.5, 42 "currentTime starts at 0 and has progressed at first timeupdate" 43 ); 44 assert_equals(elem.readyState, elem.HAVE_ENOUGH_DATA, 45 "Media element has enough data once currentTime is progressing" 46 ); 47 return elem; 48 } 49 50 async function checkCurrentTimeProgressing(t, elem) { 51 const currentTime1 = elem.currentTime; 52 // Note that when `currentTime1` was updated by the UA, it dispatched a task 53 // to fire a "timeupdate" event (per the "time marches on" algorithm in the 54 // spec). This event may not have fired yet, which is why we must wait for two 55 // such events. 56 try { 57 await Promise.race([ 58 (async () => 59 { 60 await waitUntilEvent(elem, "timeupdate"); 61 await waitUntilEvent(elem, "timeupdate"); 62 } 63 )(), 64 new Promise((res, rej) => t.step_timeout(rej, 3000)), 65 ]); 66 } catch(e) { 67 assert_unreached("Timed out waiting for timeupdate"); 68 } 69 assert_greater_than(elem.currentTime, currentTime1); 70 } 71 72 async function setSenderActive(t, sender, active) { 73 const parameters = sender.getParameters(); 74 parameters.encodings[0].active = active; 75 await sender.setParameters(parameters); 76 // Wait a bit longer to be certain the parameter changes have propagated to 77 // the receiver. 78 await new Promise(r => t.step_timeout(r, 100)); 79 } 80 81 promise_test(async t => { 82 const {track} = await setupPeerConnectionAndWaitForTrack(t, "audio"); 83 const elem = await setupMediaElementAndCheckInitialCurrentTime(t, track); 84 await checkCurrentTimeProgressing(t, elem); 85 }, 'currentTime advances for receive audio track of active sender'); 86 87 promise_test(async t => { 88 const {track} = await setupPeerConnectionAndWaitForTrack(t, "video"); 89 const elem = await setupMediaElementAndCheckInitialCurrentTime(t, track); 90 await checkCurrentTimeProgressing(t, elem); 91 }, 'currentTime advances for receive video track of active sender'); 92 93 promise_test(async t => { 94 const {pc1, track} = await setupPeerConnectionAndWaitForTrack(t, "audio"); 95 const elem = await setupMediaElementAndCheckInitialCurrentTime(t, track); 96 await setSenderActive(t, pc1.getSenders()[0], false); 97 await checkCurrentTimeProgressing(t, elem); 98 }, 'currentTime advances for receive audio track of inactive sender'); 99 100 promise_test(async t => { 101 const {pc1, track} = await setupPeerConnectionAndWaitForTrack(t, "video"); 102 const elem = await setupMediaElementAndCheckInitialCurrentTime(t, track); 103 await setSenderActive(t, pc1.getSenders()[0], false); 104 await checkCurrentTimeProgressing(t, elem); 105 }, 'currentTime advances for receive video track of inactive sender'); 106 107 </script>