mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
81 lines
2.7 KiB
HTML
81 lines
2.7 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test for bug 1073406. Pausing a video element should not pause another playing the same stream.</title>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
<script type="text/javascript" src="manifest.js"></script>
|
|
<script type="text/javascript" src="gUM_support.js"></script>
|
|
</head>
|
|
<body>
|
|
<video id="video1" autoplay></video>
|
|
<video id="video2" autoplay></video>
|
|
<script class="testbody" type="text/javascript">
|
|
async function startTest() {
|
|
function getVideoImagePixelData(v) {
|
|
let canvas = document.createElement("canvas");
|
|
let ctx = canvas.getContext("2d");
|
|
ctx.drawImage(v, 0, 0);
|
|
let imgData = ctx.getImageData(canvas.width/2, canvas.height/2, 1, 1).data;
|
|
return "r" + imgData[0] +
|
|
"g" + imgData[1] +
|
|
"b" + imgData[2] +
|
|
"a" + imgData[3];
|
|
}
|
|
|
|
try {
|
|
// This test expects fake devices so that the video color will change
|
|
// over time, explicitly request fakes.
|
|
await pushGetUserMediaTestPrefs({fakeAudio: true, fakeVideo: true});
|
|
let stream = await navigator.mediaDevices.getUserMedia({video: true});
|
|
let video1 = document.getElementById('video1');
|
|
let video2 = document.getElementById('video2');
|
|
|
|
video1.srcObject = stream;
|
|
video2.srcObject = stream;
|
|
|
|
video1.onplaying = () => video1.pause();
|
|
|
|
let v1PausedImageData;
|
|
let v2PausedImageData;
|
|
|
|
video1.onpause = function() {
|
|
v1PausedImageData = getVideoImagePixelData(video1);
|
|
v2PausedImageData = getVideoImagePixelData(video2);
|
|
v2TimesToTest = 3;
|
|
video2.ontimeupdate = function() {
|
|
if (getVideoImagePixelData(video2) === v2PausedImageData) {
|
|
// Wait until video2 has progressed it's video.
|
|
// If it doesn't, we'll time out and fail.
|
|
info("video2 has not progressed. Waiting.");
|
|
return;
|
|
}
|
|
|
|
if (--v2TimesToTest > 0) {
|
|
// Wait for a while to be sure video1 would have gotten a frame
|
|
// if it is playing.
|
|
info("video2 progressed OK");
|
|
return;
|
|
}
|
|
|
|
video2.ontimeupdate = null;
|
|
ok(true, "video2 is playing");
|
|
isnot(video1.currentTime, video2.currentTime,
|
|
"v1 and v2 should not be at the same currentTime");
|
|
is(v1PausedImageData, getVideoImagePixelData(video1),
|
|
"video1 video frame should not have updated since video1 paused");
|
|
SimpleTest.finish();
|
|
};
|
|
};
|
|
} catch (error) {
|
|
ok(false, "getUserMedia should not fail, got " + error.name);
|
|
SimpleTest.finish();
|
|
}
|
|
}
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
startTest();
|
|
</script>
|
|
</body>
|
|
</html>
|