| <!DOCTYPE html> |
| <body> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script> |
| function with_iframe(url, allow) { |
| let frame = document.createElement('iframe'); |
| frame.src = url; |
| frame.setAttribute('allow', allow); |
| return new Promise(resolve => { |
| frame.onload = () => { resolve(frame); }; |
| document.body.appendChild(frame); |
| }); |
| } |
| |
| // The frame posts its result from its own load event. Listen before creating the frame: with the |
| // frame in another process, its message and its load notification arrive as separate IPCs, so a |
| // listener installed after awaiting the load can miss the message. |
| function nextMessage() { |
| return new Promise(resolve => window.addEventListener("message", event => resolve(event.data), { once: true })); |
| } |
| |
| promise_test(async () => { |
| navigator.audioSession.type = "play-and-record"; |
| const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); |
| |
| const message1 = nextMessage(); |
| const frame1 = await with_iframe("http://localhost:8080/webrtc/resources/audioSessionFrame.html", "microphone:'none'"); |
| const result1 = await message1; |
| frame1.remove(); |
| |
| const message2 = nextMessage(); |
| const frame2 = await with_iframe("http://localhost:8080/webrtc/resources/audioSessionFrame.html", "microphone"); |
| const result2 = await message2; |
| frame2.remove(); |
| |
| assert_equals(result1.type, "auto"); |
| assert_equals(result1.state, "inactive"); |
| |
| assert_equals(result2.type, "play-and-record"); |
| assert_equals(result2.state, "active"); |
| |
| stream.getTracks().forEach(t => t.stop()); |
| }, "Allow audioSession in iframes where microphone is allowed"); |
| </script> |
| </body> |