Updated W3C getusermedia tests to the latest version of the spec.

BUG=webrtc:3455
R=kjellander@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/16719004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6459 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
phoglund@webrtc.org 2014-06-17 08:46:58 +00:00
parent 8f8503d947
commit 6b061425c2
2 changed files with 216 additions and 93 deletions

View File

@ -52,15 +52,16 @@ Notice that this requires the site you're browsing to use HTTPS.
</p> </p>
<div id="log"></div> <div id="log"></div>
<video id="local-view" autoplay="autoplay" muted="true"></video>
<!-- These files are in place when executing on W3C. --> <!-- These files are in place when executing on W3C. -->
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="/common/vendor-prefix.js" <script src="/common/vendor-prefix.js"
data-prefixed-objects= '[{"ancestors":["navigator"], "name":"getUserMedia"}, data-prefixed-objects=
'[{"ancestors":["navigator"], "name":"getUserMedia"},
{"ancestors":["window"], "name":"RTCPeerConnection"}]' {"ancestors":["window"], "name":"RTCPeerConnection"}]'
data-prefixed-prototypes='[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'></script> data-prefixed-prototypes=
'[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'>
</script>
<script src="getusermedia_conformance_test.js"></script> <script src="getusermedia_conformance_test.js"></script>
</body> </body>

View File

@ -6,7 +6,7 @@
// in the file PATENTS. All contributing project authors may // in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree. // be found in the AUTHORS file in the root of the source tree.
setup({timeout:10000}); setup({timeout:5000});
// Helper functions to minimize code duplication. // Helper functions to minimize code duplication.
function failedCallback(test) { function failedCallback(test) {
@ -19,6 +19,14 @@ function invokeGetUserMedia(test, okCallback) {
failedCallback(test)); failedCallback(test));
} }
function createInvisibleVideoTag() {
var video = document.createElement('video');
video.autoplay = true;
video.style.display = 'none';
document.body.appendChild(video);
return video;
}
// 4.2 MediaStream. // 4.2 MediaStream.
var mediaStreamTest = async_test('4.2 MediaStream'); var mediaStreamTest = async_test('4.2 MediaStream');
@ -56,21 +64,25 @@ function verifyMediaStream(stream) {
}, '[MediaStream] removeTrack function'); }, '[MediaStream] removeTrack function');
test(function () { test(function () {
// Missing in Chrome.
assert_inherits(stream, 'clone'); assert_inherits(stream, 'clone');
assert_true(typeof stream.clone === 'function'); assert_true(typeof stream.clone === 'function');
}, '[MediaStream] clone function'); }, '[MediaStream] clone function');
test(function () { test(function () {
assert_own_property(stream, 'ended'); assert_own_property(stream, 'active');
assert_true(typeof stream.ended === 'boolean'); assert_true(typeof stream.active === 'boolean');
assert_readonly(stream, 'ended'); assert_readonly(stream, 'active');
}, '[MediaStream] ended attribute'); }, '[MediaStream] active attribute');
test(function () { test(function () {
assert_own_property(stream, 'onended'); assert_own_property(stream, 'onactive');
assert_true(stream.onended === null); assert_true(stream.onactive === null);
}, '[MediaStream] onended EventHandler'); }, '[MediaStream] onactive EventHandler');
test(function () {
assert_own_property(stream, 'oninactive');
assert_true(stream.oninactive === null);
}, '[MediaStream] oninactive EventHandler');
test(function () { test(function () {
assert_own_property(stream, 'onaddtrack'); assert_own_property(stream, 'onaddtrack');
@ -86,28 +98,43 @@ function verifyMediaStream(stream) {
mediaStreamTest.step(function() { mediaStreamTest.step(function() {
var okCallback = mediaStreamTest.step_func(function (stream) { var okCallback = mediaStreamTest.step_func(function (stream) {
verifyMediaStream(stream); verifyMediaStream(stream);
var videoTracks = stream.getVideoTracks(); var videoTracks = stream.getVideoTracks();
assert_true(videoTracks.length > 0); assert_true(videoTracks.length > 0);
mediaStreamTest.done();
});
// Verify event handlers are working.
stream.onaddtrack = onAddTrackCallback
stream.onremovetrack = onRemoveTrackCallback
stream.removeTrack(videoTracks[0]);
stream.addTrack(videoTracks[0]);
mediaStreamTest.done();
});
var onAddTrackCallback = mediaStreamTest.step_func(function () {
// TODO(kjellander): verify number of tracks.
mediaStreamTest.done();
});
var onRemoveTrackCallback = mediaStreamTest.step_func(function () {
// TODO(kjellander): verify number of tracks.
mediaStreamTest.done();
});
invokeGetUserMedia(mediaStreamTest, okCallback); invokeGetUserMedia(mediaStreamTest, okCallback);
}); });
var mediaStreamCallbacksTest = async_test('4.2.2 MediaStream callbacks');
mediaStreamCallbacksTest.step(function() {
var addCallbackCalled = false;
var onAddTrackCallback = mediaStreamCallbacksTest.step_func(function (event) {
assert_true(event.track instanceof MediaStreamTrack);
addCallbackCalled = true;
});
var onRemoveTrackCallback =
mediaStreamCallbacksTest.step_func(function (event) {
assert_true(event.track instanceof MediaStreamTrack);
assert_true(addCallbackCalled, 'Add should have been called after remove.');
mediaStreamCallbacksTest.done();
});
var okCallback = mediaStreamCallbacksTest.step_func(function (stream) {
var videoTracks = stream.getVideoTracks();
// Verify event handlers are working.
stream.onaddtrack = onAddTrackCallback;
stream.onremovetrack = onRemoveTrackCallback;
stream.removeTrack(videoTracks[0]);
stream.addTrack(videoTracks[0]);
});
invokeGetUserMedia(mediaStreamCallbacksTest, okCallback);
});
// TODO(phoglund): add test for onactive/oninactive.
// 4.3 MediaStreamTrack. // 4.3 MediaStreamTrack.
var mediaStreamTrackTest = async_test('4.3 MediaStreamTrack'); var mediaStreamTrackTest = async_test('4.3 MediaStreamTrack');
@ -140,7 +167,6 @@ function verifyTrack(type, track) {
}, '[MediaStreamTrack (' + type + ')] enabled attribute'); }, '[MediaStreamTrack (' + type + ')] enabled attribute');
test(function () { test(function () {
// Missing in Chrome.
assert_own_property(track, 'muted'); assert_own_property(track, 'muted');
assert_readonly(track, 'muted'); assert_readonly(track, 'muted');
assert_true(typeof track.muted === 'boolean'); assert_true(typeof track.muted === 'boolean');
@ -250,59 +276,113 @@ mediaStreamTrackTest.step(function() {
var mediaStreamTrackEventTest = async_test('4.4 MediaStreamTrackEvent'); var mediaStreamTrackEventTest = async_test('4.4 MediaStreamTrackEvent');
mediaStreamTrackEventTest.step(function() { mediaStreamTrackEventTest.step(function() {
var okCallback = mediaStreamTrackEventTest.step_func(function (stream) { var okCallback = mediaStreamTrackEventTest.step_func(function (stream) {
// TODO(kjellander): verify attributes // TODO(kjellander): verify attributes.
mediaStreamTrackEventTest.done(); mediaStreamTrackEventTest.done();
}); });
invokeGetUserMedia(mediaStreamTrackEventTest, okCallback); invokeGetUserMedia(mediaStreamTrackEventTest, okCallback);
}); });
// 4.5 Video and Audio Tracks tests. // 6. Media streams as media elements.
var avTracksTest = async_test('4.5 Video and Audio Tracks');
avTracksTest.step(function() { var playingInMediaElementTest = async_test(
var okCallback = avTracksTest.step_func(function (stream) { '6.2 Loading and Playing a MediaStream in a Media Element');
// TODO(kjellander): verify attributes playingInMediaElementTest.step(function() {
avTracksTest.done(); var video = createInvisibleVideoTag();
var okCallback = playingInMediaElementTest.step_func(function (stream) {
video.onplay = playingInMediaElementTest.step_func(function() {
// This depends on what webcam we're actually running with, but the
// resolution should at least be greater than or equal to QVGA.
assert_greater_than_equal(video.videoWidth, 320);
assert_greater_than_equal(video.videoHeight, 240);
playingInMediaElementTest.done();
}); });
invokeGetUserMedia(avTracksTest, okCallback); video.srcObject = stream;
});
invokeGetUserMedia(playingInMediaElementTest, okCallback);
}); });
// 5. The model: sources, sinks, constraints, and states // Verifies a media element track (for instance belonging to a video tag)
// after it has been assigned a media stream.
function verifyOneMediaElementTrack(track, correspondingMediaStreamTrack) {
assert_equals(track.id, correspondingMediaStreamTrack.id);
assert_equals(track.kind, 'main');
assert_equals(track.label, correspondingMediaStreamTrack.label);
assert_equals(track.language, '');
}
// 6. Source states var setsUpMediaTracksRightTest = async_test(
// 6.1 Dictionary MediaSourceStates Members '6.2 Sets up <video> audio and video tracks right');
setsUpMediaTracksRightTest.step(function() {
var video = createInvisibleVideoTag();
// 7. Source capabilities var okCallback = setsUpMediaTracksRightTest.step_func(function (stream) {
// 7.1 Dictionary CapabilityRange Members video.onplay = setsUpMediaTracksRightTest.step_func(function() {
// 7.2 CapabilityList array // Verify the requirements on the video tag's streams as outlined in 6.2.
// 7.3 Dictionary AllVideoCapabilities Members // There could be any number of tracks depending on what device we have
// 7.4 Dictionary AllAudioCapabilities Members // connected, so verify all of them. There should be at least one of audio
// and video each though.
assert_inherits(video, 'videoTracks',
'Browser missing videoTracks support on media elements.');
assert_readonly(video, 'videoTracks');
assert_greater_than_equal(video.videoTracks.length, 1);
assert_equals(video.videoTracks.length, stream.getVideoTracks().length);
// 8. URL tests. for (var i = 0; i < video.videoTracks.length; i++) {
var createObjectURLTest = async_test('8.1 URL createObjectURL method'); verifyOneMediaElementTrack(video.videoTracks[i],
createObjectURLTest.step(function() { stream.getVideoTracks()[i]);
var okCallback = createObjectURLTest.step_func(function (stream) { }
var url = URL.createObjectURL(stream);
assert_true(typeof url === 'string'); assert_inherits(video, 'audioTracks',
createObjectURLTest.done(); 'Browser missing audioTracks support on media elements.');
assert_readonly(video, 'audioTracks');
assert_greater_than_equal(video.audioTracks.length, 1);
assert_equals(video.audioTracks.length, stream.getAudioTracks().length);
for (var i = 0; i < video.audioTracks.length; i++) {
verifyOneMediaElementTrack(audio.audioTracks[i],
stream.getAudioTracks()[i]);
}
setsUpMediaTracksRightTest.done();
}); });
invokeGetUserMedia(createObjectURLTest, okCallback); video.srcObject = stream;
});
invokeGetUserMedia(setsUpMediaTracksRightTest, okCallback);
}); });
// 9. MediaStreams as Media Elements. var mediaElementsTest =
var mediaElementsTest = async_test('9. MediaStreams as Media Elements'); async_test('6.3 Media Element Attributes when Playing a MediaStream');
function verifyVideoTagWithStream(videoTag) { function verifyVideoTagWithStream(videoTag) {
test(function () {
assert_equals(videoTag.currentSrc, '');
}, '[Video tag] currentSrc attribute');
test(function () {
assert_equals(videoTag.preload, 'none');
}, '[Video tag] preload attribute');
test(function () { test(function () {
assert_equals(videoTag.buffered.length, 0); assert_equals(videoTag.buffered.length, 0);
}, '[Video tag] buffered attribute'); }, '[Video tag] buffered attribute');
test(function () { test(function () {
// Attempts to alter currentTime shall be ignored. // Where 1 is NETWORK_IDLE.
assert_equals(videoTag.networkState, 1);
}, '[Video tag] networkState attribute');
test(function () {
// 0 is HAVE_NOTHING, 4 is HAVE_ENOUGH_DATA.
assert_true(videoTag.readyState == 0 || videoTag.readyState == 4);
}, '[Video tag] readyState attribute');
test(function () {
assert_true(videoTag.currentTime >= 0); assert_true(videoTag.currentTime >= 0);
assert_throws('InvalidStateError', assert_throws(
function () { videoTag.currentTime = 1234; }, 'InvalidStateError', function () { videoTag.currentTime = 1234; },
'Attempts to modify currentTime shall throw ' + 'Attempts to modify currentTime shall throw InvalidStateError');
'InvalidStateError');
}, '[Video tag] currentTime attribute'); }, '[Video tag] currentTime attribute');
test(function () { test(function () {
@ -315,15 +395,15 @@ function verifyVideoTagWithStream(videoTag) {
test(function () { test(function () {
assert_equals(videoTag.defaultPlaybackRate, 1.0); assert_equals(videoTag.defaultPlaybackRate, 1.0);
assert_throws('DOMException', assert_throws(
function () { videoTag.defaultPlaybackRate = 2.0; }, 'DOMException', function () { videoTag.defaultPlaybackRate = 2.0; },
'Attempts to alter videoTag.defaultPlaybackRate MUST fail'); 'Attempts to alter videoTag.defaultPlaybackRate MUST fail');
}, '[Video tag] defaultPlaybackRate attribute'); }, '[Video tag] defaultPlaybackRate attribute');
test(function () { test(function () {
assert_equals(videoTag.playbackRate, 1.0); assert_equals(videoTag.playbackRate, 1.0);
assert_throws('DOMException', assert_throws(
function () { videoTag.playbackRate = 2.0; }, 'DOMException', function () { videoTag.playbackRate = 2.0; },
'Attempts to alter videoTag.playbackRate MUST fail'); 'Attempts to alter videoTag.playbackRate MUST fail');
}, '[Video tag] playbackRate attribute'); }, '[Video tag] playbackRate attribute');
@ -335,56 +415,96 @@ function verifyVideoTagWithStream(videoTag) {
test(function () { test(function () {
assert_equals(videoTag.seekable.length, 0); assert_equals(videoTag.seekable.length, 0);
assert_equals(videoTag.seekable.start(), videoTag.currentTime); // This is wrong in the standard: start() and end() must have arguments, but
assert_equals(videoTag.seekable.end(), videoTag.currentTime); // since the time range is empty as we assert in the line above, there is no
assert_equals(videoTag.startDate, NaN, 'videoTag.startDate'); // valid argument with which we can call the methods.
// assert_equals(videoTag.seekable.start(), videoTag.currentTime);
// assert_equals(videoTag.seekable.end(), videoTag.currentTime);
}, '[Video tag] seekable attribute'); }, '[Video tag] seekable attribute');
test(function () {
assert_equals(videoTag.startDate, NaN, 'videoTag.startDate');
}, '[Video tag] startDate attribute');
test(function () { test(function () {
assert_false(videoTag.loop); assert_false(videoTag.loop);
}, '[Video tag] loop attribute'); }, '[Video tag] loop attribute');
}; };
mediaElementsTest.step(function() { mediaElementsTest.step(function() {
var okCallback = mediaElementsTest.step_func(function (stream) { var okCallback = mediaElementsTest.step_func(function (stream) {
var videoTag = document.getElementById('local-view'); var video = createInvisibleVideoTag();
videoTag.srcObject = stream; video.srcObject = stream;
verifyVideoTagWithStream(videoTag); verifyVideoTagWithStream(video);
mediaElementsTest.done(); mediaElementsTest.done();
}); });
invokeGetUserMedia(mediaElementsTest, okCallback); invokeGetUserMedia(mediaElementsTest, okCallback);
}); });
// 11. Obtaining local multimedia content. // 9. Enumerating local media devices.
// TODO(phoglund): add tests.
// 11.1 NavigatorUserMedia. // 10. Obtaining local multimedia content.
var getUserMediaTest = async_test('11.1 NavigatorUserMedia');
getUserMediaTest.step(function() { function testGetUserMedia(test, constraints) {
var okCallback = getUserMediaTest.step_func(function (stream) { var okCallback = test.step_func(function (stream) {
assert_true(stream !== null); assert_true(stream !== null);
getUserMediaTest.done(); test.done();
});
navigator.getUserMedia(constraints, okCallback, failedCallback(test));
}
var getUserMediaTestAudioVideo = async_test('10.1.1 NavigatorUserMedia A/V');
getUserMediaTestAudioVideo.step(function() {
testGetUserMedia(getUserMediaTestAudioVideo, { video: true, audio: true });
}); });
// All three arguments are mandatory, so pass all of them. var getUserMediaTestVideo = async_test('10.1.1 NavigatorUserMedia V');
navigator.getUserMedia({ video: true, audio: true }, okCallback, getUserMediaTestVideo.step(function() {
failedCallback(getUserMediaTest)); testGetUserMedia(getUserMediaTestVideo, { video: true, audio: false });
navigator.getUserMedia({ video: true, audio: false }, okCallback,
failedCallback(getUserMediaTest));
navigator.getUserMedia({ video: false, audio: true }, okCallback,
failedCallback(getUserMediaTest));
}); });
// 11.2 MediaStreamConstraints. var getUserMediaTestAudio = async_test('10.1.1 NavigatorUserMedia A');
var constraintsTest = async_test('11.2 MediaStreamConstraints'); getUserMediaTestAudio.step(function() {
testGetUserMedia(getUserMediaTestAudio, { video: false, audio: true });
});
var getUserMediaTestNull = async_test('10.1.1 NavigatorUserMedia Null');
getUserMediaTestNull.step(function() {
testGetUserMedia(getUserMediaTestNull, null);
});
var getUserMediaTestPeerIdentity =
async_test('10.2 NavigatorUserMedia with peerIdentity');
getUserMediaTestPeerIdentity.step(function() {
var peerIdentity = 'my_identity';
var okCallback = getUserMediaTestPeerIdentity.step_func(function (stream) {
assert_true(stream !== null);
stream.getVideoTracks().forEach(function(track) {
assert_equals(track.peerIdentity, peerIdentity);
});
stream.getAudioTracks().forEach(function(track) {
assert_equals(track.peerIdentity, peerIdentity);
});
getUserMediaTestPeerIdentity.done();
});
navigator.getUserMedia(
{video: true, audio: true, peerIdentity: 'my_identity' },
okCallback, failedCallback(getUserMediaTestPeerIdentity));
});
// 10.2 MediaStreamConstraints.
var constraintsTest = async_test('10.2 MediaStreamConstraints');
constraintsTest.step(function() { constraintsTest.step(function() {
var okCallback = constraintsTest.step_func(function (stream) { var okCallback = constraintsTest.step_func(function (stream) {
assert_true(stream !== null); assert_true(stream !== null);
constraintsTest.done(); constraintsTest.done();
}); });
// Constraints on video. // See https://googlechrome.github.io/webrtc/samples/web/content/constraints/
// See http://webrtc.googlecode.com/svn/trunk/samples/js/demos/html/constraints-and-stats.html
// for more examples of constraints. // for more examples of constraints.
// TODO(phoglund): test more constraints; the possibilities here are endless.
var constraints = {}; var constraints = {};
constraints.audio = true; constraints.audio = true;
constraints.video = { mandatory: {}, optional: [] }; constraints.video = { mandatory: {}, optional: [] };
@ -396,9 +516,9 @@ constraintsTest.step(function() {
failedCallback(constraintsTest)); failedCallback(constraintsTest));
}); });
// 11.3 NavigatorUserMediaSuccessCallback. // 10.4 NavigatorUserMediaSuccessCallback.
var successCallbackTest = var successCallbackTest =
async_test('11.3 NavigatorUserMediaSuccessCallback'); async_test('10.4 NavigatorUserMediaSuccessCallback');
successCallbackTest.step(function() { successCallbackTest.step(function() {
var okCallback = successCallbackTest.step_func(function (stream) { var okCallback = successCallbackTest.step_func(function (stream) {
assert_true(stream !== null); assert_true(stream !== null);
@ -407,3 +527,5 @@ successCallbackTest.step(function() {
invokeGetUserMedia(successCallbackTest, okCallback); invokeGetUserMedia(successCallbackTest, okCallback);
}); });
// 11. Constrainable Pattern.
// TODO(phoglund): add tests.