cors-check.https.html (2580B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 Test if MediaElementAudioSourceNode works for cross-origin redirects with 6 "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 audioElement.crossOrigin = 'anonymous'; 25 const wav = 26 host_info.HTTPS_ORIGIN + '/webaudio/resources/4ch-440.wav?' + 27 'pipe=header(access-control-allow-origin,*)'; 28 audioElement.src = 29 host_info.HTTPS_REMOTE_ORIGIN + 30 '/fetch/api/resources/redirect.py?location=' + 31 encodeURIComponent(wav); 32 let source; 33 let workletRecorder; 34 35 audit.define( 36 {label: 'setting-up-graph'}, 37 (task, should) => { 38 source = new MediaElementAudioSourceNode(context, { 39 mediaElement: audioElement 40 }); 41 workletRecorder = new AudioWorkletNode( 42 context, 'recorder-processor', {channelCount: 4}); 43 source.connect(workletRecorder).connect(context.destination); 44 task.done(); 45 }); 46 47 // The recorded data from MESN must be non-zero. The source file contains 48 // 4 channels of sine wave. 49 audit.define( 50 {label: 'start-playback-and-capture'}, 51 (task, should) => { 52 workletRecorder.port.onmessage = (event) => { 53 if (event.data.type === 'recordfinished') { 54 for (let i = 0; i < event.data.recordBuffer.length; ++i) { 55 const channelData = event.data.recordBuffer[i]; 56 should(channelData, `Recorded channel #${i}`) 57 .notBeConstantValueOf(0); 58 } 59 } 60 61 task.done(); 62 }; 63 64 context.resume(); 65 audioElement.play(); 66 }); 67 68 Promise.all([ 69 context.audioWorklet.addModule('/webaudio/js/worklet-recorder.js') 70 ]).then(() => { 71 audit.run(); 72 }); 73 }); 74 </script> 75 </body> 76 </html>