From 6b061425c2004954b458207845c7601011f9559c Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Tue, 17 Jun 2014 08:46:58 +0000 Subject: [PATCH] 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 --- .../w3c/getusermedia_conformance_test.html | 11 +- .../test/w3c/getusermedia_conformance_test.js | 298 ++++++++++++------ 2 files changed, 216 insertions(+), 93 deletions(-) diff --git a/webrtc/test/w3c/getusermedia_conformance_test.html b/webrtc/test/w3c/getusermedia_conformance_test.html index 6ddb6030c..7b724a936 100644 --- a/webrtc/test/w3c/getusermedia_conformance_test.html +++ b/webrtc/test/w3c/getusermedia_conformance_test.html @@ -52,15 +52,16 @@ Notice that this requires the site you're browsing to use HTTPS.

- - + data-prefixed-objects= + '[{"ancestors":["navigator"], "name":"getUserMedia"}, + {"ancestors":["window"], "name":"RTCPeerConnection"}]' + data-prefixed-prototypes= + '[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'> + diff --git a/webrtc/test/w3c/getusermedia_conformance_test.js b/webrtc/test/w3c/getusermedia_conformance_test.js index fe1dcc8c0..d7c782807 100644 --- a/webrtc/test/w3c/getusermedia_conformance_test.js +++ b/webrtc/test/w3c/getusermedia_conformance_test.js @@ -6,7 +6,7 @@ // in the file PATENTS. All contributing project authors may // 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. function failedCallback(test) { @@ -19,6 +19,14 @@ function invokeGetUserMedia(test, okCallback) { 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. var mediaStreamTest = async_test('4.2 MediaStream'); @@ -56,21 +64,25 @@ function verifyMediaStream(stream) { }, '[MediaStream] removeTrack function'); test(function () { - // Missing in Chrome. assert_inherits(stream, 'clone'); assert_true(typeof stream.clone === 'function'); }, '[MediaStream] clone function'); test(function () { - assert_own_property(stream, 'ended'); - assert_true(typeof stream.ended === 'boolean'); - assert_readonly(stream, 'ended'); - }, '[MediaStream] ended attribute'); + assert_own_property(stream, 'active'); + assert_true(typeof stream.active === 'boolean'); + assert_readonly(stream, 'active'); + }, '[MediaStream] active attribute'); test(function () { - assert_own_property(stream, 'onended'); - assert_true(stream.onended === null); - }, '[MediaStream] onended EventHandler'); + assert_own_property(stream, 'onactive'); + assert_true(stream.onactive === null); + }, '[MediaStream] onactive EventHandler'); + + test(function () { + assert_own_property(stream, 'oninactive'); + assert_true(stream.oninactive === null); + }, '[MediaStream] oninactive EventHandler'); test(function () { assert_own_property(stream, 'onaddtrack'); @@ -86,28 +98,43 @@ function verifyMediaStream(stream) { mediaStreamTest.step(function() { var okCallback = mediaStreamTest.step_func(function (stream) { verifyMediaStream(stream); - var videoTracks = stream.getVideoTracks(); 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); }); +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. var mediaStreamTrackTest = async_test('4.3 MediaStreamTrack'); @@ -140,7 +167,6 @@ function verifyTrack(type, track) { }, '[MediaStreamTrack (' + type + ')] enabled attribute'); test(function () { - // Missing in Chrome. assert_own_property(track, 'muted'); assert_readonly(track, 'muted'); assert_true(typeof track.muted === 'boolean'); @@ -250,59 +276,113 @@ mediaStreamTrackTest.step(function() { var mediaStreamTrackEventTest = async_test('4.4 MediaStreamTrackEvent'); mediaStreamTrackEventTest.step(function() { var okCallback = mediaStreamTrackEventTest.step_func(function (stream) { - // TODO(kjellander): verify attributes + // TODO(kjellander): verify attributes. mediaStreamTrackEventTest.done(); }); invokeGetUserMedia(mediaStreamTrackEventTest, okCallback); }); -// 4.5 Video and Audio Tracks tests. -var avTracksTest = async_test('4.5 Video and Audio Tracks'); -avTracksTest.step(function() { - var okCallback = avTracksTest.step_func(function (stream) { - // TODO(kjellander): verify attributes - avTracksTest.done(); +// 6. Media streams as media elements. + +var playingInMediaElementTest = async_test( + '6.2 Loading and Playing a MediaStream in a Media Element'); +playingInMediaElementTest.step(function() { + 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(); + }); + video.srcObject = stream; }); - invokeGetUserMedia(avTracksTest, okCallback); + 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 -// 6.1 Dictionary MediaSourceStates Members +var setsUpMediaTracksRightTest = async_test( + '6.2 Sets up