test_peerConnection_trackDisabling.html (4212B)
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" 13 }); 14 15 runNetworkTest(async () => { 16 const 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 video to be somewhat green and 24 // audio to have a large 1000Hz component. 25 ['media.audio_loopback_dev', ''], 26 ['media.video_loopback_dev', ''], 27 ['media.navigator.streams.fake', true]); 28 29 test.setMediaConstraints([{audio: true, video: true}], []); 30 test.chain.append([ 31 function CHECK_ASSUMPTIONS() { 32 is(test.pcLocal.localMediaElements.length, 2, 33 "pcLocal should have one media element"); 34 is(test.pcRemote.remoteMediaElements.length, 2, 35 "pcRemote should have one media element"); 36 is(test.pcLocal._pc.getLocalStreams().length, 1, 37 "pcLocal should have one stream"); 38 is(test.pcRemote._pc.getRemoteStreams().length, 1, 39 "pcRemote should have one stream"); 40 }, 41 async function CHECK_VIDEO() { 42 const h = new CaptureStreamTestHelper2D(); 43 const localVideo = test.pcLocal.localMediaElements 44 .find(e => e instanceof HTMLVideoElement); 45 const remoteVideo = test.pcRemote.remoteMediaElements 46 .find(e => e instanceof HTMLVideoElement); 47 // We check a pixel somewhere away from the top left corner since 48 // MediaEngineFake puts semi-transparent time indicators there. 49 const offsetX = 50; 50 const offsetY = 50; 51 const threshold = 128; 52 53 // We're regarding black as disabled here, and we're setting the alpha 54 // channel of the pixel to 255 to disregard alpha when testing. 55 const checkVideoEnabled = video => h.waitForPixel(video, 56 px => { 57 px[3] = 255; 58 return h.isPixelNot(px, h.black, threshold); 59 }, 60 { offsetX, offsetY } 61 ); 62 const checkVideoDisabled = video => h.waitForPixel(video, 63 px => { 64 px[3] = 255; 65 return h.isPixel(px, h.black, threshold); 66 }, 67 { offsetX, offsetY } 68 ); 69 70 info("Checking local video enabled"); 71 await checkVideoEnabled(localVideo); 72 info("Checking remote video enabled"); 73 await checkVideoEnabled(remoteVideo); 74 75 info("Disabling original"); 76 test.pcLocal._pc.getLocalStreams()[0].getVideoTracks()[0].enabled = false; 77 78 info("Checking local video disabled"); 79 await checkVideoDisabled(localVideo); 80 info("Checking remote video disabled"); 81 await checkVideoDisabled(remoteVideo); 82 }, 83 async function CHECK_AUDIO() { 84 const ac = new AudioContext(); 85 const localAnalyser = new AudioStreamAnalyser(ac, test.pcLocal._pc.getLocalStreams()[0]); 86 const remoteAnalyser = new AudioStreamAnalyser(ac, test.pcRemote._pc.getRemoteStreams()[0]); 87 88 const checkAudio = (analyser, fun) => analyser.waitForAnalysisSuccess(fun); 89 90 const freq = localAnalyser.binIndexForFrequency(TEST_AUDIO_FREQ); 91 const checkAudioEnabled = analyser => 92 checkAudio(analyser, array => array[freq] > 200); 93 const checkAudioDisabled = analyser => 94 checkAudio(analyser, array => array[freq] < 50); 95 96 info("Checking local audio enabled"); 97 await checkAudioEnabled(localAnalyser); 98 info("Checking remote audio enabled"); 99 await checkAudioEnabled(remoteAnalyser); 100 101 test.pcLocal._pc.getLocalStreams()[0].getAudioTracks()[0].enabled = false; 102 103 info("Checking local audio disabled"); 104 await checkAudioDisabled(localAnalyser); 105 info("Checking remote audio disabled"); 106 await checkAudioDisabled(remoteAnalyser); 107 }, 108 ]); 109 await test.run(); 110 }); 111 </script> 112 </pre> 113 </body> 114 </html>