no-cors.https.html (2532B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 Test if MediaElementAudioSourceNode works for cross-origin redirects with 6 "no-cors" request mode. 7 </title> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/webaudio/resources/audit.js"></script> 11 <script src="/common/get-host-info.sub.js"></script> 12 </head> 13 <body> 14 <script id="layout-test-code"> 15 const audit = Audit.createTaskRunner(); 16 17 setup(() => { 18 const context = new AudioContext(); 19 context.suspend(); 20 21 const host_info = get_host_info(); 22 const audioElement = document.createElement('audio'); 23 audioElement.loop = true; 24 const wav = 25 host_info.HTTPS_ORIGIN + '/webaudio/resources/4ch-440.wav?' + 26 'pipe=header(access-control-allow-origin,*)'; 27 audioElement.src = 28 host_info.HTTPS_REMOTE_ORIGIN + 29 '/fetch/api/resources/redirect.py?location=' + 30 encodeURIComponent(wav); 31 let source; 32 let workletRecorder; 33 34 audit.define( 35 {label: 'setting-up-graph'}, 36 (task, should) => { 37 source = new MediaElementAudioSourceNode(context, { 38 mediaElement: audioElement 39 }); 40 workletRecorder = new AudioWorkletNode( 41 context, 'recorder-processor', {channelCount: 4}); 42 source.connect(workletRecorder).connect(context.destination); 43 task.done(); 44 }); 45 46 // The recorded data from MESN must be non-zero. The source file contains 47 // 4 channels of sine wave. 48 audit.define( 49 {label: 'start-playback-and-capture'}, 50 (task, should) => { 51 workletRecorder.port.onmessage = (event) => { 52 if (event.data.type === 'recordfinished') { 53 for (let i = 0; i < event.data.recordBuffer.length; ++i) { 54 const channelData = event.data.recordBuffer[i]; 55 should(channelData, `Recorded channel #${i}`) 56 .beConstantValueOf(0); 57 } 58 } 59 60 task.done(); 61 }; 62 63 context.resume(); 64 audioElement.play(); 65 }); 66 67 Promise.all([ 68 context.audioWorklet.addModule('/webaudio/js/worklet-recorder.js') 69 ]).then(() => { 70 audit.run(); 71 }); 72 }); 73 </script> 74 </body> 75 </html>