blob: e5a365ccbabe719591e2ccce40664612ed494a70 [file] [log] [blame]
<!DOCTYPE HTML>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests getUserMedia (Promise-based version on navigator.mediaDevices)");
function setUserMediaPermission(isGranted) {
if (window.testRunner)
testRunner.setUserMediaPermission(isGranted);
else
debug("This test can not be run without the testRunner");
}
var stream;
var errorArg;
let audioConstraints;
let videoConstraints;
function invalidGotStream() {
testFailed("Stream generated when an error should have occurred.");
finishJSTest();
}
function error2(e) {
testPassed("Error callback called.");
finishJSTest();
}
function error1(e) {
errorArg = e;
testPassed("Error callback called.");
shouldBeEqualToString("errorArg.name", "NotAllowedError");
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:true}).then(invalidGotStream).catch(error2);");
}
function errorWithConstraints2() {
testPassed("Error callback called.");
setUserMediaPermission(false);
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:true}).then(invalidGotStream, error1);");
}
function errorWithConstraints1() {
testPassed("Error callback called.");
videoConstraints = {
width: {
max: -1,
ideal: 2
},
height: 11
};
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:false, video:videoConstraints}).then(invalidGotStream).catch(errorWithConstraints2)");
}
function gotStreamWithConstraints2() {
testPassed("Stream generated.");
audioConstraints = {
sampleRate: {
min: 6,
max: 5,
ideal: 10
},
sampleSize: 11
};
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:audioConstraints, video:false}).then(invalidGotStream).catch(errorWithConstraints1)");
}
function gotStreamWithConstraints1() {
testPassed("Stream generated.");
videoConstraints = {
width: {
min: 5,
exact: 5,
max: 5,
ideal: 2
},
height: 11,
facingMode: {
exact:['valid']
}
};
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:false, video:videoConstraints}).then(gotStreamWithConstraints2)");
}
function gotStream4(s) {
stream = s;
testPassed("Stream generated.");
shouldBe("stream.getAudioTracks().length", "1");
shouldBe("stream.getVideoTracks().length", "1");
audioConstraints = {
sampleRate: {
min: 5,
exact: 5,
max: 5,
ideal: 2
},
sampleSize: 11
};
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:audioConstraints, video:false}).then(gotStreamWithConstraints1)");
}
function gotStream3(s) {
stream = s;
testPassed("Stream generated.");
shouldBe("stream.getAudioTracks().length", "1");
shouldBe("stream.getVideoTracks().length", "1");
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:{}, video:{}}).then(gotStream4);");
}
function gotStream2(s) {
stream = s;
testPassed("Stream generated.");
shouldBe("stream.getAudioTracks().length", "0");
shouldBe("stream.getVideoTracks().length", "1");
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:true, video:true}).then(gotStream3);");
}
function gotStream1(s) {
stream = s;
testPassed("Stream generated.");
shouldBe("stream.getAudioTracks().length", "1");
shouldBe("stream.getVideoTracks().length", "0");
shouldNotThrow("navigator.mediaDevices.getUserMedia({video:true}).then(gotStream2);")
}
navigator.mediaDevices.getUserMedia().then(invalidGotStream, function(error) {
testPassed("navigator.mediaDevices.getUserMedia() rejected with error: " + error);
});
navigator.mediaDevices.getUserMedia({}).then(invalidGotStream, function(error) {
testPassed("navigator.mediaDevices.getUserMedia({}) rejected with error: " + error);
});
shouldBe("typeof navigator.mediaDevices.webkitGetUserMedia", "'undefined'");
setUserMediaPermission(true);
shouldNotThrow("navigator.mediaDevices.getUserMedia({audio:true}).then(gotStream1);");
navigator.mediaDevices.getUserMedia.apply(undefined, {audio:true}).then(invalidGotStream, function(error) {
testPassed("navigator.mediaDevices.getUserMedia.apply(undefined) rejected with error: " + error);
});
window.jsTestIsAsync = true;
window.successfullyParsed = true;
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>