| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>Testing change of device while capturing.</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| </head> |
| <body> |
| <video id="video"></video> |
| <script> |
| let setup = async (test) => { |
| if (!window.testRunner) |
| return Promise.reject("test requires internal API"); |
| |
| test.add_cleanup(() => { testRunner.resetMockMediaDevices(); }); |
| } |
| |
| async function getDeviceId(label) |
| { |
| const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); |
| const devices = await navigator.mediaDevices.enumerateDevices(); |
| let deviceId; |
| devices.forEach(device => { |
| if (device.label === "my USB microphone") |
| deviceId = device.deviceId; |
| }); |
| |
| stream.getAudioTracks()[0].stop(); |
| |
| return deviceId; |
| } |
| |
| promise_test(async (test) => { |
| await setup(test); |
| |
| testRunner.addMockMicrophoneDevice("usbmic", "my USB microphone"); |
| const deviceId = await getDeviceId("my USB microphone"); |
| video.srcObject = await navigator.mediaDevices.getUserMedia({ audio: { deviceId } }); |
| await video.play(); |
| |
| testRunner.removeMockMediaDevice("usbmic"); |
| return new Promise((resolve, reject) => { |
| video.srcObject.getAudioTracks()[0].onended = resolve; |
| setTimeout(reject, 2000); |
| }); |
| }, "Detection of missing capturing device should trigger capture to fail"); |
| |
| promise_test(async (test) => { |
| await setup(test); |
| |
| testRunner.addMockMicrophoneDevice("usbmic1", "my USB microphone"); |
| testRunner.addMockMicrophoneDevice("usbmic2", "my second USB microphone"); |
| const deviceId = await getDeviceId("my USB microphone"); |
| video.srcObject = await navigator.mediaDevices.getUserMedia({ audio: { deviceId } }); |
| await video.play(); |
| testRunner.removeMockMediaDevice("usbmic2"); |
| testRunner.addMockMicrophoneDevice("usbmic3", "my third USB microphone"); |
| await new Promise(resolve => setTimeout(resolve, 200)); |
| assert_equals(video.srcObject.getAudioTracks()[0].readyState, "live"); |
| video.srcObject.getAudioTracks()[0].stop(); |
| }, "Adding or removing a new device should not fail ongoing capture"); |
| </script> |
| </body> |
| </html> |