| <!DOCTYPE html> <!-- webkit-test-runner [ allowTestOnlyIPC=true ] --> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>Capture source interruption and AudioSession category</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| </head> |
| <body> |
| <script> |
| function wait1sForMute(track, testName) |
| { |
| return new Promise((resolve, reject) => { |
| track.onmute = resolve; |
| setTimeout(() => reject("rejected mute for " + testName), 1000); |
| }); |
| } |
| |
| function wait1sForUnmute(track, testName) |
| { |
| return new Promise((resolve, reject) => { |
| track.onunmute = resolve; |
| setTimeout(() => reject("rejected unmute for " + testName), 1000); |
| }); |
| } |
| |
| const streams = []; |
| var context = new AudioContext(); |
| promise_test(async (test) => { |
| test.add_cleanup(() => streams.forEach(stream => stream.getTracks().forEach(track => track.stop()))); |
| |
| const stream = await navigator.mediaDevices.getUserMedia({audio: true}); |
| streams.push(stream); |
| if (!window.internals) |
| return; |
| assert_equals(internals.audioSessionCategory(), "PlayAndRecord", "test1"); |
| |
| // Muting capture should trigger change of category. |
| const onMutePromise1 = wait1sForMute(stream.getAudioTracks()[0], "onMutePromise1"); |
| if (window.internals) |
| internals.setPageMuted("capturedevices"); |
| await onMutePromise1; |
| // We clone the capture stream to trigger an audio session category recomputation. |
| let clone = stream.clone(); |
| streams.push(clone); |
| assert_equals(internals.audioSessionCategory(), "AmbientSound", "test2"); |
| |
| const onUnmutePromise1 = wait1sForUnmute(stream.getAudioTracks()[0], "onUnmutePromise1"); |
| if (window.internals) |
| internals.setPageMuted(""); |
| await onUnmutePromise1; |
| clone = stream.clone(); |
| streams.push(clone); |
| assert_equals(internals.audioSessionCategory(), "PlayAndRecord", "test3"); |
| |
| // PlayAndRecord should stick even with capture interruption. |
| const onMutePromise2 = wait1sForMute(stream.getAudioTracks()[0], "onMutePromise2"); |
| if (window.internals) |
| internals.beginAudioSessionInterruption(); |
| await onMutePromise2; |
| clone = stream.clone(); |
| streams.push(clone); |
| assert_equals(internals.audioSessionCategory(), "PlayAndRecord", "test4"); |
| |
| const onUnmutePromise2 = wait1sForUnmute(stream.getAudioTracks()[0], "onUnmutePromise2"); |
| if (window.internals) |
| internals.endAudioSessionInterruption(); |
| await onUnmutePromise2; |
| clone = stream.clone(); |
| streams.push(clone); |
| assert_equals(internals.audioSessionCategory(), "PlayAndRecord", "test5"); |
| }, "AudioSession category should staty to PlayAndRecord when interrupted, not when muted by user"); |
| </script> |
| </body> |
| </html> |