blob: 15cf80513ef481a8796fd3d71b06c05c5575d562 [file] [log] [blame]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing video rotation in basic video exchange </title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<video id="video" autoplay playsInline width="320" height="240"></video>
<canvas id="canvas1" width="320" height="240"></canvas>
<canvas id="canvas2" width="320" height="240"></canvas>
<canvas id="canvas3" width="320" height="240"></canvas>
<script src ="routines.js"></script>
<script>
function isVideoBlack(id)
{
var canvas = document.getElementById(id);
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height);
data = imageData.data;
for (var cptr = 0; cptr < canvas.width * canvas.height; ++cptr) {
// Approximatively black pixels.
if (data[4 * cptr] > 30 || data[4 * cptr + 1] > 30 || data[4 * cptr + 2] > 30)
return false;
}
return true;
}
function pollVideoBlackCheck(expected, id, resolve)
{
if (isVideoBlack(id) === expected) {
resolve();
return;
}
setTimeout(() => pollVideoBlackCheck(expected, id, resolve), 100);
}
function checkVideoBlack(expected, id)
{
return new Promise((resolve, reject) => {
pollVideoBlackCheck(expected, id, resolve);
setTimeout(() => reject("checkVideoBlack timed out for '" + id + "', expected " + expected), 5000);
});
}
var track;
promise_test((test) => {
if (window.testRunner)
testRunner.setUserMediaPermission(true);
return navigator.mediaDevices.getUserMedia({video: {width: 320, height: 240, facingMode: "environment"}}).then((localStream) => {
return new Promise((resolve, reject) => {
track = localStream.getVideoTracks()[0];
createConnections((firstConnection) => {
firstConnection.addTrack(track, localStream);
if (window.internals)
internals.applyRotationForOutgoingVideoSources(firstConnection);
}, (secondConnection) => {
secondConnection.ontrack = (trackEvent) => {
resolve(trackEvent.streams[0]);
};
});
setTimeout(() => reject("Test timed out"), 5000);
});
}).then((remoteStream) => {
video.srcObject = remoteStream;
return video.play();
});
}, "Setting video exchange");
promise_test((test) => {
return checkVideoBlack(false, "canvas1");
}, "Track is enabled, video should not be black");
promise_test((test) => {
if (window.internals)
window.internals.setCameraMediaStreamTrackOrientation(track, 90);
return checkVideoBlack(false, "canvas1").then(() => {
return waitForVideoSize(video, 240, 320);
});
}, "Track is enabled and rotated, video should not be black and should change size");
</script>
</body>
</html>