Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
// A site the user allowed earlier asks the AudioServer to capture when getUserMedia() opens the microphone. While
// the system denies the browser the microphone, every such capture is refused, but the user is told only once, and
// the site's permission is left as it was.
asyncTest(async done => {
const state = () => JSON.parse(internals.microphoneState());
// The process counts its capture decisions, and an earlier test may have run in it.
const { captureDecisions: decisionsBefore, captureRefusals: refusalsBefore } = state();
const captureDecisions = () => state().captureDecisions - decisionsBefore;
const captureRefusals = () => state().captureRefusals - refusalsBefore;
const captureDecided = count => waitForCondition(() => captureDecisions() >= count);
await internals.setPermission("microphone", "granted");
internals.setSystemMicrophoneAuthorization("denied");
internals.setNextPermissionPromptOutcome("microphone", "dismiss");
for (let i = 1; i <= 2; ++i) {
try {
await navigator.mediaDevices.getUserMedia({ audio: true });
println("getUserMedia: resolved");
} catch (error) {
println(`getUserMedia: ${error.name}`);
}
await captureDecided(i);
// A capture of the same device joins one that waits on the AudioServer, so the next starts once this one's
// refusal has reached this process.
await waitForCondition(() => !internals.audioCaptureIsPending());
}
const { noticesShown, dismissals } = state();
println(`capture decisions: ${captureDecisions()}`);
println(`capture refusals: ${captureRefusals()}`);
println(`notices shown: ${noticesShown}`);
println(`dismissals: ${dismissals}`);
println(`query: ${(await navigator.permissions.query({ name: "microphone" })).state}`);
println(`request: ${await internals.requestPermission("microphone")}`);
done();
});
</script>