haikuwebkit/LayoutTests/webrtc/video-addTrack.html

85 lines
3.1 KiB
HTML
Raw Permalink Normal View History

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing basic video exchange from offerer to receiver</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<video id="video" autoplay=""></video>
<canvas id="canvas" width="640" height="480"></canvas>
<script src ="routines.js"></script>
<script>
video = document.getElementById("video");
canvas = document.getElementById("canvas");
function testImage(wait)
{
test(() => {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = canvas.getContext('2d').getImageData(10, 325, 250, 1);
data = imageData.data;
var index = 20;
assert_true(data[index] < 100);
assert_true(data[index + 1] < 100);
assert_true(data[index + 2] < 100);
index = 80;
assert_true(data[index] > 200);
assert_true(data[index + 1] > 200);
assert_true(data[index + 2] > 200);
index += 80;
assert_true(data[index] > 200);
assert_true(data[index + 1] > 200);
assert_true(data[index + 2] < 100);
}, "Testing image result, wait = " + wait);
}
function testBasicVideoExchangeWithAddTrack(waitForSecondTrack)
{
promise_test((test) => {
if (window.testRunner)
testRunner.setUserMediaPermission(true);
return navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((stream) => {
return new Promise((resolve, reject) => {
createConnections((firstConnection) => {
assert_equals(stream.getTracks().length, 2);
Add a runtime flag for WebRTC unified plan https://bugs.webkit.org/show_bug.cgi?id=189068 Reviewed by Eric Carlson. LayoutTests/imported/w3c: * web-platform-tests/webrtc/RTCPeerConnection-addTrack.https-expected.txt: Source/WebCore: Covered by existing updated tests. Main change is to call addTrack with a stream parameter so that on the other side, the track will be tied to a stream. Receive-only case in unified plan is not yet supported. This will be supported in follow-up patches. * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp: (WebCore::LibWebRTCMediaEndpoint::setConfiguration): Activate unified plan based on runtime flag. (WebCore::LibWebRTCMediaEndpoint::addTrack): Do not use AddStream in case of unified plan. (WebCore::LibWebRTCMediaEndpoint::shouldOfferAllowToReceiveAudio const): (WebCore::LibWebRTCMediaEndpoint::shouldOfferAllowToReceiveVideo const): (WebCore::LibWebRTCMediaEndpoint::doCreateOffer): Use legacy webrtc option for receive only cases only in plan B case. * page/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::webRTCUnifiedPlanEnabled const): (WebCore::RuntimeEnabledFeatures::setWebRTCUnifiedPlanEnabled): Source/WebKit: * Shared/WebPreferences.yaml: * WebProcess/InjectedBundle/InjectedBundle.cpp: (WebKit::InjectedBundle::overrideBoolPreferenceForTestRunner): Tools: * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::TestRunner::setWebRTCUnifiedPlanEnabled): * WebKitTestRunner/InjectedBundle/TestRunner.h: LayoutTests: * fast/mediastream/RTCPeerConnection-add-removeTrack-expected.txt: * webrtc/peer-connection-audio-mute2.html: * webrtc/peer-connection-remote-audio-mute2.html: * webrtc/video-addTrack-expected.txt: * webrtc/video-addTrack.html: * webrtc/video-addTransceiver.html: Canonical link: https://commits.webkit.org/204132@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-08-29 21:50:28 +00:00
stream.getTracks().forEach(track => firstConnection.addTrack(track, stream));
}, (secondConnection) => {
var count = 0;
secondConnection.ontrack = (trackEvent) => {
window.test(function() {
if (trackEvent.track.kind === "video")
assert_equals(trackEvent.track.id, stream.getVideoTracks()[0].id);
else
assert_equals(trackEvent.track.id, stream.getAudioTracks()[0].id);
assert_equals(trackEvent.streams.length, 1);
assert_equals(trackEvent.streams[0].getTracks().length, 2);
}, " track " + count + ", wait = " + waitForSecondTrack);
if (count++ === (waitForSecondTrack ? 1 : 0))
resolve(trackEvent.streams[0]);
};
});
setTimeout(() => reject("Test timed out"), 5000);
});
}).then((stream) => {
video.srcObject = stream;
return video.play();
}).then(() => {
testImage(waitForSecondTrack);
});
}, "Basic video exchange with addTrack - " + (waitForSecondTrack ? "waiting for second track before playing" : "not waiting for second track to play"));
}
testBasicVideoExchangeWithAddTrack(true);
testBasicVideoExchangeWithAddTrack(false);
</script>
</body>
</html>