blob: 1d4811818170b9f5dbf76bd175e11c75b7dd23da [file] [edit]
<!doctype html> <!-- webkit-test-runner [ allowTestOnlyIPC=true ] -->
<html>
<head>
<meta charset="utf-8">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
</head>
<body>
<video id="localVideo" muted autoplay playsInline></video>
<video id="remoteVideo" autoplay playsInline></video>
<script>
function waitForStateChange()
{
return new Promise((resolve, reject) => {
navigator.audioSession.onstatechange = () => resolve(navigator.audioSession.state);
setTimeout(() => reject("no audio session state change"), 3000);
});
}
promise_test(async (test) => {
assert_equals(navigator.audioSession.type, "auto");
assert_equals(navigator.audioSession.state, "inactive");
localVideo.srcObject = await navigator.mediaDevices.getUserMedia({ audio:true, video: true });
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);
pc1.addTrack(localVideo.srcObject.getAudioTracks()[0], localVideo.srcObject);
pc2.ontrack = e => remoteVideo.srcObject = e.streams[0];
await pc1.setLocalDescription();
await pc2.setRemoteDescription(pc1.localDescription);
await pc2.setLocalDescription(await pc2.createAnswer());
await pc1.setRemoteDescription(pc2.localDescription);
await localVideo.play();
await remoteVideo.play();
if (navigator.audioSession.state != "active")
assert_equals(await waitForStateChange(), "active");
if (!window.internals)
return;
internals.setMediaSessionRestrictions("audio", "interruptedplaybacknotpermitted");
internals.setMediaSessionRestrictions("video", "interruptedplaybacknotpermitted");
statePromise = waitForStateChange();
internals.beginAudioSessionInterruption();
assert_equals(await statePromise, "interrupted");
await new Promise(resolve => setTimeout(resolve, 50));
statePromise = waitForStateChange();
internals.endAudioSessionInterruption();
assert_equals(await statePromise, "active");
}, "AudioSession and interruption");
</script>
</body>
</html>