blob: b44582142500f61bb68255170479ce0920b8d9c6 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>getDisplayMedia prompt</title>
<script src="../../../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
let stream;
let err;
function numberOfTimesGetUserMediaPromptHasBeenCalled() {
return testRunner.userMediaPermissionRequestCountForOrigin(document.location.href, document.location.href);
}
async function promptForAudioOnly() {
debug("<br>** Request an audio-only stream, the user should be prompted **");
stream = await navigator.mediaDevices.getDisplayMedia({ audio: true });
shouldBe("numberOfTimesGetUserMediaPromptHasBeenCalled()", "1");
shouldBe("stream.getAudioTracks().length", "1");
shouldBe("stream.getVideoTracks().length", "0");
}
async function promptForVideoOnly() {
debug("<br>** Request an video-only stream, the user should be prompted **");
stream = await navigator.mediaDevices.getDisplayMedia({ video: true });
shouldBe("numberOfTimesGetUserMediaPromptHasBeenCalled()", "2");
shouldBe("stream.getAudioTracks().length", "0");
shouldBe("stream.getVideoTracks().length", "1");
}
async function promptForAudioAndVideo() {
debug("<br>** Request a stream with audio and video, the user should be prompted **");
stream = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: true });
shouldBe("numberOfTimesGetUserMediaPromptHasBeenCalled()", "3");
shouldBe("stream.getAudioTracks().length", "1");
shouldBe("stream.getVideoTracks().length", "1");
}
async function promptWithMediaTrackConstraints() {
debug("<br>** Request a stream with invalid constraints, the user should not be prompted **");
stream = null;
try {
stream = await navigator.mediaDevices.getDisplayMedia({ video: {width: {exact: 640}, height: {exact: 480}} });
} catch (e) {
err = e;
}
shouldBe("numberOfTimesGetUserMediaPromptHasBeenCalled()", "3");
shouldBeNull("stream");
shouldBeTrue("err instanceof Error ");
shouldBeEqualToString("err.name", "InvalidAccessError");
}
(async function() {
description('Test basic getDisplayMedia prompting behavior');
jsTestIsAsync = true;
testRunner.resetUserMediaPermissionRequestCountForOrigin(document.location.href, document.location.href);
window.internals.settings.setScreenCaptureEnabled(true);
shouldBe("numberOfTimesGetUserMediaPromptHasBeenCalled()", "0");
await promptForAudioOnly();
await promptForVideoOnly();
await promptForAudioAndVideo();
await promptWithMediaTrackConstraints();
debug("");
finishJSTest();
})()
</script>
<script src="../../../../resources/js-test-post.js"></script>
</body>
</html>