test_peerConnection_trackDisabling_clones.html (6414B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="pc.js"></script> 5 <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script> 6 </head> 7 <body> 8 <pre id="test"> 9 <script type="application/javascript"> 10 createHTML({ 11 bug: "1219711", 12 title: "Disabling locally should be reflected remotely, individually for clones" 13 }); 14 15 runNetworkTest(async () => { 16 var test = new PeerConnectionTest(); 17 18 await pushPrefs( 19 ["media.getusermedia.camera.stop_on_disable.enabled", true], 20 ["media.getusermedia.camera.stop_on_disable.delay_ms", 0], 21 ["media.getusermedia.microphone.stop_on_disable.enabled", true], 22 ["media.getusermedia.microphone.stop_on_disable.delay_ms", 0], 23 // Always use fake tracks since we depend on audio to have a large 1000Hz 24 // component. 25 ['media.audio_loopback_dev', ''], 26 ['media.navigator.streams.fake', true]); 27 // [TODO] re-enable HW decoder after bug 1526207 is fixed. 28 if (navigator.userAgent.includes("Android")) { 29 await pushPrefs(["media.navigator.mediadatadecoder_vpx_enabled", false], 30 ["media.webrtc.hw.h264.enabled", false]); 31 } 32 33 var originalStream; 34 var localVideoOriginal; 35 36 test.setMediaConstraints([{audio: true, video: true}], []); 37 test.chain.replace("PC_LOCAL_GUM", [ 38 function PC_LOCAL_GUM_CLONE() { 39 return getUserMedia(test.pcLocal.constraints[0]).then(stream => { 40 originalStream = stream; 41 localVideoOriginal = 42 createMediaElement("video", "local-original"); 43 localVideoOriginal.srcObject = stream; 44 test.pcLocal.attachLocalStream(originalStream.clone()); 45 }); 46 } 47 ]); 48 test.chain.append([ 49 function CHECK_ASSUMPTIONS() { 50 is(test.pcLocal.localMediaElements.length, 2, 51 "pcLocal should have one media element"); 52 is(test.pcRemote.remoteMediaElements.length, 2, 53 "pcRemote should have one media element"); 54 is(test.pcLocal._pc.getLocalStreams().length, 1, 55 "pcLocal should have one stream"); 56 is(test.pcRemote._pc.getRemoteStreams().length, 1, 57 "pcRemote should have one stream"); 58 }, 59 async function CHECK_VIDEO() { 60 info("Checking video"); 61 var h = new CaptureStreamTestHelper2D(); 62 var localVideoClone = test.pcLocal.localMediaElements 63 .find(e => e instanceof HTMLVideoElement); 64 var remoteVideoClone = test.pcRemote.remoteMediaElements 65 .find(e => e instanceof HTMLVideoElement); 66 67 // We check a pixel somewhere away from the top left corner since 68 // MediaEngineFake puts semi-transparent time indicators there. 69 const offsetX = 50; 70 const offsetY = 50; 71 const threshold = 128; 72 const remoteDisabledColor = h.black; 73 74 // We're regarding black as disabled here, and we're setting the alpha 75 // channel of the pixel to 255 to disregard alpha when testing. 76 var checkVideoEnabled = video => h.waitForPixel(video, 77 px => { 78 px[3] = 255; 79 return h.isPixelNot(px, h.black, threshold); 80 }, 81 { offsetX, offsetY } 82 ); 83 var checkVideoDisabled = video => h.waitForPixel(video, 84 px => { 85 px[3] = 255; 86 return h.isPixel(px, h.black, threshold); 87 }, 88 { offsetX, offsetY } 89 ); 90 91 info("Checking local original enabled"); 92 await checkVideoEnabled(localVideoOriginal); 93 info("Checking local clone enabled"); 94 await checkVideoEnabled(localVideoClone); 95 info("Checking remote clone enabled"); 96 await checkVideoEnabled(remoteVideoClone); 97 98 info("Disabling original"); 99 originalStream.getVideoTracks()[0].enabled = false; 100 101 info("Checking local original disabled"); 102 await checkVideoDisabled(localVideoOriginal); 103 info("Checking local clone enabled"); 104 await checkVideoEnabled(localVideoClone); 105 info("Checking remote clone enabled"); 106 await checkVideoEnabled(remoteVideoClone); 107 108 info("Re-enabling original; disabling clone"); 109 originalStream.getVideoTracks()[0].enabled = true; 110 test.pcLocal._pc.getLocalStreams()[0].getVideoTracks()[0].enabled = false; 111 112 info("Checking local original enabled"); 113 await checkVideoEnabled(localVideoOriginal); 114 info("Checking local clone disabled"); 115 await checkVideoDisabled(localVideoClone); 116 info("Checking remote clone disabled"); 117 await checkVideoDisabled(remoteVideoClone); 118 }, 119 async function CHECK_AUDIO() { 120 info("Checking audio"); 121 var ac = new AudioContext(); 122 var localAnalyserOriginal = new AudioStreamAnalyser(ac, originalStream); 123 var localAnalyserClone = 124 new AudioStreamAnalyser(ac, test.pcLocal._pc.getLocalStreams()[0]); 125 var remoteAnalyserClone = 126 new AudioStreamAnalyser(ac, test.pcRemote._pc.getRemoteStreams()[0]); 127 128 var freq = localAnalyserOriginal.binIndexForFrequency(TEST_AUDIO_FREQ); 129 var checkAudioEnabled = analyser => 130 analyser.waitForAnalysisSuccess(array => array[freq] > 200); 131 var checkAudioDisabled = analyser => 132 analyser.waitForAnalysisSuccess(array => array[freq] < 50); 133 134 info("Checking local original enabled"); 135 await checkAudioEnabled(localAnalyserOriginal); 136 info("Checking local clone enabled"); 137 await checkAudioEnabled(localAnalyserClone); 138 info("Checking remote clone enabled"); 139 await checkAudioEnabled(remoteAnalyserClone); 140 141 info("Disabling original"); 142 originalStream.getAudioTracks()[0].enabled = false; 143 144 info("Checking local original disabled"); 145 await checkAudioDisabled(localAnalyserOriginal); 146 info("Checking local clone enabled"); 147 await checkAudioEnabled(localAnalyserClone); 148 info("Checking remote clone enabled"); 149 await checkAudioEnabled(remoteAnalyserClone); 150 151 info("Re-enabling original; disabling clone"); 152 originalStream.getAudioTracks()[0].enabled = true; 153 test.pcLocal._pc.getLocalStreams()[0].getAudioTracks()[0].enabled = false; 154 155 info("Checking local original enabled"); 156 await checkAudioEnabled(localAnalyserOriginal); 157 info("Checking local clone disabled"); 158 await checkAudioDisabled(localAnalyserClone); 159 info("Checking remote clone disabled"); 160 await checkAudioDisabled(remoteAnalyserClone); 161 }, 162 ]); 163 await test.run(); 164 }); 165 </script> 166 </pre> 167 </body> 168 </html>